2 * Copyright 2012 Red Hat
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.
8 * Authors: Matthew Garrett
11 #include <linux/module.h>
12 #include <linux/console.h>
16 #include "mgag200_drv.h"
18 #include "drm_pciids.h"
21 * This is the generic driver code. This binds the driver to the drm core,
22 * which then performs further device association and calls our graphics init
25 int mgag200_modeset = -1;
27 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
28 module_param_named(modeset, mgag200_modeset, int, 0400);
30 static struct drm_driver driver;
32 static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
33 { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_A },
34 { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
35 { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
36 { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
37 { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
38 { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
42 MODULE_DEVICE_TABLE(pci, pciidlist);
44 static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev)
46 struct apertures_struct *ap;
49 ap = alloc_apertures(1);
53 ap->ranges[0].base = pci_resource_start(pdev, 0);
54 ap->ranges[0].size = pci_resource_len(pdev, 0);
57 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
59 remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
65 mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
67 mgag200_kick_out_firmware_fb(pdev);
69 return drm_get_pci_dev(pdev, ent, &driver);
72 static void mga_pci_remove(struct pci_dev *pdev)
74 struct drm_device *dev = pci_get_drvdata(pdev);
79 static const struct file_operations mgag200_driver_fops = {
82 .release = drm_release,
83 .unlocked_ioctl = drm_ioctl,
90 static struct drm_driver driver = {
91 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_USE_MTRR,
92 .load = mgag200_driver_load,
93 .unload = mgag200_driver_unload,
94 .fops = &mgag200_driver_fops,
98 .major = DRIVER_MAJOR,
99 .minor = DRIVER_MINOR,
100 .patchlevel = DRIVER_PATCHLEVEL,
102 .gem_init_object = mgag200_gem_init_object,
103 .gem_free_object = mgag200_gem_free_object,
104 .dumb_create = mgag200_dumb_create,
105 .dumb_map_offset = mgag200_dumb_mmap_offset,
106 .dumb_destroy = mgag200_dumb_destroy,
109 static struct pci_driver mgag200_pci_driver = {
111 .id_table = pciidlist,
112 .probe = mga_pci_probe,
113 .remove = mga_pci_remove,
116 static int __init mgag200_init(void)
118 #ifdef CONFIG_VGA_CONSOLE
119 if (vgacon_text_force() && mgag200_modeset == -1)
123 if (mgag200_modeset == 0)
125 return drm_pci_init(&driver, &mgag200_pci_driver);
128 static void __exit mgag200_exit(void)
130 drm_pci_exit(&driver, &mgag200_pci_driver);
133 module_init(mgag200_init);
134 module_exit(mgag200_exit);
136 MODULE_AUTHOR(DRIVER_AUTHOR);
137 MODULE_DESCRIPTION(DRIVER_DESC);
138 MODULE_LICENSE("GPL");