blob: 953fc8aea69c141cf076dcccbc1c4ed2ec775321 [file] [log] [blame]
Dave Airlief9aa76a2012-04-17 14:12:29 +01001/*
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 Howells760285e2012-10-02 18:01:07 +010013#include <drm/drmP.h>
Dave Airlief9aa76a2012-04-17 14:12:29 +010014
15#include "cirrus_drv.h"
16
17int cirrus_modeset = -1;
18
19MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
20module_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
28static struct drm_driver driver;
29
30/* only bind to the cirrus chip in qemu */
31static 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 Airliededc14e2012-06-01 11:11:09 +010037
Tommi Rantalabfb82ff2012-11-09 09:19:35 +000038static int cirrus_kick_out_firmware_fb(struct pci_dev *pdev)
Dave Airliededc14e2012-06-01 11:11:09 +010039{
40 struct apertures_struct *ap;
41 bool primary = false;
42
43 ap = alloc_apertures(1);
Tommi Rantalabfb82ff2012-11-09 09:19:35 +000044 if (!ap)
45 return -ENOMEM;
46
Dave Airliededc14e2012-06-01 11:11:09 +010047 ap->ranges[0].base = pci_resource_start(pdev, 0);
48 ap->ranges[0].size = pci_resource_len(pdev, 0);
49
50#ifdef CONFIG_X86
51 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
52#endif
53 remove_conflicting_framebuffers(ap, "cirrusdrmfb", primary);
54 kfree(ap);
Tommi Rantalabfb82ff2012-11-09 09:19:35 +000055
56 return 0;
Dave Airliededc14e2012-06-01 11:11:09 +010057}
58
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -080059static int cirrus_pci_probe(struct pci_dev *pdev,
60 const struct pci_device_id *ent)
Dave Airlief9aa76a2012-04-17 14:12:29 +010061{
Tommi Rantalabfb82ff2012-11-09 09:19:35 +000062 int ret;
63
64 ret = cirrus_kick_out_firmware_fb(pdev);
65 if (ret)
66 return ret;
Dave Airliededc14e2012-06-01 11:11:09 +010067
Dave Airlief9aa76a2012-04-17 14:12:29 +010068 return drm_get_pci_dev(pdev, ent, &driver);
69}
70
71static void cirrus_pci_remove(struct pci_dev *pdev)
72{
73 struct drm_device *dev = pci_get_drvdata(pdev);
74
75 drm_put_dev(dev);
76}
77
78static const struct file_operations cirrus_driver_fops = {
79 .owner = THIS_MODULE,
80 .open = drm_open,
81 .release = drm_release,
82 .unlocked_ioctl = drm_ioctl,
83 .mmap = cirrus_mmap,
84 .poll = drm_poll,
Keith Packard804d74a2012-07-09 15:40:07 -070085#ifdef CONFIG_COMPAT
86 .compat_ioctl = drm_compat_ioctl,
87#endif
Dave Airlief9aa76a2012-04-17 14:12:29 +010088};
89static struct drm_driver driver = {
Daniel Vetter28185642013-08-08 15:41:27 +020090 .driver_features = DRIVER_MODESET | DRIVER_GEM,
Dave Airlief9aa76a2012-04-17 14:12:29 +010091 .load = cirrus_driver_load,
92 .unload = cirrus_driver_unload,
93 .fops = &cirrus_driver_fops,
94 .name = DRIVER_NAME,
95 .desc = DRIVER_DESC,
96 .date = DRIVER_DATE,
97 .major = DRIVER_MAJOR,
98 .minor = DRIVER_MINOR,
99 .patchlevel = DRIVER_PATCHLEVEL,
Dave Airlief9aa76a2012-04-17 14:12:29 +0100100 .gem_free_object = cirrus_gem_free_object,
101 .dumb_create = cirrus_dumb_create,
102 .dumb_map_offset = cirrus_dumb_mmap_offset,
Daniel Vetter43387b32013-07-16 09:12:04 +0200103 .dumb_destroy = drm_gem_dumb_destroy,
Dave Airlief9aa76a2012-04-17 14:12:29 +0100104};
105
106static struct pci_driver cirrus_pci_driver = {
107 .name = DRIVER_NAME,
108 .id_table = pciidlist,
109 .probe = cirrus_pci_probe,
110 .remove = cirrus_pci_remove,
111};
112
113static int __init cirrus_init(void)
114{
Dave Airlie4688a69d2012-05-19 16:33:21 +0100115#ifdef CONFIG_VGA_CONSOLE
Dave Airlief9aa76a2012-04-17 14:12:29 +0100116 if (vgacon_text_force() && cirrus_modeset == -1)
117 return -EINVAL;
Dave Airlie4688a69d2012-05-19 16:33:21 +0100118#endif
Dave Airlief9aa76a2012-04-17 14:12:29 +0100119
120 if (cirrus_modeset == 0)
121 return -EINVAL;
122 return drm_pci_init(&driver, &cirrus_pci_driver);
123}
124
125static void __exit cirrus_exit(void)
126{
127 drm_pci_exit(&driver, &cirrus_pci_driver);
128}
129
130module_init(cirrus_init);
131module_exit(cirrus_exit);
132
133MODULE_DEVICE_TABLE(pci, pciidlist);
134MODULE_AUTHOR(DRIVER_AUTHOR);
135MODULE_DESCRIPTION(DRIVER_DESC);
136MODULE_LICENSE("GPL");