2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
9 #include <linux/module.h>
10 #include <linux/slab.h>
14 static bool enable_fbdev = true;
15 module_param_named(fbdev, enable_fbdev, bool, 0444);
16 MODULE_PARM_DESC(fbdev, "register fbdev device");
18 /* ---------------------------------------------------------------------- */
21 static int bochs_unload(struct drm_device *dev)
23 struct bochs_device *bochs = dev->dev_private;
25 bochs_fbdev_fini(bochs);
26 bochs_kms_fini(bochs);
30 dev->dev_private = NULL;
34 static int bochs_load(struct drm_device *dev, unsigned long flags)
36 struct bochs_device *bochs;
39 bochs = kzalloc(sizeof(*bochs), GFP_KERNEL);
42 dev->dev_private = bochs;
45 ret = bochs_hw_init(dev, flags);
49 ret = bochs_mm_init(bochs);
53 ret = bochs_kms_init(bochs);
58 bochs_fbdev_init(bochs);
67 static const struct file_operations bochs_fops = {
70 .release = drm_release,
71 .unlocked_ioctl = drm_ioctl,
73 .compat_ioctl = drm_compat_ioctl,
81 static struct drm_driver bochs_driver = {
82 .driver_features = DRIVER_GEM | DRIVER_MODESET,
84 .unload = bochs_unload,
87 .desc = "bochs dispi vga interface (qemu stdvga)",
91 .gem_free_object = bochs_gem_free_object,
92 .dumb_create = bochs_dumb_create,
93 .dumb_map_offset = bochs_dumb_mmap_offset,
94 .dumb_destroy = drm_gem_dumb_destroy,
97 /* ---------------------------------------------------------------------- */
100 #ifdef CONFIG_PM_SLEEP
101 static int bochs_pm_suspend(struct device *dev)
103 struct pci_dev *pdev = to_pci_dev(dev);
104 struct drm_device *drm_dev = pci_get_drvdata(pdev);
105 struct bochs_device *bochs = drm_dev->dev_private;
107 drm_kms_helper_poll_disable(drm_dev);
109 if (bochs->fb.initialized) {
111 fb_set_suspend(bochs->fb.helper.fbdev, 1);
118 static int bochs_pm_resume(struct device *dev)
120 struct pci_dev *pdev = to_pci_dev(dev);
121 struct drm_device *drm_dev = pci_get_drvdata(pdev);
122 struct bochs_device *bochs = drm_dev->dev_private;
124 drm_helper_resume_force_mode(drm_dev);
126 if (bochs->fb.initialized) {
128 fb_set_suspend(bochs->fb.helper.fbdev, 0);
132 drm_kms_helper_poll_enable(drm_dev);
137 static const struct dev_pm_ops bochs_pm_ops = {
138 SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend,
142 /* ---------------------------------------------------------------------- */
145 static int bochs_kick_out_firmware_fb(struct pci_dev *pdev)
147 struct apertures_struct *ap;
149 ap = alloc_apertures(1);
153 ap->ranges[0].base = pci_resource_start(pdev, 0);
154 ap->ranges[0].size = pci_resource_len(pdev, 0);
155 remove_conflicting_framebuffers(ap, "bochsdrmfb", false);
161 static int bochs_pci_probe(struct pci_dev *pdev,
162 const struct pci_device_id *ent)
166 ret = bochs_kick_out_firmware_fb(pdev);
170 return drm_get_pci_dev(pdev, ent, &bochs_driver);
173 static void bochs_pci_remove(struct pci_dev *pdev)
175 struct drm_device *dev = pci_get_drvdata(pdev);
180 static const struct pci_device_id bochs_pci_tbl[] = {
186 .driver_data = BOCHS_QEMU_STDVGA,
191 .subvendor = PCI_ANY_ID,
192 .subdevice = PCI_ANY_ID,
193 .driver_data = BOCHS_UNKNOWN,
195 { /* end of list */ }
198 static struct pci_driver bochs_pci_driver = {
200 .id_table = bochs_pci_tbl,
201 .probe = bochs_pci_probe,
202 .remove = bochs_pci_remove,
203 .driver.pm = &bochs_pm_ops,
206 /* ---------------------------------------------------------------------- */
207 /* module init/exit */
209 static int __init bochs_init(void)
211 return drm_pci_init(&bochs_driver, &bochs_pci_driver);
214 static void __exit bochs_exit(void)
216 drm_pci_exit(&bochs_driver, &bochs_pci_driver);
219 module_init(bochs_init);
220 module_exit(bochs_exit);
222 MODULE_DEVICE_TABLE(pci, bochs_pci_tbl);
223 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
224 MODULE_LICENSE("GPL");