VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/drm/vbox_drv.c@ 61602

Last change on this file since 61602 was 60584, checked in by vboxsync, 9 years ago

Linux host/guest modules: include the revision into the Linux kernel modules (for modinfo MODULE.ko)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/* $Id: vbox_drv.c 60584 2016-04-20 09:40:50Z vboxsync $ */
2/** @file
3 * VirtualBox Additions Linux kernel video driver
4 */
5
6/*
7 * Copyright (C) 2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 * --------------------------------------------------------------------
17 *
18 * This code is based on
19 * ast_drv.c
20 * with the following copyright and permission notice:
21 *
22 * Copyright 2012 Red Hat Inc.
23 *
24 * Permission is hereby granted, free of charge, to any person obtaining a
25 * copy of this software and associated documentation files (the
26 * "Software"), to deal in the Software without restriction, including
27 * without limitation the rights to use, copy, modify, merge, publish,
28 * distribute, sub license, and/or sell copies of the Software, and to
29 * permit persons to whom the Software is furnished to do so, subject to
30 * the following conditions:
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
35 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
36 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
37 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
38 * USE OR OTHER DEALINGS IN THE SOFTWARE.
39 *
40 * The above copyright notice and this permission notice (including the
41 * next paragraph) shall be included in all copies or substantial portions
42 * of the Software.
43 *
44 */
45/*
46 * Authors: Dave Airlie <[email protected]>
47 */
48#include "vbox_drv.h"
49
50#include <VBox/VBoxGuest.h>
51#include "version-generated.h"
52#include "revision-generated.h"
53
54#include <linux/module.h>
55#include <linux/console.h>
56#include <linux/vt_kern.h>
57
58#include <drm/drmP.h>
59#include <drm/drm_crtc_helper.h>
60
61int vbox_modeset = -1;
62
63MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
64module_param_named(modeset, vbox_modeset, int, 0400);
65
66static struct drm_driver driver;
67
68static DEFINE_PCI_DEVICE_TABLE(pciidlist) =
69{
70 {0x80ee, 0xbeef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
71 {0, 0, 0},
72};
73
74MODULE_DEVICE_TABLE(pci, pciidlist);
75
76static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
77{
78 return drm_get_pci_dev(pdev, ent, &driver);
79}
80
81
82static void vbox_pci_remove(struct pci_dev *pdev)
83{
84 struct drm_device *dev = pci_get_drvdata(pdev);
85
86 drm_put_dev(dev);
87}
88
89
90
91static int vbox_drm_freeze(struct drm_device *dev)
92{
93 drm_kms_helper_poll_disable(dev);
94
95 pci_save_state(dev->pdev);
96
97 console_lock();
98 vbox_fbdev_set_suspend(dev, 1);
99 console_unlock();
100 return 0;
101}
102
103static int vbox_drm_thaw(struct drm_device *dev)
104{
105 int error = 0;
106
107 drm_mode_config_reset(dev);
108 drm_helper_resume_force_mode(dev);
109
110 console_lock();
111 vbox_fbdev_set_suspend(dev, 0);
112 console_unlock();
113 return error;
114}
115
116static int vbox_drm_resume(struct drm_device *dev)
117{
118 int ret;
119
120 if (pci_enable_device(dev->pdev))
121 return -EIO;
122
123 ret = vbox_drm_thaw(dev);
124 if (ret)
125 return ret;
126
127 drm_kms_helper_poll_enable(dev);
128 return 0;
129}
130
131static int vbox_pm_suspend(struct device *dev)
132{
133 struct pci_dev *pdev = to_pci_dev(dev);
134 struct drm_device *ddev = pci_get_drvdata(pdev);
135 int error;
136
137 error = vbox_drm_freeze(ddev);
138 if (error)
139 return error;
140
141 pci_disable_device(pdev);
142 pci_set_power_state(pdev, PCI_D3hot);
143 return 0;
144}
145
146static int vbox_pm_resume(struct device *dev)
147{
148 struct pci_dev *pdev = to_pci_dev(dev);
149 struct drm_device *ddev = pci_get_drvdata(pdev);
150 return vbox_drm_resume(ddev);
151}
152
153static int vbox_pm_freeze(struct device *dev)
154{
155 struct pci_dev *pdev = to_pci_dev(dev);
156 struct drm_device *ddev = pci_get_drvdata(pdev);
157
158 if (!ddev || !ddev->dev_private)
159 return -ENODEV;
160 return vbox_drm_freeze(ddev);
161
162}
163
164static int vbox_pm_thaw(struct device *dev)
165{
166 struct pci_dev *pdev = to_pci_dev(dev);
167 struct drm_device *ddev = pci_get_drvdata(pdev);
168 return vbox_drm_thaw(ddev);
169}
170
171static int vbox_pm_poweroff(struct device *dev)
172{
173 struct pci_dev *pdev = to_pci_dev(dev);
174 struct drm_device *ddev = pci_get_drvdata(pdev);
175
176 return vbox_drm_freeze(ddev);
177}
178
179static const struct dev_pm_ops vbox_pm_ops = {
180 .suspend = vbox_pm_suspend,
181 .resume = vbox_pm_resume,
182 .freeze = vbox_pm_freeze,
183 .thaw = vbox_pm_thaw,
184 .poweroff = vbox_pm_poweroff,
185 .restore = vbox_pm_resume,
186};
187
188static struct pci_driver vbox_pci_driver =
189{
190 .name = DRIVER_NAME,
191 .id_table = pciidlist,
192 .probe = vbox_pci_probe,
193 .remove = vbox_pci_remove,
194 .driver.pm = &vbox_pm_ops,
195};
196
197static const struct file_operations vbox_fops =
198{
199 .owner = THIS_MODULE,
200 .open = drm_open,
201 .release = drm_release,
202 .unlocked_ioctl = drm_ioctl,
203 .mmap = vbox_mmap,
204 .poll = drm_poll,
205#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0)
206 .fasync = drm_fasync,
207#endif
208#ifdef CONFIG_COMPAT
209 .compat_ioctl = drm_compat_ioctl,
210#endif
211 .read = drm_read,
212};
213
214static int vbox_master_set(struct drm_device *dev,
215 struct drm_file *file_priv,
216 bool from_open)
217{
218 struct vbox_private *vbox = dev->dev_private;
219 vbox->initial_mode_queried = false;
220 vbox_disable_accel(vbox);
221 return 0;
222}
223
224static void vbox_master_drop(struct drm_device *dev,
225 struct drm_file *file_priv,
226 bool from_release)
227{
228 struct vbox_private *vbox = dev->dev_private;
229 vbox->initial_mode_queried = false;
230 vbox_disable_accel(vbox);
231}
232
233static struct drm_driver driver =
234{
235 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED,
236 .dev_priv_size = 0,
237
238 .load = vbox_driver_load,
239 .unload = vbox_driver_unload,
240 .lastclose = vbox_driver_lastclose,
241 .master_set = vbox_master_set,
242 .master_drop = vbox_master_drop,
243#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
244 .set_busid = drm_pci_set_busid,
245#endif
246
247 .fops = &vbox_fops,
248 .irq_handler = vbox_irq_handler,
249 .name = DRIVER_NAME,
250 .desc = DRIVER_DESC,
251 .date = DRIVER_DATE,
252 .major = DRIVER_MAJOR,
253 .minor = DRIVER_MINOR,
254 .patchlevel = DRIVER_PATCHLEVEL,
255
256 .gem_free_object = vbox_gem_free_object,
257 .dumb_create = vbox_dumb_create,
258 .dumb_map_offset = vbox_dumb_mmap_offset,
259#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0)
260 .dumb_destroy = vbox_dumb_destroy,
261#else
262 .dumb_destroy = drm_gem_dumb_destroy,
263#endif
264
265};
266
267static int __init vbox_init(void)
268{
269 unsigned i;
270
271#ifdef CONFIG_VGA_CONSOLE
272 if (vgacon_text_force() && vbox_modeset == -1)
273 return -EINVAL;
274#endif
275
276 if (vbox_modeset == 0)
277 return -EINVAL;
278
279 /* Do not load if any of the virtual consoles is in graphics mode to be
280 * sure that we do not pick a fight with a user-mode driver or VESA. */
281 for (i = 0; i < MAX_NR_CONSOLES - 1; ++i)
282 if (vc_cons[i].d && vc_cons[i].d->vc_mode == KD_GRAPHICS)
283 return -EINVAL;
284
285 return drm_pci_init(&driver, &vbox_pci_driver);
286}
287static void __exit vbox_exit(void)
288{
289 drm_pci_exit(&driver, &vbox_pci_driver);
290}
291
292module_init(vbox_init);
293module_exit(vbox_exit);
294
295MODULE_AUTHOR(DRIVER_AUTHOR);
296MODULE_DESCRIPTION(DRIVER_DESC);
297MODULE_LICENSE("GPL and additional rights");
298#ifdef MODULE_VERSION
299MODULE_VERSION(VBOX_VERSION_STRING " r" RT_XSTR(VBOX_SVN_REV));
300#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette