summaryrefslogtreecommitdiff
path: root/bsd
diff options
context:
space:
mode:
Diffstat (limited to 'bsd')
-rw-r--r--bsd/Makefile2
-rw-r--r--bsd/Makefile.bsd2
-rw-r--r--bsd/ati_pcigart.h53
-rw-r--r--bsd/drm.h1
-rw-r--r--bsd/drmP.h163
-rw-r--r--bsd/drm_agpsupport.h37
-rw-r--r--bsd/drm_auth.h18
-rw-r--r--bsd/drm_bufs.h77
-rw-r--r--bsd/drm_context.h29
-rw-r--r--bsd/drm_dma.h44
-rw-r--r--bsd/drm_drawable.h2
-rw-r--r--bsd/drm_drv.h223
-rw-r--r--bsd/drm_fops.h7
-rw-r--r--bsd/drm_init.h2
-rw-r--r--bsd/drm_ioctl.h4
-rw-r--r--bsd/drm_lists.h11
-rw-r--r--bsd/drm_lock.h35
-rw-r--r--bsd/drm_memory.h83
-rw-r--r--bsd/drm_os_freebsd.h182
-rw-r--r--bsd/drm_os_netbsd.h224
-rw-r--r--bsd/drm_scatter.h59
-rw-r--r--bsd/drm_sysctl.h98
-rw-r--r--bsd/drm_vm.h34
-rw-r--r--bsd/gamma.h71
-rw-r--r--bsd/gamma/Makefile23
-rw-r--r--bsd/gamma_dma.c611
-rw-r--r--bsd/gamma_drm.h89
-rw-r--r--bsd/gamma_drv.c86
-rw-r--r--bsd/gamma_drv.h104
-rw-r--r--bsd/mga_drv.c8
-rw-r--r--bsd/r128_drv.c9
-rw-r--r--bsd/radeon_drv.c57
-rw-r--r--bsd/tdfx_drv.c7
33 files changed, 737 insertions, 1718 deletions
diff --git a/bsd/Makefile b/bsd/Makefile
index ea44a7cd8..6281b00c0 100644
--- a/bsd/Makefile
+++ b/bsd/Makefile
@@ -1,6 +1,6 @@
# $FreeBSD$
# i810, i830 & sis are not complete
-SUBDIR = gamma mga r128 radeon tdfx # i810 i830 sis
+SUBDIR = mga r128 radeon tdfx # i810 i830 sis gamma
.include <bsd.subdir.mk>
diff --git a/bsd/Makefile.bsd b/bsd/Makefile.bsd
index ea44a7cd8..6281b00c0 100644
--- a/bsd/Makefile.bsd
+++ b/bsd/Makefile.bsd
@@ -1,6 +1,6 @@
# $FreeBSD$
# i810, i830 & sis are not complete
-SUBDIR = gamma mga r128 radeon tdfx # i810 i830 sis
+SUBDIR = mga r128 radeon tdfx # i810 i830 sis gamma
.include <bsd.subdir.mk>
diff --git a/bsd/ati_pcigart.h b/bsd/ati_pcigart.h
index 28723f568..0cc63a3aa 100644
--- a/bsd/ati_pcigart.h
+++ b/bsd/ati_pcigart.h
@@ -25,6 +25,8 @@
*
* Authors:
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/ati_pcigart.h,v 1.1 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -42,25 +44,6 @@
# define ATI_MAX_PCIGART_PAGES 8192 /* 32 MB aperture, 4K pages */
# define ATI_PCIGART_PAGE_SIZE 4096 /* PCI GART page size */
-static unsigned long DRM(ati_alloc_pcigart_table)( void )
-{
- unsigned long address;
-
- DRM_DEBUG( "\n" );
-
- address = (unsigned long) malloc( (1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE, DRM(M_DRM), M_WAITOK );
-
- DRM_DEBUG( "returning 0x%08lx\n", address );
- return address;
-}
-
-static void DRM(ati_free_pcigart_table)( unsigned long address )
-{
- DRM_DEBUG( "\n" );
-
- free( (void *)address, DRM(M_DRM));
-}
-
int DRM(ati_pcigart_init)( drm_device_t *dev,
unsigned long *addr,
dma_addr_t *bus_addr)
@@ -76,23 +59,15 @@ int DRM(ati_pcigart_init)( drm_device_t *dev,
goto done;
}
- address = DRM(ati_alloc_pcigart_table)();
+ address = (long)contigmalloc((1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE,
+ DRM(M_DRM), M_WAITOK, 0ul, 0xfffffffful, PAGE_SIZE, 0);
if ( !address ) {
DRM_ERROR( "cannot allocate PCI GART page!\n" );
goto done;
}
- /* FIXME non-vtophys==bustophys-arches */
+ /* XXX: we need to busdma this */
bus_address = vtophys( address );
- /*pci_map_single(dev->pdev, (void *)address,
- ATI_PCIGART_TABLE_PAGES * PAGE_SIZE,
- PCI_DMA_TODEVICE);*/
-/* if (bus_address == 0) {
- DRM_ERROR( "unable to map PCIGART pages!\n" );
- DRM(ati_free_pcigart_table)( (unsigned long)address );
- address = 0;
- goto done;
- }*/
pci_gart = (u32 *)address;
@@ -102,16 +77,7 @@ int DRM(ati_pcigart_init)( drm_device_t *dev,
bzero( pci_gart, ATI_MAX_PCIGART_PAGES * sizeof(u32) );
for ( i = 0 ; i < pages ; i++ ) {
- /* we need to support large memory configurations */
- /* FIXME non-vtophys==vtobus-arches */
entry->busaddr[i] = vtophys( entry->handle + (i*PAGE_SIZE) );
-/* if (entry->busaddr[i] == 0) {
- DRM_ERROR( "unable to map PCIGART pages!\n" );
- DRM(ati_pcigart_cleanup)( dev, (unsigned long)address, bus_address );
- address = 0;
- bus_address = 0;
- goto done;
- }*/
page_base = (u32) entry->busaddr[i];
for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
@@ -122,8 +88,6 @@ int DRM(ati_pcigart_init)( drm_device_t *dev,
ret = 1;
- DRM_READMEMORYBARRIER();
-
done:
*addr = address;
*bus_addr = bus_address;
@@ -142,9 +106,8 @@ int DRM(ati_pcigart_cleanup)( drm_device_t *dev,
return 0;
}
- if ( addr ) {
- DRM(ati_free_pcigart_table)( addr );
- }
-
+#if __FreeBSD_version > 500000
+ contigfree( (void *)addr, (1 << ATI_PCIGART_TABLE_ORDER) * PAGE_SIZE, DRM(M_DRM)); /* Not available on 4.x */
+#endif
return 1;
}
diff --git a/bsd/drm.h b/bsd/drm.h
index d1d669437..abe2ac3ff 100644
--- a/bsd/drm.h
+++ b/bsd/drm.h
@@ -30,6 +30,7 @@
* Acknowledgements:
* Dec 1999, Richard Henderson <rth@twiddle.net>, move to generic cmpxchg.
*
+ * $FreeBSD: src/sys/dev/drm/drm.h,v 1.3 2003/03/09 02:08:28 anholt Exp $
*/
#ifndef _DRM_H_
diff --git a/bsd/drmP.h b/bsd/drmP.h
index 541bc2ebe..96dd52d84 100644
--- a/bsd/drmP.h
+++ b/bsd/drmP.h
@@ -27,6 +27,7 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ * $FreeBSD: src/sys/dev/drm/drmP.h,v 1.3 2003/03/09 02:08:28 anholt Exp $
*/
#ifndef _DRM_P_H_
@@ -95,21 +96,20 @@ typedef struct drm_file drm_file_t;
#define DRM_MEM_MAGIC 3
#define DRM_MEM_IOCTLS 4
#define DRM_MEM_MAPS 5
-#define DRM_MEM_VMAS 6
-#define DRM_MEM_BUFS 7
-#define DRM_MEM_SEGS 8
-#define DRM_MEM_PAGES 9
-#define DRM_MEM_FILES 10
-#define DRM_MEM_QUEUES 11
-#define DRM_MEM_CMDS 12
-#define DRM_MEM_MAPPINGS 13
-#define DRM_MEM_BUFLISTS 14
-#define DRM_MEM_AGPLISTS 15
-#define DRM_MEM_TOTALAGP 16
-#define DRM_MEM_BOUNDAGP 17
-#define DRM_MEM_CTXBITMAP 18
-#define DRM_MEM_STUB 19
-#define DRM_MEM_SGLISTS 20
+#define DRM_MEM_BUFS 6
+#define DRM_MEM_SEGS 7
+#define DRM_MEM_PAGES 8
+#define DRM_MEM_FILES 9
+#define DRM_MEM_QUEUES 10
+#define DRM_MEM_CMDS 11
+#define DRM_MEM_MAPPINGS 12
+#define DRM_MEM_BUFLISTS 13
+#define DRM_MEM_AGPLISTS 14
+#define DRM_MEM_TOTALAGP 15
+#define DRM_MEM_BOUNDAGP 16
+#define DRM_MEM_CTXBITMAP 17
+#define DRM_MEM_STUB 18
+#define DRM_MEM_SGLISTS 19
#define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8)
@@ -121,15 +121,15 @@ typedef struct drm_file drm_file_t;
/* Mapping helper macros */
#define DRM_IOREMAP(map) \
- (map)->handle = DRM(ioremap)( (map)->offset, (map)->size )
+ (map)->handle = DRM(ioremap)( dev, map )
#define DRM_IOREMAP_NOCACHE(map) \
- (map)->handle = DRM(ioremap_nocache)((map)->offset, (map)->size)
+ (map)->handle = DRM(ioremap_nocache)( dev, map )
#define DRM_IOREMAPFREE(map) \
do { \
if ( (map)->handle && (map)->size ) \
- DRM(ioremapfree)( (map)->handle, (map)->size ); \
+ DRM(ioremapfree)( map ); \
} while (0)
/* Internal types and structures */
@@ -152,16 +152,11 @@ typedef struct drm_pci_list {
} drm_pci_list_t;
typedef struct drm_ioctl_desc {
- d_ioctl_t *func;
+ int (*func)(DRM_IOCTL_ARGS);
int auth_needed;
int root_only;
} drm_ioctl_desc_t;
-typedef struct drm_devstate {
- pid_t owner; /* X server pid holding x_lock */
-
-} drm_devstate_t;
-
typedef struct drm_magic_entry {
drm_magic_t magic;
struct drm_file *priv;
@@ -173,12 +168,6 @@ typedef struct drm_magic_head {
struct drm_magic_entry *tail;
} drm_magic_head_t;
-typedef struct drm_vma_entry {
- struct vm_area_struct *vma;
- struct drm_vma_entry *next;
- pid_t pid;
-} drm_vma_entry_t;
-
typedef struct drm_buf {
int idx; /* Index into master buflist */
int total; /* Buffer size */
@@ -191,7 +180,7 @@ typedef struct drm_buf {
__volatile__ int waiting; /* On kernel DMA queue */
__volatile__ int pending; /* On hardware DMA queue */
wait_queue_head_t dma_wait; /* Processes waiting */
- pid_t pid; /* PID of holding process */
+ DRMFILE filp; /* Unique identifier of holding process */
int context; /* Kernel queue for this buffer */
int while_locked;/* Dispatch this buffer while locked */
enum {
@@ -308,7 +297,7 @@ typedef struct drm_queue {
typedef struct drm_lock_data {
drm_hw_lock_t *hw_lock; /* Hardware lock */
- pid_t pid; /* PID of lock holder (0=kernel) */
+ DRMFILE filp; /* Unique identifier of holding process (NULL is kernel)*/
wait_queue_head_t lock_queue; /* Queue of blocked processes */
unsigned long lock_time; /* Time of last lock in jiffies */
} drm_lock_data_t;
@@ -377,7 +366,6 @@ typedef struct drm_sg_mem {
unsigned long handle;
void *virtual;
int pages;
- struct page **pagelist;
dma_addr_t *busaddr;
} drm_sg_mem_t;
@@ -386,10 +374,23 @@ typedef struct drm_sigdata {
drm_hw_lock_t *lock;
} drm_sigdata_t;
+typedef struct drm_local_map {
+ unsigned long offset; /* Physical address (0 for SAREA)*/
+ unsigned long size; /* Physical size (bytes) */
+ drm_map_type_t type; /* Type of memory mapped */
+ drm_map_flags_t flags; /* Flags */
+ void *handle; /* User-space: "Handle" to pass to mmap */
+ /* Kernel-space: kernel-virtual address */
+ int mtrr; /* MTRR slot used */
+ /* Private data */
+ bus_space_tag_t iot;
+ bus_space_handle_t ioh;
+} drm_local_map_t;
+
typedef TAILQ_HEAD(drm_map_list, drm_map_list_entry) drm_map_list_t;
typedef struct drm_map_list_entry {
TAILQ_ENTRY(drm_map_list_entry) link;
- drm_map_t *map;
+ drm_local_map_t *map;
} drm_map_list_entry_t;
TAILQ_HEAD(drm_vbl_sig_list, drm_vbl_sig);
@@ -423,7 +424,6 @@ struct drm_device {
/* Usage Counters */
int open_count; /* Outstanding files open */
atomic_t ioctl_count; /* Outstanding IOCTLs pending */
- atomic_t vma_count; /* Outstanding vma areas open */
int buf_use; /* Buffers in use -- cannot alloc */
atomic_t buf_alloc; /* Buffer allocation in progress */
@@ -440,10 +440,9 @@ struct drm_device {
drm_map_list_t *maplist; /* Linked list of regions */
int map_count; /* Number of mappable regions */
- drm_map_t **context_sareas;
+ drm_local_map_t **context_sareas;
int max_context;
- drm_vma_entry_t *vmalist; /* List of vmas (for debugging) */
drm_lock_data_t lock; /* Information on hardware lock */
/* DMA queues (contexts) */
@@ -454,9 +453,9 @@ struct drm_device {
drm_device_dma_t *dma; /* Optional pointer for DMA support */
/* Context support */
-#ifdef __FreeBSD__
int irq; /* Interrupt used by board */
int irqrid; /* Interrupt used by board */
+#ifdef __FreeBSD__
struct resource *irqr; /* Resource for interrupt used by board */
#elif defined(__NetBSD__)
struct pci_attach_args pa;
@@ -477,9 +476,11 @@ struct drm_device {
#if __HAVE_VBL_IRQ
wait_queue_head_t vbl_queue; /* vbl wait channel */
atomic_t vbl_received;
+#if 0 /* vbl signals are untested, ntested */
struct drm_vbl_sig_list vbl_sig_list;
DRM_SPINTYPE vbl_lock;
#endif
+#endif
cycles_t ctx_start;
cycles_t lck_start;
#if __HAVE_DMA_HISTOGRAM
@@ -530,15 +531,16 @@ extern int DRM(write_string)(drm_device_t *dev, const char *s);
/* Memory management support (drm_memory.h) */
extern void DRM(mem_init)(void);
+extern void DRM(mem_uninit)(void);
extern void *DRM(alloc)(size_t size, int area);
extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
int area);
extern char *DRM(strdup)(const char *s, int area);
extern void DRM(strfree)(char *s, int area);
extern void DRM(free)(void *pt, size_t size, int area);
-extern void *DRM(ioremap)(unsigned long offset, unsigned long size);
-extern void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size);
-extern void DRM(ioremapfree)(void *pt, unsigned long size);
+extern void *DRM(ioremap)(drm_device_t *dev, drm_local_map_t *map);
+extern void *DRM(ioremap_nocache)(drm_device_t *dev, drm_local_map_t *map);
+extern void DRM(ioremapfree)(drm_local_map_t *map);
#if __REALLY_HAVE_AGP
extern agp_memory *DRM(alloc_agp)(int pages, u32 type);
@@ -580,7 +582,7 @@ extern int DRM(order)( unsigned long size );
extern int DRM(dma_setup)(drm_device_t *dev);
extern void DRM(dma_takedown)(drm_device_t *dev);
extern void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf);
-extern void DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid);
+extern void DRM(reclaim_buffers)(drm_device_t *dev, DRMFILE filp);
#if __HAVE_OLD_DMA
/* GH: This is a dirty hack for now...
*/
@@ -652,5 +654,82 @@ extern int DRM(ati_pcigart_cleanup)(drm_device_t *dev,
dma_addr_t bus_addr);
#endif
+/* Locking IOCTL support (drm_drv.h) */
+extern int DRM(lock)(DRM_IOCTL_ARGS);
+extern int DRM(unlock)(DRM_IOCTL_ARGS);
+
+/* Misc. IOCTL support (drm_ioctl.h) */
+extern int DRM(irq_busid)(DRM_IOCTL_ARGS);
+extern int DRM(getunique)(DRM_IOCTL_ARGS);
+extern int DRM(setunique)(DRM_IOCTL_ARGS);
+extern int DRM(getmap)(DRM_IOCTL_ARGS);
+extern int DRM(getclient)(DRM_IOCTL_ARGS);
+extern int DRM(getstats)(DRM_IOCTL_ARGS);
+
+/* Context IOCTL support (drm_context.h) */
+extern int DRM(resctx)(DRM_IOCTL_ARGS);
+extern int DRM(addctx)(DRM_IOCTL_ARGS);
+extern int DRM(modctx)(DRM_IOCTL_ARGS);
+extern int DRM(getctx)(DRM_IOCTL_ARGS);
+extern int DRM(switchctx)(DRM_IOCTL_ARGS);
+extern int DRM(newctx)(DRM_IOCTL_ARGS);
+extern int DRM(rmctx)(DRM_IOCTL_ARGS);
+extern int DRM(setsareactx)(DRM_IOCTL_ARGS);
+extern int DRM(getsareactx)(DRM_IOCTL_ARGS);
+
+/* Drawable IOCTL support (drm_drawable.h) */
+extern int DRM(adddraw)(DRM_IOCTL_ARGS);
+extern int DRM(rmdraw)(DRM_IOCTL_ARGS);
+
+/* Authentication IOCTL support (drm_auth.h) */
+extern int DRM(getmagic)(DRM_IOCTL_ARGS);
+extern int DRM(authmagic)(DRM_IOCTL_ARGS);
+
+/* Locking IOCTL support (drm_lock.h) */
+extern int DRM(block)(DRM_IOCTL_ARGS);
+extern int DRM(unblock)(DRM_IOCTL_ARGS);
+extern int DRM(finish)(DRM_IOCTL_ARGS);
+
+/* Buffer management support (drm_bufs.h) */
+extern int DRM(addmap)(DRM_IOCTL_ARGS);
+extern int DRM(rmmap)(DRM_IOCTL_ARGS);
+#if __HAVE_DMA
+extern int DRM(addbufs_agp)(DRM_IOCTL_ARGS);
+extern int DRM(addbufs_pci)(DRM_IOCTL_ARGS);
+extern int DRM(addbufs_sg)(DRM_IOCTL_ARGS);
+extern int DRM(addbufs)(DRM_IOCTL_ARGS);
+extern int DRM(infobufs)(DRM_IOCTL_ARGS);
+extern int DRM(markbufs)(DRM_IOCTL_ARGS);
+extern int DRM(freebufs)(DRM_IOCTL_ARGS);
+extern int DRM(mapbufs)(DRM_IOCTL_ARGS);
+#endif
+
+/* DMA support (drm_dma.h) */
+#if __HAVE_DMA
+extern int DRM(control)(DRM_IOCTL_ARGS);
+#endif
+#if __HAVE_VBL_IRQ
+extern int DRM(wait_vblank)(DRM_IOCTL_ARGS);
+#endif
+
+/* AGP/GART support (drm_agpsupport.h) */
+#if __REALLY_HAVE_AGP
+extern int DRM(agp_acquire)(DRM_IOCTL_ARGS);
+extern int DRM(agp_release)(DRM_IOCTL_ARGS);
+extern int DRM(agp_enable)(DRM_IOCTL_ARGS);
+extern int DRM(agp_info)(DRM_IOCTL_ARGS);
+extern int DRM(agp_alloc)(DRM_IOCTL_ARGS);
+extern int DRM(agp_free)(DRM_IOCTL_ARGS);
+extern int DRM(agp_unbind)(DRM_IOCTL_ARGS);
+extern int DRM(agp_bind)(DRM_IOCTL_ARGS);
+#endif
+
+/* Scatter Gather Support (drm_scatter.h) */
+#if __HAVE_SG
+extern int DRM(sg_alloc)(DRM_IOCTL_ARGS);
+extern int DRM(sg_free)(DRM_IOCTL_ARGS);
+#endif
+
+
#endif /* __KERNEL__ */
#endif /* _DRM_P_H_ */
diff --git a/bsd/drm_agpsupport.h b/bsd/drm_agpsupport.h
index a940378e3..ca7bea9ef 100644
--- a/bsd/drm_agpsupport.h
+++ b/bsd/drm_agpsupport.h
@@ -27,6 +27,7 @@
* Author:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ * $FreeBSD: src/sys/dev/drm/drm_agpsupport.h,v 1.2 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -37,7 +38,8 @@ int DRM(agp_info)(DRM_IOCTL_ARGS)
struct agp_info *kern;
drm_agp_info_t info;
- if (!dev->agp || !dev->agp->acquired) return EINVAL;
+ if (!dev->agp || !dev->agp->acquired)
+ return EINVAL;
kern = &dev->agp->info;
agp_get_info(dev->agp->agpdev, kern);
@@ -60,9 +62,11 @@ int DRM(agp_acquire)(DRM_IOCTL_ARGS)
DRM_DEVICE;
int retcode;
- if (!dev->agp || dev->agp->acquired) return EINVAL;
+ if (!dev->agp || dev->agp->acquired)
+ return EINVAL;
retcode = agp_acquire(dev->agp->agpdev);
- if (retcode) return retcode;
+ if (retcode)
+ return retcode;
dev->agp->acquired = 1;
return 0;
}
@@ -93,7 +97,8 @@ int DRM(agp_enable)(DRM_IOCTL_ARGS)
DRM_DEVICE;
drm_agp_mode_t mode;
- if (!dev->agp || !dev->agp->acquired) return EINVAL;
+ if (!dev->agp || !dev->agp->acquired)
+ return EINVAL;
mode = *(drm_agp_mode_t *) data;
@@ -114,7 +119,8 @@ int DRM(agp_alloc)(DRM_IOCTL_ARGS)
u_int32_t type;
struct agp_memory_info info;
- if (!dev->agp || !dev->agp->acquired) return EINVAL;
+ if (!dev->agp || !dev->agp->acquired)
+ return EINVAL;
request = *(drm_agp_buffer_t *) data;
@@ -136,7 +142,8 @@ int DRM(agp_alloc)(DRM_IOCTL_ARGS)
entry->pages = pages;
entry->prev = NULL;
entry->next = dev->agp->memory;
- if (dev->agp->memory) dev->agp->memory->prev = entry;
+ if (dev->agp->memory)
+ dev->agp->memory->prev = entry;
dev->agp->memory = entry;
agp_memory_info(dev->agp->agpdev, entry->handle, &info);
@@ -166,7 +173,8 @@ int DRM(agp_unbind)(DRM_IOCTL_ARGS)
drm_agp_mem_t *entry;
int retcode;
- if (!dev->agp || !dev->agp->acquired) return EINVAL;
+ if (!dev->agp || !dev->agp->acquired)
+ return EINVAL;
request = *(drm_agp_binding_t *) data;
if (!(entry = DRM(agp_lookup_entry)(dev, (void *) request.handle)))
return EINVAL;
@@ -209,15 +217,20 @@ int DRM(agp_free)(DRM_IOCTL_ARGS)
drm_agp_buffer_t request;
drm_agp_mem_t *entry;
- if (!dev->agp || !dev->agp->acquired) return EINVAL;
+ if (!dev->agp || !dev->agp->acquired)
+ return EINVAL;
request = *(drm_agp_buffer_t *) data;
if (!(entry = DRM(agp_lookup_entry)(dev, (void*) request.handle)))
return EINVAL;
- if (entry->bound) DRM(unbind_agp)(entry->handle);
+ if (entry->bound)
+ DRM(unbind_agp)(entry->handle);
- if (entry->prev) entry->prev->next = entry->next;
- else dev->agp->memory = entry->next;
- if (entry->next) entry->next->prev = entry->prev;
+ if (entry->prev)
+ entry->prev->next = entry->next;
+ else
+ dev->agp->memory = entry->next;
+ if (entry->next)
+ entry->next->prev = entry->prev;
DRM(free_agp)(entry->handle, entry->pages);
DRM(free)(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
return 0;
diff --git a/bsd/drm_auth.h b/bsd/drm_auth.h
index 0b411d14d..c506ee7e0 100644
--- a/bsd/drm_auth.h
+++ b/bsd/drm_auth.h
@@ -27,6 +27,7 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ * $FreeBSD: src/sys/dev/drm/drm_auth.h,v 1.3 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -116,25 +117,20 @@ int DRM(getmagic)(DRM_IOCTL_ARGS)
{
static drm_magic_t sequence = 0;
drm_auth_t auth;
- static DRM_SPINTYPE lock;
- static int first = 1;
DRM_DEVICE;
DRM_PRIV;
- if (first) {
- DRM_SPININIT(lock, "drm getmagic");
- first = 0;
- }
-
/* Find unique magic */
if (priv->magic) {
auth.magic = priv->magic;
} else {
do {
- DRM_SPINLOCK(&lock);
- if (!sequence) ++sequence; /* reserve 0 */
- auth.magic = sequence++;
- DRM_SPINUNLOCK(&lock);
+ int old = sequence;
+
+ auth.magic = old+1;
+
+ if (!atomic_cmpset_int(&sequence, old, auth.magic))
+ continue;
} while (DRM(find_file)(dev, auth.magic));
priv->magic = auth.magic;
DRM(add_magic)(dev, priv, auth.magic);
diff --git a/bsd/drm_bufs.h b/bsd/drm_bufs.h
index 7d56d0a38..8e0534f2e 100644
--- a/bsd/drm_bufs.h
+++ b/bsd/drm_bufs.h
@@ -27,6 +27,7 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ * $FreeBSD: src/sys/dev/drm/drm_bufs.h,v 1.4 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -69,18 +70,26 @@ int DRM(order)( unsigned long size )
int DRM(addmap)( DRM_IOCTL_ARGS )
{
DRM_DEVICE;
- drm_map_t *map;
+ drm_map_t request;
+ drm_local_map_t *map;
drm_map_list_entry_t *list;
if (!(dev->flags & (FREAD|FWRITE)))
return DRM_ERR(EACCES); /* Require read/write */
- map = (drm_map_t *) DRM(alloc)( sizeof(*map), DRM_MEM_MAPS );
+ DRM_COPY_FROM_USER_IOCTL( request, (drm_map_t *)data, sizeof(drm_map_t) );
+
+ map = (drm_local_map_t *) DRM(alloc)( sizeof(*map), DRM_MEM_MAPS );
if ( !map )
return DRM_ERR(ENOMEM);
- *map = *(drm_map_t *)data;
-
+ map->offset = request.offset;
+ map->size = request.size;
+ map->type = request.type;
+ map->flags = request.flags;
+ map->mtrr = -1;
+ map->handle = 0;
+
/* Only allow shared memory to be removable since we only keep enough
* book keeping information about shared memory to allow for removal
* when processes fork.
@@ -95,22 +104,14 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
return DRM_ERR(EINVAL);
}
- map->mtrr = -1;
- map->handle = 0;
switch ( map->type ) {
case _DRM_REGISTERS:
case _DRM_FRAME_BUFFER:
-#if !defined(__sparc__) && !defined(__alpha__)
- if ( map->offset + map->size < map->offset
- ) {
+ if ( map->offset + map->size < map->offset ) {
DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
return DRM_ERR(EINVAL);
}
-#endif
-#ifdef __alpha__
- map->offset += dev->hose->mem_space->start;
-#endif
#if __REALLY_HAVE_MTRR
if ( map->type == _DRM_FRAME_BUFFER ||
(map->flags & _DRM_WRITE_COMBINING) ) {
@@ -130,14 +131,12 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
mtrrmap.base = map->offset;
mtrrmap.len = map->size;
mtrrmap.type = MTRR_TYPE_WC;
- mtrrmap.flags = MTRR_PRIVATE | MTRR_VALID;
- mtrrmap.owner = p->p_pid;
- /* USER? KERNEL? XXX */
- map->mtrr = mtrr_get( &mtrrmap, &one, p, MTRR_GETSET_KERNEL );
+ mtrrmap.flags = MTRR_VALID;
+ map->mtrr = mtrr_set( &mtrrmap, &one, p, MTRR_GETSET_KERNEL );
#endif
}
#endif /* __REALLY_HAVE_MTRR */
- map->handle = DRM(ioremap)( map->offset, map->size );
+ DRM_IOREMAP(map);
break;
case _DRM_SHM:
@@ -155,9 +154,6 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
break;
#if __REALLY_HAVE_AGP
case _DRM_AGP:
-#ifdef __alpha__
- map->offset += dev->hose->mem_space->start;
-#endif
map->offset += dev->agp->base;
map->mtrr = dev->agp->agp_mtrr; /* for getmap */
break;
@@ -187,11 +183,19 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
TAILQ_INSERT_TAIL(dev->maplist, list, link);
DRM_UNLOCK;
- *(drm_map_t *)data = *map;
+ request.offset = map->offset;
+ request.size = map->size;
+ request.type = map->type;
+ request.flags = map->flags;
+ request.mtrr = map->mtrr;
+ request.handle = map->handle;
- if ( map->type != _DRM_SHM ) {
- ((drm_map_t *)data)->handle = (void *)map->offset;
+ if ( request.type != _DRM_SHM ) {
+ request.handle = (void *)request.offset;
}
+
+ DRM_COPY_TO_USER_IOCTL( (drm_map_t *)data, request, sizeof(drm_map_t) );
+
return 0;
}
@@ -204,7 +208,7 @@ int DRM(rmmap)( DRM_IOCTL_ARGS )
{
DRM_DEVICE;
drm_map_list_entry_t *list;
- drm_map_t *map;
+ drm_local_map_t *map;
drm_map_t request;
int found_maps = 0;
@@ -257,7 +261,7 @@ int DRM(rmmap)( DRM_IOCTL_ARGS )
#endif
}
#endif
- DRM(ioremapfree)(map->handle, map->size);
+ DRM(ioremapfree)( map );
break;
case _DRM_SHM:
DRM(free)( map->handle, map->size, DRM_MEM_SAREA );
@@ -413,7 +417,7 @@ int DRM(addbufs_agp)( DRM_IOCTL_ARGS )
buf->waiting = 0;
buf->pending = 0;
buf->dma_wait = 0;
- buf->pid = 0;
+ buf->filp = NULL;
buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T);
buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T),
@@ -621,7 +625,7 @@ int DRM(addbufs_pci)( DRM_IOCTL_ARGS )
buf->waiting = 0;
buf->pending = 0;
buf->dma_wait = 0;
- buf->pid = 0;
+ buf->filp = NULL;
#if __HAVE_DMA_HISTOGRAM
buf->time_queued = 0;
buf->time_dispatched = 0;
@@ -774,7 +778,7 @@ int DRM(addbufs_sg)( DRM_IOCTL_ARGS )
buf->waiting = 0;
buf->pending = 0;
buf->dma_wait = 0;
- buf->pid = 0;
+ buf->filp = NULL;
buf->dev_priv_size = sizeof(DRIVER_BUF_PRIV_T);
buf->dev_private = DRM(alloc)( sizeof(DRIVER_BUF_PRIV_T),
@@ -858,16 +862,16 @@ int DRM(addbufs)( DRM_IOCTL_ARGS )
#if __REALLY_HAVE_AGP
if ( request.flags & _DRM_AGP_BUFFER )
- return DRM(addbufs_agp)( kdev, cmd, data, flags, p );
+ return DRM(addbufs_agp)( kdev, cmd, data, flags, p, filp );
else
#endif
#if __REALLY_HAVE_SG
if ( request.flags & _DRM_SG_BUFFER )
- return DRM(addbufs_sg)( kdev, cmd, data, flags, p );
+ return DRM(addbufs_sg)( kdev, cmd, data, flags, p, filp );
else
#endif
#if __HAVE_PCI_DMA
- return DRM(addbufs_pci)( kdev, cmd, data, flags, p );
+ return DRM(addbufs_pci)( kdev, cmd, data, flags, p, filp );
#else
return DRM_ERR(EINVAL);
#endif
@@ -991,9 +995,9 @@ int DRM(freebufs)( DRM_IOCTL_ARGS )
return DRM_ERR(EINVAL);
}
buf = dma->buflist[idx];
- if ( buf->pid != DRM_CURRENTPID ) {
- DRM_ERROR( "Process %d freeing buffer owned by %d\n",
- DRM_CURRENTPID, buf->pid );
+ if ( buf->filp != filp ) {
+ DRM_ERROR("Process %d freeing buffer not owned\n",
+ DRM_CURRENTPID);
return DRM_ERR(EINVAL);
}
DRM(free_buffer)( dev, buf );
@@ -1018,6 +1022,7 @@ int DRM(mapbufs)( DRM_IOCTL_ARGS )
#endif /* __FreeBSD__ */
#ifdef __NetBSD__
struct vnode *vn;
+ struct vmspace *vms = p->p_vmspace;
#endif /* __NetBSD__ */
drm_buf_map_t request;
@@ -1043,7 +1048,7 @@ int DRM(mapbufs)( DRM_IOCTL_ARGS )
if ( request.count >= dma->buf_count ) {
if ( (__HAVE_AGP && (dma->flags & _DRM_DMA_USE_AGP)) ||
(__HAVE_SG && (dma->flags & _DRM_DMA_USE_SG)) ) {
- drm_map_t *map = DRIVER_AGP_BUFFERS_MAP( dev );
+ drm_local_map_t *map = DRIVER_AGP_BUFFERS_MAP( dev );
if ( !map ) {
retcode = EINVAL;
diff --git a/bsd/drm_context.h b/bsd/drm_context.h
index 0274a8b79..c3a20f6e6 100644
--- a/bsd/drm_context.h
+++ b/bsd/drm_context.h
@@ -27,6 +27,7 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ * $FreeBSD: src/sys/dev/drm/drm_context.h,v 1.3 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -69,7 +70,7 @@ int DRM(ctxbitmap_next)( drm_device_t *dev )
if((bit+1) > dev->max_context) {
dev->max_context = (bit+1);
if(dev->context_sareas) {
- drm_map_t **ctx_sareas;
+ drm_local_map_t **ctx_sareas;
ctx_sareas = DRM(realloc)(dev->context_sareas,
(dev->max_context - 1) *
@@ -149,7 +150,7 @@ int DRM(getsareactx)( DRM_IOCTL_ARGS )
{
DRM_DEVICE;
drm_ctx_priv_map_t request;
- drm_map_t *map;
+ drm_local_map_t *map;
DRM_COPY_FROM_USER_IOCTL( request, (drm_ctx_priv_map_t *)data,
sizeof(request) );
@@ -174,7 +175,7 @@ int DRM(setsareactx)( DRM_IOCTL_ARGS )
{
DRM_DEVICE;
drm_ctx_priv_map_t request;
- drm_map_t *map = NULL;
+ drm_local_map_t *map = NULL;
drm_map_list_entry_t *list;
DRM_COPY_FROM_USER_IOCTL( request, (drm_ctx_priv_map_t *)data,
@@ -183,24 +184,20 @@ int DRM(setsareactx)( DRM_IOCTL_ARGS )
DRM_LOCK;
TAILQ_FOREACH(list, dev->maplist, link) {
map=list->map;
- if(map->handle == request.handle)
- goto found;
+ if(map->handle == request.handle) {
+ if (dev->max_context < 0)
+ goto bad;
+ if (request.ctx_id >= (unsigned) dev->max_context)
+ goto bad;
+ dev->context_sareas[request.ctx_id] = map;
+ DRM_UNLOCK;
+ return 0;
+ }
}
bad:
DRM_UNLOCK;
return DRM_ERR(EINVAL);
-
-found:
- map = list->map;
- if (!map) goto bad;
- if (dev->max_context < 0)
- goto bad;
- if (request.ctx_id >= (unsigned) dev->max_context)
- goto bad;
- dev->context_sareas[request.ctx_id] = map;
- DRM_UNLOCK;
- return 0;
}
/* ================================================================
diff --git a/bsd/drm_dma.h b/bsd/drm_dma.h
index 0f0dd4fdf..fa0bd20d0 100644
--- a/bsd/drm_dma.h
+++ b/bsd/drm_dma.h
@@ -27,6 +27,8 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_dma.h,v 1.4 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -180,7 +182,7 @@ void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf)
buf->waiting = 0;
buf->pending = 0;
- buf->pid = 0;
+ buf->filp = NULL;
buf->used = 0;
#if __HAVE_DMA_HISTOGRAM
buf->time_completed = get_cycles();
@@ -203,14 +205,14 @@ void DRM(free_buffer)(drm_device_t *dev, drm_buf_t *buf)
}
#if !__HAVE_DMA_RECLAIM
-void DRM(reclaim_buffers)(drm_device_t *dev, pid_t pid)
+void DRM(reclaim_buffers)(drm_device_t *dev, DRMFILE filp)
{
drm_device_dma_t *dma = dev->dma;
int i;
if (!dma) return;
for (i = 0; i < dma->buf_count; i++) {
- if (dma->buflist[i]->pid == pid) {
+ if (dma->buflist[i]->filp == filp) {
switch (dma->buflist[i]->list) {
case DRM_LIST_NONE:
DRM(free_buffer)(dev, dma->buflist[i]);
@@ -524,7 +526,7 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
TASK_INIT(&dev->task, 0, DRM(dma_immediate_bh), dev);
#endif
-#if __HAVE_VBL_IRQ
+#if __HAVE_VBL_IRQ && 0 /* disabled */
DRM_SPININIT( dev->vbl_lock, "vblsig" );
TAILQ_INIT( &dev->vbl_sig_list );
#endif
@@ -534,9 +536,13 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
/* Install handler */
dev->irqrid = 0;
+#ifdef __FreeBSD__
dev->irqr = bus_alloc_resource(dev->device, SYS_RES_IRQ, &dev->irqrid,
0, ~0, 1, RF_SHAREABLE);
if (!dev->irqr) {
+#elif defined(__NetBSD__)
+ if (pci_intr_map(&dev->pa, &dev->ih) != 0) {
+#endif
DRM_LOCK;
dev->irq = 0;
dev->irqrid = 0;
@@ -544,11 +550,24 @@ int DRM(irq_install)( drm_device_t *dev, int irq )
return ENOENT;
}
+#ifdef __FreeBSD__
+#if __FreeBSD_version < 500000
retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY,
DRM(dma_service), dev, &dev->irqh);
+#else
+ retcode = bus_setup_intr(dev->device, dev->irqr, INTR_TYPE_TTY | INTR_MPSAFE,
+ DRM(dma_service), dev, &dev->irqh);
+#endif
if ( retcode ) {
+#elif defined(__NetBSD__)
+ dev->irqh = pci_intr_establish(&dev->pa.pa_pc, dev->ih, IPL_TTY,
+ (int (*)(DRM_IRQ_ARGS))DRM(dma_service), dev);
+ if ( !dev->irqh ) {
+#endif
DRM_LOCK;
+#ifdef __FreeBSD__
bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid, dev->irqr);
+#endif
dev->irq = 0;
dev->irqrid = 0;
DRM_UNLOCK;
@@ -580,9 +599,13 @@ int DRM(irq_uninstall)( drm_device_t *dev )
DRM(driver_irq_uninstall)( 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__)
+ pci_intr_disestablish(&dev->pa.pa_pc, dev->irqh);
+#endif
+
return 0;
}
@@ -624,6 +647,7 @@ int DRM(wait_vblank)( DRM_IOCTL_ARGS )
flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
if (flags & _DRM_VBLANK_SIGNAL) {
+#if 0 /* disabled */
drm_vbl_sig_t *vbl_sig = DRM_MALLOC(sizeof(drm_vbl_sig_t));
if (vbl_sig == NULL)
return ENOMEM;
@@ -639,6 +663,8 @@ int DRM(wait_vblank)( DRM_IOCTL_ARGS )
TAILQ_INSERT_HEAD(&dev->vbl_sig_list, vbl_sig, link);
DRM_SPINUNLOCK(&dev->vbl_lock);
ret = 0;
+#endif
+ ret = EINVAL;
} else {
ret = DRM(vblank_wait)(dev, &vblwait.request.sequence);
@@ -653,6 +679,11 @@ int DRM(wait_vblank)( DRM_IOCTL_ARGS )
return ret;
}
+void DRM(vbl_send_signals)(drm_device_t *dev)
+{
+}
+
+#if 0 /* disabled */
void DRM(vbl_send_signals)( drm_device_t *dev )
{
drm_vbl_sig_t *vbl_sig;
@@ -671,13 +702,14 @@ void DRM(vbl_send_signals)( drm_device_t *dev )
psignal(p, vbl_sig->signo);
TAILQ_REMOVE(&dev->vbl_sig_list, vbl_sig, link);
- DRM_FREE(vbl_sig);
+ DRM_FREE(vbl_sig,sizeof(*vbl_sig));
}
vbl_sig = next;
}
DRM_SPINUNLOCK(&dev->vbl_lock);
}
+#endif
#endif /* __HAVE_VBL_IRQ */
diff --git a/bsd/drm_drawable.h b/bsd/drm_drawable.h
index 308410678..25dfc6d90 100644
--- a/bsd/drm_drawable.h
+++ b/bsd/drm_drawable.h
@@ -27,6 +27,8 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_drawable.h,v 1.2 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
diff --git a/bsd/drm_drv.h b/bsd/drm_drv.h
index 4a6fc15f1..d43a46663 100644
--- a/bsd/drm_drv.h
+++ b/bsd/drm_drv.h
@@ -27,6 +27,8 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_drv.h,v 1.12 2003/03/09 02:08:28 anholt Exp $
*/
/*
@@ -125,16 +127,10 @@
#define DRIVER_NUM_CARDS 1
#endif
-#ifdef __FreeBSD__
static int DRM(init)(device_t nbdev);
static void DRM(cleanup)(device_t nbdev);
-#elif defined(__NetBSD__)
-static int DRM(init)(drm_device_t *);
-static void DRM(cleanup)(drm_device_t *);
-#endif
#ifdef __FreeBSD__
-#define CDEV_MAJOR 145
#define DRIVER_SOFTC(unit) \
((drm_device_t *) devclass_get_softc(DRM(devclass), unit))
@@ -147,9 +143,8 @@ MODULE_DEPEND(DRIVER_NAME, linux, 1, 1, 1);
#endif /* __FreeBSD__ */
#ifdef __NetBSD__
-#define CDEV_MAJOR 90
#define DRIVER_SOFTC(unit) \
- ((drm_device_t *) device_lookup(&DRM(_cd), unit))
+ ((drm_device_t *) device_lookup(&DRM(cd), unit))
#endif /* __NetBSD__ */
static drm_ioctl_desc_t DRM(ioctls)[] = {
@@ -229,6 +224,22 @@ static drm_ioctl_desc_t DRM(ioctls)[] = {
const char *DRM(find_description)(int vendor, int device);
#ifdef __FreeBSD__
+static struct cdevsw DRM(cdevsw) = {
+ .d_open = DRM( open ),
+ .d_close = DRM( close ),
+ .d_read = DRM( read ),
+ .d_write = DRM( write ),
+ .d_ioctl = DRM( ioctl ),
+ .d_poll = DRM( poll ),
+ .d_mmap = DRM( mmap ),
+ .d_name = DRIVER_NAME,
+ .d_maj = CDEV_MAJOR,
+ .d_flags = D_TTY | D_TRACKCLOSE,
+#if __FreeBSD_version < 500000
+ .d_bmaj = -1
+#endif
+};
+
static int DRM(probe)(device_t dev)
{
const char *s = NULL;
@@ -271,57 +282,108 @@ static driver_t DRM(driver) = {
sizeof(drm_device_t),
};
-static devclass_t DRM( devclass);
-
-static struct cdevsw DRM( cdevsw) = {
- /* open */ DRM( open ),
- /* close */ DRM( close ),
- /* read */ DRM( read ),
- /* write */ DRM( write ),
- /* ioctl */ DRM( ioctl ),
- /* poll */ DRM( poll ),
- /* mmap */ DRM( mmap ),
- /* strategy */ nostrategy,
- /* name */ DRIVER_NAME,
- /* maj */ CDEV_MAJOR,
- /* dump */ nodump,
- /* psize */ nopsize,
- /* flags */ D_TTY | D_TRACKCLOSE,
-#if __FreeBSD_version >= 500000
- /* kqfilter */ 0
+static devclass_t DRM(devclass);
+
+#elif defined(__NetBSD__)
+
+static struct cdevsw DRM(cdevsw) = {
+ DRM(open),
+ DRM(close),
+ DRM(read),
+ DRM(write),
+ DRM(ioctl),
+ nostop,
+ notty,
+ DRM(poll),
+ DRM(mmap),
+ nokqfilter,
+ D_TTY
+};
+
+int DRM(refcnt) = 0;
+#if __NetBSD_Version__ >= 106080000
+MOD_DEV( DRIVER_NAME, DRIVER_NAME, NULL, -1, &DRM(cdevsw), CDEV_MAJOR);
#else
- /* bmaj */ -1
+MOD_DEV( DRIVER_NAME, LM_DT_CHAR, CDEV_MAJOR, &DRM(cdevsw) );
#endif
-};
-#elif defined(__NetBSD__)
-int DRM(probe)(struct device *parent, struct cfdata *match, void *aux);
-void DRM(attach)(struct device *parent, struct device *self, void *aux);
-int DRM(detach)(struct device *self, int flags);
-int DRM(activate)(struct device *self, enum devact act);
-
-struct cfattach DRM(_ca) = {
- sizeof(drm_device_t), DRM(probe),
- DRM(attach), DRM(detach), DRM(activate) };
+int DRM(lkmentry)(struct lkm_table *lkmtp, int cmd, int ver);
+static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd);
+
+int DRM(modprobe)();
+int DRM(probe)(struct pci_attach_args *pa);
+void DRM(attach)(struct pci_attach_args *pa, dev_t kdev);
+
+int DRM(lkmentry)(struct lkm_table *lkmtp, int cmd, int ver) {
+ DISPATCH(lkmtp, cmd, ver, DRM(lkmhandle), DRM(lkmhandle), DRM(lkmhandle));
+}
+
+static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd)
+{
+ int j, error = 0;
+#if defined(__NetBSD__) && (__NetBSD_Version__ > 106080000)
+ struct lkm_dev *args = lkmtp->private.lkm_dev;
+#endif
+
+ switch(cmd) {
+ case LKM_E_LOAD:
+ if (lkmexists(lkmtp))
+ return EEXIST;
+
+ if(DRM(modprobe)())
+ return 0;
+
+ return 1;
+
+ case LKM_E_UNLOAD:
+ if (DRM(refcnt) > 0)
+ return (EBUSY);
+ break;
+ case LKM_E_STAT:
+ break;
+
+ default:
+ error = EIO;
+ break;
+ }
-int DRM(probe)(struct device *parent, struct cfdata *match, void *aux)
+ return error;
+}
+
+int DRM(modprobe)() {
+ struct pci_attach_args pa;
+ int error = 0;
+ if((error = pci_find_device(&pa, DRM(probe))) != 0)
+ DRM(attach)(&pa, 0);
+
+ return error;
+}
+
+int DRM(probe)(struct pci_attach_args *pa)
{
- struct pci_attach_args *pa = aux;
const char *desc;
desc = DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id));
- if (desc != NULL)
- return 10;
+ if (desc != NULL) {
+ return 1;
+ }
+
return 0;
}
-void DRM(attach)(struct device *parent, struct device *self, void *aux)
+void DRM(attach)(struct pci_attach_args *pa, dev_t kdev)
{
- struct pci_attach_args *pa = aux;
- drm_device_t *dev = (drm_device_t *)self;
-
- memcpy(&dev->pa, aux, sizeof(dev->pa));
-
+ int i;
+ drm_device_t *dev;
+
+ config_makeroom(kdev, &DRM(cd));
+ DRM(cd).cd_devs[(kdev)] = DRM(alloc)(sizeof(drm_device_t),
+ DRM_MEM_DRIVER);
+ dev = DRIVER_SOFTC(kdev);
+
+ memset(dev, 0, sizeof(drm_device_t));
+ memcpy(&dev->pa, pa, sizeof(dev->pa));
+
DRM_INFO("%s", DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id)));
DRM(init)(dev);
}
@@ -345,8 +407,7 @@ int DRM(activate)(struct device *self, enum devact act)
}
return (0);
}
-
-#endif
+#endif /* __NetBSD__ */
const char *DRM(find_description)(int vendor, int device) {
const char *s = NULL;
@@ -372,7 +433,6 @@ static int DRM(setup)( drm_device_t *dev )
DRIVER_PRESETUP();
atomic_set( &dev->ioctl_count, 0 );
- atomic_set( &dev->vma_count, 0 );
dev->buf_use = 0;
atomic_set( &dev->buf_alloc, 0 );
@@ -435,7 +495,6 @@ static int DRM(setup)( drm_device_t *dev )
TAILQ_INIT(dev->maplist);
dev->map_count = 0;
- dev->vmalist = NULL;
dev->lock.hw_lock = NULL;
dev->lock.lock_queue = 0;
dev->queue_count = 0;
@@ -487,9 +546,8 @@ static int DRM(setup)( drm_device_t *dev )
static int DRM(takedown)( drm_device_t *dev )
{
drm_magic_entry_t *pt, *next;
- drm_map_t *map;
+ drm_local_map_t *map;
drm_map_list_entry_t *list;
- drm_vma_entry_t *vma, *vma_next;
int i;
DRM_DEBUG( "\n" );
@@ -546,15 +604,6 @@ static int DRM(takedown)( drm_device_t *dev )
}
#endif
- /* Clear vma list (only built for debugging) */
- if ( dev->vmalist ) {
- for ( vma = dev->vmalist ; vma ; vma = vma_next ) {
- vma_next = vma->next;
- DRM(free)( vma, sizeof(*vma), DRM_MEM_VMAS );
- }
- dev->vmalist = NULL;
- }
-
if( dev->maplist ) {
while ((list=TAILQ_FIRST(dev->maplist))) {
map = list->map;
@@ -581,15 +630,13 @@ static int DRM(takedown)( drm_device_t *dev )
mtrrmap.len = map->size;
mtrrmap.type = MTRR_TYPE_WC;
mtrrmap.flags = 0;
- /*mtrrmap.owner = p->p_pid;*/
- /* XXX: Use curproc here? */
retcode = mtrr_set( &mtrrmap, &one,
DRM_CURPROC, MTRR_GETSET_KERNEL);
#endif
DRM_DEBUG( "mtrr_del=%d\n", retcode );
}
#endif
- DRM(ioremapfree)( map->handle, map->size );
+ DRM(ioremapfree)( map );
break;
case _DRM_SHM:
DRM(free)(map->handle,
@@ -646,7 +693,7 @@ static int DRM(takedown)( drm_device_t *dev )
#endif
if ( dev->lock.hw_lock ) {
dev->lock.hw_lock = NULL; /* SHM removed */
- dev->lock.pid = 0;
+ dev->lock.filp = NULL;
DRM_WAKEUP_INT((void *)&dev->lock.lock_queue);
}
DRM_UNLOCK;
@@ -658,15 +705,13 @@ static int DRM(takedown)( drm_device_t *dev )
* linux/init/main.c (this is not currently supported).
* bsd: drm_init is called via the attach function per device.
*/
-#ifdef __FreeBSD__
static int DRM(init)( device_t nbdev )
-#elif defined(__NetBSD__)
-static int DRM(init)( drm_device_t *dev )
-#endif
{
int unit;
#ifdef __FreeBSD__
drm_device_t *dev;
+#elif defined(__NetBSD__)
+ drm_device_t *dev = nbdev;
#endif
#if __HAVE_CTX_BITMAP
int retcode;
@@ -724,7 +769,6 @@ static int DRM(init)( drm_device_t *dev )
struct mtrr mtrrmap;
int one = 1;
mtrrmap.base = dev->agp->info.ai_aperture_base;
- /* Might need a multiplier here XXX */
mtrrmap.len = dev->agp->info.ai_aperture_size;
mtrrmap.type = MTRR_TYPE_WC;
mtrrmap.flags = MTRR_VALID;
@@ -763,21 +807,16 @@ static int DRM(init)( drm_device_t *dev )
* bsd: drm_cleanup is called per device at module unload time.
* FIXME: NetBSD
*/
-#ifdef __FreeBSD__
static void DRM(cleanup)(device_t nbdev)
-#elif defined(__NetBSD__)
-static void DRM(cleanup)(drm_device_t *dev)
-#endif
{
-#ifdef __FreeBSD__
drm_device_t *dev;
-#endif
-#if __REALLY_HAVE_MTRR
#ifdef __NetBSD__
+#if __REALLY_HAVE_MTRR
struct mtrr mtrrmap;
int one = 1;
-#endif /* __NetBSD__ */
#endif /* __REALLY_HAVE_MTRR */
+ dev = nbdev;
+#endif /* __NetBSD__ */
DRM_DEBUG( "\n" );
@@ -799,7 +838,7 @@ static void DRM(cleanup)(drm_device_t *dev)
mtrrmap.len = dev->agp->info.ai_aperture_size;
mtrrmap.type = 0;
mtrrmap.flags = 0;
- retval = mtrr_set( &mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
+ mtrr_set( &mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
#endif
}
#endif
@@ -814,6 +853,8 @@ static void DRM(cleanup)(drm_device_t *dev)
}
#endif
DRIVER_POSTCLEANUP();
+ DRM(mem_uninit)();
+ DRM_SPINUNINIT(dev->count_lock);
}
@@ -876,7 +917,8 @@ int DRM(close)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p)
drm_file_t *priv;
DRM_DEVICE;
int retcode = 0;
-
+ DRMFILE __unused filp = (void *)(DRM_CURRENTPID);
+
DRM_DEBUG( "open_count = %d\n", dev->open_count );
priv = DRM(find_file_by_proc)(dev, p);
if (!priv) {
@@ -899,7 +941,7 @@ int DRM(close)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p)
#endif
if (dev->lock.hw_lock && _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)
- && dev->lock.pid == DRM_CURRENTPID) {
+ && dev->lock.filp == (void *)DRM_CURRENTPID) {
DRM_DEBUG("Process %d dead, freeing lock for context %d\n",
DRM_CURRENTPID,
_DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
@@ -926,7 +968,7 @@ int DRM(close)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p)
}
if ( DRM(lock_take)( &dev->lock.hw_lock->lock,
DRM_KERNEL_CONTEXT ) ) {
- dev->lock.pid = p->p_pid;
+ dev->lock.pid = DRM_CURRENTPID;
dev->lock.lock_time = jiffies;
atomic_inc( &dev->counts[_DRM_STAT_LOCKS] );
break; /* Got lock */
@@ -935,7 +977,7 @@ int DRM(close)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p)
#if 0
atomic_inc( &dev->total_sleeps );
#endif
- retcode = tsleep(&dev->lock.lock_queue,
+ retcode = tsleep((void *)&dev->lock.lock_queue,
PZERO|PCATCH,
"drmlk2",
0);
@@ -949,7 +991,7 @@ int DRM(close)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p)
}
}
#elif __HAVE_DMA
- DRM(reclaim_buffers)( dev, priv->pid );
+ DRM(reclaim_buffers)( dev, (void *)priv->pid );
#endif
#if defined (__FreeBSD__) && (__FreeBSD_version >= 500000)
@@ -999,12 +1041,13 @@ int DRM(close)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p)
/* DRM(ioctl) is called whenever a process performs an ioctl on /dev/drm.
*/
-int DRM(ioctl)( DRM_IOCTL_ARGS )
+int DRM(ioctl)(dev_t kdev, u_long cmd, caddr_t data, int flags,
+ DRM_STRUCTPROC *p)
{
DRM_DEVICE;
int retcode = 0;
drm_ioctl_desc_t *ioctl;
- d_ioctl_t *func;
+ int (*func)(DRM_IOCTL_ARGS);
int nr = DRM_IOCTL_NR(cmd);
DRM_PRIV;
@@ -1043,7 +1086,6 @@ int DRM(ioctl)( DRM_IOCTL_ARGS )
*(int *) data = fgetown(dev->buf_sigio);
#endif
return 0;
- }
#endif /* __FreeBSD__ */
#ifdef __NetBSD__
case TIOCSPGRP:
@@ -1056,6 +1098,7 @@ int DRM(ioctl)( DRM_IOCTL_ARGS )
*(int *)data = dev->buf_pgid;
return 0;
#endif /* __NetBSD__ */
+ }
if ( nr >= DRIVER_IOCTL_COUNT ) {
retcode = EINVAL;
@@ -1070,7 +1113,7 @@ int DRM(ioctl)( DRM_IOCTL_ARGS )
|| ( ioctl->auth_needed && !priv->authenticated ) ) {
retcode = EACCES;
} else {
- retcode = func( kdev, cmd, data, flags, p );
+ retcode = func(kdev, cmd, data, flags, p, (void *)DRM_CURRENTPID);
}
}
@@ -1125,7 +1168,7 @@ int DRM(lock)( DRM_IOCTL_ARGS )
}
if ( DRM(lock_take)( &dev->lock.hw_lock->lock,
lock.context ) ) {
- dev->lock.pid = DRM_CURRENTPID;
+ dev->lock.filp = (void *)DRM_CURRENTPID;
dev->lock.lock_time = jiffies;
atomic_inc( &dev->counts[_DRM_STAT_LOCKS] );
break; /* Got lock */
diff --git a/bsd/drm_fops.h b/bsd/drm_fops.h
index ed85a8def..75baa5f27 100644
--- a/bsd/drm_fops.h
+++ b/bsd/drm_fops.h
@@ -28,6 +28,8 @@
* Rickard E. (Rik) Faith <faith@valinux.com>
* Daryll Strauss <daryll@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_fops.h,v 1.5 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -100,7 +102,7 @@ int DRM(open_helper)(dev_t kdev, int flags, int fmt, DRM_STRUCTPROC *p,
the circular buffer), is based on Alessandro Rubini's LINUX DEVICE
DRIVERS (Cambridge: O'Reilly, 1998), pages 111-113. */
-ssize_t DRM(read)(dev_t kdev, struct uio *uio, int ioflag)
+int DRM(read)(dev_t kdev, struct uio *uio, int ioflag)
{
DRM_DEVICE;
int left;
@@ -182,8 +184,8 @@ int DRM(write_string)(drm_device_t *dev, const char *s)
selwakeup(&dev->buf_sel);
}
- DRM_DEBUG("dev->buf_sigio=%p\n", dev->buf_sigio);
#ifdef __FreeBSD__
+ DRM_DEBUG("dev->buf_sigio=%p\n", dev->buf_sigio);
if (dev->buf_sigio) {
DRM_DEBUG("dev->buf_sigio->sio_pgid=%d\n", dev->buf_sigio->sio_pgid);
#if __FreeBSD_version >= 500000
@@ -200,6 +202,7 @@ int DRM(write_string)(drm_device_t *dev, const char *s)
gsignal(dev->buf_pgid, SIGIO);
else if(dev->buf_pgid && (p = pfind(-dev->buf_pgid)) != NULL)
psignal(p, SIGIO);
+ }
#endif /* __NetBSD__ */
DRM_DEBUG("waking\n");
wakeup(&dev->buf_rp);
diff --git a/bsd/drm_init.h b/bsd/drm_init.h
index adf421a4e..ec9ea1d71 100644
--- a/bsd/drm_init.h
+++ b/bsd/drm_init.h
@@ -27,6 +27,8 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_init.h,v 1.2 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
diff --git a/bsd/drm_ioctl.h b/bsd/drm_ioctl.h
index 63562fef9..270b2bb52 100644
--- a/bsd/drm_ioctl.h
+++ b/bsd/drm_ioctl.h
@@ -27,6 +27,8 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_ioctl.h,v 1.3 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -136,7 +138,7 @@ int DRM(getmap)( DRM_IOCTL_ARGS )
{
DRM_DEVICE;
drm_map_t map;
- drm_map_t *mapinlist;
+ drm_local_map_t *mapinlist;
drm_map_list_entry_t *list;
int idx;
int i = 0;
diff --git a/bsd/drm_lists.h b/bsd/drm_lists.h
index 1ab55f903..8c34e1171 100644
--- a/bsd/drm_lists.h
+++ b/bsd/drm_lists.h
@@ -27,6 +27,8 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_lists.h,v 1.3 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -43,7 +45,7 @@ int DRM(waitlist_create)(drm_waitlist_t *bl, int count)
if(!bl->bufs) return DRM_ERR(ENOMEM);
- memset(bl->bufs, 0, sizeof(*bl->bufs));
+ bzero(bl->bufs, sizeof(*bl->bufs));
bl->count = count;
bl->rp = bl->bufs;
@@ -66,6 +68,8 @@ int DRM(waitlist_destroy)(drm_waitlist_t *bl)
bl->rp = NULL;
bl->wp = NULL;
bl->end = NULL;
+ DRM_SPINUNINIT( bl->write_lock );
+ DRM_SPINUNINIT( bl->read_lock );
return 0;
}
@@ -137,6 +141,7 @@ int DRM(freelist_destroy)(drm_freelist_t *bl)
{
atomic_set(&bl->count, 0);
bl->next = NULL;
+ DRM_SPINUNINIT( bl->lock );
return 0;
}
@@ -175,7 +180,7 @@ int DRM(freelist_put)(drm_device_t *dev, drm_freelist_t *bl, drm_buf_t *buf)
/* Check for high water mark */
if (atomic_read(&bl->wfh) && atomic_read(&bl->count)>=bl->high_mark) {
atomic_set(&bl->wfh, 0);
- DRM_WAKEUP_INT(&bl->waiting);
+ DRM_WAKEUP_INT((void *)&bl->waiting);
}
return 0;
}
@@ -222,7 +227,7 @@ drm_buf_t *DRM(freelist_get)(drm_freelist_t *bl, int block)
for (;;) {
if (!atomic_read(&bl->wfh)
&& (buf = DRM(freelist_try(bl)))) break;
- error = tsleep(&bl->waiting, PZERO|PCATCH,
+ error = tsleep((void *)&bl->waiting, PZERO|PCATCH,
"drmfg", 0);
if (error)
break;
diff --git a/bsd/drm_lock.h b/bsd/drm_lock.h
index 5e9294bc9..3bab78efe 100644
--- a/bsd/drm_lock.h
+++ b/bsd/drm_lock.h
@@ -27,6 +27,8 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_lock.h,v 1.2 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -47,14 +49,12 @@ int DRM(lock_take)(__volatile__ unsigned int *lock, unsigned int context)
{
unsigned int old, new;
- char failed;
-
do {
old = *lock;
if (old & _DRM_LOCK_HELD) new = old | _DRM_LOCK_CONT;
else new = context | _DRM_LOCK_HELD;
- _DRM_CAS(lock, old, new, failed);
- } while (failed);
+ } while (!atomic_cmpset_int(lock, old, new));
+
if (_DRM_LOCKING_CONTEXT(old) == context) {
if (old & _DRM_LOCK_HELD) {
if (context != DRM_KERNEL_CONTEXT) {
@@ -77,14 +77,13 @@ int DRM(lock_transfer)(drm_device_t *dev,
__volatile__ unsigned int *lock, unsigned int context)
{
unsigned int old, new;
- char failed;
- dev->lock.pid = 0;
+ dev->lock.filp = NULL;
do {
old = *lock;
new = context | _DRM_LOCK_HELD;
- _DRM_CAS(lock, old, new, failed);
- } while (failed);
+ } while (!atomic_cmpset_int(lock, old, new));
+
return 1;
}
@@ -92,20 +91,16 @@ int DRM(lock_free)(drm_device_t *dev,
__volatile__ unsigned int *lock, unsigned int context)
{
unsigned int old, new;
- pid_t pid = dev->lock.pid;
- char failed;
- dev->lock.pid = 0;
+ dev->lock.filp = NULL;
do {
old = *lock;
new = 0;
- _DRM_CAS(lock, old, new, failed);
- } while (failed);
+ } while (!atomic_cmpset_int(lock, old, new));
+
if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
- DRM_ERROR("%d freed heavyweight lock held by %d (pid %d)\n",
- context,
- _DRM_LOCKING_CONTEXT(old),
- pid);
+ DRM_ERROR("%d freed heavyweight lock held by %d\n",
+ context, _DRM_LOCKING_CONTEXT(old));
return 1;
}
DRM_WAKEUP_INT((void *)&dev->lock.lock_queue);
@@ -224,8 +219,6 @@ int DRM(notifier)(void *priv)
{
drm_sigdata_t *s = (drm_sigdata_t *)priv;
unsigned int old, new;
- char failed;
-
/* Allow signal delivery if lock isn't held */
if (!_DRM_LOCK_IS_HELD(s->lock->lock)
@@ -236,8 +229,8 @@ int DRM(notifier)(void *priv)
do {
old = s->lock->lock;
new = old | _DRM_LOCK_CONT;
- _DRM_CAS(&s->lock->lock, old, new, failed);
- } while (failed);
+ } while (!atomic_cmpset_int(&s->lock->lock, old, new));
+
return 0;
}
diff --git a/bsd/drm_memory.h b/bsd/drm_memory.h
index f7dc547a9..0df7ee72d 100644
--- a/bsd/drm_memory.h
+++ b/bsd/drm_memory.h
@@ -27,13 +27,15 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_memory.h,v 1.7 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__NetBSD__)
#define malloctype DRM(M_DRM)
-/* The macros confliced in the MALLOC_DEFINE */
+/* The macros conflicted in the MALLOC_DEFINE */
MALLOC_DEFINE(malloctype, "drm", "DRM Data Structures");
@@ -59,7 +61,6 @@ static drm_mem_stats_t DRM(mem_stats)[] = {
[DRM_MEM_MAGIC] = { "magic" },
[DRM_MEM_IOCTLS] = { "ioctltab" },
[DRM_MEM_MAPS] = { "maplist" },
- [DRM_MEM_VMAS] = { "vmalist" },
[DRM_MEM_BUFS] = { "buflist" },
[DRM_MEM_SEGS] = { "seglist" },
[DRM_MEM_PAGES] = { "pagelist" },
@@ -81,6 +82,10 @@ void DRM(mem_init)(void)
{
drm_mem_stats_t *mem;
+#ifdef __NetBSD__
+ malloc_type_attach(DRM(M_DRM));
+#endif
+
DRM_SPININIT(DRM(mem_lock), "drm memory");
for (mem = DRM(mem_stats); mem->name; ++mem) {
@@ -95,9 +100,16 @@ void DRM(mem_init)(void)
DRM(ram_used) = 0;
}
+void DRM(mem_uninit)(void)
+{
+ DRM_SPINUNINIT(DRM(mem_lock));
+}
+
#ifdef __FreeBSD__
/* drm_mem_info is called whenever a process reads /dev/drm/mem. */
-static int DRM(_mem_info) DRM_SYSCTL_HANDLER_ARGS
+static int
+DRM(_mem_info)(drm_mem_stats_t *stats, struct sysctl_oid *oidp, void *arg1,
+ int arg2, struct sysctl_req *req)
{
drm_mem_stats_t *pt;
char buf[128];
@@ -112,7 +124,7 @@ static int DRM(_mem_info) DRM_SYSCTL_HANDLER_ARGS
DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu |\n",
"locked", 0, 0, 0, DRM(ram_used));
DRM_SYSCTL_PRINT("\n");
- for (pt = DRM(mem_stats); pt->name; pt++) {
+ for (pt = stats; pt->name; pt++) {
DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu %10lu | %6d %10ld\n",
pt->name,
pt->succeed_count,
@@ -132,13 +144,22 @@ static int DRM(_mem_info) DRM_SYSCTL_HANDLER_ARGS
int DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS
{
int ret;
-
+ drm_mem_stats_t *stats;
+
+ stats = malloc(sizeof(DRM(mem_stats)), DRM(M_DRM), M_NOWAIT);
+ if (stats == NULL)
+ return ENOMEM;
+
DRM_SPINLOCK(&DRM(mem_lock));
- ret = DRM(_mem_info)(oidp, arg1, arg2, req);
+ bcopy(DRM(mem_stats), stats, sizeof(DRM(mem_stats)));
DRM_SPINUNLOCK(&DRM(mem_lock));
+
+ ret = DRM(_mem_info)(stats, oidp, arg1, arg2, req);
+
+ free(stats, DRM(M_DRM));
return ret;
}
-#endif
+#endif /* __FreeBSD__ */
void *DRM(alloc)(size_t size, int area)
{
@@ -149,11 +170,7 @@ void *DRM(alloc)(size_t size, int area)
return NULL;
}
-#ifdef __FreeBSD__
if (!(pt = malloc(size, DRM(M_DRM), M_NOWAIT))) {
-#elif defined(__NetBSD__)
- if (!(pt = malloc(size, M_DEVBUF, M_NOWAIT))) {
-#endif
DRM_SPINLOCK(&DRM(mem_lock));
++DRM(mem_stats)[area].fail_count;
DRM_SPINUNLOCK(&DRM(mem_lock));
@@ -203,13 +220,10 @@ void DRM(free)(void *pt, size_t size, int area)
int alloc_count;
int free_count;
- if (!pt) DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
+ if (!pt)
+ DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n");
else
-#ifdef __FreeBSD__
- free(pt, DRM(M_DRM));
-#elif defined(__NetBSD__)
- free(pt, M_DEVBUF);
-#endif
+ free(pt, DRM(M_DRM));
DRM_SPINLOCK(&DRM(mem_lock));
DRM(mem_stats)[area].bytes_freed += size;
free_count = ++DRM(mem_stats)[area].free_count;
@@ -221,25 +235,36 @@ void DRM(free)(void *pt, size_t size, int area)
}
}
-void *DRM(ioremap)(unsigned long offset, unsigned long size)
+void *DRM(ioremap)( drm_device_t *dev, drm_local_map_t *map )
{
void *pt;
- if (!size) {
+ if (!map->size) {
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
- "Mapping 0 bytes at 0x%08lx\n", offset);
+ "Mapping 0 bytes at 0x%08lx\n", map->offset);
return NULL;
}
+#ifdef __NetBSD__
+ map->iot = dev->pa.pa_memt;
+#endif
- if (!(pt = pmap_mapdev(offset, size))) {
+#ifdef __FreeBSD__
+ if (!(pt = pmap_mapdev(map->offset, map->size))) {
+#elif defined(__NetBSD__)
+ if (bus_space_map(map->iot, map->offset, map->size,
+ BUS_SPACE_MAP_LINEAR, &map->ioh)) {
+#endif
DRM_SPINLOCK(&DRM(mem_lock));
++DRM(mem_stats)[DRM_MEM_MAPPINGS].fail_count;
DRM_SPINUNLOCK(&DRM(mem_lock));
return NULL;
}
+#ifdef __NetBSD__
+ pt = bus_space_vaddr(map->iot, map->ioh);
+#endif
DRM_SPINLOCK(&DRM(mem_lock));
++DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
- DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_allocated += size;
+ DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_allocated += map->size;
DRM_SPINUNLOCK(&DRM(mem_lock));
return pt;
}
@@ -271,19 +296,23 @@ void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size)
}
#endif
-void DRM(ioremapfree)(void *pt, unsigned long size)
+void DRM(ioremapfree)(drm_local_map_t *map)
{
int alloc_count;
int free_count;
- if (!pt)
+ if (map->handle == NULL)
DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
"Attempt to free NULL pointer\n");
else
- pmap_unmapdev((vm_offset_t) pt, size);
+#ifdef __FreeBSD__
+ pmap_unmapdev((vm_offset_t) map->handle, map->size);
+#elif defined(__NetBSD__)
+ bus_space_unmap(map->iot, map->ioh, map->size);
+#endif
DRM_SPINLOCK(&DRM(mem_lock));
- DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_freed += size;
+ DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_freed += map->size;
free_count = ++DRM(mem_stats)[DRM_MEM_MAPPINGS].free_count;
alloc_count = DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
DRM_SPINUNLOCK(&DRM(mem_lock));
diff --git a/bsd/drm_os_freebsd.h b/bsd/drm_os_freebsd.h
index 1a3feb6e8..30a6e3623 100644
--- a/bsd/drm_os_freebsd.h
+++ b/bsd/drm_os_freebsd.h
@@ -1,3 +1,6 @@
+/*
+ * $FreeBSD: src/sys/dev/drm/drm_os_freebsd.h,v 1.8 2003/03/09 02:08:28 anholt Exp $
+ */
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/malloc.h>
@@ -45,7 +48,11 @@
#define __REALLY_HAVE_AGP __HAVE_AGP
#endif
+#ifdef __i386__
#define __REALLY_HAVE_MTRR (__HAVE_MTRR)
+#else
+#define __REALLY_HAVE_MTRR 0
+#endif
#define __REALLY_HAVE_SG (__HAVE_SG)
#if __REALLY_HAVE_AGP
@@ -79,6 +86,7 @@
#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_CURRENTPID curthread->td_proc->p_pid
@@ -87,12 +95,17 @@
#define DRM_STRUCTPROC struct proc
#define DRM_SPINTYPE struct simplelock
#define DRM_SPININIT(l,name) simple_lock_init(&l)
+#define DRM_SPINUNINIT(l)
#define DRM_SPINLOCK(l) simple_lock(l)
#define DRM_SPINUNLOCK(u) simple_unlock(u);
#define DRM_CURRENTPID curproc->p_pid
#endif
-#define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, int flags, DRM_STRUCTPROC *p
+/* 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 lockmgr(&dev->dev_lock, LK_EXCLUSIVE, 0, DRM_CURPROC)
#define DRM_UNLOCK lockmgr(&dev->dev_lock, LK_RELEASE, 0, DRM_CURPROC)
#define DRM_SUSER(p) suser(p)
@@ -100,12 +113,20 @@
#define DRM_IRQ_ARGS void *arg
#define DRM_DEVICE drm_device_t *dev = kdev->si_drv1
#define DRM_MALLOC(size) malloc( size, DRM(M_DRM), M_NOWAIT )
-#define DRM_FREE(pt) free( pt, DRM(M_DRM) )
+#define DRM_FREE(pt,size) free( pt, DRM(M_DRM) )
#define DRM_VTOPHYS(addr) vtophys(addr)
-#define DRM_READ8(addr) *((volatile char *)(addr))
-#define DRM_READ32(addr) *((volatile long *)(addr))
-#define DRM_WRITE8(addr, val) *((volatile char *)(addr)) = (val)
-#define DRM_WRITE32(addr, val) *((volatile long *)(addr)) = (val)
+
+/* 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_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_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
@@ -116,6 +137,16 @@
return EINVAL; \
}
+#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; \
@@ -130,7 +161,7 @@ do { \
do { \
drm_map_list_entry_t *listentry; \
TAILQ_FOREACH(listentry, dev->maplist, link) { \
- drm_map_t *map = listentry->map; \
+ drm_local_map_t *map = listentry->map; \
if (map->type == _DRM_SHM && \
map->flags & _DRM_CONTAINS_LOCK) { \
dev_priv->sarea = map; \
@@ -166,7 +197,7 @@ while (!condition) { \
copyin(user, kern, size)
/* Macros for userspace access with checking readability once */
/* FIXME: can't find equivalent functionality for nocheck yet.
- * It's be slower than linux, but should be correct.
+ * It'll be slower than linux, but should be correct.
*/
#define DRM_VERIFYAREA_READ( uaddr, size ) \
(!useracc((caddr_t)uaddr, size, VM_PROT_READ))
@@ -175,20 +206,13 @@ while (!condition) { \
#define DRM_GET_USER_UNCHECKED(val, uaddr) \
((val) = fuword(uaddr), 0)
-/* From machine/bus_at386.h on i386 */
-#define DRM_READMEMORYBARRIER() \
-do { \
- __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory"); \
-} while (0)
-
-#define DRM_WRITEMEMORYBARRIER() \
-do { \
- __asm __volatile("" : : : "memory"); \
-} while (0)
-
+#define DRM_WRITEMEMORYBARRIER( map ) \
+ bus_space_barrier((map)->iot, (map)->ioh, 0, (map)->size, 0);
+#define DRM_READMEMORYBARRIER( map ) \
+ bus_space_barrier((map)->iot, (map)->ioh, 0, (map)->size, BUS_SPACE_BARRIER_READ);
#define PAGE_ALIGN(addr) round_page(addr)
-
+
#ifndef M_WAITOK /* M_WAITOK (=0) name removed in -current */
#define M_WAITOK 0
#endif
@@ -206,12 +230,11 @@ typedef struct drm_chipinfo
char *name;
} drm_chipinfo_t;
-#define cpu_to_le32(x) (x)
+#define cpu_to_le32(x) (x) /* FIXME */
-typedef u_int32_t dma_addr_t;
+typedef unsigned long dma_addr_t;
typedef u_int32_t atomic_t;
typedef u_int32_t cycles_t;
-typedef u_int32_t spinlock_t;
typedef u_int32_t u32;
typedef u_int16_t u16;
typedef u_int8_t u8;
@@ -223,6 +246,23 @@ typedef u_int8_t u8;
#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 int *dst, int old, int new)
+{
+ int s = splhigh();
+ if (*dst==old) {
+ *dst = new;
+ splx(s);
+ return 1;
+ }
+ splx(s);
+ return 0;
+}
+#endif
+
static __inline atomic_t
test_and_set_bit(int b, volatile void *p)
{
@@ -284,20 +324,6 @@ find_first_zero_bit(volatile void *p, int max)
#endif
-#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
-#define _DRM_CAS(lock,old,new,__ret) \
- do { \
- int __dummy; /* Can't mark eax as clobbered */ \
- __asm__ __volatile__( \
- "lock ; cmpxchg %4,%1\n\t" \
- "setnz %0" \
- : "=d" (__ret), \
- "=m" (__drm_dummy_lock(lock)), \
- "=a" (__dummy) \
- : "2" (old), \
- "r" (new)); \
- } while (0)
-
/* Redefinitions to make templating easy */
#define wait_queue_head_t atomic_t
#define agp_memory void
@@ -356,8 +382,6 @@ find_first_zero_bit(volatile void *p, int max)
/* drm_drv.h */
extern d_ioctl_t DRM(ioctl);
-extern d_ioctl_t DRM(lock);
-extern d_ioctl_t DRM(unlock);
extern d_open_t DRM(open);
extern d_close_t DRM(close);
extern d_read_t DRM(read);
@@ -369,81 +393,9 @@ extern int DRM(open_helper)(dev_t kdev, int flags, int fmt,
extern drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev,
DRM_STRUCTPROC *p);
-/* Misc. IOCTL support (drm_ioctl.h) */
-extern d_ioctl_t DRM(irq_busid);
-extern d_ioctl_t DRM(getunique);
-extern d_ioctl_t DRM(setunique);
-extern d_ioctl_t DRM(getmap);
-extern d_ioctl_t DRM(getclient);
-extern d_ioctl_t DRM(getstats);
-
-/* Context IOCTL support (drm_context.h) */
-extern d_ioctl_t DRM(resctx);
-extern d_ioctl_t DRM(addctx);
-extern d_ioctl_t DRM(modctx);
-extern d_ioctl_t DRM(getctx);
-extern d_ioctl_t DRM(switchctx);
-extern d_ioctl_t DRM(newctx);
-extern d_ioctl_t DRM(rmctx);
-extern d_ioctl_t DRM(setsareactx);
-extern d_ioctl_t DRM(getsareactx);
-
-/* Drawable IOCTL support (drm_drawable.h) */
-extern d_ioctl_t DRM(adddraw);
-extern d_ioctl_t DRM(rmdraw);
-
-/* Authentication IOCTL support (drm_auth.h) */
-extern d_ioctl_t DRM(getmagic);
-extern d_ioctl_t DRM(authmagic);
-
-/* Locking IOCTL support (drm_lock.h) */
-extern d_ioctl_t DRM(block);
-extern d_ioctl_t DRM(unblock);
-extern d_ioctl_t DRM(finish);
-
-/* Buffer management support (drm_bufs.h) */
-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);
-extern d_ioctl_t DRM(freebufs);
-extern d_ioctl_t DRM(mapbufs);
-#endif
-
-/* Memory management support (drm_memory.h) */
-extern int DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS;
-
-/* DMA support (drm_dma.h) */
-#if __HAVE_DMA
-extern d_ioctl_t DRM(control);
-#endif
-#if __HAVE_VBL_IRQ
-extern d_ioctl_t DRM(wait_vblank);
-#endif
-
-/* AGP/GART support (drm_agpsupport.h) */
-#if __REALLY_HAVE_AGP
-extern d_ioctl_t DRM(agp_acquire);
-extern d_ioctl_t DRM(agp_release);
-extern d_ioctl_t DRM(agp_enable);
-extern d_ioctl_t DRM(agp_info);
-extern d_ioctl_t DRM(agp_alloc);
-extern d_ioctl_t DRM(agp_free);
-extern d_ioctl_t DRM(agp_unbind);
-extern d_ioctl_t DRM(agp_bind);
-#endif
-
-/* Scatter Gather Support (drm_scatter.h) */
-#if __HAVE_SG
-extern d_ioctl_t DRM(sg_alloc);
-extern d_ioctl_t DRM(sg_free);
-#endif
-
-/* SysCtl Support (drm_sysctl.h) */
+/* sysctl support (drm_sysctl.h) */
extern int DRM(sysctl_init)(drm_device_t *dev);
extern int DRM(sysctl_cleanup)(drm_device_t *dev);
+
+/* Memory info sysctl (drm_memory.h) */
+extern int DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS;
diff --git a/bsd/drm_os_netbsd.h b/bsd/drm_os_netbsd.h
index 2082c0477..fa1582542 100644
--- a/bsd/drm_os_netbsd.h
+++ b/bsd/drm_os_netbsd.h
@@ -17,6 +17,7 @@
#include <uvm/uvm.h>
#include <sys/vnode.h>
#include <sys/poll.h>
+#include <sys/lkm.h>
/* For TIOCSPGRP/TIOCGPGRP */
#include <sys/ttycom.h>
@@ -31,11 +32,9 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
-#include "drmvar.h"
-
#define __REALLY_HAVE_AGP __HAVE_AGP
-#define __REALLY_HAVE_MTRR 0
+#define __REALLY_HAVE_MTRR 1
#define __REALLY_HAVE_SG 0
#if __REALLY_HAVE_AGP
@@ -43,8 +42,7 @@
#include <sys/agpio.h>
#endif
-#define device_t struct device *
-extern struct cfdriver DRM(_cd);
+#include <opt_drm.h>
#if DRM_DEBUG
#undef DRM_DEBUG_CODE
@@ -52,36 +50,58 @@ extern struct cfdriver DRM(_cd);
#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 90
+#define CDEV_MAJOR 34
#define DRM_CURPROC curproc
-#define DRM_STRUCTPROC struct proc
+#define DRM_STRUCTPROC struct proc
#define DRM_SPINTYPE struct simplelock
#define DRM_SPININIT(l,name) simple_lock_init(&l)
-#define DRM_SPINLOCK(l) simple_lock(l)
+#define DRM_SPINUNINIT(l)
+#define DRM_SPINLOCK(l) simple_lock(l)
#define DRM_SPINUNLOCK(u) simple_unlock(u);
-#define DRM_CURRENTPID curproc->p_pid
+#define DRM_CURRENTPID curproc->p_pid
-#define DRM_IOCTL_ARGS dev_t kdev, u_long cmd, caddr_t data, int flags, DRM_STRUCTPROC *p
+/* 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 lockmgr(&dev->dev_lock, LK_EXCLUSIVE, NULL)
#define DRM_UNLOCK lockmgr(&dev->dev_lock, LK_RELEASE, NULL)
#define DRM_SUSER(p) suser(p->p_ucred, &p->p_acflag)
#define DRM_TASKQUEUE_ARGS void *dev, int pending
-#define DRM_IRQ_ARGS void *device
-#define DRM_DEVICE drm_device_t *dev = device_lookup(&DRM(_cd), minor(kdev))
+#define DRM_IRQ_ARGS void *arg
+#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(DRM(M_DRM));
+#else
+/* XXX Make sure this works */
+extern const int DRM(M_DRM) = M_DEVBUF;
+#endif /* __NetBSD_Version__ */
#define DRM_MALLOC(size) malloc( size, DRM(M_DRM), M_NOWAIT )
-#define DRM_FREE(pt) free( pt, DRM(M_DRM) )
+#define DRM_FREE(pt,size) free( pt, DRM(M_DRM) )
#define DRM_VTOPHYS(addr) vtophys(addr)
-#define DRM_READ8(addr) *((volatile char *)(addr))
-#define DRM_READ32(addr) *((volatile long *)(addr))
-#define DRM_WRITE8(addr, val) *((volatile char *)(addr)) = (val)
-#define DRM_WRITE32(addr, val) *((volatile long *)(addr)) = (val)
-#define DRM_AGP_FIND_DEVICE()
+
+#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(0)
#define DRM_PRIV \
drm_file_t *priv = (drm_file_t *) DRM(find_file_by_proc)(dev, p); \
@@ -90,6 +110,16 @@ extern struct cfdriver DRM(_cd);
return EINVAL; \
}
+#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; \
@@ -104,7 +134,7 @@ do { \
do { \
drm_map_list_entry_t *listentry; \
TAILQ_FOREACH(listentry, dev->maplist, link) { \
- drm_map_t *map = listentry->map; \
+ drm_local_map_t *map = listentry->map; \
if (map->type == _DRM_SHM && \
map->flags & _DRM_CONTAINS_LOCK) { \
dev_priv->sarea = map; \
@@ -113,7 +143,15 @@ do { \
} \
} while (0)
-#define return DRM_ERR(v) return v;
+#define DRM_HZ hz
+
+#define DRM_WAIT_ON( ret, queue, timeout, condition ) \
+while (!condition) { \
+ ret = tsleep( (void *)&(queue), PZERO | PCATCH, "drmwtq", (timeout) ); \
+ if ( ret ) \
+ return ret; \
+}
+
#define DRM_ERR(v) v
#define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
@@ -124,21 +162,25 @@ do { \
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_GET_USER_UNCHECKED(val, uaddr) \
+ ((val) = fuword(uaddr), 0)
-#define DRM_READMEMORYBARRIER \
-{ \
- int xchangeDummy; \
- DRM_DEBUG("%s\n", __FUNCTION__); \
- __asm__ volatile(" push %%eax ; xchg %%eax, %0 ; pop %%eax" : : "m" (xchangeDummy)); \
- __asm__ volatile(" push %%eax ; push %%ebx ; push %%ecx ; push %%edx ;" \
- " movl $0,%%eax ; cpuid ; pop %%edx ; pop %%ecx ; pop %%ebx ;" \
- " pop %%eax" : /* no outputs */ : /* no inputs */ ); \
-} while (0);
-
-#define DRM_WRITEMEMORYBARRIER DRM_READMEMORYBARRIER
+#define DRM_WRITEMEMORYBARRIER( map ) \
+ bus_space_barrier((map)->iot, (map)->ioh, 0, (map)->size, 0);
+#define DRM_READMEMORYBARRIER( map ) \
+ bus_space_barrier((map)->iot, (map)->ioh, 0, (map)->size, BUS_SPACE_BARRIER_READ);
-#define DRM_WAKEUP(w) wakeup(w)
+#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)
@@ -150,30 +192,46 @@ typedef struct drm_chipinfo
char *name;
} drm_chipinfo_t;
+#define cpu_to_le32(x) (x) /* FIXME */
+
typedef u_int32_t dma_addr_t;
-typedef volatile u_int32_t atomic_t;
+typedef volatile long atomic_t;
typedef u_int32_t cycles_t;
-typedef u_int32_t spinlock_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) atomic_add_int(p, 1)
-#define atomic_dec(p) atomic_subtract_int(p, 1)
-#define atomic_add(n, p) atomic_add_int(p, n)
-#define atomic_sub(n, p) atomic_subtract_int(p, n)
+#define atomic_inc(p) (*(p) += 1)
+#define atomic_dec(p) (*(p) -= 1)
+#define atomic_add(n, p) (*(p) += (n))
+#define atomic_sub(n, p) (*(p) -= (n))
-/* FIXME: Is NetBSD's kernel non-reentrant? */
+/* 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)
{
@@ -223,20 +281,6 @@ find_first_zero_bit(atomic_t *p, int max)
#define spldrm() spltty()
#define jiffies hardclock_ticks
-#define __drm_dummy_lock(lock) (*(__volatile__ unsigned int *)lock)
-#define _DRM_CAS(lock,old,new,__ret) \
- do { \
- int __dummy; /* Can't mark eax as clobbered */ \
- __asm__ __volatile__( \
- "lock ; cmpxchg %4,%1\n\t" \
- "setnz %0" \
- : "=d" (__ret), \
- "=m" (__drm_dummy_lock(lock)), \
- "=a" (__dummy) \
- : "2" (old), \
- "r" (new)); \
- } while (0)
-
/* Redefinitions to make templating easy */
#define wait_queue_head_t atomic_t
#define agp_memory void
@@ -257,7 +301,7 @@ do { \
#define DRM_DEBUG(fmt, arg...) \
do { \
if (DRM(flags) & DRM_FLAG_DEBUG) \
- printf("[" DRM_NAME ":%s] " fmt , __FUNCTION__,## arg); \
+ printf("[" DRM_NAME ":%s] " fmt , __FUNCTION__ ,## arg); \
} while (0)
#else
#define DRM_DEBUG(fmt, arg...) do { } while (0)
@@ -291,8 +335,6 @@ do { \
/* drm_drv.h */
extern dev_type_ioctl(DRM(ioctl));
-extern dev_type_ioctl(DRM(lock));
-extern dev_type_ioctl(DRM(unlock));
extern dev_type_open(DRM(open));
extern dev_type_close(DRM(close));
extern dev_type_read(DRM(read));
@@ -304,75 +346,5 @@ extern int DRM(open_helper)(dev_t kdev, int flags, int fmt,
extern drm_file_t *DRM(find_file_by_proc)(drm_device_t *dev,
DRM_STRUCTPROC *p);
-/* Misc. IOCTL support (drm_ioctl.h) */
-extern dev_type_ioctl(DRM(irq_busid));
-extern dev_type_ioctl(DRM(getunique));
-extern dev_type_ioctl(DRM(setunique));
-extern dev_type_ioctl(DRM(getmap));
-extern dev_type_ioctl(DRM(getclient));
-extern dev_type_ioctl(DRM(getstats));
-
-/* Context IOCTL support (drm_context.h) */
-extern dev_type_ioctl(DRM(resctx));
-extern dev_type_ioctl(DRM(addctx));
-extern dev_type_ioctl(DRM(modctx));
-extern dev_type_ioctl(DRM(getctx));
-extern dev_type_ioctl(DRM(switchctx));
-extern dev_type_ioctl(DRM(newctx));
-extern dev_type_ioctl(DRM(rmctx));
-extern dev_type_ioctl(DRM(setsareactx));
-extern dev_type_ioctl(DRM(getsareactx));
-
-/* Drawable IOCTL support (drm_drawable.h) */
-extern dev_type_ioctl(DRM(adddraw));
-extern dev_type_ioctl(DRM(rmdraw));
-
-/* Authentication IOCTL support (drm_auth.h) */
-extern dev_type_ioctl(DRM(getmagic));
-extern dev_type_ioctl(DRM(authmagic));
-
-/* Locking IOCTL support (drm_lock.h) */
-extern dev_type_ioctl(DRM(block));
-extern dev_type_ioctl(DRM(unblock));
-extern dev_type_ioctl(DRM(finish));
-
-/* Buffer management support (drm_bufs.h) */
-extern dev_type_ioctl(DRM(addmap));
-extern dev_type_ioctl(DRM(rmmap));
-#if __HAVE_DMA
-extern dev_type_ioctl(DRM(addbufs_agp));
-extern dev_type_ioctl(DRM(addbufs_pci));
-extern dev_type_ioctl(DRM(addbufs_sg));
-extern dev_type_ioctl(DRM(addbufs));
-extern dev_type_ioctl(DRM(infobufs));
-extern dev_type_ioctl(DRM(markbufs));
-extern dev_type_ioctl(DRM(freebufs));
-extern dev_type_ioctl(DRM(mapbufs));
-#endif
-
-/* DMA support (drm_dma.h) */
-#if __HAVE_DMA
-extern dev_type_ioctl(DRM(control));
-#endif
-
-/* AGP/GART support (drm_agpsupport.h) */
-#if __REALLY_HAVE_AGP
-extern dev_type_ioctl(DRM(agp_acquire));
-extern dev_type_ioctl(DRM(agp_release));
-extern dev_type_ioctl(DRM(agp_enable));
-extern dev_type_ioctl(DRM(agp_info));
-extern dev_type_ioctl(DRM(agp_alloc));
-extern dev_type_ioctl(DRM(agp_free));
-extern dev_type_ioctl(DRM(agp_unbind));
-extern dev_type_ioctl(DRM(agp_bind));
-#endif
-
-/* Scatter Gather Support (drm_scatter.h) */
-#if __HAVE_SG
-extern dev_type_ioctl(DRM(sg_alloc));
-extern dev_type_ioctl(DRM(sg_free));
-#endif
-
-/* 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/drm_scatter.h b/bsd/drm_scatter.h
index c16b7c05c..e57e5e5b6 100644
--- a/bsd/drm_scatter.h
+++ b/bsd/drm_scatter.h
@@ -25,6 +25,8 @@
*
* Authors:
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_scatter.h,v 1.4 2003/03/09 02:08:28 anholt Exp $
*/
#include "drmP.h"
@@ -40,9 +42,6 @@ void DRM(sg_cleanup)( drm_sg_mem_t *entry )
DRM(free)( entry->busaddr,
entry->pages * sizeof(*entry->busaddr),
DRM_MEM_PAGES );
- DRM(free)( entry->pagelist,
- entry->pages * sizeof(*entry->pagelist),
- DRM_MEM_PAGES );
DRM(free)( entry,
sizeof(*entry),
DRM_MEM_SGLISTS );
@@ -73,21 +72,10 @@ int DRM(sg_alloc)( DRM_IOCTL_ARGS )
DRM_DEBUG( "sg size=%ld pages=%ld\n", request.size, pages );
entry->pages = pages;
- entry->pagelist = DRM(alloc)( pages * sizeof(*entry->pagelist),
- DRM_MEM_PAGES );
- if ( !entry->pagelist ) {
- DRM(free)( entry, sizeof(*entry), DRM_MEM_SGLISTS );
- return ENOMEM;
- }
-
- bzero(entry->pagelist, pages * sizeof(*entry->pagelist));
entry->busaddr = DRM(alloc)( pages * sizeof(*entry->busaddr),
DRM_MEM_PAGES );
if ( !entry->busaddr ) {
- DRM(free)( entry->pagelist,
- entry->pages * sizeof(*entry->pagelist),
- DRM_MEM_PAGES );
DRM(free)( entry,
sizeof(*entry),
DRM_MEM_SGLISTS );
@@ -100,9 +88,6 @@ int DRM(sg_alloc)( DRM_IOCTL_ARGS )
DRM(free)( entry->busaddr,
entry->pages * sizeof(*entry->busaddr),
DRM_MEM_PAGES );
- DRM(free)( entry->pagelist,
- entry->pages * sizeof(*entry->pagelist),
- DRM_MEM_PAGES );
DRM(free)( entry,
sizeof(*entry),
DRM_MEM_SGLISTS );
@@ -124,46 +109,6 @@ int DRM(sg_alloc)( DRM_IOCTL_ARGS )
dev->sg = entry;
-#if DEBUG_SCATTER
- /* Verify that each page points to its virtual address, and vice
- * versa.
- */
- {
- int error = 0;
-
- for ( i = 0 ; i < pages ; i++ ) {
- unsigned long *tmp;
-
- tmp = page_address( entry->pagelist[i] );
- for ( j = 0 ;
- j < PAGE_SIZE / sizeof(unsigned long) ;
- j++, tmp++ ) {
- *tmp = 0xcafebabe;
- }
- tmp = (unsigned long *)((u8 *)entry->virtual +
- (PAGE_SIZE * i));
- for( j = 0 ;
- j < PAGE_SIZE / sizeof(unsigned long) ;
- j++, tmp++ ) {
- if ( *tmp != 0xcafebabe && error == 0 ) {
- error = 1;
- DRM_ERROR( "Scatter allocation error, "
- "pagelist does not match "
- "virtual mapping\n" );
- }
- }
- tmp = page_address( entry->pagelist[i] );
- for(j = 0 ;
- j < PAGE_SIZE / sizeof(unsigned long) ;
- j++, tmp++) {
- *tmp = 0;
- }
- }
- if (error == 0)
- DRM_ERROR( "Scatter allocation matches pagelist\n" );
- }
-#endif
-
return 0;
DRM(sg_cleanup)( entry );
diff --git a/bsd/drm_sysctl.h b/bsd/drm_sysctl.h
index 2ec7ff95c..2ca187d8c 100644
--- a/bsd/drm_sysctl.h
+++ b/bsd/drm_sysctl.h
@@ -1,5 +1,5 @@
/*
- * $FreeBSD: src/sys/dev/drm/drm_sysctl.h,v 1.1 2002/04/27 20:47:57 anholt Exp $
+ * $FreeBSD: src/sys/dev/drm/drm_sysctl.h,v 1.2 2003/03/09 02:08:28 anholt Exp $
*/
#ifdef __FreeBSD__
@@ -11,9 +11,6 @@ static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS;
static int DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS;
static int DRM(queues_info)DRM_SYSCTL_HANDLER_ARGS;
static int DRM(bufs_info)DRM_SYSCTL_HANDLER_ARGS;
-#if DRM_DEBUG_CODExx
-static int DRM(vma_info)DRM_SYSCTL_HANDLER_ARGS;
-#endif
#if DRM_DMA_HISTOGRAM
static int DRM(histo_info)DRM_SYSCTL_HANDLER_ARGS;
#endif
@@ -28,9 +25,6 @@ struct DRM(sysctl_list) {
{ "clients", DRM(clients_info) },
{ "queues", DRM(queues_info) },
{ "bufs", DRM(bufs_info) },
-#if DRM_DEBUG_CODExx
- { "vma", DRM(vma_info) },
-#endif
#if DRM_DMA_HISTOGRAM
{ "histo", drm_histo_info) },
#endif
@@ -125,7 +119,7 @@ static int DRM(name_info)DRM_SYSCTL_HANDLER_ARGS
static int DRM(_vm_info)DRM_SYSCTL_HANDLER_ARGS
{
drm_device_t *dev = arg1;
- drm_map_t *map;
+ drm_local_map_t *map;
drm_map_list_entry_t *listentry;
const char *types[] = { "FB", "REG", "SHM" };
const char *type;
@@ -203,7 +197,7 @@ static int DRM(_queues_info)DRM_SYSCTL_HANDLER_ARGS
q->read_queue ? 'r':'-',
q->write_queue ? 'w':'-',
q->flush_queue ? 'f':'-',
- DRM_BUFCOUNT(&q->waitlist),
+ (int)DRM_BUFCOUNT(&q->waitlist),
atomic_read(&q->total_flushed),
atomic_read(&q->total_queued),
atomic_read(&q->total_locks));
@@ -309,92 +303,6 @@ static int DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS
return ret;
}
-#if DRM_DEBUG_CODExx
-
-static int DRM(_vma_info)DRM_SYSCTL_HANDLER_ARGS
-{
- drm_device_t *dev = arg1;
- drm_vma_entry_t *pt;
- pgd_t *pgd;
- pmd_t *pmd;
- pte_t *pte;
- unsigned long i;
- struct vm_area_struct *vma;
- unsigned long address;
-#if defined(__i386__)
- unsigned int pgprot;
-#endif
- char buf[128];
- int error;
-
- DRM_SYSCTL_PRINT("vma use count: %d, high_memory = %p, 0x%08lx\n",
- atomic_read(&dev->vma_count),
- high_memory, virt_to_phys(high_memory));
- for (pt = dev->vmalist; pt; pt = pt->next) {
- if (!(vma = pt->vma)) continue;
- DRM_SYSCTL_PRINT("\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx",
- pt->pid,
- vma->vm_start,
- vma->vm_end,
- vma->vm_flags & VM_READ ? 'r' : '-',
- vma->vm_flags & VM_WRITE ? 'w' : '-',
- vma->vm_flags & VM_EXEC ? 'x' : '-',
- vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
- vma->vm_flags & VM_LOCKED ? 'l' : '-',
- vma->vm_flags & VM_IO ? 'i' : '-',
- vma->vm_offset );
-#if defined(__i386__)
- pgprot = pgprot_val(vma->vm_page_prot);
- DRM_SYSCTL_PRINT(" %c%c%c%c%c%c%c%c%c",
- pgprot & _PAGE_PRESENT ? 'p' : '-',
- pgprot & _PAGE_RW ? 'w' : 'r',
- pgprot & _PAGE_USER ? 'u' : 's',
- pgprot & _PAGE_PWT ? 't' : 'b',
- pgprot & _PAGE_PCD ? 'u' : 'c',
- pgprot & _PAGE_ACCESSED ? 'a' : '-',
- pgprot & _PAGE_DIRTY ? 'd' : '-',
- pgprot & _PAGE_4M ? 'm' : 'k',
- pgprot & _PAGE_GLOBAL ? 'g' : 'l' );
-#endif
- DRM_SYSCTL_PRINT("\n");
- for (i = vma->vm_start; i < vma->vm_end; i += PAGE_SIZE) {
- pgd = pgd_offset(vma->vm_mm, i);
- pmd = pmd_offset(pgd, i);
- pte = pte_offset(pmd, i);
- if (pte_present(*pte)) {
- address = __pa(pte_page(*pte))
- + (i & (PAGE_SIZE-1));
- DRM_SYSCTL_PRINT(" 0x%08lx -> 0x%08lx"
- " %c%c%c%c%c\n",
- i,
- address,
- pte_read(*pte) ? 'r' : '-',
- pte_write(*pte) ? 'w' : '-',
- pte_exec(*pte) ? 'x' : '-',
- pte_dirty(*pte) ? 'd' : '-',
- pte_young(*pte) ? 'a' : '-' );
- } else {
- DRM_SYSCTL_PRINT(" 0x%08lx\n", i);
- }
- }
- }
-
- SYSCTL_OUT(req, "", 1);
- return 0;
-}
-
-static int DRM(vma_info)DRM_SYSCTL_HANDLER_ARGS
-{
- drm_device_t *dev = arg1;
- int ret;
-
- DRM_LOCK;
- ret = DRM(_vma_info)(oidp, arg1, arg2, req);
- DRM_UNLOCK;
- return ret;
-}
-#endif
-
#if DRM_DMA_HISTOGRAM
static int DRM(_histo_info)DRM_SYSCTL_HANDLER_ARGS
diff --git a/bsd/drm_vm.h b/bsd/drm_vm.h
index 70a5b0e68..1ce0efab3 100644
--- a/bsd/drm_vm.h
+++ b/bsd/drm_vm.h
@@ -1,5 +1,11 @@
+/*
+ * $FreeBSD: src/sys/dev/drm/drm_vm.h,v 1.4 2003/03/09 02:08:28 anholt Exp $
+ */
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
+static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, vm_offset_t *paddr,
+ int prot)
+#elif defined(__FreeBSD__)
static int DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
#elif defined(__NetBSD__)
static paddr_t DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
@@ -17,17 +23,25 @@ static paddr_t DRM(dma_mmap)(dev_t kdev, vm_offset_t offset, int prot)
physical = dma->pagelist[page];
DRM_DEBUG("0x%08lx (page %lu) => 0x%08lx\n", (long)offset, page, physical);
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
+ *paddr = physical;
+ return 0;
+#else
return atop(physical);
+#endif
}
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
+int DRM(mmap)(dev_t kdev, vm_offset_t offset, vm_offset_t *paddr,
+ int prot)
+#elif defined(__FreeBSD__)
int DRM(mmap)(dev_t kdev, vm_offset_t offset, int prot)
#elif defined(__NetBSD__)
paddr_t DRM(mmap)(dev_t kdev, off_t offset, int prot)
#endif
{
DRM_DEVICE;
- drm_map_t *map = NULL;
+ drm_local_map_t *map = NULL;
drm_map_list_entry_t *listentry=NULL;
drm_file_t *priv;
@@ -44,7 +58,11 @@ paddr_t DRM(mmap)(dev_t kdev, off_t offset, int prot)
if (dev->dma
&& offset >= 0
&& offset < ptoa(dev->dma->page_count))
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
+ return DRM(dma_mmap)(kdev, offset, paddr, prot);
+#else
return DRM(dma_mmap)(kdev, offset, prot);
+#endif
/* A sequential search of a linked list is
fine here because: 1) there will only be
@@ -73,10 +91,20 @@ paddr_t DRM(mmap)(dev_t kdev, off_t offset, int prot)
case _DRM_FRAME_BUFFER:
case _DRM_REGISTERS:
case _DRM_AGP:
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
+ *paddr = offset;
+ return 0;
+#else
return atop(offset);
+#endif
case _DRM_SCATTER_GATHER:
case _DRM_SHM:
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500102
+ *paddr = vtophys(offset);
+ return 0;
+#else
return atop(vtophys(offset));
+#endif
default:
return -1; /* This should never happen. */
}
diff --git a/bsd/gamma.h b/bsd/gamma.h
deleted file mode 100644
index 161dc0481..000000000
--- a/bsd/gamma.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/* gamma.c -- 3dlabs GMX 2000 driver -*- linux-c -*-
- * Created: Mon Jan 4 08:58:31 1999 by gareth@valinux.com
- *
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * 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
- * PRECISION INSIGHT 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.
- *
- * Authors:
- * Gareth Hughes <gareth@valinux.com>
- */
-
-#ifndef __GAMMA_H__
-#define __GAMMA_H__
-
-/* This remains constant for all DRM template files.
- */
-#define DRM(x) gamma_##x
-
-/* General customization:
- */
-#define __HAVE_MTRR 1
-
-/* DMA customization:
- */
-#define __HAVE_DMA 1
-#define __HAVE_OLD_DMA 1
-#define __HAVE_PCI_DMA 1
-
-#define __HAVE_MULTIPLE_DMA_QUEUES 1
-#define __HAVE_DMA_WAITQUEUE 1
-
-#define __HAVE_DMA_WAITLIST 1
-#define __HAVE_DMA_FREELIST 1
-
-#define __HAVE_DMA_FLUSH 1
-#define __HAVE_DMA_SCHEDULE 1
-
-#define __HAVE_DMA_READY 1
-#define DRIVER_DMA_READY() do { \
- gamma_dma_ready(dev); \
-} while (0)
-
-#define __HAVE_DMA_QUIESCENT 1
-#define DRIVER_DMA_QUIESCENT() do { \
- /* FIXME ! */ \
- gamma_dma_quiescent_dual(dev); \
- return 0; \
-} while (0)
-
-#define __HAVE_DMA_IRQ 1
-#define __HAVE_DMA_IRQ_BH 1
-
-#endif /* __GAMMA_H__ */
diff --git a/bsd/gamma/Makefile b/bsd/gamma/Makefile
deleted file mode 100644
index d416e4635..000000000
--- a/bsd/gamma/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-# $FreeBSD$
-
-.PATH: ${.CURDIR}/..
-KMOD = gamma
-NOMAN= YES
-SRCS = gamma_drv.c gamma_dma.c
-SRCS += device_if.h bus_if.h pci_if.h opt_drm.h
-CFLAGS += ${DEBUG_FLAGS} -I. -I..
-
-.if defined(DRM_DEBUG)
-DRM_DEBUG_OPT= "\#define DRM_DEBUG 1"
-.endif
-
-.if !defined(DRM_NOLINUX)
-DRM_LINUX_OPT= "\#define DRM_LINUX 1"
-.endif
-
-opt_drm.h:
- touch opt_drm.h
- echo $(DRM_DEBUG_OPT) >> opt_drm.h
- echo $(DRM_LINUX_OPT) >> opt_drm.h
-
-.include <bsd.kmod.mk>
diff --git a/bsd/gamma_dma.c b/bsd/gamma_dma.c
deleted file mode 100644
index 714554d2e..000000000
--- a/bsd/gamma_dma.c
+++ /dev/null
@@ -1,611 +0,0 @@
-/* gamma_dma.c -- DMA support for GMX 2000 -*- linux-c -*-
- * Created: Fri Mar 19 14:30:16 1999 by faith@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * 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
- * PRECISION INSIGHT 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.
- *
- * Authors:
- * Rickard E. (Rik) Faith <faith@valinux.com>
- *
- */
-
-
-
-#include "gamma.h"
-#include "drmP.h"
-#include "drm.h"
-#include "gamma_drm.h"
-#include "gamma_drv.h"
-
-
-static __inline__ void gamma_dma_dispatch(drm_device_t *dev, unsigned long address,
- unsigned long length)
-{
- drm_gamma_private_t *dev_priv =
- (drm_gamma_private_t *)dev->dev_private;
-
- GAMMA_WRITE(GAMMA_DMAADDRESS, DRM_VTOPHYS((void *)address));
- while (GAMMA_READ(GAMMA_GCOMMANDSTATUS) != 4)
- ;
- GAMMA_WRITE(GAMMA_DMACOUNT, length / 4);
-}
-
-void gamma_dma_quiescent_single(drm_device_t *dev)
-{
- drm_gamma_private_t *dev_priv =
- (drm_gamma_private_t *)dev->dev_private;
-
- while (GAMMA_READ(GAMMA_DMACOUNT))
- ;
- while (GAMMA_READ(GAMMA_INFIFOSPACE) < 3)
- ;
-
- GAMMA_WRITE(GAMMA_FILTERMODE, 1 << 10);
- GAMMA_WRITE(GAMMA_SYNC, 0);
-
- do {
- while (!GAMMA_READ(GAMMA_OUTFIFOWORDS))
- ;
- } while (GAMMA_READ(GAMMA_OUTPUTFIFO) != GAMMA_SYNC_TAG);
-}
-
-void gamma_dma_quiescent_dual(drm_device_t *dev)
-{
- drm_gamma_private_t *dev_priv =
- (drm_gamma_private_t *)dev->dev_private;
-
- while (GAMMA_READ(GAMMA_DMACOUNT))
- ;
- while (GAMMA_READ(GAMMA_INFIFOSPACE) < 3)
- ;
-
- GAMMA_WRITE(GAMMA_BROADCASTMASK, 3);
-
- GAMMA_WRITE(GAMMA_FILTERMODE, 1 << 10);
- GAMMA_WRITE(GAMMA_SYNC, 0);
-
- /* Read from first MX */
- do {
- while (!GAMMA_READ(GAMMA_OUTFIFOWORDS))
- ;
- } while (GAMMA_READ(GAMMA_OUTPUTFIFO) != GAMMA_SYNC_TAG);
-
- /* Read from second MX */
- do {
- while (!GAMMA_READ(GAMMA_OUTFIFOWORDS + 0x10000))
- ;
- } while (GAMMA_READ(GAMMA_OUTPUTFIFO + 0x10000) != GAMMA_SYNC_TAG);
-}
-
-void gamma_dma_ready(drm_device_t *dev)
-{
- drm_gamma_private_t *dev_priv =
- (drm_gamma_private_t *)dev->dev_private;
-
- while (GAMMA_READ(GAMMA_DMACOUNT))
- ;
-}
-
-static __inline__ int gamma_dma_is_ready(drm_device_t *dev)
-{
- drm_gamma_private_t *dev_priv =
- (drm_gamma_private_t *)dev->dev_private;
-
- return !GAMMA_READ(GAMMA_DMACOUNT);
-}
-
-void gamma_dma_service( DRM_IRQ_ARGS)
-{
- drm_device_t *dev = (drm_device_t *)arg;
- drm_device_dma_t *dma = dev->dma;
- drm_gamma_private_t *dev_priv =
- (drm_gamma_private_t *)dev->dev_private;
-
- atomic_inc(&dev->counts[6]); /* _DRM_STAT_IRQ */
- GAMMA_WRITE(GAMMA_GDELAYTIMER, 0xc350/2); /* 0x05S */
- GAMMA_WRITE(GAMMA_GCOMMANDINTFLAGS, 8);
- GAMMA_WRITE(GAMMA_GINTFLAGS, 0x2001);
- if (gamma_dma_is_ready(dev)) {
- /* Free previous buffer */
- if (test_and_set_bit(0, &dev->dma_flag)) return;
- if (dma->this_buffer) {
- gamma_free_buffer(dev, dma->this_buffer);
- dma->this_buffer = NULL;
- }
- clear_bit(0, &dev->dma_flag);
-
- taskqueue_enqueue(taskqueue_swi, &dev->task);
- }
-}
-
-/* Only called by gamma_dma_schedule. */
-static int gamma_do_dma(drm_device_t *dev, int locked)
-{
- unsigned long address;
- unsigned long length;
- drm_buf_t *buf;
- int retcode = 0;
- drm_device_dma_t *dma = dev->dma;
-#if DRM_DMA_HISTOGRAM
- cycles_t dma_start, dma_stop;
-#endif
-
- if (test_and_set_bit(0, &dev->dma_flag)) return DRM_ERR( EBUSY );
-
-#if DRM_DMA_HISTOGRAM
- dma_start = get_cycles();
-#endif
-
- if (!dma->next_buffer) {
- DRM_ERROR("No next_buffer\n");
- clear_bit(0, &dev->dma_flag);
- return DRM_ERR( EINVAL );
- }
-
- buf = dma->next_buffer;
- address = (unsigned long)buf->address;
- length = buf->used;
-
- DRM_DEBUG("context %d, buffer %d (%ld bytes)\n",
- buf->context, buf->idx, length);
-
- if (buf->list == DRM_LIST_RECLAIM) {
- gamma_clear_next_buffer(dev);
- gamma_free_buffer(dev, buf);
- clear_bit(0, &dev->dma_flag);
- return DRM_ERR( EINVAL );
- }
-
- if (!length) {
- DRM_ERROR("0 length buffer\n");
- gamma_clear_next_buffer(dev);
- gamma_free_buffer(dev, buf);
- clear_bit(0, &dev->dma_flag);
- return 0;
- }
-
- if (!gamma_dma_is_ready(dev)) {
- clear_bit(0, &dev->dma_flag);
- return DRM_ERR( EBUSY );
- }
-
- if (buf->while_locked) {
- if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) {
- DRM_ERROR("Dispatching buffer %d from pid %d"
- " \"while locked\", but no lock held\n",
- buf->idx, buf->pid);
- }
- } else {
- if (!locked && !gamma_lock_take(&dev->lock.hw_lock->lock,
- DRM_KERNEL_CONTEXT)) {
- clear_bit(0, &dev->dma_flag);
- return DRM_ERR( EBUSY );
- }
- }
-
- if (dev->last_context != buf->context
- && !(dev->queuelist[buf->context]->flags
- & _DRM_CONTEXT_PRESERVED)) {
- /* PRE: dev->last_context != buf->context */
- if (DRM(context_switch)(dev, dev->last_context,
- buf->context)) {
- DRM(clear_next_buffer)(dev);
- DRM(free_buffer)(dev, buf);
- }
- retcode = EBUSY;
- goto cleanup;
-
- /* POST: we will wait for the context
- switch and will dispatch on a later call
- when dev->last_context == buf->context.
- NOTE WE HOLD THE LOCK THROUGHOUT THIS
- TIME! */
- }
-
- gamma_clear_next_buffer(dev);
- buf->pending = 1;
- buf->waiting = 0;
- buf->list = DRM_LIST_PEND;
-#if DRM_DMA_HISTOGRAM
- buf->time_dispatched = get_cycles();
-#endif
-
- gamma_dma_dispatch(dev, address, length);
- gamma_free_buffer(dev, dma->this_buffer);
- dma->this_buffer = buf;
-
- atomic_inc(&dev->counts[7]); /* _DRM_STAT_DMA */
- atomic_add(length, &dev->counts[8]); /* _DRM_STAT_PRIMARY */
-
- if (!buf->while_locked && !dev->context_flag && !locked) {
- if (gamma_lock_free(dev, &dev->lock.hw_lock->lock,
- DRM_KERNEL_CONTEXT)) {
- DRM_ERROR("\n");
- }
- }
-cleanup:
-
- clear_bit(0, &dev->dma_flag);
-
-#if DRM_DMA_HISTOGRAM
- dma_stop = get_cycles();
- atomic_inc(&dev->histo.dma[gamma_histogram_slot(dma_stop - dma_start)]);
-#endif
-
- return DRM_ERR( retcode );
-}
-
-static void gamma_dma_timer_bh(unsigned long dev)
-{
- gamma_dma_schedule((drm_device_t *)dev, 0);
-}
-
-void gamma_dma_immediate_bh(DRM_TASKQUEUE_ARGS)
-{
- gamma_dma_schedule(arg, 0);
-}
-
-int gamma_dma_schedule(drm_device_t *dev, int locked)
-{
- int next;
- drm_queue_t *q;
- drm_buf_t *buf;
- int retcode = 0;
- int processed = 0;
- int missed;
- int expire = 20;
- drm_device_dma_t *dma = dev->dma;
-#if DRM_DMA_HISTOGRAM
- cycles_t schedule_start;
-#endif
-
- if (test_and_set_bit(0, &dev->interrupt_flag)) {
- /* Not reentrant */
- atomic_inc(&dev->counts[10]); /* _DRM_STAT_MISSED */
- return DRM_ERR( EBUSY );
- }
- missed = atomic_read(&dev->counts[10]);
-
-#if DRM_DMA_HISTOGRAM
- schedule_start = get_cycles();
-#endif
-
-again:
- if (dev->context_flag) {
- clear_bit(0, &dev->interrupt_flag);
- return DRM_ERR( EBUSY );
- }
- if (dma->next_buffer) {
- /* Unsent buffer that was previously
- selected, but that couldn't be sent
- because the lock could not be obtained
- or the DMA engine wasn't ready. Try
- again. */
- if (!(retcode = gamma_do_dma(dev, locked))) ++processed;
- } else {
- do {
- next = gamma_select_queue(dev, gamma_dma_timer_bh);
- if (next >= 0) {
- q = dev->queuelist[next];
- buf = gamma_waitlist_get(&q->waitlist);
- dma->next_buffer = buf;
- dma->next_queue = q;
- if (buf && buf->list == DRM_LIST_RECLAIM) {
- gamma_clear_next_buffer(dev);
- gamma_free_buffer(dev, buf);
- }
- }
- } while (next >= 0 && !dma->next_buffer);
- if (dma->next_buffer) {
- if (!(retcode = gamma_do_dma(dev, locked))) {
- ++processed;
- }
- }
- }
-
- if (--expire) {
- if (missed != atomic_read(&dev->counts[10])) {
- if (gamma_dma_is_ready(dev)) goto again;
- }
- if (processed && gamma_dma_is_ready(dev)) {
- processed = 0;
- goto again;
- }
- }
-
- clear_bit(0, &dev->interrupt_flag);
-
-#if DRM_DMA_HISTOGRAM
- atomic_inc(&dev->histo.schedule[gamma_histogram_slot(get_cycles()
- - schedule_start)]);
-#endif
- return retcode;
-}
-
-static int gamma_dma_priority(drm_device_t *dev, drm_dma_t *d)
-{
- unsigned long address;
- unsigned long length;
- int must_free = 0;
- int retcode = 0;
- int i;
- int idx;
- drm_buf_t *buf;
- drm_buf_t *last_buf = NULL;
- drm_device_dma_t *dma = dev->dma;
- static int never;
-
- /* Turn off interrupt handling */
- while (test_and_set_bit(0, &dev->interrupt_flag)) {
- retcode = tsleep(&never, PZERO|PCATCH, "gamp1", 1);
- if (retcode)
- return retcode;
- }
- if (!(d->flags & _DRM_DMA_WHILE_LOCKED)) {
- while (!gamma_lock_take(&dev->lock.hw_lock->lock,
- DRM_KERNEL_CONTEXT)) {
- retcode = tsleep(&never, PZERO|PCATCH, "gamp2", 1);
- if (retcode)
- return retcode;
- }
- ++must_free;
- }
-
- for (i = 0; i < d->send_count; i++) {
- idx = d->send_indices[i];
- if (idx < 0 || idx >= dma->buf_count) {
- DRM_ERROR("Index %d (of %d max)\n",
- d->send_indices[i], dma->buf_count - 1);
- continue;
- }
- buf = dma->buflist[ idx ];
- if (buf->pid != DRM_CURRENTPID) {
- DRM_ERROR("Process %d using buffer owned by %d\n",
- DRM_CURRENTPID, buf->pid);
- retcode = EINVAL;
- goto cleanup;
- }
- if (buf->list != DRM_LIST_NONE) {
- DRM_ERROR("Process %d using %d's buffer on list %d\n",
- DRM_CURRENTPID, buf->pid, buf->list);
- retcode = EINVAL;
- goto cleanup;
- }
- /* This isn't a race condition on
- buf->list, since our concern is the
- buffer reclaim during the time the
- process closes the /dev/drm? handle, so
- it can't also be doing DMA. */
- buf->list = DRM_LIST_PRIO;
- buf->used = d->send_sizes[i];
- buf->context = d->context;
- buf->while_locked = d->flags & _DRM_DMA_WHILE_LOCKED;
- address = (unsigned long)buf->address;
- length = buf->used;
- if (!length) {
- DRM_ERROR("0 length buffer\n");
- }
- if (buf->pending) {
- DRM_ERROR("Sending pending buffer:"
- " buffer %d, offset %d\n",
- d->send_indices[i], i);
- retcode = EINVAL;
- goto cleanup;
- }
- if (buf->waiting) {
- DRM_ERROR("Sending waiting buffer:"
- " buffer %d, offset %d\n",
- d->send_indices[i], i);
- retcode = EINVAL;
- goto cleanup;
- }
- buf->pending = 1;
-
- if (dev->last_context != buf->context
- && !(dev->queuelist[buf->context]->flags
- & _DRM_CONTEXT_PRESERVED)) {
- /* PRE: dev->last_context != buf->context */
- DRM(context_switch)(dev, dev->last_context,
- buf->context);
- /* POST: we will wait for the context
- switch and will dispatch on a later call
- when dev->last_context == buf->context.
- NOTE WE HOLD THE LOCK THROUGHOUT THIS
- TIME! */
- retcode = tsleep(&dev->context_wait, PZERO|PCATCH,
- "gamctx", 0);
- if (retcode)
- goto cleanup;
- if (dev->last_context != buf->context) {
- DRM_ERROR("Context mismatch: %d %d\n",
- dev->last_context,
- buf->context);
- }
- }
-
-#if DRM_DMA_HISTOGRAM
- buf->time_queued = get_cycles();
- buf->time_dispatched = buf->time_queued;
-#endif
- gamma_dma_dispatch(dev, address, length);
- atomic_inc(&dev->counts[9]); /* _DRM_STAT_SPECIAL */
- atomic_add(length, &dev->counts[8]); /* _DRM_STAT_PRIMARY */
-
- if (last_buf) {
- gamma_free_buffer(dev, last_buf);
- }
- last_buf = buf;
- }
-
-
-cleanup:
- if (last_buf) {
- gamma_dma_ready(dev);
- gamma_free_buffer(dev, last_buf);
- }
-
- if (must_free && !dev->context_flag) {
- if (gamma_lock_free(dev, &dev->lock.hw_lock->lock,
- DRM_KERNEL_CONTEXT)) {
- DRM_ERROR("\n");
- }
- }
- clear_bit(0, &dev->interrupt_flag);
- return DRM_ERR( retcode );
-}
-
-static int gamma_dma_send_buffers(drm_device_t *dev, drm_dma_t *d)
-{
- drm_buf_t *last_buf = NULL;
- int retcode = 0;
- drm_device_dma_t *dma = dev->dma;
-
- if (d->flags & _DRM_DMA_BLOCK) {
- last_buf = dma->buflist[d->send_indices[d->send_count-1]];
- atomic_inc(&last_buf->dma_wait);
- }
-
- if ((retcode = gamma_dma_enqueue(dev, d))) {
- if (d->flags & _DRM_DMA_BLOCK)
- atomic_dec(&last_buf->dma_wait);
- return retcode;
- }
-
- gamma_dma_schedule(dev, 0);
-
- if (d->flags & _DRM_DMA_BLOCK) {
- DRM_DEBUG("%d waiting\n", DRM_CURRENTPID);
- for (;;) {
- retcode = tsleep(&last_buf->dma_wait, PZERO|PCATCH,
- "gamdw", 0);
- if (!last_buf->waiting
- && !last_buf->pending)
- break; /* finished */
- if (retcode)
- break;
- }
- atomic_dec(&last_buf->dma_wait);
- DRM_DEBUG("%d running\n", DRM_CURRENTPID);
- if (!retcode
- || (last_buf->list==DRM_LIST_PEND && !last_buf->pending)) {
- if (!last_buf->dma_wait) {
- gamma_free_buffer(dev, last_buf);
- }
- }
- if (retcode) {
- DRM_ERROR("ctx%d w%d p%d c%d i%d l%d %d/%d\n",
- d->context,
- last_buf->waiting,
- last_buf->pending,
- DRM_WAITCOUNT(dev, d->context),
- last_buf->idx,
- last_buf->list,
- last_buf->pid,
- DRM_CURRENTPID);
- }
- }
- return DRM_ERR( retcode );
-}
-
-int gamma_dma( DRM_IOCTL_ARGS )
-{
- DRM_DEVICE;
- drm_device_dma_t *dma = dev->dma;
- int retcode = 0;
- drm_dma_t d;
-
- DRM_COPY_FROM_USER_IOCTL(d, (drm_dma_t *) data, sizeof(d));
-
- if (d.send_count < 0 || d.send_count > dma->buf_count) {
- DRM_ERROR("Process %d trying to send %d buffers (of %d max)\n",
- DRM_CURRENTPID, d.send_count, dma->buf_count);
- return DRM_ERR( EINVAL );
- }
-
- if (d.request_count < 0 || d.request_count > dma->buf_count) {
- DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
- DRM_CURRENTPID, d.request_count, dma->buf_count);
- return DRM_ERR( EINVAL );
- }
-
- if (d.send_count) {
- if (d.flags & _DRM_DMA_PRIORITY)
- retcode = gamma_dma_priority(dev, &d);
- else
- retcode = gamma_dma_send_buffers(dev, &d);
- }
-
- d.granted_count = 0;
-
- if (!retcode && d.request_count) {
- retcode = gamma_dma_get_buffers(dev, &d);
- }
-
- DRM_DEBUG("%d returning, granted = %d\n",
- DRM_CURRENTPID, d.granted_count);
- DRM_COPY_TO_USER_IOCTL((drm_dma_t *) data, d, sizeof(d));
-
- return retcode;
-}
-
-void DRM(driver_irq_preinstall)(drm_device_t *dev) {
- drm_gamma_private_t *dev_priv =
- (drm_gamma_private_t *)dev->dev_private;
-#if 1
- while(GAMMA_READ(GAMMA_INFIFOSPACE) < 2);
- GAMMA_WRITE( GAMMA_GCOMMANDMODE, 0x00000004 );
- GAMMA_WRITE( GAMMA_GDMACONTROL, 0x00000000 );
-#else
- while(GAMMA_READ(GAMMA_INFIFOSPACE) < 2);
- while(GAMMA_READ(GAMMA_INFIFOSPACE) < 2);
- GAMMA_WRITE( GAMMA_GCOMMANDMODE, GAMMA_QUEUED_DMA_MODE );
- GAMMA_WRITE( GAMMA_GDMACONTROL, 0x00000000 );
-#endif
-}
-
-void DRM(driver_irq_postinstall)(drm_device_t *dev) {
- drm_gamma_private_t *dev_priv =
- (drm_gamma_private_t *)dev->dev_private;
-#if 1
- while(GAMMA_READ(GAMMA_INFIFOSPACE) < 2);
- while(GAMMA_READ(GAMMA_INFIFOSPACE) < 3);
- GAMMA_WRITE( GAMMA_GINTENABLE, 0x00002001 );
- GAMMA_WRITE( GAMMA_COMMANDINTENABLE, 0x00000008 );
- GAMMA_WRITE( GAMMA_GDELAYTIMER, 0x00039090 );
-#else
- while(GAMMA_READ(GAMMA_INFIFOSPACE) < 2);
- while(GAMMA_READ(GAMMA_INFIFOSPACE) < 2);
- GAMMA_WRITE( GAMMA_GINTENABLE, 0x00002000 );
- GAMMA_WRITE( GAMMA_COMMANDINTENABLE, 0x00000004 );
-#endif
-}
-
-void DRM(driver_irq_uninstall)( drm_device_t *dev ) {
- drm_gamma_private_t *dev_priv =
- (drm_gamma_private_t *)dev->dev_private;
- while(GAMMA_READ(GAMMA_INFIFOSPACE) < 2);
- while(GAMMA_READ(GAMMA_INFIFOSPACE) < 3);
- GAMMA_WRITE( GAMMA_GDELAYTIMER, 0x00000000 );
- GAMMA_WRITE( GAMMA_COMMANDINTENABLE, 0x00000000 );
- GAMMA_WRITE( GAMMA_GINTENABLE, 0x00000000 );
-}
diff --git a/bsd/gamma_drm.h b/bsd/gamma_drm.h
deleted file mode 100644
index 0d58b07b5..000000000
--- a/bsd/gamma_drm.h
+++ /dev/null
@@ -1,89 +0,0 @@
-#ifndef _GAMMA_DRM_H_
-#define _GAMMA_DRM_H_
-
-typedef struct _drm_gamma_tex_region {
- unsigned char next, prev; /* indices to form a circular LRU */
- unsigned char in_use; /* owned by a client, or free? */
- int age; /* tracked by clients to update local LRU's */
-} drm_gamma_tex_region_t;
-
-typedef struct {
- unsigned int GDeltaMode;
- unsigned int GDepthMode;
- unsigned int GGeometryMode;
- unsigned int GTransformMode;
-} drm_gamma_context_regs_t;
-
-typedef struct _drm_gamma_sarea {
- drm_gamma_context_regs_t context_state;
-
- unsigned int dirty;
-
-
- /* Maintain an LRU of contiguous regions of texture space. If
- * you think you own a region of texture memory, and it has an
- * age different to the one you set, then you are mistaken and
- * it has been stolen by another client. If global texAge
- * hasn't changed, there is no need to walk the list.
- *
- * These regions can be used as a proxy for the fine-grained
- * texture information of other clients - by maintaining them
- * in the same lru which is used to age their own textures,
- * clients have an approximate lru for the whole of global
- * texture space, and can make informed decisions as to which
- * areas to kick out. There is no need to choose whether to
- * kick out your own texture or someone else's - simply eject
- * them all in LRU order.
- */
-
-#define GAMMA_NR_TEX_REGIONS 64
- drm_gamma_tex_region_t texList[GAMMA_NR_TEX_REGIONS+1];
- /* Last elt is sentinal */
- int texAge; /* last time texture was uploaded */
- int last_enqueue; /* last time a buffer was enqueued */
- int last_dispatch; /* age of the most recently dispatched buffer */
- int last_quiescent; /* */
- int ctxOwner; /* last context to upload state */
-
- int vertex_prim;
-} drm_gamma_sarea_t;
-
-/* WARNING: If you change any of these defines, make sure to change the
- * defines in the Xserver file (xf86drmGamma.h)
- */
-
-/* Gamma specific ioctls
- * The device specific ioctl range is 0x40 to 0x79.
- */
-#define DRM_IOCTL_GAMMA_INIT DRM_IOW( 0x40, drm_gamma_init_t)
-#define DRM_IOCTL_GAMMA_COPY DRM_IOW( 0x41, drm_gamma_copy_t)
-
-typedef struct drm_gamma_copy {
- unsigned int DMAOutputAddress;
- unsigned int DMAOutputCount;
- unsigned int DMAReadGLINTSource;
- unsigned int DMARectangleWriteAddress;
- unsigned int DMARectangleWriteLinePitch;
- unsigned int DMARectangleWrite;
- unsigned int DMARectangleReadAddress;
- unsigned int DMARectangleReadLinePitch;
- unsigned int DMARectangleRead;
- unsigned int DMARectangleReadTarget;
-} drm_gamma_copy_t;
-
-typedef struct drm_gamma_init {
- enum {
- GAMMA_INIT_DMA = 0x01,
- GAMMA_CLEANUP_DMA = 0x02
- } func;
-
- int sarea_priv_offset;
- int pcimode;
- unsigned int mmio0;
- unsigned int mmio1;
- unsigned int mmio2;
- unsigned int mmio3;
- unsigned int buffers_offset;
-} drm_gamma_init_t;
-
-#endif /* _GAMMA_DRM_H_ */
diff --git a/bsd/gamma_drv.c b/bsd/gamma_drv.c
deleted file mode 100644
index 153420fb1..000000000
--- a/bsd/gamma_drv.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/* gamma.c -- 3dlabs GMX 2000 driver -*- linux-c -*-
- * Created: Mon Jan 4 08:58:31 1999 by faith@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * 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
- * PRECISION INSIGHT 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.
- *
- * Authors:
- * Rickard E. (Rik) Faith <faith@valinux.com>
- * Gareth Hughes <gareth@valinux.com>
- */
-
-#include <sys/types.h>
-#include "gamma.h"
-#include "drmP.h"
-#include "drm.h"
-#include "gamma_drm.h"
-#include "gamma_drv.h"
-
-#define DRIVER_AUTHOR "VA Linux Systems Inc."
-
-#define DRIVER_NAME "gamma"
-#define DRIVER_DESC "3DLabs gamma"
-#define DRIVER_DATE "20010216"
-
-#define DRIVER_MAJOR 1
-#define DRIVER_MINOR 0
-#define DRIVER_PATCHLEVEL 0
-
-#define DRIVER_IOCTLS \
- [DRM_IOCTL_NR(DRM_IOCTL_DMA)] = { gamma_dma, 1, 0 }
-
-/* List acquired from http://www.yourvote.com/pci/pcihdr.h and xc/xc/programs/Xserver/hw/xfree86/common/xf86PciInfo.h
- * Please report to anholt@teleport.com inaccuracies or if a chip you have works that is marked unsupported here.
- */
-drm_chipinfo_t DRM(devicelist)[] = {
- {0x3d3d, 0x0008, 1, "3DLabs Gamma"},
- {0, 0, 0, NULL}
-};
-
-
-#define __HAVE_COUNTERS 5
-#define __HAVE_COUNTER6 _DRM_STAT_IRQ
-#define __HAVE_COUNTER7 _DRM_STAT_DMA
-#define __HAVE_COUNTER8 _DRM_STAT_PRIMARY
-#define __HAVE_COUNTER9 _DRM_STAT_SPECIAL
-#define __HAVE_COUNTER10 _DRM_STAT_MISSED
-
-
-#include "drm_auth.h"
-#include "drm_bufs.h"
-#include "drm_context.h"
-#include "drm_dma.h"
-#include "drm_drawable.h"
-#include "drm_drv.h"
-
-
-#include "drm_fops.h"
-#include "drm_init.h"
-#include "drm_ioctl.h"
-#include "drm_lists.h"
-#include "drm_lock.h"
-#include "drm_memory.h"
-#include "drm_vm.h"
-#include "drm_sysctl.h"
-
-DRIVER_MODULE(gamma, pci, gamma_driver, gamma_devclass, 0, 0);
diff --git a/bsd/gamma_drv.h b/bsd/gamma_drv.h
deleted file mode 100644
index 69250b9ee..000000000
--- a/bsd/gamma_drv.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/* gamma_drv.h -- Private header for 3dlabs GMX 2000 driver -*- linux-c -*-
- * Created: Mon Jan 4 10:05:05 1999 by faith@precisioninsight.com
- *
- * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
- * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
- * 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
- * PRECISION INSIGHT 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.
- *
- * Authors:
- * Rickard E. (Rik) Faith <faith@valinux.com>
- *
- */
-
-#ifndef _GAMMA_DRV_H_
-#define _GAMMA_DRV_H_
-
-
-typedef struct drm_gamma_private {
- drm_map_t *buffers;
- drm_map_t *mmio0;
- drm_map_t *mmio1;
- drm_map_t *mmio2;
- drm_map_t *mmio3;
-} drm_gamma_private_t;
-
-#define LOCK_TEST_WITH_RETURN( dev ) \
-do { \
- if ( !_DRM_LOCK_IS_HELD( dev->lock.hw_lock->lock ) || \
- dev->lock.pid != DRM_CURRENTPID ) { \
- DRM_ERROR( "%s called without lock held\n", \
- __FUNCTION__ ); \
- return DRM_ERR( EINVAL ); \
- } \
-} while (0)
-
-
-extern void gamma_dma_ready(drm_device_t *dev);
-extern void gamma_dma_quiescent_single(drm_device_t *dev);
-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( DRM_IOCTL_ARGS );
-extern int gamma_find_devices(void);
-extern int gamma_found(void);
-
-
-#define GAMMA_OFF(reg) \
- ((reg < 0x1000) \
- ? reg \
- : ((reg < 0x10000) \
- ? (reg - 0x1000) \
- : ((reg < 0x11000) \
- ? (reg - 0x10000) \
- : (reg - 0x11000))))
-
-#define GAMMA_BASE(reg) ((unsigned long) \
- ((reg < 0x1000) ? dev_priv->mmio0->handle : \
- ((reg < 0x10000) ? dev_priv->mmio1->handle : \
- ((reg < 0x11000) ? dev_priv->mmio2->handle : \
- dev_priv->mmio3->handle))))
-
-#define GAMMA_ADDR(reg) (GAMMA_BASE(reg) + GAMMA_OFF(reg))
-#define GAMMA_DEREF(reg) *(__volatile__ int *)GAMMA_ADDR(reg)
-#define GAMMA_READ(reg) GAMMA_DEREF(reg)
-#define GAMMA_WRITE(reg,val) do { GAMMA_DEREF(reg) = val; } while (0)
-
-#define GAMMA_BROADCASTMASK 0x9378
-#define GAMMA_COMMANDINTENABLE 0x0c48
-#define GAMMA_DMAADDRESS 0x0028
-#define GAMMA_DMACOUNT 0x0030
-#define GAMMA_FILTERMODE 0x8c00
-#define GAMMA_GCOMMANDINTFLAGS 0x0c50
-#define GAMMA_GCOMMANDMODE 0x0c40
-#define GAMMA_GCOMMANDSTATUS 0x0c60
-#define GAMMA_GDELAYTIMER 0x0c38
-#define GAMMA_GDMACONTROL 0x0060
-#define GAMMA_GINTENABLE 0x0808
-#define GAMMA_GINTFLAGS 0x0810
-#define GAMMA_INFIFOSPACE 0x0018
-#define GAMMA_OUTFIFOWORDS 0x0020
-#define GAMMA_OUTPUTFIFO 0x2000
-#define GAMMA_SYNC 0x8c40
-#define GAMMA_SYNC_TAG 0x0188
-
-#endif
diff --git a/bsd/mga_drv.c b/bsd/mga_drv.c
index 8b69b41b3..de0387f71 100644
--- a/bsd/mga_drv.c
+++ b/bsd/mga_drv.c
@@ -27,10 +27,10 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/mga_drv.c,v 1.4 2003/03/09 02:08:28 anholt Exp $
*/
-#include <sys/types.h>
-
#include "mga.h"
#include "drmP.h"
#include "drm.h"
@@ -63,4 +63,8 @@ drm_chipinfo_t DRM(devicelist)[] = {
#include "drm_vm.h"
#include "drm_sysctl.h"
+#ifdef __FreeBSD__
DRIVER_MODULE(mga, pci, mga_driver, mga_devclass, 0, 0);
+#elif defined(__NetBSD__)
+CFDRIVER_DECL(mga, DV_TTY, NULL);
+#endif
diff --git a/bsd/r128_drv.c b/bsd/r128_drv.c
index 1a8046fb2..28a2c85e7 100644
--- a/bsd/r128_drv.c
+++ b/bsd/r128_drv.c
@@ -27,11 +27,10 @@
* Authors:
* Rickard E. (Rik) Faith <faith@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/r128_drv.c,v 1.4 2003/03/09 02:08:28 anholt Exp $
*/
-
-#include <sys/types.h>
-
#include "r128.h"
#include "drmP.h"
#include "drm.h"
@@ -83,4 +82,8 @@ drm_chipinfo_t DRM(devicelist)[] = {
#include "drm_scatter.h"
#endif
+#ifdef __FreeBSD__
DRIVER_MODULE(r128, pci, r128_driver, r128_devclass, 0, 0);
+#elif defined(__NetBSD__)
+CFDRIVER_DECL(r128, DV_TTY, NULL);
+#endif /* __FreeBSD__ */
diff --git a/bsd/radeon_drv.c b/bsd/radeon_drv.c
index d02ab9594..2e7c5d666 100644
--- a/bsd/radeon_drv.c
+++ b/bsd/radeon_drv.c
@@ -25,10 +25,10 @@
*
* Authors:
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/radeon_drv.c,v 1.5 2003/03/11 01:38:17 anholt Exp $
*/
-#include <sys/types.h>
-
#include "radeon.h"
#include "drmP.h"
#include "drm.h"
@@ -38,21 +38,42 @@
#include "ati_pcigart.h"
#endif
-/* List acquired from http://www.yourvote.com/pci/pcihdr.h and xc/xc/programs/Xserver/hw/xfree86/common/xf86PciInfo.h
- * Please report to eta@lclark.edu inaccuracies or if a chip you have works that is marked unsupported here.
- */
drm_chipinfo_t DRM(devicelist)[] = {
- {0x1002, 0x4C57, 1, "ATI Radeon LW Mobility 7 (AGP)"},
- {0x1002, 0x4C59, 1, "ATI Radeon LY Mobility 6 (AGP)"},
- {0x1002, 0x4C5A, 1, "ATI Radeon LZ Mobility 6 (AGP)"},
- {0x1002, 0x5144, 1, "ATI Radeon QD (AGP)"},
- {0x1002, 0x5145, 1, "ATI Radeon QE (AGP)"},
- {0x1002, 0x5146, 1, "ATI Radeon QF (AGP)"},
- {0x1002, 0x5147, 1, "ATI Radeon QG (AGP)"},
- {0x1002, 0x5157, 1, "ATI Radeon QW 7500 (AGP)"},
- {0x1002, 0x5159, 1, "ATI Radeon QY VE (AGP)"},
- {0x1002, 0x515A, 1, "ATI Radeon QZ VE (AGP)"},
- {0x1002, 0x514C, 1, "ATI Radeon QL 8500 (AGP)"},
+ {0x1002, 0x4242, 1, "ATI Radeon BB R200 AIW 8500DV"},
+ {0x1002, 0x4336, 1, "ATI Radeon Mobility U1"},
+ {0x1002, 0x4964, 1, "ATI Radeon Id R250 9000"},
+ {0x1002, 0x4965, 1, "ATI Radeon Ie R250 9000"},
+ {0x1002, 0x4966, 1, "ATI Radeon If R250 9000"},
+ {0x1002, 0x4967, 1, "ATI Radeon Ig R250 9000"},
+ {0x1002, 0x4C57, 1, "ATI Radeon LW Mobility 7500 M7"},
+ {0x1002, 0x4C58, 1, "ATI Radeon LX RV200 Mobility FireGL 7800 M7"},
+ {0x1002, 0x4C59, 1, "ATI Radeon LY Mobility M6"},
+ {0x1002, 0x4C5A, 1, "ATI Radeon LZ Mobility M6"},
+ {0x1002, 0x4C64, 1, "ATI Radeon Ld R250 Mobility 9000 M9"},
+ {0x1002, 0x4C65, 1, "ATI Radeon Le R250 Mobility 9000 M9"},
+ {0x1002, 0x4C66, 1, "ATI Radeon Lf R250 Mobility 9000 M9"},
+ {0x1002, 0x4C67, 1, "ATI Radeon Lg R250 Mobility 9000 M9"},
+ {0x1002, 0x5144, 1, "ATI Radeon QD R100"},
+ {0x1002, 0x5145, 1, "ATI Radeon QE R100"},
+ {0x1002, 0x5146, 1, "ATI Radeon QF R100"},
+ {0x1002, 0x5147, 1, "ATI Radeon QG R100"},
+ {0x1002, 0x5148, 1, "ATI Radeon QH FireGL 8x00"},
+ {0x1002, 0x5149, 1, "ATI Radeon QI R200"},
+ {0x1002, 0x514A, 1, "ATI Radeon QJ R200"},
+ {0x1002, 0x514B, 1, "ATI Radeon QK R200"},
+ {0x1002, 0x514C, 1, "ATI Radeon QL R200 8500 LE"},
+ {0x1002, 0x514D, 1, "ATI Radeon QM R200 9100"},
+ {0x1002, 0x514E, 1, "ATI Radeon QN R200 8500 LE"},
+ {0x1002, 0x514F, 1, "ATI Radeon QO R200 8500 LE"},
+ {0x1002, 0x5157, 1, "ATI Radeon QW RV200 7500"},
+ {0x1002, 0x5158, 1, "ATI Radeon QX RV200 7500"},
+ {0x1002, 0x5159, 1, "ATI Radeon QY RV100 VE"},
+ {0x1002, 0x515A, 1, "ATI Radeon QZ RV100 VE"},
+ {0x1002, 0x5168, 1, "ATI Radeon Qh R200"},
+ {0x1002, 0x5169, 1, "ATI Radeon Qi R200"},
+ {0x1002, 0x516A, 1, "ATI Radeon Qj R200"},
+ {0x1002, 0x516B, 1, "ATI Radeon Qk R200"},
+ {0x1002, 0x516C, 1, "ATI Radeon Ql R200"},
{0, 0, 0, NULL}
};
@@ -74,4 +95,8 @@ drm_chipinfo_t DRM(devicelist)[] = {
#include "drm_scatter.h"
#endif
+#ifdef __FreeBSD__
DRIVER_MODULE(DRIVER_NAME, pci, DRM(driver), DRM(devclass), 0, 0);
+#elif defined(__NetBSD__)
+CFDRIVER_DECL(radeon, DV_TTY, NULL);
+#endif /* __FreeBSD__ */
diff --git a/bsd/tdfx_drv.c b/bsd/tdfx_drv.c
index 8bc8c57db..e10542f14 100644
--- a/bsd/tdfx_drv.c
+++ b/bsd/tdfx_drv.c
@@ -28,11 +28,10 @@
* Rickard E. (Rik) Faith <faith@valinux.com>
* Daryll Strauss <daryll@valinux.com>
* Gareth Hughes <gareth@valinux.com>
+ *
+ * $FreeBSD: src/sys/dev/drm/tdfx_drv.c,v 1.3 2003/03/09 02:08:28 anholt Exp $
*/
-
-#include <sys/types.h>
-
#include "tdfx.h"
#include "drmP.h"
@@ -96,4 +95,6 @@ drm_chipinfo_t DRM(devicelist)[] = {
#ifdef __FreeBSD__
DRIVER_MODULE(tdfx, pci, tdfx_driver, tdfx_devclass, 0, 0);
+#elif defined(__NetBSD__)
+CFDRIVER_DECL(tdfx, DV_TTY, NULL);
#endif /* __FreeBSD__ */