| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /** | 
|  | 2 | * \file drm_stub.h | 
|  | 3 | * Stub support | 
|  | 4 | * | 
|  | 5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> | 
|  | 6 | */ | 
|  | 7 |  | 
|  | 8 | /* | 
|  | 9 | * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org | 
|  | 10 | * | 
|  | 11 | * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California. | 
|  | 12 | * All Rights Reserved. | 
|  | 13 | * | 
|  | 14 | * Permission is hereby granted, free of charge, to any person obtaining a | 
|  | 15 | * copy of this software and associated documentation files (the "Software"), | 
|  | 16 | * to deal in the Software without restriction, including without limitation | 
|  | 17 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
|  | 18 | * and/or sell copies of the Software, and to permit persons to whom the | 
|  | 19 | * Software is furnished to do so, subject to the following conditions: | 
|  | 20 | * | 
|  | 21 | * The above copyright notice and this permission notice (including the next | 
|  | 22 | * paragraph) shall be included in all copies or substantial portions of the | 
|  | 23 | * Software. | 
|  | 24 | * | 
|  | 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
|  | 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
|  | 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL | 
|  | 28 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | 
|  | 29 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | 
|  | 30 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 
|  | 31 | * DEALINGS IN THE SOFTWARE. | 
|  | 32 | */ | 
|  | 33 |  | 
|  | 34 | #include <linux/module.h> | 
|  | 35 | #include <linux/moduleparam.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 36 | #include <linux/slab.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include "drmP.h" | 
|  | 38 | #include "drm_core.h" | 
|  | 39 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 40 | unsigned int drm_debug = 0;	/* 1 to enable debug output */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | EXPORT_SYMBOL(drm_debug); | 
|  | 42 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 43 | MODULE_AUTHOR(CORE_AUTHOR); | 
|  | 44 | MODULE_DESCRIPTION(CORE_DESC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | MODULE_LICENSE("GPL and additional rights"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | MODULE_PARM_DESC(debug, "Enable debug output"); | 
|  | 47 |  | 
| Dave Jones | c075814 | 2005-10-03 15:02:20 -0400 | [diff] [blame] | 48 | module_param_named(debug, drm_debug, int, 0600); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 |  | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 50 | struct idr drm_minors_idr; | 
|  | 51 |  | 
| Greg Kroah-Hartman | 0650fd5 | 2006-01-20 14:08:59 -0800 | [diff] [blame] | 52 | struct class *drm_class; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct proc_dir_entry *drm_proc_root; | 
| Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 54 | struct dentry *drm_debugfs_root; | 
| yakui_zhao | 4fefcb2 | 2009-06-02 14:09:47 +0800 | [diff] [blame] | 55 | void drm_ut_debug_printk(unsigned int request_level, | 
|  | 56 | const char *prefix, | 
|  | 57 | const char *function_name, | 
|  | 58 | const char *format, ...) | 
|  | 59 | { | 
|  | 60 | va_list args; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 |  | 
| yakui_zhao | 4fefcb2 | 2009-06-02 14:09:47 +0800 | [diff] [blame] | 62 | if (drm_debug & request_level) { | 
|  | 63 | if (function_name) | 
|  | 64 | printk(KERN_DEBUG "[%s:%s], ", prefix, function_name); | 
|  | 65 | va_start(args, format); | 
|  | 66 | vprintk(format, args); | 
|  | 67 | va_end(args); | 
|  | 68 | } | 
|  | 69 | } | 
|  | 70 | EXPORT_SYMBOL(drm_ut_debug_printk); | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 71 | static int drm_minor_get_id(struct drm_device *dev, int type) | 
|  | 72 | { | 
|  | 73 | int new_id; | 
|  | 74 | int ret; | 
|  | 75 | int base = 0, limit = 63; | 
|  | 76 |  | 
| Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 77 | if (type == DRM_MINOR_CONTROL) { | 
|  | 78 | base += 64; | 
|  | 79 | limit = base + 127; | 
|  | 80 | } else if (type == DRM_MINOR_RENDER) { | 
|  | 81 | base += 128; | 
|  | 82 | limit = base + 255; | 
|  | 83 | } | 
|  | 84 |  | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 85 | again: | 
|  | 86 | if (idr_pre_get(&drm_minors_idr, GFP_KERNEL) == 0) { | 
|  | 87 | DRM_ERROR("Out of memory expanding drawable idr\n"); | 
|  | 88 | return -ENOMEM; | 
|  | 89 | } | 
|  | 90 | mutex_lock(&dev->struct_mutex); | 
|  | 91 | ret = idr_get_new_above(&drm_minors_idr, NULL, | 
|  | 92 | base, &new_id); | 
|  | 93 | mutex_unlock(&dev->struct_mutex); | 
|  | 94 | if (ret == -EAGAIN) { | 
|  | 95 | goto again; | 
|  | 96 | } else if (ret) { | 
|  | 97 | return ret; | 
|  | 98 | } | 
|  | 99 |  | 
|  | 100 | if (new_id >= limit) { | 
|  | 101 | idr_remove(&drm_minors_idr, new_id); | 
|  | 102 | return -EINVAL; | 
|  | 103 | } | 
|  | 104 | return new_id; | 
|  | 105 | } | 
|  | 106 |  | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 107 | struct drm_master *drm_master_create(struct drm_minor *minor) | 
|  | 108 | { | 
|  | 109 | struct drm_master *master; | 
|  | 110 |  | 
| Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 111 | master = kzalloc(sizeof(*master), GFP_KERNEL); | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 112 | if (!master) | 
|  | 113 | return NULL; | 
|  | 114 |  | 
|  | 115 | kref_init(&master->refcount); | 
|  | 116 | spin_lock_init(&master->lock.spinlock); | 
|  | 117 | init_waitqueue_head(&master->lock.lock_queue); | 
|  | 118 | drm_ht_create(&master->magiclist, DRM_MAGIC_HASH_ORDER); | 
|  | 119 | INIT_LIST_HEAD(&master->magicfree); | 
|  | 120 | master->minor = minor; | 
|  | 121 |  | 
|  | 122 | list_add_tail(&master->head, &minor->master_list); | 
|  | 123 |  | 
|  | 124 | return master; | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | struct drm_master *drm_master_get(struct drm_master *master) | 
|  | 128 | { | 
|  | 129 | kref_get(&master->refcount); | 
|  | 130 | return master; | 
|  | 131 | } | 
| Thomas Hellstrom | 85bb0c3 | 2009-12-06 21:46:28 +0100 | [diff] [blame] | 132 | EXPORT_SYMBOL(drm_master_get); | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 133 |  | 
|  | 134 | static void drm_master_destroy(struct kref *kref) | 
|  | 135 | { | 
|  | 136 | struct drm_master *master = container_of(kref, struct drm_master, refcount); | 
|  | 137 | struct drm_magic_entry *pt, *next; | 
|  | 138 | struct drm_device *dev = master->minor->dev; | 
| Dave Airlie | c1ff85d | 2009-01-19 17:17:58 +1000 | [diff] [blame] | 139 | struct drm_map_list *r_list, *list_temp; | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 140 |  | 
|  | 141 | list_del(&master->head); | 
|  | 142 |  | 
|  | 143 | if (dev->driver->master_destroy) | 
|  | 144 | dev->driver->master_destroy(dev, master); | 
|  | 145 |  | 
| Dave Airlie | c1ff85d | 2009-01-19 17:17:58 +1000 | [diff] [blame] | 146 | list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) { | 
|  | 147 | if (r_list->master == master) { | 
|  | 148 | drm_rmmap_locked(dev, r_list->map); | 
|  | 149 | r_list = NULL; | 
|  | 150 | } | 
|  | 151 | } | 
|  | 152 |  | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 153 | if (master->unique) { | 
| Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 154 | kfree(master->unique); | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 155 | master->unique = NULL; | 
|  | 156 | master->unique_len = 0; | 
|  | 157 | } | 
|  | 158 |  | 
| Chris Wilson | 6e35023 | 2010-07-24 18:29:36 +0100 | [diff] [blame] | 159 | kfree(dev->devname); | 
|  | 160 | dev->devname = NULL; | 
|  | 161 |  | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 162 | list_for_each_entry_safe(pt, next, &master->magicfree, head) { | 
|  | 163 | list_del(&pt->head); | 
|  | 164 | drm_ht_remove_item(&master->magiclist, &pt->hash_item); | 
| Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 165 | kfree(pt); | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 166 | } | 
|  | 167 |  | 
|  | 168 | drm_ht_remove(&master->magiclist); | 
|  | 169 |  | 
| Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 170 | kfree(master); | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 171 | } | 
|  | 172 |  | 
|  | 173 | void drm_master_put(struct drm_master **master) | 
|  | 174 | { | 
|  | 175 | kref_put(&(*master)->refcount, drm_master_destroy); | 
|  | 176 | *master = NULL; | 
|  | 177 | } | 
| Thomas Hellstrom | 85bb0c3 | 2009-12-06 21:46:28 +0100 | [diff] [blame] | 178 | EXPORT_SYMBOL(drm_master_put); | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 179 |  | 
|  | 180 | int drm_setmaster_ioctl(struct drm_device *dev, void *data, | 
|  | 181 | struct drm_file *file_priv) | 
|  | 182 | { | 
| Thomas Hellstrom | 862302f | 2009-12-02 18:15:25 +0000 | [diff] [blame] | 183 | int ret = 0; | 
|  | 184 |  | 
| Jonas Bonn | 6b00842 | 2009-04-16 09:00:02 +0200 | [diff] [blame] | 185 | if (file_priv->is_master) | 
|  | 186 | return 0; | 
|  | 187 |  | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 188 | if (file_priv->minor->master && file_priv->minor->master != file_priv->master) | 
|  | 189 | return -EINVAL; | 
|  | 190 |  | 
|  | 191 | if (!file_priv->master) | 
|  | 192 | return -EINVAL; | 
|  | 193 |  | 
|  | 194 | if (!file_priv->minor->master && | 
|  | 195 | file_priv->minor->master != file_priv->master) { | 
|  | 196 | mutex_lock(&dev->struct_mutex); | 
|  | 197 | file_priv->minor->master = drm_master_get(file_priv->master); | 
| Jonas Bonn | 6b00842 | 2009-04-16 09:00:02 +0200 | [diff] [blame] | 198 | file_priv->is_master = 1; | 
| Thomas Hellstrom | 862302f | 2009-12-02 18:15:25 +0000 | [diff] [blame] | 199 | if (dev->driver->master_set) { | 
|  | 200 | ret = dev->driver->master_set(dev, file_priv, false); | 
|  | 201 | if (unlikely(ret != 0)) { | 
|  | 202 | file_priv->is_master = 0; | 
|  | 203 | drm_master_put(&file_priv->minor->master); | 
|  | 204 | } | 
|  | 205 | } | 
| Helge Bahmann | 5ad8b7d | 2009-03-04 21:49:14 +1000 | [diff] [blame] | 206 | mutex_unlock(&dev->struct_mutex); | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 207 | } | 
|  | 208 |  | 
|  | 209 | return 0; | 
|  | 210 | } | 
|  | 211 |  | 
|  | 212 | int drm_dropmaster_ioctl(struct drm_device *dev, void *data, | 
|  | 213 | struct drm_file *file_priv) | 
|  | 214 | { | 
| Jonas Bonn | 6b00842 | 2009-04-16 09:00:02 +0200 | [diff] [blame] | 215 | if (!file_priv->is_master) | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 216 | return -EINVAL; | 
| Jonas Bonn | 6b00842 | 2009-04-16 09:00:02 +0200 | [diff] [blame] | 217 |  | 
| Dave Airlie | 07f1c7a | 2009-04-20 09:32:50 +1000 | [diff] [blame] | 218 | if (!file_priv->minor->master) | 
|  | 219 | return -EINVAL; | 
|  | 220 |  | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 221 | mutex_lock(&dev->struct_mutex); | 
| Thomas Hellstrom | 862302f | 2009-12-02 18:15:25 +0000 | [diff] [blame] | 222 | if (dev->driver->master_drop) | 
|  | 223 | dev->driver->master_drop(dev, file_priv, false); | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 224 | drm_master_put(&file_priv->minor->master); | 
| Jonas Bonn | 6b00842 | 2009-04-16 09:00:02 +0200 | [diff] [blame] | 225 | file_priv->is_master = 0; | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 226 | mutex_unlock(&dev->struct_mutex); | 
|  | 227 | return 0; | 
|  | 228 | } | 
|  | 229 |  | 
| Jordan Crouse | dcdb167 | 2010-05-27 13:40:25 -0600 | [diff] [blame] | 230 | int drm_fill_in_dev(struct drm_device *dev, | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 231 | const struct pci_device_id *ent, | 
|  | 232 | struct drm_driver *driver) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { | 
|  | 234 | int retcode; | 
|  | 235 |  | 
| Dave Airlie | bd1b331 | 2007-05-26 05:01:51 +1000 | [diff] [blame] | 236 | INIT_LIST_HEAD(&dev->filelist); | 
| Dave Airlie | 7c158ac | 2007-07-11 12:05:36 +1000 | [diff] [blame] | 237 | INIT_LIST_HEAD(&dev->ctxlist); | 
|  | 238 | INIT_LIST_HEAD(&dev->vmalist); | 
|  | 239 | INIT_LIST_HEAD(&dev->maplist); | 
| Kristian Høgsberg | c9a9c5e | 2009-09-12 04:33:34 +1000 | [diff] [blame] | 240 | INIT_LIST_HEAD(&dev->vblank_event_list); | 
| Dave Airlie | 7c158ac | 2007-07-11 12:05:36 +1000 | [diff] [blame] | 241 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | spin_lock_init(&dev->count_lock); | 
| =?utf-8?q?Michel_D=C3=A4nzer?= | bea5679 | 2006-10-24 23:04:19 +1000 | [diff] [blame] | 243 | spin_lock_init(&dev->drw_lock); | 
| Kristian Høgsberg | c9a9c5e | 2009-09-12 04:33:34 +1000 | [diff] [blame] | 244 | spin_lock_init(&dev->event_lock); | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 245 | init_timer(&dev->timer); | 
| Dave Airlie | 30e2fb1 | 2006-02-02 19:37:46 +1100 | [diff] [blame] | 246 | mutex_init(&dev->struct_mutex); | 
|  | 247 | mutex_init(&dev->ctxlist_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 |  | 
| Dave Airlie | 45ea5dcd | 2007-07-17 14:20:07 +1000 | [diff] [blame] | 249 | idr_init(&dev->drw_idr); | 
|  | 250 |  | 
| Thomas Hellstrom | 8d153f7 | 2006-08-07 22:36:47 +1000 | [diff] [blame] | 251 | if (drm_ht_create(&dev->map_hash, 12)) { | 
| Thomas Hellstrom | 8d153f7 | 2006-08-07 22:36:47 +1000 | [diff] [blame] | 252 | return -ENOMEM; | 
|  | 253 | } | 
| Dave Airlie | 836cf04 | 2005-07-10 19:27:04 +1000 | [diff] [blame] | 254 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /* the DRM has 6 basic counters */ | 
|  | 256 | dev->counters = 6; | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 257 | dev->types[0] = _DRM_STAT_LOCK; | 
|  | 258 | dev->types[1] = _DRM_STAT_OPENS; | 
|  | 259 | dev->types[2] = _DRM_STAT_CLOSES; | 
|  | 260 | dev->types[3] = _DRM_STAT_IOCTLS; | 
|  | 261 | dev->types[4] = _DRM_STAT_LOCKS; | 
|  | 262 | dev->types[5] = _DRM_STAT_UNLOCKS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 |  | 
|  | 264 | dev->driver = driver; | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 265 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | if (drm_core_has_AGP(dev)) { | 
| Dave Airlie | cda1738 | 2005-07-10 17:31:26 +1000 | [diff] [blame] | 267 | if (drm_device_is_agp(dev)) | 
|  | 268 | dev->agp = drm_agp_init(dev); | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 269 | if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP) | 
|  | 270 | && (dev->agp == NULL)) { | 
|  | 271 | DRM_ERROR("Cannot initialize the agpgart module.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | retcode = -EINVAL; | 
|  | 273 | goto error_out_unreg; | 
|  | 274 | } | 
|  | 275 | if (drm_core_has_MTRR(dev)) { | 
|  | 276 | if (dev->agp) | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 277 | dev->agp->agp_mtrr = | 
|  | 278 | mtrr_add(dev->agp->agp_info.aper_base, | 
|  | 279 | dev->agp->agp_info.aper_size * | 
|  | 280 | 1024 * 1024, MTRR_TYPE_WRCOMB, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } | 
|  | 282 | } | 
|  | 283 |  | 
| Dave Airlie | 2716a02 | 2007-11-22 18:23:13 +1000 | [diff] [blame] | 284 |  | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 285 | retcode = drm_ctxbitmap_init(dev); | 
|  | 286 | if (retcode) { | 
|  | 287 | DRM_ERROR("Cannot allocate memory for context bitmap.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | goto error_out_unreg; | 
|  | 289 | } | 
|  | 290 |  | 
| Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 291 | if (driver->driver_features & DRIVER_GEM) { | 
|  | 292 | retcode = drm_gem_init(dev); | 
|  | 293 | if (retcode) { | 
|  | 294 | DRM_ERROR("Cannot initialize graphics execution " | 
|  | 295 | "manager (GEM)\n"); | 
|  | 296 | goto error_out_unreg; | 
|  | 297 | } | 
|  | 298 | } | 
|  | 299 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | return 0; | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 301 |  | 
|  | 302 | error_out_unreg: | 
| Dave Airlie | 22eae94 | 2005-11-10 22:16:34 +1100 | [diff] [blame] | 303 | drm_lastclose(dev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | return retcode; | 
|  | 305 | } | 
|  | 306 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | /** | 
|  | 309 | * Get a secondary minor number. | 
|  | 310 | * | 
|  | 311 | * \param dev device data structure | 
|  | 312 | * \param sec-minor structure to hold the assigned minor | 
|  | 313 | * \return negative number on failure. | 
|  | 314 | * | 
|  | 315 | * Search an empty entry and initialize it to the given parameters, and | 
|  | 316 | * create the proc init entry via proc_init(). This routines assigns | 
|  | 317 | * minor numbers to secondary heads of multi-headed cards | 
|  | 318 | */ | 
| Jordan Crouse | dcdb167 | 2010-05-27 13:40:25 -0600 | [diff] [blame] | 319 | int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 321 | struct drm_minor *new_minor; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | int ret; | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 323 | int minor_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 |  | 
|  | 325 | DRM_DEBUG("\n"); | 
|  | 326 |  | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 327 | minor_id = drm_minor_get_id(dev, type); | 
|  | 328 | if (minor_id < 0) | 
|  | 329 | return minor_id; | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 330 |  | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 331 | new_minor = kzalloc(sizeof(struct drm_minor), GFP_KERNEL); | 
|  | 332 | if (!new_minor) { | 
|  | 333 | ret = -ENOMEM; | 
|  | 334 | goto err_idr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 336 |  | 
|  | 337 | new_minor->type = type; | 
|  | 338 | new_minor->device = MKDEV(DRM_MAJOR, minor_id); | 
|  | 339 | new_minor->dev = dev; | 
|  | 340 | new_minor->index = minor_id; | 
| Dave Airlie | 7c1c287 | 2008-11-28 14:22:24 +1000 | [diff] [blame] | 341 | INIT_LIST_HEAD(&new_minor->master_list); | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 342 |  | 
|  | 343 | idr_replace(&drm_minors_idr, new_minor, minor_id); | 
|  | 344 |  | 
|  | 345 | if (type == DRM_MINOR_LEGACY) { | 
|  | 346 | ret = drm_proc_init(new_minor, minor_id, drm_proc_root); | 
|  | 347 | if (ret) { | 
|  | 348 | DRM_ERROR("DRM: Failed to initialize /proc/dri.\n"); | 
|  | 349 | goto err_mem; | 
|  | 350 | } | 
|  | 351 | } else | 
| Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 352 | new_minor->proc_root = NULL; | 
|  | 353 |  | 
|  | 354 | #if defined(CONFIG_DEBUG_FS) | 
|  | 355 | ret = drm_debugfs_init(new_minor, minor_id, drm_debugfs_root); | 
|  | 356 | if (ret) { | 
| GeunSik Lim | 156f5a7 | 2009-06-02 15:01:37 +0900 | [diff] [blame] | 357 | DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); | 
| Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 358 | goto err_g2; | 
|  | 359 | } | 
|  | 360 | #endif | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 361 |  | 
|  | 362 | ret = drm_sysfs_device_add(new_minor); | 
|  | 363 | if (ret) { | 
|  | 364 | printk(KERN_ERR | 
|  | 365 | "DRM: Error sysfs_device_add.\n"); | 
|  | 366 | goto err_g2; | 
|  | 367 | } | 
|  | 368 | *minor = new_minor; | 
|  | 369 |  | 
|  | 370 | DRM_DEBUG("new minor assigned %d\n", minor_id); | 
|  | 371 | return 0; | 
|  | 372 |  | 
|  | 373 |  | 
|  | 374 | err_g2: | 
|  | 375 | if (new_minor->type == DRM_MINOR_LEGACY) | 
|  | 376 | drm_proc_cleanup(new_minor, drm_proc_root); | 
|  | 377 | err_mem: | 
|  | 378 | kfree(new_minor); | 
|  | 379 | err_idr: | 
|  | 380 | idr_remove(&drm_minors_idr, minor_id); | 
|  | 381 | *minor = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | return ret; | 
|  | 383 | } | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 384 |  | 
| Dave Airlie | c94f702 | 2005-07-07 21:03:38 +1000 | [diff] [blame] | 385 | /** | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | * Put a secondary minor number. | 
|  | 387 | * | 
|  | 388 | * \param sec_minor - structure to be released | 
|  | 389 | * \return always zero | 
|  | 390 | * | 
|  | 391 | * Cleans up the proc resources. Not legal for this to be the | 
|  | 392 | * last minor released. | 
|  | 393 | * | 
|  | 394 | */ | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 395 | int drm_put_minor(struct drm_minor **minor_p) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 397 | struct drm_minor *minor = *minor_p; | 
| Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 398 |  | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 399 | DRM_DEBUG("release secondary minor %d\n", minor->index); | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 400 |  | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 401 | if (minor->type == DRM_MINOR_LEGACY) | 
|  | 402 | drm_proc_cleanup(minor, drm_proc_root); | 
| Ben Gamari | 955b12d | 2009-02-17 20:08:49 -0500 | [diff] [blame] | 403 | #if defined(CONFIG_DEBUG_FS) | 
|  | 404 | drm_debugfs_cleanup(minor); | 
|  | 405 | #endif | 
|  | 406 |  | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 407 | drm_sysfs_device_remove(minor); | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 408 |  | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 409 | idr_remove(&drm_minors_idr, minor->index); | 
| Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 410 |  | 
| Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 411 | kfree(minor); | 
|  | 412 | *minor_p = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return 0; | 
|  | 414 | } | 
| Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 415 |  | 
|  | 416 | /** | 
|  | 417 | * Called via drm_exit() at module unload time or when pci device is | 
|  | 418 | * unplugged. | 
|  | 419 | * | 
|  | 420 | * Cleans up all DRM device, calling drm_lastclose(). | 
|  | 421 | * | 
|  | 422 | * \sa drm_init | 
|  | 423 | */ | 
|  | 424 | void drm_put_dev(struct drm_device *dev) | 
|  | 425 | { | 
| Julia Lawall | ecca068 | 2009-07-11 09:50:09 +0200 | [diff] [blame] | 426 | struct drm_driver *driver; | 
| Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 427 | struct drm_map_list *r_list, *list_temp; | 
|  | 428 |  | 
|  | 429 | DRM_DEBUG("\n"); | 
|  | 430 |  | 
|  | 431 | if (!dev) { | 
|  | 432 | DRM_ERROR("cleanup called no dev\n"); | 
|  | 433 | return; | 
|  | 434 | } | 
| Julia Lawall | ecca068 | 2009-07-11 09:50:09 +0200 | [diff] [blame] | 435 | driver = dev->driver; | 
| Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 436 |  | 
| Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 437 | drm_lastclose(dev); | 
|  | 438 |  | 
|  | 439 | if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && | 
|  | 440 | dev->agp && dev->agp->agp_mtrr >= 0) { | 
|  | 441 | int retval; | 
|  | 442 | retval = mtrr_del(dev->agp->agp_mtrr, | 
|  | 443 | dev->agp->agp_info.aper_base, | 
|  | 444 | dev->agp->agp_info.aper_size * 1024 * 1024); | 
|  | 445 | DRM_DEBUG("mtrr_del=%d\n", retval); | 
|  | 446 | } | 
|  | 447 |  | 
|  | 448 | if (dev->driver->unload) | 
|  | 449 | dev->driver->unload(dev); | 
|  | 450 |  | 
|  | 451 | if (drm_core_has_AGP(dev) && dev->agp) { | 
| Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 452 | kfree(dev->agp); | 
| Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 453 | dev->agp = NULL; | 
|  | 454 | } | 
|  | 455 |  | 
| Jesse Barnes | b78315f | 2010-03-26 11:07:16 -0700 | [diff] [blame] | 456 | drm_vblank_cleanup(dev); | 
|  | 457 |  | 
| Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 458 | list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) | 
|  | 459 | drm_rmmap(dev, r_list->map); | 
| Ben Skeggs | 30ddbd9 | 2009-03-02 11:13:04 +1000 | [diff] [blame] | 460 | drm_ht_remove(&dev->map_hash); | 
|  | 461 |  | 
|  | 462 | drm_ctxbitmap_cleanup(dev); | 
| Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 463 |  | 
|  | 464 | if (drm_core_check_feature(dev, DRIVER_MODESET)) | 
|  | 465 | drm_put_minor(&dev->control); | 
|  | 466 |  | 
|  | 467 | if (driver->driver_features & DRIVER_GEM) | 
|  | 468 | drm_gem_destroy(dev); | 
|  | 469 |  | 
|  | 470 | drm_put_minor(&dev->primary); | 
|  | 471 |  | 
|  | 472 | if (dev->devname) { | 
| Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 473 | kfree(dev->devname); | 
| Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 474 | dev->devname = NULL; | 
|  | 475 | } | 
| Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 476 | kfree(dev); | 
| Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 477 | } | 
|  | 478 | EXPORT_SYMBOL(drm_put_dev); |