mgag200_drv.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright 2012 Red Hat
  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 "mgag200_drv.h"
  15. #include <drm/drm_pciids.h>
  16. /*
  17. * This is the generic driver code. This binds the driver to the drm core,
  18. * which then performs further device association and calls our graphics init
  19. * functions
  20. */
  21. int mgag200_modeset = -1;
  22. MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
  23. module_param_named(modeset, mgag200_modeset, int, 0400);
  24. static struct drm_driver driver;
  25. static const struct pci_device_id pciidlist[] = {
  26. { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_A },
  27. { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
  28. { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
  29. { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
  30. { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
  31. { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
  32. { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
  33. {0,}
  34. };
  35. MODULE_DEVICE_TABLE(pci, pciidlist);
  36. static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev)
  37. {
  38. struct apertures_struct *ap;
  39. bool primary = false;
  40. ap = alloc_apertures(1);
  41. if (!ap)
  42. return;
  43. ap->ranges[0].base = pci_resource_start(pdev, 0);
  44. ap->ranges[0].size = pci_resource_len(pdev, 0);
  45. #ifdef CONFIG_X86
  46. primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  47. #endif
  48. remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
  49. kfree(ap);
  50. }
  51. static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  52. {
  53. mgag200_kick_out_firmware_fb(pdev);
  54. return drm_get_pci_dev(pdev, ent, &driver);
  55. }
  56. static void mga_pci_remove(struct pci_dev *pdev)
  57. {
  58. struct drm_device *dev = pci_get_drvdata(pdev);
  59. drm_put_dev(dev);
  60. }
  61. static const struct file_operations mgag200_driver_fops = {
  62. .owner = THIS_MODULE,
  63. .open = drm_open,
  64. .release = drm_release,
  65. .unlocked_ioctl = drm_ioctl,
  66. .mmap = mgag200_mmap,
  67. .poll = drm_poll,
  68. #ifdef CONFIG_COMPAT
  69. .compat_ioctl = drm_compat_ioctl,
  70. #endif
  71. .read = drm_read,
  72. };
  73. static struct drm_driver driver = {
  74. .driver_features = DRIVER_GEM | DRIVER_MODESET,
  75. .load = mgag200_driver_load,
  76. .unload = mgag200_driver_unload,
  77. .set_busid = drm_pci_set_busid,
  78. .fops = &mgag200_driver_fops,
  79. .name = DRIVER_NAME,
  80. .desc = DRIVER_DESC,
  81. .date = DRIVER_DATE,
  82. .major = DRIVER_MAJOR,
  83. .minor = DRIVER_MINOR,
  84. .patchlevel = DRIVER_PATCHLEVEL,
  85. .gem_free_object = mgag200_gem_free_object,
  86. .dumb_create = mgag200_dumb_create,
  87. .dumb_map_offset = mgag200_dumb_mmap_offset,
  88. .dumb_destroy = drm_gem_dumb_destroy,
  89. };
  90. static struct pci_driver mgag200_pci_driver = {
  91. .name = DRIVER_NAME,
  92. .id_table = pciidlist,
  93. .probe = mga_pci_probe,
  94. .remove = mga_pci_remove,
  95. };
  96. static int __init mgag200_init(void)
  97. {
  98. #ifdef CONFIG_VGA_CONSOLE
  99. if (vgacon_text_force() && mgag200_modeset == -1)
  100. return -EINVAL;
  101. #endif
  102. if (mgag200_modeset == 0)
  103. return -EINVAL;
  104. return drm_pci_init(&driver, &mgag200_pci_driver);
  105. }
  106. static void __exit mgag200_exit(void)
  107. {
  108. drm_pci_exit(&driver, &mgag200_pci_driver);
  109. }
  110. module_init(mgag200_init);
  111. module_exit(mgag200_exit);
  112. MODULE_AUTHOR(DRIVER_AUTHOR);
  113. MODULE_DESCRIPTION(DRIVER_DESC);
  114. MODULE_LICENSE("GPL");