1 /* i830_dma.c -- DMA support for the I830 -*- linux-c -*-
3 * Copyright 2002 Tungsten Graphics, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
25 * Authors: Keith Whitwell <keith@tungstengraphics.com>
33 #include <linux/interrupt.h> /* For task queue support */
34 #include <linux/delay.h>
36 irqreturn_t
i830_driver_irq_handler(DRM_IRQ_ARGS
)
38 drm_device_t
*dev
= (drm_device_t
*) arg
;
39 drm_i830_private_t
*dev_priv
= (drm_i830_private_t
*) dev
->dev_private
;
42 temp
= I830_READ16(I830REG_INT_IDENTITY_R
);
43 DRM_DEBUG("%x\n", temp
);
48 I830_WRITE16(I830REG_INT_IDENTITY_R
, temp
);
50 atomic_inc(&dev_priv
->irq_received
);
51 wake_up_interruptible(&dev_priv
->irq_queue
);
56 static int i830_emit_irq(drm_device_t
* dev
)
58 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
61 DRM_DEBUG("%s\n", __FUNCTION__
);
63 atomic_inc(&dev_priv
->irq_emitted
);
67 OUT_RING(GFX_OP_USER_INTERRUPT
);
70 return atomic_read(&dev_priv
->irq_emitted
);
73 static int i830_wait_irq(drm_device_t
* dev
, int irq_nr
)
75 drm_i830_private_t
*dev_priv
= (drm_i830_private_t
*) dev
->dev_private
;
76 DECLARE_WAITQUEUE(entry
, current
);
77 unsigned long end
= jiffies
+ HZ
* 3;
80 DRM_DEBUG("%s\n", __FUNCTION__
);
82 if (atomic_read(&dev_priv
->irq_received
) >= irq_nr
)
85 dev_priv
->sarea_priv
->perf_boxes
|= I830_BOX_WAIT
;
87 add_wait_queue(&dev_priv
->irq_queue
, &entry
);
90 __set_current_state(TASK_INTERRUPTIBLE
);
91 if (atomic_read(&dev_priv
->irq_received
) >= irq_nr
)
93 if ((signed)(end
- jiffies
) <= 0) {
94 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
95 I830_READ16(I830REG_INT_IDENTITY_R
),
96 I830_READ16(I830REG_INT_MASK_R
),
97 I830_READ16(I830REG_INT_ENABLE_R
),
98 I830_READ16(I830REG_HWSTAM
));
100 ret
= -EBUSY
; /* Lockup? Missed irq? */
103 schedule_timeout(HZ
* 3);
104 if (signal_pending(current
)) {
110 __set_current_state(TASK_RUNNING
);
111 remove_wait_queue(&dev_priv
->irq_queue
, &entry
);
115 /* Needs the lock as it touches the ring.
117 int i830_irq_emit(struct inode
*inode
, struct file
*filp
, unsigned int cmd
,
120 drm_file_t
*priv
= filp
->private_data
;
121 drm_device_t
*dev
= priv
->head
->dev
;
122 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
123 drm_i830_irq_emit_t emit
;
126 LOCK_TEST_WITH_RETURN(dev
, filp
);
129 DRM_ERROR("%s called with no initialization\n", __FUNCTION__
);
134 (&emit
, (drm_i830_irq_emit_t __user
*) arg
, sizeof(emit
)))
137 result
= i830_emit_irq(dev
);
139 if (copy_to_user(emit
.irq_seq
, &result
, sizeof(int))) {
140 DRM_ERROR("copy_to_user\n");
147 /* Doesn't need the hardware lock.
149 int i830_irq_wait(struct inode
*inode
, struct file
*filp
, unsigned int cmd
,
152 drm_file_t
*priv
= filp
->private_data
;
153 drm_device_t
*dev
= priv
->head
->dev
;
154 drm_i830_private_t
*dev_priv
= dev
->dev_private
;
155 drm_i830_irq_wait_t irqwait
;
158 DRM_ERROR("%s called with no initialization\n", __FUNCTION__
);
162 if (copy_from_user(&irqwait
, (drm_i830_irq_wait_t __user
*) arg
,
166 return i830_wait_irq(dev
, irqwait
.irq_seq
);
171 void i830_driver_irq_preinstall(drm_device_t
* dev
)
173 drm_i830_private_t
*dev_priv
= (drm_i830_private_t
*) dev
->dev_private
;
175 I830_WRITE16(I830REG_HWSTAM
, 0xffff);
176 I830_WRITE16(I830REG_INT_MASK_R
, 0x0);
177 I830_WRITE16(I830REG_INT_ENABLE_R
, 0x0);
178 atomic_set(&dev_priv
->irq_received
, 0);
179 atomic_set(&dev_priv
->irq_emitted
, 0);
180 init_waitqueue_head(&dev_priv
->irq_queue
);
183 void i830_driver_irq_postinstall(drm_device_t
* dev
)
185 drm_i830_private_t
*dev_priv
= (drm_i830_private_t
*) dev
->dev_private
;
187 I830_WRITE16(I830REG_INT_ENABLE_R
, 0x2);
190 void i830_driver_irq_uninstall(drm_device_t
* dev
)
192 drm_i830_private_t
*dev_priv
= (drm_i830_private_t
*) dev
->dev_private
;
196 I830_WRITE16(I830REG_INT_MASK_R
, 0xffff);
197 I830_WRITE16(I830REG_INT_ENABLE_R
, 0x0);