DragonFly BSD
DragonFly submit List (threaded) for 2004-01
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

DRM Updates part 2


From: Craig Dooley <craig@xxxxxxxxxx>
Date: Wed, 14 Jan 2004 09:14:46 -0500

This is a better patch from yesterday.  It replaces all OS checks to 
explicitly test __DragonFly__, Changes DRM_LOCK and DRM_UNLOCK to 
DRM_LOCK() and DRM_UNLOCK(), and splits memory debugging into 2 files.
I have only tested it on a radeon, but all the other changes are minimal
to specific drivers.
-- 
------------------------------------------------------------------------
Craig Dooley                                            craig@xxxxxxxxxx
------------------------------------------------------------------------
Index: sys/dev/drm/drm_auth.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_auth.h,v
retrieving revision 1.2
diff -u -u -r1.2 drm_auth.h
--- sys/dev/drm/drm_auth.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/drm_auth.h	14 Jan 2004 13:33:21 -0000
@@ -44,14 +44,14 @@
 	drm_magic_entry_t *pt;
 	int		  hash	  = DRM(hash_magic)(magic);
 
-	DRM_LOCK;
+	DRM_LOCK();
 	for (pt = dev->magiclist[hash].head; pt; pt = pt->next) {
 		if (pt->magic == magic) {
 			retval = pt->priv;
 			break;
 		}
 	}
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 	return retval;
 }
 
@@ -70,7 +70,7 @@
 	entry->priv  = priv;
 	entry->next  = NULL;
 
-	DRM_LOCK;
+	DRM_LOCK();
 	if (dev->magiclist[hash].tail) {
 		dev->magiclist[hash].tail->next = entry;
 		dev->magiclist[hash].tail	= entry;
@@ -78,7 +78,7 @@
 		dev->magiclist[hash].head	= entry;
 		dev->magiclist[hash].tail	= entry;
 	}
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	return 0;
 }
@@ -92,7 +92,7 @@
 	DRM_DEBUG("%d\n", magic);
 	hash = DRM(hash_magic)(magic);
 
-	DRM_LOCK;
+	DRM_LOCK();
 	for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) {
 		if (pt->magic == magic) {
 			if (dev->magiclist[hash].head == pt) {
@@ -104,11 +104,11 @@
 			if (prev) {
 				prev->next = pt->next;
 			}
-			DRM_UNLOCK;
+			DRM_UNLOCK();
 			return 0;
 		}
 	}
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	DRM(free)(pt, sizeof(*pt), DRM_MEM_MAGIC);
 	return DRM_ERR(EINVAL);
Index: sys/dev/drm/drm_bufs.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_bufs.h,v
retrieving revision 1.3
diff -u -u -r1.3 drm_bufs.h
--- sys/dev/drm/drm_bufs.h	21 Jul 2003 07:57:40 -0000	1.3
+++ sys/dev/drm/drm_bufs.h	14 Jan 2004 13:34:10 -0000
@@ -180,9 +180,9 @@
 	memset(list, 0, sizeof(*list));
 	list->map = map;
 
-	DRM_LOCK;
+	DRM_LOCK();
 	TAILQ_INSERT_TAIL(dev->maplist, list, link);
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	request.offset = map->offset;
 	request.size = map->size;
@@ -215,7 +215,7 @@
 
 	DRM_COPY_FROM_USER_IOCTL( request, (drm_map_t *)data, sizeof(request) );
 
-	DRM_LOCK;
+	DRM_LOCK();
 	TAILQ_FOREACH(list, dev->maplist, link) {
 		map = list->map;
 		if(map->handle == request.handle &&
@@ -226,7 +226,7 @@
 	 * find anything.
 	 */
 	if(list == NULL) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(EINVAL);
 	}
 	TAILQ_REMOVE(dev->maplist, list, link);
@@ -273,7 +273,7 @@
 		}
 		DRM(free)(map, sizeof(*map), DRM_MEM_MAPS);
 	}
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 	return 0;
 }
 
@@ -356,17 +356,17 @@
 	if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) 
 		return DRM_ERR(EINVAL);
 
-	DRM_LOCK;
+	DRM_LOCK();
 	entry = &dma->bufs[order];
 	if ( entry->buf_count ) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM); /* May only call once for each order */
 	}
 
 	entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
 				    DRM_MEM_BUFS );
 	if ( !entry->buflist ) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);
 	}
 	memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
@@ -415,7 +415,7 @@
 	if(!temp_buflist) {
 		/* Free the entry because it isn't valid */
 		DRM(cleanup_buf_error)(entry);
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);
 	}
 	dma->buflist = temp_buflist;
@@ -430,7 +430,7 @@
 	DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
 	DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
 
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	request->count = entry->buf_count;
 	request->size = size;
@@ -476,17 +476,17 @@
 	page_order = order - PAGE_SHIFT > 0 ? order - PAGE_SHIFT : 0;
 	total = PAGE_SIZE << page_order;
 
-	DRM_LOCK;
+	DRM_LOCK();
 	entry = &dma->bufs[order];
 	if ( entry->buf_count ) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);	/* May only call once for each order */
 	}
 
 	entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
 				    DRM_MEM_BUFS );
 	if ( !entry->buflist ) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);
 	}
 	memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
@@ -497,7 +497,7 @@
 		DRM(free)( entry->buflist,
 			  count * sizeof(*entry->buflist),
 			  DRM_MEM_BUFS );
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);
 	}
 	memset( entry->seglist, 0, count * sizeof(*entry->seglist) );
@@ -514,7 +514,7 @@
 		DRM(free)( entry->seglist,
 			   count * sizeof(*entry->seglist),
 			   DRM_MEM_SEGS );
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);
 	}
 
@@ -565,7 +565,7 @@
 	if(!temp_buflist) {
 		/* Free the entry because it isn't valid */
 		DRM(cleanup_buf_error)(entry);
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);
 	}
 	dma->buflist = temp_buflist;
@@ -579,7 +579,7 @@
 	dma->page_count += entry->seg_count << page_order;
 	dma->byte_count += PAGE_SIZE * (entry->seg_count << page_order);
 
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	request->count = entry->buf_count;
 	request->size = size;
@@ -630,17 +630,17 @@
 	if ( order < DRM_MIN_ORDER || order > DRM_MAX_ORDER ) 
 		return DRM_ERR(EINVAL);
 
-	DRM_LOCK;
+	DRM_LOCK();
 	entry = &dma->bufs[order];
 	if ( entry->buf_count ) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM); /* May only call once for each order */
 	}
 
 	entry->buflist = DRM(alloc)( count * sizeof(*entry->buflist),
 				     DRM_MEM_BUFS );
 	if ( !entry->buflist ) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);
 	}
 	memset( entry->buflist, 0, count * sizeof(*entry->buflist) );
@@ -671,7 +671,7 @@
 			/* Set count correctly so we free the proper amount. */
 			entry->buf_count = count;
 			DRM(cleanup_buf_error)(entry);
-			DRM_UNLOCK;
+			DRM_UNLOCK();
 			return DRM_ERR(ENOMEM);
 		}
 
@@ -695,7 +695,7 @@
 	if(!temp_buflist) {
 		/* Free the entry because it isn't valid */
 		DRM(cleanup_buf_error)(entry);
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);
 	}
 	dma->buflist = temp_buflist;
@@ -710,7 +710,7 @@
 	DRM_DEBUG( "dma->buf_count : %d\n", dma->buf_count );
 	DRM_DEBUG( "entry->buf_count : %d\n", entry->buf_count );
 
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	request->count = entry->buf_count;
 	request->size = size;
Index: sys/dev/drm/drm_context.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_context.h,v
retrieving revision 1.2
diff -u -u -r1.2 drm_context.h
--- sys/dev/drm/drm_context.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/drm_context.h	14 Jan 2004 13:34:41 -0000
@@ -47,10 +47,10 @@
 	if ( !dev->ctx_bitmap ) goto failed;
 
 	if ( ctx_handle < DRM_MAX_CTXBITMAP ) {
-		DRM_LOCK;
+		DRM_LOCK();
 		clear_bit( ctx_handle, dev->ctx_bitmap );
 		dev->context_sareas[ctx_handle] = NULL;
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return;
 	}
 failed:
@@ -65,7 +65,7 @@
 
 	if(!dev->ctx_bitmap) return -1;
 
-	DRM_LOCK;
+	DRM_LOCK();
 	bit = find_first_zero_bit( dev->ctx_bitmap, DRM_MAX_CTXBITMAP );
 	if ( bit < DRM_MAX_CTXBITMAP ) {
 		set_bit( bit, dev->ctx_bitmap );
@@ -83,7 +83,7 @@
 						DRM_MEM_MAPS);
 				if(!ctx_sareas) {
 					clear_bit(bit, dev->ctx_bitmap);
-					DRM_UNLOCK;
+					DRM_UNLOCK();
 					return -1;
 				}
 				dev->context_sareas = ctx_sareas;
@@ -96,16 +96,16 @@
 						DRM_MEM_MAPS);
 				if(!dev->context_sareas) {
 					clear_bit(bit, dev->ctx_bitmap);
-					DRM_UNLOCK;
+					DRM_UNLOCK();
 					return -1;
 				}
 				dev->context_sareas[bit] = NULL;
 			}
 		}
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return bit;
 	}
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 	return -1;
 }
 
@@ -114,17 +114,17 @@
 	int i;
    	int temp;
 
