blob: 1443b3a34775cbcaca50532482cfa32fd3052671 [file] [log] [blame]
Dave Airlie414c4532012-04-17 15:01:25 +01001/*
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>
David Howells760285e2012-10-02 18:01:07 +010013#include <drm/drmP.h>
Dave Airlie414c4532012-04-17 15:01:25 +010014
15#include "mgag200_drv.h"
16
David Howells760285e2012-10-02 18:01:07 +010017#include <drm/drm_pciids.h>
Dave Airlie414c4532012-04-17 15:01:25 +010018
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
Benoit Taine9baa3c32014-08-08 15:56:03 +020031static const struct pci_device_id pciidlist[] = {
Dave Airlie414c4532012-04-17 15:01:25 +010032 { 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 },
Mathieu Larouche6d857c12015-08-21 09:24:05 -040038 { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
Dave Airlie414c4532012-04-17 15:01:25 +010039 {0,}
40};
41
42MODULE_DEVICE_TABLE(pci, pciidlist);
43
Dave Airlie08ef8e42012-06-01 11:12:39 +010044static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev)
45{
46 struct apertures_struct *ap;
47 bool primary = false;
48
49 ap = alloc_apertures(1);
Devendra Naga4dbdf0a2012-07-07 09:22:15 +000050 if (!ap)
51 return;
52
Dave Airlie08ef8e42012-06-01 11:12:39 +010053 ap->ranges[0].base = pci_resource_start(pdev, 0);
54 ap->ranges[0].size = pci_resource_len(pdev, 0);
55
56#ifdef CONFIG_X86
57 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
58#endif
Daniel Vetter44adece2016-08-10 18:52:34 +020059 drm_fb_helper_remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
Dave Airlie08ef8e42012-06-01 11:12:39 +010060 kfree(ap);
61}
62
63
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -080064static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Dave Airlie414c4532012-04-17 15:01:25 +010065{
Dave Airlie08ef8e42012-06-01 11:12:39 +010066 mgag200_kick_out_firmware_fb(pdev);
67
Dave Airlie414c4532012-04-17 15:01:25 +010068 return drm_get_pci_dev(pdev, ent, &driver);
69}
70
71static void mga_pci_remove(struct pci_dev *pdev)
72{
73 struct drm_device *dev = pci_get_drvdata(pdev);
74
75 drm_put_dev(dev);
76}
77
78static const struct file_operations mgag200_driver_fops = {
79 .owner = THIS_MODULE,
80 .open = drm_open,
81 .release = drm_release,
82 .unlocked_ioctl = drm_ioctl,
83 .mmap = mgag200_mmap,
84 .poll = drm_poll,
Keith Packard804d74a2012-07-09 15:40:07 -070085#ifdef CONFIG_COMPAT
86 .compat_ioctl = drm_compat_ioctl,
87#endif
Dave Airlie414c4532012-04-17 15:01:25 +010088 .read = drm_read,
89};
90
91static struct drm_driver driver = {
Daniel Vetter28185642013-08-08 15:41:27 +020092 .driver_features = DRIVER_GEM | DRIVER_MODESET,
Dave Airlie414c4532012-04-17 15:01:25 +010093 .load = mgag200_driver_load,
94 .unload = mgag200_driver_unload,
David Herrmann915b4d12014-08-29 12:12:43 +020095 .set_busid = drm_pci_set_busid,
Dave Airlie414c4532012-04-17 15:01:25 +010096 .fops = &mgag200_driver_fops,
97 .name = DRIVER_NAME,
98 .desc = DRIVER_DESC,
99 .date = DRIVER_DATE,
100 .major = DRIVER_MAJOR,
101 .minor = DRIVER_MINOR,
102 .patchlevel = DRIVER_PATCHLEVEL,
103
Daniel Vetterfaf13eb2016-05-30 19:52:59 +0200104 .gem_free_object_unlocked = mgag200_gem_free_object,
Dave Airlie414c4532012-04-17 15:01:25 +0100105 .dumb_create = mgag200_dumb_create,
106 .dumb_map_offset = mgag200_dumb_mmap_offset,
Daniel Vetter43387b32013-07-16 09:12:04 +0200107 .dumb_destroy = drm_gem_dumb_destroy,
Dave Airlie414c4532012-04-17 15:01:25 +0100108};
109
110static struct pci_driver mgag200_pci_driver = {
111 .name = DRIVER_NAME,
112 .id_table = pciidlist,
113 .probe = mga_pci_probe,
114 .remove = mga_pci_remove,
115};
116
117static int __init mgag200_init(void)
118{
119 if (vgacon_text_force() && mgag200_modeset == -1)
120 return -EINVAL;
Dave Airlie414c4532012-04-17 15:01:25 +0100121
122 if (mgag200_modeset == 0)
123 return -EINVAL;
124 return drm_pci_init(&driver, &mgag200_pci_driver);
125}
126
127static void __exit mgag200_exit(void)
128{
129 drm_pci_exit(&driver, &mgag200_pci_driver);
130}
131
132module_init(mgag200_init);
133module_exit(mgag200_exit);
134
135MODULE_AUTHOR(DRIVER_AUTHOR);
136MODULE_DESCRIPTION(DRIVER_DESC);
137MODULE_LICENSE("GPL");