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>
12 #include <drm/drm_probe_helper.h>
16 static int bochs_modeset
= -1;
17 module_param_named(modeset
, bochs_modeset
, int, 0444);
18 MODULE_PARM_DESC(modeset
, "enable/disable kernel modesetting");
20 /* ---------------------------------------------------------------------- */
23 static void bochs_unload(struct drm_device
*dev
)
25 struct bochs_device
*bochs
= dev
->dev_private
;
27 bochs_kms_fini(bochs
);
31 dev
->dev_private
= NULL
;
34 static int bochs_load(struct drm_device
*dev
)
36 struct bochs_device
*bochs
;
39 bochs
= kzalloc(sizeof(*bochs
), GFP_KERNEL
);
42 dev
->dev_private
= bochs
;
45 ret
= bochs_hw_init(dev
);
49 ret
= bochs_mm_init(bochs
);
53 ret
= bochs_kms_init(bochs
);
64 static const struct file_operations bochs_fops
= {
67 .release
= drm_release
,
68 .unlocked_ioctl
= drm_ioctl
,
69 .compat_ioctl
= drm_compat_ioctl
,
76 static struct drm_driver bochs_driver
= {
77 .driver_features
= DRIVER_GEM
| DRIVER_MODESET
| DRIVER_ATOMIC
|
81 .desc
= "bochs dispi vga interface (qemu stdvga)",
85 .gem_free_object_unlocked
= bochs_gem_free_object
,
86 .dumb_create
= bochs_dumb_create
,
87 .dumb_map_offset
= bochs_dumb_mmap_offset
,
89 .gem_prime_export
= drm_gem_prime_export
,
90 .gem_prime_import
= drm_gem_prime_import
,
91 .gem_prime_pin
= bochs_gem_prime_pin
,
92 .gem_prime_unpin
= bochs_gem_prime_unpin
,
93 .gem_prime_vmap
= bochs_gem_prime_vmap
,
94 .gem_prime_vunmap
= bochs_gem_prime_vunmap
,
95 .gem_prime_mmap
= bochs_gem_prime_mmap
,
98 /* ---------------------------------------------------------------------- */
101 #ifdef CONFIG_PM_SLEEP
102 static int bochs_pm_suspend(struct device
*dev
)
104 struct pci_dev
*pdev
= to_pci_dev(dev
);
105 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
107 return drm_mode_config_helper_suspend(drm_dev
);
110 static int bochs_pm_resume(struct device
*dev
)
112 struct pci_dev
*pdev
= to_pci_dev(dev
);
113 struct drm_device
*drm_dev
= pci_get_drvdata(pdev
);
115 return drm_mode_config_helper_resume(drm_dev
);
119 static const struct dev_pm_ops bochs_pm_ops
= {
120 SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend
,
124 /* ---------------------------------------------------------------------- */
127 static int bochs_pci_probe(struct pci_dev
*pdev
,
128 const struct pci_device_id
*ent
)
130 struct drm_device
*dev
;
131 unsigned long fbsize
;
134 fbsize
= pci_resource_len(pdev
, 0);
135 if (fbsize
< 4 * 1024 * 1024) {
136 DRM_ERROR("less than 4 MB video memory, ignoring device\n");
140 ret
= drm_fb_helper_remove_conflicting_pci_framebuffers(pdev
, 0, "bochsdrmfb");
144 dev
= drm_dev_alloc(&bochs_driver
, &pdev
->dev
);
149 pci_set_drvdata(pdev
, dev
);
151 ret
= bochs_load(dev
);
155 ret
= drm_dev_register(dev
, 0);
159 drm_fbdev_generic_setup(dev
, 32);
169 static void bochs_pci_remove(struct pci_dev
*pdev
)
171 struct drm_device
*dev
= pci_get_drvdata(pdev
);
173 drm_dev_unregister(dev
);
178 static const struct pci_device_id bochs_pci_tbl
[] = {
182 .subvendor
= PCI_SUBVENDOR_ID_REDHAT_QUMRANET
,
183 .subdevice
= PCI_SUBDEVICE_ID_QEMU
,
184 .driver_data
= BOCHS_QEMU_STDVGA
,
189 .subvendor
= PCI_ANY_ID
,
190 .subdevice
= PCI_ANY_ID
,
191 .driver_data
= BOCHS_UNKNOWN
,
193 { /* end of list */ }
196 static struct pci_driver bochs_pci_driver
= {
198 .id_table
= bochs_pci_tbl
,
199 .probe
= bochs_pci_probe
,
200 .remove
= bochs_pci_remove
,
201 .driver
.pm
= &bochs_pm_ops
,
204 /* ---------------------------------------------------------------------- */
205 /* module init/exit */
207 static int __init
bochs_init(void)
209 if (vgacon_text_force() && bochs_modeset
== -1)
212 if (bochs_modeset
== 0)
215 return pci_register_driver(&bochs_pci_driver
);
218 static void __exit
bochs_exit(void)
220 pci_unregister_driver(&bochs_pci_driver
);
223 module_init(bochs_init
);
224 module_exit(bochs_exit
);
226 MODULE_DEVICE_TABLE(pci
, bochs_pci_tbl
);
227 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
228 MODULE_LICENSE("GPL");