- Move IRQ functions from drm_dma.h to new drm_irq.h and disentangle them
authorEric Anholt <anholt@freebsd.org>
Fri, 17 Oct 2003 05:13:48 +0000 (05:13 +0000)
committerEric Anholt <anholt@freebsd.org>
Fri, 17 Oct 2003 05:13:48 +0000 (05:13 +0000)
    from __HAVE_DMA. This will be useful for adding vblank sync support to
    sis and tdfx. Rename dma_service to irq_handler, which is more
    accurately what it is.
- Fix the #if _HAVE_DMA_IRQ in radeon, r128, mga, i810, i830, gamma to have
    the right number of underscores. This may have been a problem in the
    case that the server died without doing its DRM_IOCTL_CONTROL to
    uninit.

59 files changed:
bsd-core/drmP.h
bsd-core/drm_dma.c
bsd-core/drm_drv.c
bsd-core/drm_irq.c [new file with mode: 0644]
bsd-core/mga_drv.c
bsd-core/r128_drv.c
bsd-core/radeon_drv.c
bsd/drmP.h
bsd/drm_dma.h
bsd/drm_drv.h
bsd/drm_irq.h [new file with mode: 0644]
bsd/mga_drv.c
bsd/r128_drv.c
bsd/radeon_drv.c
linux-core/Doxyfile
linux-core/drmP.h
linux-core/drm_dma.c
linux-core/drm_drv.c
linux-core/drm_irq.c [new file with mode: 0644]
linux-core/i810_dma.c
linux-core/i830_dma.c
linux-core/i830_drv.c
linux-core/i830_irq.c
linux-core/mga_drv.c
linux-core/r128_drv.c
linux-core/radeon_drv.c
linux/Doxyfile
linux/Makefile.linux
linux/drmP.h
linux/drm_dma.h
linux/drm_drv.h
linux/drm_irq.h [new file with mode: 0644]
linux/gamma.h
linux/gamma_dma.c
linux/gamma_drv.c
linux/i810.h
linux/i810_dma.c
linux/i830.h
linux/i830_dma.c
linux/i830_drv.c
linux/i830_irq.c
linux/mga_drv.c
linux/r128_drv.c
linux/radeon_drv.c
shared-core/mga_dma.c
shared-core/mga_irq.c
shared-core/r128_cce.c
shared-core/r128_irq.c
shared-core/radeon_cp.c
shared-core/radeon_irq.c
shared/mga.h
shared/mga_dma.c
shared/mga_irq.c
shared/r128.h
shared/r128_cce.c
shared/r128_irq.c
shared/radeon.h
shared/radeon_cp.c
shared/radeon_irq.c

index 0a93ef3..c39df16 100644 (file)
@@ -49,8 +49,8 @@
 #ifndef __HAVE_DMA
 #define __HAVE_DMA             0
 #endif
-#ifndef __HAVE_DMA_IRQ
-#define __HAVE_DMA_IRQ         0
+#ifndef __HAVE_IRQ
+#define __HAVE_IRQ             0
 #endif
 
 #define DRM_DEBUG_CODE 0         /* Include debugging code (if > 1, then
@@ -437,19 +437,21 @@ extern int             DRM(dma_setup)(drm_device_t *dev);
 extern void         DRM(dma_takedown)(drm_device_t *dev);
 extern void         DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
 extern void         DRM(reclaim_buffers)(drm_device_t *dev, DRMFILE filp);
-#if __HAVE_DMA_IRQ
+#endif
+
+#if __HAVE_IRQ
+                               /* IRQ support (drm_irq.h) */
 extern int           DRM(irq_install)( drm_device_t *dev, int irq );
 extern int           DRM(irq_uninstall)( drm_device_t *dev );
-extern irqreturn_t   DRM(dma_service)( DRM_IRQ_ARGS );
+extern irqreturn_t   DRM(irq_handler)( DRM_IRQ_ARGS );
 extern void          DRM(driver_irq_preinstall)( drm_device_t *dev );
 extern void          DRM(driver_irq_postinstall)( drm_device_t *dev );
 extern void          DRM(driver_irq_uninstall)( drm_device_t *dev );
-#if __HAVE_DMA_IRQ_BH
-extern void          DRM(dma_immediate_bh)( DRM_TASKQUEUE_ARGS );
+#if __HAVE_IRQ_BH
+extern void          DRM(irq_immediate_bh)( DRM_TASKQUEUE_ARGS );
 #endif
 #endif
 
-#endif /* __HAVE_DMA */
 #if __HAVE_VBL_IRQ
 extern int           DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq);
 extern void          DRM(vbl_send_signals)( drm_device_t *dev );
@@ -524,8 +526,8 @@ extern int          DRM(freebufs)(DRM_IOCTL_ARGS);
 extern int             DRM(mapbufs)(DRM_IOCTL_ARGS);
 #endif
 
-/* DMA support (drm_dma.h) */
-#if __HAVE_DMA
+/* IRQ support (drm_irq.h) */
+#if __HAVE_IRQ || __HAVE_DMA
 extern int             DRM(control)(DRM_IOCTL_ARGS);
 #endif
 #if __HAVE_VBL_IRQ
index 6c502ef..877fd4e 100644 (file)
@@ -149,224 +149,11 @@ void DRM(reclaim_buffers)(drm_device_t *dev, DRMFILE filp)
 }
 #endif
 
-
-#if __HAVE_DMA_IRQ
-
-int DRM(irq_install)( drm_device_t *dev, int irq )
-{
-       int retcode;
-
-       if ( irq == 0 || dev->dev_private == NULL)
-               return DRM_ERR(EINVAL);
-
-       DRM_LOCK();
-       if ( dev->irq ) {
-               DRM_UNLOCK();
-               return DRM_ERR(EBUSY);
-       }
-       dev->irq = irq;
-       DRM_UNLOCK();
-
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
-       dev->context_flag = 0;
-
-       dev->dma->next_buffer = NULL;
-       dev->dma->this_buffer = NULL;
-
-#if __HAVE_DMA_IRQ_BH
-       TASK_INIT(&dev->task, 0, DRM(dma_immediate_bh), dev);
-#endif
-
-#if __HAVE_VBL_IRQ && 0 /* disabled */
-       DRM_SPININIT( dev->vbl_lock, "vblsig" );
-       TAILQ_INIT( &dev->vbl_sig_list );
-#endif
-
-                               /* Before installing handler */
-       DRM(driver_irq_preinstall)( dev );
-
-                               /* Install handler */
-       dev->irqrid = 0;
-#ifdef __FreeBSD__
-       dev->irqr = bus_alloc_resource(dev->device, SYS_RES_IRQ, &dev->irqrid,
-                                     0, ~0, 1, RF_SHAREABLE);
-       if (!dev->irqr) {
-#elif defined(__NetBSD__)
-       if (pci_intr_map(&dev->pa, &dev->ih) != 0) {
-#endif
-               DRM_LOCK();
-               dev->irq = 0;
-               dev->irqrid = 0;
-               DRM_UNLOCK();
-               return ENOENT;
-       }
-       
-#ifdef __FreeBSD__
-#if __FreeBSD_version < 500000
-       retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY,
-                                DRM(dma_service), dev, &dev->irqh);
-#else
-       retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY | INTR_MPSAFE,
-                                DRM(dma_service), dev, &dev->irqh);
-#endif
-       if ( retcode ) {
-#elif defined(__NetBSD__)
-       dev->irqh = pci_intr_establish(&dev->pa.pa_pc, dev->ih, IPL_TTY,
-                                     (irqreturn_t (*)(DRM_IRQ_ARGS))DRM(dma_service), dev);
-       if ( !dev->irqh ) {
-#endif
-               DRM_LOCK();
-#ifdef __FreeBSD__
-               bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid, dev->irqr);
-#endif
-               dev->irq = 0;
-               dev->irqrid = 0;
-               DRM_UNLOCK();
-               return retcode;
-       }
-
-                               /* After installing handler */
-       DRM(driver_irq_postinstall)( dev );
-
-       return 0;
-}
-
-int DRM(irq_uninstall)( drm_device_t *dev )
-{
-       int irq;
-       int irqrid;
-       
-       DRM_LOCK();
-       irq = dev->irq;
-       irqrid = dev->irqrid;
-       dev->irq = 0;
-       dev->irqrid = 0;
-       DRM_UNLOCK();
-
-       if ( !irq )
-               return DRM_ERR(EINVAL);
-
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
-       DRM(driver_irq_uninstall)( dev );
-
-#ifdef __FreeBSD__
-       bus_teardown_intr(dev->device, dev->irqr, dev->irqh);
-       bus_release_resource(dev->device, SYS_RES_IRQ, irqrid, dev->irqr);
-#elif defined(__NetBSD__)
-       pci_intr_disestablish(&dev->pa.pa_pc, dev->irqh);
-#endif
-
-       return 0;
-}
-
-int DRM(control)( DRM_IOCTL_ARGS )
-{
-       DRM_DEVICE;
-       drm_control_t ctl;
-
-       DRM_COPY_FROM_USER_IOCTL( ctl, (drm_control_t *) data, sizeof(ctl) );
-
-       switch ( ctl.func ) {
-       case DRM_INST_HANDLER:
-               return DRM(irq_install)( dev, ctl.irq );
-       case DRM_UNINST_HANDLER:
-               return DRM(irq_uninstall)( dev );
-       default:
-               return DRM_ERR(EINVAL);
-       }
-}
-
-#if __HAVE_VBL_IRQ
-int DRM(wait_vblank)( DRM_IOCTL_ARGS )
-{
-       DRM_DEVICE;
-       drm_wait_vblank_t vblwait;
-       struct timeval now;
-       int ret;
-
-       if (!dev->irq)
-               return DRM_ERR(EINVAL);
-
-       DRM_COPY_FROM_USER_IOCTL( vblwait, (drm_wait_vblank_t *)data,
-                                 sizeof(vblwait) );
-
-       if (vblwait.request.type & _DRM_VBLANK_RELATIVE) {
-               vblwait.request.sequence += atomic_read(&dev->vbl_received);
-               vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
-       }
-
-       flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
-       if (flags & _DRM_VBLANK_SIGNAL) {
-#if 0 /* disabled */
-               drm_vbl_sig_t *vbl_sig = DRM_MALLOC(sizeof(drm_vbl_sig_t));
-               if (vbl_sig == NULL)
-                       return ENOMEM;
-               bzero(vbl_sig, sizeof(*vbl_sig));
-               
-               vbl_sig->sequence = vblwait.request.sequence;
-               vbl_sig->signo = vblwait.request.signal;
-               vbl_sig->pid = DRM_CURRENTPID;
-
-               vblwait.reply.sequence = atomic_read(&dev->vbl_received);
-               
-               DRM_SPINLOCK(&dev->vbl_lock);
-               TAILQ_INSERT_HEAD(&dev->vbl_sig_list, vbl_sig, link);
-               DRM_SPINUNLOCK(&dev->vbl_lock);
-               ret = 0;
-#endif
-               ret = EINVAL;
-       } else {
-               ret = DRM(vblank_wait)(dev, &vblwait.request.sequence);
-               
-               microtime(&now);
-               vblwait.reply.tval_sec = now.tv_sec;
-               vblwait.reply.tval_usec = now.tv_usec;
-       }
-
-       DRM_COPY_TO_USER_IOCTL( (drm_wait_vblank_t *)data, vblwait,
-                               sizeof(vblwait) );
-
-       return ret;
-}
-
-void DRM(vbl_send_signals)(drm_device_t *dev)
-{
-}
-
-#if 0 /* disabled */
-void DRM(vbl_send_signals)( drm_device_t *dev )
-{
-       drm_vbl_sig_t *vbl_sig;
-       unsigned int vbl_seq = atomic_read( &dev->vbl_received );
-       struct proc *p;
-
-       DRM_SPINLOCK(&dev->vbl_lock);
-
-       vbl_sig = TAILQ_FIRST(&dev->vbl_sig_list);
-       while (vbl_sig != NULL) {
-               drm_vbl_sig_t *next = TAILQ_NEXT(vbl_sig, link);
-
-               if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
-                       p = pfind(vbl_sig->pid);
-                       if (p != NULL)
-                               psignal(p, vbl_sig->signo);
-
-                       TAILQ_REMOVE(&dev->vbl_sig_list, vbl_sig, link);
-                       DRM_FREE(vbl_sig,sizeof(*vbl_sig));
-               }
-               vbl_sig = next;
-       }
-
-       DRM_SPINUNLOCK(&dev->vbl_lock);
-}
-#endif
-
-#endif /*  __HAVE_VBL_IRQ */
-
-#else
-
+#if !__HAVE_IRQ
+/* This stub DRM_IOCTL_CONTROL handler is for the drivers that used to require
+ * IRQs for DMA but no longer do.  It maintains compatibility with the X Servers
+ * that try to use the control ioctl by simply returning success.
+ */
 int DRM(control)( DRM_IOCTL_ARGS )
 {
        drm_control_t ctl;
@@ -381,8 +168,6 @@ int DRM(control)( DRM_IOCTL_ARGS )
                return DRM_ERR(EINVAL);
        }
 }
