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