]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/drm/i915_irq.c
This commit was generated by cvs2svn to compensate for changes in r154182,
[FreeBSD/FreeBSD.git] / sys / dev / drm / i915_irq.c
1 /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
2  */
3 /*-
4  * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5  * All Rights Reserved.
6  * 
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:
14  * 
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  * 
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.
26  * 
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 #include "dev/drm/drmP.h"
33 #include "dev/drm/drm.h"
34 #include "dev/drm/i915_drm.h"
35 #include "dev/drm/i915_drv.h"
36
37 #define USER_INT_FLAG 0x2
38 #define MAX_NOPID ((u32)~0)
39 #define READ_BREADCRUMB(dev_priv)  (((u32*)(dev_priv->hw_status_page))[5])
40
41 irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
42 {
43         drm_device_t *dev = (drm_device_t *) arg;
44         drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
45         u16 temp;
46
47         temp = I915_READ16(I915REG_INT_IDENTITY_R);
48         temp &= USER_INT_FLAG;
49
50         DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
51
52         if (temp == 0)
53                 return IRQ_NONE;
54
55         I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
56         DRM_WAKEUP(&dev_priv->irq_queue);
57
58         return IRQ_HANDLED;
59 }
60
61 static int i915_emit_irq(drm_device_t * dev)
62 {
63         drm_i915_private_t *dev_priv = dev->dev_private;
64         u32 ret;
65         RING_LOCALS;
66
67         i915_kernel_lost_context(dev);
68
69         DRM_DEBUG("%s\n", __FUNCTION__);
70
71         ret = dev_priv->counter;
72
73         BEGIN_LP_RING(2);
74         OUT_RING(0);
75         OUT_RING(GFX_OP_USER_INTERRUPT);
76         ADVANCE_LP_RING();
77
78         return ret;
79 }
80
81 static int i915_wait_irq(drm_device_t * dev, int irq_nr)
82 {
83         drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
84         int ret = 0;
85
86         DRM_DEBUG("%s irq_nr=%d breadcrumb=%d\n", __FUNCTION__, irq_nr,
87                   READ_BREADCRUMB(dev_priv));
88
89         if (READ_BREADCRUMB(dev_priv) >= irq_nr)
90                 return 0;
91
92         dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
93
94         DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
95                     READ_BREADCRUMB(dev_priv) >= irq_nr);
96
97         if (ret == DRM_ERR(EBUSY)) {
98                 DRM_ERROR("%s: EBUSY -- rec: %d emitted: %d\n",
99                           __FUNCTION__,
100                           READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
101         }
102
103         dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
104         return ret;
105 }
106
107 /* Needs the lock as it touches the ring.
108  */
109 int i915_irq_emit(DRM_IOCTL_ARGS)
110 {
111         DRM_DEVICE;
112         drm_i915_private_t *dev_priv = dev->dev_private;
113         drm_i915_irq_emit_t emit;
114         int result;
115
116         LOCK_TEST_WITH_RETURN(dev, filp);
117
118         if (!dev_priv) {
119                 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
120                 return DRM_ERR(EINVAL);
121         }
122
123         DRM_COPY_FROM_USER_IOCTL(emit, (drm_i915_irq_emit_t __user *) data,
124                                  sizeof(emit));
125
126         result = i915_emit_irq(dev);
127
128         if (DRM_COPY_TO_USER(emit.irq_seq, &result, sizeof(int))) {
129                 DRM_ERROR("copy_to_user\n");
130                 return DRM_ERR(EFAULT);
131         }
132
133         return 0;
134 }
135
136 /* Doesn't need the hardware lock.
137  */
138 int i915_irq_wait(DRM_IOCTL_ARGS)
139 {
140         DRM_DEVICE;
141         drm_i915_private_t *dev_priv = dev->dev_private;
142         drm_i915_irq_wait_t irqwait;
143
144         if (!dev_priv) {
145                 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
146                 return DRM_ERR(EINVAL);
147         }
148
149         DRM_COPY_FROM_USER_IOCTL(irqwait, (drm_i915_irq_wait_t __user *) data,
150                                  sizeof(irqwait));
151
152         return i915_wait_irq(dev, irqwait.irq_seq);
153 }
154
155 /* drm_dma.h hooks
156 */
157 void i915_driver_irq_preinstall(drm_device_t * dev)
158 {
159         drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
160
161         I915_WRITE16(I915REG_HWSTAM, 0xfffe);
162         I915_WRITE16(I915REG_INT_MASK_R, 0x0);
163         I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
164 }
165
166 void i915_driver_irq_postinstall(drm_device_t * dev)
167 {
168         drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
169
170         I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG);
171         DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
172 }
173
174 void i915_driver_irq_uninstall(drm_device_t * dev)
175 {
176         drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
177         if (!dev_priv)
178                 return;
179
180         I915_WRITE16(I915REG_HWSTAM, 0xffff);
181         I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
182         I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
183 }