Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* sis_mm.c -- Private header for Direct Rendering Manager -*- linux-c -*- |
| 2 | * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw |
| 3 | * |
| 4 | * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 13 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * The above copyright notice and this permission notice (including the next |
| 15 | * paragraph) shall be included in all copies or substantial portions of the |
| 16 | * Software. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 22 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 | * DEALINGS IN THE SOFTWARE. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 25 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * Authors: |
| 27 | * Sung-Ching Lin <sclin@sis.com.tw> |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 28 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include "drmP.h" |
| 32 | #include "sis_drm.h" |
| 33 | #include "sis_drv.h" |
| 34 | #include "sis_ds.h" |
| 35 | #if defined(__linux__) && defined(CONFIG_FB_SIS) |
| 36 | #include <video/sisfb.h> |
| 37 | #endif |
| 38 | |
| 39 | #define MAX_CONTEXT 100 |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 40 | #define VIDEO_TYPE 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define AGP_TYPE 1 |
| 42 | |
| 43 | typedef struct { |
| 44 | int used; |
| 45 | int context; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 46 | set_t *sets[2]; /* 0 for video, 1 for AGP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } sis_context_t; |
| 48 | |
| 49 | static sis_context_t global_ppriv[MAX_CONTEXT]; |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | static int add_alloc_set(int context, int type, unsigned int val) |
| 52 | { |
| 53 | int i, retval = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | for (i = 0; i < MAX_CONTEXT; i++) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 56 | if (global_ppriv[i].used && global_ppriv[i].context == context) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | retval = setAdd(global_ppriv[i].sets[type], val); |
| 58 | break; |
| 59 | } |
| 60 | } |
| 61 | return retval; |
| 62 | } |
| 63 | |
| 64 | static int del_alloc_set(int context, int type, unsigned int val) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 65 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | int i, retval = 0; |
| 67 | |
| 68 | for (i = 0; i < MAX_CONTEXT; i++) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 69 | if (global_ppriv[i].used && global_ppriv[i].context == context) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | retval = setDel(global_ppriv[i].sets[type], val); |
| 71 | break; |
| 72 | } |
| 73 | } |
| 74 | return retval; |
| 75 | } |
| 76 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 77 | /* fb management via fb device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #if defined(__linux__) && defined(CONFIG_FB_SIS) |
| 79 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 80 | static int sis_fb_init(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | return 0; |
| 83 | } |
| 84 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 85 | static int sis_fb_alloc(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
| 87 | drm_sis_mem_t fb; |
| 88 | struct sis_memreq req; |
Dave Airlie | 952d751 | 2006-01-02 14:44:12 +1100 | [diff] [blame] | 89 | drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 105 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Dave Airlie | 952d751 | 2006-01-02 14:44:12 +1100 | [diff] [blame] | 113 | DRM_DEBUG("alloc fb, size = %d, offset = %ld\n", fb.size, req.offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | return retval; |
| 116 | } |
| 117 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 118 | static int sis_fb_free(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
| 120 | drm_sis_mem_t fb; |
| 121 | int retval = 0; |
| 122 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 123 | DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_mem_t __user *) data, sizeof(fb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
Dave Airlie | 952d751 | 2006-01-02 14:44:12 +1100 | [diff] [blame] | 130 | sis_free(fb.free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Dave Airlie | 952d751 | 2006-01-02 14:44:12 +1100 | [diff] [blame] | 132 | DRM_DEBUG("free fb, offset = 0x%lx\n", fb.free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | return retval; |
| 135 | } |
| 136 | |
| 137 | #else |
| 138 | |
| 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 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 149 | static int sis_fb_init(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
| 151 | DRM_DEVICE; |
| 152 | drm_sis_private_t *dev_priv = dev->dev_private; |
| 153 | drm_sis_fb_t fb; |
| 154 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 155 | DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_fb_t __user *) data, sizeof(fb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | if (dev_priv == NULL) { |
| 158 | dev->dev_private = drm_calloc(1, sizeof(drm_sis_private_t), |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 159 | DRM_MEM_DRIVER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | dev_priv = dev->dev_private; |
| 161 | if (dev_priv == NULL) |
| 162 | return ENOMEM; |
| 163 | } |
| 164 | |
| 165 | if (dev_priv->FBHeap != NULL) |
| 166 | return DRM_ERR(EINVAL); |
| 167 | |
| 168 | dev_priv->FBHeap = mmInit(fb.offset, fb.size); |
| 169 | |
| 170 | DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size); |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 175 | static int sis_fb_alloc(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
| 177 | DRM_DEVICE; |
| 178 | drm_sis_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 952d751 | 2006-01-02 14:44:12 +1100 | [diff] [blame] | 179 | drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | drm_sis_mem_t fb; |
| 181 | PMemBlock block; |
| 182 | int retval = 0; |
| 183 | |
| 184 | if (dev_priv == NULL || dev_priv->FBHeap == NULL) |
| 185 | return DRM_ERR(EINVAL); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | DRM_COPY_FROM_USER_IOCTL(fb, argp, sizeof(fb)); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | block = mmAllocMem(dev_priv->FBHeap, fb.size, 0, 0); |
| 190 | if (block) { |
| 191 | /* TODO */ |
| 192 | fb.offset = block->ofs; |
| 193 | fb.free = (unsigned long)block; |
| 194 | if (!add_alloc_set(fb.context, VIDEO_TYPE, fb.free)) { |
| 195 | DRM_DEBUG("adding to allocation set fails\n"); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 196 | mmFreeMem((PMemBlock) fb.free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | retval = DRM_ERR(EINVAL); |
| 198 | } |
| 199 | } else { |
| 200 | fb.offset = 0; |
| 201 | fb.size = 0; |
| 202 | fb.free = 0; |
| 203 | } |
| 204 | |
| 205 | DRM_COPY_TO_USER_IOCTL(argp, fb, sizeof(fb)); |
| 206 | |
| 207 | DRM_DEBUG("alloc fb, size = %d, offset = %d\n", fb.size, fb.offset); |
| 208 | |
| 209 | return retval; |
| 210 | } |
| 211 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 212 | static int sis_fb_free(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
| 214 | DRM_DEVICE; |
| 215 | drm_sis_private_t *dev_priv = dev->dev_private; |
| 216 | drm_sis_mem_t fb; |
| 217 | |
| 218 | if (dev_priv == NULL || dev_priv->FBHeap == NULL) |
| 219 | return DRM_ERR(EINVAL); |
| 220 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 221 | DRM_COPY_FROM_USER_IOCTL(fb, (drm_sis_mem_t __user *) data, sizeof(fb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 223 | if (!mmBlockInHeap(dev_priv->FBHeap, (PMemBlock) fb.free)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | return DRM_ERR(EINVAL); |
| 225 | |
| 226 | if (!del_alloc_set(fb.context, VIDEO_TYPE, fb.free)) |
| 227 | return DRM_ERR(EINVAL); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 228 | mmFreeMem((PMemBlock) fb.free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
| 230 | DRM_DEBUG("free fb, free = 0x%lx\n", fb.free); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | #endif |
| 236 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 237 | /* agp memory management */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 239 | static int sis_ioctl_agp_init(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
| 241 | DRM_DEVICE; |
| 242 | drm_sis_private_t *dev_priv = dev->dev_private; |
| 243 | drm_sis_agp_t agp; |
| 244 | |
| 245 | if (dev_priv == NULL) { |
| 246 | dev->dev_private = drm_calloc(1, sizeof(drm_sis_private_t), |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 247 | DRM_MEM_DRIVER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 256 | DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_agp_t __user *) data, |
| 257 | sizeof(agp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | dev_priv->AGPHeap = mmInit(agp.offset, agp.size); |
| 260 | |
| 261 | DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | return 0; |
| 264 | } |
| 265 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 266 | static int sis_ioctl_agp_alloc(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
| 268 | DRM_DEVICE; |
| 269 | drm_sis_private_t *dev_priv = dev->dev_private; |
Dave Airlie | 952d751 | 2006-01-02 14:44:12 +1100 | [diff] [blame] | 270 | drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | drm_sis_mem_t agp; |
| 272 | PMemBlock block; |
| 273 | int retval = 0; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (dev_priv == NULL || dev_priv->AGPHeap == NULL) |
| 276 | return DRM_ERR(EINVAL); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | DRM_COPY_FROM_USER_IOCTL(agp, argp, sizeof(agp)); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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"); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 287 | mmFreeMem((PMemBlock) agp.free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | retval = -1; |
| 289 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 290 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | agp.offset = 0; |
| 292 | agp.size = 0; |
| 293 | agp.free = 0; |
| 294 | } |
| 295 | |
| 296 | DRM_COPY_TO_USER_IOCTL(argp, agp, sizeof(agp)); |
| 297 | |
| 298 | DRM_DEBUG("alloc agp, size = %d, offset = %d\n", agp.size, agp.offset); |
| 299 | |
| 300 | return retval; |
| 301 | } |
| 302 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 303 | static int sis_ioctl_agp_free(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
| 305 | DRM_DEVICE; |
| 306 | 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 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 312 | DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_mem_t __user *) data, |
| 313 | sizeof(agp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 315 | if (!mmBlockInHeap(dev_priv->AGPHeap, (PMemBlock) agp.free)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | return DRM_ERR(EINVAL); |
| 317 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 318 | mmFreeMem((PMemBlock) agp.free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | int sis_init_context(struct drm_device *dev, int context) |
| 328 | { |
| 329 | int i; |
| 330 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 331 | for (i = 0; i < MAX_CONTEXT; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if (global_ppriv[i].used && |
| 333 | (global_ppriv[i].context == context)) |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | if (i >= MAX_CONTEXT) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 338 | for (i = 0; i < MAX_CONTEXT; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, " |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 345 | "context = %d\n", i, context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | break; |
| 347 | } |
| 348 | } |
| 349 | if ((i >= MAX_CONTEXT) || (global_ppriv[i].sets[0] == NULL) || |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 350 | (global_ppriv[i].sets[1] == NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | return 1; |
| 356 | } |
| 357 | |
| 358 | int sis_final_context(struct drm_device *dev, int context) |
| 359 | { |
| 360 | int i; |
| 361 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 362 | for (i = 0; i < MAX_CONTEXT; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (global_ppriv[i].used && |
| 364 | (global_ppriv[i].context == context)) |
| 365 | break; |
| 366 | } |
| 367 | |
| 368 | if (i < MAX_CONTEXT) { |
| 369 | set_t *set; |
Dave Airlie | 952d751 | 2006-01-02 14:44:12 +1100 | [diff] [blame] | 370 | ITEM_TYPE item; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) { |
Dave Airlie | 952d751 | 2006-01-02 14:44:12 +1100 | [diff] [blame] | 379 | DRM_DEBUG("free video memory 0x%lx\n", item); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | #if defined(__linux__) && defined(CONFIG_FB_SIS) |
| 381 | sis_free(item); |
| 382 | #else |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 383 | mmFreeMem((PMemBlock) item); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) { |
Dave Airlie | 952d751 | 2006-01-02 14:44:12 +1100 | [diff] [blame] | 393 | DRM_DEBUG("free agp memory 0x%lx\n", item); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 394 | mmFreeMem((PMemBlock) item); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | retval = setNext(set, &item); |
| 396 | } |
| 397 | setDestroy(set); |
| 398 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 399 | global_ppriv[i].used = 0; |
| 400 | } |
| 401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return 1; |
| 403 | } |
| 404 | |
| 405 | drm_ioctl_desc_t sis_ioctls[] = { |
Dave Airlie | a7a2cc3 | 2006-01-02 13:54:04 +1100 | [diff] [blame] | 406 | [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}, |
| 408 | [DRM_IOCTL_NR(DRM_SIS_AGP_INIT)] = {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}, |
| 410 | [DRM_IOCTL_NR(DRM_SIS_AGP_FREE)] = {sis_ioctl_agp_free, DRM_AUTH}, |
| 411 | [DRM_IOCTL_NR(DRM_SIS_FB_INIT)] = {sis_fb_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | }; |
| 413 | |
| 414 | int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls); |