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 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 34 | #include <drm/drmP.h> |
| 35 | #include <drm/sis_drm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 44 | struct sis_memblock { |
| 45 | struct drm_mm_node mm_node; |
| 46 | struct sis_memreq req; |
| 47 | struct list_head owner_list; |
| 48 | }; |
| 49 | |
David Howells | 6bb9e4b | 2008-07-30 12:29:37 -0700 | [diff] [blame] | 50 | #if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 51 | /* fb management via fb device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 53 | #define SIS_MM_ALIGN_SHIFT 0 |
| 54 | #define SIS_MM_ALIGN_MASK 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
David Howells | 6bb9e4b | 2008-07-30 12:29:37 -0700 | [diff] [blame] | 56 | #else /* CONFIG_FB_SIS[_MODULE] */ |
Adrian Bunk | fb41e54 | 2006-08-16 11:55:18 +1000 | [diff] [blame] | 57 | |
| 58 | #define SIS_MM_ALIGN_SHIFT 4 |
Nicolas Kaiser | a7b98b6 | 2010-07-09 16:47:28 +0200 | [diff] [blame] | 59 | #define SIS_MM_ALIGN_MASK ((1 << SIS_MM_ALIGN_SHIFT) - 1) |
Adrian Bunk | fb41e54 | 2006-08-16 11:55:18 +1000 | [diff] [blame] | 60 | |
David Howells | 6bb9e4b | 2008-07-30 12:29:37 -0700 | [diff] [blame] | 61 | #endif /* CONFIG_FB_SIS[_MODULE] */ |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 62 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 63 | 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] | 64 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | drm_sis_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 66 | drm_sis_fb_t *fb = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 68 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 69 | /* Unconditionally init the drm_mm, even though we don't use it when the |
| 70 | * fb sis driver is available - make cleanup easier. */ |
| 71 | drm_mm_init(&dev_priv->vram_mm, 0, fb->size >> SIS_MM_ALIGN_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 73 | dev_priv->vram_initialized = 1; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 74 | dev_priv->vram_offset = fb->offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 76 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 83bc5fd | 2012-06-24 19:57:24 +0200 | [diff] [blame] | 77 | DRM_DEBUG("offset = %lu, size = %lu\n", fb->offset, fb->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
Daniel Vetter | fdc0b8a | 2011-10-25 16:32:34 +0200 | [diff] [blame] | 82 | static int sis_drm_alloc(struct drm_device *dev, struct drm_file *file, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 83 | void *data, int pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | drm_sis_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 86 | drm_sis_mem_t *mem = data; |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 87 | int retval = 0, user_key; |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 88 | struct sis_memblock *item; |
Daniel Vetter | fdc0b8a | 2011-10-25 16:32:34 +0200 | [diff] [blame] | 89 | struct sis_file_private *file_priv = file->driver_priv; |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 90 | unsigned long offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 92 | mutex_lock(&dev->struct_mutex); |
| 93 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 94 | if (0 == ((pool == 0) ? dev_priv->vram_initialized : |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 95 | dev_priv->agp_initialized)) { |
| 96 | DRM_ERROR |
| 97 | ("Attempt to allocate from uninitialized memory manager.\n"); |
Roel Kluin | 038477a | 2007-11-05 10:53:18 +1000 | [diff] [blame] | 98 | mutex_unlock(&dev->struct_mutex); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 99 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 102 | item = kzalloc(sizeof(*item), GFP_KERNEL); |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 103 | if (!item) { |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 104 | retval = -ENOMEM; |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 105 | goto fail_alloc; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 106 | } |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 107 | |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 108 | mem->size = (mem->size + SIS_MM_ALIGN_MASK) >> SIS_MM_ALIGN_SHIFT; |
| 109 | if (pool == AGP_TYPE) { |
| 110 | retval = drm_mm_insert_node(&dev_priv->agp_mm, |
| 111 | &item->mm_node, |
David Herrmann | 31e5d7c | 2013-07-27 13:36:27 +0200 | [diff] [blame] | 112 | mem->size, 0, |
| 113 | DRM_MM_SEARCH_DEFAULT); |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 114 | offset = item->mm_node.start; |
| 115 | } else { |
| 116 | #if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE) |
| 117 | item->req.size = mem->size; |
| 118 | sis_malloc(&item->req); |
| 119 | if (item->req.size == 0) |
| 120 | retval = -ENOMEM; |
| 121 | offset = item->req.offset; |
| 122 | #else |
| 123 | retval = drm_mm_insert_node(&dev_priv->vram_mm, |
| 124 | &item->mm_node, |
David Herrmann | 31e5d7c | 2013-07-27 13:36:27 +0200 | [diff] [blame] | 125 | mem->size, 0, |
| 126 | DRM_MM_SEARCH_DEFAULT); |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 127 | offset = item->mm_node.start; |
| 128 | #endif |
| 129 | } |
| 130 | if (retval) |
| 131 | goto fail_alloc; |
| 132 | |
Tejun Heo | ff51235 | 2013-02-27 17:04:11 -0800 | [diff] [blame] | 133 | retval = idr_alloc(&dev_priv->object_idr, item, 1, 0, GFP_KERNEL); |
| 134 | if (retval < 0) |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 135 | goto fail_idr; |
Tejun Heo | ff51235 | 2013-02-27 17:04:11 -0800 | [diff] [blame] | 136 | user_key = retval; |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 137 | |
| 138 | list_add(&item->owner_list, &file_priv->obj_list); |
Daniel Vetter | fdc0b8a | 2011-10-25 16:32:34 +0200 | [diff] [blame] | 139 | mutex_unlock(&dev->struct_mutex); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 140 | |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 141 | mem->offset = ((pool == 0) ? |
| 142 | dev_priv->vram_offset : dev_priv->agp_offset) + |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 143 | (offset << SIS_MM_ALIGN_SHIFT); |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 144 | mem->free = user_key; |
| 145 | mem->size = mem->size << SIS_MM_ALIGN_SHIFT; |
| 146 | |
| 147 | return 0; |
| 148 | |
| 149 | fail_idr: |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 150 | drm_mm_remove_node(&item->mm_node); |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 151 | fail_alloc: |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 152 | kfree(item); |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 153 | mutex_unlock(&dev->struct_mutex); |
| 154 | |
| 155 | mem->offset = 0; |
| 156 | mem->size = 0; |
| 157 | mem->free = 0; |
| 158 | |
Daniel Vetter | 83bc5fd | 2012-06-24 19:57:24 +0200 | [diff] [blame] | 159 | DRM_DEBUG("alloc %d, size = %ld, offset = %ld\n", pool, mem->size, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 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; |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 169 | struct sis_memblock *obj; |
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); |
Daniel Vetter | 6de8a74 | 2011-10-25 18:00:41 +0200 | [diff] [blame] | 172 | obj = idr_find(&dev_priv->object_idr, mem->free); |
| 173 | if (obj == NULL) { |
| 174 | mutex_unlock(&dev->struct_mutex); |
| 175 | return -EINVAL; |
| 176 | } |
| 177 | |
| 178 | idr_remove(&dev_priv->object_idr, mem->free); |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 179 | list_del(&obj->owner_list); |
| 180 | if (drm_mm_node_allocated(&obj->mm_node)) |
| 181 | drm_mm_remove_node(&obj->mm_node); |
| 182 | #if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE) |
| 183 | else |
| 184 | sis_free(obj->req.offset); |
| 185 | #endif |
| 186 | kfree(obj); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 187 | mutex_unlock(&dev->struct_mutex); |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 188 | DRM_DEBUG("free = 0x%lx\n", mem->free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
Daniel Vetter | b5215ef | 2012-01-08 22:42:27 +0100 | [diff] [blame] | 190 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 193 | static int sis_fb_alloc(struct drm_device *dev, void *data, |
| 194 | struct drm_file *file_priv) |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 195 | { |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 196 | return sis_drm_alloc(dev, file_priv, data, VIDEO_TYPE); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 199 | static int sis_ioctl_agp_init(struct drm_device *dev, void *data, |
| 200 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | drm_sis_private_t *dev_priv = dev->dev_private; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 203 | drm_sis_agp_t *agp = data; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 204 | dev_priv = dev->dev_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 206 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 207 | drm_mm_init(&dev_priv->agp_mm, 0, agp->size >> SIS_MM_ALIGN_SHIFT); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 208 | |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 209 | dev_priv->agp_initialized = 1; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 210 | dev_priv->agp_offset = agp->offset; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 211 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Daniel Vetter | 83bc5fd | 2012-06-24 19:57:24 +0200 | [diff] [blame] | 213 | DRM_DEBUG("offset = %lu, size = %lu\n", agp->offset, agp->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 217 | static int sis_ioctl_agp_alloc(struct drm_device *dev, void *data, |
| 218 | struct drm_file *file_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 220 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 221 | return sis_drm_alloc(dev, file_priv, data, AGP_TYPE); |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 222 | } |
| 223 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 224 | static drm_local_map_t *sis_reg_init(struct drm_device *dev) |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 225 | { |
Dave Airlie | 5591051 | 2007-07-11 16:53:40 +1000 | [diff] [blame] | 226 | struct drm_map_list *entry; |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 227 | drm_local_map_t *map; |
| 228 | |
Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 229 | list_for_each_entry(entry, &dev->maplist, head) { |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 230 | map = entry->map; |
| 231 | if (!map) |
| 232 | continue; |
Nicolas Kaiser | a7b98b6 | 2010-07-09 16:47:28 +0200 | [diff] [blame] | 233 | if (map->type == _DRM_REGISTERS) |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 234 | return map; |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 235 | } |
| 236 | return NULL; |
| 237 | } |
| 238 | |
Dave Airlie | 84b1fd1 | 2007-07-11 15:53:27 +1000 | [diff] [blame] | 239 | int sis_idle(struct drm_device *dev) |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 240 | { |
| 241 | drm_sis_private_t *dev_priv = dev->dev_private; |
| 242 | uint32_t idle_reg; |
| 243 | unsigned long end; |
| 244 | int i; |
| 245 | |
| 246 | if (dev_priv->idle_fault) |
| 247 | return 0; |
| 248 | |
| 249 | if (dev_priv->mmio == NULL) { |
| 250 | dev_priv->mmio = sis_reg_init(dev); |
| 251 | if (dev_priv->mmio == NULL) { |
| 252 | DRM_ERROR("Could not find register map.\n"); |
| 253 | return 0; |
| 254 | } |
| 255 | } |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 256 | |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 257 | /* |
| 258 | * Implement a device switch here if needed |
| 259 | */ |
| 260 | |
| 261 | if (dev_priv->chipset != SIS_CHIP_315) |
| 262 | return 0; |
| 263 | |
| 264 | /* |
| 265 | * Timeout after 3 seconds. We cannot use DRM_WAIT_ON here |
| 266 | * because its polling frequency is too low. |
| 267 | */ |
| 268 | |
Daniel Vetter | bfd8303 | 2013-12-11 11:34:41 +0100 | [diff] [blame] | 269 | end = jiffies + (HZ * 3); |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 270 | |
Nicolas Kaiser | a7b98b6 | 2010-07-09 16:47:28 +0200 | [diff] [blame] | 271 | for (i = 0; i < 4; ++i) { |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 272 | do { |
| 273 | idle_reg = SIS_READ(0x85cc); |
Nicolas Kaiser | a7b98b6 | 2010-07-09 16:47:28 +0200 | [diff] [blame] | 274 | } while (!time_after_eq(jiffies, end) && |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 275 | ((idle_reg & 0x80000000) != 0x80000000)); |
| 276 | } |
| 277 | |
| 278 | if (time_after_eq(jiffies, end)) { |
| 279 | DRM_ERROR("Graphics engine idle timeout. " |
| 280 | "Disabling idle check\n"); |
Andrew Morton | a1d0fcf | 2006-08-14 11:35:15 +1000 | [diff] [blame] | 281 | dev_priv->idle_fault = 1; |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /* |
| 285 | * The caller never sees an error code. It gets trapped |
| 286 | * in libdrm. |
| 287 | */ |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 293 | void sis_lastclose(struct drm_device *dev) |
| 294 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | drm_sis_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 296 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 297 | if (!dev_priv) |
| 298 | return; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 299 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 300 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 301 | if (dev_priv->vram_initialized) { |
| 302 | drm_mm_takedown(&dev_priv->vram_mm); |
| 303 | dev_priv->vram_initialized = 0; |
| 304 | } |
| 305 | if (dev_priv->agp_initialized) { |
| 306 | drm_mm_takedown(&dev_priv->agp_mm); |
| 307 | dev_priv->agp_initialized = 0; |
| 308 | } |
Thomas Hellstrom | 7981bf7 | 2006-08-08 21:34:46 +1000 | [diff] [blame] | 309 | dev_priv->mmio = NULL; |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 310 | mutex_unlock(&dev->struct_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Nicolas Kaiser | a7b98b6 | 2010-07-09 16:47:28 +0200 | [diff] [blame] | 313 | void sis_reclaim_buffers_locked(struct drm_device *dev, |
Daniel Vetter | fdc0b8a | 2011-10-25 16:32:34 +0200 | [diff] [blame] | 314 | struct drm_file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | { |
Daniel Vetter | fdc0b8a | 2011-10-25 16:32:34 +0200 | [diff] [blame] | 316 | struct sis_file_private *file_priv = file->driver_priv; |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 317 | struct sis_memblock *entry, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Daniel Vetter | ea5e437 | 2011-10-25 23:42:59 +0200 | [diff] [blame] | 319 | if (!(file->minor->master && file->master->lock.hw_lock)) |
| 320 | return; |
| 321 | |
David Herrmann | bb6d822 | 2014-08-29 12:12:46 +0200 | [diff] [blame] | 322 | drm_legacy_idlelock_take(&file->master->lock); |
Daniel Vetter | ea5e437 | 2011-10-25 23:42:59 +0200 | [diff] [blame] | 323 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 324 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | fdc0b8a | 2011-10-25 16:32:34 +0200 | [diff] [blame] | 325 | if (list_empty(&file_priv->obj_list)) { |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 326 | mutex_unlock(&dev->struct_mutex); |
David Herrmann | bb6d822 | 2014-08-29 12:12:46 +0200 | [diff] [blame] | 327 | drm_legacy_idlelock_release(&file->master->lock); |
Daniel Vetter | ea5e437 | 2011-10-25 23:42:59 +0200 | [diff] [blame] | 328 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 329 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Daniel Vetter | ea5e437 | 2011-10-25 23:42:59 +0200 | [diff] [blame] | 332 | sis_idle(dev); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 333 | |
Daniel Vetter | fdc0b8a | 2011-10-25 16:32:34 +0200 | [diff] [blame] | 334 | |
| 335 | list_for_each_entry_safe(entry, next, &file_priv->obj_list, |
| 336 | owner_list) { |
Daniel Vetter | be2fb9d | 2011-10-26 22:22:59 +0200 | [diff] [blame] | 337 | list_del(&entry->owner_list); |
| 338 | if (drm_mm_node_allocated(&entry->mm_node)) |
| 339 | drm_mm_remove_node(&entry->mm_node); |
| 340 | #if defined(CONFIG_FB_SIS) || defined(CONFIG_FB_SIS_MODULE) |
| 341 | else |
| 342 | sis_free(entry->req.offset); |
| 343 | #endif |
| 344 | kfree(entry); |
Daniel Vetter | fdc0b8a | 2011-10-25 16:32:34 +0200 | [diff] [blame] | 345 | } |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 346 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | ea5e437 | 2011-10-25 23:42:59 +0200 | [diff] [blame] | 347 | |
David Herrmann | bb6d822 | 2014-08-29 12:12:46 +0200 | [diff] [blame] | 348 | drm_legacy_idlelock_release(&file->master->lock); |
Daniel Vetter | ea5e437 | 2011-10-25 23:42:59 +0200 | [diff] [blame] | 349 | |
Thomas Hellstrom | ce65a44 | 2006-08-07 22:03:22 +1000 | [diff] [blame] | 350 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Rob Clark | baa7094 | 2013-08-02 13:27:49 -0400 | [diff] [blame] | 353 | const struct drm_ioctl_desc sis_ioctls[] = { |
Dave Airlie | 1b2f148 | 2010-08-14 20:20:34 +1000 | [diff] [blame] | 354 | DRM_IOCTL_DEF_DRV(SIS_FB_ALLOC, sis_fb_alloc, DRM_AUTH), |
| 355 | DRM_IOCTL_DEF_DRV(SIS_FB_FREE, sis_drm_free, DRM_AUTH), |
| 356 | DRM_IOCTL_DEF_DRV(SIS_AGP_INIT, sis_ioctl_agp_init, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY), |
| 357 | DRM_IOCTL_DEF_DRV(SIS_AGP_ALLOC, sis_ioctl_agp_alloc, DRM_AUTH), |
| 358 | DRM_IOCTL_DEF_DRV(SIS_AGP_FREE, sis_drm_free, DRM_AUTH), |
| 359 | DRM_IOCTL_DEF_DRV(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] | 360 | }; |
| 361 | |
Damien Lespiau | f95aeb1 | 2014-06-09 14:39:49 +0100 | [diff] [blame] | 362 | int sis_max_ioctl = ARRAY_SIZE(sis_ioctls); |