summaryrefslogtreecommitdiffstats
path: root/sys/dev/drm/drm_bufs.h
diff options
context:
space:
mode:
authoranholt <anholt@FreeBSD.org>2003-04-25 01:18:47 +0000
committeranholt <anholt@FreeBSD.org>2003-04-25 01:18:47 +0000
commit6afbdfe8ea6944a3f1856cc687cc6ea5e1d09657 (patch)
treeefa3d0f59b543fa0e752db53d7ddd71f5a18e325 /sys/dev/drm/drm_bufs.h
parenta521aa5aa4b354de2cb042c0909b4830a4884051 (diff)
downloadFreeBSD-src-6afbdfe8ea6944a3f1856cc687cc6ea5e1d09657.zip
FreeBSD-src-6afbdfe8ea6944a3f1856cc687cc6ea5e1d09657.tar.gz
Update the DRM to the latest from DRI CVS. Includes some bugfixes and removal
of the infrastructure for the gamma driver which was removed a while back. The DRM_LINUX option is removed because the handler is now provided by the linux compat code itself.
Diffstat (limited to 'sys/dev/drm/drm_bufs.h')
-rw-r--r--sys/dev/drm/drm_bufs.h253
1 files changed, 70 insertions, 183 deletions
diff --git a/sys/dev/drm/drm_bufs.h b/sys/dev/drm/drm_bufs.h
index 92855a7..9fab73f 100644
--- a/sys/dev/drm/drm_bufs.h
+++ b/sys/dev/drm/drm_bufs.h
@@ -310,20 +310,14 @@ static void DRM(cleanup_buf_error)(drm_buf_entry_t *entry)
sizeof(*entry->buflist),
DRM_MEM_BUFS);
-#if __HAVE_DMA_FREELIST
- DRM(freelist_destroy)(&entry->freelist);
-#endif
-
entry->buf_count = 0;
}
}
#if __REALLY_HAVE_AGP
-int DRM(addbufs_agp)( DRM_IOCTL_ARGS )
+static int DRM(addbufs_agp)(drm_device_t *dev, drm_buf_desc_t *request)
{
- DRM_DEVICE;
drm_device_dma_t *dma = dev->dma;
- drm_buf_desc_t request;
drm_buf_entry_t *entry;
drm_buf_t *buf;
unsigned long offset;
@@ -338,21 +332,17 @@ int DRM(addbufs_agp)( DRM_IOCTL_ARGS )
int i;
drm_buf_t **temp_buflist;
- if ( !dma ) return DRM_ERR(EINVAL);
-
- DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_desc_t *)data, sizeof(request) );
-
- count = request.count;
- order = DRM(order)( request.size );
+ count = request->count;
+ order = DRM(order)(request->size);
size = 1 << order;
- alignment = (request.flags & _DRM_PAGE_ALIGN)
+ alignment = (request->flags & _DRM_PAGE_ALIGN)
? round_page(size) : size;
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
total = PAGE_SIZE << page_order;
byte_count = 0;
- agp_offset = dev->agp->base + request.agp_start;
+ agp_offset = dev->agp->base + request->agp_start;
DRM_DEBUG( "count: %d\n", count );
DRM_DEBUG( "order: %d\n", order );
@@ -364,36 +354,18 @@ int DRM(addbufs_agp)( DRM_IOCTL_ARGS )
if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER )
return DRM_ERR(EINVAL);
- if ( dev->queue_count )
- return DRM_ERR(EBUSY); /* Not while in use */
-
- DRM_SPINLOCK( &dev->count_lock );
- if ( dev->buf_use ) {
- DRM_SPINUNLOCK( &dev->count_lock );
- return DRM_ERR(EBUSY);
- }
- atomic_inc( &dev->buf_alloc );
- DRM_SPINUNLOCK( &dev->count_lock );
DRM_LOCK;
entry = &dma->bufs[order];
if ( entry->buf_count ) {
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM); /* May only call once for each order */
}
- if (count < 0 || count > 4096) {
- DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
- return DRM_ERR(EINVAL);
- }
-
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
DRM_MEM_BUFS );
if ( !entry->buflist ) {
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM);
}
memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
@@ -414,10 +386,8 @@ int DRM(addbufs_agp)( DRM_IOCTL_ARGS )
buf->bus_address = agp_offset + offset;
buf->address = (void *)(agp_offset + offset);
buf->next = NULL;
- buf->waiting = 0;
buf->pending = 0;
- buf->dma_wait = 0;
- buf->pid = 0;
+ buf->filp = NULL;
buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T);
buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T),
@@ -429,13 +399,6 @@ int DRM(addbufs_agp)( DRM_IOCTL_ARGS )
}
memset( buf->dev_private, 0, buf->dev_priv_size );
-#if __HAVE_DMA_HISTOGRAM
- buf->time_queued = 0;
- buf->time_dispatched = 0;
- buf->time_completed = 0;
- buf->time_freed = 0;
-#endif
-
offset += alignment;
entry->buf_count++;
byte_count += PAGE_SIZE << page_order;
@@ -452,7 +415,6 @@ int DRM(addbufs_agp)( DRM_IOCTL_ARGS )
/* Free the entry because it isn't valid */
DRM(cleanup_buf_error)(entry);
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM);
}
dma->buflist = temp_buflist;
@@ -467,32 +429,21 @@ int DRM(addbufs_agp)( DRM_IOCTL_ARGS )
DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
-#if __HAVE_DMA_FREELIST
- DRM(freelist_create)( &entry->freelist, entry->buf_count );
- for ( i = 0 ; i < entry->buf_count ; i++ ) {
- DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] );
- }
-#endif
DRM_UNLOCK;
- request.count = entry->buf_count;
- request.size = size;
-
- DRM_COPY_TO_USER_IOCTL( (drm_buf_desc_t *)data, request, sizeof(request) );
+ request->count = entry->buf_count;
+ request->size = size;
dma->flags = _DRM_DMA_USE_AGP;
- atomic_dec( &dev->buf_alloc );
return 0;
}
#endif /* __REALLY_HAVE_AGP */
#if __HAVE_PCI_DMA
-int DRM(addbufs_pci)( DRM_IOCTL_ARGS )
+static int DRM(addbufs_pci)(drm_device_t *dev, drm_buf_desc_t *request)
{
- DRM_DEVICE;
drm_device_dma_t *dma = dev->dma;
- drm_buf_desc_t request;
int count;
int order;
int size;
@@ -509,55 +460,32 @@ int DRM(addbufs_pci)( DRM_IOCTL_ARGS )
unsigned long *temp_pagelist;
drm_buf_t **temp_buflist;
- if ( !dma ) return DRM_ERR(EINVAL);
-
- DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_desc_t *)data, sizeof(request) );
-
- count = request.count;
- order = DRM(order)( request.size );
+ count = request->count;
+ order = DRM(order)(request->size);
size = 1 << order;
- DRM_DEBUG( "count=%d, size=%d (%d), order=%d, queue_count=%d\n",
- request.count, request.size, size,
- order, dev->queue_count );
+ DRM_DEBUG( "count=%d, size=%d (%d), order=%d\n",
+ request->count, request->size, size, order );
if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER )
return DRM_ERR(EINVAL);
- if ( dev->queue_count )
- return DRM_ERR(EBUSY); /* Not while in use */
- alignment = (request.flags & _DRM_PAGE_ALIGN)
+ alignment = (request->flags & _DRM_PAGE_ALIGN)
? round_page(size) : size;
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
total = PAGE_SIZE << page_order;
- DRM_SPINLOCK( &dev->count_lock );
- if ( dev->buf_use ) {
- DRM_SPINUNLOCK( &dev->count_lock );
- return DRM_ERR(EBUSY);
- }
- atomic_inc( &dev->buf_alloc );
- DRM_SPINUNLOCK( &dev->count_lock );
-
DRM_LOCK;
entry = &dma->bufs[order];
if ( entry->buf_count ) {
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM); /* May only call once for each order */
}
- if (count < 0 || count > 4096) {
- DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
- return DRM_ERR(EINVAL);
- }
-
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
DRM_MEM_BUFS );
if ( !entry->buflist ) {
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM);
}
memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
@@ -569,7 +497,6 @@ int DRM(addbufs_pci)( DRM_IOCTL_ARGS )
count * sizeof(*entry->buflist),
DRM_MEM_BUFS );
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM);
}
memset( entry->seglist, 0, count * sizeof(*entry->seglist) );
@@ -587,7 +514,6 @@ int DRM(addbufs_pci)( DRM_IOCTL_ARGS )
count * sizeof(*entry->seglist),
DRM_MEM_SEGS );
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM);
}
@@ -622,16 +548,8 @@ int DRM(addbufs_pci)( DRM_IOCTL_ARGS )
buf->offset = (dma->byte_count + byte_count + offset);
buf->address = (void *)(page + offset);
buf->next = NULL;
- buf->waiting = 0;
buf->pending = 0;
- buf->dma_wait = 0;
- buf->pid = 0;
-#if __HAVE_DMA_HISTOGRAM
- buf->time_queued = 0;
- buf->time_dispatched = 0;
- buf->time_completed = 0;
- buf->time_freed = 0;
-#endif
+ buf->filp = NULL;
DRM_DEBUG( "buffer %d @ %p\n",
entry->buf_count, buf->address );
}
@@ -647,7 +565,6 @@ int DRM(addbufs_pci)( DRM_IOCTL_ARGS )
/* Free the entry because it isn't valid */
DRM(cleanup_buf_error)(entry);
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM);
}
dma->buflist = temp_buflist;
@@ -661,31 +578,20 @@ int DRM(addbufs_pci)( DRM_IOCTL_ARGS )
dma->page_count += entry->seg_count << page_order;
dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
-#if __HAVE_DMA_FREELIST
- DRM(freelist_create)( &entry->freelist, entry->buf_count );
- for ( i = 0 ; i < entry->buf_count ; i++ ) {
- DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] );
- }
-#endif
DRM_UNLOCK;
- request.count = entry->buf_count;
- request.size = size;
-
- DRM_COPY_TO_USER_IOCTL( (drm_buf_desc_t *)data, request, sizeof(request) );
+ request->count = entry->buf_count;
+ request->size = size;
- atomic_dec( &dev->buf_alloc );
return 0;
}
#endif /* __HAVE_PCI_DMA */
#if __REALLY_HAVE_SG
-int DRM(addbufs_sg)( DRM_IOCTL_ARGS )
+static int DRM(addbufs_sg)(drm_device_t *dev, drm_buf_desc_t *request)
{
- DRM_DEVICE;
drm_device_dma_t *dma = dev->dma;
- drm_buf_desc_t request;
drm_buf_entry_t *entry;
drm_buf_t *buf;
unsigned long offset;
@@ -700,21 +606,17 @@ int DRM(addbufs_sg)( DRM_IOCTL_ARGS )
int i;
drm_buf_t **temp_buflist;
- if ( !dma ) return DRM_ERR(EINVAL);
-
- DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_desc_t *)data, sizeof(request) );
-
- count = request.count;
- order = DRM(order)( request.size );
+ count = request->count;
+ order = DRM(order)(request->size);
size = 1 << order;
- alignment = (request.flags & _DRM_PAGE_ALIGN)
+ alignment = (request->flags & _DRM_PAGE_ALIGN)
? round_page(size) : size;
page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
total = PAGE_SIZE << page_order;
byte_count = 0;
- agp_offset = request.agp_start;
+ agp_offset = request->agp_start;
DRM_DEBUG( "count: %d\n", count );
DRM_DEBUG( "order: %d\n", order );
@@ -726,35 +628,18 @@ int DRM(addbufs_sg)( DRM_IOCTL_ARGS )
if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER )
return DRM_ERR(EINVAL);
- if ( dev->queue_count ) return DRM_ERR(EBUSY); /* Not while in use */
-
- DRM_SPINLOCK( &dev->count_lock );
- if ( dev->buf_use ) {
- DRM_SPINUNLOCK( &dev->count_lock );
- return DRM_ERR(EBUSY);
- }
- atomic_inc( &dev->buf_alloc );
- DRM_SPINUNLOCK( &dev->count_lock );
DRM_LOCK;
entry = &dma->bufs[order];
if ( entry->buf_count ) {
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM); /* May only call once for each order */
}
- if (count < 0 || count > 4096) {
- DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
- return DRM_ERR(EINVAL);
- }
-
entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
DRM_MEM_BUFS );
if ( !entry->buflist ) {
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM);
}
memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
@@ -775,10 +660,8 @@ int DRM(addbufs_sg)( DRM_IOCTL_ARGS )
buf->bus_address = agp_offset + offset;
buf->address = (void *)(agp_offset + offset + dev->sg->handle);
buf->next = NULL;
- buf->waiting = 0;
buf->pending = 0;
- buf->dma_wait = 0;
- buf->pid = 0;
+ buf->filp = NULL;
buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T);
buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T),
@@ -788,18 +671,11 @@ int DRM(addbufs_sg)( DRM_IOCTL_ARGS )
entry->buf_count = count;
DRM(cleanup_buf_error)(entry);
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM);
}
memset( buf->dev_private, 0, buf->dev_priv_size );
-# if __HAVE_DMA_HISTOGRAM
- buf->time_queued = 0;
- buf->time_dispatched = 0;
- buf->time_completed = 0;
- buf->time_freed = 0;
-# endif
DRM_DEBUG( "buffer %d @ %p\n",
entry->buf_count, buf->address );
@@ -819,7 +695,6 @@ int DRM(addbufs_sg)( DRM_IOCTL_ARGS )
/* Free the entry because it isn't valid */
DRM(cleanup_buf_error)(entry);
DRM_UNLOCK;
- atomic_dec( &dev->buf_alloc );
return DRM_ERR(ENOMEM);
}
dma->buflist = temp_buflist;
@@ -834,47 +709,65 @@ int DRM(addbufs_sg)( DRM_IOCTL_ARGS )
DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
-#if __HAVE_DMA_FREELIST
- DRM(freelist_create)( &entry->freelist, entry->buf_count );
- for ( i = 0 ; i < entry->buf_count ; i++ ) {
- DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] );
- }
-#endif
DRM_UNLOCK;
- request.count = entry->buf_count;
- request.size = size;
-
- DRM_COPY_TO_USER_IOCTL( (drm_buf_desc_t *)data, request, sizeof(request) );
+ request->count = entry->buf_count;
+ request->size = size;
dma->flags = _DRM_DMA_USE_SG;
- atomic_dec( &dev->buf_alloc );
return 0;
}
#endif /* __REALLY_HAVE_SG */
int DRM(addbufs)( DRM_IOCTL_ARGS )
{
+ DRM_DEVICE;
drm_buf_desc_t request;
+ int err;
DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_desc_t *)data, sizeof(request) );
+ if (dev->dma == NULL)
+ return DRM_ERR(EINVAL);
+
+ if (request.count < 0 || request.count > 4096)
+ return DRM_ERR(EINVAL);
+
+ DRM_SPINLOCK(&dev->count_lock);
+ if (dev->buf_use) {
+ DRM_SPINUNLOCK(&dev->count_lock);
+ return DRM_ERR(EBUSY);
+ }
+ /* dev->buf_alloc acts as a lock to prevent infobufs/mapbufs from
+ * trying to read from the dma->bufs while buffers are being allocated */
+ dev->buf_alloc++;
+ DRM_SPINUNLOCK(&dev->count_lock);
+
+
#if __REALLY_HAVE_AGP
if ( request.flags & _DRM_AGP_BUFFER )
- return DRM(addbufs_agp)( kdev, cmd, data, flags, p );
+ err = DRM(addbufs_agp)(dev, &request);
else
#endif
#if __REALLY_HAVE_SG
if ( request.flags & _DRM_SG_BUFFER )
- return DRM(addbufs_sg)( kdev, cmd, data, flags, p );
+ err = DRM(addbufs_sg)(dev, &request);
else
#endif
#if __HAVE_PCI_DMA
- return DRM(addbufs_pci)( kdev, cmd, data, flags, p );
+ err = DRM(addbufs_pci)(dev, &request);
#else
- return DRM_ERR(EINVAL);
+ err = DRM_ERR(EINVAL);
#endif
+
+ DRM_COPY_TO_USER_IOCTL((drm_buf_desc_t *)data, request, sizeof(request));
+
+ DRM_SPINLOCK(&dev->count_lock);
+ dev->buf_alloc--;
+ DRM_SPINUNLOCK(&dev->count_lock);
+
+ return err;
}
int DRM(infobufs)( DRM_IOCTL_ARGS )
@@ -888,7 +781,7 @@ int DRM(infobufs)( DRM_IOCTL_ARGS )
if ( !dma ) return DRM_ERR(EINVAL);
DRM_SPINLOCK( &dev->count_lock );
- if ( atomic_read( &dev->buf_alloc ) ) {
+ if (dev->buf_alloc != 0) {
DRM_SPINUNLOCK( &dev->count_lock );
return DRM_ERR(EBUSY);
}
@@ -906,21 +799,15 @@ int DRM(infobufs)( DRM_IOCTL_ARGS )
if ( request.count >= count ) {
for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) {
if ( dma->bufs[i].buf_count ) {
- drm_buf_desc_t *to = &request.list[count];
- drm_buf_entry_t *from = &dma->bufs[i];
- drm_freelist_t *list = &dma->bufs[i].freelist;
- if ( DRM_COPY_TO_USER( &to->count,
- &from->buf_count,
- sizeof(from->buf_count) ) ||
- DRM_COPY_TO_USER( &to->size,
- &from->buf_size,
- sizeof(from->buf_size) ) ||
- DRM_COPY_TO_USER( &to->low_mark,
- &list->low_mark,
- sizeof(list->low_mark) ) ||
- DRM_COPY_TO_USER( &to->high_mark,
- &list->high_mark,
- sizeof(list->high_mark) ) )
+ drm_buf_desc_t from;
+
+ from.count = dma->bufs[i].buf_count;
+ from.size = dma->bufs[i].buf_size;
+ from.low_mark = dma->bufs[i].freelist.low_mark;
+ from.high_mark = dma->bufs[i].freelist.high_mark;
+
+ if (DRM_COPY_TO_USER(&request.list[count], &from,
+ sizeof(drm_buf_desc_t)) != 0)
return DRM_ERR(EFAULT);
DRM_DEBUG( "%d %d %d %d %d\n",
@@ -995,9 +882,9 @@ int DRM(freebufs)( DRM_IOCTL_ARGS )
return DRM_ERR(EINVAL);
}
buf = dma->buflist[idx];
- if ( buf->pid != DRM_CURRENTPID ) {
- DRM_ERROR( "Process %d freeing buffer owned by %d\n",
- DRM_CURRENTPID, buf->pid );
+ if ( buf->filp != filp ) {
+ DRM_ERROR("Process %d freeing buffer not owned\n",
+ DRM_CURRENTPID);
return DRM_ERR(EINVAL);
}
DRM(free_buffer)( dev, buf );
@@ -1031,7 +918,7 @@ int DRM(mapbufs)( DRM_IOCTL_ARGS )
if ( !dma ) return DRM_ERR(EINVAL);
DRM_SPINLOCK( &dev->count_lock );
- if ( atomic_read( &dev->buf_alloc ) ) {
+ if (dev->buf_alloc != 0) {
DRM_SPINUNLOCK( &dev->count_lock );
return DRM_ERR(EBUSY);
}
OpenPOWER on IntegriCloud