2 * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org
4 * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California.
7 * Author Rickard E. (Rik) Faith <faith@valinux.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice (including the next
17 * paragraph) shall be included in all copies or substantial portions of the
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
29 #include <linux/debugfs.h>
31 #include <linux/module.h>
32 #include <linux/moduleparam.h>
33 #include <linux/mount.h>
34 #include <linux/slab.h>
36 #include <drm/drm_core.h>
37 #include "drm_crtc_internal.h"
38 #include "drm_legacy.h"
39 #include "drm_internal.h"
42 * drm_debug: Enable debug output.
43 * Bitmask of DRM_UT_x. See include/drm/drmP.h for details.
45 unsigned int drm_debug = 0;
46 EXPORT_SYMBOL(drm_debug);
48 MODULE_AUTHOR(CORE_AUTHOR);
49 MODULE_DESCRIPTION(CORE_DESC);
50 MODULE_LICENSE("GPL and additional rights");
51 MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug category.\n"
52 "\t\tBit 0 (0x01) will enable CORE messages (drm core code)\n"
53 "\t\tBit 1 (0x02) will enable DRIVER messages (drm controller code)\n"
54 "\t\tBit 2 (0x04) will enable KMS messages (modesetting code)\n"
55 "\t\tBit 3 (0x08) will enable PRIME messages (prime code)\n"
56 "\t\tBit 4 (0x10) will enable ATOMIC messages (atomic code)\n"
57 "\t\tBit 5 (0x20) will enable VBL messages (vblank code)");
58 module_param_named(debug, drm_debug, int, 0600);
60 static DEFINE_SPINLOCK(drm_minor_lock);
61 static struct idr drm_minors_idr;
63 static struct dentry *drm_debugfs_root;
65 #define DRM_PRINTK_FMT "[" DRM_NAME ":%s]%s %pV"
67 void drm_dev_printk(const struct device *dev, const char *level,
68 unsigned int category, const char *function_name,
69 const char *prefix, const char *format, ...)
74 if (category != DRM_UT_NONE && !(drm_debug & category))
77 va_start(args, format);
81 dev_printk(level, dev, DRM_PRINTK_FMT, function_name, prefix,
86 EXPORT_SYMBOL(drm_dev_printk);
88 void drm_printk(const char *level, unsigned int category,
89 const char *function_name, const char *prefix,
90 const char *format, ...)
95 if (category != DRM_UT_NONE && !(drm_debug & category))
98 va_start(args, format);
102 printk("%s" DRM_PRINTK_FMT, level, function_name, prefix, &vaf);
106 EXPORT_SYMBOL(drm_printk);
108 struct drm_master *drm_master_create(struct drm_minor *minor)
110 struct drm_master *master;
112 master = kzalloc(sizeof(*master), GFP_KERNEL);
116 kref_init(&master->refcount);
117 spin_lock_init(&master->lock.spinlock);
118 init_waitqueue_head(&master->lock.lock_queue);
119 idr_init(&master->magic_map);
120 master->minor = minor;
125 struct drm_master *drm_master_get(struct drm_master *master)
127 kref_get(&master->refcount);
130 EXPORT_SYMBOL(drm_master_get);
132 static void drm_master_destroy(struct kref *kref)
134 struct drm_master *master = container_of(kref, struct drm_master, refcount);
135 struct drm_device *dev = master->minor->dev;
136 struct drm_map_list *r_list, *list_temp;
138 mutex_lock(&dev->struct_mutex);
139 if (dev->driver->master_destroy)
140 dev->driver->master_destroy(dev, master);
142 list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) {
143 if (r_list->master == master) {
144 drm_legacy_rmmap_locked(dev, r_list->map);
148 mutex_unlock(&dev->struct_mutex);
150 idr_destroy(&master->magic_map);
151 kfree(master->unique);
155 void drm_master_put(struct drm_master **master)
157 kref_put(&(*master)->refcount, drm_master_destroy);
160 EXPORT_SYMBOL(drm_master_put);
162 int drm_setmaster_ioctl(struct drm_device *dev, void *data,
163 struct drm_file *file_priv)
167 mutex_lock(&dev->master_mutex);
168 if (file_priv->is_master)
171 if (file_priv->minor->master) {
176 if (!file_priv->master) {
181 if (!file_priv->allowed_master) {
182 ret = drm_new_set_master(dev, file_priv);
186 file_priv->minor->master = drm_master_get(file_priv->master);
187 file_priv->is_master = 1;
188 if (dev->driver->master_set) {
189 ret = dev->driver->master_set(dev, file_priv, false);
190 if (unlikely(ret != 0)) {
191 file_priv->is_master = 0;
192 drm_master_put(&file_priv->minor->master);
197 mutex_unlock(&dev->master_mutex);
201 int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
202 struct drm_file *file_priv)
206 mutex_lock(&dev->master_mutex);
207 if (!file_priv->is_master)
210 if (!file_priv->minor->master)
214 if (dev->driver->master_drop)
215 dev->driver->master_drop(dev, file_priv, false);
216 drm_master_put(&file_priv->minor->master);
217 file_priv->is_master = 0;
220 mutex_unlock(&dev->master_mutex);
226 * A DRM device can provide several char-dev interfaces on the DRM-Major. Each
227 * of them is represented by a drm_minor object. Depending on the capabilities
228 * of the device-driver, different interfaces are registered.
230 * Minors can be accessed via dev->$minor_name. This pointer is either
231 * NULL or a valid drm_minor pointer and stays valid as long as the device is
232 * valid. This means, DRM minors have the same life-time as the underlying
233 * device. However, this doesn't mean that the minor is active. Minors are
234 * registered and unregistered dynamically according to device-state.
237 static struct drm_minor **drm_minor_get_slot(struct drm_device *dev,
241 case DRM_MINOR_LEGACY:
242 return &dev->primary;
243 case DRM_MINOR_RENDER:
245 case DRM_MINOR_CONTROL:
246 return &dev->control;
252 static int drm_minor_alloc(struct drm_device *dev, unsigned int type)
254 struct drm_minor *minor;
258 minor = kzalloc(sizeof(*minor), GFP_KERNEL);
265 idr_preload(GFP_KERNEL);
266 spin_lock_irqsave(&drm_minor_lock, flags);
267 r = idr_alloc(&drm_minors_idr,
272 spin_unlock_irqrestore(&drm_minor_lock, flags);
280 minor->kdev = drm_sysfs_minor_alloc(minor);
281 if (IS_ERR(minor->kdev)) {
282 r = PTR_ERR(minor->kdev);
286 *drm_minor_get_slot(dev, type) = minor;
290 spin_lock_irqsave(&drm_minor_lock, flags);
291 idr_remove(&drm_minors_idr, minor->index);
292 spin_unlock_irqrestore(&drm_minor_lock, flags);
298 static void drm_minor_free(struct drm_device *dev, unsigned int type)
300 struct drm_minor **slot, *minor;
303 slot = drm_minor_get_slot(dev, type);
308 put_device(minor->kdev);
310 spin_lock_irqsave(&drm_minor_lock, flags);
311 idr_remove(&drm_minors_idr, minor->index);
312 spin_unlock_irqrestore(&drm_minor_lock, flags);
318 static int drm_minor_register(struct drm_device *dev, unsigned int type)
320 struct drm_minor *minor;
326 minor = *drm_minor_get_slot(dev, type);
330 ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root);
332 DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n");
336 ret = device_add(minor->kdev);
340 /* replace NULL with @minor so lookups will succeed from now on */
341 spin_lock_irqsave(&drm_minor_lock, flags);
342 idr_replace(&drm_minors_idr, minor, minor->index);
343 spin_unlock_irqrestore(&drm_minor_lock, flags);
345 DRM_DEBUG("new minor registered %d\n", minor->index);
349 drm_debugfs_cleanup(minor);
353 static void drm_minor_unregister(struct drm_device *dev, unsigned int type)
355 struct drm_minor *minor;
358 minor = *drm_minor_get_slot(dev, type);
359 if (!minor || !device_is_registered(minor->kdev))
362 /* replace @minor with NULL so lookups will fail from now on */
363 spin_lock_irqsave(&drm_minor_lock, flags);
364 idr_replace(&drm_minors_idr, NULL, minor->index);
365 spin_unlock_irqrestore(&drm_minor_lock, flags);
367 device_del(minor->kdev);
368 dev_set_drvdata(minor->kdev, NULL); /* safety belt */
369 drm_debugfs_cleanup(minor);
373 * drm_minor_acquire - Acquire a DRM minor
374 * @minor_id: Minor ID of the DRM-minor
376 * Looks up the given minor-ID and returns the respective DRM-minor object. The
377 * refence-count of the underlying device is increased so you must release this
378 * object with drm_minor_release().
380 * As long as you hold this minor, it is guaranteed that the object and the
381 * minor->dev pointer will stay valid! However, the device may get unplugged and
382 * unregistered while you hold the minor.
385 * Pointer to minor-object with increased device-refcount, or PTR_ERR on
388 struct drm_minor *drm_minor_acquire(unsigned int minor_id)
390 struct drm_minor *minor;
393 spin_lock_irqsave(&drm_minor_lock, flags);
394 minor = idr_find(&drm_minors_idr, minor_id);
396 drm_dev_ref(minor->dev);
397 spin_unlock_irqrestore(&drm_minor_lock, flags);
400 return ERR_PTR(-ENODEV);
401 } else if (drm_device_is_unplugged(minor->dev)) {
402 drm_dev_unref(minor->dev);
403 return ERR_PTR(-ENODEV);
410 * drm_minor_release - Release DRM minor
411 * @minor: Pointer to DRM minor object
413 * Release a minor that was previously acquired via drm_minor_acquire().
415 void drm_minor_release(struct drm_minor *minor)
417 drm_dev_unref(minor->dev);
420 struct drm_device *drm_device_get_by_name(const char *name)
424 for (i = 0; i < 64; i++) {
425 struct drm_minor *minor;
427 minor = drm_minor_acquire(i + DRM_MINOR_CONTROL);
430 if (!minor->dev || !minor->dev->driver ||
431 !minor->dev->driver->name)
435 if (!strcmp(name, minor->dev->driver->name))
443 * DOC: driver instance overview
445 * A device instance for a drm driver is represented by struct &drm_device. This
446 * is allocated with drm_dev_alloc(), usually from bus-specific ->probe()
447 * callbacks implemented by the driver. The driver then needs to initialize all
448 * the various subsystems for the drm device like memory management, vblank
449 * handling, modesetting support and intial output configuration plus obviously
450 * initialize all the corresponding hardware bits. An important part of this is
451 * also calling drm_dev_set_unique() to set the userspace-visible unique name of
452 * this device instance. Finally when everything is up and running and ready for
453 * userspace the device instance can be published using drm_dev_register().
455 * There is also deprecated support for initalizing device instances using
456 * bus-specific helpers and the ->load() callback. But due to
457 * backwards-compatibility needs the device instance have to be published too
458 * early, which requires unpretty global locking to make safe and is therefore
459 * only support for existing drivers not yet converted to the new scheme.
461 * When cleaning up a device instance everything needs to be done in reverse:
462 * First unpublish the device instance with drm_dev_unregister(). Then clean up
463 * any other resources allocated at device initialization and drop the driver's
464 * reference to &drm_device using drm_dev_unref().
466 * Note that the lifetime rules for &drm_device instance has still a lot of
467 * historical baggage. Hence use the reference counting provided by
468 * drm_dev_ref() and drm_dev_unref() only carefully.
470 * Also note that embedding of &drm_device is currently not (yet) supported (but
471 * it would be easy to add). Drivers can store driver-private data in the
472 * dev_priv field of &drm_device.
476 * drm_put_dev - Unregister and release a DRM device
479 * Called at module unload time or when a PCI device is unplugged.
481 * Cleans up all DRM device, calling drm_lastclose().
483 * Note: Use of this function is deprecated. It will eventually go away
484 * completely. Please use drm_dev_unregister() and drm_dev_unref() explicitly
485 * instead to make sure that the device isn't userspace accessible any more
486 * while teardown is in progress, ensuring that userspace can't access an
487 * inconsistent state.
489 void drm_put_dev(struct drm_device *dev)
494 DRM_ERROR("cleanup called no dev\n");
498 drm_dev_unregister(dev);
501 EXPORT_SYMBOL(drm_put_dev);
503 void drm_unplug_dev(struct drm_device *dev)
505 /* for a USB device */
506 drm_minor_unregister(dev, DRM_MINOR_LEGACY);
507 drm_minor_unregister(dev, DRM_MINOR_RENDER);
508 drm_minor_unregister(dev, DRM_MINOR_CONTROL);
510 mutex_lock(&drm_global_mutex);
512 drm_device_set_unplugged(dev);
514 if (dev->open_count == 0) {
517 mutex_unlock(&drm_global_mutex);
519 EXPORT_SYMBOL(drm_unplug_dev);
523 * We want to be able to allocate our own "struct address_space" to control
524 * memory-mappings in VRAM (or stolen RAM, ...). However, core MM does not allow
525 * stand-alone address_space objects, so we need an underlying inode. As there
526 * is no way to allocate an independent inode easily, we need a fake internal
529 * The drm_fs_inode_new() function allocates a new inode, drm_fs_inode_free()
530 * frees it again. You are allowed to use iget() and iput() to get references to
531 * the inode. But each drm_fs_inode_new() call must be paired with exactly one
532 * drm_fs_inode_free() call (which does not have to be the last iput()).
533 * We use drm_fs_inode_*() to manage our internal VFS mount-point and share it
534 * between multiple inode-users. You could, technically, call
535 * iget() + drm_fs_inode_free() directly after alloc and sometime later do an
536 * iput(), but this way you'd end up with a new vfsmount for each inode.
539 static int drm_fs_cnt;
540 static struct vfsmount *drm_fs_mnt;
542 static const struct dentry_operations drm_fs_dops = {
543 .d_dname = simple_dname,
546 static const struct super_operations drm_fs_sops = {
547 .statfs = simple_statfs,
550 static struct dentry *drm_fs_mount(struct file_system_type *fs_type, int flags,
551 const char *dev_name, void *data)
553 return mount_pseudo(fs_type,
560 static struct file_system_type drm_fs_type = {
562 .owner = THIS_MODULE,
563 .mount = drm_fs_mount,
564 .kill_sb = kill_anon_super,
567 static struct inode *drm_fs_inode_new(void)
572 r = simple_pin_fs(&drm_fs_type, &drm_fs_mnt, &drm_fs_cnt);
574 DRM_ERROR("Cannot mount pseudo fs: %d\n", r);
578 inode = alloc_anon_inode(drm_fs_mnt->mnt_sb);
580 simple_release_fs(&drm_fs_mnt, &drm_fs_cnt);
585 static void drm_fs_inode_free(struct inode *inode)
589 simple_release_fs(&drm_fs_mnt, &drm_fs_cnt);
594 * drm_dev_alloc - Allocate new DRM device
595 * @driver: DRM driver to allocate device for
596 * @parent: Parent device object
598 * Allocate and initialize a new DRM device. No device registration is done.
599 * Call drm_dev_register() to advertice the device to user space and register it
600 * with other core subsystems. This should be done last in the device
601 * initialization sequence to make sure userspace can't access an inconsistent
604 * The initial ref-count of the object is 1. Use drm_dev_ref() and
605 * drm_dev_unref() to take and drop further ref-counts.
607 * Note that for purely virtual devices @parent can be NULL.
610 * Pointer to new DRM device, or NULL if out of memory.
612 struct drm_device *drm_dev_alloc(struct drm_driver *driver,
613 struct device *parent)
615 struct drm_device *dev;
618 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
622 kref_init(&dev->ref);
624 dev->driver = driver;
626 INIT_LIST_HEAD(&dev->filelist);
627 INIT_LIST_HEAD(&dev->ctxlist);
628 INIT_LIST_HEAD(&dev->vmalist);
629 INIT_LIST_HEAD(&dev->maplist);
630 INIT_LIST_HEAD(&dev->vblank_event_list);
632 spin_lock_init(&dev->buf_lock);
633 spin_lock_init(&dev->event_lock);
634 mutex_init(&dev->struct_mutex);
635 mutex_init(&dev->ctxlist_mutex);
636 mutex_init(&dev->master_mutex);
638 dev->anon_inode = drm_fs_inode_new();
639 if (IS_ERR(dev->anon_inode)) {
640 ret = PTR_ERR(dev->anon_inode);
641 DRM_ERROR("Cannot allocate anonymous inode: %d\n", ret);
645 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
646 ret = drm_minor_alloc(dev, DRM_MINOR_CONTROL);
650 WARN_ON(driver->suspend || driver->resume);
653 if (drm_core_check_feature(dev, DRIVER_RENDER)) {
654 ret = drm_minor_alloc(dev, DRM_MINOR_RENDER);
659 ret = drm_minor_alloc(dev, DRM_MINOR_LEGACY);
663 if (drm_ht_create(&dev->map_hash, 12))
666 drm_legacy_ctxbitmap_init(dev);
668 if (drm_core_check_feature(dev, DRIVER_GEM)) {
669 ret = drm_gem_init(dev);
671 DRM_ERROR("Cannot initialize graphics execution manager (GEM)\n");
679 drm_legacy_ctxbitmap_cleanup(dev);
680 drm_ht_remove(&dev->map_hash);
682 drm_minor_free(dev, DRM_MINOR_LEGACY);
683 drm_minor_free(dev, DRM_MINOR_RENDER);
684 drm_minor_free(dev, DRM_MINOR_CONTROL);
685 drm_fs_inode_free(dev->anon_inode);
687 mutex_destroy(&dev->master_mutex);
691 EXPORT_SYMBOL(drm_dev_alloc);
693 static void drm_dev_release(struct kref *ref)
695 struct drm_device *dev = container_of(ref, struct drm_device, ref);
697 if (drm_core_check_feature(dev, DRIVER_GEM))
698 drm_gem_destroy(dev);
700 drm_legacy_ctxbitmap_cleanup(dev);
701 drm_ht_remove(&dev->map_hash);
702 drm_fs_inode_free(dev->anon_inode);
704 drm_minor_free(dev, DRM_MINOR_LEGACY);
705 drm_minor_free(dev, DRM_MINOR_RENDER);
706 drm_minor_free(dev, DRM_MINOR_CONTROL);
708 mutex_destroy(&dev->master_mutex);
714 * drm_dev_ref - Take reference of a DRM device
715 * @dev: device to take reference of or NULL
717 * This increases the ref-count of @dev by one. You *must* already own a
718 * reference when calling this. Use drm_dev_unref() to drop this reference
721 * This function never fails. However, this function does not provide *any*
722 * guarantee whether the device is alive or running. It only provides a
723 * reference to the object and the memory associated with it.
725 void drm_dev_ref(struct drm_device *dev)
730 EXPORT_SYMBOL(drm_dev_ref);
733 * drm_dev_unref - Drop reference of a DRM device
734 * @dev: device to drop reference of or NULL
736 * This decreases the ref-count of @dev by one. The device is destroyed if the
737 * ref-count drops to zero.
739 void drm_dev_unref(struct drm_device *dev)
742 kref_put(&dev->ref, drm_dev_release);
744 EXPORT_SYMBOL(drm_dev_unref);
747 * drm_dev_register - Register DRM device
748 * @dev: Device to register
749 * @flags: Flags passed to the driver's .load() function
751 * Register the DRM device @dev with the system, advertise device to user-space
752 * and start normal device operation. @dev must be allocated via drm_dev_alloc()
755 * Never call this twice on any device!
757 * NOTE: To ensure backward compatibility with existing drivers method this
758 * function calls the ->load() method after registering the device nodes,
759 * creating race conditions. Usage of the ->load() methods is therefore
760 * deprecated, drivers must perform all initialization before calling
761 * drm_dev_register().
764 * 0 on success, negative error code on failure.
766 int drm_dev_register(struct drm_device *dev, unsigned long flags)
770 mutex_lock(&drm_global_mutex);
772 ret = drm_minor_register(dev, DRM_MINOR_CONTROL);
776 ret = drm_minor_register(dev, DRM_MINOR_RENDER);
780 ret = drm_minor_register(dev, DRM_MINOR_LEGACY);
784 if (dev->driver->load) {
785 ret = dev->driver->load(dev, flags);
790 if (drm_core_check_feature(dev, DRIVER_MODESET))
791 drm_modeset_register_all(dev);
797 drm_minor_unregister(dev, DRM_MINOR_LEGACY);
798 drm_minor_unregister(dev, DRM_MINOR_RENDER);
799 drm_minor_unregister(dev, DRM_MINOR_CONTROL);
801 mutex_unlock(&drm_global_mutex);
804 EXPORT_SYMBOL(drm_dev_register);
807 * drm_dev_unregister - Unregister DRM device
808 * @dev: Device to unregister
810 * Unregister the DRM device from the system. This does the reverse of
811 * drm_dev_register() but does not deallocate the device. The caller must call
812 * drm_dev_unref() to drop their final reference.
814 * This should be called first in the device teardown code to make sure
815 * userspace can't access the device instance any more.
817 void drm_dev_unregister(struct drm_device *dev)
819 struct drm_map_list *r_list, *list_temp;
823 if (drm_core_check_feature(dev, DRIVER_MODESET))
824 drm_modeset_unregister_all(dev);
826 if (dev->driver->unload)
827 dev->driver->unload(dev);
830 drm_pci_agp_destroy(dev);
832 drm_vblank_cleanup(dev);
834 list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head)
835 drm_legacy_rmmap(dev, r_list->map);
837 drm_minor_unregister(dev, DRM_MINOR_LEGACY);
838 drm_minor_unregister(dev, DRM_MINOR_RENDER);
839 drm_minor_unregister(dev, DRM_MINOR_CONTROL);
841 EXPORT_SYMBOL(drm_dev_unregister);
844 * drm_dev_set_unique - Set the unique name of a DRM device
845 * @dev: device of which to set the unique name
846 * @fmt: format string for unique name
848 * Sets the unique name of a DRM device using the specified format string and
849 * a variable list of arguments. Drivers can use this at driver probe time if
850 * the unique name of the devices they drive is static.
852 * Return: 0 on success or a negative error code on failure.
854 int drm_dev_set_unique(struct drm_device *dev, const char *fmt, ...)
861 dev->unique = kvasprintf(GFP_KERNEL, fmt, ap);
864 return dev->unique ? 0 : -ENOMEM;
866 EXPORT_SYMBOL(drm_dev_set_unique);
870 * The DRM core module initializes all global DRM objects and makes them
871 * available to drivers. Once setup, drivers can probe their respective
873 * Currently, core management includes:
874 * - The "DRM-Global" key/value database
875 * - Global ID management for connectors
876 * - DRM major number allocation
877 * - DRM minor management
881 * Furthermore, the DRM core provides dynamic char-dev lookups. For each
882 * interface registered on a DRM device, you can request minor numbers from DRM
883 * core. DRM core takes care of major-number management and char-dev
884 * registration. A stub ->open() callback forwards any open() requests to the
888 static int drm_stub_open(struct inode *inode, struct file *filp)
890 const struct file_operations *new_fops;
891 struct drm_minor *minor;
896 mutex_lock(&drm_global_mutex);
897 minor = drm_minor_acquire(iminor(inode));
899 err = PTR_ERR(minor);
903 new_fops = fops_get(minor->dev->driver->fops);
909 replace_fops(filp, new_fops);
910 if (filp->f_op->open)
911 err = filp->f_op->open(inode, filp);
916 drm_minor_release(minor);
918 mutex_unlock(&drm_global_mutex);
922 static const struct file_operations drm_stub_fops = {
923 .owner = THIS_MODULE,
924 .open = drm_stub_open,
925 .llseek = noop_llseek,
928 static int __init drm_core_init(void)
933 drm_connector_ida_init();
934 idr_init(&drm_minors_idr);
936 if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
939 ret = drm_sysfs_init();
941 printk(KERN_ERR "DRM: Error creating drm class.\n");
945 drm_debugfs_root = debugfs_create_dir("dri", NULL);
946 if (!drm_debugfs_root) {
947 DRM_ERROR("Cannot create /sys/kernel/debug/dri\n");
952 DRM_INFO("Initialized %s %d.%d.%d %s\n",
953 CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
958 unregister_chrdev(DRM_MAJOR, "drm");
960 idr_destroy(&drm_minors_idr);
965 static void __exit drm_core_exit(void)
967 debugfs_remove(drm_debugfs_root);
970 unregister_chrdev(DRM_MAJOR, "drm");
972 drm_connector_ida_destroy();
973 idr_destroy(&drm_minors_idr);
976 module_init(drm_core_init);
977 module_exit(drm_core_exit);