summaryrefslogtreecommitdiff
path: root/src/vmwaremodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vmwaremodule.c')
-rw-r--r--src/vmwaremodule.c256
1 files changed, 0 insertions, 256 deletions
diff --git a/src/vmwaremodule.c b/src/vmwaremodule.c
deleted file mode 100644
index 0da2440..0000000
--- a/src/vmwaremodule.c
+++ /dev/null
@@ -1,256 +0,0 @@
1/**********************************************************
2 * Copyright 2010 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
30#ifdef HAVE_LIBDRM
31#include <xf86drm.h>
32#endif
33
34#include <xorg-server.h>
35#include <xf86.h>
36
37#ifndef HAVE_XORG_SERVER_1_5_0
38#include <xf86_ansic.h>
39#include <xf86_libc.h>
40#endif
41
42/*
43 * Defines and exported module info.
44 */
45
46#define VMWARE_DRIVER_NAME "vmware"
47#define VMWGFX_DRIVER_NAME "vmwgfx"
48#define VMWGFX_MODULE_NAME "vmwgfx"
49#define VMWGFX_COMPAT_MAJOR 11
50#define VMWGFX_REQUIRED_MAJOR 11
51#define VMWGFX_REQUIRED_MINOR 0
52#define VMWLEGACY_DRIVER_NAME "vmwlegacy"
53
54#define VMW_STRING_INNER(s) #s
55#define VMW_STRING(str) VMW_STRING_INNER(str)
56
57#define VMWARE_DRIVER_VERSION \
58 (PACKAGE_VERSION_MAJOR * 65536 + PACKAGE_VERSION_MINOR * 256 + PACKAGE_VERSION_PATCHLEVEL)
59#define VMWARE_DRIVER_VERSION_STRING \
60 VMW_STRING(PACKAGE_VERSION_MAJOR) "." VMW_STRING(PACKAGE_VERSION_MINOR) \
61 "." VMW_STRING(PACKAGE_VERSION_PATCHLEVEL)
62
63/*
64 * Standard four digit version string expected by VMware Tools installer.
65 * As the driver's version is only {major, minor, patchlevel},
66 * the fourth digit may describe the commit number relative to the
67 * last version tag as output from `git describe`
68 */
69
70#ifdef __GNUC__
71#ifdef VMW_SUBPATCH
72const char vmware_drv_modinfo[] __attribute__((section(".modinfo"),unused)) =
73 "version=" VMWARE_DRIVER_VERSION_STRING "." VMW_STRING(VMW_SUBPATCH);
74#else
75const char vmware_drv_modinfo[] __attribute__((section(".modinfo"),unused)) =
76 "version=" VMWARE_DRIVER_VERSION_STRING ".0";
77#endif /*VMW_SUBPATCH*/
78#endif
79
80static XF86ModuleVersionInfo vmware_version;
81static MODULESETUPPROTO(vmware_setup);
82
83_X_EXPORT XF86ModuleData vmwareModuleData = {
84 &vmware_version,
85 vmware_setup,
86 NULL
87};
88
89extern XF86ModuleData *VMWGFX_MODULE_DATA;
90
91/*
92 * Chain loading functions
93 */
94
95static Bool
96vmware_check_kernel_module()
97{
98#ifdef HAVE_LIBDRM
99 /* Super simple way of knowing if the kernel driver is loaded */
100 int ret = drmOpen(VMWGFX_MODULE_NAME, NULL);
101 if (ret < 0) {
102 /* This shouldn't go in the log as the original message does not */
103 fprintf(stderr, "%s: Please ignore above \"FATAL: Module %s not found."
104 "\"\n", VMWARE_DRIVER_NAME, VMWGFX_MODULE_NAME);
105 /* This is what goes into the log on the other hand */
106 xf86DrvMsg(-1, X_PROBED, "%s: Please ignore above \"[drm] failed to "
107 "load kernel module \"%s\"\"\n", VMWARE_DRIVER_NAME,
108 VMWGFX_MODULE_NAME);
109 return FALSE;
110 }
111
112 drmClose(ret);
113
114 return TRUE;
115#else
116 return FALSE;
117#endif /* HAVE_LIBDRM */
118}
119
120static Bool
121vmware_check_vmwgfx_driver(int matched, pointer opts)
122{
123#ifdef HAVE_LIBDRM
124 int major; int minor;
125 pointer module;
126 CARD32 version;
127
128 if (matched) {
129 xf86DrvMsg(-1, X_PROBED, "%s: X configured to use %s X driver assume "
130 "who ever did that knows what they are doing\n",
131 VMWARE_DRIVER_NAME, VMWGFX_DRIVER_NAME);
132 /* Also how did they end up here, if the configured X to use vmwgfx and
133 * X should load that driver for that hardware. And since there is only
134 * one SVGA device this driver shouldn't be loaded. Weird...
135 */
136 return TRUE;
137 }
138
139 module = xf86LoadOneModule(VMWGFX_DRIVER_NAME, opts);
140 if (!module) {
141 xf86DrvMsg(-1, X_ERROR, "%s: Please ignore the above warnings about "
142 "not being able to to load module/driver %s\n",
143 VMWARE_DRIVER_NAME, VMWGFX_DRIVER_NAME);
144 return FALSE;
145 }
146
147 version = xf86GetModuleVersion(module);
148 major = GET_MODULE_MAJOR_VERSION(version);
149 minor = GET_MODULE_MINOR_VERSION(version);
150
151 if (major > VMWGFX_COMPAT_MAJOR ||
152 major < VMWGFX_REQUIRED_MAJOR ||
153 (major == VMWGFX_REQUIRED_MAJOR && minor < VMWGFX_REQUIRED_MINOR)) {
154 xf86DrvMsg(-1, X_PROBED, "%s: The %s X driver failed version "
155 "checking.\n", VMWARE_DRIVER_NAME, VMWGFX_DRIVER_NAME);
156 goto err;
157 }
158
159 return TRUE;
160
161err:
162 /* XXX We should drop the reference on the module here */
163#endif /* HAVE_LIBDRM */
164 return FALSE;
165}
166
167static Bool
168vmware_chain_module(pointer opts)
169{
170 int vmwlegacy_devices;
171 int vmwgfx_devices;
172 int vmware_devices;
173 int matched;
174 char *driver_name;
175 GDevPtr *gdevs;
176 GDevPtr gdev;
177 int i;
178
179 vmware_devices = xf86MatchDevice(VMWARE_DRIVER_NAME, &gdevs);
180 vmwgfx_devices = xf86MatchDevice(VMWGFX_DRIVER_NAME, NULL);
181 vmwlegacy_devices = xf86MatchDevice(VMWLEGACY_DRIVER_NAME, NULL);
182
183 if (vmware_check_vmwgfx_driver(vmwgfx_devices, opts) &&
184 vmware_check_kernel_module()) {
185 xf86DrvMsg(-1, X_INFO, "%s: Using %s X driver.\n",
186 VMWARE_DRIVER_NAME, VMWGFX_DRIVER_NAME);
187 driver_name = VMWGFX_DRIVER_NAME;
188 matched = 1;
189 } else {
190 xf86DrvMsg(-1, X_INFO, "%s: Using %s driver everything is fine.\n",
191 VMWARE_DRIVER_NAME, VMWLEGACY_DRIVER_NAME);
192 driver_name = VMWLEGACY_DRIVER_NAME;
193 matched = vmwlegacy_devices;
194 }
195
196 /* Xorg -configure returns 1 from xf86MatchDevice with NULL gdevs */
197 for (i = 0; gdevs && i < vmware_devices; i++) {
198 gdev = gdevs[i];
199 gdev->driver = driver_name;
200 }
201
202 free(gdevs);
203
204 if (!matched) {
205 if (xf86LoadOneModule(driver_name, opts) == NULL) {
206 xf86DrvMsg(-1, X_ERROR, "%s: Unexpected failure while "
207 "loading the \"%s\" driver. Giving up.\n",
208 VMWARE_DRIVER_NAME, driver_name);
209 return FALSE;
210 }
211 }
212
213 return TRUE;
214}
215
216
217/*
218 * Module info
219 */
220
221static XF86ModuleVersionInfo vmware_version = {
222 VMWARE_DRIVER_NAME,
223 MODULEVENDORSTRING,
224 MODINFOSTRING1,
225 MODINFOSTRING2,
226 XORG_VERSION_CURRENT,
227 PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
228 ABI_CLASS_VIDEODRV,
229 ABI_VIDEODRV_VERSION,
230 MOD_CLASS_VIDEODRV,
231 {0, 0, 0, 0}
232};
233
234static pointer
235vmware_setup(pointer module, pointer opts, int *errmaj, int *errmin)
236{
237 static Bool setupDone = 0;
238
239 /* This module should be loaded only once, but check to be sure. */
240 if (!setupDone) {
241 setupDone = 1;
242
243 /* Chain load the real driver */
244 if (vmware_chain_module(opts))
245 return (pointer) 1;
246 else {
247 if (errmaj)
248 *errmaj = LDR_NOSUBENT;
249 return NULL;
250 }
251 } else {
252 if (errmaj)
253 *errmaj = LDR_ONCEONLY;
254 return NULL;
255 }
256}