VirtualBox

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

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

bugref:8087: Additions/x11: support non-root X server: additional kernel module build fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1/* $Id: vbox_drv.c 59964 2016-03-09 11:20:48Z 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
52#include <linux/module.h>
53#include <linux/console.h>
54
55#include <drm/drmP.h>
56#include <drm/drm_crtc_helper.h>
57
58int vbox_modeset = -1;
59
60MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
61module_param_named(modeset, vbox_modeset, int, 0400);
62
63static struct drm_driver driver;
64
65static DEFINE_PCI_DEVICE_TABLE(pciidlist) =
66{
67 {0x80ee, 0xbeef, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
68 {0, 0, 0},
69};
70
71MODULE_DEVICE_TABLE(pci, pciidlist);
72
73static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
74{
75 return drm_get_pci_dev(pdev, ent, &driver);
76}
77
78
79static void vbox_pci_remove(struct pci_dev *pdev)
80{
81 struct drm_device *dev = pci_get_drvdata(pdev);
82
83 drm_put_dev(dev);
84}
85
86
87
88static int vbox_drm_freeze(struct drm_device *dev)
89{
90 drm_kms_helper_poll_disable(dev);
91
92 pci_save_state(dev->pdev);
93
94 console_lock();
95 vbox_fbdev_set_suspend(dev, 1);
96 console_unlock();
97 return 0;
98}
99
100static int vbox_drm_thaw(struct drm_device *dev)
101{
102 int error = 0;
103
104 drm_mode_config_reset(dev);
105 drm_helper_resume_force_mode(dev);
106
107 console_lock();
108 vbox_fbdev_set_suspend(dev, 0);
109 console_unlock();
110 return error;
111}
112
113static int vbox_drm_resume(struct drm_device *dev)
114{
115 int ret;
116
117 if (pci_enable_device(dev->pdev))
118 return -EIO;
119
120 ret = vbox_drm_thaw(dev);
121 if (ret)
122 return ret;
123
124 drm_kms_helper_poll_enable(dev);
125 return 0;
126}
127
128static int vbox_pm_suspend(struct device *dev)
129{
130 struct pci_dev *pdev = to_pci_dev(dev);
131 struct drm_device *ddev = pci_get_drvdata(pdev);
132 int error;
133
134 error = vbox_drm_freeze(ddev);
135 if (error)
136 return error;
137
138 pci_disable_device(pdev);
139 pci_set_power_state(pdev, PCI_D3hot);
140 return 0;
141}
142
143static int vbox_pm_resume(struct device *dev)
144{
145 struct pci_dev *pdev = to_pci_dev(dev);
146 struct drm_device *ddev = pci_get_drvdata(pdev);
147 return vbox_drm_resume(ddev);
148}
149
150static int vbox_pm_freeze(struct device *dev)
151{
152 struct pci_dev *pdev = to_pci_dev(dev);
153 struct drm_device *ddev = pci_get_drvdata(pdev);
154
155 if (!ddev || !ddev->dev_private)
156 return -ENODEV;
157 return vbox_drm_freeze(ddev);
158
159}
160
161static int vbox_pm_thaw(struct device *dev)
162{
163 struct pci_dev *pdev = to_pci_dev(dev);
164 struct drm_device *ddev = pci_get_drvdata(pdev);
165 return vbox_drm_thaw(ddev);
166}
167
168static int vbox_pm_poweroff(struct device *dev)
169{
170 struct pci_dev *pdev = to_pci_dev(dev);
171 struct drm_device *ddev = pci_get_drvdata(pdev);
172
173 return vbox_drm_freeze(ddev);
174}
175
176static const struct dev_pm_ops vbox_pm_ops = {
177 .suspend = vbox_pm_suspend,
178 .resume = vbox_pm_resume,
179 .freeze = vbox_pm_freeze,
180 .thaw = vbox_pm_thaw,
181 .poweroff = vbox_pm_poweroff,
182 .restore = vbox_pm_resume,
183};
184
185static struct pci_driver vbox_pci_driver =
186{
187 .name = DRIVER_NAME,
188 .id_table = pciidlist,
189 .probe = vbox_pci_probe,
190 .remove = vbox_pci_remove,
191 .driver.pm = &vbox_pm_ops,
192};
193
194
195static const struct file_operations vbox_fops =
196{
197 .owner = THIS_MODULE,
198 .open = drm_open,
199 .release = drm_release,
200 .unlocked_ioctl = drm_ioctl,
201 .mmap = vbox_mmap,
202 .poll = drm_poll,
203#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0)
204 .fasync = drm_fasync,
205#endif
206#ifdef CONFIG_COMPAT
207 .compat_ioctl = drm_compat_ioctl,
208#endif
209 .read = drm_read,
210};
211
212static struct drm_driver driver =
213{
214 .driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_HAVE_IRQ,
215 .dev_priv_size = 0,
216
217 .load = vbox_driver_load,
218 .unload = vbox_driver_unload,
219 .lastclose = vbox_driver_lastclose,
220#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
221 .set_busid = drm_pci_set_busid,
222#endif
223
224 .fops = &vbox_fops,
225 .irq_handler = vbox_irq_handler,
226 .name = DRIVER_NAME,
227 .desc = DRIVER_DESC,
228 .date = DRIVER_DATE,
229 .major = DRIVER_MAJOR,
230 .minor = DRIVER_MINOR,
231 .patchlevel = DRIVER_PATCHLEVEL,
232
233 .gem_free_object = vbox_gem_free_object,
234 .dumb_create = vbox_dumb_create,
235 .dumb_map_offset = vbox_dumb_mmap_offset,
236#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0)
237 .dumb_destroy = vbox_dumb_destroy,
238#else
239 .dumb_destroy = drm_gem_dumb_destroy,
240#endif
241
242};
243
244static int __init vbox_init(void)
245{
246#ifdef CONFIG_VGA_CONSOLE
247 if (vgacon_text_force() && vbox_modeset == -1)
248 return -EINVAL;
249#endif
250
251 if (vbox_modeset == 0)
252 return -EINVAL;
253 return drm_pci_init(&driver, &vbox_pci_driver);
254}
255static void __exit vbox_exit(void)
256{
257 drm_pci_exit(&driver, &vbox_pci_driver);
258}
259
260module_init(vbox_init);
261module_exit(vbox_exit);
262
263MODULE_AUTHOR(DRIVER_AUTHOR);
264MODULE_DESCRIPTION(DRIVER_DESC);
265MODULE_LICENSE("GPL and additional rights");
266
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