-	DRM_LOCK;
+	DRM_LOCK();
 	dev->ctx_bitmap = (atomic_t *) DRM(alloc)( PAGE_SIZE,
 							DRM_MEM_CTXBITMAP );
 	if ( dev->ctx_bitmap == NULL ) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(ENOMEM);
 	}
 	memset( (void *)dev->ctx_bitmap, 0, PAGE_SIZE );
 	dev->context_sareas = NULL;
 	dev->max_context = -1;
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	for ( i = 0 ; i < DRM_RESERVED_CONTEXTS ; i++ ) {
 		temp = DRM(ctxbitmap_next)( dev );
@@ -136,13 +136,13 @@
 
 void DRM(ctxbitmap_cleanup)( drm_device_t *dev )
 {
-	DRM_LOCK;
+	DRM_LOCK();
 	if( dev->context_sareas ) DRM(free)( dev->context_sareas,
 					     sizeof(*dev->context_sareas) * 
 					     dev->max_context,
 					     DRM_MEM_MAPS );
 	DRM(free)( (void *)dev->ctx_bitmap, PAGE_SIZE, DRM_MEM_CTXBITMAP );
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 }
 
 /* ================================================================
@@ -158,14 +158,14 @@
 	DRM_COPY_FROM_USER_IOCTL( request, (drm_ctx_priv_map_t *)data, 
 			   sizeof(request) );
 
-	DRM_LOCK;
+	DRM_LOCK();
 	if (dev->max_context < 0 || request.ctx_id >= (unsigned) dev->max_context) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(EINVAL);
 	}
 
 	map = dev->context_sareas[request.ctx_id];
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	request.handle = map->handle;
 
@@ -184,7 +184,7 @@
 	DRM_COPY_FROM_USER_IOCTL( request, (drm_ctx_priv_map_t *)data,
 			   sizeof(request) );
 
-	DRM_LOCK;
+	DRM_LOCK();
 	TAILQ_FOREACH(list, dev->maplist, link) {
 		map=list->map;
 		if(map->handle == request.handle) {
@@ -193,13 +193,13 @@
 			if (request.ctx_id >= (unsigned) dev->max_context)
 				goto bad;
 			dev->context_sareas[request.ctx_id] = map;
-			DRM_UNLOCK;
+			DRM_UNLOCK();
 			return 0;
 		}
 	}
 
 bad:
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 	return DRM_ERR(EINVAL);
 }
 
Index: sys/dev/drm/drm_dma.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_dma.h,v
retrieving revision 1.3
diff -u -u -r1.3 drm_dma.h
--- sys/dev/drm/drm_dma.h	6 Jul 2003 21:23:47 -0000	1.3
+++ sys/dev/drm/drm_dma.h	14 Jan 2004 13:35:16 -0000
@@ -162,13 +162,13 @@
 	if ( !irq )
 		return DRM_ERR(EINVAL);
 
-	DRM_LOCK;
+	DRM_LOCK();
 	if ( dev->irq ) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(EBUSY);
 	}
 	dev->irq = irq;
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	DRM_DEBUG( "%s: irq=%d\n", __FUNCTION__, irq );
 
@@ -198,10 +198,10 @@
 #elif defined(__NetBSD__)
 	if (pci_intr_map(&dev->pa, &dev->ih) != 0) {
 #endif
-		DRM_LOCK;
+		DRM_LOCK();
 		dev->irq = 0;
 		dev->irqrid = 0;
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return ENOENT;
 	}
 	
@@ -219,13 +219,13 @@
 				      (int (*)(DRM_IRQ_ARGS))DRM(dma_service), dev);
 	if ( !dev->irqh ) {
 #endif
-		DRM_LOCK;
+		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;
+		DRM_UNLOCK();
 		return retcode;
 	}
 
@@ -240,12 +240,12 @@
 	int irq;
 	int irqrid;
 	
-	DRM_LOCK;
+	DRM_LOCK();
 	irq = dev->irq;
 	irqrid = dev->irqrid;
 	dev->irq = 0;
 	dev->irqrid = 0;
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	if ( !irq )
 		return DRM_ERR(EINVAL);
Index: sys/dev/drm/drm_drv.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_drv.h,v
retrieving revision 1.5
diff -u -u -r1.5 drm_drv.h
--- sys/dev/drm/drm_drv.h	22 Jul 2003 17:03:28 -0000	1.5
+++ sys/dev/drm/drm_drv.h	14 Jan 2004 13:35:32 -0000
@@ -512,7 +512,7 @@
 	if ( dev->irq ) DRM(irq_uninstall)( dev );
 #endif
 
-	DRM_LOCK;
+	DRM_LOCK();
 	callout_stop( &dev->timer );
 
 	if ( dev->unique ) {
@@ -626,7 +626,7 @@
 		dev->lock.filp = NULL;
 		DRM_WAKEUP_INT((void *)&dev->lock.lock_queue);
 	}
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	return 0;
 }
@@ -930,7 +930,7 @@
 	dev->buf_pgid = 0;
 #endif /* __NetBSD__ */
 
-	DRM_LOCK;
+	DRM_LOCK();
 	priv = DRM(find_file_by_proc)(dev, p);
 	if (priv) {
 		priv->refs--;
@@ -939,7 +939,7 @@
 			DRM(free)( priv, sizeof(*priv), DRM_MEM_FILES );
 		}
 	}
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 
 	/* ========================================================
Index: sys/dev/drm/drm_fops.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_fops.h,v
retrieving revision 1.3
diff -u -u -r1.3 drm_fops.h
--- sys/dev/drm/drm_fops.h	21 Jul 2003 07:57:40 -0000	1.3
+++ sys/dev/drm/drm_fops.h	14 Jan 2004 13:35:50 -0000
@@ -86,9 +86,9 @@
 		priv->devXX		= dev;
 		priv->ioctl_count 	= 0;
 		priv->authenticated	= !DRM_SUSER(p);
-		DRM_LOCK;
+		DRM_LOCK();
 		TAILQ_INSERT_TAIL(&dev->files, priv, link);
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 	}
 #ifdef __FreeBSD__
 	kdev->si_drv1 = dev;
Index: sys/dev/drm/drm_ioctl.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_ioctl.h,v
retrieving revision 1.2
diff -u -u -r1.2 drm_ioctl.h
--- sys/dev/drm/drm_ioctl.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/drm_ioctl.h	14 Jan 2004 13:36:05 -0000
@@ -139,9 +139,9 @@
 
 	idx = map.offset;
 
-	DRM_LOCK;
+	DRM_LOCK();
 	if (idx < 0) {
-		DRM_UNLOCK;
+		DRM_UNLOCK();
 		return DRM_ERR(EINVAL);
 	}
 
@@ -159,7 +159,7 @@
 		i++;
 	}
 
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
  	if (!list)
 		return EINVAL;
@@ -180,7 +180,7 @@
 	DRM_COPY_FROM_USER_IOCTL( client, (drm_client_t *)data, sizeof(client) );
 
 	idx = client.idx;
-	DRM_LOCK;
+	DRM_LOCK();
 	TAILQ_FOREACH(pt, &dev->files, link) {
 		if (i==idx)
 		{
@@ -189,14 +189,14 @@
 			client.uid   = pt->uid;
 			client.magic = pt->magic;
 			client.iocs  = pt->ioctl_count;
-			DRM_UNLOCK;
+			DRM_UNLOCK();
 
 			*(drm_client_t *)data = client;
 			return 0;
 		}
 		i++;
 	}
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	DRM_COPY_TO_USER_IOCTL( (drm_client_t *)data, client, sizeof(client) );
 
@@ -211,7 +211,7 @@
 
 	memset(&stats, 0, sizeof(stats));
 	
-	DRM_LOCK;
+	DRM_LOCK();
 
 	for (i = 0; i < dev->counters; i++) {
 		if (dev->types[i] == _DRM_STAT_LOCK)
@@ -225,7 +225,7 @@
 	
 	stats.count = dev->counters;
 
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	DRM_COPY_TO_USER_IOCTL( (drm_stats_t *)data, stats, sizeof(stats) );
 
Index: sys/dev/drm/drm_memory.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_memory.h,v
retrieving revision 1.2
diff -u -u -r1.2 drm_memory.h
--- sys/dev/drm/drm_memory.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/drm_memory.h	14 Jan 2004 13:56:27 -0000
@@ -37,408 +37,151 @@
 #if defined(__FreeBSD__) || defined(__NetBSD__)
 #define malloctype DRM(M_DRM)
 /* The macros conflicted in the MALLOC_DEFINE */
-
 MALLOC_DEFINE(malloctype, "drm", "DRM Data Structures");
-
 #undef malloctype
 #endif
 
-typedef struct drm_mem_stats {
-	const char	  *name;
-	int		  succeed_count;
-	int		  free_count;
-	int		  fail_count;
-	unsigned long	  bytes_allocated;
-	unsigned long	  bytes_freed;
-} drm_mem_stats_t;
-
-static DRM_SPINTYPE	  DRM(mem_lock);
-static unsigned long	  DRM(ram_available) = 0; /* In pages */
-static unsigned long	  DRM(ram_used)      = 0;
-static drm_mem_stats_t	  DRM(mem_stats)[]   = {
-	[DRM_MEM_DMA]	    = { "dmabufs"  },
-	[DRM_MEM_SAREA]	    = { "sareas"   },
-	[DRM_MEM_DRIVER]    = { "driver"   },
-	[DRM_MEM_MAGIC]	    = { "magic"	   },
-	[DRM_MEM_IOCTLS]    = { "ioctltab" },
-	[DRM_MEM_MAPS]	    = { "maplist"  },
-	[DRM_MEM_BUFS]	    = { "buflist"  },
-	[DRM_MEM_SEGS]	    = { "seglist"  },
-	[DRM_MEM_PAGES]	    = { "pagelist" },
-	[DRM_MEM_FILES]	    = { "files"	   },
-	[DRM_MEM_QUEUES]    = { "queues"   },
-	[DRM_MEM_CMDS]	    = { "commands" },
-	[DRM_MEM_MAPPINGS]  = { "mappings" },
-	[DRM_MEM_BUFLISTS]  = { "buflists" },
-	[DRM_MEM_AGPLISTS]  = { "agplist"  },
-	[DRM_MEM_SGLISTS]   = { "sglist"   },
-	[DRM_MEM_TOTALAGP]  = { "totalagp" },
-	[DRM_MEM_BOUNDAGP]  = { "boundagp" },
-	[DRM_MEM_CTXBITMAP] = { "ctxbitmap"},
-	[DRM_MEM_STUB]      = { "stub"     },
-	{ NULL, 0, }		/* Last entry must be null */
-};
-
+#ifdef DEBUG_MEMORY
+#include "drm_memory_debug.h"
+#else
 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) {
-		mem->succeed_count   = 0;
-		mem->free_count	     = 0;
-		mem->fail_count	     = 0;
-		mem->bytes_allocated = 0;
-		mem->bytes_freed     = 0;
-	}
-
-	DRM(ram_available) = 0; /* si.totalram */
-	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_mem_stats_t *stats, struct sysctl_oid *oidp, void *arg1, 
-    int arg2, struct sysctl_req *req)
-{
-	drm_mem_stats_t *pt;
-	char buf[128];
-	int error;
-
-	DRM_SYSCTL_PRINT("		  total counts			"
-		       " |    outstanding  \n");
-	DRM_SYSCTL_PRINT("type	   alloc freed fail	bytes	   freed"
-		       " | allocs      bytes\n\n");
-	DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu	    |\n",
-		       "system", 0, 0, 0, DRM(ram_available));
-	DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu	    |\n",
-		       "locked", 0, 0, 0, DRM(ram_used));
-	DRM_SYSCTL_PRINT("\n");
-	for (pt = stats; pt->name; pt++) {
-		DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu %10lu | %6d %10ld\n",
-			       pt->name,
-			       pt->succeed_count,
-			       pt->free_count,
-			       pt->fail_count,
-			       pt->bytes_allocated,
-			       pt->bytes_freed,
-			       pt->succeed_count - pt->free_count,
-			       (long)pt->bytes_allocated
-			       - (long)pt->bytes_freed);
-	}
-	SYSCTL_OUT(req, "", 1);
-	
-	return 0;
-}
-
-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));
-	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 /* __FreeBSD__ */
 
 void *DRM(alloc)(size_t size, int area)
 {
-	void *pt;
-
-	if (!size) {
-		DRM_MEM_ERROR(area, "Allocating 0 bytes\n");
-		return NULL;
-	}
+	return malloc(size, DRM(M_DRM), M_NOWAIT);
+}
 
