summaryrefslogtreecommitdiff
path: root/bsd-core/drm_dma.c
diff options
context:
space:
mode:
authorAlan Hourihane <alanh@fairlite.demon.co.uk>2003-03-25 00:28:44 +0000
committerAlan Hourihane <alanh@fairlite.demon.co.uk>2003-03-25 00:28:44 +0000
commitc323a818180a22a12f0c0db0ce04459faefe95e8 (patch)
treef61fb0903bd0a6aa44c08b554744d5f80e528177 /bsd-core/drm_dma.c
parentc4ccaa7dadf3010c9f4952caa3de2b6980092c6e (diff)
XFree86 4.3.0 merge
Diffstat (limited to 'bsd-core/drm_dma.c')
-rw-r--r--bsd-core/drm_dma.c170
1 files changed, 117 insertions, 53 deletions
diff --git a/bsd-core/drm_dma.c b/bsd-core/drm_dma.c
index e5aef241..eb553984 100644
--- a/bsd-core/drm_dma.c
+++ b/bsd-core/drm_dma.c
@@ -29,10 +29,6 @@
* Gareth Hughes <gareth@valinux.com>
*/
-#include <machine/bus.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
#include "drmP.h"
#ifndef __HAVE_DMA_WAITQUEUE
@@ -45,12 +41,6 @@
#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
int DRM(dma_setup)( drm_device_t *dev )
@@ -59,7 +49,7 @@ int DRM(dma_setup)( drm_device_t *dev )
dev->dma = DRM(alloc)( sizeof(*dev->dma), DRM_MEM_DRIVER );
if ( !dev->dma )
- DRM_OS_RETURN(ENOMEM);
+ return DRM_ERR(ENOMEM);
memset( dev->dma, 0, sizeof(*dev->dma) );
@@ -85,8 +75,8 @@ void DRM(dma_takedown)(drm_device_t *dev)
dma->bufs[i].buf_count,
dma->bufs[i].seg_count);
for (j = 0; j < dma->bufs[i].seg_count; j++) {
- DRM(free_pages)(dma->bufs[i].seglist[j],
- dma->bufs[i].page_order,
+ DRM(free)((void *)dma->bufs[i].seglist[j],
+ dma->bufs[i].buf_size,
DRM_MEM_DMA);
}
DRM(free)(dma->bufs[i].seglist,
@@ -197,7 +187,7 @@ void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf)
#endif
if ( buf->dma_wait ) {
- wakeup( &buf->dma_wait );
+ wakeup( (void *)&buf->dma_wait );
buf->dma_wait = 0;
}
#if __HAVE_DMA_FREELIST
@@ -248,7 +238,7 @@ void DRM(clear_next_buffer)(drm_device_t *dev)
dma->next_buffer = NULL;
if (dma->next_queue && !DRM_BUFCOUNT(&dma->next_queue->waitlist)) {
- DRM_OS_WAKEUP_INT(&dma->next_queue->flush_queue);
+ DRM_WAKEUP_INT(&dma->next_queue->flush_queue);
}
dma->next_queue = NULL;
}
@@ -340,7 +330,7 @@ int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d)
if (!_DRM_LOCK_IS_HELD(context)) {
DRM_ERROR("No lock held during \"while locked\""
" request\n");
- DRM_OS_RETURN(EINVAL);
+ return DRM_ERR(EINVAL);
}
if (d->context != _DRM_LOCKING_CONTEXT(context)
&& _DRM_LOCKING_CONTEXT(context) != DRM_KERNEL_CONTEXT) {
@@ -348,7 +338,7 @@ int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d)
" \"while locked\" request\n",
_DRM_LOCKING_CONTEXT(context),
d->context);
- DRM_OS_RETURN(EINVAL);
+ return DRM_ERR(EINVAL);
}
q = dev->queuelist[DRM_KERNEL_CONTEXT];
while_locked = 1;
@@ -378,19 +368,19 @@ int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d)
atomic_dec(&q->use_count);
DRM_ERROR("Index %d (of %d max)\n",
d->send_indices[i], dma->buf_count - 1);
- DRM_OS_RETURN(EINVAL);
+ return DRM_ERR(EINVAL);
}
buf = dma->buflist[ idx ];
- if (buf->pid != DRM_OS_CURRENTPID) {
+ if (buf->pid != DRM_CURRENTPID) {
atomic_dec(&q->use_count);
DRM_ERROR("Process %d using buffer owned by %d\n",
- DRM_OS_CURRENTPID, buf->pid);
- DRM_OS_RETURN(EINVAL);
+ DRM_CURRENTPID, buf->pid);
+ return DRM_ERR(EINVAL);
}
if (buf->list != DRM_LIST_NONE) {
atomic_dec(&q->use_count);
DRM_ERROR("Process %d using buffer %d on list %d\n",
- DRM_OS_CURRENTPID, buf->idx, buf->list);
+ DRM_CURRENTPID, buf->idx, buf->list);
}
buf->used = d->send_sizes[i];
buf->while_locked = while_locked;
@@ -403,14 +393,14 @@ int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d)
DRM_ERROR("Queueing pending buffer:"
" buffer %d, offset %d\n",
d->send_indices[i], i);
- DRM_OS_RETURN(EINVAL);
+ return DRM_ERR(EINVAL);
}
if (buf->waiting) {
atomic_dec(&q->use_count);
DRM_ERROR("Queueing waiting buffer:"
" buffer %d, offset %d\n",
d->send_indices[i], i);
- DRM_OS_RETURN(EINVAL);
+ return DRM_ERR(EINVAL);
}
buf->waiting = 1;
if (atomic_read(&q->use_count) == 1
@@ -444,16 +434,16 @@ static int DRM(dma_get_buffers_of_order)(drm_device_t *dev, drm_dma_t *d,
buf->waiting,
buf->pending);
}
- buf->pid = DRM_OS_CURRENTPID;
- if (DRM_OS_COPYTOUSR(&d->request_indices[i],
+ buf->pid = DRM_CURRENTPID;
+ if (DRM_COPY_TO_USER(&d->request_indices[i],
&buf->idx,
sizeof(buf->idx)))
- DRM_OS_RETURN(EFAULT);
+ return DRM_ERR(EFAULT);
- if (DRM_OS_COPYTOUSR(&d->request_sizes[i],
+ if (DRM_COPY_TO_USER(&d->request_sizes[i],
&buf->total,
sizeof(buf->total)))
- DRM_OS_RETURN(EFAULT);
+ return DRM_ERR(EFAULT);
++d->granted_count;
}
@@ -507,19 +497,18 @@ int DRM(dma_get_buffers)(drm_device_t *dev, drm_dma_t *dma)
int DRM(irq_install)( drm_device_t *dev, int irq )
{
- int rid;
int retcode;
if ( !irq )
- DRM_OS_RETURN(EINVAL);
+ return DRM_ERR(EINVAL);
- DRM_OS_LOCK;
+ DRM_LOCK;
if ( dev->irq ) {
- DRM_OS_UNLOCK;
- DRM_OS_RETURN(EBUSY);
+ DRM_UNLOCK;
+ return DRM_ERR(EBUSY);
}
dev->irq = irq;
- DRM_OS_UNLOCK;
+ DRM_UNLOCK;
DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
@@ -536,27 +525,33 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
#endif
/* Before installing handler */
- DRIVER_PREINSTALL();
+ DRM(driver_irq_preinstall)( dev );
/* Install handler */
- rid = 0;
- dev->irqr = bus_alloc_resource(dev->device, SYS_RES_IRQ, &rid,
+ dev->irqrid = 0;
+ dev->irqr = bus_alloc_resource(dev->device, SYS_RES_IRQ, &dev->irqrid,
0, ~0, 1, RF_SHAREABLE);
- if (!dev->irqr)
+ if (!dev->irqr) {
+ DRM_LOCK;
+ dev->irq = 0;
+ dev->irqrid = 0;
+ DRM_UNLOCK;
return ENOENT;
+ }
retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY,
DRM(dma_service), dev, &dev->irqh);
if ( retcode ) {
- DRM_OS_LOCK;
- bus_release_resource(dev->device, SYS_RES_IRQ, 0, dev->irqr);
+ DRM_LOCK;
+ bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid, dev->irqr);
dev->irq = 0;
- DRM_OS_UNLOCK;
+ dev->irqrid = 0;
+ DRM_UNLOCK;
return retcode;
}
/* After installing handler */
- DRIVER_POSTINSTALL();
+ DRM(driver_irq_postinstall)( dev );
return 0;
}
@@ -564,31 +559,34 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
int DRM(irq_uninstall)( drm_device_t *dev )
{
int irq;
-
- DRM_OS_LOCK;
+ int irqrid;
+
+ DRM_LOCK;
irq = dev->irq;
+ irqrid = dev->irqrid;
dev->irq = 0;
- DRM_OS_UNLOCK;
+ dev->irqrid = 0;
+ DRM_UNLOCK;
if ( !irq )
- DRM_OS_RETURN(EINVAL);
+ return DRM_ERR(EINVAL);
DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
- DRIVER_UNINSTALL();
+ DRM(driver_irq_uninstall)( dev );
bus_teardown_intr(dev->device, dev->irqr, dev->irqh);
- bus_release_resource(dev->device, SYS_RES_IRQ, 0, dev->irqr);
+ bus_release_resource(dev->device, SYS_RES_IRQ, irqrid, dev->irqr);
return 0;
}
-int DRM(control)( DRM_OS_IOCTL )
+int DRM(control)( DRM_IOCTL_ARGS )
{
- DRM_OS_DEVICE;
+ DRM_DEVICE;
drm_control_t ctl;
- DRM_OS_KRNFROMUSR( ctl, (drm_control_t *) data, sizeof(ctl) );
+ DRM_COPY_FROM_USER_IOCTL( ctl, (drm_control_t *) data, sizeof(ctl) );
switch ( ctl.func ) {
case DRM_INST_HANDLER:
@@ -596,10 +594,76 @@ int DRM(control)( DRM_OS_IOCTL )
case DRM_UNINST_HANDLER:
return DRM(irq_uninstall)( dev );
default:
- DRM_OS_RETURN(EINVAL);
+ 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) );
+
+ switch ( vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK ) {
+ case _DRM_VBLANK_RELATIVE:
+ vblwait.request.sequence += atomic_read( &dev->vbl_received );
+ case _DRM_VBLANK_ABSOLUTE:
+ break;
+ default:
+ return EINVAL;
+ }
+
+ if ( flags & _DRM_VBLANK_SIGNAL ) {
+ /* Signals from vblank not supported on BSD yet */
+ return EINVAL;
+ }
+
+ flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
+
+ 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 ) {
+ /* Signals from vblank not supported on BSD yet */
+}
+
+#endif /* __HAVE_VBL_IRQ */
+
+#else
+
+int DRM(control)( DRM_IOCTL_ARGS )
+{
+ drm_control_t ctl;
+
+ DRM_COPY_FROM_USER_IOCTL( ctl, (drm_control_t *) data, sizeof(ctl) );
+
+ switch ( ctl.func ) {
+ case DRM_INST_HANDLER:
+ case DRM_UNINST_HANDLER:
+ return 0;
+ default:
+ return DRM_ERR(EINVAL);
}
}
#endif /* __HAVE_DMA_IRQ */
#endif /* __HAVE_DMA */
+