Dave Airlie | f9aa76a | 2012-04-17 14:12:29 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Red Hat <mjg@redhat.com> |
| 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 | f9aa76a | 2012-04-17 14:12:29 +0100 | [diff] [blame] | 14 | |
| 15 | #include "cirrus_drv.h" |
| 16 | |
| 17 | int cirrus_modeset = -1; |
| 18 | |
| 19 | MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); |
| 20 | module_param_named(modeset, cirrus_modeset, int, 0400); |
| 21 | |
| 22 | /* |
| 23 | * This is the generic driver code. This binds the driver to the drm core, |
| 24 | * which then performs further device association and calls our graphics init |
| 25 | * functions |
| 26 | */ |
| 27 | |
| 28 | static struct drm_driver driver; |
| 29 | |
| 30 | /* only bind to the cirrus chip in qemu */ |
| 31 | static DEFINE_PCI_DEVICE_TABLE(pciidlist) = { |
| 32 | { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, 0x1af4, 0x1100, 0, |
| 33 | 0, 0 }, |
| 34 | {0,} |
| 35 | }; |
| 36 | |
Dave Airlie | dedc14e | 2012-06-01 11:11:09 +0100 | [diff] [blame] | 37 | |
| 38 | static void cirrus_kick_out_firmware_fb(struct pci_dev *pdev) |
| 39 | { |
| 40 | struct apertures_struct *ap; |
| 41 | bool primary = false; |
| 42 | |
| 43 | ap = alloc_apertures(1); |
| 44 | ap->ranges[0].base = pci_resource_start(pdev, 0); |
| 45 | ap->ranges[0].size = pci_resource_len(pdev, 0); |
| 46 | |
| 47 | #ifdef CONFIG_X86 |
| 48 | primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW; |
| 49 | #endif |
| 50 | remove_conflicting_framebuffers(ap, "cirrusdrmfb", primary); |
| 51 | kfree(ap); |
| 52 | } |
| 53 | |
Dave Airlie | f9aa76a | 2012-04-17 14:12:29 +0100 | [diff] [blame] | 54 | static int __devinit |
| 55 | cirrus_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 56 | { |
Dave Airlie | dedc14e | 2012-06-01 11:11:09 +0100 | [diff] [blame] | 57 | cirrus_kick_out_firmware_fb(pdev); |
| 58 | |
Dave Airlie | f9aa76a | 2012-04-17 14:12:29 +0100 | [diff] [blame] | 59 | return drm_get_pci_dev(pdev, ent, &driver); |
| 60 | } |
| 61 | |
| 62 | static void cirrus_pci_remove(struct pci_dev *pdev) |
| 63 | { |
| 64 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 65 | |
| 66 | drm_put_dev(dev); |
| 67 | } |
| 68 | |
| 69 | static const struct file_operations cirrus_driver_fops = { |
| 70 | .owner = THIS_MODULE, |
| 71 | .open = drm_open, |
| 72 | .release = drm_release, |
| 73 | .unlocked_ioctl = drm_ioctl, |
| 74 | .mmap = cirrus_mmap, |
| 75 | .poll = drm_poll, |
Keith Packard | 804d74a | 2012-07-09 15:40:07 -0700 | [diff] [blame] | 76 | #ifdef CONFIG_COMPAT |
| 77 | .compat_ioctl = drm_compat_ioctl, |
| 78 | #endif |
Dave Airlie | f9aa76a | 2012-04-17 14:12:29 +0100 | [diff] [blame] | 79 | .fasync = drm_fasync, |
| 80 | }; |
| 81 | static struct drm_driver driver = { |
| 82 | .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_USE_MTRR, |
| 83 | .load = cirrus_driver_load, |
| 84 | .unload = cirrus_driver_unload, |
| 85 | .fops = &cirrus_driver_fops, |
| 86 | .name = DRIVER_NAME, |
| 87 | .desc = DRIVER_DESC, |
| 88 | .date = DRIVER_DATE, |
| 89 | .major = DRIVER_MAJOR, |
| 90 | .minor = DRIVER_MINOR, |
| 91 | .patchlevel = DRIVER_PATCHLEVEL, |
| 92 | .gem_init_object = cirrus_gem_init_object, |
| 93 | .gem_free_object = cirrus_gem_free_object, |
| 94 | .dumb_create = cirrus_dumb_create, |
| 95 | .dumb_map_offset = cirrus_dumb_mmap_offset, |
| 96 | .dumb_destroy = cirrus_dumb_destroy, |
| 97 | }; |
| 98 | |
| 99 | static struct pci_driver cirrus_pci_driver = { |
| 100 | .name = DRIVER_NAME, |
| 101 | .id_table = pciidlist, |
| 102 | .probe = cirrus_pci_probe, |
| 103 | .remove = cirrus_pci_remove, |
| 104 | }; |
| 105 | |
| 106 | static int __init cirrus_init(void) |
| 107 | { |
Dave Airlie | 4688a69 | 2012-05-19 16:33:21 +0100 | [diff] [blame] | 108 | #ifdef CONFIG_VGA_CONSOLE |
Dave Airlie | f9aa76a | 2012-04-17 14:12:29 +0100 | [diff] [blame] | 109 | if (vgacon_text_force() && cirrus_modeset == -1) |
| 110 | return -EINVAL; |
Dave Airlie | 4688a69 | 2012-05-19 16:33:21 +0100 | [diff] [blame] | 111 | #endif |
Dave Airlie | f9aa76a | 2012-04-17 14:12:29 +0100 | [diff] [blame] | 112 | |
| 113 | if (cirrus_modeset == 0) |
| 114 | return -EINVAL; |
| 115 | return drm_pci_init(&driver, &cirrus_pci_driver); |
| 116 | } |
| 117 | |
| 118 | static void __exit cirrus_exit(void) |
| 119 | { |
| 120 | drm_pci_exit(&driver, &cirrus_pci_driver); |
| 121 | } |
| 122 | |
| 123 | module_init(cirrus_init); |
| 124 | module_exit(cirrus_exit); |
| 125 | |
| 126 | MODULE_DEVICE_TABLE(pci, pciidlist); |
| 127 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 128 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 129 | MODULE_LICENSE("GPL"); |