diff options
Diffstat (limited to '')
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/HGSMIMemAlloc.h | 63 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/Makefile.kmk | 467 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/README.testing | 33 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/VBoxVideoIPRT.h | 243 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/edid.c | 165 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/getmode.c | 325 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/hgsmimemalloc.c | 104 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/pointer.c | 496 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/setmode.c | 129 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/vboxvideo.c | 1491 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/vboxvideo.h | 240 | ||||
-rw-r--r-- | src/VBox/Additions/x11/vboxvideo/vbva.c | 255 |
12 files changed, 4011 insertions, 0 deletions
diff --git a/src/VBox/Additions/x11/vboxvideo/HGSMIMemAlloc.h b/src/VBox/Additions/x11/vboxvideo/HGSMIMemAlloc.h new file mode 100644 index 00000000..ae5d2c3d --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/HGSMIMemAlloc.h @@ -0,0 +1,63 @@ +/* $Id: HGSMIMemAlloc.h $ */ +/* + * Copyright (C) 2017-2022 Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* In builds inside of the VirtualBox source tree we override the default + * HGSMIMemAlloc.h using -include, therefore this define must match the one + * there. */ + +#ifndef VBOX_INCLUDED_Graphics_HGSMIMemAlloc_h +#define VBOX_INCLUDED_Graphics_HGSMIMemAlloc_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include "HGSMIDefs.h" +#include "VBoxVideoIPRT.h" + +#define HGSMI_MA_DESC_ORDER_BASE UINT32_C(5) + +#define HGSMI_MA_BLOCK_SIZE_MIN (UINT32_C(1) << (HGSMI_MA_DESC_ORDER_BASE + 0)) + +typedef struct HGSMIMADATA +{ + HGSMIAREA area; + bool fAllocated; +} HGSMIMADATA; + +RT_C_DECLS_BEGIN + +int HGSMIMAInit(HGSMIMADATA *pMA, const HGSMIAREA *pArea, + HGSMIOFFSET *paDescriptors, uint32_t cDescriptors, + HGSMISIZE cbMaxBlock, const HGSMIENV *pEnv); +void HGSMIMAUninit(HGSMIMADATA *pMA); + +void RT_UNTRUSTED_VOLATILE_GUEST *HGSMIMAAlloc(HGSMIMADATA *pMA, HGSMISIZE cb); +void HGSMIMAFree(HGSMIMADATA *pMA, void RT_UNTRUSTED_VOLATILE_GUEST *pv); + +RT_C_DECLS_END + +#endif /* !VBOX_INCLUDED_Graphics_HGSMIMemAlloc_h */ diff --git a/src/VBox/Additions/x11/vboxvideo/Makefile.kmk b/src/VBox/Additions/x11/vboxvideo/Makefile.kmk new file mode 100644 index 00000000..a01d8107 --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/Makefile.kmk @@ -0,0 +1,467 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for the VBox Linux Additions X.org graphics driver. +# + +# +# Copyright (C) 2006-2022 Oracle and/or its affiliates. +# +# This file is part of VirtualBox base platform packages, as +# available from https://www.virtualbox.org. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, in version 3 of the +# License. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see <https://www.gnu.org/licenses>. +# +# SPDX-License-Identifier: GPL-3.0-only +# + +SUB_DEPTH = ../../../../.. +include $(KBUILD_PATH)/subheader.kmk + +vboxvideo_70_DEFS := \ + IN_MODULE XORG_7X RENDER=1 IN_RT_STATIC X_BYTE_ORDER=X_LITTLE_ENDIAN +ifeq ($(KBUILD_TARGET),solaris) # don't use .solaris or anything here. + vboxvideo_70_DEFS += __EXTENSIONS__ ## @todo Why this? +endif +vboxvideo_13_DEFS := $(vboxvideo_70_DEFS) VBOXVIDEO_13 +vboxvideo_15_DEFS := \ + $(vboxvideo_13_DEFS) NO_ANSIC PCIACCESS XSERVER_LIBPCIACCESS _XORG_SERVER_H_ _DIX_CONFIG_H_ +vboxvideo_xorg_INCS = \ + $(VBOX_PATH_X11_ROOT)/fontsproto-2.1.3 \ + $(VBOX_PATH_X11_ROOT)/inputproto-1.9.99.902 \ + $(VBOX_PATH_X11_ROOT)/kbproto-1.0.7 \ + $(VBOX_PATH_X11_ROOT)/libpciaccess-0.10.8 \ + $(VBOX_PATH_X11_ROOT)/pixman-0.40.0 \ + $(VBOX_PATH_X11_ROOT)/randrproto-1.5.0 \ + $(VBOX_PATH_X11_ROOT)/renderproto-0.11.1 \ + $(VBOX_PATH_X11_ROOT)/xextproto-7.1.1 \ + $(VBOX_PATH_X11_ROOT)/xproto-7.0.31 \ + $(VBOX_GRAPHICS_INCS) +vboxvideo_override_INCLUDES = \ + -include $(PATH_ROOT)/src/VBox/Additions/x11/vboxvideo/VBoxVideoIPRT.h \ + -include $(PATH_ROOT)/src/VBox/Additions/x11/vboxvideo/HGSMIMemAlloc.h + +LIBRARIES += vboxvideo_drv_lib + +# +# vboxvideo_drv_lib +# +vboxvideo_drv_lib_TEMPLATE = VBOXGUESTR3XORGMOD +# We are relying in the include guard in the two headers below to stop the more +# generic ones from being included. Not very nice, I know. +vboxvideo_drv_lib_CFLAGS += $(vboxvideo_override_INCLUDES) +vboxvideo_drv_lib_CXXFLAGS += $(vboxvideo_override_INCLUDES) +ifeq ($(KBUILD_TARGET),solaris) # don't use .solaris or anything here. Do we need this? I don't want to find out. + vboxvideo_drv_lib_CFLAGS += -D_XPG6 -Wno-shadow # Use XPG6 until we have moved the C++ bits into a library. +endif +vboxvideo_drv_lib_SOURCES = \ + $(PATH_ROOT)/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp \ + $(PATH_ROOT)/src/VBox/Additions/common/VBoxVideo/HGSMIBuffers.cpp \ + $(PATH_ROOT)/src/VBox/Additions/common/VBoxVideo/Modesetting.cpp \ + $(PATH_ROOT)/src/VBox/Additions/common/VBoxVideo/VBVABase.cpp \ + $(PATH_ROOT)/src/VBox/GuestHost/HGSMI/HGSMICommon.cpp \ + $(PATH_ROOT)/src/VBox/Additions/x11/vboxvideo/hgsmimemalloc.c +# $(VBOX_PATH_X11_ROOT)/xorg-server-1.18.0 is for in[blw] and out[blw], xproto +# for _X_[UN]LIKELY. +vboxvideo_drv_lib_INCS = \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.18.0 \ + $(VBOX_PATH_X11_ROOT)/xproto-7.0.18 \ + $(VBOX_PATH_X11_ROOT)/pixman-0.40.0 \ + $(PATH_ROOT)/src/VBox/Runtime/include \ + $(VBOX_GRAPHICS_INCS) +vboxvideo_drv_lib_INST = $(INST_LIB) + +# +# vboxvideo_drv +# +if1of ($(KBUILD_TARGET), linux) + SYSMODS += vboxvideo_drv +endif # target linux +vboxvideo_drv_TEMPLATE = VBOXGUESTR3XF86MOD +vboxvideo_drv_CFLAGS += $(vboxvideo_override_INCLUDES) +vboxvideo_drv_CFLAGS += -Wno-shadow # Avoid MBs of warnings in X11 and OpenGL headers (solaris mostly). +vboxvideo_drv_CXXFLAGS += $(vboxvideo_override_INCLUDES) +vboxvideo_drv_DEFS.linux = linux +vboxvideo_drv_DEFS.x86 = __i386__ +# This one has to be defined when building server code on systems where +# unsigned long is 64bits +vboxvideo_drv_DEFS.amd64 += _XSERVER64 +vboxvideo_drv_DEFS = \ + _POSIX_C_SOURCE=199309L _POSIX_SOURCE _XOPEN_SOURCE _DEFAULT_SOURCE \ + _BSD_SOURCE _SVID_SOURCE _GNU_SOURCE SHAPE XINPUT XKB LBX XAPPGROUP \ + XCSECURITY TOGCUP XF86BIGFONT DPMSExtension PIXPRIV PANORAMIX RENDER \ + GCCUSESGAS AVOID_GLYPHBLT PIXPRIV SINGLEDEPTH XFreeXDGA XvExtension \ + XFree86LOADER XFree86Server XF86VIDMODE XvMCExtension SMART_SCHEDULE \ + BUILDDEBUG X_BYTE_ORDER=X_LITTLE_ENDIAN DNDEBUG FUNCPROTO=15 NARROWPROTO \ + IN_MODULE XFree86Module IN_XF86_MODULE IN_RT_STATIC +vboxvideo_drv_INCS = \ + $(VBOX_PATH_X11_ROOT)/XFree86-4.3 \ + $(VBOX_PATH_X11_ROOT)/XFree86-4.3/X11 \ + $(VBOX_PATH_X11_ROOT)/XFree86-4.3/X11/extensions \ + $(VBOX_PATH_X11_ROOT)/XFree86-4.3/X11/fonts \ + $(VBOX_PATH_X11_ROOT)/XFree86-4.3/Xserver +vboxvideo_drv_INCS += \ + $(PATH_ROOT)/src/VBox/Runtime/include \ + $(VBOX_GRAPHICS_INCS) +vboxvideo_drv_SOURCES = \ + getmode.c \ + pointer.c \ + setmode.c \ + vboxvideo.c \ + vbva.c \ + $(vboxvideo_drv_lib_SOURCES) + # Any global symbols in the driver object files will be added to XFree86's + # symbol table, which can cause problems if we e.g. define a symbol in two + # modules. + vboxvideo_drv_POST_CMDS = \ + objcopy --keep-global-symbol vboxvideoModuleData $(out) $(out)-objcopy$$(NLTAB) \ + $(MV) -f $(out)-objcopy $(out) + +# +# vboxvideo_drv_70 +# +# Remark: The other X.org drivers below are derived from this one. So, to make +# that as simple as possible we do ifeq/if1of test here and extends the +# base keywords instead of using .solaris or .linux. +# Also it is *important* to use := and not = when deriving a property. +# +DLLS += vboxvideo_drv_70 +vboxvideo_drv_70_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_70_DEFS = $(vboxvideo_70_DEFS) XORG_VERSION_CURRENT=70000000 +vboxvideo_drv_70_CFLAGS += $(vboxvideo_override_INCLUDES) +ifeq ($(KBUILD_TARGET),solaris) # don't use .solaris or anything here. + vboxvideo_drv_70_CFLAGS += -D_XPG6 -Wno-shadow # Use XPG6 until we have moved the C++ bits into a library. +endif +vboxvideo_drv_70_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.0.1 +vboxvideo_drv_70_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_70_SOURCES = $(filter-out $(vboxvideo_drv_lib_SOURCES),$(vboxvideo_drv_SOURCES)) +vboxvideo_drv_70_LIBS = $(PATH_STAGE_LIB)/vboxvideo_drv_lib$(VBOX_SUFF_LIB) + + +# +# vboxvideo_drv_71 +# +DLLS += vboxvideo_drv_71 +vboxvideo_drv_71_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_71_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_71_DEFS := $(vboxvideo_70_DEFS) XORG_VERSION_CURRENT=70100000 +vboxvideo_drv_71_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.1.0 +vboxvideo_drv_71_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_71_SOURCES = $(vboxvideo_drv_70_SOURCES) +vboxvideo_drv_71_LIBS = $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_13 +# +DLLS += vboxvideo_drv_13 +vboxvideo_drv_13_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_13_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_13_DEFS := $(vboxvideo_13_DEFS) XORG_VERSION_CURRENT=10300000 +vboxvideo_drv_13_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.3.0.0 +vboxvideo_drv_13_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_13_SOURCES = $(vboxvideo_drv_70_SOURCES) edid.c +vboxvideo_drv_13_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_14 +# +DLLS += vboxvideo_drv_14 +vboxvideo_drv_14_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_14_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_14_DEFS := $(vboxvideo_13_DEFS) XORG_VERSION_CURRENT=10400000 +vboxvideo_drv_14_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.4.2 +vboxvideo_drv_14_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_14_SOURCES = $(vboxvideo_drv_13_SOURCES) +vboxvideo_drv_14_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_15 +# +DLLS += vboxvideo_drv_15 +vboxvideo_drv_15_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_15_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_15_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=10503000 +vboxvideo_drv_15_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.5.3 +vboxvideo_drv_15_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_15_SOURCES = $(vboxvideo_drv_13_SOURCES) +vboxvideo_drv_15_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_16 +# +DLLS += vboxvideo_drv_16 +vboxvideo_drv_16_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_16_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_16_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=10600000 +vboxvideo_drv_16_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.6.5 \ +vboxvideo_drv_16_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_16_SOURCES := $(vboxvideo_drv_15_SOURCES) +vboxvideo_drv_16_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_17 +# +DLLS += vboxvideo_drv_17 +vboxvideo_drv_17_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_17_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_17_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=10699000 +vboxvideo_drv_17_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.7.7 +vboxvideo_drv_17_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_17_SOURCES := $(vboxvideo_drv_13_SOURCES) +vboxvideo_drv_17_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_18 +# +DLLS += vboxvideo_drv_18 +vboxvideo_drv_18_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_18_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_18_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=10800000 +vboxvideo_drv_18_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.8.0 +vboxvideo_drv_18_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_18_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_18_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_19 +# +DLLS += vboxvideo_drv_19 +vboxvideo_drv_19_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_19_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_19_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=10900000 +vboxvideo_drv_19_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.9.0 +vboxvideo_drv_19_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_19_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_19_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_110 +# +DLLS += vboxvideo_drv_110 +vboxvideo_drv_110_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_110_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_110_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11000000 +vboxvideo_drv_110_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.10.0 +vboxvideo_drv_110_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_110_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_110_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_111 +# +DLLS += vboxvideo_drv_111 +vboxvideo_drv_111_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_111_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_111_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11100000 +vboxvideo_drv_111_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.11.0 +vboxvideo_drv_111_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_111_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_111_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_112 +# +DLLS += vboxvideo_drv_112 +vboxvideo_drv_112_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_112_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_112_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11200000 +vboxvideo_drv_112_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.12.0 +vboxvideo_drv_112_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_112_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_112_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_113 +# +DLLS += vboxvideo_drv_113 +vboxvideo_drv_113_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_113_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_113_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11300000 +vboxvideo_drv_113_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.13.0 +vboxvideo_drv_113_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_113_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_113_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_114 +# +DLLS += vboxvideo_drv_114 +vboxvideo_drv_114_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_114_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_114_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11400000 +vboxvideo_drv_114_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.14.0 +vboxvideo_drv_114_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_114_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_114_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_115 +# +DLLS += vboxvideo_drv_115 +vboxvideo_drv_115_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_115_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_115_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11500000 +vboxvideo_drv_115_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.15.0 +vboxvideo_drv_115_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_115_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_115_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_116 +# +DLLS += vboxvideo_drv_116 +vboxvideo_drv_116_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_116_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_116_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11600000 +vboxvideo_drv_116_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.16.0 +vboxvideo_drv_116_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_116_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_116_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_117 +# +DLLS += vboxvideo_drv_117 +vboxvideo_drv_117_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_117_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_117_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11700000 +vboxvideo_drv_117_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.17.1 +vboxvideo_drv_117_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_117_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_117_LIBS += $(vboxvideo_drv_70_LIBS) + + +# +# vboxvideo_drv_118 +# +DLLS += vboxvideo_drv_118 +vboxvideo_drv_118_TEMPLATE = VBOXGUESTR3XORGMOD +vboxvideo_drv_118_CFLAGS := $(vboxvideo_drv_70_CFLAGS) +vboxvideo_drv_118_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11800000 +vboxvideo_drv_118_INCS = \ + $(vboxvideo_xorg_INCS) \ + $(VBOX_PATH_X11_ROOT)/xorg-server-1.18.0 +vboxvideo_drv_118_INCS += $(PATH_ROOT)/src/VBox/Runtime/include +vboxvideo_drv_118_SOURCES := $(vboxvideo_drv_17_SOURCES) +vboxvideo_drv_118_LIBS += $(vboxvideo_drv_70_LIBS) + +ifdef VBOX_USE_SYSTEM_XORG_HEADERS + # Build using local X.Org headers. We assume X.Org Server 1.7 or later. + DLLS := $(filter-out vboxvideo_drv_%,$(DLLS)) vboxvideo_drv_system + SYSMODS := $(filter-out vboxvideo_drv%,$(SYSMODS)) + vboxvideo_drv_system_TEMPLATE = VBOXGUESTR3XORGMOD + vboxvideo_drv_system_CFLAGS := \ + $(vboxvideo_drv_70_CFLAGS) -include xorg-server.h + vboxvideo_drv_system_DEFS := $(filter-out _XORG_SERVER_H_ _DIX_CONFIG_H_, $(vboxvideo_15_DEFS)) + vboxvideo_drv_system_INCS += \ + $(PATH_ROOT)/src/VBox/Runtime/include \ + $(VBOX_GRAPHICS_INCS) \ + /usr/include/xorg \ + /usr/include/pixman-1 + vboxvideo_drv_system_SOURCES := $(vboxvideo_drv_17_SOURCES) +endif + + +# Check the undefined symbols in the X.Org modules against lists of allowed +# symbols. Not very elegant, but it will catch problems early. + +ifdef VBOX_WITH_TESTCASES +# ifndef VBOX_ONLY_ADDITIONS + ifndef VBOX_USE_SYSTEM_XORG_HEADERS + if1of ($(KBUILD_TARGET),linux solaris) + ifeq ($(KBUILD_HOST_ARCH),$(KBUILD_TARGET_ARCH)) + ifndef VBOX_ONLY_SDK + VBOXVIDEO_SRC_PATH := $(PATH_SUB_CURRENT) + + ifeq ($(KBUILD_TARGET),linux) + TESTING += $(vboxvideo_drv_0_OUTDIR)/tstvboxvideo68.run + OTHERS += $(vboxvideo_drv_0_OUTDIR)/tstvboxvideo68.run +$$(vboxvideo_drv_0_OUTDIR)/tstvboxvideo68.run: $$(vboxvideo_drv_1_STAGE_TARGET) + $(QUIET)$(call MSG_L1,Checking for unresolved symbols in $<) + $(QUIET)$(ASH) $(PATH_ROOT)/src/bldprogs/checkUndefined.sh $(KBUILD_HOST) \ + $(vboxvideo_drv_1_STAGE_TARGET) --static $(VBOXVIDEO_SRC_PATH)/../undefined_xfree86 $(VBOXVIDEO_SRC_PATH)/../undefined_xfree86_modules + $(QUIET)$(APPEND) -t "$@" "done" + endif + +## +# Using the extra expansion to replace $(ver) before eval, thus everything +# else needs escaped dollars. + define def_vboxvideo_test + TESTING += $$(vboxvideo_drv$(ver)_0_OUTDIR)/tstvboxvideo$(ver).run + OTHERS += $$(vboxvideo_drv$(ver)_0_OUTDIR)/tstvboxvideo$(ver).run + $$$$(vboxvideo_drv$(ver)_0_OUTDIR)/tstvboxvideo$(ver).run: $$$$(vboxvideo_drv$(ver)_1_STAGE_TARGET) + $$(QUIET)$$(call MSG_L1,Checking for unresolved symbols in $$<) + $$(QUIET)$$(ASH) $$(PATH_ROOT)/src/bldprogs/checkUndefined.sh $$(KBUILD_HOST) \ + $$(vboxvideo_drv$(ver)_1_STAGE_TARGET) $$(VBOXVIDEO_SRC_PATH)/../undefined_xfree86 $(VBOXVIDEO_SRC_PATH)/../undefined_xfree86_modules $$(VBOXVIDEO_SRC_PATH)/../undefined_xorg + $$(QUIET)$$(APPEND) -t "$$@" "done" + endef + + $(foreach ver, _70 _71 _13 _14 _15 _16 _17 _18 _19 _110 _111 _112 _113 _114 _115 _116 _117 _118, $(eval $(def_vboxvideo_test))) + + endif # ! VBOX_ONLY_SDK + endif # eq ($(KBUILD_HOST_ARCH),$(KBUILD_TARGET_ARCH)) + endif # 1of ($(KBUILD_TARGET),linux solaris) + endif # ! VBOX_USE_SYSTEM_XORG_HEADERS +# endif # ! VBOX_ONLY_ADDITIONS +endif # VBOX_WITH_TESTCASES + +include $(FILE_KBUILD_SUB_FOOTER) diff --git a/src/VBox/Additions/x11/vboxvideo/README.testing b/src/VBox/Additions/x11/vboxvideo/README.testing new file mode 100644 index 00000000..03d6482f --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/README.testing @@ -0,0 +1,33 @@ +This file contains some notes about things to try out to give the X.Org video +driver a reasonably thorough test. We will add cases of things which have been +known to fail in the past to this file as we discover them. Tests should be +carried out with Additions installed, and both with and without 3D enabled in +the machine settings. + + * Test XFree86 guests (CentOS 3), early X.Org (CentOS 5) and recent + (CentOS 6 and 7, current Ubuntu/Fedora). Test Solaris guests (10 and 11?). + * Dynamic resizing should work, on CentOS 6 and later Linux guests it should + work without VBoxClient running. + * Disabling and enabling virtual screens (VBoxManage in 4.3). + * Dynamic resizing with one of more virtual screens disabled. + * Test switching to virtual terminals and back from windowed, full screen and + seamless modes (seamless currently only works properly with VBoxClient + running). + * Test switching directly between normal, full-screen, seamless and scaled + modes. + * Test re-ordering the virtual screen using the native guest operating system + tools and make sure that mouse integration still works as expected. + * Test disabling and re-enabling guest screens with the native system tools. + * Try disabling and re-enabling mouse integration and check that capturing + works with multiple guest screens. + * Shutting down and re-starting a virtual machine should restore the last size + for all monitors (note: currently only after log-in). Full shut-down, not + a reboot. + * Test power management by disabling guest screens ("xrandr --output VGA-n + --off") and re-enabling them ("xrandr --output VGA-n --preferred --pos XxY") + where X and Y are the position of the screen before disabling it. + * Test sending video mode hints with screen position information via + VBoxManage. The screen position is a hint only. The approximate position + should be preserved after a shut down and re-start of the guest. + * Test re-starting the X server after resizing all guest windows. The server + should not crash. diff --git a/src/VBox/Additions/x11/vboxvideo/VBoxVideoIPRT.h b/src/VBox/Additions/x11/vboxvideo/VBoxVideoIPRT.h new file mode 100644 index 00000000..ec1e397c --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/VBoxVideoIPRT.h @@ -0,0 +1,243 @@ +/* $Id: VBoxVideoIPRT.h $ */ +/* + * Copyright (C) 2017-2022 Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/* In builds inside of the VirtualBox source tree we override the default + * VBoxVideoIPRT.h using -include, therefore this define must match the one + * there. */ + +#ifndef VBOX_INCLUDED_Graphics_VBoxVideoIPRT_h +#define VBOX_INCLUDED_Graphics_VBoxVideoIPRT_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +# include "VBoxVideoErr.h" + +#ifndef __cplusplus +typedef enum +{ + false = 0, + true +} bool; +# define RT_C_DECLS_BEGIN +# define RT_C_DECLS_END +#else +# define RT_C_DECLS_BEGIN extern "C" { +# define RT_C_DECLS_END } +#endif + +#if defined(IN_XF86_MODULE) && !defined(NO_ANSIC) +# ifdef __cplusplus +/* xf86Module.h redefines this. */ +# define NULL 0 +# endif +RT_C_DECLS_BEGIN +# include "xf86_ansic.h" +RT_C_DECLS_END +#endif /* defined(IN_XF86_MODULE) && !defined(NO_ANSIC) */ +#define __STDC_LIMIT_MACROS /* define *INT*_MAX on C++ too. */ +#include "compiler.h" /* Can pull in <sdtint.h>. Must come after xf86_ansic.h on XFree86. */ +#include <X11/Xfuncproto.h> +#include <stdint.h> +#if defined(IN_XF86_MODULE) && !defined(NO_ANSIC) +# ifndef offsetof +# define offsetof(type, member) ( (int)(uintptr_t)&( ((type *)(void *)0)->member) ) +# endif +#else /* !(defined(IN_XF86_MODULE) && !defined(NO_ANSIC)) */ +# include <stdarg.h> +# include <stddef.h> +# include <string.h> +#endif /* !(defined(IN_XF86_MODULE) && !defined(NO_ANSIC)) */ + +/* XFree86 (and newer Xfuncproto.h) do not have these. Not that I care much for micro-optimisations + * in most cases anyway. */ +#ifndef _X_LIKELY +# define _X_LIKELY(x) (x) +#endif +#ifndef _X_UNLIKELY +# define _X_UNLIKELY(x) (x) +#endif + +RT_C_DECLS_BEGIN +extern int RTASSERTVAR[1]; +RT_C_DECLS_END + +#define AssertCompile(expr) \ + extern int RTASSERTVAR[1] __attribute__((__unused__)), \ + RTASSERTVAR[(expr) ? 1 : 0] __attribute__((__unused__)) +#define AssertCompileSize(type, size) \ + AssertCompile(sizeof(type) == (size)) +#define AssertPtrNullReturnVoid(a) do { } while(0) + +#if !defined(IN_XF86_MODULE) && defined(DEBUG) +# include <assert.h> +# define Assert assert +# define AssertFailed() assert(0) +# define AssertMsg(expr, msg) \ + do { \ + if (!(expr)) xf86ErrorF msg; \ + assert((expr)); \ + } while (0) +# define AssertPtr assert +# define AssertPtrReturn(pv, rcRet) do { assert(pv); if (pv) {} else return(rcRet); } while(0) +# define AssertRC(expr) assert (!expr) +#else +# define Assert(expr) do { } while(0) +# define AssertFailed() do { } while(0) +# define AssertMsg(expr, msg) do { } while(0) +# define AssertPtr(ptr) do { } while(0) +# define AssertPtrReturn(pv, rcRet) do { if (pv) {} else return(rcRet); } while(0) +# define AssertRC(expr) do { } while(0) +#endif + +#define DECLCALLBACK(a_RetType) a_RetType +#define DECLCALLBACKTYPE(a_RetType, a_Name, a_Args) a_RetType a_Name a_Args +#define DECLCALLBACKMEMBER(a_RetType, a_Name, a_Args) a_RetType (*a_Name) a_Args +#if __GNUC__ >= 4 +# define DECLHIDDEN(type) __attribute__((visibility("hidden"))) type +#else +# define DECLHIDDEN(type) type +#endif +#define DECLINLINE(type) static __inline__ type + +#define _1K 1024 +#define ASMCompilerBarrier mem_barrier +#define RT_BIT(bit) ( 1U << (bit) ) +#define RT_BOOL(Value) ( !!(Value) ) +#define RT_BZERO(pv, cb) do { memset((pv), 0, cb); } while (0) +#define RT_CLAMP(Value, Min, Max) ( (Value) > (Max) ? (Max) : (Value) < (Min) ? (Min) : (Value) ) +#define RT_ELEMENTS(aArray) ( sizeof(aArray) / sizeof((aArray)[0]) ) +#define RTIOPORT unsigned short +#define RT_NOREF(...) (void)(__VA_ARGS__) +#define RT_OFFSETOF(type, member) offsetof(type, member) +#define RT_UOFFSETOF(type, member) offsetof(type, member) +#define RT_ZERO(Obj) RT_BZERO(&(Obj), sizeof(Obj)) +#define RT_VALID_PTR(ptr) ( (uintptr_t)(ptr) + 0x1000U >= 0x2000U ) +#ifndef INT16_C +# define INT16_C(Value) (Value) +#endif +#ifndef UINT16_C +# define UINT16_C(Value) (Value) +#endif +#ifndef INT32_C +# define INT32_C(Value) (Value ## U) +#endif +#ifndef UINT32_C +# define UINT32_C(Value) (Value ## U) +#endif +#define RT_UNTRUSTED_GUEST +#define RT_UNTRUSTED_VOLATILE_GUEST volatile +#define RT_UNTRUSTED_HOST +#define RT_UNTRUSTED_VOLATILE_HOST volatile +#define RT_UNTRUSTED_HSTGST +#define RT_UNTRUSTED_VOLATILE_HSTGST volatile + +#define likely _X_LIKELY +#define unlikely _X_UNLIKELY + +/** + * A point in a two dimentional coordinate system. + */ +typedef struct RTPOINT +{ + /** X coordinate. */ + int32_t x; + /** Y coordinate. */ + int32_t y; +} RTPOINT; + +/** + * Rectangle data type, double point. + */ +typedef struct RTRECT +{ + /** left X coordinate. */ + int32_t xLeft; + /** top Y coordinate. */ + int32_t yTop; + /** right X coordinate. (exclusive) */ + int32_t xRight; + /** bottom Y coordinate. (exclusive) */ + int32_t yBottom; +} RTRECT; + +/** + * Rectangle data type, point + size. + */ +typedef struct RTRECT2 +{ + /** X coordinate. + * Unless stated otherwise, this is the top left corner. */ + int32_t x; + /** Y coordinate. + * Unless stated otherwise, this is the top left corner. */ + int32_t y; + /** The width. + * Unless stated otherwise, this is to the right of (x,y) and will not + * be a negative number. */ + int32_t cx; + /** The height. + * Unless stated otherwise, this is down from (x,y) and will not be a + * negative number. */ + int32_t cy; +} RTRECT2; + +/** + * The size of a rectangle. + */ +typedef struct RTRECTSIZE +{ + /** The width (along the x-axis). */ + uint32_t cx; + /** The height (along the y-axis). */ + uint32_t cy; +} RTRECTSIZE; + +/** @name Port I/O helpers + * @{ */ + +/** Write an 8-bit value to an I/O port. */ +#define VBVO_PORT_WRITE_U8(Port, Value) \ + outb(Port, Value) +/** Write a 16-bit value to an I/O port. */ +#define VBVO_PORT_WRITE_U16(Port, Value) \ + outw(Port, Value) +/** Write a 32-bit value to an I/O port. */ +#define VBVO_PORT_WRITE_U32(Port, Value) \ + outl(Port, Value) +/** Read an 8-bit value from an I/O port. */ +#define VBVO_PORT_READ_U8(Port) \ + inb(Port) +/** Read a 16-bit value from an I/O port. */ +#define VBVO_PORT_READ_U16(Port) \ + inw(Port) +/** Read a 32-bit value from an I/O port. */ +#define VBVO_PORT_READ_U32(Port) \ + inl(Port) + +/** @} */ + +#endif /* !VBOX_INCLUDED_Graphics_VBoxVideoIPRT_h */ diff --git a/src/VBox/Additions/x11/vboxvideo/edid.c b/src/VBox/Additions/x11/vboxvideo/edid.c new file mode 100644 index 00000000..265ecbe9 --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/edid.c @@ -0,0 +1,165 @@ +/* $Id: edid.c $ */ +/** @file + * + * Linux Additions X11 graphics driver, EDID construction + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * This file is based on drmmode_display.c from the X.Org xf86-video-intel + * driver with the following copyright notice: + * + * Copyright © 2007 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Authors: + * Dave Airlie <airlied@redhat.com> + * Michael Thayer <michael.thayer@oracle.com> + */ + +#include "misc.h" +#include "xf86DDC.h" +#include "xf86Crtc.h" +#include "vboxvideo.h" + +enum { EDID_SIZE = 128 }; + +const unsigned char g_acszEDIDBase[EDID_SIZE] = +{ + 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, /* header */ + 0x58, 0x58, /* manufacturer (VBX) */ + 0x00, 0x00, /* product code */ + 0x00, 0x00,0x00, 0x00, /* serial number goes here */ + 0x01, /* week of manufacture */ + 0x00, /* year of manufacture */ + 0x01, 0x03, /* EDID version */ + 0x80, /* capabilities - digital */ + 0x00, /* horiz. res in cm, zero for projectors */ + 0x00, /* vert. res in cm */ + 0x78, /* display gamma (120 == 2.2). Should we ask the host for this? */ + 0xEE, /* features (standby, suspend, off, RGB, standard colour space, + * preferred timing mode) */ + 0xEE, 0x91, 0xA3, 0x54, 0x4C, 0x99, 0x26, 0x0F, 0x50, 0x54, + /* chromaticity for standard colour space - should we ask the host? */ + 0x00, 0x00, 0x00, /* no default timings */ + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, /* no standard timings */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* descriptor block 1 goes here */ + 0x00, 0x00, 0x00, 0xFD, 0x00, /* descriptor block 2, monitor ranges */ + 0x00, 0xC8, 0x00, 0xC8, 0x64, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, /* 0-200Hz vertical, 0-200KHz horizontal, 1000MHz pixel clock */ + 0x00, 0x00, 0x00, 0xFC, 0x00, /* descriptor block 3, monitor name */ + 'V', 'B', 'O', 'X', ' ', 'm', 'o', 'n', 'i', 't', 'o', 'r', '\n', + 0x00, 0x00, 0x00, 0x10, 0x00, /* descriptor block 4: dummy data */ + 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, + 0x20, + 0x00, /* number of extensions */ + 0x00 /* checksum goes here */ +}; + +static void fillDescBlockTimings(unsigned char *pchDescBlock, + DisplayModePtr mode) +{ + struct detailed_timings timing; + + timing.clock = mode->Clock * 1000; + timing.h_active = mode->HDisplay; + timing.h_blanking = mode->HTotal - mode->HDisplay; + timing.v_active = mode->VDisplay; + timing.v_blanking = mode->VTotal - mode->VDisplay; + timing.h_sync_off = mode->HSyncStart - mode->HDisplay; + timing.h_sync_width = mode->HSyncEnd - mode->HSyncStart; + timing.v_sync_off = mode->VSyncStart - mode->VDisplay; + timing.v_sync_width = mode->VSyncEnd - mode->VSyncStart; + pchDescBlock[0] = (timing.clock / 10000) & 0xff; + pchDescBlock[1] = (timing.clock / 10000) >> 8; + pchDescBlock[2] = timing.h_active & 0xff; + pchDescBlock[3] = timing.h_blanking & 0xff; + pchDescBlock[4] = (timing.h_active >> 4) & 0xf0; + pchDescBlock[4] |= (timing.h_blanking >> 8) & 0xf; + pchDescBlock[5] = timing.v_active & 0xff; + pchDescBlock[6] = timing.v_blanking & 0xff; + pchDescBlock[7] = (timing.v_active >> 4) & 0xf0; + pchDescBlock[7] |= (timing.v_blanking >> 8) & 0xf; + pchDescBlock[8] = timing.h_sync_off & 0xff; + pchDescBlock[9] = timing.h_sync_width & 0xff; + pchDescBlock[10] = (timing.v_sync_off << 4) & 0xf0; + pchDescBlock[10] |= timing.v_sync_width & 0xf; + pchDescBlock[11] = (timing.h_sync_off >> 2) & 0xC0; + pchDescBlock[11] |= (timing.h_sync_width >> 4) & 0x30; + pchDescBlock[11] |= (timing.v_sync_off >> 2) & 0xC; + pchDescBlock[11] |= (timing.v_sync_width >> 4) & 0x3; + pchDescBlock[12] = pchDescBlock[13] = pchDescBlock[14] + = pchDescBlock[15] = pchDescBlock[16] + = pchDescBlock[17] = 0; +} + + +static void setEDIDChecksum(unsigned char *pch) +{ + unsigned i, sum = 0; + for (i = 0; i < EDID_SIZE - 1; ++i) + sum += pch[i]; + pch[EDID_SIZE - 1] = (0x100 - (sum & 0xFF)) & 0xFF; +} + + +/** + * Construct an EDID for an output given a preferred mode. The main reason for + * doing this is to confound gnome-settings-deamon which tries to reset the + * last mode configuration if the same monitors are plugged in again, which is + * a reasonable thing to do but not what we want in a VM. We evily store + * the (empty) raw EDID data at the end of the structure so that it gets + * freed automatically along with the structure. + */ +Bool VBOXEDIDSet(xf86OutputPtr output, DisplayModePtr pmode) +{ + unsigned char *pch, *pchEDID; + xf86MonPtr pEDIDMon; + + pch = calloc(1, sizeof(xf86Monitor) + EDID_SIZE); + if (!pch) + { + xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, + "Can't allocate memory for EDID structure.\n"); + return FALSE; + } + pchEDID = pch + sizeof(xf86Monitor); + memcpy(pchEDID, g_acszEDIDBase, EDID_SIZE); + pchEDID[12] = pmode->HDisplay & 0xff; + pchEDID[13] = pmode->HDisplay >> 8; + pchEDID[14] = pmode->VDisplay & 0xff; + pchEDID[15] = pmode->VDisplay >> 8; + fillDescBlockTimings(pchEDID + 54, pmode); + setEDIDChecksum(pchEDID); + pEDIDMon = xf86InterpretEDID(output->scrn->scrnIndex, pchEDID); + if (!pEDIDMon) + { + free(pch); + return FALSE; + } + memcpy(pch, pEDIDMon, sizeof(xf86Monitor)); + free(pEDIDMon); + pEDIDMon = (xf86MonPtr)pch; + xf86OutputSetEDID(output, pEDIDMon); + return TRUE; +} diff --git a/src/VBox/Additions/x11/vboxvideo/getmode.c b/src/VBox/Additions/x11/vboxvideo/getmode.c new file mode 100644 index 00000000..30383541 --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/getmode.c @@ -0,0 +1,325 @@ +/* $Id: getmode.c $ */ +/** @file + * VirtualBox X11 Additions graphics driver dynamic video mode functions. + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "vboxvideo.h" + +#define NEED_XF86_TYPES +#include "xf86.h" + +#ifdef XORG_7X +# include <stdio.h> +# include <stdlib.h> +# include <string.h> +#endif + +#ifdef VBOXVIDEO_13 +# ifdef RT_OS_LINUX +# include <linux/input.h> +# ifndef EVIOCGRAB +# define EVIOCGRAB _IOW('E', 0x90, int) +# endif +# ifndef KEY_SWITCHVIDEOMODE +# define KEY_SWITCHVIDEOMODE 227 +# endif +# include <dirent.h> +# include <errno.h> +# include <fcntl.h> +# include <unistd.h> +# endif /* RT_OS_LINUX */ +#endif /* VBOXVIDEO_13 */ + +/************************************************************************** +* Main functions * +**************************************************************************/ + +/** + * Fills a display mode M with a built-in mode of name pszName and dimensions + * cx and cy. + */ +static void vboxFillDisplayMode(ScrnInfoPtr pScrn, DisplayModePtr m, + const char *pszName, unsigned cx, unsigned cy) +{ + VBOXPtr pVBox = pScrn->driverPrivate; + char szName[256]; + DisplayModePtr pPrev = m->prev; + DisplayModePtr pNext = m->next; + + if (!pszName) + { + sprintf(szName, "%ux%u", cx, cy); + pszName = szName; + } + TRACE_LOG("pszName=%s, cx=%u, cy=%u\n", pszName, cx, cy); + if (m->name) + free((void*)m->name); + memset(m, '\0', sizeof(*m)); + m->prev = pPrev; + m->next = pNext; + m->status = MODE_OK; + m->type = M_T_BUILTIN; + /* Older versions of VBox only support screen widths which are a multiple + * of 8 */ + if (pVBox->fAnyX) + m->HDisplay = cx; + else + m->HDisplay = cx & ~7; + m->HSyncStart = m->HDisplay + 2; + m->HSyncEnd = m->HDisplay + 4; + m->HTotal = m->HDisplay + 6; + m->VDisplay = cy; + m->VSyncStart = m->VDisplay + 2; + m->VSyncEnd = m->VDisplay + 4; + m->VTotal = m->VDisplay + 6; + m->Clock = m->HTotal * m->VTotal * 60 / 1000; /* kHz */ + m->name = xnfstrdup(pszName); +} + +/** + * Allocates an empty display mode and links it into the doubly linked list of + * modes pointed to by pScrn->modes. Returns a pointer to the newly allocated + * memory. + */ +static DisplayModePtr vboxAddEmptyScreenMode(ScrnInfoPtr pScrn) +{ + DisplayModePtr pMode = xnfcalloc(sizeof(DisplayModeRec), 1); + + TRACE_ENTRY(); + if (!pScrn->modes) + { + pScrn->modes = pMode; + pMode->next = pMode; + pMode->prev = pMode; + } + else + { + pMode->next = pScrn->modes; + pMode->prev = pScrn->modes->prev; + pMode->next->prev = pMode; + pMode->prev->next = pMode; + } + return pMode; +} + +/** + * Create display mode entries in the screen information structure for each + * of the graphics modes that we wish to support, that is: + * - A dynamic mode in first place which will be updated by the RandR code. + * - Any modes that the user requested in xorg.conf/XFree86Config. + */ +void vboxAddModes(ScrnInfoPtr pScrn) +{ + unsigned cx = 0; + unsigned cy = 0; + unsigned i; + DisplayModePtr pMode; + + /* Add two dynamic mode entries. When we receive a new size hint we will + * update whichever of these is not current. */ + pMode = vboxAddEmptyScreenMode(pScrn); + vboxFillDisplayMode(pScrn, pMode, NULL, 800, 600); + pMode = vboxAddEmptyScreenMode(pScrn); + vboxFillDisplayMode(pScrn, pMode, NULL, 800, 600); + /* Add any modes specified by the user. We assume here that the mode names + * reflect the mode sizes. */ + for (i = 0; pScrn->display->modes && pScrn->display->modes[i]; i++) + { + if (sscanf(pScrn->display->modes[i], "%ux%u", &cx, &cy) == 2) + { + pMode = vboxAddEmptyScreenMode(pScrn); + vboxFillDisplayMode(pScrn, pMode, pScrn->display->modes[i], cx, cy); + } + } +} + +/** Set the initial values for the guest screen size hints to standard values + * in case nothing else is available. */ +void VBoxInitialiseSizeHints(ScrnInfoPtr pScrn) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + unsigned i; + + for (i = 0; i < pVBox->cScreens; ++i) + { + pVBox->pScreens[i].aPreferredSize.cx = 800; + pVBox->pScreens[i].aPreferredSize.cy = 600; + pVBox->pScreens[i].afConnected = true; + } + /* Set up the first mode correctly to match the requested initial mode. */ + pScrn->modes->HDisplay = pVBox->pScreens[0].aPreferredSize.cx; + pScrn->modes->VDisplay = pVBox->pScreens[0].aPreferredSize.cy; +} + +static Bool useHardwareCursor(uint32_t fCursorCapabilities) +{ + if (fCursorCapabilities & VBOX_VBVA_CURSOR_CAPABILITY_HARDWARE) + return true; + return false; +} + +static void compareAndMaybeSetUseHardwareCursor(VBOXPtr pVBox, uint32_t fCursorCapabilities, Bool *pfChanged, Bool fSet) +{ + if (pVBox->fUseHardwareCursor != useHardwareCursor(fCursorCapabilities)) + *pfChanged = true; + if (fSet) + pVBox->fUseHardwareCursor = useHardwareCursor(fCursorCapabilities); +} + +#define COMPARE_AND_MAYBE_SET(pDest, src, pfChanged, fSet) \ +do { \ + if (*(pDest) != (src)) \ + { \ + if (fSet) \ + *(pDest) = (src); \ + *(pfChanged) = true; \ + } \ +} while(0) + +/** Read in information about the most recent size hints and cursor + * capabilities requested for the guest screens from HGSMI. */ +void vbvxReadSizesAndCursorIntegrationFromHGSMI(ScrnInfoPtr pScrn, Bool *pfNeedUpdate) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + int rc; + unsigned i; + Bool fChanged = false; + uint32_t fCursorCapabilities; + + if (!pVBox->fHaveHGSMIModeHints) + return; + rc = VBoxHGSMIGetModeHints(&pVBox->guestCtx, pVBox->cScreens, pVBox->paVBVAModeHints); + AssertMsg(rc == VINF_SUCCESS, ("VBoxHGSMIGetModeHints failed, rc=%d.\n", rc)); + for (i = 0; i < pVBox->cScreens; ++i) + if (pVBox->paVBVAModeHints[i].magic == VBVAMODEHINT_MAGIC) + { + COMPARE_AND_MAYBE_SET(&pVBox->pScreens[i].aPreferredSize.cx, pVBox->paVBVAModeHints[i].cx & 0x8fff, &fChanged, true); + COMPARE_AND_MAYBE_SET(&pVBox->pScreens[i].aPreferredSize.cy, pVBox->paVBVAModeHints[i].cy & 0x8fff, &fChanged, true); + COMPARE_AND_MAYBE_SET(&pVBox->pScreens[i].afConnected, RT_BOOL(pVBox->paVBVAModeHints[i].fEnabled), &fChanged, true); + COMPARE_AND_MAYBE_SET(&pVBox->pScreens[i].aPreferredLocation.x, (int32_t)pVBox->paVBVAModeHints[i].dx & 0x8fff, &fChanged, + true); + COMPARE_AND_MAYBE_SET(&pVBox->pScreens[i].aPreferredLocation.y, (int32_t)pVBox->paVBVAModeHints[i].dy & 0x8fff, &fChanged, + true); + if (pVBox->paVBVAModeHints[i].dx != ~(uint32_t)0 && pVBox->paVBVAModeHints[i].dy != ~(uint32_t)0) + COMPARE_AND_MAYBE_SET(&pVBox->pScreens[i].afHaveLocation, true, &fChanged, true); + else + COMPARE_AND_MAYBE_SET(&pVBox->pScreens[i].afHaveLocation, false, &fChanged, true); + } + rc = VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_CURSOR_CAPABILITIES, &fCursorCapabilities); + AssertMsg(rc == VINF_SUCCESS, ("Getting VBOX_VBVA_CONF32_CURSOR_CAPABILITIES failed, rc=%d.\n", rc)); + compareAndMaybeSetUseHardwareCursor(pVBox, fCursorCapabilities, &fChanged, true); + if (pfNeedUpdate != NULL && fChanged) + *pfNeedUpdate = true; +} + +#undef COMPARE_AND_MAYBE_SET + +#ifdef VBOXVIDEO_13 +# ifdef RT_OS_LINUX +/** We have this for two purposes: one is to ensure that the X server is woken + * up when we get a video ACPI event. Two is to grab ACPI video events to + * prevent gnome-settings-daemon from seeing them, as older versions ignored + * the time stamp and handled them at the wrong time. */ +static void acpiEventHandler(int fd, void *pvData) +{ + struct input_event event; + ssize_t rc; + RT_NOREF(pvData); + + do + rc = read(fd, &event, sizeof(event)); + while (rc > 0 || (rc == -1 && errno == EINTR)); + /* Why do they return EAGAIN instead of zero bytes read like everyone else does? */ + AssertMsg(rc != -1 || errno == EAGAIN, ("Reading ACPI input event failed.\n")); +} + +void vbvxSetUpLinuxACPI(ScreenPtr pScreen) +{ + static const char s_szDevInput[] = "/dev/input/"; + struct dirent *pDirent; + char szFile[sizeof(s_szDevInput) + sizeof(pDirent->d_name) + 16]; + VBOXPtr pVBox = VBOXGetRec(xf86Screens[pScreen->myNum]); + DIR *pDir; + int fd = -1; + + if (pVBox->fdACPIDevices != -1 || pVBox->hACPIEventHandler != NULL) + FatalError("ACPI input file descriptor not initialised correctly.\n"); + pDir = opendir("/dev/input"); + if (pDir == NULL) + return; + memcpy(szFile, s_szDevInput, sizeof(s_szDevInput)); + for (pDirent = readdir(pDir); pDirent != NULL; pDirent = readdir(pDir)) + { + if (strncmp(pDirent->d_name, "event", sizeof("event") - 1) == 0) + { +#define BITS_PER_BLOCK (sizeof(unsigned long) * 8) + char szDevice[64] = ""; + unsigned long afKeys[KEY_MAX / BITS_PER_BLOCK]; + size_t const cchName = strlen(pDirent->d_name); + if (cchName + sizeof(s_szDevInput) > sizeof(szFile)) + continue; + memcpy(&szFile[sizeof(s_szDevInput) - 1], pDirent->d_name, cchName + 1); + if (fd != -1) + close(fd); + fd = open(szFile, O_RDONLY | O_NONBLOCK); + if ( fd == -1 + || ioctl(fd, EVIOCGNAME(sizeof(szDevice)), szDevice) == -1 + || strcmp(szDevice, "Video Bus") != 0) + continue; + if ( ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(afKeys)), afKeys) == -1 + || (( afKeys[KEY_SWITCHVIDEOMODE / BITS_PER_BLOCK] + >> KEY_SWITCHVIDEOMODE % BITS_PER_BLOCK) & 1) == 0) + break; + if (ioctl(fd, EVIOCGRAB, (void *)1) != 0) + break; + pVBox->hACPIEventHandler + = xf86AddGeneralHandler(fd, acpiEventHandler, pScreen); + if (pVBox->hACPIEventHandler == NULL) + break; + pVBox->fdACPIDevices = fd; + fd = -1; + break; +#undef BITS_PER_BLOCK + } + } + if (fd != -1) + close(fd); + closedir(pDir); +} + +void vbvxCleanUpLinuxACPI(ScreenPtr pScreen) +{ + VBOXPtr pVBox = VBOXGetRec(xf86Screens[pScreen->myNum]); + if (pVBox->fdACPIDevices != -1) + close(pVBox->fdACPIDevices); + pVBox->fdACPIDevices = -1; + xf86RemoveGeneralHandler(pVBox->hACPIEventHandler); + pVBox->hACPIEventHandler = NULL; +} +# endif /* RT_OS_LINUX */ +#endif /* VBOXVIDEO_13 */ diff --git a/src/VBox/Additions/x11/vboxvideo/hgsmimemalloc.c b/src/VBox/Additions/x11/vboxvideo/hgsmimemalloc.c new file mode 100644 index 00000000..02cf199d --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/hgsmimemalloc.c @@ -0,0 +1,104 @@ +/* $Id: hgsmimemalloc.c $ */ +/* + * Copyright (C) 2017-2022 Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * Memory allocator + * ---------------- + * + * Implementation + * -------------- + * + * Since the X.Org driver is single threaded and works using an allocate, + * submit and free pattern, we replace the generic allocator with a simple + * Boolean. Need more be said? + * + * bird> Yes, it's buggy. You never set fAllocated. See HGSMIMAAlloc(). + */ + +#include <VBoxVideoIPRT.h> +#include <HGSMIMemAlloc.h> +#include <HGSMI.h> + +int HGSMIMAInit(HGSMIMADATA *pMA, const HGSMIAREA *pArea, + HGSMIOFFSET *paDescriptors, uint32_t cDescriptors, HGSMISIZE cbMaxBlock, + const HGSMIENV *pEnv) +{ + (void)paDescriptors; + (void)cDescriptors; + (void)cbMaxBlock; + (void)pEnv; + if (!(pArea->cbArea < UINT32_C(0x80000000))) + return VERR_INVALID_PARAMETER; + if (!(pArea->cbArea >= HGSMI_MA_BLOCK_SIZE_MIN)) + return VERR_INVALID_PARAMETER; + + pMA->area = *pArea; + pMA->fAllocated = false; + return VINF_SUCCESS; +} + +void HGSMIMAUninit(HGSMIMADATA *pMA) +{ + (void)pMA; +} + +static HGSMIOFFSET HGSMIMAPointerToOffset(const HGSMIMADATA *pMA, const void RT_UNTRUSTED_VOLATILE_GUEST *pv) +{ + if (HGSMIAreaContainsPointer(&pMA->area, pv)) + return HGSMIPointerToOffset(&pMA->area, pv); + + AssertFailed(); + return HGSMIOFFSET_VOID; +} + +static void RT_UNTRUSTED_VOLATILE_GUEST *HGSMIMAOffsetToPointer(const HGSMIMADATA *pMA, HGSMIOFFSET off) +{ + if (HGSMIAreaContainsOffset(&pMA->area, off)) + return HGSMIOffsetToPointer(&pMA->area, off); + + AssertFailed(); + return NULL; +} + +void RT_UNTRUSTED_VOLATILE_GUEST *HGSMIMAAlloc(HGSMIMADATA *pMA, HGSMISIZE cb) +{ + (void)cb; + if (pMA->fAllocated) + return NULL; + HGSMIOFFSET off = pMA->area.offBase; + return HGSMIMAOffsetToPointer(pMA, off); + pMA->fAllocated = true; /** @todo r=bird: Errr. what's this doing *after* the return statement? */ +} + +void HGSMIMAFree(HGSMIMADATA *pMA, void RT_UNTRUSTED_VOLATILE_GUEST *pv) +{ + HGSMIOFFSET off = HGSMIMAPointerToOffset(pMA, pv); + if (off != HGSMIOFFSET_VOID) + pMA->fAllocated = false; + else + AssertFailed(); +} + diff --git a/src/VBox/Additions/x11/vboxvideo/pointer.c b/src/VBox/Additions/x11/vboxvideo/pointer.c new file mode 100644 index 00000000..96f09744 --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/pointer.c @@ -0,0 +1,496 @@ +/* $Id: pointer.c $ */ +/** @file + * VirtualBox X11 Additions graphics driver utility functions + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef PCIACCESS +# include "xf86Pci.h" +# include <Pci.h> +#endif + +#include "xf86.h" +#define NEED_XF86_TYPES +#include "compiler.h" +#include "cursorstr.h" +#include "servermd.h" + +#include "vboxvideo.h" + +#ifdef XORG_7X +# include <stdlib.h> +# include <string.h> +#endif + +#define VBOX_MAX_CURSOR_WIDTH 64 +#define VBOX_MAX_CURSOR_HEIGHT 64 + +/************************************************************************** +* Debugging functions and macros * +**************************************************************************/ + +/* #define DEBUG_POINTER */ + +#ifdef DEBUG +# define PUT_PIXEL(c) ErrorF ("%c", c) +#else /* DEBUG_VIDEO not defined */ +# define PUT_PIXEL(c) do { } while(0) +#endif /* DEBUG_VIDEO not defined */ + +/** Macro to printf an error message and return from a function */ +#define RETERROR(scrnIndex, RetVal, ...) \ + do \ + { \ + xf86DrvMsg(scrnIndex, X_ERROR, __VA_ARGS__); \ + return RetVal; \ + } \ + while (0) + +/** Structure to pass cursor image data between realise_cursor() and + * load_cursor_image(). The members match the parameters to + * @a VBoxHGSMIUpdatePointerShape(). */ +struct vboxCursorImage +{ + uint32_t fFlags; + uint32_t cHotX; + uint32_t cHotY; + uint32_t cWidth; + uint32_t cHeight; + uint8_t *pPixels; + uint32_t cbLength; +}; + +#ifdef DEBUG_POINTER +static void +vbox_show_shape(unsigned short w, unsigned short h, CARD32 bg, unsigned char *image) +{ + size_t x, y; + unsigned short pitch; + CARD32 *color; + unsigned char *mask; + size_t sizeMask; + + image += sizeof(struct vboxCursorImage); + mask = image; + pitch = (w + 7) / 8; + sizeMask = (pitch * h + 3) & ~3; + color = (CARD32 *)(image + sizeMask); + + TRACE_ENTRY(); + for (y = 0; y < h; ++y, mask += pitch, color += w) + { + for (x = 0; x < w; ++x) + { + if (mask[x / 8] & (1 << (7 - (x % 8)))) + ErrorF (" "); + else + { + CARD32 c = color[x]; + if (c == bg) + ErrorF("Y"); + else + ErrorF("X"); + } + } + ErrorF("\n"); + } +} +#endif + +/************************************************************************** +* Main functions * +**************************************************************************/ + +void vbvxCursorTerm(VBOXPtr pVBox) +{ + TRACE_ENTRY(); + + xf86DestroyCursorInfoRec(pVBox->pCurs); + pVBox->pCurs = NULL; + TRACE_EXIT(); +} + +static void +vbox_vmm_hide_cursor(ScrnInfoPtr pScrn, VBOXPtr pVBox) +{ + int rc; + RT_NOREF(pScrn); + + rc = VBoxHGSMIUpdatePointerShape(&pVBox->guestCtx, 0, 0, 0, 0, 0, NULL, 0); + AssertMsg(rc == VINF_SUCCESS, ("Could not hide the virtual mouse pointer, VBox error %d.\n", rc)); +} + +static void +vbox_vmm_show_cursor(ScrnInfoPtr pScrn, VBOXPtr pVBox) +{ + int rc; + RT_NOREF(pScrn); + + if (!pVBox->fUseHardwareCursor) + return; + rc = VBoxHGSMIUpdatePointerShape(&pVBox->guestCtx, VBOX_MOUSE_POINTER_VISIBLE, + 0, 0, 0, 0, NULL, 0); + AssertMsg(rc == VINF_SUCCESS, ("Could not unhide the virtual mouse pointer.\n")); +} + +static void +vbox_vmm_load_cursor_image(ScrnInfoPtr pScrn, VBOXPtr pVBox, + unsigned char *pvImage) +{ + int rc; + struct vboxCursorImage *pImage; + pImage = (struct vboxCursorImage *)pvImage; + RT_NOREF(pScrn); + +#ifdef DEBUG_POINTER + vbox_show_shape(pImage->cWidth, pImage->cHeight, 0, pvImage); +#endif + + rc = VBoxHGSMIUpdatePointerShape(&pVBox->guestCtx, pImage->fFlags, + pImage->cHotX, pImage->cHotY, pImage->cWidth, pImage->cHeight, + pImage->pPixels, pImage->cbLength); + AssertMsg(rc == VINF_SUCCESS, ("Unable to set the virtual mouse pointer image.\n")); +} + +static void +vbox_set_cursor_colors(ScrnInfoPtr pScrn, int bg, int fg) +{ + RT_NOREF(pScrn); + RT_NOREF(bg); + RT_NOREF(fg); + /* ErrorF("vbox_set_cursor_colors NOT IMPLEMENTED\n"); */ +} + + +static void +vbox_set_cursor_position(ScrnInfoPtr pScrn, int x, int y) +{ + VBOXPtr pVBox = pScrn->driverPrivate; + + /* This currently does nothing. */ + VBoxHGSMICursorPosition(&pVBox->guestCtx, true, x, y, NULL, NULL); +} + +static void +vbox_hide_cursor(ScrnInfoPtr pScrn) +{ + VBOXPtr pVBox = pScrn->driverPrivate; + + vbox_vmm_hide_cursor(pScrn, pVBox); +} + +static void +vbox_show_cursor(ScrnInfoPtr pScrn) +{ + VBOXPtr pVBox = pScrn->driverPrivate; + + vbox_vmm_show_cursor(pScrn, pVBox); +} + +static void +vbox_load_cursor_image(ScrnInfoPtr pScrn, unsigned char *image) +{ + VBOXPtr pVBox = pScrn->driverPrivate; + + vbox_vmm_load_cursor_image(pScrn, pVBox, image); +} + +static Bool +vbox_use_hw_cursor(ScreenPtr pScreen, CursorPtr pCurs) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + VBOXPtr pVBox = pScrn->driverPrivate; + RT_NOREF(pCurs); + return pVBox->fUseHardwareCursor; +} + +static unsigned char +color_to_byte(unsigned c) +{ + return (c >> 8) & 0xff; +} + +static unsigned char * +vbox_realize_cursor(xf86CursorInfoPtr infoPtr, CursorPtr pCurs) +{ + VBOXPtr pVBox; + CursorBitsPtr bitsp; + unsigned short w, h, x, y; + unsigned char *c, *p, *pm, *ps, *m; + size_t sizeRequest, sizeRgba, sizeMask, srcPitch, dstPitch; + CARD32 fc, bc, *cp; + int scrnIndex = infoPtr->pScrn->scrnIndex; + struct vboxCursorImage *pImage; + + pVBox = infoPtr->pScrn->driverPrivate; + bitsp = pCurs->bits; + w = bitsp->width; + h = bitsp->height; + + if (!w || !h || w > VBOX_MAX_CURSOR_WIDTH || h > VBOX_MAX_CURSOR_HEIGHT) + RETERROR(scrnIndex, NULL, + "Error invalid cursor dimensions %dx%d\n", w, h); + + if ((bitsp->xhot > w) || (bitsp->yhot > h)) + RETERROR(scrnIndex, NULL, + "Error invalid cursor hotspot location %dx%d (max %dx%d)\n", + bitsp->xhot, bitsp->yhot, w, h); + + srcPitch = PixmapBytePad (bitsp->width, 1); + dstPitch = (w + 7) / 8; + sizeMask = ((dstPitch * h) + 3) & (size_t) ~3; + sizeRgba = w * h * 4; + sizeRequest = sizeMask + sizeRgba + sizeof(*pImage); + + p = c = calloc (1, sizeRequest); + if (!c) + RETERROR(scrnIndex, NULL, + "Error failed to alloc %lu bytes for cursor\n", + (unsigned long) sizeRequest); + + pImage = (struct vboxCursorImage *)p; + pImage->pPixels = m = p + sizeof(*pImage); + cp = (CARD32 *)(m + sizeMask); + + TRACE_LOG ("w=%d h=%d sm=%d sr=%d p=%d\n", + w, h, (int) sizeMask, (int) sizeRgba, (int) dstPitch); + TRACE_LOG ("m=%p c=%p cp=%p\n", m, c, (void *)cp); + + fc = color_to_byte (pCurs->foreBlue) + | (color_to_byte (pCurs->foreGreen) << 8) + | (color_to_byte (pCurs->foreRed) << 16); + + bc = color_to_byte (pCurs->backBlue) + | (color_to_byte (pCurs->backGreen) << 8) + | (color_to_byte (pCurs->backRed) << 16); + + /* + * Convert the Xorg source/mask bits to the and/xor bits VBox needs. + * Xorg: + * The mask is a bitmap indicating which parts of the cursor are + * transparent and which parts are drawn. The source is a bitmap + * indicating which parts of the non-transparent portion of the + * the cursor should be painted in the foreground color and which + * should be painted in the background color. By default, set bits + * indicate the opaque part of the mask bitmap and clear bits + * indicate the transparent part. + * VBox: + * The color data is the XOR mask. The AND mask bits determine + * which pixels of the color data (XOR mask) will replace (overwrite) + * the screen pixels (AND mask bit = 0) and which ones will be XORed + * with existing screen pixels (AND mask bit = 1). + * For example when you have the AND mask all 0, then you see the + * correct mouse pointer image surrounded by black square. + */ + for (pm = bitsp->mask, ps = bitsp->source, y = 0; + y < h; + ++y, pm += srcPitch, ps += srcPitch, m += dstPitch) + { + for (x = 0; x < w; ++x) + { + if (pm[x / 8] & (1 << (x % 8))) + { + /* opaque, leave AND mask bit at 0 */ + if (ps[x / 8] & (1 << (x % 8))) + { + *cp++ = fc; + PUT_PIXEL('X'); + } + else + { + *cp++ = bc; + PUT_PIXEL('*'); + } + } + else + { + /* transparent, set AND mask bit */ + m[x / 8] |= 1 << (7 - (x % 8)); + /* don't change the screen pixel */ + *cp++ = 0; + PUT_PIXEL(' '); + } + } + PUT_PIXEL('\n'); + } + + pImage->cWidth = w; + pImage->cHeight = h; + pImage->cHotX = bitsp->xhot; + pImage->cHotY = bitsp->yhot; + pImage->fFlags = VBOX_MOUSE_POINTER_VISIBLE | VBOX_MOUSE_POINTER_SHAPE; + pImage->cbLength = sizeRequest - sizeof(*pImage); + +#ifdef DEBUG_POINTER + ErrorF("shape = %p\n", p); + vbox_show_shape(w, h, bc, c); +#endif + + return p; +} + +#ifdef ARGB_CURSOR +static Bool +vbox_use_hw_cursor_argb(ScreenPtr pScreen, CursorPtr pCurs) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + VBOXPtr pVBox = pScrn->driverPrivate; + + if (!pVBox->fUseHardwareCursor) + return FALSE; + if ( (pCurs->bits->height > VBOX_MAX_CURSOR_HEIGHT) + || (pCurs->bits->width > VBOX_MAX_CURSOR_WIDTH) + || (pScrn->bitsPerPixel <= 8)) + return FALSE; + return TRUE; +} + + +static void +vbox_load_cursor_argb(ScrnInfoPtr pScrn, CursorPtr pCurs) +{ + VBOXPtr pVBox; + CursorBitsPtr bitsp; + unsigned short w, h; + unsigned short cx, cy; + unsigned char *pm; + CARD32 *pc; + size_t sizeData, sizeMask; + CARD8 *p; + int scrnIndex; + uint32_t fFlags = VBOX_MOUSE_POINTER_VISIBLE | VBOX_MOUSE_POINTER_SHAPE + | VBOX_MOUSE_POINTER_ALPHA; + + pVBox = pScrn->driverPrivate; + bitsp = pCurs->bits; + w = bitsp->width; + h = bitsp->height; + scrnIndex = pScrn->scrnIndex; + + /* Mask must be generated for alpha cursors, that is required by VBox. */ + /* note: (michael) the next struct must be 32bit aligned. */ + sizeMask = ((w + 7) / 8 * h + 3) & ~3; + + if (!w || !h || w > VBOX_MAX_CURSOR_WIDTH || h > VBOX_MAX_CURSOR_HEIGHT) + RETERROR(scrnIndex, , + "Error invalid cursor dimensions %dx%d\n", w, h); + + if ((bitsp->xhot > w) || (bitsp->yhot > h)) + RETERROR(scrnIndex, , + "Error invalid cursor hotspot location %dx%d (max %dx%d)\n", + bitsp->xhot, bitsp->yhot, w, h); + + sizeData = w * h * 4 + sizeMask; + p = calloc(1, sizeData); + if (!p) + RETERROR(scrnIndex, , + "Error failed to alloc %lu bytes for cursor\n", + (unsigned long)sizeData); + + memcpy(p + sizeMask, bitsp->argb, w * h * 4); + + /* Emulate the AND mask. */ + pm = p; + pc = bitsp->argb; + + /* Init AND mask to 1 */ + memset(pm, 0xFF, sizeMask); + + /* + * The additions driver must provide the AND mask for alpha cursors. The host frontend + * which can handle alpha channel, will ignore the AND mask and draw an alpha cursor. + * But if the host does not support ARGB, then it simply uses the AND mask and the color + * data to draw a normal color cursor. + */ + for (cy = 0; cy < h; cy++) + { + unsigned char bitmask = 0x80; + + for (cx = 0; cx < w; cx++, bitmask >>= 1) + { + if (bitmask == 0) + bitmask = 0x80; + + if (pc[cx] >= 0xF0000000) + pm[cx / 8] &= ~bitmask; + } + + /* Point to next source and dest scans */ + pc += w; + pm += (w + 7) / 8; + } + + VBoxHGSMIUpdatePointerShape(&pVBox->guestCtx, fFlags, bitsp->xhot, + bitsp->yhot, w, h, p, sizeData); + free(p); +} +#endif + +Bool vbvxCursorInit(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + VBOXPtr pVBox = pScrn->driverPrivate; + xf86CursorInfoPtr pCurs = NULL; + Bool rc = TRUE; + + TRACE_ENTRY(); + pVBox->pCurs = pCurs = xf86CreateCursorInfoRec(); + if (!pCurs) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed to create X Window cursor information structures for virtual mouse.\n"); + rc = FALSE; + } + if (rc) { + pCurs->MaxWidth = VBOX_MAX_CURSOR_WIDTH; + pCurs->MaxHeight = VBOX_MAX_CURSOR_HEIGHT; + pCurs->Flags = HARDWARE_CURSOR_TRUECOLOR_AT_8BPP + | HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 + | HARDWARE_CURSOR_BIT_ORDER_MSBFIRST + | HARDWARE_CURSOR_UPDATE_UNHIDDEN; + + pCurs->SetCursorColors = vbox_set_cursor_colors; + pCurs->SetCursorPosition = vbox_set_cursor_position; + pCurs->LoadCursorImage = vbox_load_cursor_image; + pCurs->HideCursor = vbox_hide_cursor; + pCurs->ShowCursor = vbox_show_cursor; + pCurs->UseHWCursor = vbox_use_hw_cursor; + pCurs->RealizeCursor = vbox_realize_cursor; + +#ifdef ARGB_CURSOR + pCurs->UseHWCursorARGB = vbox_use_hw_cursor_argb; + pCurs->LoadCursorARGB = vbox_load_cursor_argb; +#endif + + rc = xf86InitCursor(pScreen, pCurs); + } + if (!rc) + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed to enable mouse pointer integration.\n"); + if (!rc && (pCurs != NULL)) + xf86DestroyCursorInfoRec(pCurs); + return rc; +} diff --git a/src/VBox/Additions/x11/vboxvideo/setmode.c b/src/VBox/Additions/x11/vboxvideo/setmode.c new file mode 100644 index 00000000..2c8373e0 --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/setmode.c @@ -0,0 +1,129 @@ +/* $Id: setmode.c $ */ +/** @file + * Linux Additions X11 graphics driver, mode setting + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * This file is based on X11 VESA driver (hardly any traces left here): + * + * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com) + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Conectiva Linux shall + * not be used in advertising or otherwise to promote the sale, use or other + * dealings in this Software without prior written authorization from + * Conectiva Linux. + * + * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br> + * Michael Thayer <michael.thayer@oracle.com> + */ + +#ifdef XORG_7X +/* We include <unistd.h> for Solaris below, and the ANSI C emulation layer + * interferes with that. */ +# define _XF86_ANSIC_H +# define XF86_LIBC_H +# include <string.h> +#endif +#include "vboxvideo.h" +#include "xf86.h" + +/* VGA hardware functions for setting and restoring text mode */ +#include "vgaHW.h" + +#ifdef RT_OS_SOLARIS +# include <sys/vuid_event.h> +# include <sys/msio.h> +# include <errno.h> +# include <fcntl.h> +# include <unistd.h> +#endif + +/** Clear the virtual framebuffer in VRAM. Optionally also clear up to the + * size of a new framebuffer. Framebuffer sizes larger than available VRAM + * be treated as zero and passed over. */ +void vbvxClearVRAM(ScrnInfoPtr pScrn, size_t cbOldSize, size_t cbNewSize) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + + /* Assume 32BPP - this is just a sanity test. */ + AssertMsg( cbOldSize / 4 <= VBOX_VIDEO_MAX_VIRTUAL * VBOX_VIDEO_MAX_VIRTUAL + && cbNewSize / 4 <= VBOX_VIDEO_MAX_VIRTUAL * VBOX_VIDEO_MAX_VIRTUAL, + ("cbOldSize=%llu cbNewSize=%llu, max=%u.\n", (unsigned long long)cbOldSize, (unsigned long long)cbNewSize, + VBOX_VIDEO_MAX_VIRTUAL * VBOX_VIDEO_MAX_VIRTUAL)); + if (cbOldSize > (size_t)pVBox->cbFBMax) + cbOldSize = pVBox->cbFBMax; + if (cbNewSize > (size_t)pVBox->cbFBMax) + cbNewSize = pVBox->cbFBMax; + memset(pVBox->base, 0, max(cbOldSize, cbNewSize)); +} + +/** Set a graphics mode. Poke any required values into registers, do an HGSMI + * mode set and tell the host we support advanced graphics functions. + */ +void vbvxSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth, unsigned cHeight, int x, int y, Bool fEnabled, + Bool fConnected, struct vbvxFrameBuffer *pFrameBuffer) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + uint32_t offStart; + uint16_t fFlags; + int rc; + Bool fEnabledAndVisible = fEnabled && x + cWidth <= pFrameBuffer->cWidth && y + cHeight <= pFrameBuffer->cHeight; + /* Recent host code has a flag to blank the screen; older code needs BPP set to zero. */ + uint32_t cBPP = fEnabledAndVisible || pVBox->fHostHasScreenBlankingFlag ? pFrameBuffer->cBPP : 0; + + TRACE_LOG("cDisplay=%u, cWidth=%u, cHeight=%u, x=%d, y=%d, fEnabled=%d, fConnected=%d, pFrameBuffer: { x0=%d, y0=%d, cWidth=%u, cHeight=%u, cBPP=%u }\n", + cDisplay, cWidth, cHeight, x, y, fEnabled, fConnected, pFrameBuffer->x0, pFrameBuffer->y0, pFrameBuffer->cWidth, + pFrameBuffer->cHeight, pFrameBuffer->cBPP); + AssertMsg(cWidth != 0 && cHeight != 0, ("cWidth = 0 or cHeight = 0\n")); + offStart = (y * pFrameBuffer->cWidth + x) * pFrameBuffer->cBPP / 8; + if (cDisplay == 0 && fEnabled) + VBoxVideoSetModeRegisters(cWidth, cHeight, pFrameBuffer->cWidth, pFrameBuffer->cBPP, 0, x, y); + fFlags = VBVA_SCREEN_F_ACTIVE; + fFlags |= (fConnected ? 0 : VBVA_SCREEN_F_DISABLED); + fFlags |= (!fEnabledAndVisible && pVBox->fHostHasScreenBlankingFlag ? VBVA_SCREEN_F_BLANK : 0); + VBoxHGSMIProcessDisplayInfo(&pVBox->guestCtx, cDisplay, x - pFrameBuffer->x0, y - pFrameBuffer->y0, offStart, + pFrameBuffer->cWidth * pFrameBuffer->cBPP / 8, cWidth, cHeight, cBPP, fFlags); + rc = VBoxHGSMIUpdateInputMapping(&pVBox->guestCtx, 0 - pFrameBuffer->x0, 0 - pFrameBuffer->y0, pFrameBuffer->cWidth, + pFrameBuffer->cHeight); + if (RT_FAILURE(rc)) + FatalError("Failed to update the input mapping.\n"); +} + +/** Tell the virtual mouse device about the new virtual desktop size. */ +void vbvxSetSolarisMouseRange(int width, int height) +{ +#ifdef RT_OS_SOLARIS + int rc; + int hMouse = open("/dev/mouse", O_RDWR); + + if (hMouse >= 0) + { + do { + Ms_screen_resolution Res = { height, width }; + rc = ioctl(hMouse, MSIOSRESOLUTION, &Res); + } while ((rc != 0) && (errno == EINTR)); + close(hMouse); + } +#else + (void)width; (void)height; +#endif +} diff --git a/src/VBox/Additions/x11/vboxvideo/vboxvideo.c b/src/VBox/Additions/x11/vboxvideo/vboxvideo.c new file mode 100644 index 00000000..672f22b0 --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/vboxvideo.c @@ -0,0 +1,1491 @@ +/* $Id: vboxvideo.c $ */ +/** @file + * Linux Additions X11 graphics driver + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * This file is based on the X.Org VESA driver: + * + * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com) + * Copyright 2008 Red Hat, Inc. + * Copyright 2012 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Conectiva Linux shall + * not be used in advertising or otherwise to promote the sale, use or other + * dealings in this Software without prior written authorization from + * Conectiva Linux. + * + * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br> + * David Dawes <dawes@xfree86.org> + * Adam Jackson <ajax@redhat.com> + * Dave Airlie <airlied@redhat.com> + * Michael Thayer <michael.thayer@oracle.com> + */ + +#include "vboxvideo.h" +#include <VBoxVideoVBE.h> + +/* Basic definitions and functions needed by all drivers. */ +#include "xf86.h" +/* For video memory mapping. */ +#include "xf86_OSproc.h" +#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6 +/* PCI resources. */ +# include "xf86Resources.h" +#endif +/* Generic server linear frame-buffer APIs. */ +#include "fb.h" +/* Colormap and visual handling. */ +#include "micmap.h" +#include "xf86cmap.h" +/* ShadowFB support */ +#include "shadowfb.h" +/* VGA hardware functions for setting and restoring text mode */ +#include "vgaHW.h" +#ifdef VBOXVIDEO_13 +/* X.org 1.3+ mode setting */ +# define _HAVE_STRING_ARCH_strsep /* bits/string2.h, __strsep_1c. */ +# include "xf86Crtc.h" +# include "xf86Modes.h" +/* For xf86RandR12GetOriginalVirtualSize(). */ +# include "xf86RandR12.h" +#endif +/* For setting the root window property. */ +#include "property.h" +#include <X11/Xatom.h> + +#ifdef XORG_7X +# include <stdlib.h> +# include <string.h> +# include <fcntl.h> +# include <unistd.h> +#endif + +/* Mandatory functions */ + +static const OptionInfoRec * VBOXAvailableOptions(int chipid, int busid); +static void VBOXIdentify(int flags); +#ifndef PCIACCESS +static Bool VBOXProbe(DriverPtr drv, int flags); +#else +static Bool VBOXPciProbe(DriverPtr drv, int entity_num, + struct pci_device *dev, intptr_t match_data); +#endif +static Bool VBOXPreInit(ScrnInfoPtr pScrn, int flags); +static Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv); +static Bool VBOXEnterVT(ScrnInfoPtr pScrn); +static void VBOXLeaveVT(ScrnInfoPtr pScrn); +static Bool VBOXCloseScreen(ScreenPtr pScreen); +#ifndef VBOXVIDEO_13 +static Bool VBOXSaveScreen(ScreenPtr pScreen, int mode); +#endif +static Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode); +static void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y); +static void VBOXFreeScreen(ScrnInfoPtr pScrn); +#ifndef VBOXVIDEO_13 +static void VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode, int flags); +#endif + +/* locally used functions */ +static Bool VBOXMapVidMem(ScrnInfoPtr pScrn); +static void VBOXUnmapVidMem(ScrnInfoPtr pScrn); +static void VBOXSaveMode(ScrnInfoPtr pScrn); +static void VBOXRestoreMode(ScrnInfoPtr pScrn); +static void setSizesAndCursorIntegration(ScrnInfoPtr pScrn, Bool fScreenInitTime); + +#ifndef XF86_SCRN_INTERFACE +# define xf86ScreenToScrn(pScreen) xf86Screens[(pScreen)->myNum] +# define xf86ScrnToScreen(pScrn) screenInfo.screens[(pScrn)->scrnIndex] +#endif + +static inline void VBOXSetRec(ScrnInfoPtr pScrn) +{ + if (!pScrn->driverPrivate) + { + VBOXPtr pVBox = (VBOXPtr)xnfcalloc(sizeof(VBOXRec), 1); + pScrn->driverPrivate = pVBox; +#if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX) + pVBox->fdACPIDevices = -1; +#endif + } +} + +enum GenericTypes +{ + CHIP_VBOX_GENERIC +}; + +#ifdef PCIACCESS +static const struct pci_id_match vbox_device_match[] = { + { + VBOX_VENDORID, VBOX_DEVICEID, PCI_MATCH_ANY, PCI_MATCH_ANY, + 0, 0, 0 + }, + + { 0, 0, 0 }, +}; +#endif + +/* Supported chipsets */ +static SymTabRec VBOXChipsets[] = +{ + {VBOX_DEVICEID, "vbox"}, + {-1, NULL} +}; + +static PciChipsets VBOXPCIchipsets[] = { + { VBOX_DEVICEID, VBOX_DEVICEID, RES_SHARED_VGA }, + { -1, -1, RES_UNDEFINED }, +}; + +/* + * This contains the functions needed by the server after loading the + * driver module. It must be supplied, and gets added the driver list by + * the Module Setup function in the dynamic case. In the static case a + * reference to this is compiled in, and this requires that the name of + * this DriverRec be an upper-case version of the driver name. + */ + +#ifdef XORG_7X +_X_EXPORT +#endif +DriverRec VBOXVIDEO = { + VBOX_VERSION, + VBOX_DRIVER_NAME, + VBOXIdentify, +#ifdef PCIACCESS + NULL, +#else + VBOXProbe, +#endif + VBOXAvailableOptions, + NULL, + 0, +#ifdef XORG_7X + NULL, +#endif +#ifdef PCIACCESS + vbox_device_match, + VBOXPciProbe +#endif +}; + +/* No options for now */ +static const OptionInfoRec VBOXOptions[] = { + { -1, NULL, OPTV_NONE, {0}, FALSE } +}; + +#ifndef XORG_7X +/* + * List of symbols from other modules that this module references. This + * list is used to tell the loader that it is OK for symbols here to be + * unresolved providing that it hasn't been told that they haven't been + * told that they are essential via a call to xf86LoaderReqSymbols() or + * xf86LoaderReqSymLists(). The purpose is this is to avoid warnings about + * unresolved symbols that are not required. + */ +static const char *fbSymbols[] = { + "fbPictureInit", + "fbScreenInit", + NULL +}; + +static const char *shadowfbSymbols[] = { + "ShadowFBInit2", + NULL +}; + +static const char *ramdacSymbols[] = { + "xf86DestroyCursorInfoRec", + "xf86InitCursor", + "xf86CreateCursorInfoRec", + NULL +}; + +static const char *vgahwSymbols[] = { + "vgaHWFreeHWRec", + "vgaHWGetHWRec", + "vgaHWGetIOBase", + "vgaHWGetIndex", + "vgaHWRestore", + "vgaHWSave", + "vgaHWSetStdFuncs", + NULL +}; +#endif /* !XORG_7X */ + +/** Resize the virtual framebuffer. */ +static Bool adjustScreenPixmap(ScrnInfoPtr pScrn, int width, int height) +{ + ScreenPtr pScreen = xf86ScrnToScreen(pScrn); + VBOXPtr pVBox = VBOXGetRec(pScrn); + int adjustedWidth = pScrn->bitsPerPixel == 16 ? (width + 1) & ~1 : width; + int cbLine = adjustedWidth * pScrn->bitsPerPixel / 8; + PixmapPtr pPixmap; + + TRACE_LOG("width=%d, height=%d\n", width, height); + AssertMsg(width >= 0 && height >= 0, ("Invalid negative width (%d) or height (%d)\n", width, height)); + if (pScreen == NULL) /* Not yet initialised. */ + return TRUE; + pPixmap = pScreen->GetScreenPixmap(pScreen); + AssertMsg(pPixmap != NULL, ("Failed to get the screen pixmap.\n")); + 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", + (void *)pPixmap, adjustedWidth, height, pScrn->depth, + pScrn->bitsPerPixel, cbLine, pVBox->base, + pPixmap->drawable.width, pPixmap->drawable.height); + if ( adjustedWidth != pPixmap->drawable.width + || height != pPixmap->drawable.height) + { + if ( adjustedWidth > VBOX_VIDEO_MAX_VIRTUAL || height > VBOX_VIDEO_MAX_VIRTUAL + || (unsigned)cbLine * (unsigned)height >= pVBox->cbFBMax) + { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Virtual framebuffer %dx%d too large. For information, video memory: %u Kb.\n", + adjustedWidth, height, (unsigned) pVBox->cbFBMax / 1024); + return FALSE; + } + if (pScrn->vtSema) + vbvxClearVRAM(pScrn, ((size_t)pScrn->virtualX) * pScrn->virtualY * (pScrn->bitsPerPixel / 8), + ((size_t)adjustedWidth) * height * (pScrn->bitsPerPixel / 8)); + pScreen->ModifyPixmapHeader(pPixmap, adjustedWidth, height, pScrn->depth, pScrn->bitsPerPixel, cbLine, pVBox->base); + } + pScrn->displayWidth = pScrn->virtualX = adjustedWidth; + pScrn->virtualY = height; + return TRUE; +} + +#ifndef VBOXVIDEO_13 +/** Set a video mode to the hardware, RandR 1.1 version. + * + * Since we no longer do virtual frame buffers, adjust the screen pixmap + * dimensions to match. The "override" parameters are for when we received a + * mode hint while switched to a virtual terminal. In this case VBoxClient will + * have told us about the mode, but not yet been able to do a mode switch using + * RandR. We solve this by setting the requested mode to the host but keeping + * the virtual frame- + * buffer matching what the X server expects. */ +static void setModeRandR11(ScrnInfoPtr pScrn, DisplayModePtr pMode, Bool fScreenInitTime, Bool fEnterVTTime, + int cXOverRide, int cYOverRide) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + struct vbvxFrameBuffer frameBuffer = { 0, 0, pMode->HDisplay, pMode->VDisplay, pScrn->bitsPerPixel}; + int cXPhysical = cXOverRide > 0 ? min(cXOverRide, pMode->HDisplay) : pMode->HDisplay; + int cYPhysical = cYOverRide > 0 ? min(cYOverRide, pMode->VDisplay) : pMode->VDisplay; + + pVBox->pScreens[0].aScreenLocation.cx = pMode->HDisplay; + pVBox->pScreens[0].aScreenLocation.cy = pMode->VDisplay; + if (fScreenInitTime) + { + /* The screen structure is not fully set up yet, so do not touch it. */ + pScrn->displayWidth = pScrn->virtualX = pMode->HDisplay; + pScrn->virtualY = pMode->VDisplay; + } + else + { + xf86ScrnToScreen(pScrn)->width = pMode->HDisplay; + xf86ScrnToScreen(pScrn)->height = pMode->VDisplay; + /* This prevents a crash in CentOS 3. I was unable to debug it to + * satisfaction, partly due to the lack of symbols. My guess is that + * pScrn->ModifyPixmapHeader() expects certain things to be set up when + * it sees pScrn->vtSema set to true which are not quite done at this + * point of the VT switch. */ + if (fEnterVTTime) + pScrn->vtSema = FALSE; + adjustScreenPixmap(pScrn, pMode->HDisplay, pMode->VDisplay); + if (fEnterVTTime) + pScrn->vtSema = TRUE; + } + if (pMode->HDisplay != 0 && pMode->VDisplay != 0 && pScrn->vtSema) + vbvxSetMode(pScrn, 0, cXPhysical, cYPhysical, 0, 0, true, true, &frameBuffer); + pScrn->currentMode = pMode; +} +#endif + +#ifdef VBOXVIDEO_13 +/* X.org 1.3+ mode-setting support ******************************************/ + +/** Set a video mode to the hardware, RandR 1.2 version. If this is the first + * screen, re-set the current mode for all others (the offset for the first + * screen is always treated as zero by the hardware, so all other screens need + * to be changed to compensate for any changes!). The mode to set is taken + * from the X.Org Crtc structure. */ +static void setModeRandR12(ScrnInfoPtr pScrn, unsigned cScreen) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + unsigned i; + struct vbvxFrameBuffer frameBuffer = { pVBox->pScreens[0].paCrtcs->x, pVBox->pScreens[0].paCrtcs->y, pScrn->virtualX, + pScrn->virtualY, pScrn->bitsPerPixel }; + unsigned cFirst = cScreen; + unsigned cLast = cScreen != 0 ? cScreen + 1 : pVBox->cScreens; + int originalX, originalY; + + /* Check that this code cannot trigger the resizing bug in X.Org Server 1.3. + * See the work-around in ScreenInit. */ + xf86RandR12GetOriginalVirtualSize(pScrn, &originalX, &originalY); + AssertMsg(originalX == VBOX_VIDEO_MAX_VIRTUAL && originalY == VBOX_VIDEO_MAX_VIRTUAL, ("OriginalSize=%dx%d", + originalX, originalY)); + for (i = cFirst; i < cLast; ++i) + if (pVBox->pScreens[i].paCrtcs->mode.HDisplay != 0 && pVBox->pScreens[i].paCrtcs->mode.VDisplay != 0 && pScrn->vtSema) + vbvxSetMode(pScrn, i, pVBox->pScreens[i].paCrtcs->mode.HDisplay, pVBox->pScreens[i].paCrtcs->mode.VDisplay, + pVBox->pScreens[i].paCrtcs->x, pVBox->pScreens[i].paCrtcs->y, pVBox->pScreens[i].fPowerOn, + pVBox->pScreens[i].paOutputs->status == XF86OutputStatusConnected, &frameBuffer); +} + +/** Wrapper around setModeRandR12() to avoid exposing non-obvious semantics. + */ +static void setAllModesRandR12(ScrnInfoPtr pScrn) +{ + setModeRandR12(pScrn, 0); +} + +/* For descriptions of these functions and structures, see + hw/xfree86/modes/xf86Crtc.h and hw/xfree86/modes/xf86Modes.h in the + X.Org source tree. */ + +static Bool vbox_config_resize(ScrnInfoPtr pScrn, int cw, int ch) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + Bool rc; + unsigned i; + + TRACE_LOG("width=%d, height=%d\n", cw, ch); + rc = adjustScreenPixmap(pScrn, cw, ch); + /* Power-on all screens (the server expects this) and set the new pitch to them. */ + for (i = 0; i < pVBox->cScreens; ++i) + pVBox->pScreens[i].fPowerOn = true; + setAllModesRandR12(pScrn); + vbvxSetSolarisMouseRange(cw, ch); + return rc; +} + +static const xf86CrtcConfigFuncsRec VBOXCrtcConfigFuncs = { + vbox_config_resize +}; + +static void +vbox_crtc_dpms(xf86CrtcPtr crtc, int mode) +{ + ScrnInfoPtr pScrn = crtc->scrn; + VBOXPtr pVBox = VBOXGetRec(pScrn); + unsigned cDisplay = (uintptr_t)crtc->driver_private; + + TRACE_LOG("mode=%d\n", mode); + pVBox->pScreens[cDisplay].fPowerOn = (mode != DPMSModeOff); + setModeRandR12(pScrn, cDisplay); +} + +static Bool +vbox_crtc_lock (xf86CrtcPtr crtc) +{ RT_NOREF(crtc); return FALSE; } + + +/* We use this function to check whether the X server owns the active virtual + * terminal before attempting a mode switch, since the RandR extension isn't + * very dilligent here, which can mean crashes if we are unlucky. This is + * not the way it the function is intended - it is meant for reporting modes + * which the hardware can't handle. I hope that this won't confuse any clients + * connecting to us. */ +static Bool +vbox_crtc_mode_fixup (xf86CrtcPtr crtc, DisplayModePtr mode, + DisplayModePtr adjusted_mode) +{ RT_NOREF(crtc, mode, adjusted_mode); return TRUE; } + +static void +vbox_crtc_stub (xf86CrtcPtr crtc) +{ RT_NOREF(crtc); } + +static void +vbox_crtc_mode_set (xf86CrtcPtr crtc, DisplayModePtr mode, + DisplayModePtr adjusted_mode, int x, int y) +{ + RT_NOREF(mode); + VBOXPtr pVBox = VBOXGetRec(crtc->scrn); + unsigned cDisplay = (uintptr_t)crtc->driver_private; + + TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name, + adjusted_mode->HDisplay, adjusted_mode->VDisplay, x, y); + pVBox->pScreens[cDisplay].fPowerOn = true; + pVBox->pScreens[cDisplay].aScreenLocation.cx = adjusted_mode->HDisplay; + pVBox->pScreens[cDisplay].aScreenLocation.cy = adjusted_mode->VDisplay; + pVBox->pScreens[cDisplay].aScreenLocation.x = x; + pVBox->pScreens[cDisplay].aScreenLocation.y = y; + setModeRandR12(crtc->scrn, cDisplay); +} + +static void +vbox_crtc_gamma_set (xf86CrtcPtr crtc, CARD16 *red, + CARD16 *green, CARD16 *blue, int size) +{ RT_NOREF(crtc, red, green, blue, size); } + +static void * +vbox_crtc_shadow_allocate (xf86CrtcPtr crtc, int width, int height) +{ RT_NOREF(crtc, width, height); return NULL; } + +static const xf86CrtcFuncsRec VBOXCrtcFuncs = { + .dpms = vbox_crtc_dpms, + .save = NULL, /* These two are never called by the server. */ + .restore = NULL, + .lock = vbox_crtc_lock, + .unlock = NULL, /* This will not be invoked if lock returns FALSE. */ + .mode_fixup = vbox_crtc_mode_fixup, + .prepare = vbox_crtc_stub, + .mode_set = vbox_crtc_mode_set, + .commit = vbox_crtc_stub, + .gamma_set = vbox_crtc_gamma_set, + .shadow_allocate = vbox_crtc_shadow_allocate, + .shadow_create = NULL, /* These two should not be invoked if allocate + returns NULL. */ + .shadow_destroy = NULL, + .set_cursor_colors = NULL, /* We are still using the old cursor API. */ + .set_cursor_position = NULL, + .show_cursor = NULL, + .hide_cursor = NULL, + .load_cursor_argb = NULL, + .destroy = vbox_crtc_stub +}; + +static void +vbox_output_stub (xf86OutputPtr output) +{ RT_NOREF(output); } + +static void +vbox_output_dpms (xf86OutputPtr output, int mode) +{ + RT_NOREF(output, mode); +} + +static int +vbox_output_mode_valid (xf86OutputPtr output, DisplayModePtr mode) +{ + return MODE_OK; +} + +static Bool +vbox_output_mode_fixup (xf86OutputPtr output, DisplayModePtr mode, + DisplayModePtr adjusted_mode) +{ RT_NOREF(output, mode, adjusted_mode); return TRUE; } + +static void +vbox_output_mode_set (xf86OutputPtr output, DisplayModePtr mode, + DisplayModePtr adjusted_mode) +{ RT_NOREF(output, mode, adjusted_mode); } + +static xf86OutputStatus +vbox_output_detect (xf86OutputPtr output) +{ + ScrnInfoPtr pScrn = output->scrn; + VBOXPtr pVBox = VBOXGetRec(pScrn); + uint32_t iScreen = (uintptr_t)output->driver_private; + return pVBox->pScreens[iScreen].afConnected + ? XF86OutputStatusConnected : XF86OutputStatusDisconnected; +} + +static DisplayModePtr vbox_output_add_mode(VBOXPtr pVBox, DisplayModePtr *pModes, const char *pszName, int x, int y, + Bool isPreferred, Bool isUserDef) +{ + TRACE_LOG("pszName=%s, x=%d, y=%d\n", pszName ? pszName : "(null)", x, y); + DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec)); + int cRefresh = 60; + + pMode->status = MODE_OK; + /* We don't ask the host whether it likes user defined modes, + * as we assume that the user really wanted that mode. */ + pMode->type = isUserDef ? M_T_USERDEF : M_T_BUILTIN; + if (isPreferred) + pMode->type |= M_T_PREFERRED; + /* Older versions of VBox only support screen widths which are a multiple + * of 8 */ + if (pVBox->fAnyX) + pMode->HDisplay = x; + else + pMode->HDisplay = x & ~7; + pMode->HSyncStart = pMode->HDisplay + 2; + pMode->HSyncEnd = pMode->HDisplay + 4; + pMode->HTotal = pMode->HDisplay + 6; + pMode->VDisplay = y; + pMode->VSyncStart = pMode->VDisplay + 2; + pMode->VSyncEnd = pMode->VDisplay + 4; + pMode->VTotal = pMode->VDisplay + 6; + pMode->Clock = pMode->HTotal * pMode->VTotal * cRefresh / 1000; /* kHz */ + if (NULL == pszName) { + xf86SetModeDefaultName(pMode); + } else { + pMode->name = xnfstrdup(pszName); + } + *pModes = xf86ModesAdd(*pModes, pMode); + return pMode; +} + +static DisplayModePtr +vbox_output_get_modes (xf86OutputPtr output) +{ + DisplayModePtr pModes = NULL; + DisplayModePtr pPreferred = NULL; + ScrnInfoPtr pScrn = output->scrn; + VBOXPtr pVBox = VBOXGetRec(pScrn); + + TRACE_ENTRY(); + uint32_t iScreen = (uintptr_t)output->driver_private; + pPreferred = vbox_output_add_mode(pVBox, &pModes, NULL, + RT_CLAMP(pVBox->pScreens[iScreen].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL), + RT_CLAMP(pVBox->pScreens[iScreen].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL), + TRUE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 2560, 1600, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 2560, 1440, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 2048, 1536, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 1920, 1600, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 1920, 1080, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 1680, 1050, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 1600, 1200, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 1400, 1050, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 1280, 1024, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 1024, 768, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 800, 600, FALSE, FALSE); + vbox_output_add_mode(pVBox, &pModes, NULL, 640, 480, FALSE, FALSE); + VBOXEDIDSet(output, pPreferred); + TRACE_EXIT(); + return pModes; +} + +static const xf86OutputFuncsRec VBOXOutputFuncs = { + .create_resources = vbox_output_stub, + .dpms = vbox_output_dpms, + .save = NULL, /* These two are never called by the server. */ + .restore = NULL, + .mode_valid = vbox_output_mode_valid, + .mode_fixup = vbox_output_mode_fixup, + .prepare = vbox_output_stub, + .commit = vbox_output_stub, + .mode_set = vbox_output_mode_set, + .detect = vbox_output_detect, + .get_modes = vbox_output_get_modes, +#ifdef RANDR_12_INTERFACE + .set_property = NULL, +#endif + .destroy = vbox_output_stub +}; +#endif /* VBOXVIDEO_13 */ + +/* Module loader interface */ +static MODULESETUPPROTO(vboxSetup); + +static XF86ModuleVersionInfo vboxVersionRec = +{ + VBOX_DRIVER_NAME, + "Oracle Corporation", + MODINFOSTRING1, + MODINFOSTRING2, +#ifdef XORG_7X + XORG_VERSION_CURRENT, +#else + XF86_VERSION_CURRENT, +#endif + 1, /* Module major version. Xorg-specific */ + 0, /* Module minor version. Xorg-specific */ + 1, /* Module patchlevel. Xorg-specific */ + ABI_CLASS_VIDEODRV, /* This is a video driver */ + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +/* + * This data is accessed by the loader. The name must be the module name + * followed by "ModuleData". + */ +#ifdef XORG_7X +_X_EXPORT +#endif +XF86ModuleData vboxvideoModuleData = { &vboxVersionRec, vboxSetup, NULL }; + +static pointer +vboxSetup(pointer Module, pointer Options, int *ErrorMajor, int *ErrorMinor) +{ + static Bool Initialised = FALSE; + RT_NOREF(Options, ErrorMinor); + + if (!Initialised) + { + Initialised = TRUE; +#ifdef PCIACCESS + xf86AddDriver(&VBOXVIDEO, Module, HaveDriverFuncs); +#else + xf86AddDriver(&VBOXVIDEO, Module, 0); +#endif +#ifndef XORG_7X + LoaderRefSymLists(fbSymbols, + shadowfbSymbols, + ramdacSymbols, + vgahwSymbols, + NULL); +#endif + xf86Msg(X_CONFIG, "Load address of symbol \"VBOXVIDEO\" is %p\n", + (void *)&VBOXVIDEO); + return (pointer)TRUE; + } + + if (ErrorMajor) + *ErrorMajor = LDR_ONCEONLY; + return (NULL); +} + + +static const OptionInfoRec * +VBOXAvailableOptions(int chipid, int busid) +{ + RT_NOREF(chipid, busid); + return (VBOXOptions); +} + +static void +VBOXIdentify(int flags) +{ + RT_NOREF(flags); + xf86PrintChipsets(VBOX_NAME, "guest driver for VirtualBox", VBOXChipsets); +} + +#ifndef XF86_SCRN_INTERFACE +# define SCRNINDEXAPI(pfn) pfn ## Index +static Bool VBOXScreenInitIndex(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) +{ + RT_NOREF(scrnIndex); + return VBOXScreenInit(pScreen, argc, argv); +} + +static Bool VBOXEnterVTIndex(int scrnIndex, int flags) +{ RT_NOREF(flags); return VBOXEnterVT(xf86Screens[scrnIndex]); } + +static void VBOXLeaveVTIndex(int scrnIndex, int flags) +{ RT_NOREF(flags); VBOXLeaveVT(xf86Screens[scrnIndex]); } + +static Bool VBOXCloseScreenIndex(int scrnIndex, ScreenPtr pScreen) +{ RT_NOREF(scrnIndex); return VBOXCloseScreen(pScreen); } + +static Bool VBOXSwitchModeIndex(int scrnIndex, DisplayModePtr pMode, int flags) +{ RT_NOREF(flags); return VBOXSwitchMode(xf86Screens[scrnIndex], pMode); } + +static void VBOXAdjustFrameIndex(int scrnIndex, int x, int y, int flags) +{ RT_NOREF(flags); VBOXAdjustFrame(xf86Screens[scrnIndex], x, y); } + +static void VBOXFreeScreenIndex(int scrnIndex, int flags) +{ RT_NOREF(flags); VBOXFreeScreen(xf86Screens[scrnIndex]); } +# else +# define SCRNINDEXAPI(pfn) pfn +#endif /* XF86_SCRN_INTERFACE */ + +static void setScreenFunctions(ScrnInfoPtr pScrn, xf86ProbeProc pfnProbe) +{ + pScrn->driverVersion = VBOX_VERSION; + pScrn->driverName = VBOX_DRIVER_NAME; + pScrn->name = VBOX_NAME; + pScrn->Probe = pfnProbe; + pScrn->PreInit = VBOXPreInit; + pScrn->ScreenInit = SCRNINDEXAPI(VBOXScreenInit); + pScrn->SwitchMode = SCRNINDEXAPI(VBOXSwitchMode); + pScrn->AdjustFrame = SCRNINDEXAPI(VBOXAdjustFrame); + pScrn->EnterVT = SCRNINDEXAPI(VBOXEnterVT); + pScrn->LeaveVT = SCRNINDEXAPI(VBOXLeaveVT); + pScrn->FreeScreen = SCRNINDEXAPI(VBOXFreeScreen); +} + +/* + * One of these functions is called once, at the start of the first server + * generation to do a minimal probe for supported hardware. + */ + +#ifdef PCIACCESS +static Bool +VBOXPciProbe(DriverPtr drv, int entity_num, struct pci_device *dev, + intptr_t match_data) +{ + ScrnInfoPtr pScrn; + int drmFd; + + TRACE_ENTRY(); + + drmFd = open("/dev/dri/card0", O_RDWR, 0); + if (drmFd >= 0) + { + xf86Msg(X_INFO, "vboxvideo: kernel driver found, not loading.\n"); + close(drmFd); + return FALSE; + } + /* It is safe to call this, as the X server enables I/O access before + * calling the probe call-backs. */ + if (!xf86EnableIO()) + { + xf86Msg(X_INFO, "vboxvideo: this driver requires direct hardware access. You may wish to use the kernel driver instead.\n"); + return FALSE; + } + pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets, + NULL, NULL, NULL, NULL, NULL); + if (pScrn != NULL) { + VBOXPtr pVBox; + + VBOXSetRec(pScrn); + pVBox = VBOXGetRec(pScrn); + if (!pVBox) + return FALSE; + setScreenFunctions(pScrn, NULL); + pVBox->pciInfo = dev; + } + + TRACE_LOG("returning %s\n", pScrn == NULL ? "false" : "true"); + return (pScrn != NULL); +} +#endif + +#ifndef PCIACCESS +static Bool +VBOXProbe(DriverPtr drv, int flags) +{ + Bool foundScreen = FALSE; + int numDevSections; + GDevPtr *devSections; + + /* + * Find the config file Device sections that match this + * driver, and return if there are none. + */ + if ((numDevSections = xf86MatchDevice(VBOX_NAME, + &devSections)) <= 0) + return (FALSE); + + /* PCI BUS */ + if (xf86GetPciVideoInfo()) + { + int numUsed; + int *usedChips; + int i; + numUsed = xf86MatchPciInstances(VBOX_NAME, VBOX_VENDORID, + VBOXChipsets, VBOXPCIchipsets, + devSections, numDevSections, + drv, &usedChips); + if (numUsed > 0) + { + if (flags & PROBE_DETECT) + foundScreen = TRUE; + else + for (i = 0; i < numUsed; i++) + { + ScrnInfoPtr pScrn = NULL; + /* Allocate a ScrnInfoRec */ + if ((pScrn = xf86ConfigPciEntity(pScrn,0,usedChips[i], + VBOXPCIchipsets,NULL, + NULL,NULL,NULL,NULL))) + { + setScreenFunctions(pScrn, VBOXProbe); + foundScreen = TRUE; + } + } + free(usedChips); + } + } + free(devSections); + return (foundScreen); +} +#endif + + +/* + * QUOTE from the XFree86 DESIGN document: + * + * The purpose of this function is to find out all the information + * required to determine if the configuration is usable, and to initialise + * those parts of the ScrnInfoRec that can be set once at the beginning of + * the first server generation. + * + * (...) + * + * This includes probing for video memory, clocks, ramdac, and all other + * HW info that is needed. It includes determining the depth/bpp/visual + * and related info. It includes validating and determining the set of + * video modes that will be used (and anything that is required to + * determine that). + * + * This information should be determined in the least intrusive way + * possible. The state of the HW must remain unchanged by this function. + * Although video memory (including MMIO) may be mapped within this + * function, it must be unmapped before returning. + * + * END QUOTE + */ + +static Bool +VBOXPreInit(ScrnInfoPtr pScrn, int flags) +{ + VBOXPtr pVBox; + Gamma gzeros = {0.0, 0.0, 0.0}; + rgb rzeros = {0, 0, 0}; + + TRACE_ENTRY(); + /* Are we really starting the server, or is this just a dummy run? */ + if (flags & PROBE_DETECT) + return (FALSE); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "VirtualBox guest additions video driver version %d.%d\n", + VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR); + + /* The ramdac module is needed for the hardware cursor. */ + if (!xf86LoadSubModule(pScrn, "ramdac")) + return FALSE; + + /* The framebuffer module. */ + if (!xf86LoadSubModule(pScrn, "fb")) + return (FALSE); + + if (!xf86LoadSubModule(pScrn, "shadowfb")) + return FALSE; + + if (!xf86LoadSubModule(pScrn, "vgahw")) + return FALSE; + + /* Get our private data from the ScrnInfoRec structure. */ + VBOXSetRec(pScrn); + pVBox = VBOXGetRec(pScrn); + if (!pVBox) + return FALSE; + + /* Entity information seems to mean bus information. */ + pVBox->pEnt = xf86GetEntityInfo(pScrn->entityList[0]); + +#ifndef PCIACCESS + if (pVBox->pEnt->location.type != BUS_PCI) + return FALSE; + + pVBox->pciInfo = xf86GetPciInfoForEntity(pVBox->pEnt->index); + pVBox->pciTag = pciTag(pVBox->pciInfo->bus, + pVBox->pciInfo->device, + pVBox->pciInfo->func); +#endif + + /* Set up our ScrnInfoRec structure to describe our virtual + capabilities to X. */ + + pScrn->chipset = "vbox"; + /** @note needed during colourmap initialisation */ + pScrn->rgbBits = 8; + + /* Let's create a nice, capable virtual monitor. */ + pScrn->monitor = pScrn->confScreen->monitor; + pScrn->monitor->DDC = NULL; + pScrn->monitor->nHsync = 1; + pScrn->monitor->hsync[0].lo = 1; + pScrn->monitor->hsync[0].hi = 10000; + pScrn->monitor->nVrefresh = 1; + pScrn->monitor->vrefresh[0].lo = 1; + pScrn->monitor->vrefresh[0].hi = 100; + + pScrn->progClock = TRUE; + + /* Using the PCI information caused problems with non-powers-of-two + sized video RAM configurations */ + pVBox->cbFBMax = VBoxVideoGetVRAMSize(); + pScrn->videoRam = pVBox->cbFBMax / 1024; + + /* Check if the chip restricts horizontal resolution or not. */ + pVBox->fAnyX = VBoxVideoAnyWidthAllowed(); + + /* Set up clock information that will support all modes we need. */ + pScrn->clockRanges = xnfcalloc(sizeof(ClockRange), 1); + pScrn->clockRanges->minClock = 1000; + pScrn->clockRanges->maxClock = 1000000000; + pScrn->clockRanges->clockIndex = -1; + pScrn->clockRanges->ClockMulFactor = 1; + pScrn->clockRanges->ClockDivFactor = 1; + + if (!xf86SetDepthBpp(pScrn, 24, 0, 0, Support32bppFb)) + return FALSE; + /* We only support 16 and 24 bits depth (i.e. 16 and 32bpp) */ + if (pScrn->bitsPerPixel != 32 && pScrn->bitsPerPixel != 16) + { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "The VBox additions only support 16 and 32bpp graphics modes\n"); + return FALSE; + } + xf86PrintDepthBpp(pScrn); + vboxAddModes(pScrn); + +#ifdef VBOXVIDEO_13 + pScrn->virtualX = VBOX_VIDEO_MAX_VIRTUAL; + pScrn->virtualY = VBOX_VIDEO_MAX_VIRTUAL; +#else + /* We don't validate with xf86ValidateModes and xf86PruneModes as we + * already know what we like and what we don't. */ + + pScrn->currentMode = pScrn->modes; + + /* Set the right virtual resolution. */ + pScrn->virtualX = pScrn->bitsPerPixel == 16 ? (pScrn->currentMode->HDisplay + 1) & ~1 : pScrn->currentMode->HDisplay; + pScrn->virtualY = pScrn->currentMode->VDisplay; + +#endif /* !VBOXVIDEO_13 */ + + pScrn->displayWidth = pScrn->virtualX; + + xf86PrintModes(pScrn); + + /* VGA hardware initialisation */ + if (!vgaHWGetHWRec(pScrn)) + return FALSE; + /* Must be called before any VGA registers are saved or restored */ + vgaHWSetStdFuncs(VGAHWPTR(pScrn)); + vgaHWGetIOBase(VGAHWPTR(pScrn)); + + /* Colour weight - we always call this, since we are always in + truecolour. */ + if (!xf86SetWeight(pScrn, rzeros, rzeros)) + return (FALSE); + + /* visual init */ + if (!xf86SetDefaultVisual(pScrn, -1)) + return (FALSE); + + xf86SetGamma(pScrn, gzeros); + + /* Set the DPI. Perhaps we should read this from the host? */ + xf86SetDpi(pScrn, 96, 96); + + if (pScrn->memPhysBase == 0) { +#ifdef PCIACCESS + pScrn->memPhysBase = pVBox->pciInfo->regions[0].base_addr; +#else + pScrn->memPhysBase = pVBox->pciInfo->memBase[0]; +#endif + pScrn->fbOffset = 0; + } + + TRACE_EXIT(); + return (TRUE); +} + +/** + * Dummy function for setting the colour palette, which we actually never + * touch. However, the server still requires us to provide this. + */ +static void +vboxLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, + LOCO *colors, VisualPtr pVisual) +{ + RT_NOREF(pScrn, numColors, indices, colors, pVisual); +} + +/** Set the graphics and guest cursor support capabilities to the host if + * the user-space helper is running. */ +static void updateGraphicsCapability(ScrnInfoPtr pScrn, Bool hasVT) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + + if (!pVBox->fHaveHGSMIModeHints) + return; + VBoxHGSMISendCapsInfo(&pVBox->guestCtx, hasVT + ? VBVACAPS_VIDEO_MODE_HINTS | VBVACAPS_DISABLE_CURSOR_INTEGRATION + : VBVACAPS_DISABLE_CURSOR_INTEGRATION); +} + +#ifndef VBOXVIDEO_13 + +#define PREFERRED_MODE_ATOM_NAME "VBOXVIDEO_PREFERRED_MODE" + +static void setSizesRandR11(ScrnInfoPtr pScrn) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + DisplayModePtr pNewMode; + int32_t propertyValue; + + pNewMode = pScrn->modes != pScrn->currentMode ? pScrn->modes : pScrn->modes->next; + pNewMode->HDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL); + pNewMode->VDisplay = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL); + propertyValue = (pNewMode->HDisplay << 16) + pNewMode->VDisplay; + ChangeWindowProperty(ROOT_WINDOW(pScrn), MakeAtom(PREFERRED_MODE_ATOM_NAME, + sizeof(PREFERRED_MODE_ATOM_NAME) - 1, TRUE), XA_INTEGER, 32, + PropModeReplace, 1, &propertyValue, TRUE); +} + +#endif + +static void reprobeCursor(ScrnInfoPtr pScrn) +{ + if (ROOT_WINDOW(pScrn) == NULL) + return; +#ifdef XF86_SCRN_INTERFACE + pScrn->EnableDisableFBAccess(pScrn, FALSE); + pScrn->EnableDisableFBAccess(pScrn, TRUE); +#else + pScrn->EnableDisableFBAccess(pScrn->scrnIndex, FALSE); + pScrn->EnableDisableFBAccess(pScrn->scrnIndex, TRUE); +#endif +} + +static void setSizesAndCursorIntegration(ScrnInfoPtr pScrn, Bool fScreenInitTime) +{ + RT_NOREF(fScreenInitTime); + TRACE_LOG("fScreenInitTime=%d\n", (int)fScreenInitTime); +#ifdef VBOXVIDEO_13 +# if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 5 + RRGetInfo(xf86ScrnToScreen(pScrn), TRUE); +# else + RRGetInfo(xf86ScrnToScreen(pScrn)); +# endif +#else + setSizesRandR11(pScrn); +#endif + /* This calls EnableDisableFBAccess(), so only use when switched in. */ + if (pScrn->vtSema) + reprobeCursor(pScrn); +} + +/* We update the size hints from the X11 property set by VBoxClient every time + * that the X server goes to sleep (to catch the property change request). + * Although this is far more often than necessary it should not have real-life + * performance consequences and allows us to simplify the code quite a bit. */ +static void vboxBlockHandler(pointer pData, +#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 23 + OSTimePtr pTimeout, + pointer pReadmask +#else + void *pTimeout +#endif + ) +{ + ScrnInfoPtr pScrn = (ScrnInfoPtr)pData; + Bool fNeedUpdate = false; + + RT_NOREF(pTimeout); +#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 23 + RT_NOREF(pReadmask); +#endif + if (pScrn->vtSema) + vbvxReadSizesAndCursorIntegrationFromHGSMI(pScrn, &fNeedUpdate); + if (fNeedUpdate) + setSizesAndCursorIntegration(pScrn, false); +} + +/* + * QUOTE from the XFree86 DESIGN document: + * + * This is called at the start of each server generation. + * + * (...) + * + * Decide which operations need to be placed under resource access + * control. (...) Map any video memory or other memory regions. (...) + * Save the video card state. (...) Initialise the initial video + * mode. + * + * End QUOTE. + */ +static Bool VBOXScreenInit(ScreenPtr pScreen, int argc, char **argv) +{ + ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); + VBOXPtr pVBox = VBOXGetRec(pScrn); + VisualPtr visual; + RT_NOREF(argc, argv); + + TRACE_ENTRY(); + + if (!VBOXMapVidMem(pScrn)) + return (FALSE); + + /* save current video state */ + VBOXSaveMode(pScrn); + + /* mi layer - reset the visual list (?)*/ + miClearVisualTypes(); + if (!miSetVisualTypes(pScrn->depth, TrueColorMask, + pScrn->rgbBits, TrueColor)) + return (FALSE); + if (!miSetPixmapDepths()) + return (FALSE); + + if (!fbScreenInit(pScreen, pVBox->base, + pScrn->virtualX, pScrn->virtualY, + pScrn->xDpi, pScrn->yDpi, + pScrn->displayWidth, pScrn->bitsPerPixel)) + return (FALSE); + + /* Fixup RGB ordering */ + /** @note the X server uses this even in true colour. */ + visual = pScreen->visuals + pScreen->numVisuals; + while (--visual >= pScreen->visuals) { + if ((visual->class | DynamicClass) == DirectColor) { + visual->offsetRed = pScrn->offset.red; + visual->offsetGreen = pScrn->offset.green; + visual->offsetBlue = pScrn->offset.blue; + visual->redMask = pScrn->mask.red; + visual->greenMask = pScrn->mask.green; + visual->blueMask = pScrn->mask.blue; + } + } + + /* must be after RGB ordering fixed */ + fbPictureInit(pScreen, 0, 0); + + xf86SetBlackWhitePixels(pScreen); + pScrn->vtSema = TRUE; + +#if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX) + vbvxSetUpLinuxACPI(pScreen); +#endif + + if (!VBoxHGSMIIsSupported()) + { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Graphics device too old to support.\n"); + return FALSE; + } + vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024); + pVBox->cScreens = VBoxHGSMIGetMonitorCount(&pVBox->guestCtx); + pVBox->pScreens = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->pScreens)); + pVBox->paVBVAModeHints = xnfcalloc(pVBox->cScreens, sizeof(*pVBox->paVBVAModeHints)); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Requested monitor count: %u\n", pVBox->cScreens); + vboxEnableVbva(pScrn); + /* Set up the dirty rectangle handler. It will be added into a function + * chain and gets removed when the screen is cleaned up. */ + if (ShadowFBInit2(pScreen, NULL, vbvxHandleDirtyRect) != TRUE) + return FALSE; + VBoxInitialiseSizeHints(pScrn); + +#ifdef VBOXVIDEO_13 + /* Initialise CRTC and output configuration for use with randr1.2. */ + xf86CrtcConfigInit(pScrn, &VBOXCrtcConfigFuncs); + + { + uint32_t i; + + for (i = 0; i < pVBox->cScreens; ++i) + { + char szOutput[256]; + + /* Setup our virtual CRTCs. */ + pVBox->pScreens[i].paCrtcs = xf86CrtcCreate(pScrn, &VBOXCrtcFuncs); + pVBox->pScreens[i].paCrtcs->driver_private = (void *)(uintptr_t)i; + + /* Set up our virtual outputs. */ + snprintf(szOutput, sizeof(szOutput), "VGA-%u", i); + pVBox->pScreens[i].paOutputs + = xf86OutputCreate(pScrn, &VBOXOutputFuncs, szOutput); + + /* We are not interested in the monitor section in the + * configuration file. */ + xf86OutputUseScreenMonitor(pVBox->pScreens[i].paOutputs, FALSE); + pVBox->pScreens[i].paOutputs->possible_crtcs = 1 << i; + pVBox->pScreens[i].paOutputs->possible_clones = 0; + pVBox->pScreens[i].paOutputs->driver_private = (void *)(uintptr_t)i; + TRACE_LOG("Created crtc (%p) and output %s (%p)\n", + (void *)pVBox->pScreens[i].paCrtcs, szOutput, + (void *)pVBox->pScreens[i].paOutputs); + } + } + + /* Set a sane minimum and maximum mode size to match what the hardware + * supports. */ + xf86CrtcSetSizeRange(pScrn, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL, VBOX_VIDEO_MAX_VIRTUAL); + + /* Now create our initial CRTC/output configuration. */ + if (!xf86InitialConfiguration(pScrn, TRUE)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Initial CRTC configuration failed!\n"); + return (FALSE); + } + + /* Work around a bug in the original X server modesetting code, which took + * the first valid values set to these two as maxima over the server + * lifetime. This bug was introduced on Feb 15 2007 and was fixed in commit + * fa877d7f three months later, so it was present in X.Org Server 1.3. */ + pScrn->virtualX = VBOX_VIDEO_MAX_VIRTUAL; + pScrn->virtualY = VBOX_VIDEO_MAX_VIRTUAL; + + /* Initialise randr 1.2 mode-setting functions. */ + if (!xf86CrtcScreenInit(pScreen)) { + return FALSE; + } + + /* set first video mode */ + if (!xf86SetDesiredModes(pScrn)) { + return FALSE; + } +#else /* !VBOXVIDEO_13 */ + /* set first video mode */ + setModeRandR11(pScrn, pScrn->currentMode, true, false, 0, 0); +#endif /* !VBOXVIDEO_13 */ + + /* Say that we support graphics. */ + updateGraphicsCapability(pScrn, TRUE); + +#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) >= 23 +# define WakeupHandlerProcPtr ServerWakeupHandlerProcPtr +#endif + + /* Register block and wake-up handlers for getting new screen size hints. */ + RegisterBlockAndWakeupHandlers(vboxBlockHandler, (WakeupHandlerProcPtr)NoopDDA, (pointer)pScrn); + + /* software cursor */ + miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); + + /* colourmap code */ + if (!miCreateDefColormap(pScreen)) + return (FALSE); + + if(!xf86HandleColormaps(pScreen, 256, 8, vboxLoadPalette, NULL, 0)) + return (FALSE); + + pVBox->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = SCRNINDEXAPI(VBOXCloseScreen); +#ifdef VBOXVIDEO_13 + pScreen->SaveScreen = xf86SaveScreen; +#else + pScreen->SaveScreen = VBOXSaveScreen; +#endif + +#ifdef VBOXVIDEO_13 + xf86DPMSInit(pScreen, xf86DPMSSet, 0); +#else + /* We probably do want to support power management - even if we just use + a dummy function. */ + xf86DPMSInit(pScreen, VBOXDisplayPowerManagementSet, 0); +#endif + + /* Report any unused options (only for the first generation) */ + if (serverGeneration == 1) + xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); + + if (vbvxCursorInit(pScreen) != TRUE) + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Unable to start the VirtualBox mouse pointer integration with the host system.\n"); + + return (TRUE); +} + +#define NO_VT_ATOM_NAME "VBOXVIDEO_NO_VT" + +static Bool VBOXEnterVT(ScrnInfoPtr pScrn) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); +#ifndef VBOXVIDEO_13 + /* If we got a mode request while we were switched out, temporarily override + * the physical mode set to the device while keeping things consistent from + * the server's point of view. */ + int cXOverRide = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cx, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL); + int cYOverRide = RT_CLAMP(pVBox->pScreens[0].aPreferredSize.cy, VBOX_VIDEO_MIN_SIZE, VBOX_VIDEO_MAX_VIRTUAL); +#endif + + TRACE_ENTRY(); + vbvxSetUpHGSMIHeapInGuest(pVBox, pScrn->videoRam * 1024); + vboxEnableVbva(pScrn); + /* Re-set video mode */ +#ifdef VBOXVIDEO_13 + if (!xf86SetDesiredModes(pScrn)) { + return FALSE; + } +#else + setModeRandR11(pScrn, pScrn->currentMode, false, true, cXOverRide, cYOverRide); + DeleteProperty(ROOT_WINDOW(pScrn), MakeAtom(NO_VT_ATOM_NAME, sizeof(NO_VT_ATOM_NAME) - 1, TRUE)); +#endif + updateGraphicsCapability(pScrn, TRUE); + return TRUE; +} + +static void VBOXLeaveVT(ScrnInfoPtr pScrn) +{ +#ifdef VBOXVIDEO_13 + VBOXPtr pVBox = VBOXGetRec(pScrn); + unsigned i; +#else + int32_t propertyValue = 0; +#endif + + TRACE_ENTRY(); +#ifdef VBOXVIDEO_13 + for (i = 0; i < pVBox->cScreens; ++i) + vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff); +#else + ChangeWindowProperty(ROOT_WINDOW(pScrn), MakeAtom(NO_VT_ATOM_NAME, sizeof(NO_VT_ATOM_NAME) - 1, FALSE), XA_INTEGER, 32, + PropModeReplace, 1, &propertyValue, TRUE); +#endif + updateGraphicsCapability(pScrn, FALSE); + vboxDisableVbva(pScrn); + vbvxClearVRAM(pScrn, ((size_t)pScrn->virtualX) * pScrn->virtualY * (pScrn->bitsPerPixel / 8), 0); + VBOXRestoreMode(pScrn); + TRACE_EXIT(); +} + +static Bool VBOXCloseScreen(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); + VBOXPtr pVBox = VBOXGetRec(pScrn); + BOOL ret; + + if (pScrn->vtSema) + { +#ifdef VBOXVIDEO_13 + unsigned i; + + for (i = 0; i < pVBox->cScreens; ++i) + vbox_crtc_dpms(pVBox->pScreens[i].paCrtcs, DPMSModeOff); +#endif + vboxDisableVbva(pScrn); + vbvxClearVRAM(pScrn, ((size_t)pScrn->virtualX) * pScrn->virtualY * (pScrn->bitsPerPixel / 8), 0); + } + if (pScrn->vtSema) + VBOXRestoreMode(pScrn); + if (pScrn->vtSema) + VBOXUnmapVidMem(pScrn); + pScrn->vtSema = FALSE; + + vbvxCursorTerm(pVBox); + + pScreen->CloseScreen = pVBox->CloseScreen; +#if defined(VBOXVIDEO_13) && defined(RT_OS_LINUX) + vbvxCleanUpLinuxACPI(pScreen); +#endif +#ifndef XF86_SCRN_INTERFACE + ret = pScreen->CloseScreen(pScreen->myNum, pScreen); +#else + ret = pScreen->CloseScreen(pScreen); +#endif + return ret; +} + +static Bool VBOXSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr pMode) +{ + Bool rc = TRUE; + + TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay); +#ifdef VBOXVIDEO_13 + rc = xf86SetSingleMode(pScrn, pMode, RR_Rotate_0); +#else + setModeRandR11(pScrn, pMode, false, false, 0, 0); +#endif + TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE"); + return rc; +} + +static void VBOXAdjustFrame(ScrnInfoPtr pScrn, int x, int y) +{ RT_NOREF(pScrn, x, y); } + +static void VBOXFreeScreen(ScrnInfoPtr pScrn) +{ + /* Destroy the VGA hardware record */ + vgaHWFreeHWRec(pScrn); + /* And our private record */ + free(pScrn->driverPrivate); + pScrn->driverPrivate = NULL; +} + +static Bool +VBOXMapVidMem(ScrnInfoPtr pScrn) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + Bool rc = TRUE; + + TRACE_ENTRY(); + if (!pVBox->base) + { +#ifdef PCIACCESS + (void) pci_device_map_range(pVBox->pciInfo, + pScrn->memPhysBase, + pScrn->videoRam * 1024, + PCI_DEV_MAP_FLAG_WRITABLE, + & pVBox->base); +#else + pVBox->base = xf86MapPciMem(pScrn->scrnIndex, + VIDMEM_FRAMEBUFFER, + pVBox->pciTag, pScrn->memPhysBase, + (unsigned) pScrn->videoRam * 1024); +#endif + if (!pVBox->base) + rc = FALSE; + } + TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE"); + return rc; +} + +static void +VBOXUnmapVidMem(ScrnInfoPtr pScrn) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + + TRACE_ENTRY(); + if (pVBox->base == NULL) + return; + +#ifdef PCIACCESS + (void) pci_device_unmap_range(pVBox->pciInfo, + pVBox->base, + pScrn->videoRam * 1024); +#else + xf86UnMapVidMem(pScrn->scrnIndex, pVBox->base, + (unsigned) pScrn->videoRam * 1024); +#endif + pVBox->base = NULL; + TRACE_EXIT(); +} + +#ifndef VBOXVIDEO_13 +static Bool +VBOXSaveScreen(ScreenPtr pScreen, int mode) +{ + RT_NOREF(pScreen, mode); + return TRUE; +} +#endif + +void +VBOXSaveMode(ScrnInfoPtr pScrn) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + vgaRegPtr vgaReg; + + TRACE_ENTRY(); + vgaReg = &VGAHWPTR(pScrn)->SavedReg; + vgaHWSave(pScrn, vgaReg, VGA_SR_ALL); + pVBox->fSavedVBEMode = VBoxVideoGetModeRegisters(&pVBox->cSavedWidth, + &pVBox->cSavedHeight, + &pVBox->cSavedPitch, + &pVBox->cSavedBPP, + &pVBox->fSavedFlags); +} + +void +VBOXRestoreMode(ScrnInfoPtr pScrn) +{ + VBOXPtr pVBox = VBOXGetRec(pScrn); + vgaRegPtr vgaReg; + + TRACE_ENTRY(); + vgaReg = &VGAHWPTR(pScrn)->SavedReg; + vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL); + if (pVBox->fSavedVBEMode) + VBoxVideoSetModeRegisters(pVBox->cSavedWidth, pVBox->cSavedHeight, + pVBox->cSavedPitch, pVBox->cSavedBPP, + pVBox->fSavedFlags, 0, 0); + else + VBoxVideoDisableVBE(); +} + +#ifndef VBOXVIDEO_13 +static void +VBOXDisplayPowerManagementSet(ScrnInfoPtr pScrn, int mode, int flags) +{ + RT_NOREF(pScrn, mode, flags); +} +#endif diff --git a/src/VBox/Additions/x11/vboxvideo/vboxvideo.h b/src/VBox/Additions/x11/vboxvideo/vboxvideo.h new file mode 100644 index 00000000..f7be37c2 --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/vboxvideo.h @@ -0,0 +1,240 @@ +/* $Id: vboxvideo.h $ */ +/** @file + * VirtualBox X11 Additions graphics driver + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * This file is based on the X11 VESA driver: + * + * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com) + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Conectiva Linux shall + * not be used in advertising or otherwise to promote the sale, use or other + * dealings in this Software without prior written authorization from + * Conectiva Linux. + * + * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br> + * Michael Thayer <michael.thayer@oracle.com> + */ + +#ifndef GA_INCLUDED_SRC_x11_vboxvideo_vboxvideo_h +#define GA_INCLUDED_SRC_x11_vboxvideo_vboxvideo_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#include <VBoxVideoGuest.h> +#include <VBoxVideo.h> +#include "version-generated.h" + +#define VBOX_VENDORID 0x80EE +#define VBOX_DEVICEID 0xBEEF + +#ifndef VBVA_SCREEN_F_BLANK +# define VBVA_SCREEN_F_BLANK 0x0004 +#endif + +#include <VBoxVideoVBE.h> + +#include "xf86.h" +#include "xf86str.h" +#include "xf86Cursor.h" + +#ifdef DEBUG + +#define TRACE_ENTRY() do { xf86ErrorF("%s: entering\n", __func__); } while(0) +#define TRACE_EXIT() do { xf86ErrorF("%s: leaving\n", __func__); } while(0) +#define TRACE_LINE() \ + do { xf86ErrorF("%s: line\n", __func__, __LINE__); } while(0) +#define TRACE_LOG(...) \ +do { \ + xf86ErrorF("%s: ", __func__); \ + xf86ErrorF(__VA_ARGS__); \ +} while(0) + +#else /* !DEBUG */ + +#define TRACE_ENTRY() do { } while (0) +#define TRACE_EXIT() do { } while (0) +#define TRACE_LOG(...) do { } while (0) + +#endif /* !DEBUG */ + +#define VBOX_VERSION VBOX_VERSION_MAJOR * 10000 \ + + VBOX_VERSION_MINOR * 100 +#define VBOX_NAME "VBoxVideo" +#define VBOX_DRIVER_NAME "vboxvideo" + +#define VBOX_VIDEO_MAJOR VBOX_VERSION_MAJOR +#define VBOX_VIDEO_MINOR VBOX_VERSION_MINOR + +#define VBOX_VIDEO_MIN_SIZE 64 +#define VBOX_VIDEO_MAX_VIRTUAL (INT16_MAX - 1) + +#define VBOXPTR(p) ((VBOXPtr)((p)->driverPrivate)) + +/** Helper to work round different ways of getting the root window in different + * server versions. */ +#if defined(XORG_VERSION_CURRENT) && XORG_VERSION_CURRENT < 70000000 \ + && XORG_VERSION_CURRENT >= 10900000 +# define ROOT_WINDOW(pScrn) screenInfo.screens[(pScrn)->scrnIndex]->root +#else +# define ROOT_WINDOW(pScrn) WindowTable[(pScrn)->scrnIndex] +#endif + +/** ChangeWindowProperty for X.Org Server 1.19 and later */ +#if defined(XORG_VERSION_CURRENT) && XORG_VERSION_CURRENT < 70000000 \ + && XORG_VERSION_CURRENT >= 11900000 +# define ChangeWindowProperty(pWin, property, type, format, mode, \ + len, value, sendevent) \ + dixChangeWindowProperty(serverClient, pWin, property, type, format, \ + mode, len, value, sendevent) +#endif + +/** Structure containing all virtual monitor-specific information. */ +struct VBoxScreen +{ + /** Position information for each virtual screen for the purposes of + * sending dirty rectangle information to the right one. */ + RTRECT2 aScreenLocation; + /** Is this CRTC enabled or in DPMS off state? */ + Bool fPowerOn; +#ifdef VBOXVIDEO_13 + /** The virtual crtcs. */ + struct _xf86Crtc *paCrtcs; + /** The virtual outputs, logically not distinct from crtcs. */ + struct _xf86Output *paOutputs; +#endif + /** Offsets of VBVA buffers in video RAM */ + uint32_t aoffVBVABuffer; + /** Context information about the VBVA buffers for each screen */ + struct VBVABUFFERCONTEXT aVbvaCtx; + /** The current preferred resolution for the screen */ + RTRECTSIZE aPreferredSize; + /** The current preferred location for the screen. */ + RTPOINT aPreferredLocation; + /** Has this screen been enabled by the host? */ + Bool afConnected; + /** Does this screen have a preferred location? */ + Bool afHaveLocation; +}; + +typedef struct VBOXRec +{ + EntityInfoPtr pEnt; +#ifdef PCIACCESS + struct pci_device *pciInfo; +#else + pciVideoPtr pciInfo; + PCITAG pciTag; +#endif + void *base; + /** The amount of VRAM available for use as a framebuffer */ + unsigned long cbFBMax; + /** The size of the framebuffer and the VBVA buffers at the end of it. */ + unsigned long cbView; + /** Whether the pre-X-server mode was a VBE mode */ + Bool fSavedVBEMode; + /** Paramters of the saved pre-X-server VBE mode, invalid if there is none + */ + uint16_t cSavedWidth, cSavedHeight, cSavedPitch, cSavedBPP, fSavedFlags; + CloseScreenProcPtr CloseScreen; + /** Default X server procedure for enabling and disabling framebuffer access */ + xf86EnableDisableFBAccessProc *EnableDisableFBAccess; + OptionInfoPtr Options; + /** @todo we never actually free this */ + xf86CursorInfoPtr pCurs; + /** Do we currently want to use the host cursor? */ + Bool fUseHardwareCursor; + /** Number of screens attached */ + uint32_t cScreens; + /** Information about each virtual screen. */ + struct VBoxScreen *pScreens; + /** Can we get mode hint and cursor integration information from HGSMI? */ + Bool fHaveHGSMIModeHints; + /** Does the host support the screen blanking flag? */ + Bool fHostHasScreenBlankingFlag; + /** Array of structures for receiving mode hints. */ + VBVAMODEHINT *paVBVAModeHints; +#ifdef VBOXVIDEO_13 +# ifdef RT_OS_LINUX + /** Input device file descriptor for getting ACPI hot-plug events. */ + int fdACPIDevices; + /** Input handler handle for ACPI hot-plug listener. */ + void *hACPIEventHandler; +# endif +#endif + /** HGSMI guest heap context */ + HGSMIGUESTCOMMANDCONTEXT guestCtx; + /** Unrestricted horizontal resolution flag. */ + Bool fAnyX; +} VBOXRec, *VBOXPtr; + +#define VBOXGetRec(pScrn) ((VBOXPtr)(pScrn)->driverPrivate) + +/* setmode.c */ + +/** Structure describing the virtual frame buffer. It starts at the beginning + * of the video RAM. */ +struct vbvxFrameBuffer { + /** X offset of first screen in frame buffer. */ + int x0; + /** Y offset of first screen in frame buffer. */ + int y0; + /** Frame buffer virtual width. */ + unsigned cWidth; + /** Frame buffer virtual height. */ + unsigned cHeight; + /** Bits per pixel. */ + unsigned cBPP; +}; + +extern void vbvxClearVRAM(ScrnInfoPtr pScrn, size_t cbOldSize, size_t cbNewSize); +extern void vbvxSetMode(ScrnInfoPtr pScrn, unsigned cDisplay, unsigned cWidth, unsigned cHeight, int x, int y, Bool fEnabled, + Bool fConnected, struct vbvxFrameBuffer *pFrameBuffer); +extern void vbvxSetSolarisMouseRange(int width, int height); + +/* pointer.h */ +extern Bool vbvxCursorInit(ScreenPtr pScreen); +extern void vbvxCursorTerm(VBOXPtr pVBox); + +/* vbva.c */ +extern void vbvxHandleDirtyRect(ScrnInfoPtr pScrn, int iRects, BoxPtr aRects); +extern void vbvxSetUpHGSMIHeapInGuest(VBOXPtr pVBox, uint32_t cbVRAM); +extern Bool vboxEnableVbva(ScrnInfoPtr pScrn); +extern void vboxDisableVbva(ScrnInfoPtr pScrn); + +/* getmode.c */ +extern void vboxAddModes(ScrnInfoPtr pScrn); +extern void VBoxInitialiseSizeHints(ScrnInfoPtr pScrn); +extern void vbvxReadSizesAndCursorIntegrationFromProperties(ScrnInfoPtr pScrn, Bool *pfNeedUpdate); +extern void vbvxReadSizesAndCursorIntegrationFromHGSMI(ScrnInfoPtr pScrn, Bool *pfNeedUpdate); +extern void vbvxSetUpLinuxACPI(ScreenPtr pScreen); +extern void vbvxCleanUpLinuxACPI(ScreenPtr pScreen); + +/* EDID generation */ +#ifdef VBOXVIDEO_13 +extern Bool VBOXEDIDSet(struct _xf86Output *output, DisplayModePtr pmode); +#endif + +#endif /* !GA_INCLUDED_SRC_x11_vboxvideo_vboxvideo_h */ + diff --git a/src/VBox/Additions/x11/vboxvideo/vbva.c b/src/VBox/Additions/x11/vboxvideo/vbva.c new file mode 100644 index 00000000..3dfced3c --- /dev/null +++ b/src/VBox/Additions/x11/vboxvideo/vbva.c @@ -0,0 +1,255 @@ +/* $Id: vbva.c $ */ +/** @file + * VirtualBox X11 Additions graphics driver 2D acceleration functions + */ + +/* + * Copyright (C) 2006-2022 Oracle and/or its affiliates. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#if defined(IN_XF86_MODULE) && !defined(NO_ANSIC) +# include "xf86_ansic.h" +#endif +#include "compiler.h" + +#include "vboxvideo.h" + +#ifdef XORG_7X +# include <stdlib.h> +# include <string.h> +#endif + +/************************************************************************** +* Main functions * +**************************************************************************/ + +/** + * Callback function called by the X server to tell us about dirty + * rectangles in the video buffer. + * + * @param pScrn pointer to the information structure for the current + * screen + * @param iRects Number of dirty rectangles to update + * @param aRects Array of structures containing the coordinates of the + * rectangles + */ +void vbvxHandleDirtyRect(ScrnInfoPtr pScrn, int iRects, BoxPtr aRects) +{ + VBVACMDHDR cmdHdr; + VBOXPtr pVBox; + int i; + unsigned j; + + pVBox = pScrn->driverPrivate; + if (!pScrn->vtSema) + return; + + for (j = 0; j < pVBox->cScreens; ++j) + { + /* Just continue quietly if VBVA is not currently active. */ + struct VBVABUFFER *pVBVA = pVBox->pScreens[j].aVbvaCtx.pVBVA; + if ( !pVBVA + || !(pVBVA->hostFlags.u32HostEvents & VBVA_F_MODE_ENABLED)) + continue; + for (i = 0; i < iRects; ++i) + { + if ( aRects[i].x1 > pVBox->pScreens[j].aScreenLocation.x + + pVBox->pScreens[j].aScreenLocation.cx + || aRects[i].y1 > pVBox->pScreens[j].aScreenLocation.y + + pVBox->pScreens[j].aScreenLocation.cy + || aRects[i].x2 < pVBox->pScreens[j].aScreenLocation.x + || aRects[i].y2 < pVBox->pScreens[j].aScreenLocation.y) + continue; + cmdHdr.x = (int16_t)aRects[i].x1 - pVBox->pScreens[0].aScreenLocation.x; + cmdHdr.y = (int16_t)aRects[i].y1 - pVBox->pScreens[0].aScreenLocation.y; + cmdHdr.w = (uint16_t)(aRects[i].x2 - aRects[i].x1); + cmdHdr.h = (uint16_t)(aRects[i].y2 - aRects[i].y1); + +#if 0 + TRACE_LOG("display=%u, x=%d, y=%d, w=%d, h=%d\n", + j, cmdHdr.x, cmdHdr.y, cmdHdr.w, cmdHdr.h); +#endif + + if (VBoxVBVABufferBeginUpdate(&pVBox->pScreens[j].aVbvaCtx, + &pVBox->guestCtx)) + { + VBoxVBVAWrite(&pVBox->pScreens[j].aVbvaCtx, &pVBox->guestCtx, &cmdHdr, + sizeof(cmdHdr)); + VBoxVBVABufferEndUpdate(&pVBox->pScreens[j].aVbvaCtx); + } + } + } +} + +static DECLCALLBACK(void *) hgsmiEnvAlloc(void *pvEnv, HGSMISIZE cb) +{ + RT_NOREF(pvEnv); + return calloc(1, cb); +} + +static DECLCALLBACK(void) hgsmiEnvFree(void *pvEnv, void *pv) +{ + RT_NOREF(pvEnv); + free(pv); +} + +static HGSMIENV g_hgsmiEnv = +{ + NULL, + hgsmiEnvAlloc, + hgsmiEnvFree +}; + +/** + * Calculate the location in video RAM of and initialise the heap for guest to + * host messages. + */ +void vbvxSetUpHGSMIHeapInGuest(VBOXPtr pVBox, uint32_t cbVRAM) +{ + int rc; + uint32_t offVRAMBaseMapping, offGuestHeapMemory, cbGuestHeapMemory; + void *pvGuestHeapMemory; + + VBoxHGSMIGetBaseMappingInfo(cbVRAM, &offVRAMBaseMapping, NULL, &offGuestHeapMemory, &cbGuestHeapMemory, NULL); + pvGuestHeapMemory = ((uint8_t *)pVBox->base) + offVRAMBaseMapping + offGuestHeapMemory; + rc = VBoxHGSMISetupGuestContext(&pVBox->guestCtx, pvGuestHeapMemory, cbGuestHeapMemory, + offVRAMBaseMapping + offGuestHeapMemory, &g_hgsmiEnv); + AssertMsg(RT_SUCCESS(rc), ("Failed to set up the guest-to-host message buffer heap, rc=%d\n", rc)); + pVBox->cbView = offVRAMBaseMapping; +} + +/** Callback to fill in the view structures */ +static DECLCALLBACK(int) vboxFillViewInfo(void *pvVBox, struct VBVAINFOVIEW *pViews, uint32_t cViews) +{ + VBOXPtr pVBox = (VBOXPtr)pvVBox; + unsigned i; + for (i = 0; i < cViews; ++i) + { + pViews[i].u32ViewIndex = i; + pViews[i].u32ViewOffset = 0; + pViews[i].u32ViewSize = pVBox->cbView; + pViews[i].u32MaxScreenSize = pVBox->cbFBMax; + } + return VINF_SUCCESS; +} + +/** + * Initialise VirtualBox's accelerated video extensions. + * + * @returns TRUE on success, FALSE on failure + */ +static Bool vboxSetupVRAMVbva(VBOXPtr pVBox) +{ + int rc = VINF_SUCCESS; + unsigned i; + + pVBox->cbFBMax = pVBox->cbView; + for (i = 0; i < pVBox->cScreens; ++i) + { + pVBox->cbFBMax -= VBVA_MIN_BUFFER_SIZE; + pVBox->pScreens[i].aoffVBVABuffer = pVBox->cbFBMax; + TRACE_LOG("VBVA buffer offset for screen %u: 0x%lx\n", i, + (unsigned long) pVBox->cbFBMax); + VBoxVBVASetupBufferContext(&pVBox->pScreens[i].aVbvaCtx, + pVBox->pScreens[i].aoffVBVABuffer, + VBVA_MIN_BUFFER_SIZE); + } + TRACE_LOG("Maximum framebuffer size: %lu (0x%lx)\n", + (unsigned long) pVBox->cbFBMax, + (unsigned long) pVBox->cbFBMax); + rc = VBoxHGSMISendViewInfo(&pVBox->guestCtx, pVBox->cScreens, + vboxFillViewInfo, (void *)pVBox); + AssertMsg(RT_SUCCESS(rc), ("Failed to send the view information to the host, rc=%d\n", rc)); + return TRUE; +} + +static Bool haveHGSMIModeHintAndCursorReportingInterface(VBOXPtr pVBox) +{ + uint32_t fModeHintReporting, fCursorReporting; + + return RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_MODE_HINT_REPORTING, &fModeHintReporting)) + && RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_GUEST_CURSOR_REPORTING, &fCursorReporting)) + && fModeHintReporting == VINF_SUCCESS + && fCursorReporting == VINF_SUCCESS; +} + +static Bool hostHasScreenBlankingFlag(VBOXPtr pVBox) +{ + uint32_t fScreenFlags; + + return RT_SUCCESS(VBoxQueryConfHGSMI(&pVBox->guestCtx, VBOX_VBVA_CONF32_SCREEN_FLAGS, &fScreenFlags)) + && fScreenFlags & VBVA_SCREEN_F_BLANK; +} + +/** + * Inform VBox that we will supply it with dirty rectangle information + * and install the dirty rectangle handler. + * + * @returns TRUE for success, FALSE for failure + * @param pScrn Pointer to a structure describing the X screen in use + */ +Bool +vboxEnableVbva(ScrnInfoPtr pScrn) +{ + Bool rc = TRUE; + unsigned i; + VBOXPtr pVBox = pScrn->driverPrivate; + + TRACE_ENTRY(); + if (!vboxSetupVRAMVbva(pVBox)) + return FALSE; + for (i = 0; i < pVBox->cScreens; ++i) + { + struct VBVABUFFER *pVBVA; + + pVBVA = (struct VBVABUFFER *) ( ((uint8_t *)pVBox->base) + + pVBox->pScreens[i].aoffVBVABuffer); + if (!VBoxVBVAEnable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx, + pVBVA, i)) + rc = FALSE; + } + AssertMsg(rc, ("Failed to enable screen update reporting for at least one virtual monitor.\n")); + pVBox->fHaveHGSMIModeHints = haveHGSMIModeHintAndCursorReportingInterface(pVBox); + pVBox->fHostHasScreenBlankingFlag = hostHasScreenBlankingFlag(pVBox); + return rc; +} + +/** + * Inform VBox that we will stop supplying it with dirty rectangle + * information. This function is intended to be called when an X + * virtual terminal is disabled, or the X server is terminated. + * + * @returns TRUE for success, FALSE for failure + * @param pScrn Pointer to a structure describing the X screen in use + */ +void +vboxDisableVbva(ScrnInfoPtr pScrn) +{ + unsigned i; + VBOXPtr pVBox = pScrn->driverPrivate; + + TRACE_ENTRY(); + for (i = 0; i < pVBox->cScreens; ++i) + VBoxVBVADisable(&pVBox->pScreens[i].aVbvaCtx, &pVBox->guestCtx, i); +} |