diff --git a/bsd-core/drm_os_freebsd.h b/bsd-core/drm_os_freebsd.h index c0739310..09ba2805 100644 --- a/bsd-core/drm_os_freebsd.h +++ b/bsd-core/drm_os_freebsd.h @@ -130,6 +130,39 @@ find_first_zero_bit(volatile u_int32_t *p, int max) #define wait_queue_head_t int #define cycles_t struct timespec + + /* Macros to make printf easier */ +#define DRM_ERROR(fmt, arg...) \ + printf("error: " "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg) +#define DRM_MEM_ERROR(area, fmt, arg...) \ + printf("error: " "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \ + DRM(mem_stats)[area].name , ##arg) +#define DRM_INFO(fmt, arg...) printf("info: " "[" DRM_NAME "] " fmt , ##arg) + +#if DRM_DEBUG_CODE +#define DRM_DEBUG(fmt, arg...) \ + do { \ + if (DRM(flags) & DRM_FLAG_DEBUG) \ + printf("[" DRM_NAME ":" __FUNCTION__ "] " fmt , \ + ##arg); \ + } while (0) +#else +#define DRM_DEBUG(fmt, arg...) do { } while (0) +#endif + +#define DRM_PROC_LIMIT (PAGE_SIZE-80) + +#define DRM_SYSCTL_PRINT(fmt, arg...) \ + snprintf(buf, sizeof(buf), fmt, ##arg); \ + error = SYSCTL_OUT(req, buf, strlen(buf)); \ + if (error) return error; + +#define DRM_SYSCTL_PRINT_RET(ret, fmt, arg...) \ + snprintf(buf, sizeof(buf), fmt, ##arg); \ + error = SYSCTL_OUT(req, buf, strlen(buf)); \ + if (error) { ret; return error; } + + #define DRM_FIND_MAP(dest, o) \ do { \ drm_map_list_entry_t *listentry; \ diff --git a/bsd/drm_os_freebsd.h b/bsd/drm_os_freebsd.h index c0739310..09ba2805 100644 --- a/bsd/drm_os_freebsd.h +++ b/bsd/drm_os_freebsd.h @@ -130,6 +130,39 @@ find_first_zero_bit(volatile u_int32_t *p, int max) #define wait_queue_head_t int #define cycles_t struct timespec + + /* Macros to make printf easier */ +#define DRM_ERROR(fmt, arg...) \ + printf("error: " "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg) +#define DRM_MEM_ERROR(area, fmt, arg...) \ + printf("error: " "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \ + DRM(mem_stats)[area].name , ##arg) +#define DRM_INFO(fmt, arg...) printf("info: " "[" DRM_NAME "] " fmt , ##arg) + +#if DRM_DEBUG_CODE +#define DRM_DEBUG(fmt, arg...) \ + do { \ + if (DRM(flags) & DRM_FLAG_DEBUG) \ + printf("[" DRM_NAME ":" __FUNCTION__ "] " fmt , \ + ##arg); \ + } while (0) +#else +#define DRM_DEBUG(fmt, arg...) do { } while (0) +#endif + +#define DRM_PROC_LIMIT (PAGE_SIZE-80) + +#define DRM_SYSCTL_PRINT(fmt, arg...) \ + snprintf(buf, sizeof(buf), fmt, ##arg); \ + error = SYSCTL_OUT(req, buf, strlen(buf)); \ + if (error) return error; + +#define DRM_SYSCTL_PRINT_RET(ret, fmt, arg...) \ + snprintf(buf, sizeof(buf), fmt, ##arg); \ + error = SYSCTL_OUT(req, buf, strlen(buf)); \ + if (error) { ret; return error; } + + #define DRM_FIND_MAP(dest, o) \ do { \ drm_map_list_entry_t *listentry; \ diff --git a/linux-core/drmP.h b/linux-core/drmP.h index 039f0c05..aaa95b24 100644 --- a/linux-core/drmP.h +++ b/linux-core/drmP.h @@ -118,36 +118,6 @@ #define _PAGE_PWT _PAGE_WT #endif - /* Macros to make printk easier */ -#define DRM_ERROR(fmt, arg...) \ - printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg) -#define DRM_MEM_ERROR(area, fmt, arg...) \ - printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \ - DRM(mem_stats)[area].name , ##arg) -#define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg) - -#if DRM_DEBUG_CODE -#define DRM_DEBUG(fmt, arg...) \ - do { \ - if ( DRM(flags) & DRM_FLAG_DEBUG ) \ - printk(KERN_DEBUG \ - "[" DRM_NAME ":" __FUNCTION__ "] " fmt , \ - ##arg); \ - } while (0) -#else -#define DRM_DEBUG(fmt, arg...) do { } while (0) -#endif - -#define DRM_PROC_LIMIT (PAGE_SIZE-80) - -#define DRM_PROC_PRINT(fmt, arg...) \ - len += sprintf(&buf[len], fmt , ##arg); \ - if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; } - -#define DRM_PROC_PRINT_RET(ret, fmt, arg...) \ - len += sprintf(&buf[len], fmt , ##arg); \ - if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; } - /* Mapping helper macros */ #define DRM_IOREMAP(map) \ (map)->handle = DRM(ioremap)( (map)->offset, (map)->size ) @@ -442,10 +412,20 @@ typedef struct drm_device { const char *name; /* Simple driver name */ char *unique; /* Unique identifier: e.g., busid */ int unique_len; /* Length of unique field */ +#ifdef __linux__ dev_t device; /* Device number for mknod */ +#endif +#ifdef __FreeBSD__ + device_t device; /* Device instance from newbus */ + dev_t devnode; /* Device number for mknod */ +#endif char *devname; /* For /proc/interrupts */ int blocked; /* Blocked due to VC switch? */ +#ifdef __FreeBSD__ + int flags; /* Flags to open(2) */ + int writable; /* Opened with FWRITE */ +#endif struct proc_dir_entry *root; /* Root for this device's entries */ /* Locks */ diff --git a/linux-core/drm_bufs.c b/linux-core/drm_bufs.c index 692b087c..7439e8b8 100644 --- a/linux-core/drm_bufs.c +++ b/linux-core/drm_bufs.c @@ -70,17 +70,26 @@ int DRM(order)( unsigned long size ) return order; } -int DRM(addmap)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addmap)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_map_t *map; +#ifdef __linux__ drm_map_list_t *list; +#endif +#ifdef __FreeBSD__ + drm_map_list_entry_t *list; +#endif +#ifdef __linux__ if ( !(filp->f_mode & 3) ) return -EACCES; /* Require read/write */ +#endif +#ifdef __FreeBSD__ + if (!(dev->flags & (FREAD|FWRITE))) + return EACCES; /* Require read/write */ +#endif - map = DRM(alloc)( sizeof(*map), DRM_MEM_MAPS ); + map = (drm_map_t *) DRM(alloc)( sizeof(*map), DRM_MEM_MAPS ); if ( !map ) return -ENOMEM; @@ -110,8 +119,11 @@ int DRM(addmap)( struct inode *inode, struct file *filp, case _DRM_REGISTERS: case _DRM_FRAME_BUFFER: #if !defined(__sparc__) && !defined(__alpha__) - if ( map->offset + map->size < map->offset || - map->offset < virt_to_phys(high_memory) ) { + if ( map->offset + map->size < map->offset +#ifdef __linux__ + || map->offset < virt_to_phys(high_memory) +#endif + ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); return -EINVAL; } @@ -172,9 +184,14 @@ int DRM(addmap)( struct inode *inode, struct file *filp, memset(list, 0, sizeof(*list)); list->map = map; - down(&dev->struct_sem); + DRM_OS_LOCK; +#ifdef __linux__ list_add(&list->head, &dev->maplist->head); - up(&dev->struct_sem); +#endif +#ifdef __FreeBSD__ + TAILQ_INSERT_TAIL(dev->maplist, list, link); +#endif + DRM_OS_UNLOCK; if ( copy_to_user( (drm_map_t *)arg, map, sizeof(*map) ) ) return -EFAULT; @@ -192,11 +209,9 @@ int DRM(addmap)( struct inode *inode, struct file *filp, * isn't in use. */ -int DRM(rmmap)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(rmmap)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; struct list_head *list; drm_map_list_t *r_list; drm_vma_entry_t *pt, *prev; @@ -209,7 +224,7 @@ int DRM(rmmap)(struct inode *inode, struct file *filp, return -EFAULT; } - down(&dev->struct_sem); + DRM_OS_LOCK; list = &dev->maplist->head; list_for_each(list, &dev->maplist->head) { r_list = (drm_map_list_t *) list; @@ -223,7 +238,7 @@ int DRM(rmmap)(struct inode *inode, struct file *filp, * find anything. */ if(list == (&dev->maplist->head)) { - up(&dev->struct_sem); + DRM_OS_UNLOCK; return -EINVAL; } map = r_list->map; @@ -262,18 +277,16 @@ int DRM(rmmap)(struct inode *inode, struct file *filp, } DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); } - up(&dev->struct_sem); + DRM_OS_UNLOCK; return 0; } #if __HAVE_DMA #if __REALLY_HAVE_AGP -int DRM(addbufs_agp)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addbufs_agp)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_desc_t request; drm_buf_entry_t *entry; @@ -326,10 +339,10 @@ int DRM(addbufs_agp)( struct inode *inode, struct file *filp, atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); - down( &dev->struct_sem ); + DRM_OS_LOCK; entry = &dma->bufs[order]; if ( entry->buf_count ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; /* May only call once for each order */ } @@ -337,7 +350,7 @@ int DRM(addbufs_agp)( struct inode *inode, struct file *filp, entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), DRM_MEM_BUFS ); if ( !entry->buflist ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; } @@ -406,7 +419,7 @@ int DRM(addbufs_agp)( struct inode *inode, struct file *filp, DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] ); } #endif - up( &dev->struct_sem ); + DRM_OS_UNLOCK; request.count = entry->buf_count; request.size = size; @@ -422,11 +435,9 @@ int DRM(addbufs_agp)( struct inode *inode, struct file *filp, #endif /* __REALLY_HAVE_AGP */ #if __HAVE_PCI_DMA -int DRM(addbufs_pci)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addbufs_pci)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_desc_t request; int count; @@ -473,10 +484,10 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); - down( &dev->struct_sem ); + DRM_OS_LOCK; entry = &dma->bufs[order]; if ( entry->buf_count ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; /* May only call once for each order */ } @@ -484,7 +495,7 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), DRM_MEM_BUFS ); if ( !entry->buflist ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; } @@ -496,7 +507,7 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, DRM(free)( entry->buflist, count * sizeof(*entry->buflist), DRM_MEM_BUFS ); - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; } @@ -573,7 +584,7 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] ); } #endif - up( &dev->struct_sem ); + DRM_OS_UNLOCK; request.count = entry->buf_count; request.size = size; @@ -587,11 +598,9 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, #endif /* __HAVE_PCI_DMA */ #ifdef __HAVE_SG -int DRM(addbufs_sg)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addbufs_sg)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_desc_t request; drm_buf_entry_t *entry; @@ -644,10 +653,10 @@ int DRM(addbufs_sg)( struct inode *inode, struct file *filp, atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); - down( &dev->struct_sem ); + DRM_OS_LOCK; entry = &dma->bufs[order]; if ( entry->buf_count ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; /* May only call once for each order */ } @@ -655,7 +664,7 @@ int DRM(addbufs_sg)( struct inode *inode, struct file *filp, entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), DRM_MEM_BUFS ); if ( !entry->buflist ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; } @@ -724,7 +733,7 @@ int DRM(addbufs_sg)( struct inode *inode, struct file *filp, DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] ); } #endif - up( &dev->struct_sem ); + DRM_OS_UNLOCK; request.count = entry->buf_count; request.size = size; @@ -739,8 +748,7 @@ int DRM(addbufs_sg)( struct inode *inode, struct file *filp, } #endif /* __HAVE_SG */ -int DRM(addbufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addbufs)( DRM_OS_IOCTL ) { drm_buf_desc_t request; @@ -765,11 +773,9 @@ int DRM(addbufs)( struct inode *inode, struct file *filp, #endif } -int DRM(infobufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(infobufs)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_info_t request; int i; @@ -836,11 +842,9 @@ int DRM(infobufs)( struct inode *inode, struct file *filp, return 0; } -int DRM(markbufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(markbufs)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_desc_t request; int order; @@ -870,11 +874,9 @@ int DRM(markbufs)( struct inode *inode, struct file *filp, return 0; } -int DRM(freebufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(freebufs)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_free_t request; int i; @@ -911,11 +913,9 @@ int DRM(freebufs)( struct inode *inode, struct file *filp, return 0; } -int DRM(mapbufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(mapbufs)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; int retcode = 0; const int zero = 0; @@ -948,33 +948,43 @@ int DRM(mapbufs)( struct inode *inode, struct file *filp, goto done; } +#ifdef __linux__ #if LINUX_VERSION_CODE <= 0x020402 down( ¤t->mm->mmap_sem ); #else down_write( ¤t->mm->mmap_sem ); #endif +#endif + virtual = do_mmap( filp, 0, map->size, PROT_READ | PROT_WRITE, MAP_SHARED, (unsigned long)map->offset ); +#ifdef __linux__ #if LINUX_VERSION_CODE <= 0x020402 up( ¤t->mm->mmap_sem ); #else up_write( ¤t->mm->mmap_sem ); +#endif #endif } else { +#ifdef __linux__ #if LINUX_VERSION_CODE <= 0x020402 down( ¤t->mm->mmap_sem ); #else down_write( ¤t->mm->mmap_sem ); #endif +#endif + virtual = do_mmap( filp, 0, dma->byte_count, PROT_READ | PROT_WRITE, MAP_SHARED, 0 ); +#ifdef __linux__ #if LINUX_VERSION_CODE <= 0x020402 up( ¤t->mm->mmap_sem ); #else up_write( ¤t->mm->mmap_sem ); +#endif #endif } if ( virtual > -1024UL ) { diff --git a/linux-core/drm_os_linux.h b/linux-core/drm_os_linux.h index d1a8a9be..6392fb58 100644 --- a/linux-core/drm_os_linux.h +++ b/linux-core/drm_os_linux.h @@ -210,6 +210,36 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, #endif /* !__HAVE_ARCH_CMPXCHG */ + /* Macros to make printk easier */ +#define DRM_ERROR(fmt, arg...) \ + printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg) +#define DRM_MEM_ERROR(area, fmt, arg...) \ + printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \ + DRM(mem_stats)[area].name , ##arg) +#define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg) + +#if DRM_DEBUG_CODE +#define DRM_DEBUG(fmt, arg...) \ + do { \ + if ( DRM(flags) & DRM_FLAG_DEBUG ) \ + printk(KERN_DEBUG \ + "[" DRM_NAME ":" __FUNCTION__ "] " fmt , \ + ##arg); \ + } while (0) +#else +#define DRM_DEBUG(fmt, arg...) do { } while (0) +#endif + +#define DRM_PROC_LIMIT (PAGE_SIZE-80) + +#define DRM_PROC_PRINT(fmt, arg...) \ + len += sprintf(&buf[len], fmt , ##arg); \ + if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; } + +#define DRM_PROC_PRINT_RET(ret, fmt, arg...) \ + len += sprintf(&buf[len], fmt , ##arg); \ + if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; } + #define DRM_FIND_MAP(_map, _o) \ do { \ struct list_head *_list; \ diff --git a/linux/drmP.h b/linux/drmP.h index 039f0c05..aaa95b24 100644 --- a/linux/drmP.h +++ b/linux/drmP.h @@ -118,36 +118,6 @@ #define _PAGE_PWT _PAGE_WT #endif - /* Macros to make printk easier */ -#define DRM_ERROR(fmt, arg...) \ - printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg) -#define DRM_MEM_ERROR(area, fmt, arg...) \ - printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \ - DRM(mem_stats)[area].name , ##arg) -#define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg) - -#if DRM_DEBUG_CODE -#define DRM_DEBUG(fmt, arg...) \ - do { \ - if ( DRM(flags) & DRM_FLAG_DEBUG ) \ - printk(KERN_DEBUG \ - "[" DRM_NAME ":" __FUNCTION__ "] " fmt , \ - ##arg); \ - } while (0) -#else -#define DRM_DEBUG(fmt, arg...) do { } while (0) -#endif - -#define DRM_PROC_LIMIT (PAGE_SIZE-80) - -#define DRM_PROC_PRINT(fmt, arg...) \ - len += sprintf(&buf[len], fmt , ##arg); \ - if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; } - -#define DRM_PROC_PRINT_RET(ret, fmt, arg...) \ - len += sprintf(&buf[len], fmt , ##arg); \ - if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; } - /* Mapping helper macros */ #define DRM_IOREMAP(map) \ (map)->handle = DRM(ioremap)( (map)->offset, (map)->size ) @@ -442,10 +412,20 @@ typedef struct drm_device { const char *name; /* Simple driver name */ char *unique; /* Unique identifier: e.g., busid */ int unique_len; /* Length of unique field */ +#ifdef __linux__ dev_t device; /* Device number for mknod */ +#endif +#ifdef __FreeBSD__ + device_t device; /* Device instance from newbus */ + dev_t devnode; /* Device number for mknod */ +#endif char *devname; /* For /proc/interrupts */ int blocked; /* Blocked due to VC switch? */ +#ifdef __FreeBSD__ + int flags; /* Flags to open(2) */ + int writable; /* Opened with FWRITE */ +#endif struct proc_dir_entry *root; /* Root for this device's entries */ /* Locks */ diff --git a/linux/drm_bufs.h b/linux/drm_bufs.h index 692b087c..7439e8b8 100644 --- a/linux/drm_bufs.h +++ b/linux/drm_bufs.h @@ -70,17 +70,26 @@ int DRM(order)( unsigned long size ) return order; } -int DRM(addmap)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addmap)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_map_t *map; +#ifdef __linux__ drm_map_list_t *list; +#endif +#ifdef __FreeBSD__ + drm_map_list_entry_t *list; +#endif +#ifdef __linux__ if ( !(filp->f_mode & 3) ) return -EACCES; /* Require read/write */ +#endif +#ifdef __FreeBSD__ + if (!(dev->flags & (FREAD|FWRITE))) + return EACCES; /* Require read/write */ +#endif - map = DRM(alloc)( sizeof(*map), DRM_MEM_MAPS ); + map = (drm_map_t *) DRM(alloc)( sizeof(*map), DRM_MEM_MAPS ); if ( !map ) return -ENOMEM; @@ -110,8 +119,11 @@ int DRM(addmap)( struct inode *inode, struct file *filp, case _DRM_REGISTERS: case _DRM_FRAME_BUFFER: #if !defined(__sparc__) && !defined(__alpha__) - if ( map->offset + map->size < map->offset || - map->offset < virt_to_phys(high_memory) ) { + if ( map->offset + map->size < map->offset +#ifdef __linux__ + || map->offset < virt_to_phys(high_memory) +#endif + ) { DRM(free)( map, sizeof(*map), DRM_MEM_MAPS ); return -EINVAL; } @@ -172,9 +184,14 @@ int DRM(addmap)( struct inode *inode, struct file *filp, memset(list, 0, sizeof(*list)); list->map = map; - down(&dev->struct_sem); + DRM_OS_LOCK; +#ifdef __linux__ list_add(&list->head, &dev->maplist->head); - up(&dev->struct_sem); +#endif +#ifdef __FreeBSD__ + TAILQ_INSERT_TAIL(dev->maplist, list, link); +#endif + DRM_OS_UNLOCK; if ( copy_to_user( (drm_map_t *)arg, map, sizeof(*map) ) ) return -EFAULT; @@ -192,11 +209,9 @@ int DRM(addmap)( struct inode *inode, struct file *filp, * isn't in use. */ -int DRM(rmmap)(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) +int DRM(rmmap)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; struct list_head *list; drm_map_list_t *r_list; drm_vma_entry_t *pt, *prev; @@ -209,7 +224,7 @@ int DRM(rmmap)(struct inode *inode, struct file *filp, return -EFAULT; } - down(&dev->struct_sem); + DRM_OS_LOCK; list = &dev->maplist->head; list_for_each(list, &dev->maplist->head) { r_list = (drm_map_list_t *) list; @@ -223,7 +238,7 @@ int DRM(rmmap)(struct inode *inode, struct file *filp, * find anything. */ if(list == (&dev->maplist->head)) { - up(&dev->struct_sem); + DRM_OS_UNLOCK; return -EINVAL; } map = r_list->map; @@ -262,18 +277,16 @@ int DRM(rmmap)(struct inode *inode, struct file *filp, } DRM(free)(map, sizeof(*map), DRM_MEM_MAPS); } - up(&dev->struct_sem); + DRM_OS_UNLOCK; return 0; } #if __HAVE_DMA #if __REALLY_HAVE_AGP -int DRM(addbufs_agp)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addbufs_agp)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_desc_t request; drm_buf_entry_t *entry; @@ -326,10 +339,10 @@ int DRM(addbufs_agp)( struct inode *inode, struct file *filp, atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); - down( &dev->struct_sem ); + DRM_OS_LOCK; entry = &dma->bufs[order]; if ( entry->buf_count ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; /* May only call once for each order */ } @@ -337,7 +350,7 @@ int DRM(addbufs_agp)( struct inode *inode, struct file *filp, entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), DRM_MEM_BUFS ); if ( !entry->buflist ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; } @@ -406,7 +419,7 @@ int DRM(addbufs_agp)( struct inode *inode, struct file *filp, DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] ); } #endif - up( &dev->struct_sem ); + DRM_OS_UNLOCK; request.count = entry->buf_count; request.size = size; @@ -422,11 +435,9 @@ int DRM(addbufs_agp)( struct inode *inode, struct file *filp, #endif /* __REALLY_HAVE_AGP */ #if __HAVE_PCI_DMA -int DRM(addbufs_pci)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addbufs_pci)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_desc_t request; int count; @@ -473,10 +484,10 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); - down( &dev->struct_sem ); + DRM_OS_LOCK; entry = &dma->bufs[order]; if ( entry->buf_count ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; /* May only call once for each order */ } @@ -484,7 +495,7 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), DRM_MEM_BUFS ); if ( !entry->buflist ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; } @@ -496,7 +507,7 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, DRM(free)( entry->buflist, count * sizeof(*entry->buflist), DRM_MEM_BUFS ); - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; } @@ -573,7 +584,7 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] ); } #endif - up( &dev->struct_sem ); + DRM_OS_UNLOCK; request.count = entry->buf_count; request.size = size; @@ -587,11 +598,9 @@ int DRM(addbufs_pci)( struct inode *inode, struct file *filp, #endif /* __HAVE_PCI_DMA */ #ifdef __HAVE_SG -int DRM(addbufs_sg)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addbufs_sg)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_desc_t request; drm_buf_entry_t *entry; @@ -644,10 +653,10 @@ int DRM(addbufs_sg)( struct inode *inode, struct file *filp, atomic_inc( &dev->buf_alloc ); spin_unlock( &dev->count_lock ); - down( &dev->struct_sem ); + DRM_OS_LOCK; entry = &dma->bufs[order]; if ( entry->buf_count ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; /* May only call once for each order */ } @@ -655,7 +664,7 @@ int DRM(addbufs_sg)( struct inode *inode, struct file *filp, entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist), DRM_MEM_BUFS ); if ( !entry->buflist ) { - up( &dev->struct_sem ); + DRM_OS_UNLOCK; atomic_dec( &dev->buf_alloc ); return -ENOMEM; } @@ -724,7 +733,7 @@ int DRM(addbufs_sg)( struct inode *inode, struct file *filp, DRM(freelist_put)( dev, &entry->freelist, &entry->buflist[i] ); } #endif - up( &dev->struct_sem ); + DRM_OS_UNLOCK; request.count = entry->buf_count; request.size = size; @@ -739,8 +748,7 @@ int DRM(addbufs_sg)( struct inode *inode, struct file *filp, } #endif /* __HAVE_SG */ -int DRM(addbufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(addbufs)( DRM_OS_IOCTL ) { drm_buf_desc_t request; @@ -765,11 +773,9 @@ int DRM(addbufs)( struct inode *inode, struct file *filp, #endif } -int DRM(infobufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(infobufs)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_info_t request; int i; @@ -836,11 +842,9 @@ int DRM(infobufs)( struct inode *inode, struct file *filp, return 0; } -int DRM(markbufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(markbufs)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_desc_t request; int order; @@ -870,11 +874,9 @@ int DRM(markbufs)( struct inode *inode, struct file *filp, return 0; } -int DRM(freebufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(freebufs)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; drm_buf_free_t request; int i; @@ -911,11 +913,9 @@ int DRM(freebufs)( struct inode *inode, struct file *filp, return 0; } -int DRM(mapbufs)( struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg ) +int DRM(mapbufs)( DRM_OS_IOCTL ) { - drm_file_t *priv = filp->private_data; - drm_device_t *dev = priv->dev; + DRM_OS_DEVICE; drm_device_dma_t *dma = dev->dma; int retcode = 0; const int zero = 0; @@ -948,33 +948,43 @@ int DRM(mapbufs)( struct inode *inode, struct file *filp, goto done; } +#ifdef __linux__ #if LINUX_VERSION_CODE <= 0x020402 down( ¤t->mm->mmap_sem ); #else down_write( ¤t->mm->mmap_sem ); #endif +#endif + virtual = do_mmap( filp, 0, map->size, PROT_READ | PROT_WRITE, MAP_SHARED, (unsigned long)map->offset ); +#ifdef __linux__ #if LINUX_VERSION_CODE <= 0x020402 up( ¤t->mm->mmap_sem ); #else up_write( ¤t->mm->mmap_sem ); +#endif #endif } else { +#ifdef __linux__ #if LINUX_VERSION_CODE <= 0x020402 down( ¤t->mm->mmap_sem ); #else down_write( ¤t->mm->mmap_sem ); #endif +#endif + virtual = do_mmap( filp, 0, dma->byte_count, PROT_READ | PROT_WRITE, MAP_SHARED, 0 ); +#ifdef __linux__ #if LINUX_VERSION_CODE <= 0x020402 up( ¤t->mm->mmap_sem ); #else up_write( ¤t->mm->mmap_sem ); +#endif #endif } if ( virtual > -1024UL ) { diff --git a/linux/drm_os_linux.h b/linux/drm_os_linux.h index d1a8a9be..6392fb58 100644 --- a/linux/drm_os_linux.h +++ b/linux/drm_os_linux.h @@ -210,6 +210,36 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, #endif /* !__HAVE_ARCH_CMPXCHG */ + /* Macros to make printk easier */ +#define DRM_ERROR(fmt, arg...) \ + printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ "] *ERROR* " fmt , ##arg) +#define DRM_MEM_ERROR(area, fmt, arg...) \ + printk(KERN_ERR "[" DRM_NAME ":" __FUNCTION__ ":%s] *ERROR* " fmt , \ + DRM(mem_stats)[area].name , ##arg) +#define DRM_INFO(fmt, arg...) printk(KERN_INFO "[" DRM_NAME "] " fmt , ##arg) + +#if DRM_DEBUG_CODE +#define DRM_DEBUG(fmt, arg...) \ + do { \ + if ( DRM(flags) & DRM_FLAG_DEBUG ) \ + printk(KERN_DEBUG \ + "[" DRM_NAME ":" __FUNCTION__ "] " fmt , \ + ##arg); \ + } while (0) +#else +#define DRM_DEBUG(fmt, arg...) do { } while (0) +#endif + +#define DRM_PROC_LIMIT (PAGE_SIZE-80) + +#define DRM_PROC_PRINT(fmt, arg...) \ + len += sprintf(&buf[len], fmt , ##arg); \ + if (len > DRM_PROC_LIMIT) { *eof = 1; return len - offset; } + +#define DRM_PROC_PRINT_RET(ret, fmt, arg...) \ + len += sprintf(&buf[len], fmt , ##arg); \ + if (len > DRM_PROC_LIMIT) { ret; *eof = 1; return len - offset; } + #define DRM_FIND_MAP(_map, _o) \ do { \ struct list_head *_list; \