blob: a1381c61aa631e3b9e27f9256157897c9dfaa1db [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
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 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#include "drmP.h"
30#include "drm.h"
31#include "i915_drm.h"
32#include "i915_drv.h"
33
Dave Airlie0d6aa602006-01-02 20:14:23 +110034#define USER_INT_FLAG (1<<1)
35#define VSYNC_PIPEB_FLAG (1<<5)
36#define VSYNC_PIPEA_FLAG (1<<7)
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define MAX_NOPID ((u32)~0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
41{
42 drm_device_t *dev = (drm_device_t *) arg;
43 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
44 u16 temp;
45
46 temp = I915_READ16(I915REG_INT_IDENTITY_R);
Dave Airlie0d6aa602006-01-02 20:14:23 +110047 temp &= (USER_INT_FLAG | VSYNC_PIPEA_FLAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 DRM_DEBUG("%s flag=%08x\n", __FUNCTION__, temp);
50
51 if (temp == 0)
52 return IRQ_NONE;
53
54 I915_WRITE16(I915REG_INT_IDENTITY_R, temp);
Dave Airlie0d6aa602006-01-02 20:14:23 +110055
56 if (temp & USER_INT_FLAG)
57 DRM_WAKEUP(&dev_priv->irq_queue);
58
59 if (temp & VSYNC_PIPEA_FLAG) {
60 atomic_inc(&dev->vbl_received);
61 DRM_WAKEUP(&dev->vbl_queue);
62 drm_vbl_send_signals(dev);
63 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 return IRQ_HANDLED;
66}
67
Dave Airliec94f7022005-07-07 21:03:38 +100068static int i915_emit_irq(drm_device_t * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70 drm_i915_private_t *dev_priv = dev->dev_private;
71 u32 ret;
72 RING_LOCALS;
73
74 i915_kernel_lost_context(dev);
75
76 DRM_DEBUG("%s\n", __FUNCTION__);
77
78 ret = dev_priv->counter;
79
80 BEGIN_LP_RING(2);
81 OUT_RING(0);
82 OUT_RING(GFX_OP_USER_INTERRUPT);
83 ADVANCE_LP_RING();
84
85 return ret;
86}
87
Dave Airliec94f7022005-07-07 21:03:38 +100088static int i915_wait_irq(drm_device_t * dev, int irq_nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
91 int ret = 0;
92
93 DRM_DEBUG("%s irq_nr=%d breadcrumb=%d\n", __FUNCTION__, irq_nr,
94 READ_BREADCRUMB(dev_priv));
95
96 if (READ_BREADCRUMB(dev_priv) >= irq_nr)
97 return 0;
98
99 dev_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
100
101 DRM_WAIT_ON(ret, dev_priv->irq_queue, 3 * DRM_HZ,
102 READ_BREADCRUMB(dev_priv) >= irq_nr);
103
104 if (ret == DRM_ERR(EBUSY)) {
105 DRM_ERROR("%s: EBUSY -- rec: %d emitted: %d\n",
106 __FUNCTION__,
107 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
108 }
109
110 dev_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
111 return ret;
112}
113
Dave Airlie0d6aa602006-01-02 20:14:23 +1100114int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
115{
116 drm_i915_private_t *dev_priv = dev->dev_private;
117 unsigned int cur_vblank;
118 int ret = 0;
119
120 if (!dev_priv) {
121 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
122 return DRM_ERR(EINVAL);
123 }
124
125 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
126 (((cur_vblank = atomic_read(&dev->vbl_received))
127 - *sequence) <= (1<<23)));
128
129 *sequence = cur_vblank;
130
131 return ret;
132}
133
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/* Needs the lock as it touches the ring.
136 */
137int i915_irq_emit(DRM_IOCTL_ARGS)
138{
139 DRM_DEVICE;
140 drm_i915_private_t *dev_priv = dev->dev_private;
141 drm_i915_irq_emit_t emit;
142 int result;
143
144 LOCK_TEST_WITH_RETURN(dev, filp);
145
146 if (!dev_priv) {
147 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
148 return DRM_ERR(EINVAL);
149 }
150
151 DRM_COPY_FROM_USER_IOCTL(emit, (drm_i915_irq_emit_t __user *) data,
152 sizeof(emit));
153
154 result = i915_emit_irq(dev);
155
156 if (DRM_COPY_TO_USER(emit.irq_seq, &result, sizeof(int))) {
157 DRM_ERROR("copy_to_user\n");
158 return DRM_ERR(EFAULT);
159 }
160
161 return 0;
162}
163
164/* Doesn't need the hardware lock.
165 */
166int i915_irq_wait(DRM_IOCTL_ARGS)
167{
168 DRM_DEVICE;
169 drm_i915_private_t *dev_priv = dev->dev_private;
170 drm_i915_irq_wait_t irqwait;
171
172 if (!dev_priv) {
173 DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
174 return DRM_ERR(EINVAL);
175 }
176
177 DRM_COPY_FROM_USER_IOCTL(irqwait, (drm_i915_irq_wait_t __user *) data,
178 sizeof(irqwait));
179
180 return i915_wait_irq(dev, irqwait.irq_seq);
181}
182
183/* drm_dma.h hooks
184*/
185void i915_driver_irq_preinstall(drm_device_t * dev)
186{
187 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
188
189 I915_WRITE16(I915REG_HWSTAM, 0xfffe);
190 I915_WRITE16(I915REG_INT_MASK_R, 0x0);
191 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
192}
193
194void i915_driver_irq_postinstall(drm_device_t * dev)
195{
196 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
197
Dave Airlie0d6aa602006-01-02 20:14:23 +1100198 I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | VSYNC_PIPEA_FLAG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
200}
201
202void i915_driver_irq_uninstall(drm_device_t * dev)
203{
204 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
205 if (!dev_priv)
206 return;
207
208 I915_WRITE16(I915REG_HWSTAM, 0xffff);
209 I915_WRITE16(I915REG_INT_MASK_R, 0xffff);
210 I915_WRITE16(I915REG_INT_ENABLE_R, 0x0);
211}