-
-#endif /* __HAVE_DMA_IRQ */
+#endif
 
 #endif /* __HAVE_DMA */
-
index bfded6b..8a9e303 100644 (file)
@@ -55,8 +55,8 @@
 #ifndef __HAVE_CTX_BITMAP
 #define __HAVE_CTX_BITMAP              0
 #endif
-#ifndef __HAVE_DMA_IRQ
-#define __HAVE_DMA_IRQ                 0
+#ifndef __HAVE_IRQ
+#define __HAVE_IRQ                     0
 #endif
 #ifndef __HAVE_DMA_QUEUE
 #define __HAVE_DMA_QUEUE               0
@@ -170,9 +170,9 @@ static drm_ioctl_desc_t               DRM(ioctls)[] = {
        [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)]     = { DRM(infobufs),    1, 0 },
        [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)]      = { DRM(mapbufs),     1, 0 },
        [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)]     = { DRM(freebufs),    1, 0 },
-
-       /* The DRM_IOCTL_DMA ioctl should be defined by the driver.
-        */
+       /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
+#endif
+#if __HAVE_IRQ || __HAVE_DMA
        [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)]       = { DRM(control),     1, 1 },
 #endif
 
@@ -510,7 +510,7 @@ static int DRM(takedown)( drm_device_t *dev )
        DRM_DEBUG( "\n" );
 
        DRIVER_PRETAKEDOWN();
-#if __HAVE_DMA_IRQ
+#if __HAVE_IRQ
        if (dev->irq != 0)
                DRM(irq_uninstall)( dev );
 #endif
diff --git a/bsd-core/drm_irq.c b/bsd-core/drm_irq.c
new file mode 100644 (file)
index 0000000..3366ff1
--- /dev/null
@@ -0,0 +1,242 @@
+/* drm_dma.c -- DMA IOCTL and function support
+ * Created: Fri Oct 18 2003 by anholt@FreeBSD.org
+ *
+ * Copyright 2003 Eric Anholt
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Eric Anholt <anholt@FreeBSD.org>
+ *
+ */
+int DRM(irq_install)( drm_device_t *dev, int irq )
+{
+       int retcode;
+
+       if ( irq == 0 || dev->dev_private == NULL)
+               return DRM_ERR(EINVAL);
+
+       DRM_LOCK();
+       if ( dev->irq ) {
+               DRM_UNLOCK();
+               return DRM_ERR(EBUSY);
+       }
+       dev->irq = irq;
+       DRM_UNLOCK();
+
+       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+
+       dev->context_flag = 0;
+
+       dev->dma->next_buffer = NULL;
+       dev->dma->this_buffer = NULL;
+
+#if __HAVE_IRQ_BH
+       TASK_INIT(&dev->task, 0, DRM(dma_immediate_bh), dev);
+#endif
+
+#if __HAVE_VBL_IRQ && 0 /* disabled */
+       DRM_SPININIT( dev->vbl_lock, "vblsig" );
+       TAILQ_INIT( &dev->vbl_sig_list );
+#endif
+
+                               /* Before installing handler */
+       DRM(driver_irq_preinstall)( dev );
+
+                               /* Install handler */
+       dev->irqrid = 0;
+#ifdef __FreeBSD__
+       dev->irqr = bus_alloc_resource(dev->device, SYS_RES_IRQ, &dev->irqrid,
+                                     0, ~0, 1, RF_SHAREABLE);
+       if (!dev->irqr) {
+#elif defined(__NetBSD__)
+       if (pci_intr_map(&dev->pa, &dev->ih) != 0) {
+#endif
+               DRM_LOCK();
+               dev->irq = 0;
+               dev->irqrid = 0;
+               DRM_UNLOCK();
+               return ENOENT;
+       }
+       
+#ifdef __FreeBSD__
+#if __FreeBSD_version < 500000
+       retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY,
+                                DRM(irq_handler), dev, &dev->irqh);
+#else
+       retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY | INTR_MPSAFE,
+                                DRM(irq_handler), dev, &dev->irqh);
+#endif
+       if ( retcode ) {
+#elif defined(__NetBSD__)
+       dev->irqh = pci_intr_establish(&dev->pa.pa_pc, dev->ih, IPL_TTY,
+           (irqreturn_t (*)(DRM_IRQ_ARGS))DRM(irq_handler), dev);
+       if ( !dev->irqh ) {
+#endif
+               DRM_LOCK();
+#ifdef __FreeBSD__
+               bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid, dev->irqr);
+#endif
+               dev->irq = 0;
+               dev->irqrid = 0;
+               DRM_UNLOCK();
+               return retcode;
+       }
+
+                               /* After installing handler */
+       DRM(driver_irq_postinstall)( dev );
+
+       return 0;
+}
+
+int DRM(irq_uninstall)( drm_device_t *dev )
+{
+       int irq;
+       int irqrid;
+       
+       DRM_LOCK();
+       irq = dev->irq;
+       irqrid = dev->irqrid;
+       dev->irq = 0;
+       dev->irqrid = 0;
+       DRM_UNLOCK();
+
+       if ( !irq )
+               return DRM_ERR(EINVAL);
+
+       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+
+       DRM(driver_irq_uninstall)( dev );
+
+#ifdef __FreeBSD__
+       bus_teardown_intr(dev->device, dev->irqr, dev->irqh);
+       bus_release_resource(dev->device, SYS_RES_IRQ, irqrid, dev->irqr);
+#elif defined(__NetBSD__)
+       pci_intr_disestablish(&dev->pa.pa_pc, dev->irqh);
+#endif
+
+       return 0;
+}
+
+int DRM(control)( DRM_IOCTL_ARGS )
+{
+       DRM_DEVICE;
+       drm_control_t ctl;
+
+       DRM_COPY_FROM_USER_IOCTL( ctl, (drm_control_t *) data, sizeof(ctl) );
+
+       switch ( ctl.func ) {
+       case DRM_INST_HANDLER:
+               return DRM(irq_install)( dev, ctl.irq );
+       case DRM_UNINST_HANDLER:
+               return DRM(irq_uninstall)( dev );
+       default:
+               return DRM_ERR(EINVAL);
+       }
+}
+
+#if __HAVE_VBL_IRQ
+int DRM(wait_vblank)( DRM_IOCTL_ARGS )
+{
+       DRM_DEVICE;
+       drm_wait_vblank_t vblwait;
+       struct timeval now;
+       int ret;
+
+       if (!dev->irq)
+               return DRM_ERR(EINVAL);
+
+       DRM_COPY_FROM_USER_IOCTL( vblwait, (drm_wait_vblank_t *)data,
+                                 sizeof(vblwait) );
+
+       if (vblwait.request.type & _DRM_VBLANK_RELATIVE) {
+               vblwait.request.sequence += atomic_read(&dev->vbl_received);
+               vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
+       }
+
+       flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
+       if (flags & _DRM_VBLANK_SIGNAL) {
+#if 0 /* disabled */
+               drm_vbl_sig_t *vbl_sig = DRM_MALLOC(sizeof(drm_vbl_sig_t));
+               if (vbl_sig == NULL)
+                       return ENOMEM;
+               bzero(vbl_sig, sizeof(*vbl_sig));
+               
+               vbl_sig->sequence = vblwait.request.sequence;
+               vbl_sig->signo = vblwait.request.signal;
+               vbl_sig->pid = DRM_CURRENTPID;
+
+               vblwait.reply.sequence = atomic_read(&dev->vbl_received);
+               
+               DRM_SPINLOCK(&dev->vbl_lock);
+               TAILQ_INSERT_HEAD(&dev->vbl_sig_list, vbl_sig, link);
+               DRM_SPINUNLOCK(&dev->vbl_lock);
+               ret = 0;
+#endif
+               ret = EINVAL;
+       } else {
+               ret = DRM(vblank_wait)(dev, &vblwait.request.sequence);
+               
+               microtime(&now);
+               vblwait.reply.tval_sec = now.tv_sec;
+               vblwait.reply.tval_usec = now.tv_usec;
+       }
+
+       DRM_COPY_TO_USER_IOCTL( (drm_wait_vblank_t *)data, vblwait,
+                               sizeof(vblwait) );
+
+       return ret;
+}
+
+void DRM(vbl_send_signals)(drm_device_t *dev)
+{
+}
+
+#if 0 /* disabled */
+void DRM(vbl_send_signals)( drm_device_t *dev )
+{
+       drm_vbl_sig_t *vbl_sig;
+       unsigned int vbl_seq = atomic_read( &dev->vbl_received );
+       struct proc *p;
+
+       DRM_SPINLOCK(&dev->vbl_lock);
+
+       vbl_sig = TAILQ_FIRST(&dev->vbl_sig_list);
+       while (vbl_sig != NULL) {
+               drm_vbl_sig_t *next = TAILQ_NEXT(vbl_sig, link);
+
+               if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
+                       p = pfind(vbl_sig->pid);
+                       if (p != NULL)
+                               psignal(p, vbl_sig->signo);
+
+                       TAILQ_REMOVE(&dev->vbl_sig_list, vbl_sig, link);
+                       DRM_FREE(vbl_sig,sizeof(*vbl_sig));
+               }
+               vbl_sig = next;
+       }
+
+       DRM_SPINUNLOCK(&dev->vbl_lock);
+}
+#endif
+
+#endif /*  __HAVE_VBL_IRQ */
index 4eaf5ed..477086e 100644 (file)
@@ -45,6 +45,7 @@
 #include "drm_drv.h"
 #include "drm_fops.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_vm.h"
index e656f60..a9af369 100644 (file)
@@ -48,6 +48,7 @@
 #include "drm_drv.h"
 #include "drm_fops.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_pci.h"
index 3b69976..df941f9 100644 (file)
@@ -46,6 +46,7 @@
 #include "drm_drv.h"
 #include "drm_fops.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_pci.h"
index 0a93ef3..c39df16 100644 (file)
@@ -49,8 +49,8 @@
 #ifndef __HAVE_DMA
 #define __HAVE_DMA             0
 #endif
-#ifndef __HAVE_DMA_IRQ
-#define __HAVE_DMA_IRQ         0
+#ifndef __HAVE_IRQ
+#define __HAVE_IRQ             0
 #endif
 
 #define DRM_DEBUG_CODE 0         /* Include debugging code (if > 1, then
@@ -437,19 +437,21 @@ extern int             DRM(dma_setup)(drm_device_t *dev);
 extern void         DRM(dma_takedown)(drm_device_t *dev);
 extern void         DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
 extern void         DRM(reclaim_buffers)(drm_device_t *dev, DRMFILE filp);
-#if __HAVE_DMA_IRQ
+#endif
+
+#if __HAVE_IRQ
+                               /* IRQ support (drm_irq.h) */
 extern int           DRM(irq_install)( drm_device_t *dev, int irq );
 extern int           DRM(irq_uninstall)( drm_device_t *dev );
-extern irqreturn_t   DRM(dma_service)( DRM_IRQ_ARGS );
+extern irqreturn_t   DRM(irq_handler)( DRM_IRQ_ARGS );
 extern void          DRM(driver_irq_preinstall)( drm_device_t *dev );
 extern void          DRM(driver_irq_postinstall)( drm_device_t *dev );
 extern void          DRM(driver_irq_uninstall)( drm_device_t *dev );
-#if __HAVE_DMA_IRQ_BH
-extern void          DRM(dma_immediate_bh)( DRM_TASKQUEUE_ARGS );
+#if __HAVE_IRQ_BH
+extern void          DRM(irq_immediate_bh)( DRM_TASKQUEUE_ARGS );
 #endif
 #endif
 
-#endif /* __HAVE_DMA */
 #if __HAVE_VBL_IRQ
 extern int           DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq);
 extern void          DRM(vbl_send_signals)( drm_device_t *dev );
@@ -524,8 +526,8 @@ extern int          DRM(freebufs)(DRM_IOCTL_ARGS);
 extern int             DRM(mapbufs)(DRM_IOCTL_ARGS);
 #endif
 
-/* DMA support (drm_dma.h) */
-#if __HAVE_DMA
+/* IRQ support (drm_irq.h) */
+#if __HAVE_IRQ || __HAVE_DMA
 extern int             DRM(control)(DRM_IOCTL_ARGS);
 #endif
 #if __HAVE_VBL_IRQ
index 6c502ef..877fd4e 100644 (file)
@@ -149,224 +149,11 @@ void DRM(reclaim_buffers)(drm_device_t *dev, DRMFILE filp)
 }
 #endif
 
