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>
11 #include <drm/drm_fb_helper.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 /* ---------------------------------------------------------------------- */
22 static int bochs_unload(struct drm_device
*dev
)
24 struct bochs_device
*bochs
= dev
->dev_private
;
26 bochs_fbdev_fini(bochs
);
27 bochs_kms_fini(bochs
);
31 dev
->dev_private
= NULL
;
35 static int bochs_load(struct drm_device
*dev
, unsigned long flags
)
37 struct bochs_device
*bochs
;
40 bochs
= kzalloc(sizeof(*bochs
), GFP_KERNEL
);
43 dev
->dev_private
= bochs
;
46 ret
= bochs_hw_init(dev
, flags
);
50 ret
= bochs_mm_init(bochs
);
54 ret
= bochs_kms_init(bochs
);
59 bochs_fbdev_init(bochs
);
68 static const struct file_operations bochs_fops
= {
71 .release
= drm_release
,
72 .unlocked_ioctl
= drm_ioctl
,
74 .compat_ioctl
= drm_compat_ioctl
,
82 static struct drm_driver bochs_driver
= {
83 .driver_features
= DRIVER_GEM
| DRIVER_MODESET
,
85 .unload
= bochs_unload
,
86 .set_busid
= drm_pci_set_busid
,
89 .desc
= "bochs dispi vga interface (qemu stdvga)",
93 .gem_free_object_unlocked
= bochs_gem_free_object
,
94 .dumb_create
= bochs_dumb_create
,
95 .dumb_map_offset
= bochs_dumb_mmap_offset
,
96 .dumb_destroy
= drm_gem_dumb_destroy
,
99 /* ---------------------------------------------------------------------- */
102 #ifdef CONFIG_PM_SLEEP
103 static int bochs_pm_suspend(struct device
*dev
)
105 struct pci_dev
*pdev
= to_pci_dev(dev
);
106 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
107 struct bochs_device
*bochs
= drm_dev
->dev_private
;
109 drm_kms_helper_poll_disable(drm_dev
);
111 if (bochs
->fb
.initialized
) {
113 drm_fb_helper_set_suspend(&bochs
->fb
.helper
, 1);
120 static int bochs_pm_resume(struct device
*dev
)
122 struct pci_dev
*pdev
= to_pci_dev(dev
);
123 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
124 struct bochs_device
*bochs
= drm_dev
->dev_private
;
126 drm_helper_resume_force_mode(drm_dev
);
128 if (bochs
->fb
.initialized
) {
130 drm_fb_helper_set_suspend(&bochs
->fb
.helper
, 0);
134 drm_kms_helper_poll_enable(drm_dev
);
139 static const struct dev_pm_ops bochs_pm_ops
= {
140 SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend
,
144 /* ---------------------------------------------------------------------- */
147 static int bochs_kick_out_firmware_fb(struct pci_dev
*pdev
)
149 struct apertures_struct
*ap
;
151 ap
= alloc_apertures(1);
155 ap
->ranges
[0].base
= pci_resource_start(pdev
, 0);
156 ap
->ranges
[0].size
= pci_resource_len(pdev
, 0);
157 drm_fb_helper_remove_conflicting_framebuffers(ap
, "bochsdrmfb", false);
163 static int bochs_pci_probe(struct pci_dev
*pdev
,
164 const struct pci_device_id
*ent
)
166 unsigned long fbsize
;
169 fbsize
= pci_resource_len(pdev
, 0);
170 if (fbsize
< 4 * 1024 * 1024) {
171 DRM_ERROR("less than 4 MB video memory, ignoring device\n");
175 ret
= bochs_kick_out_firmware_fb(pdev
);
179 return drm_get_pci_dev(pdev
, ent
, &bochs_driver
);
182 static void bochs_pci_remove(struct pci_dev
*pdev
)
184 struct drm_device
*dev
= pci_get_drvdata(pdev
);
189 static const struct pci_device_id bochs_pci_tbl
[] = {
193 .subvendor
= PCI_SUBVENDOR_ID_REDHAT_QUMRANET
,
194 .subdevice
= PCI_SUBDEVICE_ID_QEMU
,
195 .driver_data
= BOCHS_QEMU_STDVGA
,
200 .subvendor
= PCI_ANY_ID
,
201 .subdevice
= PCI_ANY_ID
,
202 .driver_data
= BOCHS_UNKNOWN
,
204 { /* end of list */ }
207 static struct pci_driver bochs_pci_driver
= {
209 .id_table
= bochs_pci_tbl
,
210 .probe
= bochs_pci_probe
,
211 .remove
= bochs_pci_remove
,
212 .driver
.pm
= &bochs_pm_ops
,
215 /* ---------------------------------------------------------------------- */
216 /* module init/exit */
218 static int __init
bochs_init(void)
220 return drm_pci_init(&bochs_driver
, &bochs_pci_driver
);
223 static void __exit
bochs_exit(void)
225 drm_pci_exit(&bochs_driver
, &bochs_pci_driver
);
228 module_init(bochs_init
);
229 module_exit(bochs_exit
);
231 MODULE_DEVICE_TABLE(pci
, bochs_pci_tbl
);
232 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
233 MODULE_LICENSE("GPL");