drm/exynos: Stop using drm_framebuffer_unregister_private
[linux/fpc-iii.git] / drivers / gpu / drm / bochs / bochs_drv.c
blob8a12b3f6fc66e0027f3d362bea42c99e146b9a26
1 /*
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.
6 */
8 #include <linux/mm.h>
9 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <drm/drm_fb_helper.h>
13 #include "bochs.h"
15 static bool enable_fbdev = true;
16 module_param_named(fbdev, enable_fbdev, bool, 0444);
17 MODULE_PARM_DESC(fbdev, "register fbdev device");
19 /* ---------------------------------------------------------------------- */
20 /* drm interface */
22 static void bochs_unload(struct drm_device *dev)
24 struct bochs_device *bochs = dev->dev_private;
26 bochs_fbdev_fini(bochs);
27 bochs_kms_fini(bochs);
28 bochs_mm_fini(bochs);
29 bochs_hw_fini(dev);
30 kfree(bochs);
31 dev->dev_private = NULL;
34 static int bochs_load(struct drm_device *dev, unsigned long flags)
36 struct bochs_device *bochs;
37 int ret;
39 bochs = kzalloc(sizeof(*bochs), GFP_KERNEL);
40 if (bochs == NULL)
41 return -ENOMEM;
42 dev->dev_private = bochs;
43 bochs->dev = dev;
45 ret = bochs_hw_init(dev, flags);
46 if (ret)
47 goto err;
49 ret = bochs_mm_init(bochs);
50 if (ret)
51 goto err;
53 ret = bochs_kms_init(bochs);
54 if (ret)
55 goto err;
57 if (enable_fbdev)
58 bochs_fbdev_init(bochs);
60 return 0;
62 err:
63 bochs_unload(dev);
64 return ret;
67 static const struct file_operations bochs_fops = {
68 .owner = THIS_MODULE,
69 .open = drm_open,
70 .release = drm_release,
71 .unlocked_ioctl = drm_ioctl,
72 .compat_ioctl = drm_compat_ioctl,
73 .poll = drm_poll,
74 .read = drm_read,
75 .llseek = no_llseek,
76 .mmap = bochs_mmap,
79 static struct drm_driver bochs_driver = {
80 .driver_features = DRIVER_GEM | DRIVER_MODESET,
81 .load = bochs_load,
82 .unload = bochs_unload,
83 .set_busid = drm_pci_set_busid,
84 .fops = &bochs_fops,
85 .name = "bochs-drm",
86 .desc = "bochs dispi vga interface (qemu stdvga)",
87 .date = "20130925",
88 .major = 1,
89 .minor = 0,
90 .gem_free_object_unlocked = bochs_gem_free_object,
91 .dumb_create = bochs_dumb_create,
92 .dumb_map_offset = bochs_dumb_mmap_offset,
93 .dumb_destroy = drm_gem_dumb_destroy,
96 /* ---------------------------------------------------------------------- */
97 /* pm interface */
99 #ifdef CONFIG_PM_SLEEP
100 static int bochs_pm_suspend(struct device *dev)
102 struct pci_dev *pdev = to_pci_dev(dev);
103 struct drm_device *drm_dev = pci_get_drvdata(pdev);
104 struct bochs_device *bochs = drm_dev->dev_private;
106 drm_kms_helper_poll_disable(drm_dev);
108 if (bochs->fb.initialized) {
109 console_lock();
110 drm_fb_helper_set_suspend(&bochs->fb.helper, 1);
111 console_unlock();
114 return 0;
117 static int bochs_pm_resume(struct device *dev)
119 struct pci_dev *pdev = to_pci_dev(dev);
120 struct drm_device *drm_dev = pci_get_drvdata(pdev);
121 struct bochs_device *bochs = drm_dev->dev_private;
123 drm_helper_resume_force_mode(drm_dev);
125 if (bochs->fb.initialized) {
126 console_lock();
127 drm_fb_helper_set_suspend(&bochs->fb.helper, 0);
128 console_unlock();
131 drm_kms_helper_poll_enable(drm_dev);
132 return 0;
134 #endif
136 static const struct dev_pm_ops bochs_pm_ops = {
137 SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend,
138 bochs_pm_resume)
141 /* ---------------------------------------------------------------------- */
142 /* pci interface */
144 static int bochs_kick_out_firmware_fb(struct pci_dev *pdev)
146 struct apertures_struct *ap;
148 ap = alloc_apertures(1);
149 if (!ap)
150 return -ENOMEM;
152 ap->ranges[0].base = pci_resource_start(pdev, 0);
153 ap->ranges[0].size = pci_resource_len(pdev, 0);
154 drm_fb_helper_remove_conflicting_framebuffers(ap, "bochsdrmfb", false);
155 kfree(ap);
157 return 0;
160 static int bochs_pci_probe(struct pci_dev *pdev,
161 const struct pci_device_id *ent)
163 unsigned long fbsize;
164 int ret;
166 fbsize = pci_resource_len(pdev, 0);
167 if (fbsize < 4 * 1024 * 1024) {
168 DRM_ERROR("less than 4 MB video memory, ignoring device\n");
169 return -ENOMEM;
172 ret = bochs_kick_out_firmware_fb(pdev);
173 if (ret)
174 return ret;
176 return drm_get_pci_dev(pdev, ent, &bochs_driver);
179 static void bochs_pci_remove(struct pci_dev *pdev)
181 struct drm_device *dev = pci_get_drvdata(pdev);
183 drm_put_dev(dev);
186 static const struct pci_device_id bochs_pci_tbl[] = {
188 .vendor = 0x1234,
189 .device = 0x1111,
190 .subvendor = PCI_SUBVENDOR_ID_REDHAT_QUMRANET,
191 .subdevice = PCI_SUBDEVICE_ID_QEMU,
192 .driver_data = BOCHS_QEMU_STDVGA,
195 .vendor = 0x1234,
196 .device = 0x1111,
197 .subvendor = PCI_ANY_ID,
198 .subdevice = PCI_ANY_ID,
199 .driver_data = BOCHS_UNKNOWN,
201 { /* end of list */ }
204 static struct pci_driver bochs_pci_driver = {
205 .name = "bochs-drm",
206 .id_table = bochs_pci_tbl,
207 .probe = bochs_pci_probe,
208 .remove = bochs_pci_remove,
209 .driver.pm = &bochs_pm_ops,
212 /* ---------------------------------------------------------------------- */
213 /* module init/exit */
215 static int __init bochs_init(void)
217 return drm_pci_init(&bochs_driver, &bochs_pci_driver);
220 static void __exit bochs_exit(void)
222 drm_pci_exit(&bochs_driver, &bochs_pci_driver);
225 module_init(bochs_init);
226 module_exit(bochs_exit);
228 MODULE_DEVICE_TABLE(pci, bochs_pci_tbl);
229 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
230 MODULE_LICENSE("GPL");