bochs_drv.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. */
  7. #include <linux/mm.h>
  8. #include <linux/module.h>
  9. #include <linux/slab.h>
  10. #include "bochs.h"
  11. static bool enable_fbdev = true;
  12. module_param_named(fbdev, enable_fbdev, bool, 0444);
  13. MODULE_PARM_DESC(fbdev, "register fbdev device");
  14. /* ---------------------------------------------------------------------- */
  15. /* drm interface */
  16. static int bochs_unload(struct drm_device *dev)
  17. {
  18. struct bochs_device *bochs = dev->dev_private;
  19. bochs_fbdev_fini(bochs);
  20. bochs_kms_fini(bochs);
  21. bochs_mm_fini(bochs);
  22. bochs_hw_fini(dev);
  23. kfree(bochs);
  24. dev->dev_private = NULL;
  25. return 0;
  26. }
  27. static int bochs_load(struct drm_device *dev, unsigned long flags)
  28. {
  29. struct bochs_device *bochs;
  30. int ret;
  31. bochs = kzalloc(sizeof(*bochs), GFP_KERNEL);
  32. if (bochs == NULL)
  33. return -ENOMEM;
  34. dev->dev_private = bochs;
  35. bochs->dev = dev;
  36. ret = bochs_hw_init(dev, flags);
  37. if (ret)
  38. goto err;
  39. ret = bochs_mm_init(bochs);
  40. if (ret)
  41. goto err;
  42. ret = bochs_kms_init(bochs);
  43. if (ret)
  44. goto err;
  45. if (enable_fbdev)
  46. bochs_fbdev_init(bochs);
  47. return 0;
  48. err:
  49. bochs_unload(dev);
  50. return ret;
  51. }
  52. static const struct file_operations bochs_fops = {
  53. .owner = THIS_MODULE,
  54. .open = drm_open,
  55. .release = drm_release,
  56. .unlocked_ioctl = drm_ioctl,
  57. #ifdef CONFIG_COMPAT
  58. .compat_ioctl = drm_compat_ioctl,
  59. #endif
  60. .poll = drm_poll,
  61. .read = drm_read,
  62. .llseek = no_llseek,
  63. .mmap = bochs_mmap,
  64. };
  65. static struct drm_driver bochs_driver = {
  66. .driver_features = DRIVER_GEM | DRIVER_MODESET,
  67. .load = bochs_load,
  68. .unload = bochs_unload,
  69. .fops = &bochs_fops,
  70. .name = "bochs-drm",
  71. .desc = "bochs dispi vga interface (qemu stdvga)",
  72. .date = "20130925",
  73. .major = 1,
  74. .minor = 0,
  75. .gem_free_object = bochs_gem_free_object,
  76. .dumb_create = bochs_dumb_create,
  77. .dumb_map_offset = bochs_dumb_mmap_offset,
  78. .dumb_destroy = drm_gem_dumb_destroy,
  79. };
  80. /* ---------------------------------------------------------------------- */
  81. /* pci interface */
  82. static int bochs_kick_out_firmware_fb(struct pci_dev *pdev)
  83. {
  84. struct apertures_struct *ap;
  85. ap = alloc_apertures(1);
  86. if (!ap)
  87. return -ENOMEM;
  88. ap->ranges[0].base = pci_resource_start(pdev, 0);
  89. ap->ranges[0].size = pci_resource_len(pdev, 0);
  90. remove_conflicting_framebuffers(ap, "bochsdrmfb", false);
  91. kfree(ap);
  92. return 0;
  93. }
  94. static int bochs_pci_probe(struct pci_dev *pdev,
  95. const struct pci_device_id *ent)
  96. {
  97. int ret;
  98. ret = bochs_kick_out_firmware_fb(pdev);
  99. if (ret)
  100. return ret;
  101. return drm_get_pci_dev(pdev, ent, &bochs_driver);
  102. }
  103. static void bochs_pci_remove(struct pci_dev *pdev)
  104. {
  105. struct drm_device *dev = pci_get_drvdata(pdev);
  106. drm_put_dev(dev);
  107. }
  108. static DEFINE_PCI_DEVICE_TABLE(bochs_pci_tbl) = {
  109. {
  110. .vendor = 0x1234,
  111. .device = 0x1111,
  112. .subvendor = 0x1af4,
  113. .subdevice = 0x1100,
  114. .driver_data = BOCHS_QEMU_STDVGA,
  115. },
  116. {
  117. .vendor = 0x1234,
  118. .device = 0x1111,
  119. .subvendor = PCI_ANY_ID,
  120. .subdevice = PCI_ANY_ID,
  121. .driver_data = BOCHS_UNKNOWN,
  122. },
  123. { /* end of list */ }
  124. };
  125. static struct pci_driver bochs_pci_driver = {
  126. .name = "bochs-drm",
  127. .id_table = bochs_pci_tbl,
  128. .probe = bochs_pci_probe,
  129. .remove = bochs_pci_remove,
  130. };
  131. /* ---------------------------------------------------------------------- */
  132. /* module init/exit */
  133. static int __init bochs_init(void)
  134. {
  135. return drm_pci_init(&bochs_driver, &bochs_pci_driver);
  136. }
  137. static void __exit bochs_exit(void)
  138. {
  139. drm_pci_exit(&bochs_driver, &bochs_pci_driver);
  140. }
  141. module_init(bochs_init);
  142. module_exit(bochs_exit);
  143. MODULE_DEVICE_TABLE(pci, bochs_pci_tbl);
  144. MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
  145. MODULE_LICENSE("GPL");