diff options
Diffstat (limited to 'driver/xf86-video-vmware/src')
21 files changed, 7621 insertions, 0 deletions
diff --git a/driver/xf86-video-vmware/src/Makefile.am b/driver/xf86-video-vmware/src/Makefile.am new file mode 100644 index 000000000..b7857b982 --- /dev/null +++ b/driver/xf86-video-vmware/src/Makefile.am @@ -0,0 +1,50 @@ +# Copyright 2005 Adam Jackson. +# +# 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 +# on the rights to use, copy, modify, merge, publish, distribute, sub +# license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL +# ADAM JACKSON 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. + +# this is obnoxious: +# -module lets us name the module exactly how we want +# -avoid-version prevents gratuitous .0.0.0 version numbers on the end +# _ladir passes a dummy rpath to libtool so the thing will actually link +# TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. +AM_CFLAGS = @XORG_CFLAGS@ +vmware_drv_la_LTLIBRARIES = vmware_drv.la +vmware_drv_la_LDFLAGS = -module -avoid-version +vmware_drv_ladir = @moduledir@/drivers + +vmware_drv_la_SOURCES = \ + bits2pixels.c \ + bits2pixels.h \ + guest_os.h \ + includeCheck.h \ + offscreen_manager.c \ + offscreen_manager.h \ + svga_limits.h \ + svga_reg.h \ + svga_struct.h \ + vm_basic_types.h \ + vm_device_version.h \ + vmware.c \ + vmwarecurs.c \ + vmware.h \ + vmwarexaa.c \ + vmwarectrl.c \ + vmwarectrl.h \ + vmwarectrlproto.h \ + vmwarexinerama.c diff --git a/driver/xf86-video-vmware/src/Makefile.in b/driver/xf86-video-vmware/src/Makefile.in new file mode 100644 index 000000000..80083a8b0 --- /dev/null +++ b/driver/xf86-video-vmware/src/Makefile.in @@ -0,0 +1,530 @@ +# Makefile.in generated by automake 1.9.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# Copyright 2005 Adam Jackson. +# +# 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 +# on the rights to use, copy, modify, merge, publish, distribute, sub +# license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL +# ADAM JACKSON 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. + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(vmware_drv_ladir)" +vmware_drv_laLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(vmware_drv_la_LTLIBRARIES) +vmware_drv_la_LIBADD = +am_vmware_drv_la_OBJECTS = bits2pixels.lo offscreen_manager.lo \ + vmware.lo vmwarecurs.lo vmwarexaa.lo vmwarectrl.lo \ + vmwarexinerama.lo +vmware_drv_la_OBJECTS = $(am_vmware_drv_la_OBJECTS) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(vmware_drv_la_SOURCES) +DIST_SOURCES = $(vmware_drv_la_SOURCES) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +ADMIN_MAN_DIR = @ADMIN_MAN_DIR@ +ADMIN_MAN_SUFFIX = @ADMIN_MAN_SUFFIX@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +APP_MAN_DIR = @APP_MAN_DIR@ +APP_MAN_SUFFIX = @APP_MAN_SUFFIX@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DRIVER_MAN_DIR = @DRIVER_MAN_DIR@ +DRIVER_MAN_SUFFIX = @DRIVER_MAN_SUFFIX@ +DRIVER_NAME = @DRIVER_NAME@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +FILE_MAN_DIR = @FILE_MAN_DIR@ +FILE_MAN_SUFFIX = @FILE_MAN_SUFFIX@ +GREP = @GREP@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIB_MAN_DIR = @LIB_MAN_DIR@ +LIB_MAN_SUFFIX = @LIB_MAN_SUFFIX@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@ +MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@ +MAKEINFO = @MAKEINFO@ +MISC_MAN_DIR = @MISC_MAN_DIR@ +MISC_MAN_SUFFIX = @MISC_MAN_SUFFIX@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +XORG_CFLAGS = @XORG_CFLAGS@ +XORG_LIBS = @XORG_LIBS@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +moduledir = @moduledir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ + +# this is obnoxious: +# -module lets us name the module exactly how we want +# -avoid-version prevents gratuitous .0.0.0 version numbers on the end +# _ladir passes a dummy rpath to libtool so the thing will actually link +# TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. +AM_CFLAGS = @XORG_CFLAGS@ +vmware_drv_la_LTLIBRARIES = vmware_drv.la +vmware_drv_la_LDFLAGS = -module -avoid-version +vmware_drv_ladir = @moduledir@/drivers +vmware_drv_la_SOURCES = \ + bits2pixels.c \ + bits2pixels.h \ + guest_os.h \ + includeCheck.h \ + offscreen_manager.c \ + offscreen_manager.h \ + svga_limits.h \ + svga_reg.h \ + svga_struct.h \ + vm_basic_types.h \ + vm_device_version.h \ + vmware.c \ + vmwarecurs.c \ + vmware.h \ + vmwarexaa.c \ + vmwarectrl.c \ + vmwarectrl.h \ + vmwarectrlproto.h \ + vmwarexinerama.c + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-vmware_drv_laLTLIBRARIES: $(vmware_drv_la_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(vmware_drv_ladir)" || $(mkdir_p) "$(DESTDIR)$(vmware_drv_ladir)" + @list='$(vmware_drv_la_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=install $(vmware_drv_laLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(vmware_drv_ladir)/$$f'"; \ + $(LIBTOOL) --mode=install $(vmware_drv_laLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(vmware_drv_ladir)/$$f"; \ + else :; fi; \ + done + +uninstall-vmware_drv_laLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @set -x; list='$(vmware_drv_la_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(vmware_drv_ladir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(vmware_drv_ladir)/$$p"; \ + done + +clean-vmware_drv_laLTLIBRARIES: + -test -z "$(vmware_drv_la_LTLIBRARIES)" || rm -f $(vmware_drv_la_LTLIBRARIES) + @list='$(vmware_drv_la_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +vmware_drv.la: $(vmware_drv_la_OBJECTS) $(vmware_drv_la_DEPENDENCIES) + $(LINK) -rpath $(vmware_drv_ladir) $(vmware_drv_la_LDFLAGS) $(vmware_drv_la_OBJECTS) $(vmware_drv_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bits2pixels.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/offscreen_manager.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vmware.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vmwarectrl.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vmwarecurs.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vmwarexaa.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vmwarexinerama.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) +installdirs: + for dir in "$(DESTDIR)$(vmware_drv_ladir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-vmware_drv_laLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-vmware_drv_laLTLIBRARIES + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am uninstall-vmware_drv_laLTLIBRARIES + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-vmware_drv_laLTLIBRARIES ctags distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-strip install-vmware_drv_laLTLIBRARIES installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-info-am \ + uninstall-vmware_drv_laLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/driver/xf86-video-vmware/src/bits2pixels.c b/driver/xf86-video-vmware/src/bits2pixels.c new file mode 100644 index 000000000..2a1cc1490 --- /dev/null +++ b/driver/xf86-video-vmware/src/bits2pixels.c @@ -0,0 +1,1419 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/bits2pixels.c,v 1.1 2001/04/05 19:29:43 dawes Exp $ */ +/* ********************************************************** + * Copyright (C) 1999-2001 VMware, Inc. + * All Rights Reserved + * **********************************************************/ +#ifdef VMX86_DEVEL +char rcsId_bits2pixels[] = "Id: bits2pixels.c,v 1.6 2001/01/26 23:32:15 yoel Exp $"; +#else +#define FILECODE "F(814)" +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* + * bits2pixels.c -- + * + * Emulation routines to convert bitmaps to pixmaps + */ + +#include "vm_basic_types.h" +#include "bits2pixels.h" + + +/* + * Local functions + */ + +static void RasterBitsToPixels8(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, + uint32 width, uint32 height, uint32 fg, uint32 bg); + +static void RasterBitsToPixels16(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, + uint32 width, uint32 height, uint32 fg, uint32 bg); + +static void RasterBitsToPixels24(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, + uint32 width, uint32 height, uint32 fg, uint32 bg); + +static void RasterBitsToPixels32(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, + uint32 width, uint32 height, uint32 fg, uint32 bg); + + +/* + *---------------------------------------------------------------------- + * + * vmwareRaster_BitsToPixels -- + * + * Convert a bitmap to a pixmap, converting 1 bits to the foreground + * color (fg) and 0 bits to the background color (bg). + * + * Results: + * Pixmap filled with pixels + * + * Side effects: + * None + * + *---------------------------------------------------------------------- + */ + +void +vmwareRaster_BitsToPixels(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, int bytes_per_pixel, + uint32 width, uint32 height, uint32 fg, uint32 bg) +{ + switch (bytes_per_pixel) { + case 1: + RasterBitsToPixels8(bits, bits_increment, pix, pix_increment, + width, height, fg, bg); + break; + + case 2: + RasterBitsToPixels16(bits, bits_increment, pix, pix_increment, + width, height, fg, bg); + break; + + case 3: + RasterBitsToPixels24(bits, bits_increment, pix, pix_increment, + width, height, fg, bg); + break; + + case 4: + RasterBitsToPixels32(bits, bits_increment, pix, pix_increment, + width, height, fg, bg); + break; + } +} + + +/* + *---------------------------------------------------------------------- + * + * RasterBitsToPixels8 -- + * + * Convert a bitmap to a pixmap, converting 1 bits to the foreground + * color (fg) and 0 bits to the background color (bg), for an 8-bit + * pixmap + * + * Results: + * Pixmap filled with pixels + * + * Side effects: + * None + * + *---------------------------------------------------------------------- + */ + +void +RasterBitsToPixels8(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, + uint32 width, uint32 height, uint32 fg, uint32 bg) +{ + uint8 *lpix, *lbits; + int i, j; + uint32 expbits = 0; /* Bits to be expanded */ + + for (i=0; i<height; i++) { + lpix = pix; + lbits = bits; + for (j = width ; j > 0; j -= 4) { + expbits = (*lbits >> 4) & 0x0f; + + if (j < 4) + break; + + switch (expbits) { + case 0: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 1: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 2: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 3: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 4: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 5: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 6: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 7: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 8: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 9: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 10: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 11: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 12: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 13: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 14: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 15: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + } + + expbits = *lbits & 0x0f; + + j -= 4; + if (j < 4) { + break; + } + + switch (expbits) { + case 0: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 1: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 2: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 3: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 4: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 5: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 6: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 7: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 8: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 9: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 10: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 11: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 12: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 13: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 14: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 15: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + } + lbits++; + } + + if (j > 0) { + *lpix++ = (expbits & 0x08) ? fg : bg; + j--; + if (j > 0) { + *lpix++ = (expbits & 0x04) ? fg : bg; + j--; + if (j > 0) { + *lpix++ = (expbits & 0x02) ? fg : bg; + j--; + } + } + } + + pix += pix_increment; + bits += bits_increment; + } + return; +} + + +/* + *---------------------------------------------------------------------- + * + * RasterBitsToPixels16 -- + * + * Convert a bitmap to a pixmap, converting 1 bits to the foreground + * color (fg) and 0 bits to the background color (bg), for a 16-bit + * pixmap + * + * Results: + * Pixmap filled with pixels + * + * Side effects: + * None + * + *---------------------------------------------------------------------- + */ + +void +RasterBitsToPixels16(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, + uint32 width, uint32 height, uint32 fg, uint32 bg) +{ + uint16 *lpix; + uint8 *lbits; + int i, j; + uint32 expbits = 0; /* Bits to be expanded */ + + for (i=0; i<height; i++) { + lpix = (uint16 *)pix; + lbits = bits; + for (j = width; j > 0; j -= 4) { + expbits = (*lbits >> 4) & 0x0f; + + if (j < 4) + break; + + switch (expbits) { + case 0: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 1: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 2: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 3: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 4: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 5: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 6: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 7: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 8: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 9: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 10: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 11: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 12: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 13: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 14: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 15: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + } + + expbits = *lbits & 0x0f; + + j -= 4; + if (j < 4) { + break; + } + + switch (expbits) { + case 0: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 1: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 2: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 3: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 4: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 5: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 6: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 7: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 8: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 9: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 10: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 11: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 12: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 13: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 14: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 15: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + } + lbits++; + } + + if (j > 0) { + *lpix++ = (expbits & 0x08) ? fg : bg; + j--; + if (j > 0) { + *lpix++ = (expbits & 0x04) ? fg : bg; + j--; + if (j > 0) { + *lpix++ = (expbits & 0x02) ? fg : bg; + j--; + } + } + } + + pix += pix_increment; + bits += bits_increment; + } + return; +} + + + +/* + *---------------------------------------------------------------------- + * + * RasterBitsToPixels24 -- + * + * Convert a bitmap to a pixmap, converting 1 bits to the foreground + * color (fg) and 0 bits to the background color (bg), for a 24-bit + * pixmap + * + * Results: + * Pixmap filled with pixels + * + * Side effects: + * None + * + *---------------------------------------------------------------------- + */ + +void +RasterBitsToPixels24(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, + uint32 width, uint32 height, uint32 fg, uint32 bg) +{ + uint8 *lpix, *lbits; + uint32 fgColor1, fgColor2, fgColor3; + uint32 bgColor1, bgColor2, bgColor3; + + int i, j; + uint32 expbits = 0; /* Bits to be expanded */ + + fgColor1 = fg & 0x000000ff; + fgColor2 = (fg >> 8) & 0x000000ff; + fgColor3 = (fg >> 16) & 0x000000ff; + + bgColor1 = bg & 0x000000ff; + bgColor2 = (bg >> 8) & 0x000000ff; + bgColor3 = (bg >> 16) & 0x000000ff; + + for (i=0; i<height; i++) { + lpix = pix; + lbits = bits; + for (j = width; j > 0; j -= 4) { + expbits = (*lbits >> 4) & 0x0f; + + if (j < 4) + break; + + switch (expbits) { + case 0: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 1: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 2: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 3: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 4: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 5: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 6: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 7: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 8: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 9: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 10: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 11: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 12: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 13: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 14: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 15: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + } + + expbits = *lbits & 0x0f; + + j -= 4; + if (j < 4) { + break; + } + + switch (expbits) { + case 0: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 1: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 2: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 3: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 4: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 5: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 6: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 7: + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 8: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 9: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 10: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 11: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 12: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 13: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + case 14: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = bgColor1; + *lpix++ = bgColor2; + *lpix++ = bgColor3; + break; + case 15: + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + *lpix++ = fgColor1; + *lpix++ = fgColor2; + *lpix++ = fgColor3; + break; + } + lbits++; + } + + if (j > 0) { + *lpix++ = (expbits & 0x08) ? fgColor1 : bgColor1; + *lpix++ = (expbits & 0x08) ? fgColor2 : bgColor2; + *lpix++ = (expbits & 0x08) ? fgColor3 : bgColor3; + j--; + if (j > 0) { + *lpix++ = (expbits & 0x04) ? fgColor1 : bgColor1; + *lpix++ = (expbits & 0x04) ? fgColor2 : bgColor2; + *lpix++ = (expbits & 0x04) ? fgColor3 : bgColor3; + j--; + if (j > 0) { + *lpix++ = (expbits & 0x02) ? fgColor1 : bgColor1; + *lpix++ = (expbits & 0x02) ? fgColor2 : bgColor2; + *lpix++ = (expbits & 0x02) ? fgColor3 : bgColor3; + j--; + } + } + } + + pix += pix_increment; + bits += bits_increment; + } + return; +} + + + +/* + *---------------------------------------------------------------------- + * + * RasterBitsToPixels32 -- + * + * Convert a bitmap to a pixmap, converting 1 bits to the foreground + * color (fg) and 0 bits to the background color (bg), for a 32-bit + * pixmap + * + * Results: + * Pixmap filled with pixels + * + * Side effects: + * None + * + *---------------------------------------------------------------------- + */ + +void +RasterBitsToPixels32(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, + uint32 width, uint32 height, uint32 fg, uint32 bg) +{ + uint32 *lpix; + uint8 *lbits; + int i, j; + uint32 expbits = 0; /* Bits to be expanded */ + + for (i=0; i<height; i++) { + lpix = (uint32 *)pix; + lbits = bits; + for (j = width; j > 0; j -= 4) { + expbits = (*lbits >> 4) & 0x0f; + + if (j < 4) + break; + + switch (expbits) { + case 0: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 1: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 2: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 3: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 4: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 5: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 6: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 7: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 8: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 9: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 10: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 11: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 12: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 13: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 14: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 15: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + } + + expbits = *lbits & 0x0f; + + j -= 4; + if (j < 4) { + break; + } + + switch (expbits) { + case 0: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 1: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 2: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 3: + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 4: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 5: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 6: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 7: + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 8: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 9: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 10: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 11: + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + *lpix++ = fg; + break; + case 12: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = bg; + break; + case 13: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + *lpix++ = fg; + break; + case 14: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = bg; + break; + case 15: + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + *lpix++ = fg; + break; + } + lbits++; + } + + if (j > 0) { + *lpix++ = (expbits & 0x08) ? fg : bg; + j--; + if (j > 0) { + *lpix++ = (expbits & 0x04) ? fg : bg; + j--; + if (j > 0) { + *lpix++ = (expbits & 0x02) ? fg : bg; + j--; + } + } + } + + pix += pix_increment; + bits += bits_increment; + } + return; +} diff --git a/driver/xf86-video-vmware/src/bits2pixels.h b/driver/xf86-video-vmware/src/bits2pixels.h new file mode 100644 index 000000000..585f6fc9d --- /dev/null +++ b/driver/xf86-video-vmware/src/bits2pixels.h @@ -0,0 +1,25 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/bits2pixels.h,v 1.2 2002/12/11 17:07:58 dawes Exp $ */ +/* ********************************************************** + * Copyright (C) 1999-2001 VMware, Inc. + * All Rights Reserved + * Id: bits2pixels.h,v 1.4 2001/01/26 23:32:15 yoel Exp $ + * **********************************************************/ + +/* + * bits2pixels.h -- + * + * Drawing emulation routines + */ + +#ifndef _BITS2PIXELS_H_ +#define _BITS2PIXELS_H_ + +#define INCLUDE_ALLOW_USERLEVEL +#include "includeCheck.h" + +void +vmwareRaster_BitsToPixels(uint8 *bits, uint32 bits_increment, + uint8 *pix, uint32 pix_increment, int bytes_per_pixel, + uint32 width, uint32 height, uint32 fg, uint32 bg); + +#endif /* _BITS4PIXELS_H_ */ diff --git a/driver/xf86-video-vmware/src/guest_os.h b/driver/xf86-video-vmware/src/guest_os.h new file mode 100644 index 000000000..dedebe040 --- /dev/null +++ b/driver/xf86-video-vmware/src/guest_os.h @@ -0,0 +1,30 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/guest_os.h,v 1.1 2001/04/05 19:29:44 dawes Exp $ */ +/* ********************************************************* + * Copyright (C) 1999-2001 VMware, Inc. + * All Rights Reserved + * Id: guest_os.h,v 1.5 2001/01/26 23:32:15 yoel Exp $ + * **********************************************************/ + +#ifndef _GUEST_OS_H_ +#define _GUEST_OS_H_ + +#define INCLUDE_ALLOW_USERLEVEL +#include "includeCheck.h" + +#define GUEST_OS_BASE 0x5000 + +#define GUEST_OS_DOS (GUEST_OS_BASE+1) +#define GUEST_OS_WIN31 (GUEST_OS_BASE+2) +#define GUEST_OS_WINDOWS95 (GUEST_OS_BASE+3) +#define GUEST_OS_WINDOWS98 (GUEST_OS_BASE+4) +#define GUEST_OS_WINDOWSME (GUEST_OS_BASE+5) +#define GUEST_OS_NT (GUEST_OS_BASE+6) +#define GUEST_OS_WIN2000 (GUEST_OS_BASE+7) +#define GUEST_OS_LINUX (GUEST_OS_BASE+8) +#define GUEST_OS_OS2 (GUEST_OS_BASE+9) +#define GUEST_OS_OTHER (GUEST_OS_BASE+10) +#define GUEST_OS_FREEBSD (GUEST_OS_BASE+11) +#define GUEST_OS_WHISTLER (GUEST_OS_BASE+12) + + +#endif diff --git a/driver/xf86-video-vmware/src/includeCheck.h b/driver/xf86-video-vmware/src/includeCheck.h new file mode 100644 index 000000000..8df466635 --- /dev/null +++ b/driver/xf86-video-vmware/src/includeCheck.h @@ -0,0 +1,3 @@ +/* This space intentionally left blank. */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/includeCheck.h,v 1.3 2002/10/16 22:12:53 alanh Exp $ */ + diff --git a/driver/xf86-video-vmware/src/offscreen_manager.c b/driver/xf86-video-vmware/src/offscreen_manager.c new file mode 100644 index 000000000..10e2e59b4 --- /dev/null +++ b/driver/xf86-video-vmware/src/offscreen_manager.c @@ -0,0 +1,136 @@ +/* ********************************************************** + * Copyright (C) 1998-2002 VMware, Inc. + * All Rights Reserved + * **********************************************************/ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/offscreen_manager.c,v 1.1 2002/12/10 04:17:19 dawes Exp $ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "vmware.h" + +struct _Heap { + CARD8* ptr; + CARD32 size; + CARD32 maxSlots; + CARD32 startOffset; + SVGASurface* frontBuffer; + SVGASurface* slotsStart; + Bool clear; +}; + +static SVGASurface* FillInSurface(Heap* heap, SVGASurface* surface, + CARD32 width, CARD32 height, + CARD32 bpp, CARD32 pitch, CARD32 size, + CARD32 sizeUsed); + +Heap* +vmwareHeap_Create(CARD8* ptr, CARD32 size, CARD32 maxSlots, CARD32 startOffset, + CARD32 sWidth, CARD32 sHeight, CARD32 sBPP, CARD32 sPitch, + CARD32 sFbOffset) +{ + Heap* newHeap = malloc(sizeof (Heap)); + + newHeap->ptr = ptr; + newHeap->size = size - sizeof(SVGASurface); /* leave room for frontbuffer */ + newHeap->maxSlots = maxSlots; + newHeap->startOffset = startOffset; + + newHeap->frontBuffer = FillInSurface(newHeap, + (SVGASurface*)(ptr + newHeap->size), + sWidth, sHeight, sBPP, sPitch, + sHeight * sPitch, 0); + newHeap->frontBuffer->dataOffset = sFbOffset; + newHeap->frontBuffer->numQueued = newHeap->frontBuffer->numDequeued = 0; + + newHeap->slotsStart = (SVGASurface*)(newHeap->ptr + newHeap->size) - + newHeap->maxSlots; + newHeap->clear = FALSE; + vmwareHeap_Clear(newHeap); + + return newHeap; +} + +void +vmwareHeap_Destroy(Heap* heap) +{ + free(heap); +} + +void +vmwareHeap_Clear(Heap* heap) +{ + if (!heap->clear) { + memset(heap->slotsStart, 0, heap->maxSlots * sizeof (SVGASurface)); + heap->clear = TRUE; + } +} + +static SVGASurface* +FillInSurface(Heap* heap, SVGASurface* surface, CARD32 width, CARD32 height, + CARD32 bpp, CARD32 pitch, CARD32 size, CARD32 offset) +{ + surface->size = sizeof (SVGASurface); + surface->version = SVGA_SURFACE_VERSION_1; + surface->bpp = bpp; + surface->width = width; + surface->height = height; + surface->pitch = pitch; + if (surface->userData == 0) { + /* + * We allocate exactly what we need the first time we use a slot, so + * all reuses of this slot will be equal or smaller. + */ + surface->userData = size; + } + surface->dataOffset = offset + heap->startOffset; + + return surface; +} + +SVGASurface* +vmwareHeap_GetFrontBuffer(Heap* heap) +{ + return heap->frontBuffer; +} + +SVGASurface* +vmwareHeap_AllocSurface(Heap* heap, CARD32 width, CARD32 height, + CARD32 pitch, CARD32 bpp) +{ + CARD32 size = pitch * height; + CARD32 sizeUsed = 0; + SVGASurface* surface = heap->slotsStart; + int i; + + /* + * NOTE: we use SVGASurface::userData to store the largest this slot's + * size has ever been, since we don't ever compact anything. + */ + + /* find a free slot that's big enough */ + for (i = 0; i < heap->maxSlots; i++) { + if (surface[i].userData == 0) { /* this surface has never been used */ + if ((CARD8*)heap->slotsStart - heap->ptr - sizeUsed < size) { + /* no room left for data*/ + return NULL; + } + + heap->clear = FALSE; + return FillInSurface(heap, surface + i, width, height, bpp, + pitch, size, sizeUsed); + } + + if (surface[i].numQueued == surface[i].numDequeued && + surface[i].userData >= size) { /* free and big enough, sweet! */ + heap->clear = FALSE; + return FillInSurface(heap, surface + i, width, height, bpp, + pitch, size, sizeUsed); + } + + sizeUsed += surface[i].userData; + } + + return NULL; +} diff --git a/driver/xf86-video-vmware/src/offscreen_manager.h b/driver/xf86-video-vmware/src/offscreen_manager.h new file mode 100644 index 000000000..e948da9d2 --- /dev/null +++ b/driver/xf86-video-vmware/src/offscreen_manager.h @@ -0,0 +1,25 @@ +/* ********************************************************** + * Copyright (C) 1998-2002 VMware, Inc. + * All Rights Reserved + * **********************************************************/ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/offscreen_manager.h,v 1.2 2002/12/11 17:07:58 dawes Exp $ */ + +#ifndef OFFSCREEN_MANAGER_H +#define OFFSCREEN_MANAGER_H + +struct _Heap; +typedef struct _Heap Heap; + +extern Heap* vmwareHeap_Create(CARD8* ptr, CARD32 size, CARD32 maxSlots, + CARD32 startOffset, CARD32 sWidth, CARD32 sHeight, + CARD32 sBPP, CARD32 sPitch, CARD32 sFbOffset); +extern void vmwareHeap_Destroy(Heap* heap); + +extern void vmwareHeap_Clear(Heap* heap); + +extern SVGASurface* vmwareHeap_GetFrontBuffer(Heap* heap); + +extern SVGASurface* vmwareHeap_AllocSurface(Heap* heap, CARD32 width, CARD32 height, + CARD32 pitch, CARD32 bpp); + +#endif diff --git a/driver/xf86-video-vmware/src/svga_limits.h b/driver/xf86-video-vmware/src/svga_limits.h new file mode 100644 index 000000000..dbc8cf95b --- /dev/null +++ b/driver/xf86-video-vmware/src/svga_limits.h @@ -0,0 +1,57 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/svga_limits.h,v 1.1 2001/04/05 19:29:44 dawes Exp $ */ +/* ********************************************************** + * Copyright (C) 1998-2001 VMware, Inc. + * All Rights Reserved + * $Id: svga_limits.h,v 1.1 2006/11/26 20:21:18 matthieu Exp $ + * **********************************************************/ + +/* + * svga_limits.h -- + * + * SVGA limits + */ + +#ifndef _SVGA_LIMITS_H_ +#define _SVGA_LIMITS_H_ + +#define INCLUDE_ALLOW_USERLEVEL +#define INCLUDE_ALLOW_MONITOR +#include "includeCheck.h" + +/* + * Location and size of SVGA frame buffer and the FIFO. + */ +#define SVGA_VRAM_SIZE (16*1024*1024) +#define SVGA_MEM_SIZE (256*1024) + +/* + * SVGA_FB_START is the default starting address of the SVGA frame + * buffer in the guest's physical address space. + * SVGA_FB_START_BIGMEM is the starting address of the SVGA frame + * buffer for VMs that have a large amount of physical memory. + * + * The address of SVGA_FB_START is set to 2GB - (SVGA_FB_MAX_SIZE + SVGA_MEM_SIZE), + * thus the SVGA frame buffer sits at [SVGA_FB_START .. 2GB-1] in the + * physical address space. Our older SVGA drivers for NT treat the + * address of the frame buffer as a signed integer. For backwards + * compatibility, we keep the default location of the frame buffer + * at under 2GB in the address space. This restricts VMs to have "only" + * up to ~2031MB (i.e., up to SVGA_FB_START) of physical memory. + * + * For VMs that want more memory than the ~2031MB, we place the SVGA + * frame buffer at SVGA_FB_START_BIGMEM. This allows VMs to have up + * to 3584MB, at least as far as the SVGA frame buffer is concerned + * (note that there may be other issues that limit the VM memory + * size). PCI devices use high memory addresses, so we have to put + * SVGA_FB_START_BIGMEM low enough so that it doesn't overlap with any + * of these devices. Placing SVGA_FB_START_BIGMEM at 0xE0000000 + * should leave plenty of room for the PCI devices. + * + * NOTE: All of that is only true for the 0710 chipset. As of the 0405 + * chipset, the framebuffer start is determined solely based on the value + * the guest BIOS or OS programs into the PCI base address registers. + */ +#define SVGA_FB_LEGACY_START 0x7EFC0000 +#define SVGA_FB_LEGACY_START_BIGMEM 0xE0000000 + +#endif diff --git a/driver/xf86-video-vmware/src/svga_reg.h b/driver/xf86-video-vmware/src/svga_reg.h new file mode 100644 index 000000000..4f35780d8 --- /dev/null +++ b/driver/xf86-video-vmware/src/svga_reg.h @@ -0,0 +1,523 @@ +/* ********************************************************** + * Copyright (C) 1998-2001 VMware, Inc. + * All Rights Reserved + * $Id: svga_reg.h,v 1.1 2006/11/26 20:21:17 matthieu Exp $ + * **********************************************************/ + +/* + * svga_reg.h -- + * + * SVGA hardware definitions + */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/svga_reg.h,v 1.7 2002/12/10 04:17:19 dawes Exp $ */ + +#ifndef _SVGA_REG_H_ +#define _SVGA_REG_H_ + +#define INCLUDE_ALLOW_USERLEVEL +#define INCLUDE_ALLOW_VMMEXT +#include "includeCheck.h" + +/* + * Memory and port addresses and fundamental constants + */ + +/* + * Note-- MAX_WIDTH and MAX_HEIGHT are largely ignored by the code. This + * isn't such a bad thing for forward compatibility. --Jeremy. + */ +#define SVGA_MAX_WIDTH 2360 +#define SVGA_MAX_HEIGHT 1770 +#define SVGA_MAX_BITS_PER_PIXEL 32 +#define SVGA_MAX_DEPTH 24 + +#define SVGA_FB_MAX_SIZE \ + ((((SVGA_MAX_WIDTH * SVGA_MAX_HEIGHT * \ + SVGA_MAX_BITS_PER_PIXEL / 8) >> PAGE_SHIFT) + 1) << PAGE_SHIFT) + +#define SVGA_MAX_PSEUDOCOLOR_DEPTH 8 +#define SVGA_MAX_PSEUDOCOLORS (1 << SVGA_MAX_PSEUDOCOLOR_DEPTH) +#define SVGA_NUM_PALETTE_REGS (3 * SVGA_MAX_PSEUDOCOLORS) + +#define SVGA_MAGIC 0x900000UL +#define SVGA_MAKE_ID(ver) (SVGA_MAGIC << 8 | (ver)) + +/* Version 2 let the address of the frame buffer be unsigned on Win32 */ +#define SVGA_VERSION_2 2 +#define SVGA_ID_2 SVGA_MAKE_ID(SVGA_VERSION_2) + +/* Version 1 has new registers starting with SVGA_REG_CAPABILITIES so + PALETTE_BASE has moved */ +#define SVGA_VERSION_1 1 +#define SVGA_ID_1 SVGA_MAKE_ID(SVGA_VERSION_1) + +/* Version 0 is the initial version */ +#define SVGA_VERSION_0 0 +#define SVGA_ID_0 SVGA_MAKE_ID(SVGA_VERSION_0) + +/* Invalid SVGA_ID_ */ +#define SVGA_ID_INVALID 0xFFFFFFFF + +/* More backwards compatibility, old location of color map: */ +#define SVGA_OLD_PALETTE_BASE 17 + +/* Base and Offset gets us headed the right way for PCI Base Addr Registers */ +#define SVGA_LEGACY_BASE_PORT 0x4560 +#define SVGA_INDEX_PORT 0x0 +#define SVGA_VALUE_PORT 0x1 +#define SVGA_BIOS_PORT 0x2 +#define SVGA_NUM_PORTS 0x3 + +/* This port is deprecated, but retained because of old drivers. */ +#define SVGA_LEGACY_ACCEL_PORT 0x3 + +/* Legal values for the SVGA_REG_CURSOR_ON register in cursor bypass mode */ +#define SVGA_CURSOR_ON_HIDE 0x0 /* Must be 0 to maintain backward compatibility */ +#define SVGA_CURSOR_ON_SHOW 0x1 /* Must be 1 to maintain backward compatibility */ +#define SVGA_CURSOR_ON_REMOVE_FROM_FB 0x2 /* Remove the cursor from the framebuffer because we need to see what's under it */ +#define SVGA_CURSOR_ON_RESTORE_TO_FB 0x3 /* Put the cursor back in the framebuffer so the user can see it */ + +/* + * Registers + */ + +enum { + SVGA_REG_ID = 0, + SVGA_REG_ENABLE = 1, + SVGA_REG_WIDTH = 2, + SVGA_REG_HEIGHT = 3, + SVGA_REG_MAX_WIDTH = 4, + SVGA_REG_MAX_HEIGHT = 5, + SVGA_REG_DEPTH = 6, + SVGA_REG_BITS_PER_PIXEL = 7, /* Current bpp in the guest */ + SVGA_REG_PSEUDOCOLOR = 8, + SVGA_REG_RED_MASK = 9, + SVGA_REG_GREEN_MASK = 10, + SVGA_REG_BLUE_MASK = 11, + SVGA_REG_BYTES_PER_LINE = 12, + SVGA_REG_FB_START = 13, + SVGA_REG_FB_OFFSET = 14, + SVGA_REG_VRAM_SIZE = 15, + SVGA_REG_FB_SIZE = 16, + + /* ID 0 implementation only had the above registers, then the palette */ + + SVGA_REG_CAPABILITIES = 17, + SVGA_REG_MEM_START = 18, /* Memory for command FIFO and bitmaps */ + SVGA_REG_MEM_SIZE = 19, + SVGA_REG_CONFIG_DONE = 20, /* Set when memory area configured */ + SVGA_REG_SYNC = 21, /* Write to force synchronization */ + SVGA_REG_BUSY = 22, /* Read to check if sync is done */ + SVGA_REG_GUEST_ID = 23, /* Set guest OS identifier */ + SVGA_REG_CURSOR_ID = 24, /* ID of cursor */ + SVGA_REG_CURSOR_X = 25, /* Set cursor X position */ + SVGA_REG_CURSOR_Y = 26, /* Set cursor Y position */ + SVGA_REG_CURSOR_ON = 27, /* Turn cursor on/off */ + SVGA_REG_HOST_BITS_PER_PIXEL = 28, /* Current bpp in the host */ + SVGA_REG_SCRATCH_SIZE = 29, /* Number of scratch registers */ + SVGA_REG_MEM_REGS = 30, /* Number of FIFO registers */ + SVGA_REG_NUM_DISPLAYS = 31, /* Number of guest displays */ + SVGA_REG_PITCHLOCK = 32, /* Fixed pitch for all modes */ + SVGA_REG_TOP = 33, /* Must be 1 more than the last register */ + + SVGA_PALETTE_BASE = 1024, /* Base of SVGA color map */ + /* Next 768 (== 256*3) registers exist for colormap */ + SVGA_SCRATCH_BASE = SVGA_PALETTE_BASE + SVGA_NUM_PALETTE_REGS + /* Base of scratch registers */ + /* Next reg[SVGA_REG_SCRATCH_SIZE] registers exist for scratch usage: + First 4 are reserved for VESA BIOS Extension; any remaining are for + the use of the current SVGA driver. */ +}; + + +/* + * Capabilities + */ + +#define SVGA_CAP_NONE 0x00000 +#define SVGA_CAP_RECT_FILL 0x00001 +#define SVGA_CAP_RECT_COPY 0x00002 +#define SVGA_CAP_RECT_PAT_FILL 0x00004 +#define SVGA_CAP_LEGACY_OFFSCREEN 0x00008 +#define SVGA_CAP_RASTER_OP 0x00010 +#define SVGA_CAP_CURSOR 0x00020 +#define SVGA_CAP_CURSOR_BYPASS 0x00040 +#define SVGA_CAP_CURSOR_BYPASS_2 0x00080 +#define SVGA_CAP_8BIT_EMULATION 0x00100 +#define SVGA_CAP_ALPHA_CURSOR 0x00200 +#define SVGA_CAP_GLYPH 0x00400 +#define SVGA_CAP_GLYPH_CLIPPING 0x00800 +#define SVGA_CAP_OFFSCREEN_1 0x01000 +#define SVGA_CAP_ALPHA_BLEND 0x02000 +#define SVGA_CAP_3D 0x04000 +#define SVGA_CAP_EXTENDED_FIFO 0x08000 +#define SVGA_CAP_MULTIMON 0x10000 +#define SVGA_CAP_PITCHLOCK 0x20000 + +/* + * Raster op codes (same encoding as X) used by FIFO drivers. + */ + +#define SVGA_ROP_CLEAR 0x00 /* 0 */ +#define SVGA_ROP_AND 0x01 /* src AND dst */ +#define SVGA_ROP_AND_REVERSE 0x02 /* src AND NOT dst */ +#define SVGA_ROP_COPY 0x03 /* src */ +#define SVGA_ROP_AND_INVERTED 0x04 /* NOT src AND dst */ +#define SVGA_ROP_NOOP 0x05 /* dst */ +#define SVGA_ROP_XOR 0x06 /* src XOR dst */ +#define SVGA_ROP_OR 0x07 /* src OR dst */ +#define SVGA_ROP_NOR 0x08 /* NOT src AND NOT dst */ +#define SVGA_ROP_EQUIV 0x09 /* NOT src XOR dst */ +#define SVGA_ROP_INVERT 0x0a /* NOT dst */ +#define SVGA_ROP_OR_REVERSE 0x0b /* src OR NOT dst */ +#define SVGA_ROP_COPY_INVERTED 0x0c /* NOT src */ +#define SVGA_ROP_OR_INVERTED 0x0d /* NOT src OR dst */ +#define SVGA_ROP_NAND 0x0e /* NOT src OR NOT dst */ +#define SVGA_ROP_SET 0x0f /* 1 */ +#define SVGA_ROP_UNSUPPORTED 0x10 + +#define SVGA_NUM_SUPPORTED_ROPS 16 +#define SVGA_ROP_ALL (MASK(SVGA_NUM_SUPPORTED_ROPS)) +#define SVGA_IS_VALID_ROP(rop) (rop < SVGA_NUM_SUPPORTED_ROPS) + +/* + * Ops + * For each pixel, the four channels of the image are computed with: + * + * C = Ca * Fa + Cb * Fb + * + * where C, Ca, Cb are the values of the respective channels and Fa + * and Fb come from the following table: + * + * BlendOp Fa Fb + * ------------------------------------------ + * Clear 0 0 + * Src 1 0 + * Dst 0 1 + * Over 1 1-Aa + * OverReverse 1-Ab 1 + * In Ab 0 + * InReverse 0 Aa + * Out 1-Ab 0 + * OutReverse 0 1-Aa + * Atop Ab 1-Aa + * AtopReverse 1-Ab Aa + * Xor 1-Ab 1-Aa + * Add 1 1 + * Saturate min(1,(1-Ab)/Aa) 1 + * + * Flags + * You can use the following flags to achieve additional affects: + * + * Flag Effect + * ------------------------------------------ + * ConstantSourceAlpha Ca = Ca * Param0 + * ConstantDestAlpha Cb = Cb * Param1 + * + * Flag effects resolve before the op. For example + * BlendOp == Add && Flags == ConstantSourceAlpha | + * ConstantDestAlpha results in: + * + * C = (Ca * Param0) + (Cb * Param1) + */ + +#define SVGA_BLENDOP_CLEAR 0 +#define SVGA_BLENDOP_SRC 1 +#define SVGA_BLENDOP_DST 2 +#define SVGA_BLENDOP_OVER 3 +#define SVGA_BLENDOP_OVER_REVERSE 4 +#define SVGA_BLENDOP_IN 5 +#define SVGA_BLENDOP_IN_REVERSE 6 +#define SVGA_BLENDOP_OUT 7 +#define SVGA_BLENDOP_OUT_REVERSE 8 +#define SVGA_BLENDOP_ATOP 9 +#define SVGA_BLENDOP_ATOP_REVERSE 10 +#define SVGA_BLENDOP_XOR 11 +#define SVGA_BLENDOP_ADD 12 +#define SVGA_BLENDOP_SATURATE 13 + +#define SVGA_NUM_BLENDOPS 14 +#define SVGA_IS_VALID_BLENDOP(op) (op >= 0 && op < SVGA_NUM_BLENDOPS) + +#define SVGA_BLENDFLAG_CONSTANT_SOURCE_ALPHA 0x01 +#define SVGA_BLENDFLAG_CONSTANT_DEST_ALPHA 0x02 +#define SVGA_NUM_BLENDFLAGS 2 +#define SVGA_BLENDFLAG_ALL (MASK(SVGA_NUM_BLENDFLAGS)) +#define SVGA_IS_VALID_BLENDFLAG(flag) ((flag & ~SVGA_BLENDFLAG_ALL) == 0) + + +/* + * FIFO offsets (viewed as an array of 32-bit words) + */ + +enum { + /* + * The original defined FIFO offsets + */ + + SVGA_FIFO_MIN = 0, + SVGA_FIFO_MAX, /* The distance from MIN to MAX must be at least 10K */ + SVGA_FIFO_NEXT_CMD, + SVGA_FIFO_STOP, + + /* + * Additional offsets added as of SVGA_CAP_EXTENDED_FIFO + */ + + SVGA_FIFO_CAPABILITIES = 4, + SVGA_FIFO_FLAGS, + SVGA_FIFO_FENCE, + SVGA_FIFO_3D_HWVERSION, /* Check SVGA3dHardwareVersion in svga3d_reg.h */ + SVGA_FIFO_PITCHLOCK, + + /* + * Always keep this last. It's not an offset with semantic value, but + * rather a convenient way to produce the value of fifo[SVGA_FIFO_NUM_REGS] + */ + + SVGA_FIFO_NUM_REGS +}; + +/* + * FIFO Capabilities + * + * Fence -- Fence register and command are supported + * Accel Front -- Front buffer only commands are supported + * Pitch Lock -- Pitch lock register is supported + */ + +#define SVGA_FIFO_CAP_NONE 0 +#define SVGA_FIFO_CAP_FENCE (1<<0) +#define SVGA_FIFO_CAP_ACCELFRONT (1<<1) +#define SVGA_FIFO_CAP_PITCHLOCK (1<<2) + + +/* + * FIFO Flags + * + * Accel Front -- Driver should use front buffer only commands + */ + +#define SVGA_FIFO_FLAG_NONE 0 +#define SVGA_FIFO_FLAG_ACCELFRONT (1<<0) + + +/* + * Drawing object ID's, in the range 0 to SVGA_MAX_ID + */ + +#define SVGA_MAX_ID 499 + +/* + * Macros to compute variable length items (sizes in 32-bit words, except + * for SVGA_GLYPH_SCANLINE_SIZE, which is in bytes). + */ + +#define SVGA_BITMAP_SIZE(w,h) ((((w)+31) >> 5) * (h)) +#define SVGA_BITMAP_SCANLINE_SIZE(w) (( (w)+31 ) >> 5) +#define SVGA_PIXMAP_SIZE(w,h,bpp) ((( ((w)*(bpp))+31 ) >> 5) * (h)) +#define SVGA_PIXMAP_SCANLINE_SIZE(w,bpp) (( ((w)*(bpp))+31 ) >> 5) +#define SVGA_GLYPH_SIZE(w,h) ((((((w) + 7) >> 3) * (h)) + 3) >> 2) +#define SVGA_GLYPH_SCANLINE_SIZE(w) (((w) + 7) >> 3) + +/* + * Increment from one scanline to the next of a bitmap or pixmap + */ +#define SVGA_BITMAP_INCREMENT(w) ((( (w)+31 ) >> 5) * sizeof (uint32)) +#define SVGA_PIXMAP_INCREMENT(w,bpp) ((( ((w)*(bpp))+31 ) >> 5) * sizeof (uint32)) + +/* + * Transparent color for DRAW_GLYPH_CLIPPED + */ +#define SVGA_COLOR_TRANSPARENT (~0) + +/* + * Commands in the command FIFO + */ + +#define SVGA_CMD_INVALID_CMD 0 + /* FIFO layout: + <nothing> (well, undefined) */ + +#define SVGA_CMD_UPDATE 1 + /* FIFO layout: + X, Y, Width, Height */ + +#define SVGA_CMD_RECT_FILL 2 + /* FIFO layout: + Color, X, Y, Width, Height */ + +#define SVGA_CMD_RECT_COPY 3 + /* FIFO layout: + Source X, Source Y, Dest X, Dest Y, Width, Height */ + +#define SVGA_CMD_DEFINE_BITMAP 4 + /* FIFO layout: + Pixmap ID, Width, Height, <scanlines> */ + +#define SVGA_CMD_DEFINE_BITMAP_SCANLINE 5 + /* FIFO layout: + Pixmap ID, Width, Height, Line #, scanline */ + +#define SVGA_CMD_DEFINE_PIXMAP 6 + /* FIFO layout: + Pixmap ID, Width, Height, Depth, <scanlines> */ + +#define SVGA_CMD_DEFINE_PIXMAP_SCANLINE 7 + /* FIFO layout: + Pixmap ID, Width, Height, Depth, Line #, scanline */ + +#define SVGA_CMD_RECT_BITMAP_FILL 8 + /* FIFO layout: + Bitmap ID, X, Y, Width, Height, Foreground, Background */ + +#define SVGA_CMD_RECT_PIXMAP_FILL 9 + /* FIFO layout: + Pixmap ID, X, Y, Width, Height */ + +#define SVGA_CMD_RECT_BITMAP_COPY 10 + /* FIFO layout: + Bitmap ID, Source X, Source Y, Dest X, Dest Y, + Width, Height, Foreground, Background */ + +#define SVGA_CMD_RECT_PIXMAP_COPY 11 + /* FIFO layout: + Pixmap ID, Source X, Source Y, Dest X, Dest Y, Width, Height */ + +#define SVGA_CMD_FREE_OBJECT 12 + /* FIFO layout: + Object (pixmap, bitmap, ...) ID */ + +#define SVGA_CMD_RECT_ROP_FILL 13 + /* FIFO layout: + Color, X, Y, Width, Height, ROP */ + +#define SVGA_CMD_RECT_ROP_COPY 14 + /* FIFO layout: + Source X, Source Y, Dest X, Dest Y, Width, Height, ROP */ + +#define SVGA_CMD_RECT_ROP_BITMAP_FILL 15 + /* FIFO layout: + ID, X, Y, Width, Height, Foreground, Background, ROP */ + +#define SVGA_CMD_RECT_ROP_PIXMAP_FILL 16 + /* FIFO layout: + ID, X, Y, Width, Height, ROP */ + +#define SVGA_CMD_RECT_ROP_BITMAP_COPY 17 + /* FIFO layout: + ID, Source X, Source Y, + Dest X, Dest Y, Width, Height, Foreground, Background, ROP */ + +#define SVGA_CMD_RECT_ROP_PIXMAP_COPY 18 + /* FIFO layout: + ID, Source X, Source Y, Dest X, Dest Y, Width, Height, ROP */ + +#define SVGA_CMD_DEFINE_CURSOR 19 + /* FIFO layout: + ID, Hotspot X, Hotspot Y, Width, Height, + Depth for AND mask, Depth for XOR mask, + <scanlines for AND mask>, <scanlines for XOR mask> */ + +#define SVGA_CMD_DISPLAY_CURSOR 20 + /* FIFO layout: + ID, On/Off (1 or 0) */ + +#define SVGA_CMD_MOVE_CURSOR 21 + /* FIFO layout: + X, Y */ + +#define SVGA_CMD_DEFINE_ALPHA_CURSOR 22 + /* FIFO layout: + ID, Hotspot X, Hotspot Y, Width, Height, + <scanlines> */ + +#define SVGA_CMD_DRAW_GLYPH 23 + /* FIFO layout: + X, Y, W, H, FGCOLOR, <stencil buffer> */ + +#define SVGA_CMD_DRAW_GLYPH_CLIPPED 24 + /* FIFO layout: + X, Y, W, H, FGCOLOR, BGCOLOR, <cliprect>, <stencil buffer> + Transparent color expands are done by setting BGCOLOR to ~0 */ + +#define SVGA_CMD_UPDATE_VERBOSE 25 + /* FIFO layout: + X, Y, Width, Height, Reason */ + +#define SVGA_CMD_SURFACE_FILL 26 + /* FIFO layout: + color, dstSurfaceOffset, x, y, w, h, rop */ + +#define SVGA_CMD_SURFACE_COPY 27 + /* FIFO layout: + srcSurfaceOffset, dstSurfaceOffset, srcX, srcY, + destX, destY, w, h, rop */ + +#define SVGA_CMD_SURFACE_ALPHA_BLEND 28 + /* FIFO layout: + srcSurfaceOffset, dstSurfaceOffset, srcX, srcY, + destX, destY, w, h, op (SVGA_BLENDOP*), flags (SVGA_BLENDFLAGS*), + param1, param2 */ + +#define SVGA_CMD_FRONT_ROP_FILL 29 + /* FIFO layout: + Color, X, Y, Width, Height, ROP */ + +#define SVGA_CMD_FENCE 30 + /* FIFO layout: + Fence value */ + +#define SVGA_CMD_MAX 31 + +#define SVGA_CMD_MAX_ARGS 64 + +/* + * Location and size of SVGA frame buffer and the FIFO. + */ +#define SVGA_VRAM_MAX_SIZE (16 * 1024 * 1024) + +#define SVGA_VRAM_SIZE_WS (16 * 1024 * 1024) // 16 MB +#define SVGA_MEM_SIZE_WS (2 * 1024 * 1024) // 2 MB +#define SVGA_VRAM_SIZE_SERVER (4 * 1024 * 1024) // 4 MB +#define SVGA_MEM_SIZE_SERVER (256 * 1024) // 256 KB + +#if /* defined(VMX86_WGS) || */ defined(VMX86_SERVER) +#define SVGA_VRAM_SIZE SVGA_VRAM_SIZE_SERVER +#define SVGA_MEM_SIZE SVGA_MEM_SIZE_SERVER +#else +#define SVGA_VRAM_SIZE SVGA_VRAM_SIZE_WS +#define SVGA_MEM_SIZE SVGA_MEM_SIZE_WS +#endif + +/* + * SVGA_FB_START is the default starting address of the SVGA frame + * buffer in the guest's physical address space. + * SVGA_FB_START_BIGMEM is the starting address of the SVGA frame + * buffer for VMs that have a large amount of physical memory. + * + * The address of SVGA_FB_START is set to 2GB - (SVGA_FB_MAX_SIZE + SVGA_MEM_SIZE), + * thus the SVGA frame buffer sits at [SVGA_FB_START .. 2GB-1] in the + * physical address space. Our older SVGA drivers for NT treat the + * address of the frame buffer as a signed integer. For backwards + * compatibility, we keep the default location of the frame buffer + * at under 2GB in the address space. This restricts VMs to have "only" + * up to ~2031MB (i.e., up to SVGA_FB_START) of physical memory. + * + * For VMs that want more memory than the ~2031MB, we place the SVGA + * frame buffer at SVGA_FB_START_BIGMEM. This allows VMs to have up + * to 3584MB, at least as far as the SVGA frame buffer is concerned + * (note that there may be other issues that limit the VM memory + * size). PCI devices use high memory addresses, so we have to put + * SVGA_FB_START_BIGMEM low enough so that it doesn't overlap with any + * of these devices. Placing SVGA_FB_START_BIGMEM at 0xE0000000 + * should leave plenty of room for the PCI devices. + * + * NOTE: All of that is only true for the 0710 chipset. As of the 0405 + * chipset, the framebuffer start is determined solely based on the value + * the guest BIOS or OS programs into the PCI base address registers. + */ +#define SVGA_FB_LEGACY_START 0x7EFC0000 +#define SVGA_FB_LEGACY_START_BIGMEM 0xE0000000 + +#endif diff --git a/driver/xf86-video-vmware/src/svga_struct.h b/driver/xf86-video-vmware/src/svga_struct.h new file mode 100644 index 000000000..fe4f0bfc5 --- /dev/null +++ b/driver/xf86-video-vmware/src/svga_struct.h @@ -0,0 +1,40 @@ +/* ********************************************************** + * Copyright (C) 1998-2000 VMware, Inc. + * All Rights Reserved + * **********************************************************/ + +#ifndef _SVGA_STRUCT_H_ +#define _SVGA_STRUCT_H_ + +#define INCLUDE_ALLOW_USERLEVEL +#define INCLUDE_ALLOW_MONITOR +#include "includeCheck.h" + + /* + * Offscreen memory surface structure + * + */ + +enum SVGASurfaceVersion { + SVGA_SURFACE_VERSION_1 = 1 /* Initial version... */ +}; + +typedef struct _SVGASurface { + uint32 size; /* Size of the structure */ + uint32 version; /* Version of this surface structure. */ + uint32 bpp; /* Format of the surface */ + uint32 width; /* Width of the surface */ + uint32 height; /* Height of the surface */ + uint32 pitch; /* Pitch of the surface */ + volatile uint32 numQueued; /* Number of times this bitmap has been queued */ + volatile uint32 numDequeued; /* Number of times this bitmap has been dequeued */ + uint32 userData; /* Driver defined data */ + uint32 dataOffset; /* Offset to the data */ +} SVGASurface; + +typedef struct SVGAPoint { + int16 x; + int16 y; +} SVGAPoint; + +#endif diff --git a/driver/xf86-video-vmware/src/vm_basic_types.h b/driver/xf86-video-vmware/src/vm_basic_types.h new file mode 100644 index 000000000..673522f88 --- /dev/null +++ b/driver/xf86-video-vmware/src/vm_basic_types.h @@ -0,0 +1,173 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/vm_basic_types.h,v 1.5 2002/01/07 20:38:29 dawes Exp $ */ +/* ********************************************************** + * Copyright (C) 1998-2001 VMware, Inc. + * All Rights Reserved + * Id: vm_basic_types.h,v 1.9 2001/02/14 22:22:53 bennett Exp $ + * **********************************************************/ + +/* + * + * vm_basic_types.h -- + * + * basic data types. + */ + + +#ifndef _VM_BASIC_TYPES_H_ +#define _VM_BASIC_TYPES_H_ + +#define INCLUDE_ALLOW_USERLEVEL +#define INCLUDE_ALLOW_MONITOR +#define INCLUDE_ALLOW_MODULE +#define INCLUDE_ALLOW_VMKERNEL +#include "includeCheck.h" + +/* STRICT ANSI means the Xserver build and X defines Bool differently. */ +#if 0 +typedef char Bool; +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifdef _MSC_VER +typedef unsigned __int64 uint64; +typedef signed __int64 int64; + +#pragma warning (disable :4018) // signed/unsigned mismatch +#pragma warning (disable :4761) // integral size mismatch in argument; conversion supplied +#pragma warning (disable :4305) // truncation from 'const int' to 'short' +#pragma warning (disable :4244) // conversion from 'unsigned short' to 'unsigned char' +//#pragma warning (disable :4101) // unreferenced local variable +#pragma warning (disable :4133) // incompatible types - from 'struct VM *' to 'int *' +#pragma warning (disable :4047) // differs in levels of indirection +#pragma warning (disable :4146) // unary minus operator applied to unsigned type, result still unsigned +#pragma warning (disable :4142) // benign redefinition of type + +#elif defined(__GNUC__) +/* The Xserver source compiles with -ansi -pendantic */ +#ifndef __STRICT_ANSI__ +typedef unsigned long long uint64; +typedef long long int64; +#endif +#else +/* int64/uint64 aren't actually used in the vmware driver. */ +#if 0 +#error - Need compiler define for int64/uint64 +#endif +#endif + +typedef unsigned int uint32; +typedef unsigned short uint16; +typedef unsigned char uint8; + +typedef int int32; +typedef short int16; +typedef char int8; + + +/* + * Printf format for 64-bit number. Use it like this: + * printf("%"FMT64"d\n", big); + */ + +#ifdef _MSC_VER +#define FMT64 "I64" +#elif defined(__GNUC__) +#define FMT64 "L" +#else +/* FMT64 isn't actually used in the vmware driver. */ +#if 0 +#error - Need compiler define for FMT64 +#endif +#endif + +typedef uint32 VA; +typedef uint32 VPN; + +typedef uint32 PA; +typedef uint32 PPN; + +typedef uint32 MA; +typedef uint32 MPN; + +#define INVALID_MPN ((MPN)-1) + +#define EXTERN extern +/* + * Right now our use of CONST is broken enough that it only works + * with GCC. XXX Need to fix this. + */ +#ifdef __GNUC__ +#define CONST const +#else +#ifndef CONST +#define CONST +#endif +#endif + +#ifdef _MSC_VER +#ifndef INLINE +#define INLINE __inline +#endif +#else +#ifndef INLINE +#define INLINE inline +#endif +#endif + + +#if defined(WIN32) && !defined(VMX86_NO_THREADS) +#define THREADSPECIFIC _declspec(thread) +#else +#define THREADSPECIFIC +#endif + +/* + * Like "INLINE" but use this token to mark functions that are inline + * because they have only a single call site. In other words, if a second + * call site is introduced, the "INLINE_SINGLE_CALLER" token should be + * removed. + */ +#define INLINE_SINGLE_CALLER INLINE + +/* + * Attributes placed on function declarations to tell the compiler + * that the function never returns. + */ +#ifdef _MSC_VER +#define NORETURN_DECL(_fndecl) __declspec(noreturn) _fndecl +#elif defined(__GNUC__) && __GNUC__ >= 2 && __GNUC_MINOR__ >= 5 +#define NORETURN_DECL(_fndecl) _fndecl __attribute__((__noreturn__)) +#else +#define NORETURN_DECL(_fndecl) _fndecl +#endif + + +/* + * GCC's argument checking for printf-like functions + * This is conditional until we have replaced all `"%x", void *' + * with `"0x%08x", (uint32) void *'. Note that %p prints different things + * on different platforms. + * + * fmtPos is the position of the format string argument, beginning at 1 + * varPos is the position of the variable argument, beginning at 1 + */ +#if defined(__GNUC__) && defined(notdef) +# define PRINTF_DECL(fmtPos, varPos) __attribute__((__format__(__printf__, fmtPos, varPos))) +#else +# define PRINTF_DECL(fmtPos, varPos) +#endif + +/* + * Used to silence compiler warnings that get generated when the + * compiler thinks that a function returns when it is marked noreturn. + */ +#define INFINITE_LOOP() do { } while (1) + +#endif diff --git a/driver/xf86-video-vmware/src/vm_device_version.h b/driver/xf86-video-vmware/src/vm_device_version.h new file mode 100644 index 000000000..8f6dd3b87 --- /dev/null +++ b/driver/xf86-video-vmware/src/vm_device_version.h @@ -0,0 +1,64 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/vm_device_version.h,v 1.1 2001/04/05 19:29:44 dawes Exp $ */ +/* ********************************************************** + * Copyright (C) 1998-2001 VMware, Inc. + * All Rights Reserved + * Id: vm_device_version.h,v 1.2 2001/01/26 21:53:27 yoel Exp $ + * **********************************************************/ + + +#ifndef VM_DEVICE_VERSION_H +#define VM_DEVICE_VERSION_H + +#define INCLUDE_ALLOW_USERLEVEL +#define INCLUDE_ALLOW_MONITOR +#define INCLUDE_ALLOW_MODULE +#define INCLUDE_ALLOW_VMKERNEL +#include "includeCheck.h" + +#define PCI_VENDOR_ID_VMWARE 0x15AD +#define PCI_DEVICE_ID_VMWARE_SVGA2 0x0405 +#define PCI_DEVICE_ID_VMWARE_SVGA 0x0710 +#define PCI_DEVICE_ID_VMWARE_NET 0x0720 +#define PCI_DEVICE_ID_VMWARE_SCSI 0x0730 +#define PCI_DEVICE_ID_VMWARE_IDE 0x1729 + +/* From linux/pci.h. We emulate an AMD ethernet controller */ +#define PCI_VENDOR_ID_AMD 0x1022 +#define PCI_DEVICE_ID_AMD_VLANCE 0x2000 +#define PCI_VENDOR_ID_BUSLOGIC 0x104B +#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC 0x0140 +#define PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER 0x1040 + +/* Intel Values for the chipset */ +#define PCI_VENDOR_ID_INTEL 0x8086 +#define PCI_DEVICE_ID_INTEL_82439TX 0x7100 +#define PCI_DEVICE_ID_INTEL_82371AB_0 0x7110 +#define PCI_DEVICE_ID_INTEL_82371AB_3 0x7113 +#define PCI_DEVICE_ID_INTEL_82371AB 0x7111 +#define PCI_DEVICE_ID_INTEL_82443BX 0x7192 + + +/************* Strings for IDE Identity Fields **************************/ +#define VIDE_ID_SERIAL_STR "00000000000000000001" /* Must be 20 Bytes */ +#define VIDE_ID_FIRMWARE_STR "00000001" /* Must be 8 Bytes */ + +/* No longer than 40 Bytes and must be an even length. */ +#define VIDE_ATA_MODEL_STR PRODUCT_GENERIC_NAME " Virtual IDE Hard Drive " +#define VIDE_ATAPI_MODEL_STR PRODUCT_GENERIC_NAME " Virtual IDE CDROM Drive " + +#define ATAPI_VENDOR_ID "NECVMWar" /* Must be 8 Bytes */ +#define ATAPI_PRODUCT_ID PRODUCT_GENERIC_NAME " IDE CDROM" /* Must be 16 Bytes */ +#define ATAPI_REV_LEVEL "1.00" /* Must be 4 Bytes */ + + +/************* Strings for SCSI Identity Fields **************************/ +#define SCSI_DISK_MODEL_STR PRODUCT_GENERIC_NAME " Virtual SCSI Hard Drive" +#define SCSI_CDROM_MODEL_STR PRODUCT_GENERIC_NAME " Virtual SCSI CDROM Drive" + +/************* Strings for the VESA BIOS Identity Fields *****************/ +#define VBE_OEM_STRING COMPANY_NAME " SVGA" +#define VBE_VENDOR_NAME COMPANY_NAME +#define VBE_PRODUCT_NAME PRODUCT_GENERIC_NAME + + +#endif /* VM_DEVICE_VERSION_H */ diff --git a/driver/xf86-video-vmware/src/vmware.c b/driver/xf86-video-vmware/src/vmware.c new file mode 100644 index 000000000..2190c8a17 --- /dev/null +++ b/driver/xf86-video-vmware/src/vmware.c @@ -0,0 +1,1788 @@ +/* ********************************************************** + * Copyright (C) 1998-2001 VMware, Inc. + * All Rights Reserved + * **********************************************************/ +#ifdef VMX86_DEVEL +char rcsId_vmware[] = + "Id: vmware.c,v 1.11 2001/02/23 02:10:39 yoel Exp $"; +#endif +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/vmware.c,v 1.18 2003/09/24 02:43:31 dawes Exp $ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* + * TODO: support the vmware linux kernel fb driver (Option "UseFBDev"). + */ + +#include "xf86.h" +#include "xf86_OSproc.h" +#include "xf86Resources.h" + +#include "compiler.h" /* inb/outb */ + +#include "xf86PciInfo.h" /* pci vendor id */ +#include "xf86Pci.h" /* pci */ + +#include "mipointer.h" /* sw cursor */ +#include "mibstore.h" /* backing store */ +#include "micmap.h" /* mi color map */ +#include "vgaHW.h" /* VGA hardware */ +#include "fb.h" +#include "shadowfb.h" /* ShadowFB wrappers */ + +#include "xf86cmap.h" /* xf86HandleColormaps */ + +#include "vmware.h" +#include "guest_os.h" +#include "vm_device_version.h" + +#ifdef HaveDriverFuncs +#define VMWARE_DRIVER_FUNC HaveDriverFuncs +#else +#define VMWARE_DRIVER_FUNC 0 +#endif + +/* + * So that the file compiles unmodified when dropped in to a < 6.9 source tree. + */ +#ifndef _X_EXPORT +#define _X_EXPORT +#endif +/* + * So that the file compiles unmodified when dropped into an xfree source tree. + */ +#ifndef XORG_VERSION_CURRENT +#define XORG_VERSION_CURRENT XF86_VERSION_CURRENT +#endif + +/* + * Sanity check that xf86PciInfo.h has the correct values (which come from + * the VMware source tree in vm_device_version.h. + */ +#if PCI_CHIP_VMWARE0405 != PCI_DEVICE_ID_VMWARE_SVGA2 +#error "PCI_CHIP_VMWARE0405 is wrong, update it from vm_device_version.h" +#endif +#if PCI_CHIP_VMWARE0710 != PCI_DEVICE_ID_VMWARE_SVGA +#error "PCI_CHIP_VMWARE0710 is wrong, update it from vm_device_version.h" +#endif +#if PCI_VENDOR_VMWARE != PCI_VENDOR_ID_VMWARE +#error "PCI_VENDOR_VMWARE is wrong, update it from vm_device_version.h" +#endif + +/* + * This is the only way I know to turn a #define of an integer constant into + * a constant string. + */ +#define VMW_INNERSTRINGIFY(s) #s +#define VMW_STRING(str) VMW_INNERSTRINGIFY(str) + +#define VMWARE_NAME "VMWARE" +#define VMWARE_DRIVER_NAME "vmware" +#define VMWARE_MAJOR_VERSION 10 +#define VMWARE_MINOR_VERSION 14 +#define VMWARE_PATCHLEVEL 0 +#define VMWARE_DRIVER_VERSION \ + (VMWARE_MAJOR_VERSION * 65536 + VMWARE_MINOR_VERSION * 256 + VMWARE_PATCHLEVEL) + +static const char VMWAREBuildStr[] = "VMware Guest X Server " + VMW_STRING(VMWARE_MAJOR_VERSION) "." VMW_STRING(VMWARE_MINOR_VERSION) + "." VMW_STRING(VMWARE_PATCHLEVEL) " - build=$Name: $\n"; + +static SymTabRec VMWAREChipsets[] = { + { PCI_CHIP_VMWARE0405, "vmware0405" }, + { PCI_CHIP_VMWARE0710, "vmware0710" }, + { -1, NULL } +}; + +static resRange vmwareLegacyRes[] = { + { ResExcIoBlock, SVGA_LEGACY_BASE_PORT, + SVGA_LEGACY_BASE_PORT + SVGA_NUM_PORTS*sizeof(uint32)}, + _VGA_EXCLUSIVE, _END +}; + +/* + * Currently, even the PCI obedient 0405 chip still only obeys IOSE and + * MEMSE for the SVGA resources. Thus, RES_EXCLUSIVE_VGA is required. + * + * The 0710 chip also uses hardcoded IO ports that aren't disablable. + */ + +static PciChipsets VMWAREPciChipsets[] = { + { PCI_CHIP_VMWARE0405, PCI_CHIP_VMWARE0405, RES_EXCLUSIVE_VGA }, + { PCI_CHIP_VMWARE0710, PCI_CHIP_VMWARE0710, vmwareLegacyRes }, + { -1, -1, RES_UNDEFINED } +}; + +static const char *vgahwSymbols[] = { + "vgaHWGetHWRec", + "vgaHWGetIOBase", + "vgaHWGetIndex", + "vgaHWInit", + "vgaHWProtect", + "vgaHWRestore", + "vgaHWSave", + "vgaHWSaveScreen", + "vgaHWUnlock", + NULL +}; + +static const char *fbSymbols[] = { + "fbCreateDefColormap", + "fbPictureInit", + "fbScreenInit", + NULL +}; + +static const char *ramdacSymbols[] = { + "xf86CreateCursorInfoRec", + "xf86DestroyCursorInfoRec", + "xf86InitCursor", + NULL +}; + +static const char *shadowfbSymbols[] = { + "ShadowFBInit2", + NULL +}; + +#ifdef XFree86LOADER +static XF86ModuleVersionInfo vmwareVersRec = { + "vmware", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + VMWARE_MAJOR_VERSION, VMWARE_MINOR_VERSION, VMWARE_PATCHLEVEL, + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + { 0, 0, 0, 0} +}; +#endif /* XFree86LOADER */ + +typedef enum { + OPTION_HW_CURSOR, + OPTION_NOACCEL, + OPTION_XINERAMA, + OPTION_STATIC_XINERAMA +} VMWAREOpts; + +static const OptionInfoRec VMWAREOptions[] = { + { OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, FALSE }, + { OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE }, + { OPTION_XINERAMA, "Xinerama", OPTV_BOOLEAN, {0}, FALSE }, + { OPTION_STATIC_XINERAMA, "StaticXinerama", OPTV_STRING, {0}, FALSE }, + { -1, NULL, OPTV_NONE, {0}, FALSE } +}; + +static void VMWAREStopFIFO(ScrnInfoPtr pScrn); +static void VMWARESave(ScrnInfoPtr pScrn); + +static Bool +VMWAREGetRec(ScrnInfoPtr pScrn) +{ + if (pScrn->driverPrivate != NULL) { + return TRUE; + } + pScrn->driverPrivate = xnfcalloc(sizeof(VMWARERec), 1); + /* FIXME: Initialize driverPrivate... */ + return TRUE; +} + +static void +VMWAREFreeRec(ScrnInfoPtr pScrn) +{ + if (pScrn->driverPrivate) { + xfree(pScrn->driverPrivate); + pScrn->driverPrivate = NULL; + } +} + +CARD32 +vmwareReadReg(VMWAREPtr pVMWARE, int index) +{ + /* + * Block SIGIO for the duration, so we don't get interrupted after the + * outl but before the inl by a mouse move (which write to our registers). + */ + int oldsigio, ret; + oldsigio = xf86BlockSIGIO(); + outl(pVMWARE->indexReg, index); + ret = inl(pVMWARE->valueReg); + xf86UnblockSIGIO(oldsigio); + return ret; +} + +void +vmwareWriteReg(VMWAREPtr pVMWARE, int index, CARD32 value) +{ + /* + * Block SIGIO for the duration, so we don't get interrupted in between + * the outls by a mouse move (which write to our registers). + */ + int oldsigio; + oldsigio = xf86BlockSIGIO(); + outl(pVMWARE->indexReg, index); + outl(pVMWARE->valueReg, value); + xf86UnblockSIGIO(oldsigio); +} + +void +vmwareWriteWordToFIFO(VMWAREPtr pVMWARE, CARD32 value) +{ + CARD32* vmwareFIFO = pVMWARE->vmwareFIFO; + + /* Need to sync? */ + if ((vmwareFIFO[SVGA_FIFO_NEXT_CMD] + sizeof(CARD32) == vmwareFIFO[SVGA_FIFO_STOP]) + || (vmwareFIFO[SVGA_FIFO_NEXT_CMD] == vmwareFIFO[SVGA_FIFO_MAX] - sizeof(CARD32) && + vmwareFIFO[SVGA_FIFO_STOP] == vmwareFIFO[SVGA_FIFO_MIN])) { + VmwareLog(("Syncing because of full fifo\n")); + vmwareWaitForFB(pVMWARE); + } + + vmwareFIFO[vmwareFIFO[SVGA_FIFO_NEXT_CMD] / sizeof(CARD32)] = value; + if(vmwareFIFO[SVGA_FIFO_NEXT_CMD] == vmwareFIFO[SVGA_FIFO_MAX] - + sizeof(CARD32)) { + vmwareFIFO[SVGA_FIFO_NEXT_CMD] = vmwareFIFO[SVGA_FIFO_MIN]; + } else { + vmwareFIFO[SVGA_FIFO_NEXT_CMD] += sizeof(CARD32); + } +} + +void +vmwareWaitForFB(VMWAREPtr pVMWARE) +{ + vmwareWriteReg(pVMWARE, SVGA_REG_SYNC, 1); + while (vmwareReadReg(pVMWARE, SVGA_REG_BUSY)); +} + +void +vmwareSendSVGACmdUpdate(VMWAREPtr pVMWARE, BoxPtr pBB) +{ + vmwareWriteWordToFIFO(pVMWARE, SVGA_CMD_UPDATE); + vmwareWriteWordToFIFO(pVMWARE, pBB->x1); + vmwareWriteWordToFIFO(pVMWARE, pBB->y1); + vmwareWriteWordToFIFO(pVMWARE, pBB->x2 - pBB->x1); + vmwareWriteWordToFIFO(pVMWARE, pBB->y2 - pBB->y1); +} + +static void +vmwareSendSVGACmdUpdateFullScreen(VMWAREPtr pVMWARE) +{ + BoxRec BB; + + BB.x1 = 0; + BB.y1 = 0; + BB.x2 = pVMWARE->ModeReg.svga_reg_width; + BB.y2 = pVMWARE->ModeReg.svga_reg_height; + vmwareSendSVGACmdUpdate(pVMWARE, &BB); +} + +static void +vmwareSetPitchLock(VMWAREPtr pVMWARE, unsigned long fbPitch) +{ + CARD32 *vmwareFIFO = pVMWARE->vmwareFIFO; + + VmwareLog(("Attempting to set pitchlock\n")); + + if (pVMWARE->vmwareCapability & SVGA_CAP_PITCHLOCK) { + VmwareLog(("Using PitchLock register\n")); + vmwareWriteReg(pVMWARE, SVGA_REG_PITCHLOCK, fbPitch); + } else if (pVMWARE->hasPitchLockFIFOReg && + vmwareFIFO[SVGA_FIFO_MIN] >= (vmwareReadReg(pVMWARE, SVGA_REG_MEM_REGS) << 2)) { + VmwareLog(("Using PitchLock FIFO register\n")); + vmwareFIFO[SVGA_FIFO_PITCHLOCK] = fbPitch; + } +} + +static CARD32 +vmwareCalculateWeight(CARD32 mask) +{ + CARD32 weight; + + for (weight = 0; mask; mask >>= 1) { + if (mask & 1) { + weight++; + } + } + return weight; +} + +/* + *----------------------------------------------------------------------------- + * + * VMXGetVMwareSvgaId -- + * + * Retrieve the SVGA_ID of the VMware SVGA adapter. + * This function should hide any backward compatibility mess. + * + * Results: + * The SVGA_ID_* of the present VMware adapter. + * + * Side effects: + * ins/outs + * + *----------------------------------------------------------------------------- + */ + +static uint32 +VMXGetVMwareSvgaId(VMWAREPtr pVMWARE) +{ + uint32 vmware_svga_id; + + /* Any version with any SVGA_ID_* support will initialize SVGA_REG_ID + * to SVGA_ID_0 to support versions of this driver with SVGA_ID_0. + * + * Versions of SVGA_ID_0 ignore writes to the SVGA_REG_ID register. + * + * Versions of SVGA_ID_1 will allow us to overwrite the content + * of the SVGA_REG_ID register only with the values SVGA_ID_0 or SVGA_ID_1. + * + * Versions of SVGA_ID_2 will allow us to overwrite the content + * of the SVGA_REG_ID register only with the values SVGA_ID_0 or SVGA_ID_1 + * or SVGA_ID_2. + */ + + vmwareWriteReg(pVMWARE, SVGA_REG_ID, SVGA_ID_2); + vmware_svga_id = vmwareReadReg(pVMWARE, SVGA_REG_ID); + if (vmware_svga_id == SVGA_ID_2) { + return SVGA_ID_2; + } + + vmwareWriteReg(pVMWARE, SVGA_REG_ID, SVGA_ID_1); + vmware_svga_id = vmwareReadReg(pVMWARE, SVGA_REG_ID); + if (vmware_svga_id == SVGA_ID_1) { + return SVGA_ID_1; + } + + if (vmware_svga_id == SVGA_ID_0) { + return SVGA_ID_0; + } + + /* No supported VMware SVGA devices found */ + return SVGA_ID_INVALID; +} + + +/* + *---------------------------------------------------------------------- + * + * RewriteTagString -- + * + * Rewrites the given string, removing the $Name: $, and + * replacing it with the contents. The output string must + * have enough room, or else. + * + * Results: + * + * Output string updated. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static void +RewriteTagString(const char *istr, char *ostr, int osize) +{ + int chr; + Bool inTag = FALSE; + char *op = ostr; + + do { + chr = *istr++; + if (chr == '$') { + if (inTag) { + inTag = FALSE; + for (; op > ostr && op[-1] == ' '; op--) { + } + continue; + } + if (strncmp(istr, "Name:", 5) == 0) { + istr += 5; + istr += strspn(istr, " "); + inTag = TRUE; + continue; + } + } + *op++ = chr; + } while (chr); +} + +static void +VMWAREIdentify(int flags) +{ + xf86PrintChipsets(VMWARE_NAME, "driver for VMware SVGA", VMWAREChipsets); +} + +static const OptionInfoRec * +VMWAREAvailableOptions(int chipid, int busid) +{ + return VMWAREOptions; +} + +static int +VMWAREParseTopologyElement(ScrnInfoPtr pScrn, + unsigned int output, + const char *elementName, + const char *element, + const char *expectedTerminators, + Bool needTerminator, + unsigned int *outValue) +{ + char buf[10]; + size_t i = 0; + int retVal = -1; + const char *str = element; + + for (i = 0; str[i] >= '0' && str[i] <= '9'; i++); + if (i == 0) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Output %u: unable to parse %s.\n", + output, elementName); + goto exit; + } + + strncpy(buf, str, i); + *outValue = atoi(buf); + + if (*outValue > (unsigned short)-1) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Output %u: %s must be less than %hu.\n", + output, elementName, (unsigned short)-1); + goto exit; + } + + str += i; + + if (needTerminator || str[0] != '\0') { + Bool unexpected = TRUE; + + for (i = 0; i < strlen(expectedTerminators); i++) { + if (str[0] == expectedTerminators[i]) { + unexpected = FALSE; + } + } + + if (unexpected) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Output %u: unexpected character '%c' after %s.\n", + output, str[0], elementName); + goto exit; + } else { + str++; + } + } + + retVal = str - element; + + exit: + return retVal; +} + +static xXineramaScreenInfo * +VMWAREParseTopologyString(ScrnInfoPtr pScrn, + const char *topology, + unsigned int *retNumOutputs) +{ + xXineramaScreenInfo *extents = NULL; + unsigned int numOutputs = 0; + const char *str = topology; + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Parsing static Xinerama topology: Starting...\n"); + + do { + unsigned int x, y, width, height; + int i; + + i = VMWAREParseTopologyElement(pScrn, numOutputs, "width", str, "xX", TRUE, &width); + if (i == -1) { + goto error; + } + str += i; + + i = VMWAREParseTopologyElement(pScrn, numOutputs, "height", str, "+", TRUE, &height); + if (i == -1) { + goto error; + } + str += i; + + i= VMWAREParseTopologyElement(pScrn, numOutputs, "X offset", str, "+", TRUE, &x); + if (i == -1) { + goto error; + } + str += i; + + i = VMWAREParseTopologyElement(pScrn, numOutputs, "Y offset", str, ";", FALSE, &y); + if (i == -1) { + goto error; + } + str += i; + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Output %u: %ux%u+%u+%u\n", + numOutputs, width, height, x, y); + + numOutputs++; + extents = xrealloc(extents, numOutputs * sizeof (xXineramaScreenInfo)); + extents[numOutputs - 1].x_org = x; + extents[numOutputs - 1].y_org = y; + extents[numOutputs - 1].width = width; + extents[numOutputs - 1].height = height; + } while (*str != 0); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Parsing static Xinerama topology: Succeeded.\n"); + goto exit; + + error: + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Parsing static Xinerama topology: Failed.\n"); + + xfree(extents); + extents = NULL; + numOutputs = 0; + + exit: + *retNumOutputs = numOutputs; + return extents; +} + + +static Bool +VMWAREPreInit(ScrnInfoPtr pScrn, int flags) +{ + MessageType from; + VMWAREPtr pVMWARE; + OptionInfoPtr options; + int bpp24flags; + uint32 id; + int i; + ClockRange* clockRanges; + IOADDRESS domainIOBase = 0; + Bool useXinerama = TRUE; + +#ifndef BUILD_FOR_420 + domainIOBase = pScrn->domainIOBase; +#endif + + if (flags & PROBE_DETECT) { + return FALSE; + } + + if (pScrn->numEntities != 1) { + return FALSE; + } + + if (!VMWAREGetRec(pScrn)) { + return FALSE; + } + pVMWARE = VMWAREPTR(pScrn); + + pVMWARE->pvtSema = &pScrn->vtSema; + + pVMWARE->pEnt = xf86GetEntityInfo(pScrn->entityList[0]); + if (pVMWARE->pEnt->location.type != BUS_PCI) { + return FALSE; + } + pVMWARE->PciInfo = xf86GetPciInfoForEntity(pVMWARE->pEnt->index); + if (pVMWARE->PciInfo == NULL) { + return FALSE; + } + + if (pVMWARE->PciInfo->chipType == PCI_CHIP_VMWARE0710) { + pVMWARE->indexReg = domainIOBase + + SVGA_LEGACY_BASE_PORT + SVGA_INDEX_PORT*sizeof(uint32); + pVMWARE->valueReg = domainIOBase + + SVGA_LEGACY_BASE_PORT + SVGA_VALUE_PORT*sizeof(uint32); + } else { + /* Note: This setting of valueReg causes unaligned I/O */ + pVMWARE->indexReg = domainIOBase + + pVMWARE->PciInfo->ioBase[0] + SVGA_INDEX_PORT; + pVMWARE->valueReg = domainIOBase + + pVMWARE->PciInfo->ioBase[0] + SVGA_VALUE_PORT; + } + xf86DrvMsg(pScrn->scrnIndex, X_PROBED, + "VMware SVGA regs at (0x%04lx, 0x%04lx)\n", + pVMWARE->indexReg, pVMWARE->valueReg); + + if (!xf86LoadSubModule(pScrn, "vgahw")) { + return FALSE; + } + + xf86LoaderReqSymLists(vgahwSymbols, NULL); + + if (!vgaHWGetHWRec(pScrn)) { + return FALSE; + } + + /* + * Save the current video state. Do it here before VMXGetVMwareSvgaId + * writes to any registers. + */ + VMWARESave(pScrn); + + id = VMXGetVMwareSvgaId(pVMWARE); + if (id == SVGA_ID_0 || id == SVGA_ID_INVALID) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "No supported VMware SVGA found (read ID 0x%08x).\n", id); + return FALSE; + } + + pVMWARE->PciTag = pciTag(pVMWARE->PciInfo->bus, pVMWARE->PciInfo->device, + pVMWARE->PciInfo->func); + pVMWARE->Primary = xf86IsPrimaryPci(pVMWARE->PciInfo); + + pScrn->monitor = pScrn->confScreen->monitor; + +#ifdef ACCELERATE_OPS + pVMWARE->vmwareCapability = vmwareReadReg(pVMWARE, SVGA_REG_CAPABILITIES); +#else + pVMWARE->vmwareCapability = 0; +#endif + + pVMWARE->bitsPerPixel = vmwareReadReg(pVMWARE, + SVGA_REG_HOST_BITS_PER_PIXEL); + if (pVMWARE->vmwareCapability & SVGA_CAP_8BIT_EMULATION) { + vmwareWriteReg(pVMWARE, SVGA_REG_BITS_PER_PIXEL, pVMWARE->bitsPerPixel); + } + + pVMWARE->depth = vmwareReadReg(pVMWARE, SVGA_REG_DEPTH); + pVMWARE->videoRam = vmwareReadReg(pVMWARE, SVGA_REG_VRAM_SIZE); + pVMWARE->memPhysBase = vmwareReadReg(pVMWARE, SVGA_REG_FB_START); + pVMWARE->maxWidth = vmwareReadReg(pVMWARE, SVGA_REG_MAX_WIDTH); + pVMWARE->maxHeight = vmwareReadReg(pVMWARE, SVGA_REG_MAX_HEIGHT); + pVMWARE->cursorDefined = FALSE; + pVMWARE->cursorShouldBeHidden = FALSE; + + if (pVMWARE->vmwareCapability & SVGA_CAP_CURSOR_BYPASS_2) { + pVMWARE->cursorRemoveFromFB = SVGA_CURSOR_ON_REMOVE_FROM_FB; + pVMWARE->cursorRestoreToFB = SVGA_CURSOR_ON_RESTORE_TO_FB; + } else { + pVMWARE->cursorRemoveFromFB = SVGA_CURSOR_ON_HIDE; + pVMWARE->cursorRestoreToFB = SVGA_CURSOR_ON_SHOW; + } + + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "caps: 0x%08X\n", pVMWARE->vmwareCapability); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "depth: %d\n", pVMWARE->depth); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "bpp: %d\n", pVMWARE->bitsPerPixel); + + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "vram: %d\n", pVMWARE->videoRam); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "pbase: 0x%08lx\n", pVMWARE->memPhysBase); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "mwidt: %d\n", pVMWARE->maxWidth); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, 2, "mheig: %d\n", pVMWARE->maxHeight); + + if (pVMWARE->vmwareCapability & SVGA_CAP_8BIT_EMULATION) { + bpp24flags = Support24bppFb | Support32bppFb; + } else { + switch (pVMWARE->depth) { + case 16: + /* + * In certain cases, the Windows host appears to + * report 16 bpp and 16 depth but 555 weight. Just + * silently convert it to depth of 15. + */ + if (pVMWARE->bitsPerPixel == 16 && + pVMWARE->weight.green == 5) + pVMWARE->depth = 15; + case 8: + case 15: + bpp24flags = NoDepth24Support; + break; + case 32: + /* + * There is no 32 bit depth, apparently it can get + * reported this way sometimes on the Windows host. + */ + if (pVMWARE->bitsPerPixel == 32) + pVMWARE->depth = 24; + case 24: + if (pVMWARE->bitsPerPixel == 24) + bpp24flags = Support24bppFb; + else + bpp24flags = Support32bppFb; + break; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Adapter is using an unsupported depth (%d).\n", + pVMWARE->depth); + return FALSE; + } + } + + if (!xf86SetDepthBpp(pScrn, pVMWARE->depth, pVMWARE->bitsPerPixel, + pVMWARE->bitsPerPixel, bpp24flags)) { + return FALSE; + } + + /* Check that the returned depth is one we support */ + switch (pScrn->depth) { + case 8: + case 15: + case 16: + case 24: + /* OK */ + break; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Given depth (%d) is not supported by this driver\n", + pScrn->depth); + return FALSE; + } + + if (pScrn->bitsPerPixel != pVMWARE->bitsPerPixel) { + if (pVMWARE->vmwareCapability & SVGA_CAP_8BIT_EMULATION) { + vmwareWriteReg(pVMWARE, SVGA_REG_BITS_PER_PIXEL, + pScrn->bitsPerPixel); + pVMWARE->bitsPerPixel = + vmwareReadReg(pVMWARE, SVGA_REG_BITS_PER_PIXEL); + pVMWARE->depth = vmwareReadReg(pVMWARE, SVGA_REG_DEPTH); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Currently unavailable depth/bpp of %d/%d requested.\n" + "\tThe guest X server must run at the same depth and bpp as the host\n" + "\t(which are currently %d/%d). This is automatically detected. Please\n" + "\tdo not specify a depth on the command line or via the config file.\n", + pScrn->depth, pScrn->bitsPerPixel, + pVMWARE->depth, pVMWARE->bitsPerPixel); + return FALSE; + } + } + + /* + * Defer reading the colour registers until here in case we changed + * bpp above. + */ + + pVMWARE->weight.red = + vmwareCalculateWeight(vmwareReadReg(pVMWARE, SVGA_REG_RED_MASK)); + pVMWARE->weight.green = + vmwareCalculateWeight(vmwareReadReg(pVMWARE, SVGA_REG_GREEN_MASK)); + pVMWARE->weight.blue = + vmwareCalculateWeight(vmwareReadReg(pVMWARE, SVGA_REG_BLUE_MASK)); + pVMWARE->offset.blue = 0; + pVMWARE->offset.green = pVMWARE->weight.blue; + pVMWARE->offset.red = pVMWARE->weight.green + pVMWARE->offset.green; + pVMWARE->defaultVisual = vmwareReadReg(pVMWARE, SVGA_REG_PSEUDOCOLOR) ? + PseudoColor : TrueColor; + + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, + 2, "depth: %d\n", pVMWARE->depth); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, + 2, "bpp: %d\n", pVMWARE->bitsPerPixel); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, + 2, "w.red: %d\n", (int)pVMWARE->weight.red); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, + 2, "w.grn: %d\n", (int)pVMWARE->weight.green); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, + 2, "w.blu: %d\n", (int)pVMWARE->weight.blue); + xf86DrvMsgVerb(pScrn->scrnIndex, X_PROBED, + 2, "vis: %d\n", pVMWARE->defaultVisual); + + if (pScrn->depth != pVMWARE->depth) { + if (pVMWARE->vmwareCapability & SVGA_CAP_8BIT_EMULATION) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Currently unavailable depth of %d requested.\n" + "\tIf the guest X server's BPP matches the host's " + "BPP, then\n\tthe guest X server's depth must also " + "match the\n\thost's depth (currently %d).\n", + pScrn->depth, pVMWARE->depth); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Currently unavailable depth of %d requested.\n" + "\tThe guest X server must run at the same depth as " + "the host (which\n\tis currently %d). This is " + "automatically detected. Please do not\n\tspecify " + "a depth on the command line or via the config file.\n", + pScrn->depth, pVMWARE->depth); + } + return FALSE; + } + xf86PrintDepthBpp(pScrn); + +#if 0 + if (pScrn->depth == 24 && pix24bpp == 0) { + pix24bpp = xf86GetBppFromDepth(pScrn, 24); + } +#endif + + if (pScrn->depth > 8) { + rgb zeros = { 0, 0, 0 }; + + if (!xf86SetWeight(pScrn, pVMWARE->weight, zeros)) { + return FALSE; + } + /* FIXME check returned weight */ + } + if (!xf86SetDefaultVisual(pScrn, pVMWARE->defaultVisual)) { + return FALSE; + } + if (pScrn->defaultVisual != pVMWARE->defaultVisual) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Given visual (%d) is not supported by this driver (%d is required)\n", + pScrn->defaultVisual, pVMWARE->defaultVisual); + return FALSE; + } +#if 0 + bytesPerPixel = pScrn->bitsPerPixel / 8; +#endif + pScrn->progClock = TRUE; + +#if 0 /* MGA does not do this */ + if (pScrn->visual != 0) { /* FIXME */ + /* print error message */ + return FALSE; + } +#endif + + xf86CollectOptions(pScrn, NULL); + if (!(options = xalloc(sizeof(VMWAREOptions)))) + return FALSE; + memcpy(options, VMWAREOptions, sizeof(VMWAREOptions)); + xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options); + + if (pScrn->depth <= 8) { + pScrn->rgbBits = 8; + } + + from = X_PROBED; + pScrn->chipset = (char*)xf86TokenToString(VMWAREChipsets, pVMWARE->PciInfo->chipType); + + if (!pScrn->chipset) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "ChipID 0x%04x is not recognised\n", pVMWARE->PciInfo->chipType); + return FALSE; + } + + from = X_DEFAULT; + pVMWARE->hwCursor = TRUE; + if (xf86GetOptValBool(options, OPTION_HW_CURSOR, &pVMWARE->hwCursor)) { + from = X_CONFIG; + } + if (pVMWARE->hwCursor && !(pVMWARE->vmwareCapability & SVGA_CAP_CURSOR)) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "HW cursor is not supported in this configuration\n"); + from = X_PROBED; + pVMWARE->hwCursor = FALSE; + } + xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n", + pVMWARE->hwCursor ? "HW" : "SW"); + if (xf86IsOptionSet(options, OPTION_NOACCEL)) { + pVMWARE->noAccel = TRUE; + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Acceleration disabled\n"); + } else { + pVMWARE->noAccel = FALSE; + } + pScrn->videoRam = pVMWARE->videoRam / 1024; + pScrn->memPhysBase = pVMWARE->memPhysBase; + + /* + * Init xinerama preferences. + */ + useXinerama = xf86ReturnOptValBool(options, OPTION_XINERAMA, + pVMWARE->vmwareCapability & SVGA_CAP_MULTIMON); + if (useXinerama && !(pVMWARE->vmwareCapability & SVGA_CAP_MULTIMON)) { + xf86DrvMsg(pScrn->scrnIndex, X_WARNING, + "Xinerama is not safely supported by the current virtual hardware. " + "Do not request resolutions that require > 16MB of framebuffer.\n"); + } + + + if (useXinerama && xf86IsOptionSet(options, OPTION_STATIC_XINERAMA)) { + char *topology = xf86GetOptValString(options, OPTION_STATIC_XINERAMA); + if (topology) { + pVMWARE->xineramaState = + VMWAREParseTopologyString(pScrn, topology, &pVMWARE->xineramaNumOutputs); + + pVMWARE->xineramaStatic = pVMWARE->xineramaState != NULL; + + xfree(topology); + } + } + + xfree(options); + + { + Gamma zeros = { 0.0, 0.0, 0.0 }; + if (!xf86SetGamma(pScrn, zeros)) { + return FALSE; + } + } +#if 0 + if ((i = xf86GetPciInfoForScreen(pScrn->scrnIndex, &pciList, NULL)) != 1) { + /* print error message */ + VMWAREFreeRec(pScrn); + if (i > 0) { + xfree(pciList); + } + return FALSE; + } +#endif + clockRanges = xnfcalloc(sizeof(ClockRange), 1); + clockRanges->next = NULL; + clockRanges->minClock = 1; + clockRanges->maxClock = 400000000; + clockRanges->clockIndex = -1; + clockRanges->interlaceAllowed = FALSE; + clockRanges->doubleScanAllowed = FALSE; + clockRanges->ClockMulFactor = 1; + clockRanges->ClockDivFactor = 1; + + i = xf86ValidateModes(pScrn, pScrn->monitor->Modes, pScrn->display->modes, + clockRanges, NULL, 256, pVMWARE->maxWidth, 32 * 32, + 128, pVMWARE->maxHeight, + pScrn->display->virtualX, pScrn->display->virtualY, + pVMWARE->videoRam, + LOOKUP_BEST_REFRESH); + if (i == -1) { + VMWAREFreeRec(pScrn); + return FALSE; + } + xf86PruneDriverModes(pScrn); + if (i == 0 || pScrn->modes == NULL) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n"); + VMWAREFreeRec(pScrn); + return FALSE; + } + xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V); + pScrn->currentMode = pScrn->modes; + xf86PrintModes(pScrn); + xf86SetDpi(pScrn, 0, 0); + if (!xf86LoadSubModule(pScrn, "fb") || + !xf86LoadSubModule(pScrn, "shadowfb")) { + VMWAREFreeRec(pScrn); + return FALSE; + } + xf86LoaderReqSymLists(fbSymbols, shadowfbSymbols, NULL); + + /* Need ramdac for hwcursor */ + if (pVMWARE->hwCursor) { + if (!xf86LoadSubModule(pScrn, "ramdac")) { + VMWAREFreeRec(pScrn); + return FALSE; + } + xf86LoaderReqSymLists(ramdacSymbols, NULL); + } + + if (!pVMWARE->noAccel) { + if (!xf86LoadSubModule(pScrn, "xaa")) { + VMWAREFreeRec(pScrn); + return FALSE; + } + xf86LoaderReqSymLists(vmwareXaaSymbols, NULL); + } + + /* Initialise VMWARE_CTRL extension. */ + VMwareCtrl_ExtInit(pScrn); + + /* Initialise Xinerama extension. */ + if (useXinerama) { + VMwareXinerama_ExtInit(pScrn); + } + + if (pVMWARE->xinerama && pVMWARE->xineramaStatic) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, pVMWARE->xineramaState ? + "Using static Xinerama.\n" : + "Failed to configure static Xinerama.\n"); + } + + return TRUE; +} + +static Bool +VMWAREMapMem(ScrnInfoPtr pScrn) +{ + VMWAREPtr pVMWARE; + + pVMWARE = VMWAREPTR(pScrn); + + pVMWARE->FbBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER, + pVMWARE->PciTag, + pVMWARE->memPhysBase, + pVMWARE->videoRam); + if (!pVMWARE->FbBase) + return FALSE; + + VmwareLog(("FB Mapped: %p/%u -> %p/%u\n", + pVMWARE->memPhysBase, pVMWARE->videoRam, + pVMWARE->FbBase, pVMWARE->videoRam)); + return TRUE; +} + +static Bool +VMWAREUnmapMem(ScrnInfoPtr pScrn) +{ + VMWAREPtr pVMWARE; + + pVMWARE = VMWAREPTR(pScrn); + + VmwareLog(("Unmapped: %p/%u\n", pVMWARE->FbBase, pVMWARE->videoRam)); + + xf86UnMapVidMem(pScrn->scrnIndex, pVMWARE->FbBase, pVMWARE->videoRam); + pVMWARE->FbBase = NULL; + return TRUE; +} + +static void +VMWARESave(ScrnInfoPtr pScrn) +{ + vgaHWPtr hwp = VGAHWPTR(pScrn); + vgaRegPtr vgaReg = &hwp->SavedReg; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + VMWARERegPtr vmwareReg = &pVMWARE->SavedReg; + + vgaHWSave(pScrn, vgaReg, VGA_SR_ALL); + + vmwareReg->svga_reg_enable = vmwareReadReg(pVMWARE, SVGA_REG_ENABLE); + vmwareReg->svga_reg_width = vmwareReadReg(pVMWARE, SVGA_REG_WIDTH); + vmwareReg->svga_reg_height = vmwareReadReg(pVMWARE, SVGA_REG_HEIGHT); + vmwareReg->svga_reg_bits_per_pixel = + vmwareReadReg(pVMWARE, SVGA_REG_BITS_PER_PIXEL); + vmwareReg->svga_reg_id = vmwareReadReg(pVMWARE, SVGA_REG_ID); + + /* XXX this should be based on the cap bit, not hwCursor... */ + if (pVMWARE->hwCursor) { + vmwareReg->svga_reg_cursor_on = + vmwareReadReg(pVMWARE, SVGA_REG_CURSOR_ON); + vmwareReg->svga_reg_cursor_x = + vmwareReadReg(pVMWARE, SVGA_REG_CURSOR_X); + vmwareReg->svga_reg_cursor_y = + vmwareReadReg(pVMWARE, SVGA_REG_CURSOR_Y); + vmwareReg->svga_reg_cursor_id = + vmwareReadReg(pVMWARE, SVGA_REG_CURSOR_ID); + } + + vmwareReg->svga_fifo_enabled = vmwareReadReg(pVMWARE, SVGA_REG_CONFIG_DONE); +} + +static void +VMWARERestoreRegs(ScrnInfoPtr pScrn, VMWARERegPtr vmwareReg) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + VmwareLog(("VMWARERestoreRegs: W: %d, H: %d, BPP: %d, Enable: %d\n", + vmwareReg->svga_reg_width, vmwareReg->svga_reg_height, + vmwareReg->svga_reg_bits_per_pixel, vmwareReg->svga_reg_enable)); + if (vmwareReg->svga_reg_enable) { + vmwareWriteReg(pVMWARE, SVGA_REG_ID, vmwareReg->svga_reg_id); + vmwareWriteReg(pVMWARE, SVGA_REG_WIDTH, vmwareReg->svga_reg_width); + vmwareWriteReg(pVMWARE, SVGA_REG_HEIGHT, vmwareReg->svga_reg_height); + vmwareWriteReg(pVMWARE, SVGA_REG_BITS_PER_PIXEL, + vmwareReg->svga_reg_bits_per_pixel); + vmwareWriteReg(pVMWARE, SVGA_REG_ENABLE, vmwareReg->svga_reg_enable); + vmwareWriteReg(pVMWARE, SVGA_REG_GUEST_ID, GUEST_OS_LINUX); + if (pVMWARE->hwCursor) { + vmwareWriteReg(pVMWARE, SVGA_REG_CURSOR_ID, + vmwareReg->svga_reg_cursor_id); + vmwareWriteReg(pVMWARE, SVGA_REG_CURSOR_X, + vmwareReg->svga_reg_cursor_x); + vmwareWriteReg(pVMWARE, SVGA_REG_CURSOR_Y, + vmwareReg->svga_reg_cursor_y); + vmwareWriteReg(pVMWARE, SVGA_REG_CURSOR_ON, + vmwareReg->svga_reg_cursor_on); + } + } else { + vmwareWriteReg(pVMWARE, SVGA_REG_ENABLE, vmwareReg->svga_reg_enable); + } +} + +static void +VMWARERestore(ScrnInfoPtr pScrn) +{ + vgaHWPtr hwp = VGAHWPTR(pScrn); + vgaRegPtr vgaReg = &hwp->SavedReg; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + VMWARERegPtr vmwareReg = &pVMWARE->SavedReg; + + vmwareWaitForFB(pVMWARE); + if (!vmwareReg->svga_fifo_enabled) { + VMWAREStopFIFO(pScrn); + } + + vgaHWProtect(pScrn, TRUE); + VMWARERestoreRegs(pScrn, vmwareReg); + vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL); + vgaHWProtect(pScrn, FALSE); +} + +static Bool +VMWAREModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) +{ + vgaHWPtr hwp = VGAHWPTR(pScrn); + vgaRegPtr vgaReg = &hwp->ModeReg; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + VMWARERegPtr vmwareReg = &pVMWARE->ModeReg; + + vgaHWUnlock(hwp); + if (!vgaHWInit(pScrn, mode)) + return FALSE; + pScrn->vtSema = TRUE; + + vmwareReg->svga_reg_enable = 1; + vmwareReg->svga_reg_width = max(mode->HDisplay, pScrn->virtualX); + vmwareReg->svga_reg_height = max(mode->VDisplay, pScrn->virtualY); + vmwareReg->svga_reg_bits_per_pixel = pVMWARE->bitsPerPixel; + + vgaHWProtect(pScrn, TRUE); + + vgaHWRestore(pScrn, vgaReg, VGA_SR_ALL); + VMWARERestoreRegs(pScrn, vmwareReg); + + if (pVMWARE->hwCursor) { + vmwareCursorModeInit(pScrn, mode); + } + + VmwareLog(("Required mode: %ux%u\n", mode->HDisplay, mode->VDisplay)); + VmwareLog(("Virtual: %ux%u\n", pScrn->virtualX, pScrn->virtualY)); + VmwareLog(("dispWidth: %u\n", pScrn->displayWidth)); + pVMWARE->fbOffset = vmwareReadReg(pVMWARE, SVGA_REG_FB_OFFSET); + pVMWARE->fbPitch = vmwareReadReg(pVMWARE, SVGA_REG_BYTES_PER_LINE); + pVMWARE->FbSize = vmwareReadReg(pVMWARE, SVGA_REG_FB_SIZE); + + pScrn->displayWidth = (pVMWARE->fbPitch * 8) / ((pScrn->bitsPerPixel + 7) & ~7); + VmwareLog(("fbOffset: %u\n", pVMWARE->fbOffset)); + VmwareLog(("fbPitch: %u\n", pVMWARE->fbPitch)); + VmwareLog(("fbSize: %u\n", pVMWARE->FbSize)); + VmwareLog(("New dispWidth: %u\n", pScrn->displayWidth)); + + vgaHWProtect(pScrn, FALSE); + + /* + * XXX -- If we want to check that we got the mode we asked for, this + * would be a good place. + */ + + /* + * Let XAA know about the mode change. + */ + if (!pVMWARE->noAccel) { + if (!vmwareXAAModeInit(pScrn, mode)) { + return FALSE; + } + } + + /* + * Update Xinerama info appropriately. + */ + if (pVMWARE->xinerama && !pVMWARE->xineramaStatic) { + if (pVMWARE->xineramaNextState) { + xfree(pVMWARE->xineramaState); + pVMWARE->xineramaState = pVMWARE->xineramaNextState; + pVMWARE->xineramaNumOutputs = pVMWARE->xineramaNextNumOutputs; + + pVMWARE->xineramaNextState = NULL; + pVMWARE->xineramaNextNumOutputs = 0; + } else { + VMWAREXineramaPtr basicState = + (VMWAREXineramaPtr)xcalloc(1, sizeof (VMWAREXineramaRec)); + if (basicState) { + basicState->x_org = 0; + basicState->y_org = 0; + basicState->width = vmwareReg->svga_reg_width; + basicState->height = vmwareReg->svga_reg_height; + + xfree(pVMWARE->xineramaState); + pVMWARE->xineramaState = basicState; + pVMWARE->xineramaNumOutputs = 1; + } + } + } + + return TRUE; +} + +static void +VMWAREAdjustFrame(int scrnIndex, int x, int y, int flags) +{ + /* FIXME */ +} + +static void +VMWAREInitFIFO(ScrnInfoPtr pScrn) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + CARD32* vmwareFIFO; + Bool extendedFifo; + int min; + + TRACEPOINT + + pVMWARE->mmioPhysBase = vmwareReadReg(pVMWARE, SVGA_REG_MEM_START); + pVMWARE->mmioSize = vmwareReadReg(pVMWARE, SVGA_REG_MEM_SIZE) & ~3; + pVMWARE->mmioVirtBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_MMIO, + pVMWARE->PciTag, + pVMWARE->mmioPhysBase, + pVMWARE->mmioSize); + vmwareFIFO = pVMWARE->vmwareFIFO = (CARD32*)pVMWARE->mmioVirtBase; + + extendedFifo = pVMWARE->vmwareCapability & SVGA_CAP_EXTENDED_FIFO; + min = extendedFifo ? vmwareReadReg(pVMWARE, SVGA_REG_MEM_REGS) : 4; + + vmwareFIFO[SVGA_FIFO_MIN] = min * sizeof(CARD32); + vmwareFIFO[SVGA_FIFO_MAX] = pVMWARE->mmioSize; + vmwareFIFO[SVGA_FIFO_NEXT_CMD] = min * sizeof(CARD32); + vmwareFIFO[SVGA_FIFO_STOP] = min * sizeof(CARD32); + vmwareWriteReg(pVMWARE, SVGA_REG_CONFIG_DONE, 1); + + pVMWARE->hasPitchLockFIFOReg = + extendedFifo && (vmwareFIFO[SVGA_FIFO_CAPABILITIES] & SVGA_FIFO_CAP_PITCHLOCK); +} + +static void +VMWAREStopFIFO(ScrnInfoPtr pScrn) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + TRACEPOINT + + vmwareWriteReg(pVMWARE, SVGA_REG_CONFIG_DONE, 0); + xf86UnMapVidMem(pScrn->scrnIndex, pVMWARE->mmioVirtBase, pVMWARE->mmioSize); +} + +static Bool +VMWARECloseScreen(int scrnIndex, ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + ScreenPtr save = &pVMWARE->ScrnFuncs; + + VmwareLog(("cursorSema: %d\n", pVMWARE->cursorSema)); + + if (*pVMWARE->pvtSema) { + if (pVMWARE->CursorInfoRec) { + vmwareCursorCloseScreen(pScreen); + } + + if (pVMWARE->xaaInfo) { + vmwareXAACloseScreen(pScreen); + } + + vmwareSetPitchLock(pVMWARE, 0); + + VMWARERestore(pScrn); + VMWAREUnmapMem(pScrn); + + pScrn->vtSema = FALSE; + } + + pScreen->CloseScreen = save->CloseScreen; + pScreen->SaveScreen = save->SaveScreen; + +#if VMWARE_DRIVER_FUNC + pScrn->DriverFunc = NULL; +#endif + + return (*pScreen->CloseScreen)(scrnIndex, pScreen); +} + +static Bool +VMWARESaveScreen(ScreenPtr pScreen, int mode) +{ + VmwareLog(("VMWareSaveScreen() mode = %d\n", mode)); + + /* + * This thoroughly fails to do anything useful to svga mode. I doubt + * we care; who wants to idle-blank their VM's screen anyway? + */ + return vgaHWSaveScreen(pScreen, mode); +} + +/* disabled by default to reduce spew in DEBUG_LOGGING mode. */ +/*#define DEBUG_LOG_UPDATES*/ + +static void +VMWAREPreDirtyBBUpdate(ScrnInfoPtr pScrn, int nboxes, BoxPtr boxPtr) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + +#ifdef DEBUG_LOG_UPDATES + { + int i; + for (i = 0; i < nboxes; i++) { + VmwareLog(("PreUpdate #%d (%d, %d, w = %d, h = %d)\n", nboxes - i, + boxPtr[i].x1, boxPtr[i].y1, + boxPtr[i].x2 - boxPtr[i].x1, + boxPtr[i].y2 - boxPtr[i].y1)); + } + } +#endif + + /* + * We only register this callback if we have a HW cursor. + */ + while (nboxes--) { + if (BOX_INTERSECT(*boxPtr, pVMWARE->hwcur.box)) { + if (!pVMWARE->cursorExcludedForUpdate) { + PRE_OP_HIDE_CURSOR(); + pVMWARE->cursorExcludedForUpdate = TRUE; + } + break; + } + boxPtr++; + } +} + +static void +VMWAREPostDirtyBBUpdate(ScrnInfoPtr pScrn, int nboxes, BoxPtr boxPtr) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + while (nboxes--) { +#ifdef DEBUG_LOG_UPDATES + VmwareLog(("PostUpdate #%d (%d, %d, w = %d, h = %d)\n", nboxes, + boxPtr->x1, boxPtr->y1, + boxPtr->x2 - boxPtr->x1, boxPtr->y2 - boxPtr->y1)); +#endif + + /* Clip off (y only) for offscreen memory */ + if (boxPtr->y2 >= pVMWARE->ModeReg.svga_reg_height) + boxPtr->y2 = pVMWARE->ModeReg.svga_reg_height; + if (boxPtr->y1 >= pVMWARE->ModeReg.svga_reg_height) + boxPtr->y1 = pVMWARE->ModeReg.svga_reg_height; + if (boxPtr->y1 == boxPtr->y2) { + boxPtr++; + continue; + } + + vmwareSendSVGACmdUpdate(pVMWARE, boxPtr++); + } + + if (pVMWARE->hwCursor && pVMWARE->cursorExcludedForUpdate) { + POST_OP_SHOW_CURSOR(); + pVMWARE->cursorExcludedForUpdate = FALSE; + } +} + +static void +VMWARELoadPalette(ScrnInfoPtr pScrn, int numColors, int* indices, + LOCO* colors, VisualPtr pVisual) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + int i; + + for (i = 0; i < numColors; i++) { + vmwareWriteReg(pVMWARE, SVGA_PALETTE_BASE + *indices * 3 + 0, colors[*indices].red); + vmwareWriteReg(pVMWARE, SVGA_PALETTE_BASE + *indices * 3 + 1, colors[*indices].green); + vmwareWriteReg(pVMWARE, SVGA_PALETTE_BASE + *indices * 3 + 2, colors[*indices].blue); + indices++; + } + VmwareLog(("Palette loading done\n")); +} + + +DisplayModeRec * +VMWAREAddDisplayMode(ScrnInfoPtr pScrn, + const char *name, + int width, + int height) +{ + DisplayModeRec *mode; + + mode = xalloc(sizeof(DisplayModeRec)); + + mode->name = xalloc(strlen(name) + 1); + strcpy(mode->name, name); + mode->status = MODE_OK; + mode->type = M_T_DEFAULT; + mode->HDisplay = width; + mode->VDisplay = height; + + mode->next = pScrn->modes; + mode->prev = pScrn->modes->prev; + pScrn->modes->prev->next = mode; + pScrn->modes->prev = mode; + + return mode; +} + + +#if VMWARE_DRIVER_FUNC +static Bool +VMWareDriverFunc(ScrnInfoPtr pScrn, + xorgDriverFuncOp op, + pointer data) +{ + CARD32 *flag; + xorgRRModeMM *modemm; + + switch (op) { + case GET_REQUIRED_HW_INTERFACES: + flag = (CARD32 *)data; + + if (flag) { + *flag = HW_IO | HW_MMIO; + } + return TRUE; + case RR_GET_MODE_MM: + modemm = (xorgRRModeMM *)data; + + /* + * Because changing the resolution of the guest is usually changing the size + * of a window on the host desktop, the real physical DPI will not change. To + * keep the guest in sync, we scale the 'physical' screen dimensions to + * keep the DPI constant. + */ + if (modemm && modemm->mode) { + modemm->mmWidth *= modemm->mode->HDisplay / (double)(modemm->virtX); + modemm->mmHeight *= modemm->mode->VDisplay / (double)(modemm->virtY); + } + return TRUE; + default: + return FALSE; + } +} +#endif + + +static Bool +VMWAREScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) +{ + ScrnInfoPtr pScrn; + vgaHWPtr hwp; + VMWAREPtr pVMWARE; + + /* Get the ScrnInfoRec */ + pScrn = xf86Screens[pScreen->myNum]; + pVMWARE = VMWAREPTR(pScrn); + + /* + * If using the vgahw module, its data structures and related + * things are typically initialised/mapped here. + */ + + hwp = VGAHWPTR(pScrn); + vgaHWGetIOBase(hwp); + + VMWAREInitFIFO(pScrn); + + /* Initialise the first mode */ + VMWAREModeInit(pScrn, pScrn->currentMode); + + vmwareSetPitchLock(pVMWARE, pVMWARE->fbPitch); + + /* Set the viewport if supported */ + VMWAREAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + + /* + * Setup the screen's visuals, and initialise the framebuffer + * code. + */ + VMWAREMapMem(pScrn); + + /* + * Clear the framebuffer (and any black-border mode areas). + */ + memset(pVMWARE->FbBase, 0, pVMWARE->FbSize); + vmwareSendSVGACmdUpdateFullScreen(pVMWARE); + + /* Reset the visual list */ + miClearVisualTypes(); + + /* + * Setup the visuals supported. This driver only supports + * TrueColor for bpp > 8, so the default set of visuals isn't + * acceptable. To deal with this, call miSetVisualTypes with + * the appropriate visual mask. + */ + + if (pScrn->bitsPerPixel > 8) { + if (!miSetVisualTypes(pScrn->depth, TrueColorMask, + pScrn->rgbBits, pScrn->defaultVisual)) { + return FALSE; + } + } else { + if (!miSetVisualTypes(pScrn->depth, + miGetDefaultVisualMask(pScrn->depth), + pScrn->rgbBits, pScrn->defaultVisual)) { + return FALSE; + } + } + + miSetPixmapDepths(); + + /* + * Initialise the framebuffer. + */ + if (!fbScreenInit(pScreen, pVMWARE->FbBase + pVMWARE->fbOffset, + pScrn->virtualX, pScrn->virtualY, + pScrn->xDpi, pScrn->yDpi, + pScrn->displayWidth, + pScrn->bitsPerPixel)) { + return FALSE; + } + + /* Override the default mask/offset settings */ + if (pScrn->bitsPerPixel > 8) { + int i; + VisualPtr visual; + + for (i = 0, visual = pScreen->visuals; + i < pScreen->numVisuals; i++, visual++) { + 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); + + /* + * Save the old screen vector, then wrap CloseScreen and + * set SaveScreen. + */ + pVMWARE->ScrnFuncs = *pScreen; + pScreen->CloseScreen = VMWARECloseScreen; + pScreen->SaveScreen = VMWARESaveScreen; + + /* + * Set initial black & white colourmap indices. + */ + xf86SetBlackWhitePixels(pScreen); + + /* + * Initialize shadowfb to notify us of dirty rectangles. We only + * need preFB access callbacks if we're using the hw cursor. + */ + if (!ShadowFBInit2(pScreen, + pVMWARE->hwCursor ? VMWAREPreDirtyBBUpdate : NULL, + VMWAREPostDirtyBBUpdate)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "ShadowFB initialization failed\n"); + return FALSE; + } + + /* + * If we have a hw cursor, we need to hook functions that might + * read from the framebuffer. + */ + if (pVMWARE->hwCursor) { + vmwareCursorHookWrappers(pScreen); + } + + /* + * Initialize acceleration. + */ + if (!pVMWARE->noAccel) { + if (!vmwareXAAScreenInit(pScreen)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "XAA initialization failed -- running unaccelerated!\n"); + pVMWARE->noAccel = TRUE; + } + } + + /* + * If backing store is to be supported (as is usually the case), + * initialise it. + */ + miInitializeBackingStore(pScreen); + xf86SetBackingStore(pScreen); + xf86SetSilkenMouse(pScreen); + + /* + * Initialize software cursor. + */ + miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); + + /* + * Initialize hardware cursor. + */ + if (pVMWARE->hwCursor) { + if (!vmwareCursorInit(pScreen)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Hardware cursor initialization failed\n"); + pVMWARE->hwCursor = FALSE; + } + } + + /* + * Install colourmap functions. If using the vgahw module, + * vgaHandleColormaps would usually be called here. + */ + + if (!fbCreateDefColormap(pScreen)) + return FALSE; + + if (!xf86HandleColormaps(pScreen, 256, 8, + VMWARELoadPalette, NULL, + CMAP_PALETTED_TRUECOLOR | + CMAP_RELOAD_ON_MODE_SWITCH)) { + return FALSE; + } + + /* + * The initial mode that fixes the framebuffer is the current mode + * at ScreenInit time. + */ + pVMWARE->initialMode = pScrn->currentMode; + + /* + * We will lazily add the dynamic modes as the are needed when new + * modes are requested through the control extension. + */ + pVMWARE->dynMode1 = NULL; + pVMWARE->dynMode2 = NULL; + +#if VMWARE_DRIVER_FUNC + pScrn->DriverFunc = VMWareDriverFunc; +#endif + + /* Report any unused options (only for the first generation) */ + if (serverGeneration == 1) { + xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); + } + + /* Done */ + return TRUE; +} + +static Bool +VMWARESwitchMode(int scrnIndex, DisplayModePtr mode, int flags) +{ + return VMWAREModeInit(xf86Screens[scrnIndex], mode); +} + +static Bool +VMWAREEnterVT(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + if (!pVMWARE->SavedReg.svga_fifo_enabled) { + VMWAREInitFIFO(pScrn); + } + + vmwareSetPitchLock(pVMWARE, pVMWARE->fbPitch); + + return VMWAREModeInit(pScrn, pScrn->currentMode); +} + +static void +VMWARELeaveVT(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + vmwareSetPitchLock(pVMWARE, 0); + + VMWARERestore(pScrn); +} + +static void +VMWAREFreeScreen(int scrnIndex, int flags) +{ + /* + * If the vgahw module is used vgaHWFreeHWRec() would be called + * here. + */ + VMWAREFreeRec(xf86Screens[scrnIndex]); +} + +static ModeStatus +VMWAREValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags) +{ + return MODE_OK; +} + +static Bool +VMWAREProbe(DriverPtr drv, int flags) +{ + int numDevSections, numUsed; + GDevPtr *devSections; + int *usedChips; + int i; + Bool foundScreen = FALSE; + char buildString[sizeof(VMWAREBuildStr)]; + + RewriteTagString(VMWAREBuildStr, buildString, sizeof(VMWAREBuildStr)); + xf86MsgVerb(X_PROBED, 4, "%s", buildString); + + numDevSections = xf86MatchDevice(VMWARE_DRIVER_NAME, &devSections); + if (numDevSections <= 0) { +#ifdef DEBUG + xf86MsgVerb(X_ERROR, 0, "No vmware driver section\n"); +#endif + return FALSE; + } + if (xf86GetPciVideoInfo()) { + VmwareLog(("Some PCI Video Info Exists\n")); + numUsed = xf86MatchPciInstances(VMWARE_NAME, PCI_VENDOR_VMWARE, + VMWAREChipsets, VMWAREPciChipsets, devSections, + numDevSections, drv, &usedChips); + xfree(devSections); + if (numUsed <= 0) + return FALSE; + if (flags & PROBE_DETECT) + foundScreen = TRUE; + else + for (i = 0; i < numUsed; i++) { + ScrnInfoPtr pScrn = NULL; + + VmwareLog(("Even some VMware SVGA PCI instances exists\n")); + pScrn = xf86ConfigPciEntity(pScrn, flags, usedChips[i], + VMWAREPciChipsets, NULL, NULL, NULL, + NULL, NULL); + if (pScrn) { + VmwareLog(("And even configuration suceeded\n")); + pScrn->driverVersion = VMWARE_DRIVER_VERSION; + pScrn->driverName = VMWARE_DRIVER_NAME; + pScrn->name = VMWARE_NAME; + pScrn->Probe = VMWAREProbe; + pScrn->PreInit = VMWAREPreInit; + pScrn->ScreenInit = VMWAREScreenInit; + pScrn->SwitchMode = VMWARESwitchMode; + pScrn->AdjustFrame = VMWAREAdjustFrame; + pScrn->EnterVT = VMWAREEnterVT; + pScrn->LeaveVT = VMWARELeaveVT; + pScrn->FreeScreen = VMWAREFreeScreen; + pScrn->ValidMode = VMWAREValidMode; + foundScreen = TRUE; + } + } + xfree(usedChips); + } + return foundScreen; +} + + +_X_EXPORT DriverRec VMWARE = { + VMWARE_DRIVER_VERSION, + VMWARE_DRIVER_NAME, + VMWAREIdentify, + VMWAREProbe, + VMWAREAvailableOptions, + NULL, + 0, +#if VMWARE_DRIVER_FUNC + VMWareDriverFunc, +#endif +}; + +#ifdef XFree86LOADER +static MODULESETUPPROTO(vmwareSetup); + +_X_EXPORT XF86ModuleData vmwareModuleData = { + &vmwareVersRec, + vmwareSetup, + NULL +}; + +static pointer +vmwareSetup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = FALSE; + + if (!setupDone) { + setupDone = TRUE; + xf86AddDriver(&VMWARE, module, VMWARE_DRIVER_FUNC); + + LoaderRefSymLists(vgahwSymbols, fbSymbols, ramdacSymbols, + shadowfbSymbols, vmwareXaaSymbols, NULL); + + return (pointer)1; + } + if (errmaj) { + *errmaj = LDR_ONCEONLY; + } + return NULL; +} +#endif /* XFree86LOADER */ diff --git a/driver/xf86-video-vmware/src/vmware.h b/driver/xf86-video-vmware/src/vmware.h new file mode 100644 index 000000000..7f138a6cd --- /dev/null +++ b/driver/xf86-video-vmware/src/vmware.h @@ -0,0 +1,279 @@ +/* ********************************************************** + * Copyright (C) 1998-2001 VMware, Inc. + * All Rights Reserved + * Id: vmware.h,v 1.6 2001/01/30 18:13:47 bennett Exp $ + * **********************************************************/ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/vmware.h,v 1.11 2003/04/13 18:09:27 dawes Exp $ */ + +#ifndef VMWARE_H +#define VMWARE_H + +#include <string.h> + +#include "xf86.h" +#include "xf86_OSproc.h" +#include "xf86Resources.h" + +#include <X11/extensions/panoramiXproto.h> + +#include "compiler.h" /* inb/outb */ + +#include "xf86PciInfo.h" /* pci vendor id */ +#include "xf86Pci.h" /* pci */ +#include "xf86Cursor.h" /* hw cursor */ +#include "cursorstr.h" /* xhot/yhot */ + +#include "vgaHW.h" /* VGA hardware */ +#include "fb.h" +#include "xaa.h" + +#include "xf86cmap.h" /* xf86HandleColormaps */ + +#include "vm_basic_types.h" +#include "svga_reg.h" +#include "svga_struct.h" + +#include "offscreen_manager.h" + +/* Arbitrarily choose max cursor dimensions. The emulation doesn't care. */ +#define MAX_CURS 32 + +typedef struct { + CARD32 svga_reg_enable; + CARD32 svga_reg_width; + CARD32 svga_reg_height; + CARD32 svga_reg_bits_per_pixel; + + CARD32 svga_reg_cursor_on; + CARD32 svga_reg_cursor_x; + CARD32 svga_reg_cursor_y; + CARD32 svga_reg_cursor_id; + + Bool svga_fifo_enabled; + + CARD32 svga_reg_id; +} VMWARERegRec, *VMWARERegPtr; + +typedef xXineramaScreenInfo VMWAREXineramaRec, *VMWAREXineramaPtr; + +typedef struct { + EntityInfoPtr pEnt; + pciVideoPtr PciInfo; + PCITAG PciTag; + Bool Primary; + int depth; + int bitsPerPixel; + rgb weight; + rgb offset; + int defaultVisual; + int videoRam; + unsigned long memPhysBase; + unsigned long fbOffset; + unsigned long fbPitch; + unsigned long ioBase; + int maxWidth; + int maxHeight; + unsigned int vmwareCapability; + + unsigned char* FbBase; + unsigned long FbSize; + + VMWARERegRec SavedReg; + VMWARERegRec ModeReg; + + DisplayModePtr initialMode; + DisplayModePtr dynMode1; + DisplayModePtr dynMode2; + + Bool* pvtSema; + + Bool noAccel; + Bool hwCursor; + Bool cursorDefined; + int cursorSema; + Bool cursorExcludedForUpdate; + Bool cursorShouldBeHidden; + + unsigned int cursorRemoveFromFB; + unsigned int cursorRestoreToFB; + +#ifdef RENDER + CompositeProcPtr Composite; + void (*EnableDisableFBAccess)(int, Bool); +#endif /* RENDER */ + + unsigned long mmioPhysBase; + unsigned long mmioSize; + + unsigned char* mmioVirtBase; + CARD32* vmwareFIFO; + Bool hasPitchLockFIFOReg; + + xf86CursorInfoPtr CursorInfoRec; + struct { + int bg, fg, x, y; + int hotX, hotY; + BoxRec box; + + uint32 mask[SVGA_BITMAP_SIZE(MAX_CURS, MAX_CURS)]; + uint32 maskPixmap[SVGA_PIXMAP_SIZE(MAX_CURS, MAX_CURS, 32)]; + uint32 source[SVGA_BITMAP_SIZE(MAX_CURS, MAX_CURS)]; + uint32 sourcePixmap[SVGA_PIXMAP_SIZE(MAX_CURS, MAX_CURS, 32)]; + } hwcur; + + IOADDRESS indexReg, valueReg; + + ScreenRec ScrnFuncs; + + /* + * XAA info rec and misc storage + */ + XAAInfoRecPtr xaaInfo; + int xaaFGColor; + int xaaBGColor; + int xaaRop; + + unsigned char* xaaColorExpScanLine[1]; + unsigned int xaaColorExpSize; /* size of current scan line in DWords */ + + Heap* heap; + SVGASurface* frontBuffer; + + SVGASurface* curPict; + int op; + + /* + * Xinerama state + */ + Bool xinerama; + Bool xineramaStatic; + + VMWAREXineramaPtr xineramaState; + unsigned int xineramaNumOutputs; + + VMWAREXineramaPtr xineramaNextState; + unsigned int xineramaNextNumOutputs; + +} VMWARERec, *VMWAREPtr; + +#define VMWAREPTR(p) ((VMWAREPtr)((p)->driverPrivate)) + +static __inline ScrnInfoPtr infoFromScreen(ScreenPtr s) { + return xf86Screens[s->myNum]; +} + +#define MIN(a,b) ((a)<(b)?(a):(b)) +#define MAX(a,b) ((a)>(b)?(a):(b)) +#define ABS(x) (((x) >= 0) ? (x) : -(x)) + +#define BOX_INTERSECT(a, b) \ + (ABS(((a).x1 + (a).x2) - ((b).x1 + (b).x2)) <= \ + ((a).x2 - (a).x1) + ((b).x2 - (b).x1) && \ + ABS(((a).y1 + (a).y2) - ((b).y1 + (b).y2)) <= \ + ((a).y2 - (a).y1) + ((b).y2 - (b).y1)) + +#define SVGA_GLYPH_SCANLINE_SIZE_DWORDS(w) (((w) + 31) >> 5) + +#define PRE_OP_HIDE_CURSOR() \ + if (pVMWARE->cursorDefined && *pVMWARE->pvtSema) { \ + pVMWARE->cursorSema++; \ + if (pVMWARE->cursorSema == 1) { \ + vmwareWriteCursorRegs(pVMWARE, FALSE, FALSE); \ + } \ + } +#define POST_OP_SHOW_CURSOR() \ + if (pVMWARE->cursorDefined && *pVMWARE->pvtSema) { \ + pVMWARE->cursorSema--; \ + if (!pVMWARE->cursorSema && !pVMWARE->cursorShouldBeHidden) { \ + vmwareWriteCursorRegs(pVMWARE, TRUE, FALSE); \ + } \ + } + +#define MOUSE_ID 1 + +extern const char *vmwareXaaSymbols[]; + +/*#define DEBUG_LOGGING*/ +#ifdef DEBUG_LOGGING +# define VmwareLog(args) ErrorF args +# define TRACEPOINT VmwareLog((__FUNCTION__ ":" __FILE__ "\n")); +#else +# define VmwareLog(args) +# define TRACEPOINT +#endif + +/* Undefine this to kill all acceleration */ +#define ACCELERATE_OPS + +void vmwareWriteReg( + VMWAREPtr pVMWARE, int index, CARD32 value + ); + +CARD32 vmwareReadReg( + VMWAREPtr pVMWARE, int index + ); + +void vmwareWriteWordToFIFO( + VMWAREPtr pVMWARE, CARD32 value + ); + +void vmwareWaitForFB( + VMWAREPtr pVMWARE + ); + +void vmwareSendSVGACmdUpdate( + VMWAREPtr pVMWARE, BoxPtr pBB + ); + +DisplayModeRec *VMWAREAddDisplayMode( + ScrnInfoPtr pScrn, + const char *name, + int width, + int height + ); + +/* vmwarecurs.c */ +Bool vmwareCursorInit( + ScreenPtr pScr + ); + +void vmwareCursorModeInit( + ScrnInfoPtr pScrn, + DisplayModePtr mode + ); + +void vmwareCursorCloseScreen( + ScreenPtr pScr + ); + +void vmwareWriteCursorRegs( + VMWAREPtr pVMWARE, + Bool visible, + Bool force + ); + +void vmwareCursorHookWrappers( + ScreenPtr pScreen + ); + + +/* vmwarexaa.c */ +Bool vmwareXAAScreenInit( + ScreenPtr pScreen + ); + +Bool vmwareXAAModeInit( + ScrnInfoPtr pScrn, DisplayModePtr mode + ); + +void vmwareXAACloseScreen( + ScreenPtr pScreen + ); + +/* vmwarectrl.c */ +void VMwareCtrl_ExtInit(ScrnInfoPtr pScrn); + +/* vmwarexinerama.c */ +void VMwareXinerama_ExtInit(ScrnInfoPtr pScrn); + +#endif diff --git a/driver/xf86-video-vmware/src/vmwarectrl.c b/driver/xf86-video-vmware/src/vmwarectrl.c new file mode 100644 index 000000000..f57ad7ef4 --- /dev/null +++ b/driver/xf86-video-vmware/src/vmwarectrl.c @@ -0,0 +1,562 @@ +/* + * Copyright 2006 by VMware, 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +/* + * vmwarectrl.c -- + * + * The implementation of the VMWARE_CTRL protocol extension that + * allows X clients to communicate with the driver. + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#define NEED_REPLIES +#define NEED_EVENTS +#include "dixstruct.h" +#include "extnsionst.h" +#include <X11/X.h> +#include <X11/extensions/panoramiXproto.h> + +#include "vmware.h" +#include "vmwarectrlproto.h" + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlQueryVersion -- + * + * Implementation of QueryVersion command handler. Initialises and + * sends a reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareCtrlQueryVersion(ClientPtr client) +{ + xVMwareCtrlQueryVersionReply rep = { 0, }; + register int n; + + REQUEST_SIZE_MATCH(xVMwareCtrlQueryVersionReq); + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.majorVersion = VMWARE_CTRL_MAJOR_VERSION; + rep.minorVersion = VMWARE_CTRL_MINOR_VERSION; + if (client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.majorVersion, n); + swapl(&rep.minorVersion, n); + } + WriteToClient(client, sizeof(xVMwareCtrlQueryVersionReply), (char *)&rep); + + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlDoSetRes -- + * + * Set the custom resolution into the mode list. + * + * This is done by alternately updating one of two dynamic modes. It is + * done this way because the server gets upset if you try to switch + * to a new resolution that has the same index as the current one. + * + * Results: + * TRUE on success, FALSE otherwise. + * + * Side effects: + * One dynamic mode will be updated if successful. + * + *---------------------------------------------------------------------------- + */ + +static Bool +VMwareCtrlDoSetRes(ScrnInfoPtr pScrn, + CARD32 x, + CARD32 y) +{ + DisplayModePtr mode; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + if (pScrn && pScrn->modes) { + /* + * Don't resize larger than possible but don't + * return an X Error either. + */ + if (x > pVMWARE->initialMode->HDisplay || + y > pVMWARE->initialMode->VDisplay) { + return TRUE; + } + + /* + * Switch the dynamic modes so that we alternate + * which one gets updated on each call. + */ + mode = pVMWARE->dynMode1; + pVMWARE->dynMode1 = pVMWARE->dynMode2; + pVMWARE->dynMode2 = mode; + + /* + * Initialise the dynamic mode if it hasn't been used before. + */ + if (!pVMWARE->dynMode1) { + pVMWARE->dynMode1 = VMWAREAddDisplayMode(pScrn, "DynMode", 1, 1); + } + mode = pVMWARE->dynMode1; + + mode->HDisplay = x; + mode->VDisplay = y; + + return TRUE; + } else { + return FALSE; + } +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlSetRes -- + * + * Implementation of SetRes command handler. Initialises and sends a + * reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareCtrlSetRes(ClientPtr client) +{ + REQUEST(xVMwareCtrlSetResReq); + xVMwareCtrlSetResReply rep = { 0, }; + ScrnInfoPtr pScrn; + ExtensionEntry *ext; + register int n; + + REQUEST_SIZE_MATCH(xVMwareCtrlSetResReq); + + if (!(ext = CheckExtension(VMWARE_CTRL_PROTOCOL_NAME))) { + return BadMatch; + } + + pScrn = ext->extPrivate; + if (pScrn->scrnIndex != stuff->screen) { + return BadMatch; + } + + if (!VMwareCtrlDoSetRes(pScrn, stuff->x, stuff->y)) { + return BadValue; + } + + rep.type = X_Reply; + rep.length = (sizeof(xVMwareCtrlSetResReply) - sizeof(xGenericReply)) >> 2; + rep.sequenceNumber = client->sequence; + rep.screen = stuff->screen; + rep.x = stuff->x; + rep.y = stuff->y; + if (client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.screen, n); + swapl(&rep.x, n); + swapl(&rep.y, n); + } + WriteToClient(client, sizeof(xVMwareCtrlSetResReply), (char *)&rep); + + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlDoSetTopology -- + * + * Set the custom topology and set a dynamic mode to the bounding box + * of the passed topology. + * + * Results: + * TRUE on success, FALSE otherwise. + * + * Side effects: + * One dynamic mode and the pending xinerama state will be updated if + * successful. + * + *---------------------------------------------------------------------------- + */ + +static Bool +VMwareCtrlDoSetTopology(ScrnInfoPtr pScrn, + xXineramaScreenInfo *extents, + unsigned long number) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + if (pVMWARE && pVMWARE->xinerama) { + VMWAREXineramaPtr xineramaState; + short maxX = 0; + short maxY = 0; + size_t i; + + for (i = 0; i < number; i++) { + maxX = MAX(maxX, extents[i].x_org + extents[i].width); + maxY = MAX(maxY, extents[i].y_org + extents[i].height); + } + + xineramaState = (VMWAREXineramaPtr)xcalloc(number, sizeof(VMWAREXineramaRec)); + if (xineramaState) { + memcpy(xineramaState, extents, number * sizeof (VMWAREXineramaRec)); + + xfree(pVMWARE->xineramaNextState); + pVMWARE->xineramaNextState = xineramaState; + pVMWARE->xineramaNextNumOutputs = number; + + return VMwareCtrlDoSetRes(pScrn, maxX, maxY); + } else { + return FALSE; + } + } else { + return FALSE; + } +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlSetTopology -- + * + * Implementation of SetTopology command handler. Initialises and sends a + * reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareCtrlSetTopology(ClientPtr client) +{ + REQUEST(xVMwareCtrlSetTopologyReq); + xVMwareCtrlSetTopologyReply rep = { 0, }; + ScrnInfoPtr pScrn; + ExtensionEntry *ext; + register int n; + xXineramaScreenInfo *extents; + size_t i; + + REQUEST_AT_LEAST_SIZE(xVMwareCtrlSetTopologyReq); + + if (!(ext = CheckExtension(VMWARE_CTRL_PROTOCOL_NAME))) { + return BadMatch; + } + + pScrn = ext->extPrivate; + if (pScrn->scrnIndex != stuff->screen) { + return BadMatch; + } + + extents = (xXineramaScreenInfo *)(stuff + 1); + if (!VMwareCtrlDoSetTopology(pScrn, extents, stuff->number)) { + return BadValue; + } + + rep.type = X_Reply; + rep.length = (sizeof(xVMwareCtrlSetTopologyReply) - sizeof(xGenericReply)) >> 2; + rep.sequenceNumber = client->sequence; + rep.screen = stuff->screen; + if (client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.screen, n); + } + WriteToClient(client, sizeof(xVMwareCtrlSetTopologyReply), (char *)&rep); + + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlDispatch -- + * + * Dispatcher for VMWARE_CTRL commands. Calls the correct handler for + * each command type. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of individual command handlers. + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareCtrlDispatch(ClientPtr client) +{ + REQUEST(xReq); + + switch(stuff->data) { + case X_VMwareCtrlQueryVersion: + return VMwareCtrlQueryVersion(client); + case X_VMwareCtrlSetRes: + return VMwareCtrlSetRes(client); + case X_VMwareCtrlSetTopology: + return VMwareCtrlSetTopology(client); + } + return BadRequest; +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareCtrlQueryVersion -- + * + * Wrapper for QueryVersion handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareCtrlQueryVersion(ClientPtr client) +{ + register int n; + + REQUEST(xVMwareCtrlQueryVersionReq); + REQUEST_SIZE_MATCH(xVMwareCtrlQueryVersionReq); + + swaps(&stuff->length, n); + + return VMwareCtrlQueryVersion(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareCtrlSetRes -- + * + * Wrapper for SetRes handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareCtrlSetRes(ClientPtr client) +{ + register int n; + + REQUEST(xVMwareCtrlSetResReq); + REQUEST_SIZE_MATCH(xVMwareCtrlSetResReq); + + swaps(&stuff->length, n); + swapl(&stuff->screen, n); + swapl(&stuff->x, n); + swapl(&stuff->y, n); + + return VMwareCtrlSetRes(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareCtrlSetTopology -- + * + * Wrapper for SetTopology handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareCtrlSetTopology(ClientPtr client) +{ + register int n; + + REQUEST(xVMwareCtrlSetTopologyReq); + REQUEST_SIZE_MATCH(xVMwareCtrlSetTopologyReq); + + swaps(&stuff->length, n); + swapl(&stuff->screen, n); + swapl(&stuff->number, n); + /* Each extent is a struct of shorts. */ + SwapRestS(stuff); + + return VMwareCtrlSetTopology(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareCtrlDispatch -- + * + * Wrapper for dispatcher that handles input from other-endian clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of individual command handlers. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareCtrlDispatch(ClientPtr client) +{ + REQUEST(xReq); + + switch(stuff->data) { + case X_VMwareCtrlQueryVersion: + return SVMwareCtrlQueryVersion(client); + case X_VMwareCtrlSetRes: + return SVMwareCtrlSetRes(client); + case X_VMwareCtrlSetTopology: + return SVMwareCtrlSetTopology(client); + } + return BadRequest; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrlResetProc -- + * + * Cleanup handler called when the extension is removed. + * + * Results: + * None + * + * Side effects: + * None + * + *---------------------------------------------------------------------------- + */ + +static void +VMwareCtrlResetProc(ExtensionEntry* extEntry) +{ + /* Currently, no cleanup is necessary. */ +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrl_ExitInit -- + * + * Initialiser for the VMWARE_CTRL protocol extension. + * + * Results: + * None. + * + * Side effects: + * Protocol extension will be registered if successful. + * + *---------------------------------------------------------------------------- + */ + +void +VMwareCtrl_ExtInit(ScrnInfoPtr pScrn) +{ + ExtensionEntry *myext; + + if (!(myext = CheckExtension(VMWARE_CTRL_PROTOCOL_NAME))) { + if (!(myext = AddExtension(VMWARE_CTRL_PROTOCOL_NAME, 0, 0, + VMwareCtrlDispatch, + SVMwareCtrlDispatch, + VMwareCtrlResetProc, + StandardMinorOpcode))) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed to add VMWARE_CTRL extension\n"); + return; + } + + /* + * For now, only support one screen as that's all the virtual + * hardware supports. + */ + myext->extPrivate = pScrn; + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Initialized VMWARE_CTRL extension version %d.%d\n", + VMWARE_CTRL_MAJOR_VERSION, VMWARE_CTRL_MINOR_VERSION); + } +} diff --git a/driver/xf86-video-vmware/src/vmwarectrl.h b/driver/xf86-video-vmware/src/vmwarectrl.h new file mode 100644 index 000000000..a671ae1dc --- /dev/null +++ b/driver/xf86-video-vmware/src/vmwarectrl.h @@ -0,0 +1,48 @@ +/* + * Copyright 2006 by VMware, 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +/* + * vmwarectrl.h -- + * + * The definitions used by the VMWARE_CTRL protocol extension that + * allows X clients to communicate with the driver. + */ + + +#ifndef _VMWARE_CTRL_H_ +#define _VMWARE_CTRL_H_ + +#define VMWARE_CTRL_PROTOCOL_NAME "VMWARE_CTRL" + +#define VMWARE_CTRL_MAJOR_VERSION 0 +#define VMWARE_CTRL_MINOR_VERSION 2 + +#define X_VMwareCtrlQueryVersion 0 +#define X_VMwareCtrlSetRes 1 +#define X_VMwareCtrlSetTopology 2 + +#endif /* _VMWARE_CTRL_H_ */ diff --git a/driver/xf86-video-vmware/src/vmwarectrlproto.h b/driver/xf86-video-vmware/src/vmwarectrlproto.h new file mode 100644 index 000000000..76f157f91 --- /dev/null +++ b/driver/xf86-video-vmware/src/vmwarectrlproto.h @@ -0,0 +1,122 @@ +/* + * Copyright 2006 by VMware, 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +/* + * vmwarectrlproto.h -- + * + * The description of the VMWARE_CTRL protocol extension that + * allows X clients to communicate with the driver. + */ + +#ifndef _VMWARE_CTRL_PROTO_H_ +#define _VMWARE_CTRL_PROTO_H_ + + +#include <X11/X.h> +#include "vmwarectrl.h" + + +/* + * Requests and Replies + */ + +/* Version 0.1 definitions. */ + +typedef struct { + CARD8 reqType; /* always X_VMwareCtrlReqCode */ + CARD8 VMwareCtrlReqType; /* always X_VMwareCtrlQueryVersion */ + CARD16 length B16; + CARD32 majorVersion B32; + CARD32 minorVersion B32; +} xVMwareCtrlQueryVersionReq; +#define sz_xVMwareCtrlQueryVersionReq 12 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 majorVersion B32; + CARD32 minorVersion B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; +} xVMwareCtrlQueryVersionReply; +#define sz_xVMwareCtrlQueryVersionReply 32 + +typedef struct { + CARD8 reqType; /* always X_VMwareCtrlReqCode */ + CARD8 VMwareCtrlReqType; /* always X_VMwareCtrlSetRes */ + CARD16 length B16; + CARD32 screen B32; + CARD32 x B32; + CARD32 y B32; +} xVMwareCtrlSetResReq; +#define sz_xVMwareCtrlSetResReq 16 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 screen B32; + CARD32 x B32; + CARD32 y B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; +} xVMwareCtrlSetResReply; +#define sz_xVMwareCtrlSetResReply 32 + +/* Version 0.2 definitions. */ + +typedef struct { + CARD8 reqType; /* always X_VMwareCtrlReqCode */ + CARD8 VMwareCtrlReqType; /* always X_VMwareCtrlSetTopology */ + CARD16 length B16; + CARD32 screen B32; + CARD32 number B32; + CARD32 pad1 B32; +} xVMwareCtrlSetTopologyReq; +#define sz_xVMwareCtrlSetTopologyReq 16 + +typedef struct { + BYTE type; /* X_Reply */ + BYTE pad1; + CARD16 sequenceNumber B16; + CARD32 length B32; + CARD32 screen B32; + CARD32 pad2 B32; + CARD32 pad3 B32; + CARD32 pad4 B32; + CARD32 pad5 B32; + CARD32 pad6 B32; +} xVMwareCtrlSetTopologyReply; +#define sz_xVMwareCtrlSetTopologyReply 32 + +#endif /* _VMWARE_CTRL_PROTO_H_ */ diff --git a/driver/xf86-video-vmware/src/vmwarecurs.c b/driver/xf86-video-vmware/src/vmwarecurs.c new file mode 100644 index 000000000..ddd98bcc5 --- /dev/null +++ b/driver/xf86-video-vmware/src/vmwarecurs.c @@ -0,0 +1,467 @@ +/* ********************************************************** + * Copyright (C) 1998-2001 VMware, Inc. + * All Rights Reserved + * **********************************************************/ +#ifdef VMX86_DEVEL +char rcsId_vmwarecurs[] = + "Id: vmwarecurs.c,v 1.5 2001/01/30 23:33:02 bennett Exp $"; +#endif +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/vmwarecurs.c,v 1.10 2003/02/04 01:39:53 dawes Exp $ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "vmware.h" +#include "bits2pixels.h" + +static void VMWAREGetImage(DrawablePtr src, int x, int y, int w, int h, + unsigned int format, unsigned long planeMask, + char *pBinImage); +static void VMWARECopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, + RegionPtr prgnSrc); + +#ifdef RENDER +static void VMWAREComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask, + PicturePtr pDst, INT16 xSrc, INT16 ySrc, + INT16 xMask, INT16 yMask, INT16 xDst, INT16 yDst, + CARD16 width, CARD16 height); +#endif /* RENDER */ + +static void +RedefineCursor(VMWAREPtr pVMWARE) +{ + int i; + + VmwareLog(("RedefineCursor\n")); + + pVMWARE->cursorDefined = FALSE; + + /* Define cursor */ + vmwareWriteWordToFIFO(pVMWARE, SVGA_CMD_DEFINE_CURSOR); + vmwareWriteWordToFIFO(pVMWARE, MOUSE_ID); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->hwcur.hotX); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->hwcur.hotY); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->CursorInfoRec->MaxWidth); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->CursorInfoRec->MaxHeight); + vmwareWriteWordToFIFO(pVMWARE, 1); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->bitsPerPixel); + + /* + * Since we have AND and XOR masks rather than 'source' and 'mask', + * color expand 'mask' with all zero as its foreground and all one as + * its background. This makes 'image & 0 ^ 'source' = source. We + * arange for 'image' & 1 ^ 'source' = 'image' below when we clip + * 'source' below. + */ + vmwareRaster_BitsToPixels((uint8 *) pVMWARE->hwcur.mask, + SVGA_BITMAP_INCREMENT(pVMWARE->CursorInfoRec->MaxWidth), + (uint8 *) pVMWARE->hwcur.maskPixmap, + SVGA_PIXMAP_INCREMENT(pVMWARE->CursorInfoRec->MaxWidth, + pVMWARE->bitsPerPixel), + pVMWARE->bitsPerPixel / 8, + pVMWARE->CursorInfoRec->MaxWidth, + pVMWARE->CursorInfoRec->MaxHeight, 0, ~0); + for (i = 0; i < SVGA_BITMAP_SIZE(pVMWARE->CursorInfoRec->MaxWidth, + pVMWARE->CursorInfoRec->MaxHeight); i++) { + vmwareWriteWordToFIFO(pVMWARE, ~pVMWARE->hwcur.mask[i]); + } + + vmwareRaster_BitsToPixels((uint8 *) pVMWARE->hwcur.source, + SVGA_BITMAP_INCREMENT(pVMWARE->CursorInfoRec->MaxWidth), + (uint8 *) pVMWARE->hwcur.sourcePixmap, + SVGA_PIXMAP_INCREMENT(pVMWARE->CursorInfoRec->MaxWidth, + pVMWARE->bitsPerPixel), + pVMWARE->bitsPerPixel / 8, + pVMWARE->CursorInfoRec->MaxWidth, + pVMWARE->CursorInfoRec->MaxHeight, + pVMWARE->hwcur.fg, pVMWARE->hwcur.bg); + /* + * As pointed out above, we need to clip the expanded 'source' against + * the expanded 'mask' since we actually have AND and XOR masks in the + * virtual hardware. Effectively, 'source' becomes a three color fg/bg/0 + * pixmap that XORs appropriately. + */ + for (i = 0; i < SVGA_PIXMAP_SIZE(pVMWARE->CursorInfoRec->MaxWidth, + pVMWARE->CursorInfoRec->MaxHeight, + pVMWARE->bitsPerPixel); i++) { + pVMWARE->hwcur.sourcePixmap[i] &= ~pVMWARE->hwcur.maskPixmap[i]; + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->hwcur.sourcePixmap[i]); + } + + /* Sync the FIFO, so that the definition preceeds any use of the cursor */ + vmwareWaitForFB(pVMWARE); + pVMWARE->cursorDefined = TRUE; +} + +static void +vmwareSetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + TRACEPOINT + + if (pVMWARE->hwcur.fg != fg || pVMWARE->hwcur.bg != bg) { + VmwareLog(("SetCursorColors(0x%08x, 0x%08x)\n", bg, fg)); + pVMWARE->hwcur.fg = fg; + pVMWARE->hwcur.bg = bg; + RedefineCursor(pVMWARE); + } +} + +static Bool +vmwareUseHWCursor(ScreenPtr pScreen, CursorPtr pCurs) +{ + ScrnInfoPtr pScrn = infoFromScreen(pScreen); + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + pVMWARE->hwcur.hotX = pCurs->bits->xhot; + pVMWARE->hwcur.hotY = pCurs->bits->yhot; + + return pScrn->bitsPerPixel > 8; +} + +static void +vmwareLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src ) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + const int imageSize = SVGA_BITMAP_SIZE(pVMWARE->CursorInfoRec->MaxWidth, + pVMWARE->CursorInfoRec->MaxHeight); + TRACEPOINT + + memcpy(pVMWARE->hwcur.source, src, imageSize * sizeof(uint32)); + memcpy(pVMWARE->hwcur.mask, + src + imageSize * sizeof(uint32), imageSize * sizeof(uint32)); + RedefineCursor(pVMWARE); +} + +#ifdef ARGB_CURSOR +#include "cursorstr.h" + +static Bool +vmwareUseHWCursorARGB(ScreenPtr pScreen, CursorPtr pCurs) +{ + ScrnInfoPtr pScrn = infoFromScreen(pScreen); + + return pCurs->bits->height <= MAX_CURS && + pCurs->bits->width <= MAX_CURS && + pScrn->bitsPerPixel > 8; +} + +static void +vmwareLoadCursorARGB(ScrnInfoPtr pScrn, CursorPtr pCurs) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + CARD32 width = pCurs->bits->width; + CARD32 height = pCurs->bits->height; + CARD32* image = pCurs->bits->argb; + CARD32* imageEnd = image + (width * height); + + pVMWARE->cursorDefined = FALSE; + + pVMWARE->hwcur.hotX = pCurs->bits->xhot; + pVMWARE->hwcur.hotY = pCurs->bits->yhot; + + vmwareWriteWordToFIFO(pVMWARE, SVGA_CMD_DEFINE_ALPHA_CURSOR); + vmwareWriteWordToFIFO(pVMWARE, MOUSE_ID); + vmwareWriteWordToFIFO(pVMWARE, pCurs->bits->xhot); + vmwareWriteWordToFIFO(pVMWARE, pCurs->bits->yhot); + vmwareWriteWordToFIFO(pVMWARE, width); + vmwareWriteWordToFIFO(pVMWARE, height); + + while (image != imageEnd) { + vmwareWriteWordToFIFO(pVMWARE, *image++); + } + + vmwareWaitForFB(pVMWARE); + pVMWARE->cursorDefined = TRUE; +} +#endif + +void +vmwareWriteCursorRegs(VMWAREPtr pVMWARE, Bool visible, Bool force) +{ + int enableVal; + + vmwareWriteReg(pVMWARE, SVGA_REG_CURSOR_ID, MOUSE_ID); + if (visible) { + vmwareWriteReg(pVMWARE, SVGA_REG_CURSOR_X, + pVMWARE->hwcur.x + pVMWARE->hwcur.hotX); + vmwareWriteReg(pVMWARE, SVGA_REG_CURSOR_Y, + pVMWARE->hwcur.y + pVMWARE->hwcur.hotY); + } + + if (force) { + enableVal = visible ? SVGA_CURSOR_ON_SHOW : SVGA_CURSOR_ON_HIDE; + } else { + enableVal = visible ? pVMWARE->cursorRestoreToFB : + pVMWARE->cursorRemoveFromFB; + } + vmwareWriteReg(pVMWARE, SVGA_REG_CURSOR_ON, enableVal); +} + +/* disabled by default to reduce spew in DEBUG_LOGGING mode. */ +/* #define DEBUG_LOG_MOUSE_HIDE_SHOW */ + +static void +vmwareShowCursor(ScrnInfoPtr pScrn) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); +#ifdef DEBUG_LOG_MOUSE_HIDE_SHOW + VmwareLog(("Show: %d %d %d\n", pVMWARE->cursorSema, pVMWARE->cursorDefined, + pVMWARE->cursorShouldBeHidden)); +#endif + pVMWARE->cursorShouldBeHidden = FALSE; + if (pVMWARE->cursorSema == 0 && pVMWARE->cursorDefined) { + vmwareWriteCursorRegs(pVMWARE, TRUE, TRUE); + } +} + +static void +vmwareHideCursor(ScrnInfoPtr pScrn) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); +#ifdef DEBUG_LOG_MOUSE_HIDE_SHOW + VmwareLog(("Hide: %d %d %d\n", pVMWARE->cursorSema, pVMWARE->cursorDefined, + pVMWARE->cursorShouldBeHidden)); +#endif + if (pVMWARE->cursorDefined) { + vmwareWriteCursorRegs(pVMWARE, FALSE, TRUE); + } + pVMWARE->cursorShouldBeHidden = TRUE; +} + +/* disabled by default to reduce spew in DEBUG_LOGGING mode. */ +/* #define DEBUG_LOG_MOUSE_MOVE */ + +static void +vmwareSetCursorPosition(ScrnInfoPtr pScrn, int x, int y) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); +#ifdef DEBUG_LOG_MOUSE_MOVE + VmwareLog(("Move: %d %d %d\n", pVMWARE->cursorSema, pVMWARE->cursorDefined, + pVMWARE->cursorShouldBeHidden)); +#endif + /* + * We're bad people. We have no concept of a frame (VMWAREAdjustFrame() + * is a NOP). The hwcursor code expects us to be frame aware though, so + * we have to do this. I'm open to suggestions. I tried not even + * hooking AdjustFrame and it didn't help. + */ + pVMWARE->hwcur.x = x + pScrn->frameX0; + pVMWARE->hwcur.y = y + pScrn->frameY0; + pVMWARE->hwcur.box.x1 = pVMWARE->hwcur.x; + pVMWARE->hwcur.box.x2 = pVMWARE->hwcur.x + pVMWARE->CursorInfoRec->MaxWidth; + pVMWARE->hwcur.box.y1 = pVMWARE->hwcur.y; + pVMWARE->hwcur.box.y2 = pVMWARE->hwcur.y + pVMWARE->CursorInfoRec->MaxHeight; + + vmwareShowCursor(pScrn); +} + +void +vmwareCursorModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + if (pVMWARE->cursorDefined) { + vmwareWriteCursorRegs(pVMWARE, !pVMWARE->cursorShouldBeHidden, TRUE); + } +} + +Bool +vmwareCursorInit(ScreenPtr pScreen) +{ + xf86CursorInfoPtr infoPtr; + VMWAREPtr pVMWARE = VMWAREPTR(infoFromScreen(pScreen)); + Bool ret; + + TRACEPOINT + + /* Require cursor bypass for hwcursor. Ignore deprecated FIFO hwcursor */ + if (!(pVMWARE->vmwareCapability & SVGA_CAP_CURSOR_BYPASS)) { + return FALSE; + } + + infoPtr = xf86CreateCursorInfoRec(); + if (!infoPtr) + return FALSE; + + pVMWARE->CursorInfoRec = infoPtr; + + infoPtr->MaxWidth = MAX_CURS; + infoPtr->MaxHeight = MAX_CURS; + infoPtr->Flags = HARDWARE_CURSOR_BIT_ORDER_MSBFIRST | + HARDWARE_CURSOR_SOURCE_MASK_NOT_INTERLEAVED; + infoPtr->SetCursorColors = vmwareSetCursorColors; + infoPtr->SetCursorPosition = vmwareSetCursorPosition; + infoPtr->LoadCursorImage = vmwareLoadCursorImage; + infoPtr->HideCursor = vmwareHideCursor; + infoPtr->ShowCursor = vmwareShowCursor; + infoPtr->UseHWCursor = vmwareUseHWCursor; + +#ifdef ARGB_CURSOR + if (pVMWARE->vmwareCapability & SVGA_CAP_ALPHA_CURSOR) { + infoPtr->UseHWCursorARGB = vmwareUseHWCursorARGB; + infoPtr->LoadCursorARGB = vmwareLoadCursorARGB; + } +#endif + + ret = xf86InitCursor(pScreen, infoPtr); + if (!ret) { + xf86DestroyCursorInfoRec(infoPtr); + pVMWARE->CursorInfoRec = NULL; + } + return ret; +} + +void +vmwareCursorCloseScreen(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = infoFromScreen(pScreen); + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); +#ifdef RENDER + PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); +#endif + + pScreen->GetImage = pVMWARE->ScrnFuncs.GetImage; + pScreen->CopyWindow = pVMWARE->ScrnFuncs.CopyWindow; +#ifdef RENDER + if (ps) { + ps->Composite = pVMWARE->Composite; + } +#endif /* RENDER */ + + vmwareHideCursor(pScrn); + xf86DestroyCursorInfoRec(pVMWARE->CursorInfoRec); +} + +/*** Wrap functions that read from the framebuffer ***/ + +void +vmwareCursorHookWrappers(ScreenPtr pScreen) +{ + VMWAREPtr pVMWARE = VMWAREPTR(infoFromScreen(pScreen)); +#ifdef RENDER + PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); +#endif + + TRACEPOINT + + pVMWARE->ScrnFuncs.GetImage = pScreen->GetImage; + pVMWARE->ScrnFuncs.CopyWindow = pScreen->CopyWindow; + pScreen->GetImage = VMWAREGetImage; + pScreen->CopyWindow = VMWARECopyWindow; + +#ifdef RENDER + if (ps) { + pVMWARE->Composite = ps->Composite; + ps->Composite = VMWAREComposite; + } +#endif /* RENDER */ + +} + +static void +VMWAREGetImage(DrawablePtr src, int x, int y, int w, int h, + unsigned int format, unsigned long planeMask, char *pBinImage) +{ + ScreenPtr pScreen = src->pScreen; + VMWAREPtr pVMWARE = VMWAREPTR(infoFromScreen(src->pScreen)); + BoxRec box; + Bool hidden = FALSE; + + VmwareLog(("VMWAREGetImage(%p, %d, %d, %d, %d, %d, %d, %p)\n", + src, x, y, w, h, format, planeMask, pBinImage)); + + box.x1 = src->x + x; + box.y1 = src->y + y; + box.x2 = box.x1 + w; + box.y2 = box.y1 + h; + + if (BOX_INTERSECT(box, pVMWARE->hwcur.box)) { + PRE_OP_HIDE_CURSOR(); + hidden = TRUE; + } + + pScreen->GetImage = pVMWARE->ScrnFuncs.GetImage; + (*pScreen->GetImage)(src, x, y, w, h, format, planeMask, pBinImage); + pScreen->GetImage = VMWAREGetImage; + + if (hidden) { + POST_OP_SHOW_CURSOR(); + } +} + +static void +VMWARECopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) +{ + ScreenPtr pScreen = pWin->drawable.pScreen; + VMWAREPtr pVMWARE = VMWAREPTR(infoFromScreen(pWin->drawable.pScreen)); + BoxPtr pBB; + Bool hidden = FALSE; + + /* + * We only worry about the source region here, since shadowfb will + * take care of the destination region. + */ + pBB = REGION_EXTENTS(pWin->drawable.pScreen, prgnSrc); + + VmwareLog(("VMWARECopyWindow(%p, (%d, %d), (%d, %d - %d, %d)\n", + pWin, ptOldOrg.x, ptOldOrg.y, + pBB->x1, pBB->y1, pBB->x2, pBB->y2)); + + if (BOX_INTERSECT(*pBB, pVMWARE->hwcur.box)) { + PRE_OP_HIDE_CURSOR(); + hidden = TRUE; + } + + pScreen->CopyWindow = pVMWARE->ScrnFuncs.CopyWindow; + (*pScreen->CopyWindow)(pWin, ptOldOrg, prgnSrc); + pScreen->CopyWindow = VMWARECopyWindow; + + if (hidden) { + POST_OP_SHOW_CURSOR(); + } +} + +#ifdef RENDER +static void +VMWAREComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask, + PicturePtr pDst, INT16 xSrc, INT16 ySrc, + INT16 xMask, INT16 yMask, INT16 xDst, INT16 yDst, + CARD16 width, CARD16 height) +{ + ScreenPtr pScreen = pDst->pDrawable->pScreen; + VMWAREPtr pVMWARE = VMWAREPTR(infoFromScreen(pScreen)); + PictureScreenPtr ps = GetPictureScreen(pScreen); + BoxRec box; + Bool hidden = FALSE; + + VmwareLog(("VMWAREComposite op = %d, pSrc = %p, pMask = %p, pDst = %p," + " src = (%d, %d), mask = (%d, %d), dst = (%d, %d), w = %d," + " h = %d\n", op, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask, + xDst, yDst, width, height)); + + /* + * We only worry about the source region here, since shadowfb or XAA will + * take care of the destination region. + */ + box.x1 = pSrc->pDrawable->x + xSrc; + box.y1 = pSrc->pDrawable->y + ySrc; + box.x2 = box.x1 + width; + box.y2 = box.y1 + height; + + if (BOX_INTERSECT(box, pVMWARE->hwcur.box)) { + PRE_OP_HIDE_CURSOR(); + hidden = TRUE; + } + + ps->Composite = pVMWARE->Composite; + (*ps->Composite)(op, pSrc, pMask, pDst, xSrc, ySrc, + xMask, yMask, xDst, yDst, width, height); + ps->Composite = VMWAREComposite; + + if (hidden) { + POST_OP_SHOW_CURSOR(); + } +} +#endif /* RENDER */ diff --git a/driver/xf86-video-vmware/src/vmwarexaa.c b/driver/xf86-video-vmware/src/vmwarexaa.c new file mode 100644 index 000000000..b0882c5f5 --- /dev/null +++ b/driver/xf86-video-vmware/src/vmwarexaa.c @@ -0,0 +1,589 @@ +/* ********************************************************** + * Copyright (C) 1998-2001 VMware, Inc. + * All Rights Reserved + * **********************************************************/ +#ifdef VMX86_DEVEL +char rcsId_vmwarexaa[] = + "Id: $"; +#endif +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/vmware/vmwarexaa.c,v 1.5 2003/02/04 01:39:53 dawes Exp $ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "vmware.h" + +#define OFFSCREEN_SCRATCH_SIZE 1*1024*1024 +/* We'll assume we average about 32x32 alpha surfaces (4096 bytes) or larger */ +#define OFFSCREEN_SCRATCH_MAX_SLOTS OFFSCREEN_SCRATCH_SIZE / 4096 + +const char *vmwareXaaSymbols[] = { + "XAACreateInfoRec", + "XAADestroyInfoRec", + "XAAInit", + NULL +}; + +static void vmwareXAASync(ScrnInfoPtr pScrn); + +static void vmwareSetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop, + unsigned int planemask); +static void vmwareSubsequentSolidFillRect(ScrnInfoPtr pScrn, + int x, int y, int w, int h); + +static void vmwareSetupForScreenToScreenCopy(ScrnInfoPtr pScrn, + int xdir, int ydir, int rop, + unsigned int planemask, + int trans_color); +static void vmwareSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, + int x1, int y1, + int x2, int y2, + int width, int height); + +static void vmwareSetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, + int fg, int bg, + int rop, + unsigned int planemask); +static void vmwareSubsequentScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, + int x, int y, + int w, int h, + int skipleft ); +static void vmwareSubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno); + +#ifdef RENDER +static Bool vmwareSetupForCPUToScreenAlphaTexture(ScrnInfoPtr pScrn, int op, + CARD16 red, CARD16 green, + CARD16 blue, CARD16 alpha, + int alphaType, CARD8 *alphaPtr, + int alphaPitch, + int width, int height, + int flags); + +static Bool vmwareSetupForCPUToScreenTexture(ScrnInfoPtr pScrn, int op, + int texType, CARD8 *texPtr, + int texPitch, + int width, int height, + int flags); + +static void vmwareSubsequentCPUToScreenTexture(ScrnInfoPtr pScrn, + int dstx, int dsty, + int srcx, int srcy, + int width, int height); + +static void vmwareXAAEnableDisableFBAccess(int index, Bool enable); + +CARD32 vmwareAlphaTextureFormats[2] = {PICT_a8, 0}; +CARD32 vmwareTextureFormats[2] = {PICT_a8r8g8b8, 0}; + +#endif + +#define SCRATCH_SIZE_BYTES(pvmware) \ + (((OFFSCREEN_SCRATCH_SIZE + (pvmware)->fbPitch - 1) / \ + (pvmware)->fbPitch) * (pvmware)->fbPitch) + +static void vmwareXAACreateHeap(ScreenPtr pScreen, ScrnInfoPtr pScrn, + VMWAREPtr pVMWARE) { + int scratchSizeBytes = SCRATCH_SIZE_BYTES(pVMWARE); + CARD8* osPtr = pVMWARE->FbBase + pVMWARE->videoRam - scratchSizeBytes; + + pVMWARE->heap = vmwareHeap_Create(osPtr, + scratchSizeBytes, + OFFSCREEN_SCRATCH_MAX_SLOTS, + pVMWARE->videoRam - scratchSizeBytes, + pScrn->virtualX, + pScrn->virtualY, + pVMWARE->bitsPerPixel, + pVMWARE->fbPitch, + pVMWARE->fbOffset); + pVMWARE->frontBuffer = vmwareHeap_GetFrontBuffer(pVMWARE->heap); +} + +#define DESTROY_XAA_INFO(pVMWARE) \ + if (pVMWARE->xaaInfo) { XAADestroyInfoRec(pVMWARE->xaaInfo); \ + pVMWARE->xaaInfo = NULL; } + +Bool +vmwareXAAScreenInit(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + XAAInfoRecPtr xaaInfo; + + pVMWARE->xaaInfo = XAACreateInfoRec(); + if (!pVMWARE->xaaInfo) { + return FALSE; + } + + xaaInfo = pVMWARE->xaaInfo; + + xaaInfo->Sync = vmwareXAASync; + + if (pVMWARE->vmwareCapability & SVGA_CAP_RECT_FILL) { + xaaInfo->SetupForSolidFill = vmwareSetupForSolidFill; + xaaInfo->SubsequentSolidFillRect = vmwareSubsequentSolidFillRect; + + xaaInfo->SolidFillFlags = NO_PLANEMASK | + (pVMWARE->vmwareCapability & SVGA_CAP_RASTER_OP ? 0 : GXCOPY_ONLY); + } + + if (pVMWARE->vmwareCapability & SVGA_CAP_RECT_COPY) { + xaaInfo->SetupForScreenToScreenCopy = vmwareSetupForScreenToScreenCopy; + xaaInfo->SubsequentScreenToScreenCopy = + vmwareSubsequentScreenToScreenCopy; + + xaaInfo->ScreenToScreenCopyFlags = NO_TRANSPARENCY | NO_PLANEMASK | + (pVMWARE->vmwareCapability & SVGA_CAP_RASTER_OP ? 0 : GXCOPY_ONLY); + } + + /* + * We don't support SVGA_CAP_GLYPH without clipping, since we use clipping + * for normal glyphs. + */ + if (pVMWARE->vmwareCapability & SVGA_CAP_GLYPH_CLIPPING) { + xaaInfo->SetupForScanlineCPUToScreenColorExpandFill = + vmwareSetupForScanlineCPUToScreenColorExpandFill; + xaaInfo->SubsequentScanlineCPUToScreenColorExpandFill = + vmwareSubsequentScanlineCPUToScreenColorExpandFill; + xaaInfo->SubsequentColorExpandScanline = + vmwareSubsequentColorExpandScanline; + + xaaInfo->NumScanlineColorExpandBuffers = 1; + xaaInfo->ScanlineColorExpandBuffers = pVMWARE->xaaColorExpScanLine; + + xaaInfo->ScanlineCPUToScreenColorExpandFillFlags = GXCOPY_ONLY | + NO_PLANEMASK | BIT_ORDER_IN_BYTE_MSBFIRST | LEFT_EDGE_CLIPPING; + } + + if (pVMWARE->vmwareCapability & SVGA_CAP_OFFSCREEN_1) { + int scratchSizeBytes = SCRATCH_SIZE_BYTES(pVMWARE); + BoxRec box; + RegionRec region; + + box.x1 = 0; + box.y1 = (pVMWARE->FbSize + pVMWARE->fbPitch - 1) / pVMWARE->fbPitch; + box.x2 = pScrn->displayWidth; + box.y2 = pVMWARE->videoRam / pVMWARE->fbPitch; + +#ifdef RENDER + if (pVMWARE->vmwareCapability & SVGA_CAP_ALPHA_BLEND && + pScrn->bitsPerPixel > 8) { + if (box.y2 - (scratchSizeBytes / pVMWARE->fbPitch) > box.y1 + 4) { + box.y2 -= scratchSizeBytes / pVMWARE->fbPitch; + + VmwareLog(("Allocated %d bytes at offset %d for alpha scratch\n", + scratchSizeBytes, + pVMWARE->videoRam - scratchSizeBytes)); + + vmwareXAACreateHeap(pScreen, pScrn, pVMWARE); + + xaaInfo->SetupForCPUToScreenAlphaTexture = + vmwareSetupForCPUToScreenAlphaTexture; + xaaInfo->SubsequentCPUToScreenAlphaTexture = + vmwareSubsequentCPUToScreenTexture; + xaaInfo->CPUToScreenAlphaTextureFlags = XAA_RENDER_NO_TILE | + XAA_RENDER_NO_SRC_ALPHA; + xaaInfo->CPUToScreenAlphaTextureFormats = vmwareAlphaTextureFormats; + + xaaInfo->SetupForCPUToScreenTexture = + vmwareSetupForCPUToScreenTexture; + xaaInfo->SubsequentCPUToScreenTexture = + vmwareSubsequentCPUToScreenTexture; + xaaInfo->CPUToScreenTextureFlags = XAA_RENDER_NO_TILE; + xaaInfo->CPUToScreenTextureFormats = vmwareTextureFormats; + } else { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Allocation of offscreen " + "scratch area for alpha blending failed\n"); + } + } +#endif + + if (box.y2 > box.y1) { + REGION_INIT(pScreen, ®ion, &box, 1); + + if (REGION_NOTEMPTY(pScreen, ®ion) && + xf86InitFBManagerRegion(pScreen, ®ion)) { + VmwareLog(("Offscreen memory initialized: (%d, %d) - (%d, %d)\n", + box.x1, box.y1, box.x2, box.y2)); + + xaaInfo->Flags = + LINEAR_FRAMEBUFFER | PIXMAP_CACHE | OFFSCREEN_PIXMAPS; + } else { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Offscreen memory manager " + "initialization failed.\n"); + } + + REGION_UNINIT(pScreen, ®ion); + } + } + + if (!XAAInit(pScreen, xaaInfo)) { + DESTROY_XAA_INFO(pVMWARE); + return FALSE; + } + +#ifdef RENDER + if (pVMWARE->heap) { + pVMWARE->EnableDisableFBAccess = pScrn->EnableDisableFBAccess; + pScrn->EnableDisableFBAccess = vmwareXAAEnableDisableFBAccess; + } +#endif + + return TRUE; +} + +Bool +vmwareXAAModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + /* + * Alloc a sufficiently large buffer for XAA to render scanlines + * for a color expand into. + */ + if (pVMWARE->vmwareCapability & SVGA_CAP_GLYPH) { + /* + * This formula came straight from the XAA.HOWTO doc. The +62 is + * there because we potentially have 31 extra bits off to the left, + * since we claim LEFT_EDGE_CLIPPING support. + */ + int scanLineSize = ((pScrn->virtualX + 62)/32) * 4; + if (pVMWARE->xaaColorExpScanLine[0]) { + xfree(pVMWARE->xaaColorExpScanLine[0]); + } + pVMWARE->xaaColorExpScanLine[0] = xalloc(scanLineSize); + return pVMWARE->xaaColorExpScanLine[0] != NULL; + } + + return TRUE; +} + +void +vmwareXAACloseScreen(ScreenPtr pScreen) +{ + VMWAREPtr pVMWARE = VMWAREPTR(xf86Screens[pScreen->myNum]); + + if (pVMWARE->xaaColorExpScanLine[0]) { + xfree(pVMWARE->xaaColorExpScanLine[0]); + pVMWARE->xaaColorExpScanLine[0] = NULL; + } + + DESTROY_XAA_INFO(pVMWARE); + +#ifdef RENDER + if (pVMWARE->heap) { + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + pScrn->EnableDisableFBAccess = pVMWARE->EnableDisableFBAccess; + vmwareHeap_Destroy(pVMWARE->heap); + pVMWARE->heap = NULL; + } +#endif +} + +static void +vmwareXAASync(ScrnInfoPtr pScrn) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + VmwareLog(("Sync\n")); + + vmwareWaitForFB(pVMWARE); + +#ifdef RENDER + if (pVMWARE->heap) { + vmwareHeap_Clear(pVMWARE->heap); + } +#endif +} + +static void +vmwareSetupForSolidFill(ScrnInfoPtr pScrn, + int color, int rop, unsigned int planemask) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + pVMWARE->xaaFGColor = color; + pVMWARE->xaaRop = rop; + + VmwareLog(("Setup Solid Fill (color = %d, rop = %d)\n", color, rop)); +} + +static void +vmwareSubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + VmwareLog((" Do Solid Fill (x = %d, y = %d, w = %d, h = %d)\n", x, y, w, h)); + + if (pVMWARE->xaaRop != GXcopy) { + /* + * We'll never get here if SVGA_CAP_RASTER_OP isn't set, since + * we tell XAA we are GXCOPY_ONLY. + */ + vmwareWriteWordToFIFO(pVMWARE, SVGA_CMD_RECT_ROP_FILL); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->xaaFGColor); + vmwareWriteWordToFIFO(pVMWARE, x); + vmwareWriteWordToFIFO(pVMWARE, y); + vmwareWriteWordToFIFO(pVMWARE, w); + vmwareWriteWordToFIFO(pVMWARE, h); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->xaaRop); + } else { + vmwareWriteWordToFIFO(pVMWARE, SVGA_CMD_RECT_FILL); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->xaaFGColor); + vmwareWriteWordToFIFO(pVMWARE, x); + vmwareWriteWordToFIFO(pVMWARE, y); + vmwareWriteWordToFIFO(pVMWARE, w); + vmwareWriteWordToFIFO(pVMWARE, h); + } +} + +static void +vmwareSetupForScreenToScreenCopy(ScrnInfoPtr pScrn, + int xdir, int ydir, int rop, + unsigned int planemask, + int trans_color) +{ + /* + * We can safely ignore xdir and ydir since our "hardware" is smart + * enough to figure out the direction from the srcx/y, dstx/y, w and h. + */ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + pVMWARE->xaaRop = rop; + + VmwareLog(("Setup Screen2Screen copy (rop = %d)\n", rop)); +} + +static void +vmwareSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, + int x1, int y1, + int x2, int y2, + int width, int height) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + VmwareLog((" Do Screen2Screen copy (x1 = %d, y1 = %d, x2 = %d, y2 = %d," + " w = %d, h = %d)\n", x1, y1, x2, y2, width, height)); + + if (pVMWARE->xaaRop != GXcopy) { + /* + * We'll never get here if SVGA_CAP_RASTER_OP isn't set, since + * we tell XAA we are GXCOPY_ONLY. + */ + vmwareWriteWordToFIFO(pVMWARE, SVGA_CMD_RECT_ROP_COPY); + vmwareWriteWordToFIFO(pVMWARE, x1); + vmwareWriteWordToFIFO(pVMWARE, y1); + vmwareWriteWordToFIFO(pVMWARE, x2); + vmwareWriteWordToFIFO(pVMWARE, y2); + vmwareWriteWordToFIFO(pVMWARE, width); + vmwareWriteWordToFIFO(pVMWARE, height); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->xaaRop); + } else { + vmwareWriteWordToFIFO(pVMWARE, SVGA_CMD_RECT_COPY); + vmwareWriteWordToFIFO(pVMWARE, x1); + vmwareWriteWordToFIFO(pVMWARE, y1); + vmwareWriteWordToFIFO(pVMWARE, x2); + vmwareWriteWordToFIFO(pVMWARE, y2); + vmwareWriteWordToFIFO(pVMWARE, width); + vmwareWriteWordToFIFO(pVMWARE, height); + } +} + +static void +vmwareSetupForScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, + int fg, int bg, + int rop, + unsigned int planemask) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + pVMWARE->xaaFGColor = fg; + pVMWARE->xaaBGColor = bg; + VmwareLog(("Setup color expand (fg = %d, bg = %d, rop = %d)\n", + fg, bg, rop)); +} + +static void +vmwareSubsequentScanlineCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, + int x, int y, + int w, int h, + int skipleft ) +{ + /* + * XXX TODO: if xaaColorExpSize will fit entirely into the FIFO, + * temporarily switch to direct mode, and have XAA write bits + * directly into the fifo. See ATI driver for an example. + */ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + pVMWARE->xaaColorExpSize = SVGA_GLYPH_SCANLINE_SIZE_DWORDS(w); + + VmwareLog((" Do color expand (x = %d, y = %d, w = %d, h = %d," + " skipleft = %d, sizedw = %d)\n", + x, y, w, h, skipleft, pVMWARE->xaaColorExpSize)); + + vmwareWriteWordToFIFO(pVMWARE, SVGA_CMD_DRAW_GLYPH_CLIPPED); + vmwareWriteWordToFIFO(pVMWARE, x); + vmwareWriteWordToFIFO(pVMWARE, y); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->xaaColorExpSize * 32U); + vmwareWriteWordToFIFO(pVMWARE, h); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->xaaFGColor); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->xaaBGColor); + vmwareWriteWordToFIFO(pVMWARE, x + skipleft); + vmwareWriteWordToFIFO(pVMWARE, y); + vmwareWriteWordToFIFO(pVMWARE, w - skipleft); + vmwareWriteWordToFIFO(pVMWARE, h); +} + +static void +vmwareSubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + CARD32* scanLine = (CARD32*)pVMWARE->xaaColorExpScanLine[0]; + unsigned int dwords = pVMWARE->xaaColorExpSize; + + while (dwords--) { + vmwareWriteWordToFIFO(pVMWARE, *scanLine++); + } +} + +#ifdef RENDER + +static void +RGBPlusAlphaChannelToPremultipliedRGBA( + CARD8 red, CARD8 green, CARD8 blue, + CARD8 *alphaPtr, /* in bytes */ + int alphaPitch, + CARD32 *dstPtr, + int dstPitch, /* in dwords */ + int width, int height) +{ + int x; + + while (height--) { + for (x = 0; x < width; x++) { + CARD8 alpha = alphaPtr[x]; + dstPtr[x] = (alpha << 24) | + ((red * alpha / 255) << 16) | + ((green * alpha / 255) << 8) | + (blue * alpha / 255); + } + dstPtr += dstPitch; + alphaPtr += alphaPitch; + } +} + +Bool +vmwareSetupForCPUToScreenAlphaTexture(ScrnInfoPtr pScrn, int op, + CARD16 red, CARD16 green, + CARD16 blue, CARD16 alpha, + int alphaType, CARD8 *alphaPtr, + int alphaPitch, + int width, int height, + int flags) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + SVGASurface* surf; + + VmwareLog(("Setup alpha texture (op = %d, r = %d, g = %d, b = %d," + " a = %d, alphaType = %d, alphaPitch = %d, w = %d, h = %d," + " flags = %d)\n", op, red, green, blue, alpha, alphaType, + alphaPitch, width, height, flags)); + + if (op > PictOpSaturate) { + return FALSE; + } + + surf = vmwareHeap_AllocSurface(pVMWARE->heap, width, height, width * 4, 32); + + if (!surf) { + return FALSE; + } + + RGBPlusAlphaChannelToPremultipliedRGBA( + red >> 8, green >> 8, blue >> 8, + alphaPtr, alphaPitch, + (CARD32*)(pVMWARE->FbBase + surf->dataOffset), + width, width, height); + + pVMWARE->curPict = surf; + pVMWARE->op = op; + + return TRUE; +} + +Bool +vmwareSetupForCPUToScreenTexture(ScrnInfoPtr pScrn, int op, + int texType, CARD8 *texPtr, + int texPitch, + int width, int height, + int flags) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + SVGASurface* surf; + + VmwareLog(("Setup texture (op = %d, texType = %d, texPitch = %d," + " w = %d, h = %d, flags = %d)\n", op, texType, texPitch, + width, height, flags)); + + if (op > PictOpSaturate) { + return FALSE; + } + + surf = vmwareHeap_AllocSurface(pVMWARE->heap, width, height, texPitch, 32); + + if (!surf) { + return FALSE; + } + + memcpy(pVMWARE->FbBase + surf->dataOffset, texPtr, texPitch * height); + + pVMWARE->curPict = surf; + pVMWARE->op = op; + + return TRUE; +} + +void +vmwareSubsequentCPUToScreenTexture(ScrnInfoPtr pScrn, + int dstx, int dsty, + int srcx, int srcy, + int width, int height) +{ + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + VmwareLog((" Do texture (dstx = %d, dsty = %d, srcx = %d, srcy = %d" + " w = %d, h = %d)\n", dstx, dsty, srcx, srcy, width, height)); + + pVMWARE->curPict->numQueued++; + pVMWARE->frontBuffer->numQueued++; + + vmwareWriteWordToFIFO(pVMWARE, SVGA_CMD_SURFACE_ALPHA_BLEND); + vmwareWriteWordToFIFO(pVMWARE, (CARD8*)pVMWARE->curPict - pVMWARE->FbBase); + vmwareWriteWordToFIFO(pVMWARE, (CARD8*)pVMWARE->frontBuffer - pVMWARE->FbBase); + vmwareWriteWordToFIFO(pVMWARE, srcx); + vmwareWriteWordToFIFO(pVMWARE, srcy); + vmwareWriteWordToFIFO(pVMWARE, dstx); + vmwareWriteWordToFIFO(pVMWARE, dsty); + vmwareWriteWordToFIFO(pVMWARE, width); + vmwareWriteWordToFIFO(pVMWARE, height); + vmwareWriteWordToFIFO(pVMWARE, pVMWARE->op); + vmwareWriteWordToFIFO(pVMWARE, 0); /* flags */ + vmwareWriteWordToFIFO(pVMWARE, 0); /* param1 */ + vmwareWriteWordToFIFO(pVMWARE, 0); /* param2 */ +} + +void +vmwareXAAEnableDisableFBAccess(int index, Bool enable) +{ + ScrnInfoPtr pScrn = xf86Screens[index]; + ScreenPtr pScreen = pScrn->pScreen; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + if (enable && pVMWARE->heap) { + vmwareHeap_Destroy(pVMWARE->heap); + vmwareXAACreateHeap(pScreen, pScrn, pVMWARE); + } + + (*pVMWARE->EnableDisableFBAccess)(index, enable); +} + +#endif diff --git a/driver/xf86-video-vmware/src/vmwarexinerama.c b/driver/xf86-video-vmware/src/vmwarexinerama.c new file mode 100644 index 000000000..204bade91 --- /dev/null +++ b/driver/xf86-video-vmware/src/vmwarexinerama.c @@ -0,0 +1,691 @@ +/* + * Copyright 2006 by VMware, 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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 the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +/* + * vmwarexinerama.c -- + * + * The implementation of the Xinerama protocol extension. + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#define NEED_REPLIES +#define NEED_EVENTS +#include "dixstruct.h" +#include "extnsionst.h" +#include <X11/X.h> +#include <X11/extensions/panoramiXproto.h> + +#include "vmware.h" + + +/* + *---------------------------------------------------------------------------- + * + * VMwareXineramaQueryVersion -- + * + * Implementation of QueryVersion command handler. Initialises and + * sends a reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client. + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareXineramaQueryVersion(ClientPtr client) +{ + xPanoramiXQueryVersionReply rep; + register int n; + + REQUEST_SIZE_MATCH(xPanoramiXQueryVersionReq); + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.majorVersion = 1; + rep.minorVersion = 0; + if(client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swaps(&rep.majorVersion, n); + swaps(&rep.minorVersion, n); + } + WriteToClient(client, sizeof(xPanoramiXQueryVersionReply), (char *)&rep); + return (client->noClientException); +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareXineramaGetState -- + * + * Implementation of GetState command handler. Initialises and + * sends a reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client. + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareXineramaGetState(ClientPtr client) +{ + REQUEST(xPanoramiXGetStateReq); + WindowPtr pWin; + xPanoramiXGetStateReply rep; + register int n; + ExtensionEntry *ext; + ScrnInfoPtr pScrn; + VMWAREPtr pVMWARE; + + REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); + pWin = LookupWindow(stuff->window, client); + if(!pWin) return BadWindow; + + if (!(ext = CheckExtension(PANORAMIX_PROTOCOL_NAME))) { + return BadMatch; + } + pScrn = ext->extPrivate; + pVMWARE = VMWAREPTR(pScrn); + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.state = pVMWARE->xinerama; + if(client->swapped) { + swaps (&rep.sequenceNumber, n); + swapl (&rep.length, n); + swaps (&rep.state, n); + } + WriteToClient(client, sizeof(xPanoramiXGetStateReply), (char *)&rep); + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareXineramaGetScreenCount -- + * + * Implementation of GetScreenCount command handler. Initialises and + * sends a reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client. + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareXineramaGetScreenCount(ClientPtr client) +{ + REQUEST(xPanoramiXGetScreenCountReq); + WindowPtr pWin; + xPanoramiXGetScreenCountReply rep; + register int n; + ExtensionEntry *ext; + ScrnInfoPtr pScrn; + VMWAREPtr pVMWARE; + + REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); + pWin = LookupWindow(stuff->window, client); + if(!pWin) return BadWindow; + + if (!(ext = CheckExtension(PANORAMIX_PROTOCOL_NAME))) { + return BadMatch; + } + pScrn = ext->extPrivate; + pVMWARE = VMWAREPTR(pScrn); + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.ScreenCount = pVMWARE->xineramaNumOutputs; + if(client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swaps(&rep.ScreenCount, n); + } + WriteToClient(client, sizeof(xPanoramiXGetScreenCountReply), (char *)&rep); + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareXineramaGetScreenSize -- + * + * Implementation of GetScreenSize command handler. Initialises and + * sends a reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client. + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareXineramaGetScreenSize(ClientPtr client) +{ + REQUEST(xPanoramiXGetScreenSizeReq); + WindowPtr pWin; + xPanoramiXGetScreenSizeReply rep; + register int n; + ExtensionEntry *ext; + ScrnInfoPtr pScrn; + VMWAREPtr pVMWARE; + + REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); + pWin = LookupWindow (stuff->window, client); + if(!pWin) return BadWindow; + + if (!(ext = CheckExtension(PANORAMIX_PROTOCOL_NAME))) { + return BadMatch; + } + pScrn = ext->extPrivate; + pVMWARE = VMWAREPTR(pScrn); + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.width = pVMWARE->xineramaState[stuff->screen].width; + rep.height = pVMWARE->xineramaState[stuff->screen].height; + if(client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swaps(&rep.width, n); + swaps(&rep.height, n); + } + WriteToClient(client, sizeof(xPanoramiXGetScreenSizeReply), (char *)&rep); + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareXineramaIsActive -- + * + * Implementation of IsActive command handler. Initialises and + * sends a reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client. + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareXineramaIsActive(ClientPtr client) +{ + xXineramaIsActiveReply rep; + ExtensionEntry *ext; + ScrnInfoPtr pScrn; + VMWAREPtr pVMWARE; + + REQUEST_SIZE_MATCH(xXineramaIsActiveReq); + + if (!(ext = CheckExtension(PANORAMIX_PROTOCOL_NAME))) { + return BadMatch; + } + pScrn = ext->extPrivate; + pVMWARE = VMWAREPTR(pScrn); + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.state = pVMWARE->xinerama; + if(client->swapped) { + register int n; + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.state, n); + } + WriteToClient(client, sizeof(xXineramaIsActiveReply), (char *) &rep); + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareXineramaQueryScreens -- + * + * Implementation of QueryScreens command handler. Initialises and + * sends a reply. + * + * Results: + * Standard response codes. + * + * Side effects: + * Writes reply to client. + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareXineramaQueryScreens(ClientPtr client) +{ + xXineramaQueryScreensReply rep; + ExtensionEntry *ext; + ScrnInfoPtr pScrn; + VMWAREPtr pVMWARE; + + REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); + + if (!(ext = CheckExtension(PANORAMIX_PROTOCOL_NAME))) { + return BadMatch; + } + pScrn = ext->extPrivate; + pVMWARE = VMWAREPTR(pScrn); + + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.number = pVMWARE->xinerama ? pVMWARE->xineramaNumOutputs : 0; + rep.length = rep.number * sz_XineramaScreenInfo >> 2; + if(client->swapped) { + register int n; + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.number, n); + } + WriteToClient(client, sizeof(xXineramaQueryScreensReply), (char *)&rep); + + if(pVMWARE->xinerama) { + xXineramaScreenInfo scratch; + int i; + + for(i = 0; i < pVMWARE->xineramaNumOutputs; i++) { + scratch.x_org = pVMWARE->xineramaState[i].x_org; + scratch.y_org = pVMWARE->xineramaState[i].y_org; + scratch.width = pVMWARE->xineramaState[i].width; + scratch.height = pVMWARE->xineramaState[i].height; + if(client->swapped) { + register int n; + swaps(&scratch.x_org, n); + swaps(&scratch.y_org, n); + swaps(&scratch.width, n); + swaps(&scratch.height, n); + } + WriteToClient(client, sz_XineramaScreenInfo, (char *)&scratch); + } + } + + return client->noClientException; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareXineramaDispatch -- + * + * Dispatcher for Xinerama commands. Calls the correct handler for + * each command type. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of individual command handlers. + * + *---------------------------------------------------------------------------- + */ + +static int +VMwareXineramaDispatch(ClientPtr client) +{ + REQUEST(xReq); + switch (stuff->data) { + case X_PanoramiXQueryVersion: + return VMwareXineramaQueryVersion(client); + case X_PanoramiXGetState: + return VMwareXineramaGetState(client); + case X_PanoramiXGetScreenCount: + return VMwareXineramaGetScreenCount(client); + case X_PanoramiXGetScreenSize: + return VMwareXineramaGetScreenSize(client); + case X_XineramaIsActive: + return VMwareXineramaIsActive(client); + case X_XineramaQueryScreens: + return VMwareXineramaQueryScreens(client); + } + return BadRequest; +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareXineramaQueryVersion -- + * + * Wrapper for QueryVersion handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareXineramaQueryVersion (ClientPtr client) +{ + REQUEST(xPanoramiXQueryVersionReq); + register int n; + swaps(&stuff->length,n); + REQUEST_SIZE_MATCH (xPanoramiXQueryVersionReq); + return VMwareXineramaQueryVersion(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareXineramaGetState -- + * + * Wrapper for GetState handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareXineramaGetState(ClientPtr client) +{ + REQUEST(xPanoramiXGetStateReq); + register int n; + swaps (&stuff->length, n); + REQUEST_SIZE_MATCH(xPanoramiXGetStateReq); + return VMwareXineramaGetState(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareXineramaGetScreenCount -- + * + * Wrapper for GetScreenCount handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareXineramaGetScreenCount(ClientPtr client) +{ + REQUEST(xPanoramiXGetScreenCountReq); + register int n; + swaps (&stuff->length, n); + REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq); + return VMwareXineramaGetScreenCount(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareXineramaGetScreenSize -- + * + * Wrapper for GetScreenSize handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareXineramaGetScreenSize(ClientPtr client) +{ + REQUEST(xPanoramiXGetScreenSizeReq); + register int n; + swaps (&stuff->length, n); + REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq); + return VMwareXineramaGetScreenSize(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareXineramaIsActive -- + * + * Wrapper for IsActive handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareXineramaIsActive(ClientPtr client) +{ + REQUEST(xXineramaIsActiveReq); + register int n; + swaps (&stuff->length, n); + REQUEST_SIZE_MATCH(xXineramaIsActiveReq); + return VMwareXineramaIsActive(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareXineramaQueryScreens -- + * + * Wrapper for QueryScreens handler that handles input from other-endian + * clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of unswapped implementation. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareXineramaQueryScreens(ClientPtr client) +{ + REQUEST(xXineramaQueryScreensReq); + register int n; + swaps (&stuff->length, n); + REQUEST_SIZE_MATCH(xXineramaQueryScreensReq); + return VMwareXineramaQueryScreens(client); +} + + +/* + *---------------------------------------------------------------------------- + * + * SVMwareXineramaDispatch -- + * + * Wrapper for dispatcher that handles input from other-endian clients. + * + * Results: + * Standard response codes. + * + * Side effects: + * Side effects of individual command handlers. + * + *---------------------------------------------------------------------------- + */ + +static int +SVMwareXineramaDispatch(ClientPtr client) +{ + REQUEST(xReq); + switch (stuff->data) { + case X_PanoramiXQueryVersion: + return SVMwareXineramaQueryVersion(client); + case X_PanoramiXGetState: + return SVMwareXineramaGetState(client); + case X_PanoramiXGetScreenCount: + return SVMwareXineramaGetScreenCount(client); + case X_PanoramiXGetScreenSize: + return SVMwareXineramaGetScreenSize(client); + case X_XineramaIsActive: + return SVMwareXineramaIsActive(client); + case X_XineramaQueryScreens: + return SVMwareXineramaQueryScreens(client); + } + return BadRequest; +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareXineramaResetProc -- + * + * Cleanup handler called when the extension is removed. + * + * Results: + * None + * + * Side effects: + * None + * + *---------------------------------------------------------------------------- + */ + +static void +VMwareXineramaResetProc(ExtensionEntry* extEntry) +{ + /* Called by CloseDownExtensions() */ + + ScrnInfoPtr pScrn = extEntry->extPrivate; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + + if (pVMWARE->xineramaState) { + xfree(pVMWARE->xineramaState); + pVMWARE->xineramaState = NULL; + pVMWARE->xineramaNumOutputs = 0; + pVMWARE->xinerama = FALSE; + } +} + + +/* + *---------------------------------------------------------------------------- + * + * VMwareCtrl_ExitInit -- + * + * Initialiser for the Xinerama protocol extension. + * + * Results: + * None. + * + * Side effects: + * Protocol extension will be registered if successful. + * + *---------------------------------------------------------------------------- + */ + +void +VMwareXinerama_ExtInit(ScrnInfoPtr pScrn) +{ + ExtensionEntry *myext; + VMWAREPtr pVMWARE = VMWAREPTR(pScrn); + +#ifdef PANORAMIX + if(!noPanoramiXExtension) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Built-in Xinerama active, not initializing VMware Xinerama\n"); + pVMWARE->xinerama = FALSE; + return; + } +#endif + + if (!(myext = CheckExtension(PANORAMIX_PROTOCOL_NAME))) { + if (!(myext = AddExtension(PANORAMIX_PROTOCOL_NAME, 0, 0, + VMwareXineramaDispatch, + SVMwareXineramaDispatch, + VMwareXineramaResetProc, + StandardMinorOpcode))) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed to add VMware Xinerama extension.\n"); + return; + } + + pVMWARE->xinerama = TRUE; + + myext->extPrivate = pScrn; + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Initialized VMware Xinerama extension.\n"); + } +} |