1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
/*
* Copyright 2011 VMWare, Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Author: Unknown at vmware
* Author: Thomas Hellstrom <thellstrom@vmware.com>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "xf86.h"
#include "compiler.h"
#include "xf86Pci.h" /* pci */
#include "vm_device_version.h"
#include "vmware_bootstrap.h"
#include <stdint.h>
#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
#include "xf86Resources.h"
#endif
#ifndef XSERVER_LIBPCIACCESS
#include "vm_basic_types.h"
#include "svga_reg.h"
#endif
#ifndef HAVE_XORG_SERVER_1_5_0
#include <xf86_ansic.h>
#include <xf86_libc.h>
#endif
#ifdef XSERVER_PLATFORM_BUS
#include "xf86platformBus.h"
#endif
#ifdef HaveDriverFuncs
#define VMWARE_DRIVER_FUNC HaveDriverFuncs
#else
#define VMWARE_DRIVER_FUNC 0
#endif
/*
* So that the file compiles unmodified when dropped in to a < 6.9 source tree.
*/
#ifndef _X_EXPORT
#define _X_EXPORT
#endif
/*
* So that the file compiles unmodified when dropped into an xfree source tree.
*/
#ifndef XORG_VERSION_CURRENT
#define XORG_VERSION_CURRENT XF86_VERSION_CURRENT
#endif
/*
* This is the only way I know to turn a #define of an integer constant into
* a constant string.
*/
#define VMW_INNERSTRINGIFY(s) #s
#define VMW_STRING(str) VMW_INNERSTRINGIFY(str)
#define VMWARE_DRIVER_NAME "vmware"
#define VMWARE_NAME "vmware"
static char vmware_driver_name[] = VMWARE_DRIVER_NAME;
#define VMWARE_DRIVER_VERSION \
(PACKAGE_VERSION_MAJOR * 65536 + PACKAGE_VERSION_MINOR * 256 + PACKAGE_VERSION_PATCHLEVEL)
#define VMWARE_DRIVER_VERSION_STRING \
VMW_STRING(PACKAGE_VERSION_MAJOR) "." VMW_STRING(PACKAGE_VERSION_MINOR) \
"." VMW_STRING(PACKAGE_VERSION_PATCHLEVEL)
#if !XSERVER_LIBPCIACCESS
static const char VMWAREBuildStr[] = "VMware Guest X Server "
VMWARE_DRIVER_VERSION_STRING " - build=$Name$\n";
#else
static char vmware_name[] = VMWARE_NAME;
#endif
/*
* Standard four digit version string expected by VMware Tools installer.
* As the driver's version is only {major, minor, patchlevel},
* The fourth digit may describe the commit number relative to the
* last version tag as output from `git describe`
*/
#ifdef __GNUC__
#ifdef VMW_SUBPATCH
const char vmware_drv_modinfo[]
__attribute__((section(".modinfo"),unused)) =
"version=" VMWARE_DRIVER_VERSION_STRING "." VMW_STRING(VMW_SUBPATCH);
#else
const char vmware_drv_modinfo[]
__attribute__((section(".modinfo"),unused)) =
"version=" VMWARE_DRIVER_VERSION_STRING ".0";
#endif /*VMW_SUBPATCH*/
#endif
#ifndef XSERVER_LIBPCIACCESS
static resRange vmwareLegacyRes[] = {
{ ResExcIoBlock, SVGA_LEGACY_BASE_PORT,
SVGA_LEGACY_BASE_PORT + SVGA_NUM_PORTS*sizeof(uint32)},
_VGA_EXCLUSIVE, _END
};
#else
#define vmwareLegacyRes NULL
#endif
#if XSERVER_LIBPCIACCESS
#define VENDOR_ID(p) (p)->vendor_id
#define DEVICE_ID(p) (p)->device_id
#define SUBVENDOR_ID(p) (p)->subvendor_id
#define SUBSYS_ID(p) (p)->subdevice_id
#define CHIP_REVISION(p) (p)->revision
#else
#define VENDOR_ID(p) (p)->vendor
#define DEVICE_ID(p) (p)->chipType
#define SUBVENDOR_ID(p) (p)->subsysVendor
#define SUBSYS_ID(p) (p)->subsysCard
#define CHIP_REVISION(p) (p)->chipRev
#endif
#if XSERVER_LIBPCIACCESS
#define VMWARE_DEVICE_MATCH(d, i) \
{PCI_VENDOR_ID_VMWARE, (d), PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, (i) }
static const struct pci_id_match VMwareDeviceMatch[] = {
VMWARE_DEVICE_MATCH (PCI_DEVICE_ID_VMWARE_SVGA2, 0 ),
VMWARE_DEVICE_MATCH (PCI_DEVICE_ID_VMWARE_SVGA, 0 ),
{ 0, 0, 0 },
};
#endif
/*
* Currently, even the PCI obedient 0405 chip still only obeys IOSE and
* MEMSE for the SVGA resources. Thus, RES_EXCLUSIVE_VGA is required.
*
* The 0710 chip also uses hardcoded IO ports that aren't disablable.
*/
static PciChipsets VMWAREPciChipsets[] = {
{ PCI_DEVICE_ID_VMWARE_SVGA2, PCI_DEVICE_ID_VMWARE_SVGA2, RES_EXCLUSIVE_VGA },
{ PCI_DEVICE_ID_VMWARE_SVGA, PCI_DEVICE_ID_VMWARE_SVGA, vmwareLegacyRes },
{ -1, -1, RES_UNDEFINED }
};
static SymTabRec VMWAREChipsets[] = {
{ PCI_DEVICE_ID_VMWARE_SVGA2, "vmware0405" },
{ PCI_DEVICE_ID_VMWARE_SVGA, "vmware0710" },
{ -1, NULL }
};
#ifdef XFree86LOADER
static XF86ModuleVersionInfo vmwareVersRec = {
VMWARE_DRIVER_NAME,
MODULEVENDORSTRING,
MODINFOSTRING1,
MODINFOSTRING2,
XORG_VERSION_CURRENT,
PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
ABI_CLASS_VIDEODRV,
ABI_VIDEODRV_VERSION,
MOD_CLASS_VIDEODRV,
{ 0, 0, 0, 0}
};
#endif /* XFree86LOADER */
static const OptionInfoRec VMWAREOptions[] = {
{ OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_XINERAMA, "Xinerama", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_STATIC_XINERAMA, "StaticXinerama", OPTV_STRING, {0}, FALSE },
{ OPTION_GUI_LAYOUT, "GuiLayout", OPTV_STRING, {0}, FALSE },
{ OPTION_DEFAULT_MODE, "AddDefaultMode", OPTV_BOOLEAN, {0}, FALSE },
{ OPTION_RENDER_ACCEL, "RenderAccel", OPTV_BOOLEAN, {0}, FALSE},
{ OPTION_DRI, "DRI", OPTV_BOOLEAN, {0}, FALSE},
{ OPTION_DIRECT_PRESENTS, "DirectPresents", OPTV_BOOLEAN, {0}, FALSE},
{ OPTION_HW_PRESENTS, "HWPresents", OPTV_BOOLEAN, {0}, FALSE},
{ OPTION_RENDERCHECK, "RenderCheck", OPTV_BOOLEAN, {0}, FALSE},
{ -1, NULL, OPTV_NONE, {0}, FALSE }
};
OptionInfoPtr VMWARECopyOptions(void)
{
OptionInfoPtr options;
if (!(options = malloc(sizeof(VMWAREOptions))))
return NULL;
memcpy(options, VMWAREOptions, sizeof(VMWAREOptions));
return options;
}
/*
* Also in vmwgfx_hosted.h, which we don't include.
*/
void *
vmwgfx_hosted_detect(void);
static Bool
VMwarePreinitStub(ScrnInfoPtr pScrn, int flags)
{
#if XSERVER_LIBPCIACCESS
struct pci_device *pciInfo;
#else
pciVideoPtr pciInfo;
#endif /* XSERVER_LIBPCIACCESS */
EntityInfoPtr pEnt;
pScrn->PreInit = pScrn->driverPrivate;
#ifdef BUILD_VMWGFX
pScrn->driverPrivate = NULL;
/*
* Try vmwgfx path.
*/
if ((*pScrn->PreInit)(pScrn, flags))
return TRUE;
/*
* Can't run legacy hosted
*/
if (vmwgfx_hosted_detect())
return FALSE;
#else
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"Driver was compiled without KMS- and 3D support.\n");
#endif /* defined(BUILD_VMWGFX) */
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"Disabling 3D support.\n");
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"Disabling Render Acceleration.\n");
xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
"Disabling RandR12+ support.\n");
pScrn->driverPrivate = NULL;
vmwlegacy_hookup(pScrn);
pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
pciInfo = xf86GetPciInfoForEntity(pEnt->index);
if (pciInfo == NULL)
return FALSE;
pScrn->chipset = xstrdup(xf86TokenToString(VMWAREChipsets,
DEVICE_ID(pciInfo)));
if (pScrn->chipset == NULL)
return FALSE;
return (*pScrn->PreInit)(pScrn, flags);
};
#if XSERVER_LIBPCIACCESS
static Bool
VMwarePciProbe (DriverPtr drv,
int entity_num,
struct pci_device *device,
intptr_t match_data)
{
ScrnInfoPtr scrn = NULL;
scrn = xf86ConfigPciEntity(scrn, 0, entity_num, VMWAREPciChipsets,
NULL, NULL, NULL, NULL, NULL);
if (scrn != NULL) {
scrn->driverVersion = VMWARE_DRIVER_VERSION;
scrn->driverName = vmware_driver_name;
scrn->name = vmware_name;
scrn->Probe = NULL;
}
switch (DEVICE_ID(device)) {
case PCI_DEVICE_ID_VMWARE_SVGA2:
case PCI_DEVICE_ID_VMWARE_SVGA:
xf86MsgVerb(X_INFO, 4, "VMwarePciProbe: Valid device\n");
#ifdef BUILD_VMWGFX
vmwgfx_hookup(scrn);
#else
vmwlegacy_hookup(scrn);
#endif /* defined(BUILD_VMWGFX) */
scrn->driverPrivate = scrn->PreInit;
scrn->PreInit = VMwarePreinitStub;
break;
default:
xf86MsgVerb(X_INFO, 4, "VMwarePciProbe: Unknown device\n");
}
return scrn != NULL;
}
#else
/*
*----------------------------------------------------------------------
*
* RewriteTagString --
*
* Rewrites the given string, removing the $Name$, and
* replacing it with the contents. The output string must
* have enough room, or else.
*
* Results:
*
* Output string updated.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static void
RewriteTagString(const char *istr, char *ostr, int osize)
{
int chr;
Bool inTag = FALSE;
char *op = ostr;
do {
chr = *istr++;
if (chr == '$') {
if (inTag) {
inTag = FALSE;
for (; op > ostr && op[-1] == ' '; op--) {
}
continue;
}
if (strncmp(istr, "Name:", 5) == 0) {
istr += 5;
istr += strspn(istr, " ");
inTag = TRUE;
continue;
}
}
*op++ = chr;
} while (chr);
}
static Bool
VMWAREProbe(DriverPtr drv, int flags)
{
int numDevSections, numUsed;
GDevPtr *devSections;
int *usedChips;
int i;
Bool foundScreen = FALSE;
char buildString[sizeof(VMWAREBuildStr)];
RewriteTagString(VMWAREBuildStr, buildString, sizeof(VMWAREBuildStr));
xf86MsgVerb(X_PROBED, 4, "%s", buildString);
numDevSections = xf86MatchDevice(VMWARE_DRIVER_NAME, &devSections);
if (numDevSections <= 0) {
#ifdef DEBUG
xf86MsgVerb(X_ERROR, 0, "No vmware driver section\n");
#endif
return FALSE;
}
if (xf86GetPciVideoInfo()) {
VmwareLog(("Some PCI Video Info Exists\n"));
numUsed = xf86MatchPciInstances(VMWARE_NAME, PCI_VENDOR_ID_VMWARE,
VMWAREChipsets, VMWAREPciChipsets, devSections,
numDevSections, drv, &usedChips);
free(devSections);
if (numUsed <= 0)
return FALSE;
if (flags & PROBE_DETECT)
foundScreen = TRUE;
else
for (i = 0; i < numUsed; i++) {
ScrnInfoPtr pScrn = NULL;
VmwareLog(("Even some VMware SVGA PCI instances exists\n"));
pScrn = xf86ConfigPciEntity(pScrn, flags, usedChips[i],
VMWAREPciChipsets, NULL, NULL, NULL,
NULL, NULL);
if (pScrn) {
VmwareLog(("And even configuration suceeded\n"));
pScrn->driverVersion = VMWARE_DRIVER_VERSION;
pScrn->driverName = VMWARE_DRIVER_NAME;
pScrn->name = VMWARE_NAME;
pScrn->Probe = VMWAREProbe;
#ifdef BUILD_VMWGFX
vmwgfx_hookup(pScrn);
#else
vmwlegacy_hookup(pScrn);
#endif /* defined(BUILD_VMWGFX) */
pScrn->driverPrivate = pScrn->PreInit;
pScrn->PreInit = VMwarePreinitStub;
foundScreen = TRUE;
}
}
free(usedChips);
}
return foundScreen;
}
#endif
#ifdef XSERVER_PLATFORM_BUS
static Bool
VMwarePlatformProbe(DriverPtr drv, int entity, int flags,
struct xf86_platform_device *dev, intptr_t match_data)
{
ScrnInfoPtr pScrn;
int scrnFlag = 0;
if (!dev->pdev)
return FALSE;
if (flags & PLATFORM_PROBE_GPU_SCREEN)
scrnFlag = XF86_ALLOCATE_GPU_SCREEN;
pScrn = xf86AllocateScreen(drv, scrnFlag);
if (!pScrn)
return FALSE;
if (xf86IsEntitySharable(entity))
xf86SetEntityShared(entity);
xf86AddEntityToScreen(pScrn, entity);
pScrn->driverVersion = VMWARE_DRIVER_VERSION;
pScrn->driverName = VMWARE_DRIVER_NAME;
pScrn->name = VMWARE_NAME;
pScrn->Probe = NULL;
#ifdef BUILD_VMWGFX
vmwgfx_hookup(pScrn);
#else
vmwlegacy_hookup(pScrn);
#endif
pScrn->driverPrivate = pScrn->PreInit;
pScrn->PreInit = VMwarePreinitStub;
return TRUE;
}
#endif
static void
VMWAREIdentify(int flags)
{
xf86PrintChipsets(VMWARE_NAME, "driver for VMware SVGA", VMWAREChipsets);
}
static const OptionInfoRec *
VMWAREAvailableOptions(int chipid, int busid)
{
return VMWAREOptions;
}
#if VMWARE_DRIVER_FUNC
static Bool
VMWareDriverFunc(ScrnInfoPtr pScrn,
xorgDriverFuncOp op,
pointer data)
{
uint32_t *flag;
xorgRRModeMM *modemm;
switch (op) {
case GET_REQUIRED_HW_INTERFACES:
flag = (uint32_t *)data;
if (flag) {
#ifdef BUILD_VMWGFX
vmwgfx_modify_flags(flag);
#else
*flag = HW_IO | HW_MMIO;
#endif
}
return TRUE;
case RR_GET_MODE_MM:
modemm = (xorgRRModeMM *)data;
/*
* Because changing the resolution of the guest is usually changing the size
* of a window on the host desktop, the real physical DPI will not change. To
* keep the guest in sync, we scale the 'physical' screen dimensions to
* keep the DPI constant.
*/
if (modemm && modemm->mode) {
modemm->mmWidth = (modemm->mode->HDisplay * VMWARE_INCHTOMM +
pScrn->xDpi / 2) / pScrn->xDpi;
modemm->mmHeight = (modemm->mode->VDisplay * VMWARE_INCHTOMM +
pScrn->yDpi / 2) / pScrn->yDpi;
}
return TRUE;
#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 18
case SUPPORTS_SERVER_FDS:
return TRUE;
#endif
default:
return FALSE;
}
}
#endif
_X_EXPORT DriverRec vmware = {
VMWARE_DRIVER_VERSION,
vmware_driver_name,
VMWAREIdentify,
#if XSERVER_LIBPCIACCESS
NULL,
#else
VMWAREProbe,
#endif
VMWAREAvailableOptions,
NULL,
0,
#if VMWARE_DRIVER_FUNC
VMWareDriverFunc,
#endif
#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 4
#if XSERVER_LIBPCIACCESS
VMwareDeviceMatch,
VMwarePciProbe,
#else
NULL,
NULL,
#endif
#endif
#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 13
#ifdef XSERVER_PLATFORM_BUS
VMwarePlatformProbe,
#else
NULL,
#endif
#endif
};
#ifdef XFree86LOADER
static MODULESETUPPROTO(vmwareSetup);
_X_EXPORT XF86ModuleData vmwareModuleData = {
&vmwareVersRec,
vmwareSetup,
NULL
};
static pointer
vmwareSetup(pointer module, pointer opts, int *errmaj, int *errmin)
{
static Bool setupDone = FALSE;
if (!setupDone) {
setupDone = TRUE;
xf86AddDriver(&vmware, module, VMWARE_DRIVER_FUNC);
VMWARERefSymLists();
return (pointer)1;
}
if (errmaj) {
*errmaj = LDR_ONCEONLY;
}
return NULL;
}
#endif /* XFree86LOADER */
|