Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 1 | /************************************************************************** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 3 | * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 13 | * |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the 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, |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 25 | * |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 26 | * |
| 27 | **************************************************************************/ |
| 28 | |
| 29 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * Authors: |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 31 | * Thomas Hellström <thomas-at-tungstengraphics-dot-com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | #include "drmP.h" |
| 35 | #include "sis_drm.h" |
| 36 | #include "sis_drv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 38 | #include <video/sisfb.h> |
| 39 | |
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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 44 | #if defined(CONFIG_FB_SIS) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 45 | /* fb management via fb device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 47 | #define SIS_MM_ALIGN_SHIFT 0 |
| 48 | #define SIS_MM_ALIGN_MASK 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 50 | static void *sis_sman_mm_allocate(void *private, unsigned long size, |
| 51 | unsigned alignment) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct sis_memreq req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 55 | req.size = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | sis_malloc(&req); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 57 | if (req.size == 0) |
| 58 | return NULL; |
| 59 | else |
| 60 | return (void *)~req.offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 63 | static void sis_sman_mm_free(void *private, void *ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 65 | sis_free(~((unsigned long)ref)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 68 | static void sis_sman_mm_destroy(void *private) |
| 69 | { |
| 70 | ; |
| 71 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Adrian Bunk | fb41e54 | 2006-08-16 11:55:18 +1000 | [diff] [blame] | 73 | static unsigned long sis_sman_mm_offset(void *private, void *ref) |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 74 | { |
| 75 | return ~((unsigned long)ref); |
| 76 | } |
| 77 | |
Adrian Bunk | fb41e54 | 2006-08-16 11:55:18 +1000 | [diff] [blame] | 78 | #else /* CONFIG_FB_SIS */ |
| 79 | |
| 80 | #define SIS_MM_ALIGN_SHIFT 4 |
| 81 | #define SIS_MM_ALIGN_MASK ( (1 << SIS_MM_ALIGN_SHIFT) - 1) |
| 82 | |
| 83 | #endif /* CONFIG_FB_SIS */ |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 84 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 85 | static int sis_fb_init(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
| 87 | DRM_DEVICE; |
| 88 | drm_sis_private_t *dev_priv = dev->dev_private; |
| 89 | drm_sis_fb_t fb; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 90 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 92 | 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] | 93 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 94 | mutex_lock(&dev->struct_mutex); |
| 95 | #if defined(CONFIG_FB_SIS) |
| 96 | { |
| 97 | drm_sman_mm_t sman_mm; |
| 98 | sman_mm.private = (void *)0xFFFFFFFF; |
| 99 | sman_mm.allocate = sis_sman_mm_allocate; |
| 100 | sman_mm.free = sis_sman_mm_free; |
| 101 | sman_mm.destroy = sis_sman_mm_destroy; |
| 102 | sman_mm.offset = sis_sman_mm_offset; |
| 103 | ret = |
| 104 | drm_sman_set_manager(&dev_priv->sman, VIDEO_TYPE, &sman_mm); |
| 105 | } |
| 106 | #else |
| 107 | ret = drm_sman_set_range(&dev_priv->sman, VIDEO_TYPE, 0, |
| 108 | fb.size >> SIS_MM_ALIGN_SHIFT); |
| 109 | #endif |
| 110 | |
| 111 | if (ret) { |
| 112 | DRM_ERROR("VRAM memory manager initialisation error\n"); |
| 113 | mutex_unlock(&dev->struct_mutex); |
| 114 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 117 | dev_priv->vram_initialized = 1; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 118 | dev_priv->vram_offset = fb.offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 120 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | DRM_DEBUG("offset = %u, size = %u", fb.offset, fb.size); |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 126 | static int sis_drm_alloc(drm_device_t * dev, drm_file_t * priv, |
| 127 | unsigned long data, int pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | drm_sis_private_t *dev_priv = dev->dev_private; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 130 | drm_sis_mem_t __user *argp = (drm_sis_mem_t __user *) data; |
| 131 | drm_sis_mem_t mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | int retval = 0; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 133 | drm_memblock_item_t *item; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 135 | DRM_COPY_FROM_USER_IOCTL(mem, argp, sizeof(mem)); |
| 136 | |
| 137 | mutex_lock(&dev->struct_mutex); |
| 138 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 139 | if (0 == ((pool == 0) ? dev_priv->vram_initialized : |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 140 | dev_priv->agp_initialized)) { |
| 141 | DRM_ERROR |
| 142 | ("Attempt to allocate from uninitialized memory manager.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return DRM_ERR(EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 146 | mem.size = (mem.size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT; |
| 147 | item = drm_sman_alloc(&dev_priv->sman, pool, mem.size, 0, |
| 148 | (unsigned long)priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 150 | mutex_unlock(&dev->struct_mutex); |
| 151 | if (item) { |
| 152 | mem.offset = ((pool == 0) ? |
| 153 | dev_priv->vram_offset : dev_priv->agp_offset) + |
| 154 | (item->mm-> |
| 155 | offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT); |
| 156 | mem.free = item->user_hash.key; |
| 157 | mem.size = mem.size << SIS_MM_ALIGN_SHIFT; |
| 158 | } else { |
| 159 | mem.offset = 0; |
| 160 | mem.size = 0; |
| 161 | mem.free = 0; |
| 162 | retval = DRM_ERR(ENOMEM); |
| 163 | } |
| 164 | |
| 165 | DRM_COPY_TO_USER_IOCTL(argp, mem, sizeof(mem)); |
| 166 | |
| 167 | DRM_DEBUG("alloc %d, size = %d, offset = %d\n", pool, mem.size, |
| 168 | mem.offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | return retval; |
| 171 | } |
| 172 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 173 | static int sis_drm_free(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
| 175 | DRM_DEVICE; |
| 176 | drm_sis_private_t *dev_priv = dev->dev_private; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 177 | drm_sis_mem_t mem; |
| 178 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 180 | DRM_COPY_FROM_USER_IOCTL(mem, (drm_sis_mem_t __user *) data, |
| 181 | sizeof(mem)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 183 | mutex_lock(&dev->struct_mutex); |
| 184 | ret = drm_sman_free_key(&dev_priv->sman, mem.free); |
| 185 | mutex_unlock(&dev->struct_mutex); |
| 186 | DRM_DEBUG("free = 0x%lx\n", mem.free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 188 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 191 | static int sis_fb_alloc(DRM_IOCTL_ARGS) |
| 192 | { |
| 193 | DRM_DEVICE; |
| 194 | return sis_drm_alloc(dev, priv, data, VIDEO_TYPE); |
| 195 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 197 | static int sis_ioctl_agp_init(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
| 199 | DRM_DEVICE; |
| 200 | drm_sis_private_t *dev_priv = dev->dev_private; |
| 201 | drm_sis_agp_t agp; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 202 | int ret; |
| 203 | dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 205 | DRM_COPY_FROM_USER_IOCTL(agp, (drm_sis_agp_t __user *) data, |
| 206 | sizeof(agp)); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 207 | mutex_lock(&dev->struct_mutex); |
| 208 | ret = drm_sman_set_range(&dev_priv->sman, AGP_TYPE, 0, |
| 209 | agp.size >> SIS_MM_ALIGN_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 211 | if (ret) { |
| 212 | DRM_ERROR("AGP memory manager initialisation error\n"); |
| 213 | mutex_unlock(&dev->struct_mutex); |
| 214 | return ret; |
| 215 | } |
| 216 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 217 | dev_priv->agp_initialized = 1; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 218 | dev_priv->agp_offset = agp.offset; |
| 219 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | DRM_DEBUG("offset = %u, size = %u", agp.offset, agp.size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 225 | static int sis_ioctl_agp_alloc(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | { |
| 227 | DRM_DEVICE; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 228 | |
| 229 | return sis_drm_alloc(dev, priv, data, AGP_TYPE); |
| 230 | } |
| 231 | |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 232 | static drm_local_map_t *sis_reg_init(drm_device_t *dev) |
| 233 | { |
| 234 | drm_map_list_t *entry; |
| 235 | drm_local_map_t *map; |
| 236 | |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame^] | 237 | list_for_each_entry(entry, &dev->maplist, head) { |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 238 | map = entry->map; |
| 239 | if (!map) |
| 240 | continue; |
| 241 | if (map->type == _DRM_REGISTERS) { |
| 242 | return map; |
| 243 | } |
| 244 | } |
| 245 | return NULL; |
| 246 | } |
| 247 | |
| 248 | int sis_idle(drm_device_t *dev) |
| 249 | { |
| 250 | drm_sis_private_t *dev_priv = dev->dev_private; |
| 251 | uint32_t idle_reg; |
| 252 | unsigned long end; |
| 253 | int i; |
| 254 | |
| 255 | if (dev_priv->idle_fault) |
| 256 | return 0; |
| 257 | |
| 258 | if (dev_priv->mmio == NULL) { |
| 259 | dev_priv->mmio = sis_reg_init(dev); |
| 260 | if (dev_priv->mmio == NULL) { |
| 261 | DRM_ERROR("Could not find register map.\n"); |
| 262 | return 0; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Implement a device switch here if needed |
| 268 | */ |
| 269 | |
| 270 | if (dev_priv->chipset != SIS_CHIP_315) |
| 271 | return 0; |
| 272 | |
| 273 | /* |
| 274 | * Timeout after 3 seconds. We cannot use DRM_WAIT_ON here |
| 275 | * because its polling frequency is too low. |
| 276 | */ |
| 277 | |
| 278 | end = jiffies + (DRM_HZ * 3); |
| 279 | |
| 280 | for (i=0; i<4; ++i) { |
| 281 | do { |
| 282 | idle_reg = SIS_READ(0x85cc); |
| 283 | } while ( !time_after_eq(jiffies, end) && |
| 284 | ((idle_reg & 0x80000000) != 0x80000000)); |
| 285 | } |
| 286 | |
| 287 | if (time_after_eq(jiffies, end)) { |
| 288 | DRM_ERROR("Graphics engine idle timeout. " |
| 289 | "Disabling idle check\n"); |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 290 | dev_priv->idle_fault = 1; |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* |
| 294 | * The caller never sees an error code. It gets trapped |
| 295 | * in libdrm. |
| 296 | */ |
| 297 | |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 302 | void sis_lastclose(struct drm_device *dev) |
| 303 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | drm_sis_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 305 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 306 | if (!dev_priv) |
| 307 | return; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 308 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 309 | mutex_lock(&dev->struct_mutex); |
| 310 | drm_sman_cleanup(&dev_priv->sman); |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 311 | dev_priv->vram_initialized = 0; |
| 312 | dev_priv->agp_initialized = 0; |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 313 | dev_priv->mmio = NULL; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 314 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 317 | void sis_reclaim_buffers_locked(drm_device_t * dev, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | drm_sis_private_t *dev_priv = dev->dev_private; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 320 | drm_file_t *priv = filp->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 322 | mutex_lock(&dev->struct_mutex); |
| 323 | if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)priv)) { |
| 324 | mutex_unlock(&dev->struct_mutex); |
| 325 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 328 | if (dev->driver->dma_quiescent) { |
| 329 | dev->driver->dma_quiescent(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 331 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 332 | drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)priv); |
| 333 | mutex_unlock(&dev->struct_mutex); |
| 334 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | drm_ioctl_desc_t sis_ioctls[] = { |
Dave Airlie | a7a2cc3 | 2006-01-02 13:54:04 +1100 | [diff] [blame] | 338 | [DRM_IOCTL_NR(DRM_SIS_FB_ALLOC)] = {sis_fb_alloc, DRM_AUTH}, |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 339 | [DRM_IOCTL_NR(DRM_SIS_FB_FREE)] = {sis_drm_free, DRM_AUTH}, |
| 340 | [DRM_IOCTL_NR(DRM_SIS_AGP_INIT)] = |
| 341 | {sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY}, |
Dave Airlie | a7a2cc3 | 2006-01-02 13:54:04 +1100 | [diff] [blame] | 342 | [DRM_IOCTL_NR(DRM_SIS_AGP_ALLOC)] = {sis_ioctl_agp_alloc, DRM_AUTH}, |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 343 | [DRM_IOCTL_NR(DRM_SIS_AGP_FREE)] = {sis_drm_free, DRM_AUTH}, |
| 344 | [DRM_IOCTL_NR(DRM_SIS_FB_INIT)] = |
| 345 | {sis_fb_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | }; |
| 347 | |
| 348 | int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls); |