VirtualBox

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

Last change on this file since 52002 was 50902, checked in by vboxsync, 11 years ago

Additions/linux/drm: add host mouse cursor support to the kernel video driver.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/** @file $Id: vbox_drv.c 50902 2014-03-26 22:05:24Z vboxsync $
2 *
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 <airlied@redhat.com>
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
87static struct pci_driver vbox_pci_driver =
88{
89 .name = DRIVER_NAME,
90 .id_table = pciidlist,
91 .probe = vbox_pci_probe,
92 .remove = vbox_pci_remove,
93};
94
95
96static struct drm_ioctl_desc vbox_ioctls[] =
97{
98 DRM_IOCTL_DEF_DRV(VBOX_DISABLE_HGSMI, VBoxDisableHGSMI,
99 DRM_UNLOCKED|DRM_ROOT_ONLY),
100 DRM_IOCTL_DEF_DRV(VBOX_ENABLE_HGSMI, VBoxEnableHGSMI,
101 DRM_UNLOCKED|DRM_ROOT_ONLY)
102};
103
104/* Intercept the old-style cursor IOCtl which does not pass the hot-spot to stop
105 * the kernel from translating it to a new-style one with a zero hot-spot, which
106 * we do not want. */
107static long vbox_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
108{
109 if (cmd != DRM_IOCTL_MODE_CURSOR)
110 return drm_ioctl(filp, cmd, arg);
111 return -EINVAL;
112}
113
114#ifdef CONFIG_COMPAT
115static long vbox_compat_ioctl(struct file *filp, unsigned int cmd,
116 unsigned long arg)
117{
118 if (cmd != DRM_IOCTL_MODE_CURSOR)
119 return drm_compat_ioctl(filp, cmd, arg);
120 return -EINVAL;
121}
122#endif
123
124static const struct file_operations vbox_fops =
125{
126 .owner = THIS_MODULE,
127 .open = drm_open,
128 .release = drm_release,
129 .unlocked_ioctl = vbox_ioctl,
130 .mmap = vbox_mmap,
131 .poll = drm_poll,
132 .fasync = drm_fasync,
133#ifdef CONFIG_COMPAT
134 .compat_ioctl = vbox_compat_ioctl,
135#endif
136 .read = drm_read,
137};
138
139static struct drm_driver driver =
140{
141 .driver_features = DRIVER_USE_MTRR | DRIVER_MODESET | DRIVER_GEM,
142 .dev_priv_size = 0,
143
144 .load = vbox_driver_load,
145 .unload = vbox_driver_unload,
146
147 .ioctls = vbox_ioctls,
148 .num_ioctls = RT_ELEMENTS(vbox_ioctls),
149 .fops = &vbox_fops,
150 .name = DRIVER_NAME,
151 .desc = DRIVER_DESC,
152 .date = DRIVER_DATE,
153 .major = DRIVER_MAJOR,
154 .minor = DRIVER_MINOR,
155 .patchlevel = DRIVER_PATCHLEVEL,
156
157 .gem_init_object = vbox_gem_init_object,
158 .gem_free_object = vbox_gem_free_object,
159 .dumb_create = vbox_dumb_create,
160 .dumb_map_offset = vbox_dumb_mmap_offset,
161 .dumb_destroy = vbox_dumb_destroy,
162
163};
164
165static int __init vbox_init(void)
166{
167#ifdef CONFIG_VGA_CONSOLE
168 if (vgacon_text_force() && vbox_modeset == -1)
169 return -EINVAL;
170#endif
171
172 if (vbox_modeset == 0)
173 return -EINVAL;
174 return drm_pci_init(&driver, &vbox_pci_driver);
175}
176static void __exit vbox_exit(void)
177{
178 drm_pci_exit(&driver, &vbox_pci_driver);
179}
180
181module_init(vbox_init);
182module_exit(vbox_exit);
183
184MODULE_AUTHOR(DRIVER_AUTHOR);
185MODULE_DESCRIPTION(DRIVER_DESC);
186MODULE_LICENSE("GPL and additional rights");
187
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