]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/bochs/bochs_drv.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[linux.git] / drivers / gpu / drm / bochs / bochs_drv.c
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>
11 #include <drm/drm_fb_helper.h>
12
13 #include "bochs.h"
14
15 static int bochs_modeset = -1;
16 module_param_named(modeset, bochs_modeset, int, 0444);
17 MODULE_PARM_DESC(modeset, "enable/disable kernel modesetting");
18
19 static bool enable_fbdev = true;
20 module_param_named(fbdev, enable_fbdev, bool, 0444);
21 MODULE_PARM_DESC(fbdev, "register fbdev device");
22
23 /* ---------------------------------------------------------------------- */
24 /* drm interface                                                          */
25
26 static void bochs_unload(struct drm_device *dev)
27 {
28         struct bochs_device *bochs = dev->dev_private;
29
30         bochs_fbdev_fini(bochs);
31         bochs_kms_fini(bochs);
32         bochs_mm_fini(bochs);
33         bochs_hw_fini(dev);
34         kfree(bochs);
35         dev->dev_private = NULL;
36 }
37
38 static int bochs_load(struct drm_device *dev)
39 {
40         struct bochs_device *bochs;
41         int ret;
42
43         bochs = kzalloc(sizeof(*bochs), GFP_KERNEL);
44         if (bochs == NULL)
45                 return -ENOMEM;
46         dev->dev_private = bochs;
47         bochs->dev = dev;
48
49         ret = bochs_hw_init(dev);
50         if (ret)
51                 goto err;
52
53         ret = bochs_mm_init(bochs);
54         if (ret)
55                 goto err;
56
57         ret = bochs_kms_init(bochs);
58         if (ret)
59                 goto err;
60
61         if (enable_fbdev)
62                 bochs_fbdev_init(bochs);
63
64         return 0;
65
66 err:
67         bochs_unload(dev);
68         return ret;
69 }
70
71 static const struct file_operations bochs_fops = {
72         .owner          = THIS_MODULE,
73         .open           = drm_open,
74         .release        = drm_release,
75         .unlocked_ioctl = drm_ioctl,
76         .compat_ioctl   = drm_compat_ioctl,
77         .poll           = drm_poll,
78         .read           = drm_read,
79         .llseek         = no_llseek,
80         .mmap           = bochs_mmap,
81 };
82
83 static struct drm_driver bochs_driver = {
84         .driver_features        = DRIVER_GEM | DRIVER_MODESET,
85         .fops                   = &bochs_fops,
86         .name                   = "bochs-drm",
87         .desc                   = "bochs dispi vga interface (qemu stdvga)",
88         .date                   = "20130925",
89         .major                  = 1,
90         .minor                  = 0,
91         .gem_free_object_unlocked = bochs_gem_free_object,
92         .dumb_create            = bochs_dumb_create,
93         .dumb_map_offset        = bochs_dumb_mmap_offset,
94 };
95
96 /* ---------------------------------------------------------------------- */
97 /* pm interface                                                           */
98
99 #ifdef CONFIG_PM_SLEEP
100 static int bochs_pm_suspend(struct device *dev)
101 {
102         struct pci_dev *pdev = to_pci_dev(dev);
103         struct drm_device *drm_dev = pci_get_drvdata(pdev);
104         struct bochs_device *bochs = drm_dev->dev_private;
105
106         drm_kms_helper_poll_disable(drm_dev);
107
108         drm_fb_helper_set_suspend_unlocked(&bochs->fb.helper, 1);
109
110         return 0;
111 }
112
113 static int bochs_pm_resume(struct device *dev)
114 {
115         struct pci_dev *pdev = to_pci_dev(dev);
116         struct drm_device *drm_dev = pci_get_drvdata(pdev);
117         struct bochs_device *bochs = drm_dev->dev_private;
118
119         drm_helper_resume_force_mode(drm_dev);
120
121         drm_fb_helper_set_suspend_unlocked(&bochs->fb.helper, 0);
122
123         drm_kms_helper_poll_enable(drm_dev);
124         return 0;
125 }
126 #endif
127
128 static const struct dev_pm_ops bochs_pm_ops = {
129         SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend,
130                                 bochs_pm_resume)
131 };
132
133 /* ---------------------------------------------------------------------- */
134 /* pci interface                                                          */
135
136 static int bochs_pci_probe(struct pci_dev *pdev,
137                            const struct pci_device_id *ent)
138 {
139         struct drm_device *dev;
140         unsigned long fbsize;
141         int ret;
142
143         fbsize = pci_resource_len(pdev, 0);
144         if (fbsize < 4 * 1024 * 1024) {
145                 DRM_ERROR("less than 4 MB video memory, ignoring device\n");
146                 return -ENOMEM;
147         }
148
149         ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "bochsdrmfb");
150         if (ret)
151                 return ret;
152
153         dev = drm_dev_alloc(&bochs_driver, &pdev->dev);
154         if (IS_ERR(dev))
155                 return PTR_ERR(dev);
156
157         ret = pci_enable_device(pdev);
158         if (ret)
159                 goto err_free_dev;
160
161         dev->pdev = pdev;
162         pci_set_drvdata(pdev, dev);
163
164         ret = bochs_load(dev);
165         if (ret)
166                 goto err_free_dev;
167
168         ret = drm_dev_register(dev, 0);
169         if (ret)
170                 goto err_unload;
171
172         return ret;
173
174 err_unload:
175         bochs_unload(dev);
176 err_free_dev:
177         drm_dev_put(dev);
178         return ret;
179 }
180
181 static void bochs_pci_remove(struct pci_dev *pdev)
182 {
183         struct drm_device *dev = pci_get_drvdata(pdev);
184
185         drm_dev_unregister(dev);
186         bochs_unload(dev);
187         drm_dev_put(dev);
188 }
189
190 static const struct pci_device_id bochs_pci_tbl[] = {
191         {
192                 .vendor      = 0x1234,
193                 .device      = 0x1111,
194                 .subvendor   = PCI_SUBVENDOR_ID_REDHAT_QUMRANET,
195                 .subdevice   = PCI_SUBDEVICE_ID_QEMU,
196                 .driver_data = BOCHS_QEMU_STDVGA,
197         },
198         {
199                 .vendor      = 0x1234,
200                 .device      = 0x1111,
201                 .subvendor   = PCI_ANY_ID,
202                 .subdevice   = PCI_ANY_ID,
203                 .driver_data = BOCHS_UNKNOWN,
204         },
205         { /* end of list */ }
206 };
207
208 static struct pci_driver bochs_pci_driver = {
209         .name =         "bochs-drm",
210         .id_table =     bochs_pci_tbl,
211         .probe =        bochs_pci_probe,
212         .remove =       bochs_pci_remove,
213         .driver.pm =    &bochs_pm_ops,
214 };
215
216 /* ---------------------------------------------------------------------- */
217 /* module init/exit                                                       */
218
219 static int __init bochs_init(void)
220 {
221         if (vgacon_text_force() && bochs_modeset == -1)
222                 return -EINVAL;
223
224         if (bochs_modeset == 0)
225                 return -EINVAL;
226
227         return pci_register_driver(&bochs_pci_driver);
228 }
229
230 static void __exit bochs_exit(void)
231 {
232         pci_unregister_driver(&bochs_pci_driver);
233 }
234
235 module_init(bochs_init);
236 module_exit(bochs_exit);
237
238 MODULE_DEVICE_TABLE(pci, bochs_pci_tbl);
239 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
240 MODULE_LICENSE("GPL");