]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/drm/drm_memory.c
This commit was generated by cvs2svn to compensate for changes in r152058,
[FreeBSD/FreeBSD.git] / sys / dev / drm / drm_memory.c
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 /*-
5  *Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
6  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
7  * All Rights Reserved.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and associated documentation files (the "Software"),
11  * to deal in the Software without restriction, including without limitation
12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  * and/or sell copies of the Software, and to permit persons to whom the
14  * Software is furnished to do so, subject to the following conditions:
15  *
16  * The above copyright notice and this permission notice (including the next
17  * paragraph) shall be included in all copies or substantial portions of the
18  * Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
23  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  *
28  * Authors:
29  *    Rickard E. (Rik) Faith <faith@valinux.com>
30  *    Gareth Hughes <gareth@valinux.com>
31  *
32  * $FreeBSD$
33  */
34
35 #include "dev/drm/drmP.h"
36
37 MALLOC_DEFINE(M_DRM, "drm", "DRM Data Structures");
38
39 void drm_mem_init(void)
40 {
41 #if defined(__NetBSD__) || defined(__OpenBSD__)
42         malloc_type_attach(M_DRM);
43 #endif
44 }
45
46 void drm_mem_uninit(void)
47 {
48 }
49
50 void *drm_alloc(size_t size, int area)
51 {
52         return malloc(size, M_DRM, M_NOWAIT);
53 }
54
55 void *drm_calloc(size_t nmemb, size_t size, int area)
56 {
57         return malloc(size * nmemb, M_DRM, M_NOWAIT | M_ZERO);
58 }
59
60 void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
61 {
62         void *pt;
63
64         pt = malloc(size, M_DRM, M_NOWAIT);
65         if (pt == NULL)
66                 return NULL;
67         if (oldpt && oldsize) {
68                 memcpy(pt, oldpt, oldsize);
69                 free(oldpt, M_DRM);
70         }
71         return pt;
72 }
73
74 void drm_free(void *pt, size_t size, int area)
75 {
76         free(pt, M_DRM);
77 }
78
79 void *drm_ioremap(drm_device_t *dev, drm_local_map_t *map)
80 {
81 #ifdef __FreeBSD__
82         return pmap_mapdev(map->offset, map->size);
83 #elif defined(__NetBSD__) || defined(__OpenBSD__)
84         map->bst = dev->pa.pa_memt;
85         if (bus_space_map(map->bst, map->offset, map->size, 
86             BUS_SPACE_MAP_LINEAR, &map->bsh))
87                 return NULL;
88         return bus_space_vaddr(map->bst, map->bsh);
89 #endif
90 }
91
92 void drm_ioremapfree(drm_local_map_t *map)
93 {
94 #ifdef __FreeBSD__
95         pmap_unmapdev((vm_offset_t) map->handle, map->size);
96 #elif defined(__NetBSD__) || defined(__OpenBSD__)
97         bus_space_unmap(map->bst, map->bsh, map->size);
98 #endif
99 }
100
101 #ifdef __FreeBSD__
102 int
103 drm_mtrr_add(unsigned long offset, size_t size, int flags)
104 {
105         int act;
106         struct mem_range_desc mrdesc;
107
108         mrdesc.mr_base = offset;
109         mrdesc.mr_len = size;
110         mrdesc.mr_flags = flags;
111         act = MEMRANGE_SET_UPDATE;
112         strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
113         return mem_range_attr_set(&mrdesc, &act);
114 }
115
116 int
117 drm_mtrr_del(unsigned long offset, size_t size, int flags)
118 {
119         int act;
120         struct mem_range_desc mrdesc;
121
122         mrdesc.mr_base = offset;
123         mrdesc.mr_len = size;
124         mrdesc.mr_flags = flags;
125         act = MEMRANGE_SET_REMOVE;
126         strlcpy(mrdesc.mr_owner, "drm", sizeof(mrdesc.mr_owner));
127         return mem_range_attr_set(&mrdesc, &act);
128 }
129 #elif defined(__NetBSD__) || defined(__OpenBSD__)
130 int
131 drm_mtrr_add(unsigned long offset, size_t size, int flags)
132 {
133         struct mtrr mtrrmap;
134         int one = 1;
135
136         mtrrmap.base = offset;
137         mtrrmap.len = size;
138         mtrrmap.type = flags;
139         mtrrmap.flags = MTRR_VALID;
140         return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
141 }
142
143 int
144 drm_mtrr_del(unsigned long offset, size_t size, int flags)
145 {
146         struct mtrr mtrrmap;
147         int one = 1;
148
149         mtrrmap.base = offset;
150         mtrrmap.len = size;
151         mtrrmap.type = flags;
152         mtrrmap.flags = 0;
153         return mtrr_set(&mtrrmap, &one, NULL, MTRR_GETSET_KERNEL);
154 }
155 #endif