-
-#if __HAVE_DMA_IRQ
-
-int DRM(irq_install)( drm_device_t *dev, int irq )
-{
-       int retcode;
-
-       if ( irq == 0 || dev->dev_private == NULL)
-               return DRM_ERR(EINVAL);
-
-       DRM_LOCK();
-       if ( dev->irq ) {
-               DRM_UNLOCK();
-               return DRM_ERR(EBUSY);
-       }
-       dev->irq = irq;
-       DRM_UNLOCK();
-
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
-       dev->context_flag = 0;
-
-       dev->dma->next_buffer = NULL;
-       dev->dma->this_buffer = NULL;
-
-#if __HAVE_DMA_IRQ_BH
-       TASK_INIT(&dev->task, 0, DRM(dma_immediate_bh), dev);
-#endif
-
-#if __HAVE_VBL_IRQ && 0 /* disabled */
-       DRM_SPININIT( dev->vbl_lock, "vblsig" );
-       TAILQ_INIT( &dev->vbl_sig_list );
-#endif
-
-                               /* Before installing handler */
-       DRM(driver_irq_preinstall)( dev );
-
-                               /* Install handler */
-       dev->irqrid = 0;
-#ifdef __FreeBSD__
-       dev->irqr = bus_alloc_resource(dev->device, SYS_RES_IRQ, &dev->irqrid,
-                                     0, ~0, 1, RF_SHAREABLE);
-       if (!dev->irqr) {
-#elif defined(__NetBSD__)
-       if (pci_intr_map(&dev->pa, &dev->ih) != 0) {
-#endif
-               DRM_LOCK();
-               dev->irq = 0;
-               dev->irqrid = 0;
-               DRM_UNLOCK();
-               return ENOENT;
-       }
-       
-#ifdef __FreeBSD__
-#if __FreeBSD_version < 500000
-       retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY,
-                                DRM(dma_service), dev, &dev->irqh);
-#else
-       retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY | INTR_MPSAFE,
-                                DRM(dma_service), dev, &dev->irqh);
-#endif
-       if ( retcode ) {
-#elif defined(__NetBSD__)
-       dev->irqh = pci_intr_establish(&dev->pa.pa_pc, dev->ih, IPL_TTY,
-                                     (irqreturn_t (*)(DRM_IRQ_ARGS))DRM(dma_service), dev);
-       if ( !dev->irqh ) {
-#endif
-               DRM_LOCK();
-#ifdef __FreeBSD__
-               bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid, dev->irqr);
-#endif
-               dev->irq = 0;
-               dev->irqrid = 0;
-               DRM_UNLOCK();
-               return retcode;
-       }
-
-                               /* After installing handler */
-       DRM(driver_irq_postinstall)( dev );
-
-       return 0;
-}
-
-int DRM(irq_uninstall)( drm_device_t *dev )
-{
-       int irq;
-       int irqrid;
-       
-       DRM_LOCK();
-       irq = dev->irq;
-       irqrid = dev->irqrid;
-       dev->irq = 0;
-       dev->irqrid = 0;
-       DRM_UNLOCK();
-
-       if ( !irq )
-               return DRM_ERR(EINVAL);
-
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
-       DRM(driver_irq_uninstall)( dev );
-
-#ifdef __FreeBSD__
-       bus_teardown_intr(dev->device, dev->irqr, dev->irqh);
-       bus_release_resource(dev->device, SYS_RES_IRQ, irqrid, dev->irqr);
-#elif defined(__NetBSD__)
-       pci_intr_disestablish(&dev->pa.pa_pc, dev->irqh);
-#endif
-
-       return 0;
-}
-
-int DRM(control)( DRM_IOCTL_ARGS )
-{
-       DRM_DEVICE;
-       drm_control_t ctl;
-
-       DRM_COPY_FROM_USER_IOCTL( ctl, (drm_control_t *) data, sizeof(ctl) );
-
-       switch ( ctl.func ) {
-       case DRM_INST_HANDLER:
-               return DRM(irq_install)( dev, ctl.irq );
-       case DRM_UNINST_HANDLER:
-               return DRM(irq_uninstall)( dev );
-       default:
-               return DRM_ERR(EINVAL);
-       }
-}
-
-#if __HAVE_VBL_IRQ
-int DRM(wait_vblank)( DRM_IOCTL_ARGS )
-{
-       DRM_DEVICE;
-       drm_wait_vblank_t vblwait;
-       struct timeval now;
-       int ret;
-
-       if (!dev->irq)
-               return DRM_ERR(EINVAL);
-
-       DRM_COPY_FROM_USER_IOCTL( vblwait, (drm_wait_vblank_t *)data,
-                                 sizeof(vblwait) );
-
-       if (vblwait.request.type & _DRM_VBLANK_RELATIVE) {
-               vblwait.request.sequence += atomic_read(&dev->vbl_received);
-               vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
-       }
-
-       flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
-       if (flags & _DRM_VBLANK_SIGNAL) {
-#if 0 /* disabled */
-               drm_vbl_sig_t *vbl_sig = DRM_MALLOC(sizeof(drm_vbl_sig_t));
-               if (vbl_sig == NULL)
-                       return ENOMEM;
-               bzero(vbl_sig, sizeof(*vbl_sig));
-               
-               vbl_sig->sequence = vblwait.request.sequence;
-               vbl_sig->signo = vblwait.request.signal;
-               vbl_sig->pid = DRM_CURRENTPID;
-
-               vblwait.reply.sequence = atomic_read(&dev->vbl_received);
-               
-               DRM_SPINLOCK(&dev->vbl_lock);
-               TAILQ_INSERT_HEAD(&dev->vbl_sig_list, vbl_sig, link);
-               DRM_SPINUNLOCK(&dev->vbl_lock);
-               ret = 0;
-#endif
-               ret = EINVAL;
-       } else {
-               ret = DRM(vblank_wait)(dev, &vblwait.request.sequence);
-               
-               microtime(&now);
-               vblwait.reply.tval_sec = now.tv_sec;
-               vblwait.reply.tval_usec = now.tv_usec;
-       }
-
-       DRM_COPY_TO_USER_IOCTL( (drm_wait_vblank_t *)data, vblwait,
-                               sizeof(vblwait) );
-
-       return ret;
-}
-
-void DRM(vbl_send_signals)(drm_device_t *dev)
-{
-}
-
-#if 0 /* disabled */
-void DRM(vbl_send_signals)( drm_device_t *dev )
-{
-       drm_vbl_sig_t *vbl_sig;
-       unsigned int vbl_seq = atomic_read( &dev->vbl_received );
-       struct proc *p;
-
-       DRM_SPINLOCK(&dev->vbl_lock);
-
-       vbl_sig = TAILQ_FIRST(&dev->vbl_sig_list);
-       while (vbl_sig != NULL) {
-               drm_vbl_sig_t *next = TAILQ_NEXT(vbl_sig, link);
-
-               if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
-                       p = pfind(vbl_sig->pid);
-                       if (p != NULL)
-                               psignal(p, vbl_sig->signo);
-
-                       TAILQ_REMOVE(&dev->vbl_sig_list, vbl_sig, link);
-                       DRM_FREE(vbl_sig,sizeof(*vbl_sig));
-               }
-               vbl_sig = next;
-       }
-
-       DRM_SPINUNLOCK(&dev->vbl_lock);
-}
-#endif
-
-#endif /*  __HAVE_VBL_IRQ */
-
-#else
-
+#if !__HAVE_IRQ
+/* This stub DRM_IOCTL_CONTROL handler is for the drivers that used to require
+ * IRQs for DMA but no longer do.  It maintains compatibility with the X Servers
+ * that try to use the control ioctl by simply returning success.
+ */
 int DRM(control)( DRM_IOCTL_ARGS )
 {
        drm_control_t ctl;
@@ -381,8 +168,6 @@ int DRM(control)( DRM_IOCTL_ARGS )
                return DRM_ERR(EINVAL);
        }
 }
-
-#endif /* __HAVE_DMA_IRQ */
+#endif
 
 #endif /* __HAVE_DMA */
-
index bfded6b..8a9e303 100644 (file)
@@ -55,8 +55,8 @@
 #ifndef __HAVE_CTX_BITMAP
 #define __HAVE_CTX_BITMAP              0
 #endif
-#ifndef __HAVE_DMA_IRQ
-#define __HAVE_DMA_IRQ                 0
+#ifndef __HAVE_IRQ
+#define __HAVE_IRQ                     0
 #endif
 #ifndef __HAVE_DMA_QUEUE
 #define __HAVE_DMA_QUEUE               0
@@ -170,9 +170,9 @@ static drm_ioctl_desc_t               DRM(ioctls)[] = {
        [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)]     = { DRM(infobufs),    1, 0 },
        [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)]      = { DRM(mapbufs),     1, 0 },
        [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)]     = { DRM(freebufs),    1, 0 },
-
-       /* The DRM_IOCTL_DMA ioctl should be defined by the driver.
-        */
+       /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
+#endif
+#if __HAVE_IRQ || __HAVE_DMA
        [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)]       = { DRM(control),     1, 1 },
 #endif
 
@@ -510,7 +510,7 @@ static int DRM(takedown)( drm_device_t *dev )
        DRM_DEBUG( "\n" );
 
        DRIVER_PRETAKEDOWN();
-#if __HAVE_DMA_IRQ
+#if __HAVE_IRQ
        if (dev->irq != 0)
                DRM(irq_uninstall)( dev );
 #endif
