]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/drm/drm_memory.h
This commit was generated by cvs2svn to compensate for changes in r136632,
[FreeBSD/FreeBSD.git] / sys / dev / drm / drm_memory.h
1 /* drm_memory.h -- Memory management wrappers for DRM -*- linux-c -*-
2  * Created: Thu Feb  4 14:00:34 1999 by faith@valinux.com
3  *
4  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6  * All Rights Reserved.
7  *
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:
14  *
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
17  * Software.
18  *
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.
26  *
27  * Authors:
28  *    Rickard E. (Rik) Faith <faith@valinux.com>
29  *    Gareth Hughes <gareth@valinux.com>
30  *
31  * $FreeBSD$
32  */
33
34 #include "dev/drm/drmP.h"
35
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");
40 #undef malloctype
41 #endif
42
43 #ifdef DEBUG_MEMORY
44 #include "drm_memory_debug.h"
45 #else
46 void DRM(mem_init)(void)
47 {
48 #ifdef __NetBSD__
49         malloc_type_attach(DRM(M_DRM));
50 #endif
51 }
52
53 void DRM(mem_uninit)(void)
54 {
55 }
56
57 void *DRM(alloc)(size_t size, int area)
58 {
59         return malloc(size, DRM(M_DRM), M_NOWAIT);
60 }
61
62 void *DRM(calloc)(size_t nmemb, size_t size, int area)
63 {
64         return malloc(size * nmemb, DRM(M_DRM), M_NOWAIT | M_ZERO);
65 }
66
67 void *DRM(realloc)(void *oldpt, size_t oldsize, size_t size, int area)
68 {
69         void *pt;
70
71         pt = malloc(size, DRM(M_DRM), M_NOWAIT);
72         if (pt == NULL)
73                 return NULL;
74         if (oldpt && oldsize) {
75                 memcpy(pt, oldpt, oldsize);
76                 free(oldpt, DRM(M_DRM));
77         }
78         return pt;
79 }
80
81 void DRM(free)(void *pt, size_t size, int area)
82 {
83         free(pt, DRM(M_DRM));
84 }
85
86 void *DRM(ioremap)( drm_device_t *dev, drm_local_map_t *map )
87 {
88 #ifdef __FreeBSD__
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))
94                 return NULL;
95         return bus_space_vaddr(map->iot, map->ioh);
96 #endif
97 }
98
99 void DRM(ioremapfree)(drm_local_map_t *map)
100 {
101 #ifdef __FreeBSD__
102         pmap_unmapdev((vm_offset_t) map->handle, map->size);
103 #elif defined(__NetBSD__)
104         bus_space_unmap(map->iot, map->ioh, map->size);
105 #endif
106 }
107
108 #if __REALLY_HAVE_AGP
109 agp_memory *DRM(alloc_agp)(int pages, u32 type)
110 {
111         return DRM(agp_allocate_memory)(pages, type);
112 }
113
114 int DRM(free_agp)(agp_memory *handle, int pages)
115 {
116         return DRM(agp_free_memory)(handle);
117 }
118
119 int DRM(bind_agp)(agp_memory *handle, unsigned int start)
120 {
121         return DRM(agp_bind_memory)(handle, start);
122 }
123
124 int DRM(unbind_agp)(agp_memory *handle)
125 {
126         return DRM(agp_unbind_memory)(handle);
127 }
128 #endif /* __REALLY_HAVE_AGP */
129
130 #ifdef __FreeBSD__
131 int
132 DRM(mtrr_add)(unsigned long offset, size_t size, int flags)
133 {
134         int act;
135         struct mem_range_desc mrdesc;
136
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);
143 }
144
145 int
146 DRM(mtrr_del)(unsigned long offset, size_t size, int flags)
147 {
148         int act;
149         struct mem_range_desc mrdesc;
150
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);
157 }
158 #elif defined(__NetBSD__)
159 int
160 DRM(mtrr_add)(unsigned long offset, size_t size, int flags)
161 {
162         struct mtrr mtrrmap;
163         int one = 1;
164
165         mtrrmap.base = offset;
166         mtrrmap.len = size;
167         mtrrmap.type = flags;
168         mtrrmap.flags = MTRR_VALID;
169         return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
170 }
171
172 int
173 DRM(mtrr_del)(unsigned long offset, size_t size, int flags)
174 {
175         struct mtrr mtrrmap;
176         int one = 1;
177
178         mtrrmap.base = offset;
179         mtrrmap.len = size;
180         mtrrmap.type = flags;
181         mtrrmap.flags = 0;
182         return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
183 }
184 #endif
185
186 #endif /* DEBUG_MEMORY */