summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <anholt@freebsd.org>2002-10-31 04:23:09 +0000
committerEric Anholt <anholt@freebsd.org>2002-10-31 04:23:09 +0000
commit9a6b59db39c79369aa849280c0a8b8301876ec93 (patch)
tree102f51d0a3f2c1f24993de323d4d4b1a27d66871
parente656655a361acf73c5652fcef8cf6ba61dfe7a50 (diff)
Inaugurate bsd-4-0-0-branch with Erik Reid's NetBSD patches (with enough
modifications on my part to have probably broken them thoroughly).
-rw-r--r--bsd-core/drmP.h29
-rw-r--r--bsd-core/drm_bufs.c41
-rw-r--r--bsd-core/drm_context.c28
-rw-r--r--bsd-core/drm_drv.c169
-rw-r--r--bsd-core/drm_fops.c1
-rw-r--r--bsd-core/drm_ioctl.c2
-rw-r--r--bsd-core/drm_memory.c35
-rw-r--r--bsd-core/drm_os_freebsd.h8
-rw-r--r--bsd-core/drm_os_netbsd.h43
-rw-r--r--bsd-core/drm_sysctl.c2
-rw-r--r--bsd-core/drm_vm.c2
-rw-r--r--bsd-core/mga_drv.c2
-rw-r--r--bsd-core/r128_drv.c2
-rw-r--r--bsd-core/radeon_drv.c2
-rw-r--r--bsd/drmP.h29
-rw-r--r--bsd/drm_bufs.h41
-rw-r--r--bsd/drm_context.h28
-rw-r--r--bsd/drm_drv.h169
-rw-r--r--bsd/drm_fops.h1
-rw-r--r--bsd/drm_ioctl.h2
-rw-r--r--bsd/drm_lists.h4
-rw-r--r--bsd/drm_memory.h35
-rw-r--r--bsd/drm_os_freebsd.h8
-rw-r--r--bsd/drm_os_netbsd.h43
-rw-r--r--bsd/drm_sysctl.h2
-rw-r--r--bsd/drm_vm.h2
-rw-r--r--bsd/gamma_drv.c2
-rw-r--r--bsd/gamma_drv.h10
-rw-r--r--bsd/mga_drv.c2
-rw-r--r--bsd/r128_drv.c2
-rw-r--r--bsd/radeon_drv.c2
-rw-r--r--libdrm/xf86drm.c13
-rw-r--r--linux-core/drmP.h3
-rw-r--r--linux-core/drm_os_linux.h6
-rw-r--r--linux/drmP.h3
-rw-r--r--linux/drm_os_linux.h6
-rw-r--r--linux/gamma_drm.h10
-rw-r--r--shared-core/mga_drv.h22
-rw-r--r--shared-core/r128_drv.h20
-rw-r--r--shared-core/radeon_drv.h22
-rw-r--r--shared/mga_drv.h22
-rw-r--r--shared/r128_drv.h20
-rw-r--r--shared/radeon_drv.h22
43 files changed, 589 insertions, 328 deletions
diff --git a/bsd-core/drmP.h b/bsd-core/drmP.h
index b7b21da4..ad23fc6f 100644
--- a/bsd-core/drmP.h
+++ b/bsd-core/drmP.h
@@ -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 */
@@ -386,10 +386,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;
struct drm_device {
@@ -432,7 +445,7 @@ 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) */
@@ -526,9 +539,9 @@ extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
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);
diff --git a/bsd-core/drm_bufs.c b/bsd-core/drm_bufs.c
index 7d56d0a3..69f419fc 100644
--- a/bsd-core/drm_bufs.c
+++ b/bsd-core/drm_bufs.c
@@ -69,18 +69,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,8 +103,6 @@ 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:
@@ -137,7 +143,7 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
#endif
}
#endif /* __REALLY_HAVE_MTRR */
- map->handle = DRM(ioremap)( map->offset, map->size );
+ DRM_IOREMAP(map);
break;
case _DRM_SHM:
@@ -187,11 +193,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 +218,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 +271,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 );
@@ -1018,6 +1032,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 +1058,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-core/drm_context.c b/bsd-core/drm_context.c
index 0274a8b7..ffabe661 100644
--- a/bsd-core/drm_context.c
+++ b/bsd-core/drm_context.c
@@ -69,7 +69,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 +149,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 +174,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 +183,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-core/drm_drv.c b/bsd-core/drm_drv.c
index 4a6fc15f..ed605bd4 100644
--- a/bsd-core/drm_drv.c
+++ b/bsd-core/drm_drv.c
@@ -134,7 +134,6 @@ 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 +146,11 @@ 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(devs)[(unit)])
+
+drm_device_t *DRM(devs)[16];
+
#endif /* __NetBSD__ */
static drm_ioctl_desc_t DRM(ioctls)[] = {
@@ -228,6 +229,35 @@ static drm_ioctl_desc_t DRM(ioctls)[] = {
const char *DRM(find_description)(int vendor, int device);
+static struct cdevsw DRM(cdevsw) = {
+ /* open */ DRM( open ),
+ /* close */ DRM( close ),
+ /* read */ DRM( read ),
+ /* write */ DRM( write ),
+ /* ioctl */ DRM( ioctl ),
+#ifdef __NetBSD__
+ /* stop */ NULL,
+ /* tty */ NULL,
+#endif /* __NetBSD__ */
+ /* poll */ DRM( poll ),
+ /* mmap */ DRM( mmap ),
+#ifdef __NetBSD__
+ /* type */ NULL
+#elif defined(__FreeBSD__)
+ /* strategy */ nostrategy,
+ /* name */ DRIVER_NAME,
+ /* maj */ CDEV_MAJOR,
+ /* dump */ nodump,
+ /* psize */ nopsize,
+ /* flags */ D_TTY | D_TRACKCLOSE,
+#if __FreeBSD_version >= 500000
+ /* kqfilter */ 0
+#else
+ /* bmaj */ -1
+#endif
+#endif /* __FreeBSD__ */
+};
+
#ifdef __FreeBSD__
static int DRM(probe)(device_t dev)
{
@@ -271,79 +301,85 @@ 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
-#else
- /* bmaj */ -1
-#endif
-};
+static devclass_t DRM(devclass);
#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(probe)(struct device *parent, struct cfdata *match, void *aux)
-{
- struct pci_attach_args *pa = aux;
- const char *desc;
+int DRM(refcnt) = 0;
+MOD_DEV( DRIVER_NAME, LM_DT_CHAR, CDEV_MAJOR, &DRM(cdevsw) );
- desc = DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id));
- if (desc != NULL)
- return 10;
- return 0;
+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);
+
+int DRM(lkmentry)(struct lkm_table *lkmtp, int cmd, int ver)
+ DISPATCH(lkmtp, cmd, ver, DRM(lkmhandle), DRM(lkmhandle), DRM(lkmhandle));
}
-void DRM(attach)(struct device *parent, struct device *self, void *aux)
+static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd)
{
- struct pci_attach_args *pa = aux;
- drm_device_t *dev = (drm_device_t *)self;
-
- memcpy(&dev->pa, aux, sizeof(dev->pa));
-
- DRM_INFO("%s", DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id)));
- DRM(init)(dev);
+ int j, error = 0;
+
+ 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);
+/* for (j = 0; j <= sc->sc_maxvm; j++)
+ DRM(destroy)(j); */
+ break;
+
+ case LKM_E_STAT:
+ break;
+
+ default:
+ error = EIO;
+ break;
+ }
+ return error;
}
-int DRM(detach)(struct device *self, int flags)
-{
- DRM(cleanup)((drm_device_t *)self);
- return 0;
+int DRM(modprobe)() {
+ struct pci_attach_args pa;
+ int error = 0;
+ if((error = pci_find_device(&pa, DRM(probe))) != 0)
+ DRM(attach)(&pa);
+ return error;
}
-int DRM(activate)(struct device *self, enum devact act)
+int DRM(probe)(struct pci_attach_args *pa)
{
- switch (act) {
- case DVACT_ACTIVATE:
- return (EOPNOTSUPP);
- break;
+ const char *desc;
- case DVACT_DEACTIVATE:
- /* FIXME */
- break;
+ desc = DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id));
+ if (desc != NULL) {
+ return 10;
}
- return (0);
+
+ return 0;
+}
+
+void DRM(attach)(struct pci_attach_args *pa)
+ {
+ int i;
+ drm_device_t *dev = malloc(sizeof(drm_device_t), M_DEVBUF, M_WAITOK);
+
+ memset(dev, 0, sizeof(drm_device_t));
+ memcpy(&dev->pa, pa, sizeof(dev->pa));
+
+ DRM(devs)[0] = dev;
+
+ DRM_INFO("%s", DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id)));
+ DRM(init)(dev);
}
#endif
@@ -487,7 +523,7 @@ 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;
@@ -589,7 +625,7 @@ static int DRM(takedown)( drm_device_t *dev )
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,
@@ -724,7 +760,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;
@@ -1043,7 +1078,6 @@ int DRM(ioctl)( DRM_IOCTL_ARGS )
*(int *) data = fgetown(dev->buf_sigio);
#endif
return 0;
- }
#endif /* __FreeBSD__ */
#ifdef __NetBSD__
case TIOCSPGRP:
@@ -1056,6 +1090,7 @@ int DRM(ioctl)( DRM_IOCTL_ARGS )
*(int *)data = dev->buf_pgid;
return 0;
#endif /* __NetBSD__ */
+ }
if ( nr >= DRIVER_IOCTL_COUNT ) {
retcode = EINVAL;
diff --git a/bsd-core/drm_fops.c b/bsd-core/drm_fops.c
index ed85a8de..68926c8b 100644
--- a/bsd-core/drm_fops.c
+++ b/bsd-core/drm_fops.c
@@ -200,6 +200,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-core/drm_ioctl.c b/bsd-core/drm_ioctl.c
index 63562fef..b4770385 100644
--- a/bsd-core/drm_ioctl.c
+++ b/bsd-core/drm_ioctl.c
@@ -136,7 +136,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-core/drm_memory.c b/bsd-core/drm_memory.c
index f7dc547a..a1a65442 100644
--- a/bsd-core/drm_memory.c
+++ b/bsd-core/drm_memory.c
@@ -138,7 +138,7 @@ int DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS
DRM_SPINUNLOCK(&DRM(mem_lock));
return ret;
}
-#endif
+#endif /* __FreeBSD__ */
void *DRM(alloc)(size_t size, int area)
{
@@ -221,25 +221,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, &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 +282,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-core/drm_os_freebsd.h b/bsd-core/drm_os_freebsd.h
index ff2a6460..00136962 100644
--- a/bsd-core/drm_os_freebsd.h
+++ b/bsd-core/drm_os_freebsd.h
@@ -106,6 +106,12 @@
#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_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_AGP_FIND_DEVICE() agp_find_device()
#define DRM_ERR(v) v
@@ -130,7 +136,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; \
diff --git a/bsd-core/drm_os_netbsd.h b/bsd-core/drm_os_netbsd.h
index 2082c047..b14ed74b 100644
--- a/bsd-core/drm_os_netbsd.h
+++ b/bsd-core/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,8 +32,6 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
-#include "drmvar.h"
-
#define __REALLY_HAVE_AGP __HAVE_AGP
#define __REALLY_HAVE_MTRR 0
@@ -43,8 +42,9 @@
#include <sys/agpio.h>
#endif
-#define device_t struct device *
-extern struct cfdriver DRM(_cd);
+typedef drm_device_t *device_t;
+
+extern drm_device_t *DRM(devs)[16];
#if DRM_DEBUG
#undef DRM_DEBUG_CODE
@@ -57,7 +57,7 @@ extern struct cfdriver DRM(_cd);
#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
@@ -73,15 +73,22 @@ extern struct cfdriver DRM(_cd);
#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_DEVICE drm_device_t *dev = \
+ (DRM(devs)[minor(kdev)])
#define DRM_MALLOC(size) malloc( size, DRM(M_DRM), M_NOWAIT )
#define DRM_FREE(pt) free( pt, DRM(M_DRM) )
#define DRM_VTOPHYS(addr) vtophys(addr)
-#define DRM_READ8(addr) *((volatile char *)(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, val );
+#define DRM_READ32(map, offset) bus_space_read_4( map->iot, map->ioh, offset, val );
+#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); \
@@ -104,7 +111,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 +120,6 @@ do { \
} \
} while (0)
-#define return DRM_ERR(v) return v;
#define DRM_ERR(v) v
#define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
@@ -125,7 +131,7 @@ do { \
#define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
copyin(arg2, arg1, arg3)
-#define DRM_READMEMORYBARRIER \
+#define DRM_READMEMORYBARRIER() \
{ \
int xchangeDummy; \
DRM_DEBUG("%s\n", __FUNCTION__); \
@@ -135,7 +141,7 @@ do { \
" pop %%eax" : /* no outputs */ : /* no inputs */ ); \
} while (0);
-#define DRM_WRITEMEMORYBARRIER DRM_READMEMORYBARRIER
+#define DRM_WRITEMEMORYBARRIER() DRM_READMEMORYBARRIER()
#define DRM_WAKEUP(w) wakeup(w)
#define DRM_WAKEUP_INT(w) wakeup(w)
@@ -151,7 +157,7 @@ typedef struct drm_chipinfo
} drm_chipinfo_t;
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;
@@ -160,14 +166,15 @@ 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)
diff --git a/bsd-core/drm_sysctl.c b/bsd-core/drm_sysctl.c
index 2ec7ff95..55910583 100644
--- a/bsd-core/drm_sysctl.c
+++ b/bsd-core/drm_sysctl.c
@@ -125,7 +125,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;
diff --git a/bsd-core/drm_vm.c b/bsd-core/drm_vm.c
index 70a5b0e6..040d58b8 100644
--- a/bsd-core/drm_vm.c
+++ b/bsd-core/drm_vm.c
@@ -27,7 +27,7 @@ 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;
diff --git a/bsd-core/mga_drv.c b/bsd-core/mga_drv.c
index 8b69b41b..814dfaea 100644
--- a/bsd-core/mga_drv.c
+++ b/bsd-core/mga_drv.c
@@ -63,4 +63,6 @@ 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);
+#endif
diff --git a/bsd-core/r128_drv.c b/bsd-core/r128_drv.c
index 1a8046fb..228c589b 100644
--- a/bsd-core/r128_drv.c
+++ b/bsd-core/r128_drv.c
@@ -83,4 +83,6 @@ drm_chipinfo_t DRM(devicelist)[] = {
#include "drm_scatter.h"
#endif
+#ifdef __FreeBSD__
DRIVER_MODULE(r128, pci, r128_driver, r128_devclass, 0, 0);
+#endif /* __FreeBSD__ */
diff --git a/bsd-core/radeon_drv.c b/bsd-core/radeon_drv.c
index d02ab959..c8601afd 100644
--- a/bsd-core/radeon_drv.c
+++ b/bsd-core/radeon_drv.c
@@ -74,4 +74,6 @@ drm_chipinfo_t DRM(devicelist)[] = {
#include "drm_scatter.h"
#endif
+#ifdef __FreeBSD__
DRIVER_MODULE(DRIVER_NAME, pci, DRM(driver), DRM(devclass), 0, 0);
+#endif /* __FreeBSD__ */
diff --git a/bsd/drmP.h b/bsd/drmP.h
index b7b21da4..ad23fc6f 100644
--- a/bsd/drmP.h
+++ b/bsd/drmP.h
@@ -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 */
@@ -386,10 +386,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;
struct drm_device {
@@ -432,7 +445,7 @@ 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) */
@@ -526,9 +539,9 @@ extern void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size,
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);
diff --git a/bsd/drm_bufs.h b/bsd/drm_bufs.h
index 7d56d0a3..69f419fc 100644
--- a/bsd/drm_bufs.h
+++ b/bsd/drm_bufs.h
@@ -69,18 +69,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,8 +103,6 @@ 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:
@@ -137,7 +143,7 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
#endif
}
#endif /* __REALLY_HAVE_MTRR */
- map->handle = DRM(ioremap)( map->offset, map->size );
+ DRM_IOREMAP(map);
break;
case _DRM_SHM:
@@ -187,11 +193,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 +218,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 +271,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 );
@@ -1018,6 +1032,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 +1058,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 0274a8b7..ffabe661 100644
--- a/bsd/drm_context.h
+++ b/bsd/drm_context.h
@@ -69,7 +69,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 +149,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 +174,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 +183,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_drv.h b/bsd/drm_drv.h
index 4a6fc15f..ed605bd4 100644
--- a/bsd/drm_drv.h
+++ b/bsd/drm_drv.h
@@ -134,7 +134,6 @@ 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 +146,11 @@ 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(devs)[(unit)])
+
+drm_device_t *DRM(devs)[16];
+
#endif /* __NetBSD__ */
static drm_ioctl_desc_t DRM(ioctls)[] = {
@@ -228,6 +229,35 @@ static drm_ioctl_desc_t DRM(ioctls)[] = {
const char *DRM(find_description)(int vendor, int device);
+static struct cdevsw DRM(cdevsw) = {
+ /* open */ DRM( open ),
+ /* close */ DRM( close ),
+ /* read */ DRM( read ),
+ /* write */ DRM( write ),
+ /* ioctl */ DRM( ioctl ),
+#ifdef __NetBSD__
+ /* stop */ NULL,
+ /* tty */ NULL,
+#endif /* __NetBSD__ */
+ /* poll */ DRM( poll ),
+ /* mmap */ DRM( mmap ),
+#ifdef __NetBSD__
+ /* type */ NULL
+#elif defined(__FreeBSD__)
+ /* strategy */ nostrategy,
+ /* name */ DRIVER_NAME,
+ /* maj */ CDEV_MAJOR,
+ /* dump */ nodump,
+ /* psize */ nopsize,
+ /* flags */ D_TTY | D_TRACKCLOSE,
+#if __FreeBSD_version >= 500000
+ /* kqfilter */ 0
+#else
+ /* bmaj */ -1
+#endif
+#endif /* __FreeBSD__ */
+};
+
#ifdef __FreeBSD__
static int DRM(probe)(device_t dev)
{
@@ -271,79 +301,85 @@ 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
-#else
- /* bmaj */ -1
-#endif
-};
+static devclass_t DRM(devclass);
#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(probe)(struct device *parent, struct cfdata *match, void *aux)
-{
- struct pci_attach_args *pa = aux;
- const char *desc;
+int DRM(refcnt) = 0;
+MOD_DEV( DRIVER_NAME, LM_DT_CHAR, CDEV_MAJOR, &DRM(cdevsw) );
- desc = DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id));
- if (desc != NULL)
- return 10;
- return 0;
+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);
+
+int DRM(lkmentry)(struct lkm_table *lkmtp, int cmd, int ver)
+ DISPATCH(lkmtp, cmd, ver, DRM(lkmhandle), DRM(lkmhandle), DRM(lkmhandle));
}
-void DRM(attach)(struct device *parent, struct device *self, void *aux)
+static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd)
{
- struct pci_attach_args *pa = aux;
- drm_device_t *dev = (drm_device_t *)self;
-
- memcpy(&dev->pa, aux, sizeof(dev->pa));
-
- DRM_INFO("%s", DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id)));
- DRM(init)(dev);
+ int j, error = 0;
+
+ 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);
+/* for (j = 0; j <= sc->sc_maxvm; j++)
+ DRM(destroy)(j); */
+ break;
+
+ case LKM_E_STAT:
+ break;
+
+ default:
+ error = EIO;
+ break;
+ }
+ return error;
}
-int DRM(detach)(struct device *self, int flags)
-{
- DRM(cleanup)((drm_device_t *)self);
- return 0;
+int DRM(modprobe)() {
+ struct pci_attach_args pa;
+ int error = 0;
+ if((error = pci_find_device(&pa, DRM(probe))) != 0)
+ DRM(attach)(&pa);
+ return error;
}
-int DRM(activate)(struct device *self, enum devact act)
+int DRM(probe)(struct pci_attach_args *pa)
{
- switch (act) {
- case DVACT_ACTIVATE:
- return (EOPNOTSUPP);
- break;
+ const char *desc;
- case DVACT_DEACTIVATE:
- /* FIXME */
- break;
+ desc = DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id));
+ if (desc != NULL) {
+ return 10;
}
- return (0);
+
+ return 0;
+}
+
+void DRM(attach)(struct pci_attach_args *pa)
+ {
+ int i;
+ drm_device_t *dev = malloc(sizeof(drm_device_t), M_DEVBUF, M_WAITOK);
+
+ memset(dev, 0, sizeof(drm_device_t));
+ memcpy(&dev->pa, pa, sizeof(dev->pa));
+
+ DRM(devs)[0] = dev;
+
+ DRM_INFO("%s", DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id)));
+ DRM(init)(dev);
}
#endif
@@ -487,7 +523,7 @@ 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;
@@ -589,7 +625,7 @@ static int DRM(takedown)( drm_device_t *dev )
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,
@@ -724,7 +760,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;
@@ -1043,7 +1078,6 @@ int DRM(ioctl)( DRM_IOCTL_ARGS )
*(int *) data = fgetown(dev->buf_sigio);
#endif
return 0;
- }
#endif /* __FreeBSD__ */
#ifdef __NetBSD__
case TIOCSPGRP:
@@ -1056,6 +1090,7 @@ int DRM(ioctl)( DRM_IOCTL_ARGS )
*(int *)data = dev->buf_pgid;
return 0;
#endif /* __NetBSD__ */
+ }
if ( nr >= DRIVER_IOCTL_COUNT ) {
retcode = EINVAL;
diff --git a/bsd/drm_fops.h b/bsd/drm_fops.h
index ed85a8de..68926c8b 100644
--- a/bsd/drm_fops.h
+++ b/bsd/drm_fops.h
@@ -200,6 +200,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_ioctl.h b/bsd/drm_ioctl.h
index 63562fef..b4770385 100644
--- a/bsd/drm_ioctl.h
+++ b/bsd/drm_ioctl.h
@@ -136,7 +136,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 1ab55f90..2a8ec8eb 100644
--- a/bsd/drm_lists.h
+++ b/bsd/drm_lists.h
@@ -175,7 +175,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 +222,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_memory.h b/bsd/drm_memory.h
index f7dc547a..a1a65442 100644
--- a/bsd/drm_memory.h
+++ b/bsd/drm_memory.h
@@ -138,7 +138,7 @@ int DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS
DRM_SPINUNLOCK(&DRM(mem_lock));
return ret;
}
-#endif
+#endif /* __FreeBSD__ */
void *DRM(alloc)(size_t size, int area)
{
@@ -221,25 +221,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, &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 +282,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 ff2a6460..00136962 100644
--- a/bsd/drm_os_freebsd.h
+++ b/bsd/drm_os_freebsd.h
@@ -106,6 +106,12 @@
#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_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_AGP_FIND_DEVICE() agp_find_device()
#define DRM_ERR(v) v
@@ -130,7 +136,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; \
diff --git a/bsd/drm_os_netbsd.h b/bsd/drm_os_netbsd.h
index 2082c047..b14ed74b 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,8 +32,6 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
-#include "drmvar.h"
-
#define __REALLY_HAVE_AGP __HAVE_AGP
#define __REALLY_HAVE_MTRR 0
@@ -43,8 +42,9 @@
#include <sys/agpio.h>
#endif
-#define device_t struct device *
-extern struct cfdriver DRM(_cd);
+typedef drm_device_t *device_t;
+
+extern drm_device_t *DRM(devs)[16];
#if DRM_DEBUG
#undef DRM_DEBUG_CODE
@@ -57,7 +57,7 @@ extern struct cfdriver DRM(_cd);
#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
@@ -73,15 +73,22 @@ extern struct cfdriver DRM(_cd);
#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_DEVICE drm_device_t *dev = \
+ (DRM(devs)[minor(kdev)])
#define DRM_MALLOC(size) malloc( size, DRM(M_DRM), M_NOWAIT )
#define DRM_FREE(pt) free( pt, DRM(M_DRM) )
#define DRM_VTOPHYS(addr) vtophys(addr)
-#define DRM_READ8(addr) *((volatile char *)(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, val );
+#define DRM_READ32(map, offset) bus_space_read_4( map->iot, map->ioh, offset, val );
+#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); \
@@ -104,7 +111,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 +120,6 @@ do { \
} \
} while (0)
-#define return DRM_ERR(v) return v;
#define DRM_ERR(v) v
#define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
@@ -125,7 +131,7 @@ do { \
#define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
copyin(arg2, arg1, arg3)
-#define DRM_READMEMORYBARRIER \
+#define DRM_READMEMORYBARRIER() \
{ \
int xchangeDummy; \
DRM_DEBUG("%s\n", __FUNCTION__); \
@@ -135,7 +141,7 @@ do { \
" pop %%eax" : /* no outputs */ : /* no inputs */ ); \
} while (0);
-#define DRM_WRITEMEMORYBARRIER DRM_READMEMORYBARRIER
+#define DRM_WRITEMEMORYBARRIER() DRM_READMEMORYBARRIER()
#define DRM_WAKEUP(w) wakeup(w)
#define DRM_WAKEUP_INT(w) wakeup(w)
@@ -151,7 +157,7 @@ typedef struct drm_chipinfo
} drm_chipinfo_t;
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;
@@ -160,14 +166,15 @@ 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)
diff --git a/bsd/drm_sysctl.h b/bsd/drm_sysctl.h
index 2ec7ff95..55910583 100644
--- a/bsd/drm_sysctl.h
+++ b/bsd/drm_sysctl.h
@@ -125,7 +125,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;
diff --git a/bsd/drm_vm.h b/bsd/drm_vm.h
index 70a5b0e6..040d58b8 100644
--- a/bsd/drm_vm.h
+++ b/bsd/drm_vm.h
@@ -27,7 +27,7 @@ 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;
diff --git a/bsd/gamma_drv.c b/bsd/gamma_drv.c
index 153420fb..e0a53eac 100644
--- a/bsd/gamma_drv.c
+++ b/bsd/gamma_drv.c
@@ -83,4 +83,6 @@ drm_chipinfo_t DRM(devicelist)[] = {
#include "drm_vm.h"
#include "drm_sysctl.h"
+#ifdef __FreeBSD__
DRIVER_MODULE(gamma, pci, gamma_driver, gamma_devclass, 0, 0);
+#endif /* __FreeBSD__ */
diff --git a/bsd/gamma_drv.h b/bsd/gamma_drv.h
index 69250b9e..fb3245bf 100644
--- a/bsd/gamma_drv.h
+++ b/bsd/gamma_drv.h
@@ -34,11 +34,11 @@
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_local_map_t *buffers;
+ drm_local_map_t *mmio0;
+ drm_local_map_t *mmio1;
+ drm_local_map_t *mmio2;
+ drm_local_map_t *mmio3;
} drm_gamma_private_t;
#define LOCK_TEST_WITH_RETURN( dev ) \
diff --git a/bsd/mga_drv.c b/bsd/mga_drv.c
index 8b69b41b..814dfaea 100644
--- a/bsd/mga_drv.c
+++ b/bsd/mga_drv.c
@@ -63,4 +63,6 @@ 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);
+#endif
diff --git a/bsd/r128_drv.c b/bsd/r128_drv.c
index 1a8046fb..228c589b 100644
--- a/bsd/r128_drv.c
+++ b/bsd/r128_drv.c
@@ -83,4 +83,6 @@ drm_chipinfo_t DRM(devicelist)[] = {
#include "drm_scatter.h"
#endif
+#ifdef __FreeBSD__
DRIVER_MODULE(r128, pci, r128_driver, r128_devclass, 0, 0);
+#endif /* __FreeBSD__ */
diff --git a/bsd/radeon_drv.c b/bsd/radeon_drv.c
index d02ab959..c8601afd 100644
--- a/bsd/radeon_drv.c
+++ b/bsd/radeon_drv.c
@@ -74,4 +74,6 @@ drm_chipinfo_t DRM(devicelist)[] = {
#include "drm_scatter.h"
#endif
+#ifdef __FreeBSD__
DRIVER_MODULE(DRIVER_NAME, pci, DRM(driver), DRM(devclass), 0, 0);
+#endif /* __FreeBSD__ */
diff --git a/libdrm/xf86drm.c b/libdrm/xf86drm.c
index 0532a1ec..4ff2ebf1 100644
--- a/libdrm/xf86drm.c
+++ b/libdrm/xf86drm.c
@@ -84,13 +84,16 @@ extern unsigned long _bus_base(void);
#include "xf86drm.h"
-#ifndef DRM_MAJOR
-#define DRM_MAJOR 226 /* Linux */
+#ifdef __FreeBSD__
+#define DRM_MAJOR 145
+#endif
+
+#ifdef __NetBSD__
+#define DRM_MAJOR 34
#endif
-#ifndef __linux__
-#undef DRM_MAJOR
-#define DRM_MAJOR 145 /* Should set in drm.h for *BSD */
+#ifndef DRM_MAJOR
+#define DRM_MAJOR 226 /* Linux */
#endif
#ifndef DRM_MAX_MINOR
diff --git a/linux-core/drmP.h b/linux-core/drmP.h
index 6f6f91c4..39190b1f 100644
--- a/linux-core/drmP.h
+++ b/linux-core/drmP.h
@@ -255,6 +255,7 @@ do { \
} \
} \
} while(0)
+#define DRM_DROP_MAP(_map)
/* Internal types and structures */
#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
@@ -518,6 +519,8 @@ typedef struct drm_map_list {
drm_map_t *map;
} drm_map_list_t;
+typedef drm_map_t drm_local_map_t;
+
typedef struct drm_device {
const char *name; /* Simple driver name */
char *unique; /* Unique identifier: e.g., busid */
diff --git a/linux-core/drm_os_linux.h b/linux-core/drm_os_linux.h
index e9b24356..8863e93f 100644
--- a/linux-core/drm_os_linux.h
+++ b/linux-core/drm_os_linux.h
@@ -11,6 +11,12 @@
#define DRM_READ32(addr) readl(addr)
#define DRM_WRITE8(addr, val) writeb(val, addr)
#define DRM_WRITE32(addr, val) writel(val, addr)
+/*
+#define DRM_READ8(map, offset) readb((unsigned long)map->handle + offset)
+#define DRM_READ32(map, offset) readl((unsigned long)map->handle + offset)
+#define DRM_WRITE8(map, offset, val) writeb(val, (unsigned long)map->handle + offset)
+#define DRM_WRITE32(map, offset, val) writel(val, (unsigned long)map->handle + offset)
+*/
#define DRM_READMEMORYBARRIER() mb()
#define DRM_WRITEMEMORYBARRIER() wmb()
#define DRM_DEVICE drm_file_t *priv = filp->private_data; \
diff --git a/linux/drmP.h b/linux/drmP.h
index 6f6f91c4..39190b1f 100644
--- a/linux/drmP.h
+++ b/linux/drmP.h
@@ -255,6 +255,7 @@ do { \
} \
} \
} while(0)
+#define DRM_DROP_MAP(_map)
/* Internal types and structures */
#define DRM_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
@@ -518,6 +519,8 @@ typedef struct drm_map_list {
drm_map_t *map;
} drm_map_list_t;
+typedef drm_map_t drm_local_map_t;
+
typedef struct drm_device {
const char *name; /* Simple driver name */
char *unique; /* Unique identifier: e.g., busid */
diff --git a/linux/drm_os_linux.h b/linux/drm_os_linux.h
index e9b24356..8863e93f 100644
--- a/linux/drm_os_linux.h
+++ b/linux/drm_os_linux.h
@@ -11,6 +11,12 @@
#define DRM_READ32(addr) readl(addr)
#define DRM_WRITE8(addr, val) writeb(val, addr)
#define DRM_WRITE32(addr, val) writel(val, addr)
+/*
+#define DRM_READ8(map, offset) readb((unsigned long)map->handle + offset)
+#define DRM_READ32(map, offset) readl((unsigned long)map->handle + offset)
+#define DRM_WRITE8(map, offset, val) writeb(val, (unsigned long)map->handle + offset)
+#define DRM_WRITE32(map, offset, val) writel(val, (unsigned long)map->handle + offset)
+*/
#define DRM_READMEMORYBARRIER() mb()
#define DRM_WRITEMEMORYBARRIER() wmb()
#define DRM_DEVICE drm_file_t *priv = filp->private_data; \
diff --git a/linux/gamma_drm.h b/linux/gamma_drm.h
index d06763ae..0d58b07b 100644
--- a/linux/gamma_drm.h
+++ b/linux/gamma_drm.h
@@ -48,6 +48,16 @@ typedef struct _drm_gamma_sarea {
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;
diff --git a/shared-core/mga_drv.h b/shared-core/mga_drv.h
index a5085b06..cd889e75 100644
--- a/shared-core/mga_drv.h
+++ b/shared-core/mga_drv.h
@@ -90,14 +90,14 @@ typedef struct drm_mga_private {
unsigned int texture_offset;
unsigned int texture_size;
- drm_map_t *sarea;
- drm_map_t *fb;
- drm_map_t *mmio;
- drm_map_t *status;
- drm_map_t *warp;
- drm_map_t *primary;
- drm_map_t *buffers;
- drm_map_t *agp_textures;
+ drm_local_map_t *sarea;
+ drm_local_map_t *fb;
+ drm_local_map_t *mmio;
+ drm_local_map_t *status;
+ drm_local_map_t *warp;
+ drm_local_map_t *primary;
+ drm_local_map_t *buffers;
+ drm_local_map_t *agp_textures;
} drm_mga_private_t;
/* mga_dma.c */
@@ -157,6 +157,12 @@ static inline u32 _MGA_READ(u32 *addr)
#define MGA_READ8( reg ) MGA_DEREF8( reg )
#define MGA_WRITE( reg, val ) do { MGA_DEREF( reg ) = val; } while (0)
#define MGA_WRITE8( reg, val ) do { MGA_DEREF8( reg ) = val; } while (0)
+/*
+#define MGA_READ8( reg ) DRM_READ8(dev_priv->mmio, reg)
+#define MGA_READ( reg ) DRM_READ32(dev_priv->mmio, reg)
+#define MGA_WRITE8( reg, val ) DRM_WRITE8(dev_priv->mmio, reg, val)
+#define MGA_WRITE( reg, val ) DRM_WRITE32(dev_priv->mmio, reg, val)
+*/
#endif
#define DWGREG0 0x1c00
diff --git a/shared-core/r128_drv.h b/shared-core/r128_drv.h
index 763fcb3a..26464a5a 100644
--- a/shared-core/r128_drv.h
+++ b/shared-core/r128_drv.h
@@ -98,13 +98,13 @@ typedef struct drm_r128_private {
u32 depth_pitch_offset_c;
u32 span_pitch_offset_c;
- drm_map_t *sarea;
- drm_map_t *fb;
- drm_map_t *mmio;
- drm_map_t *cce_ring;
- drm_map_t *ring_rptr;
- drm_map_t *buffers;
- drm_map_t *agp_textures;
+ drm_local_map_t *sarea;
+ drm_local_map_t *fb;
+ drm_local_map_t *mmio;
+ drm_local_map_t *cce_ring;
+ drm_local_map_t *ring_rptr;
+ drm_local_map_t *buffers;
+ drm_local_map_t *agp_textures;
} drm_r128_private_t;
typedef struct drm_r128_buf_priv {
@@ -379,6 +379,12 @@ extern int r128_cce_indirect( DRM_IOCTL_ARGS );
#define R128_READ8(reg) DRM_READ8( (volatile u8 *) R128_ADDR(reg) )
#define R128_WRITE8(reg,val) DRM_WRITE8( (volatile u8 *) R128_ADDR(reg), (val) )
+/*
+#define R128_READ(reg) DRM_READ32( dev_priv->mmio, reg )
+#define R128_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, reg, (val) )
+#define R128_READ8(reg) DRM_READ8( dev_priv->mmio, reg )
+#define R128_WRITE8(reg,val) DRM_WRITE8( dev_priv->mmio, reg, (val) )
+*/
#define R128_WRITE_PLL(addr,val) \
do { \
diff --git a/shared-core/radeon_drv.h b/shared-core/radeon_drv.h
index 65f3c926..9ba86116 100644
--- a/shared-core/radeon_drv.h
+++ b/shared-core/radeon_drv.h
@@ -126,13 +126,13 @@ typedef struct drm_radeon_private {
drm_radeon_depth_clear_t depth_clear;
- drm_map_t *sarea;
- drm_map_t *fb;
- drm_map_t *mmio;
- drm_map_t *cp_ring;
- drm_map_t *ring_rptr;
- drm_map_t *buffers;
- drm_map_t *agp_textures;
+ drm_local_map_t *sarea;
+ drm_local_map_t *fb;
+ drm_local_map_t *mmio;
+ drm_local_map_t *cp_ring;
+ drm_local_map_t *ring_rptr;
+ drm_local_map_t *buffers;
+ drm_local_map_t *agp_textures;
struct mem_block *agp_heap;
struct mem_block *fb_heap;
@@ -692,9 +692,17 @@ extern int radeon_emit_irq(drm_device_t *dev);
#define RADEON_READ(reg) DRM_READ32( (volatile u32 *) RADEON_ADDR(reg) )
#define RADEON_WRITE(reg,val) DRM_WRITE32( (volatile u32 *) RADEON_ADDR(reg), (val) )
+/*
+#define RADEON_READ(reg) DRM_READ32( dev_priv->mmio, reg )
+#define RADEON_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, reg, (val) )
+*/
#define RADEON_READ8(reg) DRM_READ8( (volatile u8 *) RADEON_ADDR(reg) )
#define RADEON_WRITE8(reg,val) DRM_WRITE8( (volatile u8 *) RADEON_ADDR(reg), (val) )
+/*
+#define RADEON_READ8(reg) DRM_READ8( dev_priv->mmio, reg )
+#define RADEON_WRITE8(reg,val) DRM_WRITE8( dev_priv->mmio, reg, (val) )
+*/
#define RADEON_WRITE_PLL( addr, val ) \
do { \
diff --git a/shared/mga_drv.h b/shared/mga_drv.h
index a5085b06..cd889e75 100644
--- a/shared/mga_drv.h
+++ b/shared/mga_drv.h
@@ -90,14 +90,14 @@ typedef struct drm_mga_private {
unsigned int texture_offset;
unsigned int texture_size;
- drm_map_t *sarea;
- drm_map_t *fb;
- drm_map_t *mmio;
- drm_map_t *status;
- drm_map_t *warp;
- drm_map_t *primary;
- drm_map_t *buffers;
- drm_map_t *agp_textures;
+ drm_local_map_t *sarea;
+ drm_local_map_t *fb;
+ drm_local_map_t *mmio;
+ drm_local_map_t *status;
+ drm_local_map_t *warp;
+ drm_local_map_t *primary;
+ drm_local_map_t *buffers;
+ drm_local_map_t *agp_textures;
} drm_mga_private_t;
/* mga_dma.c */
@@ -157,6 +157,12 @@ static inline u32 _MGA_READ(u32 *addr)
#define MGA_READ8( reg ) MGA_DEREF8( reg )
#define MGA_WRITE( reg, val ) do { MGA_DEREF( reg ) = val; } while (0)
#define MGA_WRITE8( reg, val ) do { MGA_DEREF8( reg ) = val; } while (0)
+/*
+#define MGA_READ8( reg ) DRM_READ8(dev_priv->mmio, reg)
+#define MGA_READ( reg ) DRM_READ32(dev_priv->mmio, reg)
+#define MGA_WRITE8( reg, val ) DRM_WRITE8(dev_priv->mmio, reg, val)
+#define MGA_WRITE( reg, val ) DRM_WRITE32(dev_priv->mmio, reg, val)
+*/
#endif
#define DWGREG0 0x1c00
diff --git a/shared/r128_drv.h b/shared/r128_drv.h
index 763fcb3a..26464a5a 100644
--- a/shared/r128_drv.h
+++ b/shared/r128_drv.h
@@ -98,13 +98,13 @@ typedef struct drm_r128_private {
u32 depth_pitch_offset_c;
u32 span_pitch_offset_c;
- drm_map_t *sarea;
- drm_map_t *fb;
- drm_map_t *mmio;
- drm_map_t *cce_ring;
- drm_map_t *ring_rptr;
- drm_map_t *buffers;
- drm_map_t *agp_textures;
+ drm_local_map_t *sarea;
+ drm_local_map_t *fb;
+ drm_local_map_t *mmio;
+ drm_local_map_t *cce_ring;
+ drm_local_map_t *ring_rptr;
+ drm_local_map_t *buffers;
+ drm_local_map_t *agp_textures;
} drm_r128_private_t;
typedef struct drm_r128_buf_priv {
@@ -379,6 +379,12 @@ extern int r128_cce_indirect( DRM_IOCTL_ARGS );
#define R128_READ8(reg) DRM_READ8( (volatile u8 *) R128_ADDR(reg) )
#define R128_WRITE8(reg,val) DRM_WRITE8( (volatile u8 *) R128_ADDR(reg), (val) )
+/*
+#define R128_READ(reg) DRM_READ32( dev_priv->mmio, reg )
+#define R128_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, reg, (val) )
+#define R128_READ8(reg) DRM_READ8( dev_priv->mmio, reg )
+#define R128_WRITE8(reg,val) DRM_WRITE8( dev_priv->mmio, reg, (val) )
+*/
#define R128_WRITE_PLL(addr,val) \
do { \
diff --git a/shared/radeon_drv.h b/shared/radeon_drv.h
index 65f3c926..9ba86116 100644
--- a/shared/radeon_drv.h
+++ b/shared/radeon_drv.h
@@ -126,13 +126,13 @@ typedef struct drm_radeon_private {
drm_radeon_depth_clear_t depth_clear;
- drm_map_t *sarea;
- drm_map_t *fb;
- drm_map_t *mmio;
- drm_map_t *cp_ring;
- drm_map_t *ring_rptr;
- drm_map_t *buffers;
- drm_map_t *agp_textures;
+ drm_local_map_t *sarea;
+ drm_local_map_t *fb;
+ drm_local_map_t *mmio;
+ drm_local_map_t *cp_ring;
+ drm_local_map_t *ring_rptr;
+ drm_local_map_t *buffers;
+ drm_local_map_t *agp_textures;
struct mem_block *agp_heap;
struct mem_block *fb_heap;
@@ -692,9 +692,17 @@ extern int radeon_emit_irq(drm_device_t *dev);
#define RADEON_READ(reg) DRM_READ32( (volatile u32 *) RADEON_ADDR(reg) )
#define RADEON_WRITE(reg,val) DRM_WRITE32( (volatile u32 *) RADEON_ADDR(reg), (val) )
+/*
+#define RADEON_READ(reg) DRM_READ32( dev_priv->mmio, reg )
+#define RADEON_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, reg, (val) )
+*/
#define RADEON_READ8(reg) DRM_READ8( (volatile u8 *) RADEON_ADDR(reg) )
#define RADEON_WRITE8(reg,val) DRM_WRITE8( (volatile u8 *) RADEON_ADDR(reg), (val) )
+/*
+#define RADEON_READ8(reg) DRM_READ8( dev_priv->mmio, reg )
+#define RADEON_WRITE8(reg,val) DRM_WRITE8( dev_priv->mmio, reg, (val) )
+*/
#define RADEON_WRITE_PLL( addr, val ) \
do { \