diff options
Diffstat (limited to 'bsd-core')
-rw-r--r-- | bsd-core/drmP.h | 411 | ||||
-rw-r--r-- | bsd-core/drm_agpsupport.c | 18 | ||||
-rw-r--r-- | bsd-core/drm_bufs.c | 13 | ||||
-rw-r--r-- | bsd-core/drm_drv.c | 39 | ||||
-rw-r--r-- | bsd-core/drm_irq.c | 4 | ||||
-rw-r--r-- | bsd-core/drm_memory.c | 32 | ||||
-rw-r--r-- | bsd-core/drm_os_freebsd.h | 449 | ||||
-rw-r--r-- | bsd-core/drm_os_netbsd.h | 367 | ||||
-rw-r--r-- | bsd-core/drm_sysctl.c | 15 | ||||
-rw-r--r-- | bsd-core/drm_vm.c | 4 |
10 files changed, 420 insertions, 932 deletions
diff --git a/bsd-core/drmP.h b/bsd-core/drmP.h index 815fd5dd..c5015100 100644 --- a/bsd-core/drmP.h +++ b/bsd-core/drmP.h @@ -35,23 +35,94 @@ #if defined(_KERNEL) || defined(__KERNEL__) -#define DRM_DEBUG_CODE 0 /* Include debugging code (if > 1, then - also include looping detection. */ - typedef struct drm_device drm_device_t; typedef struct drm_file drm_file_t; -/* There's undoubtably more of this file to go into these OS dependent ones. */ - -#ifdef __FreeBSD__ -#include "drm_os_freebsd.h" -#elif defined __NetBSD__ -#include "drm_os_netbsd.h" +#include <sys/param.h> +#include <sys/queue.h> +#include <sys/malloc.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/systm.h> +#include <sys/conf.h> +#include <sys/stat.h> +#include <sys/proc.h> +#include <sys/lock.h> +#include <sys/fcntl.h> +#include <sys/uio.h> +#include <sys/filio.h> +#include <sys/sysctl.h> +#include <sys/bus.h> +#include <sys/signalvar.h> +#include <sys/poll.h> +#include <vm/vm.h> +#include <vm/pmap.h> +#include <vm/vm_extern.h> +#include <vm/vm_map.h> +#include <vm/vm_param.h> +#include <machine/param.h> +#include <machine/pmap.h> +#include <machine/bus.h> +#include <machine/resource.h> +#include <machine/sysarch.h> +#include <sys/endian.h> +#include <sys/mman.h> +#if defined(__FreeBSD__) +#include <sys/rman.h> +#include <sys/memrange.h> +#include <pci/agpvar.h> +#include <sys/agpio.h> +#if __FreeBSD_version >= 500000 +#include <sys/mutex.h> +#include <dev/pci/pcivar.h> +#include <sys/selinfo.h> +#else /* __FreeBSD_version >= 500000 */ +#include <pci/pcivar.h> +#include <sys/select.h> +#endif /* __FreeBSD_version < 500000 */ +#elif defined(__NetBSD__) +#include <machine/mtrr.h> +#include <sys/vnode.h> +#include <sys/select.h> +#include <sys/device.h> +#include <sys/resourcevar.h> +#include <sys/lkm.h> +#include <sys/agpio.h> +#include <sys/ttycom.h> +#include <uvm/uvm.h> +#include <dev/pci/pcireg.h> +#include <dev/pci/pcivar.h> +#include <dev/pci/agpvar.h> +#elif defined(__OpenBSD__) +#include <sys/lkm.h> +#include <uvm/uvm.h> #endif +#include <sys/bus.h> #include "drm.h" +#include "drm_linux_list.h" +#include "drm_atomic.h" + +#ifdef __FreeBSD__ +#include <opt_drm.h> +#ifdef DRM_DEBUG +#undef DRM_DEBUG +#define DRM_DEBUG_DEFAULT_ON 1 +#endif /* DRM_DEBUG */ +#endif -/* Begin the DRM... */ +#if defined(DRM_LINUX) && DRM_LINUX && !defined(__amd64__) +#include <sys/file.h> +#include <sys/proc.h> +#include <machine/../linux/linux.h> +#include <machine/../linux/linux_proto.h> +#else +/* Either it was defined when it shouldn't be (FreeBSD amd64) or it isn't + * supported on this OS yet. + */ +#undef DRM_LINUX +#define DRM_LINUX 0 +#endif #define DRM_HASH_SIZE 16 /* Size of key hash table */ #define DRM_KERNEL_CONTEXT 0 /* Change drm_resctx if changed */ @@ -89,10 +160,264 @@ typedef struct drm_file drm_file_t; #define DRM_IF_VERSION(maj, min) (maj << 16 | min) +MALLOC_DECLARE(M_DRM); + +#define __OS_HAS_AGP 1 + +#define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) +#define DRM_DEV_UID 0 +#define DRM_DEV_GID 0 + +#define wait_queue_head_t atomic_t +#define DRM_WAKEUP(w) wakeup((void *)w) +#define DRM_WAKEUP_INT(w) wakeup(w) +#define DRM_INIT_WAITQUEUE(queue) do {} while (0) + +#if defined(__FreeBSD__) && __FreeBSD_version < 502109 +#define bus_alloc_resource_any(dev, type, rid, flags) \ + bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags) +#endif + +#if defined(__FreeBSD__) && __FreeBSD_version >= 500000 +#define DRM_CURPROC curthread +#define DRM_STRUCTPROC struct thread +#define DRM_SPINTYPE struct mtx +#define DRM_SPININIT(l,name) mtx_init(&l, name, NULL, MTX_DEF) +#define DRM_SPINUNINIT(l) mtx_destroy(&l) +#define DRM_SPINLOCK(l) mtx_lock(l) +#define DRM_SPINUNLOCK(u) mtx_unlock(u); +#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED) +#define DRM_CURRENTPID curthread->td_proc->p_pid +#define DRM_LOCK() mtx_lock(&dev->dev_lock) +#define DRM_UNLOCK() mtx_unlock(&dev->dev_lock) +#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS) +#else /* __FreeBSD__ && __FreeBSD_version >= 500000 */ +#define DRM_CURPROC curproc +#define DRM_STRUCTPROC struct proc +#define DRM_SPINTYPE struct simplelock +#define DRM_SPININIT(l,name) +#define DRM_SPINUNINIT(l) +#define DRM_SPINLOCK(l) +#define DRM_SPINUNLOCK(u) +#define DRM_CURRENTPID curproc->p_pid +#define DRM_LOCK() +#define DRM_UNLOCK() +#define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS +#define spldrm() spltty() +#endif /* __NetBSD__ || __OpenBSD__ */ + +/* Currently our DRMFILE (filp) is a void * which is actually the pid + * of the current process. It should be a per-open unique pointer, but + * code for that is not yet written */ +#define DRMFILE void * +#define DRM_IRQ_ARGS void *arg +typedef void irqreturn_t; +#define IRQ_HANDLED /* nothing */ +#define IRQ_NONE /* nothing */ + +#if defined(__FreeBSD__) +#define DRM_DEVICE \ + drm_device_t *dev = kdev->si_drv1 +#define DRM_IOCTL_ARGS struct cdev *kdev, u_long cmd, caddr_t data, \ + int flags, DRM_STRUCTPROC *p, DRMFILE filp + +#define PAGE_ALIGN(addr) round_page(addr) +#define DRM_SUSER(p) suser(p) +#define DRM_AGP_FIND_DEVICE() agp_find_device() +#define DRM_MTRR_WC MDF_WRITECOMBINE +#define jiffies ticks + +#else /* __FreeBSD__ */ + +#if defined(__NetBSD__) +#define DRM_DEVICE \ + drm_device_t *dev = device_lookup(&drm_cd, minor(kdev)) +#elif defined(__OpenBSD__) +#define DRM_DEVICE \ + drm_device_t *dev = (device_lookup(&drm_cd, \ + minor(kdev)))->dv_cfdata->cf_driver->cd_devs[minor(kdev)] +#endif /* __OpenBSD__ */ +#define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, \ + int flags, DRM_STRUCTPROC *p, DRMFILE filp + +#define CDEV_MAJOR 34 +#define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK) +#define DRM_SUSER(p) suser(p->p_ucred, &p->p_acflag) +#define DRM_AGP_FIND_DEVICE() agp_find_device(0) +#define DRM_MTRR_WC MTRR_TYPE_WC +#define jiffies hardclock_ticks + +typedef drm_device_t *device_t; +extern struct cfdriver drm_cd; +#endif /* !__FreeBSD__ */ + +typedef unsigned long dma_addr_t; +typedef u_int32_t u32; +typedef u_int16_t u16; +typedef u_int8_t u8; + +/* DRM_READMEMORYBARRIER() prevents reordering of reads. + * DRM_WRITEMEMORYBARRIER() prevents reordering of writes. + * DRM_MEMORYBARRIER() prevents reordering of reads and writes. + */ +#if defined(__i386__) +#define DRM_READMEMORYBARRIER() __asm __volatile( \ + "lock; addl $0,0(%%esp)" : : : "memory"); +#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); +#define DRM_MEMORYBARRIER() __asm __volatile( \ + "lock; addl $0,0(%%esp)" : : : "memory"); +#elif defined(__alpha__) +#define DRM_READMEMORYBARRIER() alpha_mb(); +#define DRM_WRITEMEMORYBARRIER() alpha_wmb(); +#define DRM_MEMORYBARRIER() alpha_mb(); +#elif defined(__amd64__) +#define DRM_READMEMORYBARRIER() __asm __volatile( \ + "lock; addl $0,0(%%rsp)" : : : "memory"); +#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); +#define DRM_MEMORYBARRIER() __asm __volatile( \ + "lock; addl $0,0(%%rsp)" : : : "memory"); +#endif + +#ifdef __FreeBSD__ +#define DRM_READ8(map, offset) \ + *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) +#define DRM_READ16(map, offset) \ + *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) +#define DRM_READ32(map, offset) \ + *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) +#define DRM_WRITE8(map, offset, val) \ + *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val +#define DRM_WRITE16(map, offset, val) \ + *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val +#define DRM_WRITE32(map, offset, val) \ + *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val + +#define DRM_VERIFYAREA_READ( uaddr, size ) \ + (!useracc((caddr_t)uaddr, size, VM_PROT_READ)) + +#else /* __FreeBSD__ */ + +typedef vaddr_t vm_offset_t; + +#define DRM_READ8(map, offset) \ + bus_space_read_1( (map)->iot, (map)->ioh, (offset)) +#define DRM_READ16(map, offset) \ + bus_space_read_2( (map)->iot, (map)->ioh, (offset)) +#define DRM_READ32(map, offset) \ + bus_space_read_4( (map)->iot, (map)->ioh, (offset)) +#define DRM_WRITE8(map, offset, val) \ + bus_space_write_1((map)->iot, (map)->ioh, (offset), (val)) +#define DRM_WRITE16(map, offset, val) \ + bus_space_write_2((map)->iot, (map)->ioh, (offset), (val)) +#define DRM_WRITE32(map, offset, val) \ + bus_space_write_4((map)->iot, (map)->ioh, (offset), (val)) + +#define DRM_VERIFYAREA_READ( uaddr, size ) \ + (!uvm_useracc((caddr_t)uaddr, size, VM_PROT_READ)) +#endif /* !__FreeBSD__ */ + +#define DRM_COPY_TO_USER_IOCTL(user, kern, size) \ + if ( IOCPARM_LEN(cmd) != size) \ + return EINVAL; \ + *user = kern; +#define DRM_COPY_FROM_USER_IOCTL(kern, user, size) \ + if ( IOCPARM_LEN(cmd) != size) \ + return EINVAL; \ + kern = *user; +#define DRM_COPY_TO_USER(user, kern, size) \ + copyout(kern, user, size) +#define DRM_COPY_FROM_USER(kern, user, size) \ + copyin(user, kern, size) +#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ + copyin(arg2, arg1, arg3) +#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ + copyout(arg2, arg1, arg3) +#define DRM_GET_USER_UNCHECKED(val, uaddr) \ + ((val) = fuword(uaddr), 0) +#define DRM_PUT_USER_UNCHECKED(uaddr, val) \ + suword(uaddr, val) + +#define cpu_to_le32(x) htole32(x) +#define le32_to_cpu(x) le32toh(x) + +#define DRM_ERR(v) v +#define DRM_HZ hz +#define DRM_UDELAY(udelay) DELAY(udelay) +#define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ + #define DRM_GET_PRIV_SAREA(_dev, _ctx, _map) do { \ (_map) = (_dev)->context_sareas[_ctx]; \ } while(0) +#define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) \ +do { \ + if (_filp != (DRMFILE)(intptr_t)DRM_CURRENTPID) { \ + DRM_ERROR("filp doesn't match curproc\n"); \ + return EINVAL; \ + } \ + DRM_LOCK(); \ + _priv = drm_find_file_by_proc(dev, DRM_CURPROC); \ + DRM_UNLOCK(); \ + if (_priv == NULL) { \ + DRM_ERROR("can't find authenticator\n"); \ + return EINVAL; \ + } \ +} while (0) + +#define LOCK_TEST_WITH_RETURN(dev, filp) \ +do { \ + if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ + dev->lock.filp != filp) { \ + DRM_ERROR("%s called without lock held\n", \ + __FUNCTION__); \ + return EINVAL; \ + } \ +} while (0) + +#define DRM_GETSAREA() \ +do { \ + drm_map_list_entry_t *listentry; \ + TAILQ_FOREACH(listentry, dev->maplist, link) { \ + drm_local_map_t *map = listentry->map; \ + if (map->type == _DRM_SHM && \ + map->flags & _DRM_CONTAINS_LOCK) { \ + dev_priv->sarea = map; \ + break; \ + } \ + } \ +} while (0) + +#if defined(__FreeBSD__) && __FreeBSD_version > 500000 +#define DRM_WAIT_ON( ret, queue, timeout, condition ) \ +for ( ret = 0 ; !ret && !(condition) ; ) { \ + mtx_lock(&dev->irq_lock); \ + if (!(condition)) \ + ret = msleep(&(queue), &dev->irq_lock, \ + PZERO | PCATCH, "drmwtq", (timeout)); \ + mtx_unlock(&dev->irq_lock); \ +} +#else +#define DRM_WAIT_ON( ret, queue, timeout, condition ) \ +for ( ret = 0 ; !ret && !(condition) ; ) { \ + int s = spldrm(); \ + if (!(condition)) \ + ret = tsleep( &(queue), PZERO | PCATCH, \ + "drmwtq", (timeout) ); \ + splx(s); \ +} +#endif + +#define DRM_ERROR(fmt, arg...) \ + printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \ + DRM_CURRENTPID, __func__ , ## arg) + +#define DRM_INFO(fmt, arg...) printf("info: [" DRM_NAME "] " fmt , ## arg) + +#define DRM_DEBUG(fmt, arg...) do { \ + if (drm_flags & DRM_FLAG_DEBUG) \ + printf("[" DRM_NAME ":pid%d:%s] " fmt, DRM_CURRENTPID, \ + __func__ , ## arg); \ +} while (0) typedef struct drm_pci_id_list { @@ -176,9 +501,6 @@ struct drm_file { drm_magic_t magic; unsigned long ioctl_count; void *driver_priv; -#ifdef DRIVER_FILE_FIELDS - DRIVER_FILE_FIELDS; -#endif }; typedef struct drm_lock_data { @@ -273,8 +595,8 @@ typedef struct drm_vbl_sig { * DRM device functions structure */ struct drm_device { -#ifdef __NetBSD__ - struct device device; /* NetBSD's softc is an extension of struct device */ +#if defined(__NetBSD__) || defined(__OpenBSD__) + struct device device; /* softc is an extension of struct device */ #endif /* Beginning of driver-config section */ @@ -342,7 +664,7 @@ struct drm_device { /* Locks */ #if defined(__FreeBSD__) && __FreeBSD_version > 500000 struct mtx dma_lock; /* protects dev->dma */ - struct mtx irq_lock; /* protects irq condition checks */ + struct mtx irq_lock; /* protects irq condition checks */ struct mtx dev_lock; /* protects everything else */ #endif /* Usage Counters */ @@ -375,7 +697,7 @@ struct drm_device { #ifdef __FreeBSD__ int irqrid; /* Interrupt used by board */ struct resource *irqr; /* Resource for interrupt used by board */ -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) struct pci_attach_args pa; pci_intr_handle_t ih; #endif @@ -388,9 +710,6 @@ struct drm_device { atomic_t context_flag; /* Context swapping flag */ int last_context; /* Last current context */ -#if __FreeBSD_version >= 400005 - struct task task; -#endif int vbl_queue; /* vbl wait channel */ atomic_t vbl_received; @@ -418,11 +737,36 @@ extern int drm_flags; int drm_probe(device_t nbdev, drm_pci_id_list_t *idlist); int drm_attach(device_t nbdev, drm_pci_id_list_t *idlist); int drm_detach(device_t nbdev); -#elif defined(__NetBSD__) +d_ioctl_t drm_ioctl; +d_open_t drm_open; +d_close_t drm_close; +d_read_t drm_read; +d_poll_t drm_poll; +d_mmap_t drm_mmap; +#elif defined(__NetBSD__) || defined(__OpenBSD__) int drm_probe(struct pci_attach_args *pa, drm_pci_id_list_t *idlist); int drm_attach(struct pci_attach_args *pa, dev_t kdev, drm_pci_id_list_t *idlist); +dev_type_ioctl(drm_ioctl); +dev_type_open(drm_open); +dev_type_close(drm_close); +dev_type_read(drm_read); +dev_type_poll(drm_poll); +dev_type_mmap(drm_mmap); #endif +/* File operations helpers (drm_fops.c) */ +#ifdef __FreeBSD__ +extern int drm_open_helper(struct cdev *kdev, int flags, int fmt, + DRM_STRUCTPROC *p, drm_device_t *dev); +extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev, + DRM_STRUCTPROC *p); +#elif defined(__NetBSD__) || defined(__OpenBSD__) +extern int drm_open_helper(dev_t kdev, int flags, int fmt, + DRM_STRUCTPROC *p, drm_device_t *dev); +extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev, + DRM_STRUCTPROC *p); +#endif /* __NetBSD__ || __OpenBSD__ */ + /* Memory management support (drm_memory.c) */ void drm_mem_init(void); void drm_mem_uninit(void); @@ -436,11 +780,6 @@ void drm_ioremapfree(drm_local_map_t *map); int drm_mtrr_add(unsigned long offset, size_t size, int flags); int drm_mtrr_del(unsigned long offset, size_t size, int flags); -agp_memory *drm_alloc_agp(int pages, u32 type); -int drm_free_agp(agp_memory *handle, int pages); -int drm_bind_agp(agp_memory *handle, unsigned int start); -int drm_unbind_agp(agp_memory *handle); - int drm_context_switch(drm_device_t *dev, int old, int new); int drm_context_switch_complete(drm_device_t *dev, int new); @@ -483,14 +822,20 @@ int drm_device_is_agp(drm_device_t *dev); drm_agp_head_t *drm_agp_init(void); void drm_agp_uninit(void); void drm_agp_do_release(void); -agp_memory *drm_agp_allocate_memory(size_t pages, u32 type); -int drm_agp_free_memory(agp_memory *handle); -int drm_agp_bind_memory(agp_memory *handle, off_t start); -int drm_agp_unbind_memory(agp_memory *handle); +void *drm_agp_allocate_memory(size_t pages, u32 type); +int drm_agp_free_memory(void *handle); +int drm_agp_bind_memory(void *handle, off_t start); +int drm_agp_unbind_memory(void *handle); /* Scatter Gather Support (drm_scatter.c) */ void drm_sg_cleanup(drm_sg_mem_t *entry); +#ifdef __FreeBSD__ +/* sysctl support (drm_sysctl.h) */ +extern int drm_sysctl_init(drm_device_t *dev); +extern int drm_sysctl_cleanup(drm_device_t *dev); +#endif /* __FreeBSD__ */ + /* ATI PCIGART support (ati_pcigart.c) */ int drm_ati_pcigart_init(drm_device_t *dev, unsigned long *addr, dma_addr_t *bus_addr); @@ -569,12 +914,6 @@ static __inline__ void drm_core_ioremap(struct drm_local_map *map, struct drm_de { map->handle = drm_ioremap(dev, map); } -#if 0 -static __inline__ void drm_core_ioremap_nocache(struct drm_map *map, struct drm_device *dev) -{ - map->handle = drm_ioremap_nocache(dev, map); -} -#endif static __inline__ void drm_core_ioremapfree(struct drm_local_map *map, struct drm_device *dev) { if ( map->handle && map->size ) diff --git a/bsd-core/drm_agpsupport.c b/bsd-core/drm_agpsupport.c index 899638d7..eecf2e59 100644 --- a/bsd-core/drm_agpsupport.c +++ b/bsd-core/drm_agpsupport.c @@ -139,7 +139,7 @@ int drm_agp_alloc(DRM_IOCTL_ARGS) pages = (request.size + PAGE_SIZE - 1) / PAGE_SIZE; type = (u_int32_t) request.type; - if (!(handle = drm_alloc_agp(pages, type))) { + if (!(handle = drm_agp_allocate_memory(pages, type))) { drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); return ENOMEM; } @@ -186,7 +186,7 @@ int drm_agp_unbind(DRM_IOCTL_ARGS) if (!(entry = drm_agp_lookup_entry(dev, (void *)request.handle))) return EINVAL; if (!entry->bound) return EINVAL; - retcode = drm_unbind_agp(entry->handle); + retcode = drm_agp_unbind_memory(entry->handle); if (!retcode) { entry->bound=0; @@ -212,7 +212,7 @@ int drm_agp_bind(DRM_IOCTL_ARGS) return EINVAL; if (entry->bound) return EINVAL; page = (request.offset + PAGE_SIZE - 1) / PAGE_SIZE; - if ((retcode = drm_bind_agp(entry->handle, page))) + if ((retcode = drm_agp_bind_memory(entry->handle, page))) return retcode; entry->bound = dev->agp->base + (page << PAGE_SHIFT); return 0; @@ -230,7 +230,7 @@ int drm_agp_free(DRM_IOCTL_ARGS) if (!(entry = drm_agp_lookup_entry(dev, (void*)request.handle))) return EINVAL; if (entry->bound) - drm_unbind_agp(entry->handle); + drm_agp_unbind_memory(entry->handle); if (entry->prev) entry->prev->next = entry->next; @@ -238,7 +238,7 @@ int drm_agp_free(DRM_IOCTL_ARGS) dev->agp->memory = entry->next; if (entry->next) entry->next->prev = entry->prev; - drm_free_agp(entry->handle, entry->pages); + drm_agp_free_memory(entry->handle); drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); return 0; } @@ -275,7 +275,7 @@ void drm_agp_uninit(void) } -agp_memory *drm_agp_allocate_memory(size_t pages, u32 type) +void *drm_agp_allocate_memory(size_t pages, u32 type) { device_t agpdev; @@ -286,7 +286,7 @@ agp_memory *drm_agp_allocate_memory(size_t pages, u32 type) return agp_alloc_memory(agpdev, type, pages << AGP_PAGE_SHIFT); } -int drm_agp_free_memory(agp_memory *handle) +int drm_agp_free_memory(void *handle) { device_t agpdev; @@ -298,7 +298,7 @@ int drm_agp_free_memory(agp_memory *handle) return 1; } -int drm_agp_bind_memory(agp_memory *handle, off_t start) +int drm_agp_bind_memory(void *handle, off_t start) { device_t agpdev; @@ -309,7 +309,7 @@ int drm_agp_bind_memory(agp_memory *handle, off_t start) return agp_bind_memory(agpdev, handle, start * PAGE_SIZE); } -int drm_agp_unbind_memory(agp_memory *handle) +int drm_agp_unbind_memory(void *handle) { device_t agpdev; diff --git a/bsd-core/drm_bufs.c b/bsd-core/drm_bufs.c index 0148eaa0..860b38b5 100644 --- a/bsd-core/drm_bufs.c +++ b/bsd-core/drm_bufs.c @@ -831,22 +831,21 @@ int drm_mapbufs(DRM_IOCTL_ARGS) vm_ooffset_t foff; vm_size_t size; vm_offset_t vaddr; -#endif /* __FreeBSD__ */ -#ifdef __NetBSD__ +#elif defined(__NetBSD__) || defined(__OpenBSD__) struct vnode *vn; vm_size_t size; vaddr_t vaddr; -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ || __OpenBSD__ */ drm_buf_map_t request; int i; DRM_COPY_FROM_USER_IOCTL( request, (drm_buf_map_t *)data, sizeof(request) ); -#ifdef __NetBSD__ +#if defined(__NetBSD__) || defined(__OpenBSD__) if (!vfinddev(kdev, VCHR, &vn)) return 0; /* FIXME: Shouldn't this be EINVAL or something? */ -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ || __OpenBSD */ #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 vms = p->td_proc->p_vmspace; @@ -880,12 +879,12 @@ int drm_mapbufs(DRM_IOCTL_ARGS) vaddr = round_page((vm_offset_t)vms->vm_daddr + MAXDSIZ); retcode = vm_mmap(&vms->vm_map, &vaddr, size, PROT_READ | PROT_WRITE, VM_PROT_ALL, MAP_SHARED, SLIST_FIRST(&kdev->si_hlist), foff ); -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) vaddr = round_page((vaddr_t)vms->vm_daddr + MAXDSIZ); retcode = uvm_mmap(&vms->vm_map, &vaddr, size, UVM_PROT_READ | UVM_PROT_WRITE, UVM_PROT_ALL, MAP_SHARED, &vn->v_uobj, foff, p->p_rlimit[RLIMIT_MEMLOCK].rlim_cur); -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ || __OpenBSD */ if (retcode) goto done; diff --git a/bsd-core/drm_drv.c b/bsd-core/drm_drv.c index b40bf1e4..7138096c 100644 --- a/bsd-core/drm_drv.c +++ b/bsd-core/drm_drv.c @@ -33,7 +33,7 @@ #include "drmP.h" #include "drm.h" -#if 1 && DRM_DEBUG_CODE +#ifdef DRM_DEBUG_DEFAULT_ON int drm_flags = DRM_FLAG_DEBUG; #else int drm_flags = 0; @@ -51,10 +51,10 @@ MODULE_DEPEND(drm, agp, 1, 1, 1); MODULE_DEPEND(drm, pci, 1, 1, 1); #endif /* __FreeBSD__ */ -#ifdef __NetBSD__ +#if defined(__NetBSD__) || defined(__OpenBSD__) #define DRIVER_SOFTC(unit) \ ((drm_device_t *)device_lookup(&drm_cd, unit)) -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ || __OpenBSD__ */ static drm_ioctl_desc_t drm_ioctls[256] = { [DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { drm_version, 0, 0 }, @@ -180,7 +180,7 @@ int drm_detach(device_t dev) devclass_t drm_devclass; -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) static struct cdevsw drm_cdevsw = { drm_open, @@ -197,7 +197,8 @@ static struct cdevsw drm_cdevsw = { }; int drm_refcnt = 0; -#if __NetBSD_Version__ >= 106080000 + +#if defined(__NetBSD__) && __NetBSD_Version__ >= 106080000 MOD_DEV("drm", DRIVER_NAME, NULL, -1, &drm_cdevsw, CDEV_MAJOR); #else MOD_DEV("drm", LM_DT_CHAR, CDEV_MAJOR, &drm_cdevsw); @@ -307,7 +308,7 @@ int drm_activate(struct device *self, enum devact act) } return (0); } -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ || __OpenBSD__ */ const char *drm_find_description(int vendor, int device, drm_pci_id_list_t *idlist) { int i = 0; @@ -364,7 +365,7 @@ static int drm_setup(drm_device_t *dev) #ifdef __FreeBSD__ dev->buf_sigio = NULL; -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) dev->buf_pgid = 0; #endif @@ -419,8 +420,8 @@ static int drm_takedown(drm_device_t *dev) for ( entry = dev->agp->memory ; entry ; entry = nexte ) { nexte = entry->next; if ( entry->bound ) - drm_unbind_agp(entry->handle); - drm_free_agp(entry->handle, entry->pages); + drm_agp_unbind_memory(entry->handle); + drm_agp_free_memory(entry->handle); drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); } dev->agp->memory = NULL; @@ -513,9 +514,9 @@ static int drm_init(device_t nbdev) #if __FreeBSD_version >= 500000 mtx_init(&dev->dev_lock, "drm device", NULL, MTX_DEF); #endif -#elif defined(__NetBSD__) - unit = minor(dev->device.dv_unit); +#elif defined(__NetBSD__) || defined(__OpenBSD__) dev = nbdev; + unit = minor(dev->device.dv_unit); if (dev->preinit != NULL) dev->preinit(dev, 0); @@ -536,7 +537,9 @@ static int drm_init(device_t nbdev) TAILQ_INIT(dev->maplist); drm_mem_init(); +#ifdef __FreeBSD__ drm_sysctl_init(dev); +#endif TAILQ_INIT(&dev->files); if (dev->use_agp) { @@ -575,7 +578,9 @@ static int drm_init(device_t nbdev) return 0; error: +#ifdef __FreeBSD__ drm_sysctl_cleanup(dev); +#endif DRM_LOCK(); drm_takedown(dev); DRM_UNLOCK(); @@ -598,8 +603,8 @@ static void drm_cleanup(drm_device_t *dev) DRM_DEBUG( "\n" ); - drm_sysctl_cleanup(dev); #ifdef __FreeBSD__ + drm_sysctl_cleanup(dev); destroy_dev(dev->devnode); #endif @@ -718,7 +723,7 @@ int drm_close(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p) #ifdef __FreeBSD__ DRM_DEBUG( "pid = %d, device = 0x%lx, open_count = %d\n", DRM_CURRENTPID, (long)dev->device, dev->open_count ); -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) DRM_DEBUG( "pid = %d, device = 0x%lx, open_count = %d\n", DRM_CURRENTPID, (long)&dev->device, dev->open_count); #endif @@ -778,9 +783,9 @@ int drm_close(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p) funsetown(&dev->buf_sigio); #elif defined(__FreeBSD__) funsetown(dev->buf_sigio); -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) dev->buf_pgid = 0; -#endif /* __NetBSD__ */ +#endif /* __NetBSD__ || __OpenBSD__ */ if (--priv->refs == 0) { TAILQ_REMOVE(&dev->files, priv, link); @@ -824,7 +829,7 @@ int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags, #ifdef __FreeBSD__ DRM_DEBUG( "pid=%d, cmd=0x%02lx, nr=0x%02x, dev 0x%lx, auth=%d\n", DRM_CURRENTPID, cmd, nr, (long)dev->device, priv->authenticated ); -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) DRM_DEBUG( "pid=%d, cmd=0x%02lx, nr=0x%02x, dev 0x%lx, auth=%d\n", DRM_CURRENTPID, cmd, nr, (long)&dev->device, priv->authenticated ); #endif @@ -846,7 +851,7 @@ int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags, #endif return 0; #endif /* __FreeBSD__ */ -#ifdef __NetBSD__ +#if defined(__NetBSD__) || defined(__OpenBSD__) case TIOCSPGRP: dev->buf_pgid = *(int *)data; return 0; diff --git a/bsd-core/drm_irq.c b/bsd-core/drm_irq.c index d1f0505b..32ad5a61 100644 --- a/bsd-core/drm_irq.c +++ b/bsd-core/drm_irq.c @@ -111,7 +111,7 @@ int drm_irq_install(drm_device_t *dev) #endif if (retcode != 0) goto err; -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) if (pci_intr_map(&dev->pa, &dev->ih) != 0) { retcode = ENOENT; goto err; @@ -164,7 +164,7 @@ int drm_irq_uninstall(drm_device_t *dev) #ifdef __FreeBSD__ bus_teardown_intr(dev->device, dev->irqr, dev->irqh); bus_release_resource(dev->device, SYS_RES_IRQ, irqrid, dev->irqr); -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) pci_intr_disestablish(&dev->pa.pa_pc, dev->irqh); #endif DRM_SPINUNINIT(dev->irq_lock); diff --git a/bsd-core/drm_memory.c b/bsd-core/drm_memory.c index dee3530c..8a49d40e 100644 --- a/bsd-core/drm_memory.c +++ b/bsd-core/drm_memory.c @@ -32,15 +32,11 @@ #include "drmP.h" -#if defined(__FreeBSD__) || defined(__NetBSD__) -/* The macros conflicted in the MALLOC_DEFINE */ MALLOC_DEFINE(M_DRM, "drm", "DRM Data Structures"); -#undef malloctype -#endif void drm_mem_init(void) { -#ifdef __NetBSD__ +#if defined(__NetBSD__) || defined(__OpenBSD__) malloc_type_attach(M_DRM); #endif } @@ -82,7 +78,7 @@ void *drm_ioremap(drm_device_t *dev, drm_local_map_t *map) { #ifdef __FreeBSD__ return pmap_mapdev(map->offset, map->size); -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) map->iot = dev->pa.pa_memt; if (bus_space_map(map->iot, map->offset, map->size, BUS_SPACE_MAP_LINEAR, &map->ioh)) @@ -95,31 +91,11 @@ void drm_ioremapfree(drm_local_map_t *map) { #ifdef __FreeBSD__ pmap_unmapdev((vm_offset_t) map->handle, map->size); -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) bus_space_unmap(map->iot, map->ioh, map->size); #endif } -agp_memory *drm_alloc_agp(int pages, u32 type) -{ - return drm_agp_allocate_memory(pages, type); -} - -int drm_free_agp(agp_memory *handle, int pages) -{ - return drm_agp_free_memory(handle); -} - -int drm_bind_agp(agp_memory *handle, unsigned int start) -{ - return drm_agp_bind_memory(handle, start); -} - -int drm_unbind_agp(agp_memory *handle) -{ - return drm_agp_unbind_memory(handle); -} - #ifdef __FreeBSD__ int drm_mtrr_add(unsigned long offset, size_t size, int flags) @@ -148,7 +124,7 @@ drm_mtrr_del(unsigned long offset, size_t size, int flags) strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner)); return mem_range_attr_set(&mrdesc, &act); } -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) int drm_mtrr_add(unsigned long offset, size_t size, int flags) { diff --git a/bsd-core/drm_os_freebsd.h b/bsd-core/drm_os_freebsd.h deleted file mode 100644 index ac72a7ae..00000000 --- a/bsd-core/drm_os_freebsd.h +++ /dev/null @@ -1,449 +0,0 @@ -/** - * \file drm_os_freebsd.h - * OS-specific #defines for FreeBSD - * - * \author Eric Anholt <anholt@FreeBSD.org> - */ - -/* - * Copyright 2003 Eric Anholt - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#include <sys/param.h> -#include <sys/queue.h> -#include <sys/malloc.h> -#include <sys/kernel.h> -#include <sys/module.h> -#include <sys/systm.h> -#include <sys/conf.h> -#include <sys/stat.h> -#include <sys/proc.h> -#include <sys/lock.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <sys/filio.h> -#include <sys/sysctl.h> -#include <sys/bus.h> -#include <sys/signalvar.h> -#include <sys/poll.h> -#include <vm/vm.h> -#include <vm/pmap.h> -#include <vm/vm_extern.h> -#include <vm/vm_map.h> -#include <vm/vm_param.h> -#include <machine/param.h> -#include <machine/pmap.h> -#include <machine/bus.h> -#include <machine/resource.h> -#if __FreeBSD_version >= 480000 -#include <sys/endian.h> -#endif -#include <sys/mman.h> -#include <sys/rman.h> -#include <sys/memrange.h> -#if __FreeBSD_version >= 500000 -#include <dev/pci/pcivar.h> -#include <sys/selinfo.h> -#else -#include <pci/pcivar.h> -#include <sys/select.h> -#endif -#include <sys/bus.h> -#if __FreeBSD_version >= 400005 -#include <sys/taskqueue.h> -#endif -#if __FreeBSD_version >= 500000 -#include <sys/mutex.h> -#endif -#include <pci/agpvar.h> -#include <sys/agpio.h> - -#include "drm_linux_list.h" - -#include <opt_drm.h> -#if DRM_DEBUG -#undef DRM_DEBUG_CODE -#define DRM_DEBUG_CODE 2 -#endif -#undef DRM_DEBUG - -#if defined(__amd64__) -/* XXX: We don't have the necessary headers yet. At least. */ -#undef DRM_LINUX -#endif - -#if DRM_LINUX -#include <sys/file.h> -#include <sys/proc.h> -#include <machine/../linux/linux.h> -#include <machine/../linux/linux_proto.h> -#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 - -#define __OS_HAS_AGP 1 - -#if __FreeBSD_version >= 500000 -#define DRM_CURPROC curthread -#define DRM_STRUCTPROC struct thread -#define DRM_SPINTYPE struct mtx -#define DRM_SPININIT(l,name) mtx_init(&l, name, NULL, MTX_DEF) -#define DRM_SPINUNINIT(l) mtx_destroy(&l) -#define DRM_SPINLOCK(l) mtx_lock(l) -#define DRM_SPINUNLOCK(u) mtx_unlock(u); -#define DRM_SPINLOCK_ASSERT(l) mtx_assert(l, MA_OWNED) -#define DRM_CURRENTPID curthread->td_proc->p_pid -#define DRM_LOCK() mtx_lock(&dev->dev_lock) -#define DRM_UNLOCK() mtx_unlock(&dev->dev_lock) -#else -/* There is no need for locking on FreeBSD 4.x. Synchronization is handled by - * the fact that there is no reentrancy of the kernel except for interrupt - * handlers, and the interrupt handler synchronization is managed by spls. - */ -#define DRM_CURPROC curproc -#define DRM_STRUCTPROC struct proc -#define DRM_SPINTYPE -#define DRM_SPININIT(l,name) -#define DRM_SPINUNINIT(l) -#define DRM_SPINLOCK(l) -#define DRM_SPINUNLOCK(u) -#define DRM_SPINLOCK_ASSERT(l) -#define DRM_CURRENTPID curproc->p_pid -#define DRM_LOCK() -#define DRM_UNLOCK() -#endif - -/* Currently our DRMFILE (filp) is a void * which is actually the pid - * of the current process. It should be a per-open unique pointer, but - * code for that is not yet written */ -#define DRMFILE void * -#define DRM_IOCTL_ARGS struct cdev *kdev, u_long cmd, caddr_t data, \ - int flags, DRM_STRUCTPROC *p, DRMFILE filp -#define DRM_SUSER(p) suser(p) -#define DRM_TASKQUEUE_ARGS void *arg, int pending -#define DRM_IRQ_ARGS void *arg -typedef void irqreturn_t; -#define IRQ_HANDLED /* nothing */ -#define IRQ_NONE /* nothing */ -#define DRM_DEVICE drm_device_t *dev = kdev->si_drv1 -#define DRM_MALLOC(size) malloc(size, M_DRM, M_NOWAIT) -#define DRM_FREE(pt,size) free(pt, M_DRM) - -/* Read/write from bus space, with byteswapping to le if necessary */ -#define DRM_READ8(map, offset) *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) -#define DRM_READ16(map, offset) *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) -#define DRM_READ32(map, offset) *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) -#define DRM_WRITE8(map, offset, val) *(volatile u_int8_t *) (((unsigned long)(map)->handle) + (offset)) = val -#define DRM_WRITE16(map, offset, val) *(volatile u_int16_t *) (((unsigned long)(map)->handle) + (offset)) = val -#define DRM_WRITE32(map, offset, val) *(volatile u_int32_t *)(((unsigned long)(map)->handle) + (offset)) = val -/* -#define DRM_READ8(map, offset) bus_space_read_1( (map)->iot, (map)->ioh, (offset) ) -#define DRM_READ32(map, offset) bus_space_read_4( (map)->iot, (map)->ioh, (offset) ) -#define DRM_WRITE8(map, offset, val) bus_space_write_1( (map)->iot, (map)->ioh, (offset), (val) ) -#define DRM_WRITE32(map, offset, val) bus_space_write_4( (map)->iot, (map)->ioh, (offset), (val) ) -*/ -#define DRM_AGP_FIND_DEVICE() agp_find_device() -#define DRM_ERR(v) v - -#define DRM_MTRR_WC MDF_WRITECOMBINE - -#define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) \ -do { \ - if (_filp != (DRMFILE)(intptr_t)DRM_CURRENTPID) { \ - DRM_ERROR("filp doesn't match curproc\n"); \ - return EINVAL; \ - } \ - DRM_LOCK(); \ - _priv = drm_find_file_by_proc(dev, DRM_CURPROC); \ - DRM_UNLOCK(); \ - if (_priv == NULL) { \ - DRM_ERROR("can't find authenticator\n"); \ - return EINVAL; \ - } \ -} while (0) - -#define LOCK_TEST_WITH_RETURN(dev, filp) \ -do { \ - if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ - dev->lock.filp != filp) { \ - DRM_ERROR("%s called without lock held\n", \ - __FUNCTION__); \ - return EINVAL; \ - } \ -} while (0) - -#define DRM_UDELAY(udelay) DELAY(udelay) - -#define DRM_GETSAREA() \ -do { \ - drm_map_list_entry_t *listentry; \ - TAILQ_FOREACH(listentry, dev->maplist, link) { \ - drm_local_map_t *map = listentry->map; \ - if (map->type == _DRM_SHM && \ - map->flags & _DRM_CONTAINS_LOCK) { \ - dev_priv->sarea = map; \ - break; \ - } \ - } \ -} while (0) - -#define DRM_HZ hz - -#if defined(__FreeBSD__) && __FreeBSD_version > 500000 -#define DRM_WAIT_ON( ret, queue, timeout, condition ) \ -for ( ret = 0 ; !ret && !(condition) ; ) { \ - mtx_lock(&dev->irq_lock); \ - if (!(condition)) \ - ret = msleep(&(queue), &dev->irq_lock, \ - PZERO | PCATCH, "drmwtq", (timeout)); \ - mtx_unlock(&dev->irq_lock); \ -} -#else -#define DRM_WAIT_ON( ret, queue, timeout, condition ) \ -for ( ret = 0 ; !ret && !(condition) ; ) { \ - int s = spldrm(); \ - if (!(condition)) \ - ret = tsleep( &(queue), PZERO | PCATCH, \ - "drmwtq", (timeout) ); \ - splx(s); \ -} -#endif - -#define DRM_WAKEUP( queue ) wakeup( queue ) -#define DRM_WAKEUP_INT( queue ) wakeup( queue ) -#define DRM_INIT_WAITQUEUE( queue ) do {} while (0) - -#define DRM_COPY_TO_USER_IOCTL(user, kern, size) \ - if ( IOCPARM_LEN(cmd) != size) \ - return EINVAL; \ - *user = kern; -#define DRM_COPY_FROM_USER_IOCTL(kern, user, size) \ - if ( IOCPARM_LEN(cmd) != size) \ - return EINVAL; \ - kern = *user; -#define DRM_COPY_TO_USER(user, kern, size) \ - copyout(kern, user, size) -#define DRM_COPY_FROM_USER(kern, user, size) \ - copyin(user, kern, size) -/* Macros for userspace access with checking readability once */ -/* FIXME: can't find equivalent functionality for nocheck yet. - * It'll be slower than linux, but should be correct. - */ -#define DRM_VERIFYAREA_READ( uaddr, size ) \ - (!useracc((caddr_t)uaddr, size, VM_PROT_READ)) -#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ - copyin(arg2, arg1, arg3) -#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ - copyout(arg2, arg1, arg3) -#define DRM_GET_USER_UNCHECKED(val, uaddr) \ - ((val) = fuword(uaddr), 0) -#define DRM_PUT_USER_UNCHECKED(uaddr, val) \ - suword(uaddr, val) - -/* DRM_READMEMORYBARRIER() prevents reordering of reads. - * DRM_WRITEMEMORYBARRIER() prevents reordering of writes. - * DRM_MEMORYBARRIER() prevents reordering of reads and writes. - */ -#if defined(__i386__) -#define DRM_READMEMORYBARRIER() __asm __volatile( \ - "lock; addl $0,0(%%esp)" : : : "memory"); -#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); -#define DRM_MEMORYBARRIER() __asm __volatile( \ - "lock; addl $0,0(%%esp)" : : : "memory"); -#elif defined(__alpha__) -#define DRM_READMEMORYBARRIER() alpha_mb(); -#define DRM_WRITEMEMORYBARRIER() alpha_wmb(); -#define DRM_MEMORYBARRIER() alpha_mb(); -#elif defined(__amd64__) -#define DRM_READMEMORYBARRIER() __asm __volatile( \ - "lock; addl $0,0(%%rsp)" : : : "memory"); -#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); -#define DRM_MEMORYBARRIER() __asm __volatile( \ - "lock; addl $0,0(%%rsp)" : : : "memory"); -#endif - -#define PAGE_ALIGN(addr) round_page(addr) - -#ifndef M_WAITOK /* M_WAITOK (=0) name removed in -current */ -#define M_WAITOK 0 -#endif - -MALLOC_DECLARE(M_DRM); - -#if __FreeBSD_version < 502109 -#define bus_alloc_resource_any(dev, type, rid, flags) \ - bus_alloc_resource(dev, type, rid, 0ul, ~0ul, 1, flags) -#endif - -#if __FreeBSD_version >= 480000 -#define cpu_to_le32(x) htole32(x) -#define le32_to_cpu(x) le32toh(x) -#else -#define cpu_to_le32(x) (x) -#define le32_to_cpu(x) (x) -#endif - -typedef unsigned long dma_addr_t; -typedef u_int32_t atomic_t; -typedef u_int32_t u32; -typedef u_int16_t u16; -typedef u_int8_t u8; -#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) - -/* Fake this */ - -#if __FreeBSD_version < 500000 -/* The extra atomic functions from 5.0 haven't been merged to 4.x */ -static __inline int -atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src) -{ - int res = exp; - - __asm __volatile ( - " lock ; " - " cmpxchgl %1,%2 ; " - " setz %%al ; " - " movzbl %%al,%0 ; " - "1: " - "# atomic_cmpset_int" - : "+a" (res) /* 0 (result) */ - : "r" (src), /* 1 */ - "m" (*(dst)) /* 2 */ - : "memory"); - - return (res); -} -#endif - -static __inline atomic_t -test_and_set_bit(int b, volatile void *p) -{ - int s = splhigh(); - unsigned int m = 1<<b; - unsigned int r = *(volatile int *)p & m; - *(volatile int *)p |= m; - splx(s); - return r; -} - -static __inline void -clear_bit(int b, volatile void *p) -{ - atomic_clear_int(((volatile int *)p) + (b >> 5), 1 << (b & 0x1f)); -} - -static __inline void -set_bit(int b, volatile void *p) -{ - atomic_set_int(((volatile int *)p) + (b >> 5), 1 << (b & 0x1f)); -} - -static __inline int -test_bit(int b, volatile void *p) -{ - return ((volatile int *)p)[b >> 5] & (1 << (b & 0x1f)); -} - -static __inline int -find_first_zero_bit(volatile void *p, int max) -{ - int b; - - for (b = 0; b < max; b += 32) { - if (((volatile int *)p)[b >> 5] != ~0) { - for (;;) { - if ((((volatile int *)p)[b >> 5] & (1 << (b & 0x1f))) == 0) - return b; - b++; - } - } - } - return max; -} - -#define spldrm() spltty() - -/* - * Fake out the module macros for versions of FreeBSD where they don't - * exist. - */ -#if (__FreeBSD_version < 500002 && __FreeBSD_version > 500000) || __FreeBSD_version < 420000 -#define MODULE_VERSION(a,b) struct __hack -#define MODULE_DEPEND(a,b,c,d,e) struct __hack -#endif - -/* Redefinitions to make templating easy */ -#define wait_queue_head_t atomic_t -#define agp_memory void -#define jiffies ticks - - /* Macros to make printf easier */ -#define DRM_ERROR(fmt, arg...) \ - printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt, \ - DRM_CURRENTPID, __func__ , ## 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 ":pid%d:%s] " fmt, \ - DRM_CURRENTPID, __func__ , ## arg); \ - } while (0) -#else -#define DRM_DEBUG(fmt, arg...) do { } while (0) -#endif - -#if (__FreeBSD_version >= 500000) || ((__FreeBSD_version < 500000) && (__FreeBSD_version >= 410002)) -#define DRM_SYSCTL_HANDLER_ARGS (SYSCTL_HANDLER_ARGS) -#else -#define DRM_SYSCTL_HANDLER_ARGS SYSCTL_HANDLER_ARGS -#endif - -/* Internal functions */ - -/* drm_drv.h */ -extern d_ioctl_t drm_ioctl; -extern d_open_t drm_open; -extern d_close_t drm_close; -extern d_read_t drm_read; -extern d_poll_t drm_poll; -extern d_mmap_t drm_mmap; -extern int drm_open_helper(struct cdev *kdev, int flags, int fmt, - DRM_STRUCTPROC *p, drm_device_t *dev); -extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev, - DRM_STRUCTPROC *p); - -/* sysctl support (drm_sysctl.h) */ -extern int drm_sysctl_init(drm_device_t *dev); -extern int drm_sysctl_cleanup(drm_device_t *dev); diff --git a/bsd-core/drm_os_netbsd.h b/bsd-core/drm_os_netbsd.h deleted file mode 100644 index 7e1392c3..00000000 --- a/bsd-core/drm_os_netbsd.h +++ /dev/null @@ -1,367 +0,0 @@ -/** - * \file drm_os_netbsd.h - * OS-specific #defines for NetBSD - * - * \author Eric Anholt <anholt@FreeBSD.org> - * \author Erik Reid <reide@canuck.com> - */ - -/* - * Copyright 2003 Eric Anholt - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#include <sys/param.h> -#include <sys/queue.h> -#include <sys/malloc.h> -#include <sys/kernel.h> -#include <sys/systm.h> -#include <sys/conf.h> -#include <sys/stat.h> -#include <sys/proc.h> -#include <sys/lock.h> -#include <sys/fcntl.h> -#include <sys/uio.h> -#include <sys/filio.h> -#include <sys/sysctl.h> -#include <sys/select.h> -#include <sys/device.h> -#include <sys/mman.h> -#include <uvm/uvm.h> -#include <sys/vnode.h> -#include <sys/poll.h> -#include <sys/lkm.h> -/* For TIOCSPGRP/TIOCGPGRP */ -#include <sys/ttycom.h> -#include <sys/endian.h> - -#include <uvm/uvm.h> - -#include <machine/pmap.h> -#include <machine/bus.h> -#include <sys/resourcevar.h> -#include <machine/sysarch.h> -#include <machine/mtrr.h> - -#include <dev/pci/pcireg.h> -#include <dev/pci/pcivar.h> - -#include <dev/pci/agpvar.h> -#include <sys/agpio.h> - -#include <opt_drm.h> - -#if DRM_DEBUG -#undef DRM_DEBUG_CODE -#define DRM_DEBUG_CODE 2 -#endif -#undef DRM_DEBUG - -#if DRM_LINUX -#undef DRM_LINUX /* FIXME: Linux compat has not been ported yet */ -#endif - -typedef drm_device_t *device_t; - -extern struct cfdriver drm_cd; - -#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 -#define CDEV_MAJOR 34 - -#define __OS_HAS_AGP 1 - -#define DRM_CURPROC curproc -#define DRM_STRUCTPROC struct proc -#define DRM_SPINTYPE struct simplelock -#define DRM_SPININIT(l,name) -#define DRM_SPINUNINIT(l) -#define DRM_SPINLOCK(l) -#define DRM_SPINUNLOCK(u) -#define DRM_CURRENTPID curproc->p_pid - -/* Currently our DRMFILE (filp) is a void * which is actually the pid - * of the current process. It should be a per-open unique pointer, but - * code for that is not yet written */ -#define DRMFILE void * -#define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, int flags, DRM_STRUCTPROC *p, DRMFILE filp -#define DRM_LOCK() -#define DRM_UNLOCK() -#define DRM_SUSER(p) suser(p->p_ucred, &p->p_acflag) -#define DRM_TASKQUEUE_ARGS void *dev, int pending -#define DRM_IRQ_ARGS void *arg -typedef int irqreturn_t; -#define IRQ_NONE /* FIXME */ -#define IRQ_HANDLED /* FIXME */ -#define DRM_DEVICE drm_device_t *dev = device_lookup(&drm_cd, minor(kdev)) -/* XXX Not sure if this is the 'right' version.. */ -#if __NetBSD_Version__ >= 106140000 -MALLOC_DECLARE(M_DRM); -#else -/* XXX Make sure this works */ -extern const int M_DRM = M_DEVBUF; -#endif /* __NetBSD_Version__ */ -#define DRM_MALLOC(size) malloc(size, M_DRM, M_NOWAIT) -#define DRM_FREE(pt,size) free(pt, M_DRM)) - -#define DRM_READ8(map, offset) bus_space_read_1( (map)->iot, (map)->ioh, (offset) ) -#define DRM_READ32(map, offset) bus_space_read_4( (map)->iot, (map)->ioh, (offset) ) -#define DRM_WRITE8(map, offset, val) bus_space_write_1( (map)->iot, (map)->ioh, (offset), (val) ) -#define DRM_WRITE32(map, offset, val) bus_space_write_4( (map)->iot, (map)->ioh, (offset), (val) ) - -#define DRM_MTRR_WC MTRR_TYPE_WC - -#define DRM_AGP_FIND_DEVICE() agp_find_device(0) - -#define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) \ -do { \ - if (_filp != (DRMFILE)DRM_CURRENTPID) { \ - DRM_ERROR("filp doesn't match curproc\n"); \ - return EINVAL; \ - } \ - _priv = drm_find_file_by_proc(dev, DRM_CURPROC); \ - if (_priv == NULL) { \ - DRM_ERROR("can't find authenticator\n"); \ - return EINVAL; \ - } \ -} while (0) - -#define LOCK_TEST_WITH_RETURN(dev, filp) \ -do { \ - if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) || \ - dev->lock.filp != filp) { \ - DRM_ERROR("%s called without lock held\n", \ - __FUNCTION__); \ - return EINVAL; \ - } \ -} while (0) - -#define DRM_UDELAY( udelay ) \ -do { \ - struct timeval tv1, tv2; \ - microtime(&tv1); \ - do { \ - microtime(&tv2); \ - } \ - while (((tv2.tv_sec-tv1.tv_sec)*1000000 + tv2.tv_usec - tv1.tv_usec) < udelay ); \ -} while (0) - -#define DRM_GETSAREA() \ -do { \ - drm_map_list_entry_t *listentry; \ - TAILQ_FOREACH(listentry, dev->maplist, link) { \ - drm_local_map_t *map = listentry->map; \ - if (map->type == _DRM_SHM && \ - map->flags & _DRM_CONTAINS_LOCK) { \ - dev_priv->sarea = map; \ - break; \ - } \ - } \ -} while (0) - -#define DRM_HZ hz - -#define DRM_WAIT_ON( ret, queue, timeout, condition ) \ -while (!condition) { \ - int s = spldrm(); \ - ret = tsleep( (void *)&(queue), PZERO | PCATCH, "drmwtq", (timeout) ); \ - if ( ret ) \ - return ret; \ - splx(s); \ -} - -#define DRM_ERR(v) v - -#define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \ - *arg1 = arg2 -#define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \ - arg1 = *arg2 -#define DRM_COPY_TO_USER(arg1, arg2, arg3) \ - copyout(arg2, arg1, arg3) -#define DRM_COPY_FROM_USER(arg1, arg2, arg3) \ - copyin(arg2, arg1, arg3) -/* Macros for userspace access with checking readability once */ -/* FIXME: can't find equivalent functionality for nocheck yet. - * It'll be slower than linux, but should be correct. - */ -#define DRM_VERIFYAREA_READ( uaddr, size ) \ - (!uvm_useracc((caddr_t)uaddr, size, VM_PROT_READ)) -#define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \ - copyin(arg2, arg1, arg3) -#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \ - copyout(arg2, arg1, arg3) -#define DRM_GET_USER_UNCHECKED(val, uaddr) \ - ((val) = fuword(uaddr), 0) - -/* DRM_READMEMORYBARRIER() prevents reordering of reads. - * DRM_WRITEMEMORYBARRIER() prevents reordering of writes. - * DRM_MEMORYBARRIER() prevents reordering of reads and writes. - */ -#if defined(__i386__) -#define DRM_READMEMORYBARRIER() __asm __volatile( \ - "lock; addl $0,0(%%esp)" : : : "memory"); -#define DRM_WRITEMEMORYBARRIER() __asm __volatile("" : : : "memory"); -#define DRM_MEMORYBARRIER() __asm __volatile( \ - "lock; addl $0,0(%%esp)" : : : "memory"); -#elif defined(__alpha__) -#define DRM_READMEMORYBARRIER() alpha_mb(); -#define DRM_WRITEMEMORYBARRIER() alpha_wmb(); -#define DRM_MEMORYBARRIER() alpha_mb(); -#endif - -#define DRM_WAKEUP(w) wakeup((void *)w) -#define DRM_WAKEUP_INT(w) wakeup(w) -#define DRM_INIT_WAITQUEUE( queue ) do {} while (0) - -#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) - -#define cpu_to_le32(x) htole32(x) -#define le32_to_cpu(x) le32toh(x) - -typedef u_int32_t dma_addr_t; -typedef volatile long atomic_t; -typedef u_int32_t u32; -typedef u_int16_t u16; -typedef u_int8_t u8; -typedef dev_type_ioctl(d_ioctl_t); -typedef vaddr_t vm_offset_t; - -/* FIXME */ -#define atomic_set(p, v) (*(p) = (v)) -#define atomic_read(p) (*(p)) -#define atomic_inc(p) (*(p) += 1) -#define atomic_dec(p) (*(p) -= 1) -#define atomic_add(n, p) (*(p) += (n)) -#define atomic_sub(n, p) (*(p) -= (n)) - -/* FIXME */ -#define atomic_add_int(p, v) *(p) += v -#define atomic_subtract_int(p, v) *(p) -= v -#define atomic_set_int(p, bits) *(p) |= (bits) -#define atomic_clear_int(p, bits) *(p) &= ~(bits) - -/* Fake this */ - -static __inline int -atomic_cmpset_int(__volatile__ int *dst, int old, int new) -{ - int s = splhigh(); - if (*dst==old) { - *dst = new; - splx(s); - return 1; - } - splx(s); - return 0; -} - -static __inline atomic_t -test_and_set_bit(int b, atomic_t *p) -{ - int s = splhigh(); - unsigned int m = 1<<b; - unsigned int r = *p & m; - *p |= m; - splx(s); - return r; -} - -static __inline void -clear_bit(int b, atomic_t *p) -{ - atomic_clear_int(p + (b >> 5), 1 << (b & 0x1f)); -} - -static __inline void -set_bit(int b, atomic_t *p) -{ - atomic_set_int(p + (b >> 5), 1 << (b & 0x1f)); -} - -static __inline int -test_bit(int b, atomic_t *p) -{ - return p[b >> 5] & (1 << (b & 0x1f)); -} - -static __inline int -find_first_zero_bit(atomic_t *p, int max) -{ - int b; - - for (b = 0; b < max; b += 32) { - if (p[b >> 5] != ~0) { - for (;;) { - if ((p[b >> 5] & (1 << (b & 0x1f))) == 0) - return b; - b++; - } - } - } - return max; -} - -#define spldrm() spltty() -#define jiffies hardclock_ticks - -/* Redefinitions to make templating easy */ -#define wait_queue_head_t int -#define agp_memory void - - /* Macros to make printf easier */ -#define DRM_ERROR(fmt, arg...) \ -do { \ - printf("error: [" DRM_NAME ":%s] *ERROR* ", __func__ ); \ - printf( fmt,## arg ); \ -} while (0) - -#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 ":%s] " fmt , __FUNCTION__ ,## arg); \ - } while (0) -#else -#define DRM_DEBUG(fmt, arg...) do { } while (0) -#endif - -/* Internal functions */ - -/* drm_drv.h */ -extern dev_type_ioctl(drm_ioctl); -extern dev_type_open(drm_open); -extern dev_type_close(drm_close); -extern dev_type_read(drm_read); -extern dev_type_poll(drm_poll); -extern dev_type_mmap(drm_mmap); -extern int drm_open_helper(dev_t kdev, int flags, int fmt, - DRM_STRUCTPROC *p, drm_device_t *dev); -extern drm_file_t *drm_find_file_by_proc(drm_device_t *dev, - DRM_STRUCTPROC *p); - -extern int drm_sysctl_init(drm_device_t *dev); -extern int drm_sysctl_cleanup(drm_device_t *dev); diff --git a/bsd-core/drm_sysctl.c b/bsd-core/drm_sysctl.c index 085fb1f5..64066bc2 100644 --- a/bsd-core/drm_sysctl.c +++ b/bsd-core/drm_sysctl.c @@ -25,8 +25,6 @@ #include "drmP.h" #include "drm.h" -#ifdef __FreeBSD__ - #include <sys/sysctl.h> static int drm_name_info DRM_SYSCTL_HANDLER_ARGS; @@ -303,16 +301,3 @@ done: drm_free(tempprivs, sizeof(drm_file_t) * privcount, DRM_MEM_FILES); return retcode; } - -#elif defined(__NetBSD__) -/* stub it out for now, sysctl is only for debugging */ -int drm_sysctl_init(drm_device_t *dev) -{ - return 0; -} - -int drm_sysctl_cleanup(drm_device_t *dev) -{ - return 0; -} -#endif diff --git a/bsd-core/drm_vm.c b/bsd-core/drm_vm.c index da6d7773..f3558b9e 100644 --- a/bsd-core/drm_vm.c +++ b/bsd-core/drm_vm.c @@ -30,7 +30,7 @@ static int drm_dma_mmap(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr, int prot) #elif defined(__FreeBSD__) static int drm_dma_mmap(dev_t kdev, vm_offset_t offset, int prot) -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) static paddr_t drm_dma_mmap(dev_t kdev, vm_offset_t offset, int prot) #endif { @@ -59,7 +59,7 @@ int drm_mmap(struct cdev *kdev, vm_offset_t offset, vm_paddr_t *paddr, int prot) #elif defined(__FreeBSD__) int drm_mmap(dev_t kdev, vm_offset_t offset, int prot) -#elif defined(__NetBSD__) +#elif defined(__NetBSD__) || defined(__OpenBSD__) paddr_t drm_mmap(dev_t kdev, off_t offset, int prot) #endif { |