1 /* drm_memory.h -- Memory management wrappers for DRM -*- linux-c -*-
2 * Created: Thu Feb 4 14:00:34 1999 by faith@valinux.com
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
28 * Rickard E. (Rik) Faith <faith@valinux.com>
29 * Gareth Hughes <gareth@valinux.com>
34 #include "dev/drm/drmP.h"
36 #if defined(__FreeBSD__) || defined(__NetBSD__)
37 #define malloctype DRM(M_DRM)
38 /* The macros conflicted in the MALLOC_DEFINE */
39 MALLOC_DEFINE(malloctype, "drm", "DRM Data Structures");
44 #include "drm_memory_debug.h"
46 void DRM(mem_init)(void)
49 malloc_type_attach(DRM(M_DRM));
53 void DRM(mem_uninit)(void)
57 void *DRM(alloc)(size_t size, int area)
59 return malloc(size, DRM(M_DRM), M_NOWAIT);
62 void *DRM(calloc)(size_t nmemb, size_t size, int area)
64 return malloc(size * nmemb, DRM(M_DRM), M_NOWAIT | M_ZERO);
67 void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
71 pt = malloc(size, DRM(M_DRM), M_NOWAIT);
74 if (oldpt && oldsize) {
75 memcpy(pt, oldpt, oldsize);
76 free(oldpt, DRM(M_DRM));
81 void DRM(free)(void *pt, size_t size, int area)
86 void *DRM(ioremap)( drm_device_t *dev, drm_local_map_t *map )
89 return pmap_mapdev(map->offset, map->size);
90 #elif defined(__NetBSD__)
91 map->iot = dev->pa.pa_memt;
92 if (bus_space_map(map->iot, map->offset, map->size,
93 BUS_SPACE_MAP_LINEAR, &map->ioh))
95 return bus_space_vaddr(map->iot, map->ioh);
99 void DRM(ioremapfree)(drm_local_map_t *map)
102 pmap_unmapdev((vm_offset_t) map->handle, map->size);
103 #elif defined(__NetBSD__)
104 bus_space_unmap(map->iot, map->ioh, map->size);
108 #if __REALLY_HAVE_AGP
109 agp_memory *DRM(alloc_agp)(int pages, u32 type)
111 return DRM(agp_allocate_memory)(pages, type);
114 int DRM(free_agp)(agp_memory *handle, int pages)
116 return DRM(agp_free_memory)(handle);
119 int DRM(bind_agp)(agp_memory *handle, unsigned int start)
121 return DRM(agp_bind_memory)(handle, start);
124 int DRM(unbind_agp)(agp_memory *handle)
126 return DRM(agp_unbind_memory)(handle);
128 #endif /* __REALLY_HAVE_AGP */
132 DRM(mtrr_add)(unsigned long offset, size_t size, int flags)
135 struct mem_range_desc mrdesc;
137 mrdesc.mr_base = offset;
138 mrdesc.mr_len = size;
139 mrdesc.mr_flags = flags;
140 act = MEMRANGE_SET_UPDATE;
141 bcopy(DRIVER_NAME, &mrdesc.mr_owner, strlen(DRIVER_NAME));
142 return mem_range_attr_set(&mrdesc, &act);
146 DRM(mtrr_del)(unsigned long offset, size_t size, int flags)
149 struct mem_range_desc mrdesc;
151 mrdesc.mr_base = offset;
152 mrdesc.mr_len = size;
153 mrdesc.mr_flags = flags;
154 act = MEMRANGE_SET_REMOVE;
155 bcopy(DRIVER_NAME, &mrdesc.mr_owner, strlen(DRIVER_NAME));
156 return mem_range_attr_set(&mrdesc, &act);
158 #elif defined(__NetBSD__)
160 DRM(mtrr_add)(unsigned long offset, size_t size, int flags)
165 mtrrmap.base = offset;
167 mtrrmap.type = flags;
168 mtrrmap.flags = MTRR_VALID;
169 return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
173 DRM(mtrr_del)(unsigned long offset, size_t size, int flags)
178 mtrrmap.base = offset;
180 mtrrmap.type = flags;
182 return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
186 #endif /* DEBUG_MEMORY */