qxl_drv.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* vim: set ts=8 sw=8 tw=78 ai noexpandtab */
  2. /* qxl_drv.c -- QXL driver -*- linux-c -*-
  3. *
  4. * Copyright 2011 Red Hat, Inc.
  5. * All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the next
  15. * paragraph) shall be included in all copies or substantial portions of the
  16. * Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Authors:
  27. * Dave Airlie <airlie@redhat.com>
  28. * Alon Levy <alevy@redhat.com>
  29. */
  30. #include <linux/module.h>
  31. #include <linux/console.h>
  32. #include "drmP.h"
  33. #include "drm/drm.h"
  34. #include "qxl_drv.h"
  35. extern int qxl_max_ioctls;
  36. static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
  37. { 0x1b36, 0x100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8,
  38. 0xffff00, 0 },
  39. { 0x1b36, 0x100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_OTHER << 8,
  40. 0xffff00, 0 },
  41. { 0, 0, 0 },
  42. };
  43. MODULE_DEVICE_TABLE(pci, pciidlist);
  44. static int qxl_modeset = -1;
  45. int qxl_num_crtc = 4;
  46. MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
  47. module_param_named(modeset, qxl_modeset, int, 0400);
  48. MODULE_PARM_DESC(num_heads, "Number of virtual crtcs to expose (default 4)");
  49. module_param_named(num_heads, qxl_num_crtc, int, 0400);
  50. static struct drm_driver qxl_driver;
  51. static struct pci_driver qxl_pci_driver;
  52. static int
  53. qxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  54. {
  55. if (pdev->revision < 4) {
  56. DRM_ERROR("qxl too old, doesn't support client_monitors_config,"
  57. " use xf86-video-qxl in user mode");
  58. return -EINVAL; /* TODO: ENODEV ? */
  59. }
  60. return drm_get_pci_dev(pdev, ent, &qxl_driver);
  61. }
  62. static void
  63. qxl_pci_remove(struct pci_dev *pdev)
  64. {
  65. struct drm_device *dev = pci_get_drvdata(pdev);
  66. drm_put_dev(dev);
  67. }
  68. static struct pci_driver qxl_pci_driver = {
  69. .name = DRIVER_NAME,
  70. .id_table = pciidlist,
  71. .probe = qxl_pci_probe,
  72. .remove = qxl_pci_remove,
  73. };
  74. static const struct file_operations qxl_fops = {
  75. .owner = THIS_MODULE,
  76. .open = drm_open,
  77. .release = drm_release,
  78. .unlocked_ioctl = drm_ioctl,
  79. .poll = drm_poll,
  80. .fasync = drm_fasync,
  81. .mmap = qxl_mmap,
  82. };
  83. static struct drm_driver qxl_driver = {
  84. .driver_features = DRIVER_GEM | DRIVER_MODESET |
  85. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED,
  86. .dev_priv_size = 0,
  87. .load = qxl_driver_load,
  88. .unload = qxl_driver_unload,
  89. .dumb_create = qxl_mode_dumb_create,
  90. .dumb_map_offset = qxl_mode_dumb_mmap,
  91. .dumb_destroy = qxl_mode_dumb_destroy,
  92. #if defined(CONFIG_DEBUG_FS)
  93. .debugfs_init = qxl_debugfs_init,
  94. .debugfs_cleanup = qxl_debugfs_takedown,
  95. #endif
  96. .gem_init_object = qxl_gem_object_init,
  97. .gem_free_object = qxl_gem_object_free,
  98. .gem_open_object = qxl_gem_object_open,
  99. .gem_close_object = qxl_gem_object_close,
  100. .fops = &qxl_fops,
  101. .ioctls = qxl_ioctls,
  102. .irq_handler = qxl_irq_handler,
  103. .name = DRIVER_NAME,
  104. .desc = DRIVER_DESC,
  105. .date = DRIVER_DATE,
  106. .major = 0,
  107. .minor = 1,
  108. .patchlevel = 0,
  109. };
  110. static int __init qxl_init(void)
  111. {
  112. #ifdef CONFIG_VGA_CONSOLE
  113. if (vgacon_text_force() && qxl_modeset == -1)
  114. return -EINVAL;
  115. #endif
  116. if (qxl_modeset == 0)
  117. return -EINVAL;
  118. qxl_driver.num_ioctls = qxl_max_ioctls;
  119. return drm_pci_init(&qxl_driver, &qxl_pci_driver);
  120. }
  121. static void __exit qxl_exit(void)
  122. {
  123. drm_pci_exit(&qxl_driver, &qxl_pci_driver);
  124. }
  125. module_init(qxl_init);
  126. module_exit(qxl_exit);
  127. MODULE_AUTHOR(DRIVER_AUTHOR);
  128. MODULE_DESCRIPTION(DRIVER_DESC);
  129. MODULE_LICENSE("GPL and additional rights");