]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/bochs/bochs_drv.c
Merge remote-tracking branches 'asoc/fix/alc5623', 'asoc/fix/cs42l52', 'asoc/fix...
[karo-tx-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
12 #include "bochs.h"
13
14 static bool enable_fbdev = true;
15 module_param_named(fbdev, enable_fbdev, bool, 0444);
16 MODULE_PARM_DESC(fbdev, "register fbdev device");
17
18 /* ---------------------------------------------------------------------- */
19 /* drm interface                                                          */
20
21 static int bochs_unload(struct drm_device *dev)
22 {
23         struct bochs_device *bochs = dev->dev_private;
24
25         bochs_fbdev_fini(bochs);
26         bochs_kms_fini(bochs);
27         bochs_mm_fini(bochs);
28         bochs_hw_fini(dev);
29         kfree(bochs);
30         dev->dev_private = NULL;
31         return 0;
32 }
33
34 static int bochs_load(struct drm_device *dev, unsigned long flags)
35 {
36         struct bochs_device *bochs;
37         int ret;
38
39         bochs = kzalloc(sizeof(*bochs), GFP_KERNEL);
40         if (bochs == NULL)
41                 return -ENOMEM;
42         dev->dev_private = bochs;
43         bochs->dev = dev;
44
45         ret = bochs_hw_init(dev, flags);
46         if (ret)
47                 goto err;
48
49         ret = bochs_mm_init(bochs);
50         if (ret)
51                 goto err;
52
53         ret = bochs_kms_init(bochs);
54         if (ret)
55                 goto err;
56
57         if (enable_fbdev)
58                 bochs_fbdev_init(bochs);
59
60         return 0;
61
62 err:
63         bochs_unload(dev);
64         return ret;
65 }
66
67 static const struct file_operations bochs_fops = {
68         .owner          = THIS_MODULE,
69         .open           = drm_open,
70         .release        = drm_release,
71         .unlocked_ioctl = drm_ioctl,
72 #ifdef CONFIG_COMPAT
73         .compat_ioctl   = drm_compat_ioctl,
74 #endif
75         .poll           = drm_poll,
76         .read           = drm_read,
77         .llseek         = no_llseek,
78         .mmap           = bochs_mmap,
79 };
80
81 static struct drm_driver bochs_driver = {
82         .driver_features        = DRIVER_GEM | DRIVER_MODESET,
83         .load                   = bochs_load,
84         .unload                 = bochs_unload,
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        = bochs_gem_free_object,
92         .dumb_create            = bochs_dumb_create,
93         .dumb_map_offset        = bochs_dumb_mmap_offset,
94         .dumb_destroy           = drm_gem_dumb_destroy,
95 };
96
97 /* ---------------------------------------------------------------------- */
98 /* pm interface                                                           */
99
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         if (bochs->fb.initialized) {
109                 console_lock();
110                 fb_set_suspend(bochs->fb.helper.fbdev, 1);
111                 console_unlock();
112         }
113
114         return 0;
115 }
116
117 static int bochs_pm_resume(struct device *dev)
118 {
119         struct pci_dev *pdev = to_pci_dev(dev);
120         struct drm_device *drm_dev = pci_get_drvdata(pdev);
121         struct bochs_device *bochs = drm_dev->dev_private;
122
123         drm_helper_resume_force_mode(drm_dev);
124
125         if (bochs->fb.initialized) {
126                 console_lock();
127                 fb_set_suspend(bochs->fb.helper.fbdev, 0);
128                 console_unlock();
129         }
130
131         drm_kms_helper_poll_enable(drm_dev);
132         return 0;
133 }
134
135 static const struct dev_pm_ops bochs_pm_ops = {
136         SET_SYSTEM_SLEEP_PM_OPS(bochs_pm_suspend,
137                                 bochs_pm_resume)
138 };
139
140 /* ---------------------------------------------------------------------- */
141 /* pci interface                                                          */
142
143 static int bochs_kick_out_firmware_fb(struct pci_dev *pdev)
144 {
145         struct apertures_struct *ap;
146
147         ap = alloc_apertures(1);
148         if (!ap)
149                 return -ENOMEM;
150
151         ap->ranges[0].base = pci_resource_start(pdev, 0);
152         ap->ranges[0].size = pci_resource_len(pdev, 0);
153         remove_conflicting_framebuffers(ap, "bochsdrmfb", false);
154         kfree(ap);
155
156         return 0;
157 }
158
159 static int bochs_pci_probe(struct pci_dev *pdev,
160                            const struct pci_device_id *ent)
161 {
162         int ret;
163
164         ret = bochs_kick_out_firmware_fb(pdev);
165         if (ret)
166                 return ret;
167
168         return drm_get_pci_dev(pdev, ent, &bochs_driver);
169 }
170
171 static void bochs_pci_remove(struct pci_dev *pdev)
172 {
173         struct drm_device *dev = pci_get_drvdata(pdev);
174
175         drm_put_dev(dev);
176 }
177
178 static DEFINE_PCI_DEVICE_TABLE(bochs_pci_tbl) = {
179         {
180                 .vendor      = 0x1234,
181                 .device      = 0x1111,
182                 .subvendor   = 0x1af4,
183                 .subdevice   = 0x1100,
184                 .driver_data = BOCHS_QEMU_STDVGA,
185         },
186         {
187                 .vendor      = 0x1234,
188                 .device      = 0x1111,
189                 .subvendor   = PCI_ANY_ID,
190                 .subdevice   = PCI_ANY_ID,
191                 .driver_data = BOCHS_UNKNOWN,
192         },
193         { /* end of list */ }
194 };
195
196 static struct pci_driver bochs_pci_driver = {
197         .name =         "bochs-drm",
198         .id_table =     bochs_pci_tbl,
199         .probe =        bochs_pci_probe,
200         .remove =       bochs_pci_remove,
201         .driver.pm =    &bochs_pm_ops,
202 };
203
204 /* ---------------------------------------------------------------------- */
205 /* module init/exit                                                       */
206
207 static int __init bochs_init(void)
208 {
209         return drm_pci_init(&bochs_driver, &bochs_pci_driver);
210 }
211
212 static void __exit bochs_exit(void)
213 {
214         drm_pci_exit(&bochs_driver, &bochs_pci_driver);
215 }
216
217 module_init(bochs_init);
218 module_exit(bochs_exit);
219
220 MODULE_DEVICE_TABLE(pci, bochs_pci_tbl);
221 MODULE_AUTHOR("Gerd Hoffmann <kraxel@redhat.com>");
222 MODULE_LICENSE("GPL");