diff options
Diffstat (limited to 'bsd/drm_memory.h')
-rw-r--r-- | bsd/drm_memory.h | 172 |
1 files changed, 79 insertions, 93 deletions
diff --git a/bsd/drm_memory.h b/bsd/drm_memory.h index 605b42ae..a4e74d9f 100644 --- a/bsd/drm_memory.h +++ b/bsd/drm_memory.h @@ -29,20 +29,16 @@ * Gareth Hughes <gareth@valinux.com> */ -#define __NO_VERSION__ #include "drmP.h" -#include <vm/vm.h> -#include <vm/pmap.h> -#if __REALLY_HAVE_AGP -#include <sys/agpio.h> -#endif +#ifdef __FreeBSD__ #define malloctype DRM(M_DRM) /* The macros confliced in the MALLOC_DEFINE */ MALLOC_DEFINE(malloctype, "drm", "DRM Data Structures"); #undef malloctype +#endif typedef struct drm_mem_stats { const char *name; @@ -53,7 +49,7 @@ typedef struct drm_mem_stats { unsigned long bytes_freed; } drm_mem_stats_t; -static DRM_OS_SPINTYPE DRM(mem_lock); +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)[] = { @@ -85,7 +81,7 @@ void DRM(mem_init)(void) { drm_mem_stats_t *mem; - DRM_OS_SPININIT(DRM(mem_lock), "drm memory"); + DRM_SPININIT(DRM(mem_lock), "drm memory"); for (mem = DRM(mem_stats); mem->name; ++mem) { mem->succeed_count = 0; @@ -99,8 +95,13 @@ void DRM(mem_init)(void) DRM(ram_used) = 0; } -/* drm_mem_info is called whenever a process reads /dev/drm/mem. */ +void DRM(mem_uninit)(void) +{ + DRM_SPINUNINIT(DRM(mem_lock)); +} +#ifdef __FreeBSD__ +/* drm_mem_info is called whenever a process reads /dev/drm/mem. */ static int DRM(_mem_info) DRM_SYSCTL_HANDLER_ARGS { drm_mem_stats_t *pt; @@ -137,11 +138,12 @@ int DRM(mem_info) DRM_SYSCTL_HANDLER_ARGS { int ret; - DRM_OS_SPINLOCK(&DRM(mem_lock)); + DRM_SPINLOCK(&DRM(mem_lock)); ret = DRM(_mem_info)(oidp, arg1, arg2, req); - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); + DRM_SPINUNLOCK(&DRM(mem_lock)); return ret; } +#endif void *DRM(alloc)(size_t size, int area) { @@ -152,16 +154,20 @@ void *DRM(alloc)(size_t size, int area) return NULL; } +#ifdef __FreeBSD__ if (!(pt = malloc(size, DRM(M_DRM), M_NOWAIT))) { - DRM_OS_SPINLOCK(&DRM(mem_lock)); +#elif defined(__NetBSD__) + if (!(pt = malloc(size, M_DEVBUF, M_NOWAIT))) { +#endif + DRM_SPINLOCK(&DRM(mem_lock)); ++DRM(mem_stats)[area].fail_count; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); + DRM_SPINUNLOCK(&DRM(mem_lock)); return NULL; } - DRM_OS_SPINLOCK(&DRM(mem_lock)); + DRM_SPINLOCK(&DRM(mem_lock)); ++DRM(mem_stats)[area].succeed_count; DRM(mem_stats)[area].bytes_allocated += size; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); + DRM_SPINUNLOCK(&DRM(mem_lock)); return pt; } @@ -203,71 +209,49 @@ void DRM(free)(void *pt, size_t size, int area) int free_count; if (!pt) DRM_MEM_ERROR(area, "Attempt to free NULL pointer\n"); - else free(pt, DRM(M_DRM)); - DRM_OS_SPINLOCK(&DRM(mem_lock)); + else +#ifdef __FreeBSD__ + free(pt, DRM(M_DRM)); +#elif defined(__NetBSD__) + free(pt, M_DEVBUF); +#endif + 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_OS_SPINUNLOCK(&DRM(mem_lock)); + 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); } } -unsigned long DRM(alloc_pages)(int order, int area) -{ - vm_offset_t address; - unsigned long bytes = PAGE_SIZE << order; - - - address = (vm_offset_t) contigmalloc(bytes, DRM(M_DRM), M_WAITOK, 0, ~0, 1, 0); - if (!address) { - DRM_OS_SPINLOCK(&DRM(mem_lock)); - ++DRM(mem_stats)[area].fail_count; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); - return 0; - } - DRM_OS_SPINLOCK(&DRM(mem_lock)); - ++DRM(mem_stats)[area].succeed_count; - DRM(mem_stats)[area].bytes_allocated += bytes; - DRM(ram_used) += bytes; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); - - - /* Zero outside the lock */ - memset((void *)address, 0, bytes); - - - return address; -} - -void DRM(free_pages)(unsigned long address, int order, int area) +void *DRM(ioremap)(unsigned long offset, unsigned long size) { - unsigned long bytes = PAGE_SIZE << order; - int alloc_count; - int free_count; + void *pt; - if (!address) { - DRM_MEM_ERROR(area, "Attempt to free address 0\n"); - } else { - contigfree((void *) address, bytes, DRM(M_DRM)); + if (!size) { + DRM_MEM_ERROR(DRM_MEM_MAPPINGS, + "Mapping 0 bytes at 0x%08lx\n", offset); + return NULL; } - DRM_OS_SPINLOCK(&DRM(mem_lock)); - free_count = ++DRM(mem_stats)[area].free_count; - alloc_count = DRM(mem_stats)[area].succeed_count; - DRM(mem_stats)[area].bytes_freed += bytes; - DRM(ram_used) -= bytes; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); - if (free_count > alloc_count) { - DRM_MEM_ERROR(area, - "Excess frees: %d frees, %d allocs\n", - free_count, alloc_count); + if (!(pt = pmap_mapdev(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; } -void *DRM(ioremap)(unsigned long offset, unsigned long size) +/* unused so far */ +#if 0 +void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size) { void *pt; @@ -277,18 +261,20 @@ void *DRM(ioremap)(unsigned long offset, unsigned long size) return NULL; } - if (!(pt = pmap_mapdev(offset, size))) { - DRM_OS_SPINLOCK(&DRM(mem_lock)); + /* FIXME FOR BSD */ + if (!(pt = ioremap_nocache(offset, size))) { + DRM_SPINLOCK(&DRM(mem_lock)); ++DRM(mem_stats)[DRM_MEM_MAPPINGS].fail_count; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); + DRM_SPINUNLOCK(&DRM(mem_lock)); return NULL; } - DRM_OS_SPINLOCK(&DRM(mem_lock)); + DRM_SPINLOCK(&DRM(mem_lock)); ++DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count; DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_allocated += size; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); + DRM_SPINUNLOCK(&DRM(mem_lock)); return pt; } +#endif void DRM(ioremapfree)(void *pt, unsigned long size) { @@ -301,11 +287,11 @@ void DRM(ioremapfree)(void *pt, unsigned long size) else pmap_unmapdev((vm_offset_t) pt, size); - DRM_OS_SPINLOCK(&DRM(mem_lock)); + DRM_SPINLOCK(&DRM(mem_lock)); DRM(mem_stats)[DRM_MEM_MAPPINGS].bytes_freed += size; free_count = ++DRM(mem_stats)[DRM_MEM_MAPPINGS].free_count; alloc_count = DRM(mem_stats)[DRM_MEM_MAPPINGS].succeed_count; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); + DRM_SPINUNLOCK(&DRM(mem_lock)); if (free_count > alloc_count) { DRM_MEM_ERROR(DRM_MEM_MAPPINGS, "Excess frees: %d frees, %d allocs\n", @@ -324,16 +310,16 @@ agp_memory *DRM(alloc_agp)(int pages, u32 type) } if ((handle = DRM(agp_allocate_memory)(pages, type))) { - DRM_OS_SPINLOCK(&DRM(mem_lock)); + 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_OS_SPINUNLOCK(&DRM(mem_lock)); + DRM_SPINUNLOCK(&DRM(mem_lock)); return handle; } - DRM_OS_SPINLOCK(&DRM(mem_lock)); + DRM_SPINLOCK(&DRM(mem_lock)); ++DRM(mem_stats)[DRM_MEM_TOTALAGP].fail_count; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); + DRM_SPINUNLOCK(&DRM(mem_lock)); return NULL; } @@ -345,16 +331,16 @@ int DRM(free_agp)(agp_memory *handle, int pages) if (!handle) { DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Attempt to free NULL AGP handle\n"); - DRM_OS_RETURN(EINVAL); + return DRM_ERR(EINVAL); } if (DRM(agp_free_memory)(handle)) { - DRM_OS_SPINLOCK(&DRM(mem_lock)); + 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_OS_SPINUNLOCK(&DRM(mem_lock)); + DRM_SPINUNLOCK(&DRM(mem_lock)); if (free_count > alloc_count) { DRM_MEM_ERROR(DRM_MEM_TOTALAGP, "Excess frees: %d frees, %d allocs\n", @@ -362,13 +348,13 @@ int DRM(free_agp)(agp_memory *handle, int pages) } return 0; } - DRM_OS_RETURN(EINVAL); + return DRM_ERR(EINVAL); } int DRM(bind_agp)(agp_memory *handle, unsigned int start) { int retcode; - device_t dev = agp_find_device(); + device_t dev = DRM_AGP_FIND_DEVICE(); struct agp_memory_info info; if (!dev) @@ -377,22 +363,22 @@ int DRM(bind_agp)(agp_memory *handle, unsigned int start) if (!handle) { DRM_MEM_ERROR(DRM_MEM_BOUNDAGP, "Attempt to bind NULL AGP handle\n"); - DRM_OS_RETURN(EINVAL); + return DRM_ERR(EINVAL); } if (!(retcode = DRM(agp_bind_memory)(handle, start))) { - DRM_OS_SPINLOCK(&DRM(mem_lock)); + 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_OS_SPINUNLOCK(&DRM(mem_lock)); - DRM_OS_RETURN(0); + DRM_SPINUNLOCK(&DRM(mem_lock)); + return DRM_ERR(0); } - DRM_OS_SPINLOCK(&DRM(mem_lock)); + DRM_SPINLOCK(&DRM(mem_lock)); ++DRM(mem_stats)[DRM_MEM_BOUNDAGP].fail_count; - DRM_OS_SPINUNLOCK(&DRM(mem_lock)); - DRM_OS_RETURN(retcode); + DRM_SPINUNLOCK(&DRM(mem_lock)); + return DRM_ERR(retcode); } int DRM(unbind_agp)(agp_memory *handle) @@ -400,7 +386,7 @@ int DRM(unbind_agp)(agp_memory *handle) int alloc_count; int free_count; int retcode = EINVAL; - device_t dev = agp_find_device(); + device_t dev = DRM_AGP_FIND_DEVICE(); struct agp_memory_info info; if (!dev) @@ -409,25 +395,25 @@ int DRM(unbind_agp)(agp_memory *handle) if (!handle) { DRM_MEM_ERROR(DRM_MEM_BOUNDAGP, "Attempt to unbind NULL AGP handle\n"); - DRM_OS_RETURN(retcode); + return DRM_ERR(retcode); } agp_memory_info(dev, handle, &info); if ((retcode = DRM(agp_unbind_memory)(handle))) - DRM_OS_RETURN(retcode); + return DRM_ERR(retcode); - DRM_OS_SPINLOCK(&DRM(mem_lock)); + 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_OS_SPINUNLOCK(&DRM(mem_lock)); + 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); } - DRM_OS_RETURN(retcode); + return DRM_ERR(retcode); } #endif |