]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
5a0e3ad6 | 36 | #include <linux/slab.h> |
1da177e4 LT |
37 | #include "drmP.h" |
38 | #include "drm_core.h" | |
39 | ||
b5e89ed5 | 40 | unsigned int drm_debug = 0; /* 1 to enable debug output */ |
1da177e4 LT |
41 | EXPORT_SYMBOL(drm_debug); |
42 | ||
b5e89ed5 DA |
43 | MODULE_AUTHOR(CORE_AUTHOR); |
44 | MODULE_DESCRIPTION(CORE_DESC); | |
1da177e4 | 45 | MODULE_LICENSE("GPL and additional rights"); |
1da177e4 LT |
46 | MODULE_PARM_DESC(debug, "Enable debug output"); |
47 | ||
c0758146 | 48 | module_param_named(debug, drm_debug, int, 0600); |
1da177e4 | 49 | |
2c14f28b DA |
50 | struct idr drm_minors_idr; |
51 | ||
0650fd58 | 52 | struct class *drm_class; |
1da177e4 | 53 | struct proc_dir_entry *drm_proc_root; |
955b12de | 54 | struct dentry *drm_debugfs_root; |
4fefcb27 | 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; | |
1da177e4 | 61 | |
4fefcb27 | 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); | |
2c14f28b DA |
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 | ||
f453ba04 DA |
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 | ||
2c14f28b DA |
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 | ||
7c1c2871 DA |
107 | struct drm_master *drm_master_create(struct drm_minor *minor) |
108 | { | |
109 | struct drm_master *master; | |
110 | ||
9a298b2a | 111 | master = kzalloc(sizeof(*master), GFP_KERNEL); |
7c1c2871 DA |
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 | } | |
85bb0c37 | 132 | EXPORT_SYMBOL(drm_master_get); |
7c1c2871 DA |
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; | |
c1ff85d9 | 139 | struct drm_map_list *r_list, *list_temp; |
7c1c2871 DA |
140 | |
141 | list_del(&master->head); | |
142 | ||
143 | if (dev->driver->master_destroy) | |
144 | dev->driver->master_destroy(dev, master); | |
145 | ||
c1ff85d9 DA |
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 | ||
7c1c2871 | 153 | if (master->unique) { |
9a298b2a | 154 | kfree(master->unique); |
7c1c2871 DA |
155 | master->unique = NULL; |
156 | master->unique_len = 0; | |
157 | } | |
158 | ||
159 | list_for_each_entry_safe(pt, next, &master->magicfree, head) { | |
160 | list_del(&pt->head); | |
161 | drm_ht_remove_item(&master->magiclist, &pt->hash_item); | |
9a298b2a | 162 | kfree(pt); |
7c1c2871 DA |
163 | } |
164 | ||
165 | drm_ht_remove(&master->magiclist); | |
166 | ||
9a298b2a | 167 | kfree(master); |
7c1c2871 DA |
168 | } |
169 | ||
170 | void drm_master_put(struct drm_master **master) | |
171 | { | |
172 | kref_put(&(*master)->refcount, drm_master_destroy); | |
173 | *master = NULL; | |
174 | } | |
85bb0c37 | 175 | EXPORT_SYMBOL(drm_master_put); |
7c1c2871 DA |
176 | |
177 | int drm_setmaster_ioctl(struct drm_device *dev, void *data, | |
178 | struct drm_file *file_priv) | |
179 | { | |
862302ff TH |
180 | int ret = 0; |
181 | ||
6b008426 JB |
182 | if (file_priv->is_master) |
183 | return 0; | |
184 | ||
7c1c2871 DA |
185 | if (file_priv->minor->master && file_priv->minor->master != file_priv->master) |
186 | return -EINVAL; | |
187 | ||
188 | if (!file_priv->master) | |
189 | return -EINVAL; | |
190 | ||
191 | if (!file_priv->minor->master && | |
192 | file_priv->minor->master != file_priv->master) { | |
193 | mutex_lock(&dev->struct_mutex); | |
194 | file_priv->minor->master = drm_master_get(file_priv->master); | |
6b008426 | 195 | file_priv->is_master = 1; |
862302ff TH |
196 | if (dev->driver->master_set) { |
197 | ret = dev->driver->master_set(dev, file_priv, false); | |
198 | if (unlikely(ret != 0)) { | |
199 | file_priv->is_master = 0; | |
200 | drm_master_put(&file_priv->minor->master); | |
201 | } | |
202 | } | |
5ad8b7d1 | 203 | mutex_unlock(&dev->struct_mutex); |
7c1c2871 DA |
204 | } |
205 | ||
206 | return 0; | |
207 | } | |
208 | ||
209 | int drm_dropmaster_ioctl(struct drm_device *dev, void *data, | |
210 | struct drm_file *file_priv) | |
211 | { | |
6b008426 | 212 | if (!file_priv->is_master) |
7c1c2871 | 213 | return -EINVAL; |
6b008426 | 214 | |
07f1c7a7 DA |
215 | if (!file_priv->minor->master) |
216 | return -EINVAL; | |
217 | ||
7c1c2871 | 218 | mutex_lock(&dev->struct_mutex); |
862302ff TH |
219 | if (dev->driver->master_drop) |
220 | dev->driver->master_drop(dev, file_priv, false); | |
7c1c2871 | 221 | drm_master_put(&file_priv->minor->master); |
6b008426 | 222 | file_priv->is_master = 0; |
7c1c2871 DA |
223 | mutex_unlock(&dev->struct_mutex); |
224 | return 0; | |
225 | } | |
226 | ||
84b1fd10 | 227 | static int drm_fill_in_dev(struct drm_device * dev, struct pci_dev *pdev, |
b5e89ed5 DA |
228 | const struct pci_device_id *ent, |
229 | struct drm_driver *driver) | |
1da177e4 LT |
230 | { |
231 | int retcode; | |
232 | ||
bd1b331f | 233 | INIT_LIST_HEAD(&dev->filelist); |
7c158ace DA |
234 | INIT_LIST_HEAD(&dev->ctxlist); |
235 | INIT_LIST_HEAD(&dev->vmalist); | |
236 | INIT_LIST_HEAD(&dev->maplist); | |
c9a9c5e0 | 237 | INIT_LIST_HEAD(&dev->vblank_event_list); |
7c158ace | 238 | |
1da177e4 | 239 | spin_lock_init(&dev->count_lock); |
bea5679f | 240 | spin_lock_init(&dev->drw_lock); |
c9a9c5e0 | 241 | spin_lock_init(&dev->event_lock); |
b5e89ed5 | 242 | init_timer(&dev->timer); |
30e2fb18 DA |
243 | mutex_init(&dev->struct_mutex); |
244 | mutex_init(&dev->ctxlist_mutex); | |
1da177e4 | 245 | |
45ea5dcd DA |
246 | idr_init(&dev->drw_idr); |
247 | ||
b5e89ed5 | 248 | dev->pdev = pdev; |
2f02cc3f EA |
249 | dev->pci_device = pdev->device; |
250 | dev->pci_vendor = pdev->vendor; | |
1da177e4 LT |
251 | |
252 | #ifdef __alpha__ | |
b5e89ed5 | 253 | dev->hose = pdev->sysdata; |
1da177e4 | 254 | #endif |
1da177e4 | 255 | |
8d153f71 | 256 | if (drm_ht_create(&dev->map_hash, 12)) { |
8d153f71 TH |
257 | return -ENOMEM; |
258 | } | |
836cf046 | 259 | |
1da177e4 LT |
260 | /* the DRM has 6 basic counters */ |
261 | dev->counters = 6; | |
b5e89ed5 DA |
262 | dev->types[0] = _DRM_STAT_LOCK; |
263 | dev->types[1] = _DRM_STAT_OPENS; | |
264 | dev->types[2] = _DRM_STAT_CLOSES; | |
265 | dev->types[3] = _DRM_STAT_IOCTLS; | |
266 | dev->types[4] = _DRM_STAT_LOCKS; | |
267 | dev->types[5] = _DRM_STAT_UNLOCKS; | |
1da177e4 LT |
268 | |
269 | dev->driver = driver; | |
b5e89ed5 | 270 | |
1da177e4 | 271 | if (drm_core_has_AGP(dev)) { |
cda17380 DA |
272 | if (drm_device_is_agp(dev)) |
273 | dev->agp = drm_agp_init(dev); | |
b5e89ed5 DA |
274 | if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP) |
275 | && (dev->agp == NULL)) { | |
276 | DRM_ERROR("Cannot initialize the agpgart module.\n"); | |
1da177e4 LT |
277 | retcode = -EINVAL; |
278 | goto error_out_unreg; | |
279 | } | |
280 | if (drm_core_has_MTRR(dev)) { | |
281 | if (dev->agp) | |
b5e89ed5 DA |
282 | dev->agp->agp_mtrr = |
283 | mtrr_add(dev->agp->agp_info.aper_base, | |
284 | dev->agp->agp_info.aper_size * | |
285 | 1024 * 1024, MTRR_TYPE_WRCOMB, 1); | |
1da177e4 LT |
286 | } |
287 | } | |
288 | ||
2716a02f | 289 | |
b5e89ed5 DA |
290 | retcode = drm_ctxbitmap_init(dev); |
291 | if (retcode) { | |
292 | DRM_ERROR("Cannot allocate memory for context bitmap.\n"); | |
1da177e4 LT |
293 | goto error_out_unreg; |
294 | } | |
295 | ||
673a394b EA |
296 | if (driver->driver_features & DRIVER_GEM) { |
297 | retcode = drm_gem_init(dev); | |
298 | if (retcode) { | |
299 | DRM_ERROR("Cannot initialize graphics execution " | |
300 | "manager (GEM)\n"); | |
301 | goto error_out_unreg; | |
302 | } | |
303 | } | |
304 | ||
1da177e4 | 305 | return 0; |
b5e89ed5 DA |
306 | |
307 | error_out_unreg: | |
22eae947 | 308 | drm_lastclose(dev); |
1da177e4 LT |
309 | return retcode; |
310 | } | |
311 | ||
1da177e4 | 312 | |
1da177e4 LT |
313 | /** |
314 | * Get a secondary minor number. | |
315 | * | |
316 | * \param dev device data structure | |
317 | * \param sec-minor structure to hold the assigned minor | |
318 | * \return negative number on failure. | |
319 | * | |
320 | * Search an empty entry and initialize it to the given parameters, and | |
321 | * create the proc init entry via proc_init(). This routines assigns | |
322 | * minor numbers to secondary heads of multi-headed cards | |
323 | */ | |
2c14f28b | 324 | static int drm_get_minor(struct drm_device *dev, struct drm_minor **minor, int type) |
1da177e4 | 325 | { |
2c14f28b | 326 | struct drm_minor *new_minor; |
1da177e4 | 327 | int ret; |
2c14f28b | 328 | int minor_id; |
1da177e4 LT |
329 | |
330 | DRM_DEBUG("\n"); | |
331 | ||
2c14f28b DA |
332 | minor_id = drm_minor_get_id(dev, type); |
333 | if (minor_id < 0) | |
334 | return minor_id; | |
335 | ||
336 | new_minor = kzalloc(sizeof(struct drm_minor), GFP_KERNEL); | |
337 | if (!new_minor) { | |
338 | ret = -ENOMEM; | |
339 | goto err_idr; | |
340 | } | |
341 | ||
342 | new_minor->type = type; | |
343 | new_minor->device = MKDEV(DRM_MAJOR, minor_id); | |
344 | new_minor->dev = dev; | |
345 | new_minor->index = minor_id; | |
7c1c2871 | 346 | INIT_LIST_HEAD(&new_minor->master_list); |
2c14f28b DA |
347 | |
348 | idr_replace(&drm_minors_idr, new_minor, minor_id); | |
349 | ||
350 | if (type == DRM_MINOR_LEGACY) { | |
351 | ret = drm_proc_init(new_minor, minor_id, drm_proc_root); | |
352 | if (ret) { | |
353 | DRM_ERROR("DRM: Failed to initialize /proc/dri.\n"); | |
354 | goto err_mem; | |
1da177e4 | 355 | } |
2c14f28b | 356 | } else |
955b12de BG |
357 | new_minor->proc_root = NULL; |
358 | ||
359 | #if defined(CONFIG_DEBUG_FS) | |
360 | ret = drm_debugfs_init(new_minor, minor_id, drm_debugfs_root); | |
361 | if (ret) { | |
156f5a78 | 362 | DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); |
955b12de BG |
363 | goto err_g2; |
364 | } | |
365 | #endif | |
2c14f28b DA |
366 | |
367 | ret = drm_sysfs_device_add(new_minor); | |
368 | if (ret) { | |
369 | printk(KERN_ERR | |
370 | "DRM: Error sysfs_device_add.\n"); | |
371 | goto err_g2; | |
1da177e4 | 372 | } |
2c14f28b DA |
373 | *minor = new_minor; |
374 | ||
375 | DRM_DEBUG("new minor assigned %d\n", minor_id); | |
376 | return 0; | |
377 | ||
378 | ||
379 | err_g2: | |
380 | if (new_minor->type == DRM_MINOR_LEGACY) | |
381 | drm_proc_cleanup(new_minor, drm_proc_root); | |
382 | err_mem: | |
383 | kfree(new_minor); | |
384 | err_idr: | |
385 | idr_remove(&drm_minors_idr, minor_id); | |
386 | *minor = NULL; | |
1da177e4 LT |
387 | return ret; |
388 | } | |
b5e89ed5 | 389 | |
c94f7029 DA |
390 | /** |
391 | * Register. | |
392 | * | |
393 | * \param pdev - PCI device structure | |
394 | * \param ent entry from the PCI ID table with device type flags | |
395 | * \return zero on success or a negative number on failure. | |
396 | * | |
397 | * Attempt to gets inter module "drm" information. If we are first | |
398 | * then register the character device and inter module information. | |
399 | * Try and register, if we fail to register, backout previous work. | |
400 | */ | |
401 | int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent, | |
b5e89ed5 | 402 | struct drm_driver *driver) |
c94f7029 | 403 | { |
84b1fd10 | 404 | struct drm_device *dev; |
c94f7029 DA |
405 | int ret; |
406 | ||
407 | DRM_DEBUG("\n"); | |
408 | ||
9a298b2a | 409 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
c94f7029 DA |
410 | if (!dev) |
411 | return -ENOMEM; | |
412 | ||
2c3f0edd JG |
413 | ret = pci_enable_device(pdev); |
414 | if (ret) | |
415 | goto err_g1; | |
c94f7029 | 416 | |
19a8f59a | 417 | pci_set_master(pdev); |
c94f7029 DA |
418 | if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) { |
419 | printk(KERN_ERR "DRM: Fill_in_dev failed.\n"); | |
2c3f0edd | 420 | goto err_g2; |
c94f7029 | 421 | } |
f453ba04 DA |
422 | |
423 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { | |
112b715e | 424 | pci_set_drvdata(pdev, dev); |
f453ba04 DA |
425 | ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL); |
426 | if (ret) | |
427 | goto err_g2; | |
428 | } | |
429 | ||
2c14f28b | 430 | if ((ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY))) |
f453ba04 | 431 | goto err_g3; |
bc5f4523 | 432 | |
f453ba04 DA |
433 | if (dev->driver->load) { |
434 | ret = dev->driver->load(dev, ent->driver_data); | |
435 | if (ret) | |
3788f48a | 436 | goto err_g4; |
f453ba04 DA |
437 | } |
438 | ||
439 | /* setup the grouping for the legacy output */ | |
440 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { | |
441 | ret = drm_mode_group_init_legacy_group(dev, &dev->primary->mode_group); | |
442 | if (ret) | |
3788f48a | 443 | goto err_g4; |
f453ba04 | 444 | } |
a9d51a5a | 445 | |
e7f7ab45 DA |
446 | list_add_tail(&dev->driver_item, &driver->device_list); |
447 | ||
cd00f95a | 448 | DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n", |
22eae947 | 449 | driver->name, driver->major, driver->minor, driver->patchlevel, |
cd00f95a | 450 | driver->date, pci_name(pdev), dev->primary->index); |
c94f7029 DA |
451 | |
452 | return 0; | |
453 | ||
3788f48a | 454 | err_g4: |
a9d51a5a | 455 | drm_put_minor(&dev->primary); |
3788f48a BS |
456 | err_g3: |
457 | if (drm_core_check_feature(dev, DRIVER_MODESET)) | |
458 | drm_put_minor(&dev->control); | |
2c3f0edd JG |
459 | err_g2: |
460 | pci_disable_device(pdev); | |
461 | err_g1: | |
9a298b2a | 462 | kfree(dev); |
c94f7029 DA |
463 | return ret; |
464 | } | |
112b715e | 465 | EXPORT_SYMBOL(drm_get_dev); |
1da177e4 LT |
466 | |
467 | /** | |
468 | * Put a secondary minor number. | |
469 | * | |
470 | * \param sec_minor - structure to be released | |
471 | * \return always zero | |
472 | * | |
473 | * Cleans up the proc resources. Not legal for this to be the | |
474 | * last minor released. | |
475 | * | |
476 | */ | |
2c14f28b | 477 | int drm_put_minor(struct drm_minor **minor_p) |
1da177e4 | 478 | { |
2c14f28b | 479 | struct drm_minor *minor = *minor_p; |
673a394b | 480 | |
2c14f28b | 481 | DRM_DEBUG("release secondary minor %d\n", minor->index); |
b5e89ed5 | 482 | |
2c14f28b DA |
483 | if (minor->type == DRM_MINOR_LEGACY) |
484 | drm_proc_cleanup(minor, drm_proc_root); | |
955b12de BG |
485 | #if defined(CONFIG_DEBUG_FS) |
486 | drm_debugfs_cleanup(minor); | |
487 | #endif | |
488 | ||
2c14f28b | 489 | drm_sysfs_device_remove(minor); |
1da177e4 | 490 | |
2c14f28b | 491 | idr_remove(&drm_minors_idr, minor->index); |
b5e89ed5 | 492 | |
2c14f28b DA |
493 | kfree(minor); |
494 | *minor_p = NULL; | |
1da177e4 LT |
495 | return 0; |
496 | } | |
112b715e KH |
497 | |
498 | /** | |
499 | * Called via drm_exit() at module unload time or when pci device is | |
500 | * unplugged. | |
501 | * | |
502 | * Cleans up all DRM device, calling drm_lastclose(). | |
503 | * | |
504 | * \sa drm_init | |
505 | */ | |
506 | void drm_put_dev(struct drm_device *dev) | |
507 | { | |
ecca0683 | 508 | struct drm_driver *driver; |
112b715e KH |
509 | struct drm_map_list *r_list, *list_temp; |
510 | ||
511 | DRM_DEBUG("\n"); | |
512 | ||
513 | if (!dev) { | |
514 | DRM_ERROR("cleanup called no dev\n"); | |
515 | return; | |
516 | } | |
ecca0683 | 517 | driver = dev->driver; |
112b715e KH |
518 | |
519 | drm_vblank_cleanup(dev); | |
520 | ||
521 | drm_lastclose(dev); | |
522 | ||
523 | if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && | |
524 | dev->agp && dev->agp->agp_mtrr >= 0) { | |
525 | int retval; | |
526 | retval = mtrr_del(dev->agp->agp_mtrr, | |
527 | dev->agp->agp_info.aper_base, | |
528 | dev->agp->agp_info.aper_size * 1024 * 1024); | |
529 | DRM_DEBUG("mtrr_del=%d\n", retval); | |
530 | } | |
531 | ||
532 | if (dev->driver->unload) | |
533 | dev->driver->unload(dev); | |
534 | ||
535 | if (drm_core_has_AGP(dev) && dev->agp) { | |
9a298b2a | 536 | kfree(dev->agp); |
112b715e KH |
537 | dev->agp = NULL; |
538 | } | |
539 | ||
112b715e KH |
540 | list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) |
541 | drm_rmmap(dev, r_list->map); | |
30ddbd94 BS |
542 | drm_ht_remove(&dev->map_hash); |
543 | ||
544 | drm_ctxbitmap_cleanup(dev); | |
112b715e KH |
545 | |
546 | if (drm_core_check_feature(dev, DRIVER_MODESET)) | |
547 | drm_put_minor(&dev->control); | |
548 | ||
549 | if (driver->driver_features & DRIVER_GEM) | |
550 | drm_gem_destroy(dev); | |
551 | ||
552 | drm_put_minor(&dev->primary); | |
553 | ||
554 | if (dev->devname) { | |
9a298b2a | 555 | kfree(dev->devname); |
112b715e KH |
556 | dev->devname = NULL; |
557 | } | |
9a298b2a | 558 | kfree(dev); |
112b715e KH |
559 | } |
560 | EXPORT_SYMBOL(drm_put_dev); |