diff --git a/bsd/drm_irq.h b/bsd/drm_irq.h
new file mode 100644 (file)
index 0000000..3366ff1
--- /dev/null
@@ -0,0 +1,242 @@
+/* drm_dma.c -- DMA IOCTL and function support
+ * Created: Fri Oct 18 2003 by anholt@FreeBSD.org
+ *
+ * Copyright 2003 Eric Anholt
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Eric Anholt <anholt@FreeBSD.org>
+ *
+ */
+int DRM(irq_install)( drm_device_t *dev, int irq )
+{
+       int retcode;
+
+       if ( irq == 0 || dev->dev_private == NULL)
+               return DRM_ERR(EINVAL);
+
+       DRM_LOCK();
+       if ( dev->irq ) {
+               DRM_UNLOCK();
+               return DRM_ERR(EBUSY);
+       }
+       dev->irq = irq;
+       DRM_UNLOCK();
+
+       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+
+       dev->context_flag = 0;
+
+       dev->dma->next_buffer = NULL;
+       dev->dma->this_buffer = NULL;
+
+#if __HAVE_IRQ_BH
+       TASK_INIT(&dev->task, 0, DRM(dma_immediate_bh), dev);
+#endif
+
+#if __HAVE_VBL_IRQ && 0 /* disabled */
+       DRM_SPININIT( dev->vbl_lock, "vblsig" );
+       TAILQ_INIT( &dev->vbl_sig_list );
+#endif
+
+                               /* Before installing handler */
+       DRM(driver_irq_preinstall)( dev );
+
+                               /* Install handler */
+       dev->irqrid = 0;
+#ifdef __FreeBSD__
+       dev->irqr = bus_alloc_resource(dev->device, SYS_RES_IRQ, &dev->irqrid,
+                                     0, ~0, 1, RF_SHAREABLE);
+       if (!dev->irqr) {
+#elif defined(__NetBSD__)
+       if (pci_intr_map(&dev->pa, &dev->ih) != 0) {
+#endif
+               DRM_LOCK();
+               dev->irq = 0;
+               dev->irqrid = 0;
+               DRM_UNLOCK();
+               return ENOENT;
+       }
+       
+#ifdef __FreeBSD__
+#if __FreeBSD_version < 500000
+       retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY,
+                                DRM(irq_handler), dev, &dev->irqh);
+#else
+       retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY | INTR_MPSAFE,
+                                DRM(irq_handler), dev, &dev->irqh);
+#endif
+       if ( retcode ) {
+#elif defined(__NetBSD__)
+       dev->irqh = pci_intr_establish(&dev->pa.pa_pc, dev->ih, IPL_TTY,
+           (irqreturn_t (*)(DRM_IRQ_ARGS))DRM(irq_handler), dev);
+       if ( !dev->irqh ) {
+#endif
+               DRM_LOCK();
+#ifdef __FreeBSD__
+               bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid, dev->irqr);
+#endif
+               dev->irq = 0;
+               dev->irqrid = 0;
+               DRM_UNLOCK();
+               return retcode;
+       }
+
+                               /* After installing handler */
+       DRM(driver_irq_postinstall)( dev );
+
+       return 0;
+}
+
+int DRM(irq_uninstall)( drm_device_t *dev )
+{
+       int irq;
+       int irqrid;
+       
+       DRM_LOCK();
+       irq = dev->irq;
+       irqrid = dev->irqrid;
+       dev->irq = 0;
+       dev->irqrid = 0;
+       DRM_UNLOCK();
+
+       if ( !irq )
+               return DRM_ERR(EINVAL);
+
+       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+
+       DRM(driver_irq_uninstall)( dev );
+
+#ifdef __FreeBSD__
+       bus_teardown_intr(dev->device, dev->irqr, dev->irqh);
+       bus_release_resource(dev->device, SYS_RES_IRQ, irqrid, dev->irqr);
+#elif defined(__NetBSD__)
+       pci_intr_disestablish(&dev->pa.pa_pc, dev->irqh);
+#endif
+
+       return 0;
+}
+
+int DRM(control)( DRM_IOCTL_ARGS )
+{
+       DRM_DEVICE;
+       drm_control_t ctl;
+
+       DRM_COPY_FROM_USER_IOCTL( ctl, (drm_control_t *) data, sizeof(ctl) );
+
+       switch ( ctl.func ) {
+       case DRM_INST_HANDLER:
+               return DRM(irq_install)( dev, ctl.irq );
+       case DRM_UNINST_HANDLER:
+               return DRM(irq_uninstall)( dev );
+       default:
+               return DRM_ERR(EINVAL);
+       }
+}
+
+#if __HAVE_VBL_IRQ
+int DRM(wait_vblank)( DRM_IOCTL_ARGS )
+{
+       DRM_DEVICE;
+       drm_wait_vblank_t vblwait;
+       struct timeval now;
+       int ret;
+
+       if (!dev->irq)
+               return DRM_ERR(EINVAL);
+
+       DRM_COPY_FROM_USER_IOCTL( vblwait, (drm_wait_vblank_t *)data,
+                                 sizeof(vblwait) );
+
+       if (vblwait.request.type & _DRM_VBLANK_RELATIVE) {
+               vblwait.request.sequence += atomic_read(&dev->vbl_received);
+               vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
+       }
+
+       flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
+       if (flags & _DRM_VBLANK_SIGNAL) {
+#if 0 /* disabled */
+               drm_vbl_sig_t *vbl_sig = DRM_MALLOC(sizeof(drm_vbl_sig_t));
+               if (vbl_sig == NULL)
+                       return ENOMEM;
+               bzero(vbl_sig, sizeof(*vbl_sig));
+               
+               vbl_sig->sequence = vblwait.request.sequence;
+               vbl_sig->signo = vblwait.request.signal;
+               vbl_sig->pid = DRM_CURRENTPID;
+
+               vblwait.reply.sequence = atomic_read(&dev->vbl_received);
+               
+               DRM_SPINLOCK(&dev->vbl_lock);
+               TAILQ_INSERT_HEAD(&dev->vbl_sig_list, vbl_sig, link);
+               DRM_SPINUNLOCK(&dev->vbl_lock);
+               ret = 0;
+#endif
+               ret = EINVAL;
+       } else {
+               ret = DRM(vblank_wait)(dev, &vblwait.request.sequence);
+               
+               microtime(&now);
+               vblwait.reply.tval_sec = now.tv_sec;
+               vblwait.reply.tval_usec = now.tv_usec;
+       }
+
+       DRM_COPY_TO_USER_IOCTL( (drm_wait_vblank_t *)data, vblwait,
+                               sizeof(vblwait) );
+
+       return ret;
+}
+
+void DRM(vbl_send_signals)(drm_device_t *dev)
+{
+}
+
+#if 0 /* disabled */
+void DRM(vbl_send_signals)( drm_device_t *dev )
+{
+       drm_vbl_sig_t *vbl_sig;
+       unsigned int vbl_seq = atomic_read( &dev->vbl_received );
+       struct proc *p;
+
+       DRM_SPINLOCK(&dev->vbl_lock);
+
+       vbl_sig = TAILQ_FIRST(&dev->vbl_sig_list);
+       while (vbl_sig != NULL) {
+               drm_vbl_sig_t *next = TAILQ_NEXT(vbl_sig, link);
+
+               if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
+                       p = pfind(vbl_sig->pid);
+                       if (p != NULL)
+                               psignal(p, vbl_sig->signo);
+
+                       TAILQ_REMOVE(&dev->vbl_sig_list, vbl_sig, link);
+                       DRM_FREE(vbl_sig,sizeof(*vbl_sig));
+               }
+               vbl_sig = next;
+       }
+
+       DRM_SPINUNLOCK(&dev->vbl_lock);
+}
+#endif
+
+#endif /*  __HAVE_VBL_IRQ */
index 4eaf5ed..477086e 100644 (file)
@@ -45,6 +45,7 @@
 #include "drm_drv.h"
 #include "drm_fops.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_vm.h"
index e656f60..a9af369 100644 (file)
@@ -48,6 +48,7 @@
 #include "drm_drv.h"
 #include "drm_fops.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_pci.h"
index 3b69976..df941f9 100644 (file)
@@ -46,6 +46,7 @@
 #include "drm_drv.h"
 #include "drm_fops.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_pci.h"
index 2d02589..4bef88f 100644 (file)
@@ -852,7 +852,7 @@ PREDEFINED             = \
                        __HAVE_SG=0 \
                        __HAVE_PCI_DMA=0 \
                        __HAVE_DMA=1 \
-                       __HAVE_DMA_IRQ=1 \
+                       __HAVE_IRQ=1 \
                        __HAVE_VBL_IRQ=1 \
                        __HAVE_SHARED_IRQ=1
 
index f7137b2..ae499ca 100644 (file)
 #ifndef __HAVE_DMA
 #define __HAVE_DMA             0
 #endif
-#ifndef __HAVE_DMA_IRQ
-#define __HAVE_DMA_IRQ         0
+#ifndef __HAVE_IRQ
+#define __HAVE_IRQ             0
 #endif
 #ifndef __HAVE_DMA_WAITLIST
 #define __HAVE_DMA_WAITLIST    0
@@ -937,12 +937,17 @@ extern int             DRM(dma_setup)(drm_device_t *dev);
 extern void         DRM(dma_takedown)(drm_device_t *dev);
 extern void         DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
 extern void         DRM(reclaim_buffers)( struct file *filp );
-#if __HAVE_DMA_IRQ
+#endif /* __HAVE_DMA */
+
+                               /* IRQ support (drm_irq.h) */
+#if __HAVE_IRQ || __HAVE_DMA
 extern int           DRM(control)( struct inode *inode, struct file *filp,
                                   unsigned int cmd, unsigned long arg );
+#endif
+#if __HAVE_IRQ
 extern int           DRM(irq_install)( drm_device_t *dev, int irq );
 extern int           DRM(irq_uninstall)( drm_device_t *dev );
-extern irqreturn_t   DRM(dma_service)( DRM_IRQ_ARGS );
+extern irqreturn_t   DRM(irq_handler)( DRM_IRQ_ARGS );
 extern void          DRM(driver_irq_preinstall)( drm_device_t *dev );
 extern void          DRM(driver_irq_postinstall)( drm_device_t *dev );
 extern void          DRM(driver_irq_uninstall)( drm_device_t *dev );
@@ -952,12 +957,11 @@ extern int           DRM(wait_vblank)(struct inode *inode, struct file *filp,
 extern int           DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq);
 extern void          DRM(vbl_send_signals)( drm_device_t *dev );
 #endif
-#if __HAVE_DMA_IRQ_BH
-extern void          DRM(dma_immediate_bh)( void *dev );
+#if __HAVE_IRQ_BH
+extern void          DRM(irq_immediate_bh)( void *dev );
 #endif
 #endif
 
-#endif /* __HAVE_DMA */
 
 #if __REALLY_HAVE_AGP
                                /* AGP/GART support (drm_agpsupport.h) */
index aef84d4..f36cd1c 100644 (file)
@@ -36,7 +36,6 @@
 #define __NO_VERSION__
 #include "drmP.h"
 
-#include <linux/interrupt.h>   /* For task queue support */
 
 #ifndef __HAVE_DMA_WAITQUEUE
 #define __HAVE_DMA_WAITQUEUE   0
 #ifndef __HAVE_DMA_RECLAIM
 #define __HAVE_DMA_RECLAIM     0
 #endif
-#ifndef __HAVE_SHARED_IRQ
-#define __HAVE_SHARED_IRQ      0
-#endif
-
-#if __HAVE_SHARED_IRQ
-#define DRM_IRQ_TYPE           SA_SHIRQ
-#else
-#define DRM_IRQ_TYPE           0
-#endif
 
 #if __HAVE_DMA
 
@@ -215,303 +205,14 @@ void DRM(reclaim_buffers)( struct file *filp )
 }
 #endif
 