-	if (!(pt = malloc(size, DRM(M_DRM), M_NOWAIT))) {
-		DRM_SPINLOCK(&DRM(mem_lock));
-		++DRM(mem_stats)[area].fail_count;
-		DRM_SPINUNLOCK(&DRM(mem_lock));
-		return NULL;
-	}
-	DRM_SPINLOCK(&DRM(mem_lock));
-	++DRM(mem_stats)[area].succeed_count;
-	DRM(mem_stats)[area].bytes_allocated += size;
-	DRM_SPINUNLOCK(&DRM(mem_lock));
-	return pt;
+void *DRM(calloc)(size_t nmemb, size_t size, int area)
+{
+	return malloc(size * nmemb, DRM(M_DRM), M_NOWAIT | M_ZERO);
 }
 
 void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
 {
 	void *pt;
 
-	if (!(pt = DRM(alloc)(size, area))) return NULL;
+	pt = malloc(size, DRM(M_DRM), M_NOWAIT);
+	if (pt == NULL)
+		return NULL;
 	if (oldpt && oldsize) {
 		memcpy(pt, oldpt, oldsize);
-		DRM(free)(oldpt, oldsize, area);
+		free(oldpt, DRM(M_DRM));
 	}
 	return pt;
 }
 
-char *DRM(strdup)(const char *s, int area)
-{
-	char *pt;
-	int	 length = s ? strlen(s) : 0;
-
-	if (!(pt = DRM(alloc)(length+1, area))) return NULL;
-	strcpy(pt, s);
-	return pt;
-}
-
-void DRM(strfree)(char *s, int area)
-{
-	unsigned int size;
-
-	if (!s) return;
-
-	size = 1 + strlen(s);
-	DRM(free)((void *)s, size, area);
-}
-
 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");
-	else
-		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;
-	alloc_count =	DRM(mem_stats)[area].succeed_count;
-	DRM_SPINUNLOCK(&DRM(mem_lock));
-	if (free_count > alloc_count) {
-		DRM_MEM_ERROR(area, "Excess frees: %d frees, %d allocs\n",
-			      free_count, alloc_count);
-	}
+	free(pt, DRM(M_DRM));
 }
 
 void *DRM(ioremap)( drm_device_t *dev, drm_local_map_t *map )
 {
-	void *pt;
-
-	if (!map->size) {
-		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
-			      "Mapping 0 bytes at 0x%08lx\n", map->offset);
-		return NULL;
-	}
-#ifdef __NetBSD__
-	map->iot = dev->pa.pa_memt;
-#endif
-
 #ifdef __FreeBSD__
-	if (!(pt = pmap_mapdev(map->offset, map->size))) {
+	return pmap_mapdev(map->offset, map->size);
 #elif defined(__NetBSD__)
+	map->iot = dev->pa.pa_memt;
 	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));
+	    BUS_SPACE_MAP_LINEAR, &map->ioh))
 		return NULL;
-	}
-#ifdef __NetBSD__
-	pt = bus_space_vaddr(map->iot, map->ioh);
+	return 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 += map->size;
-	DRM_SPINUNLOCK(&DRM(mem_lock));
-	return pt;
-}
-
-/* unused so far */
-#if 0
-void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size)
-{
-	void *pt;
-
-	if (!size) {
-		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
-			      "Mapping 0 bytes at 0x%08lx\n", offset);
-		return NULL;
-	}
-
-	/* FIXME FOR BSD */
-	if (!(pt = ioremap_nocache(offset, size))) {
-		DRM_SPINLOCK(&DRM(mem_lock));
-		++DRM(mem_stats)[DRM_MEM_MAPPINGS].fail_count;
-		DRM_SPINUNLOCK(&DRM(mem_lock));
-		return NULL;
-	}
-	DRM_SPINLOCK(&DRM(mem_lock));
-	++DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
-	DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_allocated += size;
-	DRM_SPINUNLOCK(&DRM(mem_lock));
-	return pt;
 }
-#endif
 
 void DRM(ioremapfree)(drm_local_map_t *map)
 {
-	int alloc_count;
-	int free_count;
-
-	if (map->handle == NULL)
-		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
-			      "Attempt to free NULL pointer\n");
-	else
 #ifdef __FreeBSD__
-		pmap_unmapdev((vm_offset_t) map->handle, map->size);
+	pmap_unmapdev((vm_offset_t) map->handle, map->size);
 #elif defined(__NetBSD__)
-		bus_space_unmap(map->iot, map->ioh, map->size);
+	bus_space_unmap(map->iot, map->ioh, map->size);
 #endif
-
-	DRM_SPINLOCK(&DRM(mem_lock));
-	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));
-	if (free_count > alloc_count) {
-		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
-			      "Excess frees: %d frees, %d allocs\n",
-			      free_count, alloc_count);
-	}
 }
 
 #if __REALLY_HAVE_AGP
 agp_memory *DRM(alloc_agp)(int pages, u32 type)
 {
-	agp_memory *handle;
-
-	if (!pages) {
-		DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
-		return NULL;
-	}
-
-	if ((handle = DRM(agp_allocate_memory)(pages, type))) {
-		DRM_SPINLOCK(&DRM(mem_lock));
-		++DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
-		DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_allocated
-			+= pages << PAGE_SHIFT;
-		DRM_SPINUNLOCK(&DRM(mem_lock));
-		return handle;
-	}
-	DRM_SPINLOCK(&DRM(mem_lock));
-	++DRM(mem_stats)[DRM_MEM_TOTALAGP].fail_count;
-	DRM_SPINUNLOCK(&DRM(mem_lock));
-	return NULL;
+	return DRM(agp_allocate_memory)(pages, type);
 }
 
 int DRM(free_agp)(agp_memory *handle, int pages)
 {
-	int           alloc_count;
-	int           free_count;
-
-	if (!handle) {
-		DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
-		return DRM_ERR(EINVAL);
-	}
-
-	if (DRM(agp_free_memory)(handle)) {
-		DRM_SPINLOCK(&DRM(mem_lock));
-		free_count  = ++DRM(mem_stats)[DRM_MEM_TOTALAGP].free_count;
-		alloc_count =   DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
-		DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_freed
-			+= pages << PAGE_SHIFT;
-		DRM_SPINUNLOCK(&DRM(mem_lock));
-		if (free_count > alloc_count) {
-			DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
-				      "Excess frees: %d frees, %d allocs\n",
-				      free_count, alloc_count);
-		}
-		return 0;
-	}
-	return DRM_ERR(EINVAL);
+	return DRM(agp_free_memory)(handle);
 }
 
 int DRM(bind_agp)(agp_memory *handle, unsigned int start)
 {
-	int retcode;
-	device_t dev = DRM_AGP_FIND_DEVICE();
-	struct agp_memory_info info;
-
-	if (!dev)
-		return EINVAL;
-
-	if (!handle) {
-		DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
-			      "Attempt to bind NULL AGP handle\n");
-		return DRM_ERR(EINVAL);
-	}
-
-	if (!(retcode = DRM(agp_bind_memory)(handle, start))) {
-		DRM_SPINLOCK(&DRM(mem_lock));
-		++DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
-		agp_memory_info(dev, handle, &info);
-		DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_allocated
-			+= info.ami_size;
-		DRM_SPINUNLOCK(&DRM(mem_lock));
-		return DRM_ERR(0);
-	}
-	DRM_SPINLOCK(&DRM(mem_lock));
-	++DRM(mem_stats)[DRM_MEM_BOUNDAGP].fail_count;
-	DRM_SPINUNLOCK(&DRM(mem_lock));
-	return DRM_ERR(retcode);
+	return DRM(agp_bind_memory)(handle, start);
 }
 
 int DRM(unbind_agp)(agp_memory *handle)
 {
-	int alloc_count;
-	int free_count;
-	int retcode = EINVAL;
-	device_t dev = DRM_AGP_FIND_DEVICE();
-	struct agp_memory_info info;
-
-	if (!dev)
-		return EINVAL;
-
-	if (!handle) {
-		DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
-			      "Attempt to unbind NULL AGP handle\n");
-		return DRM_ERR(retcode);
-	}
+	return DRM(agp_unbind_memory)(handle);
+}
+#endif /* __REALLY_HAVE_AGP */
 
