VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.c@ 52677

Last change on this file since 52677 was 52677, checked in by vboxsync, 11 years ago

Additions/x11/vboxvideo: remove output property handler.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette