diff --git a/bsd-core/drm_os_freebsd.h b/bsd-core/drm_os_freebsd.h index 09ba2805..e220604a 100644 --- a/bsd-core/drm_os_freebsd.h +++ b/bsd-core/drm_os_freebsd.h @@ -45,43 +45,43 @@ typedef u_int32_t cycles_t; typedef u_int32_t spinlock_t; #define atomic_set(p, v) (*(p) = (v)) #define atomic_read(p) (*(p)) -#define atomic_inc(p) atomic_add_int(p, 1) -#define atomic_dec(p) atomic_subtract_int(p, 1) -#define atomic_add(n, p) atomic_add_int(p, n) -#define atomic_sub(n, p) atomic_subtract_int(p, n) +#define atomic_inc(p) atomic_add_long(p, 1) +#define atomic_dec(p) atomic_subtract_long(p, 1) +#define atomic_add(n, p) atomic_add_long(p, n) +#define atomic_sub(n, p) atomic_subtract_long(p, n) /* Fake this */ -static __inline u_int32_t -test_and_set_bit(int b, volatile u_int32_t *p) +static __inline unsigned long +test_and_set_bit(int b, volatile unsigned long *p) { int s = splhigh(); - u_int32_t m = 1<> 5), 1 << (b & 0x1f)); + atomic_clear_long(p + (b >> 5), 1 << (b & 0x1f)); } static __inline void -set_bit(int b, volatile u_int32_t *p) +set_bit(int b, volatile unsigned long *p) { - atomic_set_int(p + (b >> 5), 1 << (b & 0x1f)); + atomic_set_long(p + (b >> 5), 1 << (b & 0x1f)); } static __inline int -test_bit(int b, volatile u_int32_t *p) +test_bit(int b, volatile unsigned long *p) { return p[b >> 5] & (1 << (b & 0x1f)); } static __inline int -find_first_zero_bit(volatile u_int32_t *p, int max) +find_first_zero_bit(volatile unsigned long *p, int max) { int b; @@ -128,8 +128,6 @@ find_first_zero_bit(volatile u_int32_t *p, int max) /* Redefinitions to make templating easy */ #define wait_queue_head_t int -#define cycles_t struct timespec - /* Macros to make printf easier */ #define DRM_ERROR(fmt, arg...) \ diff --git a/bsd/drm_os_freebsd.h b/bsd/drm_os_freebsd.h index 09ba2805..e220604a 100644 --- a/bsd/drm_os_freebsd.h +++ b/bsd/drm_os_freebsd.h @@ -45,43 +45,43 @@ typedef u_int32_t cycles_t; typedef u_int32_t spinlock_t; #define atomic_set(p, v) (*(p) = (v)) #define atomic_read(p) (*(p)) -#define atomic_inc(p) atomic_add_int(p, 1) -#define atomic_dec(p) atomic_subtract_int(p, 1) -#define atomic_add(n, p) atomic_add_int(p, n) -#define atomic_sub(n, p) atomic_subtract_int(p, n) +#define atomic_inc(p) atomic_add_long(p, 1) +#define atomic_dec(p) atomic_subtract_long(p, 1) +#define atomic_add(n, p) atomic_add_long(p, n) +#define atomic_sub(n, p) atomic_subtract_long(p, n) /* Fake this */ -static __inline u_int32_t -test_and_set_bit(int b, volatile u_int32_t *p) +static __inline unsigned long +test_and_set_bit(int b, volatile unsigned long *p) { int s = splhigh(); - u_int32_t m = 1<> 5), 1 << (b & 0x1f)); + atomic_clear_long(p + (b >> 5), 1 << (b & 0x1f)); } static __inline void -set_bit(int b, volatile u_int32_t *p) +set_bit(int b, volatile unsigned long *p) { - atomic_set_int(p + (b >> 5), 1 << (b & 0x1f)); + atomic_set_long(p + (b >> 5), 1 << (b & 0x1f)); } static __inline int -test_bit(int b, volatile u_int32_t *p) +test_bit(int b, volatile unsigned long *p) { return p[b >> 5] & (1 << (b & 0x1f)); } static __inline int -find_first_zero_bit(volatile u_int32_t *p, int max) +find_first_zero_bit(volatile unsigned long *p, int max) { int b; @@ -128,8 +128,6 @@ find_first_zero_bit(volatile u_int32_t *p, int max) /* Redefinitions to make templating easy */ #define wait_queue_head_t int -#define cycles_t struct timespec - /* Macros to make printf easier */ #define DRM_ERROR(fmt, arg...) \ diff --git a/linux-core/drm_auth.c b/linux-core/drm_auth.c index 252cd442..17692470 100644 --- a/linux-core/drm_auth.c +++ b/linux-core/drm_auth.c @@ -172,5 +172,5 @@ int DRM(authmagic)(DRM_OS_IOCTL) DRM(remove_magic)(dev, auth.magic); return 0; } - return -EINVAL; + DRM_OS_RETURN(EINVAL); } diff --git a/linux-core/drm_bufs.c b/linux-core/drm_bufs.c index 7439e8b8..fcdd4975 100644 --- a/linux-core/drm_bufs.c +++ b/linux-core/drm_bufs.c @@ -82,20 +82,20 @@ int DRM(addmap)( DRM_OS_IOCTL ) #endif #ifdef __linux__ - if ( !(filp->f_mode & 3) ) return -EACCES; /* Require read/write */ + if ( !(filp->f_mode & 3) ) #endif #ifdef __FreeBSD__ if (!(dev->flags & (FREAD|FWRITE))) - return EACCES; /* Require read/write */ #endif + DRM_OS_RETURN(EACCES); /* Require read/write */ map = (drm_map_t *) DRM(alloc)( sizeof(*map), DRM_MEM_MAPS ); if ( !map ) - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); if ( copy_from_user( map, (drm_map_t *)arg, sizeof(*map) ) ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EFAULT; + DRM_OS_RETURN(EFAULT); } /* Only allow shared memory to be removable since we only keep enough @@ -104,13 +104,13 @@ int DRM(addmap)( DRM_OS_IOCTL ) */ if ( (map->flags & _DRM_REMOVABLE) && map->type != _DRM_SHM ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } DRM_DEBUG( "offset = 0x%08lx, size = 0x%08lx, type = %d\n", map->offset, map->size, map->type ); if ( (map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK)) ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } map->mtrr = -1; map->handle = 0; @@ -125,7 +125,7 @@ int DRM(addmap)( DRM_OS_IOCTL ) #endif ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } #endif #ifdef __alpha__ @@ -147,7 +147,7 @@ int DRM(addmap)( DRM_OS_IOCTL ) map->size, DRM(order)( map->size ), map->handle ); if ( !map->handle ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } map->offset = (unsigned long)map->handle; if ( map->flags & _DRM_CONTAINS_LOCK ) { @@ -166,20 +166,20 @@ int DRM(addmap)( DRM_OS_IOCTL ) case _DRM_SCATTER_GATHER: if (!dev->sg) { DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } map->offset = map->offset + dev->sg->handle; break; default: DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } list = DRM(alloc)(sizeof(*list), DRM_MEM_MAPS); if(!list) { DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } memset(list, 0, sizeof(*list)); list->map = map; @@ -194,12 +194,12 @@ int DRM(addmap)( DRM_OS_IOCTL ) DRM_OS_UNLOCK; if ( copy_to_user( (drm_map_t *)arg, map, sizeof(*map) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ( map->type != _DRM_SHM ) { if ( copy_to_user( &((drm_map_t *)arg)->handle, &map->offset, sizeof(map->offset) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); } return 0; } @@ -212,8 +212,13 @@ int DRM(addmap)( DRM_OS_IOCTL ) int DRM(rmmap)( DRM_OS_IOCTL ) { DRM_OS_DEVICE; +#ifdef __linux__ struct list_head *list; drm_map_list_t *r_list; +#endif +#ifdef __FreeBSD__ + drm_map_list_entry_t *list; +#endif drm_vma_entry_t *pt, *prev; drm_map_t *map; drm_map_t request; @@ -221,10 +226,11 @@ int DRM(rmmap)( DRM_OS_IOCTL ) if (copy_from_user(&request, (drm_map_t *)arg, sizeof(request))) { - return -EFAULT; + DRM_OS_RETURN(EFAULT); } DRM_OS_LOCK; +#ifdef __linux__ list = &dev->maplist->head; list_for_each(list, &dev->maplist->head) { r_list = (drm_map_list_t *) list; @@ -239,10 +245,27 @@ int DRM(rmmap)( DRM_OS_IOCTL ) */ if(list == (&dev->maplist->head)) { DRM_OS_UNLOCK; - return -EINVAL; + DRM_OS_RETURN(EINVAL); } map = r_list->map; list_del(list); +#endif +#ifdef __FreeBSD__ + TAILQ_FOREACH(list, dev->maplist, link) { + map = list->map; + 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) { + DRM_OS_UNLOCK; + DRM_OS_RETURN(EINVAL); + } + TAILQ_REMOVE(dev->maplist, list, link); +#endif DRM(free)(list, sizeof(*list), DRM_MEM_MAPS); for (pt = dev->vmalist, prev = NULL; pt; prev = pt, pt = pt->next) { @@ -302,11 +325,11 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) int byte_count; int i; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); count = request.count; order = DRM(order)( request.size ); @@ -328,13 +351,15 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) DRM_DEBUG( "page_order: %d\n", page_order ); DRM_DEBUG( "total: %d\n", total ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL; - if ( dev->queue_count ) return -EBUSY; /* Not while in use */ + if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) + DRM_OS_RETURN(EINVAL); + if ( dev->queue_count ) + DRM_OS_RETURN(EBUSY); /* Not while in use */ spin_lock( &dev->count_lock ); if ( dev->buf_use ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); @@ -344,7 +369,7 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) if ( entry->buf_count ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; /* May only call once for each order */ + DRM_OS_RETURN(ENOMEM); /* May only call once for each order */ } entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), @@ -352,7 +377,7 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) if ( !entry->buflist ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } memset( entry->buflist, 0, count * sizeof(*entry->buflist) ); @@ -425,7 +450,7 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) request.size = size; if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); dma->flags = _DRM_DMA_USE_AGP; @@ -454,11 +479,11 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) int byte_count; int page_count; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); count = request.count; order = DRM(order)( request.size ); @@ -468,8 +493,10 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) request.count, request.size, size, order, dev->queue_count ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL; - if ( dev->queue_count ) return -EBUSY; /* Not while in use */ + if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) + DRM_OS_RETURN(EINVAL); + if ( dev->queue_count ) + DRM_OS_RETURN(EBUSY); /* Not while in use */ alignment = (request.flags & _DRM_PAGE_ALIGN) ? PAGE_ALIGN(size) : size; @@ -479,7 +506,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) spin_lock( &dev->count_lock ); if ( dev->buf_use ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); @@ -489,7 +516,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) if ( entry->buf_count ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; /* May only call once for each order */ + DRM_OS_RETURN(ENOMEM); /* May only call once for each order */ } entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), @@ -497,7 +524,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) if ( !entry->buflist ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } memset( entry->buflist, 0, count * sizeof(*entry->buflist) ); @@ -509,7 +536,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) DRM_MEM_BUFS ); DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } memset( entry->seglist, 0, count * sizeof(*entry->seglist) ); @@ -590,7 +617,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) request.size = size; if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); atomic_dec( &dev->buf_alloc ); return 0; @@ -616,11 +643,11 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) int byte_count; int i; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); count = request.count; order = DRM(order)( request.size ); @@ -642,13 +669,15 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) DRM_DEBUG( "page_order: %d\n", page_order ); DRM_DEBUG( "total: %d\n", total ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL; - if ( dev->queue_count ) return -EBUSY; /* Not while in use */ + if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) + DRM_OS_RETURN(EINVAL); + if ( dev->queue_count ) + DRM_OS_RETURN(EBUSY); /* Not while in use */ spin_lock( &dev->count_lock ); if ( dev->buf_use ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); @@ -658,7 +687,7 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) if ( entry->buf_count ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; /* May only call once for each order */ + DRM_OS_RETURN(ENOMEM); /* May only call once for each order */ } entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), @@ -666,7 +695,7 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) if ( !entry->buflist ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } memset( entry->buflist, 0, count * sizeof(*entry->buflist) ); @@ -739,7 +768,7 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) request.size = size; if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); dma->flags = _DRM_DMA_USE_SG; @@ -754,7 +783,7 @@ int DRM(addbufs)( DRM_OS_IOCTL ) if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); #if __REALLY_HAVE_AGP if ( request.flags & _DRM_AGP_BUFFER ) @@ -769,7 +798,7 @@ int DRM(addbufs)( DRM_OS_IOCTL ) #if __HAVE_PCI_DMA return DRM(addbufs_pci)( inode, filp, cmd, arg ); #else - return -EINVAL; + DRM_OS_RETURN(EINVAL); #endif } @@ -781,12 +810,12 @@ int DRM(infobufs)( DRM_OS_IOCTL ) int i; int count; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); spin_lock( &dev->count_lock ); if ( atomic_read( &dev->buf_alloc ) ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } ++dev->buf_use; /* Can't allocate more after this call */ spin_unlock( &dev->count_lock ); @@ -794,7 +823,7 @@ int DRM(infobufs)( DRM_OS_IOCTL ) if ( copy_from_user( &request, (drm_buf_info_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) { if ( dma->bufs[i].buf_count ) ++count; @@ -820,7 +849,7 @@ int DRM(infobufs)( DRM_OS_IOCTL ) copy_to_user( &to->high_mark, &list->high_mark, sizeof(list->high_mark) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d %d %d %d %d\n", i, @@ -837,7 +866,7 @@ int DRM(infobufs)( DRM_OS_IOCTL ) if ( copy_to_user( (drm_buf_info_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } @@ -850,23 +879,24 @@ int DRM(markbufs)( DRM_OS_IOCTL ) int order; drm_buf_entry_t *entry; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d, %d, %d\n", request.size, request.low_mark, request.high_mark ); order = DRM(order)( request.size ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL; + if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) + DRM_OS_RETURN(EINVAL); entry = &dma->bufs[order]; if ( request.low_mark < 0 || request.low_mark > entry->buf_count ) - return -EINVAL; + DRM_OS_RETURN(EINVAL); if ( request.high_mark < 0 || request.high_mark > entry->buf_count ) - return -EINVAL; + DRM_OS_RETURN(EINVAL); entry->freelist.low_mark = request.low_mark; entry->freelist.high_mark = request.high_mark; @@ -883,29 +913,29 @@ int DRM(freebufs)( DRM_OS_IOCTL ) int idx; drm_buf_t *buf; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_free_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d\n", request.count ); for ( i = 0 ; i < request.count ; i++ ) { if ( copy_from_user( &idx, &request.list[i], sizeof(idx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ( idx < 0 || idx >= dma->buf_count ) { DRM_ERROR( "Index %d (of %d max)\n", idx, dma->buf_count - 1 ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } buf = dma->buflist[idx]; if ( buf->pid != current->pid ) { DRM_ERROR( "Process %d freeing buffer owned by %d\n", current->pid, buf->pid ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } DRM(free_buffer)( dev, buf ); } @@ -924,19 +954,19 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) drm_buf_map_t request; int i; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); spin_lock( &dev->count_lock ); if ( atomic_read( &dev->buf_alloc ) ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } dev->buf_use++; /* Can't allocate more after this call */ spin_unlock( &dev->count_lock ); if ( copy_from_user( &request, (drm_buf_map_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ( request.count >= dma->buf_count ) { if ( (__HAVE_AGP && (dma->flags & _DRM_DMA_USE_AGP)) || @@ -1027,7 +1057,7 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) DRM_DEBUG( "%d buffers, retcode = %d\n", request.count, retcode ); if ( copy_to_user( (drm_buf_map_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return retcode; } diff --git a/linux-core/drm_context.c b/linux-core/drm_context.c index 4ac896ef..28b7e92a 100644 --- a/linux-core/drm_context.c +++ b/linux-core/drm_context.c @@ -44,10 +44,10 @@ void DRM(ctxbitmap_free)( drm_device_t *dev, int ctx_handle ) if ( !dev->ctx_bitmap ) goto failed; if ( ctx_handle < DRM_MAX_CTXBITMAP ) { - down(&dev->struct_sem); + DRM_OS_LOCK; clear_bit( ctx_handle, dev->ctx_bitmap ); dev->context_sareas[ctx_handle] = NULL; - up(&dev->struct_sem); + DRM_OS_UNLOCK; return; } failed: @@ -62,7 +62,7 @@ int DRM(ctxbitmap_next)( drm_device_t *dev ) if(!dev->ctx_bitmap) return -1; - down(&dev->struct_sem); + DRM_OS_LOCK; bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP ); if ( bit < DRM_MAX_CTXBITMAP ) { set_bit( bit, dev->ctx_bitmap ); @@ -87,10 +87,10 @@ int DRM(ctxbitmap_next)( drm_device_t *dev ) dev->context_sareas[bit] = NULL; } } - up(&dev->struct_sem); + DRM_OS_UNLOCK; return bit; } - up(&dev->struct_sem); + DRM_OS_UNLOCK; return -1; } @@ -99,17 +99,17 @@ int DRM(ctxbitmap_init)( drm_device_t *dev ) int i; int temp; - down(&dev->struct_sem); + DRM_OS_LOCK; dev->ctx_bitmap = (unsigned long *) DRM(alloc)( PAGE_SIZE, DRM_MEM_CTXBITMAP ); if ( dev->ctx_bitmap == NULL ) { - up(&dev->struct_sem); - return -ENOMEM; + DRM_OS_UNLOCK; + DRM_OS_RETURN(ENOMEM); } memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE ); dev->context_sareas = NULL; dev->max_context = -1; - up(&dev->struct_sem); + DRM_OS_UNLOCK; for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) { temp = DRM(ctxbitmap_next)( dev ); @@ -121,84 +121,97 @@ int DRM(ctxbitmap_init)( drm_device_t *dev ) void DRM(ctxbitmap_cleanup)( drm_device_t *dev ) { - down(&dev->struct_sem); + DRM_OS_LOCK; if( dev->context_sareas ) 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 ); - up(&dev->struct_sem); + DRM_OS_UNLOCK; } /* ================================================================ * Per Context SAREA Support */ -int DRM(getsareactx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(getsareactx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_priv_map_t request; drm_map_t *map; if (copy_from_user(&request, (drm_ctx_priv_map_t *)arg, sizeof(request))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); - down(&dev->struct_sem); + DRM_OS_LOCK; if ((int)request.ctx_id >= dev->max_context) { - up(&dev->struct_sem); - return -EINVAL; + DRM_OS_UNLOCK; + DRM_OS_RETURN(EINVAL); } map = dev->context_sareas[request.ctx_id]; - up(&dev->struct_sem); + DRM_OS_UNLOCK; request.handle = map->handle; if (copy_to_user((drm_ctx_priv_map_t *)arg, &request, sizeof(request))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(setsareactx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(setsareactx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_priv_map_t request; drm_map_t *map = NULL; +#ifdef __linux__ drm_map_list_t *r_list; struct list_head *list; +#endif +#ifdef __FreeBSD__ + drm_map_list_entry_t *list; +#endif if (copy_from_user(&request, (drm_ctx_priv_map_t *)arg, sizeof(request))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); - down(&dev->struct_sem); + DRM_OS_LOCK; +#ifdef __linux__ list_for_each(list, &dev->maplist->head) { r_list = (drm_map_list_t *)list; if(r_list->map && r_list->map->handle == request.handle) break; } if (list == &(dev->maplist->head)) { - up(&dev->struct_sem); - return -EINVAL; + DRM_OS_UNLOCK; + DRM_OS_RETURN(EINVAL); } map = r_list->map; - up(&dev->struct_sem); +#endif +#ifdef __FreeBSD__ + TAILQ_FOREACH(list, dev->maplist, link) { + map=list->map; + if(map->handle == request.handle) break; + } + if (!list) { + lockmgr( &dev->dev_lock, LK_RELEASE, 0, curproc ); + return EINVAL; + } +#endif + DRM_OS_UNLOCK; - if (!map) return -EINVAL; + if (!map) DRM_OS_RETURN(EINVAL); - down(&dev->struct_sem); + DRM_OS_LOCK; if ((int)request.ctx_id >= dev->max_context) { - up(&dev->struct_sem); - return -EINVAL; + DRM_OS_UNLOCK; + DRM_OS_RETURN(EINVAL); } dev->context_sareas[request.ctx_id] = map; - up(&dev->struct_sem); + DRM_OS_UNLOCK; return 0; } @@ -212,7 +225,7 @@ int DRM(context_switch)( drm_device_t *dev, int old, int new ) if ( test_and_set_bit( 0, &dev->context_flag ) ) { DRM_ERROR( "Reentering -- FIXME\n" ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } #if __HAVE_DMA_HISTOGRAM @@ -259,15 +272,14 @@ int DRM(context_switch_complete)( drm_device_t *dev, int new ) return 0; } -int DRM(resctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(resctx)( DRM_OS_IOCTL ) { drm_ctx_res_t res; drm_ctx_t ctx; int i; if ( copy_from_user( &res, (drm_ctx_res_t *)arg, sizeof(res) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ( res.count >= DRM_RESERVED_CONTEXTS ) { memset( &ctx, 0, sizeof(ctx) ); @@ -275,25 +287,23 @@ int DRM(resctx)( struct inode *inode, struct file *filp, ctx.handle = i; if ( copy_to_user( &res.contexts[i], &i, sizeof(i) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); } } res.count = DRM_RESERVED_CONTEXTS; if ( copy_to_user( (drm_ctx_res_t *)arg, &res, sizeof(res) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(addctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); ctx.handle = DRM(ctxbitmap_next)( dev ); if ( ctx.handle == DRM_KERNEL_CONTEXT ) { @@ -304,60 +314,54 @@ int DRM(addctx)( struct inode *inode, struct file *filp, if ( ctx.handle == -1 ) { DRM_DEBUG( "Not enough free contexts.\n" ); /* Should this return -EBUSY instead? */ - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } if ( copy_to_user( (drm_ctx_t *)arg, &ctx, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(modctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(modctx)( DRM_OS_IOCTL ) { /* This does nothing */ return 0; } -int DRM(getctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(getctx)( DRM_OS_IOCTL ) { drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t*)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); /* This is 0, because we don't handle any context flags */ ctx.flags = 0; if ( copy_to_user( (drm_ctx_t*)arg, &ctx, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(switchctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(switchctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d\n", ctx.handle ); return DRM(context_switch)( dev, dev->last_context, ctx.handle ); } -int DRM(newctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(newctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d\n", ctx.handle ); DRM(context_switch_complete)( dev, ctx.handle ); @@ -365,15 +369,13 @@ int DRM(newctx)( struct inode *inode, struct file *filp, return 0; } -int DRM(rmctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(rmctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d\n", ctx.handle ); if ( ctx.handle == DRM_KERNEL_CONTEXT + 1 ) { @@ -405,7 +407,7 @@ int DRM(context_switch)(drm_device_t *dev, int old, int new) if (test_and_set_bit(0, &dev->context_flag)) { DRM_ERROR("Reentering -- FIXME\n"); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } #if __HAVE_DMA_HISTOGRAM @@ -416,7 +418,7 @@ int DRM(context_switch)(drm_device_t *dev, int old, int new) if (new >= dev->queue_count) { clear_bit(0, &dev->context_flag); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (new == dev->last_context) { @@ -429,7 +431,7 @@ int DRM(context_switch)(drm_device_t *dev, int old, int new) if (atomic_read(&q->use_count) == 1) { atomic_dec(&q->use_count); clear_bit(0, &dev->context_flag); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (DRM(flags) & DRM_FLAG_NOCTX) { @@ -532,7 +534,7 @@ static int DRM(alloc_queue)(drm_device_t *dev) atomic_dec(&dev->queuelist[i]->use_count); } /* Allocate a new queue */ - down(&dev->struct_sem); + DRM_OS_LOCK; queue = gamma_alloc(sizeof(*queue), DRM_MEM_QUEUES); memset(queue, 0, sizeof(*queue)); @@ -550,20 +552,19 @@ static int DRM(alloc_queue)(drm_device_t *dev) newslots, DRM_MEM_QUEUES); if (!dev->queuelist) { - up(&dev->struct_sem); + DRM_OS_UNLOCK; DRM_DEBUG("out of memory\n"); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } } dev->queuelist[dev->queue_count-1] = queue; - up(&dev->struct_sem); + DRM_OS_UNLOCK; DRM_DEBUG("%d (new)\n", dev->queue_count - 1); return dev->queue_count - 1; } -int DRM(resctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(resctx)( DRM_OS_IOCTL ) { drm_ctx_res_t res; drm_ctx_t ctx; @@ -571,7 +572,7 @@ int DRM(resctx)(struct inode *inode, struct file *filp, DRM_DEBUG("%d\n", DRM_RESERVED_CONTEXTS); if (copy_from_user(&res, (drm_ctx_res_t *)arg, sizeof(res))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if (res.count >= DRM_RESERVED_CONTEXTS) { memset(&ctx, 0, sizeof(ctx)); for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) { @@ -579,24 +580,22 @@ int DRM(resctx)(struct inode *inode, struct file *filp, if (copy_to_user(&res.contexts[i], &i, sizeof(i))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); } } res.count = DRM_RESERVED_CONTEXTS; if (copy_to_user((drm_ctx_res_t *)arg, &res, sizeof(res))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(addctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(addctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ((ctx.handle = DRM(alloc_queue)(dev)) == DRM_KERNEL_CONTEXT) { /* Init kernel's context and get a new one. */ DRM(init_queue)(dev, dev->queuelist[ctx.handle], &ctx); @@ -605,36 +604,35 @@ int DRM(addctx)(struct inode *inode, struct file *filp, DRM(init_queue)(dev, dev->queuelist[ctx.handle], &ctx); DRM_DEBUG("%d\n", ctx.handle); if (copy_to_user((drm_ctx_t *)arg, &ctx, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(modctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(modctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; drm_queue_t *q; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); - if (ctx.handle < 0 || ctx.handle >= dev->queue_count) return -EINVAL; + if (ctx.handle < 0 || ctx.handle >= dev->queue_count) + DRM_OS_RETURN(EINVAL); q = dev->queuelist[ctx.handle]; atomic_inc(&q->use_count); if (atomic_read(&q->use_count) == 1) { /* No longer in use */ atomic_dec(&q->use_count); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (DRM_BUFCOUNT(&q->waitlist)) { atomic_dec(&q->use_count); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } q->flags = ctx.flags; @@ -643,87 +641,80 @@ int DRM(modctx)(struct inode *inode, struct file *filp, return 0; } -int DRM(getctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(getctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; drm_queue_t *q; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); - if (ctx.handle >= dev->queue_count) return -EINVAL; + if (ctx.handle >= dev->queue_count) + DRM_OS_RETURN(EINVAL); q = dev->queuelist[ctx.handle]; atomic_inc(&q->use_count); if (atomic_read(&q->use_count) == 1) { /* No longer in use */ atomic_dec(&q->use_count); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } ctx.flags = q->flags; atomic_dec(&q->use_count); if (copy_to_user((drm_ctx_t *)arg, &ctx, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(switchctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(switchctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); return DRM(context_switch)(dev, dev->last_context, ctx.handle); } -int DRM(newctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(newctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); DRM(context_switch_complete)(dev, ctx.handle); return 0; } -int DRM(rmctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(rmctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; drm_queue_t *q; drm_buf_t *buf; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); - if (ctx.handle >= dev->queue_count) return -EINVAL; + if (ctx.handle >= dev->queue_count) DRM_OS_RETURN(EINVAL); q = dev->queuelist[ctx.handle]; atomic_inc(&q->use_count); if (atomic_read(&q->use_count) == 1) { /* No longer in use */ atomic_dec(&q->use_count); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } atomic_inc(&q->finalization); /* Mark queue in finalization state */ @@ -734,7 +725,7 @@ int DRM(rmctx)(struct inode *inode, struct file *filp, schedule(); if (signal_pending(current)) { clear_bit(0, &dev->interrupt_flag); - return -EINTR; + DRM_OS_RETURN(EINTR); } } /* Remove queued buffers */ diff --git a/linux-core/drm_dma.c b/linux-core/drm_dma.c index 25734ae4..04867bf1 100644 --- a/linux-core/drm_dma.c +++ b/linux-core/drm_dma.c @@ -51,7 +51,7 @@ int DRM(dma_setup)( drm_device_t *dev ) dev->dma = DRM(alloc)( sizeof(*dev->dma), DRM_MEM_DRIVER ); if ( !dev->dma ) - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); memset( dev->dma, 0, sizeof(*dev->dma) ); @@ -330,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"); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (d->context != _DRM_LOCKING_CONTEXT(context) && _DRM_LOCKING_CONTEXT(context) != DRM_KERNEL_CONTEXT) { @@ -338,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); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } q = dev->queuelist[DRM_KERNEL_CONTEXT]; while_locked = 1; @@ -358,7 +358,7 @@ int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d) if (signal_pending(current)) { atomic_dec(&q->use_count); remove_wait_queue(&q->write_queue, &entry); - return -EINTR; + DRM_OS_RETURN(EINTR); } } atomic_dec(&q->block_count); @@ -372,14 +372,14 @@ 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); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } buf = dma->buflist[ idx ]; if (buf->pid != current->pid) { atomic_dec(&q->use_count); DRM_ERROR("Process %d using buffer owned by %d\n", current->pid, buf->pid); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (buf->list != DRM_LIST_NONE) { atomic_dec(&q->use_count); @@ -397,14 +397,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); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (buf->waiting) { atomic_dec(&q->use_count); DRM_ERROR("Queueing waiting buffer:" " buffer %d, offset %d\n", d->send_indices[i], i); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } buf->waiting = 1; if (atomic_read(&q->use_count) == 1 @@ -442,12 +442,12 @@ static int DRM(dma_get_buffers_of_order)(drm_device_t *dev, drm_dma_t *d, if (copy_to_user(&d->request_indices[i], &buf->idx, sizeof(buf->idx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if (copy_to_user(&d->request_sizes[i], &buf->total, sizeof(buf->total))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); ++d->granted_count; } @@ -504,12 +504,12 @@ int DRM(irq_install)( drm_device_t *dev, int irq ) int ret; if ( !irq ) - return -EINVAL; + DRM_OS_RETURN(EINVAL); down( &dev->struct_sem ); if ( dev->irq ) { up( &dev->struct_sem ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } dev->irq = irq; up( &dev->struct_sem ); @@ -560,7 +560,7 @@ int DRM(irq_uninstall)( drm_device_t *dev ) up( &dev->struct_sem ); if ( !irq ) - return -EINVAL; + DRM_OS_RETURN(EINVAL); DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq ); @@ -579,7 +579,7 @@ int DRM(control)( struct inode *inode, struct file *filp, drm_control_t ctl; if ( copy_from_user( &ctl, (drm_control_t *)arg, sizeof(ctl) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); switch ( ctl.func ) { case DRM_INST_HANDLER: @@ -587,7 +587,7 @@ int DRM(control)( struct inode *inode, struct file *filp, case DRM_UNINST_HANDLER: return DRM(irq_uninstall)( dev ); default: - return -EINVAL; + DRM_OS_RETURN(EINVAL); } } diff --git a/linux-core/drm_drawable.c b/linux-core/drm_drawable.c index 13e46b9f..aee7fc00 100644 --- a/linux-core/drm_drawable.c +++ b/linux-core/drm_drawable.c @@ -32,8 +32,7 @@ #define __NO_VERSION__ #include "drmP.h" -int DRM(adddraw)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(adddraw)( DRM_OS_IOCTL ) { drm_draw_t draw; @@ -44,8 +43,7 @@ int DRM(adddraw)(struct inode *inode, struct file *filp, return 0; } -int DRM(rmdraw)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(rmdraw)( DRM_OS_IOCTL ) { return 0; /* NOOP */ } diff --git a/linux-core/drm_drv.c b/linux-core/drm_drv.c index 5337646f..10c7d08c 100644 --- a/linux-core/drm_drv.c +++ b/linux-core/drm_drv.c @@ -584,8 +584,7 @@ module_init( drm_init ); module_exit( drm_cleanup ); -int DRM(version)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(version)( DRM_OS_IOCTL ) { drm_version_t version; int len; @@ -645,8 +644,7 @@ int DRM(open)( struct inode *inode, struct file *filp ) int DRM(release)( struct inode *inode, struct file *filp ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev; + DRM_OS_DEVICE; int retcode = 0; lock_kernel(); @@ -775,11 +773,9 @@ int DRM(release)( struct inode *inode, struct file *filp ) /* DRM(ioctl) is called whenever a process performs an ioctl on /dev/drm. */ -int DRM(ioctl)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(ioctl)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ioctl_desc_t *ioctl; drm_ioctl_t *func; int nr = DRM_IOCTL_NR(cmd); @@ -813,11 +809,9 @@ int DRM(ioctl)( struct inode *inode, struct file *filp, return retcode; } -int DRM(lock)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(lock)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; DECLARE_WAITQUEUE( entry, current ); drm_lock_t lock; int ret = 0; @@ -919,11 +913,9 @@ int DRM(lock)( struct inode *inode, struct file *filp, } -int DRM(unlock)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(unlock)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_lock_t lock; if ( copy_from_user( &lock, (drm_lock_t *)arg, sizeof(lock) ) ) diff --git a/linux/drm_auth.h b/linux/drm_auth.h index 252cd442..17692470 100644 --- a/linux/drm_auth.h +++ b/linux/drm_auth.h @@ -172,5 +172,5 @@ int DRM(authmagic)(DRM_OS_IOCTL) DRM(remove_magic)(dev, auth.magic); return 0; } - return -EINVAL; + DRM_OS_RETURN(EINVAL); } diff --git a/linux/drm_bufs.h b/linux/drm_bufs.h index 7439e8b8..fcdd4975 100644 --- a/linux/drm_bufs.h +++ b/linux/drm_bufs.h @@ -82,20 +82,20 @@ int DRM(addmap)( DRM_OS_IOCTL ) #endif #ifdef __linux__ - if ( !(filp->f_mode & 3) ) return -EACCES; /* Require read/write */ + if ( !(filp->f_mode & 3) ) #endif #ifdef __FreeBSD__ if (!(dev->flags & (FREAD|FWRITE))) - return EACCES; /* Require read/write */ #endif + DRM_OS_RETURN(EACCES); /* Require read/write */ map = (drm_map_t *) DRM(alloc)( sizeof(*map), DRM_MEM_MAPS ); if ( !map ) - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); if ( copy_from_user( map, (drm_map_t *)arg, sizeof(*map) ) ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EFAULT; + DRM_OS_RETURN(EFAULT); } /* Only allow shared memory to be removable since we only keep enough @@ -104,13 +104,13 @@ int DRM(addmap)( DRM_OS_IOCTL ) */ if ( (map->flags & _DRM_REMOVABLE) && map->type != _DRM_SHM ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } DRM_DEBUG( "offset = 0x%08lx, size = 0x%08lx, type = %d\n", map->offset, map->size, map->type ); if ( (map->offset & (~PAGE_MASK)) || (map->size & (~PAGE_MASK)) ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } map->mtrr = -1; map->handle = 0; @@ -125,7 +125,7 @@ int DRM(addmap)( DRM_OS_IOCTL ) #endif ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } #endif #ifdef __alpha__ @@ -147,7 +147,7 @@ int DRM(addmap)( DRM_OS_IOCTL ) map->size, DRM(order)( map->size ), map->handle ); if ( !map->handle ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } map->offset = (unsigned long)map->handle; if ( map->flags & _DRM_CONTAINS_LOCK ) { @@ -166,20 +166,20 @@ int DRM(addmap)( DRM_OS_IOCTL ) case _DRM_SCATTER_GATHER: if (!dev->sg) { DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } map->offset = map->offset + dev->sg->handle; break; default: DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } list = DRM(alloc)(sizeof(*list), DRM_MEM_MAPS); if(!list) { DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } memset(list, 0, sizeof(*list)); list->map = map; @@ -194,12 +194,12 @@ int DRM(addmap)( DRM_OS_IOCTL ) DRM_OS_UNLOCK; if ( copy_to_user( (drm_map_t *)arg, map, sizeof(*map) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ( map->type != _DRM_SHM ) { if ( copy_to_user( &((drm_map_t *)arg)->handle, &map->offset, sizeof(map->offset) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); } return 0; } @@ -212,8 +212,13 @@ int DRM(addmap)( DRM_OS_IOCTL ) int DRM(rmmap)( DRM_OS_IOCTL ) { DRM_OS_DEVICE; +#ifdef __linux__ struct list_head *list; drm_map_list_t *r_list; +#endif +#ifdef __FreeBSD__ + drm_map_list_entry_t *list; +#endif drm_vma_entry_t *pt, *prev; drm_map_t *map; drm_map_t request; @@ -221,10 +226,11 @@ int DRM(rmmap)( DRM_OS_IOCTL ) if (copy_from_user(&request, (drm_map_t *)arg, sizeof(request))) { - return -EFAULT; + DRM_OS_RETURN(EFAULT); } DRM_OS_LOCK; +#ifdef __linux__ list = &dev->maplist->head; list_for_each(list, &dev->maplist->head) { r_list = (drm_map_list_t *) list; @@ -239,10 +245,27 @@ int DRM(rmmap)( DRM_OS_IOCTL ) */ if(list == (&dev->maplist->head)) { DRM_OS_UNLOCK; - return -EINVAL; + DRM_OS_RETURN(EINVAL); } map = r_list->map; list_del(list); +#endif +#ifdef __FreeBSD__ + TAILQ_FOREACH(list, dev->maplist, link) { + map = list->map; + 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) { + DRM_OS_UNLOCK; + DRM_OS_RETURN(EINVAL); + } + TAILQ_REMOVE(dev->maplist, list, link); +#endif DRM(free)(list, sizeof(*list), DRM_MEM_MAPS); for (pt = dev->vmalist, prev = NULL; pt; prev = pt, pt = pt->next) { @@ -302,11 +325,11 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) int byte_count; int i; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); count = request.count; order = DRM(order)( request.size ); @@ -328,13 +351,15 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) DRM_DEBUG( "page_order: %d\n", page_order ); DRM_DEBUG( "total: %d\n", total ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL; - if ( dev->queue_count ) return -EBUSY; /* Not while in use */ + if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) + DRM_OS_RETURN(EINVAL); + if ( dev->queue_count ) + DRM_OS_RETURN(EBUSY); /* Not while in use */ spin_lock( &dev->count_lock ); if ( dev->buf_use ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); @@ -344,7 +369,7 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) if ( entry->buf_count ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; /* May only call once for each order */ + DRM_OS_RETURN(ENOMEM); /* May only call once for each order */ } entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), @@ -352,7 +377,7 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) if ( !entry->buflist ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } memset( entry->buflist, 0, count * sizeof(*entry->buflist) ); @@ -425,7 +450,7 @@ int DRM(addbufs_agp)( DRM_OS_IOCTL ) request.size = size; if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); dma->flags = _DRM_DMA_USE_AGP; @@ -454,11 +479,11 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) int byte_count; int page_count; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); count = request.count; order = DRM(order)( request.size ); @@ -468,8 +493,10 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) request.count, request.size, size, order, dev->queue_count ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL; - if ( dev->queue_count ) return -EBUSY; /* Not while in use */ + if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) + DRM_OS_RETURN(EINVAL); + if ( dev->queue_count ) + DRM_OS_RETURN(EBUSY); /* Not while in use */ alignment = (request.flags & _DRM_PAGE_ALIGN) ? PAGE_ALIGN(size) : size; @@ -479,7 +506,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) spin_lock( &dev->count_lock ); if ( dev->buf_use ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); @@ -489,7 +516,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) if ( entry->buf_count ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; /* May only call once for each order */ + DRM_OS_RETURN(ENOMEM); /* May only call once for each order */ } entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), @@ -497,7 +524,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) if ( !entry->buflist ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } memset( entry->buflist, 0, count * sizeof(*entry->buflist) ); @@ -509,7 +536,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) DRM_MEM_BUFS ); DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } memset( entry->seglist, 0, count * sizeof(*entry->seglist) ); @@ -590,7 +617,7 @@ int DRM(addbufs_pci)( DRM_OS_IOCTL ) request.size = size; if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); atomic_dec( &dev->buf_alloc ); return 0; @@ -616,11 +643,11 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) int byte_count; int i; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); count = request.count; order = DRM(order)( request.size ); @@ -642,13 +669,15 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) DRM_DEBUG( "page_order: %d\n", page_order ); DRM_DEBUG( "total: %d\n", total ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL; - if ( dev->queue_count ) return -EBUSY; /* Not while in use */ + if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) + DRM_OS_RETURN(EINVAL); + if ( dev->queue_count ) + DRM_OS_RETURN(EBUSY); /* Not while in use */ spin_lock( &dev->count_lock ); if ( dev->buf_use ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); @@ -658,7 +687,7 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) if ( entry->buf_count ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; /* May only call once for each order */ + DRM_OS_RETURN(ENOMEM); /* May only call once for each order */ } entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), @@ -666,7 +695,7 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) if ( !entry->buflist ) { DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } memset( entry->buflist, 0, count * sizeof(*entry->buflist) ); @@ -739,7 +768,7 @@ int DRM(addbufs_sg)( DRM_OS_IOCTL ) request.size = size; if ( copy_to_user( (drm_buf_desc_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); dma->flags = _DRM_DMA_USE_SG; @@ -754,7 +783,7 @@ int DRM(addbufs)( DRM_OS_IOCTL ) if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); #if __REALLY_HAVE_AGP if ( request.flags & _DRM_AGP_BUFFER ) @@ -769,7 +798,7 @@ int DRM(addbufs)( DRM_OS_IOCTL ) #if __HAVE_PCI_DMA return DRM(addbufs_pci)( inode, filp, cmd, arg ); #else - return -EINVAL; + DRM_OS_RETURN(EINVAL); #endif } @@ -781,12 +810,12 @@ int DRM(infobufs)( DRM_OS_IOCTL ) int i; int count; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); spin_lock( &dev->count_lock ); if ( atomic_read( &dev->buf_alloc ) ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } ++dev->buf_use; /* Can't allocate more after this call */ spin_unlock( &dev->count_lock ); @@ -794,7 +823,7 @@ int DRM(infobufs)( DRM_OS_IOCTL ) if ( copy_from_user( &request, (drm_buf_info_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); for ( i = 0, count = 0 ; i < DRM_MAX_ORDER + 1 ; i++ ) { if ( dma->bufs[i].buf_count ) ++count; @@ -820,7 +849,7 @@ int DRM(infobufs)( DRM_OS_IOCTL ) copy_to_user( &to->high_mark, &list->high_mark, sizeof(list->high_mark) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d %d %d %d %d\n", i, @@ -837,7 +866,7 @@ int DRM(infobufs)( DRM_OS_IOCTL ) if ( copy_to_user( (drm_buf_info_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } @@ -850,23 +879,24 @@ int DRM(markbufs)( DRM_OS_IOCTL ) int order; drm_buf_entry_t *entry; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_desc_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d, %d, %d\n", request.size, request.low_mark, request.high_mark ); order = DRM(order)( request.size ); - if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) return -EINVAL; + if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) + DRM_OS_RETURN(EINVAL); entry = &dma->bufs[order]; if ( request.low_mark < 0 || request.low_mark > entry->buf_count ) - return -EINVAL; + DRM_OS_RETURN(EINVAL); if ( request.high_mark < 0 || request.high_mark > entry->buf_count ) - return -EINVAL; + DRM_OS_RETURN(EINVAL); entry->freelist.low_mark = request.low_mark; entry->freelist.high_mark = request.high_mark; @@ -883,29 +913,29 @@ int DRM(freebufs)( DRM_OS_IOCTL ) int idx; drm_buf_t *buf; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); if ( copy_from_user( &request, (drm_buf_free_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d\n", request.count ); for ( i = 0 ; i < request.count ; i++ ) { if ( copy_from_user( &idx, &request.list[i], sizeof(idx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ( idx < 0 || idx >= dma->buf_count ) { DRM_ERROR( "Index %d (of %d max)\n", idx, dma->buf_count - 1 ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } buf = dma->buflist[idx]; if ( buf->pid != current->pid ) { DRM_ERROR( "Process %d freeing buffer owned by %d\n", current->pid, buf->pid ); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } DRM(free_buffer)( dev, buf ); } @@ -924,19 +954,19 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) drm_buf_map_t request; int i; - if ( !dma ) return -EINVAL; + if ( !dma ) DRM_OS_RETURN(EINVAL); spin_lock( &dev->count_lock ); if ( atomic_read( &dev->buf_alloc ) ) { spin_unlock( &dev->count_lock ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } dev->buf_use++; /* Can't allocate more after this call */ spin_unlock( &dev->count_lock ); if ( copy_from_user( &request, (drm_buf_map_t *)arg, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ( request.count >= dma->buf_count ) { if ( (__HAVE_AGP && (dma->flags & _DRM_DMA_USE_AGP)) || @@ -1027,7 +1057,7 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) DRM_DEBUG( "%d buffers, retcode = %d\n", request.count, retcode ); if ( copy_to_user( (drm_buf_map_t *)arg, &request, sizeof(request) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return retcode; } diff --git a/linux/drm_context.h b/linux/drm_context.h index 4ac896ef..28b7e92a 100644 --- a/linux/drm_context.h +++ b/linux/drm_context.h @@ -44,10 +44,10 @@ void DRM(ctxbitmap_free)( drm_device_t *dev, int ctx_handle ) if ( !dev->ctx_bitmap ) goto failed; if ( ctx_handle < DRM_MAX_CTXBITMAP ) { - down(&dev->struct_sem); + DRM_OS_LOCK; clear_bit( ctx_handle, dev->ctx_bitmap ); dev->context_sareas[ctx_handle] = NULL; - up(&dev->struct_sem); + DRM_OS_UNLOCK; return; } failed: @@ -62,7 +62,7 @@ int DRM(ctxbitmap_next)( drm_device_t *dev ) if(!dev->ctx_bitmap) return -1; - down(&dev->struct_sem); + DRM_OS_LOCK; bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP ); if ( bit < DRM_MAX_CTXBITMAP ) { set_bit( bit, dev->ctx_bitmap ); @@ -87,10 +87,10 @@ int DRM(ctxbitmap_next)( drm_device_t *dev ) dev->context_sareas[bit] = NULL; } } - up(&dev->struct_sem); + DRM_OS_UNLOCK; return bit; } - up(&dev->struct_sem); + DRM_OS_UNLOCK; return -1; } @@ -99,17 +99,17 @@ int DRM(ctxbitmap_init)( drm_device_t *dev ) int i; int temp; - down(&dev->struct_sem); + DRM_OS_LOCK; dev->ctx_bitmap = (unsigned long *) DRM(alloc)( PAGE_SIZE, DRM_MEM_CTXBITMAP ); if ( dev->ctx_bitmap == NULL ) { - up(&dev->struct_sem); - return -ENOMEM; + DRM_OS_UNLOCK; + DRM_OS_RETURN(ENOMEM); } memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE ); dev->context_sareas = NULL; dev->max_context = -1; - up(&dev->struct_sem); + DRM_OS_UNLOCK; for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) { temp = DRM(ctxbitmap_next)( dev ); @@ -121,84 +121,97 @@ int DRM(ctxbitmap_init)( drm_device_t *dev ) void DRM(ctxbitmap_cleanup)( drm_device_t *dev ) { - down(&dev->struct_sem); + DRM_OS_LOCK; if( dev->context_sareas ) 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 ); - up(&dev->struct_sem); + DRM_OS_UNLOCK; } /* ================================================================ * Per Context SAREA Support */ -int DRM(getsareactx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(getsareactx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_priv_map_t request; drm_map_t *map; if (copy_from_user(&request, (drm_ctx_priv_map_t *)arg, sizeof(request))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); - down(&dev->struct_sem); + DRM_OS_LOCK; if ((int)request.ctx_id >= dev->max_context) { - up(&dev->struct_sem); - return -EINVAL; + DRM_OS_UNLOCK; + DRM_OS_RETURN(EINVAL); } map = dev->context_sareas[request.ctx_id]; - up(&dev->struct_sem); + DRM_OS_UNLOCK; request.handle = map->handle; if (copy_to_user((drm_ctx_priv_map_t *)arg, &request, sizeof(request))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(setsareactx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(setsareactx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_priv_map_t request; drm_map_t *map = NULL; +#ifdef __linux__ drm_map_list_t *r_list; struct list_head *list; +#endif +#ifdef __FreeBSD__ + drm_map_list_entry_t *list; +#endif if (copy_from_user(&request, (drm_ctx_priv_map_t *)arg, sizeof(request))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); - down(&dev->struct_sem); + DRM_OS_LOCK; +#ifdef __linux__ list_for_each(list, &dev->maplist->head) { r_list = (drm_map_list_t *)list; if(r_list->map && r_list->map->handle == request.handle) break; } if (list == &(dev->maplist->head)) { - up(&dev->struct_sem); - return -EINVAL; + DRM_OS_UNLOCK; + DRM_OS_RETURN(EINVAL); } map = r_list->map; - up(&dev->struct_sem); +#endif +#ifdef __FreeBSD__ + TAILQ_FOREACH(list, dev->maplist, link) { + map=list->map; + if(map->handle == request.handle) break; + } + if (!list) { + lockmgr( &dev->dev_lock, LK_RELEASE, 0, curproc ); + return EINVAL; + } +#endif + DRM_OS_UNLOCK; - if (!map) return -EINVAL; + if (!map) DRM_OS_RETURN(EINVAL); - down(&dev->struct_sem); + DRM_OS_LOCK; if ((int)request.ctx_id >= dev->max_context) { - up(&dev->struct_sem); - return -EINVAL; + DRM_OS_UNLOCK; + DRM_OS_RETURN(EINVAL); } dev->context_sareas[request.ctx_id] = map; - up(&dev->struct_sem); + DRM_OS_UNLOCK; return 0; } @@ -212,7 +225,7 @@ int DRM(context_switch)( drm_device_t *dev, int old, int new ) if ( test_and_set_bit( 0, &dev->context_flag ) ) { DRM_ERROR( "Reentering -- FIXME\n" ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } #if __HAVE_DMA_HISTOGRAM @@ -259,15 +272,14 @@ int DRM(context_switch_complete)( drm_device_t *dev, int new ) return 0; } -int DRM(resctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(resctx)( DRM_OS_IOCTL ) { drm_ctx_res_t res; drm_ctx_t ctx; int i; if ( copy_from_user( &res, (drm_ctx_res_t *)arg, sizeof(res) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ( res.count >= DRM_RESERVED_CONTEXTS ) { memset( &ctx, 0, sizeof(ctx) ); @@ -275,25 +287,23 @@ int DRM(resctx)( struct inode *inode, struct file *filp, ctx.handle = i; if ( copy_to_user( &res.contexts[i], &i, sizeof(i) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); } } res.count = DRM_RESERVED_CONTEXTS; if ( copy_to_user( (drm_ctx_res_t *)arg, &res, sizeof(res) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(addctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); ctx.handle = DRM(ctxbitmap_next)( dev ); if ( ctx.handle == DRM_KERNEL_CONTEXT ) { @@ -304,60 +314,54 @@ int DRM(addctx)( struct inode *inode, struct file *filp, if ( ctx.handle == -1 ) { DRM_DEBUG( "Not enough free contexts.\n" ); /* Should this return -EBUSY instead? */ - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } if ( copy_to_user( (drm_ctx_t *)arg, &ctx, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(modctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(modctx)( DRM_OS_IOCTL ) { /* This does nothing */ return 0; } -int DRM(getctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(getctx)( DRM_OS_IOCTL ) { drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t*)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); /* This is 0, because we don't handle any context flags */ ctx.flags = 0; if ( copy_to_user( (drm_ctx_t*)arg, &ctx, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(switchctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(switchctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d\n", ctx.handle ); return DRM(context_switch)( dev, dev->last_context, ctx.handle ); } -int DRM(newctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(newctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d\n", ctx.handle ); DRM(context_switch_complete)( dev, ctx.handle ); @@ -365,15 +369,13 @@ int DRM(newctx)( struct inode *inode, struct file *filp, return 0; } -int DRM(rmctx)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(rmctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if ( copy_from_user( &ctx, (drm_ctx_t *)arg, sizeof(ctx) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG( "%d\n", ctx.handle ); if ( ctx.handle == DRM_KERNEL_CONTEXT + 1 ) { @@ -405,7 +407,7 @@ int DRM(context_switch)(drm_device_t *dev, int old, int new) if (test_and_set_bit(0, &dev->context_flag)) { DRM_ERROR("Reentering -- FIXME\n"); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } #if __HAVE_DMA_HISTOGRAM @@ -416,7 +418,7 @@ int DRM(context_switch)(drm_device_t *dev, int old, int new) if (new >= dev->queue_count) { clear_bit(0, &dev->context_flag); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (new == dev->last_context) { @@ -429,7 +431,7 @@ int DRM(context_switch)(drm_device_t *dev, int old, int new) if (atomic_read(&q->use_count) == 1) { atomic_dec(&q->use_count); clear_bit(0, &dev->context_flag); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (DRM(flags) & DRM_FLAG_NOCTX) { @@ -532,7 +534,7 @@ static int DRM(alloc_queue)(drm_device_t *dev) atomic_dec(&dev->queuelist[i]->use_count); } /* Allocate a new queue */ - down(&dev->struct_sem); + DRM_OS_LOCK; queue = gamma_alloc(sizeof(*queue), DRM_MEM_QUEUES); memset(queue, 0, sizeof(*queue)); @@ -550,20 +552,19 @@ static int DRM(alloc_queue)(drm_device_t *dev) newslots, DRM_MEM_QUEUES); if (!dev->queuelist) { - up(&dev->struct_sem); + DRM_OS_UNLOCK; DRM_DEBUG("out of memory\n"); - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); } } dev->queuelist[dev->queue_count-1] = queue; - up(&dev->struct_sem); + DRM_OS_UNLOCK; DRM_DEBUG("%d (new)\n", dev->queue_count - 1); return dev->queue_count - 1; } -int DRM(resctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(resctx)( DRM_OS_IOCTL ) { drm_ctx_res_t res; drm_ctx_t ctx; @@ -571,7 +572,7 @@ int DRM(resctx)(struct inode *inode, struct file *filp, DRM_DEBUG("%d\n", DRM_RESERVED_CONTEXTS); if (copy_from_user(&res, (drm_ctx_res_t *)arg, sizeof(res))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if (res.count >= DRM_RESERVED_CONTEXTS) { memset(&ctx, 0, sizeof(ctx)); for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) { @@ -579,24 +580,22 @@ int DRM(resctx)(struct inode *inode, struct file *filp, if (copy_to_user(&res.contexts[i], &i, sizeof(i))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); } } res.count = DRM_RESERVED_CONTEXTS; if (copy_to_user((drm_ctx_res_t *)arg, &res, sizeof(res))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(addctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(addctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if ((ctx.handle = DRM(alloc_queue)(dev)) == DRM_KERNEL_CONTEXT) { /* Init kernel's context and get a new one. */ DRM(init_queue)(dev, dev->queuelist[ctx.handle], &ctx); @@ -605,36 +604,35 @@ int DRM(addctx)(struct inode *inode, struct file *filp, DRM(init_queue)(dev, dev->queuelist[ctx.handle], &ctx); DRM_DEBUG("%d\n", ctx.handle); if (copy_to_user((drm_ctx_t *)arg, &ctx, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(modctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(modctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; drm_queue_t *q; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); - if (ctx.handle < 0 || ctx.handle >= dev->queue_count) return -EINVAL; + if (ctx.handle < 0 || ctx.handle >= dev->queue_count) + DRM_OS_RETURN(EINVAL); q = dev->queuelist[ctx.handle]; atomic_inc(&q->use_count); if (atomic_read(&q->use_count) == 1) { /* No longer in use */ atomic_dec(&q->use_count); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (DRM_BUFCOUNT(&q->waitlist)) { atomic_dec(&q->use_count); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } q->flags = ctx.flags; @@ -643,87 +641,80 @@ int DRM(modctx)(struct inode *inode, struct file *filp, return 0; } -int DRM(getctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(getctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; drm_queue_t *q; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); - if (ctx.handle >= dev->queue_count) return -EINVAL; + if (ctx.handle >= dev->queue_count) + DRM_OS_RETURN(EINVAL); q = dev->queuelist[ctx.handle]; atomic_inc(&q->use_count); if (atomic_read(&q->use_count) == 1) { /* No longer in use */ atomic_dec(&q->use_count); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } ctx.flags = q->flags; atomic_dec(&q->use_count); if (copy_to_user((drm_ctx_t *)arg, &ctx, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); return 0; } -int DRM(switchctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(switchctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); return DRM(context_switch)(dev, dev->last_context, ctx.handle); } -int DRM(newctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(newctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); DRM(context_switch_complete)(dev, ctx.handle); return 0; } -int DRM(rmctx)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(rmctx)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ctx_t ctx; drm_queue_t *q; drm_buf_t *buf; if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); DRM_DEBUG("%d\n", ctx.handle); - if (ctx.handle >= dev->queue_count) return -EINVAL; + if (ctx.handle >= dev->queue_count) DRM_OS_RETURN(EINVAL); q = dev->queuelist[ctx.handle]; atomic_inc(&q->use_count); if (atomic_read(&q->use_count) == 1) { /* No longer in use */ atomic_dec(&q->use_count); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } atomic_inc(&q->finalization); /* Mark queue in finalization state */ @@ -734,7 +725,7 @@ int DRM(rmctx)(struct inode *inode, struct file *filp, schedule(); if (signal_pending(current)) { clear_bit(0, &dev->interrupt_flag); - return -EINTR; + DRM_OS_RETURN(EINTR); } } /* Remove queued buffers */ diff --git a/linux/drm_dma.h b/linux/drm_dma.h index 25734ae4..04867bf1 100644 --- a/linux/drm_dma.h +++ b/linux/drm_dma.h @@ -51,7 +51,7 @@ int DRM(dma_setup)( drm_device_t *dev ) dev->dma = DRM(alloc)( sizeof(*dev->dma), DRM_MEM_DRIVER ); if ( !dev->dma ) - return -ENOMEM; + DRM_OS_RETURN(ENOMEM); memset( dev->dma, 0, sizeof(*dev->dma) ); @@ -330,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"); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (d->context != _DRM_LOCKING_CONTEXT(context) && _DRM_LOCKING_CONTEXT(context) != DRM_KERNEL_CONTEXT) { @@ -338,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); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } q = dev->queuelist[DRM_KERNEL_CONTEXT]; while_locked = 1; @@ -358,7 +358,7 @@ int DRM(dma_enqueue)(drm_device_t *dev, drm_dma_t *d) if (signal_pending(current)) { atomic_dec(&q->use_count); remove_wait_queue(&q->write_queue, &entry); - return -EINTR; + DRM_OS_RETURN(EINTR); } } atomic_dec(&q->block_count); @@ -372,14 +372,14 @@ 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); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } buf = dma->buflist[ idx ]; if (buf->pid != current->pid) { atomic_dec(&q->use_count); DRM_ERROR("Process %d using buffer owned by %d\n", current->pid, buf->pid); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (buf->list != DRM_LIST_NONE) { atomic_dec(&q->use_count); @@ -397,14 +397,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); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } if (buf->waiting) { atomic_dec(&q->use_count); DRM_ERROR("Queueing waiting buffer:" " buffer %d, offset %d\n", d->send_indices[i], i); - return -EINVAL; + DRM_OS_RETURN(EINVAL); } buf->waiting = 1; if (atomic_read(&q->use_count) == 1 @@ -442,12 +442,12 @@ static int DRM(dma_get_buffers_of_order)(drm_device_t *dev, drm_dma_t *d, if (copy_to_user(&d->request_indices[i], &buf->idx, sizeof(buf->idx))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); if (copy_to_user(&d->request_sizes[i], &buf->total, sizeof(buf->total))) - return -EFAULT; + DRM_OS_RETURN(EFAULT); ++d->granted_count; } @@ -504,12 +504,12 @@ int DRM(irq_install)( drm_device_t *dev, int irq ) int ret; if ( !irq ) - return -EINVAL; + DRM_OS_RETURN(EINVAL); down( &dev->struct_sem ); if ( dev->irq ) { up( &dev->struct_sem ); - return -EBUSY; + DRM_OS_RETURN(EBUSY); } dev->irq = irq; up( &dev->struct_sem ); @@ -560,7 +560,7 @@ int DRM(irq_uninstall)( drm_device_t *dev ) up( &dev->struct_sem ); if ( !irq ) - return -EINVAL; + DRM_OS_RETURN(EINVAL); DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq ); @@ -579,7 +579,7 @@ int DRM(control)( struct inode *inode, struct file *filp, drm_control_t ctl; if ( copy_from_user( &ctl, (drm_control_t *)arg, sizeof(ctl) ) ) - return -EFAULT; + DRM_OS_RETURN(EFAULT); switch ( ctl.func ) { case DRM_INST_HANDLER: @@ -587,7 +587,7 @@ int DRM(control)( struct inode *inode, struct file *filp, case DRM_UNINST_HANDLER: return DRM(irq_uninstall)( dev ); default: - return -EINVAL; + DRM_OS_RETURN(EINVAL); } } diff --git a/linux/drm_drawable.h b/linux/drm_drawable.h index 13e46b9f..aee7fc00 100644 --- a/linux/drm_drawable.h +++ b/linux/drm_drawable.h @@ -32,8 +32,7 @@ #define __NO_VERSION__ #include "drmP.h" -int DRM(adddraw)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(adddraw)( DRM_OS_IOCTL ) { drm_draw_t draw; @@ -44,8 +43,7 @@ int DRM(adddraw)(struct inode *inode, struct file *filp, return 0; } -int DRM(rmdraw)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(rmdraw)( DRM_OS_IOCTL ) { return 0; /* NOOP */ } diff --git a/linux/drm_drv.h b/linux/drm_drv.h index 5337646f..10c7d08c 100644 --- a/linux/drm_drv.h +++ b/linux/drm_drv.h @@ -584,8 +584,7 @@ module_init( drm_init ); module_exit( drm_cleanup ); -int DRM(version)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(version)( DRM_OS_IOCTL ) { drm_version_t version; int len; @@ -645,8 +644,7 @@ int DRM(open)( struct inode *inode, struct file *filp ) int DRM(release)( struct inode *inode, struct file *filp ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev; + DRM_OS_DEVICE; int retcode = 0; lock_kernel(); @@ -775,11 +773,9 @@ int DRM(release)( struct inode *inode, struct file *filp ) /* DRM(ioctl) is called whenever a process performs an ioctl on /dev/drm. */ -int DRM(ioctl)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(ioctl)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_ioctl_desc_t *ioctl; drm_ioctl_t *func; int nr = DRM_IOCTL_NR(cmd); @@ -813,11 +809,9 @@ int DRM(ioctl)( struct inode *inode, struct file *filp, return retcode; } -int DRM(lock)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(lock)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; DECLARE_WAITQUEUE( entry, current ); drm_lock_t lock; int ret = 0; @@ -919,11 +913,9 @@ int DRM(lock)( struct inode *inode, struct file *filp, } -int DRM(unlock)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(unlock)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_lock_t lock; if ( copy_from_user( &lock, (drm_lock_t *)arg, sizeof(lock) ) )