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: |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [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 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 85 | static int sis_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | drm_sis_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 88 | drm_sis_fb_t *fb = data; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 89 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 91 | mutex_lock(&dev->struct_mutex); |
| 92 | #if defined(CONFIG_FB_SIS) |
| 93 | { |
Dave Airlie | cca5307 | 2007-07-17 12:55:58 +1000 | [diff] [blame] | 94 | struct drm_sman_mm sman_mm; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 95 | sman_mm.private = (void *)0xFFFFFFFF; |
| 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); |
| 102 | } |
| 103 | #else |
| 104 | ret = drm_sman_set_range(&dev_priv->sman, VIDEO_TYPE, 0, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 105 | fb->size >> SIS_MM_ALIGN_SHIFT); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 106 | #endif |
| 107 | |
| 108 | if (ret) { |
| 109 | DRM_ERROR("VRAM memory manager initialisation error\n"); |
| 110 | mutex_unlock(&dev->struct_mutex); |
| 111 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 114 | dev_priv->vram_initialized = 1; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 115 | dev_priv->vram_offset = fb->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 117 | mutex_unlock(&dev->struct_mutex); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 118 | DRM_DEBUG("offset = %u, size = %u", fb->offset, fb->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | return 0; |
| 121 | } |
| 122 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 123 | static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file_priv, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 124 | void *data, int pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | drm_sis_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 127 | drm_sis_mem_t *mem = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | int retval = 0; |
Dave Airlie | 9698b4d | 2007-07-12 10:21:05 +1000 | [diff] [blame] | 129 | struct drm_memblock_item *item; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 131 | mutex_lock(&dev->struct_mutex); |
| 132 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 133 | if (0 == ((pool == 0) ? dev_priv->vram_initialized : |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 134 | dev_priv->agp_initialized)) { |
| 135 | DRM_ERROR |
| 136 | ("Attempt to allocate from uninitialized memory manager.\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 137 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 140 | mem->size = (mem->size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT; |
| 141 | item = drm_sman_alloc(&dev_priv->sman, pool, mem->size, 0, |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 142 | (unsigned long)file_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 144 | mutex_unlock(&dev->struct_mutex); |
| 145 | if (item) { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 146 | mem->offset = ((pool == 0) ? |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 147 | dev_priv->vram_offset : dev_priv->agp_offset) + |
| 148 | (item->mm-> |
| 149 | offset(item->mm, item->mm_info) << SIS_MM_ALIGN_SHIFT); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 150 | mem->free = item->user_hash.key; |
| 151 | mem->size = mem->size << SIS_MM_ALIGN_SHIFT; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 152 | } else { |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 153 | mem->offset = 0; |
| 154 | mem->size = 0; |
| 155 | mem->free = 0; |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 156 | retval = -ENOMEM; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 157 | } |
| 158 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 159 | DRM_DEBUG("alloc %d, size = %d, offset = %d\n", pool, mem->size, |
| 160 | mem->offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | return retval; |
| 163 | } |
| 164 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 165 | static int sis_drm_free(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | drm_sis_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 168 | drm_sis_mem_t *mem = data; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 169 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 171 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 172 | ret = drm_sman_free_key(&dev_priv->sman, mem->free); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 173 | mutex_unlock(&dev->struct_mutex); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 174 | DRM_DEBUG("free = 0x%lx\n", mem->free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 176 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 179 | static int sis_fb_alloc(struct drm_device *dev, void *data, |
| 180 | struct drm_file *file_priv) |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 181 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 182 | return sis_drm_alloc(dev, file_priv, data, VIDEO_TYPE); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 185 | static int sis_ioctl_agp_init(struct drm_device *dev, void *data, |
| 186 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | drm_sis_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 189 | drm_sis_agp_t *agp = data; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 190 | int ret; |
| 191 | dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 193 | mutex_lock(&dev->struct_mutex); |
| 194 | ret = drm_sman_set_range(&dev_priv->sman, AGP_TYPE, 0, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 195 | agp->size >> SIS_MM_ALIGN_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 197 | if (ret) { |
| 198 | DRM_ERROR("AGP memory manager initialisation error\n"); |
| 199 | mutex_unlock(&dev->struct_mutex); |
| 200 | return ret; |
| 201 | } |
| 202 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 203 | dev_priv->agp_initialized = 1; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 204 | dev_priv->agp_offset = agp->offset; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 205 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 207 | DRM_DEBUG("offset = %u, size = %u", agp->offset, agp->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 211 | static int sis_ioctl_agp_alloc(struct drm_device *dev, void *data, |
| 212 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 214 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 215 | return sis_drm_alloc(dev, file_priv, data, AGP_TYPE); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 216 | } |
| 217 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 218 | static drm_local_map_t *sis_reg_init(struct drm_device *dev) |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 219 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 220 | struct drm_map_list *entry; |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 221 | drm_local_map_t *map; |
| 222 | |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 223 | list_for_each_entry(entry, &dev->maplist, head) { |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 224 | map = entry->map; |
| 225 | if (!map) |
| 226 | continue; |
| 227 | if (map->type == _DRM_REGISTERS) { |
| 228 | return map; |
| 229 | } |
| 230 | } |
| 231 | return NULL; |
| 232 | } |
| 233 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 234 | int sis_idle(struct drm_device *dev) |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 235 | { |
| 236 | drm_sis_private_t *dev_priv = dev->dev_private; |
| 237 | uint32_t idle_reg; |
| 238 | unsigned long end; |
| 239 | int i; |
| 240 | |
| 241 | if (dev_priv->idle_fault) |
| 242 | return 0; |
| 243 | |
| 244 | if (dev_priv->mmio == NULL) { |
| 245 | dev_priv->mmio = sis_reg_init(dev); |
| 246 | if (dev_priv->mmio == NULL) { |
| 247 | DRM_ERROR("Could not find register map.\n"); |
| 248 | return 0; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /* |
| 253 | * Implement a device switch here if needed |
| 254 | */ |
| 255 | |
| 256 | if (dev_priv->chipset != SIS_CHIP_315) |
| 257 | return 0; |
| 258 | |
| 259 | /* |
| 260 | * Timeout after 3 seconds. We cannot use DRM_WAIT_ON here |
| 261 | * because its polling frequency is too low. |
| 262 | */ |
| 263 | |
| 264 | end = jiffies + (DRM_HZ * 3); |
| 265 | |
| 266 | for (i=0; i<4; ++i) { |
| 267 | do { |
| 268 | idle_reg = SIS_READ(0x85cc); |
| 269 | } while ( !time_after_eq(jiffies, end) && |
| 270 | ((idle_reg & 0x80000000) != 0x80000000)); |
| 271 | } |
| 272 | |
| 273 | if (time_after_eq(jiffies, end)) { |
| 274 | DRM_ERROR("Graphics engine idle timeout. " |
| 275 | "Disabling idle check\n"); |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 276 | dev_priv->idle_fault = 1; |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /* |
| 280 | * The caller never sees an error code. It gets trapped |
| 281 | * in libdrm. |
| 282 | */ |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 288 | void sis_lastclose(struct drm_device *dev) |
| 289 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | drm_sis_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 291 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 292 | if (!dev_priv) |
| 293 | return; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 294 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 295 | mutex_lock(&dev->struct_mutex); |
| 296 | drm_sman_cleanup(&dev_priv->sman); |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 297 | dev_priv->vram_initialized = 0; |
| 298 | dev_priv->agp_initialized = 0; |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 299 | dev_priv->mmio = NULL; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 300 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 303 | void sis_reclaim_buffers_locked(struct drm_device * dev, |
| 304 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | drm_sis_private_t *dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 308 | mutex_lock(&dev->struct_mutex); |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 309 | if (drm_sman_owner_clean(&dev_priv->sman, (unsigned long)file_priv)) { |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 310 | mutex_unlock(&dev->struct_mutex); |
| 311 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 314 | if (dev->driver->dma_quiescent) { |
| 315 | dev->driver->dma_quiescent(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 317 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 318 | drm_sman_owner_cleanup(&dev_priv->sman, (unsigned long)file_priv); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 319 | mutex_unlock(&dev->struct_mutex); |
| 320 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 323 | struct drm_ioctl_desc sis_ioctls[] = { |
| 324 | DRM_IOCTL_DEF(DRM_SIS_FB_ALLOC, sis_fb_alloc, DRM_AUTH), |
| 325 | DRM_IOCTL_DEF(DRM_SIS_FB_FREE, sis_drm_free, DRM_AUTH), |
| 326 | DRM_IOCTL_DEF(DRM_SIS_AGP_INIT, sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY), |
| 327 | DRM_IOCTL_DEF(DRM_SIS_AGP_ALLOC, sis_ioctl_agp_alloc, DRM_AUTH), |
| 328 | DRM_IOCTL_DEF(DRM_SIS_AGP_FREE, sis_drm_free, DRM_AUTH), |
| 329 | DRM_IOCTL_DEF(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] | 330 | }; |
| 331 | |
| 332 | int sis_max_ioctl = DRM_ARRAY_SIZE(sis_ioctls); |