Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 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> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 13 | #include <drm/drmP.h> |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 14 | |
| 15 | #include "mgag200_drv.h" |
| 16 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 17 | #include <drm/drm_pciids.h> |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 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 | */ |
| 24 | int mgag200_modeset = -1; |
| 25 | |
| 26 | MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); |
| 27 | module_param_named(modeset, mgag200_modeset, int, 0400); |
| 28 | |
| 29 | static struct drm_driver driver; |
| 30 | |
| 31 | static DEFINE_PCI_DEVICE_TABLE(pciidlist) = { |
| 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 }, |
| 38 | {0,} |
| 39 | }; |
| 40 | |
| 41 | MODULE_DEVICE_TABLE(pci, pciidlist); |
| 42 | |
Dave Airlie | 08ef8e4 | 2012-06-01 11:12:39 +0100 | [diff] [blame] | 43 | static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev) |
| 44 | { |
| 45 | struct apertures_struct *ap; |
| 46 | bool primary = false; |
| 47 | |
| 48 | ap = alloc_apertures(1); |
Devendra Naga | 4dbdf0a | 2012-07-07 09:22:15 +0000 | [diff] [blame] | 49 | if (!ap) |
| 50 | return; |
| 51 | |
Dave Airlie | 08ef8e4 | 2012-06-01 11:12:39 +0100 | [diff] [blame] | 52 | ap->ranges[0].base = pci_resource_start(pdev, 0); |
| 53 | ap->ranges[0].size = pci_resource_len(pdev, 0); |
| 54 | |
| 55 | #ifdef CONFIG_X86 |
| 56 | primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW; |
| 57 | #endif |
| 58 | remove_conflicting_framebuffers(ap, "mgag200drmfb", primary); |
| 59 | kfree(ap); |
| 60 | } |
| 61 | |
| 62 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame^] | 63 | static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 64 | { |
Dave Airlie | 08ef8e4 | 2012-06-01 11:12:39 +0100 | [diff] [blame] | 65 | mgag200_kick_out_firmware_fb(pdev); |
| 66 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 67 | return drm_get_pci_dev(pdev, ent, &driver); |
| 68 | } |
| 69 | |
| 70 | static void mga_pci_remove(struct pci_dev *pdev) |
| 71 | { |
| 72 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 73 | |
| 74 | drm_put_dev(dev); |
| 75 | } |
| 76 | |
| 77 | static const struct file_operations mgag200_driver_fops = { |
| 78 | .owner = THIS_MODULE, |
| 79 | .open = drm_open, |
| 80 | .release = drm_release, |
| 81 | .unlocked_ioctl = drm_ioctl, |
| 82 | .mmap = mgag200_mmap, |
| 83 | .poll = drm_poll, |
| 84 | .fasync = drm_fasync, |
Keith Packard | 804d74a | 2012-07-09 15:40:07 -0700 | [diff] [blame] | 85 | #ifdef CONFIG_COMPAT |
| 86 | .compat_ioctl = drm_compat_ioctl, |
| 87 | #endif |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 88 | .read = drm_read, |
| 89 | }; |
| 90 | |
| 91 | static struct drm_driver driver = { |
| 92 | .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_USE_MTRR, |
| 93 | .load = mgag200_driver_load, |
| 94 | .unload = mgag200_driver_unload, |
| 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 | |
| 103 | .gem_init_object = mgag200_gem_init_object, |
| 104 | .gem_free_object = mgag200_gem_free_object, |
| 105 | .dumb_create = mgag200_dumb_create, |
| 106 | .dumb_map_offset = mgag200_dumb_mmap_offset, |
| 107 | .dumb_destroy = mgag200_dumb_destroy, |
| 108 | }; |
| 109 | |
| 110 | static 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 | |
| 117 | static int __init mgag200_init(void) |
| 118 | { |
Dave Airlie | 4688a69 | 2012-05-19 16:33:21 +0100 | [diff] [blame] | 119 | #ifdef CONFIG_VGA_CONSOLE |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 120 | if (vgacon_text_force() && mgag200_modeset == -1) |
| 121 | return -EINVAL; |
Dave Airlie | 4688a69 | 2012-05-19 16:33:21 +0100 | [diff] [blame] | 122 | #endif |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 123 | |
| 124 | if (mgag200_modeset == 0) |
| 125 | return -EINVAL; |
| 126 | return drm_pci_init(&driver, &mgag200_pci_driver); |
| 127 | } |
| 128 | |
| 129 | static void __exit mgag200_exit(void) |
| 130 | { |
| 131 | drm_pci_exit(&driver, &mgag200_pci_driver); |
| 132 | } |
| 133 | |
| 134 | module_init(mgag200_init); |
| 135 | module_exit(mgag200_exit); |
| 136 | |
| 137 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 138 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 139 | MODULE_LICENSE("GPL"); |