1 | /* $Id: vboxvideo.c 38207 2011-07-27 21:56:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * Linux Additions X11 graphics driver
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | * --------------------------------------------------------------------
|
---|
18 | *
|
---|
19 | * This code is based on:
|
---|
20 | *
|
---|
21 | * X11 VESA driver
|
---|
22 | *
|
---|
23 | * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
|
---|
24 | *
|
---|
25 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
26 | * copy of this software and associated documentation files (the "Software"),
|
---|
27 | * to deal in the Software without restriction, including without limitation
|
---|
28 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
29 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
30 | * Software is furnished to do so, subject to the following conditions:
|
---|
31 | *
|
---|
32 | * The above copyright notice and this permission notice shall be included in
|
---|
33 | * all copies or substantial portions of the Software.
|
---|
34 | *
|
---|
35 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
36 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
37 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
38 | * CONECTIVA LINUX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
---|
39 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
---|
40 | * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
---|
41 | * SOFTWARE.
|
---|
42 | *
|
---|
43 | * Except as contained in this notice, the name of Conectiva Linux shall
|
---|
44 | * not be used in advertising or otherwise to promote the sale, use or other
|
---|
45 | * dealings in this Software without prior written authorization from
|
---|
46 | * Conectiva Linux.
|
---|
47 | *
|
---|
48 | * Authors: Paulo César Pereira de Andrade <[email protected]>
|
---|
49 | */
|
---|
50 |
|
---|
51 | #ifdef XORG_7X
|
---|
52 | # include "xorg-server.h"
|
---|
53 | # include <string.h>
|
---|
54 | #endif
|
---|
55 | #include "vboxvideo.h"
|
---|
56 | #include <iprt/asm-math.h>
|
---|
57 | #include "version-generated.h"
|
---|
58 | #include "product-generated.h"
|
---|
59 | #include <xf86.h>
|
---|
60 | #include <misc.h>
|
---|
61 |
|
---|
62 | /* All drivers initialising the SW cursor need this */
|
---|
63 | #include "mipointer.h"
|
---|
64 |
|
---|
65 | /* Colormap handling */
|
---|
66 | #include "micmap.h"
|
---|
67 | #include "xf86cmap.h"
|
---|
68 |
|
---|
69 | /* DPMS */
|
---|
70 | /* #define DPMS_SERVER
|
---|
71 | #include "extensions/dpms.h" */
|
---|
72 |
|
---|
73 | /* VGA hardware functions for setting and restoring text mode */
|
---|
74 | #include "vgaHW.h"
|
---|
75 |
|
---|
76 | #ifdef VBOXVIDEO_13
|
---|
77 | /* X.org 1.3+ mode setting */
|
---|
78 | # define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */
|
---|
79 | # include "xf86Crtc.h"
|
---|
80 | # include "xf86Modes.h"
|
---|
81 | # include <X11/Xatom.h>
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | /* Mandatory functions */
|
---|
85 |
|
---|
86 | static const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid);
|
---|
87 | static void VBOXIdentify(int flags);
|
---|
88 | #ifndef PCIACCESS
|
---|
89 | static Bool VBOXProbe(DriverPtr drv, int flags);
|
---|
90 | #else
|
---|
91 | static Bool VBOXPciProbe(DriverPtr drv, int entity_num,
|
---|
92 | struct pci_device *dev, intptr_t match_data);
|
---|
93 | #endif
|
---|
94 | static Bool VBOXPreInit(ScrnInfoPtr pScrn, int flags);
|
---|
95 | static Bool VBOXScreenInit(int Index, ScreenPtr pScreen, int argc,
|
---|
96 | char **argv);
|
---|
97 | static Bool VBOXEnterVT(int scrnIndex, int flags);
|
---|
98 | static void VBOXLeaveVT(int scrnIndex, int flags);
|
---|
99 | static Bool VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen);
|
---|
100 | static Bool VBOXSaveScreen(ScreenPtr pScreen, int mode);
|
---|
101 | static Bool VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags);
|
---|
102 | static void VBOXAdjustFrame(int scrnIndex, int x, int y, int flags);
|
---|
103 | static void VBOXFreeScreen(int scrnIndex, int flags);
|
---|
104 | static void VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
|
---|
105 | int flags);
|
---|
106 |
|
---|
107 | /* locally used functions */
|
---|
108 | static Bool VBOXMapVidMem(ScrnInfoPtr pScrn);
|
---|
109 | static void VBOXUnmapVidMem(ScrnInfoPtr pScrn);
|
---|
110 | static void VBOXSaveMode(ScrnInfoPtr pScrn);
|
---|
111 | static void VBOXRestoreMode(ScrnInfoPtr pScrn);
|
---|
112 |
|
---|
113 | enum GenericTypes
|
---|
114 | {
|
---|
115 | CHIP_VBOX_GENERIC
|
---|
116 | };
|
---|
117 |
|
---|
118 | #ifdef PCIACCESS
|
---|
119 | static const struct pci_id_match vbox_device_match[] = {
|
---|
120 | {
|
---|
121 | VBOX_VENDORID, VBOX_DEVICEID, PCI_MATCH_ANY, PCI_MATCH_ANY,
|
---|
122 | 0, 0, 0
|
---|
123 | },
|
---|
124 |
|
---|
125 | { 0, 0, 0 },
|
---|
126 | };
|
---|
127 | #endif
|
---|
128 |
|
---|
129 | /* Supported chipsets */
|
---|
130 | static SymTabRec VBOXChipsets[] =
|
---|
131 | {
|
---|
132 | {VBOX_DEVICEID, "vbox"},
|
---|
133 | {-1, NULL}
|
---|
134 | };
|
---|
135 |
|
---|
136 | static PciChipsets VBOXPCIchipsets[] = {
|
---|
137 | { VBOX_DEVICEID, VBOX_DEVICEID, RES_SHARED_VGA },
|
---|
138 | { -1, -1, RES_UNDEFINED },
|
---|
139 | };
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * This contains the functions needed by the server after loading the
|
---|
143 | * driver module. It must be supplied, and gets added the driver list by
|
---|
144 | * the Module Setup function in the dynamic case. In the static case a
|
---|
145 | * reference to this is compiled in, and this requires that the name of
|
---|
146 | * this DriverRec be an upper-case version of the driver name.
|
---|
147 | */
|
---|
148 |
|
---|
149 | #ifdef XORG_7X
|
---|
150 | _X_EXPORT
|
---|
151 | #endif
|
---|
152 | DriverRec VBOXVIDEO = {
|
---|
153 | VBOX_VERSION,
|
---|
154 | VBOX_DRIVER_NAME,
|
---|
155 | VBOXIdentify,
|
---|
156 | #ifdef PCIACCESS
|
---|
157 | NULL,
|
---|
158 | #else
|
---|
159 | VBOXProbe,
|
---|
160 | #endif
|
---|
161 | VBOXAvailableOptions,
|
---|
162 | NULL,
|
---|
163 | 0,
|
---|
164 | #ifdef XORG_7X
|
---|
165 | NULL,
|
---|
166 | #endif
|
---|
167 | #ifdef PCIACCESS
|
---|
168 | vbox_device_match,
|
---|
169 | VBOXPciProbe
|
---|
170 | #endif
|
---|
171 | };
|
---|
172 |
|
---|
173 | /* No options for now */
|
---|
174 | static const OptionInfoRec VBOXOptions[] = {
|
---|
175 | { -1, NULL, OPTV_NONE, {0}, FALSE }
|
---|
176 | };
|
---|
177 |
|
---|
178 | #ifndef XORG_7X
|
---|
179 | /*
|
---|
180 | * List of symbols from other modules that this module references. This
|
---|
181 | * list is used to tell the loader that it is OK for symbols here to be
|
---|
182 | * unresolved providing that it hasn't been told that they haven't been
|
---|
183 | * told that they are essential via a call to xf86LoaderReqSymbols() or
|
---|
184 | * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
|
---|
185 | * unresolved symbols that are not required.
|
---|
186 | */
|
---|
187 | static const char *fbSymbols[] = {
|
---|
188 | "fbPictureInit",
|
---|
189 | "fbScreenInit",
|
---|
190 | NULL
|
---|
191 | };
|
---|
192 |
|
---|
193 | static const char *shadowfbSymbols[] = {
|
---|
194 | "ShadowFBInit2",
|
---|
195 | NULL
|
---|
196 | };
|
---|
197 |
|
---|
198 | static const char *ramdacSymbols[] = {
|
---|
199 | "xf86InitCursor",
|
---|
200 | "xf86CreateCursorInfoRec",
|
---|
201 | NULL
|
---|
202 | };
|
---|
203 |
|
---|
204 | static const char *vgahwSymbols[] = {
|
---|
205 | "vgaHWFreeHWRec",
|
---|
206 | "vgaHWGetHWRec",
|
---|
207 | "vgaHWGetIOBase",
|
---|
208 | "vgaHWGetIndex",
|
---|
209 | "vgaHWRestore",
|
---|
210 | "vgaHWSave",
|
---|
211 | NULL
|
---|
212 | };
|
---|
213 | #endif /* !XORG_7X */
|
---|
214 |
|
---|
215 | #ifdef VBOXVIDEO_13
|
---|
216 | /* X.org 1.3+ mode-setting support ******************************************/
|
---|
217 |
|
---|
218 | /* For descriptions of these functions and structures, see
|
---|
219 | hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the
|
---|
220 | X.Org source tree. */
|
---|
221 |
|
---|
222 | static const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
|
---|
223 | VBOXAdjustScreenPixmap
|
---|
224 | };
|
---|
225 |
|
---|
226 | static void
|
---|
227 | vbox_crtc_dpms(xf86CrtcPtr crtc, int mode)
|
---|
228 | {
|
---|
229 | VBOXPtr pVBox = VBOXGetRec(crtc->scrn);
|
---|
230 | unsigned cDisplay = (uintptr_t)crtc->driver_private;
|
---|
231 | TRACE_LOG("cDisplay=%u, mode=%i\n", cDisplay, mode);
|
---|
232 | pVBox->afDisabled[cDisplay] = (mode != DPMSModeOn);
|
---|
233 | if ( pVBox->aScreenLocation[cDisplay].cx
|
---|
234 | && pVBox->aScreenLocation[cDisplay].cy)
|
---|
235 | VBOXSetMode(crtc->scrn, cDisplay,
|
---|
236 | pVBox->aScreenLocation[cDisplay].cx,
|
---|
237 | pVBox->aScreenLocation[cDisplay].cy,
|
---|
238 | pVBox->aScreenLocation[cDisplay].x,
|
---|
239 | pVBox->aScreenLocation[cDisplay].y);
|
---|
240 | }
|
---|
241 |
|
---|
242 | static Bool
|
---|
243 | vbox_crtc_lock (xf86CrtcPtr crtc)
|
---|
244 | { (void) crtc; return FALSE; }
|
---|
245 |
|
---|
246 | static Bool
|
---|
247 | vbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
248 | DisplayModePtr adjusted_mode)
|
---|
249 | { (void) crtc; (void) mode; (void) adjusted_mode; return TRUE; }
|
---|
250 |
|
---|
251 | static void
|
---|
252 | vbox_crtc_stub (xf86CrtcPtr crtc)
|
---|
253 | { (void) crtc; }
|
---|
254 |
|
---|
255 | static void
|
---|
256 | vbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
257 | DisplayModePtr adjusted_mode, int x, int y)
|
---|
258 | {
|
---|
259 | (void) mode;
|
---|
260 | VBOXPtr pVBox = VBOXGetRec(crtc->scrn);
|
---|
261 | unsigned cDisplay = (uintptr_t)crtc->driver_private;
|
---|
262 |
|
---|
263 | TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name,
|
---|
264 | adjusted_mode->HDisplay, adjusted_mode->VDisplay, x, y);
|
---|
265 | pVBox->afDisabled[cDisplay] = false;
|
---|
266 | VBOXSetMode(crtc->scrn, cDisplay, adjusted_mode->HDisplay,
|
---|
267 | adjusted_mode->VDisplay, x, y);
|
---|
268 | /* Don't remember any modes set while we are seamless, as they are
|
---|
269 | * just temporary. */
|
---|
270 | if (!vboxGuestIsSeamless(crtc->scrn))
|
---|
271 | vboxSaveVideoMode(crtc->scrn, adjusted_mode->HDisplay,
|
---|
272 | adjusted_mode->VDisplay, crtc->scrn->bitsPerPixel);
|
---|
273 | }
|
---|
274 |
|
---|
275 | static void
|
---|
276 | vbox_crtc_gamma_set (xf86CrtcPtr crtc, CARD16 *red,
|
---|
277 | CARD16 *green, CARD16 *blue, int size)
|
---|
278 | { (void) crtc; (void) red; (void) green; (void) blue; (void) size; }
|
---|
279 |
|
---|
280 | static void *
|
---|
281 | vbox_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
|
---|
282 | { (void) crtc; (void) width; (void) height; return NULL; }
|
---|
283 |
|
---|
284 | static const xf86CrtcFuncsRec VBOXCrtcFuncs = {
|
---|
285 | .dpms = vbox_crtc_dpms,
|
---|
286 | .save = NULL, /* These two are never called by the server. */
|
---|
287 | .restore = NULL,
|
---|
288 | .lock = vbox_crtc_lock,
|
---|
289 | .unlock = NULL, /* This will not be invoked if lock returns FALSE. */
|
---|
290 | .mode_fixup = vbox_crtc_mode_fixup,
|
---|
291 | .prepare = vbox_crtc_stub,
|
---|
292 | .mode_set = vbox_crtc_mode_set,
|
---|
293 | .commit = vbox_crtc_stub,
|
---|
294 | .gamma_set = vbox_crtc_gamma_set,
|
---|
295 | .shadow_allocate = vbox_crtc_shadow_allocate,
|
---|
296 | .shadow_create = NULL, /* These two should not be invoked if allocate
|
---|
297 | returns NULL. */
|
---|
298 | .shadow_destroy = NULL,
|
---|
299 | .set_cursor_colors = NULL, /* We are still using the old cursor API. */
|
---|
300 | .set_cursor_position = NULL,
|
---|
301 | .show_cursor = NULL,
|
---|
302 | .hide_cursor = NULL,
|
---|
303 | .load_cursor_argb = NULL,
|
---|
304 | .destroy = vbox_crtc_stub
|
---|
305 | };
|
---|
306 |
|
---|
307 | static void
|
---|
308 | vbox_output_stub (xf86OutputPtr output)
|
---|
309 | { (void) output; }
|
---|
310 |
|
---|
311 | static void
|
---|
312 | vbox_output_dpms (xf86OutputPtr output, int mode)
|
---|
313 | { (void) output; (void) mode; }
|
---|
314 |
|
---|
315 | static int
|
---|
316 | vbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode)
|
---|
317 | {
|
---|
318 | ScrnInfoPtr pScrn = output->scrn;
|
---|
319 | int rc = MODE_OK;
|
---|
320 | TRACE_LOG("HDisplay=%d, VDisplay=%d\n", mode->HDisplay, mode->VDisplay);
|
---|
321 | /* We always like modes specified by the user in the configuration
|
---|
322 | * file and modes requested by the host, as doing otherwise is likely to
|
---|
323 | * annoy people. */
|
---|
324 | if ( !(mode->type & M_T_USERDEF)
|
---|
325 | && !(mode->type & M_T_PREFERRED)
|
---|
326 | && vbox_device_available(VBOXGetRec(pScrn))
|
---|
327 | && !vboxHostLikesVideoMode(pScrn, mode->HDisplay, mode->VDisplay,
|
---|
328 | pScrn->bitsPerPixel)
|
---|
329 | )
|
---|
330 | rc = MODE_BAD;
|
---|
331 | TRACE_LOG("returning %s\n", MODE_OK == rc ? "MODE_OK" : "MODE_BAD");
|
---|
332 | return rc;
|
---|
333 | }
|
---|
334 |
|
---|
335 | static Bool
|
---|
336 | vbox_output_mode_fixup (xf86OutputPtr output, DisplayModePtr mode,
|
---|
337 | DisplayModePtr adjusted_mode)
|
---|
338 | { (void) output; (void) mode; (void) adjusted_mode; return TRUE; }
|
---|
339 |
|
---|
340 | static void
|
---|
341 | vbox_output_mode_set (xf86OutputPtr output, DisplayModePtr mode,
|
---|
342 | DisplayModePtr adjusted_mode)
|
---|
343 | { (void) output; (void) mode; (void) adjusted_mode; }
|
---|
344 |
|
---|
345 | /* A virtual monitor is always connected. */
|
---|
346 | static xf86OutputStatus
|
---|
347 | vbox_output_detect (xf86OutputPtr output)
|
---|
348 | {
|
---|
349 | (void) output;
|
---|
350 | return XF86OutputStatusConnected;
|
---|
351 | }
|
---|
352 |
|
---|
353 | static DisplayModePtr
|
---|
354 | vbox_output_add_mode (VBOXPtr pVBox, DisplayModePtr *pModes,
|
---|
355 | const char *pszName, int x, int y,
|
---|
356 | Bool isPreferred, Bool isUserDef)
|
---|
357 | {
|
---|
358 | TRACE_LOG("pszName=%s, x=%d, y=%d\n", pszName, x, y);
|
---|
359 | DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec));
|
---|
360 |
|
---|
361 | pMode->status = MODE_OK;
|
---|
362 | /* We don't ask the host whether it likes user defined modes,
|
---|
363 | * as we assume that the user really wanted that mode. */
|
---|
364 | pMode->type = isUserDef ? M_T_USERDEF : M_T_BUILTIN;
|
---|
365 | if (isPreferred)
|
---|
366 | pMode->type |= M_T_PREFERRED;
|
---|
367 | /* Older versions of VBox only support screen widths which are a multiple
|
---|
368 | * of 8 */
|
---|
369 | if (pVBox->fAnyX)
|
---|
370 | pMode->HDisplay = x;
|
---|
371 | else
|
---|
372 | pMode->HDisplay = x & ~7;
|
---|
373 | pMode->HSyncStart = pMode->HDisplay + 2;
|
---|
374 | pMode->HSyncEnd = pMode->HDisplay + 4;
|
---|
375 | pMode->HTotal = pMode->HDisplay + 6;
|
---|
376 | pMode->VDisplay = y;
|
---|
377 | pMode->VSyncStart = pMode->VDisplay + 2;
|
---|
378 | pMode->VSyncEnd = pMode->VDisplay + 4;
|
---|
379 | pMode->VTotal = pMode->VDisplay + 6;
|
---|
380 | pMode->Clock = pMode->HTotal * pMode->VTotal * 60 / 1000; /* kHz */
|
---|
381 | if (NULL == pszName) {
|
---|
382 | xf86SetModeDefaultName(pMode);
|
---|
383 | } else {
|
---|
384 | pMode->name = xnfstrdup(pszName);
|
---|
385 | }
|
---|
386 | *pModes = xf86ModesAdd(*pModes, pMode);
|
---|
387 | return pMode;
|
---|
388 | }
|
---|
389 |
|
---|
390 | static DisplayModePtr
|
---|
391 | vbox_output_get_modes (xf86OutputPtr output)
|
---|
392 | {
|
---|
393 | unsigned i, cIndex = 0;
|
---|
394 | DisplayModePtr pModes = NULL, pMode;
|
---|
395 | ScrnInfoPtr pScrn = output->scrn;
|
---|
396 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
397 |
|
---|
398 | TRACE_ENTRY();
|
---|
399 | uint32_t x, y, bpp, iScreen;
|
---|
400 | iScreen = (uintptr_t)output->driver_private;
|
---|
401 | vboxGetPreferredMode(pScrn, iScreen, &x, &y, &bpp);
|
---|
402 | pMode = vbox_output_add_mode(pVBox, &pModes, NULL, x, y, TRUE, FALSE);
|
---|
403 | VBOXEDIDSet(output, pMode);
|
---|
404 | /* Add standard modes supported by the host */
|
---|
405 | for ( ; ; )
|
---|
406 | {
|
---|
407 | cIndex = vboxNextStandardMode(pScrn, cIndex, &x, &y, NULL);
|
---|
408 | if (cIndex == 0)
|
---|
409 | break;
|
---|
410 | vbox_output_add_mode(pVBox, &pModes, NULL, x, y, FALSE, FALSE);
|
---|
411 | }
|
---|
412 |
|
---|
413 | /* Also report any modes the user may have requested in the xorg.conf
|
---|
414 | * configuration file. */
|
---|
415 | for (i = 0; pScrn->display->modes[i] != NULL; i++)
|
---|
416 | {
|
---|
417 | if (2 == sscanf(pScrn->display->modes[i], "%ux%u", &x, &y))
|
---|
418 | vbox_output_add_mode(pVBox, &pModes, pScrn->display->modes[i], x, y,
|
---|
419 | FALSE, TRUE);
|
---|
420 | }
|
---|
421 | TRACE_EXIT();
|
---|
422 | return pModes;
|
---|
423 | }
|
---|
424 |
|
---|
425 | #ifdef RANDR_12_INTERFACE
|
---|
426 | static Atom
|
---|
427 | vboxAtomVBoxMode(void)
|
---|
428 | {
|
---|
429 | return MakeAtom("VBOX_MODE", sizeof("VBOX_MODE") - 1, TRUE);
|
---|
430 | }
|
---|
431 |
|
---|
432 | static Atom
|
---|
433 | vboxAtomEDID(void)
|
---|
434 | {
|
---|
435 | return MakeAtom("EDID", sizeof("EDID") - 1, TRUE);
|
---|
436 | }
|
---|
437 |
|
---|
438 | /** We use this for receiving information from clients for the purpose of
|
---|
439 | * dynamic resizing, and later possibly other things too.
|
---|
440 | */
|
---|
441 | static Bool
|
---|
442 | vbox_output_set_property(xf86OutputPtr output, Atom property,
|
---|
443 | RRPropertyValuePtr value)
|
---|
444 | {
|
---|
445 | ScrnInfoPtr pScrn = output->scrn;
|
---|
446 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
447 | TRACE_LOG("property=%d, value->type=%d, value->format=%d, value->size=%ld\n",
|
---|
448 | (int)property, (int)value->type, value->format, value->size);
|
---|
449 | if (property == vboxAtomVBoxMode())
|
---|
450 | {
|
---|
451 | uint32_t cDisplay = (uintptr_t)output->driver_private;
|
---|
452 | char sz[256] = { 0 };
|
---|
453 | int w, h;
|
---|
454 |
|
---|
455 | if ( value->type != XA_STRING
|
---|
456 | || (unsigned) value->size > (sizeof(sz) - 1))
|
---|
457 | return FALSE;
|
---|
458 | strncpy(sz, value->data, value->size);
|
---|
459 | TRACE_LOG("screen=%u, property value=%s\n", cDisplay, sz);
|
---|
460 | if (sscanf(sz, "%dx%d", &w, &h) != 2)
|
---|
461 | return FALSE;
|
---|
462 | pVBox->aPreferredSize[cDisplay].cx = w;
|
---|
463 | pVBox->aPreferredSize[cDisplay].cy = h;
|
---|
464 | return TRUE;
|
---|
465 | }
|
---|
466 | if (property == vboxAtomEDID())
|
---|
467 | return TRUE;
|
---|
468 | return FALSE;
|
---|
469 | }
|
---|
470 | #endif
|
---|
471 |
|
---|
472 | static const xf86OutputFuncsRec VBOXOutputFuncs = {
|
---|
473 | .create_resources = vbox_output_stub,
|
---|
474 | .dpms = vbox_output_dpms,
|
---|
475 | .save = NULL, /* These two are never called by the server. */
|
---|
476 | .restore = NULL,
|
---|
477 | .mode_valid = vbox_output_mode_valid,
|
---|
478 | .mode_fixup = vbox_output_mode_fixup,
|
---|
479 | .prepare = vbox_output_stub,
|
---|
480 | .commit = vbox_output_stub,
|
---|
481 | .mode_set = vbox_output_mode_set,
|
---|
482 | .detect = vbox_output_detect,
|
---|
483 | .get_modes = vbox_output_get_modes,
|
---|
484 | #ifdef RANDR_12_INTERFACE
|
---|
485 | .set_property = vbox_output_set_property,
|
---|
486 | #endif
|
---|
487 | .destroy = vbox_output_stub
|
---|
488 | };
|
---|
489 | #endif /* VBOXVIDEO_13 */
|
---|
490 |
|
---|
491 | #ifdef XFree86LOADER
|
---|
492 | /* Module loader interface */
|
---|
493 | static MODULESETUPPROTO(vboxSetup);
|
---|
494 |
|
---|
495 | static XF86ModuleVersionInfo vboxVersionRec =
|
---|
496 | {
|
---|
497 | VBOX_DRIVER_NAME,
|
---|
498 | VBOX_VENDOR,
|
---|
499 | MODINFOSTRING1,
|
---|
500 | MODINFOSTRING2,
|
---|
501 | #ifdef XORG_7X
|
---|
502 | XORG_VERSION_CURRENT,
|
---|
503 | #else
|
---|
504 | XF86_VERSION_CURRENT,
|
---|
505 | #endif
|
---|
506 | 1, /* Module major version. Xorg-specific */
|
---|
507 | 0, /* Module minor version. Xorg-specific */
|
---|
508 | 1, /* Module patchlevel. Xorg-specific */
|
---|
509 | ABI_CLASS_VIDEODRV, /* This is a video driver */
|
---|
510 | ABI_VIDEODRV_VERSION,
|
---|
511 | MOD_CLASS_VIDEODRV,
|
---|
512 | {0, 0, 0, 0}
|
---|
513 | };
|
---|
514 |
|
---|
515 | /*
|
---|
516 | * This data is accessed by the loader. The name must be the module name
|
---|
517 | * followed by "ModuleData".
|
---|
518 | */
|
---|
519 | #ifdef XORG_7X
|
---|
520 | _X_EXPORT
|
---|
521 | #endif
|
---|
522 | XF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL };
|
---|
523 |
|
---|
524 | static pointer
|
---|
525 | vboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
|
---|
526 | {
|
---|
527 | static Bool Initialised = FALSE;
|
---|
528 |
|
---|
529 | if (!Initialised)
|
---|
530 | {
|
---|
531 | Initialised = TRUE;
|
---|
532 | #ifdef PCIACCESS
|
---|
533 | xf86AddDriver(&VBOXVIDEO, Module, HaveDriverFuncs);
|
---|
534 | #else
|
---|
535 | xf86AddDriver(&VBOXVIDEO, Module, 0);
|
---|
536 | #endif
|
---|
537 | #ifndef XORG_7X
|
---|
538 | LoaderRefSymLists(fbSymbols,
|
---|
539 | shadowfbSymbols,
|
---|
540 | ramdacSymbols,
|
---|
541 | vgahwSymbols,
|
---|
542 | NULL);
|
---|
543 | #endif
|
---|
544 | xf86Msg(X_CONFIG, "Load address of symbol \"VBOXVIDEO\" is %p\n",
|
---|
545 | (void *)&VBOXVIDEO);
|
---|
546 | return (pointer)TRUE;
|
---|
547 | }
|
---|
548 |
|
---|
549 | if (ErrorMajor)
|
---|
550 | *ErrorMajor = LDR_ONCEONLY;
|
---|
551 | return (NULL);
|
---|
552 | }
|
---|
553 |
|
---|
554 | #endif /* XFree86Loader defined */
|
---|
555 |
|
---|
556 | static const OptionInfoRec *
|
---|
557 | VBOXAvailableOptions(int chipid, int busid)
|
---|
558 | {
|
---|
559 | return (VBOXOptions);
|
---|
560 | }
|
---|
561 |
|
---|
562 | static void
|
---|
563 | VBOXIdentify(int flags)
|
---|
564 | {
|
---|
565 | xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets);
|
---|
566 | }
|
---|
567 |
|
---|
568 | /*
|
---|
569 | * This function is called once, at the start of the first server generation to
|
---|
570 | * do a minimal probe for supported hardware.
|
---|
571 | */
|
---|
572 |
|
---|
573 | #ifdef PCIACCESS
|
---|
574 | static Bool
|
---|
575 | VBOXPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev,
|
---|
576 | intptr_t match_data)
|
---|
577 | {
|
---|
578 | ScrnInfoPtr pScrn;
|
---|
579 |
|
---|
580 | TRACE_ENTRY();
|
---|
581 | pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets,
|
---|
582 | NULL, NULL, NULL, NULL, NULL);
|
---|
583 | if (pScrn != NULL) {
|
---|
584 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
585 |
|
---|
586 | pScrn->driverVersion = VBOX_VERSION;
|
---|
587 | pScrn->driverName = VBOX_DRIVER_NAME;
|
---|
588 | pScrn->name = VBOX_NAME;
|
---|
589 | pScrn->Probe = NULL;
|
---|
590 | pScrn->PreInit = VBOXPreInit;
|
---|
591 | pScrn->ScreenInit = VBOXScreenInit;
|
---|
592 | pScrn->SwitchMode = VBOXSwitchMode;
|
---|
593 | pScrn->AdjustFrame = VBOXAdjustFrame;
|
---|
594 | pScrn->EnterVT = VBOXEnterVT;
|
---|
595 | pScrn->LeaveVT = VBOXLeaveVT;
|
---|
596 | pScrn->FreeScreen = VBOXFreeScreen;
|
---|
597 |
|
---|
598 | pVBox->pciInfo = dev;
|
---|
599 | }
|
---|
600 |
|
---|
601 | TRACE_LOG("returning %s\n", BOOL_STR(pScrn != NULL));
|
---|
602 | return (pScrn != NULL);
|
---|
603 | }
|
---|
604 | #endif
|
---|
605 |
|
---|
606 | #ifndef PCIACCESS
|
---|
607 | static Bool
|
---|
608 | VBOXProbe(DriverPtr drv, int flags)
|
---|
609 | {
|
---|
610 | Bool foundScreen = FALSE;
|
---|
611 | int numDevSections;
|
---|
612 | GDevPtr *devSections;
|
---|
613 |
|
---|
614 | /*
|
---|
615 | * Find the config file Device sections that match this
|
---|
616 | * driver, and return if there are none.
|
---|
617 | */
|
---|
618 | if ((numDevSections = xf86MatchDevice(VBOX_NAME,
|
---|
619 | &devSections)) <= 0)
|
---|
620 | return (FALSE);
|
---|
621 |
|
---|
622 | /* PCI BUS */
|
---|
623 | if (xf86GetPciVideoInfo()) {
|
---|
624 | int numUsed;
|
---|
625 | int *usedChips;
|
---|
626 | int i;
|
---|
627 | numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID,
|
---|
628 | VBOXChipsets, VBOXPCIchipsets,
|
---|
629 | devSections, numDevSections,
|
---|
630 | drv, &usedChips);
|
---|
631 | if (numUsed > 0) {
|
---|
632 | if (flags & PROBE_DETECT)
|
---|
633 | foundScreen = TRUE;
|
---|
634 | else {
|
---|
635 | for (i = 0; i < numUsed; i++) {
|
---|
636 | ScrnInfoPtr pScrn = NULL;
|
---|
637 | /* Allocate a ScrnInfoRec */
|
---|
638 | if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i],
|
---|
639 | VBOXPCIchipsets,NULL,
|
---|
640 | NULL,NULL,NULL,NULL))) {
|
---|
641 | pScrn->driverVersion = VBOX_VERSION;
|
---|
642 | pScrn->driverName = VBOX_DRIVER_NAME;
|
---|
643 | pScrn->name = VBOX_NAME;
|
---|
644 | pScrn->Probe = VBOXProbe;
|
---|
645 | pScrn->PreInit = VBOXPreInit;
|
---|
646 | pScrn->ScreenInit = VBOXScreenInit;
|
---|
647 | pScrn->SwitchMode = VBOXSwitchMode;
|
---|
648 | pScrn->AdjustFrame = VBOXAdjustFrame;
|
---|
649 | pScrn->EnterVT = VBOXEnterVT;
|
---|
650 | pScrn->LeaveVT = VBOXLeaveVT;
|
---|
651 | pScrn->FreeScreen = VBOXFreeScreen;
|
---|
652 | foundScreen = TRUE;
|
---|
653 | }
|
---|
654 | }
|
---|
655 | }
|
---|
656 | free(usedChips);
|
---|
657 | }
|
---|
658 | }
|
---|
659 |
|
---|
660 | free(devSections);
|
---|
661 |
|
---|
662 | return (foundScreen);
|
---|
663 | }
|
---|
664 | #endif
|
---|
665 |
|
---|
666 | /**
|
---|
667 | * This function hooks into the chain that is called when framebuffer access
|
---|
668 | * is allowed or disallowed by a call to EnableDisableFBAccess in the server.
|
---|
669 | * In other words, it observes when the server wishes access to the
|
---|
670 | * framebuffer to be enabled and when it should be disabled. We need to know
|
---|
671 | * this because we disable access ourselves during mode switches (presumably
|
---|
672 | * the server should do this but it doesn't) and want to know whether to
|
---|
673 | * restore it or not afterwards.
|
---|
674 | */
|
---|
675 | static void
|
---|
676 | vboxEnableDisableFBAccess(int scrnIndex, Bool enable)
|
---|
677 | {
|
---|
678 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
679 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
680 |
|
---|
681 | TRACE_LOG("enable=%s\n", enable ? "TRUE" : "FALSE");
|
---|
682 | pVBox->accessEnabled = enable;
|
---|
683 | pVBox->EnableDisableFBAccess(scrnIndex, enable);
|
---|
684 | TRACE_EXIT();
|
---|
685 | }
|
---|
686 |
|
---|
687 | /*
|
---|
688 | * QUOTE from the XFree86 DESIGN document:
|
---|
689 | *
|
---|
690 | * The purpose of this function is to find out all the information
|
---|
691 | * required to determine if the configuration is usable, and to initialise
|
---|
692 | * those parts of the ScrnInfoRec that can be set once at the beginning of
|
---|
693 | * the first server generation.
|
---|
694 | *
|
---|
695 | * (...)
|
---|
696 | *
|
---|
697 | * This includes probing for video memory, clocks, ramdac, and all other
|
---|
698 | * HW info that is needed. It includes determining the depth/bpp/visual
|
---|
699 | * and related info. It includes validating and determining the set of
|
---|
700 | * video modes that will be used (and anything that is required to
|
---|
701 | * determine that).
|
---|
702 | *
|
---|
703 | * This information should be determined in the least intrusive way
|
---|
704 | * possible. The state of the HW must remain unchanged by this function.
|
---|
705 | * Although video memory (including MMIO) may be mapped within this
|
---|
706 | * function, it must be unmapped before returning.
|
---|
707 | *
|
---|
708 | * END QUOTE
|
---|
709 | */
|
---|
710 |
|
---|
711 | static Bool
|
---|
712 | VBOXPreInit(ScrnInfoPtr pScrn, int flags)
|
---|
713 | {
|
---|
714 | VBOXPtr pVBox;
|
---|
715 | Gamma gzeros = {0.0, 0.0, 0.0};
|
---|
716 | rgb rzeros = {0, 0, 0};
|
---|
717 | unsigned DispiId;
|
---|
718 |
|
---|
719 | TRACE_ENTRY();
|
---|
720 | /* Are we really starting the server, or is this just a dummy run? */
|
---|
721 | if (flags & PROBE_DETECT)
|
---|
722 | return (FALSE);
|
---|
723 |
|
---|
724 | xf86DrvMsg(pScrn->scrnIndex, X_INFO,
|
---|
725 | "VirtualBox guest additions video driver version "
|
---|
726 | VBOX_VERSION_STRING "\n");
|
---|
727 |
|
---|
728 | /* Get our private data from the ScrnInfoRec structure. */
|
---|
729 | pVBox = VBOXGetRec(pScrn);
|
---|
730 | if (!pVBox)
|
---|
731 | return FALSE;
|
---|
732 |
|
---|
733 | /* Initialise the guest library */
|
---|
734 | vbox_init(pScrn->scrnIndex, pVBox);
|
---|
735 |
|
---|
736 | /* Entity information seems to mean bus information. */
|
---|
737 | pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
|
---|
738 |
|
---|
739 | /* The ramdac module is needed for the hardware cursor. */
|
---|
740 | if (!xf86LoadSubModule(pScrn, "ramdac"))
|
---|
741 | return FALSE;
|
---|
742 |
|
---|
743 | /* The framebuffer module. */
|
---|
744 | if (!xf86LoadSubModule(pScrn, "fb"))
|
---|
745 | return (FALSE);
|
---|
746 |
|
---|
747 | if (!xf86LoadSubModule(pScrn, "shadowfb"))
|
---|
748 | return FALSE;
|
---|
749 |
|
---|
750 | if (!xf86LoadSubModule(pScrn, "vgahw"))
|
---|
751 | return FALSE;
|
---|
752 |
|
---|
753 | #ifdef VBOX_DRI
|
---|
754 | /* Load the dri module. */
|
---|
755 | if (!xf86LoadSubModule(pScrn, "dri"))
|
---|
756 | return FALSE;
|
---|
757 | #endif
|
---|
758 |
|
---|
759 | #ifndef PCIACCESS
|
---|
760 | if (pVBox->pEnt->location.type != BUS_PCI)
|
---|
761 | return FALSE;
|
---|
762 |
|
---|
763 | pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
|
---|
764 | pVBox->pciTag = pciTag(pVBox->pciInfo->bus,
|
---|
765 | pVBox->pciInfo->device,
|
---|
766 | pVBox->pciInfo->func);
|
---|
767 | #endif
|
---|
768 |
|
---|
769 | /* Set up our ScrnInfoRec structure to describe our virtual
|
---|
770 | capabilities to X. */
|
---|
771 |
|
---|
772 | pScrn->chipset = "vbox";
|
---|
773 | /** @note needed during colourmap initialisation */
|
---|
774 | pScrn->rgbBits = 8;
|
---|
775 |
|
---|
776 | /* Let's create a nice, capable virtual monitor. */
|
---|
777 | pScrn->monitor = pScrn->confScreen->monitor;
|
---|
778 | pScrn->monitor->DDC = NULL;
|
---|
779 | pScrn->monitor->nHsync = 1;
|
---|
780 | pScrn->monitor->hsync[0].lo = 1;
|
---|
781 | pScrn->monitor->hsync[0].hi = 10000;
|
---|
782 | pScrn->monitor->nVrefresh = 1;
|
---|
783 | pScrn->monitor->vrefresh[0].lo = 1;
|
---|
784 | pScrn->monitor->vrefresh[0].hi = 100;
|
---|
785 |
|
---|
786 | pScrn->progClock = TRUE;
|
---|
787 |
|
---|
788 | /* Using the PCI information caused problems with non-powers-of-two
|
---|
789 | sized video RAM configurations */
|
---|
790 | pVBox->cbFBMax = VBoxVideoGetVRAMSize();
|
---|
791 | pScrn->videoRam = pVBox->cbFBMax / 1024;
|
---|
792 |
|
---|
793 | /* Check if the chip restricts horizontal resolution or not. */
|
---|
794 | pVBox->fAnyX = VBoxVideoAnyWidthAllowed();
|
---|
795 |
|
---|
796 | /* Set up clock information that will support all modes we need. */
|
---|
797 | pScrn->clockRanges = xnfcalloc(sizeof(ClockRange), 1);
|
---|
798 | pScrn->clockRanges->minClock = 1000;
|
---|
799 | pScrn->clockRanges->maxClock = 1000000000;
|
---|
800 | pScrn->clockRanges->clockIndex = -1;
|
---|
801 | pScrn->clockRanges->ClockMulFactor = 1;
|
---|
802 | pScrn->clockRanges->ClockDivFactor = 1;
|
---|
803 |
|
---|
804 | /* Query the host for the preferred colour depth */
|
---|
805 | {
|
---|
806 | uint32_t cx = 0, cy = 0, cBits = 0;
|
---|
807 |
|
---|
808 | vboxGetPreferredMode(pScrn, 0, &cx, &cy, &cBits);
|
---|
809 | /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
|
---|
810 | if (cBits != 16)
|
---|
811 | cBits = 24;
|
---|
812 | if (!xf86SetDepthBpp(pScrn, cBits, 0, 0, Support32bppFb))
|
---|
813 | return FALSE;
|
---|
814 | vboxAddModes(pScrn, cx, cy);
|
---|
815 | }
|
---|
816 | if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
|
---|
817 | {
|
---|
818 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
819 | "The VBox additions only support 16 and 32bpp graphics modes\n");
|
---|
820 | return FALSE;
|
---|
821 | }
|
---|
822 | xf86PrintDepthBpp(pScrn);
|
---|
823 |
|
---|
824 | #ifdef VBOXVIDEO_13
|
---|
825 | /* Work around a bug in the original X server modesetting code, which
|
---|
826 | * took the first valid values set to these two as maxima over the
|
---|
827 | * server lifetime. */
|
---|
828 | pScrn->virtualX = 32000;
|
---|
829 | pScrn->virtualY = 32000;
|
---|
830 | #else
|
---|
831 | /* We don't validate with xf86ValidateModes and xf86PruneModes as we
|
---|
832 | * already know what we like and what we don't. */
|
---|
833 |
|
---|
834 | pScrn->currentMode = pScrn->modes;
|
---|
835 |
|
---|
836 | /* Set the right virtual resolution. */
|
---|
837 | pScrn->virtualX = pScrn->currentMode->HDisplay;
|
---|
838 | pScrn->virtualY = pScrn->currentMode->VDisplay;
|
---|
839 |
|
---|
840 | #endif /* !VBOXVIDEO_13 */
|
---|
841 |
|
---|
842 | /* Needed before we initialise DRI. */
|
---|
843 | pVBox->cbLine = vboxLineLength(pScrn, pScrn->virtualX);
|
---|
844 | pScrn->displayWidth = vboxDisplayPitch(pScrn, pVBox->cbLine);
|
---|
845 |
|
---|
846 | xf86PrintModes(pScrn);
|
---|
847 |
|
---|
848 | /* VGA hardware initialisation */
|
---|
849 | if (!vgaHWGetHWRec(pScrn))
|
---|
850 | return FALSE;
|
---|
851 | /* Must be called before any VGA registers are saved or restored */
|
---|
852 | vgaHWGetIOBase(VGAHWPTR(pScrn));
|
---|
853 |
|
---|
854 | /* Colour weight - we always call this, since we are always in
|
---|
855 | truecolour. */
|
---|
856 | if (!xf86SetWeight(pScrn, rzeros, rzeros))
|
---|
857 | return (FALSE);
|
---|
858 |
|
---|
859 | /* visual init */
|
---|
860 | if (!xf86SetDefaultVisual(pScrn, -1))
|
---|
861 | return (FALSE);
|
---|
862 |
|
---|
863 | xf86SetGamma(pScrn, gzeros);
|
---|
864 |
|
---|
865 | /* Set the DPI. Perhaps we should read this from the host? */
|
---|
866 | xf86SetDpi(pScrn, 96, 96);
|
---|
867 |
|
---|
868 | if (pScrn->memPhysBase == 0) {
|
---|
869 | #ifdef PCIACCESS
|
---|
870 | pScrn->memPhysBase = pVBox->pciInfo->regions[0].base_addr;
|
---|
871 | #else
|
---|
872 | pScrn->memPhysBase = pVBox->pciInfo->memBase[0];
|
---|
873 | #endif
|
---|
874 | pScrn->fbOffset = 0;
|
---|
875 | }
|
---|
876 |
|
---|
877 | TRACE_EXIT();
|
---|
878 | return (TRUE);
|
---|
879 | }
|
---|
880 |
|
---|
881 | /**
|
---|
882 | * Dummy function for setting the colour palette, which we actually never
|
---|
883 | * touch. However, the server still requires us to provide this.
|
---|
884 | */
|
---|
885 | static void
|
---|
886 | vboxLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
|
---|
887 | LOCO *colors, VisualPtr pVisual)
|
---|
888 | {
|
---|
889 | (void)pScrn; (void) numColors; (void) indices; (void) colors;
|
---|
890 | (void)pVisual;
|
---|
891 | }
|
---|
892 |
|
---|
893 | /*
|
---|
894 | * QUOTE from the XFree86 DESIGN document:
|
---|
895 | *
|
---|
896 | * This is called at the start of each server generation.
|
---|
897 | *
|
---|
898 | * (...)
|
---|
899 | *
|
---|
900 | * Decide which operations need to be placed under resource access
|
---|
901 | * control. (...) Map any video memory or other memory regions. (...)
|
---|
902 | * Save the video card state. (...) Initialise the initial video
|
---|
903 | * mode.
|
---|
904 | *
|
---|
905 | * End QUOTE.
|
---|
906 | */
|
---|
907 | static Bool
|
---|
908 | VBOXScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
|
---|
909 | {
|
---|
910 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
911 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
912 | VisualPtr visual;
|
---|
913 | unsigned flags;
|
---|
914 |
|
---|
915 | TRACE_ENTRY();
|
---|
916 |
|
---|
917 | if (!VBOXMapVidMem(pScrn))
|
---|
918 | return (FALSE);
|
---|
919 |
|
---|
920 | /* save current video state */
|
---|
921 | VBOXSaveMode(pScrn);
|
---|
922 |
|
---|
923 | /* mi layer - reset the visual list (?)*/
|
---|
924 | miClearVisualTypes();
|
---|
925 | if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
|
---|
926 | pScrn->rgbBits, TrueColor))
|
---|
927 | return (FALSE);
|
---|
928 | if (!miSetPixmapDepths())
|
---|
929 | return (FALSE);
|
---|
930 |
|
---|
931 | #ifdef VBOX_DRI
|
---|
932 | pVBox->useDRI = VBOXDRIScreenInit(scrnIndex, pScreen, pVBox);
|
---|
933 | #endif
|
---|
934 |
|
---|
935 | if (!fbScreenInit(pScreen, pVBox->base,
|
---|
936 | pScrn->virtualX, pScrn->virtualY,
|
---|
937 | pScrn->xDpi, pScrn->yDpi,
|
---|
938 | pScrn->displayWidth, pScrn->bitsPerPixel))
|
---|
939 | return (FALSE);
|
---|
940 |
|
---|
941 | /* Fixup RGB ordering */
|
---|
942 | /** @note the X server uses this even in true colour. */
|
---|
943 | visual = pScreen->visuals + pScreen->numVisuals;
|
---|
944 | while (--visual >= pScreen->visuals) {
|
---|
945 | if ((visual->class | DynamicClass) == DirectColor) {
|
---|
946 | visual->offsetRed = pScrn->offset.red;
|
---|
947 | visual->offsetGreen = pScrn->offset.green;
|
---|
948 | visual->offsetBlue = pScrn->offset.blue;
|
---|
949 | visual->redMask = pScrn->mask.red;
|
---|
950 | visual->greenMask = pScrn->mask.green;
|
---|
951 | visual->blueMask = pScrn->mask.blue;
|
---|
952 | }
|
---|
953 | }
|
---|
954 |
|
---|
955 | /* must be after RGB ordering fixed */
|
---|
956 | fbPictureInit(pScreen, 0, 0);
|
---|
957 |
|
---|
958 | xf86SetBlackWhitePixels(pScreen);
|
---|
959 |
|
---|
960 | /* We need to keep track of whether we are currently switched to a virtual
|
---|
961 | * terminal to know whether a mode set operation is currently safe to do.
|
---|
962 | */
|
---|
963 | pVBox->vtSwitch = FALSE;
|
---|
964 |
|
---|
965 | if (vbox_open (pScrn, pScreen, pVBox)) {
|
---|
966 | vboxEnableVbva(pScrn);
|
---|
967 | vboxEnableGraphicsCap(pVBox);
|
---|
968 | }
|
---|
969 |
|
---|
970 | #ifdef VBOXVIDEO_13
|
---|
971 | /* Initialise CRTC and output configuration for use with randr1.2. */
|
---|
972 | xf86CrtcConfigInit(pScrn, &VBOXCrtcConfigFuncs);
|
---|
973 |
|
---|
974 | {
|
---|
975 | uint32_t i;
|
---|
976 |
|
---|
977 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
978 | {
|
---|
979 | char szOutput[256];
|
---|
980 |
|
---|
981 | /* Setup our virtual CRTCs. */
|
---|
982 | pVBox->paCrtcs[i] = xf86CrtcCreate(pScrn, &VBOXCrtcFuncs);
|
---|
983 | pVBox->paCrtcs[i]->driver_private = (void *)(uintptr_t)i;
|
---|
984 |
|
---|
985 | /* Set up our virtual outputs. */
|
---|
986 | snprintf(szOutput, sizeof(szOutput), "VBOX%u", i);
|
---|
987 | pVBox->paOutputs[i] = xf86OutputCreate(pScrn, &VBOXOutputFuncs,
|
---|
988 | szOutput);
|
---|
989 |
|
---|
990 | /* We are not interested in the monitor section in the
|
---|
991 | * configuration file. */
|
---|
992 | xf86OutputUseScreenMonitor(pVBox->paOutputs[i], FALSE);
|
---|
993 | pVBox->paOutputs[i]->possible_crtcs = 1 << i;
|
---|
994 | pVBox->paOutputs[i]->possible_clones = 0;
|
---|
995 | pVBox->paOutputs[i]->driver_private = (void *)(uintptr_t)i;
|
---|
996 | TRACE_LOG("Created crtc (%p) and output %s (%p)\n",
|
---|
997 | (void *)pVBox->paCrtcs[i], szOutput,
|
---|
998 | (void *)pVBox->paOutputs[i]);
|
---|
999 | }
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 | /* Set a sane minimum and maximum mode size */
|
---|
1003 | xf86CrtcSetSizeRange(pScrn, 64, 64, 32000, 32000);
|
---|
1004 |
|
---|
1005 | /* Now create our initial CRTC/output configuration. */
|
---|
1006 | if (!xf86InitialConfiguration(pScrn, TRUE)) {
|
---|
1007 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n");
|
---|
1008 | return (FALSE);
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | /* Initialise randr 1.2 mode-setting functions and set first mode.
|
---|
1012 | * Note that the mode won't be usable until the server has resized the
|
---|
1013 | * framebuffer to something reasonable. */
|
---|
1014 | if (!xf86CrtcScreenInit(pScreen)) {
|
---|
1015 | return FALSE;
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | /* Create our VBOX_MODE display properties. */
|
---|
1019 | {
|
---|
1020 | uint32_t i;
|
---|
1021 |
|
---|
1022 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1023 | {
|
---|
1024 | char csz[] = "0x0";
|
---|
1025 | RRChangeOutputProperty(pVBox->paOutputs[i]->randr_output,
|
---|
1026 | vboxAtomVBoxMode(), XA_STRING, 8,
|
---|
1027 | PropModeReplace, sizeof(csz), csz, TRUE,
|
---|
1028 | FALSE);
|
---|
1029 |
|
---|
1030 | }
|
---|
1031 | }
|
---|
1032 |
|
---|
1033 | if (!xf86SetDesiredModes(pScrn)) {
|
---|
1034 | return FALSE;
|
---|
1035 | }
|
---|
1036 | #else /* !VBOXVIDEO_13 */
|
---|
1037 | /* set first video mode */
|
---|
1038 | if (!VBOXSetMode(pScrn, 0, pScrn->currentMode->HDisplay,
|
---|
1039 | pScrn->currentMode->VDisplay, pScrn->frameX0,
|
---|
1040 | pScrn->frameY0))
|
---|
1041 | return FALSE;
|
---|
1042 | /* And make sure that a non-current dynamic mode is at the front of the
|
---|
1043 | * list */
|
---|
1044 | vboxWriteHostModes(pScrn, pScrn->currentMode);
|
---|
1045 | #endif /* !VBOXVIDEO_13 */
|
---|
1046 |
|
---|
1047 | /* software cursor */
|
---|
1048 | miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
|
---|
1049 |
|
---|
1050 | /* colourmap code */
|
---|
1051 | if (!miCreateDefColormap(pScreen))
|
---|
1052 | return (FALSE);
|
---|
1053 |
|
---|
1054 | if(!xf86HandleColormaps(pScreen, 256, 8, vboxLoadPalette, NULL, 0))
|
---|
1055 | return (FALSE);
|
---|
1056 |
|
---|
1057 | /* Hook our observer function ito the chain which is called when
|
---|
1058 | * framebuffer access is enabled or disabled in the server, and
|
---|
1059 | * assume an initial state of enabled. */
|
---|
1060 | pVBox->accessEnabled = TRUE;
|
---|
1061 | pVBox->EnableDisableFBAccess = pScrn->EnableDisableFBAccess;
|
---|
1062 | pScrn->EnableDisableFBAccess = vboxEnableDisableFBAccess;
|
---|
1063 |
|
---|
1064 | pVBox->CloseScreen = pScreen->CloseScreen;
|
---|
1065 | pScreen->CloseScreen = VBOXCloseScreen;
|
---|
1066 | #ifdef VBOXVIDEO_13
|
---|
1067 | pScreen->SaveScreen = xf86SaveScreen;
|
---|
1068 | #else
|
---|
1069 | pScreen->SaveScreen = VBOXSaveScreen;
|
---|
1070 | #endif
|
---|
1071 |
|
---|
1072 | #ifdef VBOXVIDEO_13
|
---|
1073 | xf86DPMSInit(pScreen, xf86DPMSSet, 0);
|
---|
1074 | #else
|
---|
1075 | /* We probably do want to support power management - even if we just use
|
---|
1076 | a dummy function. */
|
---|
1077 | xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
|
---|
1078 | #endif
|
---|
1079 |
|
---|
1080 | /* Report any unused options (only for the first generation) */
|
---|
1081 | if (serverGeneration == 1)
|
---|
1082 | xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
|
---|
1083 |
|
---|
1084 | if (vbox_cursor_init(pScreen) != TRUE)
|
---|
1085 | xf86DrvMsg(scrnIndex, X_ERROR,
|
---|
1086 | "Unable to start the VirtualBox mouse pointer integration with the host system.\n");
|
---|
1087 |
|
---|
1088 | #ifdef VBOX_DRI
|
---|
1089 | if (pVBox->useDRI)
|
---|
1090 | pVBox->useDRI = VBOXDRIFinishScreenInit(pScreen);
|
---|
1091 | #endif
|
---|
1092 | return (TRUE);
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | static Bool
|
---|
1096 | VBOXEnterVT(int scrnIndex, int flags)
|
---|
1097 | {
|
---|
1098 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
1099 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1100 |
|
---|
1101 | TRACE_ENTRY();
|
---|
1102 | vboxClearVRAM(pScrn, 0, 0);
|
---|
1103 | if (pVBox->fHaveHGSMI)
|
---|
1104 | vboxEnableVbva(pScrn);
|
---|
1105 | pVBox->vtSwitch = FALSE;
|
---|
1106 | #ifdef VBOX_DRI
|
---|
1107 | if (pVBox->useDRI)
|
---|
1108 | DRIUnlock(screenInfo.screens[scrnIndex]);
|
---|
1109 | #endif
|
---|
1110 | #ifdef VBOXVIDEO_13
|
---|
1111 | if (!xf86SetDesiredModes(pScrn))
|
---|
1112 | return FALSE;
|
---|
1113 | #else
|
---|
1114 | if (!VBOXSetMode(pScrn, 0, pScrn->currentMode->HDisplay,
|
---|
1115 | pScrn->currentMode->VDisplay, pScrn->frameX0,
|
---|
1116 | pScrn->frameY0))
|
---|
1117 | return FALSE;
|
---|
1118 | #endif
|
---|
1119 | return TRUE;
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | static void
|
---|
1123 | VBOXLeaveVT(int scrnIndex, int flags)
|
---|
1124 | {
|
---|
1125 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
1126 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1127 |
|
---|
1128 | TRACE_ENTRY();
|
---|
1129 | pVBox->vtSwitch = TRUE;
|
---|
1130 | if (pVBox->fHaveHGSMI)
|
---|
1131 | vboxDisableVbva(pScrn);
|
---|
1132 | vboxClearVRAM(pScrn, 0, 0);
|
---|
1133 | VBOXRestoreMode(pScrn);
|
---|
1134 | vboxDisableGraphicsCap(pVBox);
|
---|
1135 | #ifdef VBOX_DRI
|
---|
1136 | if (pVBox->useDRI)
|
---|
1137 | DRILock(screenInfo.screens[scrnIndex], 0);
|
---|
1138 | #endif
|
---|
1139 | TRACE_EXIT();
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | static Bool
|
---|
1143 | VBOXCloseScreen(int scrnIndex, ScreenPtr pScreen)
|
---|
1144 | {
|
---|
1145 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
1146 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1147 |
|
---|
1148 | if (pVBox->fHaveHGSMI)
|
---|
1149 | vboxDisableVbva(pScrn);
|
---|
1150 | vboxDisableGraphicsCap(pVBox);
|
---|
1151 | vboxClearVRAM(pScrn, 0, 0);
|
---|
1152 | #ifdef VBOX_DRI
|
---|
1153 | if (pVBox->useDRI)
|
---|
1154 | VBOXDRICloseScreen(pScreen, pVBox);
|
---|
1155 | pVBox->useDRI = false;
|
---|
1156 | #endif
|
---|
1157 |
|
---|
1158 | if (pScrn->vtSema) {
|
---|
1159 | VBOXRestoreMode(xf86Screens[scrnIndex]);
|
---|
1160 | VBOXUnmapVidMem(pScrn);
|
---|
1161 | }
|
---|
1162 | pScrn->vtSema = FALSE;
|
---|
1163 |
|
---|
1164 | /* Do additional bits which are separate for historical reasons */
|
---|
1165 | vbox_close(pScrn, pVBox);
|
---|
1166 |
|
---|
1167 | /* Remove our observer functions from the X server call chains. */
|
---|
1168 | pScrn->EnableDisableFBAccess = pVBox->EnableDisableFBAccess;
|
---|
1169 | pScreen->CloseScreen = pVBox->CloseScreen;
|
---|
1170 | return pScreen->CloseScreen(scrnIndex, pScreen);
|
---|
1171 | }
|
---|
1172 |
|
---|
1173 | static Bool
|
---|
1174 | VBOXSwitchMode(int scrnIndex, DisplayModePtr pMode, int flags)
|
---|
1175 | {
|
---|
1176 | ScrnInfoPtr pScrn;
|
---|
1177 | VBOXPtr pVBox;
|
---|
1178 | Bool rc;
|
---|
1179 |
|
---|
1180 | TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
|
---|
1181 | pScrn = xf86Screens[scrnIndex]; /* Why does X have three ways of referring to the screen? */
|
---|
1182 | pVBox = VBOXGetRec(pScrn);
|
---|
1183 | /* We want to disable access to the framebuffer before switching mode.
|
---|
1184 | * After doing the switch, we allow access if it was allowed before. */
|
---|
1185 | if (pVBox->accessEnabled)
|
---|
1186 | pVBox->EnableDisableFBAccess(scrnIndex, FALSE);
|
---|
1187 | #ifdef VBOXVIDEO_13
|
---|
1188 | rc = xf86SetSingleMode(pScrn, pMode, 0);
|
---|
1189 | #else
|
---|
1190 | VBOXAdjustScreenPixmap(pScrn, pMode->HDisplay, pMode->VDisplay);
|
---|
1191 | rc = VBOXSetMode(pScrn, 0, pMode->HDisplay, pMode->VDisplay,
|
---|
1192 | pScrn->frameX0, pScrn->frameY0);
|
---|
1193 | if (rc)
|
---|
1194 | {
|
---|
1195 | vboxWriteHostModes(pScrn, pMode);
|
---|
1196 | xf86PrintModes(pScrn);
|
---|
1197 | }
|
---|
1198 | if (rc && !vboxGuestIsSeamless(pScrn))
|
---|
1199 | vboxSaveVideoMode(pScrn, pMode->HDisplay, pMode->VDisplay,
|
---|
1200 | pScrn->bitsPerPixel);
|
---|
1201 | #endif
|
---|
1202 | if (pVBox->accessEnabled)
|
---|
1203 | pVBox->EnableDisableFBAccess(scrnIndex, TRUE);
|
---|
1204 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1205 | return rc;
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | static void
|
---|
1209 | VBOXAdjustFrame(int scrnIndex, int x, int y, int flags)
|
---|
1210 | {
|
---|
1211 | VBOXPtr pVBox = VBOXGetRec(xf86Screens[scrnIndex]);
|
---|
1212 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
1213 |
|
---|
1214 | TRACE_ENTRY();
|
---|
1215 | /* Don't fiddle with the hardware if we are switched
|
---|
1216 | * to a virtual terminal. */
|
---|
1217 | VBOXSetMode(pScrn, 0, pVBox->aScreenLocation[0].cx,
|
---|
1218 | pVBox->aScreenLocation[0].cy, x, y);
|
---|
1219 | TRACE_EXIT();
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | static void
|
---|
1223 | VBOXFreeScreen(int scrnIndex, int flags)
|
---|
1224 | {
|
---|
1225 | ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
|
---|
1226 |
|
---|
1227 | /* Destroy the VGA hardware record */
|
---|
1228 | vgaHWFreeHWRec(pScrn);
|
---|
1229 | /* And our private record */
|
---|
1230 | free(pScrn->driverPrivate);
|
---|
1231 | pScrn->driverPrivate = NULL;
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | static Bool
|
---|
1235 | VBOXMapVidMem(ScrnInfoPtr pScrn)
|
---|
1236 | {
|
---|
1237 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1238 | Bool rc = TRUE;
|
---|
1239 |
|
---|
1240 | TRACE_ENTRY();
|
---|
1241 | if (!pVBox->base)
|
---|
1242 | {
|
---|
1243 | #ifdef PCIACCESS
|
---|
1244 | (void) pci_device_map_range(pVBox->pciInfo,
|
---|
1245 | pScrn->memPhysBase,
|
---|
1246 | pScrn->videoRam * 1024,
|
---|
1247 | PCI_DEV_MAP_FLAG_WRITABLE,
|
---|
1248 | & pVBox->base);
|
---|
1249 | #else
|
---|
1250 | pVBox->base = xf86MapPciMem(pScrn->scrnIndex,
|
---|
1251 | VIDMEM_FRAMEBUFFER,
|
---|
1252 | pVBox->pciTag, pScrn->memPhysBase,
|
---|
1253 | (unsigned) pScrn->videoRam * 1024);
|
---|
1254 | #endif
|
---|
1255 | if (!pVBox->base)
|
---|
1256 | rc = FALSE;
|
---|
1257 | }
|
---|
1258 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1259 | return rc;
|
---|
1260 | }
|
---|
1261 |
|
---|
1262 | static void
|
---|
1263 | VBOXUnmapVidMem(ScrnInfoPtr pScrn)
|
---|
1264 | {
|
---|
1265 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1266 |
|
---|
1267 | TRACE_ENTRY();
|
---|
1268 | if (pVBox->base == NULL)
|
---|
1269 | return;
|
---|
1270 |
|
---|
1271 | #ifdef PCIACCESS
|
---|
1272 | (void) pci_device_unmap_range(pVBox->pciInfo,
|
---|
1273 | pVBox->base,
|
---|
1274 | pScrn->videoRam * 1024);
|
---|
1275 | #else
|
---|
1276 | xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base,
|
---|
1277 | (unsigned) pScrn->videoRam * 1024);
|
---|
1278 | #endif
|
---|
1279 | pVBox->base = NULL;
|
---|
1280 | TRACE_EXIT();
|
---|
1281 | }
|
---|
1282 |
|
---|
1283 | static Bool
|
---|
1284 | VBOXSaveScreen(ScreenPtr pScreen, int mode)
|
---|
1285 | {
|
---|
1286 | (void)pScreen; (void)mode;
|
---|
1287 | return TRUE;
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | void
|
---|
1291 | VBOXSaveMode(ScrnInfoPtr pScrn)
|
---|
1292 | {
|
---|
1293 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1294 | vgaRegPtr vgaReg;
|
---|
1295 |
|
---|
1296 | TRACE_ENTRY();
|
---|
1297 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1298 | vgaHWSave(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1299 | pVBox->fSavedVBEMode = VBoxVideoGetModeRegisters(&pVBox->cSavedWidth,
|
---|
1300 | &pVBox->cSavedHeight,
|
---|
1301 | &pVBox->cSavedPitch,
|
---|
1302 | &pVBox->cSavedBPP,
|
---|
1303 | &pVBox->fSavedFlags);
|
---|
1304 | }
|
---|
1305 |
|
---|
1306 | void
|
---|
1307 | VBOXRestoreMode(ScrnInfoPtr pScrn)
|
---|
1308 | {
|
---|
1309 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1310 | vgaRegPtr vgaReg;
|
---|
1311 |
|
---|
1312 | TRACE_ENTRY();
|
---|
1313 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1314 | vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1315 | if (pVBox->fSavedVBEMode)
|
---|
1316 | VBoxVideoSetModeRegisters(pVBox->cSavedWidth, pVBox->cSavedHeight,
|
---|
1317 | pVBox->cSavedPitch, pVBox->cSavedBPP,
|
---|
1318 | pVBox->fSavedFlags, 0, 0);
|
---|
1319 | else
|
---|
1320 | VBoxVideoDisableVBE();
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 | static void
|
---|
1324 | VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
|
---|
1325 | int flags)
|
---|
1326 | {
|
---|
1327 | (void)pScrn; (void)mode; (void) flags;
|
---|
1328 | }
|
---|