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>
13 static int bochs_modeset = -1;
14 module_param_named(modeset, bochs_modeset, int, 0444);
15 MODULE_PARM_DESC(modeset, "enable/disable kernel modesetting");
17 /* ---------------------------------------------------------------------- */
20 static void bochs_unload(struct drm_device *dev)
22 struct bochs_device *bochs = dev->dev_private;
24 bochs_kms_fini(bochs);
28 dev->dev_private = NULL;
31 static int bochs_load(struct drm_device *dev)
33 struct bochs_device *bochs;
36 bochs = kzalloc(sizeof(*bochs), GFP_KERNEL);
39 dev->dev_private = bochs;
42 ret = bochs_hw_init(dev);
46 ret = bochs_mm_init(bochs);
50 ret = bochs_kms_init(bochs);
61 static const struct file_operations bochs_fops = {
63 DRM_VRAM_MM_FILE_OPERATIONS
66 static struct drm_driver bochs_driver = {
67 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
70 .desc = "bochs dispi vga interface (qemu stdvga)",
77 /* ---------------------------------------------------------------------- */
80 #ifdef CONFIG_PM_SLEEP
81 static int bochs_pm_suspend(struct device *dev)
83 struct drm_device *drm_dev = dev_get_drvdata(dev);
85 return drm_mode_config_helper_suspend(drm_dev);
88 static int bochs_pm_resume(struct device *dev)
90 struct drm_device *drm_dev = dev_get_drvdata(dev);
92 return drm_mode_config_helper_resume(drm_dev);
96 static const struct dev_pm_ops bochs_pm_ops = {
97 SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend,
101 /* ---------------------------------------------------------------------- */
104 static int bochs_pci_probe(struct pci_dev *pdev,
105 const struct pci_device_id *ent)
107 struct drm_device *dev;
108 unsigned long fbsize;
111 fbsize = pci_resource_len(pdev, 0);
112 if (fbsize < 4 * 1024 * 1024) {
113 DRM_ERROR("less than 4 MB video memory, ignoring device\n");
117 ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "bochsdrmfb");
121 dev = drm_dev_alloc(&bochs_driver, &pdev->dev);
125 ret = pci_enable_device(pdev);
130 pci_set_drvdata(pdev, dev);
132 ret = bochs_load(dev);
136 ret = drm_dev_register(dev, 0);
140 drm_fbdev_generic_setup(dev, 32);
150 static void bochs_pci_remove(struct pci_dev *pdev)
152 struct drm_device *dev = pci_get_drvdata(pdev);
154 drm_atomic_helper_shutdown(dev);
155 drm_dev_unregister(dev);
160 static const struct pci_device_id bochs_pci_tbl[] = {
164 .subvendor = PCI_SUBVENDOR_ID_REDHAT_QUMRANET,
165 .subdevice = PCI_SUBDEVICE_ID_QEMU,
166 .driver_data = BOCHS_QEMU_STDVGA,
171 .subvendor = PCI_ANY_ID,
172 .subdevice = PCI_ANY_ID,
173 .driver_data = BOCHS_UNKNOWN,
175 { /* end of list */ }
178 static struct pci_driver bochs_pci_driver = {
180 .id_table = bochs_pci_tbl,
181 .probe = bochs_pci_probe,
182 .remove = bochs_pci_remove,
183 .driver.pm = &bochs_pm_ops,
186 /* ---------------------------------------------------------------------- */
187 /* module init/exit */
189 static int __init bochs_init(void)
191 if (vgacon_text_force() && bochs_modeset == -1)
194 if (bochs_modeset == 0)
197 return pci_register_driver(&bochs_pci_driver);
200 static void __exit bochs_exit(void)
202 pci_unregister_driver(&bochs_pci_driver);
205 module_init(bochs_init);
206 module_exit(bochs_exit);
208 MODULE_DEVICE_TABLE(pci, bochs_pci_tbl);
209 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
210 MODULE_LICENSE("GPL");