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>
14 #include <drm/drm_crtc_helper.h>
16 #include "cirrus_drv.h"
18 int cirrus_modeset
= -1;
21 MODULE_PARM_DESC(modeset
, "Disable/Enable modesetting");
22 module_param_named(modeset
, cirrus_modeset
, int, 0400);
23 MODULE_PARM_DESC(bpp
, "Max bits-per-pixel (default:24)");
24 module_param_named(bpp
, cirrus_bpp
, int, 0400);
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
32 static struct drm_driver driver
;
34 /* only bind to the cirrus chip in qemu */
35 static const struct pci_device_id pciidlist
[] = {
36 { PCI_VENDOR_ID_CIRRUS
, PCI_DEVICE_ID_CIRRUS_5446
,
37 PCI_SUBVENDOR_ID_REDHAT_QUMRANET
, PCI_SUBDEVICE_ID_QEMU
,
39 { PCI_VENDOR_ID_CIRRUS
, PCI_DEVICE_ID_CIRRUS_5446
, PCI_VENDOR_ID_XEN
,
45 static int cirrus_kick_out_firmware_fb(struct pci_dev
*pdev
)
47 struct apertures_struct
*ap
;
50 ap
= alloc_apertures(1);
54 ap
->ranges
[0].base
= pci_resource_start(pdev
, 0);
55 ap
->ranges
[0].size
= pci_resource_len(pdev
, 0);
58 primary
= pdev
->resource
[PCI_ROM_RESOURCE
].flags
& IORESOURCE_ROM_SHADOW
;
60 drm_fb_helper_remove_conflicting_framebuffers(ap
, "cirrusdrmfb", primary
);
66 static int cirrus_pci_probe(struct pci_dev
*pdev
,
67 const struct pci_device_id
*ent
)
71 ret
= cirrus_kick_out_firmware_fb(pdev
);
75 return drm_get_pci_dev(pdev
, ent
, &driver
);
78 static void cirrus_pci_remove(struct pci_dev
*pdev
)
80 struct drm_device
*dev
= pci_get_drvdata(pdev
);
85 #ifdef CONFIG_PM_SLEEP
86 static int cirrus_pm_suspend(struct device
*dev
)
88 struct pci_dev
*pdev
= to_pci_dev(dev
);
89 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
90 struct cirrus_device
*cdev
= drm_dev
->dev_private
;
92 drm_kms_helper_poll_disable(drm_dev
);
94 if (cdev
->mode_info
.gfbdev
) {
96 drm_fb_helper_set_suspend(&cdev
->mode_info
.gfbdev
->helper
, 1);
103 static int cirrus_pm_resume(struct device
*dev
)
105 struct pci_dev
*pdev
= to_pci_dev(dev
);
106 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
107 struct cirrus_device
*cdev
= drm_dev
->dev_private
;
109 drm_helper_resume_force_mode(drm_dev
);
111 if (cdev
->mode_info
.gfbdev
) {
113 drm_fb_helper_set_suspend(&cdev
->mode_info
.gfbdev
->helper
, 0);
117 drm_kms_helper_poll_enable(drm_dev
);
122 static const struct file_operations cirrus_driver_fops
= {
123 .owner
= THIS_MODULE
,
125 .release
= drm_release
,
126 .unlocked_ioctl
= drm_ioctl
,
130 .compat_ioctl
= drm_compat_ioctl
,
133 static struct drm_driver driver
= {
134 .driver_features
= DRIVER_MODESET
| DRIVER_GEM
,
135 .load
= cirrus_driver_load
,
136 .unload
= cirrus_driver_unload
,
137 .set_busid
= drm_pci_set_busid
,
138 .fops
= &cirrus_driver_fops
,
142 .major
= DRIVER_MAJOR
,
143 .minor
= DRIVER_MINOR
,
144 .patchlevel
= DRIVER_PATCHLEVEL
,
145 .gem_free_object_unlocked
= cirrus_gem_free_object
,
146 .dumb_create
= cirrus_dumb_create
,
147 .dumb_map_offset
= cirrus_dumb_mmap_offset
,
148 .dumb_destroy
= drm_gem_dumb_destroy
,
151 static const struct dev_pm_ops cirrus_pm_ops
= {
152 SET_SYSTEM_SLEEP_PM_OPS(cirrus_pm_suspend
,
156 static struct pci_driver cirrus_pci_driver
= {
158 .id_table
= pciidlist
,
159 .probe
= cirrus_pci_probe
,
160 .remove
= cirrus_pci_remove
,
161 .driver
.pm
= &cirrus_pm_ops
,
164 static int __init
cirrus_init(void)
166 if (vgacon_text_force() && cirrus_modeset
== -1)
169 if (cirrus_modeset
== 0)
171 return drm_pci_init(&driver
, &cirrus_pci_driver
);
174 static void __exit
cirrus_exit(void)
176 drm_pci_exit(&driver
, &cirrus_pci_driver
);
179 module_init(cirrus_init
);
180 module_exit(cirrus_exit
);
182 MODULE_DEVICE_TABLE(pci
, pciidlist
);
183 MODULE_AUTHOR(DRIVER_AUTHOR
);
184 MODULE_DESCRIPTION(DRIVER_DESC
);
185 MODULE_LICENSE("GPL");