Merge tag 'drm-misc-next-2017-01-30' of git://anongit.freedesktop.org/git/drm-misc...
[linux-block.git] / drivers / gpu / drm / mgag200 / mgag200_drv.c
CommitLineData
414c4531
DA
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>
760285e7 13#include <drm/drmP.h>
414c4531
DA
14
15#include "mgag200_drv.h"
16
760285e7 17#include <drm/drm_pciids.h>
414c4531
DA
18
19/*
20 * This is the generic driver code. This binds the driver to the drm core,
21 * which then performs further device association and calls our graphics init
22 * functions
23 */
24int mgag200_modeset = -1;
25
26MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
27module_param_named(modeset, mgag200_modeset, int, 0400);
28
29static struct drm_driver driver;
30
9baa3c34 31static const struct pci_device_id pciidlist[] = {
414c4531
DA
32 { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_A },
33 { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
34 { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
35 { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
36 { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
37 { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
6d857c18 38 { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
f0493e65 39 { PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
414c4531
DA
40 {0,}
41};
42
43MODULE_DEVICE_TABLE(pci, pciidlist);
44
08ef8e41
DA
45static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev)
46{
47 struct apertures_struct *ap;
48 bool primary = false;
49
50 ap = alloc_apertures(1);
4dbdf0ae
DN
51 if (!ap)
52 return;
53
08ef8e41
DA
54 ap->ranges[0].base = pci_resource_start(pdev, 0);
55 ap->ranges[0].size = pci_resource_len(pdev, 0);
56
57#ifdef CONFIG_X86
58 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
59#endif
44adece5 60 drm_fb_helper_remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
08ef8e41
DA
61 kfree(ap);
62}
63
64
56550d94 65static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
414c4531 66{
08ef8e41
DA
67 mgag200_kick_out_firmware_fb(pdev);
68
414c4531
DA
69 return drm_get_pci_dev(pdev, ent, &driver);
70}
71
72static void mga_pci_remove(struct pci_dev *pdev)
73{
74 struct drm_device *dev = pci_get_drvdata(pdev);
75
76 drm_put_dev(dev);
77}
78
79static const struct file_operations mgag200_driver_fops = {
80 .owner = THIS_MODULE,
81 .open = drm_open,
82 .release = drm_release,
83 .unlocked_ioctl = drm_ioctl,
84 .mmap = mgag200_mmap,
85 .poll = drm_poll,
804d74ab 86 .compat_ioctl = drm_compat_ioctl,
414c4531
DA
87 .read = drm_read,
88};
89
90static struct drm_driver driver = {
28185647 91 .driver_features = DRIVER_GEM | DRIVER_MODESET,
414c4531
DA
92 .load = mgag200_driver_load,
93 .unload = mgag200_driver_unload,
915b4d11 94 .set_busid = drm_pci_set_busid,
414c4531
DA
95 .fops = &mgag200_driver_fops,
96 .name = DRIVER_NAME,
97 .desc = DRIVER_DESC,
98 .date = DRIVER_DATE,
99 .major = DRIVER_MAJOR,
100 .minor = DRIVER_MINOR,
101 .patchlevel = DRIVER_PATCHLEVEL,
102
faf13eb6 103 .gem_free_object_unlocked = mgag200_gem_free_object,
414c4531
DA
104 .dumb_create = mgag200_dumb_create,
105 .dumb_map_offset = mgag200_dumb_mmap_offset,
43387b37 106 .dumb_destroy = drm_gem_dumb_destroy,
414c4531
DA
107};
108
109static struct pci_driver mgag200_pci_driver = {
110 .name = DRIVER_NAME,
111 .id_table = pciidlist,
112 .probe = mga_pci_probe,
113 .remove = mga_pci_remove,
114};
115
116static int __init mgag200_init(void)
117{
118 if (vgacon_text_force() && mgag200_modeset == -1)
119 return -EINVAL;
120
121 if (mgag200_modeset == 0)
122 return -EINVAL;
123 return drm_pci_init(&driver, &mgag200_pci_driver);
124}
125
126static void __exit mgag200_exit(void)
127{
128 drm_pci_exit(&driver, &mgag200_pci_driver);
129}
130
131module_init(mgag200_init);
132module_exit(mgag200_exit);
133
134MODULE_AUTHOR(DRIVER_AUTHOR);
135MODULE_DESCRIPTION(DRIVER_DESC);
136MODULE_LICENSE("GPL");