1 | /* $Id: vboxvideo.c 55413 2015-04-23 20:08:25Z 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 | #include "vboxvideo.h"
|
---|
58 | #include <VBox/VBoxGuest.h>
|
---|
59 | #include <VBox/Hardware/VBoxVideoVBE.h>
|
---|
60 | #include "version-generated.h"
|
---|
61 | #include "product-generated.h"
|
---|
62 |
|
---|
63 | /* Basic definitions and functions needed by all drivers. */
|
---|
64 | #include "xf86.h"
|
---|
65 | /* For video memory mapping. */
|
---|
66 | #include "xf86_OSproc.h"
|
---|
67 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
|
---|
68 | /* PCI resources. */
|
---|
69 | # include "xf86Resources.h"
|
---|
70 | #endif
|
---|
71 | /* Generic server linear frame-buffer APIs. */
|
---|
72 | #include "fb.h"
|
---|
73 | /* Colormap and visual handling. */
|
---|
74 | #include "micmap.h"
|
---|
75 | #include "xf86cmap.h"
|
---|
76 | /* ShadowFB support */
|
---|
77 | #include "shadowfb.h"
|
---|
78 | /* VGA hardware functions for setting and restoring text mode */
|
---|
79 | #include "vgaHW.h"
|
---|
80 | #ifdef VBOX_DRI
|
---|
81 | # include "xf86drm.h"
|
---|
82 | # include "xf86drmMode.h"
|
---|
83 | #endif
|
---|
84 | #ifdef VBOXVIDEO_13
|
---|
85 | /* X.org 1.3+ mode setting */
|
---|
86 | # define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */
|
---|
87 | # include "xf86Crtc.h"
|
---|
88 | # include "xf86Modes.h"
|
---|
89 | #endif
|
---|
90 | /* For setting the root window property. */
|
---|
91 | #include "property.h"
|
---|
92 | #include "X11/Xatom.h"
|
---|
93 |
|
---|
94 | #ifdef XORG_7X
|
---|
95 | # include <stdlib.h>
|
---|
96 | # include <string.h>
|
---|
97 | #endif
|
---|
98 |
|
---|
99 | /* This was accepted upstream in X.Org Server 1.16 which bumped the video
|
---|
100 | * driver ABI to 17. */
|
---|
101 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 17
|
---|
102 | # define SET_HAVE_VT_PROPERTY
|
---|
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 | static void setSizesAndCursorIntegration(ScrnInfoPtr pScrn, bool fScreenInitTime);
|
---|
133 |
|
---|
134 | #ifndef XF86_SCRN_INTERFACE
|
---|
135 | # define xf86ScreenToScrn(pScreen) xf86Screens[(pScreen)->myNum]
|
---|
136 | # define xf86ScrnToScreen(pScrn) screenInfo.screens[(pScrn)->scrnIndex]
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | static inline void VBOXSetRec(ScrnInfoPtr pScrn)
|
---|
140 | {
|
---|
141 | if (!pScrn->driverPrivate)
|
---|
142 | {
|
---|
143 | VBOXPtr pVBox = (VBOXPtr)xnfcalloc(sizeof(VBOXRec), 1);
|
---|
144 | pScrn->driverPrivate = pVBox;
|
---|
145 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
146 | pVBox->fdACPIDevices = -1;
|
---|
147 | #endif
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | enum GenericTypes
|
---|
152 | {
|
---|
153 | CHIP_VBOX_GENERIC
|
---|
154 | };
|
---|
155 |
|
---|
156 | #ifdef PCIACCESS
|
---|
157 | static const struct pci_id_match vbox_device_match[] = {
|
---|
158 | {
|
---|
159 | VBOX_VENDORID, VBOX_DEVICEID, PCI_MATCH_ANY, PCI_MATCH_ANY,
|
---|
160 | 0, 0, 0
|
---|
161 | },
|
---|
162 |
|
---|
163 | { 0, 0, 0 },
|
---|
164 | };
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | /* Supported chipsets */
|
---|
168 | static SymTabRec VBOXChipsets[] =
|
---|
169 | {
|
---|
170 | {VBOX_DEVICEID, "vbox"},
|
---|
171 | {-1, NULL}
|
---|
172 | };
|
---|
173 |
|
---|
174 | static PciChipsets VBOXPCIchipsets[] = {
|
---|
175 | { VBOX_DEVICEID, VBOX_DEVICEID, RES_SHARED_VGA },
|
---|
176 | { -1, -1, RES_UNDEFINED },
|
---|
177 | };
|
---|
178 |
|
---|
179 | /*
|
---|
180 | * This contains the functions needed by the server after loading the
|
---|
181 | * driver module. It must be supplied, and gets added the driver list by
|
---|
182 | * the Module Setup function in the dynamic case. In the static case a
|
---|
183 | * reference to this is compiled in, and this requires that the name of
|
---|
184 | * this DriverRec be an upper-case version of the driver name.
|
---|
185 | */
|
---|
186 |
|
---|
187 | #ifdef XORG_7X
|
---|
188 | _X_EXPORT
|
---|
189 | #endif
|
---|
190 | DriverRec VBOXVIDEO = {
|
---|
191 | VBOX_VERSION,
|
---|
192 | VBOX_DRIVER_NAME,
|
---|
193 | VBOXIdentify,
|
---|
194 | #ifdef PCIACCESS
|
---|
195 | NULL,
|
---|
196 | #else
|
---|
197 | VBOXProbe,
|
---|
198 | #endif
|
---|
199 | VBOXAvailableOptions,
|
---|
200 | NULL,
|
---|
201 | 0,
|
---|
202 | #ifdef XORG_7X
|
---|
203 | NULL,
|
---|
204 | #endif
|
---|
205 | #ifdef PCIACCESS
|
---|
206 | vbox_device_match,
|
---|
207 | VBOXPciProbe
|
---|
208 | #endif
|
---|
209 | };
|
---|
210 |
|
---|
211 | /* No options for now */
|
---|
212 | static const OptionInfoRec VBOXOptions[] = {
|
---|
213 | { -1, NULL, OPTV_NONE, {0}, FALSE }
|
---|
214 | };
|
---|
215 |
|
---|
216 | #ifndef XORG_7X
|
---|
217 | /*
|
---|
218 | * List of symbols from other modules that this module references. This
|
---|
219 | * list is used to tell the loader that it is OK for symbols here to be
|
---|
220 | * unresolved providing that it hasn't been told that they haven't been
|
---|
221 | * told that they are essential via a call to xf86LoaderReqSymbols() or
|
---|
222 | * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
|
---|
223 | * unresolved symbols that are not required.
|
---|
224 | */
|
---|
225 | static const char *fbSymbols[] = {
|
---|
226 | "fbPictureInit",
|
---|
227 | "fbScreenInit",
|
---|
228 | NULL
|
---|
229 | };
|
---|
230 |
|
---|
231 | static const char *shadowfbSymbols[] = {
|
---|
232 | "ShadowFBInit2",
|
---|
233 | NULL
|
---|
234 | };
|
---|
235 |
|
---|
236 | static const char *ramdacSymbols[] = {
|
---|
237 | "xf86DestroyCursorInfoRec",
|
---|
238 | "xf86InitCursor",
|
---|
239 | "xf86CreateCursorInfoRec",
|
---|
240 | NULL
|
---|
241 | };
|
---|
242 |
|
---|
243 | static const char *vgahwSymbols[] = {
|
---|
244 | "vgaHWFreeHWRec",
|
---|
245 | "vgaHWGetHWRec",
|
---|
246 | "vgaHWGetIOBase",
|
---|
247 | "vgaHWGetIndex",
|
---|
248 | "vgaHWRestore",
|
---|
249 | "vgaHWSave",
|
---|
250 | "vgaHWSetStdFuncs",
|
---|
251 | NULL
|
---|
252 | };
|
---|
253 | #endif /* !XORG_7X */
|
---|
254 |
|
---|
255 | /** Resize the virtual framebuffer. */
|
---|
256 | static Bool adjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height)
|
---|
257 | {
|
---|
258 | ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
|
---|
259 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
260 | int adjustedWidth = pScrn->bitsPerPixel == 16 ? (width + 1) & ~1 : width;
|
---|
261 | int cbLine = adjustedWidth * pScrn->bitsPerPixel / 8;
|
---|
262 | PixmapPtr pPixmap;
|
---|
263 | int rc;
|
---|
264 |
|
---|
265 | TRACE_LOG("width=%d, height=%d\n", width, height);
|
---|
266 | VBVXASSERT(width >= 0 && height >= 0, ("Invalid negative width (%d) or height (%d)\n", width, height));
|
---|
267 | if (pScreen == NULL) /* Not yet initialised. */
|
---|
268 | return TRUE;
|
---|
269 | pPixmap = pScreen->GetScreenPixmap(pScreen);
|
---|
270 | VBVXASSERT(pPixmap != NULL, ("Failed to get the screen pixmap.\n"));
|
---|
271 | TRACE_LOG("pPixmap=%p adjustedWidth=%d height=%d pScrn->depth=%d pScrn->bitsPerPixel=%d cbLine=%d pVBox->base=%p pPixmap->drawable.width=%d pPixmap->drawable.height=%d\n",
|
---|
272 | pPixmap, adjustedWidth, height, pScrn->depth, pScrn->bitsPerPixel, cbLine, pVBox->base, pPixmap->drawable.width,
|
---|
273 | pPixmap->drawable.height);
|
---|
274 | if ( adjustedWidth != pPixmap->drawable.width
|
---|
275 | || height != pPixmap->drawable.height)
|
---|
276 | {
|
---|
277 | if ( adjustedWidth > VBOX_VIDEO_MAX_VIRTUAL || height > VBOX_VIDEO_MAX_VIRTUAL
|
---|
278 | || (unsigned)cbLine * (unsigned)height >= pVBox->cbFBMax)
|
---|
279 | {
|
---|
280 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
281 | "Virtual framebuffer %dx%d too large. For information, video memory: %u Kb.\n",
|
---|
282 | adjustedWidth, height, (unsigned) pVBox->cbFBMax / 1024);
|
---|
283 | return FALSE;
|
---|
284 | }
|
---|
285 | vbvxClearVRAM(pScrn, pScrn->virtualX * pScrn->virtualY * pScrn->bitsPerPixel / 8,
|
---|
286 | adjustedWidth * height * pScrn->bitsPerPixel / 8);
|
---|
287 | pScreen->ModifyPixmapHeader(pPixmap, adjustedWidth, height, pScrn->depth, pScrn->bitsPerPixel, cbLine, pVBox->base);
|
---|
288 | }
|
---|
289 | pScrn->displayWidth = pScrn->virtualX = adjustedWidth;
|
---|
290 | pScrn->virtualY = height;
|
---|
291 | #ifdef VBOX_DRI_OLD
|
---|
292 | if (pVBox->useDRI)
|
---|
293 | VBOXDRIUpdateStride(pScrn, pVBox);
|
---|
294 | #endif
|
---|
295 | return TRUE;
|
---|
296 | }
|
---|
297 |
|
---|
298 | /** Set a video mode to the hardware, RandR 1.1 version. Since we no longer do
|
---|
299 | * virtual frame buffers, adjust the screen pixmap dimensions to match. */
|
---|
300 | static void setModeRandR11(ScrnInfoPtr pScrn, DisplayModePtr pMode, bool fLimitedContext)
|
---|
301 | {
|
---|
302 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
303 | struct vbvxFrameBuffer frameBuffer = { 0, 0, pMode->HDisplay, pMode->VDisplay, pScrn->bitsPerPixel};
|
---|
304 |
|
---|
305 | pVBox->pScreens[0].aScreenLocation.cx = pMode->HDisplay;
|
---|
306 | pVBox->pScreens[0].aScreenLocation.cy = pMode->VDisplay;
|
---|
307 | if (fLimitedContext)
|
---|
308 | {
|
---|
309 | pScrn->displayWidth = pScrn->virtualX = pMode->HDisplay;
|
---|
310 | pScrn->virtualY = pMode->VDisplay;
|
---|
311 | }
|
---|
312 | else
|
---|
313 | adjustScreenPixmap(pScrn, pMode->HDisplay, pMode->VDisplay);
|
---|
314 | if (pMode->HDisplay != 0 && pMode->VDisplay != 0)
|
---|
315 | vbvxSetMode(pScrn, 0, pMode->HDisplay, pMode->VDisplay, 0, 0, true, true, &frameBuffer);
|
---|
316 | pScrn->currentMode = pMode;
|
---|
317 | }
|
---|
318 |
|
---|
319 | #ifdef VBOXVIDEO_13
|
---|
320 | /* X.org 1.3+ mode-setting support ******************************************/
|
---|
321 |
|
---|
322 | /** Set a video mode to the hardware, RandR 1.2 version. If this is the first
|
---|
323 | * screen, re-set the current mode for all others (the offset for the first
|
---|
324 | * screen is always treated as zero by the hardware, so all other screens need
|
---|
325 | * to be changed to compensate for any changes!). The mode to set is taken
|
---|
326 | * from the X.Org Crtc structure. */
|
---|
327 | static void setModeRandR12(ScrnInfoPtr pScrn, unsigned cScreen)
|
---|
328 | {
|
---|
329 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
330 | unsigned i;
|
---|
331 | struct vbvxFrameBuffer frameBuffer = { pVBox->pScreens[0].paCrtcs->x, pVBox->pScreens[0].paCrtcs->y, pScrn->virtualX,
|
---|
332 | pScrn->virtualY, pScrn->bitsPerPixel };
|
---|
333 | unsigned cFirst = cScreen;
|
---|
334 | unsigned cLast = cScreen != 0 ? cScreen + 1 : pVBox->cScreens;
|
---|
335 |
|
---|
336 | for (i = cFirst; i < cLast; ++i)
|
---|
337 | if (pVBox->pScreens[i].paCrtcs->mode.HDisplay != 0 && pVBox->pScreens[i].paCrtcs->mode.VDisplay != 0)
|
---|
338 | vbvxSetMode(pScrn, i, pVBox->pScreens[i].paCrtcs->mode.HDisplay, pVBox->pScreens[i].paCrtcs->mode.VDisplay,
|
---|
339 | pVBox->pScreens[i].paCrtcs->x, pVBox->pScreens[i].paCrtcs->y, pVBox->pScreens[i].fPowerOn,
|
---|
340 | pVBox->pScreens[i].paOutputs->status == XF86OutputStatusConnected, &frameBuffer);
|
---|
341 | }
|
---|
342 |
|
---|
343 | /** Wrapper around setModeRandR12() to avoid exposing non-obvious semantics.
|
---|
344 | */
|
---|
345 | static void setAllModesRandR12(ScrnInfoPtr pScrn)
|
---|
346 | {
|
---|
347 | setModeRandR12(pScrn, 0);
|
---|
348 | }
|
---|
349 |
|
---|
350 | /* For descriptions of these functions and structures, see
|
---|
351 | hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the
|
---|
352 | X.Org source tree. */
|
---|
353 |
|
---|
354 | static Bool vbox_config_resize(ScrnInfoPtr pScrn, int cw, int ch)
|
---|
355 | {
|
---|
356 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
357 | Bool rc;
|
---|
358 | unsigned i;
|
---|
359 |
|
---|
360 | TRACE_LOG("width=%d, height=%d\n", cw, ch);
|
---|
361 | /* Don't fiddle with the hardware if we are switched
|
---|
362 | * to a virtual terminal. */
|
---|
363 | if (!pScrn->vtSema) {
|
---|
364 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
365 | "We do not own the active VT, exiting.\n");
|
---|
366 | return TRUE;
|
---|
367 | }
|
---|
368 | rc = adjustScreenPixmap(pScrn, cw, ch);
|
---|
369 | /* Power-on all screens (the server expects this) and set the new pitch to them. */
|
---|
370 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
371 | pVBox->pScreens[i].fPowerOn = true;
|
---|
372 | setAllModesRandR12(pScrn);
|
---|
373 | vbvxSetSolarisMouseRange(cw, ch);
|
---|
374 | return rc;
|
---|
375 | }
|
---|
376 |
|
---|
377 | static const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
|
---|
378 | vbox_config_resize
|
---|
379 | };
|
---|
380 |
|
---|
381 | static void
|
---|
382 | vbox_crtc_dpms(xf86CrtcPtr crtc, int mode)
|
---|
383 | {
|
---|
384 | ScrnInfoPtr pScrn = crtc->scrn;
|
---|
385 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
386 | unsigned cDisplay = (uintptr_t)crtc->driver_private;
|
---|
387 |
|
---|
388 | TRACE_LOG("mode=%d\n", mode);
|
---|
389 | pVBox->pScreens[cDisplay].fPowerOn = (mode != DPMSModeOff);
|
---|
390 | setModeRandR12(pScrn, cDisplay);
|
---|
391 | }
|
---|
392 |
|
---|
393 | static Bool
|
---|
394 | vbox_crtc_lock (xf86CrtcPtr crtc)
|
---|
395 | { (void) crtc; return FALSE; }
|
---|
396 |
|
---|
397 |
|
---|
398 | /* We use this function to check whether the X server owns the active virtual
|
---|
399 | * terminal before attempting a mode switch, since the RandR extension isn't
|
---|
400 | * very dilligent here, which can mean crashes if we are unlucky. This is
|
---|
401 | * not the way it the function is intended - it is meant for reporting modes
|
---|
402 | * which the hardware can't handle. I hope that this won't confuse any clients
|
---|
403 | * connecting to us. */
|
---|
404 | static Bool
|
---|
405 | vbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
406 | DisplayModePtr adjusted_mode)
|
---|
407 | { (void) crtc; (void) mode; (void) adjusted_mode; return TRUE; }
|
---|
408 |
|
---|
409 | static void
|
---|
410 | vbox_crtc_stub (xf86CrtcPtr crtc)
|
---|
411 | { (void) crtc; }
|
---|
412 |
|
---|
413 | static void
|
---|
414 | vbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
415 | DisplayModePtr adjusted_mode, int x, int y)
|
---|
416 | {
|
---|
417 | (void) mode;
|
---|
418 | VBOXPtr pVBox = VBOXGetRec(crtc->scrn);
|
---|
419 | unsigned cDisplay = (uintptr_t)crtc->driver_private;
|
---|
420 |
|
---|
421 | TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name,
|
---|
422 | adjusted_mode->HDisplay, adjusted_mode->VDisplay, x, y);
|
---|
423 | pVBox->pScreens[cDisplay].fPowerOn = true;
|
---|
424 | pVBox->pScreens[cDisplay].aScreenLocation.cx = adjusted_mode->HDisplay;
|
---|
425 | pVBox->pScreens[cDisplay].aScreenLocation.cy = adjusted_mode->VDisplay;
|
---|
426 | pVBox->pScreens[cDisplay].aScreenLocation.x = x;
|
---|
427 | pVBox->pScreens[cDisplay].aScreenLocation.y = y;
|
---|
428 | /* Don't fiddle with the hardware if we are switched
|
---|
429 | * to a virtual terminal. */
|
---|
430 | if (!crtc->scrn->vtSema)
|
---|
431 | {
|
---|
432 | xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
|
---|
433 | "We do not own the active VT, exiting.\n");
|
---|
434 | return;
|
---|
435 | }
|
---|
436 | setModeRandR12(crtc->scrn, cDisplay);
|
---|
437 | }
|
---|
438 |
|
---|
439 | static void
|
---|
440 | vbox_crtc_gamma_set (xf86CrtcPtr crtc, CARD16 *red,
|
---|
441 | CARD16 *green, CARD16 *blue, int size)
|
---|
442 | { (void) crtc; (void) red; (void) green; (void) blue; (void) size; }
|
---|
443 |
|
---|
444 | static void *
|
---|
445 | vbox_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height)
|
---|
446 | { (void) crtc; (void) width; (void) height; return NULL; }
|
---|
447 |
|
---|
448 | static const xf86CrtcFuncsRec VBOXCrtcFuncs = {
|
---|
449 | .dpms = vbox_crtc_dpms,
|
---|
450 | .save = NULL, /* These two are never called by the server. */
|
---|
451 | .restore = NULL,
|
---|
452 | .lock = vbox_crtc_lock,
|
---|
453 | .unlock = NULL, /* This will not be invoked if lock returns FALSE. */
|
---|
454 | .mode_fixup = vbox_crtc_mode_fixup,
|
---|
455 | .prepare = vbox_crtc_stub,
|
---|
456 | .mode_set = vbox_crtc_mode_set,
|
---|
457 | .commit = vbox_crtc_stub,
|
---|
458 | .gamma_set = vbox_crtc_gamma_set,
|
---|
459 | .shadow_allocate = vbox_crtc_shadow_allocate,
|
---|
460 | .shadow_create = NULL, /* These two should not be invoked if allocate
|
---|
461 | returns NULL. */
|
---|
462 | .shadow_destroy = NULL,
|
---|
463 | .set_cursor_colors = NULL, /* We are still using the old cursor API. */
|
---|
464 | .set_cursor_position = NULL,
|
---|
465 | .show_cursor = NULL,
|
---|
466 | .hide_cursor = NULL,
|
---|
467 | .load_cursor_argb = NULL,
|
---|
468 | .destroy = vbox_crtc_stub
|
---|
469 | };
|
---|
470 |
|
---|
471 | static void
|
---|
472 | vbox_output_stub (xf86OutputPtr output)
|
---|
473 | { (void) output; }
|
---|
474 |
|
---|
475 | static void
|
---|
476 | vbox_output_dpms (xf86OutputPtr output, int mode)
|
---|
477 | {
|
---|
478 | (void)output; (void)mode;
|
---|
479 | }
|
---|
480 |
|
---|
481 | static int
|
---|
482 | vbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode)
|
---|
483 | {
|
---|
484 | return MODE_OK;
|
---|
485 | }
|
---|
486 |
|
---|
487 | static Bool
|
---|
488 | vbox_output_mode_fixup (xf86OutputPtr output, DisplayModePtr mode,
|
---|
489 | DisplayModePtr adjusted_mode)
|
---|
490 | { (void) output; (void) mode; (void) adjusted_mode; return TRUE; }
|
---|
491 |
|
---|
492 | static void
|
---|
493 | vbox_output_mode_set (xf86OutputPtr output, DisplayModePtr mode,
|
---|
494 | DisplayModePtr adjusted_mode)
|
---|
495 | { (void) output; (void) mode; (void) adjusted_mode; }
|
---|
496 |
|
---|
497 | /* A virtual monitor is always connected. */
|
---|
498 | static xf86OutputStatus
|
---|
499 | vbox_output_detect (xf86OutputPtr output)
|
---|
500 | {
|
---|
501 | ScrnInfoPtr pScrn = output->scrn;
|
---|
502 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
503 | uint32_t iScreen = (uintptr_t)output->driver_private;
|
---|
504 | return pVBox->pScreens[iScreen].afConnected
|
---|
505 | ? XF86OutputStatusConnected : XF86OutputStatusDisconnected;
|
---|
506 | }
|
---|
507 |
|
---|
508 | static DisplayModePtr vbox_output_add_mode(VBOXPtr pVBox, DisplayModePtr *pModes, const char *pszName, int x, int y,
|
---|
509 | Bool isPreferred, Bool isUserDef)
|
---|
510 | {
|
---|
511 | TRACE_LOG("pszName=%s, x=%d, y=%d\n", pszName ? pszName : "(null)", x, y);
|
---|
512 | DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec));
|
---|
513 | int cRefresh = 60;
|
---|
514 |
|
---|
515 | pMode->status = MODE_OK;
|
---|
516 | /* We don't ask the host whether it likes user defined modes,
|
---|
517 | * as we assume that the user really wanted that mode. */
|
---|
518 | pMode->type = isUserDef ? M_T_USERDEF : M_T_BUILTIN;
|
---|
519 | if (isPreferred)
|
---|
520 | pMode->type |= M_T_PREFERRED;
|
---|
521 | /* Older versions of VBox only support screen widths which are a multiple
|
---|
522 | * of 8 */
|
---|
523 | if (pVBox->fAnyX)
|
---|
524 | pMode->HDisplay = x;
|
---|
525 | else
|
---|
526 | pMode->HDisplay = x & ~7;
|
---|
527 | pMode->HSyncStart = pMode->HDisplay + 2;
|
---|
528 | pMode->HSyncEnd = pMode->HDisplay + 4;
|
---|
529 | pMode->HTotal = pMode->HDisplay + 6;
|
---|
530 | pMode->VDisplay = y;
|
---|
531 | pMode->VSyncStart = pMode->VDisplay + 2;
|
---|
532 | pMode->VSyncEnd = pMode->VDisplay + 4;
|
---|
533 | pMode->VTotal = pMode->VDisplay + 6;
|
---|
534 | pMode->Clock = pMode->HTotal * pMode->VTotal * cRefresh / 1000; /* kHz */
|
---|
535 | if (NULL == pszName) {
|
---|
536 | xf86SetModeDefaultName(pMode);
|
---|
537 | } else {
|
---|
538 | pMode->name = xnfstrdup(pszName);
|
---|
539 | }
|
---|
540 | *pModes = xf86ModesAdd(*pModes, pMode);
|
---|
541 | return pMode;
|
---|
542 | }
|
---|
543 |
|
---|
544 | static DisplayModePtr
|
---|
545 | vbox_output_get_modes (xf86OutputPtr output)
|
---|
546 | {
|
---|
547 | unsigned i, cIndex = 0;
|
---|
548 | DisplayModePtr pModes = NULL, pMode;
|
---|
549 | ScrnInfoPtr pScrn = output->scrn;
|
---|
550 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
551 |
|
---|
552 | TRACE_ENTRY();
|
---|
553 | uint32_t x, y, iScreen;
|
---|
554 | iScreen = (uintptr_t)output->driver_private;
|
---|
555 | pMode = vbox_output_add_mode(pVBox, &pModes, NULL,
|
---|
556 | RT_CLAMP(pVBox->pScreens[iScreen].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL),
|
---|
557 | RT_CLAMP(pVBox->pScreens[iScreen].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL),
|
---|
558 | TRUE, FALSE);
|
---|
559 | TRACE_EXIT();
|
---|
560 | return pModes;
|
---|
561 | }
|
---|
562 |
|
---|
563 | static const xf86OutputFuncsRec VBOXOutputFuncs = {
|
---|
564 | .create_resources = vbox_output_stub,
|
---|
565 | .dpms = vbox_output_dpms,
|
---|
566 | .save = NULL, /* These two are never called by the server. */
|
---|
567 | .restore = NULL,
|
---|
568 | .mode_valid = vbox_output_mode_valid,
|
---|
569 | .mode_fixup = vbox_output_mode_fixup,
|
---|
570 | .prepare = vbox_output_stub,
|
---|
571 | .commit = vbox_output_stub,
|
---|
572 | .mode_set = vbox_output_mode_set,
|
---|
573 | .detect = vbox_output_detect,
|
---|
574 | .get_modes = vbox_output_get_modes,
|
---|
575 | #ifdef RANDR_12_INTERFACE
|
---|
576 | .set_property = NULL,
|
---|
577 | #endif
|
---|
578 | .destroy = vbox_output_stub
|
---|
579 | };
|
---|
580 | #endif /* VBOXVIDEO_13 */
|
---|
581 |
|
---|
582 | /* Module loader interface */
|
---|
583 | static MODULESETUPPROTO(vboxSetup);
|
---|
584 |
|
---|
585 | static XF86ModuleVersionInfo vboxVersionRec =
|
---|
586 | {
|
---|
587 | VBOX_DRIVER_NAME,
|
---|
588 | VBOX_VENDOR,
|
---|
589 | MODINFOSTRING1,
|
---|
590 | MODINFOSTRING2,
|
---|
591 | #ifdef XORG_7X
|
---|
592 | XORG_VERSION_CURRENT,
|
---|
593 | #else
|
---|
594 | XF86_VERSION_CURRENT,
|
---|
595 | #endif
|
---|
596 | 1, /* Module major version. Xorg-specific */
|
---|
597 | 0, /* Module minor version. Xorg-specific */
|
---|
598 | 1, /* Module patchlevel. Xorg-specific */
|
---|
599 | ABI_CLASS_VIDEODRV, /* This is a video driver */
|
---|
600 | ABI_VIDEODRV_VERSION,
|
---|
601 | MOD_CLASS_VIDEODRV,
|
---|
602 | {0, 0, 0, 0}
|
---|
603 | };
|
---|
604 |
|
---|
605 | /*
|
---|
606 | * This data is accessed by the loader. The name must be the module name
|
---|
607 | * followed by "ModuleData".
|
---|
608 | */
|
---|
609 | #ifdef XORG_7X
|
---|
610 | _X_EXPORT
|
---|
611 | #endif
|
---|
612 | XF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL };
|
---|
613 |
|
---|
614 | static pointer
|
---|
615 | vboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
|
---|
616 | {
|
---|
617 | static Bool Initialised = FALSE;
|
---|
618 |
|
---|
619 | if (!Initialised)
|
---|
620 | {
|
---|
621 | Initialised = TRUE;
|
---|
622 | #ifdef PCIACCESS
|
---|
623 | xf86AddDriver(&VBOXVIDEO, Module, HaveDriverFuncs);
|
---|
624 | #else
|
---|
625 | xf86AddDriver(&VBOXVIDEO, Module, 0);
|
---|
626 | #endif
|
---|
627 | #ifndef XORG_7X
|
---|
628 | LoaderRefSymLists(fbSymbols,
|
---|
629 | shadowfbSymbols,
|
---|
630 | ramdacSymbols,
|
---|
631 | vgahwSymbols,
|
---|
632 | NULL);
|
---|
633 | #endif
|
---|
634 | xf86Msg(X_CONFIG, "Load address of symbol \"VBOXVIDEO\" is %p\n",
|
---|
635 | (void *)&VBOXVIDEO);
|
---|
636 | return (pointer)TRUE;
|
---|
637 | }
|
---|
638 |
|
---|
639 | if (ErrorMajor)
|
---|
640 | *ErrorMajor = LDR_ONCEONLY;
|
---|
641 | return (NULL);
|
---|
642 | }
|
---|
643 |
|
---|
644 |
|
---|
645 | static const OptionInfoRec *
|
---|
646 | VBOXAvailableOptions(int chipid, int busid)
|
---|
647 | {
|
---|
648 | return (VBOXOptions);
|
---|
649 | }
|
---|
650 |
|
---|
651 | static void
|
---|
652 | VBOXIdentify(int flags)
|
---|
653 | {
|
---|
654 | xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets);
|
---|
655 | }
|
---|
656 |
|
---|
657 | #ifndef XF86_SCRN_INTERFACE
|
---|
658 | # define SCRNINDEXAPI(pfn) pfn ## Index
|
---|
659 | static Bool VBOXScreenInitIndex(int scrnIndex, ScreenPtr pScreen, int argc,
|
---|
660 | char **argv)
|
---|
661 | { return VBOXScreenInit(pScreen, argc, argv); }
|
---|
662 |
|
---|
663 | static Bool VBOXEnterVTIndex(int scrnIndex, int flags)
|
---|
664 | { (void) flags; return VBOXEnterVT(xf86Screens[scrnIndex]); }
|
---|
665 |
|
---|
666 | static void VBOXLeaveVTIndex(int scrnIndex, int flags)
|
---|
667 | { (void) flags; VBOXLeaveVT(xf86Screens[scrnIndex]); }
|
---|
668 |
|
---|
669 | static Bool VBOXCloseScreenIndex(int scrnIndex, ScreenPtr pScreen)
|
---|
670 | { (void) scrnIndex; return VBOXCloseScreen(pScreen); }
|
---|
671 |
|
---|
672 | static Bool VBOXSwitchModeIndex(int scrnIndex, DisplayModePtr pMode, int flags)
|
---|
673 | { (void) flags; return VBOXSwitchMode(xf86Screens[scrnIndex], pMode); }
|
---|
674 |
|
---|
675 | static void VBOXAdjustFrameIndex(int scrnIndex, int x, int y, int flags)
|
---|
676 | { (void) flags; VBOXAdjustFrame(xf86Screens[scrnIndex], x, y); }
|
---|
677 |
|
---|
678 | static void VBOXFreeScreenIndex(int scrnIndex, int flags)
|
---|
679 | { (void) flags; VBOXFreeScreen(xf86Screens[scrnIndex]); }
|
---|
680 | # else
|
---|
681 | # define SCRNINDEXAPI(pfn) pfn
|
---|
682 | #endif /* XF86_SCRN_INTERFACE */
|
---|
683 |
|
---|
684 | static void setScreenFunctions(ScrnInfoPtr pScrn, xf86ProbeProc pfnProbe)
|
---|
685 | {
|
---|
686 | pScrn->driverVersion = VBOX_VERSION;
|
---|
687 | pScrn->driverName = VBOX_DRIVER_NAME;
|
---|
688 | pScrn->name = VBOX_NAME;
|
---|
689 | pScrn->Probe = pfnProbe;
|
---|
690 | pScrn->PreInit = VBOXPreInit;
|
---|
691 | pScrn->ScreenInit = SCRNINDEXAPI(VBOXScreenInit);
|
---|
692 | pScrn->SwitchMode = SCRNINDEXAPI(VBOXSwitchMode);
|
---|
693 | pScrn->AdjustFrame = SCRNINDEXAPI(VBOXAdjustFrame);
|
---|
694 | pScrn->EnterVT = SCRNINDEXAPI(VBOXEnterVT);
|
---|
695 | pScrn->LeaveVT = SCRNINDEXAPI(VBOXLeaveVT);
|
---|
696 | pScrn->FreeScreen = SCRNINDEXAPI(VBOXFreeScreen);
|
---|
697 | }
|
---|
698 |
|
---|
699 | /*
|
---|
700 | * One of these functions is called once, at the start of the first server
|
---|
701 | * generation to do a minimal probe for supported hardware.
|
---|
702 | */
|
---|
703 |
|
---|
704 | #ifdef PCIACCESS
|
---|
705 | static Bool
|
---|
706 | VBOXPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev,
|
---|
707 | intptr_t match_data)
|
---|
708 | {
|
---|
709 | ScrnInfoPtr pScrn;
|
---|
710 |
|
---|
711 | TRACE_ENTRY();
|
---|
712 | pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets,
|
---|
713 | NULL, NULL, NULL, NULL, NULL);
|
---|
714 | if (pScrn != NULL) {
|
---|
715 | VBOXPtr pVBox;
|
---|
716 |
|
---|
717 | VBOXSetRec(pScrn);
|
---|
718 | pVBox = VBOXGetRec(pScrn);
|
---|
719 | if (!pVBox)
|
---|
720 | return FALSE;
|
---|
721 | setScreenFunctions(pScrn, NULL);
|
---|
722 | pVBox->pciInfo = dev;
|
---|
723 | }
|
---|
724 |
|
---|
725 | TRACE_LOG("returning %s\n", BOOL_STR(pScrn != NULL));
|
---|
726 | return (pScrn != NULL);
|
---|
727 | }
|
---|
728 | #endif
|
---|
729 |
|
---|
730 | #ifndef PCIACCESS
|
---|
731 | static Bool
|
---|
732 | VBOXProbe(DriverPtr drv, int flags)
|
---|
733 | {
|
---|
734 | Bool foundScreen = FALSE;
|
---|
735 | int numDevSections;
|
---|
736 | GDevPtr *devSections;
|
---|
737 |
|
---|
738 | /*
|
---|
739 | * Find the config file Device sections that match this
|
---|
740 | * driver, and return if there are none.
|
---|
741 | */
|
---|
742 | if ((numDevSections = xf86MatchDevice(VBOX_NAME,
|
---|
743 | &devSections)) <= 0)
|
---|
744 | return (FALSE);
|
---|
745 |
|
---|
746 | /* PCI BUS */
|
---|
747 | if (xf86GetPciVideoInfo())
|
---|
748 | {
|
---|
749 | int numUsed;
|
---|
750 | int *usedChips;
|
---|
751 | int i;
|
---|
752 | numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID,
|
---|
753 | VBOXChipsets, VBOXPCIchipsets,
|
---|
754 | devSections, numDevSections,
|
---|
755 | drv, &usedChips);
|
---|
756 | if (numUsed > 0)
|
---|
757 | {
|
---|
758 | if (flags & PROBE_DETECT)
|
---|
759 | foundScreen = TRUE;
|
---|
760 | else
|
---|
761 | for (i = 0; i < numUsed; i++)
|
---|
762 | {
|
---|
763 | ScrnInfoPtr pScrn = NULL;
|
---|
764 | /* Allocate a ScrnInfoRec */
|
---|
765 | if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i],
|
---|
766 | VBOXPCIchipsets,NULL,
|
---|
767 | NULL,NULL,NULL,NULL)))
|
---|
768 | {
|
---|
769 | setScreenFunctions(pScrn, VBOXProbe);
|
---|
770 | foundScreen = TRUE;
|
---|
771 | }
|
---|
772 | }
|
---|
773 | free(usedChips);
|
---|
774 | }
|
---|
775 | }
|
---|
776 | free(devSections);
|
---|
777 | return (foundScreen);
|
---|
778 | }
|
---|
779 | #endif
|
---|
780 |
|
---|
781 |
|
---|
782 | /*
|
---|
783 | * QUOTE from the XFree86 DESIGN document:
|
---|
784 | *
|
---|
785 | * The purpose of this function is to find out all the information
|
---|
786 | * required to determine if the configuration is usable, and to initialise
|
---|
787 | * those parts of the ScrnInfoRec that can be set once at the beginning of
|
---|
788 | * the first server generation.
|
---|
789 | *
|
---|
790 | * (...)
|
---|
791 | *
|
---|
792 | * This includes probing for video memory, clocks, ramdac, and all other
|
---|
793 | * HW info that is needed. It includes determining the depth/bpp/visual
|
---|
794 | * and related info. It includes validating and determining the set of
|
---|
795 | * video modes that will be used (and anything that is required to
|
---|
796 | * determine that).
|
---|
797 | *
|
---|
798 | * This information should be determined in the least intrusive way
|
---|
799 | * possible. The state of the HW must remain unchanged by this function.
|
---|
800 | * Although video memory (including MMIO) may be mapped within this
|
---|
801 | * function, it must be unmapped before returning.
|
---|
802 | *
|
---|
803 | * END QUOTE
|
---|
804 | */
|
---|
805 |
|
---|
806 | static Bool
|
---|
807 | VBOXPreInit(ScrnInfoPtr pScrn, int flags)
|
---|
808 | {
|
---|
809 | VBOXPtr pVBox;
|
---|
810 | Gamma gzeros = {0.0, 0.0, 0.0};
|
---|
811 | rgb rzeros = {0, 0, 0};
|
---|
812 | unsigned DispiId;
|
---|
813 |
|
---|
814 | TRACE_ENTRY();
|
---|
815 | /* Are we really starting the server, or is this just a dummy run? */
|
---|
816 | if (flags & PROBE_DETECT)
|
---|
817 | return (FALSE);
|
---|
818 |
|
---|
819 | xf86DrvMsg(pScrn->scrnIndex, X_INFO,
|
---|
820 | "VirtualBox guest additions video driver version "
|
---|
821 | VBOX_VERSION_STRING "\n");
|
---|
822 |
|
---|
823 | /* Get our private data from the ScrnInfoRec structure. */
|
---|
824 | VBOXSetRec(pScrn);
|
---|
825 | pVBox = VBOXGetRec(pScrn);
|
---|
826 | if (!pVBox)
|
---|
827 | return FALSE;
|
---|
828 |
|
---|
829 | /* Entity information seems to mean bus information. */
|
---|
830 | pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
|
---|
831 |
|
---|
832 | /* The ramdac module is needed for the hardware cursor. */
|
---|
833 | if (!xf86LoadSubModule(pScrn, "ramdac"))
|
---|
834 | return FALSE;
|
---|
835 |
|
---|
836 | /* The framebuffer module. */
|
---|
837 | if (!xf86LoadSubModule(pScrn, "fb"))
|
---|
838 | return (FALSE);
|
---|
839 |
|
---|
840 | if (!xf86LoadSubModule(pScrn, "shadowfb"))
|
---|
841 | return FALSE;
|
---|
842 |
|
---|
843 | if (!xf86LoadSubModule(pScrn, "vgahw"))
|
---|
844 | return FALSE;
|
---|
845 |
|
---|
846 | #ifdef VBOX_DRI_OLD
|
---|
847 | /* Load the dri module. */
|
---|
848 | if (!xf86LoadSubModule(pScrn, "dri"))
|
---|
849 | return FALSE;
|
---|
850 | #else
|
---|
851 | # ifdef VBOX_DRI
|
---|
852 | /* Load the dri module. */
|
---|
853 | if (!xf86LoadSubModule(pScrn, "dri2"))
|
---|
854 | return FALSE;
|
---|
855 | # endif
|
---|
856 | #endif
|
---|
857 |
|
---|
858 | #ifndef PCIACCESS
|
---|
859 | if (pVBox->pEnt->location.type != BUS_PCI)
|
---|
860 | return FALSE;
|
---|
861 |
|
---|
862 | pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
|
---|
863 | pVBox->pciTag = pciTag(pVBox->pciInfo->bus,
|
---|
864 | pVBox->pciInfo->device,
|
---|
865 | pVBox->pciInfo->func);
|
---|
866 | #endif
|
---|
867 |
|
---|
868 | /* Set up our ScrnInfoRec structure to describe our virtual
|
---|
869 | capabilities to X. */
|
---|
870 |
|
---|
871 | pScrn->chipset = "vbox";
|
---|
872 | /** @note needed during colourmap initialisation */
|
---|
873 | pScrn->rgbBits = 8;
|
---|
874 |
|
---|
875 | /* Let's create a nice, capable virtual monitor. */
|
---|
876 | pScrn->monitor = pScrn->confScreen->monitor;
|
---|
877 | pScrn->monitor->DDC = NULL;
|
---|
878 | pScrn->monitor->nHsync = 1;
|
---|
879 | pScrn->monitor->hsync[0].lo = 1;
|
---|
880 | pScrn->monitor->hsync[0].hi = 10000;
|
---|
881 | pScrn->monitor->nVrefresh = 1;
|
---|
882 | pScrn->monitor->vrefresh[0].lo = 1;
|
---|
883 | pScrn->monitor->vrefresh[0].hi = 100;
|
---|
884 |
|
---|
885 | pScrn->progClock = TRUE;
|
---|
886 |
|
---|
887 | /* Using the PCI information caused problems with non-powers-of-two
|
---|
888 | sized video RAM configurations */
|
---|
889 | pVBox->cbFBMax = VBoxVideoGetVRAMSize();
|
---|
890 | pScrn->videoRam = pVBox->cbFBMax / 1024;
|
---|
891 |
|
---|
892 | /* Check if the chip restricts horizontal resolution or not. */
|
---|
893 | pVBox->fAnyX = VBoxVideoAnyWidthAllowed();
|
---|
894 |
|
---|
895 | /* Set up clock information that will support all modes we need. */
|
---|
896 | pScrn->clockRanges = xnfcalloc(sizeof(ClockRange), 1);
|
---|
897 | pScrn->clockRanges->minClock = 1000;
|
---|
898 | pScrn->clockRanges->maxClock = 1000000000;
|
---|
899 | pScrn->clockRanges->clockIndex = -1;
|
---|
900 | pScrn->clockRanges->ClockMulFactor = 1;
|
---|
901 | pScrn->clockRanges->ClockDivFactor = 1;
|
---|
902 |
|
---|
903 | if (!xf86SetDepthBpp(pScrn, 24, 0, 0, Support32bppFb))
|
---|
904 | return FALSE;
|
---|
905 | /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
|
---|
906 | if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
|
---|
907 | {
|
---|
908 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
909 | "The VBox additions only support 16 and 32bpp graphics modes\n");
|
---|
910 | return FALSE;
|
---|
911 | }
|
---|
912 | xf86PrintDepthBpp(pScrn);
|
---|
913 | vboxAddModes(pScrn);
|
---|
914 |
|
---|
915 | #ifdef VBOXVIDEO_13
|
---|
916 | /* Work around a bug in the original X server modesetting code, which
|
---|
917 | * took the first valid values set to these two as maxima over the
|
---|
918 | * server lifetime. */
|
---|
919 | pScrn->virtualX = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
920 | pScrn->virtualY = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
921 | #else
|
---|
922 | /* We don't validate with xf86ValidateModes and xf86PruneModes as we
|
---|
923 | * already know what we like and what we don't. */
|
---|
924 |
|
---|
925 | pScrn->currentMode = pScrn->modes;
|
---|
926 |
|
---|
927 | /* Set the right virtual resolution. */
|
---|
928 | pScrn->virtualX = pScrn->bitsPerPixel == 16 ? (pScrn->currentMode->HDisplay + 1) & ~1 : pScrn->currentMode->HDisplay;
|
---|
929 | pScrn->virtualY = pScrn->currentMode->VDisplay;
|
---|
930 |
|
---|
931 | #endif /* !VBOXVIDEO_13 */
|
---|
932 |
|
---|
933 | /* Needed before we initialise DRI. */
|
---|
934 | pScrn->displayWidth = pScrn->virtualX;
|
---|
935 |
|
---|
936 | xf86PrintModes(pScrn);
|
---|
937 |
|
---|
938 | /* VGA hardware initialisation */
|
---|
939 | if (!vgaHWGetHWRec(pScrn))
|
---|
940 | return FALSE;
|
---|
941 | /* Must be called before any VGA registers are saved or restored */
|
---|
942 | vgaHWSetStdFuncs(VGAHWPTR(pScrn));
|
---|
943 | vgaHWGetIOBase(VGAHWPTR(pScrn));
|
---|
944 |
|
---|
945 | /* Colour weight - we always call this, since we are always in
|
---|
946 | truecolour. */
|
---|
947 | if (!xf86SetWeight(pScrn, rzeros, rzeros))
|
---|
948 | return (FALSE);
|
---|
949 |
|
---|
950 | /* visual init */
|
---|
951 | if (!xf86SetDefaultVisual(pScrn, -1))
|
---|
952 | return (FALSE);
|
---|
953 |
|
---|
954 | xf86SetGamma(pScrn, gzeros);
|
---|
955 |
|
---|
956 | /* Set the DPI. Perhaps we should read this from the host? */
|
---|
957 | xf86SetDpi(pScrn, 96, 96);
|
---|
958 |
|
---|
959 | if (pScrn->memPhysBase == 0) {
|
---|
960 | #ifdef PCIACCESS
|
---|
961 | pScrn->memPhysBase = pVBox->pciInfo->regions[0].base_addr;
|
---|
962 | #else
|
---|
963 | pScrn->memPhysBase = pVBox->pciInfo->memBase[0];
|
---|
964 | #endif
|
---|
965 | pScrn->fbOffset = 0;
|
---|
966 | }
|
---|
967 |
|
---|
968 | TRACE_EXIT();
|
---|
969 | return (TRUE);
|
---|
970 | }
|
---|
971 |
|
---|
972 | /**
|
---|
973 | * Dummy function for setting the colour palette, which we actually never
|
---|
974 | * touch. However, the server still requires us to provide this.
|
---|
975 | */
|
---|
976 | static void
|
---|
977 | vboxLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
|
---|
978 | LOCO *colors, VisualPtr pVisual)
|
---|
979 | {
|
---|
980 | (void)pScrn; (void) numColors; (void) indices; (void) colors;
|
---|
981 | (void)pVisual;
|
---|
982 | }
|
---|
983 |
|
---|
984 | #define HAS_VT_ATOM_NAME "XFree86_has_VT"
|
---|
985 | #define VBOXVIDEO_DRIVER_ATOM_NAME "VBOXVIDEO_DRIVER_IN_USE"
|
---|
986 | /* The memory storing the initial value of the XFree86_has_VT root window
|
---|
987 | * property. This has to remain available until server start-up, so we just
|
---|
988 | * use a global. */
|
---|
989 | static CARD32 InitialPropertyValue = 1;
|
---|
990 |
|
---|
991 | /** Initialise a flag property on the root window to say whether the server VT
|
---|
992 | * is currently the active one as some clients need to know this. */
|
---|
993 | static void initialiseProperties(ScrnInfoPtr pScrn)
|
---|
994 | {
|
---|
995 | Atom atom = -1;
|
---|
996 | CARD32 *PropertyValue = &InitialPropertyValue;
|
---|
997 | #ifdef SET_HAVE_VT_PROPERTY
|
---|
998 | atom = MakeAtom(HAS_VT_ATOM_NAME, sizeof(HAS_VT_ATOM_NAME) - 1, TRUE);
|
---|
999 | if (xf86RegisterRootWindowProperty(pScrn->scrnIndex, atom, XA_INTEGER,
|
---|
1000 | 32, 1, PropertyValue) != Success)
|
---|
1001 | FatalError("vboxvideo: failed to register VT property\n");
|
---|
1002 | #endif /* SET_HAVE_VT_PROPERTY */
|
---|
1003 | atom = MakeAtom(VBOXVIDEO_DRIVER_ATOM_NAME,
|
---|
1004 | sizeof(VBOXVIDEO_DRIVER_ATOM_NAME) - 1, TRUE);
|
---|
1005 | if (xf86RegisterRootWindowProperty(pScrn->scrnIndex, atom, XA_INTEGER,
|
---|
1006 | 32, 1, PropertyValue) != Success)
|
---|
1007 | FatalError("vboxvideo: failed to register driver in use property\n");
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | #ifdef SET_HAVE_VT_PROPERTY
|
---|
1011 | /** Update a flag property on the root window to say whether the server VT
|
---|
1012 | * is currently the active one as some clients need to know this. */
|
---|
1013 | static void updateHasVTProperty(ScrnInfoPtr pScrn, Bool hasVT)
|
---|
1014 | {
|
---|
1015 | Atom property_name;
|
---|
1016 | int32_t value = hasVT ? 1 : 0;
|
---|
1017 | int i;
|
---|
1018 |
|
---|
1019 | property_name = MakeAtom(HAS_VT_ATOM_NAME, sizeof(HAS_VT_ATOM_NAME) - 1,
|
---|
1020 | FALSE);
|
---|
1021 | if (property_name == BAD_RESOURCE)
|
---|
1022 | FatalError("Failed to retrieve \"HAS_VT\" atom\n");
|
---|
1023 | if (ROOT_WINDOW(pScrn) == NULL)
|
---|
1024 | return;
|
---|
1025 | ChangeWindowProperty(ROOT_WINDOW(pScrn), property_name, XA_INTEGER, 32,
|
---|
1026 | PropModeReplace, 1, &value, TRUE);
|
---|
1027 | }
|
---|
1028 | #endif /* SET_HAVE_VT_PROPERTY */
|
---|
1029 |
|
---|
1030 | #ifdef VBOXVIDEO_13
|
---|
1031 |
|
---|
1032 | static void setVirtualSizeRandR12(ScrnInfoPtr pScrn, bool fLimitedContext)
|
---|
1033 | {
|
---|
1034 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1035 | unsigned i;
|
---|
1036 | unsigned cx = 0;
|
---|
1037 | unsigned cy = 0;
|
---|
1038 |
|
---|
1039 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1040 | {
|
---|
1041 | if ( pVBox->fHaveHGSMIModeHints && pVBox->pScreens[i].afHaveLocation)
|
---|
1042 | {
|
---|
1043 | pVBox->pScreens[i].paCrtcs->x = pVBox->pScreens[i].aPreferredLocation.x;
|
---|
1044 | pVBox->pScreens[i].paCrtcs->y = pVBox->pScreens[i].aPreferredLocation.y;
|
---|
1045 | }
|
---|
1046 | if ( pVBox->pScreens[i].paOutputs->status == XF86OutputStatusConnected
|
---|
1047 | && pVBox->pScreens[i].paCrtcs->x + pVBox->pScreens[i].aPreferredSize.cx < VBOX_VIDEO_MAX_VIRTUAL
|
---|
1048 | && pVBox->pScreens[i].paCrtcs->y + pVBox->pScreens[i].aPreferredSize.cy < VBOX_VIDEO_MAX_VIRTUAL)
|
---|
1049 | {
|
---|
1050 | cx = max(cx, pVBox->pScreens[i].paCrtcs->x + pVBox->pScreens[i].aPreferredSize.cx);
|
---|
1051 | cy = max(cy, pVBox->pScreens[i].paCrtcs->y + pVBox->pScreens[i].aPreferredSize.cy);
|
---|
1052 | }
|
---|
1053 | }
|
---|
1054 | if (cx != 0 && cy != 0)
|
---|
1055 | {
|
---|
1056 | /* Do not set the virtual resolution in limited context as that can
|
---|
1057 | * cause problems setting up RandR 1.2 which needs it set to the
|
---|
1058 | * maximum size at this point. */
|
---|
1059 | if (!fLimitedContext)
|
---|
1060 | {
|
---|
1061 | TRACE_LOG("cx=%u, cy=%u\n", cx, cy);
|
---|
1062 | xf86ScrnToScreen(pScrn)->width = cx;
|
---|
1063 | xf86ScrnToScreen(pScrn)->height = cy;
|
---|
1064 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 14
|
---|
1065 | xf86UpdateDesktopDimensions();
|
---|
1066 | #elif GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 12
|
---|
1067 | screenInfo.width = cx;
|
---|
1068 | screenInfo.height = cy;
|
---|
1069 | #endif
|
---|
1070 | adjustScreenPixmap(pScrn, cx, cy);
|
---|
1071 | vbvxSetSolarisMouseRange(cx, cy);
|
---|
1072 | }
|
---|
1073 | }
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | static void setScreenSizesRandR12(ScrnInfoPtr pScrn, bool fLimitedContext)
|
---|
1077 | {
|
---|
1078 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1079 | unsigned i;
|
---|
1080 |
|
---|
1081 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1082 | {
|
---|
1083 | if (!pVBox->pScreens[i].afConnected)
|
---|
1084 | continue;
|
---|
1085 | /* The Crtc can get "unset" if the screen was disconnected previously.
|
---|
1086 | * I couldn't find an API to re-set it which did not have side-effects.
|
---|
1087 | */
|
---|
1088 | pVBox->pScreens[i].paOutputs->crtc = pVBox->pScreens[i].paCrtcs;
|
---|
1089 | xf86CrtcSetMode(pVBox->pScreens[i].paCrtcs, pVBox->pScreens[i].paOutputs->probed_modes, RR_Rotate_0,
|
---|
1090 | pVBox->pScreens[i].paCrtcs->x, pVBox->pScreens[i].paCrtcs->y);
|
---|
1091 | if (!fLimitedContext)
|
---|
1092 | RRCrtcNotify(pVBox->pScreens[i].paCrtcs->randr_crtc, pVBox->pScreens[i].paOutputs->randr_output->modes[0],
|
---|
1093 | pVBox->pScreens[i].paCrtcs->x, pVBox->pScreens[i].paCrtcs->y, RR_Rotate_0,
|
---|
1094 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 5
|
---|
1095 | NULL,
|
---|
1096 | #endif
|
---|
1097 | 1, &pVBox->pScreens[i].paOutputs->randr_output);
|
---|
1098 | }
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | static void setSizesRandR12(ScrnInfoPtr pScrn, bool fLimitedContext)
|
---|
1102 | {
|
---|
1103 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1104 |
|
---|
1105 | if (!fLimitedContext)
|
---|
1106 | {
|
---|
1107 | # if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 5
|
---|
1108 | RRGetInfo(xf86ScrnToScreen(pScrn), TRUE);
|
---|
1109 | # else
|
---|
1110 | RRGetInfo(xf86ScrnToScreen(pScrn));
|
---|
1111 | # endif
|
---|
1112 | }
|
---|
1113 | setVirtualSizeRandR12(pScrn, fLimitedContext);
|
---|
1114 | setScreenSizesRandR12(pScrn, fLimitedContext);
|
---|
1115 | if (!fLimitedContext)
|
---|
1116 | {
|
---|
1117 | RRScreenSizeNotify(xf86ScrnToScreen(pScrn));
|
---|
1118 | RRTellChanged(xf86ScrnToScreen(pScrn));
|
---|
1119 | }
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | #else
|
---|
1123 |
|
---|
1124 | static void setSizesRandR11(ScrnInfoPtr pScrn, bool fLimitedContext)
|
---|
1125 | {
|
---|
1126 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1127 | DisplayModePtr pNewMode;
|
---|
1128 |
|
---|
1129 | pNewMode = pScrn->modes != pScrn->currentMode ? pScrn->modes : pScrn->modes->next;
|
---|
1130 | pNewMode->HDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1131 | pNewMode->VDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1132 | setModeRandR11(pScrn, pNewMode, fLimitedContext);
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | #endif
|
---|
1136 |
|
---|
1137 | static void setSizesAndCursorIntegration(ScrnInfoPtr pScrn, bool fScreenInitTime)
|
---|
1138 | {
|
---|
1139 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1140 |
|
---|
1141 | TRACE_LOG("fScreenInitTime=%d\n", (int)fScreenInitTime);
|
---|
1142 | #ifdef VBOXVIDEO_13
|
---|
1143 | setSizesRandR12(pScrn, fScreenInitTime);
|
---|
1144 | #else
|
---|
1145 | setSizesRandR11(pScrn, fScreenInitTime);
|
---|
1146 | #endif
|
---|
1147 | if (pScrn->vtSema)
|
---|
1148 | vbvxReprobeCursor(pScrn);
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | /* We update the size hints from the X11 property set by VBoxClient every time
|
---|
1152 | * that the X server goes to sleep (to catch the property change request).
|
---|
1153 | * Although this is far more often than necessary it should not have real-life
|
---|
1154 | * performance consequences and allows us to simplify the code quite a bit. */
|
---|
1155 | static void updateSizeHintsBlockHandler(pointer pData, OSTimePtr pTimeout, pointer pReadmask)
|
---|
1156 | {
|
---|
1157 | ScrnInfoPtr pScrn = (ScrnInfoPtr)pData;
|
---|
1158 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1159 | bool fNeedUpdate = false;
|
---|
1160 |
|
---|
1161 | (void)pTimeout;
|
---|
1162 | (void)pReadmask;
|
---|
1163 | if (!pScrn->vtSema)
|
---|
1164 | return;
|
---|
1165 | vbvxReadSizesAndCursorIntegrationFromHGSMI(pScrn, &fNeedUpdate);
|
---|
1166 | if (ROOT_WINDOW(pScrn) != NULL)
|
---|
1167 | vbvxReadSizesAndCursorIntegrationFromProperties(pScrn, &fNeedUpdate);
|
---|
1168 | if (fNeedUpdate)
|
---|
1169 | setSizesAndCursorIntegration(pScrn, false);
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | /*
|
---|
1173 | * QUOTE from the XFree86 DESIGN document:
|
---|
1174 | *
|
---|
1175 | * This is called at the start of each server generation.
|
---|
1176 | *
|
---|
1177 | * (...)
|
---|
1178 | *
|
---|
1179 | * Decide which operations need to be placed under resource access
|
---|
1180 | * control. (...) Map any video memory or other memory regions. (...)
|
---|
1181 | * Save the video card state. (...) Initialise the initial video
|
---|
1182 | * mode.
|
---|
1183 | *
|
---|
1184 | * End QUOTE.
|
---|
1185 | */
|
---|
1186 | static Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv)
|
---|
1187 | {
|
---|
1188 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
---|
1189 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1190 | VisualPtr visual;
|
---|
1191 | unsigned flags;
|
---|
1192 |
|
---|
1193 | TRACE_ENTRY();
|
---|
1194 |
|
---|
1195 | if (!VBOXMapVidMem(pScrn))
|
---|
1196 | return (FALSE);
|
---|
1197 |
|
---|
1198 | /* save current video state */
|
---|
1199 | VBOXSaveMode(pScrn);
|
---|
1200 |
|
---|
1201 | /* mi layer - reset the visual list (?)*/
|
---|
1202 | miClearVisualTypes();
|
---|
1203 | if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
|
---|
1204 | pScrn->rgbBits, TrueColor))
|
---|
1205 | return (FALSE);
|
---|
1206 | if (!miSetPixmapDepths())
|
---|
1207 | return (FALSE);
|
---|
1208 |
|
---|
1209 | #ifdef VBOX_DRI
|
---|
1210 | pVBox->useDRI = VBOXDRIScreenInit(pScrn, pScreen, pVBox);
|
---|
1211 | # ifndef VBOX_DRI_OLD /* DRI2 */
|
---|
1212 | if (pVBox->drmFD >= 0)
|
---|
1213 | /* Tell the kernel driver, if present, that we are taking over. */
|
---|
1214 | drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_DISABLE_HGSMI, NULL);
|
---|
1215 | # endif
|
---|
1216 | #endif
|
---|
1217 |
|
---|
1218 | if (!fbScreenInit(pScreen, pVBox->base,
|
---|
1219 | pScrn->virtualX, pScrn->virtualY,
|
---|
1220 | pScrn->xDpi, pScrn->yDpi,
|
---|
1221 | pScrn->displayWidth, pScrn->bitsPerPixel))
|
---|
1222 | return (FALSE);
|
---|
1223 |
|
---|
1224 | /* Fixup RGB ordering */
|
---|
1225 | /** @note the X server uses this even in true colour. */
|
---|
1226 | visual = pScreen->visuals + pScreen->numVisuals;
|
---|
1227 | while (--visual >= pScreen->visuals) {
|
---|
1228 | if ((visual->class | DynamicClass) == DirectColor) {
|
---|
1229 | visual->offsetRed = pScrn->offset.red;
|
---|
1230 | visual->offsetGreen = pScrn->offset.green;
|
---|
1231 | visual->offsetBlue = pScrn->offset.blue;
|
---|
1232 | visual->redMask = pScrn->mask.red;
|
---|
1233 | visual->greenMask = pScrn->mask.green;
|
---|
1234 | visual->blueMask = pScrn->mask.blue;
|
---|
1235 | }
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 | /* must be after RGB ordering fixed */
|
---|
1239 | fbPictureInit(pScreen, 0, 0);
|
---|
1240 |
|
---|
1241 | xf86SetBlackWhitePixels(pScreen);
|
---|
1242 | pScrn->vtSema = TRUE;
|
---|
1243 |
|
---|
1244 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
1245 | vbvxSetUpLinuxACPI(pScreen);
|
---|
1246 | #endif
|
---|
1247 |
|
---|
1248 | if (!VBoxHGSMIIsSupported())
|
---|
1249 | {
|
---|
1250 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Graphics device too old to support.\n");
|
---|
1251 | return FALSE;
|
---|
1252 | }
|
---|
1253 | vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024);
|
---|
1254 | pVBox->cScreens = VBoxHGSMIGetMonitorCount(&pVBox->guestCtx);
|
---|
1255 | pVBox->pScreens = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->pScreens));
|
---|
1256 | pVBox->paVBVAModeHints = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->paVBVAModeHints));
|
---|
1257 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Requested monitor count: %u\n", pVBox->cScreens);
|
---|
1258 | vboxEnableVbva(pScrn);
|
---|
1259 | /* Set up the dirty rectangle handler. It will be added into a function
|
---|
1260 | * chain and gets removed when the screen is cleaned up. */
|
---|
1261 | if (ShadowFBInit2(pScreen, NULL, vbvxHandleDirtyRect) != TRUE)
|
---|
1262 | return FALSE;
|
---|
1263 | VBoxInitialiseSizeHints(pScrn);
|
---|
1264 | /* Get any screen size hints from HGSMI. Do not yet try to access X11
|
---|
1265 | * properties, as they are not yet set up, and nor are the clients that
|
---|
1266 | * might have set them. */
|
---|
1267 | vbvxReadSizesAndCursorIntegrationFromHGSMI(pScrn, NULL);
|
---|
1268 |
|
---|
1269 | #ifdef VBOXVIDEO_13
|
---|
1270 | /* Initialise CRTC and output configuration for use with randr1.2. */
|
---|
1271 | xf86CrtcConfigInit(pScrn, &VBOXCrtcConfigFuncs);
|
---|
1272 |
|
---|
1273 | {
|
---|
1274 | uint32_t i;
|
---|
1275 |
|
---|
1276 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1277 | {
|
---|
1278 | char szOutput[256];
|
---|
1279 |
|
---|
1280 | /* Setup our virtual CRTCs. */
|
---|
1281 | pVBox->pScreens[i].paCrtcs = xf86CrtcCreate(pScrn, &VBOXCrtcFuncs);
|
---|
1282 | pVBox->pScreens[i].paCrtcs->driver_private = (void *)(uintptr_t)i;
|
---|
1283 |
|
---|
1284 | /* Set up our virtual outputs. */
|
---|
1285 | snprintf(szOutput, sizeof(szOutput), "VGA-%u", i);
|
---|
1286 | pVBox->pScreens[i].paOutputs
|
---|
1287 | = xf86OutputCreate(pScrn, &VBOXOutputFuncs, szOutput);
|
---|
1288 |
|
---|
1289 | /* We are not interested in the monitor section in the
|
---|
1290 | * configuration file. */
|
---|
1291 | xf86OutputUseScreenMonitor(pVBox->pScreens[i].paOutputs, FALSE);
|
---|
1292 | pVBox->pScreens[i].paOutputs->possible_crtcs = 1 << i;
|
---|
1293 | pVBox->pScreens[i].paOutputs->possible_clones = 0;
|
---|
1294 | pVBox->pScreens[i].paOutputs->driver_private = (void *)(uintptr_t)i;
|
---|
1295 | TRACE_LOG("Created crtc (%p) and output %s (%p)\n",
|
---|
1296 | (void *)pVBox->pScreens[i].paCrtcs, szOutput,
|
---|
1297 | (void *)pVBox->pScreens[i].paOutputs);
|
---|
1298 | }
|
---|
1299 | }
|
---|
1300 |
|
---|
1301 | /* Set a sane minimum and maximum mode size to match what the hardware
|
---|
1302 | * supports. */
|
---|
1303 | xf86CrtcSetSizeRange(pScrn, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1304 |
|
---|
1305 | /* Now create our initial CRTC/output configuration. */
|
---|
1306 | if (!xf86InitialConfiguration(pScrn, TRUE)) {
|
---|
1307 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n");
|
---|
1308 | return (FALSE);
|
---|
1309 | }
|
---|
1310 |
|
---|
1311 | /* Initialise randr 1.2 mode-setting functions. */
|
---|
1312 | if (!xf86CrtcScreenInit(pScreen)) {
|
---|
1313 | return FALSE;
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | #endif
|
---|
1317 | /* set first video mode */
|
---|
1318 | setSizesAndCursorIntegration(pScrn, true);
|
---|
1319 |
|
---|
1320 | /* Register block and wake-up handlers for getting new screen size hints. */
|
---|
1321 | RegisterBlockAndWakeupHandlers(updateSizeHintsBlockHandler, (WakeupHandlerProcPtr)NoopDDA, (pointer)pScrn);
|
---|
1322 |
|
---|
1323 | /* software cursor */
|
---|
1324 | miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
|
---|
1325 |
|
---|
1326 | /* colourmap code */
|
---|
1327 | if (!miCreateDefColormap(pScreen))
|
---|
1328 | return (FALSE);
|
---|
1329 |
|
---|
1330 | if(!xf86HandleColormaps(pScreen, 256, 8, vboxLoadPalette, NULL, 0))
|
---|
1331 | return (FALSE);
|
---|
1332 |
|
---|
1333 | pVBox->CloseScreen = pScreen->CloseScreen;
|
---|
1334 | pScreen->CloseScreen = SCRNINDEXAPI(VBOXCloseScreen);
|
---|
1335 | #ifdef VBOXVIDEO_13
|
---|
1336 | pScreen->SaveScreen = xf86SaveScreen;
|
---|
1337 | #else
|
---|
1338 | pScreen->SaveScreen = VBOXSaveScreen;
|
---|
1339 | #endif
|
---|
1340 |
|
---|
1341 | #ifdef VBOXVIDEO_13
|
---|
1342 | xf86DPMSInit(pScreen, xf86DPMSSet, 0);
|
---|
1343 | #else
|
---|
1344 | /* We probably do want to support power management - even if we just use
|
---|
1345 | a dummy function. */
|
---|
1346 | xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
|
---|
1347 | #endif
|
---|
1348 |
|
---|
1349 | /* Report any unused options (only for the first generation) */
|
---|
1350 | if (serverGeneration == 1)
|
---|
1351 | xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
|
---|
1352 |
|
---|
1353 | if (vbvxCursorInit(pScreen) != TRUE)
|
---|
1354 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
1355 | "Unable to start the VirtualBox mouse pointer integration with the host system.\n");
|
---|
1356 |
|
---|
1357 | #ifdef VBOX_DRI_OLD
|
---|
1358 | if (pVBox->useDRI)
|
---|
1359 | pVBox->useDRI = VBOXDRIFinishScreenInit(pScreen);
|
---|
1360 | #endif
|
---|
1361 |
|
---|
1362 | initialiseProperties(pScrn);
|
---|
1363 |
|
---|
1364 | return (TRUE);
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | static Bool VBOXEnterVT(ScrnInfoPtr pScrn)
|
---|
1368 | {
|
---|
1369 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1370 |
|
---|
1371 | TRACE_ENTRY();
|
---|
1372 | #ifdef VBOX_DRI_OLD
|
---|
1373 | if (pVBox->useDRI)
|
---|
1374 | DRIUnlock(xf86ScrnToScreen(pScrn));
|
---|
1375 | #elif defined(VBOX_DRI) /* DRI2 */
|
---|
1376 | if (pVBox->drmFD >= 0)
|
---|
1377 | {
|
---|
1378 | /* Tell the kernel driver, if present, that we are taking over. */
|
---|
1379 | drmSetMaster(pVBox->drmFD);
|
---|
1380 | }
|
---|
1381 | #endif
|
---|
1382 | vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024);
|
---|
1383 | vboxEnableVbva(pScrn);
|
---|
1384 | /* Re-set video mode */
|
---|
1385 | vbvxReadSizesAndCursorIntegrationFromHGSMI(pScrn, NULL);
|
---|
1386 | vbvxReadSizesAndCursorIntegrationFromProperties(pScrn, NULL);
|
---|
1387 | /* This prevents a crash in CentOS 3. I was unable to debug it to
|
---|
1388 | * satisfaction, partly due to the lack of symbols. My guess is that
|
---|
1389 | * pScrn->ModifyPixmapHeader() expects certain things to be set up when
|
---|
1390 | * it sees pScrn->vtSema set to true which are not quite done at this
|
---|
1391 | * point of the VT switch. */
|
---|
1392 | pScrn->vtSema = FALSE;
|
---|
1393 | setSizesAndCursorIntegration(pScrn, false);
|
---|
1394 | pScrn->vtSema = TRUE;
|
---|
1395 | #ifdef SET_HAVE_VT_PROPERTY
|
---|
1396 | updateHasVTProperty(pScrn, TRUE);
|
---|
1397 | #endif
|
---|
1398 | return TRUE;
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | static void VBOXLeaveVT(ScrnInfoPtr pScrn)
|
---|
1402 | {
|
---|
1403 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1404 | #ifdef VBOXVIDEO_13
|
---|
1405 | unsigned i;
|
---|
1406 | #endif
|
---|
1407 |
|
---|
1408 | TRACE_ENTRY();
|
---|
1409 | #ifdef VBOXVIDEO_13
|
---|
1410 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1411 | vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff);
|
---|
1412 | #endif
|
---|
1413 | vboxDisableVbva(pScrn);
|
---|
1414 | vbvxClearVRAM(pScrn, pScrn->virtualX * pScrn->virtualY * pScrn->bitsPerPixel / 8, 0);
|
---|
1415 | #ifdef VBOX_DRI_OLD
|
---|
1416 | if (pVBox->useDRI)
|
---|
1417 | DRILock(xf86ScrnToScreen(pScrn), 0);
|
---|
1418 | #elif defined(VBOX_DRI) /* DRI2 */
|
---|
1419 | if (pVBox->drmFD >= 0)
|
---|
1420 | drmDropMaster(pVBox->drmFD);
|
---|
1421 | #endif
|
---|
1422 | VBOXRestoreMode(pScrn);
|
---|
1423 | #ifdef SET_HAVE_VT_PROPERTY
|
---|
1424 | updateHasVTProperty(pScrn, FALSE);
|
---|
1425 | #endif
|
---|
1426 | TRACE_EXIT();
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | static Bool VBOXCloseScreen(ScreenPtr pScreen)
|
---|
1430 | {
|
---|
1431 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
---|
1432 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1433 | #if defined(VBOX_DRI) && !defined(VBOX_DRI_OLD) /* DRI2 */
|
---|
1434 | BOOL fRestore = TRUE;
|
---|
1435 | #endif
|
---|
1436 | if (pScrn->vtSema)
|
---|
1437 | {
|
---|
1438 | #ifdef VBOXVIDEO_13
|
---|
1439 | unsigned i;
|
---|
1440 |
|
---|
1441 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1442 | vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff);
|
---|
1443 | #endif
|
---|
1444 | vboxDisableVbva(pScrn);
|
---|
1445 | vbvxClearVRAM(pScrn, pScrn->virtualX * pScrn->virtualY * pScrn->bitsPerPixel / 8, 0);
|
---|
1446 | }
|
---|
1447 | #ifdef VBOX_DRI
|
---|
1448 | # ifndef VBOX_DRI_OLD /* DRI2 */
|
---|
1449 | if ( pVBox->drmFD >= 0
|
---|
1450 | /* Tell the kernel driver, if present, that we are going away. */
|
---|
1451 | && drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_ENABLE_HGSMI, NULL) >= 0)
|
---|
1452 | fRestore = false;
|
---|
1453 | # endif
|
---|
1454 | if (pVBox->useDRI)
|
---|
1455 | VBOXDRICloseScreen(pScreen, pVBox);
|
---|
1456 | pVBox->useDRI = false;
|
---|
1457 | #endif
|
---|
1458 | #if defined(VBOX_DRI) && !defined(VBOX_DRI_OLD) /* DRI2 */
|
---|
1459 | if (fRestore)
|
---|
1460 | #endif
|
---|
1461 | if (pScrn->vtSema)
|
---|
1462 | VBOXRestoreMode(pScrn);
|
---|
1463 | if (pScrn->vtSema)
|
---|
1464 | VBOXUnmapVidMem(pScrn);
|
---|
1465 | pScrn->vtSema = FALSE;
|
---|
1466 |
|
---|
1467 | vbvxCursorTerm(pVBox);
|
---|
1468 |
|
---|
1469 | pScreen->CloseScreen = pVBox->CloseScreen;
|
---|
1470 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
1471 | vbvxCleanUpLinuxACPI(pScreen);
|
---|
1472 | #endif
|
---|
1473 | #ifndef XF86_SCRN_INTERFACE
|
---|
1474 | return pScreen->CloseScreen(pScreen->myNum, pScreen);
|
---|
1475 | #else
|
---|
1476 | return pScreen->CloseScreen(pScreen);
|
---|
1477 | #endif
|
---|
1478 | }
|
---|
1479 |
|
---|
1480 | static Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
|
---|
1481 | {
|
---|
1482 | VBOXPtr pVBox;
|
---|
1483 | Bool rc = TRUE;
|
---|
1484 |
|
---|
1485 | TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
|
---|
1486 | if (!pScrn->vtSema)
|
---|
1487 | {
|
---|
1488 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
1489 | "We do not own the active VT, exiting.\n");
|
---|
1490 | return TRUE;
|
---|
1491 | }
|
---|
1492 | #ifdef VBOXVIDEO_13
|
---|
1493 | rc = xf86SetSingleMode(pScrn, pMode, RR_Rotate_0);
|
---|
1494 | #else
|
---|
1495 | setModeRandR11(pScrn, pMode, false);
|
---|
1496 | #endif
|
---|
1497 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1498 | return rc;
|
---|
1499 | }
|
---|
1500 |
|
---|
1501 | static void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
|
---|
1502 | { (void)pScrn; (void)x; (void)y; }
|
---|
1503 |
|
---|
1504 | static void VBOXFreeScreen(ScrnInfoPtr pScrn)
|
---|
1505 | {
|
---|
1506 | /* Destroy the VGA hardware record */
|
---|
1507 | vgaHWFreeHWRec(pScrn);
|
---|
1508 | /* And our private record */
|
---|
1509 | free(pScrn->driverPrivate);
|
---|
1510 | pScrn->driverPrivate = NULL;
|
---|
1511 | }
|
---|
1512 |
|
---|
1513 | static Bool
|
---|
1514 | VBOXMapVidMem(ScrnInfoPtr pScrn)
|
---|
1515 | {
|
---|
1516 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1517 | Bool rc = TRUE;
|
---|
1518 |
|
---|
1519 | TRACE_ENTRY();
|
---|
1520 | if (!pVBox->base)
|
---|
1521 | {
|
---|
1522 | #ifdef PCIACCESS
|
---|
1523 | (void) pci_device_map_range(pVBox->pciInfo,
|
---|
1524 | pScrn->memPhysBase,
|
---|
1525 | pScrn->videoRam * 1024,
|
---|
1526 | PCI_DEV_MAP_FLAG_WRITABLE,
|
---|
1527 | & pVBox->base);
|
---|
1528 | #else
|
---|
1529 | pVBox->base = xf86MapPciMem(pScrn->scrnIndex,
|
---|
1530 | VIDMEM_FRAMEBUFFER,
|
---|
1531 | pVBox->pciTag, pScrn->memPhysBase,
|
---|
1532 | (unsigned) pScrn->videoRam * 1024);
|
---|
1533 | #endif
|
---|
1534 | if (!pVBox->base)
|
---|
1535 | rc = FALSE;
|
---|
1536 | }
|
---|
1537 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1538 | return rc;
|
---|
1539 | }
|
---|
1540 |
|
---|
1541 | static void
|
---|
1542 | VBOXUnmapVidMem(ScrnInfoPtr pScrn)
|
---|
1543 | {
|
---|
1544 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1545 |
|
---|
1546 | TRACE_ENTRY();
|
---|
1547 | if (pVBox->base == NULL)
|
---|
1548 | return;
|
---|
1549 |
|
---|
1550 | #ifdef PCIACCESS
|
---|
1551 | (void) pci_device_unmap_range(pVBox->pciInfo,
|
---|
1552 | pVBox->base,
|
---|
1553 | pScrn->videoRam * 1024);
|
---|
1554 | #else
|
---|
1555 | xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base,
|
---|
1556 | (unsigned) pScrn->videoRam * 1024);
|
---|
1557 | #endif
|
---|
1558 | pVBox->base = NULL;
|
---|
1559 | TRACE_EXIT();
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 | static Bool
|
---|
1563 | VBOXSaveScreen(ScreenPtr pScreen, int mode)
|
---|
1564 | {
|
---|
1565 | (void)pScreen; (void)mode;
|
---|
1566 | return TRUE;
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | void
|
---|
1570 | VBOXSaveMode(ScrnInfoPtr pScrn)
|
---|
1571 | {
|
---|
1572 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1573 | vgaRegPtr vgaReg;
|
---|
1574 |
|
---|
1575 | TRACE_ENTRY();
|
---|
1576 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1577 | vgaHWSave(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1578 | pVBox->fSavedVBEMode = VBoxVideoGetModeRegisters(&pVBox->cSavedWidth,
|
---|
1579 | &pVBox->cSavedHeight,
|
---|
1580 | &pVBox->cSavedPitch,
|
---|
1581 | &pVBox->cSavedBPP,
|
---|
1582 | &pVBox->fSavedFlags);
|
---|
1583 | }
|
---|
1584 |
|
---|
1585 | void
|
---|
1586 | VBOXRestoreMode(ScrnInfoPtr pScrn)
|
---|
1587 | {
|
---|
1588 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1589 | vgaRegPtr vgaReg;
|
---|
1590 | #ifdef VBOX_DRI
|
---|
1591 | drmModeResPtr pRes;
|
---|
1592 | #endif
|
---|
1593 |
|
---|
1594 | TRACE_ENTRY();
|
---|
1595 | #ifdef VBOX_DRI
|
---|
1596 | /* Do not try to re-set the VGA state if a mode-setting driver is loaded. */
|
---|
1597 | if ( pVBox->drmFD >= 0
|
---|
1598 | && LoaderSymbol("drmModeGetResources") != NULL
|
---|
1599 | && (pRes = drmModeGetResources(pVBox->drmFD)) != NULL)
|
---|
1600 | {
|
---|
1601 | drmModeFreeResources(pRes);
|
---|
1602 | return;
|
---|
1603 | }
|
---|
1604 | #endif
|
---|
1605 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1606 | vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1607 | if (pVBox->fSavedVBEMode)
|
---|
1608 | VBoxVideoSetModeRegisters(pVBox->cSavedWidth, pVBox->cSavedHeight,
|
---|
1609 | pVBox->cSavedPitch, pVBox->cSavedBPP,
|
---|
1610 | pVBox->fSavedFlags, 0, 0);
|
---|
1611 | else
|
---|
1612 | VBoxVideoDisableVBE();
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 | static void
|
---|
1616 | VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
|
---|
1617 | int flags)
|
---|
1618 | {
|
---|
1619 | (void)pScrn; (void)mode; (void) flags;
|
---|
1620 | }
|
---|