diff --git a/bsd-core/drm_os_freebsd.h b/bsd-core/drm_os_freebsd.h index 529bb3ea..990accfb 100644 --- a/bsd-core/drm_os_freebsd.h +++ b/bsd-core/drm_os_freebsd.h @@ -28,6 +28,8 @@ #include #endif +#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ + #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) #define DRM_DEV_UID 0 #define DRM_DEV_GID 0 @@ -235,6 +237,9 @@ extern d_ioctl_t DRM(finish); extern d_ioctl_t DRM(addmap); extern d_ioctl_t DRM(rmmap); #if __HAVE_DMA +extern d_ioctl_t DRM(addbufs_agp); +extern d_ioctl_t DRM(addbufs_pci); +extern d_ioctl_t DRM(addbufs_sg); extern d_ioctl_t DRM(addbufs); extern d_ioctl_t DRM(infobufs); extern d_ioctl_t DRM(markbufs); diff --git a/bsd/drm_os_freebsd.h b/bsd/drm_os_freebsd.h index 529bb3ea..990accfb 100644 --- a/bsd/drm_os_freebsd.h +++ b/bsd/drm_os_freebsd.h @@ -28,6 +28,8 @@ #include #endif +#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ + #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) #define DRM_DEV_UID 0 #define DRM_DEV_GID 0 @@ -235,6 +237,9 @@ extern d_ioctl_t DRM(finish); extern d_ioctl_t DRM(addmap); extern d_ioctl_t DRM(rmmap); #if __HAVE_DMA +extern d_ioctl_t DRM(addbufs_agp); +extern d_ioctl_t DRM(addbufs_pci); +extern d_ioctl_t DRM(addbufs_sg); extern d_ioctl_t DRM(addbufs); extern d_ioctl_t DRM(infobufs); extern d_ioctl_t DRM(markbufs); diff --git a/linux-core/drmP.h b/linux-core/drmP.h index 44e20307..e9da9ecc 100644 --- a/linux-core/drmP.h +++ b/linux-core/drmP.h @@ -82,7 +82,6 @@ #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ #define DRM_LOOPING_LIMIT 5000000 #define DRM_BSZ 1024 /* Buffer size for /dev/drm? output */ -#define DRM_TIME_SLICE (HZ/20) /* Time slice for GLXContexts */ #define DRM_LOCK_SLICE 1 /* Time slice for lock, in jiffies */ #define DRM_FLAG_DEBUG 0x01 diff --git a/linux-core/drm_bufs.c b/linux-core/drm_bufs.c index 0ffd4247..e0bce2aa 100644 --- a/linux-core/drm_bufs.c +++ b/linux-core/drm_bufs.c @@ -33,6 +33,14 @@ #ifdef __linux__ #include #endif +#ifdef __FreeBSD__ +#include +#include +#include +#include +#include +#include +#endif #include "drmP.h" #ifndef __HAVE_PCI_DMA @@ -998,8 +1006,12 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) drm_device_dma_t *dma = dev->dma; int retcode = 0; const int zero = 0; - unsigned long virtual; - unsigned long address; +#ifdef __linux__ + unsigned long virtual, address; +#endif +#ifdef __FreeBSD__ + vm_offset_t virtual, address; +#endif drm_buf_map_t request; int i; @@ -1021,7 +1033,7 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) drm_map_t *map = DRIVER_AGP_BUFFERS_MAP( dev ); if ( !map ) { - retcode = -EINVAL; + retcode = EINVAL; goto done; } @@ -1030,19 +1042,27 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) 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 + +#ifdef __FreeBSD__ + retcode = vm_mmap(&p->p_vmspace->vm_map, + &virtual, + round_page(dma->byte_count), + PROT_READ|PROT_WRITE, VM_PROT_ALL, + MAP_SHARED, + SLIST_FIRST(&kdev->si_hlist), + (unsigned long)map->offset ); #endif } else { #ifdef __linux__ @@ -1050,25 +1070,38 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) 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 +#ifdef __FreeBSD__ + retcode = vm_mmap(&p->p_vmspace->vm_map, + &virtual, + round_page(dma->byte_count), + PROT_READ|PROT_WRITE, VM_PROT_ALL, + MAP_SHARED, + SLIST_FIRST(&kdev->si_hlist), + 0); #endif } +#ifdef __linux__ if ( virtual > -1024UL ) { /* Real error */ retcode = (signed long)virtual; goto done; } +#endif +#ifdef __FreeBSD__ + if (retcode) + goto done; +#endif request.virtual = (void *)virtual; for ( i = 0 ; i < dma->buf_count ; i++ ) { diff --git a/linux-core/drm_context.c b/linux-core/drm_context.c index b9e00c65..b19656e2 100644 --- a/linux-core/drm_context.c +++ b/linux-core/drm_context.c @@ -468,7 +468,12 @@ int DRM(context_switch_complete)(drm_device_t *dev, int new) #endif clear_bit(0, &dev->context_flag); +#ifdef __linux__ wake_up_interruptible(&dev->context_wait); +#endif +#ifdef __FreeBSD__ + wakeup( &dev->context_wait ); +#endif return 0; } @@ -480,10 +485,10 @@ static int DRM(init_queue)(drm_device_t *dev, drm_queue_t *q, drm_ctx_t *ctx) if (atomic_read(&q->use_count) != 1 || atomic_read(&q->finalization) || atomic_read(&q->block_count)) { - DRM_ERROR("New queue is already in use: u%d f%d b%d\n", - atomic_read(&q->use_count), - atomic_read(&q->finalization), - atomic_read(&q->block_count)); + DRM_ERROR("New queue is already in use: u%ld f%ld b%ld\n", + (unsigned long)atomic_read(&q->use_count), + (unsigned long)atomic_read(&q->finalization), + (unsigned long)atomic_read(&q->block_count)); } atomic_set(&q->finalization, 0); @@ -494,9 +499,16 @@ static int DRM(init_queue)(drm_device_t *dev, drm_queue_t *q, drm_ctx_t *ctx) atomic_set(&q->total_flushed, 0); atomic_set(&q->total_locks, 0); +#ifdef __linux__ init_waitqueue_head(&q->write_queue); init_waitqueue_head(&q->read_queue); init_waitqueue_head(&q->flush_queue); +#endif +#ifdef __FreeBSD__ + q->write_queue = 0; + q->read_queue = 0; + q->flush_queue = 0; +#endif q->flags = ctx->flags; diff --git a/linux-core/drm_dma.c b/linux-core/drm_dma.c index 04867bf1..2283eb53 100644 --- a/linux-core/drm_dma.c +++ b/linux-core/drm_dma.c @@ -188,9 +188,17 @@ void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf) buf->time_completed = get_cycles(); #endif +#ifdef __linux__ if ( __HAVE_DMA_WAITQUEUE && waitqueue_active(&buf->dma_wait)) { wake_up_interruptible(&buf->dma_wait); } +#endif +#ifdef __FreeBSD__ + if ( buf->dma_wait ) { + wakeup( &buf->dma_wait ); + buf->dma_wait = 0; + } +#endif #if __HAVE_DMA_FREELIST else { drm_device_dma_t *dma = dev->dma; diff --git a/linux-core/drm_memory.h b/linux-core/drm_memory.h index e86db408..03737352 100644 --- a/linux-core/drm_memory.h +++ b/linux-core/drm_memory.h @@ -310,7 +310,7 @@ unsigned long DRM(alloc_pages)(int order, int area) #ifdef __linux__ unsigned long address; #endif -#ifdef __FreeBSD_ +#ifdef __FreeBSD__ vm_offset_t address; #endif unsigned long bytes = PAGE_SIZE << order; diff --git a/linux-core/drm_os_linux.h b/linux-core/drm_os_linux.h index 5a452df2..9c4a7290 100644 --- a/linux-core/drm_os_linux.h +++ b/linux-core/drm_os_linux.h @@ -40,6 +40,8 @@ #endif #include +#define DRM_TIME_SLICE (HZ/20) /* Time slice for GLXContexts */ + /* Wait queue declarations changed in 2.3.1 */ #ifndef DECLARE_WAITQUEUE #define DECLARE_WAITQUEUE(w,c) struct wait_queue w = { c, NULL } diff --git a/linux/drmP.h b/linux/drmP.h index 44e20307..e9da9ecc 100644 --- a/linux/drmP.h +++ b/linux/drmP.h @@ -82,7 +82,6 @@ #define DRM_RESERVED_CONTEXTS 1 /* Change drm_resctx if changed */ #define DRM_LOOPING_LIMIT 5000000 #define DRM_BSZ 1024 /* Buffer size for /dev/drm? output */ -#define DRM_TIME_SLICE (HZ/20) /* Time slice for GLXContexts */ #define DRM_LOCK_SLICE 1 /* Time slice for lock, in jiffies */ #define DRM_FLAG_DEBUG 0x01 diff --git a/linux/drm_bufs.h b/linux/drm_bufs.h index 0ffd4247..e0bce2aa 100644 --- a/linux/drm_bufs.h +++ b/linux/drm_bufs.h @@ -33,6 +33,14 @@ #ifdef __linux__ #include #endif +#ifdef __FreeBSD__ +#include +#include +#include +#include +#include +#include +#endif #include "drmP.h" #ifndef __HAVE_PCI_DMA @@ -998,8 +1006,12 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) drm_device_dma_t *dma = dev->dma; int retcode = 0; const int zero = 0; - unsigned long virtual; - unsigned long address; +#ifdef __linux__ + unsigned long virtual, address; +#endif +#ifdef __FreeBSD__ + vm_offset_t virtual, address; +#endif drm_buf_map_t request; int i; @@ -1021,7 +1033,7 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) drm_map_t *map = DRIVER_AGP_BUFFERS_MAP( dev ); if ( !map ) { - retcode = -EINVAL; + retcode = EINVAL; goto done; } @@ -1030,19 +1042,27 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) 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 + +#ifdef __FreeBSD__ + retcode = vm_mmap(&p->p_vmspace->vm_map, + &virtual, + round_page(dma->byte_count), + PROT_READ|PROT_WRITE, VM_PROT_ALL, + MAP_SHARED, + SLIST_FIRST(&kdev->si_hlist), + (unsigned long)map->offset ); #endif } else { #ifdef __linux__ @@ -1050,25 +1070,38 @@ int DRM(mapbufs)( DRM_OS_IOCTL ) 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 +#ifdef __FreeBSD__ + retcode = vm_mmap(&p->p_vmspace->vm_map, + &virtual, + round_page(dma->byte_count), + PROT_READ|PROT_WRITE, VM_PROT_ALL, + MAP_SHARED, + SLIST_FIRST(&kdev->si_hlist), + 0); #endif } +#ifdef __linux__ if ( virtual > -1024UL ) { /* Real error */ retcode = (signed long)virtual; goto done; } +#endif +#ifdef __FreeBSD__ + if (retcode) + goto done; +#endif request.virtual = (void *)virtual; for ( i = 0 ; i < dma->buf_count ; i++ ) { diff --git a/linux/drm_context.h b/linux/drm_context.h index b9e00c65..b19656e2 100644 --- a/linux/drm_context.h +++ b/linux/drm_context.h @@ -468,7 +468,12 @@ int DRM(context_switch_complete)(drm_device_t *dev, int new) #endif clear_bit(0, &dev->context_flag); +#ifdef __linux__ wake_up_interruptible(&dev->context_wait); +#endif +#ifdef __FreeBSD__ + wakeup( &dev->context_wait ); +#endif return 0; } @@ -480,10 +485,10 @@ static int DRM(init_queue)(drm_device_t *dev, drm_queue_t *q, drm_ctx_t *ctx) if (atomic_read(&q->use_count) != 1 || atomic_read(&q->finalization) || atomic_read(&q->block_count)) { - DRM_ERROR("New queue is already in use: u%d f%d b%d\n", - atomic_read(&q->use_count), - atomic_read(&q->finalization), - atomic_read(&q->block_count)); + DRM_ERROR("New queue is already in use: u%ld f%ld b%ld\n", + (unsigned long)atomic_read(&q->use_count), + (unsigned long)atomic_read(&q->finalization), + (unsigned long)atomic_read(&q->block_count)); } atomic_set(&q->finalization, 0); @@ -494,9 +499,16 @@ static int DRM(init_queue)(drm_device_t *dev, drm_queue_t *q, drm_ctx_t *ctx) atomic_set(&q->total_flushed, 0); atomic_set(&q->total_locks, 0); +#ifdef __linux__ init_waitqueue_head(&q->write_queue); init_waitqueue_head(&q->read_queue); init_waitqueue_head(&q->flush_queue); +#endif +#ifdef __FreeBSD__ + q->write_queue = 0; + q->read_queue = 0; + q->flush_queue = 0; +#endif q->flags = ctx->flags; diff --git a/linux/drm_dma.h b/linux/drm_dma.h index 04867bf1..2283eb53 100644 --- a/linux/drm_dma.h +++ b/linux/drm_dma.h @@ -188,9 +188,17 @@ void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf) buf->time_completed = get_cycles(); #endif +#ifdef __linux__ if ( __HAVE_DMA_WAITQUEUE && waitqueue_active(&buf->dma_wait)) { wake_up_interruptible(&buf->dma_wait); } +#endif +#ifdef __FreeBSD__ + if ( buf->dma_wait ) { + wakeup( &buf->dma_wait ); + buf->dma_wait = 0; + } +#endif #if __HAVE_DMA_FREELIST else { drm_device_dma_t *dma = dev->dma; diff --git a/linux/drm_memory.h b/linux/drm_memory.h index e86db408..03737352 100644 --- a/linux/drm_memory.h +++ b/linux/drm_memory.h @@ -310,7 +310,7 @@ unsigned long DRM(alloc_pages)(int order, int area) #ifdef __linux__ unsigned long address; #endif -#ifdef __FreeBSD_ +#ifdef __FreeBSD__ vm_offset_t address; #endif unsigned long bytes = PAGE_SIZE << order; diff --git a/linux/drm_os_linux.h b/linux/drm_os_linux.h index 5a452df2..9c4a7290 100644 --- a/linux/drm_os_linux.h +++ b/linux/drm_os_linux.h @@ -40,6 +40,8 @@ #endif #include +#define DRM_TIME_SLICE (HZ/20) /* Time slice for GLXContexts */ + /* Wait queue declarations changed in 2.3.1 */ #ifndef DECLARE_WAITQUEUE #define DECLARE_WAITQUEUE(w,c) struct wait_queue w = { c, NULL } diff --git a/linux/gamma_drv.h b/linux/gamma_drv.h index 68b52070..72cecac7 100644 --- a/linux/gamma_drv.h +++ b/linux/gamma_drv.h @@ -58,8 +58,7 @@ extern void gamma_dma_quiescent_dual(drm_device_t *dev); /* gamma_dma.c */ extern int gamma_dma_schedule(drm_device_t *dev, int locked); -extern int gamma_dma(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg); +extern int gamma_dma( DRM_OS_IOCTL ); extern int gamma_find_devices(void); extern int gamma_found(void);