Commit | Line | Data |
---|---|---|
0a6659bd GH |
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 | */ | |
7 | ||
8 | #include <linux/mm.h> | |
9 | #include <linux/module.h> | |
10 | #include <linux/slab.h> | |
44adece5 | 11 | #include <drm/drm_fb_helper.h> |
0a6659bd GH |
12 | |
13 | #include "bochs.h" | |
14 | ||
15 | static bool enable_fbdev = true; | |
16 | module_param_named(fbdev, enable_fbdev, bool, 0444); | |
17 | MODULE_PARM_DESC(fbdev, "register fbdev device"); | |
18 | ||
19 | /* ---------------------------------------------------------------------- */ | |
20 | /* drm interface */ | |
21 | ||
22 | static int bochs_unload(struct drm_device *dev) | |
23 | { | |
24 | struct bochs_device *bochs = dev->dev_private; | |
25 | ||
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; | |
32 | return 0; | |
33 | } | |
34 | ||
35 | static int bochs_load(struct drm_device *dev, unsigned long flags) | |
36 | { | |
37 | struct bochs_device *bochs; | |
38 | int ret; | |
39 | ||
40 | bochs = kzalloc(sizeof(*bochs), GFP_KERNEL); | |
41 | if (bochs == NULL) | |
42 | return -ENOMEM; | |
43 | dev->dev_private = bochs; | |
44 | bochs->dev = dev; | |
45 | ||
46 | ret = bochs_hw_init(dev, flags); | |
47 | if (ret) | |
48 | goto err; | |
49 | ||
50 | ret = bochs_mm_init(bochs); | |
51 | if (ret) | |
52 | goto err; | |
53 | ||
54 | ret = bochs_kms_init(bochs); | |
55 | if (ret) | |
56 | goto err; | |
57 | ||
58 | if (enable_fbdev) | |
59 | bochs_fbdev_init(bochs); | |
60 | ||
61 | return 0; | |
62 | ||
63 | err: | |
64 | bochs_unload(dev); | |
65 | return ret; | |
66 | } | |
67 | ||
68 | static const struct file_operations bochs_fops = { | |
69 | .owner = THIS_MODULE, | |
70 | .open = drm_open, | |
71 | .release = drm_release, | |
72 | .unlocked_ioctl = drm_ioctl, | |
73 | #ifdef CONFIG_COMPAT | |
74 | .compat_ioctl = drm_compat_ioctl, | |
75 | #endif | |
76 | .poll = drm_poll, | |
77 | .read = drm_read, | |
78 | .llseek = no_llseek, | |
79 | .mmap = bochs_mmap, | |
80 | }; | |
81 | ||
82 | static struct drm_driver bochs_driver = { | |
83 | .driver_features = DRIVER_GEM | DRIVER_MODESET, | |
84 | .load = bochs_load, | |
85 | .unload = bochs_unload, | |
915b4d11 | 86 | .set_busid = drm_pci_set_busid, |
0a6659bd GH |
87 | .fops = &bochs_fops, |
88 | .name = "bochs-drm", | |
89 | .desc = "bochs dispi vga interface (qemu stdvga)", | |
90 | .date = "20130925", | |
91 | .major = 1, | |
92 | .minor = 0, | |
6f2c1c15 | 93 | .gem_free_object_unlocked = bochs_gem_free_object, |
0a6659bd GH |
94 | .dumb_create = bochs_dumb_create, |
95 | .dumb_map_offset = bochs_dumb_mmap_offset, | |
96 | .dumb_destroy = drm_gem_dumb_destroy, | |
97 | }; | |
98 | ||
b8ccd70f GH |
99 | /* ---------------------------------------------------------------------- */ |
100 | /* pm interface */ | |
101 | ||
150cee9c | 102 | #ifdef CONFIG_PM_SLEEP |
b8ccd70f GH |
103 | static int bochs_pm_suspend(struct device *dev) |
104 | { | |
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; | |
108 | ||
109 | drm_kms_helper_poll_disable(drm_dev); | |
110 | ||
111 | if (bochs->fb.initialized) { | |
112 | console_lock(); | |
6a752972 | 113 | drm_fb_helper_set_suspend(&bochs->fb.helper, 1); |
b8ccd70f GH |
114 | console_unlock(); |
115 | } | |
116 | ||
117 | return 0; | |
118 | } | |
119 | ||
120 | static int bochs_pm_resume(struct device *dev) | |
121 | { | |
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; | |
125 | ||
126 | drm_helper_resume_force_mode(drm_dev); | |
127 | ||
128 | if (bochs->fb.initialized) { | |
129 | console_lock(); | |
6a752972 | 130 | drm_fb_helper_set_suspend(&bochs->fb.helper, 0); |
b8ccd70f GH |
131 | console_unlock(); |
132 | } | |
133 | ||
134 | drm_kms_helper_poll_enable(drm_dev); | |
135 | return 0; | |
136 | } | |
150cee9c | 137 | #endif |
b8ccd70f GH |
138 | |
139 | static const struct dev_pm_ops bochs_pm_ops = { | |
140 | SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend, | |
141 | bochs_pm_resume) | |
142 | }; | |
143 | ||
0a6659bd GH |
144 | /* ---------------------------------------------------------------------- */ |
145 | /* pci interface */ | |
146 | ||
147 | static int bochs_kick_out_firmware_fb(struct pci_dev *pdev) | |
148 | { | |
149 | struct apertures_struct *ap; | |
150 | ||
151 | ap = alloc_apertures(1); | |
152 | if (!ap) | |
153 | return -ENOMEM; | |
154 | ||
155 | ap->ranges[0].base = pci_resource_start(pdev, 0); | |
156 | ap->ranges[0].size = pci_resource_len(pdev, 0); | |
44adece5 | 157 | drm_fb_helper_remove_conflicting_framebuffers(ap, "bochsdrmfb", false); |
0a6659bd GH |
158 | kfree(ap); |
159 | ||
160 | return 0; | |
161 | } | |
162 | ||
163 | static int bochs_pci_probe(struct pci_dev *pdev, | |
164 | const struct pci_device_id *ent) | |
165 | { | |
166 | int ret; | |
167 | ||
168 | ret = bochs_kick_out_firmware_fb(pdev); | |
169 | if (ret) | |
170 | return ret; | |
171 | ||
172 | return drm_get_pci_dev(pdev, ent, &bochs_driver); | |
173 | } | |
174 | ||
175 | static void bochs_pci_remove(struct pci_dev *pdev) | |
176 | { | |
177 | struct drm_device *dev = pci_get_drvdata(pdev); | |
178 | ||
179 | drm_put_dev(dev); | |
180 | } | |
181 | ||
9baa3c34 | 182 | static const struct pci_device_id bochs_pci_tbl[] = { |
0a6659bd GH |
183 | { |
184 | .vendor = 0x1234, | |
185 | .device = 0x1111, | |
caf02abf RJ |
186 | .subvendor = PCI_SUBVENDOR_ID_REDHAT_QUMRANET, |
187 | .subdevice = PCI_SUBDEVICE_ID_QEMU, | |
0a6659bd GH |
188 | .driver_data = BOCHS_QEMU_STDVGA, |
189 | }, | |
190 | { | |
191 | .vendor = 0x1234, | |
192 | .device = 0x1111, | |
193 | .subvendor = PCI_ANY_ID, | |
194 | .subdevice = PCI_ANY_ID, | |
195 | .driver_data = BOCHS_UNKNOWN, | |
196 | }, | |
197 | { /* end of list */ } | |
198 | }; | |
199 | ||
200 | static struct pci_driver bochs_pci_driver = { | |
201 | .name = "bochs-drm", | |
202 | .id_table = bochs_pci_tbl, | |
203 | .probe = bochs_pci_probe, | |
204 | .remove = bochs_pci_remove, | |
b8ccd70f | 205 | .driver.pm = &bochs_pm_ops, |
0a6659bd GH |
206 | }; |
207 | ||
208 | /* ---------------------------------------------------------------------- */ | |
209 | /* module init/exit */ | |
210 | ||
211 | static int __init bochs_init(void) | |
212 | { | |
213 | return drm_pci_init(&bochs_driver, &bochs_pci_driver); | |
214 | } | |
215 | ||
216 | static void __exit bochs_exit(void) | |
217 | { | |
218 | drm_pci_exit(&bochs_driver, &bochs_pci_driver); | |
219 | } | |
220 | ||
221 | module_init(bochs_init); | |
222 | module_exit(bochs_exit); | |
223 | ||
224 | MODULE_DEVICE_TABLE(pci, bochs_pci_tbl); | |
225 | MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>"); | |
226 | MODULE_LICENSE("GPL"); |