mgag200_drv.c 3.4 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 DEFINE_PCI_DEVICE_TABLE(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. {0,}
  33. };
  34. MODULE_DEVICE_TABLE(pci, pciidlist);
  35. static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev)
  36. {
  37. struct apertures_struct *ap;
  38. bool primary = false;
  39. ap = alloc_apertures(1);
  40. if (!ap)
  41. return;
  42. ap->ranges[0].base = pci_resource_start(pdev, 0);
  43. ap->ranges[0].size = pci_resource_len(pdev, 0);
  44. #ifdef CONFIG_X86
  45. primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  46. #endif
  47. remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
  48. kfree(ap);
  49. }
  50. static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  51. {
  52. mgag200_kick_out_firmware_fb(pdev);
  53. return drm_get_pci_dev(pdev, ent, &driver);
  54. }
  55. static void mga_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 mgag200_driver_fops = {
  61. .owner = THIS_MODULE,
  62. .open = drm_open,
  63. .release = drm_release,
  64. .unlocked_ioctl = drm_ioctl,
  65. .mmap = mgag200_mmap,
  66. .poll = drm_poll,
  67. .fasync = drm_fasync,
  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 | DRIVER_USE_MTRR,
  75. .load = mgag200_driver_load,
  76. .unload = mgag200_driver_unload,
  77. .fops = &mgag200_driver_fops,
  78. .name = DRIVER_NAME,
  79. .desc = DRIVER_DESC,
  80. .date = DRIVER_DATE,
  81. .major = DRIVER_MAJOR,
  82. .minor = DRIVER_MINOR,
  83. .patchlevel = DRIVER_PATCHLEVEL,
  84. .gem_init_object = mgag200_gem_init_object,
  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 = mgag200_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");