-
-
-
-#if __HAVE_DMA_IRQ
-
-/**
- * Install IRQ handler.
- *
- * \param dev DRM device.
- * \param irq IRQ number.
- *
- * Initializes the IRQ related data, and setups drm_device::vbl_queue. Installs the handler, calling the driver
- * \c DRM(driver_irq_preinstall)() and \c DRM(driver_irq_postinstall)() functions
- * before and after the installation.
- */
-int DRM(irq_install)( drm_device_t *dev, int irq )
-{
-       int ret;
-
-       if ( !irq )
-               return -EINVAL;
-
-       down( &dev->struct_sem );
-
-       /* Driver must have been initialized */
-       if ( !dev->dev_private ) {
-               up( &dev->struct_sem );
-               return -EINVAL;
-       }
-
-       if ( dev->irq ) {
-               up( &dev->struct_sem );
-               return -EBUSY;
-       }
-       dev->irq = irq;
-       up( &dev->struct_sem );
-
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
-       dev->context_flag = 0;
-       dev->interrupt_flag = 0;
-       dev->dma_flag = 0;
-
-       dev->dma->next_buffer = NULL;
-       dev->dma->next_queue = NULL;
-       dev->dma->this_buffer = NULL;
-
-#if __HAVE_DMA_IRQ_BH
-#if !HAS_WORKQUEUE
-       INIT_LIST_HEAD( &dev->tq.list );
-       dev->tq.sync = 0;
-       dev->tq.routine = DRM(dma_immediate_bh);
-       dev->tq.data = dev;
-#else
-       INIT_WORK(&dev->work, DRM(dma_immediate_bh), dev);
-#endif
-#endif
-
-#if __HAVE_VBL_IRQ
-       init_waitqueue_head(&dev->vbl_queue);
-
-       spin_lock_init( &dev->vbl_lock );
-
-       INIT_LIST_HEAD( &dev->vbl_sigs.head );
-
-       dev->vbl_pending = 0;
-#endif
-
-                               /* Before installing handler */
-       DRM(driver_irq_preinstall)(dev);
-
-                               /* Install handler */
-       ret = request_irq( dev->irq, DRM(dma_service),
-                          DRM_IRQ_TYPE, dev->devname, dev );
-       if ( ret < 0 ) {
-               down( &dev->struct_sem );
-               dev->irq = 0;
-               up( &dev->struct_sem );
-               return ret;
-       }
-
-                               /* After installing handler */
-       DRM(driver_irq_postinstall)(dev);
-
-       return 0;
-}
-
-/**
- * Uninstall the IRQ handler.
- *
- * \param dev DRM device.
- *
- * Calls the driver's \c DRM(driver_irq_uninstall)() function, and stops the irq.
- */
-int DRM(irq_uninstall)( drm_device_t *dev )
-{
-       int irq;
-
-       down( &dev->struct_sem );
-       irq = dev->irq;
-       dev->irq = 0;
-       up( &dev->struct_sem );
-
-       if ( !irq )
-               return -EINVAL;
-
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
-       DRM(driver_irq_uninstall)( dev );
-
-       free_irq( irq, dev );
-
-       return 0;
-}
-
-/**
- * IRQ control ioctl.
- *
- * \param inode device inode.
- * \param filp file pointer.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_control structure.
- * \return zero on success or a negative number on failure.
- *
- * Calls irq_install() or irq_uninstall() according to \p arg.
+#if !__HAVE_IRQ
+/* This stub DRM_IOCTL_CONTROL handler is for the drivers that used to require
+ * IRQs for DMA but no longer do.  It maintains compatibility with the X Servers
+ * that try to use the control ioctl by simply returning success.
  */
 int DRM(control)( struct inode *inode, struct file *filp,
                  unsigned int cmd, unsigned long arg )
 {
-       drm_file_t *priv = filp->private_data;
-       drm_device_t *dev = priv->dev;
-       drm_control_t ctl;
-
-       if ( copy_from_user( &ctl, (drm_control_t *)arg, sizeof(ctl) ) )
-               return -EFAULT;
-
-       switch ( ctl.func ) {
-       case DRM_INST_HANDLER:
-               return DRM(irq_install)( dev, ctl.irq );
-       case DRM_UNINST_HANDLER:
-               return DRM(irq_uninstall)( dev );
-       default:
-               return -EINVAL;
-       }
-}
-
-#if __HAVE_VBL_IRQ
-
-/**
- * Wait for VBLANK.
- *
- * \param inode device inode.
- * \param filp file pointer.
- * \param cmd command.
- * \param data user argument, pointing to a drm_wait_vblank structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the IRQ is installed. 
- *
- * If a signal is requested checks if this task has already scheduled the same signal
- * for the same vblank sequence number - nothing to be done in
- * that case. If the number of tasks waiting for the interrupt exceeds 100 the
- * function fails. Otherwise adds a new entry to drm_device::vbl_sigs for this
- * task.
- *
- * If a signal is not requested, then calls vblank_wait().
- */
-int DRM(wait_vblank)( DRM_IOCTL_ARGS )
-{
-       drm_file_t *priv = filp->private_data;
-       drm_device_t *dev = priv->dev;
-       drm_wait_vblank_t vblwait;
-       struct timeval now;
-       int ret = 0;
-       unsigned int flags;
-
-       if (!dev->irq)
-               return -EINVAL;
-
-       DRM_COPY_FROM_USER_IOCTL( vblwait, (drm_wait_vblank_t *)data,
-                                 sizeof(vblwait) );
-
-       switch ( vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK ) {
-       case _DRM_VBLANK_RELATIVE:
-               vblwait.request.sequence += atomic_read( &dev->vbl_received );
-               vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
-       case _DRM_VBLANK_ABSOLUTE:
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
-       
-       if ( flags & _DRM_VBLANK_SIGNAL ) {
-               unsigned long irqflags;
-               drm_vbl_sig_t *vbl_sig;
-               
-               vblwait.reply.sequence = atomic_read( &dev->vbl_received );
-
-               spin_lock_irqsave( &dev->vbl_lock, irqflags );
-
-               /* Check if this task has already scheduled the same signal
-                * for the same vblank sequence number; nothing to be done in
-                * that case
-                */
-               list_for_each_entry( vbl_sig, &dev->vbl_sigs.head, head ) {
-                       if (vbl_sig->sequence == vblwait.request.sequence
-                           && vbl_sig->info.si_signo == vblwait.request.signal
-                           && vbl_sig->task == current)
-                       {
-                               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
-                               goto done;
-                       }
-               }
-
-               if ( dev->vbl_pending >= 100 ) {
-                       spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
-                       return -EBUSY;
-               }
-
-               dev->vbl_pending++;
-
-               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
-
-               if ( !( vbl_sig = DRM_MALLOC( sizeof( drm_vbl_sig_t ) ) ) ) {
-                       return -ENOMEM;
-               }
-
-               memset( (void *)vbl_sig, 0, sizeof(*vbl_sig) );
-
-               vbl_sig->sequence = vblwait.request.sequence;
-               vbl_sig->info.si_signo = vblwait.request.signal;
-               vbl_sig->task = current;
-
-               spin_lock_irqsave( &dev->vbl_lock, irqflags );
-
-               list_add_tail( (struct list_head *) vbl_sig, &dev->vbl_sigs.head );
-
-               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
-       } else {
-               ret = DRM(vblank_wait)( dev, &vblwait.request.sequence );
-
-               do_gettimeofday( &now );
-               vblwait.reply.tval_sec = now.tv_sec;
-               vblwait.reply.tval_usec = now.tv_usec;
-       }
-
-done:
-       DRM_COPY_TO_USER_IOCTL( (drm_wait_vblank_t *)data, vblwait,
-                               sizeof(vblwait) );
-
-       return ret;
-}
-
-/**
- * Send the VBLANK signals.
- *
- * \param dev DRM device.
- *
- * Sends a signal for each task in drm_device::vbl_sigs and empties the list.
- *
- * If a signal is not requested, then calls vblank_wait().
- */
-void DRM(vbl_send_signals)( drm_device_t *dev )
-{
-       struct list_head *list, *tmp;
-       drm_vbl_sig_t *vbl_sig;
-       unsigned int vbl_seq = atomic_read( &dev->vbl_received );
-       unsigned long flags;
-
-       spin_lock_irqsave( &dev->vbl_lock, flags );
-
-       list_for_each_safe( list, tmp, &dev->vbl_sigs.head ) {
-               vbl_sig = list_entry( list, drm_vbl_sig_t, head );
-               if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
-                       vbl_sig->info.si_code = vbl_seq;
-                       send_sig_info( vbl_sig->info.si_signo, &vbl_sig->info, vbl_sig->task );
-
-                       list_del( list );
-
-                       DRM_FREE( vbl_sig, sizeof(*vbl_sig) );
-
-                       dev->vbl_pending--;
-               }
-       }
-
-       spin_unlock_irqrestore( &dev->vbl_lock, flags );
-}
-
-#endif /* __HAVE_VBL_IRQ */
-
-#else
-
-int DRM(control)( struct inode *inode, struct file *filp,
-                 unsigned int cmd, unsigned long arg )
-{
        drm_control_t ctl;
 
        if ( copy_from_user( &ctl, (drm_control_t *)arg, sizeof(ctl) ) )
@@ -525,7 +226,6 @@ int DRM(control)( struct inode *inode, struct file *filp,
                return -EINVAL;
        }
 }
-
-#endif /* __HAVE_DMA_IRQ */
+#endif
 
 #endif /* __HAVE_DMA */
index 801118e..d1bad56 100644 (file)
@@ -58,8 +58,8 @@
 #ifndef __HAVE_CTX_BITMAP
 #define __HAVE_CTX_BITMAP              0
 #endif
-#ifndef __HAVE_DMA_IRQ
-#define __HAVE_DMA_IRQ                 0
+#ifndef __HAVE_IRQ
+#define __HAVE_IRQ                     0
 #endif
 #ifndef __HAVE_DMA_QUEUE
 #define __HAVE_DMA_QUEUE               0
@@ -215,9 +215,9 @@ static drm_ioctl_desc_t               DRM(ioctls)[] = {
        [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)]     = { DRM(infobufs),    1, 0 },
        [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)]      = { DRM(mapbufs),     1, 0 },
        [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)]     = { DRM(freebufs),    1, 0 },
-
-       /* The DRM_IOCTL_DMA ioctl should be defined by the driver.
-        */
+       /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
+#endif
+#if __HAVE_IRQ || __HAVE_DMA
        [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)]       = { DRM(control),     1, 1 },
 #endif
 
@@ -384,7 +384,7 @@ static int DRM(takedown)( drm_device_t *dev )
        DRM_DEBUG( "\n" );
 
        DRIVER_PRETAKEDOWN();
-#if __HAVE_DMA_IRQ
+#if __HAVE_IRQ
        if ( dev->irq ) DRM(irq_uninstall)( dev );
 #endif
 