-	agp_memory_info(dev, handle, &info);
+#ifdef __FreeBSD__
+int
+DRM(mtrr_add)(unsigned long offset, size_t size, int flags)
+{
+	int act;
+	struct mem_range_desc mrdesc;
 
-	if ((retcode = DRM(agp_unbind_memory)(handle))) 
-		return DRM_ERR(retcode);
+	mrdesc.mr_base = offset;
+	mrdesc.mr_len = size;
+	mrdesc.mr_flags = flags;
+	act = MEMRANGE_SET_UPDATE;
+	bcopy(DRIVER_NAME, &mrdesc.mr_owner, strlen(DRIVER_NAME));
+	return mem_range_attr_set(&mrdesc, &act);
+}
+
+int
+DRM(mtrr_del)(unsigned long offset, size_t size, int flags)
+{
+	int act;
+	struct mem_range_desc mrdesc;
+
+	mrdesc.mr_base = offset;
+	mrdesc.mr_len = size;
+	mrdesc.mr_flags = flags;
+	act = MEMRANGE_SET_REMOVE;
+	bcopy(DRIVER_NAME, &mrdesc.mr_owner, strlen(DRIVER_NAME));
+	return mem_range_attr_set(&mrdesc, &act);
+}
+#elif defined(__NetBSD__)
+int
+DRM(mtrr_add)(unsigned long offset, size_t size, int flags)
+{
+	struct mtrr mtrrmap;
+	int one = 1;
 
-	DRM_SPINLOCK(&DRM(mem_lock));
-	free_count  = ++DRM(mem_stats)[DRM_MEM_BOUNDAGP].free_count;
-	alloc_count = DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
-	DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
-		+= info.ami_size;
-	DRM_SPINUNLOCK(&DRM(mem_lock));
-	if (free_count > alloc_count) {
-		DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
-			      "Excess frees: %d frees, %d allocs\n",
-			      free_count, alloc_count);
-	}
-	return DRM_ERR(retcode);
+	mtrrmap.base = offset;
+	mtrrmap.len = size;
+	mtrrmap.type = flags;
+	mtrrmap.flags = MTRR_VALID;
+	return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
+}
+
+int
+DRM(mtrr_del)(unsigned long offset, size_t size, int flags)
+{
+	struct mtrr mtrrmap;
+	int one = 1;
+
+	mtrrmap.base = offset;
+	mtrrmap.len = size;
+	mtrrmap.type = flags;
+	mtrrmap.flags = 0;
+	return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
 }
 #endif
+
+#endif /* DEBUG_MEMORY */
Index: sys/dev/drm/drm_memory_debug.h
===================================================================
RCS file: sys/dev/drm/drm_memory_debug.h
diff -N sys/dev/drm/drm_memory_debug.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sys/dev/drm/drm_memory_debug.h	14 Jan 2004 13:54:49 -0000
@@ -0,0 +1,422 @@
+/* drm_memory.h -- Memory management wrappers for DRM -*- linux-c -*-
+ * Created: Thu Feb  4 14:00:34 1999 by faith@xxxxxxxxxxx
+ *
+ * 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
+ * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Rickard E. (Rik) Faith <faith@xxxxxxxxxxx>
+ *    Gareth Hughes <gareth@xxxxxxxxxxx>
+ *
+ * $FreeBSD: src/sys/dev/drm/drm_memory.h,v 1.8.2.1 2003/04/26 07:05:28 anholt Exp $
+ * $DragonFly: src/sys/dev/drm/drm_memory.h,v 1.2 2003/06/17 04:28:24 dillon Exp $
+ */
+
+#include "dev/drm/drmP.h"
+
+#define DRM_SYSCTL_PRINT(fmt, arg...)				\
+do {								\
+	snprintf(buf, sizeof(buf), fmt, ##arg);			\
+	error = SYSCTL_OUT(req, buf, strlen(buf));		\
+	if (error)						\
+		return error;					\
+} while (0)
+
+typedef struct drm_mem_stats {
+	const char	  *name;
+	int		  succeed_count;
+	int		  free_count;
+	int		  fail_count;
+	unsigned long	  bytes_allocated;
+	unsigned long	  bytes_freed;
+} drm_mem_stats_t;
+
+static DRM_SPINTYPE	  DRM(mem_lock);
+static unsigned long	  DRM(ram_available) = 0; /* In pages */
+static unsigned long	  DRM(ram_used)      = 0;
+static drm_mem_stats_t	  DRM(mem_stats)[]   = {
+	[DRM_MEM_DMA]	    = { "dmabufs"  },
+	[DRM_MEM_SAREA]	    = { "sareas"   },
+	[DRM_MEM_DRIVER]    = { "driver"   },
+	[DRM_MEM_MAGIC]	    = { "magic"	   },
+	[DRM_MEM_IOCTLS]    = { "ioctltab" },
+	[DRM_MEM_MAPS]	    = { "maplist"  },
+	[DRM_MEM_BUFS]	    = { "buflist"  },
+	[DRM_MEM_SEGS]	    = { "seglist"  },
+	[DRM_MEM_PAGES]	    = { "pagelist" },
+	[DRM_MEM_FILES]	    = { "files"	   },
+	[DRM_MEM_QUEUES]    = { "queues"   },
+	[DRM_MEM_CMDS]	    = { "commands" },
+	[DRM_MEM_MAPPINGS]  = { "mappings" },
+	[DRM_MEM_BUFLISTS]  = { "buflists" },
+	[DRM_MEM_AGPLISTS]  = { "agplist"  },
+	[DRM_MEM_SGLISTS]   = { "sglist"   },
+	[DRM_MEM_TOTALAGP]  = { "totalagp" },
+	[DRM_MEM_BOUNDAGP]  = { "boundagp" },
+	[DRM_MEM_CTXBITMAP] = { "ctxbitmap"},
+	[DRM_MEM_STUB]      = { "stub"     },
+	{ NULL, 0, }		/* Last entry must be null */
+};
+
+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) {
+		mem->succeed_count   = 0;
+		mem->free_count	     = 0;
+		mem->fail_count	     = 0;
+		mem->bytes_allocated = 0;
+		mem->bytes_freed     = 0;
+	}
+
+	DRM(ram_available) = 0; /* si.totalram */
+	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_mem_stats_t *stats, struct sysctl_oid *oidp, void *arg1, 
+    int arg2, struct sysctl_req *req)
+{
+	drm_mem_stats_t *pt;
+	char buf[128];
+	int error;
+
+	DRM_SYSCTL_PRINT("		  total counts			"
+		       " |    outstanding  \n");
+	DRM_SYSCTL_PRINT("type	   alloc freed fail	bytes	   freed"
+		       " | allocs      bytes\n\n");
+	DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu	    |\n",
+		       "system", 0, 0, 0, DRM(ram_available));
+	DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu	    |\n",
+		       "locked", 0, 0, 0, DRM(ram_used));
+	DRM_SYSCTL_PRINT("\n");
+	for (pt = stats; pt->name; pt++) {
+		DRM_SYSCTL_PRINT("%-9.9s %5d %5d %4d %10lu %10lu | %6d %10ld\n",
+			       pt->name,
+			       pt->succeed_count,
+			       pt->free_count,
+			       pt->fail_count,
+			       pt->bytes_allocated,
+			       pt->bytes_freed,
+			       pt->succeed_count - pt->free_count,
+			       (long)pt->bytes_allocated
+			       - (long)pt->bytes_freed);
+	}
+	SYSCTL_OUT(req, "", 1);
+	
+	return 0;
+}
+
+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));
+	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 /* __FreeBSD__ */
+
+void *DRM(alloc)(size_t size, int area)
+{
+	void *pt;
+
+	if (!size) {
+		DRM_MEM_ERROR(area, "Allocating 0 bytes\n");
+		return NULL;
+	}
+
+	if (!(pt = malloc(size, DRM(M_DRM), M_NOWAIT))) {
+		DRM_SPINLOCK(&DRM(mem_lock));
+		++DRM(mem_stats)[area].fail_count;
+		DRM_SPINUNLOCK(&DRM(mem_lock));
+		return NULL;
+	}
+	DRM_SPINLOCK(&DRM(mem_lock));
+	++DRM(mem_stats)[area].succeed_count;
+	DRM(mem_stats)[area].bytes_allocated += size;
+	DRM_SPINUNLOCK(&DRM(mem_lock));
+	return pt;
+}
+
+void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
+{
+	void *pt;
+
+	if (!(pt = DRM(alloc)(size, area))) return NULL;
+	if (oldpt && oldsize) {
+		memcpy(pt, oldpt, oldsize);
+		DRM(free)(oldpt, oldsize, area);
+	}
+	return pt;
+}
+
+void DRM(free)(void *pt, size_t size, int area)
+{
+	int alloc_count;
+	int free_count;
+
+	if (pt == NULL)
+		return;
+	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;
+	alloc_count =	DRM(mem_stats)[area].succeed_count;
+	DRM_SPINUNLOCK(&DRM(mem_lock));
+	if (free_count > alloc_count) {
+		DRM_MEM_ERROR(area, "Excess frees: %d frees, %d allocs\n",
+			      free_count, alloc_count);
+	}
+}
+
+void *DRM(ioremap)( drm_device_t *dev, drm_local_map_t *map )
+{
+	void *pt;
+
+	if (!map->size) {
+		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
+			      "Mapping 0 bytes at 0x%08lx\n", map->offset);
+		return NULL;
+	}
+#ifdef __NetBSD__
+	map->iot = dev->pa.pa_memt;
+#endif
+
+#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 += map->size;
+	DRM_SPINUNLOCK(&DRM(mem_lock));
+	return pt;
+}
+
+/* unused so far */
+#if 0
+void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size)
+{
+	void *pt;
+
+	if (!size) {
+		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
+			      "Mapping 0 bytes at 0x%08lx\n", offset);
+		return NULL;
+	}
+
+	/* FIXME FOR BSD */
+	if (!(pt = ioremap_nocache(offset, size))) {
+		DRM_SPINLOCK(&DRM(mem_lock));
+		++DRM(mem_stats)[DRM_MEM_MAPPINGS].fail_count;
+		DRM_SPINUNLOCK(&DRM(mem_lock));
+		return NULL;
+	}
+	DRM_SPINLOCK(&DRM(mem_lock));
+	++DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count;
+	DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_allocated += size;
+	DRM_SPINUNLOCK(&DRM(mem_lock));
+	return pt;
+}
+#endif
+
+void DRM(ioremapfree)(drm_local_map_t *map)
+{
+	int alloc_count;
+	int free_count;
+
+	if (map->handle == NULL)
+		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
+			      "Attempt to free NULL pointer\n");
+	else
+#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 += 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));
+	if (free_count > alloc_count) {
+		DRM_MEM_ERROR(DRM_MEM_MAPPINGS,
+			      "Excess frees: %d frees, %d allocs\n",
+			      free_count, alloc_count);
+	}
+}
+
+#if __REALLY_HAVE_AGP
+agp_memory *DRM(alloc_agp)(int pages, u32 type)
+{
+	agp_memory *handle;
+
+	if (!pages) {
+		DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Allocating 0 pages\n");
+		return NULL;
+	}
+
+	if ((handle = DRM(agp_allocate_memory)(pages, type))) {
+		DRM_SPINLOCK(&DRM(mem_lock));
+		++DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
+		DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_allocated
+			+= pages << PAGE_SHIFT;
+		DRM_SPINUNLOCK(&DRM(mem_lock));
+		return handle;
+	}
+	DRM_SPINLOCK(&DRM(mem_lock));
+	++DRM(mem_stats)[DRM_MEM_TOTALAGP].fail_count;
+	DRM_SPINUNLOCK(&DRM(mem_lock));
+	return NULL;
+}
+
+int DRM(free_agp)(agp_memory *handle, int pages)
+{
+	int           alloc_count;
+	int           free_count;
+
+	if (!handle) {
+		DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
+			      "Attempt to free NULL AGP handle\n");
+		return DRM_ERR(EINVAL);
+	}
+
+	if (DRM(agp_free_memory)(handle)) {
+		DRM_SPINLOCK(&DRM(mem_lock));
+		free_count  = ++DRM(mem_stats)[DRM_MEM_TOTALAGP].free_count;
+		alloc_count =   DRM(mem_stats)[DRM_MEM_TOTALAGP].succeed_count;
+		DRM(mem_stats)[DRM_MEM_TOTALAGP].bytes_freed
+			+= pages << PAGE_SHIFT;
+		DRM_SPINUNLOCK(&DRM(mem_lock));
+		if (free_count > alloc_count) {
+			DRM_MEM_ERROR(DRM_MEM_TOTALAGP,
+				      "Excess frees: %d frees, %d allocs\n",
+				      free_count, alloc_count);
+		}
+		return 0;
+	}
+	return DRM_ERR(EINVAL);
+}
+
+int DRM(bind_agp)(agp_memory *handle, unsigned int start)
+{
+	int retcode;
+	device_t dev = DRM_AGP_FIND_DEVICE();
+	struct agp_memory_info info;
+
+	if (!dev)
+		return EINVAL;
+
+	if (!handle) {
+		DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
+			      "Attempt to bind NULL AGP handle\n");
+		return DRM_ERR(EINVAL);
+	}
+
+	if (!(retcode = DRM(agp_bind_memory)(handle, start))) {
+		DRM_SPINLOCK(&DRM(mem_lock));
+		++DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
+		agp_memory_info(dev, handle, &info);
+		DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_allocated
+			+= info.ami_size;
+		DRM_SPINUNLOCK(&DRM(mem_lock));
+		return DRM_ERR(0);
+	}
+	DRM_SPINLOCK(&DRM(mem_lock));
+	++DRM(mem_stats)[DRM_MEM_BOUNDAGP].fail_count;
+	DRM_SPINUNLOCK(&DRM(mem_lock));
+	return DRM_ERR(retcode);
+}
+
+int DRM(unbind_agp)(agp_memory *handle)
+{
+	int alloc_count;
+	int free_count;
+	int retcode = EINVAL;
+	device_t dev = DRM_AGP_FIND_DEVICE();
+	struct agp_memory_info info;
+
+	if (!dev)
+		return EINVAL;
+
+	if (!handle) {
+		DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
+			      "Attempt to unbind NULL AGP handle\n");
+		return DRM_ERR(retcode);
+	}
+
+	agp_memory_info(dev, handle, &info);
+
+	if ((retcode = DRM(agp_unbind_memory)(handle))) 
+		return DRM_ERR(retcode);
+
+	DRM_SPINLOCK(&DRM(mem_lock));
+	free_count  = ++DRM(mem_stats)[DRM_MEM_BOUNDAGP].free_count;
+	alloc_count = DRM(mem_stats)[DRM_MEM_BOUNDAGP].succeed_count;
+	DRM(mem_stats)[DRM_MEM_BOUNDAGP].bytes_freed
+		+= info.ami_size;
+	DRM_SPINUNLOCK(&DRM(mem_lock));
+	if (free_count > alloc_count) {
+		DRM_MEM_ERROR(DRM_MEM_BOUNDAGP,
+			      "Excess frees: %d frees, %d allocs\n",
+			      free_count, alloc_count);
+	}
+	return DRM_ERR(retcode);
+}
+#endif
Index: sys/dev/drm/drm_os_freebsd.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_os_freebsd.h,v
retrieving revision 1.7
diff -u -u -r1.7 drm_os_freebsd.h
--- sys/dev/drm/drm_os_freebsd.h	7 Aug 2003 21:16:55 -0000	1.7
+++ sys/dev/drm/drm_os_freebsd.h	14 Jan 2004 13:43:47 -0000
@@ -28,36 +28,50 @@
 #include <machine/pmap.h>
 #include <machine/bus.h>
 #include <machine/resource.h>
