summaryrefslogtreecommitdiff
path: root/bsd
diff options
context:
space:
mode:
authorEric Anholt <anholt@freebsd.org>2003-10-02 04:48:54 +0000
committerEric Anholt <anholt@freebsd.org>2003-10-02 04:48:54 +0000
commita6b84f73e18d88524a906a319c6c8e3c44bd7dea (patch)
treebaef00cdac4a6e1fd77215e22d9e12ba92ed444a /bsd
parent4dee75ff58a50559cb8a92c276c0b952c2776154 (diff)
Mostly whitespace cleanups and style(9) fixes focused on "if(" -> "if ("
Change some nearby memset()s to bzero()s or to calloc allocations to take advantage of M_ZERO). Reverse some error tests to reduce high levels of indentation. Move the sg_cleanup() call out of the maplist loop in DRM(takedown)-- I can't see any need for it to be inside.
Diffstat (limited to 'bsd')
-rw-r--r--bsd/drm_bufs.h105
-rw-r--r--bsd/drm_context.h112
-rw-r--r--bsd/drm_dma.h5
-rw-r--r--bsd/drm_drv.h57
-rw-r--r--bsd/drm_ioctl.h3
5 files changed, 129 insertions, 153 deletions
diff --git a/bsd/drm_bufs.h b/bsd/drm_bufs.h
index d718eddd..93189f92 100644
--- a/bsd/drm_bufs.h
+++ b/bsd/drm_bufs.h
@@ -171,12 +171,11 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
return DRM_ERR(EINVAL);
}
- list = DRM(alloc)(sizeof(*list), DRM_MEM_MAPS);
- if(!list) {
+ list = DRM(calloc)(1, sizeof(*list), DRM_MEM_MAPS);
+ if (list == NULL) {
DRM(free)(map, sizeof(*map), DRM_MEM_MAPS);
return DRM_ERR(EINVAL);
}
- memset(list, 0, sizeof(*list));
list->map = map;
DRM_LOCK;
@@ -210,68 +209,65 @@ int DRM(rmmap)( DRM_IOCTL_ARGS )
drm_map_list_entry_t *list;
drm_local_map_t *map;
drm_map_t request;
- int found_maps = 0;
DRM_COPY_FROM_USER_IOCTL( request, (drm_map_t *)data, sizeof(request) );
DRM_LOCK;
TAILQ_FOREACH(list, dev->maplist, link) {
map = list->map;
- if(map->handle == request.handle &&
- map->flags & _DRM_REMOVABLE) break;
+ if (map->handle == request.handle &&
+ map->flags & _DRM_REMOVABLE)
+ break;
}
- /* List has wrapped around to the head pointer, or its empty we didn't
- * find anything.
- */
- if(list == NULL) {
+ /* No match found. */
+ if (list == NULL) {
DRM_UNLOCK;
return DRM_ERR(EINVAL);
}
TAILQ_REMOVE(dev->maplist, list, link);
DRM(free)(list, sizeof(*list), DRM_MEM_MAPS);
-
- if(!found_maps) {
- switch (map->type) {
- case _DRM_REGISTERS:
- case _DRM_FRAME_BUFFER:
+ switch (map->type) {
+ case _DRM_REGISTERS:
+ case _DRM_FRAME_BUFFER:
#if __REALLY_HAVE_MTRR
- if (map->mtrr >= 0) {
- int retcode;
+ if (map->mtrr >= 0) {
+ int retcode;
#ifdef __FreeBSD__
- int act;
- struct mem_range_desc mrdesc;
- mrdesc.mr_base = map->offset;
- mrdesc.mr_len = map->size;
- mrdesc.mr_flags = MDF_WRITECOMBINE;
- act = MEMRANGE_SET_REMOVE;
- bcopy(DRIVER_NAME, &mrdesc.mr_owner, strlen(DRIVER_NAME));
- retcode = mem_range_attr_set(&mrdesc, &act);
+ int act;
+ struct mem_range_desc mrdesc;
+ mrdesc.mr_base = map->offset;
+ mrdesc.mr_len = map->size;
+ mrdesc.mr_flags = MDF_WRITECOMBINE;
+ act = MEMRANGE_SET_REMOVE;
+ bcopy(DRIVER_NAME, &mrdesc.mr_owner,
+ strlen(DRIVER_NAME));
+ retcode = mem_range_attr_set(&mrdesc, &act);
#elif defined __NetBSD__
- struct mtrr mtrrmap;
- int one = 1;
- mtrrmap.base = map->offset;
- mtrrmap.len = map->size;
- mtrrmap.type = 0;
- mtrrmap.flags = 0;
- mtrrmap.owner = p->p_pid;
- retcode = mtrr_set( &mtrrmap, &one, p, MTRR_GETSET_KERNEL);
- DRM_DEBUG("mtrr_del = %d\n", retcode);
-#endif
- }
+ struct mtrr mtrrmap;
+ int one = 1;
+ mtrrmap.base = map->offset;
+ mtrrmap.len = map->size;
+ mtrrmap.type = 0;
+ mtrrmap.flags = 0;
+ mtrrmap.owner = p->p_pid;
+ retcode = mtrr_set(&mtrrmap, &one, p,
+ MTRR_GETSET_KERNEL);
+ DRM_DEBUG("mtrr_del = %d\n", retcode);
#endif
- DRM(ioremapfree)( map );
- break;
- case _DRM_SHM:
- DRM(free)( map->handle, map->size, DRM_MEM_SAREA );
- break;
- case _DRM_AGP:
- case _DRM_SCATTER_GATHER:
- break;
}
- DRM(free)(map, sizeof(*map), DRM_MEM_MAPS);
+#endif
+ DRM(ioremapfree)(map);
+ break;
+ case _DRM_SHM:
+ DRM(free)(map->handle, map->size, DRM_MEM_SAREA);
+ break;
+ case _DRM_AGP:
+ case _DRM_SCATTER_GATHER:
+ break;
}
+ DRM(free)(map, sizeof(*map), DRM_MEM_MAPS);
DRM_UNLOCK;
return 0;
}
@@ -392,16 +388,15 @@ static int DRM(addbufs_agp)(drm_device_t *dev, drm_buf_desc_t *request)
buf->filp = NULL;
buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T);
- buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T),
- DRM_MEM_BUFS );
- if(!buf->dev_private) {
+ buf->dev_private = DRM(calloc)(1, buf->dev_priv_size,
+ DRM_MEM_BUFS);
+ if (buf->dev_private == NULL) {
/* Set count correctly so we free the proper amount. */
entry->buf_count = count;
DRM(cleanup_buf_error)(dev, entry);
DRM_UNLOCK;
return DRM_ERR(ENOMEM);
}
- memset( buf->dev_private, 0, buf->dev_priv_size );
offset += alignment;
entry->buf_count++;
@@ -415,7 +410,7 @@ static int DRM(addbufs_agp)(drm_device_t *dev, drm_buf_desc_t *request)
(dma->buf_count + entry->buf_count)
* sizeof(*dma->buflist),
DRM_MEM_BUFS );
- if(!temp_buflist) {
+ if (temp_buflist == NULL) {
/* Free the entry because it isn't valid */
DRM(cleanup_buf_error)(dev, entry);
DRM_UNLOCK;
@@ -705,9 +700,9 @@ static int DRM(addbufs_sg)(drm_device_t *dev, drm_buf_desc_t *request)
buf->filp = NULL;
buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T);
- buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T),
- DRM_MEM_BUFS );
- if(!buf->dev_private) {
+ buf->dev_private = DRM(calloc)(1, buf->dev_priv_size,
+ DRM_MEM_BUFS);
+ if (buf->dev_private == NULL) {
/* Set count correctly so we free the proper amount. */
entry->buf_count = count;
DRM(cleanup_buf_error)(dev, entry);
@@ -715,8 +710,6 @@ static int DRM(addbufs_sg)(drm_device_t *dev, drm_buf_desc_t *request)
return DRM_ERR(ENOMEM);
}
- memset( buf->dev_private, 0, buf->dev_priv_size );
-
DRM_DEBUG( "buffer %d @ %p\n",
entry->buf_count, buf->address );
@@ -732,7 +725,7 @@ static int DRM(addbufs_sg)(drm_device_t *dev, drm_buf_desc_t *request)
(dma->buf_count + entry->buf_count)
* sizeof(*dma->buflist),
DRM_MEM_BUFS );
- if(!temp_buflist) {
+ if (temp_buflist == NULL) {
/* Free the entry because it isn't valid */
DRM(cleanup_buf_error)(dev, entry);
DRM_UNLOCK;
diff --git a/bsd/drm_context.h b/bsd/drm_context.h
index a6116634..04bb005f 100644
--- a/bsd/drm_context.h
+++ b/bsd/drm_context.h
@@ -42,70 +42,68 @@
void DRM(ctxbitmap_free)( drm_device_t *dev, int ctx_handle )
{
- if ( ctx_handle < 0 ) goto failed;
- if ( !dev->ctx_bitmap ) goto failed;
-
- if ( ctx_handle < DRM_MAX_CTXBITMAP ) {
- DRM_LOCK;
- clear_bit( ctx_handle, dev->ctx_bitmap );
- dev->context_sareas[ctx_handle] = NULL;
- DRM_UNLOCK;
+ if (ctx_handle < 0 || ctx_handle >= DRM_MAX_CTXBITMAP ||
+ dev->ctx_bitmap == NULL) {
+ DRM_ERROR("Attempt to free invalid context handle: %d\n",
+ ctx_handle);
return;
}
-failed:
- DRM_ERROR( "Attempt to free invalid context handle: %d\n",
- ctx_handle );
- return;
+
+ DRM_LOCK;
+ clear_bit(ctx_handle, dev->ctx_bitmap);
+ dev->context_sareas[ctx_handle] = NULL;
+ DRM_UNLOCK;
+ return;
}
int DRM(ctxbitmap_next)( drm_device_t *dev )
{
int bit;
- if(!dev->ctx_bitmap) return -1;
+ if (dev->ctx_bitmap == NULL)
+ return -1;
DRM_LOCK;
bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP );
- if ( bit < DRM_MAX_CTXBITMAP ) {
- set_bit( bit, dev->ctx_bitmap );
- DRM_DEBUG( "drm_ctxbitmap_next bit : %d\n", bit );
- if((bit+1) > dev->max_context) {
- dev->max_context = (bit+1);
- if(dev->context_sareas) {
- drm_local_map_t **ctx_sareas;
-
- ctx_sareas = DRM(realloc)(dev->context_sareas,
- (dev->max_context - 1) *
- sizeof(*dev->context_sareas),
- dev->max_context *
- sizeof(*dev->context_sareas),
- DRM_MEM_MAPS);
- if(!ctx_sareas) {
- clear_bit(bit, dev->ctx_bitmap);
- DRM_UNLOCK;
- return -1;
- }
- dev->context_sareas = ctx_sareas;
- dev->context_sareas[bit] = NULL;
- } else {
- /* max_context == 1 at this point */
- dev->context_sareas = DRM(alloc)(
- dev->max_context *
- sizeof(*dev->context_sareas),
- DRM_MEM_MAPS);
- if(!dev->context_sareas) {
- clear_bit(bit, dev->ctx_bitmap);
- DRM_UNLOCK;
- return -1;
- }
- dev->context_sareas[bit] = NULL;
+ if (bit >= DRM_MAX_CTXBITMAP) {
+ DRM_UNLOCK;
+ return -1;
+ }
+
+ set_bit(bit, dev->ctx_bitmap);
+ DRM_DEBUG("drm_ctxbitmap_next bit : %d\n", bit);
+ if ((bit+1) > dev->max_context) {
+ dev->max_context = (bit+1);
+ if (dev->context_sareas != NULL) {
+ drm_local_map_t **ctx_sareas;
+
+ ctx_sareas = DRM(realloc)(dev->context_sareas,
+ (dev->max_context - 1) *
+ sizeof(*dev->context_sareas),
+ dev->max_context *
+ sizeof(*dev->context_sareas),
+ DRM_MEM_MAPS);
+ if (ctx_sareas == NULL) {
+ clear_bit(bit, dev->ctx_bitmap);
+ DRM_UNLOCK;
+ return -1;
}
+ dev->context_sareas = ctx_sareas;
+ dev->context_sareas[bit] = NULL;
+ } else {
+ /* max_context == 1 at this point */
+ dev->context_sareas = DRM(alloc)(dev->max_context *
+ sizeof(*dev->context_sareas), DRM_MEM_MAPS);
+ if (dev->context_sareas == NULL) {
+ clear_bit(bit, dev->ctx_bitmap);
+ DRM_UNLOCK;
+ return -1;
+ }
+ dev->context_sareas[bit] = NULL;
}
- DRM_UNLOCK;
- return bit;
}
DRM_UNLOCK;
- return -1;
+ return bit;
}
int DRM(ctxbitmap_init)( drm_device_t *dev )
@@ -114,13 +112,12 @@ int DRM(ctxbitmap_init)( drm_device_t *dev )
int temp;
DRM_LOCK;
- dev->ctx_bitmap = (atomic_t *) DRM(alloc)( PAGE_SIZE,
- DRM_MEM_CTXBITMAP );
+ dev->ctx_bitmap = (atomic_t *)DRM(calloc)(1, PAGE_SIZE,
+ DRM_MEM_CTXBITMAP);
if ( dev->ctx_bitmap == NULL ) {
DRM_UNLOCK;
return DRM_ERR(ENOMEM);
}
- memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE );
dev->context_sareas = NULL;
dev->max_context = -1;
DRM_UNLOCK;
@@ -136,10 +133,9 @@ int DRM(ctxbitmap_init)( drm_device_t *dev )
void DRM(ctxbitmap_cleanup)( drm_device_t *dev )
{
DRM_LOCK;
- if( dev->context_sareas ) DRM(free)( dev->context_sareas,
- sizeof(*dev->context_sareas) *
- dev->max_context,
- DRM_MEM_MAPS );
+ if (dev->context_sareas != NULL)
+ DRM(free)(dev->context_sareas, sizeof(*dev->context_sareas) *
+ dev->max_context, DRM_MEM_MAPS);
DRM(free)( (void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP );
DRM_UNLOCK;
}
@@ -186,7 +182,7 @@ int DRM(setsareactx)( DRM_IOCTL_ARGS )
DRM_LOCK;
TAILQ_FOREACH(list, dev->maplist, link) {
map=list->map;
- if(map->handle == request.handle) {
+ if (map->handle == request.handle) {
if (dev->max_context < 0)
goto bad;
if (request.ctx_id >= (unsigned) dev->max_context)
@@ -248,7 +244,7 @@ int DRM(resctx)( DRM_IOCTL_ARGS )
DRM_COPY_FROM_USER_IOCTL( res, (drm_ctx_res_t *)data, sizeof(res) );
if ( res.count >= DRM_RESERVED_CONTEXTS ) {
- memset( &ctx, 0, sizeof(ctx) );
+ bzero(&ctx, sizeof(ctx));
for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
ctx.handle = i;
if ( DRM_COPY_TO_USER( &res.contexts[i],
diff --git a/bsd/drm_dma.h b/bsd/drm_dma.h
index ec17d557..21036f71 100644
--- a/bsd/drm_dma.h
+++ b/bsd/drm_dma.h
@@ -156,10 +156,7 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
{
int retcode;
- if ( !irq )
- return DRM_ERR(EINVAL);
-
- if (dev->dev_private == NULL)
+ if ( irq == 0 || dev->dev_private == NULL)
return DRM_ERR(EINVAL);
DRM_LOCK;
diff --git a/bsd/drm_drv.h b/bsd/drm_drv.h
index 8ff78b7b..fd37d9e0 100644
--- a/bsd/drm_drv.h
+++ b/bsd/drm_drv.h
@@ -255,9 +255,9 @@ static int DRM(detach)(device_t dev)
}
static device_method_t DRM(methods)[] = {
/* Device interface */
- DEVMETHOD(device_probe, DRM( probe)),
- DEVMETHOD(device_attach, DRM( attach)),
- DEVMETHOD(device_detach, DRM( detach)),
+ DEVMETHOD(device_probe, DRM(probe)),
+ DEVMETHOD(device_attach, DRM(attach)),
+ DEVMETHOD(device_detach, DRM(detach)),
{ 0, 0 }
};
@@ -473,10 +473,9 @@ static int DRM(setup)( drm_device_t *dev )
dev->magiclist[i].tail = NULL;
}
- dev->maplist = DRM(alloc)(sizeof(*dev->maplist),
- DRM_MEM_MAPS);
- if(dev->maplist == NULL) return DRM_ERR(ENOMEM);
- memset(dev->maplist, 0, sizeof(*dev->maplist));
+ dev->maplist = DRM(calloc)(1, sizeof(*dev->maplist), DRM_MEM_MAPS);
+ if (dev->maplist == NULL)
+ return DRM_ERR(ENOMEM);
TAILQ_INIT(dev->maplist);
dev->lock.hw_lock = NULL;
@@ -514,7 +513,8 @@ static int DRM(takedown)( drm_device_t *dev )
DRIVER_PRETAKEDOWN();
#if __HAVE_DMA_IRQ
- if ( dev->irq ) DRM(irq_uninstall)( dev );
+ if (dev->irq != 0)
+ DRM(irq_uninstall)( dev );
#endif
DRM_LOCK;
@@ -557,8 +557,14 @@ static int DRM(takedown)( drm_device_t *dev )
dev->agp->enabled = 0;
}
#endif
+#if __REALLY_HAVE_SG
+ if (dev->sg != NULL) {
+ DRM(sg_cleanup)(dev->sg);
+ dev->sg = NULL;
+ }
+#endif
- if( dev->maplist ) {
+ if (dev->maplist != NULL) {
while ((list=TAILQ_FIRST(dev->maplist))) {
map = list->map;
switch ( map->type ) {
@@ -599,21 +605,11 @@ static int DRM(takedown)( drm_device_t *dev )
break;
case _DRM_AGP:
+ case _DRM_SCATTER_GATHER:
/* Do nothing here, because this is all
- * handled in the AGP/GART driver.
+ * handled in the AGP/GART/SG functions.
*/
break;
- case _DRM_SCATTER_GATHER:
- /* Handle it, but do nothing, if REALLY_HAVE_SG
- * isn't defined.
- */
-#if __REALLY_HAVE_SG
- if(dev->sg) {
- DRM(sg_cleanup)(dev->sg);
- dev->sg = NULL;
- }
-#endif
- break;
}
TAILQ_REMOVE(dev->maplist, list, link);
DRM(free)(list, sizeof(*list), DRM_MEM_MAPS);
@@ -720,7 +716,7 @@ static int DRM(init)( device_t nbdev )
#if __HAVE_CTX_BITMAP
retcode = DRM(ctxbitmap_init)( dev );
- if( retcode ) {
+ if (retcode != 0) {
DRM_ERROR( "Cannot allocate memory for context bitmap.\n" );
DRM(sysctl_cleanup)( dev );
#ifdef __FreeBSD__
@@ -885,7 +881,7 @@ int DRM(close)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p)
DRM_DEBUG("Process %d dead, freeing lock for context %d\n",
DRM_CURRENTPID,
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
-#if HAVE_DRIVER_RELEASE
+#if __HAVE_RELEASE
DRIVER_RELEASE();
#endif
DRM(lock_free)(dev,
@@ -914,9 +910,6 @@ int DRM(close)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p)
break; /* Got lock */
}
/* Contention */
-#if 0
- atomic_inc( &dev->total_sleeps );
-#endif
retcode = tsleep((void *)&dev->lock.lock_queue,
PZERO|PCATCH,
"drmlk2",
@@ -924,7 +917,7 @@ int DRM(close)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p)
if (retcode)
break;
}
- if( !retcode ) {
+ if (retcode == 0) {
DRIVER_RELEASE();
DRM(lock_free)( dev, &dev->lock.hw_lock->lock,
DRM_KERNEL_CONTEXT );
@@ -1131,13 +1124,9 @@ int DRM(unlock)( DRM_IOCTL_ARGS )
DRM(dma_schedule)( dev, 1 );
#endif
- /* FIXME: Do we ever really need to check this?
- */
- if ( 1 /* !dev->context_flag */ ) {
- if ( DRM(lock_free)( dev, &dev->lock.hw_lock->lock,
- DRM_KERNEL_CONTEXT ) ) {
- DRM_ERROR( "\n" );
- }
+ if ( DRM(lock_free)( dev, &dev->lock.hw_lock->lock,
+ DRM_KERNEL_CONTEXT ) ) {
+ DRM_ERROR( "\n" );
}
return 0;
diff --git a/bsd/drm_ioctl.h b/bsd/drm_ioctl.h
index 33146bb5..b9598b4e 100644
--- a/bsd/drm_ioctl.h
+++ b/bsd/drm_ioctl.h
@@ -113,7 +113,8 @@ int DRM(setunique)( DRM_IOCTL_ARGS )
dev->unique_len = u.unique_len;
dev->unique = DRM(alloc)(u.unique_len + 1, DRM_MEM_DRIVER);
- if(!dev->unique) return DRM_ERR(ENOMEM);
+ if (dev->unique == NULL)
+ return DRM_ERR(ENOMEM);
if (DRM_COPY_FROM_USER(dev->unique, u.unique, dev->unique_len))
return DRM_ERR(EFAULT);