diff --git a/linux-core/drm_irq.c b/linux-core/drm_irq.c
new file mode 100644 (file)
index 0000000..322e571
--- /dev/null
@@ -0,0 +1,340 @@
+/**
+ * \file drm_irq.h 
+ * IRQ support
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
+ *
+ * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#define __NO_VERSION__
+#include "drmP.h"
+
+#include <linux/interrupt.h>   /* For task queue support */
+
+#ifndef __HAVE_SHARED_IRQ
+#define __HAVE_SHARED_IRQ      0
+#endif
+
+#if __HAVE_SHARED_IRQ
+#define DRM_IRQ_TYPE           SA_SHIRQ
+#else
+#define DRM_IRQ_TYPE           0
+#endif
+
+#if __HAVE_IRQ
+
+/**
+ * Install IRQ handler.
+ *
+ * \param dev DRM device.
+ * \param irq IRQ number.
+ *
+ * Initializes the IRQ related data, and setups drm_device::vbl_queue. Installs the handler, calling the driver
+ * \c DRM(driver_irq_preinstall)() and \c DRM(driver_irq_postinstall)() functions
+ * before and after the installation.
+ */
+int DRM(irq_install)( drm_device_t *dev, int irq )
+{
+       int ret;
+
+       if ( !irq )
+               return -EINVAL;
+
+       down( &dev->struct_sem );
+
+       /* Driver must have been initialized */
+       if ( !dev->dev_private ) {
+               up( &dev->struct_sem );
+               return -EINVAL;
+       }
+
+       if ( dev->irq ) {
+               up( &dev->struct_sem );
+               return -EBUSY;
+       }
+       dev->irq = irq;
+       up( &dev->struct_sem );
+
+       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+
+       dev->context_flag = 0;
+       dev->interrupt_flag = 0;
+       dev->dma_flag = 0;
+
+       dev->dma->next_buffer = NULL;
+       dev->dma->next_queue = NULL;
+       dev->dma->this_buffer = NULL;
+
+#if __HAVE_IRQ_BH
+#if !HAS_WORKQUEUE
+       INIT_LIST_HEAD( &dev->tq.list );
+       dev->tq.sync = 0;
+       dev->tq.routine = DRM(irq_immediate_bh);
+       dev->tq.data = dev;
+#else
+       INIT_WORK(&dev->work, DRM(irq_immediate_bh), dev);
+#endif
+#endif
+
+#if __HAVE_VBL_IRQ
+       init_waitqueue_head(&dev->vbl_queue);
+
+       spin_lock_init( &dev->vbl_lock );
+
+       INIT_LIST_HEAD( &dev->vbl_sigs.head );
+
+       dev->vbl_pending = 0;
+#endif
+
+                               /* Before installing handler */
+       DRM(driver_irq_preinstall)(dev);
+
+                               /* Install handler */
+       ret = request_irq( dev->irq, DRM(irq_handler),
+                          DRM_IRQ_TYPE, dev->devname, dev );
+       if ( ret < 0 ) {
+               down( &dev->struct_sem );
+               dev->irq = 0;
+               up( &dev->struct_sem );
+               return ret;
+       }
+
+                               /* After installing handler */
+       DRM(driver_irq_postinstall)(dev);
+
+       return 0;
+}
+
+/**
+ * Uninstall the IRQ handler.
+ *
+ * \param dev DRM device.
+ *
+ * Calls the driver's \c DRM(driver_irq_uninstall)() function, and stops the irq.
+ */
+int DRM(irq_uninstall)( drm_device_t *dev )
+{
+       int irq;
+
+       down( &dev->struct_sem );
+       irq = dev->irq;
+       dev->irq = 0;
+       up( &dev->struct_sem );
+
+       if ( !irq )
+               return -EINVAL;
+
+       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+
+       DRM(driver_irq_uninstall)( dev );
+
+       free_irq( irq, dev );
+
+       return 0;
+}
+
+/**
+ * IRQ control ioctl.
+ *
+ * \param inode device inode.
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_control structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Calls irq_install() or irq_uninstall() according to \p arg.
+ */
+int DRM(control)( struct inode *inode, struct file *filp,
+                 unsigned int cmd, unsigned long arg )
+{
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->dev;
+       drm_control_t ctl;
+
+       if ( copy_from_user( &ctl, (drm_control_t *)arg, sizeof(ctl) ) )
+               return -EFAULT;
+
+       switch ( ctl.func ) {
+       case DRM_INST_HANDLER:
+               return DRM(irq_install)( dev, ctl.irq );
+       case DRM_UNINST_HANDLER:
+               return DRM(irq_uninstall)( dev );
+       default:
+               return -EINVAL;
+       }
+}
+
+#if __HAVE_VBL_IRQ
+
+/**
+ * Wait for VBLANK.
+ *
+ * \param inode device inode.
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param data user argument, pointing to a drm_wait_vblank structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the IRQ is installed. 
+ *
+ * If a signal is requested checks if this task has already scheduled the same signal
+ * for the same vblank sequence number - nothing to be done in
+ * that case. If the number of tasks waiting for the interrupt exceeds 100 the
+ * function fails. Otherwise adds a new entry to drm_device::vbl_sigs for this
+ * task.
+ *
+ * If a signal is not requested, then calls vblank_wait().
+ */
+int DRM(wait_vblank)( DRM_IOCTL_ARGS )
+{
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->dev;
+       drm_wait_vblank_t vblwait;
+       struct timeval now;
+       int ret = 0;
+       unsigned int flags;
+
+       if (!dev->irq)
+               return -EINVAL;
+
+       DRM_COPY_FROM_USER_IOCTL( vblwait, (drm_wait_vblank_t *)data,
+                                 sizeof(vblwait) );
+
+       switch ( vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK ) {
+       case _DRM_VBLANK_RELATIVE:
+               vblwait.request.sequence += atomic_read( &dev->vbl_received );
+               vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
+       case _DRM_VBLANK_ABSOLUTE:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
+       
+       if ( flags & _DRM_VBLANK_SIGNAL ) {
+               unsigned long irqflags;
+               drm_vbl_sig_t *vbl_sig;
+               
+               vblwait.reply.sequence = atomic_read( &dev->vbl_received );
+
+               spin_lock_irqsave( &dev->vbl_lock, irqflags );
+
+               /* Check if this task has already scheduled the same signal
+                * for the same vblank sequence number; nothing to be done in
+                * that case
+                */
+               list_for_each_entry( vbl_sig, &dev->vbl_sigs.head, head ) {
+                       if (vbl_sig->sequence == vblwait.request.sequence
+                           && vbl_sig->info.si_signo == vblwait.request.signal
+                           && vbl_sig->task == current)
+                       {
+                               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+                               goto done;
+                       }
+               }
+
+               if ( dev->vbl_pending >= 100 ) {
+                       spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+                       return -EBUSY;
+               }
+
+               dev->vbl_pending++;
+
+               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+
+               if ( !( vbl_sig = DRM_MALLOC( sizeof( drm_vbl_sig_t ) ) ) ) {
+                       return -ENOMEM;
+               }
+
+               memset( (void *)vbl_sig, 0, sizeof(*vbl_sig) );
+
+               vbl_sig->sequence = vblwait.request.sequence;
+               vbl_sig->info.si_signo = vblwait.request.signal;
+               vbl_sig->task = current;
+
+               spin_lock_irqsave( &dev->vbl_lock, irqflags );
+
+               list_add_tail( (struct list_head *) vbl_sig, &dev->vbl_sigs.head );
+
+               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+       } else {
+               ret = DRM(vblank_wait)( dev, &vblwait.request.sequence );
+
+               do_gettimeofday( &now );
+               vblwait.reply.tval_sec = now.tv_sec;
+               vblwait.reply.tval_usec = now.tv_usec;
+       }
+
+done:
+       DRM_COPY_TO_USER_IOCTL( (drm_wait_vblank_t *)data, vblwait,
+                               sizeof(vblwait) );
+
+       return ret;
+}
+
+/**
+ * Send the VBLANK signals.
+ *
+ * \param dev DRM device.
+ *
+ * Sends a signal for each task in drm_device::vbl_sigs and empties the list.
+ *
+ * If a signal is not requested, then calls vblank_wait().
+ */
+void DRM(vbl_send_signals)( drm_device_t *dev )
+{
+       struct list_head *list, *tmp;
+       drm_vbl_sig_t *vbl_sig;
+       unsigned int vbl_seq = atomic_read( &dev->vbl_received );
+       unsigned long flags;
+
+       spin_lock_irqsave( &dev->vbl_lock, flags );
+
+       list_for_each_safe( list, tmp, &dev->vbl_sigs.head ) {
+               vbl_sig = list_entry( list, drm_vbl_sig_t, head );
+               if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
+                       vbl_sig->info.si_code = vbl_seq;
+                       send_sig_info( vbl_sig->info.si_signo, &vbl_sig->info, vbl_sig->task );
+
+                       list_del( list );
+
+                       DRM_FREE( vbl_sig, sizeof(*vbl_sig) );
+
+                       dev->vbl_pending--;
+               }
+       }
+
+       spin_unlock_irqrestore( &dev->vbl_lock, flags );
+}
+
+#endif /* __HAVE_VBL_IRQ */
+
+#endif /* __HAVE_IRQ */
index 430ee52..1eeb4a3 100644 (file)
@@ -239,7 +239,7 @@ int i810_dma_cleanup(drm_device_t *dev)
 {
        drm_device_dma_t *dma = dev->dma;
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index 48b64d7..422f3ad 100644 (file)
@@ -238,7 +238,7 @@ int i830_dma_cleanup(drm_device_t *dev)
 {
        drm_device_dma_t *dma = dev->dma;
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index 0735c94..2f4e815 100644 (file)
@@ -50,6 +50,7 @@
 #include "drm_fops.h"
 #include "drm_init.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_proc.h"
index d2aabf3..6d45cda 100644 (file)
@@ -36,7 +36,7 @@
 #include <linux/delay.h>
 
 
-irqreturn_t DRM(dma_service)( DRM_IRQ_ARGS )
+irqreturn_t DRM(irq_handler)( DRM_IRQ_ARGS )
 {
        drm_device_t     *dev = (drm_device_t *)arg;
        drm_i830_private_t *dev_priv = (drm_i830_private_t *)dev->dev_private;
index f0d4935..6bcad04 100644 (file)
@@ -45,6 +45,7 @@
 #include "drm_fops.h"
 #include "drm_init.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_proc.h"
index e2e4269..1dee161 100644 (file)
@@ -47,6 +47,7 @@
 #include "drm_fops.h"
 #include "drm_init.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_proc.h"
index 6152b8a..74e32df 100644 (file)
@@ -48,6 +48,7 @@
 #include "drm_fops.h"
 #include "drm_init.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_proc.h"
index 2d02589..4bef88f 100644 (file)
@@ -852,7 +852,7 @@ PREDEFINED             = \
                        __HAVE_SG=0 \
                        __HAVE_PCI_DMA=0 \
                        __HAVE_DMA=1 \
-                       __HAVE_DMA_IRQ=1 \
+                       __HAVE_IRQ=1 \
                        __HAVE_VBL_IRQ=1 \
                        __HAVE_SHARED_IRQ=1
 
index e873242..babf41a 100644 (file)
@@ -59,7 +59,7 @@ DRM_MODULES ?= $(MODULE_LIST)
 # These definitions are for handling dependencies in the out of kernel build.
 
 DRMTEMPLATES =  drm_auth.h drm_bufs.h drm_context.h drm_dma.h drm_drawable.h \
-                drm_drv.h drm_fops.h drm_init.h drm_ioctl.h \
+                drm_drv.h drm_fops.h drm_init.h drm_ioctl.h drm_irq.h \
                 drm_lock.h drm_memory.h drm_proc.h drm_stub.h drm_vm.h
 
 DRMSHARED =     drm_sarea.h
index f7137b2..ae499ca 100644 (file)
 #ifndef __HAVE_DMA
 #define __HAVE_DMA             0
 #endif
-#ifndef __HAVE_DMA_IRQ
-#define __HAVE_DMA_IRQ         0
+#ifndef __HAVE_IRQ
+#define __HAVE_IRQ             0
 #endif
 #ifndef __HAVE_DMA_WAITLIST
 #define __HAVE_DMA_WAITLIST    0
@@ -937,12 +937,17 @@ extern int             DRM(dma_setup)(drm_device_t *dev);
 extern void         DRM(dma_takedown)(drm_device_t *dev);
 extern void         DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
 extern void         DRM(reclaim_buffers)( struct file *filp );
-#if __HAVE_DMA_IRQ
+#endif /* __HAVE_DMA */
+
+                               /* IRQ support (drm_irq.h) */
+#if __HAVE_IRQ || __HAVE_DMA
 extern int           DRM(control)( struct inode *inode, struct file *filp,
                                   unsigned int cmd, unsigned long arg );
+#endif
+#if __HAVE_IRQ
 extern int           DRM(irq_install)( drm_device_t *dev, int irq );
 extern int           DRM(irq_uninstall)( drm_device_t *dev );
-extern irqreturn_t   DRM(dma_service)( DRM_IRQ_ARGS );
+extern irqreturn_t   DRM(irq_handler)( DRM_IRQ_ARGS );
 extern void          DRM(driver_irq_preinstall)( drm_device_t *dev );
 extern void          DRM(driver_irq_postinstall)( drm_device_t *dev );
 extern void          DRM(driver_irq_uninstall)( drm_device_t *dev );
@@ -952,12 +957,11 @@ extern int           DRM(wait_vblank)(struct inode *inode, struct file *filp,
 extern int           DRM(vblank_wait)(drm_device_t *dev, unsigned int *vbl_seq);
 extern void          DRM(vbl_send_signals)( drm_device_t *dev );
 #endif
-#if __HAVE_DMA_IRQ_BH
-extern void          DRM(dma_immediate_bh)( void *dev );
+#if __HAVE_IRQ_BH
+extern void          DRM(irq_immediate_bh)( void *dev );
 #endif
 #endif
 
-#endif /* __HAVE_DMA */
 
 #if __REALLY_HAVE_AGP
                                /* AGP/GART support (drm_agpsupport.h) */
index aef84d4..f36cd1c 100644 (file)
@@ -36,7 +36,6 @@
 #define __NO_VERSION__
 #include "drmP.h"
 
-#include <linux/interrupt.h>   /* For task queue support */
 
 #ifndef __HAVE_DMA_WAITQUEUE
 #define __HAVE_DMA_WAITQUEUE   0
 #ifndef __HAVE_DMA_RECLAIM
 #define __HAVE_DMA_RECLAIM     0
 #endif
-#ifndef __HAVE_SHARED_IRQ
-#define __HAVE_SHARED_IRQ      0
-#endif
-
-#if __HAVE_SHARED_IRQ
-#define DRM_IRQ_TYPE           SA_SHIRQ
-#else
-#define DRM_IRQ_TYPE           0
-#endif
 
 #if __HAVE_DMA
 
@@ -215,303 +205,14 @@ void DRM(reclaim_buffers)( struct file *filp )
 }
 #endif
 
-
-
-
-#if __HAVE_DMA_IRQ
-
-/**
- * Install IRQ handler.
- *
- * \param dev DRM device.
- * \param irq IRQ number.
- *
- * Initializes the IRQ related data, and setups drm_device::vbl_queue. Installs the handler, calling the driver
- * \c DRM(driver_irq_preinstall)() and \c DRM(driver_irq_postinstall)() functions
- * before and after the installation.
- */
-int DRM(irq_install)( drm_device_t *dev, int irq )
-{
-       int ret;
-
-       if ( !irq )
-               return -EINVAL;
-
-       down( &dev->struct_sem );
-
-       /* Driver must have been initialized */
-       if ( !dev->dev_private ) {
-               up( &dev->struct_sem );
-               return -EINVAL;
-       }
-
-       if ( dev->irq ) {
-               up( &dev->struct_sem );
-               return -EBUSY;
-       }
-       dev->irq = irq;
-       up( &dev->struct_sem );
-
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
-       dev->context_flag = 0;
-       dev->interrupt_flag = 0;
-       dev->dma_flag = 0;
-
-       dev->dma->next_buffer = NULL;
-       dev->dma->next_queue = NULL;
-       dev->dma->this_buffer = NULL;
-
-#if __HAVE_DMA_IRQ_BH
-#if !HAS_WORKQUEUE
-       INIT_LIST_HEAD( &dev->tq.list );
-       dev->tq.sync = 0;
-       dev->tq.routine = DRM(dma_immediate_bh);
-       dev->tq.data = dev;
-#else
-       INIT_WORK(&dev->work, DRM(dma_immediate_bh), dev);
-#endif
-#endif
-
-#if __HAVE_VBL_IRQ
-       init_waitqueue_head(&dev->vbl_queue);
-
-       spin_lock_init( &dev->vbl_lock );
-
-       INIT_LIST_HEAD( &dev->vbl_sigs.head );
-
-       dev->vbl_pending = 0;
-#endif
-
-                               /* Before installing handler */
-       DRM(driver_irq_preinstall)(dev);
-
-                               /* Install handler */
-       ret = request_irq( dev->irq, DRM(dma_service),
-                          DRM_IRQ_TYPE, dev->devname, dev );
-       if ( ret < 0 ) {
-               down( &dev->struct_sem );
-               dev->irq = 0;
-               up( &dev->struct_sem );
-               return ret;
-       }
-
-                               /* After installing handler */
-       DRM(driver_irq_postinstall)(dev);
-
-       return 0;
-}
-
-/**
- * Uninstall the IRQ handler.
- *
- * \param dev DRM device.
- *
- * Calls the driver's \c DRM(driver_irq_uninstall)() function, and stops the irq.
- */
-int DRM(irq_uninstall)( drm_device_t *dev )
-{
-       int irq;
-
-       down( &dev->struct_sem );
-       irq = dev->irq;
-       dev->irq = 0;
-       up( &dev->struct_sem );
-
-       if ( !irq )
-               return -EINVAL;
-
-       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
-
-       DRM(driver_irq_uninstall)( dev );
-
-       free_irq( irq, dev );
-
-       return 0;
-}
-
-/**
- * IRQ control ioctl.
- *
- * \param inode device inode.
- * \param filp file pointer.
- * \param cmd command.
- * \param arg user argument, pointing to a drm_control structure.
- * \return zero on success or a negative number on failure.
- *
- * Calls irq_install() or irq_uninstall() according to \p arg.
+#if !__HAVE_IRQ
+/* This stub DRM_IOCTL_CONTROL handler is for the drivers that used to require
+ * IRQs for DMA but no longer do.  It maintains compatibility with the X Servers
+ * that try to use the control ioctl by simply returning success.
  */
 int DRM(control)( struct inode *inode, struct file *filp,
                  unsigned int cmd, unsigned long arg )
 {
-       drm_file_t *priv = filp->private_data;
-       drm_device_t *dev = priv->dev;
-       drm_control_t ctl;
-
-       if ( copy_from_user( &ctl, (drm_control_t *)arg, sizeof(ctl) ) )
-               return -EFAULT;
-
-       switch ( ctl.func ) {
-       case DRM_INST_HANDLER:
-               return DRM(irq_install)( dev, ctl.irq );
-       case DRM_UNINST_HANDLER:
-               return DRM(irq_uninstall)( dev );
-       default:
-               return -EINVAL;
-       }
-}
-
-#if __HAVE_VBL_IRQ
-
-/**
- * Wait for VBLANK.
- *
- * \param inode device inode.
- * \param filp file pointer.
- * \param cmd command.
- * \param data user argument, pointing to a drm_wait_vblank structure.
- * \return zero on success or a negative number on failure.
- *
- * Verifies the IRQ is installed. 
- *
- * If a signal is requested checks if this task has already scheduled the same signal
- * for the same vblank sequence number - nothing to be done in
- * that case. If the number of tasks waiting for the interrupt exceeds 100 the
- * function fails. Otherwise adds a new entry to drm_device::vbl_sigs for this
- * task.
- *
- * If a signal is not requested, then calls vblank_wait().
- */
-int DRM(wait_vblank)( DRM_IOCTL_ARGS )
-{
-       drm_file_t *priv = filp->private_data;
-       drm_device_t *dev = priv->dev;
-       drm_wait_vblank_t vblwait;
-       struct timeval now;
-       int ret = 0;
-       unsigned int flags;
-
-       if (!dev->irq)
-               return -EINVAL;
-
-       DRM_COPY_FROM_USER_IOCTL( vblwait, (drm_wait_vblank_t *)data,
-                                 sizeof(vblwait) );
-
-       switch ( vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK ) {
-       case _DRM_VBLANK_RELATIVE:
-               vblwait.request.sequence += atomic_read( &dev->vbl_received );
-               vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
-       case _DRM_VBLANK_ABSOLUTE:
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
-       
-       if ( flags & _DRM_VBLANK_SIGNAL ) {
-               unsigned long irqflags;
-               drm_vbl_sig_t *vbl_sig;
-               
-               vblwait.reply.sequence = atomic_read( &dev->vbl_received );
-
-               spin_lock_irqsave( &dev->vbl_lock, irqflags );
-
-               /* Check if this task has already scheduled the same signal
-                * for the same vblank sequence number; nothing to be done in
-                * that case
-                */
-               list_for_each_entry( vbl_sig, &dev->vbl_sigs.head, head ) {
-                       if (vbl_sig->sequence == vblwait.request.sequence
-                           && vbl_sig->info.si_signo == vblwait.request.signal
-                           && vbl_sig->task == current)
-                       {
-                               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
-                               goto done;
-                       }
-               }
-
-               if ( dev->vbl_pending >= 100 ) {
-                       spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
-                       return -EBUSY;
-               }
-
-               dev->vbl_pending++;
-
-               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
-
-               if ( !( vbl_sig = DRM_MALLOC( sizeof( drm_vbl_sig_t ) ) ) ) {
-                       return -ENOMEM;
-               }
-
-               memset( (void *)vbl_sig, 0, sizeof(*vbl_sig) );
-
-               vbl_sig->sequence = vblwait.request.sequence;
-               vbl_sig->info.si_signo = vblwait.request.signal;
-               vbl_sig->task = current;
-
-               spin_lock_irqsave( &dev->vbl_lock, irqflags );
-
-               list_add_tail( (struct list_head *) vbl_sig, &dev->vbl_sigs.head );
-
-               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
-       } else {
-               ret = DRM(vblank_wait)( dev, &vblwait.request.sequence );
-
-               do_gettimeofday( &now );
-               vblwait.reply.tval_sec = now.tv_sec;
-               vblwait.reply.tval_usec = now.tv_usec;
-       }
-
-done:
-       DRM_COPY_TO_USER_IOCTL( (drm_wait_vblank_t *)data, vblwait,
-                               sizeof(vblwait) );
-
-       return ret;
-}
-
-/**
- * Send the VBLANK signals.
- *
- * \param dev DRM device.
- *
- * Sends a signal for each task in drm_device::vbl_sigs and empties the list.
- *
- * If a signal is not requested, then calls vblank_wait().
- */
-void DRM(vbl_send_signals)( drm_device_t *dev )
-{
-       struct list_head *list, *tmp;
-       drm_vbl_sig_t *vbl_sig;
-       unsigned int vbl_seq = atomic_read( &dev->vbl_received );
-       unsigned long flags;
-
-       spin_lock_irqsave( &dev->vbl_lock, flags );
-
-       list_for_each_safe( list, tmp, &dev->vbl_sigs.head ) {
-               vbl_sig = list_entry( list, drm_vbl_sig_t, head );
-               if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
-                       vbl_sig->info.si_code = vbl_seq;
-                       send_sig_info( vbl_sig->info.si_signo, &vbl_sig->info, vbl_sig->task );
-
-                       list_del( list );
-
-                       DRM_FREE( vbl_sig, sizeof(*vbl_sig) );
-
-                       dev->vbl_pending--;
-               }
-       }
-
-       spin_unlock_irqrestore( &dev->vbl_lock, flags );
-}
-
-#endif /* __HAVE_VBL_IRQ */
-
-#else
-
-int DRM(control)( struct inode *inode, struct file *filp,
-                 unsigned int cmd, unsigned long arg )
-{
        drm_control_t ctl;
 
        if ( copy_from_user( &ctl, (drm_control_t *)arg, sizeof(ctl) ) )
@@ -525,7 +226,6 @@ int DRM(control)( struct inode *inode, struct file *filp,
                return -EINVAL;
        }
 }
-
-#endif /* __HAVE_DMA_IRQ */
+#endif
 
 #endif /* __HAVE_DMA */
index 801118e..d1bad56 100644 (file)
@@ -58,8 +58,8 @@
 #ifndef __HAVE_CTX_BITMAP
 #define __HAVE_CTX_BITMAP              0
 #endif
-#ifndef __HAVE_DMA_IRQ
-#define __HAVE_DMA_IRQ                 0
+#ifndef __HAVE_IRQ
+#define __HAVE_IRQ                     0
 #endif
 #ifndef __HAVE_DMA_QUEUE
 #define __HAVE_DMA_QUEUE               0
@@ -215,9 +215,9 @@ static drm_ioctl_desc_t               DRM(ioctls)[] = {
        [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)]     = { DRM(infobufs),    1, 0 },
        [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)]      = { DRM(mapbufs),     1, 0 },
        [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)]     = { DRM(freebufs),    1, 0 },
-
-       /* The DRM_IOCTL_DMA ioctl should be defined by the driver.
-        */
+       /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
+#endif
+#if __HAVE_IRQ || __HAVE_DMA
        [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)]       = { DRM(control),     1, 1 },
 #endif
 
