summaryrefslogtreecommitdiff
path: root/bsd/drm_memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'bsd/drm_memory.h')
-rw-r--r--bsd/drm_memory.h161
1 files changed, 59 insertions, 102 deletions
diff --git a/bsd/drm_memory.h b/bsd/drm_memory.h
index 97f2bb81..f7dc547a 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,8 @@ void DRM(mem_init)(void)
DRM(ram_used) = 0;
}
+#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 +133,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 +149,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,70 +204,23 @@ 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)
-{
- unsigned long bytes = PAGE_SIZE << order;
- int alloc_count;
- int free_count;
-
- if (!address) {
- DRM_MEM_ERROR(area, "Attempt to free address 0\n");
- } else {
- contigfree((void *) address, bytes, DRM(M_DRM));
- }
-
- 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);
- }
-}
-
void *DRM(ioremap)(unsigned long offset, unsigned long size)
{
void *pt;
@@ -278,18 +232,20 @@ void *DRM(ioremap)(unsigned long offset, unsigned long size)
}
if (!(pt = pmap_mapdev(offset, size))) {
- DRM_OS_SPINLOCK(&DRM(mem_lock));
+ 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;
}
+/* unused so far */
+#if 0
void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size)
{
void *pt;
@@ -302,17 +258,18 @@ void *DRM(ioremap_nocache)(unsigned long offset, unsigned long size)
/* FIXME FOR BSD */
if (!(pt = ioremap_nocache(offset, size))) {
- DRM_OS_SPINLOCK(&DRM(mem_lock));
+ 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)
{
@@ -325,11 +282,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",
@@ -348,16 +305,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;
}
@@ -369,16 +326,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",
@@ -386,13 +343,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)
@@ -401,22 +358,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)
@@ -424,7 +381,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)
@@ -433,25 +390,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