1 | /* $Id: vboxvideo.c 69064 2017-10-12 18:18:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Linux Additions X11 graphics driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This code is based on the X.Org VESA driver with the following copyrights:
|
---|
10 | *
|
---|
11 | * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com)
|
---|
12 | * Copyright 2008 Red Hat, Inc.
|
---|
13 | * Copyright 2012 Red Hat, Inc.
|
---|
14 | *
|
---|
15 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
16 | * copy of this software and associated documentation files (the "Software"),
|
---|
17 | * to deal in the Software without restriction, including without limitation
|
---|
18 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
19 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
20 | * Software is furnished to do so, subject to the following conditions:
|
---|
21 | *
|
---|
22 | * The above copyright notice and this permission notice shall be included in
|
---|
23 | * all copies or substantial portions of the Software.
|
---|
24 | *
|
---|
25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
27 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
---|
28 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
---|
29 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
---|
30 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
---|
31 | * USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
32 | *
|
---|
33 | * Except as contained in this notice, the name of Conectiva Linux shall
|
---|
34 | * not be used in advertising or otherwise to promote the sale, use or other
|
---|
35 | * dealings in this Software without prior written authorization from
|
---|
36 | * Conectiva Linux.
|
---|
37 | *
|
---|
38 | * Authors: Paulo César Pereira de Andrade <[email protected]>
|
---|
39 | * David Dawes <[email protected]>
|
---|
40 | * Adam Jackson <[email protected]>
|
---|
41 | * Dave Airlie <[email protected]>
|
---|
42 | * Michael Thayer <[email protected]>
|
---|
43 | */
|
---|
44 |
|
---|
45 | #include "vboxvideo.h"
|
---|
46 | #include <VBox/param.h> /* for VBOX_DEVICEID and VBOX_VENDORID */
|
---|
47 | #include <VBox/VBoxGuestLib.h>
|
---|
48 | #include <VBoxVideoVBE.h>
|
---|
49 | #include "version-generated.h"
|
---|
50 | #include "product-generated.h"
|
---|
51 | #include "revision-generated.h"
|
---|
52 |
|
---|
53 | /* Basic definitions and functions needed by all drivers. */
|
---|
54 | #include "xf86.h"
|
---|
55 | /* For video memory mapping. */
|
---|
56 | #include "xf86_OSproc.h"
|
---|
57 | #if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
|
---|
58 | /* PCI resources. */
|
---|
59 | # include "xf86Resources.h"
|
---|
60 | #endif
|
---|
61 | /* Generic server linear frame-buffer APIs. */
|
---|
62 | #include "fb.h"
|
---|
63 | /* Colormap and visual handling. */
|
---|
64 | #include "micmap.h"
|
---|
65 | #include "xf86cmap.h"
|
---|
66 | /* ShadowFB support */
|
---|
67 | #include "shadowfb.h"
|
---|
68 | /* VGA hardware functions for setting and restoring text mode */
|
---|
69 | #include "vgaHW.h"
|
---|
70 | #ifdef VBOXVIDEO_13
|
---|
71 | /* X.org 1.3+ mode setting */
|
---|
72 | # define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */
|
---|
73 | # include "xf86Crtc.h"
|
---|
74 | # include "xf86Modes.h"
|
---|
75 | /* For xf86RandR12GetOriginalVirtualSize(). */
|
---|
76 | # include "xf86RandR12.h"
|
---|
77 | #endif
|
---|
78 | /* For setting the root window property. */
|
---|
79 | #include "property.h"
|
---|
80 | #include "X11/Xatom.h"
|
---|
81 |
|
---|
82 | #ifdef XORG_7X
|
---|
83 | # include <stdlib.h>
|
---|
84 | # include <string.h>
|
---|
85 | # include <fcntl.h>
|
---|
86 | # include <unistd.h>
|
---|
87 | #endif
|
---|
88 |
|
---|
89 | /* Mandatory functions */
|
---|
90 |
|
---|
91 | static const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid);
|
---|
92 | static void VBOXIdentify(int flags);
|
---|
93 | #ifndef PCIACCESS
|
---|
94 | static Bool VBOXProbe(DriverPtr drv, int flags);
|
---|
95 | #else
|
---|
96 | static Bool VBOXPciProbe(DriverPtr drv, int entity_num,
|
---|
97 | struct pci_device *dev, intptr_t match_data);
|
---|
98 | #endif
|
---|
99 | static Bool VBOXPreInit(ScrnInfoPtr pScrn, int flags);
|
---|
100 | static Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv);
|
---|
101 | static Bool VBOXEnterVT(ScrnInfoPtr pScrn);
|
---|
102 | static void VBOXLeaveVT(ScrnInfoPtr pScrn);
|
---|
103 | static Bool VBOXCloseScreen(ScreenPtr pScreen);
|
---|
104 | #ifndef VBOXVIDEO_13
|
---|
105 | static Bool VBOXSaveScreen(ScreenPtr pScreen, int mode);
|
---|
106 | #endif
|
---|
107 | static Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode);
|
---|
108 | static void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y);
|
---|
109 | static void VBOXFreeScreen(ScrnInfoPtr pScrn);
|
---|
110 | #ifndef VBOXVIDEO_13
|
---|
111 | static void VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode, int flags);
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | /* locally used functions */
|
---|
115 | static Bool VBOXMapVidMem(ScrnInfoPtr pScrn);
|
---|
116 | static void VBOXUnmapVidMem(ScrnInfoPtr pScrn);
|
---|
117 | static void VBOXSaveMode(ScrnInfoPtr pScrn);
|
---|
118 | static void VBOXRestoreMode(ScrnInfoPtr pScrn);
|
---|
119 | static void setSizesAndCursorIntegration(ScrnInfoPtr pScrn, Bool fScreenInitTime);
|
---|
120 |
|
---|
121 | #ifndef XF86_SCRN_INTERFACE
|
---|
122 | # define xf86ScreenToScrn(pScreen) xf86Screens[(pScreen)->myNum]
|
---|
123 | # define xf86ScrnToScreen(pScrn) screenInfo.screens[(pScrn)->scrnIndex]
|
---|
124 | #endif
|
---|
125 |
|
---|
126 | static inline void VBOXSetRec(ScrnInfoPtr pScrn)
|
---|
127 | {
|
---|
128 | if (!pScrn->driverPrivate)
|
---|
129 | {
|
---|
130 | VBOXPtr pVBox = (VBOXPtr)xnfcalloc(sizeof(VBOXRec), 1);
|
---|
131 | pScrn->driverPrivate = pVBox;
|
---|
132 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
133 | pVBox->fdACPIDevices = -1;
|
---|
134 | #endif
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | enum GenericTypes
|
---|
139 | {
|
---|
140 | CHIP_VBOX_GENERIC
|
---|
141 | };
|
---|
142 |
|
---|
143 | #ifdef PCIACCESS
|
---|
144 | static const struct pci_id_match vbox_device_match[] = {
|
---|
145 | {
|
---|
146 | VBOX_VENDORID, VBOX_DEVICEID, PCI_MATCH_ANY, PCI_MATCH_ANY,
|
---|
147 | 0, 0, 0
|
---|
148 | },
|
---|
149 |
|
---|
150 | { 0, 0, 0 },
|
---|
151 | };
|
---|
152 | #endif
|
---|
153 |
|
---|
154 | /* Supported chipsets */
|
---|
155 | static SymTabRec VBOXChipsets[] =
|
---|
156 | {
|
---|
157 | {VBOX_DEVICEID, "vbox"},
|
---|
158 | {-1, NULL}
|
---|
159 | };
|
---|
160 |
|
---|
161 | static PciChipsets VBOXPCIchipsets[] = {
|
---|
162 | { VBOX_DEVICEID, VBOX_DEVICEID, RES_SHARED_VGA },
|
---|
163 | { -1, -1, RES_UNDEFINED },
|
---|
164 | };
|
---|
165 |
|
---|
166 | /*
|
---|
167 | * This contains the functions needed by the server after loading the
|
---|
168 | * driver module. It must be supplied, and gets added the driver list by
|
---|
169 | * the Module Setup function in the dynamic case. In the static case a
|
---|
170 | * reference to this is compiled in, and this requires that the name of
|
---|
171 | * this DriverRec be an upper-case version of the driver name.
|
---|
172 | */
|
---|
173 |
|
---|
174 | #ifdef XORG_7X
|
---|
175 | _X_EXPORT
|
---|
176 | #endif
|
---|
177 | DriverRec VBOXVIDEO = {
|
---|
178 | VBOX_VERSION,
|
---|
179 | VBOX_DRIVER_NAME,
|
---|
180 | VBOXIdentify,
|
---|
181 | #ifdef PCIACCESS
|
---|
182 | NULL,
|
---|
183 | #else
|
---|
184 | VBOXProbe,
|
---|
185 | #endif
|
---|
186 | VBOXAvailableOptions,
|
---|
187 | NULL,
|
---|
188 | 0,
|
---|
189 | #ifdef XORG_7X
|
---|
190 | NULL,
|
---|
191 | #endif
|
---|
192 | #ifdef PCIACCESS
|
---|
193 | vbox_device_match,
|
---|
194 | VBOXPciProbe
|
---|
195 | #endif
|
---|
196 | };
|
---|
197 |
|
---|
198 | /* No options for now */
|
---|
199 | static const OptionInfoRec VBOXOptions[] = {
|
---|
200 | { -1, NULL, OPTV_NONE, {0}, FALSE }
|
---|
201 | };
|
---|
202 |
|
---|
203 | #ifndef XORG_7X
|
---|
204 | /*
|
---|
205 | * List of symbols from other modules that this module references. This
|
---|
206 | * list is used to tell the loader that it is OK for symbols here to be
|
---|
207 | * unresolved providing that it hasn't been told that they haven't been
|
---|
208 | * told that they are essential via a call to xf86LoaderReqSymbols() or
|
---|
209 | * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about
|
---|
210 | * unresolved symbols that are not required.
|
---|
211 | */
|
---|
212 | static const char *fbSymbols[] = {
|
---|
213 | "fbPictureInit",
|
---|
214 | "fbScreenInit",
|
---|
215 | NULL
|
---|
216 | };
|
---|
217 |
|
---|
218 | static const char *shadowfbSymbols[] = {
|
---|
219 | "ShadowFBInit2",
|
---|
220 | NULL
|
---|
221 | };
|
---|
222 |
|
---|
223 | static const char *ramdacSymbols[] = {
|
---|
224 | "xf86DestroyCursorInfoRec",
|
---|
225 | "xf86InitCursor",
|
---|
226 | "xf86CreateCursorInfoRec",
|
---|
227 | NULL
|
---|
228 | };
|
---|
229 |
|
---|
230 | static const char *vgahwSymbols[] = {
|
---|
231 | "vgaHWFreeHWRec",
|
---|
232 | "vgaHWGetHWRec",
|
---|
233 | "vgaHWGetIOBase",
|
---|
234 | "vgaHWGetIndex",
|
---|
235 | "vgaHWRestore",
|
---|
236 | "vgaHWSave",
|
---|
237 | "vgaHWSetStdFuncs",
|
---|
238 | NULL
|
---|
239 | };
|
---|
240 | #endif /* !XORG_7X */
|
---|
241 |
|
---|
242 | /** Resize the virtual framebuffer. */
|
---|
243 | static Bool adjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height)
|
---|
244 | {
|
---|
245 | ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
|
---|
246 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
247 | int adjustedWidth = pScrn->bitsPerPixel == 16 ? (width + 1) & ~1 : width;
|
---|
248 | int cbLine = adjustedWidth * pScrn->bitsPerPixel / 8;
|
---|
249 | PixmapPtr pPixmap;
|
---|
250 |
|
---|
251 | TRACE_LOG("width=%d, height=%d\n", width, height);
|
---|
252 | VBVXASSERT(width >= 0 && height >= 0, ("Invalid negative width (%d) or height (%d)\n", width, height));
|
---|
253 | if (pScreen == NULL) /* Not yet initialised. */
|
---|
254 | return TRUE;
|
---|
255 | pPixmap = pScreen->GetScreenPixmap(pScreen);
|
---|
256 | VBVXASSERT(pPixmap != NULL, ("Failed to get the screen pixmap.\n"));
|
---|
257 | 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",
|
---|
258 | pPixmap, adjustedWidth, height, pScrn->depth, pScrn->bitsPerPixel, cbLine, pVBox->base, pPixmap->drawable.width,
|
---|
259 | pPixmap->drawable.height);
|
---|
260 | if ( adjustedWidth != pPixmap->drawable.width
|
---|
261 | || height != pPixmap->drawable.height)
|
---|
262 | {
|
---|
263 | if ( adjustedWidth > VBOX_VIDEO_MAX_VIRTUAL || height > VBOX_VIDEO_MAX_VIRTUAL
|
---|
264 | || (unsigned)cbLine * (unsigned)height >= pVBox->cbFBMax)
|
---|
265 | {
|
---|
266 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
267 | "Virtual framebuffer %dx%d too large. For information, video memory: %u Kb.\n",
|
---|
268 | adjustedWidth, height, (unsigned) pVBox->cbFBMax / 1024);
|
---|
269 | return FALSE;
|
---|
270 | }
|
---|
271 | if (pScrn->vtSema)
|
---|
272 | vbvxClearVRAM(pScrn, ((size_t)pScrn->virtualX) * pScrn->virtualY * (pScrn->bitsPerPixel / 8),
|
---|
273 | ((size_t)adjustedWidth) * height * (pScrn->bitsPerPixel / 8));
|
---|
274 | pScreen->ModifyPixmapHeader(pPixmap, adjustedWidth, height, pScrn->depth, pScrn->bitsPerPixel, cbLine, pVBox->base);
|
---|
275 | }
|
---|
276 | pScrn->displayWidth = pScrn->virtualX = adjustedWidth;
|
---|
277 | pScrn->virtualY = height;
|
---|
278 | return TRUE;
|
---|
279 | }
|
---|
280 |
|
---|
281 | #ifndef VBOXVIDEO_13
|
---|
282 | /** Set a video mode to the hardware, RandR 1.1 version.
|
---|
283 | *
|
---|
284 | * Since we no longer do virtual frame buffers, adjust the screen pixmap
|
---|
285 | * dimensions to match. The "override" parameters are for when we received a
|
---|
286 | * mode hint while switched to a virtual terminal. In this case VBoxClient will
|
---|
287 | * have told us about the mode, but not yet been able to do a mode switch using
|
---|
288 | * RandR. We solve this by setting the requested mode to the host but keeping
|
---|
289 | * the virtual frame-
|
---|
290 | * buffer matching what the X server expects. */
|
---|
291 | static void setModeRandR11(ScrnInfoPtr pScrn, DisplayModePtr pMode, Bool fScreenInitTime, Bool fEnterVTTime,
|
---|
292 | int cXOverRide, int cYOverRide)
|
---|
293 | {
|
---|
294 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
295 | struct vbvxFrameBuffer frameBuffer = { 0, 0, pMode->HDisplay, pMode->VDisplay, pScrn->bitsPerPixel};
|
---|
296 | int cXPhysical = cXOverRide > 0 ? min(cXOverRide, pMode->HDisplay) : pMode->HDisplay;
|
---|
297 | int cYPhysical = cYOverRide > 0 ? min(cYOverRide, pMode->VDisplay) : pMode->VDisplay;
|
---|
298 |
|
---|
299 | pVBox->pScreens[0].aScreenLocation.cx = pMode->HDisplay;
|
---|
300 | pVBox->pScreens[0].aScreenLocation.cy = pMode->VDisplay;
|
---|
301 | if (fScreenInitTime)
|
---|
302 | {
|
---|
303 | /* The screen structure is not fully set up yet, so do not touch it. */
|
---|
304 | pScrn->displayWidth = pScrn->virtualX = pMode->HDisplay;
|
---|
305 | pScrn->virtualY = pMode->VDisplay;
|
---|
306 | }
|
---|
307 | else
|
---|
308 | {
|
---|
309 | xf86ScrnToScreen(pScrn)->width = pMode->HDisplay;
|
---|
310 | xf86ScrnToScreen(pScrn)->height = pMode->VDisplay;
|
---|
311 | /* This prevents a crash in CentOS 3. I was unable to debug it to
|
---|
312 | * satisfaction, partly due to the lack of symbols. My guess is that
|
---|
313 | * pScrn->ModifyPixmapHeader() expects certain things to be set up when
|
---|
314 | * it sees pScrn->vtSema set to true which are not quite done at this
|
---|
315 | * point of the VT switch. */
|
---|
316 | if (fEnterVTTime)
|
---|
317 | pScrn->vtSema = FALSE;
|
---|
318 | adjustScreenPixmap(pScrn, pMode->HDisplay, pMode->VDisplay);
|
---|
319 | if (fEnterVTTime)
|
---|
320 | pScrn->vtSema = TRUE;
|
---|
321 | }
|
---|
322 | if (pMode->HDisplay != 0 && pMode->VDisplay != 0 && pScrn->vtSema)
|
---|
323 | vbvxSetMode(pScrn, 0, cXPhysical, cYPhysical, 0, 0, true, true, &frameBuffer);
|
---|
324 | pScrn->currentMode = pMode;
|
---|
325 | }
|
---|
326 | #endif
|
---|
327 |
|
---|
328 | #ifdef VBOXVIDEO_13
|
---|
329 | /* X.org 1.3+ mode-setting support ******************************************/
|
---|
330 |
|
---|
331 | /** Set a video mode to the hardware, RandR 1.2 version. If this is the first
|
---|
332 | * screen, re-set the current mode for all others (the offset for the first
|
---|
333 | * screen is always treated as zero by the hardware, so all other screens need
|
---|
334 | * to be changed to compensate for any changes!). The mode to set is taken
|
---|
335 | * from the X.Org Crtc structure. */
|
---|
336 | static void setModeRandR12(ScrnInfoPtr pScrn, unsigned cScreen)
|
---|
337 | {
|
---|
338 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
339 | unsigned i;
|
---|
340 | struct vbvxFrameBuffer frameBuffer = { pVBox->pScreens[0].paCrtcs->x, pVBox->pScreens[0].paCrtcs->y, pScrn->virtualX,
|
---|
341 | pScrn->virtualY, pScrn->bitsPerPixel };
|
---|
342 | unsigned cFirst = cScreen;
|
---|
343 | unsigned cLast = cScreen != 0 ? cScreen + 1 : pVBox->cScreens;
|
---|
344 | int originalX, originalY;
|
---|
345 |
|
---|
346 | /* Check that this code cannot trigger the resizing bug in X.Org Server 1.3.
|
---|
347 | * See the work-around in ScreenInit. */
|
---|
348 | xf86RandR12GetOriginalVirtualSize(pScrn, &originalX, &originalY);
|
---|
349 | VBVXASSERT(originalX == VBOX_VIDEO_MAX_VIRTUAL && originalY == VBOX_VIDEO_MAX_VIRTUAL, ("OriginalSize=%dx%d",
|
---|
350 | originalX, originalY));
|
---|
351 | for (i = cFirst; i < cLast; ++i)
|
---|
352 | if (pVBox->pScreens[i].paCrtcs->mode.HDisplay != 0 && pVBox->pScreens[i].paCrtcs->mode.VDisplay != 0 && pScrn->vtSema)
|
---|
353 | vbvxSetMode(pScrn, i, pVBox->pScreens[i].paCrtcs->mode.HDisplay, pVBox->pScreens[i].paCrtcs->mode.VDisplay,
|
---|
354 | pVBox->pScreens[i].paCrtcs->x, pVBox->pScreens[i].paCrtcs->y, pVBox->pScreens[i].fPowerOn,
|
---|
355 | pVBox->pScreens[i].paOutputs->status == XF86OutputStatusConnected, &frameBuffer);
|
---|
356 | }
|
---|
357 |
|
---|
358 | /** Wrapper around setModeRandR12() to avoid exposing non-obvious semantics.
|
---|
359 | */
|
---|
360 | static void setAllModesRandR12(ScrnInfoPtr pScrn)
|
---|
361 | {
|
---|
362 | setModeRandR12(pScrn, 0);
|
---|
363 | }
|
---|
364 |
|
---|
365 | /* For descriptions of these functions and structures, see
|
---|
366 | hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the
|
---|
367 | X.Org source tree. */
|
---|
368 |
|
---|
369 | static Bool vbox_config_resize(ScrnInfoPtr pScrn, int cw, int ch)
|
---|
370 | {
|
---|
371 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
372 | Bool rc;
|
---|
373 | unsigned i;
|
---|
374 |
|
---|
375 | TRACE_LOG("width=%d, height=%d\n", cw, ch);
|
---|
376 | rc = adjustScreenPixmap(pScrn, cw, ch);
|
---|
377 | /* Power-on all screens (the server expects this) and set the new pitch to them. */
|
---|
378 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
379 | pVBox->pScreens[i].fPowerOn = true;
|
---|
380 | setAllModesRandR12(pScrn);
|
---|
381 | vbvxSetSolarisMouseRange(cw, ch);
|
---|
382 | return rc;
|
---|
383 | }
|
---|
384 |
|
---|
385 | static const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = {
|
---|
386 | vbox_config_resize
|
---|
387 | };
|
---|
388 |
|
---|
389 | static void
|
---|
390 | vbox_crtc_dpms(xf86CrtcPtr crtc, int mode)
|
---|
391 | {
|
---|
392 | ScrnInfoPtr pScrn = crtc->scrn;
|
---|
393 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
394 | unsigned cDisplay = (uintptr_t)crtc->driver_private;
|
---|
395 |
|
---|
396 | TRACE_LOG("mode=%d\n", mode);
|
---|
397 | pVBox->pScreens[cDisplay].fPowerOn = (mode != DPMSModeOff);
|
---|
398 | setModeRandR12(pScrn, cDisplay);
|
---|
399 | }
|
---|
400 |
|
---|
401 | static Bool
|
---|
402 | vbox_crtc_lock (xf86CrtcPtr crtc)
|
---|
403 | { (void) crtc; return FALSE; }
|
---|
404 |
|
---|
405 |
|
---|
406 | /* We use this function to check whether the X server owns the active virtual
|
---|
407 | * terminal before attempting a mode switch, since the RandR extension isn't
|
---|
408 | * very dilligent here, which can mean crashes if we are unlucky. This is
|
---|
409 | * not the way it the function is intended - it is meant for reporting modes
|
---|
410 | * which the hardware can't handle. I hope that this won't confuse any clients
|
---|
411 | * connecting to us. */
|
---|
412 | static Bool
|
---|
413 | vbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
414 | DisplayModePtr adjusted_mode)
|
---|
415 | { (void) crtc; (void) mode; (void) adjusted_mode; return TRUE; }
|
---|
416 |
|
---|
417 | static void
|
---|
418 | vbox_crtc_stub (xf86CrtcPtr crtc)
|
---|
419 | { (void) crtc; }
|
---|
420 |
|
---|
421 | static void
|
---|
422 | vbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode,
|
---|
423 | DisplayModePtr adjusted_mode, int x, int y)
|
---|
424 | {
|
---|
425 | (void) mode;
|
---|
426 | VBOXPtr pVBox = VBOXGetRec(crtc->scrn);
|
---|
427 | unsigned cDisplay = (uintptr_t)crtc->driver_private;
|
---|
428 |
|
---|
429 | TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name,
|
---|
430 | adjusted_mode->HDisplay, adjusted_mode->VDisplay, x, y);
|
---|
431 | pVBox->pScreens[cDisplay].fPowerOn = true;
|
---|
432 | pVBox->pScreens[cDisplay].aScreenLocation.cx = adjusted_mode->HDisplay;
|
---|
433 | pVBox->pScreens[cDisplay].aScreenLocation.cy = adjusted_mode->VDisplay;
|
---|
434 | pVBox->pScreens[cDisplay].aScreenLocation.x = x;
|
---|
435 | pVBox->pScreens[cDisplay].aScreenLocation.y = y;
|
---|
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 | DisplayModePtr pModes = NULL;
|
---|
548 | DisplayModePtr pPreferred = NULL;
|
---|
549 | ScrnInfoPtr pScrn = output->scrn;
|
---|
550 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
551 |
|
---|
552 | TRACE_ENTRY();
|
---|
553 | uint32_t iScreen = (uintptr_t)output->driver_private;
|
---|
554 | pPreferred = vbox_output_add_mode(pVBox, &pModes, NULL,
|
---|
555 | RT_CLAMP(pVBox->pScreens[iScreen].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL),
|
---|
556 | RT_CLAMP(pVBox->pScreens[iScreen].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL),
|
---|
557 | TRUE, FALSE);
|
---|
558 | vbox_output_add_mode(pVBox, &pModes, NULL, 2560, 1600, FALSE, FALSE);
|
---|
559 | vbox_output_add_mode(pVBox, &pModes, NULL, 2560, 1440, FALSE, FALSE);
|
---|
560 | vbox_output_add_mode(pVBox, &pModes, NULL, 2048, 1536, FALSE, FALSE);
|
---|
561 | vbox_output_add_mode(pVBox, &pModes, NULL, 1920, 1600, FALSE, FALSE);
|
---|
562 | vbox_output_add_mode(pVBox, &pModes, NULL, 1920, 1080, FALSE, FALSE);
|
---|
563 | vbox_output_add_mode(pVBox, &pModes, NULL, 1680, 1050, FALSE, FALSE);
|
---|
564 | vbox_output_add_mode(pVBox, &pModes, NULL, 1600, 1200, FALSE, FALSE);
|
---|
565 | vbox_output_add_mode(pVBox, &pModes, NULL, 1400, 1050, FALSE, FALSE);
|
---|
566 | vbox_output_add_mode(pVBox, &pModes, NULL, 1280, 1024, FALSE, FALSE);
|
---|
567 | vbox_output_add_mode(pVBox, &pModes, NULL, 1024, 768, FALSE, FALSE);
|
---|
568 | vbox_output_add_mode(pVBox, &pModes, NULL, 800, 600, FALSE, FALSE);
|
---|
569 | vbox_output_add_mode(pVBox, &pModes, NULL, 640, 480, FALSE, FALSE);
|
---|
570 | VBOXEDIDSet(output, pPreferred);
|
---|
571 | TRACE_EXIT();
|
---|
572 | return pModes;
|
---|
573 | }
|
---|
574 |
|
---|
575 | static const xf86OutputFuncsRec VBOXOutputFuncs = {
|
---|
576 | .create_resources = vbox_output_stub,
|
---|
577 | .dpms = vbox_output_dpms,
|
---|
578 | .save = NULL, /* These two are never called by the server. */
|
---|
579 | .restore = NULL,
|
---|
580 | .mode_valid = vbox_output_mode_valid,
|
---|
581 | .mode_fixup = vbox_output_mode_fixup,
|
---|
582 | .prepare = vbox_output_stub,
|
---|
583 | .commit = vbox_output_stub,
|
---|
584 | .mode_set = vbox_output_mode_set,
|
---|
585 | .detect = vbox_output_detect,
|
---|
586 | .get_modes = vbox_output_get_modes,
|
---|
587 | #ifdef RANDR_12_INTERFACE
|
---|
588 | .set_property = NULL,
|
---|
589 | #endif
|
---|
590 | .destroy = vbox_output_stub
|
---|
591 | };
|
---|
592 | #endif /* VBOXVIDEO_13 */
|
---|
593 |
|
---|
594 | /* Module loader interface */
|
---|
595 | static MODULESETUPPROTO(vboxSetup);
|
---|
596 |
|
---|
597 | static XF86ModuleVersionInfo vboxVersionRec =
|
---|
598 | {
|
---|
599 | VBOX_DRIVER_NAME,
|
---|
600 | VBOX_VENDOR,
|
---|
601 | MODINFOSTRING1,
|
---|
602 | MODINFOSTRING2,
|
---|
603 | #ifdef XORG_7X
|
---|
604 | XORG_VERSION_CURRENT,
|
---|
605 | #else
|
---|
606 | XF86_VERSION_CURRENT,
|
---|
607 | #endif
|
---|
608 | 1, /* Module major version. Xorg-specific */
|
---|
609 | 0, /* Module minor version. Xorg-specific */
|
---|
610 | 1, /* Module patchlevel. Xorg-specific */
|
---|
611 | ABI_CLASS_VIDEODRV, /* This is a video driver */
|
---|
612 | ABI_VIDEODRV_VERSION,
|
---|
613 | MOD_CLASS_VIDEODRV,
|
---|
614 | {0, 0, 0, 0}
|
---|
615 | };
|
---|
616 |
|
---|
617 | /*
|
---|
618 | * This data is accessed by the loader. The name must be the module name
|
---|
619 | * followed by "ModuleData".
|
---|
620 | */
|
---|
621 | #ifdef XORG_7X
|
---|
622 | _X_EXPORT
|
---|
623 | #endif
|
---|
624 | XF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL };
|
---|
625 |
|
---|
626 | static pointer
|
---|
627 | vboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor)
|
---|
628 | {
|
---|
629 | static Bool Initialised = FALSE;
|
---|
630 | RT_NOREF(Options, ErrorMinor);
|
---|
631 |
|
---|
632 | if (!Initialised)
|
---|
633 | {
|
---|
634 | Initialised = TRUE;
|
---|
635 | #ifdef PCIACCESS
|
---|
636 | xf86AddDriver(&VBOXVIDEO, Module, HaveDriverFuncs);
|
---|
637 | #else
|
---|
638 | xf86AddDriver(&VBOXVIDEO, Module, 0);
|
---|
639 | #endif
|
---|
640 | #ifndef XORG_7X
|
---|
641 | LoaderRefSymLists(fbSymbols,
|
---|
642 | shadowfbSymbols,
|
---|
643 | ramdacSymbols,
|
---|
644 | vgahwSymbols,
|
---|
645 | NULL);
|
---|
646 | #endif
|
---|
647 | xf86Msg(X_CONFIG, "Load address of symbol \"VBOXVIDEO\" is %p\n",
|
---|
648 | (void *)&VBOXVIDEO);
|
---|
649 | return (pointer)TRUE;
|
---|
650 | }
|
---|
651 |
|
---|
652 | if (ErrorMajor)
|
---|
653 | *ErrorMajor = LDR_ONCEONLY;
|
---|
654 | return (NULL);
|
---|
655 | }
|
---|
656 |
|
---|
657 |
|
---|
658 | static const OptionInfoRec *
|
---|
659 | VBOXAvailableOptions(int chipid, int busid)
|
---|
660 | {
|
---|
661 | RT_NOREF(chipid, busid);
|
---|
662 | return (VBOXOptions);
|
---|
663 | }
|
---|
664 |
|
---|
665 | static void
|
---|
666 | VBOXIdentify(int flags)
|
---|
667 | {
|
---|
668 | RT_NOREF(flags);
|
---|
669 | xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets);
|
---|
670 | }
|
---|
671 |
|
---|
672 | #ifndef XF86_SCRN_INTERFACE
|
---|
673 | # define SCRNINDEXAPI(pfn) pfn ## Index
|
---|
674 | static Bool VBOXScreenInitIndex(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
|
---|
675 | {
|
---|
676 | RT_NOREF(scrnIndex);
|
---|
677 | return VBOXScreenInit(pScreen, argc, argv);
|
---|
678 | }
|
---|
679 |
|
---|
680 | static Bool VBOXEnterVTIndex(int scrnIndex, int flags)
|
---|
681 | { (void) flags; return VBOXEnterVT(xf86Screens[scrnIndex]); }
|
---|
682 |
|
---|
683 | static void VBOXLeaveVTIndex(int scrnIndex, int flags)
|
---|
684 | { (void) flags; VBOXLeaveVT(xf86Screens[scrnIndex]); }
|
---|
685 |
|
---|
686 | static Bool VBOXCloseScreenIndex(int scrnIndex, ScreenPtr pScreen)
|
---|
687 | { (void) scrnIndex; return VBOXCloseScreen(pScreen); }
|
---|
688 |
|
---|
689 | static Bool VBOXSwitchModeIndex(int scrnIndex, DisplayModePtr pMode, int flags)
|
---|
690 | { (void) flags; return VBOXSwitchMode(xf86Screens[scrnIndex], pMode); }
|
---|
691 |
|
---|
692 | static void VBOXAdjustFrameIndex(int scrnIndex, int x, int y, int flags)
|
---|
693 | { (void) flags; VBOXAdjustFrame(xf86Screens[scrnIndex], x, y); }
|
---|
694 |
|
---|
695 | static void VBOXFreeScreenIndex(int scrnIndex, int flags)
|
---|
696 | { (void) flags; VBOXFreeScreen(xf86Screens[scrnIndex]); }
|
---|
697 | # else
|
---|
698 | # define SCRNINDEXAPI(pfn) pfn
|
---|
699 | #endif /* XF86_SCRN_INTERFACE */
|
---|
700 |
|
---|
701 | static void setScreenFunctions(ScrnInfoPtr pScrn, xf86ProbeProc pfnProbe)
|
---|
702 | {
|
---|
703 | pScrn->driverVersion = VBOX_VERSION;
|
---|
704 | pScrn->driverName = VBOX_DRIVER_NAME;
|
---|
705 | pScrn->name = VBOX_NAME;
|
---|
706 | pScrn->Probe = pfnProbe;
|
---|
707 | pScrn->PreInit = VBOXPreInit;
|
---|
708 | pScrn->ScreenInit = SCRNINDEXAPI(VBOXScreenInit);
|
---|
709 | pScrn->SwitchMode = SCRNINDEXAPI(VBOXSwitchMode);
|
---|
710 | pScrn->AdjustFrame = SCRNINDEXAPI(VBOXAdjustFrame);
|
---|
711 | pScrn->EnterVT = SCRNINDEXAPI(VBOXEnterVT);
|
---|
712 | pScrn->LeaveVT = SCRNINDEXAPI(VBOXLeaveVT);
|
---|
713 | pScrn->FreeScreen = SCRNINDEXAPI(VBOXFreeScreen);
|
---|
714 | }
|
---|
715 |
|
---|
716 | /*
|
---|
717 | * One of these functions is called once, at the start of the first server
|
---|
718 | * generation to do a minimal probe for supported hardware.
|
---|
719 | */
|
---|
720 |
|
---|
721 | #ifdef PCIACCESS
|
---|
722 | static Bool
|
---|
723 | VBOXPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev,
|
---|
724 | intptr_t match_data)
|
---|
725 | {
|
---|
726 | ScrnInfoPtr pScrn;
|
---|
727 | int drmFd;
|
---|
728 |
|
---|
729 | TRACE_ENTRY();
|
---|
730 |
|
---|
731 | drmFd = open("/dev/dri/card0", O_RDWR, 0);
|
---|
732 | if (drmFd >= 0)
|
---|
733 | {
|
---|
734 | xf86Msg(X_INFO, "vboxvideo: kernel driver found, not loading.\n");
|
---|
735 | close(drmFd);
|
---|
736 | return FALSE;
|
---|
737 | }
|
---|
738 | /* It is safe to call this, as the X server enables I/O access before
|
---|
739 | * calling the probe call-backs. */
|
---|
740 | if (!xf86EnableIO())
|
---|
741 | {
|
---|
742 | xf86Msg(X_INFO, "vboxvideo: this driver requires direct hardware access. You may wish to use the kernel driver instead.\n");
|
---|
743 | return FALSE;
|
---|
744 | }
|
---|
745 | pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets,
|
---|
746 | NULL, NULL, NULL, NULL, NULL);
|
---|
747 | if (pScrn != NULL) {
|
---|
748 | VBOXPtr pVBox;
|
---|
749 |
|
---|
750 | VBOXSetRec(pScrn);
|
---|
751 | pVBox = VBOXGetRec(pScrn);
|
---|
752 | if (!pVBox)
|
---|
753 | return FALSE;
|
---|
754 | setScreenFunctions(pScrn, NULL);
|
---|
755 | pVBox->pciInfo = dev;
|
---|
756 | }
|
---|
757 |
|
---|
758 | TRACE_LOG("returning %s\n", BOOL_STR(pScrn != NULL));
|
---|
759 | return (pScrn != NULL);
|
---|
760 | }
|
---|
761 | #endif
|
---|
762 |
|
---|
763 | #ifndef PCIACCESS
|
---|
764 | static Bool
|
---|
765 | VBOXProbe(DriverPtr drv, int flags)
|
---|
766 | {
|
---|
767 | Bool foundScreen = FALSE;
|
---|
768 | int numDevSections;
|
---|
769 | GDevPtr *devSections;
|
---|
770 |
|
---|
771 | /*
|
---|
772 | * Find the config file Device sections that match this
|
---|
773 | * driver, and return if there are none.
|
---|
774 | */
|
---|
775 | if ((numDevSections = xf86MatchDevice(VBOX_NAME,
|
---|
776 | &devSections)) <= 0)
|
---|
777 | return (FALSE);
|
---|
778 |
|
---|
779 | /* PCI BUS */
|
---|
780 | if (xf86GetPciVideoInfo())
|
---|
781 | {
|
---|
782 | int numUsed;
|
---|
783 | int *usedChips;
|
---|
784 | int i;
|
---|
785 | numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID,
|
---|
786 | VBOXChipsets, VBOXPCIchipsets,
|
---|
787 | devSections, numDevSections,
|
---|
788 | drv, &usedChips);
|
---|
789 | if (numUsed > 0)
|
---|
790 | {
|
---|
791 | if (flags & PROBE_DETECT)
|
---|
792 | foundScreen = TRUE;
|
---|
793 | else
|
---|
794 | for (i = 0; i < numUsed; i++)
|
---|
795 | {
|
---|
796 | ScrnInfoPtr pScrn = NULL;
|
---|
797 | /* Allocate a ScrnInfoRec */
|
---|
798 | if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i],
|
---|
799 | VBOXPCIchipsets,NULL,
|
---|
800 | NULL,NULL,NULL,NULL)))
|
---|
801 | {
|
---|
802 | setScreenFunctions(pScrn, VBOXProbe);
|
---|
803 | foundScreen = TRUE;
|
---|
804 | }
|
---|
805 | }
|
---|
806 | free(usedChips);
|
---|
807 | }
|
---|
808 | }
|
---|
809 | free(devSections);
|
---|
810 | return (foundScreen);
|
---|
811 | }
|
---|
812 | #endif
|
---|
813 |
|
---|
814 |
|
---|
815 | /*
|
---|
816 | * QUOTE from the XFree86 DESIGN document:
|
---|
817 | *
|
---|
818 | * The purpose of this function is to find out all the information
|
---|
819 | * required to determine if the configuration is usable, and to initialise
|
---|
820 | * those parts of the ScrnInfoRec that can be set once at the beginning of
|
---|
821 | * the first server generation.
|
---|
822 | *
|
---|
823 | * (...)
|
---|
824 | *
|
---|
825 | * This includes probing for video memory, clocks, ramdac, and all other
|
---|
826 | * HW info that is needed. It includes determining the depth/bpp/visual
|
---|
827 | * and related info. It includes validating and determining the set of
|
---|
828 | * video modes that will be used (and anything that is required to
|
---|
829 | * determine that).
|
---|
830 | *
|
---|
831 | * This information should be determined in the least intrusive way
|
---|
832 | * possible. The state of the HW must remain unchanged by this function.
|
---|
833 | * Although video memory (including MMIO) may be mapped within this
|
---|
834 | * function, it must be unmapped before returning.
|
---|
835 | *
|
---|
836 | * END QUOTE
|
---|
837 | */
|
---|
838 |
|
---|
839 | static Bool
|
---|
840 | VBOXPreInit(ScrnInfoPtr pScrn, int flags)
|
---|
841 | {
|
---|
842 | VBOXPtr pVBox;
|
---|
843 | Gamma gzeros = {0.0, 0.0, 0.0};
|
---|
844 | rgb rzeros = {0, 0, 0};
|
---|
845 |
|
---|
846 | TRACE_ENTRY();
|
---|
847 | /* Are we really starting the server, or is this just a dummy run? */
|
---|
848 | if (flags & PROBE_DETECT)
|
---|
849 | return (FALSE);
|
---|
850 |
|
---|
851 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "VirtualBox guest additions video driver version " VBOX_VERSION_STRING "r%d\n",
|
---|
852 | VBOX_SVN_REV);
|
---|
853 |
|
---|
854 | /* The ramdac module is needed for the hardware cursor. */
|
---|
855 | if (!xf86LoadSubModule(pScrn, "ramdac"))
|
---|
856 | return FALSE;
|
---|
857 |
|
---|
858 | /* The framebuffer module. */
|
---|
859 | if (!xf86LoadSubModule(pScrn, "fb"))
|
---|
860 | return (FALSE);
|
---|
861 |
|
---|
862 | if (!xf86LoadSubModule(pScrn, "shadowfb"))
|
---|
863 | return FALSE;
|
---|
864 |
|
---|
865 | if (!xf86LoadSubModule(pScrn, "vgahw"))
|
---|
866 | return FALSE;
|
---|
867 |
|
---|
868 | /* Get our private data from the ScrnInfoRec structure. */
|
---|
869 | VBOXSetRec(pScrn);
|
---|
870 | pVBox = VBOXGetRec(pScrn);
|
---|
871 | if (!pVBox)
|
---|
872 | return FALSE;
|
---|
873 |
|
---|
874 | /* Entity information seems to mean bus information. */
|
---|
875 | pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
|
---|
876 |
|
---|
877 | #ifndef PCIACCESS
|
---|
878 | if (pVBox->pEnt->location.type != BUS_PCI)
|
---|
879 | return FALSE;
|
---|
880 |
|
---|
881 | pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index);
|
---|
882 | pVBox->pciTag = pciTag(pVBox->pciInfo->bus,
|
---|
883 | pVBox->pciInfo->device,
|
---|
884 | pVBox->pciInfo->func);
|
---|
885 | #endif
|
---|
886 |
|
---|
887 | /* Set up our ScrnInfoRec structure to describe our virtual
|
---|
888 | capabilities to X. */
|
---|
889 |
|
---|
890 | pScrn->chipset = "vbox";
|
---|
891 | /** @note needed during colourmap initialisation */
|
---|
892 | pScrn->rgbBits = 8;
|
---|
893 |
|
---|
894 | /* Let's create a nice, capable virtual monitor. */
|
---|
895 | pScrn->monitor = pScrn->confScreen->monitor;
|
---|
896 | pScrn->monitor->DDC = NULL;
|
---|
897 | pScrn->monitor->nHsync = 1;
|
---|
898 | pScrn->monitor->hsync[0].lo = 1;
|
---|
899 | pScrn->monitor->hsync[0].hi = 10000;
|
---|
900 | pScrn->monitor->nVrefresh = 1;
|
---|
901 | pScrn->monitor->vrefresh[0].lo = 1;
|
---|
902 | pScrn->monitor->vrefresh[0].hi = 100;
|
---|
903 |
|
---|
904 | pScrn->progClock = TRUE;
|
---|
905 |
|
---|
906 | /* Using the PCI information caused problems with non-powers-of-two
|
---|
907 | sized video RAM configurations */
|
---|
908 | pVBox->cbFBMax = VBoxVideoGetVRAMSize();
|
---|
909 | pScrn->videoRam = pVBox->cbFBMax / 1024;
|
---|
910 |
|
---|
911 | /* Check if the chip restricts horizontal resolution or not. */
|
---|
912 | pVBox->fAnyX = VBoxVideoAnyWidthAllowed();
|
---|
913 |
|
---|
914 | /* Set up clock information that will support all modes we need. */
|
---|
915 | pScrn->clockRanges = xnfcalloc(sizeof(ClockRange), 1);
|
---|
916 | pScrn->clockRanges->minClock = 1000;
|
---|
917 | pScrn->clockRanges->maxClock = 1000000000;
|
---|
918 | pScrn->clockRanges->clockIndex = -1;
|
---|
919 | pScrn->clockRanges->ClockMulFactor = 1;
|
---|
920 | pScrn->clockRanges->ClockDivFactor = 1;
|
---|
921 |
|
---|
922 | if (!xf86SetDepthBpp(pScrn, 24, 0, 0, Support32bppFb))
|
---|
923 | return FALSE;
|
---|
924 | /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */
|
---|
925 | if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16)
|
---|
926 | {
|
---|
927 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
928 | "The VBox additions only support 16 and 32bpp graphics modes\n");
|
---|
929 | return FALSE;
|
---|
930 | }
|
---|
931 | xf86PrintDepthBpp(pScrn);
|
---|
932 | vboxAddModes(pScrn);
|
---|
933 |
|
---|
934 | #ifdef VBOXVIDEO_13
|
---|
935 | pScrn->virtualX = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
936 | pScrn->virtualY = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
937 | #else
|
---|
938 | /* We don't validate with xf86ValidateModes and xf86PruneModes as we
|
---|
939 | * already know what we like and what we don't. */
|
---|
940 |
|
---|
941 | pScrn->currentMode = pScrn->modes;
|
---|
942 |
|
---|
943 | /* Set the right virtual resolution. */
|
---|
944 | pScrn->virtualX = pScrn->bitsPerPixel == 16 ? (pScrn->currentMode->HDisplay + 1) & ~1 : pScrn->currentMode->HDisplay;
|
---|
945 | pScrn->virtualY = pScrn->currentMode->VDisplay;
|
---|
946 |
|
---|
947 | #endif /* !VBOXVIDEO_13 */
|
---|
948 |
|
---|
949 | pScrn->displayWidth = pScrn->virtualX;
|
---|
950 |
|
---|
951 | xf86PrintModes(pScrn);
|
---|
952 |
|
---|
953 | /* VGA hardware initialisation */
|
---|
954 | if (!vgaHWGetHWRec(pScrn))
|
---|
955 | return FALSE;
|
---|
956 | /* Must be called before any VGA registers are saved or restored */
|
---|
957 | vgaHWSetStdFuncs(VGAHWPTR(pScrn));
|
---|
958 | vgaHWGetIOBase(VGAHWPTR(pScrn));
|
---|
959 |
|
---|
960 | /* Colour weight - we always call this, since we are always in
|
---|
961 | truecolour. */
|
---|
962 | if (!xf86SetWeight(pScrn, rzeros, rzeros))
|
---|
963 | return (FALSE);
|
---|
964 |
|
---|
965 | /* visual init */
|
---|
966 | if (!xf86SetDefaultVisual(pScrn, -1))
|
---|
967 | return (FALSE);
|
---|
968 |
|
---|
969 | xf86SetGamma(pScrn, gzeros);
|
---|
970 |
|
---|
971 | /* Set the DPI. Perhaps we should read this from the host? */
|
---|
972 | xf86SetDpi(pScrn, 96, 96);
|
---|
973 |
|
---|
974 | if (pScrn->memPhysBase == 0) {
|
---|
975 | #ifdef PCIACCESS
|
---|
976 | pScrn->memPhysBase = pVBox->pciInfo->regions[0].base_addr;
|
---|
977 | #else
|
---|
978 | pScrn->memPhysBase = pVBox->pciInfo->memBase[0];
|
---|
979 | #endif
|
---|
980 | pScrn->fbOffset = 0;
|
---|
981 | }
|
---|
982 |
|
---|
983 | TRACE_EXIT();
|
---|
984 | return (TRUE);
|
---|
985 | }
|
---|
986 |
|
---|
987 | /**
|
---|
988 | * Dummy function for setting the colour palette, which we actually never
|
---|
989 | * touch. However, the server still requires us to provide this.
|
---|
990 | */
|
---|
991 | static void
|
---|
992 | vboxLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
|
---|
993 | LOCO *colors, VisualPtr pVisual)
|
---|
994 | {
|
---|
995 | (void)pScrn; (void) numColors; (void) indices; (void) colors;
|
---|
996 | (void)pVisual;
|
---|
997 | }
|
---|
998 |
|
---|
999 | /** Set the graphics and guest cursor support capabilities to the host if
|
---|
1000 | * the user-space helper is running. */
|
---|
1001 | static void updateGraphicsCapability(ScrnInfoPtr pScrn, Bool hasVT)
|
---|
1002 | {
|
---|
1003 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1004 |
|
---|
1005 | if (!pVBox->fHaveHGSMIModeHints)
|
---|
1006 | return;
|
---|
1007 | VBoxHGSMISendCapsInfo(&pVBox->guestCtx, hasVT
|
---|
1008 | ? VBVACAPS_VIDEO_MODE_HINTS | VBVACAPS_DISABLE_CURSOR_INTEGRATION
|
---|
1009 | : VBVACAPS_DISABLE_CURSOR_INTEGRATION);
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | #ifndef VBOXVIDEO_13
|
---|
1013 |
|
---|
1014 | #define PREFERRED_MODE_ATOM_NAME "VBOXVIDEO_PREFERRED_MODE"
|
---|
1015 |
|
---|
1016 | static void setSizesRandR11(ScrnInfoPtr pScrn)
|
---|
1017 | {
|
---|
1018 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1019 | DisplayModePtr pNewMode;
|
---|
1020 | int32_t propertyValue;
|
---|
1021 |
|
---|
1022 | pNewMode = pScrn->modes != pScrn->currentMode ? pScrn->modes : pScrn->modes->next;
|
---|
1023 | pNewMode->HDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1024 | pNewMode->VDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1025 | propertyValue = (pNewMode->HDisplay << 16) + pNewMode->VDisplay;
|
---|
1026 | ChangeWindowProperty(ROOT_WINDOW(pScrn), MakeAtom(PREFERRED_MODE_ATOM_NAME,
|
---|
1027 | sizeof(PREFERRED_MODE_ATOM_NAME) - 1, TRUE), XA_INTEGER, 32,
|
---|
1028 | PropModeReplace, 1, &propertyValue, TRUE);
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | #endif
|
---|
1032 |
|
---|
1033 | static void setSizesAndCursorIntegration(ScrnInfoPtr pScrn, Bool fScreenInitTime)
|
---|
1034 | {
|
---|
1035 | RT_NOREF(fScreenInitTime);
|
---|
1036 | TRACE_LOG("fScreenInitTime=%d\n", (int)fScreenInitTime);
|
---|
1037 | #ifdef VBOXVIDEO_13
|
---|
1038 | # if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 5
|
---|
1039 | RRGetInfo(xf86ScrnToScreen(pScrn), TRUE);
|
---|
1040 | # else
|
---|
1041 | RRGetInfo(xf86ScrnToScreen(pScrn));
|
---|
1042 | # endif
|
---|
1043 | #else
|
---|
1044 | setSizesRandR11(pScrn);
|
---|
1045 | #endif
|
---|
1046 | /* This calls EnableDisableFBAccess(), so only use when switched in. */
|
---|
1047 | if (pScrn->vtSema)
|
---|
1048 | vbvxReprobeCursor(pScrn);
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 | /* We update the size hints from the X11 property set by VBoxClient every time
|
---|
1052 | * that the X server goes to sleep (to catch the property change request).
|
---|
1053 | * Although this is far more often than necessary it should not have real-life
|
---|
1054 | * performance consequences and allows us to simplify the code quite a bit. */
|
---|
1055 | static void vboxBlockHandler(pointer pData, OSTimePtr pTimeout, pointer pReadmask)
|
---|
1056 | {
|
---|
1057 | ScrnInfoPtr pScrn = (ScrnInfoPtr)pData;
|
---|
1058 | Bool fNeedUpdate = false;
|
---|
1059 |
|
---|
1060 | (void)pTimeout;
|
---|
1061 | (void)pReadmask;
|
---|
1062 | if (pScrn->vtSema)
|
---|
1063 | vbvxReadSizesAndCursorIntegrationFromHGSMI(pScrn, &fNeedUpdate);
|
---|
1064 | if (fNeedUpdate)
|
---|
1065 | setSizesAndCursorIntegration(pScrn, false);
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | /*
|
---|
1069 | * QUOTE from the XFree86 DESIGN document:
|
---|
1070 | *
|
---|
1071 | * This is called at the start of each server generation.
|
---|
1072 | *
|
---|
1073 | * (...)
|
---|
1074 | *
|
---|
1075 | * Decide which operations need to be placed under resource access
|
---|
1076 | * control. (...) Map any video memory or other memory regions. (...)
|
---|
1077 | * Save the video card state. (...) Initialise the initial video
|
---|
1078 | * mode.
|
---|
1079 | *
|
---|
1080 | * End QUOTE.
|
---|
1081 | */
|
---|
1082 | static Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv)
|
---|
1083 | {
|
---|
1084 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
---|
1085 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1086 | VisualPtr visual;
|
---|
1087 | RT_NOREF(argc, argv);
|
---|
1088 |
|
---|
1089 | TRACE_ENTRY();
|
---|
1090 |
|
---|
1091 | /* Initialise our guest library if possible: ignore failure. */
|
---|
1092 | VbglR3Init();
|
---|
1093 | if (!VBOXMapVidMem(pScrn))
|
---|
1094 | return (FALSE);
|
---|
1095 |
|
---|
1096 | /* save current video state */
|
---|
1097 | VBOXSaveMode(pScrn);
|
---|
1098 |
|
---|
1099 | /* mi layer - reset the visual list (?)*/
|
---|
1100 | miClearVisualTypes();
|
---|
1101 | if (!miSetVisualTypes(pScrn->depth, TrueColorMask,
|
---|
1102 | pScrn->rgbBits, TrueColor))
|
---|
1103 | return (FALSE);
|
---|
1104 | if (!miSetPixmapDepths())
|
---|
1105 | return (FALSE);
|
---|
1106 |
|
---|
1107 | if (!fbScreenInit(pScreen, pVBox->base,
|
---|
1108 | pScrn->virtualX, pScrn->virtualY,
|
---|
1109 | pScrn->xDpi, pScrn->yDpi,
|
---|
1110 | pScrn->displayWidth, pScrn->bitsPerPixel))
|
---|
1111 | return (FALSE);
|
---|
1112 |
|
---|
1113 | /* Fixup RGB ordering */
|
---|
1114 | /** @note the X server uses this even in true colour. */
|
---|
1115 | visual = pScreen->visuals + pScreen->numVisuals;
|
---|
1116 | while (--visual >= pScreen->visuals) {
|
---|
1117 | if ((visual->class | DynamicClass) == DirectColor) {
|
---|
1118 | visual->offsetRed = pScrn->offset.red;
|
---|
1119 | visual->offsetGreen = pScrn->offset.green;
|
---|
1120 | visual->offsetBlue = pScrn->offset.blue;
|
---|
1121 | visual->redMask = pScrn->mask.red;
|
---|
1122 | visual->greenMask = pScrn->mask.green;
|
---|
1123 | visual->blueMask = pScrn->mask.blue;
|
---|
1124 | }
|
---|
1125 | }
|
---|
1126 |
|
---|
1127 | /* must be after RGB ordering fixed */
|
---|
1128 | fbPictureInit(pScreen, 0, 0);
|
---|
1129 |
|
---|
1130 | xf86SetBlackWhitePixels(pScreen);
|
---|
1131 | pScrn->vtSema = TRUE;
|
---|
1132 |
|
---|
1133 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
1134 | vbvxSetUpLinuxACPI(pScreen);
|
---|
1135 | #endif
|
---|
1136 |
|
---|
1137 | if (!VBoxHGSMIIsSupported())
|
---|
1138 | {
|
---|
1139 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Graphics device too old to support.\n");
|
---|
1140 | return FALSE;
|
---|
1141 | }
|
---|
1142 | vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024);
|
---|
1143 | pVBox->cScreens = VBoxHGSMIGetMonitorCount(&pVBox->guestCtx);
|
---|
1144 | pVBox->pScreens = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->pScreens));
|
---|
1145 | pVBox->paVBVAModeHints = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->paVBVAModeHints));
|
---|
1146 | xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Requested monitor count: %u\n", pVBox->cScreens);
|
---|
1147 | vboxEnableVbva(pScrn);
|
---|
1148 | /* Set up the dirty rectangle handler. It will be added into a function
|
---|
1149 | * chain and gets removed when the screen is cleaned up. */
|
---|
1150 | if (ShadowFBInit2(pScreen, NULL, vbvxHandleDirtyRect) != TRUE)
|
---|
1151 | return FALSE;
|
---|
1152 | VBoxInitialiseSizeHints(pScrn);
|
---|
1153 |
|
---|
1154 | #ifdef VBOXVIDEO_13
|
---|
1155 | /* Initialise CRTC and output configuration for use with randr1.2. */
|
---|
1156 | xf86CrtcConfigInit(pScrn, &VBOXCrtcConfigFuncs);
|
---|
1157 |
|
---|
1158 | {
|
---|
1159 | uint32_t i;
|
---|
1160 |
|
---|
1161 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1162 | {
|
---|
1163 | char szOutput[256];
|
---|
1164 |
|
---|
1165 | /* Setup our virtual CRTCs. */
|
---|
1166 | pVBox->pScreens[i].paCrtcs = xf86CrtcCreate(pScrn, &VBOXCrtcFuncs);
|
---|
1167 | pVBox->pScreens[i].paCrtcs->driver_private = (void *)(uintptr_t)i;
|
---|
1168 |
|
---|
1169 | /* Set up our virtual outputs. */
|
---|
1170 | snprintf(szOutput, sizeof(szOutput), "VGA-%u", i);
|
---|
1171 | pVBox->pScreens[i].paOutputs
|
---|
1172 | = xf86OutputCreate(pScrn, &VBOXOutputFuncs, szOutput);
|
---|
1173 |
|
---|
1174 | /* We are not interested in the monitor section in the
|
---|
1175 | * configuration file. */
|
---|
1176 | xf86OutputUseScreenMonitor(pVBox->pScreens[i].paOutputs, FALSE);
|
---|
1177 | pVBox->pScreens[i].paOutputs->possible_crtcs = 1 << i;
|
---|
1178 | pVBox->pScreens[i].paOutputs->possible_clones = 0;
|
---|
1179 | pVBox->pScreens[i].paOutputs->driver_private = (void *)(uintptr_t)i;
|
---|
1180 | TRACE_LOG("Created crtc (%p) and output %s (%p)\n",
|
---|
1181 | (void *)pVBox->pScreens[i].paCrtcs, szOutput,
|
---|
1182 | (void *)pVBox->pScreens[i].paOutputs);
|
---|
1183 | }
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | /* Set a sane minimum and maximum mode size to match what the hardware
|
---|
1187 | * supports. */
|
---|
1188 | xf86CrtcSetSizeRange(pScrn, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1189 |
|
---|
1190 | /* Now create our initial CRTC/output configuration. */
|
---|
1191 | if (!xf86InitialConfiguration(pScrn, TRUE)) {
|
---|
1192 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n");
|
---|
1193 | return (FALSE);
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | /* Work around a bug in the original X server modesetting code, which took
|
---|
1197 | * the first valid values set to these two as maxima over the server
|
---|
1198 | * lifetime. This bug was introduced on Feb 15 2007 and was fixed in commit
|
---|
1199 | * fa877d7f three months later, so it was present in X.Org Server 1.3. */
|
---|
1200 | pScrn->virtualX = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
1201 | pScrn->virtualY = VBOX_VIDEO_MAX_VIRTUAL;
|
---|
1202 |
|
---|
1203 | /* Initialise randr 1.2 mode-setting functions. */
|
---|
1204 | if (!xf86CrtcScreenInit(pScreen)) {
|
---|
1205 | return FALSE;
|
---|
1206 | }
|
---|
1207 |
|
---|
1208 | /* set first video mode */
|
---|
1209 | if (!xf86SetDesiredModes(pScrn)) {
|
---|
1210 | return FALSE;
|
---|
1211 | }
|
---|
1212 | #else /* !VBOXVIDEO_13 */
|
---|
1213 | /* set first video mode */
|
---|
1214 | setModeRandR11(pScrn, pScrn->currentMode, true, false, 0, 0);
|
---|
1215 | #endif /* !VBOXVIDEO_13 */
|
---|
1216 |
|
---|
1217 | /* Say that we support graphics. */
|
---|
1218 | updateGraphicsCapability(pScrn, TRUE);
|
---|
1219 |
|
---|
1220 | /* Register block and wake-up handlers for getting new screen size hints. */
|
---|
1221 | RegisterBlockAndWakeupHandlers(vboxBlockHandler, (WakeupHandlerProcPtr)NoopDDA, (pointer)pScrn);
|
---|
1222 |
|
---|
1223 | /* software cursor */
|
---|
1224 | miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
|
---|
1225 |
|
---|
1226 | /* colourmap code */
|
---|
1227 | if (!miCreateDefColormap(pScreen))
|
---|
1228 | return (FALSE);
|
---|
1229 |
|
---|
1230 | if(!xf86HandleColormaps(pScreen, 256, 8, vboxLoadPalette, NULL, 0))
|
---|
1231 | return (FALSE);
|
---|
1232 |
|
---|
1233 | pVBox->CloseScreen = pScreen->CloseScreen;
|
---|
1234 | pScreen->CloseScreen = SCRNINDEXAPI(VBOXCloseScreen);
|
---|
1235 | #ifdef VBOXVIDEO_13
|
---|
1236 | pScreen->SaveScreen = xf86SaveScreen;
|
---|
1237 | #else
|
---|
1238 | pScreen->SaveScreen = VBOXSaveScreen;
|
---|
1239 | #endif
|
---|
1240 |
|
---|
1241 | #ifdef VBOXVIDEO_13
|
---|
1242 | xf86DPMSInit(pScreen, xf86DPMSSet, 0);
|
---|
1243 | #else
|
---|
1244 | /* We probably do want to support power management - even if we just use
|
---|
1245 | a dummy function. */
|
---|
1246 | xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0);
|
---|
1247 | #endif
|
---|
1248 |
|
---|
1249 | /* Report any unused options (only for the first generation) */
|
---|
1250 | if (serverGeneration == 1)
|
---|
1251 | xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
|
---|
1252 |
|
---|
1253 | if (vbvxCursorInit(pScreen) != TRUE)
|
---|
1254 | xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
|
---|
1255 | "Unable to start the VirtualBox mouse pointer integration with the host system.\n");
|
---|
1256 |
|
---|
1257 | return (TRUE);
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | #define NO_VT_ATOM_NAME "VBOXVIDEO_NO_VT"
|
---|
1261 |
|
---|
1262 | static Bool VBOXEnterVT(ScrnInfoPtr pScrn)
|
---|
1263 | {
|
---|
1264 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1265 | #ifndef VBOXVIDEO_13
|
---|
1266 | /* If we got a mode request while we were switched out, temporarily override
|
---|
1267 | * the physical mode set to the device while keeping things consistent from
|
---|
1268 | * the server's point of view. */
|
---|
1269 | int cXOverRide = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1270 | int cYOverRide = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL);
|
---|
1271 | #endif
|
---|
1272 |
|
---|
1273 | TRACE_ENTRY();
|
---|
1274 | vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024);
|
---|
1275 | vboxEnableVbva(pScrn);
|
---|
1276 | /* Re-set video mode */
|
---|
1277 | #ifdef VBOXVIDEO_13
|
---|
1278 | if (!xf86SetDesiredModes(pScrn)) {
|
---|
1279 | return FALSE;
|
---|
1280 | }
|
---|
1281 | #else
|
---|
1282 | setModeRandR11(pScrn, pScrn->currentMode, false, true, cXOverRide, cYOverRide);
|
---|
1283 | DeleteProperty(ROOT_WINDOW(pScrn), MakeAtom(NO_VT_ATOM_NAME, sizeof(NO_VT_ATOM_NAME) - 1, TRUE));
|
---|
1284 | #endif
|
---|
1285 | updateGraphicsCapability(pScrn, TRUE);
|
---|
1286 | return TRUE;
|
---|
1287 | }
|
---|
1288 |
|
---|
1289 | static void VBOXLeaveVT(ScrnInfoPtr pScrn)
|
---|
1290 | {
|
---|
1291 | #ifdef VBOXVIDEO_13
|
---|
1292 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1293 | unsigned i;
|
---|
1294 | #else
|
---|
1295 | int32_t propertyValue = 0;
|
---|
1296 | #endif
|
---|
1297 |
|
---|
1298 | TRACE_ENTRY();
|
---|
1299 | #ifdef VBOXVIDEO_13
|
---|
1300 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1301 | vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff);
|
---|
1302 | #else
|
---|
1303 | ChangeWindowProperty(ROOT_WINDOW(pScrn), MakeAtom(NO_VT_ATOM_NAME, sizeof(NO_VT_ATOM_NAME) - 1, FALSE), XA_INTEGER, 32,
|
---|
1304 | PropModeReplace, 1, &propertyValue, TRUE);
|
---|
1305 | #endif
|
---|
1306 | updateGraphicsCapability(pScrn, FALSE);
|
---|
1307 | vboxDisableVbva(pScrn);
|
---|
1308 | vbvxClearVRAM(pScrn, ((size_t)pScrn->virtualX) * pScrn->virtualY * (pScrn->bitsPerPixel / 8), 0);
|
---|
1309 | VBOXRestoreMode(pScrn);
|
---|
1310 | TRACE_EXIT();
|
---|
1311 | }
|
---|
1312 |
|
---|
1313 | static Bool VBOXCloseScreen(ScreenPtr pScreen)
|
---|
1314 | {
|
---|
1315 | ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
---|
1316 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1317 | BOOL ret;
|
---|
1318 |
|
---|
1319 | if (pScrn->vtSema)
|
---|
1320 | {
|
---|
1321 | #ifdef VBOXVIDEO_13
|
---|
1322 | unsigned i;
|
---|
1323 |
|
---|
1324 | for (i = 0; i < pVBox->cScreens; ++i)
|
---|
1325 | vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff);
|
---|
1326 | #endif
|
---|
1327 | vboxDisableVbva(pScrn);
|
---|
1328 | vbvxClearVRAM(pScrn, ((size_t)pScrn->virtualX) * pScrn->virtualY * (pScrn->bitsPerPixel / 8), 0);
|
---|
1329 | }
|
---|
1330 | if (pScrn->vtSema)
|
---|
1331 | VBOXRestoreMode(pScrn);
|
---|
1332 | if (pScrn->vtSema)
|
---|
1333 | VBOXUnmapVidMem(pScrn);
|
---|
1334 | pScrn->vtSema = FALSE;
|
---|
1335 |
|
---|
1336 | vbvxCursorTerm(pVBox);
|
---|
1337 |
|
---|
1338 | pScreen->CloseScreen = pVBox->CloseScreen;
|
---|
1339 | #if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX)
|
---|
1340 | vbvxCleanUpLinuxACPI(pScreen);
|
---|
1341 | #endif
|
---|
1342 | #ifndef XF86_SCRN_INTERFACE
|
---|
1343 | ret = pScreen->CloseScreen(pScreen->myNum, pScreen);
|
---|
1344 | #else
|
---|
1345 | ret = pScreen->CloseScreen(pScreen);
|
---|
1346 | #endif
|
---|
1347 | VbglR3Term();
|
---|
1348 | return ret;
|
---|
1349 | }
|
---|
1350 |
|
---|
1351 | static Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode)
|
---|
1352 | {
|
---|
1353 | Bool rc = TRUE;
|
---|
1354 |
|
---|
1355 | TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
|
---|
1356 | #ifdef VBOXVIDEO_13
|
---|
1357 | rc = xf86SetSingleMode(pScrn, pMode, RR_Rotate_0);
|
---|
1358 | #else
|
---|
1359 | setModeRandR11(pScrn, pMode, false, false, 0, 0);
|
---|
1360 | #endif
|
---|
1361 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1362 | return rc;
|
---|
1363 | }
|
---|
1364 |
|
---|
1365 | static void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
|
---|
1366 | { (void)pScrn; (void)x; (void)y; }
|
---|
1367 |
|
---|
1368 | static void VBOXFreeScreen(ScrnInfoPtr pScrn)
|
---|
1369 | {
|
---|
1370 | /* Destroy the VGA hardware record */
|
---|
1371 | vgaHWFreeHWRec(pScrn);
|
---|
1372 | /* And our private record */
|
---|
1373 | free(pScrn->driverPrivate);
|
---|
1374 | pScrn->driverPrivate = NULL;
|
---|
1375 | }
|
---|
1376 |
|
---|
1377 | static Bool
|
---|
1378 | VBOXMapVidMem(ScrnInfoPtr pScrn)
|
---|
1379 | {
|
---|
1380 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1381 | Bool rc = TRUE;
|
---|
1382 |
|
---|
1383 | TRACE_ENTRY();
|
---|
1384 | if (!pVBox->base)
|
---|
1385 | {
|
---|
1386 | #ifdef PCIACCESS
|
---|
1387 | (void) pci_device_map_range(pVBox->pciInfo,
|
---|
1388 | pScrn->memPhysBase,
|
---|
1389 | pScrn->videoRam * 1024,
|
---|
1390 | PCI_DEV_MAP_FLAG_WRITABLE,
|
---|
1391 | & pVBox->base);
|
---|
1392 | #else
|
---|
1393 | pVBox->base = xf86MapPciMem(pScrn->scrnIndex,
|
---|
1394 | VIDMEM_FRAMEBUFFER,
|
---|
1395 | pVBox->pciTag, pScrn->memPhysBase,
|
---|
1396 | (unsigned) pScrn->videoRam * 1024);
|
---|
1397 | #endif
|
---|
1398 | if (!pVBox->base)
|
---|
1399 | rc = FALSE;
|
---|
1400 | }
|
---|
1401 | TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
|
---|
1402 | return rc;
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | static void
|
---|
1406 | VBOXUnmapVidMem(ScrnInfoPtr pScrn)
|
---|
1407 | {
|
---|
1408 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1409 |
|
---|
1410 | TRACE_ENTRY();
|
---|
1411 | if (pVBox->base == NULL)
|
---|
1412 | return;
|
---|
1413 |
|
---|
1414 | #ifdef PCIACCESS
|
---|
1415 | (void) pci_device_unmap_range(pVBox->pciInfo,
|
---|
1416 | pVBox->base,
|
---|
1417 | pScrn->videoRam * 1024);
|
---|
1418 | #else
|
---|
1419 | xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base,
|
---|
1420 | (unsigned) pScrn->videoRam * 1024);
|
---|
1421 | #endif
|
---|
1422 | pVBox->base = NULL;
|
---|
1423 | TRACE_EXIT();
|
---|
1424 | }
|
---|
1425 |
|
---|
1426 | #ifndef VBOXVIDEO_13
|
---|
1427 | static Bool
|
---|
1428 | VBOXSaveScreen(ScreenPtr pScreen, int mode)
|
---|
1429 | {
|
---|
1430 | (void)pScreen; (void)mode;
|
---|
1431 | return TRUE;
|
---|
1432 | }
|
---|
1433 | #endif
|
---|
1434 |
|
---|
1435 | void
|
---|
1436 | VBOXSaveMode(ScrnInfoPtr pScrn)
|
---|
1437 | {
|
---|
1438 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1439 | vgaRegPtr vgaReg;
|
---|
1440 |
|
---|
1441 | TRACE_ENTRY();
|
---|
1442 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1443 | vgaHWSave(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1444 | pVBox->fSavedVBEMode = VBoxVideoGetModeRegisters(&pVBox->cSavedWidth,
|
---|
1445 | &pVBox->cSavedHeight,
|
---|
1446 | &pVBox->cSavedPitch,
|
---|
1447 | &pVBox->cSavedBPP,
|
---|
1448 | &pVBox->fSavedFlags);
|
---|
1449 | }
|
---|
1450 |
|
---|
1451 | void
|
---|
1452 | VBOXRestoreMode(ScrnInfoPtr pScrn)
|
---|
1453 | {
|
---|
1454 | VBOXPtr pVBox = VBOXGetRec(pScrn);
|
---|
1455 | vgaRegPtr vgaReg;
|
---|
1456 |
|
---|
1457 | TRACE_ENTRY();
|
---|
1458 | vgaReg = &VGAHWPTR(pScrn)->SavedReg;
|
---|
1459 | vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL);
|
---|
1460 | if (pVBox->fSavedVBEMode)
|
---|
1461 | VBoxVideoSetModeRegisters(pVBox->cSavedWidth, pVBox->cSavedHeight,
|
---|
1462 | pVBox->cSavedPitch, pVBox->cSavedBPP,
|
---|
1463 | pVBox->fSavedFlags, 0, 0);
|
---|
1464 | else
|
---|
1465 | VBoxVideoDisableVBE();
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 | #ifndef VBOXVIDEO_13
|
---|
1469 | static void
|
---|
1470 | VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode, int flags)
|
---|
1471 | {
|
---|
1472 | (void)pScrn; (void)mode; (void) flags;
|
---|
1473 | }
|
---|
1474 | #endif
|
---|