+#if __FreeBSD_version >= 480000 || __DragonFly__
+#include <sys/endian.h>
+#endif
 #include <sys/mman.h>
 #include <sys/rman.h>
 #include <sys/memrange.h>
+#if __DragonFly__
 #include <bus/pci/pcivar.h>
+#include <sys/select.h>
+#elif __FreeBSD__
 #if __FreeBSD_version >= 500000
+#include <dev/pci/pcivar.h>
 #include <sys/selinfo.h>
 #else
+#include <pci/pcivar.h>
 #include <sys/select.h>
 #endif
+#endif
 #include <sys/bus.h>
-#if __FreeBSD_version >= 400005
+#if __FreeBSD_version >= 400005 || __DragonFly__
 #include <sys/taskqueue.h>
 #endif
 #if __FreeBSD_version >= 500000
 #include <sys/mutex.h>
 #endif
 
-#if __FreeBSD_version >= 400006
+#if __FreeBSD_version >= 400006 || __DragonFly__
 #define __REALLY_HAVE_AGP	__HAVE_AGP
 #endif
 
 #ifdef __i386__
-#define __REALLY_HAVE_MTRR	(__HAVE_MTRR) && (__FreeBSD_version >= 500000)
+#define __REALLY_HAVE_MTRR	((__HAVE_MTRR) && (__FreeBSD_version >= 460000)) || __DragonFly__
 #else
 #define __REALLY_HAVE_MTRR	0
 #endif
+
 #define __REALLY_HAVE_SG	(__HAVE_SG)
 
 #if __REALLY_HAVE_AGP
+#if __DragonFly__
 #include <dev/agp/agpvar.h>
+#else
+#include <pci/agpvar.h>
+#endif
 #include <sys/agpio.h>
 #endif
 
@@ -82,6 +96,19 @@
 #define DRM_DEV_GID	0
 #define CDEV_MAJOR	145
 
+#if __DragonFly__
+#define DRM_CURPROC		curthread
+#define DRM_STRUCTPROC		struct thread
+#define DRM_SPINTYPE		struct lwkt_token
+#define DRM_SPININIT(l,name)	lwkt_inittoken(&l)
+#define DRM_SPINUNINIT(l)
+#define DRM_SPINLOCK(l)		lwkt_gettoken(l)
+#define DRM_SPINUNLOCK(u)	lwkt_reltoken(u);
+#define DRM_SPINLOCK_ASSERT(l)
+#define DRM_CURRENTPID		curthread->td_proc->p_pid
+#define DRM_LOCK()		lockmgr(&dev->dev_lock, LK_EXCLUSIVE, 0, DRM_CURPROC)
+#define DRM_UNLOCK() 		lockmgr(&dev->dev_lock, LK_RELEASE, 0, DRM_CURPROC)
+#elif __FreeBSD__
 #if __FreeBSD_version >= 500000
 #define DRM_CURPROC		curthread
 #define DRM_STRUCTPROC		struct thread
@@ -90,16 +117,27 @@
 #define DRM_SPINUNINIT(l)	mtx_destroy(&l)
 #define DRM_SPINLOCK(l)		mtx_lock(l)
 #define DRM_SPINUNLOCK(u)	mtx_unlock(u);
+#define DRM_SPINLOCK_ASSERT(l)	mtx_assert(l, MA_OWNED)
 #define DRM_CURRENTPID		curthread->td_proc->p_pid
+#define DRM_LOCK()		mtx_lock(&dev->dev_lock)
+#define DRM_UNLOCK() 		mtx_unlock(&dev->dev_lock)
 #else
-#define DRM_CURPROC		curthread
-#define DRM_STRUCTPROC		struct thread
-#define DRM_SPINTYPE		struct lwkt_token
-#define DRM_SPININIT(l,name)	lwkt_inittoken(&l)
+/* There is no need for locking on FreeBSD 4.x.  Synchronization is handled by
+ * the fact that there is no reentrancy of the kernel except for interrupt
+ * handlers, and the interrupt handler synchronization is managed by spls.
+ */
+#define DRM_CURPROC		curproc
+#define DRM_STRUCTPROC		struct proc
+#define DRM_SPINTYPE		
+#define DRM_SPININIT(l,name)
 #define DRM_SPINUNINIT(l)
-#define DRM_SPINLOCK(l)		lwkt_gettoken(l)
-#define DRM_SPINUNLOCK(u)	lwkt_reltoken(u);
-#define DRM_CURRENTPID		curthread->td_proc->p_pid
+#define DRM_SPINLOCK(l)
+#define DRM_SPINUNLOCK(u)
+#define DRM_SPINLOCK_ASSERT(l)
+#define DRM_CURRENTPID		curproc->p_pid
+#define DRM_LOCK()
+#define DRM_UNLOCK()
+#endif
 #endif
 
 /* Currently our DRMFILE (filp) is a void * which is actually the pid
@@ -107,11 +145,12 @@
  * 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(td)		suser(td)
+#define DRM_SUSER(p)		suser(p)
 #define DRM_TASKQUEUE_ARGS	void *arg, int pending
 #define DRM_IRQ_ARGS		void *arg
+typedef void			irqreturn_t;
+#define IRQ_HANDLED		/* nothing */
+#define IRQ_NONE		/* nothing */
 #define DRM_DEVICE		drm_device_t	*dev	= kdev->si_drv1
 #define DRM_MALLOC(size)	malloc( size, DRM(M_DRM), M_NOWAIT )
 #define DRM_FREE(pt,size)		free( pt, DRM(M_DRM) )
@@ -131,6 +170,23 @@
 #define DRM_AGP_FIND_DEVICE()	agp_find_device()
 #define DRM_ERR(v)		v
 
