blob: b1619e29a564db97ef626fd2c32bceaa3a18cadc [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>
Gerd Hoffmann2f1e8002014-04-14 11:34:48 +020014#include <drm/drm_crtc_helper.h>
Dave Airlief9aa76a2012-04-17 14:12:29 +010015
16#include "cirrus_drv.h"
17
18int cirrus_modeset = -1;
Takashi Iwai7f551b12015-02-03 17:51:23 +010019int cirrus_bpp = 24;
Dave Airlief9aa76a2012-04-17 14:12:29 +010020
21MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
22module_param_named(modeset, cirrus_modeset, int, 0400);
Takashi Iwai7f551b12015-02-03 17:51:23 +010023MODULE_PARM_DESC(bpp, "Max bits-per-pixel (default:24)");
24module_param_named(bpp, cirrus_bpp, int, 0400);
Dave Airlief9aa76a2012-04-17 14:12:29 +010025
26/*
27 * This is the generic driver code. This binds the driver to the drm core,
28 * which then performs further device association and calls our graphics init
29 * functions
30 */
31
32static struct drm_driver driver;
33
34/* only bind to the cirrus chip in qemu */
Benoit Taine9baa3c32014-08-08 15:56:03 +020035static const struct pci_device_id pciidlist[] = {
Dave Airlief9aa76a2012-04-17 14:12:29 +010036 { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, 0x1af4, 0x1100, 0,
37 0, 0 },
Olaf Heringc0c3e732014-04-11 08:56:23 +020038 { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, PCI_VENDOR_ID_XEN,
39 0x0001, 0, 0, 0 },
Dave Airlief9aa76a2012-04-17 14:12:29 +010040 {0,}
41};
42
Dave Airliededc14e2012-06-01 11:11:09 +010043
Tommi Rantalabfb82ff2012-11-09 09:19:35 +000044static int cirrus_kick_out_firmware_fb(struct pci_dev *pdev)
Dave Airliededc14e2012-06-01 11:11:09 +010045{
46 struct apertures_struct *ap;
47 bool primary = false;
48
49 ap = alloc_apertures(1);
Tommi Rantalabfb82ff2012-11-09 09:19:35 +000050 if (!ap)
51 return -ENOMEM;
52
Dave Airliededc14e2012-06-01 11:11:09 +010053 ap->ranges[0].base = pci_resource_start(pdev, 0);
54 ap->ranges[0].size = pci_resource_len(pdev, 0);
55
56#ifdef CONFIG_X86
57 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
58#endif
59 remove_conflicting_framebuffers(ap, "cirrusdrmfb", primary);
60 kfree(ap);
Tommi Rantalabfb82ff2012-11-09 09:19:35 +000061
62 return 0;
Dave Airliededc14e2012-06-01 11:11:09 +010063}
64
Greg Kroah-Hartman56550d92012-12-21 15:09:25 -080065static int cirrus_pci_probe(struct pci_dev *pdev,
66 const struct pci_device_id *ent)
Dave Airlief9aa76a2012-04-17 14:12:29 +010067{
Tommi Rantalabfb82ff2012-11-09 09:19:35 +000068 int ret;
69
70 ret = cirrus_kick_out_firmware_fb(pdev);
71 if (ret)
72 return ret;
Dave Airliededc14e2012-06-01 11:11:09 +010073
Dave Airlief9aa76a2012-04-17 14:12:29 +010074 return drm_get_pci_dev(pdev, ent, &driver);
75}
76
77static void cirrus_pci_remove(struct pci_dev *pdev)
78{
79 struct drm_device *dev = pci_get_drvdata(pdev);
80
81 drm_put_dev(dev);
82}
83
Russell King8f8e7e12014-07-12 11:01:43 +010084#ifdef CONFIG_PM_SLEEP
Gerd Hoffmann2f1e8002014-04-14 11:34:48 +020085static int cirrus_pm_suspend(struct device *dev)
86{
87 struct pci_dev *pdev = to_pci_dev(dev);
88 struct drm_device *drm_dev = pci_get_drvdata(pdev);
89 struct cirrus_device *cdev = drm_dev->dev_private;
90
91 drm_kms_helper_poll_disable(drm_dev);
92
93 if (cdev->mode_info.gfbdev) {
94 console_lock();
Archit Taneja2b9e6e32015-07-31 16:21:44 +053095 drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 1);
Gerd Hoffmann2f1e8002014-04-14 11:34:48 +020096 console_unlock();
97 }
98
99 return 0;
100}
101
102static int cirrus_pm_resume(struct device *dev)
103{
104 struct pci_dev *pdev = to_pci_dev(dev);
105 struct drm_device *drm_dev = pci_get_drvdata(pdev);
106 struct cirrus_device *cdev = drm_dev->dev_private;
107
108 drm_helper_resume_force_mode(drm_dev);
109
110 if (cdev->mode_info.gfbdev) {
111 console_lock();
Archit Taneja2b9e6e32015-07-31 16:21:44 +0530112 drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 0);
Gerd Hoffmann2f1e8002014-04-14 11:34:48 +0200113 console_unlock();
114 }
115
116 drm_kms_helper_poll_enable(drm_dev);
117 return 0;
118}
Russell King8f8e7e12014-07-12 11:01:43 +0100119#endif
Gerd Hoffmann2f1e8002014-04-14 11:34:48 +0200120
Dave Airlief9aa76a2012-04-17 14:12:29 +0100121static const struct file_operations cirrus_driver_fops = {
122 .owner = THIS_MODULE,
123 .open = drm_open,
124 .release = drm_release,
125 .unlocked_ioctl = drm_ioctl,
126 .mmap = cirrus_mmap,
127 .poll = drm_poll,
Keith Packard804d74a2012-07-09 15:40:07 -0700128#ifdef CONFIG_COMPAT
129 .compat_ioctl = drm_compat_ioctl,
130#endif
Dave Airlief9aa76a2012-04-17 14:12:29 +0100131};
132static struct drm_driver driver = {
Daniel Vetter28185642013-08-08 15:41:27 +0200133 .driver_features = DRIVER_MODESET | DRIVER_GEM,
Dave Airlief9aa76a2012-04-17 14:12:29 +0100134 .load = cirrus_driver_load,
135 .unload = cirrus_driver_unload,
David Herrmann915b4d12014-08-29 12:12:43 +0200136 .set_busid = drm_pci_set_busid,
Dave Airlief9aa76a2012-04-17 14:12:29 +0100137 .fops = &cirrus_driver_fops,
138 .name = DRIVER_NAME,
139 .desc = DRIVER_DESC,
140 .date = DRIVER_DATE,
141 .major = DRIVER_MAJOR,
142 .minor = DRIVER_MINOR,
143 .patchlevel = DRIVER_PATCHLEVEL,
Dave Airlief9aa76a2012-04-17 14:12:29 +0100144 .gem_free_object = cirrus_gem_free_object,
145 .dumb_create = cirrus_dumb_create,
146 .dumb_map_offset = cirrus_dumb_mmap_offset,
Daniel Vetter43387b32013-07-16 09:12:04 +0200147 .dumb_destroy = drm_gem_dumb_destroy,
Dave Airlief9aa76a2012-04-17 14:12:29 +0100148};
149
Gerd Hoffmann2f1e8002014-04-14 11:34:48 +0200150static const struct dev_pm_ops cirrus_pm_ops = {
151 SET_SYSTEM_SLEEP_PM_OPS(cirrus_pm_suspend,
152 cirrus_pm_resume)
153};
154
Dave Airlief9aa76a2012-04-17 14:12:29 +0100155static struct pci_driver cirrus_pci_driver = {
156 .name = DRIVER_NAME,
157 .id_table = pciidlist,
158 .probe = cirrus_pci_probe,
159 .remove = cirrus_pci_remove,
Gerd Hoffmann2f1e8002014-04-14 11:34:48 +0200160 .driver.pm = &cirrus_pm_ops,
Dave Airlief9aa76a2012-04-17 14:12:29 +0100161};
162
163static int __init cirrus_init(void)
164{
Dave Airlie4688a69d2012-05-19 16:33:21 +0100165#ifdef CONFIG_VGA_CONSOLE
Dave Airlief9aa76a2012-04-17 14:12:29 +0100166 if (vgacon_text_force() && cirrus_modeset == -1)
167 return -EINVAL;
Dave Airlie4688a69d2012-05-19 16:33:21 +0100168#endif
Dave Airlief9aa76a2012-04-17 14:12:29 +0100169
170 if (cirrus_modeset == 0)
171 return -EINVAL;
172 return drm_pci_init(&driver, &cirrus_pci_driver);
173}
174
175static void __exit cirrus_exit(void)
176{
177 drm_pci_exit(&driver, &cirrus_pci_driver);
178}
179
180module_init(cirrus_init);
181module_exit(cirrus_exit);
182
183MODULE_DEVICE_TABLE(pci, pciidlist);
184MODULE_AUTHOR(DRIVER_AUTHOR);
185MODULE_DESCRIPTION(DRIVER_DESC);
186MODULE_LICENSE("GPL");