diff options
author | Eric Anholt <anholt@freebsd.org> | 2003-02-08 23:52:30 +0000 |
---|---|---|
committer | Eric Anholt <anholt@freebsd.org> | 2003-02-08 23:52:30 +0000 |
commit | 8a25e70c656a6182fbb22a6b538931d1bcf53b5d (patch) | |
tree | 3c1a6e6ead1bf1eef498c4c17163c6bc65cc59b6 | |
parent | 2f01ef640271fa62f86810940730fcf2741bdcec (diff) |
Updates for NetBSD, fixing mga support at least.
Submitted by: Erik Reid
-rw-r--r-- | bsd-core/drm_drv.c | 47 | ||||
-rw-r--r-- | bsd-core/drm_fops.c | 2 | ||||
-rw-r--r-- | bsd-core/drm_memory.c | 21 | ||||
-rw-r--r-- | bsd-core/drm_os_netbsd.h | 24 | ||||
-rw-r--r-- | bsd/drm_drv.h | 47 | ||||
-rw-r--r-- | bsd/drm_fops.h | 2 | ||||
-rw-r--r-- | bsd/drm_memory.h | 21 | ||||
-rw-r--r-- | bsd/drm_os_netbsd.h | 24 |
8 files changed, 88 insertions, 100 deletions
diff --git a/bsd-core/drm_drv.c b/bsd-core/drm_drv.c index cec29bd0..3cab7316 100644 --- a/bsd-core/drm_drv.c +++ b/bsd-core/drm_drv.c @@ -125,13 +125,8 @@ #define DRIVER_NUM_CARDS 1 #endif -#ifdef __FreeBSD__ static int DRM(init)(device_t nbdev); static void DRM(cleanup)(device_t nbdev); -#elif defined(__NetBSD__) -static int DRM(init)(drm_device_t *); -static void DRM(cleanup)(drm_device_t *); -#endif #ifdef __FreeBSD__ #define DRIVER_SOFTC(unit) \ @@ -337,13 +332,7 @@ static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd) case LKM_E_LOAD: if (lkmexists(lkmtp)) return EEXIST; -
#if defined(__NetBSD__) && (__NetBSD_Version__ > 106080000) - error = devsw_attach(args->lkm_devname, - args->lkm_bdev, &args->lkm_bdevmaj, - args->lkm_cdev, &args->lkm_cdevmaj); - if(error != 0) - return error; -#endif + if(DRM(modprobe)()) return 0; @@ -352,10 +341,6 @@ static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd) case LKM_E_UNLOAD: if (DRM(refcnt) > 0) return (EBUSY); - -#if defined(__NetBSD__) && (__NetBSD_Version__ > 106080000) - devsw_detach(args->lkm_bdev, args->lkm_cdev); -#endif break; case LKM_E_STAT: break; @@ -364,6 +349,7 @@ static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd) error = EIO; break; } + return error; } @@ -372,6 +358,7 @@ int DRM(modprobe)() { int error = 0; if((error = pci_find_device(&pa, DRM(probe))) != 0) DRM(attach)(&pa, 0); + return error; } @@ -381,16 +368,21 @@ int DRM(probe)(struct pci_attach_args *pa) desc = DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id)); if (desc != NULL) { - return 10; + return 1; } return 0; } void DRM(attach)(struct pci_attach_args *pa, dev_t kdev) - { +{ int i; - DRM_DEVICE; + drm_device_t *dev; + + config_makeroom(kdev, &DRM(cd)); + DRM(cd).cd_devs[(kdev)] = DRM(alloc)(sizeof(drm_device_t), + DRM_MEM_DRIVER); + dev = DRIVER_SOFTC(kdev); memset(dev, 0, sizeof(drm_device_t)); memcpy(&dev->pa, pa, sizeof(dev->pa)); @@ -728,15 +720,13 @@ static int DRM(takedown)( drm_device_t *dev ) * linux/init/main.c (this is not currently supported). * bsd: drm_init is called via the attach function per device. */ -#ifdef __FreeBSD__ static int DRM(init)( device_t nbdev ) -#elif defined(__NetBSD__) -static int DRM(init)( drm_device_t *dev ) -#endif { int unit; #ifdef __FreeBSD__ drm_device_t *dev; +#elif defined(__NetBSD__) + drm_device_t *dev = nbdev; #endif #if __HAVE_CTX_BITMAP int retcode; @@ -832,21 +822,16 @@ static int DRM(init)( drm_device_t *dev ) * bsd: drm_cleanup is called per device at module unload time. * FIXME: NetBSD */ -#ifdef __FreeBSD__ static void DRM(cleanup)(device_t nbdev) -#elif defined(__NetBSD__) -static void DRM(cleanup)(drm_device_t *dev) -#endif { -#ifdef __FreeBSD__ drm_device_t *dev; -#endif -#if __REALLY_HAVE_MTRR #ifdef __NetBSD__ +#if __REALLY_HAVE_MTRR struct mtrr mtrrmap; int one = 1; -#endif /* __NetBSD__ */ #endif /* __REALLY_HAVE_MTRR */ + dev = nbdev; +#endif /* __NetBSD__ */ DRM_DEBUG( "\n" ); diff --git a/bsd-core/drm_fops.c b/bsd-core/drm_fops.c index c4152ac3..d2faaa43 100644 --- a/bsd-core/drm_fops.c +++ b/bsd-core/drm_fops.c @@ -182,8 +182,8 @@ int DRM(write_string)(drm_device_t *dev, const char *s) selwakeup(&dev->buf_sel); } - DRM_DEBUG("dev->buf_sigio=%p\n", dev->buf_sigio); #ifdef __FreeBSD__ + DRM_DEBUG("dev->buf_sigio=%p\n", dev->buf_sigio); if (dev->buf_sigio) { DRM_DEBUG("dev->buf_sigio->sio_pgid=%d\n", dev->buf_sigio->sio_pgid); #if __FreeBSD_version >= 500000 diff --git a/bsd-core/drm_memory.c b/bsd-core/drm_memory.c index a0b0deb6..aa81363f 100644 --- a/bsd-core/drm_memory.c +++ b/bsd-core/drm_memory.c @@ -31,9 +31,9 @@ #include "drmP.h" -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) #define malloctype DRM(M_DRM) -/* The macros confliced in the MALLOC_DEFINE */ +/* The macros conflicted in the MALLOC_DEFINE */ MALLOC_DEFINE(malloctype, "drm", "DRM Data Structures"); @@ -81,6 +81,10 @@ void DRM(mem_init)(void) { drm_mem_stats_t *mem; +#ifdef __NetBSD__ + malloc_type_attach(DRM(M_DRM)); +#endif + DRM_SPININIT(DRM(mem_lock), "drm memory"); for (mem = DRM(mem_stats); mem->name; ++mem) { @@ -164,11 +168,7 @@ void *DRM(alloc)(size_t size, int area) return NULL; } -#ifdef __FreeBSD__ if (!(pt = malloc(size, DRM(M_DRM), M_NOWAIT))) { -#elif defined(__NetBSD__) - if (!(pt = malloc(size, M_DEVBUF, M_NOWAIT))) { -#endif DRM_SPINLOCK(&DRM(mem_lock)); ++DRM(mem_stats)[area].fail_count; DRM_SPINUNLOCK(&DRM(mem_lock)); @@ -218,13 +218,10 @@ void DRM(free)(void *pt, size_t size, int area) int alloc_count; int free_count; - if (!pt) DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n"); + if (!pt) + DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n"); else -#ifdef __FreeBSD__ - free(pt, DRM(M_DRM)); -#elif defined(__NetBSD__) - free(pt, M_DEVBUF); -#endif + free(pt, DRM(M_DRM)); DRM_SPINLOCK(&DRM(mem_lock)); DRM(mem_stats)[area].bytes_freed += size; free_count = ++DRM(mem_stats)[area].free_count; diff --git a/bsd-core/drm_os_netbsd.h b/bsd-core/drm_os_netbsd.h index 4f3b839d..0be9a87a 100644 --- a/bsd-core/drm_os_netbsd.h +++ b/bsd-core/drm_os_netbsd.h @@ -42,9 +42,7 @@ #include <sys/agpio.h> #endif -typedef drm_device_t *device_t; - -extern struct cfdriver DRM(cd); +#include <opt_drm.h> #if DRM_DEBUG #undef DRM_DEBUG_CODE @@ -52,6 +50,14 @@ extern struct cfdriver DRM(cd); #endif #undef DRM_DEBUG +#if DRM_LINUX +#undef DRM_LINUX /* FIXME: Linux compat has not been ported yet */ +#endif + +typedef drm_device_t *device_t; + +extern struct cfdriver DRM(cd); + #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) @@ -75,9 +81,15 @@ extern struct cfdriver DRM(cd); #define DRM_TASKQUEUE_ARGS void *dev, int pending #define DRM_IRQ_ARGS void *arg #define DRM_DEVICE drm_device_t *dev = device_lookup(&DRM(cd), minor(kdev)) +/* XXX Not sure if this is the 'right' version.. */ +#if __NetBSD_Version__ >= 106140000 +MALLOC_DECLARE(DRM(M_DRM)); +#else +/* XXX Make sure this works */ +extern const int DRM(M_DRM) = M_DEVBUF; +#endif /* __NetBSD_Version__ */ #define DRM_MALLOC(size) malloc( size, DRM(M_DRM), M_NOWAIT ) -/* XXX Get netbsd to add a M_DRM malloc type. */ -#define DRM_FREE(pt) free( pt, M_AGP ) +#define DRM_FREE(pt) free( pt, DRM(M_DRM) ) #define DRM_VTOPHYS(addr) vtophys(addr) #define DRM_READ8(map, offset) bus_space_read_1( (map)->iot, (map)->ioh, (offset) ) @@ -265,7 +277,7 @@ do { \ #define DRM_DEBUG(fmt, arg...) \ do { \ if (DRM(flags) & DRM_FLAG_DEBUG) \ - printf("[" DRM_NAME ":%s] " fmt , __FUNCTION__,## arg); \ + printf("[" DRM_NAME ":%s] " fmt , __FUNCTION__ ,## arg); \ } while (0) #else #define DRM_DEBUG(fmt, arg...) do { } while (0) diff --git a/bsd/drm_drv.h b/bsd/drm_drv.h index cec29bd0..3cab7316 100644 --- a/bsd/drm_drv.h +++ b/bsd/drm_drv.h @@ -125,13 +125,8 @@ #define DRIVER_NUM_CARDS 1 #endif -#ifdef __FreeBSD__ static int DRM(init)(device_t nbdev); static void DRM(cleanup)(device_t nbdev); -#elif defined(__NetBSD__) -static int DRM(init)(drm_device_t *); -static void DRM(cleanup)(drm_device_t *); -#endif #ifdef __FreeBSD__ #define DRIVER_SOFTC(unit) \ @@ -337,13 +332,7 @@ static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd) case LKM_E_LOAD: if (lkmexists(lkmtp)) return EEXIST; -
#if defined(__NetBSD__) && (__NetBSD_Version__ > 106080000) - error = devsw_attach(args->lkm_devname, - args->lkm_bdev, &args->lkm_bdevmaj, - args->lkm_cdev, &args->lkm_cdevmaj); - if(error != 0) - return error; -#endif + if(DRM(modprobe)()) return 0; @@ -352,10 +341,6 @@ static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd) case LKM_E_UNLOAD: if (DRM(refcnt) > 0) return (EBUSY); - -#if defined(__NetBSD__) && (__NetBSD_Version__ > 106080000) - devsw_detach(args->lkm_bdev, args->lkm_cdev); -#endif break; case LKM_E_STAT: break; @@ -364,6 +349,7 @@ static int DRM(lkmhandle)(struct lkm_table *lkmtp, int cmd) error = EIO; break; } + return error; } @@ -372,6 +358,7 @@ int DRM(modprobe)() { int error = 0; if((error = pci_find_device(&pa, DRM(probe))) != 0) DRM(attach)(&pa, 0); + return error; } @@ -381,16 +368,21 @@ int DRM(probe)(struct pci_attach_args *pa) desc = DRM(find_description)(PCI_VENDOR(pa->pa_id), PCI_PRODUCT(pa->pa_id)); if (desc != NULL) { - return 10; + return 1; } return 0; } void DRM(attach)(struct pci_attach_args *pa, dev_t kdev) - { +{ int i; - DRM_DEVICE; + drm_device_t *dev; + + config_makeroom(kdev, &DRM(cd)); + DRM(cd).cd_devs[(kdev)] = DRM(alloc)(sizeof(drm_device_t), + DRM_MEM_DRIVER); + dev = DRIVER_SOFTC(kdev); memset(dev, 0, sizeof(drm_device_t)); memcpy(&dev->pa, pa, sizeof(dev->pa)); @@ -728,15 +720,13 @@ static int DRM(takedown)( drm_device_t *dev ) * linux/init/main.c (this is not currently supported). * bsd: drm_init is called via the attach function per device. */ -#ifdef __FreeBSD__ static int DRM(init)( device_t nbdev ) -#elif defined(__NetBSD__) -static int DRM(init)( drm_device_t *dev ) -#endif { int unit; #ifdef __FreeBSD__ drm_device_t *dev; +#elif defined(__NetBSD__) + drm_device_t *dev = nbdev; #endif #if __HAVE_CTX_BITMAP int retcode; @@ -832,21 +822,16 @@ static int DRM(init)( drm_device_t *dev ) * bsd: drm_cleanup is called per device at module unload time. * FIXME: NetBSD */ -#ifdef __FreeBSD__ static void DRM(cleanup)(device_t nbdev) -#elif defined(__NetBSD__) -static void DRM(cleanup)(drm_device_t *dev) -#endif { -#ifdef __FreeBSD__ drm_device_t *dev; -#endif -#if __REALLY_HAVE_MTRR #ifdef __NetBSD__ +#if __REALLY_HAVE_MTRR struct mtrr mtrrmap; int one = 1; -#endif /* __NetBSD__ */ #endif /* __REALLY_HAVE_MTRR */ + dev = nbdev; +#endif /* __NetBSD__ */ DRM_DEBUG( "\n" ); diff --git a/bsd/drm_fops.h b/bsd/drm_fops.h index c4152ac3..d2faaa43 100644 --- a/bsd/drm_fops.h +++ b/bsd/drm_fops.h @@ -182,8 +182,8 @@ int DRM(write_string)(drm_device_t *dev, const char *s) selwakeup(&dev->buf_sel); } - DRM_DEBUG("dev->buf_sigio=%p\n", dev->buf_sigio); #ifdef __FreeBSD__ + DRM_DEBUG("dev->buf_sigio=%p\n", dev->buf_sigio); if (dev->buf_sigio) { DRM_DEBUG("dev->buf_sigio->sio_pgid=%d\n", dev->buf_sigio->sio_pgid); #if __FreeBSD_version >= 500000 diff --git a/bsd/drm_memory.h b/bsd/drm_memory.h index a0b0deb6..aa81363f 100644 --- a/bsd/drm_memory.h +++ b/bsd/drm_memory.h @@ -31,9 +31,9 @@ #include "drmP.h" -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__NetBSD__) #define malloctype DRM(M_DRM) -/* The macros confliced in the MALLOC_DEFINE */ +/* The macros conflicted in the MALLOC_DEFINE */ MALLOC_DEFINE(malloctype, "drm", "DRM Data Structures"); @@ -81,6 +81,10 @@ void DRM(mem_init)(void) { drm_mem_stats_t *mem; +#ifdef __NetBSD__ + malloc_type_attach(DRM(M_DRM)); +#endif + DRM_SPININIT(DRM(mem_lock), "drm memory"); for (mem = DRM(mem_stats); mem->name; ++mem) { @@ -164,11 +168,7 @@ void *DRM(alloc)(size_t size, int area) return NULL; } -#ifdef __FreeBSD__ if (!(pt = malloc(size, DRM(M_DRM), M_NOWAIT))) { -#elif defined(__NetBSD__) - if (!(pt = malloc(size, M_DEVBUF, M_NOWAIT))) { -#endif DRM_SPINLOCK(&DRM(mem_lock)); ++DRM(mem_stats)[area].fail_count; DRM_SPINUNLOCK(&DRM(mem_lock)); @@ -218,13 +218,10 @@ void DRM(free)(void *pt, size_t size, int area) int alloc_count; int free_count; - if (!pt) DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n"); + if (!pt) + DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n"); else -#ifdef __FreeBSD__ - free(pt, DRM(M_DRM)); -#elif defined(__NetBSD__) - free(pt, M_DEVBUF); -#endif + free(pt, DRM(M_DRM)); DRM_SPINLOCK(&DRM(mem_lock)); DRM(mem_stats)[area].bytes_freed += size; free_count = ++DRM(mem_stats)[area].free_count; diff --git a/bsd/drm_os_netbsd.h b/bsd/drm_os_netbsd.h index 4f3b839d..0be9a87a 100644 --- a/bsd/drm_os_netbsd.h +++ b/bsd/drm_os_netbsd.h @@ -42,9 +42,7 @@ #include <sys/agpio.h> #endif -typedef drm_device_t *device_t; - -extern struct cfdriver DRM(cd); +#include <opt_drm.h> #if DRM_DEBUG #undef DRM_DEBUG_CODE @@ -52,6 +50,14 @@ extern struct cfdriver DRM(cd); #endif #undef DRM_DEBUG +#if DRM_LINUX +#undef DRM_LINUX /* FIXME: Linux compat has not been ported yet */ +#endif + +typedef drm_device_t *device_t; + +extern struct cfdriver DRM(cd); + #define DRM_TIME_SLICE (hz/20) /* Time slice for GLXContexts */ #define DRM_DEV_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) @@ -75,9 +81,15 @@ extern struct cfdriver DRM(cd); #define DRM_TASKQUEUE_ARGS void *dev, int pending #define DRM_IRQ_ARGS void *arg #define DRM_DEVICE drm_device_t *dev = device_lookup(&DRM(cd), minor(kdev)) +/* XXX Not sure if this is the 'right' version.. */ +#if __NetBSD_Version__ >= 106140000 +MALLOC_DECLARE(DRM(M_DRM)); +#else +/* XXX Make sure this works */ +extern const int DRM(M_DRM) = M_DEVBUF; +#endif /* __NetBSD_Version__ */ #define DRM_MALLOC(size) malloc( size, DRM(M_DRM), M_NOWAIT ) -/* XXX Get netbsd to add a M_DRM malloc type. */ -#define DRM_FREE(pt) free( pt, M_AGP ) +#define DRM_FREE(pt) free( pt, DRM(M_DRM) ) #define DRM_VTOPHYS(addr) vtophys(addr) #define DRM_READ8(map, offset) bus_space_read_1( (map)->iot, (map)->ioh, (offset) ) @@ -265,7 +277,7 @@ do { \ #define DRM_DEBUG(fmt, arg...) \ do { \ if (DRM(flags) & DRM_FLAG_DEBUG) \ - printf("[" DRM_NAME ":%s] " fmt , __FUNCTION__,## arg); \ + printf("[" DRM_NAME ":%s] " fmt , __FUNCTION__ ,## arg); \ } while (0) #else #define DRM_DEBUG(fmt, arg...) do { } while (0) |