+#define DRM_MTRR_WC	MDF_WRITECOMBINE
+
+#define DRM_GET_PRIV_WITH_RETURN(_priv, _filp)			\
+do {								\
+	if (_filp != (DRMFILE)DRM_CURRENTPID) {			\
+		DRM_ERROR("filp doesn't match curproc\n");	\
+		return EINVAL;					\
+	}							\
+	DRM_LOCK();						\
+	_priv = DRM(find_file_by_proc)(dev, DRM_CURPROC);	\
+	DRM_UNLOCK();						\
+	if (_priv == NULL) {					\
+		DRM_DEBUG("can't find authenticator\n");	\
+		return EINVAL;					\
+	}							\
+} while (0)
+
 #define DRM_PRIV					\
 	drm_file_t	*priv	= (drm_file_t *) DRM(find_file_by_proc)(dev, p); \
 	if (!priv) {						\
@@ -173,12 +229,25 @@
 
 #define DRM_HZ hz
 
-#define DRM_WAIT_ON( ret, queue, timeout, condition )			\
-while (!condition) {							\
-	ret = tsleep( &(queue), PCATCH, "drmwtq", (timeout) );		\
-	if ( ret )							\
-		return ret;						\
+#if defined(__FreeBSD__) && __FreeBSD_version > 500000
+#define DRM_WAIT_ON( ret, queue, timeout, condition )		\
+for ( ret = 0 ; !ret && !(condition) ; ) {			\
+	mtx_lock(&dev->irq_lock);				\
+	if (!(condition))					\
+	   ret = msleep(&(queue), &dev->irq_lock, 	\
+			 PCATCH, "drmwtq", (timeout));	\
+	mtx_unlock(&dev->irq_lock);			\
+}
+#else
+#define DRM_WAIT_ON( ret, queue, timeout, condition )	\
+for ( ret = 0 ; !ret && !(condition) ; ) {		\
+        int s = spldrm();				\
+	if (!(condition))				\
+	   ret = tsleep( &(queue), PCATCH, 	\
+			 "drmwtq", (timeout) );		\
+	splx(s);					\
 }
+#endif
 
 #define DRM_WAKEUP( queue ) wakeup( queue )
 #define DRM_WAKEUP_INT( queue ) wakeup( queue )
@@ -204,13 +273,28 @@
 	(!useracc((caddr_t)uaddr, size, VM_PROT_READ))
 #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) 	\
 	copyin(arg2, arg1, arg3)
+#define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3)	\
+	copyout(arg2, arg1, arg3)
 #define DRM_GET_USER_UNCHECKED(val, uaddr)			\
 	((val) = fuword(uaddr), 0)
+#define DRM_PUT_USER_UNCHECKED(uaddr, val)			\
+	suword(uaddr, val)
 
-#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);
+/* DRM_READMEMORYBARRIER() prevents reordering of reads.
+ * DRM_WRITEMEMORYBARRIER() prevents reordering of writes.
+ * DRM_MEMORYBARRIER() prevents reordering of reads and writes.
+ */
+#if defined(__i386__)
+#define DRM_READMEMORYBARRIER()		__asm __volatile( \
+					"lock; addl $0,0(%%esp)" : : : "memory");
+#define DRM_WRITEMEMORYBARRIER()	__asm __volatile("" : : : "memory");
+#define DRM_MEMORYBARRIER()		__asm __volatile( \
+					"lock; addl $0,0(%%esp)" : : : "memory");
+#elif defined(__alpha__)
+#define DRM_READMEMORYBARRIER()		alpha_mb();
+#define DRM_WRITEMEMORYBARRIER()	alpha_wmb();
+#define DRM_MEMORYBARRIER()		alpha_mb();
+#endif
 
 #define PAGE_ALIGN(addr) round_page(addr)
 
@@ -223,6 +307,14 @@
 MALLOC_DECLARE(malloctype);
 #undef malloctype
 
+#if __FreeBSD_version >= 480000
+#define cpu_to_le32(x) htole32(x)
+#define le32_to_cpu(x) le32toh(x)
+#else
+#define cpu_to_le32(x) (x)
+#define le32_to_cpu(x) (x)
+#endif
+
 typedef struct drm_chipinfo
 {
 	int vendor;
@@ -231,8 +323,6 @@
 	char *name;
 } drm_chipinfo_t;
 
-#define cpu_to_le32(x) (x)	/* FIXME */
-
 typedef unsigned long dma_addr_t;
 typedef u_int32_t atomic_t;
 typedef u_int32_t u32;
@@ -318,8 +408,6 @@
 
 #define spldrm()		spltty()
 
-#define memset(p, v, s)		bzero(p, s)
-
 /*
  * Fake out the module macros for versions of FreeBSD where they don't
  * exist.
@@ -336,17 +424,21 @@
 
 				/* Macros to make printf easier */
 #define DRM_ERROR(fmt, arg...) \
