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