mgag200_drv.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "drmP.h"
  14. #include "drm.h"
  15. #include "mgag200_drv.h"
  16. #include "drm_pciids.h"
  17. /*
  18. * This is the generic driver code. This binds the driver to the drm core,
  19. * which then performs further device association and calls our graphics init
  20. * functions
  21. */
  22. int mgag200_modeset = -1;
  23. MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
  24. module_param_named(modeset, mgag200_modeset, int, 0400);
  25. static struct drm_driver driver;
  26. static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
  27. { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_A },
  28. { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
  29. { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
  30. { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
  31. { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
  32. { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
  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 __devinit
  52. mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  53. {
  54. mgag200_kick_out_firmware_fb(pdev);
  55. return drm_get_pci_dev(pdev, ent, &driver);
  56. }
  57. static void mga_pci_remove(struct pci_dev *pdev)
  58. {
  59. struct drm_device *dev = pci_get_drvdata(pdev);
  60. drm_put_dev(dev);
  61. }
  62. static const struct file_operations mgag200_driver_fops = {
  63. .owner = THIS_MODULE,
  64. .open = drm_open,
  65. .release = drm_release,
  66. .unlocked_ioctl = drm_ioctl,
  67. .mmap = mgag200_mmap,
  68. .poll = drm_poll,
  69. .fasync = drm_fasync,
  70. .read = drm_read,
  71. };
  72. static struct drm_driver driver = {
  73. .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_USE_MTRR,
  74. .load = mgag200_driver_load,
  75. .unload = mgag200_driver_unload,
  76. .fops = &mgag200_driver_fops,
  77. .name = DRIVER_NAME,
  78. .desc = DRIVER_DESC,
  79. .date = DRIVER_DATE,
  80. .major = DRIVER_MAJOR,
  81. .minor = DRIVER_MINOR,
  82. .patchlevel = DRIVER_PATCHLEVEL,
  83. .gem_init_object = mgag200_gem_init_object,
  84. .gem_free_object = mgag200_gem_free_object,
  85. .dumb_create = mgag200_dumb_create,
  86. .dumb_map_offset = mgag200_dumb_mmap_offset,
  87. .dumb_destroy = mgag200_dumb_destroy,
  88. };
  89. static struct pci_driver mgag200_pci_driver = {
  90. .name = DRIVER_NAME,
  91. .id_table = pciidlist,
  92. .probe = mga_pci_probe,
  93. .remove = mga_pci_remove,
  94. };
  95. static int __init mgag200_init(void)
  96. {
  97. #ifdef CONFIG_VGA_CONSOLE
  98. if (vgacon_text_force() && mgag200_modeset == -1)
  99. return -EINVAL;
  100. #endif
  101. if (mgag200_modeset == 0)
  102. return -EINVAL;
  103. return drm_pci_init(&driver, &mgag200_pci_driver);
  104. }
  105. static void __exit mgag200_exit(void)
  106. {
  107. drm_pci_exit(&driver, &mgag200_pci_driver);
  108. }
  109. module_init(mgag200_init);
  110. module_exit(mgag200_exit);
  111. MODULE_AUTHOR(DRIVER_AUTHOR);
  112. MODULE_DESCRIPTION(DRIVER_DESC);
  113. MODULE_LICENSE("GPL");