-	printf("error: " "[" DRM_NAME ":%s] *ERROR* " fmt , __func__ , ## arg)
+	printf("error: [" DRM_NAME ":pid%d:%s] *ERROR* " fmt,		\
+	    DRM_CURRENTPID, __func__ , ## arg)
+
 #define DRM_MEM_ERROR(area, fmt, arg...) \
-	printf("error: " "[" DRM_NAME ":%s:%s] *ERROR* " fmt , \
-		__func__, DRM(mem_stats)[area].name , ##arg)
-#define DRM_INFO(fmt, arg...)  printf("info: " "[" DRM_NAME "] " fmt , ## arg)
+	printf("error: [" DRM_NAME ":pid%d:%s:%s] *ERROR* " fmt,	\
+	    DRM_CURRENTPID , __func__, DRM(mem_stats)[area].name , ##arg)
+
+#define DRM_INFO(fmt, arg...)  printf("info: [" DRM_NAME "] " fmt , ## arg)
 
 #if DRM_DEBUG_CODE
-#define DRM_DEBUG(fmt, arg...)						  \
-	do {								  \
-		if (DRM(flags) & DRM_FLAG_DEBUG)			  \
-			printf("[" DRM_NAME ":%s] " fmt , __func__ , ## arg); \
+#define DRM_DEBUG(fmt, arg...)						\
+	do {								\
+		if (DRM(flags) & DRM_FLAG_DEBUG)			\
+			printf("[" DRM_NAME ":pid%d:%s] " fmt,		\
+			    DRM_CURRENTPID, __func__ , ## arg);		\
 	} while (0)
 #else
 #define DRM_DEBUG(fmt, arg...)		 do { } while (0)
@@ -358,16 +450,10 @@
 #define DRM_SYSCTL_HANDLER_ARGS	SYSCTL_HANDLER_ARGS
 #endif
 
-#define DRM_SYSCTL_PRINT(fmt, arg...)		\
-  snprintf(buf, sizeof(buf), fmt, ##arg);	\
-  error = SYSCTL_OUT(req, buf, strlen(buf));	\
-  if (error) return error;
-
-#define DRM_SYSCTL_PRINT_RET(ret, fmt, arg...)	\
-  snprintf(buf, sizeof(buf), fmt, ##arg);	\
-  error = SYSCTL_OUT(req, buf, strlen(buf));	\
-  if (error) { ret; return error; }
-
+#define DRM_SYSCTL_PRINT(fmt, arg...)			\
+	snprintf(buf, sizeof(buf), fmt, ##arg);		\
+	error = SYSCTL_OUT(req, buf, strlen(buf));	\
+	if (error) return error;
 
 #define DRM_FIND_MAP(dest, o)						\
 	do {								\
@@ -399,5 +485,7 @@
 extern int		DRM(sysctl_init)(drm_device_t *dev);
 extern int		DRM(sysctl_cleanup)(drm_device_t *dev);
 
-/* Memory info sysctl (drm_memory.h) */
+/* Memory info sysctl (drm_memory_debug.h) */
+#ifdef DEBUG_MEMORY
 extern int		DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS;
+#endif
Index: sys/dev/drm/drm_sysctl.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/drm_sysctl.h,v
retrieving revision 1.2
diff -u -u -r1.2 drm_sysctl.h
--- sys/dev/drm/drm_sysctl.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/drm_sysctl.h	14 Jan 2004 14:00:19 -0000
@@ -10,17 +10,23 @@
 static int	   DRM(name_info)DRM_SYSCTL_HANDLER_ARGS;
 static int	   DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS;
 static int	   DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS;
+#if __HAVE_DMA
 static int	   DRM(bufs_info)DRM_SYSCTL_HANDLER_ARGS;
+#endif
 
 struct DRM(sysctl_list) {
 	const char *name;
 	int	   (*f) DRM_SYSCTL_HANDLER_ARGS;
 } DRM(sysctl_list)[] = {
 	{ "name",    DRM(name_info)    },
+#ifdef DEBUG_MEMORY
 	{ "mem",     DRM(mem_info)     },
+#endif
 	{ "vm",	     DRM(vm_info)      },
 	{ "clients", DRM(clients_info) },
+#if __HAVE_DMA
 	{ "bufs",    DRM(bufs_info)    },
+#endif
 };
 #define DRM_SYSCTL_ENTRIES (sizeof(DRM(sysctl_list))/sizeof(DRM(sysctl_list)[0]))
 
@@ -155,9 +161,9 @@
 	drm_device_t *dev = arg1;
 	int	     ret;
 
-	DRM_LOCK;
+	DRM_LOCK();
 	ret = DRM(_vm_info)(oidp, arg1, arg2, req);
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 
 	return ret;
 }
@@ -207,9 +213,9 @@
 	drm_device_t *dev = arg1;
 	int	     ret;
 
-	DRM_LOCK;
+	DRM_LOCK();
 	ret = DRM(_bufs_info)(oidp, arg1, arg2, req);
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 	return ret;
 }
 
@@ -241,9 +247,9 @@
 	drm_device_t *dev = arg1;
 	int	     ret;
 
-	DRM_LOCK;
+	DRM_LOCK();
 	ret = DRM(_clients_info)(oidp, arg1, arg2, req);
-	DRM_UNLOCK;
+	DRM_UNLOCK();
 	return ret;
 }
 
Index: sys/dev/drm/mga/mga_drv.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/mga/mga_drv.h,v
retrieving revision 1.2
diff -u -u -r1.2 mga_drv.h
--- sys/dev/drm/mga/mga_drv.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/mga/mga_drv.h	13 Jan 2004 19:16:11 -0000
@@ -134,7 +134,7 @@
 extern int mga_warp_install_microcode( drm_mga_private_t *dev_priv );
 extern int mga_warp_init( drm_mga_private_t *dev_priv );
 
-#define mga_flush_write_combine()	DRM_WRITEMEMORYBARRIER(dev_priv->primary)
+#define mga_flush_write_combine()	DRM_WRITEMEMORYBARRIER()
 
 #if defined(__linux__) && defined(__alpha__)
 #define MGA_BASE( reg )		((unsigned long)(dev_priv->mmio->handle))
@@ -145,12 +145,12 @@
 
 #define MGA_READ( reg )		(_MGA_READ((u32 *)MGA_ADDR(reg)))
 #define MGA_READ8( reg )	(_MGA_READ((u8 *)MGA_ADDR(reg)))
-#define MGA_WRITE( reg, val )	do { DRM_WRITEMEMORYBARRIER(dev_priv->mmio); MGA_DEREF( reg ) = val; } while (0)
-#define MGA_WRITE8( reg, val )  do { DRM_WRITEMEMORYBARRIER(dev_priv->mmio); MGA_DEREF8( reg ) = val; } while (0)
+#define MGA_WRITE( reg, val )	do { DRM_WRITEMEMORYBARRIER(); MGA_DEREF( reg ) = val; } while (0)
+#define MGA_WRITE8( reg, val )  do { DRM_WRITEMEMORYBARRIER(); MGA_DEREF8( reg ) = val; } while (0)
 
 static inline u32 _MGA_READ(u32 *addr)
 {
-	DRM_READMEMORYBARRIER(dev_priv->mmio);
+	DRM_MEMORYBARRIER();
 	return *(volatile u32 *)addr;
 }
 #else
Index: sys/dev/drm/r128/r128_drv.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/r128/r128_drv.h,v
retrieving revision 1.2
diff -u -u -r1.2 r128_drv.h
--- sys/dev/drm/r128/r128_drv.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/r128/r128_drv.h	13 Jan 2004 19:17:42 -0000
@@ -443,7 +443,7 @@
 #if defined(__powerpc__)
 #define r128_flush_write_combine()	(void) GET_RING_HEAD( &dev_priv->ring )
 #else
-#define r128_flush_write_combine()	DRM_WRITEMEMORYBARRIER(dev_priv->ring_rptr)
+#define r128_flush_write_combine()	DRM_MEMORYBARRIER()
 #endif
 
Index: sys/dev/drm/radeon/radeon.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/radeon/radeon.h,v
retrieving revision 1.2
diff -u -u -r1.2 radeon.h
--- sys/dev/drm/radeon/radeon.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/radeon/radeon.h	13 Jan 2004 19:06:05 -0000
@@ -124,7 +124,7 @@
 		if ( dev_priv->page_flipping ) {			\
 			radeon_do_cleanup_pageflip( dev );		\
 		}							\
-                radeon_mem_release( filp, dev_priv->agp_heap );		\
+                radeon_mem_release( filp, dev_priv->gart_heap );		\
                 radeon_mem_release( filp, dev_priv->fb_heap );		\
 	}								\
 } while (0)
Index: sys/dev/drm/radeon/radeon_cp.c
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/radeon/radeon_cp.c,v
retrieving revision 1.4
diff -u -u -r1.4 radeon_cp.c
--- sys/dev/drm/radeon/radeon_cp.c	7 Aug 2003 21:16:55 -0000	1.4
+++ sys/dev/drm/radeon/radeon_cp.c	13 Jan 2004 19:05:10 -0000
@@ -858,25 +858,25 @@
 
 	/* Initialize the memory controller */
 	RADEON_WRITE( RADEON_MC_FB_LOCATION,
-		      (dev_priv->agp_vm_start - 1) & 0xffff0000 );
+		      (dev_priv->gart_vm_start - 1) & 0xffff0000 );
 
 	if ( !dev_priv->is_pci ) {
 		RADEON_WRITE( RADEON_MC_AGP_LOCATION,
-			      (((dev_priv->agp_vm_start - 1 +
-				 dev_priv->agp_size) & 0xffff0000) |
-			       (dev_priv->agp_vm_start >> 16)) );
+			      (((dev_priv->gart_vm_start - 1 +
+				 dev_priv->gart_size) & 0xffff0000) |
+			       (dev_priv->gart_vm_start >> 16)) );
 	}
 
 #if __REALLY_HAVE_AGP
 	if ( !dev_priv->is_pci )
 		ring_start = (dev_priv->cp_ring->offset
 			      - dev->agp->base
-			      + dev_priv->agp_vm_start);
+			      + dev_priv->gart_vm_start);
        else
 #endif
 		ring_start = (dev_priv->cp_ring->offset
 			      - dev->sg->handle
-			      + dev_priv->agp_vm_start);
+			      + dev_priv->gart_vm_start);
 
 	RADEON_WRITE( RADEON_CP_RB_BASE, ring_start );
 
@@ -894,7 +894,7 @@
 		RADEON_WRITE( RADEON_CP_RB_RPTR_ADDR,
 			      dev_priv->ring_rptr->offset
 			      - dev->agp->base
-			      + dev_priv->agp_vm_start);
+			      + dev_priv->gart_vm_start);
 	} else
 #endif
 	{
@@ -1094,7 +1094,7 @@
 	dev_priv->ring_offset = init->ring_offset;
 	dev_priv->ring_rptr_offset = init->ring_rptr_offset;
 	dev_priv->buffers_offset = init->buffers_offset;
-	dev_priv->agp_textures_offset = init->agp_textures_offset;
+	dev_priv->gart_textures_offset = init->gart_textures_offset;
 	
 	if(!dev_priv->sarea) {
 		DRM_ERROR("could not find sarea!\n");
@@ -1103,13 +1103,6 @@
 		return DRM_ERR(EINVAL);
 	}
 
-	DRM_FIND_MAP( dev_priv->fb, init->fb_offset );
-	if(!dev_priv->fb) {
-		DRM_ERROR("could not find framebuffer!\n");
-		dev->dev_private = (void *)dev_priv;
-		radeon_do_cleanup_cp(dev);
-		return DRM_ERR(EINVAL);
-	}
 	DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset );
 	if(!dev_priv->mmio) {
 		DRM_ERROR("could not find mmio region!\n");
@@ -1139,11 +1132,10 @@
 		return DRM_ERR(EINVAL);
 	}
 
-	if ( !dev_priv->is_pci ) {
-		DRM_FIND_MAP( dev_priv->agp_textures,
-			      init->agp_textures_offset );
-		if(!dev_priv->agp_textures) {
-			DRM_ERROR("could not find agp texture region!\n");
+	if ( init->gart_textures_offset ) {
+		DRM_FIND_MAP( dev_priv->gart_textures, init->gart_textures_offset );
+		if ( !dev_priv->gart_textures ) {
+			DRM_ERROR("could not find GART texture region!\n");
 			dev->dev_private = (void *)dev_priv;
 			radeon_do_cleanup_cp(dev);
 			return DRM_ERR(EINVAL);
@@ -1181,26 +1173,43 @@
 			   dev_priv->buffers->handle );
 	}
 
+	dev_priv->fb_location = ( RADEON_READ( RADEON_MC_FB_LOCATION )
+				& 0xffff ) << 16;
+
+	dev_priv->front_pitch_offset = (((dev_priv->front_pitch/64) << 22) |
+					( ( dev_priv->front_offset
+					  + dev_priv->fb_location ) >> 10 ) );
+
+	dev_priv->back_pitch_offset = (((dev_priv->back_pitch/64) << 22) |
+				       ( ( dev_priv->back_offset
+					 + dev_priv->fb_location ) >> 10 ) );
+
+	dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch/64) << 22) |
+					( ( dev_priv->depth_offset
+					  + dev_priv->fb_location ) >> 10 ) );
+
+
+	dev_priv->gart_size = init->gart_size;
+	dev_priv->gart_vm_start = dev_priv->fb_location
+				+ RADEON_READ( RADEON_CONFIG_APER_SIZE );
 
-	dev_priv->agp_size = init->agp_size;
-	dev_priv->agp_vm_start = RADEON_READ( RADEON_CONFIG_APER_SIZE );
 #if __REALLY_HAVE_AGP
 	if ( !dev_priv->is_pci )
-		dev_priv->agp_buffers_offset = (dev_priv->buffers->offset
+		dev_priv->gart_buffers_offset = (dev_priv->buffers->offset
 						- dev->agp->base
-						+ dev_priv->agp_vm_start);
+						+ dev_priv->gart_vm_start);
 	else
 #endif
-		dev_priv->agp_buffers_offset = (dev_priv->buffers->offset
+		dev_priv->gart_buffers_offset = (dev_priv->buffers->offset
 						- dev->sg->handle
-						+ dev_priv->agp_vm_start);
+						+ dev_priv->gart_vm_start);
 
