1
2
3
4
5
6
7
8#include <linux/module.h>
9#include <linux/console.h>
10#include <drm/drmP.h>
11
12#include "mgag200_drv.h"
13
14#include <drm/drm_pciids.h>
15
16
17
18
19
20
21int mgag200_modeset = -1;
22
23MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
24module_param_named(modeset, mgag200_modeset, int, 0400);
25
26static struct drm_driver driver;
27
28static const struct pci_device_id pciidlist[] = {
29 { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30 G200_SE_A | MGAG200_FLAG_HW_BUG_NO_STARTADD},
31 { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
32 { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
33 { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
34 { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
35 { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
36 { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
37 { PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
38 {0,}
39};
40
41MODULE_DEVICE_TABLE(pci, pciidlist);
42
43
44static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45{
46 drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "mgag200drmfb");
47
48 return drm_get_pci_dev(pdev, ent, &driver);
49}
50
51static void mga_pci_remove(struct pci_dev *pdev)
52{
53 struct drm_device *dev = pci_get_drvdata(pdev);
54
55 drm_put_dev(dev);
56}
57
58static const struct file_operations mgag200_driver_fops = {
59 .owner = THIS_MODULE,
60 DRM_VRAM_MM_FILE_OPERATIONS
61};
62
63static bool mgag200_pin_bo_at_0(const struct mga_device *mdev)
64{
65 return mdev->flags & MGAG200_FLAG_HW_BUG_NO_STARTADD;
66}
67
68int mgag200_driver_dumb_create(struct drm_file *file,
69 struct drm_device *dev,
70 struct drm_mode_create_dumb *args)
71{
72 struct mga_device *mdev = dev->dev_private;
73 unsigned long pg_align;
74
75 if (WARN_ONCE(!dev->vram_mm, "VRAM MM not initialized"))
76 return -EINVAL;
77
78 pg_align = 0ul;
79
80
81
82
83
84
85 if (mgag200_pin_bo_at_0(mdev))
86 pg_align = PFN_UP(mdev->mc.vram_size);
87
88 return drm_gem_vram_fill_create_dumb(file, dev, &dev->vram_mm->bdev,
89 pg_align, false, args);
90}
91
92static struct drm_driver driver = {
93 .driver_features = DRIVER_GEM | DRIVER_MODESET,
94 .load = mgag200_driver_load,
95 .unload = mgag200_driver_unload,
96 .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 .dumb_create = mgag200_driver_dumb_create,
104 .dumb_map_offset = drm_gem_vram_driver_dumb_mmap_offset,
105 .gem_prime_mmap = drm_gem_prime_mmap,
106};
107
108static struct pci_driver mgag200_pci_driver = {
109 .name = DRIVER_NAME,
110 .id_table = pciidlist,
111 .probe = mga_pci_probe,
112 .remove = mga_pci_remove,
113};
114
115static int __init mgag200_init(void)
116{
117 if (vgacon_text_force() && mgag200_modeset == -1)
118 return -EINVAL;
119
120 if (mgag200_modeset == 0)
121 return -EINVAL;
122
123 return pci_register_driver(&mgag200_pci_driver);
124}
125
126static void __exit mgag200_exit(void)
127{
128 pci_unregister_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");
137