@@ -384,7 +384,7 @@ static int DRM(takedown)( drm_device_t *dev )
        DRM_DEBUG( "\n" );
 
        DRIVER_PRETAKEDOWN();
-#if __HAVE_DMA_IRQ
+#if __HAVE_IRQ
        if ( dev->irq ) DRM(irq_uninstall)( dev );
 #endif
 
diff --git a/linux/drm_irq.h b/linux/drm_irq.h
new file mode 100644 (file)
index 0000000..322e571
--- /dev/null
@@ -0,0 +1,340 @@
+/**
+ * \file drm_irq.h 
+ * IRQ support
+ *
+ * \author Rickard E. (Rik) Faith <faith@valinux.com>
+ * \author Gareth Hughes <gareth@valinux.com>
+ */
+
+/*
+ * Created: Fri Mar 19 14:30:16 1999 by faith@valinux.com
+ *
+ * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#define __NO_VERSION__
+#include "drmP.h"
+
+#include <linux/interrupt.h>   /* For task queue support */
+
+#ifndef __HAVE_SHARED_IRQ
+#define __HAVE_SHARED_IRQ      0
+#endif
+
+#if __HAVE_SHARED_IRQ
+#define DRM_IRQ_TYPE           SA_SHIRQ
+#else
+#define DRM_IRQ_TYPE           0
+#endif
+
+#if __HAVE_IRQ
+
+/**
+ * Install IRQ handler.
+ *
+ * \param dev DRM device.
+ * \param irq IRQ number.
+ *
+ * Initializes the IRQ related data, and setups drm_device::vbl_queue. Installs the handler, calling the driver
+ * \c DRM(driver_irq_preinstall)() and \c DRM(driver_irq_postinstall)() functions
+ * before and after the installation.
+ */
+int DRM(irq_install)( drm_device_t *dev, int irq )
+{
+       int ret;
+
+       if ( !irq )
+               return -EINVAL;
+
+       down( &dev->struct_sem );
+
+       /* Driver must have been initialized */
+       if ( !dev->dev_private ) {
+               up( &dev->struct_sem );
+               return -EINVAL;
+       }
+
+       if ( dev->irq ) {
+               up( &dev->struct_sem );
+               return -EBUSY;
+       }
+       dev->irq = irq;
+       up( &dev->struct_sem );
+
+       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+
+       dev->context_flag = 0;
+       dev->interrupt_flag = 0;
+       dev->dma_flag = 0;
+
+       dev->dma->next_buffer = NULL;
+       dev->dma->next_queue = NULL;
+       dev->dma->this_buffer = NULL;
+
+#if __HAVE_IRQ_BH
+#if !HAS_WORKQUEUE
+       INIT_LIST_HEAD( &dev->tq.list );
+       dev->tq.sync = 0;
+       dev->tq.routine = DRM(irq_immediate_bh);
+       dev->tq.data = dev;
+#else
+       INIT_WORK(&dev->work, DRM(irq_immediate_bh), dev);
+#endif
+#endif
+
+#if __HAVE_VBL_IRQ
+       init_waitqueue_head(&dev->vbl_queue);
+
+       spin_lock_init( &dev->vbl_lock );
+
+       INIT_LIST_HEAD( &dev->vbl_sigs.head );
+
+       dev->vbl_pending = 0;
+#endif
+
+                               /* Before installing handler */
+       DRM(driver_irq_preinstall)(dev);
+
+                               /* Install handler */
+       ret = request_irq( dev->irq, DRM(irq_handler),
+                          DRM_IRQ_TYPE, dev->devname, dev );
+       if ( ret < 0 ) {
+               down( &dev->struct_sem );
+               dev->irq = 0;
+               up( &dev->struct_sem );
+               return ret;
+       }
+
+                               /* After installing handler */
+       DRM(driver_irq_postinstall)(dev);
+
+       return 0;
+}
+
+/**
+ * Uninstall the IRQ handler.
+ *
+ * \param dev DRM device.
+ *
+ * Calls the driver's \c DRM(driver_irq_uninstall)() function, and stops the irq.
+ */
+int DRM(irq_uninstall)( drm_device_t *dev )
+{
+       int irq;
+
+       down( &dev->struct_sem );
+       irq = dev->irq;
+       dev->irq = 0;
+       up( &dev->struct_sem );
+
+       if ( !irq )
+               return -EINVAL;
+
+       DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
+
+       DRM(driver_irq_uninstall)( dev );
+
+       free_irq( irq, dev );
+
+       return 0;
+}
+
+/**
+ * IRQ control ioctl.
+ *
+ * \param inode device inode.
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param arg user argument, pointing to a drm_control structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Calls irq_install() or irq_uninstall() according to \p arg.
+ */
+int DRM(control)( struct inode *inode, struct file *filp,
+                 unsigned int cmd, unsigned long arg )
+{
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->dev;
+       drm_control_t ctl;
+
+       if ( copy_from_user( &ctl, (drm_control_t *)arg, sizeof(ctl) ) )
+               return -EFAULT;
+
+       switch ( ctl.func ) {
+       case DRM_INST_HANDLER:
+               return DRM(irq_install)( dev, ctl.irq );
+       case DRM_UNINST_HANDLER:
+               return DRM(irq_uninstall)( dev );
+       default:
+               return -EINVAL;
+       }
+}
+
+#if __HAVE_VBL_IRQ
+
+/**
+ * Wait for VBLANK.
+ *
+ * \param inode device inode.
+ * \param filp file pointer.
+ * \param cmd command.
+ * \param data user argument, pointing to a drm_wait_vblank structure.
+ * \return zero on success or a negative number on failure.
+ *
+ * Verifies the IRQ is installed. 
+ *
+ * If a signal is requested checks if this task has already scheduled the same signal
+ * for the same vblank sequence number - nothing to be done in
+ * that case. If the number of tasks waiting for the interrupt exceeds 100 the
+ * function fails. Otherwise adds a new entry to drm_device::vbl_sigs for this
+ * task.
+ *
+ * If a signal is not requested, then calls vblank_wait().
+ */
+int DRM(wait_vblank)( DRM_IOCTL_ARGS )
+{
+       drm_file_t *priv = filp->private_data;
+       drm_device_t *dev = priv->dev;
+       drm_wait_vblank_t vblwait;
+       struct timeval now;
+       int ret = 0;
+       unsigned int flags;
+
+       if (!dev->irq)
+               return -EINVAL;
+
+       DRM_COPY_FROM_USER_IOCTL( vblwait, (drm_wait_vblank_t *)data,
+                                 sizeof(vblwait) );
+
+       switch ( vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK ) {
+       case _DRM_VBLANK_RELATIVE:
+               vblwait.request.sequence += atomic_read( &dev->vbl_received );
+               vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
+       case _DRM_VBLANK_ABSOLUTE:
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
+       
+       if ( flags & _DRM_VBLANK_SIGNAL ) {
+               unsigned long irqflags;
+               drm_vbl_sig_t *vbl_sig;
+               
+               vblwait.reply.sequence = atomic_read( &dev->vbl_received );
+
+               spin_lock_irqsave( &dev->vbl_lock, irqflags );
+
+               /* Check if this task has already scheduled the same signal
+                * for the same vblank sequence number; nothing to be done in
+                * that case
+                */
+               list_for_each_entry( vbl_sig, &dev->vbl_sigs.head, head ) {
+                       if (vbl_sig->sequence == vblwait.request.sequence
+                           && vbl_sig->info.si_signo == vblwait.request.signal
+                           && vbl_sig->task == current)
+                       {
+                               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+                               goto done;
+                       }
+               }
+
+               if ( dev->vbl_pending >= 100 ) {
+                       spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+                       return -EBUSY;
+               }
+
+               dev->vbl_pending++;
+
+               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+
+               if ( !( vbl_sig = DRM_MALLOC( sizeof( drm_vbl_sig_t ) ) ) ) {
+                       return -ENOMEM;
+               }
+
+               memset( (void *)vbl_sig, 0, sizeof(*vbl_sig) );
+
+               vbl_sig->sequence = vblwait.request.sequence;
+               vbl_sig->info.si_signo = vblwait.request.signal;
+               vbl_sig->task = current;
+
+               spin_lock_irqsave( &dev->vbl_lock, irqflags );
+
+               list_add_tail( (struct list_head *) vbl_sig, &dev->vbl_sigs.head );
+
+               spin_unlock_irqrestore( &dev->vbl_lock, irqflags );
+       } else {
+               ret = DRM(vblank_wait)( dev, &vblwait.request.sequence );
+
+               do_gettimeofday( &now );
+               vblwait.reply.tval_sec = now.tv_sec;
+               vblwait.reply.tval_usec = now.tv_usec;
+       }
+
+done:
+       DRM_COPY_TO_USER_IOCTL( (drm_wait_vblank_t *)data, vblwait,
+                               sizeof(vblwait) );
+
+       return ret;
+}
+
+/**
+ * Send the VBLANK signals.
+ *
+ * \param dev DRM device.
+ *
+ * Sends a signal for each task in drm_device::vbl_sigs and empties the list.
+ *
+ * If a signal is not requested, then calls vblank_wait().
+ */
+void DRM(vbl_send_signals)( drm_device_t *dev )
+{
+       struct list_head *list, *tmp;
+       drm_vbl_sig_t *vbl_sig;
+       unsigned int vbl_seq = atomic_read( &dev->vbl_received );
+       unsigned long flags;
+
+       spin_lock_irqsave( &dev->vbl_lock, flags );
+
+       list_for_each_safe( list, tmp, &dev->vbl_sigs.head ) {
+               vbl_sig = list_entry( list, drm_vbl_sig_t, head );
+               if ( ( vbl_seq - vbl_sig->sequence ) <= (1<<23) ) {
+                       vbl_sig->info.si_code = vbl_seq;
+                       send_sig_info( vbl_sig->info.si_signo, &vbl_sig->info, vbl_sig->task );
+
+                       list_del( list );
+
+                       DRM_FREE( vbl_sig, sizeof(*vbl_sig) );
+
+                       dev->vbl_pending--;
+               }
+       }
+
+       spin_unlock_irqrestore( &dev->vbl_lock, flags );
+}
+
+#endif /* __HAVE_VBL_IRQ */
+
+#endif /* __HAVE_IRQ */
index 407eb36..d4712ef 100644 (file)
        return 0;                                                       \
 } while (0)
 
