cirrus_drv.c 3.0 KB

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