2 * Copyright 2012 Red Hat <mjg@redhat.com>
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.
8 * Authors: Matthew Garrett
11 #include <linux/module.h>
12 #include <linux/console.h>
15 #include "cirrus_drv.h"
17 int cirrus_modeset = -1;
19 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
20 module_param_named(modeset, cirrus_modeset, int, 0400);
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
28 static struct drm_driver driver;
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,
38 static int cirrus_kick_out_firmware_fb(struct pci_dev *pdev)
40 struct apertures_struct *ap;
43 ap = alloc_apertures(1);
47 ap->ranges[0].base = pci_resource_start(pdev, 0);
48 ap->ranges[0].size = pci_resource_len(pdev, 0);
51 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
53 remove_conflicting_framebuffers(ap, "cirrusdrmfb", primary);
59 static int cirrus_pci_probe(struct pci_dev *pdev,
60 const struct pci_device_id *ent)
64 ret = cirrus_kick_out_firmware_fb(pdev);
68 return drm_get_pci_dev(pdev, ent, &driver);
71 static void cirrus_pci_remove(struct pci_dev *pdev)
73 struct drm_device *dev = pci_get_drvdata(pdev);
78 static const struct file_operations cirrus_driver_fops = {
81 .release = drm_release,
82 .unlocked_ioctl = drm_ioctl,
86 .compat_ioctl = drm_compat_ioctl,
89 static struct drm_driver driver = {
90 .driver_features = DRIVER_MODESET | DRIVER_GEM,
91 .load = cirrus_driver_load,
92 .unload = cirrus_driver_unload,
93 .fops = &cirrus_driver_fops,
97 .major = DRIVER_MAJOR,
98 .minor = DRIVER_MINOR,
99 .patchlevel = DRIVER_PATCHLEVEL,
100 .gem_free_object = cirrus_gem_free_object,
101 .dumb_create = cirrus_dumb_create,
102 .dumb_map_offset = cirrus_dumb_mmap_offset,
103 .dumb_destroy = drm_gem_dumb_destroy,
106 static struct pci_driver cirrus_pci_driver = {
108 .id_table = pciidlist,
109 .probe = cirrus_pci_probe,
110 .remove = cirrus_pci_remove,
113 static int __init cirrus_init(void)
115 #ifdef CONFIG_VGA_CONSOLE
116 if (vgacon_text_force() && cirrus_modeset == -1)
120 if (cirrus_modeset == 0)
122 return drm_pci_init(&driver, &cirrus_pci_driver);
125 static void __exit cirrus_exit(void)
127 drm_pci_exit(&driver, &cirrus_pci_driver);
130 module_init(cirrus_init);
131 module_exit(cirrus_exit);
133 MODULE_DEVICE_TABLE(pci, pciidlist);
134 MODULE_AUTHOR(DRIVER_AUTHOR);
135 MODULE_DESCRIPTION(DRIVER_DESC);
136 MODULE_LICENSE("GPL");