-#define __HAVE_DMA_IRQ                 1
-#define __HAVE_DMA_IRQ_BH              1
+#define __HAVE_IRQ                     1
+#define __HAVE_IRQ_BH                  1
 
 #define DRIVER_AGP_BUFFERS_MAP( dev )                                  \
        ((drm_gamma_private_t *)((dev)->dev_private))->buffers
index 3fc6c9f..bae19bb 100644 (file)
@@ -105,7 +105,7 @@ static inline int gamma_dma_is_ready(drm_device_t *dev)
        return(!GAMMA_READ(GAMMA_DMACOUNT));
 }
 
-irqreturn_t gamma_dma_service( DRM_IRQ_ARGS )
+irqreturn_t gamma_irq_handler( DRM_IRQ_ARGS )
 {
        drm_device_t     *dev = (drm_device_t *)arg;
        drm_device_dma_t *dma = dev->dma;
@@ -253,7 +253,7 @@ static void gamma_dma_timer_bh(unsigned long dev)
        gamma_dma_schedule((drm_device_t *)dev, 0);
 }
 
-void gamma_dma_immediate_bh(void *dev)
+void gamma_irq_immediate_bh(void *dev)
 {
        gamma_dma_schedule(dev, 0);
 }
@@ -647,7 +647,7 @@ int gamma_do_cleanup_dma( drm_device_t *dev )
 {
        DRM_DEBUG( "%s\n", __FUNCTION__ );
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index f1b8b20..b1fb050 100644 (file)
@@ -48,6 +48,7 @@
 #include "drm_fops.h"
 #include "drm_init.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "gamma_lists.h"        /* NOTE */
 #include "drm_lock.h"
 #include "gamma_lock.h"                /* NOTE */
index d4098e4..ffa06c0 100644 (file)
  * a noop stub is generated for compatibility.
  */
 /* XXX: Add vblank support? */
-#define __HAVE_DMA_IRQ         0
+#define __HAVE_IRQ             0
 
 /* Buffer customization:
  */
index 430ee52..1eeb4a3 100644 (file)
@@ -239,7 +239,7 @@ int i810_dma_cleanup(drm_device_t *dev)
 {
        drm_device_dma_t *dma = dev->dma;
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index cd770bb..c0f092e 100644 (file)
 #define USE_IRQS 0
 
 #if USE_IRQS
-#define __HAVE_DMA_IRQ         1
+#define __HAVE_IRQ             1
 #define __HAVE_SHARED_IRQ      1
 #else
-#define __HAVE_DMA_IRQ          0
+#define __HAVE_IRQ             0
 #endif
 
 
index 48b64d7..422f3ad 100644 (file)
@@ -238,7 +238,7 @@ int i830_dma_cleanup(drm_device_t *dev)
 {
        drm_device_dma_t *dma = dev->dma;
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index 0735c94..2f4e815 100644 (file)
@@ -50,6 +50,7 @@
 #include "drm_fops.h"
 #include "drm_init.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_proc.h"
index d2aabf3..6d45cda 100644 (file)
@@ -36,7 +36,7 @@
 #include <linux/delay.h>
 
 
-irqreturn_t DRM(dma_service)( DRM_IRQ_ARGS )
+irqreturn_t DRM(irq_handler)( DRM_IRQ_ARGS )
 {
        drm_device_t     *dev = (drm_device_t *)arg;
        drm_i830_private_t *dev_priv = (drm_i830_private_t *)dev->dev_private;
index f0d4935..6bcad04 100644 (file)
@@ -45,6 +45,7 @@
 #include "drm_fops.h"
 #include "drm_init.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_proc.h"
index e2e4269..1dee161 100644 (file)
@@ -47,6 +47,7 @@
 #include "drm_fops.h"
 #include "drm_init.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_proc.h"
index 6152b8a..74e32df 100644 (file)
@@ -48,6 +48,7 @@
 #include "drm_fops.h"
 #include "drm_init.h"
 #include "drm_ioctl.h"
+#include "drm_irq.h"
 #include "drm_lock.h"
 #include "drm_memory.h"
 #include "drm_proc.h"
index bfaee0d..f2d92f1 100644 (file)
@@ -639,7 +639,7 @@ int mga_do_cleanup_dma( drm_device_t *dev )
 {
        DRM_DEBUG( "\n" );
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index ccced64..e486618 100644 (file)
@@ -36,7 +36,7 @@
 #include "mga_drm.h"
 #include "mga_drv.h"
 
-irqreturn_t mga_dma_service( DRM_IRQ_ARGS )
+irqreturn_t mga_irq_handler( DRM_IRQ_ARGS )
 {
        drm_device_t *dev = (drm_device_t *) arg;
        drm_mga_private_t *dev_priv = 
index 13b44a5..fdf220b 100644 (file)
@@ -594,7 +594,7 @@ static int r128_do_init_cce( drm_device_t *dev, drm_r128_init_t *init )
 int r128_do_cleanup_cce( drm_device_t *dev )
 {
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index c060e18..e77a553 100644 (file)
@@ -36,7 +36,7 @@
 #include "r128_drm.h"
 #include "r128_drv.h"
 
-irqreturn_t r128_dma_service( DRM_IRQ_ARGS )
+irqreturn_t r128_irq_handler( DRM_IRQ_ARGS )
 {
        drm_device_t *dev = (drm_device_t *) arg;
        drm_r128_private_t *dev_priv = 
index 3e3618e..b24880a 100644 (file)
@@ -1271,7 +1271,7 @@ int radeon_do_cleanup_cp( drm_device_t *dev )
 {
        DRM_DEBUG( "\n" );
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index 1d339f2..f503153 100644 (file)
@@ -54,7 +54,7 @@
  * tied to dma at all, this is just a hangover from dri prehistory.
  */
 
-irqreturn_t DRM(dma_service)( DRM_IRQ_ARGS )
+irqreturn_t DRM(irq_handler)( DRM_IRQ_ARGS )
 {
        drm_device_t *dev = (drm_device_t *) arg;
        drm_radeon_private_t *dev_priv = 
index 696a3b5..05fa9eb 100644 (file)
@@ -84,7 +84,7 @@
 /* DMA customization:
  */
 #define __HAVE_DMA             1
-#define __HAVE_DMA_IRQ         1
+#define __HAVE_IRQ             1
 #define __HAVE_VBL_IRQ         1
 #define __HAVE_SHARED_IRQ       1
 
index bfaee0d..f2d92f1 100644 (file)
@@ -639,7 +639,7 @@ int mga_do_cleanup_dma( drm_device_t *dev )
 {
        DRM_DEBUG( "\n" );
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index ccced64..e486618 100644 (file)
@@ -36,7 +36,7 @@
 #include "mga_drm.h"
 #include "mga_drv.h"
 
-irqreturn_t mga_dma_service( DRM_IRQ_ARGS )
+irqreturn_t mga_irq_handler( DRM_IRQ_ARGS )
 {
        drm_device_t *dev = (drm_device_t *) arg;
        drm_mga_private_t *dev_priv = 
index 2047e4a..97784fd 100644 (file)
 /* DMA customization:
  */
 #define __HAVE_DMA             1
-#define __HAVE_DMA_IRQ         1
+#define __HAVE_IRQ             1
 #define __HAVE_VBL_IRQ         1
 #define __HAVE_SHARED_IRQ       1
 
index 13b44a5..fdf220b 100644 (file)
@@ -594,7 +594,7 @@ static int r128_do_init_cce( drm_device_t *dev, drm_r128_init_t *init )
 int r128_do_cleanup_cce( drm_device_t *dev )
 {
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index c060e18..e77a553 100644 (file)
@@ -36,7 +36,7 @@
 #include "r128_drm.h"
 #include "r128_drv.h"
 
-irqreturn_t r128_dma_service( DRM_IRQ_ARGS )
+irqreturn_t r128_irq_handler( DRM_IRQ_ARGS )
 {
        drm_device_t *dev = (drm_device_t *) arg;
        drm_r128_private_t *dev_priv = 
index e66c11f..fadb248 100644 (file)
@@ -179,7 +179,7 @@ do {                                                \
 /* DMA customization:
  */
 #define __HAVE_DMA             1
-#define __HAVE_DMA_IRQ         1
+#define __HAVE_IRQ             1
 #define __HAVE_VBL_IRQ         1
 #define __HAVE_SHARED_IRQ       1
 
index 3e3618e..b24880a 100644 (file)
@@ -1271,7 +1271,7 @@ int radeon_do_cleanup_cp( drm_device_t *dev )
 {
        DRM_DEBUG( "\n" );
 
-#if _HAVE_DMA_IRQ
+#if __HAVE_IRQ
        /* Make sure interrupts are disabled here because the uninstall ioctl
         * may not have been called from userspace and after dev_private
         * is freed, it's too late.
index 1d339f2..f503153 100644 (file)
@@ -54,7 +54,7 @@
  * tied to dma at all, this is just a hangover from dri prehistory.
  */
 
-irqreturn_t DRM(dma_service)( DRM_IRQ_ARGS )
+irqreturn_t DRM(irq_handler)( DRM_IRQ_ARGS )
 {
        drm_device_t *dev = (drm_device_t *) arg;
        drm_radeon_private_t *dev_priv =