1 // SPDX-License-Identifier: GPL-2.0-or-later
5 #include <linux/module.h>
8 #include <drm/drm_drv.h>
9 #include <drm/drm_atomic_helper.h>
10 #include <drm/drm_managed.h>
14 static int bochs_modeset
= -1;
15 module_param_named(modeset
, bochs_modeset
, int, 0444);
16 MODULE_PARM_DESC(modeset
, "enable/disable kernel modesetting");
18 /* ---------------------------------------------------------------------- */
21 static void bochs_unload(struct drm_device
*dev
)
23 struct bochs_device
*bochs
= dev
->dev_private
;
28 static int bochs_load(struct drm_device
*dev
)
30 struct bochs_device
*bochs
;
33 bochs
= drmm_kzalloc(dev
, sizeof(*bochs
), GFP_KERNEL
);
36 dev
->dev_private
= bochs
;
39 ret
= bochs_hw_init(dev
);
43 ret
= bochs_mm_init(bochs
);
47 ret
= bochs_kms_init(bochs
);
58 DEFINE_DRM_GEM_FOPS(bochs_fops
);
60 static const struct drm_driver bochs_driver
= {
61 .driver_features
= DRIVER_GEM
| DRIVER_MODESET
| DRIVER_ATOMIC
,
64 .desc
= "bochs dispi vga interface (qemu stdvga)",
69 .release
= bochs_unload
,
72 /* ---------------------------------------------------------------------- */
75 #ifdef CONFIG_PM_SLEEP
76 static int bochs_pm_suspend(struct device
*dev
)
78 struct drm_device
*drm_dev
= dev_get_drvdata(dev
);
80 return drm_mode_config_helper_suspend(drm_dev
);
83 static int bochs_pm_resume(struct device
*dev
)
85 struct drm_device
*drm_dev
= dev_get_drvdata(dev
);
87 return drm_mode_config_helper_resume(drm_dev
);
91 static const struct dev_pm_ops bochs_pm_ops
= {
92 SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend
,
96 /* ---------------------------------------------------------------------- */
99 static int bochs_pci_probe(struct pci_dev
*pdev
,
100 const struct pci_device_id
*ent
)
102 struct drm_device
*dev
;
103 unsigned long fbsize
;
106 fbsize
= pci_resource_len(pdev
, 0);
107 if (fbsize
< 4 * 1024 * 1024) {
108 DRM_ERROR("less than 4 MB video memory, ignoring device\n");
112 ret
= drm_fb_helper_remove_conflicting_pci_framebuffers(pdev
, "bochsdrmfb");
116 dev
= drm_dev_alloc(&bochs_driver
, &pdev
->dev
);
120 ret
= pci_enable_device(pdev
);
125 pci_set_drvdata(pdev
, dev
);
127 ret
= bochs_load(dev
);
131 ret
= drm_dev_register(dev
, 0);
135 drm_fbdev_generic_setup(dev
, 32);
145 static void bochs_pci_remove(struct pci_dev
*pdev
)
147 struct drm_device
*dev
= pci_get_drvdata(pdev
);
150 drm_atomic_helper_shutdown(dev
);
155 static const struct pci_device_id bochs_pci_tbl
[] = {
159 .subvendor
= PCI_SUBVENDOR_ID_REDHAT_QUMRANET
,
160 .subdevice
= PCI_SUBDEVICE_ID_QEMU
,
161 .driver_data
= BOCHS_QEMU_STDVGA
,
166 .subvendor
= PCI_ANY_ID
,
167 .subdevice
= PCI_ANY_ID
,
168 .driver_data
= BOCHS_UNKNOWN
,
170 { /* end of list */ }
173 static struct pci_driver bochs_pci_driver
= {
175 .id_table
= bochs_pci_tbl
,
176 .probe
= bochs_pci_probe
,
177 .remove
= bochs_pci_remove
,
178 .driver
.pm
= &bochs_pm_ops
,
181 /* ---------------------------------------------------------------------- */
182 /* module init/exit */
184 static int __init
bochs_init(void)
186 if (vgacon_text_force() && bochs_modeset
== -1)
189 if (bochs_modeset
== 0)
192 return pci_register_driver(&bochs_pci_driver
);
195 static void __exit
bochs_exit(void)
197 pci_unregister_driver(&bochs_pci_driver
);
200 module_init(bochs_init
);
201 module_exit(bochs_exit
);
203 MODULE_DEVICE_TABLE(pci
, bochs_pci_tbl
);
204 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
205 MODULE_LICENSE("GPL");