3 * Generic driver template
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
8 * To use this template, you must at least define the following (samples
9 * given for the MGA driver):
12 * #define DRIVER_AUTHOR "VA Linux Systems, Inc."
14 * #define DRIVER_NAME "mga"
15 * #define DRIVER_DESC "Matrox G200/G400"
16 * #define DRIVER_DATE "20001127"
18 * #define drm_x mga_##x
23 * Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
25 * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
26 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
27 * All Rights Reserved.
29 * Permission is hereby granted, free of charge, to any person obtaining a
30 * copy of this software and associated documentation files (the "Software"),
31 * to deal in the Software without restriction, including without limitation
32 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
33 * and/or sell copies of the Software, and to permit persons to whom the
34 * Software is furnished to do so, subject to the following conditions:
36 * The above copyright notice and this permission notice (including the next
37 * paragraph) shall be included in all copies or substantial portions of the
40 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
43 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
44 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
45 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
46 * OTHER DEALINGS IN THE SOFTWARE.
51 static void drm_cleanup(struct drm_device * dev);
52 int drm_fb_loaded = 0;
54 static int drm_version(struct drm_device *dev, void *data,
55 struct drm_file *file_priv);
58 static struct drm_ioctl_desc drm_ioctls[] = {
59 DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, 0),
60 DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
61 DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0),
62 DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
63 DRM_IOCTL_DEF(DRM_IOCTL_GET_MAP, drm_getmap, 0),
64 DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT, drm_getclient, 0),
65 DRM_IOCTL_DEF(DRM_IOCTL_GET_STATS, drm_getstats, 0),
66 DRM_IOCTL_DEF(DRM_IOCTL_SET_VERSION, drm_setversion, DRM_MASTER|DRM_ROOT_ONLY),
68 DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE, drm_setunique, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
69 DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
70 DRM_IOCTL_DEF(DRM_IOCTL_UNBLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
71 DRM_IOCTL_DEF(DRM_IOCTL_AUTH_MAGIC, drm_authmagic, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
73 DRM_IOCTL_DEF(DRM_IOCTL_ADD_MAP, drm_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
74 DRM_IOCTL_DEF(DRM_IOCTL_RM_MAP, drm_rmmap_ioctl, DRM_AUTH),
76 DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
77 DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_getsareactx, DRM_AUTH),
79 DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_addctx, DRM_AUTH|DRM_ROOT_ONLY),
80 DRM_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
81 DRM_IOCTL_DEF(DRM_IOCTL_MOD_CTX, drm_modctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
82 DRM_IOCTL_DEF(DRM_IOCTL_GET_CTX, drm_getctx, DRM_AUTH),
83 DRM_IOCTL_DEF(DRM_IOCTL_SWITCH_CTX, drm_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
84 DRM_IOCTL_DEF(DRM_IOCTL_NEW_CTX, drm_newctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
85 DRM_IOCTL_DEF(DRM_IOCTL_RES_CTX, drm_resctx, DRM_AUTH),
87 DRM_IOCTL_DEF(DRM_IOCTL_ADD_DRAW, drm_adddraw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
88 DRM_IOCTL_DEF(DRM_IOCTL_RM_DRAW, drm_rmdraw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
90 DRM_IOCTL_DEF(DRM_IOCTL_LOCK, drm_lock, DRM_AUTH),
91 DRM_IOCTL_DEF(DRM_IOCTL_UNLOCK, drm_unlock, DRM_AUTH),
93 DRM_IOCTL_DEF(DRM_IOCTL_FINISH, drm_noop, DRM_AUTH),
95 DRM_IOCTL_DEF(DRM_IOCTL_ADD_BUFS, drm_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
96 DRM_IOCTL_DEF(DRM_IOCTL_MARK_BUFS, drm_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
97 DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_infobufs, DRM_AUTH),
98 DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_mapbufs, DRM_AUTH),
99 DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_freebufs, DRM_AUTH),
100 /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
101 DRM_IOCTL_DEF(DRM_IOCTL_DMA, NULL, DRM_AUTH),
103 DRM_IOCTL_DEF(DRM_IOCTL_CONTROL, drm_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
106 DRM_IOCTL_DEF(DRM_IOCTL_AGP_ACQUIRE, drm_agp_acquire_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
107 DRM_IOCTL_DEF(DRM_IOCTL_AGP_RELEASE, drm_agp_release_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
108 DRM_IOCTL_DEF(DRM_IOCTL_AGP_ENABLE, drm_agp_enable_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
109 DRM_IOCTL_DEF(DRM_IOCTL_AGP_INFO, drm_agp_info_ioctl, DRM_AUTH),
110 DRM_IOCTL_DEF(DRM_IOCTL_AGP_ALLOC, drm_agp_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
111 DRM_IOCTL_DEF(DRM_IOCTL_AGP_FREE, drm_agp_free_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
112 DRM_IOCTL_DEF(DRM_IOCTL_AGP_BIND, drm_agp_bind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
113 DRM_IOCTL_DEF(DRM_IOCTL_AGP_UNBIND, drm_agp_unbind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
116 DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_sg_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
117 DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
118 DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank, 0),
119 DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
120 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, DRM_MASTER|DRM_ROOT_ONLY),
121 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, DRM_MASTER|DRM_ROOT_ONLY),
122 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETOUTPUT, drm_mode_getoutput, DRM_MASTER|DRM_ROOT_ONLY),
123 DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETCRTC, drm_mode_setcrtc, DRM_MASTER|DRM_ROOT_ONLY),
124 DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb, DRM_MASTER|DRM_ROOT_ONLY),
125 DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb, DRM_MASTER|DRM_ROOT_ONLY),
126 DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, DRM_MASTER|DRM_ROOT_ONLY),
127 DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDMODE, drm_mode_addmode, DRM_MASTER|DRM_ROOT_ONLY),
128 DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMMODE, drm_mode_rmmode, DRM_MASTER|DRM_ROOT_ONLY),
129 DRM_IOCTL_DEF(DRM_IOCTL_MODE_ATTACHMODE, drm_mode_attachmode, DRM_MASTER|DRM_ROOT_ONLY),
130 DRM_IOCTL_DEF(DRM_IOCTL_MODE_DETACHMODE, drm_mode_detachmode, DRM_MASTER|DRM_ROOT_ONLY),
132 DRM_IOCTL_DEF(DRM_IOCTL_MM_INIT, drm_mm_init_ioctl,
133 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
134 DRM_IOCTL_DEF(DRM_IOCTL_MM_TAKEDOWN, drm_mm_takedown_ioctl,
135 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
136 DRM_IOCTL_DEF(DRM_IOCTL_MM_LOCK, drm_mm_lock_ioctl,
137 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
138 DRM_IOCTL_DEF(DRM_IOCTL_MM_UNLOCK, drm_mm_unlock_ioctl,
139 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
141 DRM_IOCTL_DEF(DRM_IOCTL_FENCE_CREATE, drm_fence_create_ioctl, DRM_AUTH),
142 DRM_IOCTL_DEF(DRM_IOCTL_FENCE_REFERENCE, drm_fence_reference_ioctl, DRM_AUTH),
143 DRM_IOCTL_DEF(DRM_IOCTL_FENCE_UNREFERENCE, drm_fence_unreference_ioctl, DRM_AUTH),
144 DRM_IOCTL_DEF(DRM_IOCTL_FENCE_SIGNALED, drm_fence_signaled_ioctl, DRM_AUTH),
145 DRM_IOCTL_DEF(DRM_IOCTL_FENCE_FLUSH, drm_fence_flush_ioctl, DRM_AUTH),
146 DRM_IOCTL_DEF(DRM_IOCTL_FENCE_WAIT, drm_fence_wait_ioctl, DRM_AUTH),
147 DRM_IOCTL_DEF(DRM_IOCTL_FENCE_EMIT, drm_fence_emit_ioctl, DRM_AUTH),
148 DRM_IOCTL_DEF(DRM_IOCTL_FENCE_BUFFERS, drm_fence_buffers_ioctl, DRM_AUTH),
150 DRM_IOCTL_DEF(DRM_IOCTL_BO_CREATE, drm_bo_create_ioctl, DRM_AUTH),
151 DRM_IOCTL_DEF(DRM_IOCTL_BO_MAP, drm_bo_map_ioctl, DRM_AUTH),
152 DRM_IOCTL_DEF(DRM_IOCTL_BO_UNMAP, drm_bo_unmap_ioctl, DRM_AUTH),
153 DRM_IOCTL_DEF(DRM_IOCTL_BO_REFERENCE, drm_bo_reference_ioctl, DRM_AUTH),
154 DRM_IOCTL_DEF(DRM_IOCTL_BO_UNREFERENCE, drm_bo_unreference_ioctl, DRM_AUTH),
155 DRM_IOCTL_DEF(DRM_IOCTL_BO_SETSTATUS, drm_bo_setstatus_ioctl, DRM_AUTH),
156 DRM_IOCTL_DEF(DRM_IOCTL_BO_INFO, drm_bo_info_ioctl, DRM_AUTH),
157 DRM_IOCTL_DEF(DRM_IOCTL_BO_WAIT_IDLE, drm_bo_wait_idle_ioctl, DRM_AUTH),
158 DRM_IOCTL_DEF(DRM_IOCTL_BO_VERSION, drm_bo_version_ioctl, 0),
161 #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
165 * Take down the DRM device.
167 * \param dev DRM device structure.
169 * Frees every resource in \p dev.
173 int drm_lastclose(struct drm_device * dev)
175 struct drm_magic_entry *pt, *next;
176 struct drm_map_list *r_list, *list_t;
177 struct drm_vma_entry *vma, *vma_temp;
183 * We can't do much about this function failing.
186 if (dev->driver->lastclose)
187 dev->driver->lastclose(dev);
188 DRM_DEBUG("driver lastclose completed\n");
191 drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);
196 if (dev->irq_enabled)
197 drm_irq_uninstall(dev);
199 /* Free drawable information memory */
200 mutex_lock(&dev->struct_mutex);
202 drm_drawable_free_all(dev);
203 del_timer(&dev->timer);
206 drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);
211 if (dev->magicfree.next) {
212 list_for_each_entry_safe(pt, next, &dev->magicfree, head) {
214 drm_ht_remove_item(&dev->magiclist, &pt->hash_item);
215 drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
217 drm_ht_remove(&dev->magiclist);
221 /* Clear AGP information */
222 if (drm_core_has_AGP(dev) && dev->agp) {
223 struct drm_agp_mem *entry, *tempe;
225 /* Remove AGP resources, but leave dev->agp
226 intact until drv_cleanup is called. */
227 list_for_each_entry_safe(entry, tempe, &dev->agp->memory, head) {
229 drm_unbind_agp(entry->memory);
230 drm_free_agp(entry->memory, entry->pages);
231 drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS);
233 INIT_LIST_HEAD(&dev->agp->memory);
235 if (dev->agp->acquired)
236 drm_agp_release(dev);
238 dev->agp->acquired = 0;
239 dev->agp->enabled = 0;
241 if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) {
242 drm_sg_cleanup(dev->sg);
246 /* Clear vma list (only built for debugging) */
247 list_for_each_entry_safe(vma, vma_temp, &dev->vmalist, head) {
248 list_del(&vma->head);
249 drm_ctl_free(vma, sizeof(*vma), DRM_MEM_VMAS);
252 list_for_each_entry_safe(r_list, list_t, &dev->maplist, head) {
253 if (!(r_list->map->flags & _DRM_DRIVER)) {
254 drm_rmmap_locked(dev, r_list->map);
259 if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist) {
260 for (i = 0; i < dev->queue_count; i++) {
262 if (dev->queuelist[i]) {
263 drm_free(dev->queuelist[i],
264 sizeof(*dev->queuelist[0]),
266 dev->queuelist[i] = NULL;
269 drm_free(dev->queuelist,
270 dev->queue_slots * sizeof(*dev->queuelist),
272 dev->queuelist = NULL;
274 dev->queue_count = 0;
276 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
277 drm_dma_takedown(dev);
279 if (dev->lock.hw_lock) {
280 dev->sigdata.lock = dev->lock.hw_lock = NULL; /* SHM removed */
281 dev->lock.file_priv = NULL;
282 wake_up_interruptible(&dev->lock.lock_queue);
284 dev->dev_mapping = NULL;
285 mutex_unlock(&dev->struct_mutex);
287 DRM_DEBUG("lastclose completed\n");
291 void drm_cleanup_pci(struct pci_dev *pdev)
293 struct drm_device *dev = pci_get_drvdata(pdev);
295 pci_set_drvdata(pdev, NULL);
296 pci_release_regions(pdev);
300 EXPORT_SYMBOL(drm_cleanup_pci);
303 * Module initialization. Called via init_module at module load time, or via
304 * linux/init/main.c (this is not currently supported).
306 * \return zero on success or a negative number on failure.
308 * Initializes an array of drm_device structures, and attempts to
309 * initialize all available devices, using consecutive minors, registering the
310 * stubs and initializing the AGP device.
312 * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
313 * after the initialization for driver customization.
315 int drm_init(struct drm_driver *driver,
316 struct pci_device_id *pciidlist)
318 struct pci_dev *pdev;
319 struct pci_device_id *pid;
324 for (i = 0; (pciidlist[i].vendor != 0) && !drm_fb_loaded; i++) {
328 /* pass back in pdev to account for multiple identical cards */
330 pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
331 pid->subdevice, pdev))) {
332 /* Are there device class requirements? */
333 if ((pid->class != 0)
334 && ((pdev->class & pid->class_mask) != pid->class)) {
337 /* is there already a driver loaded, or (short circuit saves work) */
338 /* does something like VesaFB have control of the memory region? */
339 if (pci_dev_driver(pdev)
340 || pci_request_regions(pdev, "DRM scan")) {
341 /* go into stealth mode */
346 /* no fbdev or vesadev, put things back and wait for normal probe */
347 pci_release_regions(pdev);
352 return pci_register_driver(&driver->pci_driver);
354 for (i = 0; pciidlist[i].vendor != 0; i++) {
358 /* pass back in pdev to account for multiple identical cards */
360 pci_get_subsys(pid->vendor, pid->device,
361 pid->subvendor, pid->subdevice,
363 /* Are there device class requirements? */
364 if ((pid->class != 0)
365 && ((pdev->class & pid->class_mask) != pid->class)) {
368 /* stealth mode requires a manual probe */
370 if ((rc = drm_get_dev(pdev, &pciidlist[i], driver))) {
376 DRM_INFO("Used old pci detect: framebuffer loaded\n");
380 EXPORT_SYMBOL(drm_init);
383 * Called via cleanup_module() at module unload time.
385 * Cleans up all DRM device, calling drm_lastclose().
389 static void drm_cleanup(struct drm_device * dev)
394 DRM_ERROR("cleanup called no dev\n");
399 drm_fence_manager_takedown(dev);
401 drm_mm_takedown(&dev->offset_manager);
402 drm_ht_remove(&dev->object_hash);
405 pci_disable_device(dev->pdev);
407 drm_ctxbitmap_cleanup(dev);
409 if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && dev->agp
410 && dev->agp->agp_mtrr >= 0) {
412 retval = mtrr_del(dev->agp->agp_mtrr,
413 dev->agp->agp_info.aper_base,
414 dev->agp->agp_info.aper_size * 1024 * 1024);
415 DRM_DEBUG("mtrr_del=%d\n", retval);
418 if (dev->driver->unload)
419 dev->driver->unload(dev);
421 drm_ht_remove(&dev->map_hash);
422 if (drm_core_has_AGP(dev) && dev->agp) {
423 drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS);
428 pci_disable_device(dev->pdev);
430 drm_put_head(&dev->primary);
431 if (drm_put_dev(dev))
432 DRM_ERROR("Cannot unload module\n");
435 void drm_exit(struct drm_driver *driver)
438 struct drm_device *dev = NULL;
439 struct drm_head *head;
443 for (i = 0; i < drm_cards_limit; i++) {
449 if (head->dev->driver != driver)
453 /* release the pci driver */
455 pci_dev_put(dev->pdev);
460 pci_unregister_driver(&driver->pci_driver);
461 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
464 DRM_INFO("Module unloaded\n");
466 EXPORT_SYMBOL(drm_exit);
468 /** File operations structure */
469 static const struct file_operations drm_stub_fops = {
470 .owner = THIS_MODULE,
471 .open = drm_stub_open
474 static int __init drm_core_init(void)
478 unsigned long avail_memctl_mem;
479 unsigned long max_memctl_mem;
484 * AGP only allows low / DMA32 memory ATM.
487 avail_memctl_mem = si.totalram - si.totalhigh;
493 max_memctl_mem = 1UL << (32 - PAGE_SHIFT);
494 max_memctl_mem = (max_memctl_mem / si.mem_unit) * PAGE_SIZE;
496 if (avail_memctl_mem >= max_memctl_mem)
497 avail_memctl_mem = max_memctl_mem;
499 drm_init_memctl(avail_memctl_mem/2, avail_memctl_mem*3/4, si.mem_unit);
503 (drm_cards_limit < DRM_MAX_MINOR + 1 ? drm_cards_limit : DRM_MAX_MINOR + 1);
504 drm_heads = drm_calloc(drm_cards_limit, sizeof(*drm_heads), DRM_MEM_STUB);
508 if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
511 drm_class = drm_sysfs_create(THIS_MODULE, "drm");
512 if (IS_ERR(drm_class)) {
513 printk(KERN_ERR "DRM: Error creating drm class.\n");
514 ret = PTR_ERR(drm_class);
518 drm_proc_root = proc_mkdir("dri", NULL);
519 if (!drm_proc_root) {
520 DRM_ERROR("Cannot create /proc/dri\n");
527 DRM_INFO("Initialized %s %d.%d.%d %s\n",
529 CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
534 unregister_chrdev(DRM_MAJOR, "drm");
535 drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
540 static void __exit drm_core_exit(void)
542 remove_proc_entry("dri", NULL);
545 unregister_chrdev(DRM_MAJOR, "drm");
547 drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
550 module_init(drm_core_init);
551 module_exit(drm_core_exit);
554 * Get version information
556 * \param inode device inode.
557 * \param file_priv DRM file private.
558 * \param cmd command.
559 * \param arg user argument, pointing to a drm_version structure.
560 * \return zero on success or negative number on failure.
562 * Fills in the version information in \p arg.
564 static int drm_version(struct drm_device *dev, void *data,
565 struct drm_file *file_priv)
567 struct drm_version *version = data;
570 version->version_major = dev->driver->major;
571 version->version_minor = dev->driver->minor;
572 version->version_patchlevel = dev->driver->patchlevel;
573 DRM_COPY(version->name, dev->driver->name);
574 DRM_COPY(version->date, dev->driver->date);
575 DRM_COPY(version->desc, dev->driver->desc);
581 * Called whenever a process performs an ioctl on /dev/drm.
583 * \param inode device inode.
584 * \param file_priv DRM file private.
585 * \param cmd command.
586 * \param arg user argument.
587 * \return zero on success or negative number on failure.
589 * Looks up the ioctl function in the ::ioctls table, checking for root
590 * previleges if so required, and dispatches to the respective function.
592 * Copies data in and out according to the size and direction given in cmd,
593 * which must match the ioctl cmd known by the kernel. The kernel uses a 512
594 * byte stack buffer to store the ioctl arguments in kernel space. Should we
595 * ever need much larger ioctl arguments, we may need to allocate memory.
597 int drm_ioctl(struct inode *inode, struct file *filp,
598 unsigned int cmd, unsigned long arg)
600 return drm_unlocked_ioctl(filp, cmd, arg);
602 EXPORT_SYMBOL(drm_ioctl);
604 long drm_unlocked_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
606 struct drm_file *file_priv = filp->private_data;
607 struct drm_device *dev = file_priv->head->dev;
608 struct drm_ioctl_desc *ioctl;
610 unsigned int nr = DRM_IOCTL_NR(cmd);
611 int retcode = -EINVAL;
614 atomic_inc(&dev->ioctl_count);
615 atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
616 ++file_priv->ioctl_count;
618 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
619 current->pid, cmd, nr, (long)old_encode_dev(file_priv->head->device),
620 file_priv->authenticated);
622 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
623 ((nr < DRM_COMMAND_BASE) || (nr >= DRM_COMMAND_END)))
625 if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END)
626 && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls))
627 ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE];
628 else if ((nr >= DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE))
629 ioctl = &drm_ioctls[nr];
636 * This check is disabled, because driver private ioctl->cmd
637 * are not the ioctl commands with size and direction bits but
638 * just the indices. The DRM core ioctl->cmd are the proper ioctl
639 * commands. The drivers' ioctl tables need to be fixed.
641 if (ioctl->cmd != cmd) {
647 /* is there a local override? */
648 if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl)
649 func = dev->driver->dma_ioctl;
652 if (copy_from_user(kdata, (void __user *)arg,
653 _IOC_SIZE(cmd)) != 0) {
660 DRM_DEBUG("no function\n");
662 } else if (((ioctl->flags & DRM_ROOT_ONLY) && !capable(CAP_SYS_ADMIN)) ||
663 ((ioctl->flags & DRM_AUTH) && !file_priv->authenticated) ||
664 ((ioctl->flags & DRM_MASTER) && !file_priv->master)) {
667 retcode = func(dev, kdata, file_priv);
670 if ((retcode == 0) && (cmd & IOC_OUT)) {
671 if (copy_to_user((void __user *)arg, kdata,
672 _IOC_SIZE(cmd)) != 0)
677 atomic_dec(&dev->ioctl_count);
679 DRM_DEBUG("ret = %d\n", retcode);
682 EXPORT_SYMBOL(drm_unlocked_ioctl);
684 drm_local_map_t *drm_getsarea(struct drm_device *dev)
686 struct drm_map_list *entry;
688 list_for_each_entry(entry, &dev->maplist, head) {
689 if (entry->map && entry->map->type == _DRM_SHM &&
690 (entry->map->flags & _DRM_CONTAINS_LOCK)) {
696 EXPORT_SYMBOL(drm_getsarea);