2 *Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
26 * Rickard E. (Rik) Faith <faith@valinux.com>
27 * Gareth Hughes <gareth@valinux.com>
29 * $DragonFly: src/sys/dev/drm/drm_memory.c,v 1.1 2008/04/05 18:12:29 hasso Exp $
32 /** @file drm_memory.c
33 * Wrappers for kernel memory allocation routines, and MTRR management support.
35 * This file previously implemented a memory consumption tracking system using
36 * the "area" argument for various different types of allocations, but that
37 * has been stripped out for now.
42 MALLOC_DEFINE(M_DRM
, "drm", "DRM Data Structures");
44 void drm_mem_init(void)
46 #if defined(__NetBSD__) || defined(__OpenBSD__)
47 malloc_type_attach(M_DRM
);
51 void drm_mem_uninit(void)
55 void *drm_alloc(size_t size
, int area
)
57 return malloc(size
, M_DRM
, M_NOWAIT
);
60 void *drm_calloc(size_t nmemb
, size_t size
, int area
)
62 return malloc(size
* nmemb
, M_DRM
, M_NOWAIT
| M_ZERO
);
65 void *drm_realloc(void *oldpt
, size_t oldsize
, size_t size
, int area
)
69 pt
= malloc(size
, M_DRM
, M_NOWAIT
);
72 if (oldpt
&& oldsize
) {
73 memcpy(pt
, oldpt
, oldsize
);
79 void drm_free(void *pt
, size_t size
, int area
)
84 void *drm_ioremap(drm_device_t
*dev
, drm_local_map_t
*map
)
86 #if defined(__FreeBSD__) || defined(__DragonFly__)
87 return pmap_mapdev(map
->offset
, map
->size
);
88 #elif defined(__NetBSD__) || defined(__OpenBSD__)
89 map
->bst
= dev
->pa
.pa_memt
;
90 if (bus_space_map(map
->bst
, map
->offset
, map
->size
,
91 BUS_SPACE_MAP_LINEAR
, &map
->bsh
))
93 return bus_space_vaddr(map
->bst
, map
->bsh
);
97 void drm_ioremapfree(drm_local_map_t
*map
)
99 #if defined(__FreeBSD__) || defined(__DragonFly__)
100 pmap_unmapdev((vm_offset_t
) map
->handle
, map
->size
);
101 #elif defined(__NetBSD__) || defined(__OpenBSD__)
102 bus_space_unmap(map
->bst
, map
->bsh
, map
->size
);
106 #if defined(__FreeBSD__) || defined(__DragonFly__)
108 drm_mtrr_add(unsigned long offset
, size_t size
, int flags
)
111 struct mem_range_desc mrdesc
;
113 mrdesc
.mr_base
= offset
;
114 mrdesc
.mr_len
= size
;
115 mrdesc
.mr_flags
= flags
;
116 act
= MEMRANGE_SET_UPDATE
;
117 strlcpy(mrdesc
.mr_owner
, "drm", sizeof(mrdesc
.mr_owner
));
118 return mem_range_attr_set(&mrdesc
, &act
);
122 drm_mtrr_del(int __unused handle
, unsigned long offset
, size_t size
, int flags
)
125 struct mem_range_desc mrdesc
;
127 mrdesc
.mr_base
= offset
;
128 mrdesc
.mr_len
= size
;
129 mrdesc
.mr_flags
= flags
;
130 act
= MEMRANGE_SET_REMOVE
;
131 strlcpy(mrdesc
.mr_owner
, "drm", sizeof(mrdesc
.mr_owner
));
132 return mem_range_attr_set(&mrdesc
, &act
);
134 #elif defined(__NetBSD__) || defined(__OpenBSD__)
136 drm_mtrr_add(unsigned long offset
, size_t size
, int flags
)
141 mtrrmap
.base
= offset
;
143 mtrrmap
.type
= flags
;
144 mtrrmap
.flags
= MTRR_VALID
;
145 return mtrr_set(&mtrrmap
, &one
, NULL
, MTRR_GETSET_KERNEL
);
149 drm_mtrr_del(unsigned long offset
, size_t size
, int flags
)
154 mtrrmap
.base
= offset
;
156 mtrrmap
.type
= flags
;
158 return mtrr_set(&mtrrmap
, &one
, NULL
, MTRR_GETSET_KERNEL
);