cirrus_drv.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 <drm/drm_crtc_helper.h>
  15. #include "cirrus_drv.h"
  16. int cirrus_modeset = -1;
  17. int cirrus_bpp = 24;
  18. MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
  19. module_param_named(modeset, cirrus_modeset, int, 0400);
  20. MODULE_PARM_DESC(bpp, "Max bits-per-pixel (default:24)");
  21. module_param_named(bpp, cirrus_bpp, int, 0400);
  22. /*
  23. * This is the generic driver code. This binds the driver to the drm core,
  24. * which then performs further device association and calls our graphics init
  25. * functions
  26. */
  27. static struct drm_driver driver;
  28. /* only bind to the cirrus chip in qemu */
  29. static const struct pci_device_id pciidlist[] = {
  30. { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446,
  31. PCI_SUBVENDOR_ID_REDHAT_QUMRANET, PCI_SUBDEVICE_ID_QEMU,
  32. 0, 0, 0 },
  33. { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, PCI_VENDOR_ID_XEN,
  34. 0x0001, 0, 0, 0 },
  35. {0,}
  36. };
  37. static int cirrus_kick_out_firmware_fb(struct pci_dev *pdev)
  38. {
  39. struct apertures_struct *ap;
  40. bool primary = false;
  41. ap = alloc_apertures(1);
  42. if (!ap)
  43. return -ENOMEM;
  44. ap->ranges[0].base = pci_resource_start(pdev, 0);
  45. ap->ranges[0].size = pci_resource_len(pdev, 0);
  46. #ifdef CONFIG_X86
  47. primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  48. #endif
  49. drm_fb_helper_remove_conflicting_framebuffers(ap, "cirrusdrmfb", primary);
  50. kfree(ap);
  51. return 0;
  52. }
  53. static int cirrus_pci_probe(struct pci_dev *pdev,
  54. const struct pci_device_id *ent)
  55. {
  56. int ret;
  57. ret = cirrus_kick_out_firmware_fb(pdev);
  58. if (ret)
  59. return ret;
  60. return drm_get_pci_dev(pdev, ent, &driver);
  61. }
  62. static void cirrus_pci_remove(struct pci_dev *pdev)
  63. {
  64. struct drm_device *dev = pci_get_drvdata(pdev);
  65. drm_put_dev(dev);
  66. }
  67. #ifdef CONFIG_PM_SLEEP
  68. static int cirrus_pm_suspend(struct device *dev)
  69. {
  70. struct pci_dev *pdev = to_pci_dev(dev);
  71. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  72. struct cirrus_device *cdev = drm_dev->dev_private;
  73. drm_kms_helper_poll_disable(drm_dev);
  74. if (cdev->mode_info.gfbdev) {
  75. console_lock();
  76. drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 1);
  77. console_unlock();
  78. }
  79. return 0;
  80. }
  81. static int cirrus_pm_resume(struct device *dev)
  82. {
  83. struct pci_dev *pdev = to_pci_dev(dev);
  84. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  85. struct cirrus_device *cdev = drm_dev->dev_private;
  86. drm_helper_resume_force_mode(drm_dev);
  87. if (cdev->mode_info.gfbdev) {
  88. console_lock();
  89. drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 0);
  90. console_unlock();
  91. }
  92. drm_kms_helper_poll_enable(drm_dev);
  93. return 0;
  94. }
  95. #endif
  96. static const struct file_operations cirrus_driver_fops = {
  97. .owner = THIS_MODULE,
  98. .open = drm_open,
  99. .release = drm_release,
  100. .unlocked_ioctl = drm_ioctl,
  101. .mmap = cirrus_mmap,
  102. .poll = drm_poll,
  103. .compat_ioctl = drm_compat_ioctl,
  104. };
  105. static struct drm_driver driver = {
  106. .driver_features = DRIVER_MODESET | DRIVER_GEM,
  107. .load = cirrus_driver_load,
  108. .unload = cirrus_driver_unload,
  109. .fops = &cirrus_driver_fops,
  110. .name = DRIVER_NAME,
  111. .desc = DRIVER_DESC,
  112. .date = DRIVER_DATE,
  113. .major = DRIVER_MAJOR,
  114. .minor = DRIVER_MINOR,
  115. .patchlevel = DRIVER_PATCHLEVEL,
  116. .gem_free_object_unlocked = cirrus_gem_free_object,
  117. .dumb_create = cirrus_dumb_create,
  118. .dumb_map_offset = cirrus_dumb_mmap_offset,
  119. };
  120. static const struct dev_pm_ops cirrus_pm_ops = {
  121. SET_SYSTEM_SLEEP_PM_OPS(cirrus_pm_suspend,
  122. cirrus_pm_resume)
  123. };
  124. static struct pci_driver cirrus_pci_driver = {
  125. .name = DRIVER_NAME,
  126. .id_table = pciidlist,
  127. .probe = cirrus_pci_probe,
  128. .remove = cirrus_pci_remove,
  129. .driver.pm = &cirrus_pm_ops,
  130. };
  131. static int __init cirrus_init(void)
  132. {
  133. if (vgacon_text_force() && cirrus_modeset == -1)
  134. return -EINVAL;
  135. if (cirrus_modeset == 0)
  136. return -EINVAL;
  137. return pci_register_driver(&cirrus_pci_driver);
  138. }
  139. static void __exit cirrus_exit(void)
  140. {
  141. pci_unregister_driver(&cirrus_pci_driver);
  142. }
  143. module_init(cirrus_init);
  144. module_exit(cirrus_exit);
  145. MODULE_DEVICE_TABLE(pci, pciidlist);
  146. MODULE_AUTHOR(DRIVER_AUTHOR);
  147. MODULE_DESCRIPTION(DRIVER_DESC);
  148. MODULE_LICENSE("GPL");