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