-	DRM_DEBUG( "dev_priv->agp_size %d\n",
-		   dev_priv->agp_size );
-	DRM_DEBUG( "dev_priv->agp_vm_start 0x%x\n",
-		   dev_priv->agp_vm_start );
-	DRM_DEBUG( "dev_priv->agp_buffers_offset 0x%lx\n",
-		   dev_priv->agp_buffers_offset );
+	DRM_DEBUG( "dev_priv->gart_size %d\n",
+		   dev_priv->gart_size );
+	DRM_DEBUG( "dev_priv->gart_vm_start 0x%x\n",
+		   dev_priv->gart_vm_start );
+	DRM_DEBUG( "dev_priv->gart_buffers_offset 0x%lx\n",
+		   dev_priv->gart_buffers_offset );
 
 	dev_priv->ring.start = (u32 *)dev_priv->cp_ring->handle;
 	dev_priv->ring.end = ((u32 *)dev_priv->cp_ring->handle
@@ -1234,9 +1243,9 @@
 
 		/* set address range for PCI address translate
 		 */
-		RADEON_WRITE( RADEON_AIC_LO_ADDR, dev_priv->agp_vm_start );
-		RADEON_WRITE( RADEON_AIC_HI_ADDR, dev_priv->agp_vm_start
-						  + dev_priv->agp_size - 1);
+		RADEON_WRITE( RADEON_AIC_LO_ADDR, dev_priv->gart_vm_start );
+		RADEON_WRITE( RADEON_AIC_HI_ADDR, dev_priv->gart_vm_start
+						  + dev_priv->gart_size - 1);
 
 		/* Turn off AGP aperture -- is this required for PCIGART?
 		 */
@@ -1407,7 +1416,7 @@
 		RADEON_WRITE( RADEON_GEN_INT_CNTL, 0 );
 
 		/* Free memory heap structures */
-		radeon_mem_takedown( &(dev_priv->agp_heap) );
+		radeon_mem_takedown( &(dev_priv->gart_heap) );
 		radeon_mem_takedown( &(dev_priv->fb_heap) );
 
 		/* deallocate kernel resources */
Index: sys/dev/drm/radeon/radeon_drm.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/radeon/radeon_drm.h,v
retrieving revision 1.2
diff -u -u -r1.2 radeon_drm.h
--- sys/dev/drm/radeon/radeon_drm.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/radeon/radeon_drm.h	13 Jan 2004 18:52:42 -0000
@@ -214,11 +214,11 @@
 
 #define RADEON_NR_SAREA_CLIPRECTS	12
 
-/* There are 2 heaps (local/AGP).  Each region within a heap is a
+/* There are 2 heaps (local/GART).  Each region within a heap is a
  * minimum of 64k, and there are at most 64 of them per heap.
  */
 #define RADEON_LOCAL_TEX_HEAP		0
-#define RADEON_AGP_TEX_HEAP		1
+#define RADEON_GART_TEX_HEAP		1
 #define RADEON_NR_TEX_HEAPS		2
 #define RADEON_NR_TEX_REGIONS		64
 #define RADEON_LOG_TEX_GRANULARITY	16
@@ -404,7 +404,7 @@
 	unsigned long sarea_priv_offset;
 	int is_pci;
 	int cp_mode;
-	int agp_size;
+	int gart_size;
 	int ring_size;
 	int usec_timeout;
 
@@ -419,7 +419,7 @@
 	unsigned long ring_offset;
 	unsigned long ring_rptr_offset;
 	unsigned long buffers_offset;
-	unsigned long agp_textures_offset;
+	unsigned long gart_textures_offset;
 } drm_radeon_init_t;
 
 typedef struct drm_radeon_cp_stop {
@@ -529,16 +529,19 @@
 /* 1.3: An ioctl to get parameters that aren't available to the 3d
  * client any other way.  
  */
-#define RADEON_PARAM_AGP_BUFFER_OFFSET     1 /* card offset of 1st agp buffer */
+#define RADEON_PARAM_GART_BUFFER_OFFSET    1 /* card offset of 1st GART buffer */
 #define RADEON_PARAM_LAST_FRAME            2
 #define RADEON_PARAM_LAST_DISPATCH         3
 #define RADEON_PARAM_LAST_CLEAR            4
+/* Added with DRM version 1.6. */
 #define RADEON_PARAM_IRQ_NR                5
-#define RADEON_PARAM_AGP_BASE              6 /* card offset of agp base */
+#define RADEON_PARAM_GART_BASE             6 /* card offset of GART base */
+/* Added with DRM version 1.8. */
 #define RADEON_PARAM_REGISTER_HANDLE       7 /* for drmMap() */
 #define RADEON_PARAM_STATUS_HANDLE         8
 #define RADEON_PARAM_SAREA_HANDLE          9
-#define RADEON_PARAM_AGP_TEX_HANDLE        10
+#define RADEON_PARAM_GART_TEX_HANDLE       10
+#define RADEON_PARAM_SCRATCH_OFFSET        11
 
 typedef struct drm_radeon_getparam {
 	int param;
@@ -547,14 +550,14 @@
 
 /* 1.6: Set up a memory manager for regions of shared memory:
  */
-#define RADEON_MEM_REGION_AGP 1
+#define RADEON_MEM_REGION_GART 1
 #define RADEON_MEM_REGION_FB  2
 
 typedef struct drm_radeon_mem_alloc {
 	int region;
 	int alignment;
 	int size;
-	int *region_offset;	/* offset from start of fb or agp */
+	int *region_offset;	/* offset from start of fb or GART */
 } drm_radeon_mem_alloc_t;
 
 typedef struct drm_radeon_mem_free {
Index: sys/dev/drm/radeon/radeon_drv.h
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/radeon/radeon_drv.h,v
retrieving revision 1.2
diff -u -u -r1.2 radeon_drv.h
--- sys/dev/drm/radeon/radeon_drv.h	17 Jun 2003 04:28:24 -0000	1.2
+++ sys/dev/drm/radeon/radeon_drv.h	13 Jan 2004 19:03:50 -0000
@@ -76,9 +76,11 @@
 	drm_radeon_ring_buffer_t ring;
 	drm_radeon_sarea_t *sarea_priv;
 
-	int agp_size;
-	u32 agp_vm_start;
-	unsigned long agp_buffers_offset;
+	u32 fb_location;
+
+	int gart_size;
+	u32 gart_vm_start;
+	unsigned long gart_buffers_offset;
 
 	int cp_mode;
 	int cp_running;
@@ -133,17 +135,16 @@
 	unsigned long ring_offset;
 	unsigned long ring_rptr_offset;
 	unsigned long buffers_offset;
-	unsigned long agp_textures_offset;
+	unsigned long gart_textures_offset;
 
 	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;
+	drm_local_map_t *gart_textures;
 
-	struct mem_block *agp_heap;
+	struct mem_block *gart_heap;
 	struct mem_block *fb_heap;
 
 	/* SW interrupt */
@@ -855,7 +856,7 @@
 
 #define COMMIT_RING() do {						\
 	/* Flush writes to ring */					\
-	DRM_READMEMORYBARRIER( dev_priv->mmio );			\
+	DRM_MEMORYBARRIER();			\
 	GET_RING_HEAD( dev_priv );					\
 	RADEON_WRITE( RADEON_CP_RB_WPTR, dev_priv->ring.tail );		\
 	/* read from PCI bus to ensure correct posting */		\
Index: sys/dev/drm/radeon/radeon_mem.c
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/radeon/radeon_mem.c,v
retrieving revision 1.3
diff -u -u -r1.3 radeon_mem.c
--- sys/dev/drm/radeon/radeon_mem.c	7 Aug 2003 21:16:55 -0000	1.3
+++ sys/dev/drm/radeon/radeon_mem.c	13 Jan 2004 19:06:44 -0000
@@ -215,8 +215,8 @@
 				   int region )
 {
 	switch( region ) {
-	case RADEON_MEM_REGION_AGP:
- 		return &dev_priv->agp_heap; 
+	case RADEON_MEM_REGION_GART:
+ 		return &dev_priv->gart_heap; 
 	case RADEON_MEM_REGION_FB:
 		return &dev_priv->fb_heap;
 	default:
Index: sys/dev/drm/radeon/radeon_state.c
===================================================================
RCS file: /home/dcvs/src/sys/dev/drm/radeon/radeon_state.c,v
retrieving revision 1.3
diff -u -u -r1.3 radeon_state.c
--- sys/dev/drm/radeon/radeon_state.c	7 Aug 2003 21:16:55 -0000	1.3
+++ sys/dev/drm/radeon/radeon_state.c	13 Jan 2004 19:08:00 -0000
@@ -895,7 +895,7 @@
 {
 	drm_radeon_private_t *dev_priv = dev->dev_private;
 	drm_clip_rect_t box;
-	int offset = dev_priv->agp_buffers_offset + buf->offset + prim->start;
+	int offset = dev_priv->gart_buffers_offset + buf->offset + prim->start;
 	int numverts = (int)prim->numverts;
 	int i = 0;
 	RING_LOCALS;
@@ -969,7 +969,7 @@
 		   buf->idx, start, end );
 
 	if ( start != end ) {
-		int offset = (dev_priv->agp_buffers_offset
+		int offset = (dev_priv->gart_buffers_offset
 			      + buf->offset + start);
 		int dwords = (end - start + 3) / sizeof(u32);
 
@@ -1004,7 +1004,7 @@
 {
 	drm_radeon_private_t *dev_priv = dev->dev_private;
 	drm_clip_rect_t box;
-	int offset = dev_priv->agp_buffers_offset + prim->offset;
+	int offset = dev_priv->gart_buffers_offset + prim->offset;
 	u32 *data;
 	int dwords;
 	int i = 0;
@@ -2174,8 +2174,8 @@
 	DRM_DEBUG( "pid=%d\n", DRM_CURRENTPID );
 
 	switch( param.param ) {
-	case RADEON_PARAM_AGP_BUFFER_OFFSET:
-		value = dev_priv->agp_buffers_offset;
+	case RADEON_PARAM_GART_BUFFER_OFFSET:
+		value = dev_priv->gart_buffers_offset;
 		break;
 	case RADEON_PARAM_LAST_FRAME:
 		dev_priv->stats.last_frame_reads++;
@@ -2191,8 +2191,8 @@
 	case RADEON_PARAM_IRQ_NR:
 		value = dev->irq;
 		break;
-	case RADEON_PARAM_AGP_BASE:
-		value = dev_priv->agp_vm_start;
+	case RADEON_PARAM_GART_BASE:
+		value = dev_priv->gart_vm_start;
 		break;
 	case RADEON_PARAM_REGISTER_HANDLE:
 		value = dev_priv->mmio_offset;
@@ -2204,8 +2204,8 @@
 		/* The lock is the first dword in the sarea. */
 		value = (int)dev->lock.hw_lock; 
 		break;	
-	case RADEON_PARAM_AGP_TEX_HANDLE:
-		value = dev_priv->agp_textures_offset;
+	case RADEON_PARAM_GART_TEX_HANDLE:
+		value = dev_priv->gart_textures_offset;
 		break;
 	default:
 		return DRM_ERR(EINVAL);
@@ -2218,3 +2218,33 @@
 	
 	return 0;
 }
+
+/*
+int radeon_cp_setparam( DRM_IOCTL_ARGS ) {
+	DRM_DEVICE;
+	drm_radeon_private_t *dev_priv = dev->dev_private;
+	drm_file_t *filp_priv;
+	drm_radeon_setparam_t sp;
+
+	if ( !dev_priv ) {
+		DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
+		return DRM_ERR( EINVAL );
+	}
+
+	DRM_GET_PRIV_WITH_RETURN( filp_priv, filp );
+
+	DRM_COPY_FROM_USER_IOCTL( sp, ( drm_radeon_setparam_t* )data,
+				  sizeof( sp ) );
+
+	switch( sp.param ) {
+	case RADEON_SETPARAM_FB_LOCATION:
+		filp_priv->radeon_fb_delta = dev_priv->fb_location - sp.value;
+		break;
+	default:
+		DRM_DEBUG( "Invalid parameter %d\n", sp.param );
+		return DRM_ERR( EINVAL );
+	}
+
+	return 0;
+}
+*/


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]