cirrus_drv.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright 2012 Red Hat <mjg@redhat.com>
  3. *
  4. * This file is subject to the terms and conditions of the GNU General
  5. * Public License version 2. See the file COPYING in the main
  6. * directory of this archive for more details.
  7. *
  8. * Authors: Matthew Garrett
  9. * Dave Airlie
  10. */
  11. #include <linux/module.h>
  12. #include <linux/console.h>
  13. #include <drm/drmP.h>
  14. #include "cirrus_drv.h"
  15. int cirrus_modeset = -1;
  16. MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
  17. module_param_named(modeset, cirrus_modeset, int, 0400);
  18. /*
  19. * This is the generic driver code. This binds the driver to the drm core,
  20. * which then performs further device association and calls our graphics init
  21. * functions
  22. */
  23. static struct drm_driver driver;
  24. /* only bind to the cirrus chip in qemu */
  25. static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
  26. { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, 0x1af4, 0x1100, 0,
  27. 0, 0 },
  28. {0,}
  29. };
  30. static int cirrus_kick_out_firmware_fb(struct pci_dev *pdev)
  31. {
  32. struct apertures_struct *ap;
  33. bool primary = false;
  34. ap = alloc_apertures(1);
  35. if (!ap)
  36. return -ENOMEM;
  37. ap->ranges[0].base = pci_resource_start(pdev, 0);
  38. ap->ranges[0].size = pci_resource_len(pdev, 0);
  39. #ifdef CONFIG_X86
  40. primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  41. #endif
  42. remove_conflicting_framebuffers(ap, "cirrusdrmfb", primary);
  43. kfree(ap);
  44. return 0;
  45. }
  46. static int cirrus_pci_probe(struct pci_dev *pdev,
  47. const struct pci_device_id *ent)
  48. {
  49. int ret;
  50. ret = cirrus_kick_out_firmware_fb(pdev);
  51. if (ret)
  52. return ret;
  53. return drm_get_pci_dev(pdev, ent, &driver);
  54. }
  55. static void cirrus_pci_remove(struct pci_dev *pdev)
  56. {
  57. struct drm_device *dev = pci_get_drvdata(pdev);
  58. drm_put_dev(dev);
  59. }
  60. static const struct file_operations cirrus_driver_fops = {
  61. .owner = THIS_MODULE,
  62. .open = drm_open,
  63. .release = drm_release,
  64. .unlocked_ioctl = drm_ioctl,
  65. .mmap = cirrus_mmap,
  66. .poll = drm_poll,
  67. #ifdef CONFIG_COMPAT
  68. .compat_ioctl = drm_compat_ioctl,
  69. #endif
  70. .fasync = drm_fasync,
  71. };
  72. static struct drm_driver driver = {
  73. .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_USE_MTRR,
  74. .load = cirrus_driver_load,
  75. .unload = cirrus_driver_unload,
  76. .fops = &cirrus_driver_fops,
  77. .name = DRIVER_NAME,
  78. .desc = DRIVER_DESC,
  79. .date = DRIVER_DATE,
  80. .major = DRIVER_MAJOR,
  81. .minor = DRIVER_MINOR,
  82. .patchlevel = DRIVER_PATCHLEVEL,
  83. .gem_init_object = cirrus_gem_init_object,
  84. .gem_free_object = cirrus_gem_free_object,
  85. .dumb_create = cirrus_dumb_create,
  86. .dumb_map_offset = cirrus_dumb_mmap_offset,
  87. .dumb_destroy = cirrus_dumb_destroy,
  88. };
  89. static struct pci_driver cirrus_pci_driver = {
  90. .name = DRIVER_NAME,
  91. .id_table = pciidlist,
  92. .probe = cirrus_pci_probe,
  93. .remove = cirrus_pci_remove,
  94. };
  95. static int __init cirrus_init(void)
  96. {
  97. #ifdef CONFIG_VGA_CONSOLE
  98. if (vgacon_text_force() && cirrus_modeset == -1)
  99. return -EINVAL;
  100. #endif
  101. if (cirrus_modeset == 0)
  102. return -EINVAL;
  103. return drm_pci_init(&driver, &cirrus_pci_driver);
  104. }
  105. static void __exit cirrus_exit(void)
  106. {
  107. drm_pci_exit(&driver, &cirrus_pci_driver);
  108. }
  109. module_init(cirrus_init);
  110. module_exit(cirrus_exit);
  111. MODULE_DEVICE_TABLE(pci, pciidlist);
  112. MODULE_AUTHOR(DRIVER_AUTHOR);
  113. MODULE_DESCRIPTION(DRIVER_DESC);
  114. MODULE_LICENSE("GPL");