Remove colldef(1) manpage too via 'make upgrade'.
[dragonfly.git] / sys / dev / drm / drm_stub.c
blob79e33ac2549c85dc9504533c07d619e026834c34
1 /**
2 * \file drm_stub.h
3 * Stub support
5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 */
8 /*
9 * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org
11 * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California.
12 * All Rights Reserved.
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:
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.
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.
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <drm/drmP.h>
37 #include <drm/drm_core.h>
38 #include <linux/slab.h>
40 unsigned int drm_debug = 0; /* 1 to enable debug output */
41 EXPORT_SYMBOL(drm_debug);
43 unsigned int drm_rnodes = 0; /* 1 to enable experimental render nodes API */
44 EXPORT_SYMBOL(drm_rnodes);
46 /* 1 to allow user space to request universal planes (experimental) */
47 unsigned int drm_universal_planes = 0;
48 EXPORT_SYMBOL(drm_universal_planes);
50 unsigned int drm_vblank_offdelay = 5000; /* Default to 5000 msecs. */
51 EXPORT_SYMBOL(drm_vblank_offdelay);
53 unsigned int drm_timestamp_precision = 20; /* Default to 20 usecs. */
54 EXPORT_SYMBOL(drm_timestamp_precision);
57 * Default to use monotonic timestamps for wait-for-vblank and page-flip
58 * complete events.
60 unsigned int drm_timestamp_monotonic = 1;
62 MODULE_AUTHOR(CORE_AUTHOR);
63 MODULE_DESCRIPTION(CORE_DESC);
64 MODULE_PARM_DESC(debug, "Enable debug output");
65 MODULE_PARM_DESC(rnodes, "Enable experimental render nodes API");
66 MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable [msecs]");
67 MODULE_PARM_DESC(timestamp_precision_usec, "Max. error on timestamps [usecs]");
68 MODULE_PARM_DESC(timestamp_monotonic, "Use monotonic timestamps");
70 module_param_named(debug, drm_debug, int, 0600);
71 module_param_named(rnodes, drm_rnodes, int, 0600);
72 module_param_named(universal_planes, drm_universal_planes, int, 0600);
73 module_param_named(vblankoffdelay, drm_vblank_offdelay, int, 0600);
74 module_param_named(timestamp_precision_usec, drm_timestamp_precision, int, 0600);
75 module_param_named(timestamp_monotonic, drm_timestamp_monotonic, int, 0600);
77 struct idr drm_minors_idr;
79 struct class *drm_class;
80 struct dentry *drm_debugfs_root;
82 int drm_err(const char *func, const char *format, ...)
84 #if 0
85 struct va_format vaf;
86 va_list args;
87 int r;
89 va_start(args, format);
91 vaf.fmt = format;
92 vaf.va = &args;
94 r = printk(KERN_ERR "[" DRM_NAME ":%s] *ERROR* %pV", func, &vaf);
96 va_end(args);
98 return r;
99 #endif
100 return 0;
102 EXPORT_SYMBOL(drm_err);
104 void drm_ut_debug_printk(unsigned int request_level,
105 const char *prefix,
106 const char *function_name,
107 const char *format, ...)
109 #if 0
110 struct va_format vaf;
111 va_list args;
113 if (drm_debug & request_level) {
114 va_start(args, format);
115 vaf.fmt = format;
116 vaf.va = &args;
118 if (function_name)
119 printk(KERN_DEBUG "[%s:%s], %pV", prefix,
120 function_name, &vaf);
121 else
122 printk(KERN_DEBUG "%pV", &vaf);
123 va_end(args);
125 #endif
127 EXPORT_SYMBOL(drm_ut_debug_printk);
129 #if 0
130 static int drm_minor_get_id(struct drm_device *dev, int type)
132 int ret;
133 int base = 0, limit = 63;
135 if (type == DRM_MINOR_CONTROL) {
136 base += 64;
137 limit = base + 63;
138 } else if (type == DRM_MINOR_RENDER) {
139 base += 128;
140 limit = base + 63;
143 mutex_lock(&dev->struct_mutex);
144 ret = idr_alloc(&drm_minors_idr, NULL, base, limit, GFP_KERNEL);
145 mutex_unlock(&dev->struct_mutex);
147 return ret == -ENOSPC ? -EINVAL : ret;
150 struct drm_master *drm_master_create(struct drm_minor *minor)
152 struct drm_master *master;
154 master = kzalloc(sizeof(*master), GFP_KERNEL);
155 if (!master)
156 return NULL;
158 kref_init(&master->refcount);
159 spin_lock_init(&master->lock.spinlock);
160 init_waitqueue_head(&master->lock.lock_queue);
161 drm_ht_create(&master->magiclist, DRM_MAGIC_HASH_ORDER);
162 INIT_LIST_HEAD(&master->magicfree);
163 master->minor = minor;
165 list_add_tail(&master->head, &minor->master_list);
167 return master;
170 struct drm_master *drm_master_get(struct drm_master *master)
172 kref_get(&master->refcount);
173 return master;
175 EXPORT_SYMBOL(drm_master_get);
177 static void drm_master_destroy(struct kref *kref)
179 struct drm_master *master = container_of(kref, struct drm_master, refcount);
180 struct drm_magic_entry *pt, *next;
181 struct drm_device *dev = master->minor->dev;
182 struct drm_map_list *r_list, *list_temp;
184 list_del(&master->head);
186 if (dev->driver->master_destroy)
187 dev->driver->master_destroy(dev, master);
189 list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head) {
190 if (r_list->master == master) {
191 drm_rmmap_locked(dev, r_list->map);
192 r_list = NULL;
196 if (master->unique) {
197 kfree(master->unique);
198 master->unique = NULL;
199 master->unique_len = 0;
202 kfree(dev->devname);
203 dev->devname = NULL;
205 list_for_each_entry_safe(pt, next, &master->magicfree, head) {
206 list_del(&pt->head);
207 drm_ht_remove_item(&master->magiclist, &pt->hash_item);
208 kfree(pt);
211 drm_ht_remove(&master->magiclist);
213 kfree(master);
216 void drm_master_put(struct drm_master **master)
218 kref_put(&(*master)->refcount, drm_master_destroy);
219 *master = NULL;
221 EXPORT_SYMBOL(drm_master_put);
222 #endif
224 int drm_setmaster_ioctl(struct drm_device *dev, void *data,
225 struct drm_file *file_priv)
227 DRM_DEBUG("setmaster\n");
229 if (file_priv->master != 0)
230 return (0);
232 return (-EPERM);
235 int drm_dropmaster_ioctl(struct drm_device *dev, void *data,
236 struct drm_file *file_priv)
238 DRM_DEBUG("dropmaster\n");
239 if (file_priv->master != 0)
240 return -EINVAL;
241 return 0;
244 #if 0
246 * drm_get_minor - Allocate and register new DRM minor
247 * @dev: DRM device
248 * @minor: Pointer to where new minor is stored
249 * @type: Type of minor
251 * Allocate a new minor of the given type and register it. A pointer to the new
252 * minor is returned in @minor.
253 * Caller must hold the global DRM mutex.
255 * RETURNS:
256 * 0 on success, negative error code on failure.
258 static int drm_get_minor(struct drm_device *dev, struct drm_minor **minor,
259 int type)
261 struct drm_minor *new_minor;
262 int ret;
263 int minor_id;
265 DRM_DEBUG("\n");
267 minor_id = drm_minor_get_id(dev, type);
268 if (minor_id < 0)
269 return minor_id;
271 new_minor = kzalloc(sizeof(struct drm_minor), GFP_KERNEL);
272 if (!new_minor) {
273 ret = -ENOMEM;
274 goto err_idr;
277 new_minor->type = type;
278 new_minor->device = MKDEV(DRM_MAJOR, minor_id);
279 new_minor->dev = dev;
280 new_minor->index = minor_id;
281 INIT_LIST_HEAD(&new_minor->master_list);
283 idr_replace(&drm_minors_idr, new_minor, minor_id);
285 #if defined(CONFIG_DEBUG_FS)
286 ret = drm_debugfs_init(new_minor, minor_id, drm_debugfs_root);
287 if (ret) {
288 DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n");
289 goto err_mem;
291 #endif
293 ret = drm_sysfs_device_add(new_minor);
294 if (ret) {
295 printk(KERN_ERR
296 "DRM: Error sysfs_device_add.\n");
297 goto err_debugfs;
299 *minor = new_minor;
301 DRM_DEBUG("new minor assigned %d\n", minor_id);
302 return 0;
305 err_debugfs:
306 #if defined(CONFIG_DEBUG_FS)
307 drm_debugfs_cleanup(new_minor);
308 err_mem:
309 #endif
310 kfree(new_minor);
311 err_idr:
312 idr_remove(&drm_minors_idr, minor_id);
313 *minor = NULL;
314 return ret;
318 * drm_unplug_minor - Unplug DRM minor
319 * @minor: Minor to unplug
321 * Unplugs the given DRM minor but keeps the object. So after this returns,
322 * minor->dev is still valid so existing open-files can still access it to get
323 * device information from their drm_file ojects.
324 * If the minor is already unplugged or if @minor is NULL, nothing is done.
325 * The global DRM mutex must be held by the caller.
327 static void drm_unplug_minor(struct drm_minor *minor)
329 if (!minor || !minor->kdev)
330 return;
332 #if defined(CONFIG_DEBUG_FS)
333 drm_debugfs_cleanup(minor);
334 #endif
336 drm_sysfs_device_remove(minor);
337 idr_remove(&drm_minors_idr, minor->index);
341 * drm_put_minor - Destroy DRM minor
342 * @minor: Minor to destroy
344 * This calls drm_unplug_minor() on the given minor and then frees it. Nothing
345 * is done if @minor is NULL. It is fine to call this on already unplugged
346 * minors.
347 * The global DRM mutex must be held by the caller.
349 static void drm_put_minor(struct drm_minor *minor)
351 if (!minor)
352 return;
354 DRM_DEBUG("release secondary minor %d\n", minor->index);
356 drm_unplug_minor(minor);
357 kfree(minor);
361 * Called via drm_exit() at module unload time or when pci device is
362 * unplugged.
364 * Cleans up all DRM device, calling drm_lastclose().
367 void drm_put_dev(struct drm_device *dev)
369 DRM_DEBUG("\n");
371 if (!dev) {
372 DRM_ERROR("cleanup called no dev\n");
373 return;
376 drm_dev_unregister(dev);
377 drm_dev_free(dev);
379 EXPORT_SYMBOL(drm_put_dev);
381 void drm_unplug_dev(struct drm_device *dev)
383 /* for a USB device */
384 if (drm_core_check_feature(dev, DRIVER_MODESET))
385 drm_unplug_minor(dev->control);
386 if (dev->render)
387 drm_unplug_minor(dev->render);
388 drm_unplug_minor(dev->primary);
390 mutex_lock(&drm_global_mutex);
392 drm_device_set_unplugged(dev);
394 if (dev->open_count == 0) {
395 drm_put_dev(dev);
397 mutex_unlock(&drm_global_mutex);
399 EXPORT_SYMBOL(drm_unplug_dev);
400 #endif
402 #if 0
404 * DRM internal mount
405 * We want to be able to allocate our own "struct address_space" to control
406 * memory-mappings in VRAM (or stolen RAM, ...). However, core MM does not allow
407 * stand-alone address_space objects, so we need an underlying inode. As there
408 * is no way to allocate an independent inode easily, we need a fake internal
409 * VFS mount-point.
411 * The drm_fs_inode_new() function allocates a new inode, drm_fs_inode_free()
412 * frees it again. You are allowed to use iget() and iput() to get references to
413 * the inode. But each drm_fs_inode_new() call must be paired with exactly one
414 * drm_fs_inode_free() call (which does not have to be the last iput()).
415 * We use drm_fs_inode_*() to manage our internal VFS mount-point and share it
416 * between multiple inode-users. You could, technically, call
417 * iget() + drm_fs_inode_free() directly after alloc and sometime later do an
418 * iput(), but this way you'd end up with a new vfsmount for each inode.
421 static int drm_fs_cnt;
422 static struct vfsmount *drm_fs_mnt;
424 static const struct dentry_operations drm_fs_dops = {
425 .d_dname = simple_dname,
428 static const struct super_operations drm_fs_sops = {
429 .statfs = simple_statfs,
432 static struct dentry *drm_fs_mount(struct file_system_type *fs_type, int flags,
433 const char *dev_name, void *data)
435 return mount_pseudo(fs_type,
436 "drm:",
437 &drm_fs_sops,
438 &drm_fs_dops,
439 0x010203ff);
442 static struct file_system_type drm_fs_type = {
443 .name = "drm",
444 .owner = THIS_MODULE,
445 .mount = drm_fs_mount,
446 .kill_sb = kill_anon_super,
449 static struct inode *drm_fs_inode_new(void)
451 struct inode *inode;
452 int r;
454 r = simple_pin_fs(&drm_fs_type, &drm_fs_mnt, &drm_fs_cnt);
455 if (r < 0) {
456 DRM_ERROR("Cannot mount pseudo fs: %d\n", r);
457 return ERR_PTR(r);
460 inode = alloc_anon_inode(drm_fs_mnt->mnt_sb);
461 if (IS_ERR(inode))
462 simple_release_fs(&drm_fs_mnt, &drm_fs_cnt);
464 return inode;
467 static void drm_fs_inode_free(struct inode *inode)
469 if (inode) {
470 iput(inode);
471 simple_release_fs(&drm_fs_mnt, &drm_fs_cnt);
476 * drm_dev_alloc - Allocate new drm device
477 * @driver: DRM driver to allocate device for
478 * @parent: Parent device object
480 * Allocate and initialize a new DRM device. No device registration is done.
481 * Call drm_dev_register() to advertice the device to user space and register it
482 * with other core subsystems.
484 * RETURNS:
485 * Pointer to new DRM device, or NULL if out of memory.
487 struct drm_device *drm_dev_alloc(struct drm_driver *driver,
488 struct device *parent)
490 struct drm_device *dev;
491 int ret;
493 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
494 if (!dev)
495 return NULL;
497 dev->dev = parent;
498 dev->driver = driver;
500 INIT_LIST_HEAD(&dev->filelist);
501 INIT_LIST_HEAD(&dev->ctxlist);
502 INIT_LIST_HEAD(&dev->vmalist);
503 INIT_LIST_HEAD(&dev->maplist);
504 INIT_LIST_HEAD(&dev->vblank_event_list);
506 spin_lock_init(&dev->count_lock);
507 spin_lock_init(&dev->event_lock);
508 mutex_init(&dev->struct_mutex);
509 mutex_init(&dev->ctxlist_mutex);
511 if (drm_ht_create(&dev->map_hash, 12))
512 goto err_free;
514 ret = drm_ctxbitmap_init(dev);
515 if (ret) {
516 DRM_ERROR("Cannot allocate memory for context bitmap.\n");
517 goto err_ht;
520 if (driver->driver_features & DRIVER_GEM) {
521 ret = drm_gem_init(dev);
522 if (ret) {
523 DRM_ERROR("Cannot initialize graphics execution manager (GEM)\n");
524 goto err_ctxbitmap;
528 return dev;
530 err_ctxbitmap:
531 drm_ctxbitmap_cleanup(dev);
532 err_ht:
533 drm_ht_remove(&dev->map_hash);
534 err_free:
535 kfree(dev);
536 return NULL;
538 EXPORT_SYMBOL(drm_dev_alloc);
541 * drm_dev_free - Free DRM device
542 * @dev: DRM device to free
544 * Free a DRM device that has previously been allocated via drm_dev_alloc().
545 * You must not use kfree() instead or you will leak memory.
547 * This must not be called once the device got registered. Use drm_put_dev()
548 * instead, which then calls drm_dev_free().
550 void drm_dev_free(struct drm_device *dev)
552 drm_put_minor(dev->control);
553 drm_put_minor(dev->render);
554 drm_put_minor(dev->primary);
556 if (dev->driver->driver_features & DRIVER_GEM)
557 drm_gem_destroy(dev);
559 drm_ctxbitmap_cleanup(dev);
560 drm_ht_remove(&dev->map_hash);
562 kfree(dev->devname);
563 kfree(dev);
565 EXPORT_SYMBOL(drm_dev_free);
568 * drm_dev_register - Register DRM device
569 * @dev: Device to register
571 * Register the DRM device @dev with the system, advertise device to user-space
572 * and start normal device operation. @dev must be allocated via drm_dev_alloc()
573 * previously.
575 * Never call this twice on any device!
577 * RETURNS:
578 * 0 on success, negative error code on failure.
580 int drm_dev_register(struct drm_device *dev, unsigned long flags)
582 int ret;
584 mutex_lock(&drm_global_mutex);
586 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
587 ret = drm_get_minor(dev, &dev->control, DRM_MINOR_CONTROL);
588 if (ret)
589 goto out_unlock;
592 if (drm_core_check_feature(dev, DRIVER_RENDER) && drm_rnodes) {
593 ret = drm_get_minor(dev, &dev->render, DRM_MINOR_RENDER);
594 if (ret)
595 goto err_control_node;
598 ret = drm_get_minor(dev, &dev->primary, DRM_MINOR_LEGACY);
599 if (ret)
600 goto err_render_node;
602 if (dev->driver->load) {
603 ret = dev->driver->load(dev, flags);
604 if (ret)
605 goto err_primary_node;
608 /* setup grouping for legacy outputs */
609 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
610 ret = drm_mode_group_init_legacy_group(dev,
611 &dev->primary->mode_group);
612 if (ret)
613 goto err_unload;
616 ret = 0;
617 goto out_unlock;
619 err_unload:
620 if (dev->driver->unload)
621 dev->driver->unload(dev);
622 err_primary_node:
623 drm_unplug_minor(dev->primary);
624 err_render_node:
625 drm_unplug_minor(dev->render);
626 err_control_node:
627 drm_unplug_minor(dev->control);
628 out_unlock:
629 mutex_unlock(&drm_global_mutex);
630 return ret;
632 EXPORT_SYMBOL(drm_dev_register);
635 * drm_dev_unregister - Unregister DRM device
636 * @dev: Device to unregister
638 * Unregister the DRM device from the system. This does the reverse of
639 * drm_dev_register() but does not deallocate the device. The caller must call
640 * drm_dev_free() to free all resources.
642 void drm_dev_unregister(struct drm_device *dev)
644 struct drm_map_list *r_list, *list_temp;
646 drm_lastclose(dev);
648 if (dev->driver->unload)
649 dev->driver->unload(dev);
651 if (dev->agp)
652 drm_pci_agp_destroy(dev);
654 drm_vblank_cleanup(dev);
656 list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head)
657 drm_rmmap(dev, r_list->map);
659 drm_unplug_minor(dev->control);
660 drm_unplug_minor(dev->render);
661 drm_unplug_minor(dev->primary);
663 EXPORT_SYMBOL(drm_dev_unregister);
664 #endif