diff options
Diffstat (limited to 'drivers/char/drm/sis_mm.c')
-rw-r--r-- | drivers/char/drm/sis_mm.c | 456 |
1 files changed, 158 insertions, 298 deletions
diff --git a/drivers/char/drm/sis_mm.c b/drivers/char/drm/sis_mm.c index 5e9936bc307f..0eb1dca232b7 100644 --- a/drivers/char/drm/sis_mm.c +++ b/drivers/char/drm/sis_mm.c | |||
@@ -1,414 +1,274 @@ | |||
1 | /* sis_mm.c -- Private header for Direct Rendering Manager -*- linux-c -*- | 1 | /************************************************************************** |
2 | * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw | ||
3 | * | 2 | * |
4 | * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. | 3 | * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA. |
5 | * All rights reserved. | 4 | * All Rights Reserved. |
6 | * | 5 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining a | 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
8 | * copy of this software and associated documentation files (the "Software"), | 7 | * copy of this software and associated documentation files (the |
9 | * to deal in the Software without restriction, including without limitation | 8 | * "Software"), to deal in the Software without restriction, including |
10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 9 | * without limitation the rights to use, copy, modify, merge, publish, |
11 | * and/or sell copies of the Software, and to permit persons to whom the | 10 | * distribute, sub license, and/or sell copies of the Software, and to |
12 | * Software is furnished to do so, subject to the following conditions: | 11 | * permit persons to whom the Software is furnished to do so, subject to |
12 | * the following conditions: | ||
13 | * | 13 | * |
14 | * The above copyright notice and this permission notice (including the next | 14 | * The above copyright notice and this permission notice (including the |
15 | * paragraph) shall be included in all copies or substantial portions of the | 15 | * next paragraph) shall be included in all copies or substantial portions |
16 | * Software. | 16 | * of the Software. |
17 | * | 17 | * |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
21 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | 21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
22 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | 22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
24 | * DEALINGS IN THE SOFTWARE. | 24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
25 | * | 25 | * |
26 | * Authors: | ||
27 | * Sung-Ching Lin <sclin@sis.com.tw> | ||
28 | * | 26 | * |
27 | **************************************************************************/ | ||
28 | |||
29 | /* | ||
30 | * Authors: | ||
31 | * Thomas Hellström <thomas-at-tungstengraphics-dot-com> | ||
29 | */ | 32 | */ |
30 | 33 | ||
31 | #include "drmP.h" | 34 | #include "drmP.h" |
32 | #include "sis_drm.h" | 35 | #include "sis_drm.h" |
33 | #include "sis_drv.h" | 36 | #include "sis_drv.h" |
34 | #include "sis_ds.h" | 37 | |
35 | #if defined(__linux__) && defined(CONFIG_FB_SIS) | ||
36 | #include <video/sisfb.h> | 38 | #include <video/sisfb.h> |
37 | #endif | ||
38 | 39 | ||
39 | #define MAX_CONTEXT 100 | ||
40 | #define VIDEO_TYPE 0 | 40 | #define VIDEO_TYPE 0 |
41 | #define AGP_TYPE 1 | 41 | #define AGP_TYPE 1 |
42 | 42 | ||
43 | typedef struct { | 43 | #define SIS_MM_ALIGN_SHIFT 4 |
44 | int used; | 44 | #define SIS_MM_ALIGN_MASK ( (1 << SIS_MM_ALIGN_SHIFT) - 1) |
45 | int context; | ||
46 | set_t *sets[2]; /* 0 for video, 1 for AGP */ | ||
47 | } sis_context_t; | ||
48 | |||
49 | static sis_context_t global_ppriv[MAX_CONTEXT]; | ||
50 | 45 | ||
51 | static int add_alloc_set(int context, int type, unsigned int val) | 46 | #if defined(CONFIG_FB_SIS) |
52 | { | 47 | /* fb management via fb device */ |
53 | int i, retval = 0; | ||
54 | 48 | ||
55 | for (i = 0; i < MAX_CONTEXT; i++) { | 49 | #define SIS_MM_ALIGN_SHIFT 0 |
56 | if (global_ppriv[i].used && global_ppriv[i].context == context) { | 50 | #define SIS_MM_ALIGN_MASK 0 |
57 | retval = setAdd(global_ppriv[i].sets[type], val); | ||
58 | break; | ||
59 | } | ||
60 | } | ||
61 | return retval; | ||
62 | } | ||
63 | 51 | ||
64 | static int del_alloc_set(int context, int type, unsigned int val) | 52 | static void *sis_sman_mm_allocate(void *private, unsigned long size, |
53 | unsigned alignment) | ||
65 | { | 54 | { |
66 | int i, retval = 0; | 55 | struct sis_memreq req; |
67 | 56 | ||
68 | for (i = 0; i < MAX_CONTEXT; i++) { | 57 | req.size = size; |
69 | if (global_ppriv[i].used && global_ppriv[i].context == context) { | 58 | sis_malloc(&req); |
70 | retval = setDel(global_ppriv[i].sets[type], val); | 59 | if (req.size == 0) |
71 | break; | 60 | return NULL; |
72 | } | 61 | else |
73 | } | 62 | return (void *)~req.offset; |
74 | return retval; | ||
75 | } | 63 | } |
76 | 64 | ||
77 | /* fb management via fb device */ | 65 | static void sis_sman_mm_free(void *private, void *ref) |
78 | #if defined(__linux__) && defined(CONFIG_FB_SIS) | ||
79 | |||
80 | static int sis_fb_init(DRM_IOCTL_ARGS) | ||
81 | { | 66 | { |
82 | return 0; | 67 | sis_free(~((unsigned long)ref)); |
83 | } | 68 | } |
84 | 69 | ||
85 | static int sis_fb_alloc(DRM_IOCTL_ARGS) | 70 | static void sis_sman_mm_destroy(void *private) |
86 | { | 71 | { |
87 | drm_sis_mem_t fb; | 72 | ; |
88 | struct sis_memreq req; | ||
89 | drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data; | ||
90 | int retval = 0; | ||
91 | |||
92 | DRM_COPY_FROM_USER_IOCTL(fb, argp, sizeof(fb)); | ||
93 | |||
94 | req.size = fb.size; | ||
95 | sis_malloc(&req); | ||
96 | if (req.offset) { | ||
97 | /* TODO */ | ||
98 | fb.offset = req.offset; | ||
99 | fb.free = req.offset; | ||
100 | if (!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)) { | ||
101 | DRM_DEBUG("adding to allocation set fails\n"); | ||
102 | sis_free(req.offset); | ||
103 | retval = DRM_ERR(EINVAL); | ||
104 | } | ||
105 | } else { | ||
106 | fb.offset = 0; | ||
107 | fb.size = 0; | ||
108 | fb.free = 0; | ||
109 | } | ||
110 | |||
111 | DRM_COPY_TO_USER_IOCTL(argp, fb, sizeof(fb)); | ||
112 | |||
113 | DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, req.offset); | ||
114 | |||
115 | return retval; | ||
116 | } | 73 | } |
117 | 74 | ||
118 | static int sis_fb_free(DRM_IOCTL_ARGS) | 75 | unsigned long sis_sman_mm_offset(void *private, void *ref) |
119 | { | 76 | { |
120 | drm_sis_mem_t fb; | 77 | return ~((unsigned long)ref); |
121 | int retval = 0; | ||
122 | |||
123 | DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_mem_t __user *) data, sizeof(fb)); | ||
124 | |||
125 | if (!fb.free) | ||
126 | return DRM_ERR(EINVAL); | ||
127 | |||
128 | if (!del_alloc_set(fb.context, VIDEO_TYPE, fb.free)) | ||
129 | retval = DRM_ERR(EINVAL); | ||
130 | sis_free(fb.free); | ||
131 | |||
132 | DRM_DEBUG("free fb, offset = 0x%lx\n", fb.free); | ||
133 | |||
134 | return retval; | ||
135 | } | 78 | } |
136 | 79 | ||
137 | #else | 80 | #endif |
138 | 81 | ||
139 | /* Called by the X Server to initialize the FB heap. Allocations will fail | ||
140 | * unless this is called. Offset is the beginning of the heap from the | ||
141 | * framebuffer offset (MaxXFBMem in XFree86). | ||
142 | * | ||
143 | * Memory layout according to Thomas Winischofer: | ||
144 | * |------------------|DDDDDDDDDDDDDDDDDDDDDDDDDDDDD|HHHH|CCCCCCCCCCC| | ||
145 | * | ||
146 | * X driver/sisfb HW- Command- | ||
147 | * framebuffer memory DRI heap Cursor queue | ||
148 | */ | ||
149 | static int sis_fb_init(DRM_IOCTL_ARGS) | 82 | static int sis_fb_init(DRM_IOCTL_ARGS) |
150 | { | 83 | { |
151 | DRM_DEVICE; | 84 | DRM_DEVICE; |
152 | drm_sis_private_t *dev_priv = dev->dev_private; | 85 | drm_sis_private_t *dev_priv = dev->dev_private; |
153 | drm_sis_fb_t fb; | 86 | drm_sis_fb_t fb; |
87 | int ret; | ||
154 | 88 | ||
155 | DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_fb_t __user *) data, sizeof(fb)); | 89 | DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_fb_t __user *) data, sizeof(fb)); |
156 | 90 | ||
157 | if (dev_priv == NULL) { | 91 | mutex_lock(&dev->struct_mutex); |
158 | dev->dev_private = drm_calloc(1, sizeof(drm_sis_private_t), | 92 | #if defined(CONFIG_FB_SIS) |
159 | DRM_MEM_DRIVER); | 93 | { |
160 | dev_priv = dev->dev_private; | 94 | drm_sman_mm_t sman_mm; |
161 | if (dev_priv == NULL) | 95 | sman_mm.private = (void *)0xFFFFFFFF; |
162 | return ENOMEM; | 96 | sman_mm.allocate = sis_sman_mm_allocate; |
97 | sman_mm.free = sis_sman_mm_free; | ||
98 | sman_mm.destroy = sis_sman_mm_destroy; | ||
99 | sman_mm.offset = sis_sman_mm_offset; | ||
100 | ret = | ||
101 | drm_sman_set_manager(&dev_priv->sman, VIDEO_TYPE, &sman_mm); | ||
163 | } | 102 | } |
103 | #else | ||
104 | ret = drm_sman_set_range(&dev_priv->sman, VIDEO_TYPE, 0, | ||
105 | fb.size >> SIS_MM_ALIGN_SHIFT); | ||
106 | #endif | ||
164 | 107 | ||
165 | if (dev_priv->FBHeap != NULL) | 108 | if (ret) { |
166 | return DRM_ERR(EINVAL); | 109 | DRM_ERROR("VRAM memory manager initialisation error\n"); |
110 | mutex_unlock(&dev->struct_mutex); | ||
111 | return ret; | ||
112 | } | ||
167 | 113 | ||
168 | dev_priv->FBHeap = mmInit(fb.offset, fb.size); | 114 | dev_priv->vram_initialized = TRUE; |
115 | dev_priv->vram_offset = fb.offset; | ||
169 | 116 | ||
117 | mutex_unlock(&dev->struct_mutex); | ||
170 | DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size); | 118 | DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size); |
171 | 119 | ||
172 | return 0; | 120 | return 0; |
173 | } | 121 | } |
174 | 122 | ||
175 | static int sis_fb_alloc(DRM_IOCTL_ARGS) | 123 | static int sis_drm_alloc(drm_device_t * dev, drm_file_t * priv, |
124 | unsigned long data, int pool) | ||
176 | { | 125 | { |
177 | DRM_DEVICE; | ||
178 | drm_sis_private_t *dev_priv = dev->dev_private; | 126 | drm_sis_private_t *dev_priv = dev->dev_private; |
179 | drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data; | 127 | drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *) data; |
180 | drm_sis_mem_t fb; | 128 | drm_sis_mem_t mem; |
181 | PMemBlock block; | ||
182 | int retval = 0; | 129 | int retval = 0; |
130 | drm_memblock_item_t *item; | ||
183 | 131 | ||
184 | if (dev_priv == NULL || dev_priv->FBHeap == NULL) | 132 | DRM_COPY_FROM_USER_IOCTL(mem, argp, sizeof(mem)); |
133 | |||
134 | mutex_lock(&dev->struct_mutex); | ||
135 | |||
136 | if (FALSE == ((pool == 0) ? dev_priv->vram_initialized : | ||
137 | dev_priv->agp_initialized)) { | ||
138 | DRM_ERROR | ||
139 | ("Attempt to allocate from uninitialized memory manager.\n"); | ||
185 | return DRM_ERR(EINVAL); | 140 | return DRM_ERR(EINVAL); |
141 | } | ||
186 | 142 | ||
187 | DRM_COPY_FROM_USER_IOCTL(fb, argp, sizeof(fb)); | 143 | mem.size = (mem.size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT; |
188 | 144 | item = drm_sman_alloc(&dev_priv->sman, pool, mem.size, 0, | |
189 | block = mmAllocMem(dev_priv->FBHeap, fb.size, 0, 0); | 145 | (unsigned long)priv); |
190 | if (block) { | 146 | |
191 | /* TODO */ | 147 | mutex_unlock(&dev->struct_mutex); |
192 | fb.offset = block->ofs; | 148 | if (item) { |
193 | fb.free = (unsigned long)block; | 149 | mem.offset = ((pool == 0) ? |
194 | if (!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)) { | 150 | dev_priv->vram_offset : dev_priv->agp_offset) + |
195 | DRM_DEBUG("adding to allocation set fails\n"); | 151 | (item->mm-> |
196 | mmFreeMem((PMemBlock) fb.free); | 152 | offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT); |
197 | retval = DRM_ERR(EINVAL); | 153 | mem.free = item->user_hash.key; |
198 | } | 154 | mem.size = mem.size << SIS_MM_ALIGN_SHIFT; |
199 | } else { | 155 | } else { |
200 | fb.offset = 0; | 156 | mem.offset = 0; |
201 | fb.size = 0; | 157 | mem.size = 0; |
202 | fb.free = 0; | 158 | mem.free = 0; |
159 | retval = DRM_ERR(ENOMEM); | ||
203 | } | 160 | } |
204 | 161 | ||
205 | DRM_COPY_TO_USER_IOCTL(argp, fb, sizeof(fb)); | 162 | DRM_COPY_TO_USER_IOCTL(argp, mem, sizeof(mem)); |
206 | 163 | ||
207 | DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, fb.offset); | 164 | DRM_DEBUG("alloc %d, size = %d, offset = %d\n", pool, mem.size, |
165 | mem.offset); | ||
208 | 166 | ||
209 | return retval; | 167 | return retval; |
210 | } | 168 | } |
211 | 169 | ||
212 | static int sis_fb_free(DRM_IOCTL_ARGS) | 170 | static int sis_drm_free(DRM_IOCTL_ARGS) |
213 | { | 171 | { |
214 | DRM_DEVICE; | 172 | DRM_DEVICE; |
215 | drm_sis_private_t *dev_priv = dev->dev_private; | 173 | drm_sis_private_t *dev_priv = dev->dev_private; |
216 | drm_sis_mem_t fb; | 174 | drm_sis_mem_t mem; |
175 | int ret; | ||
217 | 176 | ||
218 | if (dev_priv == NULL || dev_priv->FBHeap == NULL) | 177 | DRM_COPY_FROM_USER_IOCTL(mem, (drm_sis_mem_t __user *) data, |
219 | return DRM_ERR(EINVAL); | 178 | sizeof(mem)); |
220 | |||
221 | DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_mem_t __user *) data, sizeof(fb)); | ||
222 | 179 | ||
223 | if (!mmBlockInHeap(dev_priv->FBHeap, (PMemBlock) fb.free)) | 180 | mutex_lock(&dev->struct_mutex); |
224 | return DRM_ERR(EINVAL); | 181 | ret = drm_sman_free_key(&dev_priv->sman, mem.free); |
182 | mutex_unlock(&dev->struct_mutex); | ||
183 | DRM_DEBUG("free = 0x%lx\n", mem.free); | ||
225 | 184 | ||
226 | if (!del_alloc_set(fb.context, VIDEO_TYPE, fb.free)) | 185 | return ret; |
227 | return DRM_ERR(EINVAL); | ||
228 | mmFreeMem((PMemBlock) fb.free); | ||
229 | |||
230 | DRM_DEBUG("free fb, free = 0x%lx\n", fb.free); | ||
231 | |||
232 | return 0; | ||
233 | } | 186 | } |
234 | 187 | ||
235 | #endif | 188 | static int sis_fb_alloc(DRM_IOCTL_ARGS) |
236 | 189 | { | |
237 | /* agp memory management */ | 190 | DRM_DEVICE; |
191 | return sis_drm_alloc(dev, priv, data, VIDEO_TYPE); | ||
192 | } | ||
238 | 193 | ||
239 | static int sis_ioctl_agp_init(DRM_IOCTL_ARGS) | 194 | static int sis_ioctl_agp_init(DRM_IOCTL_ARGS) |
240 | { | 195 | { |
241 | DRM_DEVICE; | 196 | DRM_DEVICE; |
242 | drm_sis_private_t *dev_priv = dev->dev_private; | 197 | drm_sis_private_t *dev_priv = dev->dev_private; |
243 | drm_sis_agp_t agp; | 198 | drm_sis_agp_t agp; |
244 | 199 | int ret; | |
245 | if (dev_priv == NULL) { | 200 | dev_priv = dev->dev_private; |
246 | dev->dev_private = drm_calloc(1, sizeof(drm_sis_private_t), | ||
247 | DRM_MEM_DRIVER); | ||
248 | dev_priv = dev->dev_private; | ||
249 | if (dev_priv == NULL) | ||
250 | return ENOMEM; | ||
251 | } | ||
252 | |||
253 | if (dev_priv->AGPHeap != NULL) | ||
254 | return DRM_ERR(EINVAL); | ||
255 | 201 | ||
256 | DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_agp_t __user *) data, | 202 | DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_agp_t __user *) data, |
257 | sizeof(agp)); | 203 | sizeof(agp)); |
204 | mutex_lock(&dev->struct_mutex); | ||
205 | ret = drm_sman_set_range(&dev_priv->sman, AGP_TYPE, 0, | ||
206 | agp.size >> SIS_MM_ALIGN_SHIFT); | ||
207 | |||
208 | if (ret) { | ||
209 | DRM_ERROR("AGP memory manager initialisation error\n"); | ||
210 | mutex_unlock(&dev->struct_mutex); | ||
211 | return ret; | ||
212 | } | ||
258 | 213 | ||
259 | dev_priv->AGPHeap = mmInit(agp.offset, agp.size); | 214 | dev_priv->agp_initialized = TRUE; |
215 | dev_priv->agp_offset = agp.offset; | ||
216 | mutex_unlock(&dev->struct_mutex); | ||
260 | 217 | ||
261 | DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size); | 218 | DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size); |
262 | |||
263 | return 0; | 219 | return 0; |
264 | } | 220 | } |
265 | 221 | ||
266 | static int sis_ioctl_agp_alloc(DRM_IOCTL_ARGS) | 222 | static int sis_ioctl_agp_alloc(DRM_IOCTL_ARGS) |
267 | { | 223 | { |
268 | DRM_DEVICE; | 224 | DRM_DEVICE; |
269 | drm_sis_private_t *dev_priv = dev->dev_private; | ||
270 | drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data; | ||
271 | drm_sis_mem_t agp; | ||
272 | PMemBlock block; | ||
273 | int retval = 0; | ||
274 | |||
275 | if (dev_priv == NULL || dev_priv->AGPHeap == NULL) | ||
276 | return DRM_ERR(EINVAL); | ||
277 | |||
278 | DRM_COPY_FROM_USER_IOCTL(agp, argp, sizeof(agp)); | ||
279 | |||
280 | block = mmAllocMem(dev_priv->AGPHeap, agp.size, 0, 0); | ||
281 | if (block) { | ||
282 | /* TODO */ | ||
283 | agp.offset = block->ofs; | ||
284 | agp.free = (unsigned long)block; | ||
285 | if (!add_alloc_set(agp.context, AGP_TYPE, agp.free)) { | ||
286 | DRM_DEBUG("adding to allocation set fails\n"); | ||
287 | mmFreeMem((PMemBlock) agp.free); | ||
288 | retval = -1; | ||
289 | } | ||
290 | } else { | ||
291 | agp.offset = 0; | ||
292 | agp.size = 0; | ||
293 | agp.free = 0; | ||
294 | } | ||
295 | 225 | ||
296 | DRM_COPY_TO_USER_IOCTL(argp, agp, sizeof(agp)); | 226 | return sis_drm_alloc(dev, priv, data, AGP_TYPE); |
297 | |||
298 | DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size, agp.offset); | ||
299 | |||
300 | return retval; | ||
301 | } | 227 | } |
302 | 228 | ||
303 | static int sis_ioctl_agp_free(DRM_IOCTL_ARGS) | 229 | void sis_lastclose(struct drm_device *dev) |
304 | { | 230 | { |
305 | DRM_DEVICE; | ||
306 | drm_sis_private_t *dev_priv = dev->dev_private; | 231 | drm_sis_private_t *dev_priv = dev->dev_private; |
307 | drm_sis_mem_t agp; | ||
308 | |||
309 | if (dev_priv == NULL || dev_priv->AGPHeap == NULL) | ||
310 | return DRM_ERR(EINVAL); | ||
311 | |||
312 | DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_mem_t __user *) data, | ||
313 | sizeof(agp)); | ||
314 | |||
315 | if (!mmBlockInHeap(dev_priv->AGPHeap, (PMemBlock) agp.free)) | ||
316 | return DRM_ERR(EINVAL); | ||
317 | |||
318 | mmFreeMem((PMemBlock) agp.free); | ||
319 | if (!del_alloc_set(agp.context, AGP_TYPE, agp.free)) | ||
320 | return DRM_ERR(EINVAL); | ||
321 | |||
322 | DRM_DEBUG("free agp, free = 0x%lx\n", agp.free); | ||
323 | 232 | ||
324 | return 0; | 233 | if (!dev_priv) |
325 | } | 234 | return; |
326 | |||
327 | int sis_init_context(struct drm_device *dev, int context) | ||
328 | { | ||
329 | int i; | ||
330 | 235 | ||
331 | for (i = 0; i < MAX_CONTEXT; i++) { | 236 | mutex_lock(&dev->struct_mutex); |
332 | if (global_ppriv[i].used && | 237 | drm_sman_cleanup(&dev_priv->sman); |
333 | (global_ppriv[i].context == context)) | 238 | dev_priv->vram_initialized = FALSE; |
334 | break; | 239 | dev_priv->agp_initialized = FALSE; |
335 | } | 240 | mutex_unlock(&dev->struct_mutex); |
336 | |||
337 | if (i >= MAX_CONTEXT) { | ||
338 | for (i = 0; i < MAX_CONTEXT; i++) { | ||
339 | if (!global_ppriv[i].used) { | ||
340 | global_ppriv[i].context = context; | ||
341 | global_ppriv[i].used = 1; | ||
342 | global_ppriv[i].sets[0] = setInit(); | ||
343 | global_ppriv[i].sets[1] = setInit(); | ||
344 | DRM_DEBUG("init allocation set, socket=%d, " | ||
345 | "context = %d\n", i, context); | ||
346 | break; | ||
347 | } | ||
348 | } | ||
349 | if ((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) || | ||
350 | (global_ppriv[i].sets[1] == NULL)) { | ||
351 | return 0; | ||
352 | } | ||
353 | } | ||
354 | |||
355 | return 1; | ||
356 | } | 241 | } |
357 | 242 | ||
358 | int sis_final_context(struct drm_device *dev, int context) | 243 | void sis_reclaim_buffers_locked(drm_device_t * dev, struct file *filp) |
359 | { | 244 | { |
360 | int i; | 245 | drm_sis_private_t *dev_priv = dev->dev_private; |
246 | drm_file_t *priv = filp->private_data; | ||
361 | 247 | ||
362 | for (i = 0; i < MAX_CONTEXT; i++) { | 248 | mutex_lock(&dev->struct_mutex); |
363 | if (global_ppriv[i].used && | 249 | if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)priv)) { |
364 | (global_ppriv[i].context == context)) | 250 | mutex_unlock(&dev->struct_mutex); |
365 | break; | 251 | return; |
366 | } | 252 | } |
367 | 253 | ||
368 | if (i < MAX_CONTEXT) { | 254 | if (dev->driver->dma_quiescent) { |
369 | set_t *set; | 255 | dev->driver->dma_quiescent(dev); |
370 | ITEM_TYPE item; | ||
371 | int retval; | ||
372 | |||
373 | DRM_DEBUG("find socket %d, context = %d\n", i, context); | ||
374 | |||
375 | /* Video Memory */ | ||
376 | set = global_ppriv[i].sets[0]; | ||
377 | retval = setFirst(set, &item); | ||
378 | while (retval) { | ||
379 | DRM_DEBUG("free video memory 0x%lx\n", item); | ||
380 | #if defined(__linux__) && defined(CONFIG_FB_SIS) | ||
381 | sis_free(item); | ||
382 | #else | ||
383 | mmFreeMem((PMemBlock) item); | ||
384 | #endif | ||
385 | retval = setNext(set, &item); | ||
386 | } | ||
387 | setDestroy(set); | ||
388 | |||
389 | /* AGP Memory */ | ||
390 | set = global_ppriv[i].sets[1]; | ||
391 | retval = setFirst(set, &item); | ||
392 | while (retval) { | ||
393 | DRM_DEBUG("free agp memory 0x%lx\n", item); | ||
394 | mmFreeMem((PMemBlock) item); | ||
395 | retval = setNext(set, &item); | ||
396 | } | ||
397 | setDestroy(set); | ||
398 | |||
399 | global_ppriv[i].used = 0; | ||
400 | } | 256 | } |
401 | 257 | ||
402 | return 1; | 258 | drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)priv); |
259 | mutex_unlock(&dev->struct_mutex); | ||
260 | return; | ||
403 | } | 261 | } |
404 | 262 | ||
405 | drm_ioctl_desc_t sis_ioctls[] = { | 263 | drm_ioctl_desc_t sis_ioctls[] = { |
406 | [DRM_IOCTL_NR(DRM_SIS_FB_ALLOC)] = {sis_fb_alloc, DRM_AUTH}, | 264 | [DRM_IOCTL_NR(DRM_SIS_FB_ALLOC)] = {sis_fb_alloc, DRM_AUTH}, |
407 | [DRM_IOCTL_NR(DRM_SIS_FB_FREE)] = {sis_fb_free, DRM_AUTH}, | 265 | [DRM_IOCTL_NR(DRM_SIS_FB_FREE)] = {sis_drm_free, DRM_AUTH}, |
408 | [DRM_IOCTL_NR(DRM_SIS_AGP_INIT)] = {sis_ioctl_agp_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, | 266 | [DRM_IOCTL_NR(DRM_SIS_AGP_INIT)] = |
267 | {sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY}, | ||
409 | [DRM_IOCTL_NR(DRM_SIS_AGP_ALLOC)] = {sis_ioctl_agp_alloc, DRM_AUTH}, | 268 | [DRM_IOCTL_NR(DRM_SIS_AGP_ALLOC)] = {sis_ioctl_agp_alloc, DRM_AUTH}, |
410 | [DRM_IOCTL_NR(DRM_SIS_AGP_FREE)] = {sis_ioctl_agp_free, DRM_AUTH}, | 269 | [DRM_IOCTL_NR(DRM_SIS_AGP_FREE)] = {sis_drm_free, DRM_AUTH}, |
411 | [DRM_IOCTL_NR(DRM_SIS_FB_INIT)] = {sis_fb_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY} | 270 | [DRM_IOCTL_NR(DRM_SIS_FB_INIT)] = |
271 | {sis_fb_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY} | ||
412 | }; | 272 | }; |
413 | 273 | ||
414 | int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls); | 274 | int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls); |