1 | /* $Id: vboxvideo.c 55402 2015-04-23 10:07:14Z 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 | if (fLimitedContext)
|
---|
1057 | {
|
---|
1058 | pScrn->virtualX = cx;
|
---|
1059 | pScrn->virtualY = cy;
|
---|
1060 | }
|
---|
1061 | else
|
---|
1062 | {
|
---|
1063 | TRACE_LOG("cx=%u, cy=%u\n", cx, cy);
|
---|
1064 | xf86ScrnToScreen(pScrn)->width = cx;
|
---|
1065 | xf86ScrnToScreen(pScrn)->height = cy;
|
---|
1066 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 14
|
---|
1067 | xf86UpdateDesktopDimensions();
|
---|
1068 | #elif GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 12
|
---|
1069 | screenInfo.width = cx;
|
---|
1070 | screenInfo.height = cy;
|
---|
1071 | #endif
|
---|
1072 | adjustScreenPixmap(pScrn, cx, cy);
|
---|
1073 | vbvxSetSolarisMouseRange(cx, cy);
|
---|
1074 | }
|
---|
1075 | }
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | static void setScreenSizesRandR12(ScrnInfoPtr pScrn, bool fLimitedContext)
|
---|
1079 | {
|
---|
1080 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1081 | unsigned i;
|
---|
1082 |
|
---|
1083 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1084 | {
|
---|
1085 | if (!pVBox->pScreens[i].afConnected)
|
---|
1086 | continue;
|
---|
1087 | /* The Crtc can get "unset" if the screen was disconnected previously.
|
---|
1088 | * I couldn't find an API to re-set it which did not have side-effects.
|
---|
1089 | */
|
---|
1090 | pVBox->pScreens[i].paOutputs->crtc = pVBox->pScreens[i].paCrtcs;
|
---|
1091 | xf86CrtcSetMode(pVBox->pScreens[i].paCrtcs, pVBox->pScreens[i].paOutputs->probed_modes, RR_Rotate_0,
|
---|
1092 | pVBox->pScreens[i].paCrtcs->x, pVBox->pScreens[i].paCrtcs->y);
|
---|
1093 | if (!fLimitedContext)
|
---|
1094 | RRCrtcNotify(pVBox->pScreens[i].paCrtcs->randr_crtc, pVBox->pScreens[i].paOutputs->randr_output->modes[0],
|
---|
1095 | pVBox->pScreens[i].paCrtcs->x, pVBox->pScreens[i].paCrtcs->y, RR_Rotate_0,
|
---|
1096 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 5
|
---|
1097 | NULL,
|
---|
1098 | #endif
|
---|
1099 | 1, &pVBox->pScreens[i].paOutputs->randr_output);
|
---|
1100 | }
|
---|
1101 | }
|
---|
1102 |
|
---|
1103 | static void setSizesRandR12(ScrnInfoPtr pScrn, bool fLimitedContext)
|
---|
1104 | {
|
---|
1105 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1106 |
|
---|
1107 | # if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 5
|
---|
1108 | RRGetInfo(xf86ScrnToScreen(pScrn), TRUE);
|
---|
1109 | # else
|
---|
1110 | RRGetInfo(xf86ScrnToScreen(pScrn));
|
---|
1111 | # endif
|
---|
1112 | setVirtualSizeRandR12(pScrn, fLimitedContext);
|
---|
1113 | setScreenSizesRandR12(pScrn, fLimitedContext);
|
---|
1114 | if (!fLimitedContext)
|
---|
1115 | {
|
---|
1116 | RRScreenSizeNotify(xf86ScrnToScreen(pScrn));
|
---|
1117 | RRTellChanged(xf86ScrnToScreen(pScrn));
|
---|
1118 | }
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | #else
|
---|
1122 |
|
---|
1123 | static void setSizesRandR11(ScrnInfoPtr pScrn, bool fLimitedContext)
|
---|
1124 | {
|
---|
1125 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1126 | DisplayModePtr pNewMode;
|
---|
1127 |
|
---|
1128 | pNewMode = pScrn->modes != pScrn->currentMode ? pScrn->modes : pScrn->modes->next;
|
---|
1129 | pNewMode->HDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1130 | pNewMode->VDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1131 | setModeRandR11(pScrn, pNewMode, fLimitedContext);
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 | #endif
|
---|
1135 |
|
---|
1136 | static void setSizesAndCursorIntegration(ScrnInfoPtr pScrn, bool fScreenInitTime)
|
---|
1137 | {
|
---|
1138 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1139 |
|
---|
1140 | TRACE_LOG("fScreenInitTime=%d\n", (int)fScreenInitTime);
|
---|
1141 | #ifdef VBOXVIDEO_13
|
---|
1142 | setSizesRandR12(pScrn, fScreenInitTime);
|
---|
1143 | #else
|
---|
1144 | setSizesRandR11(pScrn, fScreenInitTime);
|
---|
1145 | #endif
|
---|
1146 | if (pScrn->vtSema)
|
---|
1147 | vbvxReprobeCursor(pScrn);
|
---|
1148 | }
|
---|
1149 |
|
---|
1150 | /* We update the size hints from the X11 property set by VBoxClient every time
|
---|
1151 | * that the X server goes to sleep (to catch the property change request).
|
---|
1152 | * Although this is far more often than necessary it should not have real-life
|
---|
1153 | * performance consequences and allows us to simplify the code quite a bit. */
|
---|
1154 | static void updateSizeHintsBlockHandler(pointer pData, OSTimePtr pTimeout, pointer pReadmask)
|
---|
1155 | {
|
---|
1156 | ScrnInfoPtr pScrn = (ScrnInfoPtr)pData;
|
---|
1157 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1158 | bool fNeedUpdate = false;
|
---|
1159 |
|
---|
1160 | (void)pTimeout;
|
---|
1161 | (void)pReadmask;
|
---|
1162 | if (!pScrn->vtSema)
|
---|
1163 | return;
|
---|
1164 | vbvxReadSizesAndCursorIntegrationFromHGSMI(pScrn, &fNeedUpdate);
|
---|
1165 | if (ROOT_WINDOW(pScrn) != NULL)
|
---|
1166 | vbvxReadSizesAndCursorIntegrationFromProperties(pScrn, &fNeedUpdate);
|
---|
1167 | if (fNeedUpdate)
|
---|
1168 | setSizesAndCursorIntegration(pScrn, false);
|
---|
1169 | }
|
---|
1170 |
|
---|
1171 | /*
|
---|
1172 | * QUOTE from the XFree86 DESIGN document:
|
---|
1173 | *
|
---|
1174 | * This is called at the start of each server generation.
|
---|
1175 | *
|
---|
1176 | * (...)
|
---|
1177 | *
|
---|
1178 | * Decide which operations need to be placed under resource access
|
---|
1179 | * control. (...) Map any video memory or other memory regions. (...)
|
---|
1180 | * Save the video card state. (...) Initialise the initial video
|
---|
1181 | * mode.
|
---|
1182 | *
|
---|
1183 | * End QUOTE.
|
---|
1184 | */
|
---|
1185 | static Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv)
|
---|
1186 | {
|
---|
1187 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
---|
1188 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1189 | VisualPtr visual;
|
---|
1190 | unsigned flags;
|
---|
1191 |
|
---|
1192 | TRACE_ENTRY();
|
---|
1193 |
|
---|
1194 | if (!VBOXMapVidMem(pScrn))
|
---|
1195 | return (FALSE);
|
---|
1196 |
|
---|
1197 | /* save current video state */
|
---|
1198 | VBOXSaveMode(pScrn);
|
---|
1199 |
|
---|
1200 | /* mi layer - reset the visual list (?)*/
|
---|
1201 | miClearVisualTypes();
|
---|
1202 | if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
|
---|
1203 | pScrn->rgbBits, TrueColor))
|
---|
1204 | return (FALSE);
|
---|
1205 | if (!miSetPixmapDepths())
|
---|
1206 | return (FALSE);
|
---|
1207 |
|
---|
1208 | #ifdef VBOX_DRI
|
---|
1209 | pVBox->useDRI = VBOXDRIScreenInit(pScrn, pScreen, pVBox);
|
---|
1210 | # ifndef VBOX_DRI_OLD /* DRI2 */
|
---|
1211 | if (pVBox->drmFD >= 0)
|
---|
1212 | /* Tell the kernel driver, if present, that we are taking over. */
|
---|
1213 | drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_DISABLE_HGSMI, NULL);
|
---|
1214 | # endif
|
---|
1215 | #endif
|
---|
1216 |
|
---|
1217 | if (!fbScreenInit(pScreen, pVBox->base,
|
---|
1218 | pScrn->virtualX, pScrn->virtualY,
|
---|
1219 | pScrn->xDpi, pScrn->yDpi,
|
---|
1220 | pScrn->displayWidth, pScrn->bitsPerPixel))
|
---|
1221 | return (FALSE);
|
---|
1222 |
|
---|
1223 | /* Fixup RGB ordering */
|
---|
1224 | /** @note the X server uses this even in true colour. */
|
---|
1225 | visual = pScreen->visuals + pScreen->numVisuals;
|
---|
1226 | while (--visual >= pScreen->visuals) {
|
---|
1227 | if ((visual->class | DynamicClass) == DirectColor) {
|
---|
1228 | visual->offsetRed = pScrn->offset.red;
|
---|
1229 | visual->offsetGreen = pScrn->offset.green;
|
---|
1230 | visual->offsetBlue = pScrn->offset.blue;
|
---|
1231 | visual->redMask = pScrn->mask.red;
|
---|
1232 | visual->greenMask = pScrn->mask.green;
|
---|
1233 | visual->blueMask = pScrn->mask.blue;
|
---|
1234 | }
|
---|
1235 | }
|
---|
1236 |
|
---|
1237 | /* must be after RGB ordering fixed */
|
---|
1238 | fbPictureInit(pScreen, 0, 0);
|
---|
1239 |
|
---|
1240 | xf86SetBlackWhitePixels(pScreen);
|
---|
1241 | pScrn->vtSema = TRUE;
|
---|
1242 |
|
---|
1243 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
1244 | vbvxSetUpLinuxACPI(pScreen);
|
---|
1245 | #endif
|
---|
1246 |
|
---|
1247 | if (!VBoxHGSMIIsSupported())
|
---|
1248 | {
|
---|
1249 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Graphics device too old to support.\n");
|
---|
1250 | return FALSE;
|
---|
1251 | }
|
---|
1252 | vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024);
|
---|
1253 | pVBox->cScreens = VBoxHGSMIGetMonitorCount(&pVBox->guestCtx);
|
---|
1254 | pVBox->pScreens = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->pScreens));
|
---|
1255 | pVBox->paVBVAModeHints = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->paVBVAModeHints));
|
---|
1256 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Requested monitor count: %u\n", pVBox->cScreens);
|
---|
1257 | vboxEnableVbva(pScrn);
|
---|
1258 | /* Set up the dirty rectangle handler. It will be added into a function
|
---|
1259 | * chain and gets removed when the screen is cleaned up. */
|
---|
1260 | if (ShadowFBInit2(pScreen, NULL, vbvxHandleDirtyRect) != TRUE)
|
---|
1261 | return FALSE;
|
---|
1262 | VBoxInitialiseSizeHints(pScrn);
|
---|
1263 | /* Get any screen size hints from HGSMI. Do not yet try to access X11
|
---|
1264 | * properties, as they are not yet set up, and nor are the clients that
|
---|
1265 | * might have set them. */
|
---|
1266 | vbvxReadSizesAndCursorIntegrationFromHGSMI(pScrn, NULL);
|
---|
1267 |
|
---|
1268 | #ifdef VBOXVIDEO_13
|
---|
1269 | /* Initialise CRTC and output configuration for use with randr1.2. */
|
---|
1270 | xf86CrtcConfigInit(pScrn, &VBOXCrtcConfigFuncs);
|
---|
1271 |
|
---|
1272 | {
|
---|
1273 | uint32_t i;
|
---|
1274 |
|
---|
1275 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1276 | {
|
---|
1277 | char szOutput[256];
|
---|
1278 |
|
---|
1279 | /* Setup our virtual CRTCs. */
|
---|
1280 | pVBox->pScreens[i].paCrtcs = xf86CrtcCreate(pScrn, &VBOXCrtcFuncs);
|
---|
1281 | pVBox->pScreens[i].paCrtcs->driver_private = (void *)(uintptr_t)i;
|
---|
1282 |
|
---|
1283 | /* Set up our virtual outputs. */
|
---|
1284 | snprintf(szOutput, sizeof(szOutput), "VGA-%u", i);
|
---|
1285 | pVBox->pScreens[i].paOutputs
|
---|
1286 | = xf86OutputCreate(pScrn, &VBOXOutputFuncs, szOutput);
|
---|
1287 |
|
---|
1288 | /* We are not interested in the monitor section in the
|
---|
1289 | * configuration file. */
|
---|
1290 | xf86OutputUseScreenMonitor(pVBox->pScreens[i].paOutputs, FALSE);
|
---|
1291 | pVBox->pScreens[i].paOutputs->possible_crtcs = 1 << i;
|
---|
1292 | pVBox->pScreens[i].paOutputs->possible_clones = 0;
|
---|
1293 | pVBox->pScreens[i].paOutputs->driver_private = (void *)(uintptr_t)i;
|
---|
1294 | TRACE_LOG("Created crtc (%p) and output %s (%p)\n",
|
---|
1295 | (void *)pVBox->pScreens[i].paCrtcs, szOutput,
|
---|
1296 | (void *)pVBox->pScreens[i].paOutputs);
|
---|
1297 | }
|
---|
1298 | }
|
---|
1299 |
|
---|
1300 | /* Set a sane minimum and maximum mode size to match what the hardware
|
---|
1301 | * supports. */
|
---|
1302 | xf86CrtcSetSizeRange(pScrn, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1303 |
|
---|
1304 | /* Now create our initial CRTC/output configuration. */
|
---|
1305 | if (!xf86InitialConfiguration(pScrn, TRUE)) {
|
---|
1306 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n");
|
---|
1307 | return (FALSE);
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | /* Initialise randr 1.2 mode-setting functions. */
|
---|
1311 | if (!xf86CrtcScreenInit(pScreen)) {
|
---|
1312 | return FALSE;
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 | #endif
|
---|
1316 | /* set first video mode */
|
---|
1317 | setSizesAndCursorIntegration(pScrn, true);
|
---|
1318 |
|
---|
1319 | /* Register block and wake-up handlers for getting new screen size hints. */
|
---|
1320 | RegisterBlockAndWakeupHandlers(updateSizeHintsBlockHandler, (WakeupHandlerProcPtr)NoopDDA, (pointer)pScrn);
|
---|
1321 |
|
---|
1322 | /* software cursor */
|
---|
1323 | miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
|
---|
1324 |
|
---|
1325 | /* colourmap code */
|
---|
1326 | if (!miCreateDefColormap(pScreen))
|
---|
1327 | return (FALSE);
|
---|
1328 |
|
---|
1329 | if(!xf86HandleColormaps(pScreen, 256, 8, vboxLoadPalette, NULL, 0))
|
---|
1330 | return (FALSE);
|
---|
1331 |
|
---|
1332 | pVBox->CloseScreen = pScreen->CloseScreen;
|
---|
1333 | pScreen->CloseScreen = SCRNINDEXAPI(VBOXCloseScreen);
|
---|
1334 | #ifdef VBOXVIDEO_13
|
---|
1335 | pScreen->SaveScreen = xf86SaveScreen;
|
---|
1336 | #else
|
---|
1337 | pScreen->SaveScreen = VBOXSaveScreen;
|
---|
1338 | #endif
|
---|
1339 |
|
---|
1340 | #ifdef VBOXVIDEO_13
|
---|
1341 | xf86DPMSInit(pScreen, xf86DPMSSet, 0);
|
---|
1342 | #else
|
---|
1343 | /* We probably do want to support power management - even if we just use
|
---|
1344 | a dummy function. */
|
---|
1345 | xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
|
---|
1346 | #endif
|
---|
1347 |
|
---|
1348 | /* Report any unused options (only for the first generation) */
|
---|
1349 | if (serverGeneration == 1)
|
---|
1350 | xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
|
---|
1351 |
|
---|
1352 | if (vbvxCursorInit(pScreen) != TRUE)
|
---|
1353 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
1354 | "Unable to start the VirtualBox mouse pointer integration with the host system.\n");
|
---|
1355 |
|
---|
1356 | #ifdef VBOX_DRI_OLD
|
---|
1357 | if (pVBox->useDRI)
|
---|
1358 | pVBox->useDRI = VBOXDRIFinishScreenInit(pScreen);
|
---|
1359 | #endif
|
---|
1360 |
|
---|
1361 | initialiseProperties(pScrn);
|
---|
1362 |
|
---|
1363 | return (TRUE);
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | static Bool VBOXEnterVT(ScrnInfoPtr pScrn)
|
---|
1367 | {
|
---|
1368 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1369 |
|
---|
1370 | TRACE_ENTRY();
|
---|
1371 | #ifdef VBOX_DRI_OLD
|
---|
1372 | if (pVBox->useDRI)
|
---|
1373 | DRIUnlock(xf86ScrnToScreen(pScrn));
|
---|
1374 | #elif defined(VBOX_DRI) /* DRI2 */
|
---|
1375 | if (pVBox->drmFD >= 0)
|
---|
1376 | {
|
---|
1377 | /* Tell the kernel driver, if present, that we are taking over. */
|
---|
1378 | drmSetMaster(pVBox->drmFD);
|
---|
1379 | }
|
---|
1380 | #endif
|
---|
1381 | vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024);
|
---|
1382 | vboxEnableVbva(pScrn);
|
---|
1383 | /* Re-set video mode */
|
---|
1384 | vbvxReadSizesAndCursorIntegrationFromHGSMI(pScrn, NULL);
|
---|
1385 | vbvxReadSizesAndCursorIntegrationFromProperties(pScrn, NULL);
|
---|
1386 | /* This prevents a crash in CentOS 3. I was unable to debug it to
|
---|
1387 | * satisfaction, partly due to the lack of symbols. My guess is that
|
---|
1388 | * pScrn->ModifyPixmapHeader() expects certain things to be set up when
|
---|
1389 | * it sees pScrn->vtSema set to true which are not quite done at this
|
---|
1390 | * point of the VT switch. */
|
---|
1391 | pScrn->vtSema = FALSE;
|
---|
1392 | setSizesAndCursorIntegration(pScrn, false);
|
---|
1393 | pScrn->vtSema = TRUE;
|
---|
1394 | #ifdef SET_HAVE_VT_PROPERTY
|
---|
1395 | updateHasVTProperty(pScrn, TRUE);
|
---|
1396 | #endif
|
---|
1397 | return TRUE;
|
---|
1398 | }
|
---|
1399 |
|
---|
1400 | static void VBOXLeaveVT(ScrnInfoPtr pScrn)
|
---|
1401 | {
|
---|
1402 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1403 | #ifdef VBOXVIDEO_13
|
---|
1404 | unsigned i;
|
---|
1405 | #endif
|
---|
1406 |
|
---|
1407 | TRACE_ENTRY();
|
---|
1408 | #ifdef VBOXVIDEO_13
|
---|
1409 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1410 | vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff);
|
---|
1411 | #endif
|
---|
1412 | vboxDisableVbva(pScrn);
|
---|
1413 | vbvxClearVRAM(pScrn, pScrn->virtualX * pScrn->virtualY * pScrn->bitsPerPixel / 8, 0);
|
---|
1414 | #ifdef VBOX_DRI_OLD
|
---|
1415 | if (pVBox->useDRI)
|
---|
1416 | DRILock(xf86ScrnToScreen(pScrn), 0);
|
---|
1417 | #elif defined(VBOX_DRI) /* DRI2 */
|
---|
1418 | if (pVBox->drmFD >= 0)
|
---|
1419 | drmDropMaster(pVBox->drmFD);
|
---|
1420 | #endif
|
---|
1421 | VBOXRestoreMode(pScrn);
|
---|
1422 | #ifdef SET_HAVE_VT_PROPERTY
|
---|
1423 | updateHasVTProperty(pScrn, FALSE);
|
---|
1424 | #endif
|
---|
1425 | TRACE_EXIT();
|
---|
1426 | }
|
---|
1427 |
|
---|
1428 | static Bool VBOXCloseScreen(ScreenPtr pScreen)
|
---|
1429 | {
|
---|
1430 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
---|
1431 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1432 | #if defined(VBOX_DRI) && !defined(VBOX_DRI_OLD) /* DRI2 */
|
---|
1433 | BOOL fRestore = TRUE;
|
---|
1434 | #endif
|
---|
1435 | if (pScrn->vtSema)
|
---|
1436 | {
|
---|
1437 | #ifdef VBOXVIDEO_13
|
---|
1438 | unsigned i;
|
---|
1439 |
|
---|
1440 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1441 | vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff);
|
---|
1442 | #endif
|
---|
1443 | vboxDisableVbva(pScrn);
|
---|
1444 | vbvxClearVRAM(pScrn, pScrn->virtualX * pScrn->virtualY * pScrn->bitsPerPixel / 8, 0);
|
---|
1445 | }
|
---|
1446 | #ifdef VBOX_DRI
|
---|
1447 | # ifndef VBOX_DRI_OLD /* DRI2 */
|
---|
1448 | if ( pVBox->drmFD >= 0
|
---|
1449 | /* Tell the kernel driver, if present, that we are going away. */
|
---|
1450 | && drmIoctl(pVBox->drmFD, VBOXVIDEO_IOCTL_ENABLE_HGSMI, NULL) >= 0)
|
---|
1451 | fRestore = false;
|
---|
1452 | # endif
|
---|
1453 | if (pVBox->useDRI)
|
---|
1454 | VBOXDRICloseScreen(pScreen, pVBox);
|
---|
1455 | pVBox->useDRI = false;
|
---|
1456 | #endif
|
---|
1457 | #if defined(VBOX_DRI) && !defined(VBOX_DRI_OLD) /* DRI2 */
|
---|
1458 | if (fRestore)
|
---|
1459 | #endif
|
---|
1460 | if (pScrn->vtSema)
|
---|
1461 | VBOXRestoreMode(pScrn);
|
---|
1462 | if (pScrn->vtSema)
|
---|
1463 | VBOXUnmapVidMem(pScrn);
|
---|
1464 | pScrn->vtSema = FALSE;
|
---|
1465 |
|
---|
1466 | vbvxCursorTerm(pVBox);
|
---|
1467 |
|
---|
1468 | pScreen->CloseScreen = pVBox->CloseScreen;
|
---|
1469 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
1470 | vbvxCleanUpLinuxACPI(pScreen);
|
---|
1471 | #endif
|
---|
1472 | #ifndef XF86_SCRN_INTERFACE
|
---|
1473 | return pScreen->CloseScreen(pScreen->myNum, pScreen);
|
---|
1474 | #else
|
---|
1475 | return pScreen->CloseScreen(pScreen);
|
---|
1476 | #endif
|
---|
1477 | }
|
---|
1478 |
|
---|
1479 | static Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
|
---|
1480 | {
|
---|
1481 | VBOXPtr pVBox;
|
---|
1482 | Bool rc = TRUE;
|
---|
1483 |
|
---|
1484 | TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
|
---|
1485 | if (!pScrn->vtSema)
|
---|
1486 | {
|
---|
1487 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
1488 | "We do not own the active VT, exiting.\n");
|
---|
1489 | return TRUE;
|
---|
1490 | }
|
---|
1491 | #ifdef VBOXVIDEO_13
|
---|
1492 | rc = xf86SetSingleMode(pScrn, pMode, RR_Rotate_0);
|
---|
1493 | #else
|
---|
1494 | setModeRandR11(pScrn, pMode, false);
|
---|
1495 | #endif
|
---|
1496 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1497 | return rc;
|
---|
1498 | }
|
---|
1499 |
|
---|
1500 | static void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
|
---|
1501 | { (void)pScrn; (void)x; (void)y; }
|
---|
1502 |
|
---|
1503 | static void VBOXFreeScreen(ScrnInfoPtr pScrn)
|
---|
1504 | {
|
---|
1505 | /* Destroy the VGA hardware record */
|
---|
1506 | vgaHWFreeHWRec(pScrn);
|
---|
1507 | /* And our private record */
|
---|
1508 | free(pScrn->driverPrivate);
|
---|
1509 | pScrn->driverPrivate = NULL;
|
---|
1510 | }
|
---|
1511 |
|
---|
1512 | static Bool
|
---|
1513 | VBOXMapVidMem(ScrnInfoPtr pScrn)
|
---|
1514 | {
|
---|
1515 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1516 | Bool rc = TRUE;
|
---|
1517 |
|
---|
1518 | TRACE_ENTRY();
|
---|
1519 | if (!pVBox->base)
|
---|
1520 | {
|
---|
1521 | #ifdef PCIACCESS
|
---|
1522 | (void) pci_device_map_range(pVBox->pciInfo,
|
---|
1523 | pScrn->memPhysBase,
|
---|
1524 | pScrn->videoRam * 1024,
|
---|
1525 | PCI_DEV_MAP_FLAG_WRITABLE,
|
---|
1526 | & pVBox->base);
|
---|
1527 | #else
|
---|
1528 | pVBox->base = xf86MapPciMem(pScrn->scrnIndex,
|
---|
1529 | VIDMEM_FRAMEBUFFER,
|
---|
1530 | pVBox->pciTag, pScrn->memPhysBase,
|
---|
1531 | (unsigned) pScrn->videoRam * 1024);
|
---|
1532 | #endif
|
---|
1533 | if (!pVBox->base)
|
---|
1534 | rc = FALSE;
|
---|
1535 | }
|
---|
1536 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1537 | return rc;
|
---|
1538 | }
|
---|
1539 |
|
---|
1540 | static void
|
---|
1541 | VBOXUnmapVidMem(ScrnInfoPtr pScrn)
|
---|
1542 | {
|
---|
1543 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1544 |
|
---|
1545 | TRACE_ENTRY();
|
---|
1546 | if (pVBox->base == NULL)
|
---|
1547 | return;
|
---|
1548 |
|
---|
1549 | #ifdef PCIACCESS
|
---|
1550 | (void) pci_device_unmap_range(pVBox->pciInfo,
|
---|
1551 | pVBox->base,
|
---|
1552 | pScrn->videoRam * 1024);
|
---|
1553 | #else
|
---|
1554 | xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base,
|
---|
1555 | (unsigned) pScrn->videoRam * 1024);
|
---|
1556 | #endif
|
---|
1557 | pVBox->base = NULL;
|
---|
1558 | TRACE_EXIT();
|
---|
1559 | }
|
---|
1560 |
|
---|
1561 | static Bool
|
---|
1562 | VBOXSaveScreen(ScreenPtr pScreen, int mode)
|
---|
1563 | {
|
---|
1564 | (void)pScreen; (void)mode;
|
---|
1565 | return TRUE;
|
---|
1566 | }
|
---|
1567 |
|
---|
1568 | void
|
---|
1569 | VBOXSaveMode(ScrnInfoPtr pScrn)
|
---|
1570 | {
|
---|
1571 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1572 | vgaRegPtr vgaReg;
|
---|
1573 |
|
---|
1574 | TRACE_ENTRY();
|
---|
1575 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1576 | vgaHWSave(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1577 | pVBox->fSavedVBEMode = VBoxVideoGetModeRegisters(&pVBox->cSavedWidth,
|
---|
1578 | &pVBox->cSavedHeight,
|
---|
1579 | &pVBox->cSavedPitch,
|
---|
1580 | &pVBox->cSavedBPP,
|
---|
1581 | &pVBox->fSavedFlags);
|
---|
1582 | }
|
---|
1583 |
|
---|
1584 | void
|
---|
1585 | VBOXRestoreMode(ScrnInfoPtr pScrn)
|
---|
1586 | {
|
---|
1587 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1588 | vgaRegPtr vgaReg;
|
---|
1589 | #ifdef VBOX_DRI
|
---|
1590 | drmModeResPtr pRes;
|
---|
1591 | #endif
|
---|
1592 |
|
---|
1593 | TRACE_ENTRY();
|
---|
1594 | #ifdef VBOX_DRI
|
---|
1595 | /* Do not try to re-set the VGA state if a mode-setting driver is loaded. */
|
---|
1596 | if ( pVBox->drmFD >= 0
|
---|
1597 | && LoaderSymbol("drmModeGetResources") != NULL
|
---|
1598 | && (pRes = drmModeGetResources(pVBox->drmFD)) != NULL)
|
---|
1599 | {
|
---|
1600 | drmModeFreeResources(pRes);
|
---|
1601 | return;
|
---|
1602 | }
|
---|
1603 | #endif
|
---|
1604 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1605 | vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1606 | if (pVBox->fSavedVBEMode)
|
---|
1607 | VBoxVideoSetModeRegisters(pVBox->cSavedWidth, pVBox->cSavedHeight,
|
---|
1608 | pVBox->cSavedPitch, pVBox->cSavedBPP,
|
---|
1609 | pVBox->fSavedFlags, 0, 0);
|
---|
1610 | else
|
---|
1611 | VBoxVideoDisableVBE();
|
---|
1612 | }
|
---|
1613 |
|
---|
1614 | static void
|
---|
1615 | VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode,
|
---|
1616 | int flags)
|
---|
1617 | {
|
---|
1618 | (void)pScrn; (void)mode; (void) flags;
|
---|
1619 | }
|
---|