1 | /* $Id: vboxvideo_drm.c 58877 2015-11-26 11:27:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Additions Linux kernel driver, DRM support
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 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 | *
|
---|
20 | * tdfx_drv.c -- tdfx driver -*- linux-c -*-
|
---|
21 | * Created: Thu Oct 7 10:38:32 1999 by [email protected]
|
---|
22 | *
|
---|
23 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
---|
24 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
---|
25 | * All Rights Reserved.
|
---|
26 | *
|
---|
27 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
28 | * copy of this software and associated documentation files (the "Software"),
|
---|
29 | * to deal in the Software without restriction, including without limitation
|
---|
30 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
31 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
32 | * Software is furnished to do so, subject to the following conditions:
|
---|
33 | *
|
---|
34 | * The above copyright notice and this permission notice (including the next
|
---|
35 | * paragraph) shall be included in all copies or substantial portions of the
|
---|
36 | * Software.
|
---|
37 | *
|
---|
38 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
39 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
40 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
41 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
---|
42 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
---|
43 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
---|
44 | * DEALINGS IN THE SOFTWARE.
|
---|
45 | *
|
---|
46 | * Authors:
|
---|
47 | * Rickard E. (Rik) Faith <[email protected]>
|
---|
48 | * Daryll Strauss <[email protected]>
|
---|
49 | * Gareth Hughes <[email protected]>
|
---|
50 | */
|
---|
51 |
|
---|
52 | #include "version-generated.h"
|
---|
53 |
|
---|
54 | #include <linux/module.h>
|
---|
55 | #include <linux/version.h>
|
---|
56 | #include <drm/drmP.h>
|
---|
57 | #include "vboxvideo_drm.h"
|
---|
58 |
|
---|
59 | /* This definition and the file-operations-as-pointer change were both added in
|
---|
60 | * kernel 3.3. All back-ports of the structure change to distribution kernels
|
---|
61 | * that I have checked also back-ported the definition at the same time. */
|
---|
62 | #ifdef DRM_IOCTL_MODE_ADDFB2
|
---|
63 | # define DRM_FOPS_AS_POINTER
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | /* The first of these was introduced when drm was generalised to work with
|
---|
67 | * non-PCI buses, but was removed between 3.15 and 3.16. The second is a
|
---|
68 | * random definition introduced in the mean-time. */
|
---|
69 | #if defined(DRIVER_BUS_PCI) || defined(DRIVER_PRIME)
|
---|
70 | # define DRM_NEW_BUS_INIT 1
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
|
---|
74 | # ifdef RHEL_RELEASE_CODE
|
---|
75 | # if RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(7, 2)
|
---|
76 | # define DRM_HAVE_DRM_MAP
|
---|
77 | # endif
|
---|
78 | # else
|
---|
79 | # define DRM_HAVE_DRM_MAP
|
---|
80 | # endif
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
|
---|
84 | # define DRM_WANTS_SET_BUSID
|
---|
85 | #else
|
---|
86 | # ifdef RHEL_RELEASE_CODE
|
---|
87 | # if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 2)
|
---|
88 | # define DRM_WANTS_SET_BUSID
|
---|
89 | # endif
|
---|
90 | # endif
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | static struct pci_device_id pciidlist[] = {
|
---|
94 | vboxvideo_PCI_IDS
|
---|
95 | };
|
---|
96 |
|
---|
97 | MODULE_DEVICE_TABLE(pci, pciidlist);
|
---|
98 |
|
---|
99 | int vboxvideo_driver_load(struct drm_device * dev, unsigned long flags)
|
---|
100 | {
|
---|
101 | return 0;
|
---|
102 | }
|
---|
103 |
|
---|
104 | #ifdef DRM_FOPS_AS_POINTER
|
---|
105 | /* since linux-3.3.0-rc1 drm_driver::fops is pointer */
|
---|
106 | static struct file_operations driver_fops =
|
---|
107 | {
|
---|
108 | .owner = THIS_MODULE,
|
---|
109 | .open = drm_open,
|
---|
110 | .release = drm_release,
|
---|
111 | .unlocked_ioctl = drm_ioctl,
|
---|
112 | # ifdef DRM_HAVE_DRM_MAP
|
---|
113 | /* This shouldn't be necessary even for old kernels as there is
|
---|
114 | * nothing sensible to mmap. But we play safe and keep it for
|
---|
115 | * legacy reasons. */
|
---|
116 | .mmap = drm_mmap,
|
---|
117 | # endif
|
---|
118 | .poll = drm_poll,
|
---|
119 | };
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | static struct drm_driver driver =
|
---|
123 | {
|
---|
124 | /* .driver_features = DRIVER_USE_MTRR, */
|
---|
125 | .load = vboxvideo_driver_load,
|
---|
126 | #ifdef DRM_WANTS_SET_BUSID
|
---|
127 | /* If this is missing a warning gets printed to dmesg. We will not
|
---|
128 | * attempt to make kernels work to which the change (915b4d11b) got back-
|
---|
129 | * ported, as the problem is only cosmetic. */
|
---|
130 | .set_busid = drm_pci_set_busid,
|
---|
131 | #endif
|
---|
132 | # ifndef DRM_FOPS_AS_POINTER
|
---|
133 | .fops =
|
---|
134 | {
|
---|
135 | .owner = THIS_MODULE,
|
---|
136 | .open = drm_open,
|
---|
137 | .release = drm_release,
|
---|
138 | /* This was changed with Linux 2.6.33 but Fedora backported this
|
---|
139 | * change to their 2.6.32 kernel. */
|
---|
140 | #if defined(DRM_UNLOCKED)
|
---|
141 | .unlocked_ioctl = drm_ioctl,
|
---|
142 | #else
|
---|
143 | .ioctl = drm_ioctl,
|
---|
144 | #endif
|
---|
145 | .mmap = drm_mmap,
|
---|
146 | .poll = drm_poll,
|
---|
147 | },
|
---|
148 | #else /* defined(DRM_FOPS_AS_POINTER) */
|
---|
149 | .fops = &driver_fops,
|
---|
150 | #endif
|
---|
151 | #ifndef DRM_NEW_BUS_INIT
|
---|
152 | .pci_driver =
|
---|
153 | {
|
---|
154 | .name = DRIVER_NAME,
|
---|
155 | .id_table = pciidlist,
|
---|
156 | },
|
---|
157 | #endif
|
---|
158 | .name = DRIVER_NAME,
|
---|
159 | .desc = DRIVER_DESC,
|
---|
160 | .date = DRIVER_DATE,
|
---|
161 | .major = DRIVER_MAJOR,
|
---|
162 | .minor = DRIVER_MINOR,
|
---|
163 | .patchlevel = DRIVER_PATCHLEVEL,
|
---|
164 | };
|
---|
165 |
|
---|
166 | #ifdef DRM_NEW_BUS_INIT
|
---|
167 | static struct pci_driver pci_driver =
|
---|
168 | {
|
---|
169 | .name = DRIVER_NAME,
|
---|
170 | .id_table = pciidlist,
|
---|
171 | };
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | static int __init vboxvideo_init(void)
|
---|
175 | {
|
---|
176 | #ifndef DRM_NEW_BUS_INIT
|
---|
177 | return drm_init(&driver);
|
---|
178 | #else
|
---|
179 | return drm_pci_init(&driver, &pci_driver);
|
---|
180 | #endif
|
---|
181 | }
|
---|
182 |
|
---|
183 | static void __exit vboxvideo_exit(void)
|
---|
184 | {
|
---|
185 | #ifndef DRM_NEW_BUS_INIT
|
---|
186 | drm_exit(&driver);
|
---|
187 | #else
|
---|
188 | drm_pci_exit(&driver, &pci_driver);
|
---|
189 | #endif
|
---|
190 | }
|
---|
191 |
|
---|
192 | module_init(vboxvideo_init);
|
---|
193 | module_exit(vboxvideo_exit);
|
---|
194 |
|
---|
195 | MODULE_AUTHOR(DRIVER_AUTHOR);
|
---|
196 | MODULE_DESCRIPTION(DRIVER_DESC);
|
---|
197 | #ifdef MODULE_VERSION
|
---|
198 | MODULE_VERSION(VBOX_VERSION_STRING);
|
---|
199 | #endif
|
---|
200 | MODULE_LICENSE("GPL and additional rights");
|
---|