diff --git a/.appveyor.yml b/.appveyor.yml index de77a96d9..ee076bf43 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -73,7 +73,7 @@ cache: - '%CYGWIN_ROOT%\home\%USERNAME%\.ccache' build_script: - SET PATH=%CYGWIN_ROOT%/bin -- '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; meson setup --prefix=/usr -Dxv=false -Dxf86bigfont=true -Dxephyr=true -Dxvfb=true -Dxorg=true -Dpciaccess=false -Dint10=false -Dglamor=false build"' +- '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; meson setup --prefix=/usr -Dxv=false -Dxf86bigfont=true -Dxephyr=true -Dxvfb=true -Dglamor=false build"' - '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; meson configure build"' - '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ninja -C build"' - '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ccache -s"' diff --git a/Xext/meson.build b/Xext/meson.build index 0600fe98b..bb90e195d 100644 --- a/Xext/meson.build +++ b/Xext/meson.build @@ -73,7 +73,3 @@ libxserver_xext_vidmode = static_library('libxserver_xext_vidmode', include_directories: inc, dependencies: common_dep, ) - -if build_xorg - install_data(hdrs_xext, install_dir: xorgsdkdir) -endif diff --git a/composite/meson.build b/composite/meson.build index 4f3303e20..fb0cb0916 100644 --- a/composite/meson.build +++ b/composite/meson.build @@ -15,7 +15,3 @@ libxserver_composite = static_library('libxserver_composite', include_directories: inc, dependencies: common_dep, ) - -if build_xorg - install_data(hdrs_composite, install_dir: xorgsdkdir) -endif diff --git a/config/meson.build b/config/meson.build index 2b5ab18bb..a98c2c524 100644 --- a/config/meson.build +++ b/config/meson.build @@ -22,14 +22,3 @@ endif if host_machine.system() == 'openbsd' srcs_config += 'wscons.c' endif - -if build_xorg - install_data('10-quirks.conf', - install_dir: join_paths(get_option('datadir'), 'X11/xorg.conf.d')) -endif - -libxserver_config = static_library('libxserver_config', - srcs_config, - include_directories: inc, - dependencies: config_dep, -) diff --git a/dbe/meson.build b/dbe/meson.build index 2aa595aa3..0d9189893 100644 --- a/dbe/meson.build +++ b/dbe/meson.build @@ -12,7 +12,3 @@ libxserver_dbe = static_library('libxserver_dbe', include_directories: inc, dependencies: common_dep, ) - -if build_xorg - install_data(hdrs_dbe, install_dir: xorgsdkdir) -endif diff --git a/dri3/meson.build b/dri3/meson.build index 91bd68d87..319dc1c9e 100644 --- a/dri3/meson.build +++ b/dri3/meson.build @@ -16,7 +16,3 @@ if build_dri3 dependencies: [ common_dep, libdrm_dep ], ) endif - -if build_xorg - install_data(hdrs_dri3, install_dir: xorgsdkdir) -endif diff --git a/exa/meson.build b/exa/meson.build index 832363d27..a3b7aea8c 100644 --- a/exa/meson.build +++ b/exa/meson.build @@ -16,9 +16,4 @@ libxserver_exa = static_library('libxserver_exa', srcs_exa, include_directories: inc, dependencies: common_dep, - c_args: '-DHAVE_XORG_CONFIG_H' ) - -if build_xorg - install_data('exa.h', install_dir: xorgsdkdir) -endif diff --git a/fb/meson.build b/fb/meson.build index 1d8d259a1..2cb766e89 100644 --- a/fb/meson.build +++ b/fb/meson.build @@ -53,7 +53,3 @@ libxserver_wfb = static_library('libxserver_wfb', pic: true, build_by_default: false, ) - -if build_xorg - install_data(hdrs_fb, install_dir: xorgsdkdir) -endif diff --git a/glamor/meson.build b/glamor/meson.build index 4a3f6241a..bb7ddd876 100644 --- a/glamor/meson.build +++ b/glamor/meson.build @@ -53,7 +53,3 @@ glamor_egl_stubs = static_library('glamor_egl_stubs', include_directories: inc, dependencies: common_dep, ) - -if build_xorg - install_data('glamor.h', install_dir: xorgsdkdir) -endif diff --git a/glx/meson.build b/glx/meson.build index 2ec00ce22..f71bc0dd8 100644 --- a/glx/meson.build +++ b/glx/meson.build @@ -51,7 +51,7 @@ if build_glx endif srcs_glxdri2 = [] -if build_dri2 or build_dri3 +if build_dri3 srcs_glxdri2 = files('glxdri2.c') endif @@ -78,8 +78,4 @@ if build_glx dependency('gl', version: '>= 1.2'), ], ) - - if build_xorg - install_data(hdrs_vnd, install_dir : xorgsdkdir) - endif endif diff --git a/hw/meson.build b/hw/meson.build index 98fb7d189..6fd83a6b9 100644 --- a/hw/meson.build +++ b/hw/meson.build @@ -6,10 +6,6 @@ if get_option('xvfb') subdir('vfb') endif -if build_xorg - subdir('xfree86') -endif - if build_xwayland subdir('xwayland') endif diff --git a/hw/xfree86/.gitignore b/hw/xfree86/.gitignore deleted file mode 100644 index c84c37ffb..000000000 --- a/hw/xfree86/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -Xorg -Xorg.wrap -Xorg.sh -xorg.conf.example -sdksyms.c -sdksyms.dep diff --git a/hw/xfree86/Xorg.sh.in b/hw/xfree86/Xorg.sh.in deleted file mode 100644 index 481413523..000000000 --- a/hw/xfree86/Xorg.sh.in +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# -# Execute Xorg.wrap if it exists otherwise execute Xorg directly. -# This allows distros to put the suid wrapper in a separate package. - -basedir=@SUID_WRAPPER_DIR@ -if [ -x "$basedir"/Xorg.wrap ]; then - exec "$basedir"/Xorg.wrap "$@" -else - exec "$basedir"/Xorg "$@" -fi diff --git a/hw/xfree86/common/.gitignore b/hw/xfree86/common/.gitignore deleted file mode 100644 index 817dfda8b..000000000 --- a/hw/xfree86/common/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Add & Override for this directory and its subdirectories -xf86Build.h -xf86DefModeSet.c diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h deleted file mode 100644 index eb788d3fd..000000000 --- a/hw/xfree86/common/compiler.h +++ /dev/null @@ -1,1097 +0,0 @@ -/* - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Thomas Roell not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Thomas Roell makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * Copyright (c) 1994-2003 by The XFree86 Project, 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). - */ - -#ifndef _COMPILER_H - -#define _COMPILER_H - -#if defined(__SUNPRO_C) -#define DO_PROTOTYPES -#endif - -/* Map Sun compiler platform defines to gcc-style used in the code */ -#if defined(__amd64) && !defined(__amd64__) -#define __amd64__ -#endif -#if defined(__i386) && !defined(__i386__) -#define __i386__ -#endif -#if defined(__sparc) && !defined(__sparc__) -#define __sparc__ -#endif -#if defined(__sparcv9) && !defined(__sparc64__) -#define __sparc64__ -#endif - -#ifndef _X_EXPORT -#include -#endif - -#include /* for uint*_t types */ - -/* Allow drivers to use the GCC-supported __inline__ and/or __inline. */ -#ifndef __inline__ -#if defined(__GNUC__) - /* gcc has __inline__ */ -#else -#define __inline__ /**/ -#endif -#endif /* __inline__ */ -#ifndef __inline -#if defined(__GNUC__) - /* gcc has __inline */ -#else -#define __inline /**/ -#endif -#endif /* __inline */ -/* Support gcc's __FUNCTION__ for people using other compilers */ -#if !defined(__GNUC__) && !defined(__FUNCTION__) -#define __FUNCTION__ __func__ /* C99 */ -#endif - -#if defined(DO_PROTOTYPES) -#if !defined(__arm__) -#if !defined(__sparc__) && !defined(__arm32__) && !defined(__nds32__) \ - && !(defined(__alpha__) && defined(__linux__)) \ - && !(defined(__ia64__) && defined(__linux__)) \ - && !(defined(__mips64) && defined(__linux__)) \ - -extern _X_EXPORT void outb(unsigned short, unsigned char); -extern _X_EXPORT void outw(unsigned short, unsigned short); -extern _X_EXPORT void outl(unsigned short, unsigned int); -extern _X_EXPORT unsigned int inb(unsigned short); -extern _X_EXPORT unsigned int inw(unsigned short); -extern _X_EXPORT unsigned int inl(unsigned short); - -#else /* __sparc__, __arm32__, __alpha__, __nds32__ */ -extern _X_EXPORT void outb(unsigned long, unsigned char); -extern _X_EXPORT void outw(unsigned long, unsigned short); -extern _X_EXPORT void outl(unsigned long, unsigned int); -extern _X_EXPORT unsigned int inb(unsigned long); -extern _X_EXPORT unsigned int inw(unsigned long); -extern _X_EXPORT unsigned int inl(unsigned long); - -#ifdef __SUNPRO_C -extern _X_EXPORT unsigned char xf86ReadMmio8 (void *, unsigned long); -extern _X_EXPORT unsigned short xf86ReadMmio16Be (void *, unsigned long); -extern _X_EXPORT unsigned short xf86ReadMmio16Le (void *, unsigned long); -extern _X_EXPORT unsigned int xf86ReadMmio32Be (void *, unsigned long); -extern _X_EXPORT unsigned int xf86ReadMmio32Le (void *, unsigned long); -extern _X_EXPORT void xf86WriteMmio8 (void *, unsigned long, unsigned int); -extern _X_EXPORT void xf86WriteMmio16Be (void *, unsigned long, unsigned int); -extern _X_EXPORT void xf86WriteMmio16Le (void *, unsigned long, unsigned int); -extern _X_EXPORT void xf86WriteMmio32Be (void *, unsigned long, unsigned int); -extern _X_EXPORT void xf86WriteMmio32Le (void *, unsigned long, unsigned int); -#endif /* _SUNPRO_C */ -#endif /* __sparc__, __arm32__, __alpha__, __nds32__ */ -#endif /* __arm__ */ - -#endif /* NO_INLINE || DO_PROTOTYPES */ - -#ifdef __GNUC__ -#ifdef __i386__ - -#ifdef __SSE__ -#define write_mem_barrier() __asm__ __volatile__ ("sfence" : : : "memory") -#else -#define write_mem_barrier() __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory") -#endif - -#ifdef __SSE2__ -#define mem_barrier() __asm__ __volatile__ ("mfence" : : : "memory") -#else -#define mem_barrier() __asm__ __volatile__ ("lock; addl $0,0(%%esp)" : : : "memory") -#endif - -#elif defined __alpha__ - -#define mem_barrier() __asm__ __volatile__ ("mb" : : : "memory") -#define write_mem_barrier() __asm__ __volatile__ ("wmb" : : : "memory") - -#elif defined __amd64__ - -#define mem_barrier() __asm__ __volatile__ ("mfence" : : : "memory") -#define write_mem_barrier() __asm__ __volatile__ ("sfence" : : : "memory") - -#elif defined __ia64__ - -#ifndef __INTEL_COMPILER -#define mem_barrier() __asm__ __volatile__ ("mf" : : : "memory") -#define write_mem_barrier() __asm__ __volatile__ ("mf" : : : "memory") -#else -#include "ia64intrin.h" -#define mem_barrier() __mf() -#define write_mem_barrier() __mf() -#endif - -#elif defined __mips__ - /* Note: sync instruction requires MIPS II instruction set */ -#define mem_barrier() \ - __asm__ __volatile__( \ - ".set push\n\t" \ - ".set noreorder\n\t" \ - ".set mips2\n\t" \ - "sync\n\t" \ - ".set pop" \ - : /* no output */ \ - : /* no input */ \ - : "memory") -#define write_mem_barrier() mem_barrier() - -#elif defined __powerpc__ - -#ifndef eieio -#define eieio() __asm__ __volatile__ ("eieio" ::: "memory") -#endif /* eieio */ -#define mem_barrier() eieio() -#define write_mem_barrier() eieio() - -#elif defined __sparc__ - -#define barrier() __asm__ __volatile__ (".word 0x8143e00a" : : : "memory") -#define mem_barrier() /* XXX: nop for now */ -#define write_mem_barrier() /* XXX: nop for now */ -#endif -#endif /* __GNUC__ */ - -#ifndef barrier -#define barrier() -#endif - -#ifndef mem_barrier -#define mem_barrier() /* NOP */ -#endif - -#ifndef write_mem_barrier -#define write_mem_barrier() /* NOP */ -#endif - -#ifdef __GNUC__ -#if defined(__alpha__) - -#ifdef __linux__ -/* for Linux on Alpha, we use the LIBC _inx/_outx routines */ -/* note that the appropriate setup via "ioperm" needs to be done */ -/* *before* any inx/outx is done. */ - -extern _X_EXPORT void _outb(unsigned char val, unsigned long port); -extern _X_EXPORT void _outw(unsigned short val, unsigned long port); -extern _X_EXPORT void _outl(unsigned int val, unsigned long port); -extern _X_EXPORT unsigned int _inb(unsigned long port); -extern _X_EXPORT unsigned int _inw(unsigned long port); -extern _X_EXPORT unsigned int _inl(unsigned long port); - -static __inline__ void -outb(unsigned long port, unsigned char val) -{ - _outb(val, port); -} - -static __inline__ void -outw(unsigned long port, unsigned short val) -{ - _outw(val, port); -} - -static __inline__ void -outl(unsigned long port, unsigned int val) -{ - _outl(val, port); -} - -static __inline__ unsigned int -inb(unsigned long port) -{ - return _inb(port); -} - -static __inline__ unsigned int -inw(unsigned long port) -{ - return _inw(port); -} - -static __inline__ unsigned int -inl(unsigned long port) -{ - return _inl(port); -} - -#endif /* __linux__ */ - -#if (defined(__FreeBSD__) || defined(__OpenBSD__)) \ - && !defined(DO_PROTOTYPES) - -/* for FreeBSD and OpenBSD on Alpha, we use the libio (resp. libalpha) */ -/* inx/outx routines */ -/* note that the appropriate setup via "ioperm" needs to be done */ -/* *before* any inx/outx is done. */ - -extern _X_EXPORT void outb(unsigned int port, unsigned char val); -extern _X_EXPORT void outw(unsigned int port, unsigned short val); -extern _X_EXPORT void outl(unsigned int port, unsigned int val); -extern _X_EXPORT unsigned char inb(unsigned int port); -extern _X_EXPORT unsigned short inw(unsigned int port); -extern _X_EXPORT unsigned int inl(unsigned int port); - -#endif /* (__FreeBSD__ || __OpenBSD__ ) && !DO_PROTOTYPES */ - -#if defined(__NetBSD__) -#include -#endif /* __NetBSD__ */ - -#elif defined(__amd64__) || defined(__i386__) || defined(__ia64__) - -#include - -static __inline__ void -outb(unsigned short port, unsigned char val) -{ - __asm__ __volatile__("outb %0,%1"::"a"(val), "d"(port)); -} - -static __inline__ void -outw(unsigned short port, unsigned short val) -{ - __asm__ __volatile__("outw %0,%1"::"a"(val), "d"(port)); -} - -static __inline__ void -outl(unsigned short port, unsigned int val) -{ - __asm__ __volatile__("outl %0,%1"::"a"(val), "d"(port)); -} - -static __inline__ unsigned int -inb(unsigned short port) -{ - unsigned char ret; - __asm__ __volatile__("inb %1,%0":"=a"(ret):"d"(port)); - - return ret; -} - -static __inline__ unsigned int -inw(unsigned short port) -{ - unsigned short ret; - __asm__ __volatile__("inw %1,%0":"=a"(ret):"d"(port)); - - return ret; -} - -static __inline__ unsigned int -inl(unsigned short port) -{ - unsigned int ret; - __asm__ __volatile__("inl %1,%0":"=a"(ret):"d"(port)); - - return ret; -} - -#elif defined(__sparc__) - -#ifndef ASI_PL -#define ASI_PL 0x88 -#endif - -static __inline__ void -outb(unsigned long port, unsigned char val) -{ - __asm__ __volatile__("stba %0, [%1] %2": /* No outputs */ - :"r"(val), "r"(port), "i"(ASI_PL)); - - barrier(); -} - -static __inline__ void -outw(unsigned long port, unsigned short val) -{ - __asm__ __volatile__("stha %0, [%1] %2": /* No outputs */ - :"r"(val), "r"(port), "i"(ASI_PL)); - - barrier(); -} - -static __inline__ void -outl(unsigned long port, unsigned int val) -{ - __asm__ __volatile__("sta %0, [%1] %2": /* No outputs */ - :"r"(val), "r"(port), "i"(ASI_PL)); - - barrier(); -} - -static __inline__ unsigned int -inb(unsigned long port) -{ - unsigned int ret; - __asm__ __volatile__("lduba [%1] %2, %0":"=r"(ret) - :"r"(port), "i"(ASI_PL)); - - return ret; -} - -static __inline__ unsigned int -inw(unsigned long port) -{ - unsigned int ret; - __asm__ __volatile__("lduha [%1] %2, %0":"=r"(ret) - :"r"(port), "i"(ASI_PL)); - - return ret; -} - -static __inline__ unsigned int -inl(unsigned long port) -{ - unsigned int ret; - __asm__ __volatile__("lda [%1] %2, %0":"=r"(ret) - :"r"(port), "i"(ASI_PL)); - - return ret; -} - -static __inline__ unsigned char -xf86ReadMmio8(__volatile__ void *base, const unsigned long offset) -{ - unsigned long addr = ((unsigned long) base) + offset; - unsigned char ret; - - __asm__ __volatile__("lduba [%1] %2, %0":"=r"(ret) - :"r"(addr), "i"(ASI_PL)); - - return ret; -} - -static __inline__ unsigned short -xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset) -{ - unsigned long addr = ((unsigned long) base) + offset; - unsigned short ret; - - __asm__ __volatile__("lduh [%1], %0":"=r"(ret) - :"r"(addr)); - - return ret; -} - -static __inline__ unsigned short -xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset) -{ - unsigned long addr = ((unsigned long) base) + offset; - unsigned short ret; - - __asm__ __volatile__("lduha [%1] %2, %0":"=r"(ret) - :"r"(addr), "i"(ASI_PL)); - - return ret; -} - -static __inline__ unsigned int -xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset) -{ - unsigned long addr = ((unsigned long) base) + offset; - unsigned int ret; - - __asm__ __volatile__("ld [%1], %0":"=r"(ret) - :"r"(addr)); - - return ret; -} - -static __inline__ unsigned int -xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset) -{ - unsigned long addr = ((unsigned long) base) + offset; - unsigned int ret; - - __asm__ __volatile__("lda [%1] %2, %0":"=r"(ret) - :"r"(addr), "i"(ASI_PL)); - - return ret; -} - -static __inline__ void -xf86WriteMmio8(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - unsigned long addr = ((unsigned long) base) + offset; - - __asm__ __volatile__("stba %0, [%1] %2": /* No outputs */ - :"r"(val), "r"(addr), "i"(ASI_PL)); - - barrier(); -} - -static __inline__ void -xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - unsigned long addr = ((unsigned long) base) + offset; - - __asm__ __volatile__("sth %0, [%1]": /* No outputs */ - :"r"(val), "r"(addr)); - - barrier(); -} - -static __inline__ void -xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - unsigned long addr = ((unsigned long) base) + offset; - - __asm__ __volatile__("stha %0, [%1] %2": /* No outputs */ - :"r"(val), "r"(addr), "i"(ASI_PL)); - - barrier(); -} - -static __inline__ void -xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - unsigned long addr = ((unsigned long) base) + offset; - - __asm__ __volatile__("st %0, [%1]": /* No outputs */ - :"r"(val), "r"(addr)); - - barrier(); -} - -static __inline__ void -xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - unsigned long addr = ((unsigned long) base) + offset; - - __asm__ __volatile__("sta %0, [%1] %2": /* No outputs */ - :"r"(val), "r"(addr), "i"(ASI_PL)); - - barrier(); -} - -#elif defined(__arm32__) && !defined(__linux__) -#define PORT_SIZE long - -extern _X_EXPORT unsigned int IOPortBase; /* Memory mapped I/O port area */ - -static __inline__ void -outb(unsigned PORT_SIZE port, unsigned char val) -{ - *(volatile unsigned char *) (((unsigned PORT_SIZE) (port)) + IOPortBase) = - val; -} - -static __inline__ void -outw(unsigned PORT_SIZE port, unsigned short val) -{ - *(volatile unsigned short *) (((unsigned PORT_SIZE) (port)) + IOPortBase) = - val; -} - -static __inline__ void -outl(unsigned PORT_SIZE port, unsigned int val) -{ - *(volatile unsigned int *) (((unsigned PORT_SIZE) (port)) + IOPortBase) = - val; -} - -static __inline__ unsigned int -inb(unsigned PORT_SIZE port) -{ - return *(volatile unsigned char *) (((unsigned PORT_SIZE) (port)) + - IOPortBase); -} - -static __inline__ unsigned int -inw(unsigned PORT_SIZE port) -{ - return *(volatile unsigned short *) (((unsigned PORT_SIZE) (port)) + - IOPortBase); -} - -static __inline__ unsigned int -inl(unsigned PORT_SIZE port) -{ - return *(volatile unsigned int *) (((unsigned PORT_SIZE) (port)) + - IOPortBase); -} - -#if defined(__mips__) -#ifdef __linux__ /* don't mess with other OSs */ -#if X_BYTE_ORDER == X_BIG_ENDIAN -static __inline__ unsigned int -xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset) -{ - unsigned long addr = ((unsigned long) base) + offset; - unsigned int ret; - - __asm__ __volatile__("lw %0, 0(%1)":"=r"(ret) - :"r"(addr)); - - return ret; -} - -static __inline__ void -xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - unsigned long addr = ((unsigned long) base) + offset; - - __asm__ __volatile__("sw %0, 0(%1)": /* No outputs */ - :"r"(val), "r"(addr)); -} -#endif -#endif /* !__linux__ */ -#endif /* __mips__ */ - -#elif defined(__powerpc__) - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *)-1) -#endif - -extern _X_EXPORT volatile unsigned char *ioBase; - -static __inline__ unsigned char -xf86ReadMmio8(__volatile__ void *base, const unsigned long offset) -{ - register unsigned char val; - __asm__ __volatile__("lbzx %0,%1,%2\n\t" "eieio":"=r"(val) - :"b"(base), "r"(offset), - "m"(*((volatile unsigned char *) base + offset))); - return val; -} - -static __inline__ unsigned short -xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset) -{ - register unsigned short val; - __asm__ __volatile__("lhzx %0,%1,%2\n\t" "eieio":"=r"(val) - :"b"(base), "r"(offset), - "m"(*((volatile unsigned char *) base + offset))); - return val; -} - -static __inline__ unsigned short -xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset) -{ - register unsigned short val; - __asm__ __volatile__("lhbrx %0,%1,%2\n\t" "eieio":"=r"(val) - :"b"(base), "r"(offset), - "m"(*((volatile unsigned char *) base + offset))); - return val; -} - -static __inline__ unsigned int -xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset) -{ - register unsigned int val; - __asm__ __volatile__("lwzx %0,%1,%2\n\t" "eieio":"=r"(val) - :"b"(base), "r"(offset), - "m"(*((volatile unsigned char *) base + offset))); - return val; -} - -static __inline__ unsigned int -xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset) -{ - register unsigned int val; - __asm__ __volatile__("lwbrx %0,%1,%2\n\t" "eieio":"=r"(val) - :"b"(base), "r"(offset), - "m"(*((volatile unsigned char *) base + offset))); - return val; -} - -static __inline__ void -xf86WriteMmio8(__volatile__ void *base, const unsigned long offset, - const unsigned char val) -{ - __asm__ - __volatile__("stbx %1,%2,%3\n\t":"=m" - (*((volatile unsigned char *) base + offset)) - :"r"(val), "b"(base), "r"(offset)); - eieio(); -} - -static __inline__ void -xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset, - const unsigned short val) -{ - __asm__ - __volatile__("sthbrx %1,%2,%3\n\t":"=m" - (*((volatile unsigned char *) base + offset)) - :"r"(val), "b"(base), "r"(offset)); - eieio(); -} - -static __inline__ void -xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset, - const unsigned short val) -{ - __asm__ - __volatile__("sthx %1,%2,%3\n\t":"=m" - (*((volatile unsigned char *) base + offset)) - :"r"(val), "b"(base), "r"(offset)); - eieio(); -} - -static __inline__ void -xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - __asm__ - __volatile__("stwbrx %1,%2,%3\n\t":"=m" - (*((volatile unsigned char *) base + offset)) - :"r"(val), "b"(base), "r"(offset)); - eieio(); -} - -static __inline__ void -xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - __asm__ - __volatile__("stwx %1,%2,%3\n\t":"=m" - (*((volatile unsigned char *) base + offset)) - :"r"(val), "b"(base), "r"(offset)); - eieio(); -} - -static __inline__ void -outb(unsigned short port, unsigned char value) -{ - if (ioBase == MAP_FAILED) - return; - xf86WriteMmio8((void *) ioBase, port, value); -} - -static __inline__ void -outw(unsigned short port, unsigned short value) -{ - if (ioBase == MAP_FAILED) - return; - xf86WriteMmio16Le((void *) ioBase, port, value); -} - -static __inline__ void -outl(unsigned short port, unsigned int value) -{ - if (ioBase == MAP_FAILED) - return; - xf86WriteMmio32Le((void *) ioBase, port, value); -} - -static __inline__ unsigned int -inb(unsigned short port) -{ - if (ioBase == MAP_FAILED) - return 0; - return xf86ReadMmio8((void *) ioBase, port); -} - -static __inline__ unsigned int -inw(unsigned short port) -{ - if (ioBase == MAP_FAILED) - return 0; - return xf86ReadMmio16Le((void *) ioBase, port); -} - -static __inline__ unsigned int -inl(unsigned short port) -{ - if (ioBase == MAP_FAILED) - return 0; - return xf86ReadMmio32Le((void *) ioBase, port); -} - -#elif defined(__nds32__) - -/* - * Assume all port access are aligned. We need to revise this implementation - * if there is unaligned port access. - */ - -#define PORT_SIZE long - -static __inline__ unsigned char -xf86ReadMmio8(__volatile__ void *base, const unsigned long offset) -{ - return *(volatile unsigned char *) ((unsigned char *) base + offset); -} - -static __inline__ void -xf86WriteMmio8(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - *(volatile unsigned char *) ((unsigned char *) base + offset) = val; - barrier(); -} - -static __inline__ unsigned short -xf86ReadMmio16Swap(__volatile__ void *base, const unsigned long offset) -{ - unsigned long addr = ((unsigned long) base) + offset; - unsigned short ret; - - __asm__ __volatile__("lhi %0, [%1];\n\t" "wsbh %0, %0;\n\t":"=r"(ret) - :"r"(addr)); - - return ret; -} - -static __inline__ unsigned short -xf86ReadMmio16(__volatile__ void *base, const unsigned long offset) -{ - return *(volatile unsigned short *) ((char *) base + offset); -} - -static __inline__ void -xf86WriteMmio16Swap(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - unsigned long addr = ((unsigned long) base) + offset; - - __asm__ __volatile__("wsbh %0, %0;\n\t" "shi %0, [%1];\n\t": /* No outputs */ - :"r"(val), "r"(addr)); - - barrier(); -} - -static __inline__ void -xf86WriteMmio16(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - *(volatile unsigned short *) ((unsigned char *) base + offset) = val; - barrier(); -} - -static __inline__ unsigned int -xf86ReadMmio32Swap(__volatile__ void *base, const unsigned long offset) -{ - unsigned long addr = ((unsigned long) base) + offset; - unsigned int ret; - - __asm__ __volatile__("lwi %0, [%1];\n\t" - "wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t":"=r"(ret) - :"r"(addr)); - - return ret; -} - -static __inline__ unsigned int -xf86ReadMmio32(__volatile__ void *base, const unsigned long offset) -{ - return *(volatile unsigned int *) ((unsigned char *) base + offset); -} - -static __inline__ void -xf86WriteMmio32Swap(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - unsigned long addr = ((unsigned long) base) + offset; - - __asm__ __volatile__("wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t" "swi %0, [%1];\n\t": /* No outputs */ - :"r"(val), "r"(addr)); - - barrier(); -} - -static __inline__ void -xf86WriteMmio32(__volatile__ void *base, const unsigned long offset, - const unsigned int val) -{ - *(volatile unsigned int *) ((unsigned char *) base + offset) = val; - barrier(); -} - -#if defined(NDS32_MMIO_SWAP) -static __inline__ void -outb(unsigned PORT_SIZE port, unsigned char val) -{ - xf86WriteMmio8(IOPortBase, port, val); -} - -static __inline__ void -outw(unsigned PORT_SIZE port, unsigned short val) -{ - xf86WriteMmio16Swap(IOPortBase, port, val); -} - -static __inline__ void -outl(unsigned PORT_SIZE port, unsigned int val) -{ - xf86WriteMmio32Swap(IOPortBase, port, val); -} - -static __inline__ unsigned int -inb(unsigned PORT_SIZE port) -{ - return xf86ReadMmio8(IOPortBase, port); -} - -static __inline__ unsigned int -inw(unsigned PORT_SIZE port) -{ - return xf86ReadMmio16Swap(IOPortBase, port); -} - -static __inline__ unsigned int -inl(unsigned PORT_SIZE port) -{ - return xf86ReadMmio32Swap(IOPortBase, port); -} - -#else /* !NDS32_MMIO_SWAP */ -static __inline__ void -outb(unsigned PORT_SIZE port, unsigned char val) -{ - *(volatile unsigned char *) (((unsigned PORT_SIZE) (port))) = val; - barrier(); -} - -static __inline__ void -outw(unsigned PORT_SIZE port, unsigned short val) -{ - *(volatile unsigned short *) (((unsigned PORT_SIZE) (port))) = val; - barrier(); -} - -static __inline__ void -outl(unsigned PORT_SIZE port, unsigned int val) -{ - *(volatile unsigned int *) (((unsigned PORT_SIZE) (port))) = val; - barrier(); -} - -static __inline__ unsigned int -inb(unsigned PORT_SIZE port) -{ - return *(volatile unsigned char *) (((unsigned PORT_SIZE) (port))); -} - -static __inline__ unsigned int -inw(unsigned PORT_SIZE port) -{ - return *(volatile unsigned short *) (((unsigned PORT_SIZE) (port))); -} - -static __inline__ unsigned int -inl(unsigned PORT_SIZE port) -{ - return *(volatile unsigned int *) (((unsigned PORT_SIZE) (port))); -} - -#endif /* NDS32_MMIO_SWAP */ - -#endif /* arch madness */ - -#else /* !GNUC */ -#if defined(__STDC__) && (__STDC__ == 1) -#ifndef asm -#define asm __asm -#endif -#endif -#if !defined(__SUNPRO_C) -#include -#endif -#endif /* __GNUC__ */ - -#if !defined(MMIO_IS_BE) && \ - (defined(SPARC_MMIO_IS_BE) || defined(PPC_MMIO_IS_BE)) -#define MMIO_IS_BE -#endif - -#ifdef __alpha__ -static inline int -xf86ReadMmio8(void *Base, unsigned long Offset) -{ - mem_barrier(); - return *(CARD8 *) ((unsigned long) Base + (Offset)); -} - -static inline int -xf86ReadMmio16(void *Base, unsigned long Offset) -{ - mem_barrier(); - return *(CARD16 *) ((unsigned long) Base + (Offset)); -} - -static inline int -xf86ReadMmio32(void *Base, unsigned long Offset) -{ - mem_barrier(); - return *(CARD32 *) ((unsigned long) Base + (Offset)); -} - -static inline void -xf86WriteMmio8(int Value, void *Base, unsigned long Offset) -{ - write_mem_barrier(); - *(CARD8 *) ((unsigned long) Base + (Offset)) = Value; -} - -static inline void -xf86WriteMmio16(int Value, void *Base, unsigned long Offset) -{ - write_mem_barrier(); - *(CARD16 *) ((unsigned long) Base + (Offset)) = Value; -} - -static inline void -xf86WriteMmio32(int Value, void *Base, unsigned long Offset) -{ - write_mem_barrier(); - *(CARD32 *) ((unsigned long) Base + (Offset)) = Value; -} - -extern _X_EXPORT void xf86SlowBCopyFromBus(unsigned char *, unsigned char *, - int); -extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int); - -/* Some macros to hide the system dependencies for MMIO accesses */ -/* Changed to kill noise generated by gcc's -Wcast-align */ -#define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) -#define MMIO_IN16(base, offset) xf86ReadMmio16(base, offset) -#define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset) - -#define MMIO_OUT8(base, offset, val) \ - xf86WriteMmio8((CARD8)(val), base, offset) -#define MMIO_OUT16(base, offset, val) \ - xf86WriteMmio16((CARD16)(val), base, offset) -#define MMIO_OUT32(base, offset, val) \ - xf86WriteMmio32((CARD32)(val), base, offset) - -#elif defined(__powerpc__) || defined(__sparc__) - /* - * we provide byteswapping and no byteswapping functions here - * with byteswapping as default, - * drivers that don't need byteswapping should define MMIO_IS_BE - */ -#define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) -#define MMIO_OUT8(base, offset, val) \ - xf86WriteMmio8(base, offset, (CARD8)(val)) - -#if defined(MMIO_IS_BE) /* No byteswapping */ -#define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset) -#define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset) -#define MMIO_OUT16(base, offset, val) \ - xf86WriteMmio16Be(base, offset, (CARD16)(val)) -#define MMIO_OUT32(base, offset, val) \ - xf86WriteMmio32Be(base, offset, (CARD32)(val)) -#else /* byteswapping is the default */ -#define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset) -#define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset) -#define MMIO_OUT16(base, offset, val) \ - xf86WriteMmio16Le(base, offset, (CARD16)(val)) -#define MMIO_OUT32(base, offset, val) \ - xf86WriteMmio32Le(base, offset, (CARD32)(val)) -#endif - -#elif defined(__nds32__) - /* - * we provide byteswapping and no byteswapping functions here - * with no byteswapping as default; when endianness of CPU core - * and I/O devices don't match, byte swapping is necessary - * drivers that need byteswapping should define NDS32_MMIO_SWAP - */ -#define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset) -#define MMIO_OUT8(base, offset, val) \ - xf86WriteMmio8(base, offset, (CARD8)(val)) - -#if defined(NDS32_MMIO_SWAP) /* byteswapping */ -#define MMIO_IN16(base, offset) xf86ReadMmio16Swap(base, offset) -#define MMIO_IN32(base, offset) xf86ReadMmio32Swap(base, offset) -#define MMIO_OUT16(base, offset, val) \ - xf86WriteMmio16Swap(base, offset, (CARD16)(val)) -#define MMIO_OUT32(base, offset, val) \ - xf86WriteMmio32Swap(base, offset, (CARD32)(val)) -#else /* no byteswapping is the default */ -#define MMIO_IN16(base, offset) xf86ReadMmio16(base, offset) -#define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset) -#define MMIO_OUT16(base, offset, val) \ - xf86WriteMmio16(base, offset, (CARD16)(val)) -#define MMIO_OUT32(base, offset, val) \ - xf86WriteMmio32(base, offset, (CARD32)(val)) -#endif - -#else /* !__alpha__ && !__powerpc__ && !__sparc__ */ - -#define MMIO_IN8(base, offset) \ - *(volatile CARD8 *)(((CARD8*)(base)) + (offset)) -#define MMIO_IN16(base, offset) \ - *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset)) -#define MMIO_IN32(base, offset) \ - *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) -#define MMIO_OUT8(base, offset, val) \ - *(volatile CARD8 *)(((CARD8*)(base)) + (offset)) = (val) -#define MMIO_OUT16(base, offset, val) \ - *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset)) = (val) -#define MMIO_OUT32(base, offset, val) \ - *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val) - -#endif /* __alpha__ */ - -/* - * With Intel, the version in os-support/misc/SlowBcopy.s is used. - * This avoids port I/O during the copy (which causes problems with - * some hardware). - */ -#ifdef __alpha__ -#define slowbcopy_tobus(src,dst,count) xf86SlowBCopyToBus(src,dst,count) -#define slowbcopy_frombus(src,dst,count) xf86SlowBCopyFromBus(src,dst,count) -#else /* __alpha__ */ -#define slowbcopy_tobus(src,dst,count) xf86SlowBcopy(src,dst,count) -#define slowbcopy_frombus(src,dst,count) xf86SlowBcopy(src,dst,count) -#endif /* __alpha__ */ - -#endif /* _COMPILER_H */ diff --git a/hw/xfree86/common/dgaproc.h b/hw/xfree86/common/dgaproc.h deleted file mode 100644 index b9f003056..000000000 --- a/hw/xfree86/common/dgaproc.h +++ /dev/null @@ -1,67 +0,0 @@ - -#ifndef __DGAPROC_H -#define __DGAPROC_H - -#include -#include "pixmap.h" - -#define DGA_CONCURRENT_ACCESS 0x00000001 -#define DGA_FILL_RECT 0x00000002 -#define DGA_BLIT_RECT 0x00000004 -#define DGA_BLIT_RECT_TRANS 0x00000008 -#define DGA_PIXMAP_AVAILABLE 0x00000010 - -#define DGA_INTERLACED 0x00010000 -#define DGA_DOUBLESCAN 0x00020000 - -#define DGA_FLIP_IMMEDIATE 0x00000001 -#define DGA_FLIP_RETRACE 0x00000002 - -#define DGA_COMPLETED 0x00000000 -#define DGA_PENDING 0x00000001 - -#define DGA_NEED_ROOT 0x00000001 - -typedef struct { - int num; /* A unique identifier for the mode (num > 0) */ - const char *name; /* name of mode given in the XF86Config */ - int VSync_num; - int VSync_den; - int flags; /* DGA_CONCURRENT_ACCESS, etc... */ - int imageWidth; /* linear accessible portion (pixels) */ - int imageHeight; - int pixmapWidth; /* Xlib accessible portion (pixels) */ - int pixmapHeight; /* both fields ignored if no concurrent access */ - int bytesPerScanline; - int byteOrder; /* MSBFirst, LSBFirst */ - int depth; - int bitsPerPixel; - unsigned long red_mask; - unsigned long green_mask; - unsigned long blue_mask; - short visualClass; - int viewportWidth; - int viewportHeight; - int xViewportStep; /* viewport position granularity */ - int yViewportStep; - int maxViewportX; /* max viewport origin */ - int maxViewportY; - int viewportFlags; /* types of page flipping possible */ - int offset; - int reserved1; - int reserved2; -} XDGAModeRec, *XDGAModePtr; - -/* DDX interface */ - -extern Bool DGAScreenAvailable(ScreenPtr pScreen); -extern Bool DGAActive(int Index); - -extern Bool DGAVTSwitch(void); -extern Bool DGAStealButtonEvent(DeviceIntPtr dev, int Index, - int button, int is_down); -extern Bool DGAStealMotionEvent(DeviceIntPtr dev, int Index, int dx, int dy); -extern Bool DGAStealKeyEvent(DeviceIntPtr dev, int Index, - int key_code, int is_down); - -#endif /* __DGAPROC_H */ diff --git a/hw/xfree86/common/extramodes b/hw/xfree86/common/extramodes deleted file mode 100644 index 006b5cba1..000000000 --- a/hw/xfree86/common/extramodes +++ /dev/null @@ -1,168 +0,0 @@ -// -// Extra modes to include as default modes in the X server. -// -// $XFree86: xc/programs/Xserver/hw/xfree86/etc/extramodes,v 1.5 2002/06/05 19:43:05 dawes Exp $ -// - -# 832x624 @ 75Hz (74.55Hz) (fix if the official/Apple spec is different) hsync: 49.725kHz -ModeLine "832x624" 57.284 832 864 928 1152 624 625 628 667 -Hsync -Vsync - -# 1400x1050 @ 60Hz (VESA GTF) hsync: 65.5kHz -ModeLine "1400x1050" 122.0 1400 1488 1640 1880 1050 1052 1064 1082 +hsync +vsync - -# 1400x1050 @ 75Hz (VESA GTF) hsync: 82.2kHz -ModeLine "1400x1050" 155.8 1400 1464 1784 1912 1050 1052 1064 1090 +hsync +vsync - -# 1920x1440 @ 85Hz (VESA GTF) hsync: 128.5kHz -Modeline "1920x1440" 341.35 1920 2072 2288 2656 1440 1441 1444 1512 -hsync +vsync - -# 2048x1536 @ 60Hz (VESA GTF) hsync: 95.3kHz -Modeline "2048x1536" 266.95 2048 2200 2424 2800 1536 1537 1540 1589 -hsync +vsync - -# 2048x1536 @ 75Hz (VESA GTF) hsync: 120.2kHz -Modeline "2048x1536" 340.48 2048 2216 2440 2832 1536 1537 1540 1603 -hsync +vsync - -# 2048x1536 @ 85Hz (VESA GTF) hsync: 137.0kHz -Modeline "2048x1536" 388.04 2048 2216 2440 2832 1536 1537 1540 1612 -hsync +vsync - -### 16:9 modelines generated by cvt - -# 640x360 59.32 Hz (CVT 0.23M9-R) hsync: 22.19 kHz; pclk: 17.75 MHz -Modeline "640x360R" 17.75 640 688 720 800 360 363 368 374 +hsync -vsync - -# 640x360 59.84 Hz (CVT 0.23M9) hsync: 22.50 kHz; pclk: 18.00 MHz -Modeline "640x360" 18.00 640 664 720 800 360 363 368 376 -hsync +vsync - -# 720x405 58.99 Hz (CVT 0.29M9-R) hsync: 24.72 kHz; pclk: 21.75 MHz -Modeline "720x405R" 21.75 720 768 800 880 405 408 413 419 +hsync -vsync - -# 720x405 59.51 Hz (CVT 0.29M9) hsync: 25.11 kHz; pclk: 22.50 MHz -Modeline "720x405" 22.50 720 744 808 896 405 408 413 422 -hsync +vsync - -# 864x486 59.57 Hz (CVT 0.42M9-R) hsync: 29.79 kHz; pclk: 30.50 MHz -Modeline "864x486R" 30.50 864 912 944 1024 486 489 494 500 +hsync -vsync - -# 864x486 59.92 Hz (CVT 0.42M9) hsync: 30.32 kHz; pclk: 32.50 MHz -Modeline "864x486" 32.50 864 888 968 1072 486 489 494 506 -hsync +vsync - -# 960x540 59.82 Hz (CVT 0.52M9-R) hsync: 33.26 kHz; pclk: 37.25 MHz -Modeline "960x540R" 37.25 960 1008 1040 1120 540 543 548 556 +hsync -vsync - -# 960x540 59.63 Hz (CVT 0.52M9) hsync: 33.51 kHz; pclk: 40.75 MHz -Modeline "960x540" 40.75 960 992 1088 1216 540 543 548 562 -hsync +vsync - -# 1024x576 59.82 Hz (CVT 0.59M9-R) hsync: 35.47 kHz; pclk: 42.00 MHz -Modeline "1024x576R" 42.00 1024 1072 1104 1184 576 579 584 593 +hsync -vsync - -# 1024x576 59.90 Hz (CVT 0.59M9) hsync: 35.88 kHz; pclk: 46.50 MHz -Modeline "1024x576" 46.50 1024 1064 1160 1296 576 579 584 599 -hsync +vsync - -# 1280x720 59.74 Hz (CVT 0.92M9-R) hsync: 44.27 kHz; pclk: 63.75 MHz -Modeline "1280x720R" 63.75 1280 1328 1360 1440 720 723 728 741 +hsync -vsync - -# 1280x720 59.86 Hz (CVT 0.92M9) hsync: 44.77 kHz; pclk: 74.50 MHz -Modeline "1280x720" 74.50 1280 1344 1472 1664 720 723 728 748 -hsync +vsync - -# 1368x768 59.85 Hz (CVT) hsync: 47.28 kHz; pclk: 72.25 MHz -Modeline "1368x768R" 72.25 1368 1416 1448 1528 768 771 781 790 +hsync -vsync - -# 1368x768 59.88 Hz (CVT) hsync: 47.79 kHz; pclk: 85.25 MHz -Modeline "1368x768" 85.25 1368 1440 1576 1784 768 771 781 798 -hsync +vsync - -# 1600x900 59.82 Hz (CVT 1.44M9-R) hsync: 55.40 kHz; pclk: 97.50 MHz -Modeline "1600x900R" 97.50 1600 1648 1680 1760 900 903 908 926 +hsync -vsync - -# 1600x900 59.95 Hz (CVT 1.44M9) hsync: 55.99 kHz; pclk: 118.25 MHz -Modeline "1600x900" 118.25 1600 1696 1856 2112 900 903 908 934 -hsync +vsync - -# 1920x1080 59.93 Hz (CVT 2.07M9-R) hsync: 66.59 kHz; pclk: 138.50 MHz -Modeline "1920x1080R" 138.50 1920 1968 2000 2080 1080 1083 1088 1111 +hsync -vsync - -# 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz -Modeline "1920x1080" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync - -# 2048x1152 59.91 Hz (CVT 2.36M9-R) hsync: 70.99 kHz; pclk: 156.75 MHz -Modeline "2048x1152R" 156.75 2048 2096 2128 2208 1152 1155 1160 1185 +hsync -vsync - -# 2048x1152 59.90 Hz (CVT 2.36M9) hsync: 71.58 kHz; pclk: 197.00 MHz -Modeline "2048x1152" 197.00 2048 2184 2400 2752 1152 1155 1160 1195 -hsync +vsync - -# 2560x1440 59.95 Hz (CVT 3.69M9-R) hsync: 88.79 kHz; pclk: 241.50 MHz -Modeline "2560x1440R" 241.50 2560 2608 2640 2720 1440 1443 1448 1481 +hsync -vsync - -# 2560x1440 59.96 Hz (CVT 3.69M9) hsync: 89.52 kHz; pclk: 312.25 MHz -Modeline "2560x1440" 312.25 2560 2752 3024 3488 1440 1443 1448 1493 -hsync +vsync - -# 2880x1620 59.97 Hz (CVT 4.67M9-R) hsync: 99.92 kHz; pclk: 303.75 MHz -Modeline "2880x1620R" 303.75 2880 2928 2960 3040 1620 1623 1628 1666 +hsync -vsync - -# 2880x1620 59.96 Hz (CVT 4.67M9) hsync: 100.67 kHz; pclk: 396.25 MHz -Modeline "2880x1620" 396.25 2880 3096 3408 3936 1620 1623 1628 1679 -hsync +vsync - -# 3200x1800 59.94 Hz (CVT 5.76M9-R) hsync: 111.01 kHz; pclk: 373.00 MHz -Modeline "3200x1800R" 373.00 3200 3248 3280 3360 1800 1803 1808 1852 +hsync -vsync - -# 3200x1800 59.96 Hz (CVT 5.76M9) hsync: 111.82 kHz; pclk: 492.00 MHz -Modeline "3200x1800" 492.00 3200 3456 3800 4400 1800 1803 1808 1865 -hsync +vsync - -# 3840x2160 59.97 Hz (CVT 8.29M9-R) hsync: 133.25 kHz; pclk: 533.00 MHz -Modeline "3840x2160R" 533.00 3840 3888 3920 4000 2160 2163 2168 2222 +hsync -vsync - -# 3840x2160 59.98 Hz (CVT 8.29M9) hsync: 134.18 kHz; pclk: 712.75 MHz -Modeline "3840x2160" 712.75 3840 4160 4576 5312 2160 2163 2168 2237 -hsync +vsync - -# 4096x2304 59.98 Hz (CVT 9.44M9-R) hsync: 142.15 kHz; pclk: 605.00 MHz -Modeline "4096x2304R" 605.00 4096 4144 4176 4256 2304 2307 2312 2370 +hsync -vsync - -# 4096x2304 59.99 Hz (CVT 9.44M9) hsync: 143.13 kHz; pclk: 813.00 MHz -Modeline "4096x2304" 813.00 4096 4440 4888 5680 2304 2307 2312 2386 -hsync +vsync - -# 5120x2880 59.99 Hz (CVT 14.75M9-R) hsync: 177.70 kHz; pclk: 938.25 MHz -Modeline "5120x2880R" 938.25 5120 5168 5200 5280 2880 2883 2888 2962 +hsync -vsync - -# 5120x2880 59.99 Hz (CVT 14.75M9) hsync: 178.88 kHz; pclk: 1276.50 MHz -Modeline "5120x2880" 1276.50 5120 5560 6128 7136 2880 2883 2888 2982 -hsync +vsync - -# 7680x4320 59.99 Hz (CVT 33.18M9-R) hsync: 266.55 kHz; pclk: 2089.75 MHz -Modeline "7680x4320R" 2089.75 7680 7728 7760 7840 4320 4323 4328 4443 +hsync -vsync - -# 7680x4320 59.99 Hz (CVT 33.18M9) hsync: 268.22 kHz; pclk: 2892.50 MHz -Modeline "7680x4320" 2892.50 7680 8376 9232 10784 4320 4323 4328 4471 -hsync +vsync - -# 15360x8640 59.99 Hz (CVT 132.71M9-R) hsync: 533.10 kHz; pclk: 8273.75 MHz -Modeline "15360x8640R" 8273.75 15360 15408 15440 15520 8640 8643 8648 8886 +hsync -vsync - -# 15360x8640 60.00 Hz (CVT 132.71M9) hsync: 536.27 kHz; pclk: 11669.25 MHz -Modeline "15360x8640" 11669.25 15360 16824 18560 21760 8640 8643 8648 8938 -hsync +vsync - -## 16:10 modelines generated by cvt - -# 1280x800 59.91 Hz (CVT 1.02MA-R) hsync: 49.31 kHz; pclk: 71.00 MHz -Modeline "1280x800R" 71.00 1280 1328 1360 1440 800 803 809 823 +hsync -vsync - -# 1280x800 59.81 Hz (CVT 1.02MA) hsync: 49.70 kHz; pclk: 83.50 MHz -Modeline "1280x800" 83.50 1280 1352 1480 1680 800 803 809 831 -hsync +vsync - -# 1400x900 59.88 Hz (CVT) hsync: 55.45 kHz; pclk: 86.50 MHz -Modeline "1400x900R" 86.50 1400 1448 1480 1560 900 903 913 926 +hsync -vsync - -# 1400x900 59.96 Hz (CVT) hsync: 56.01 kHz; pclk: 103.50 MHz -Modeline "1400x900" 103.50 1400 1480 1624 1848 900 903 913 934 -hsync +vsync - -# 1680x1050 59.88 Hz (CVT 1.76MA-R) hsync: 64.67 kHz; pclk: 119.00 MHz -Modeline "1680x1050R" 119.00 1680 1728 1760 1840 1050 1053 1059 1080 +hsync -vsync - -# 1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz -Modeline "1680x1050" 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync - -# 1920x1200 59.95 Hz (CVT 2.30MA-R) hsync: 74.04 kHz; pclk: 154.00 MHz -Modeline "1920x1200R" 154.00 1920 1968 2000 2080 1200 1203 1209 1235 +hsync -vsync - -# 1920x1200 59.88 Hz (CVT 2.30MA) hsync: 74.56 kHz; pclk: 193.25 MHz -Modeline "1920x1200" 193.25 1920 2056 2256 2592 1200 1203 1209 1245 -hsync +vsync - -# 2560x1600 59.97 Hz (CVT 4.10MA-R) hsync: 98.71 kHz; pclk: 268.50 MHz -Modeline "2560x1600R" 268.50 2560 2608 2640 2720 1600 1603 1609 1646 +hsync -vsync - -# 2560x1600 59.99 Hz (CVT 4.10MA) hsync: 99.46 kHz; pclk: 348.50 MHz -Modeline "2560x1600" 348.50 2560 2760 3032 3504 1600 1603 1609 1658 -hsync +vsync diff --git a/hw/xfree86/common/meson.build b/hw/xfree86/common/meson.build deleted file mode 100644 index 7dc19c6f9..000000000 --- a/hw/xfree86/common/meson.build +++ /dev/null @@ -1,103 +0,0 @@ -srcs_xorg_common = [ - 'xf86fbBus.c', - 'xf86noBus.c', - 'xf86Configure.c', - 'xf86Bus.c', - 'xf86Config.c', - 'xf86Cursor.c', - 'xf86DPMS.c', - 'xf86Events.c', - 'xf86Globals.c', - 'xf86AutoConfig.c', - 'xf86Option.c', - 'xf86Init.c', - 'xf86VidMode.c', - 'xf86fbman.c', - 'xf86cmap.c', - 'xf86Helper.c', - 'xf86PM.c', - 'xf86RandR.c', - 'xf86Xinput.c', - 'xisb.c', - 'xf86Mode.c', - 'xorgHelper.c', - 'xf86Extensions.c', -] - -xorg_sdk_headers = [ - 'compiler.h', - 'xf86.h', - 'xf86Module.h', - 'xf86Opt.h', - 'xf86PciInfo.h', - 'xf86Priv.h', - 'xf86Privstr.h', - 'xf86cmap.h', - 'xf86fbman.h', - 'xf86str.h', - 'xf86Xinput.h', - 'xisb.h', - 'xorgVersion.h', - 'xf86sbusBus.h', - 'xf86VGAarbiter.h', - 'xf86Optionstr.h', - 'xf86platformBus.h', - 'xf86MatchDrivers.h', - 'xaarop.h', -] - -fallback_driver = get_option('fallback_input_driver') -if fallback_driver == 'auto' - if host_machine.system() == 'linux' - fallback_driver = 'libinput' - else - fallback_driver = '' - endif -endif - -if build_dga - srcs_xorg_common += 'xf86DGA.c' - xorg_sdk_headers += 'dgaproc.h' -endif - -if build_xv - srcs_xorg_common += ['xf86xv.c', 'xf86xvmc.c'] - xorg_sdk_headers += ['xf86xv.h', 'xf86xvmc.h', 'xf86xvpriv.h'] -endif - -if build_udev - srcs_xorg_common += 'xf86platformBus.c' -endif - -if get_option('pciaccess') - srcs_xorg_common += ['xf86pciBus.c', 'xf86VGAarbiter.c'] - - if host_machine.cpu() == 'sparc' or host_machine.cpu() == 'sparc64' - srcs_xorg_common += 'xf86sbusBus.c' - endif -endif - -srcs_xorg_common += custom_target( - 'xf86DefModeSet.c', - output: 'xf86DefModeSet.c', - input: ['modeline2c.awk', 'vesamodes', 'extramodes'], - command: [find_program('awk'), '-f', '@INPUT0@', '@INPUT1@', '@INPUT2@'], - capture: true, -) - -xorg_common = static_library('xorg_common', - srcs_xorg_common, - include_directories: [inc, xorg_inc, top_dir_inc], - dependencies: [ - common_dep, - dbus_dep, - pciaccess_dep, - libdrm_dep, - ], - c_args: [ - xorg_c_args, - '-DFALLBACK_INPUT_DRIVER="@0@"'.format(fallback_driver) - ], -) - -install_data(xorg_sdk_headers, install_dir: xorgsdkdir) diff --git a/hw/xfree86/common/modeline2c.awk b/hw/xfree86/common/modeline2c.awk deleted file mode 100644 index 3c9f602d1..000000000 --- a/hw/xfree86/common/modeline2c.awk +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/awk -f -# -# Copyright (c) 2007 Joerg Sonnenberger . -# All rights reserved. -# -# Based on Perl script by Dirk Hohndel. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# Usage: modeline2c.awk < modefile > xf86DefModeSet.c -# - -BEGIN { - flagsdict[""] = "0" - - flagsdict["+hsync +vsync"] = "V_PHSYNC | V_PVSYNC" - flagsdict["+hsync -vsync"] = "V_PHSYNC | V_NVSYNC" - flagsdict["-hsync +vsync"] = "V_NHSYNC | V_PVSYNC" - flagsdict["-hsync -vsync"] = "V_NHSYNC | V_NVSYNC" - flagsdict["+hsync +vsync interlace"] = "V_PHSYNC | V_PVSYNC | V_INTERLACE" - flagsdict["+hsync -vsync interlace"] = "V_PHSYNC | V_NVSYNC | V_INTERLACE" - flagsdict["-hsync +vsync interlace"] = "V_NHSYNC | V_PVSYNC | V_INTERLACE" - flagsdict["-hsync -vsync interlace"] = "V_NHSYNC | V_NVSYNC | V_INTERLACE" - - print "/* THIS FILE IS AUTOMATICALLY GENERATED -- DO NOT EDIT -- LOOK at" - print " * modeline2c.awk */" - print "" - print "/*" - print " * Author: Joerg Sonnenberger " - print " * Based on Perl script from Dirk Hohndel " - print " */" - print "" - print "#ifdef HAVE_XORG_CONFIG_H" - print "#include " - print "#endif" - print "" - print "#include \"xf86.h\"" - print "#include \"xf86Config.h\"" - print "#include \"xf86Priv.h\"" - print "#include \"xf86_OSlib.h\"" - print "" - print "#include \"globals.h\"" - print "" - print "#define MODEPREFIX NULL, NULL, NULL, MODE_OK, M_T_DEFAULT" - print "#define MODESUFFIX 0,0, 0,0,0,0,0,0,0, 0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0" - print "" - print "const DisplayModeRec xf86DefaultModes [] = {" - - modeline = "\t{MODEPREFIX,%d, %d,%d,%d,%d,0, %d,%d,%d,%d,0, %s, MODESUFFIX},\n" - modeline_data = "^[a-zA-Z]+[ \t]+[^ \t]+[ \t0-9.]+" -} - -/^[mM][oO][dD][eE][lL][iI][nN][eE]/ { - flags = $0 - gsub(modeline_data, "", flags) - flags = tolower(flags) - printf(modeline, $3 * 1000, $4, $5, $6, $7, - $8, $9, $10, $11, flagsdict[flags]) - # Half-width double scanned modes - printf(modeline, $3 * 500, $4/2, $5/2, $6/2, $7/2, - $8/2, $9/2, $10/2, $11/2, flagsdict[flags] " | V_DBLSCAN") -} - -/^#/ { - print "/*" substr($0, 2) " */" -} - -END { - print "};" - printf "const int xf86NumDefaultModes = ARRAY_SIZE(xf86DefaultModes);" -} diff --git a/hw/xfree86/common/vesamodes b/hw/xfree86/common/vesamodes deleted file mode 100644 index 2bc886276..000000000 --- a/hw/xfree86/common/vesamodes +++ /dev/null @@ -1,111 +0,0 @@ -// -// Default modes distilled from -// "VESA and Industry Standards and Guide for Computer Display Monitor -// Timing", version 1.0, revision 0.8, adopted September 17, 1998. -// -// $XFree86: xc/programs/Xserver/hw/xfree86/etc/vesamodes,v 1.3 1999/11/16 03:28:03 tsi Exp $ - - -# 640x350 @ 85Hz (VESA) hsync: 37.9kHz -ModeLine "640x350" 31.5 640 672 736 832 350 382 385 445 +hsync -vsync - -# 640x400 @ 85Hz (VESA) hsync: 37.9kHz -ModeLine "640x400" 31.5 640 672 736 832 400 401 404 445 -hsync +vsync - -# 720x400 @ 85Hz (VESA) hsync: 37.9kHz -ModeLine "720x400" 35.5 720 756 828 936 400 401 404 446 -hsync +vsync - -# 640x480 @ 60Hz (Industry standard) hsync: 31.5kHz -ModeLine "640x480" 25.175 640 656 752 800 480 490 492 525 -hsync -vsync - -# 640x480 @ 72Hz (VESA) hsync: 37.9kHz -ModeLine "640x480" 31.5 640 664 704 832 480 489 492 520 -hsync -vsync - -# 640x480 @ 75Hz (VESA) hsync: 37.5kHz -ModeLine "640x480" 31.5 640 656 720 840 480 481 484 500 -hsync -vsync - -# 640x480 @ 85Hz (VESA) hsync: 43.3kHz -ModeLine "640x480" 36.0 640 696 752 832 480 481 484 509 -hsync -vsync - -# 800x600 @ 56Hz (VESA) hsync: 35.2kHz -ModeLine "800x600" 36.0 800 824 896 1024 600 601 603 625 +hsync +vsync - -# 800x600 @ 60Hz (VESA) hsync: 37.9kHz -ModeLine "800x600" 40.0 800 840 968 1056 600 601 605 628 +hsync +vsync - -# 800x600 @ 72Hz (VESA) hsync: 48.1kHz -ModeLine "800x600" 50.0 800 856 976 1040 600 637 643 666 +hsync +vsync - -# 800x600 @ 75Hz (VESA) hsync: 46.9kHz -ModeLine "800x600" 49.5 800 816 896 1056 600 601 604 625 +hsync +vsync - -# 800x600 @ 85Hz (VESA) hsync: 53.7kHz -ModeLine "800x600" 56.3 800 832 896 1048 600 601 604 631 +hsync +vsync - -# 1024x768i @ 43Hz (industry standard) hsync: 35.5kHz -ModeLine "1024x768" 44.9 1024 1032 1208 1264 768 768 776 817 +hsync +vsync Interlace - -# 1024x768 @ 60Hz (VESA) hsync: 48.4kHz -ModeLine "1024x768" 65.0 1024 1048 1184 1344 768 771 777 806 -hsync -vsync - -# 1024x768 @ 70Hz (VESA) hsync: 56.5kHz -ModeLine "1024x768" 75.0 1024 1048 1184 1328 768 771 777 806 -hsync -vsync - -# 1024x768 @ 75Hz (VESA) hsync: 60.0kHz -ModeLine "1024x768" 78.75 1024 1040 1136 1312 768 769 772 800 +hsync +vsync - -# 1024x768 @ 85Hz (VESA) hsync: 68.7kHz -ModeLine "1024x768" 94.5 1024 1072 1168 1376 768 769 772 808 +hsync +vsync - -# 1152x864 @ 75Hz (VESA) hsync: 67.5kHz -ModeLine "1152x864" 108.0 1152 1216 1344 1600 864 865 868 900 +hsync +vsync - -# 1280x960 @ 60Hz (VESA) hsync: 60.0kHz -ModeLine "1280x960" 108.0 1280 1376 1488 1800 960 961 964 1000 +hsync +vsync - -# 1280x960 @ 85Hz (VESA) hsync: 85.9kHz -ModeLine "1280x960" 148.5 1280 1344 1504 1728 960 961 964 1011 +hsync +vsync - -# 1280x1024 @ 60Hz (VESA) hsync: 64.0kHz -ModeLine "1280x1024" 108.0 1280 1328 1440 1688 1024 1025 1028 1066 +hsync +vsync - -# 1280x1024 @ 75Hz (VESA) hsync: 80.0kHz -ModeLine "1280x1024" 135.0 1280 1296 1440 1688 1024 1025 1028 1066 +hsync +vsync - -# 1280x1024 @ 85Hz (VESA) hsync: 91.1kHz -ModeLine "1280x1024" 157.5 1280 1344 1504 1728 1024 1025 1028 1072 +hsync +vsync - -# 1600x1200 @ 60Hz (VESA) hsync: 75.0kHz -ModeLine "1600x1200" 162.0 1600 1664 1856 2160 1200 1201 1204 1250 +hsync +vsync - -# 1600x1200 @ 65Hz (VESA) hsync: 81.3kHz -ModeLine "1600x1200" 175.5 1600 1664 1856 2160 1200 1201 1204 1250 +hsync +vsync - -# 1600x1200 @ 70Hz (VESA) hsync: 87.5kHz -ModeLine "1600x1200" 189.0 1600 1664 1856 2160 1200 1201 1204 1250 +hsync +vsync - -# 1600x1200 @ 75Hz (VESA) hsync: 93.8kHz -ModeLine "1600x1200" 202.5 1600 1664 1856 2160 1200 1201 1204 1250 +hsync +vsync - -# 1600x1200 @ 85Hz (VESA) hsync: 106.3kHz -ModeLine "1600x1200" 229.5 1600 1664 1856 2160 1200 1201 1204 1250 +hsync +vsync - -# 1792x1344 @ 60Hz (VESA) hsync: 83.6kHz -ModeLine "1792x1344" 204.8 1792 1920 2120 2448 1344 1345 1348 1394 -hsync +vsync - -# 1792x1344 @ 75Hz (VESA) hsync: 106.3kHz -ModeLine "1792x1344" 261.0 1792 1888 2104 2456 1344 1345 1348 1417 -hsync +vsync - -# 1856x1392 @ 60Hz (VESA) hsync: 86.3kHz -ModeLine "1856x1392" 218.3 1856 1952 2176 2528 1392 1393 1396 1439 -hsync +vsync - -# 1856x1392 @ 75Hz (VESA) hsync: 112.5kHz -ModeLine "1856x1392" 288.0 1856 1984 2208 2560 1392 1393 1396 1500 -hsync +vsync - -# 1920x1440 @ 60Hz (VESA) hsync: 90.0kHz -ModeLine "1920x1440" 234.0 1920 2048 2256 2600 1440 1441 1444 1500 -hsync +vsync - -# 1920x1440 @ 75Hz (VESA) hsync: 112.5kHz -ModeLine "1920x1440" 297.0 1920 2064 2288 2640 1440 1441 1444 1500 -hsync +vsync - - diff --git a/hw/xfree86/common/xaarop.h b/hw/xfree86/common/xaarop.h deleted file mode 100644 index 84aa9baba..000000000 --- a/hw/xfree86/common/xaarop.h +++ /dev/null @@ -1,268 +0,0 @@ -#ifndef _XAAROP_H -#define _XAAROP_H - -#define ROP_DST 0x00000001 -#define ROP_SRC 0x00000002 -#define ROP_PAT 0x00000004 - -#define ROP_0 0x00 -#define ROP_DPSoon 0x01 -#define ROP_DPSona 0x02 -#define ROP_PSon 0x03 -#define ROP_SDPona 0x04 -#define ROP_DPon 0x05 -#define ROP_PDSxnon 0x06 -#define ROP_PDSaon 0x07 -#define ROP_SDPnaa 0x08 -#define ROP_PDSxon 0x09 -#define ROP_DPna 0x0A -#define ROP_PSDnaon 0x0B -#define ROP_SPna 0x0C -#define ROP_PDSnaon 0x0D -#define ROP_PDSonon 0x0E -#define ROP_Pn 0x0F -#define ROP_PDSona 0x10 -#define ROP_DSon 0x11 -#define ROP_SDPxnon 0x12 -#define ROP_SDPaon 0x13 -#define ROP_DPSxnon 0x14 -#define ROP_DPSaon 0x15 -#define ROP_PSDPSanaxx 0x16 -#define ROP_SSPxDSxaxn 0x17 -#define ROP_SPxPDxa 0x18 -#define ROP_SDPSanaxn 0x19 -#define ROP_PDSPaox 0x1A -#define ROP_SDPSxaxn 0x1B -#define ROP_PSDPaox 0x1C -#define ROP_DSPDxaxn 0x1D -#define ROP_PDSox 0x1E -#define ROP_PDSoan 0x1F -#define ROP_DPSnaa 0x20 -#define ROP_SDPxon 0x21 -#define ROP_DSna 0x22 -#define ROP_SPDnaon 0x23 -#define ROP_SPxDSxa 0x24 -#define ROP_PDSPanaxn 0x25 -#define ROP_SDPSaox 0x26 -#define ROP_SDPSxnox 0x27 -#define ROP_DPSxa 0x28 -#define ROP_PSDPSaoxxn 0x29 -#define ROP_DPSana 0x2A -#define ROP_SSPxPDxaxn 0x2B -#define ROP_SPDSoax 0x2C -#define ROP_PSDnox 0x2D -#define ROP_PSDPxox 0x2E -#define ROP_PSDnoan 0x2F -#define ROP_PSna 0x30 -#define ROP_SDPnaon 0x31 -#define ROP_SDPSoox 0x32 -#define ROP_Sn 0x33 -#define ROP_SPDSaox 0x34 -#define ROP_SPDSxnox 0x35 -#define ROP_SDPox 0x36 -#define ROP_SDPoan 0x37 -#define ROP_PSDPoax 0x38 -#define ROP_SPDnox 0x39 -#define ROP_SPDSxox 0x3A -#define ROP_SPDnoan 0x3B -#define ROP_PSx 0x3C -#define ROP_SPDSonox 0x3D -#define ROP_SPDSnaox 0x3E -#define ROP_PSan 0x3F -#define ROP_PSDnaa 0x40 -#define ROP_DPSxon 0x41 -#define ROP_SDxPDxa 0x42 -#define ROP_SPDSanaxn 0x43 -#define ROP_SDna 0x44 -#define ROP_DPSnaon 0x45 -#define ROP_DSPDaox 0x46 -#define ROP_PSDPxaxn 0x47 -#define ROP_SDPxa 0x48 -#define ROP_PDSPDaoxxn 0x49 -#define ROP_DPSDoax 0x4A -#define ROP_PDSnox 0x4B -#define ROP_SDPana 0x4C -#define ROP_SSPxDSxoxn 0x4D -#define ROP_PDSPxox 0x4E -#define ROP_PDSnoan 0x4F -#define ROP_PDna 0x50 -#define ROP_DSPnaon 0x51 -#define ROP_DPSDaox 0x52 -#define ROP_SPDSxaxn 0x53 -#define ROP_DPSonon 0x54 -#define ROP_Dn 0x55 -#define ROP_DPSox 0x56 -#define ROP_DPSoan 0x57 -#define ROP_PDSPoax 0x58 -#define ROP_DPSnox 0x59 -#define ROP_DPx 0x5A -#define ROP_DPSDonox 0x5B -#define ROP_DPSDxox 0x5C -#define ROP_DPSnoan 0x5D -#define ROP_DPSDnaox 0x5E -#define ROP_DPan 0x5F -#define ROP_PDSxa 0x60 -#define ROP_DSPDSaoxxn 0x61 -#define ROP_DSPDoax 0x62 -#define ROP_SDPnox 0x63 -#define ROP_SDPSoax 0x64 -#define ROP_DSPnox 0x65 -#define ROP_DSx 0x66 -#define ROP_SDPSonox 0x67 -#define ROP_DSPDSonoxxn 0x68 -#define ROP_PDSxxn 0x69 -#define ROP_DPSax 0x6A -#define ROP_PSDPSoaxxn 0x6B -#define ROP_SDPax 0x6C -#define ROP_PDSPDoaxxn 0x6D -#define ROP_SDPSnoax 0x6E -#define ROP_PDSxnan 0x6F -#define ROP_PDSana 0x70 -#define ROP_SSDxPDxaxn 0x71 -#define ROP_SDPSxox 0x72 -#define ROP_SDPnoan 0x73 -#define ROP_DSPDxox 0x74 -#define ROP_DSPnoan 0x75 -#define ROP_SDPSnaox 0x76 -#define ROP_DSan 0x77 -#define ROP_PDSax 0x78 -#define ROP_DSPDSoaxxn 0x79 -#define ROP_DPSDnoax 0x7A -#define ROP_SDPxnan 0x7B -#define ROP_SPDSnoax 0x7C -#define ROP_DPSxnan 0x7D -#define ROP_SPxDSxo 0x7E -#define ROP_DPSaan 0x7F -#define ROP_DPSaa 0x80 -#define ROP_SPxDSxon 0x81 -#define ROP_DPSxna 0x82 -#define ROP_SPDSnoaxn 0x83 -#define ROP_SDPxna 0x84 -#define ROP_PDSPnoaxn 0x85 -#define ROP_DSPDSoaxx 0x86 -#define ROP_PDSaxn 0x87 -#define ROP_DSa 0x88 -#define ROP_SDPSnaoxn 0x89 -#define ROP_DSPnoa 0x8A -#define ROP_DSPDxoxn 0x8B -#define ROP_SDPnoa 0x8C -#define ROP_SDPSxoxn 0x8D -#define ROP_SSDxPDxax 0x8E -#define ROP_PDSanan 0x8F -#define ROP_PDSxna 0x90 -#define ROP_SDPSnoaxn 0x91 -#define ROP_DPSDPoaxx 0x92 -#define ROP_SPDaxn 0x93 -#define ROP_PSDPSoaxx 0x94 -#define ROP_DPSaxn 0x95 -#define ROP_DPSxx 0x96 -#define ROP_PSDPSonoxx 0x97 -#define ROP_SDPSonoxn 0x98 -#define ROP_DSxn 0x99 -#define ROP_DPSnax 0x9A -#define ROP_SDPSoaxn 0x9B -#define ROP_SPDnax 0x9C -#define ROP_DSPDoaxn 0x9D -#define ROP_DSPDSaoxx 0x9E -#define ROP_PDSxan 0x9F -#define ROP_DPa 0xA0 -#define ROP_PDSPnaoxn 0xA1 -#define ROP_DPSnoa 0xA2 -#define ROP_DPSDxoxn 0xA3 -#define ROP_PDSPonoxn 0xA4 -#define ROP_PDxn 0xA5 -#define ROP_DSPnax 0xA6 -#define ROP_PDSPoaxn 0xA7 -#define ROP_DPSoa 0xA8 -#define ROP_DPSoxn 0xA9 -#define ROP_D 0xAA -#define ROP_DPSono 0xAB -#define ROP_SPDSxax 0xAC -#define ROP_DPSDaoxn 0xAD -#define ROP_DSPnao 0xAE -#define ROP_DPno 0xAF -#define ROP_PDSnoa 0xB0 -#define ROP_PDSPxoxn 0xB1 -#define ROP_SSPxDSxox 0xB2 -#define ROP_SDPanan 0xB3 -#define ROP_PSDnax 0xB4 -#define ROP_DPSDoaxn 0xB5 -#define ROP_DPSDPaoxx 0xB6 -#define ROP_SDPxan 0xB7 -#define ROP_PSDPxax 0xB8 -#define ROP_DSPDaoxn 0xB9 -#define ROP_DPSnao 0xBA -#define ROP_DSno 0xBB -#define ROP_SPDSanax 0xBC -#define ROP_SDxPDxan 0xBD -#define ROP_DPSxo 0xBE -#define ROP_DPSano 0xBF -#define ROP_Psa 0xC0 -#define ROP_SPDSnaoxn 0xC1 -#define ROP_SPDSonoxn 0xC2 -#define ROP_PSxn 0xC3 -#define ROP_SPDnoa 0xC4 -#define ROP_SPDSxoxn 0xC5 -#define ROP_SDPnax 0xC6 -#define ROP_PSDPoaxn 0xC7 -#define ROP_SDPoa 0xC8 -#define ROP_SPDoxn 0xC9 -#define ROP_DPSDxax 0xCA -#define ROP_SPDSaoxn 0xCB -#define ROP_S 0xCC -#define ROP_SDPono 0xCD -#define ROP_SDPnao 0xCE -#define ROP_SPno 0xCF -#define ROP_PSDnoa 0xD0 -#define ROP_PSDPxoxn 0xD1 -#define ROP_PDSnax 0xD2 -#define ROP_SPDSoaxn 0xD3 -#define ROP_SSPxPDxax 0xD4 -#define ROP_DPSanan 0xD5 -#define ROP_PSDPSaoxx 0xD6 -#define ROP_DPSxan 0xD7 -#define ROP_PDSPxax 0xD8 -#define ROP_SDPSaoxn 0xD9 -#define ROP_DPSDanax 0xDA -#define ROP_SPxDSxan 0xDB -#define ROP_SPDnao 0xDC -#define ROP_SDno 0xDD -#define ROP_SDPxo 0xDE -#define ROP_SDPano 0xDF -#define ROP_PDSoa 0xE0 -#define ROP_PDSoxn 0xE1 -#define ROP_DSPDxax 0xE2 -#define ROP_PSDPaoxn 0xE3 -#define ROP_SDPSxax 0xE4 -#define ROP_PDSPaoxn 0xE5 -#define ROP_SDPSanax 0xE6 -#define ROP_SPxPDxan 0xE7 -#define ROP_SSPxDSxax 0xE8 -#define ROP_DSPDSanaxxn 0xE9 -#define ROP_DPSao 0xEA -#define ROP_DPSxno 0xEB -#define ROP_SDPao 0xEC -#define ROP_SDPxno 0xED -#define ROP_DSo 0xEE -#define ROP_SDPnoo 0xEF -#define ROP_P 0xF0 -#define ROP_PDSono 0xF1 -#define ROP_PDSnao 0xF2 -#define ROP_PSno 0xF3 -#define ROP_PSDnao 0xF4 -#define ROP_PDno 0xF5 -#define ROP_PDSxo 0xF6 -#define ROP_PDSano 0xF7 -#define ROP_PDSao 0xF8 -#define ROP_PDSxno 0xF9 -#define ROP_DPo 0xFA -#define ROP_DPSnoo 0xFB -#define ROP_PSo 0xFC -#define ROP_PSDnoo 0xFD -#define ROP_DPSoo 0xFE -#define ROP_1 0xFF - -#define NO_SRC_ROP(rop) \ - ((rop == GXnoop) || (rop == GXset) || (rop == GXclear) || (rop == GXinvert)) - -#endif /* _XAAROP_H */ diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h deleted file mode 100644 index 927a7a7f1..000000000 --- a/hw/xfree86/common/xf86.h +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains declarations for public XFree86 functions and variables, - * and definitions of public macros. - * - * "public" means available to video drivers. - */ - -#ifndef _XF86_H -#define _XF86_H - -#ifdef HAVE_XORG_CONFIG_H -#include -#elif HAVE_DIX_CONFIG_H -#include -#endif - -#include "xf86str.h" -#include "xf86Opt.h" -#include -#include -#ifdef RANDR -#include -#endif - -#include "propertyst.h" - -/* General parameters */ -extern _X_EXPORT int xf86DoConfigure; -extern _X_EXPORT int xf86DoShowOptions; -extern _X_EXPORT Bool xf86DoConfigurePass1; -extern _X_EXPORT Bool xf86ProbeIgnorePrimary; -extern _X_EXPORT Bool xorgHWAccess; - -extern _X_EXPORT DevPrivateKeyRec xf86ScreenKeyRec; - -#define xf86ScreenKey (&xf86ScreenKeyRec) - -extern _X_EXPORT ScrnInfoPtr *xf86Screens; /* List of pointers to ScrnInfoRecs */ -extern _X_EXPORT const unsigned char byte_reversed[256]; -extern _X_EXPORT Bool fbSlotClaimed; - -#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) -extern _X_EXPORT Bool sbusSlotClaimed; -#endif - -#if defined(XSERVER_PLATFORM_BUS) -extern _X_EXPORT int platformSlotClaimed; -#endif - -extern _X_EXPORT confDRIRec xf86ConfigDRI; -extern _X_EXPORT Bool xf86DRI2Enabled(void); - -#define XF86SCRNINFO(p) xf86ScreenToScrn(p) - -#define BOOLTOSTRING(b) ((b) ? "TRUE" : "FALSE") - -/* Compatibility functions for pre-input-thread drivers */ -static inline _X_DEPRECATED int xf86BlockSIGIO(void) { input_lock(); return 0; } -static inline _X_DEPRECATED void xf86UnblockSIGIO(int wasset) { input_unlock(); } - -/* Function Prototypes */ -#ifndef _NO_XF86_PROTOTYPES - -/* PCI related */ -#ifdef XSERVER_LIBPCIACCESS -#include -extern _X_EXPORT int pciSlotClaimed; - -extern _X_EXPORT Bool xf86CheckPciSlot(const struct pci_device *); -extern _X_EXPORT int xf86ClaimPciSlot(struct pci_device *, DriverPtr drvp, - int chipset, GDevPtr dev, Bool active); -extern _X_EXPORT void xf86UnclaimPciSlot(struct pci_device *, GDevPtr dev); -extern _X_EXPORT Bool xf86ParsePciBusString(const char *busID, int *bus, - int *device, int *func); -extern _X_EXPORT Bool xf86ComparePciBusString(const char *busID, int bus, - int device, int func); -extern _X_EXPORT Bool xf86IsPrimaryPci(struct pci_device *pPci); -extern _X_EXPORT Bool xf86CheckPciMemBase(struct pci_device *pPci, - memType base); -extern _X_EXPORT struct pci_device *xf86GetPciInfoForEntity(int entityIndex); -extern _X_EXPORT int xf86MatchPciInstances(const char *driverName, - int vendorID, SymTabPtr chipsets, - PciChipsets * PCIchipsets, - GDevPtr * devList, int numDevs, - DriverPtr drvp, int **foundEntities); -extern _X_EXPORT ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn, - int scrnFlag, int entityIndex, - PciChipsets * p_chip, - void *dummy, EntityProc init, - EntityProc enter, - EntityProc leave, - void *private); -#else -#define xf86VGAarbiterInit() do {} while (0) -#define xf86VGAarbiterFini() do {} while (0) -#define xf86VGAarbiterLock(x) do {} while (0) -#define xf86VGAarbiterUnlock(x) do {} while (0) -#define xf86VGAarbiterScrnInit(x) do {} while (0) -#define xf86VGAarbiterDeviceDecodes() do {} while (0) -#define xf86VGAarbiterWrapFunctions() do {} while (0) -#endif - -/* xf86Bus.c */ - -extern _X_EXPORT int xf86GetFbInfoForScreen(int scrnIndex); -extern _X_EXPORT int xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, - Bool active); -extern _X_EXPORT int xf86ClaimNoSlot(DriverPtr drvp, int chipset, GDevPtr dev, - Bool active); -extern _X_EXPORT Bool xf86DriverHasEntities(DriverPtr drvp); -extern _X_EXPORT void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex); -extern _X_EXPORT void xf86SetEntityInstanceForScreen(ScrnInfoPtr pScrn, - int entityIndex, - int instance); -extern _X_EXPORT int xf86GetNumEntityInstances(int entityIndex); -extern _X_EXPORT GDevPtr xf86GetDevFromEntity(int entityIndex, int instance); -extern _X_EXPORT void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, - int entityIndex); -extern _X_EXPORT EntityInfoPtr xf86GetEntityInfo(int entityIndex); -extern _X_EXPORT Bool xf86IsEntityPrimary(int entityIndex); -extern _X_EXPORT ScrnInfoPtr xf86FindScreenForEntity(int entityIndex); - -#define xf86SetLastScrnFlag(e, s) do { } while (0) - -extern _X_EXPORT Bool xf86IsEntityShared(int entityIndex); -extern _X_EXPORT void xf86SetEntityShared(int entityIndex); -extern _X_EXPORT Bool xf86IsEntitySharable(int entityIndex); -extern _X_EXPORT void xf86SetEntitySharable(int entityIndex); -extern _X_EXPORT Bool xf86IsPrimInitDone(int entityIndex); -extern _X_EXPORT void xf86SetPrimInitDone(int entityIndex); -extern _X_EXPORT void xf86ClearPrimInitDone(int entityIndex); -extern _X_EXPORT int xf86AllocateEntityPrivateIndex(void); -extern _X_EXPORT DevUnion *xf86GetEntityPrivate(int entityIndex, int privIndex); - -/* xf86Configure.c */ -extern _X_EXPORT GDevPtr xf86AddBusDeviceToConfigure(const char *driver, - BusType bus, void *busData, - int chipset); - -/* xf86Cursor.c */ - -extern _X_EXPORT void xf86LockZoom(ScreenPtr pScreen, int lock); -extern _X_EXPORT void xf86InitViewport(ScrnInfoPtr pScr); -extern _X_EXPORT void xf86SetViewport(ScreenPtr pScreen, int x, int y); -extern _X_EXPORT void xf86ZoomViewport(ScreenPtr pScreen, int zoom); -extern _X_EXPORT Bool xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode); -extern _X_EXPORT void *xf86GetPointerScreenFuncs(void); -extern _X_EXPORT void xf86InitOrigins(void); -extern _X_EXPORT void xf86ReconfigureLayout(void); - -/* xf86DPMS.c */ - -extern _X_EXPORT Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, - int flags); - -/* xf86DGA.c */ - -#ifdef XFreeXDGA -extern _X_EXPORT Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs, - DGAModePtr modes, int num); -extern _X_EXPORT Bool DGAReInitModes(ScreenPtr pScreen, DGAModePtr modes, - int num); -extern _X_EXPORT xf86SetDGAModeProc xf86SetDGAMode; -#endif - -/* xf86Events.c */ - -typedef struct _InputInfoRec *InputInfoPtr; - -extern _X_EXPORT void SetTimeSinceLastInputEvent(void); -extern _X_EXPORT void *xf86AddInputHandler(int fd, InputHandlerProc proc, - void *data); -extern _X_EXPORT int xf86RemoveInputHandler(void *handler); -extern _X_EXPORT void xf86DisableInputHandler(void *handler); -extern _X_EXPORT void xf86EnableInputHandler(void *handler); -extern _X_EXPORT void *xf86AddGeneralHandler(int fd, InputHandlerProc proc, - void *data); -extern _X_EXPORT int xf86RemoveGeneralHandler(void *handler); -extern _X_EXPORT void xf86DisableGeneralHandler(void *handler); -extern _X_EXPORT void xf86EnableGeneralHandler(void *handler); -extern _X_EXPORT InputHandlerProc xf86SetConsoleHandler(InputHandlerProc - handler, void *data); -extern _X_EXPORT void xf86ProcessActionEvent(ActionEvent action, void *arg); -extern _X_EXPORT void xf86PrintBacktrace(void); -extern _X_EXPORT Bool xf86VTOwner(void); -extern _X_EXPORT void xf86VTLeave(void); -extern _X_EXPORT void xf86VTEnter(void); -extern _X_EXPORT void xf86EnableInputDeviceForVTSwitch(InputInfoPtr pInfo); -extern _X_EXPORT void xf86DisableInputDeviceForVTSwitch(InputInfoPtr pInfo); - -/* xf86Helper.c */ - -extern _X_EXPORT void xf86AddDriver(DriverPtr driver, void *module, - int flags); -extern _X_EXPORT void xf86DeleteDriver(int drvIndex); -extern _X_EXPORT ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags); -extern _X_EXPORT void xf86DeleteScreen(ScrnInfoPtr pScrn); -extern _X_EXPORT int xf86AllocateScrnInfoPrivateIndex(void); -extern _X_EXPORT Bool xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, - int pad); -extern _X_EXPORT Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp, - int fbbpp, int depth24flags); -extern _X_EXPORT void xf86PrintDepthBpp(ScrnInfoPtr scrp); -extern _X_EXPORT Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask); -extern _X_EXPORT Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual); -extern _X_EXPORT Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma newGamma); -extern _X_EXPORT void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y); -extern _X_EXPORT void xf86SetBlackWhitePixels(ScreenPtr pScreen); -extern _X_EXPORT void xf86EnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable); -extern _X_EXPORT void -xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, - const char *format, va_list args) -_X_ATTRIBUTE_PRINTF(4, 0); -extern _X_EXPORT void -xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, - const char *format, ...) -_X_ATTRIBUTE_PRINTF(4, 5); -extern _X_EXPORT void -xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...) -_X_ATTRIBUTE_PRINTF(3, 4); -extern _X_EXPORT void -xf86MsgVerb(MessageType type, int verb, const char *format, ...) -_X_ATTRIBUTE_PRINTF(3, 4); -extern _X_EXPORT void -xf86Msg(MessageType type, const char *format, ...) -_X_ATTRIBUTE_PRINTF(2, 3); -extern _X_EXPORT void -xf86ErrorFVerb(int verb, const char *format, ...) -_X_ATTRIBUTE_PRINTF(2, 3); -extern _X_EXPORT void -xf86ErrorF(const char *format, ...) -_X_ATTRIBUTE_PRINTF(1, 2); -extern _X_EXPORT const char * -xf86TokenToString(SymTabPtr table, int token); -extern _X_EXPORT int -xf86StringToToken(SymTabPtr table, const char *string); -extern _X_EXPORT void -xf86ShowClocks(ScrnInfoPtr scrp, MessageType from); -extern _X_EXPORT void -xf86PrintChipsets(const char *drvname, const char *drvmsg, SymTabPtr chips); -extern _X_EXPORT int -xf86MatchDevice(const char *drivername, GDevPtr ** driversectlist); -extern _X_EXPORT const char * -xf86GetVisualName(int visual); -extern _X_EXPORT int -xf86GetVerbosity(void); -extern _X_EXPORT int -xf86GetDepth(void); -extern _X_EXPORT rgb -xf86GetWeight(void); -extern _X_EXPORT Gamma -xf86GetGamma(void); -extern _X_EXPORT Bool -xf86ServerIsExiting(void); -extern _X_EXPORT Bool -xf86ServerIsResetting(void); -extern _X_EXPORT Bool -xf86ServerIsOnlyDetecting(void); -extern _X_EXPORT Bool -xf86GetVidModeAllowNonLocal(void); -extern _X_EXPORT Bool -xf86GetVidModeEnabled(void); -extern _X_EXPORT Bool -xf86GetModInDevAllowNonLocal(void); -extern _X_EXPORT Bool -xf86GetModInDevEnabled(void); -extern _X_EXPORT Bool -xf86GetAllowMouseOpenFail(void); -extern _X_EXPORT CARD32 -xorgGetVersion(void); -extern _X_EXPORT CARD32 -xf86GetModuleVersion(void *module); -extern _X_EXPORT void * -xf86LoadDrvSubModule(DriverPtr drv, const char *name); -extern _X_EXPORT void * -xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name); -extern _X_EXPORT void * -xf86LoadOneModule(const char *name, void *optlist); -extern _X_EXPORT void -xf86UnloadSubModule(void *mod); -extern _X_EXPORT Bool -xf86LoaderCheckSymbol(const char *name); -extern _X_EXPORT void -xf86SetBackingStore(ScreenPtr pScreen); -extern _X_EXPORT void -xf86SetSilkenMouse(ScreenPtr pScreen); -extern _X_EXPORT void * -xf86FindXvOptions(ScrnInfoPtr pScrn, int adapt_index, const char *port_name, - const char **adaptor_name, void **adaptor_options); -extern _X_EXPORT ScrnInfoPtr -xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, - int entityIndex, EntityProc init, - EntityProc enter, EntityProc leave, void *private); - -extern _X_EXPORT Bool -xf86IsScreenPrimary(ScrnInfoPtr pScrn); -extern _X_EXPORT Bool -xf86IsUnblank(int mode); - -/* xf86Init.c */ - -extern _X_EXPORT PixmapFormatPtr -xf86GetPixFormat(ScrnInfoPtr pScrn, int depth); -extern _X_EXPORT int -xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth); - -/* xf86Mode.c */ - -extern _X_EXPORT const char * -xf86ModeStatusToString(ModeStatus status); -extern _X_EXPORT ModeStatus -xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor); -extern _X_EXPORT ModeStatus -xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags); -extern _X_EXPORT int -xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, - const char **modeNames, ClockRangePtr clockRanges, - int *linePitches, int minPitch, int maxPitch, - int minHeight, int maxHeight, int pitchInc, - int virtualX, int virtualY, int apertureSize, - LookupModeFlags strategy); -extern _X_EXPORT void -xf86DeleteMode(DisplayModePtr * modeList, DisplayModePtr mode); -extern _X_EXPORT void -xf86PruneDriverModes(ScrnInfoPtr scrp); -extern _X_EXPORT void -xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags); -extern _X_EXPORT void -xf86PrintModes(ScrnInfoPtr scrp); -extern _X_EXPORT void -xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges); - -/* xf86Option.c */ - -extern _X_EXPORT void -xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts); - -/* xf86RandR.c */ -#ifdef RANDR -extern _X_EXPORT Bool -xf86RandRInit(ScreenPtr pScreen); -extern _X_EXPORT Rotation -xf86GetRotation(ScreenPtr pScreen); -extern _X_EXPORT Bool -xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen, - int newvirtX, int newvirtY, - int newmmWidth, int newmmHeight, - Bool resetMode); -#endif - -/* xf86Extensions.c */ -extern void xf86ExtensionInit(void); - -/* convert ScreenPtr to ScrnInfoPtr */ -extern _X_EXPORT ScrnInfoPtr xf86ScreenToScrn(ScreenPtr pScreen); -/* convert ScrnInfoPtr to ScreenPtr */ -extern _X_EXPORT ScreenPtr xf86ScrnToScreen(ScrnInfoPtr pScrn); - -#endif /* _NO_XF86_PROTOTYPES */ - -#define XF86_HAS_SCRN_CONV 1 /* define for drivers to use in api compat */ - -#define XF86_SCRN_INTERFACE 1 /* define for drivers to use in api compat */ - -/* flags passed to xf86 allocate screen */ -#define XF86_ALLOCATE_GPU_SCREEN 1 - -/* Update the internal total dimensions of all ScreenRecs together */ -extern _X_EXPORT void -xf86UpdateDesktopDimensions(void); - -#endif /* _XF86_H */ diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c deleted file mode 100644 index 0f4f05de9..000000000 --- a/hw/xfree86/common/xf86AutoConfig.c +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Copyright 2003 by David H. Dawes. - * Copyright 2003 by X-Oz Technologies. - * All rights reserved. - * - * 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). - * - * Author: David Dawes . - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "xf86Config.h" -#include "xf86MatchDrivers.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86platformBus.h" -#include "xf86pciBus.h" -#ifdef __sparc__ -#include "xf86sbusBus.h" -#endif - -#ifdef __sun -#include -#include -#endif - -/* Sections for the default built-in configuration. */ - -#define BUILTIN_DEVICE_NAME \ - "\"Builtin Default %s Device %d\"" - -#define BUILTIN_DEVICE_SECTION_PRE \ - "Section \"Device\"\n" \ - "\tIdentifier\t" BUILTIN_DEVICE_NAME "\n" \ - "\tDriver\t\"%s\"\n" - -#define BUILTIN_DEVICE_SECTION_POST \ - "EndSection\n\n" - -#define BUILTIN_DEVICE_SECTION \ - BUILTIN_DEVICE_SECTION_PRE \ - BUILTIN_DEVICE_SECTION_POST - -#define BUILTIN_SCREEN_NAME \ - "\"Builtin Default %s Screen %d\"" - -#define BUILTIN_SCREEN_SECTION \ - "Section \"Screen\"\n" \ - "\tIdentifier\t" BUILTIN_SCREEN_NAME "\n" \ - "\tDevice\t" BUILTIN_DEVICE_NAME "\n" \ - "EndSection\n\n" - -#define BUILTIN_LAYOUT_SECTION_PRE \ - "Section \"ServerLayout\"\n" \ - "\tIdentifier\t\"Builtin Default Layout\"\n" - -#define BUILTIN_LAYOUT_SCREEN_LINE \ - "\tScreen\t" BUILTIN_SCREEN_NAME "\n" - -#define BUILTIN_LAYOUT_SECTION_POST \ - "EndSection\n\n" - -static const char **builtinConfig = NULL; -static int builtinLines = 0; - -static void listPossibleVideoDrivers(XF86MatchedDrivers *md); - -/* - * A built-in config file is stored as an array of strings, with each string - * representing a single line. AppendToConfig() breaks up the string "s" - * into lines, and appends those lines it to builtinConfig. - */ - -static void -AppendToList(const char *s, const char ***list, int *lines) -{ - char *str, *newstr, *p; - - str = xnfstrdup(s); - for (p = strtok(str, "\n"); p; p = strtok(NULL, "\n")) { - (*lines)++; - *list = xnfreallocarray(*list, *lines + 1, sizeof(**list)); - newstr = xnfalloc(strlen(p) + 2); - strcpy(newstr, p); - strcat(newstr, "\n"); - (*list)[*lines - 1] = newstr; - (*list)[*lines] = NULL; - } - free(str); -} - -static void -FreeList(const char ***list, int *lines) -{ - int i; - - for (i = 0; i < *lines; i++) { - free((char *) ((*list)[i])); - } - free(*list); - *list = NULL; - *lines = 0; -} - -static void -FreeConfig(void) -{ - FreeList(&builtinConfig, &builtinLines); -} - -static void -AppendToConfig(const char *s) -{ - AppendToList(s, &builtinConfig, &builtinLines); -} - -void -xf86AddMatchedDriver(XF86MatchedDrivers *md, const char *driver) -{ - int j; - int nmatches = md->nmatches; - - for (j = 0; j < nmatches; ++j) { - if (xf86NameCmp(md->matches[j], driver) == 0) { - // Driver already in matched drivers - return; - } - } - - if (nmatches < MATCH_DRIVERS_LIMIT) { - md->matches[nmatches] = xnfstrdup(driver); - md->nmatches++; - } - else { - xf86Msg(X_WARNING, "Too many drivers registered, can't add %s\n", driver); - } -} - -Bool -xf86AutoConfig(void) -{ - XF86MatchedDrivers md; - int i; - const char **cp; - char buf[1024]; - ConfigStatus ret; - - /* Make sure config rec is there */ - if (xf86allocateConfig() != NULL) { - ret = CONFIG_OK; /* OK so far */ - } - else { - xf86Msg(X_ERROR, "Couldn't allocate Config record.\n"); - return FALSE; - } - - listPossibleVideoDrivers(&md); - - for (i = 0; i < md.nmatches; i++) { - snprintf(buf, sizeof(buf), BUILTIN_DEVICE_SECTION, - md.matches[i], 0, md.matches[i]); - AppendToConfig(buf); - snprintf(buf, sizeof(buf), BUILTIN_SCREEN_SECTION, - md.matches[i], 0, md.matches[i], 0); - AppendToConfig(buf); - } - - AppendToConfig(BUILTIN_LAYOUT_SECTION_PRE); - for (i = 0; i < md.nmatches; i++) { - snprintf(buf, sizeof(buf), BUILTIN_LAYOUT_SCREEN_LINE, - md.matches[i], 0); - AppendToConfig(buf); - } - AppendToConfig(BUILTIN_LAYOUT_SECTION_POST); - - for (i = 0; i < md.nmatches; i++) { - free(md.matches[i]); - } - - xf86MsgVerb(X_DEFAULT, 0, - "Using default built-in configuration (%d lines)\n", - builtinLines); - - xf86MsgVerb(X_DEFAULT, 3, "--- Start of built-in configuration ---\n"); - for (cp = builtinConfig; *cp; cp++) - xf86ErrorFVerb(3, "\t%s", *cp); - xf86MsgVerb(X_DEFAULT, 3, "--- End of built-in configuration ---\n"); - - xf86initConfigFiles(); - xf86setBuiltinConfig(builtinConfig); - ret = xf86HandleConfigFile(TRUE); - FreeConfig(); - - if (ret != CONFIG_OK) - xf86Msg(X_ERROR, "Error parsing the built-in default configuration.\n"); - - return ret == CONFIG_OK; -} - -static void -listPossibleVideoDrivers(XF86MatchedDrivers *md) -{ - md->nmatches = 0; - -#ifdef XSERVER_PLATFORM_BUS - xf86PlatformMatchDriver(md); -#endif -#ifdef __sun - /* Check for driver type based on /dev/fb type and if valid, use - it instead of PCI bus probe results */ - if (xf86Info.consoleFd >= 0) { - struct vis_identifier visid; - const char *cp; - int iret; - - SYSCALL(iret = ioctl(xf86Info.consoleFd, VIS_GETIDENTIFIER, &visid)); - if (iret < 0) { - int fbfd; - - fbfd = open(xf86SolarisFbDev, O_RDONLY); - if (fbfd >= 0) { - SYSCALL(iret = ioctl(fbfd, VIS_GETIDENTIFIER, &visid)); - close(fbfd); - } - } - - if (iret < 0) { - xf86Msg(X_WARNING, - "could not get frame buffer identifier from %s\n", - xf86SolarisFbDev); - } - else { - xf86Msg(X_PROBED, "console driver: %s\n", visid.name); - - /* Special case from before the general case was set */ - if (strcmp(visid.name, "NVDAnvda") == 0) { - xf86AddMatchedDriver(md, "nvidia"); - } - - /* General case - split into vendor name (initial all-caps - prefix) & driver name (rest of the string). */ - if (strcmp(visid.name, "SUNWtext") != 0) { - for (cp = visid.name; (*cp != '\0') && isupper(*cp); cp++) { - /* find end of all uppercase vendor section */ - } - if ((cp != visid.name) && (*cp != '\0')) { - char *vendorName = xnfstrdup(visid.name); - - vendorName[cp - visid.name] = '\0'; - - xf86AddMatchedDriver(md, vendorName); - xf86AddMatchedDriver(md, cp); - - free(vendorName); - } - } - } - } -#endif -#ifdef __sparc__ - char *sbusDriver = sparcDriverName(); - - if (sbusDriver) - xf86AddMatchedDriver(md, sbusDriver); -#endif -#ifdef XSERVER_LIBPCIACCESS - xf86PciMatchDriver(md); -#endif - -#if defined(__linux__) - xf86AddMatchedDriver(md, "modesetting"); -#endif - -#if !defined(__sun) - /* Fallback to platform default frame buffer driver */ -#if !defined(__linux__) && defined(__sparc__) - xf86AddMatchedDriver(md, "wsfb"); -#else - xf86AddMatchedDriver(md, "fbdev"); -#endif -#endif /* !__sun */ - - /* Fallback to platform default hardware */ -#if defined(__i386__) || defined(__amd64__) || defined(__hurd__) - xf86AddMatchedDriver(md, "vesa"); -#elif defined(__sparc__) && !defined(__sun) - xf86AddMatchedDriver(md, "sunffb"); -#endif -} - -/* copy a screen section and enter the desired driver - * and insert it at i in the list of screens */ -static Bool -copyScreen(confScreenPtr oscreen, GDevPtr odev, int i, char *driver) -{ - confScreenPtr nscreen; - GDevPtr cptr = NULL; - char *identifier; - - nscreen = malloc(sizeof(confScreenRec)); - if (!nscreen) - return FALSE; - memcpy(nscreen, oscreen, sizeof(confScreenRec)); - - cptr = malloc(sizeof(GDevRec)); - if (!cptr) { - free(nscreen); - return FALSE; - } - memcpy(cptr, odev, sizeof(GDevRec)); - - if (asprintf(&identifier, "Autoconfigured Video Device %s", driver) - == -1) { - free(cptr); - free(nscreen); - return FALSE; - } - cptr->driver = driver; - cptr->identifier = identifier; - - xf86ConfigLayout.screens[i].screen = nscreen; - - /* now associate the new driver entry with the new screen entry */ - xf86ConfigLayout.screens[i].screen->device = cptr; - cptr->myScreenSection = xf86ConfigLayout.screens[i].screen; - - return TRUE; -} - -GDevPtr -autoConfigDevice(GDevPtr preconf_device) -{ - GDevPtr ptr = NULL; - XF86MatchedDrivers md; - int num_screens = 0, i; - screenLayoutPtr slp; - - if (!xf86configptr) { - return NULL; - } - - /* If there's a configured section with no driver chosen, use it */ - if (preconf_device) { - ptr = preconf_device; - } - else { - ptr = calloc(1, sizeof(GDevRec)); - if (!ptr) { - return NULL; - } - ptr->chipID = -1; - ptr->chipRev = -1; - ptr->irq = -1; - - ptr->active = TRUE; - ptr->claimed = FALSE; - ptr->identifier = "Autoconfigured Video Device"; - ptr->driver = NULL; - } - if (!ptr->driver) { - /* get all possible video drivers and count them */ - listPossibleVideoDrivers(&md); - for (i = 0; i < md.nmatches; i++) { - xf86Msg(X_DEFAULT, "Matched %s as autoconfigured driver %d\n", - md.matches[i], i); - } - - slp = xf86ConfigLayout.screens; - if (slp) { - /* count the number of screens and make space for - * a new screen for each additional possible driver - * minus one for the already existing first one - * plus one for the terminating NULL */ - for (; slp[num_screens].screen; num_screens++); - xf86ConfigLayout.screens = xnfcalloc(num_screens + md.nmatches, - sizeof(screenLayoutRec)); - xf86ConfigLayout.screens[0] = slp[0]; - - /* do the first match and set that for the original first screen */ - ptr->driver = md.matches[0]; - if (!xf86ConfigLayout.screens[0].screen->device) { - xf86ConfigLayout.screens[0].screen->device = ptr; - ptr->myScreenSection = xf86ConfigLayout.screens[0].screen; - } - - /* for each other driver found, copy the first screen, insert it - * into the list of screens and set the driver */ - for (i = 1; i < md.nmatches; i++) { - if (!copyScreen(slp[0].screen, ptr, i, md.matches[i])) - return NULL; - } - - /* shift the rest of the original screen list - * to the end of the current screen list - * - * TODO Handle rest of multiple screen sections */ - for (i = 1; i < num_screens; i++) { - xf86ConfigLayout.screens[i + md.nmatches] = slp[i]; - } - xf86ConfigLayout.screens[num_screens + md.nmatches - 1].screen = - NULL; - free(slp); - } - else { - /* layout does not have any screens, not much to do */ - ptr->driver = md.matches[0]; - for (i = 1; i < md.nmatches; i++) { - free(md.matches[i]); - } - } - } - - xf86Msg(X_DEFAULT, "Assigned the driver to the xf86ConfigLayout\n"); - - return ptr; -} diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c deleted file mode 100644 index fd144dbe7..000000000 --- a/hw/xfree86/common/xf86Bus.c +++ /dev/null @@ -1,671 +0,0 @@ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains the interfaces to the bus-specific code - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" - -/* Bus-specific headers */ - -#include "xf86Bus.h" - -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" -#ifdef XSERVER_LIBPCIACCESS -#include "xf86VGAarbiter.h" -#endif -/* Entity data */ -EntityPtr *xf86Entities = NULL; /* Bus slots claimed by drivers */ -int xf86NumEntities = 0; -static int xf86EntityPrivateCount = 0; - -BusRec primaryBus = { BUS_NONE, {0} }; - -/** - * Call the driver's correct probe function. - * - * If the driver implements the \c DriverRec::PciProbe entry-point and an - * appropriate PCI device (with matching Device section in the xorg.conf file) - * is found, it is called. If \c DriverRec::PciProbe or no devices can be - * successfully probed with it (e.g., only non-PCI devices are available), - * the driver's \c DriverRec::Probe function is called. - * - * \param drv Driver to probe - * - * \return - * If a device can be successfully probed by the driver, \c TRUE is - * returned. Otherwise, \c FALSE is returned. - */ -Bool -xf86CallDriverProbe(DriverPtr drv, Bool detect_only) -{ - Bool foundScreen = FALSE; - -#ifdef XSERVER_PLATFORM_BUS - /* xf86platformBus.c does not support Xorg -configure */ - if (!xf86DoConfigure && drv->platformProbe != NULL) { - foundScreen = xf86platformProbeDev(drv); - } -#endif - -#ifdef XSERVER_LIBPCIACCESS - if (!foundScreen && (drv->PciProbe != NULL)) { - if (xf86DoConfigure && xf86DoConfigurePass1) { - assert(detect_only); - foundScreen = xf86PciAddMatchingDev(drv); - } - else { - assert(!detect_only); - foundScreen = xf86PciProbeDev(drv); - } - } -#endif - if (!foundScreen && (drv->Probe != NULL)) { - xf86Msg(X_WARNING, "Falling back to old probe method for %s\n", - drv->driverName); - foundScreen = (*drv->Probe) (drv, (detect_only) ? PROBE_DETECT - : PROBE_DEFAULT); - } - - return foundScreen; -} - -static screenLayoutPtr -xf86BusConfigMatch(ScrnInfoPtr scrnInfo, Bool is_gpu) { - screenLayoutPtr layout; - int i, j; - - for (layout = xf86ConfigLayout.screens; layout->screen != NULL; - layout++) { - for (i = 0; i < scrnInfo->numEntities; i++) { - GDevPtr dev = - xf86GetDevFromEntity(scrnInfo->entityList[i], - scrnInfo->entityInstanceList[i]); - - if (is_gpu) { - for (j = 0; j < layout->screen->num_gpu_devices; j++) { - if (dev == layout->screen->gpu_devices[j]) { - /* A match has been found */ - return layout; - } - } - } else { - if (dev == layout->screen->device) { - /* A match has been found */ - return layout; - } - } - } - } - - return NULL; -} - -/** - * @return TRUE if all buses are configured and set up correctly and FALSE - * otherwise. - */ -Bool -xf86BusConfig(void) -{ - screenLayoutPtr layout; - int i; - - /* - * 3 step probe to (hopefully) ensure that we always find at least 1 - * (non GPU) screen: - * - * 1. Call each drivers probe function normally, - * Each successful probe will result in an extra entry added to the - * xf86Screens[] list for each instance of the hardware found. - */ - for (i = 0; i < xf86NumDrivers; i++) { - xf86CallDriverProbe(xf86DriverList[i], FALSE); - } - - /* - * 2. If no Screens were found, call each drivers probe function with - * ignorePrimary = TRUE, to ensure that we do actually get a - * Screen if there is at least one supported video card. - */ - if (xf86NumScreens == 0) { - xf86ProbeIgnorePrimary = TRUE; - for (i = 0; i < xf86NumDrivers && xf86NumScreens == 0; i++) { - xf86CallDriverProbe(xf86DriverList[i], FALSE); - } - xf86ProbeIgnorePrimary = FALSE; - } - - /* - * 3. Call xf86platformAddGPUDevices() to add any additional video cards as - * GPUScreens (GPUScreens are only supported by platformBus drivers). - */ - for (i = 0; i < xf86NumDrivers; i++) { - xf86platformAddGPUDevices(xf86DriverList[i]); - } - - /* If nothing was detected, return now */ - if (xf86NumScreens == 0) { - xf86Msg(X_ERROR, "No devices detected.\n"); - return FALSE; - } - - xf86VGAarbiterInit(); - - /* - * Match up the screens found by the probes against those specified - * in the config file. Remove the ones that won't be used. Sort - * them in the order specified. - * - * What is the best way to do this? - * - * For now, go through the screens allocated by the probes, and - * look for screen config entry which refers to the same device - * section as picked out by the probe. - * - */ - for (i = 0; i < xf86NumScreens; i++) { - layout = xf86BusConfigMatch(xf86Screens[i], FALSE); - if (layout && layout->screen) - xf86Screens[i]->confScreen = layout->screen; - else { - /* No match found */ - xf86Msg(X_ERROR, - "Screen %d deleted because of no matching config section.\n", - i); - xf86DeleteScreen(xf86Screens[i--]); - } - } - - /* bind GPU conf screen to the configured protocol screen, or 0 if not configured */ - for (i = 0; i < xf86NumGPUScreens; i++) { - layout = xf86BusConfigMatch(xf86GPUScreens[i], TRUE); - int scrnum = (layout && layout->screen) ? layout->screen->screennum : 0; - xf86GPUScreens[i]->confScreen = xf86Screens[scrnum]->confScreen; - } - - /* If no screens left, return now. */ - if (xf86NumScreens == 0) { - xf86Msg(X_ERROR, - "Device(s) detected, but none match those in the config file.\n"); - return FALSE; - } - - return TRUE; -} - -/* - * Call the bus probes relevant to the architecture. - * - * The only one available so far is for PCI and SBUS. - */ - -void -xf86BusProbe(void) -{ -#ifdef XSERVER_PLATFORM_BUS - xf86platformProbe(); - if (ServerIsNotSeat0() && xf86_num_platform_devices > 0) - return; -#endif -#ifdef XSERVER_LIBPCIACCESS - xf86PciProbe(); -#endif -#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) - xf86SbusProbe(); -#endif -#ifdef XSERVER_PLATFORM_BUS - xf86platformPrimary(); -#endif -} - -/* - * Determine what bus type the busID string represents. The start of the - * bus-dependent part of the string is returned as retID. - */ - -BusType -StringToBusType(const char *busID, const char **retID) -{ - char *p, *s; - BusType ret = BUS_NONE; - - /* If no type field, Default to PCI */ - if (isdigit(busID[0])) { - if (retID) - *retID = busID; - return BUS_PCI; - } - - s = xstrdup(busID); - p = strtok(s, ":"); - if (p == NULL || *p == 0) { - free(s); - return BUS_NONE; - } - if (!xf86NameCmp(p, "pci") || !xf86NameCmp(p, "agp")) - ret = BUS_PCI; - if (!xf86NameCmp(p, "sbus")) - ret = BUS_SBUS; - if (!xf86NameCmp(p, "platform")) - ret = BUS_PLATFORM; - if (!xf86NameCmp(p, "usb")) - ret = BUS_USB; - if (ret != BUS_NONE) - if (retID) - *retID = busID + strlen(p) + 1; - free(s); - return ret; -} - -int -xf86AllocateEntity(void) -{ - xf86NumEntities++; - xf86Entities = xnfreallocarray(xf86Entities, - xf86NumEntities, sizeof(EntityPtr)); - xf86Entities[xf86NumEntities - 1] = xnfcalloc(1, sizeof(EntityRec)); - xf86Entities[xf86NumEntities - 1]->entityPrivates = - xnfcalloc(xf86EntityPrivateCount, sizeof(DevUnion)); - return xf86NumEntities - 1; -} - -Bool -xf86IsEntityPrimary(int entityIndex) -{ - EntityPtr pEnt = xf86Entities[entityIndex]; - -#ifdef XSERVER_LIBPCIACCESS - if (primaryBus.type == BUS_PLATFORM && pEnt->bus.type == BUS_PCI) - if (primaryBus.id.plat->pdev) - return MATCH_PCI_DEVICES(pEnt->bus.id.pci, primaryBus.id.plat->pdev); -#endif - - if (primaryBus.type != pEnt->bus.type) - return FALSE; - - switch (pEnt->bus.type) { - case BUS_PCI: - return pEnt->bus.id.pci == primaryBus.id.pci; - case BUS_SBUS: - return pEnt->bus.id.sbus.fbNum == primaryBus.id.sbus.fbNum; - case BUS_PLATFORM: - return pEnt->bus.id.plat == primaryBus.id.plat; - default: - return FALSE; - } -} - -Bool -xf86DriverHasEntities(DriverPtr drvp) -{ - int i; - - for (i = 0; i < xf86NumEntities; i++) { - if (xf86Entities[i]->driver == drvp) - return TRUE; - } - return FALSE; -} - -void -xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex) -{ - if (entityIndex == -1) - return; - if (xf86Entities[entityIndex]->inUse && - !(xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL)) { - ErrorF("Requested Entity already in use!\n"); - return; - } - - pScrn->numEntities++; - pScrn->entityList = xnfreallocarray(pScrn->entityList, - pScrn->numEntities, sizeof(int)); - pScrn->entityList[pScrn->numEntities - 1] = entityIndex; - xf86Entities[entityIndex]->inUse = TRUE; - pScrn->entityInstanceList = xnfreallocarray(pScrn->entityInstanceList, - pScrn->numEntities, - sizeof(int)); - pScrn->entityInstanceList[pScrn->numEntities - 1] = 0; -} - -void -xf86SetEntityInstanceForScreen(ScrnInfoPtr pScrn, int entityIndex, int instance) -{ - int i; - - if (entityIndex == -1 || entityIndex >= xf86NumEntities) - return; - - for (i = 0; i < pScrn->numEntities; i++) { - if (pScrn->entityList[i] == entityIndex) { - pScrn->entityInstanceList[i] = instance; - break; - } - } -} - -/* - * XXX This needs to be updated for the case where a single entity may have - * instances associated with more than one screen. - */ -ScrnInfoPtr -xf86FindScreenForEntity(int entityIndex) -{ - int i, j; - - if (entityIndex == -1) - return NULL; - - if (xf86Screens) { - for (i = 0; i < xf86NumScreens; i++) { - for (j = 0; j < xf86Screens[i]->numEntities; j++) { - if (xf86Screens[i]->entityList[j] == entityIndex) - return xf86Screens[i]; - } - } - } - return NULL; -} - -void -xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex) -{ - int i; - - for (i = 0; i < pScrn->numEntities; i++) { - if (pScrn->entityList[i] == entityIndex) { - for (i++; i < pScrn->numEntities; i++) - pScrn->entityList[i - 1] = pScrn->entityList[i]; - pScrn->numEntities--; - xf86Entities[entityIndex]->inUse = FALSE; - break; - } - } -} - -/* - * xf86ClearEntityListForScreen() - called when a screen is deleted - * to mark its entities unused. Called by xf86DeleteScreen(). - */ -void -xf86ClearEntityListForScreen(ScrnInfoPtr pScrn) -{ - int i, entityIndex; - - if (pScrn->entityList == NULL || pScrn->numEntities == 0) - return; - - for (i = 0; i < pScrn->numEntities; i++) { - entityIndex = pScrn->entityList[i]; - xf86Entities[entityIndex]->inUse = FALSE; - /* disable resource: call the disable function */ - } - free(pScrn->entityList); - free(pScrn->entityInstanceList); - pScrn->entityList = NULL; - pScrn->entityInstanceList = NULL; -} - -/* - * Add an extra device section (GDevPtr) to an entity. - */ - -void -xf86AddDevToEntity(int entityIndex, GDevPtr dev) -{ - EntityPtr pEnt; - - if (entityIndex >= xf86NumEntities) - return; - - pEnt = xf86Entities[entityIndex]; - pEnt->numInstances++; - pEnt->devices = xnfreallocarray(pEnt->devices, - pEnt->numInstances, sizeof(GDevPtr)); - pEnt->devices[pEnt->numInstances - 1] = dev; - dev->claimed = TRUE; -} - - -void -xf86RemoveDevFromEntity(int entityIndex, GDevPtr dev) -{ - EntityPtr pEnt; - int i, j; - if (entityIndex >= xf86NumEntities) - return; - - pEnt = xf86Entities[entityIndex]; - for (i = 0; i < pEnt->numInstances; i++) { - if (pEnt->devices[i] == dev) { - for (j = i; j < pEnt->numInstances - 1; j++) - pEnt->devices[j] = pEnt->devices[j + 1]; - break; - } - } - pEnt->numInstances--; - dev->claimed = FALSE; -} -/* - * xf86GetEntityInfo() -- This function hands information from the - * EntityRec struct to the drivers. The EntityRec structure itself - * remains invisible to the driver. - */ -EntityInfoPtr -xf86GetEntityInfo(int entityIndex) -{ - EntityInfoPtr pEnt; - int i; - - if (entityIndex == -1) - return NULL; - - if (entityIndex >= xf86NumEntities) - return NULL; - - pEnt = xnfcalloc(1, sizeof(EntityInfoRec)); - pEnt->index = entityIndex; - pEnt->location = xf86Entities[entityIndex]->bus; - pEnt->active = xf86Entities[entityIndex]->active; - pEnt->chipset = xf86Entities[entityIndex]->chipset; - pEnt->driver = xf86Entities[entityIndex]->driver; - if ((xf86Entities[entityIndex]->devices) && - (xf86Entities[entityIndex]->devices[0])) { - for (i = 0; i < xf86Entities[entityIndex]->numInstances; i++) - if (xf86Entities[entityIndex]->devices[i]->screen == 0) - break; - pEnt->device = xf86Entities[entityIndex]->devices[i]; - } - else - pEnt->device = NULL; - - return pEnt; -} - -int -xf86GetNumEntityInstances(int entityIndex) -{ - if (entityIndex >= xf86NumEntities) - return -1; - - return xf86Entities[entityIndex]->numInstances; -} - -GDevPtr -xf86GetDevFromEntity(int entityIndex, int instance) -{ - int i; - - /* We might not use AddDevtoEntity */ - if ((!xf86Entities[entityIndex]->devices) || - (!xf86Entities[entityIndex]->devices[0])) - return NULL; - - if (entityIndex >= xf86NumEntities || - instance >= xf86Entities[entityIndex]->numInstances) - return NULL; - - for (i = 0; i < xf86Entities[entityIndex]->numInstances; i++) - if (xf86Entities[entityIndex]->devices[i]->screen == instance) - return xf86Entities[entityIndex]->devices[i]; - return NULL; -} - -/* - * xf86PostProbe() -- Allocate all non conflicting resources - * This function gets called by xf86Init(). - */ -void -xf86PostProbe(void) -{ - if (fbSlotClaimed && ( -#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) - sbusSlotClaimed || -#endif -#ifdef XSERVER_PLATFORM_BUS - platformSlotClaimed || -#endif -#ifdef XSERVER_LIBPCIACCESS - pciSlotClaimed -#else - TRUE -#endif - )) - FatalError("Cannot run in framebuffer mode. Please specify busIDs " - " for all framebuffer devices\n"); -} - -Bool -xf86IsEntityShared(int entityIndex) -{ - if (entityIndex < xf86NumEntities) { - if (xf86Entities[entityIndex]->entityProp & IS_SHARED_ACCEL) { - return TRUE; - } - } - return FALSE; -} - -void -xf86SetEntityShared(int entityIndex) -{ - if (entityIndex < xf86NumEntities) { - xf86Entities[entityIndex]->entityProp |= IS_SHARED_ACCEL; - } -} - -Bool -xf86IsEntitySharable(int entityIndex) -{ - if (entityIndex < xf86NumEntities) { - if (xf86Entities[entityIndex]->entityProp & ACCEL_IS_SHARABLE) { - return TRUE; - } - } - return FALSE; -} - -void -xf86SetEntitySharable(int entityIndex) -{ - if (entityIndex < xf86NumEntities) { - xf86Entities[entityIndex]->entityProp |= ACCEL_IS_SHARABLE; - } -} - -Bool -xf86IsPrimInitDone(int entityIndex) -{ - if (entityIndex < xf86NumEntities) { - if (xf86Entities[entityIndex]->entityProp & SA_PRIM_INIT_DONE) { - return TRUE; - } - } - return FALSE; -} - -void -xf86SetPrimInitDone(int entityIndex) -{ - if (entityIndex < xf86NumEntities) { - xf86Entities[entityIndex]->entityProp |= SA_PRIM_INIT_DONE; - } -} - -void -xf86ClearPrimInitDone(int entityIndex) -{ - if (entityIndex < xf86NumEntities) { - xf86Entities[entityIndex]->entityProp &= ~SA_PRIM_INIT_DONE; - } -} - -/* - * Allocate a private in the entities. - */ - -int -xf86AllocateEntityPrivateIndex(void) -{ - int idx, i; - EntityPtr pEnt; - DevUnion *nprivs; - - idx = xf86EntityPrivateCount++; - for (i = 0; i < xf86NumEntities; i++) { - pEnt = xf86Entities[i]; - nprivs = xnfreallocarray(pEnt->entityPrivates, - xf86EntityPrivateCount, sizeof(DevUnion)); - /* Zero the new private */ - memset(&nprivs[idx], 0, sizeof(DevUnion)); - pEnt->entityPrivates = nprivs; - } - return idx; -} - -DevUnion * -xf86GetEntityPrivate(int entityIndex, int privIndex) -{ - if (entityIndex >= xf86NumEntities || privIndex >= xf86EntityPrivateCount) - return NULL; - - return &(xf86Entities[entityIndex]->entityPrivates[privIndex]); -} diff --git a/hw/xfree86/common/xf86Bus.h b/hw/xfree86/common/xf86Bus.h deleted file mode 100644 index 0d44a8a61..000000000 --- a/hw/xfree86/common/xf86Bus.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains definitions of the bus-related data structures/types. - * Everything contained here is private to xf86Bus.c. In particular the - * video drivers must not include this file. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _XF86_BUS_H -#define _XF86_BUS_H - -#include "xf86pciBus.h" -#if defined(__sparc__) || defined(__sparc) -#include "xf86sbusBus.h" -#endif -#include "xf86platformBus.h" - -typedef struct { - DriverPtr driver; - int chipset; - int entityProp; - Bool active; - Bool inUse; - BusRec bus; - DevUnion *entityPrivates; - int numInstances; - GDevPtr *devices; -} EntityRec, *EntityPtr; - -#define ACCEL_IS_SHARABLE 0x100 -#define IS_SHARED_ACCEL 0x200 -#define SA_PRIM_INIT_DONE 0x400 - -extern EntityPtr *xf86Entities; -extern int xf86NumEntities; -extern BusRec primaryBus; - -int xf86AllocateEntity(void); -BusType StringToBusType(const char *busID, const char **retID); - -#endif /* _XF86_BUS_H */ diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c deleted file mode 100644 index 5d814c148..000000000 --- a/hw/xfree86/common/xf86Config.c +++ /dev/null @@ -1,2472 +0,0 @@ -/* - * Loosely based on code bearing the following copyright: - * - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. - */ - -/* - * Copyright 1992-2003 by The XFree86 Project, Inc. - * Copyright 1997 by Metro Link, 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). - */ - -/* - * - * Authors: - * Dirk Hohndel - * David Dawes - * Marc La France - * Egbert Eich - * ... and others - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#include "xf86.h" -#include "xf86Modes.h" -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "xf86Config.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "configProcs.h" -#include "globals.h" -#include "extension.h" -#include "xf86pciBus.h" -#include "xf86Xinput.h" -#include "loaderProcs.h" - -#include "xkbsrv.h" -#include "picture.h" -#ifdef DPMSExtension -#include "dpmsproc.h" -#endif - -/* - * These paths define the way the config file search is done. The escape - * sequences are documented in parser/scan.c. - */ -#ifndef ALL_CONFIGPATH -#define ALL_CONFIGPATH "%A," "%R," \ - "/etc/X11/%R," "%P/etc/X11/%R," \ - "%E," "%F," \ - "/etc/X11/%F," "%P/etc/X11/%F," \ - "/etc/X11/%X," "/etc/%X," \ - "%P/etc/X11/%X.%H," \ - "%P/etc/X11/%X," \ - "%P/lib/X11/%X.%H," \ - "%P/lib/X11/%X" -#endif -#ifndef RESTRICTED_CONFIGPATH -#define RESTRICTED_CONFIGPATH "/etc/X11/%S," "%P/etc/X11/%S," \ - "/etc/X11/%G," "%P/etc/X11/%G," \ - "/etc/X11/%X," "/etc/%X," \ - "%P/etc/X11/%X.%H," \ - "%P/etc/X11/%X," \ - "%P/lib/X11/%X.%H," \ - "%P/lib/X11/%X" -#endif -#ifndef ALL_CONFIGDIRPATH -#define ALL_CONFIGDIRPATH "%A," "%R," \ - "/etc/X11/%R," "%C/X11/%R," \ - "/etc/X11/%X," "%C/X11/%X" -#endif -#ifndef RESTRICTED_CONFIGDIRPATH -#define RESTRICTED_CONFIGDIRPATH "/etc/X11/%R," "%C/X11/%R," \ - "/etc/X11/%X," "%C/X11/%X" -#endif -#ifndef SYS_CONFIGDIRPATH -#define SYS_CONFIGDIRPATH "%D/X11/%X" -#endif -#ifndef PROJECTROOT -#define PROJECTROOT "/usr/X11R6" -#endif - -static ModuleDefault ModuleDefaults[] = { -#ifdef GLXEXT - {.name = "glx",.toLoad = TRUE,.load_opt = NULL}, -#endif -#ifdef __CYGWIN__ - /* load DIX modules used by drivers first */ - {.name = "fb",.toLoad = TRUE,.load_opt = NULL}, - {.name = "shadow",.toLoad = TRUE,.load_opt = NULL}, -#endif - {.name = NULL,.toLoad = FALSE,.load_opt = NULL} -}; - -/* Forward declarations */ -static Bool configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, - int scrnum, MessageType from, Bool auto_gpu_device); -static Bool configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor); -static Bool configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, - Bool active, Bool gpu); -static Bool configInput(InputInfoPtr pInfo, XF86ConfInputPtr conf_input, - MessageType from); -static Bool configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display); -static Bool addDefaultModes(MonPtr monitorp); - -static void configDRI(XF86ConfDRIPtr drip); -static void configExtensions(XF86ConfExtensionsPtr conf_ext); - -/* - * xf86GetPathElem -- - * Extract a single element from the font path string starting at - * pnt. The font path element will be returned, and pnt will be - * updated to point to the start of the next element, or set to - * NULL if there are no more. - */ -static char * -xf86GetPathElem(char **pnt) -{ - char *p1; - - p1 = *pnt; - *pnt = index(*pnt, ','); - if (*pnt != NULL) { - **pnt = '\0'; - *pnt += 1; - } - return p1; -} - -/* - * xf86ValidateFontPath -- - * Validates the user-specified font path. Each element that - * begins with a '/' is checked to make sure the directory exists. - * If the directory exists, the existence of a file named 'fonts.dir' - * is checked. If either check fails, an error is printed and the - * element is removed from the font path. - */ - -#define DIR_FILE "/fonts.dir" -static char * -xf86ValidateFontPath(char *path) -{ - char *next, *tmp_path, *out_pnt, *path_elem, *p1, *dir_elem; - struct stat stat_buf; - int flag; - int dirlen; - - tmp_path = calloc(1, strlen(path) + 1); - out_pnt = tmp_path; - path_elem = NULL; - next = path; - while (next != NULL) { - path_elem = xf86GetPathElem(&next); - if (*path_elem == '/') { - dir_elem = xnfcalloc(1, strlen(path_elem) + 1); - if ((p1 = strchr(path_elem, ':')) != 0) - dirlen = p1 - path_elem; - else - dirlen = strlen(path_elem); - strlcpy(dir_elem, path_elem, dirlen + 1); - flag = stat(dir_elem, &stat_buf); - if (flag == 0) - if (!S_ISDIR(stat_buf.st_mode)) - flag = -1; - if (flag != 0) { - xf86Msg(X_WARNING, "The directory \"%s\" does not exist.\n", - dir_elem); - xf86ErrorF("\tEntry deleted from font path.\n"); - free(dir_elem); - continue; - } - else { - XNFasprintf(&p1, "%s%s", dir_elem, DIR_FILE); - flag = stat(p1, &stat_buf); - if (flag == 0) - if (!S_ISREG(stat_buf.st_mode)) - flag = -1; - free(p1); - if (flag != 0) { - xf86Msg(X_WARNING, - "`fonts.dir' not found (or not valid) in \"%s\".\n", - dir_elem); - xf86ErrorF("\tEntry deleted from font path.\n"); - xf86ErrorF("\t(Run 'mkfontdir' on \"%s\").\n", dir_elem); - free(dir_elem); - continue; - } - } - free(dir_elem); - } - - /* - * Either an OK directory, or a font server name. So add it to - * the path. - */ - if (out_pnt != tmp_path) - *out_pnt++ = ','; - strcat(out_pnt, path_elem); - out_pnt += strlen(path_elem); - } - return tmp_path; -} - -#define FIND_SUITABLE(pointertype, listhead, ptr) \ - do { \ - pointertype _l, _p; \ - \ - for (_l = (listhead), _p = NULL; !_p && _l; _l = (pointertype)_l->list.next) { \ - if (!_l->match_seat || (SeatId && xf86nameCompare(_l->match_seat, SeatId) == 0)) \ - _p = _l; \ - } \ - \ - (ptr) = _p; \ - } while(0) - -/* - * use the datastructure that the parser provides and pick out the parts - * that we need at this point - */ -const char ** -xf86ModulelistFromConfig(void ***optlist) -{ - int count = 0, i = 0; - const char **modulearray; - - const char *ignore[] = { "GLcore", "speedo", "bitmap", "drm", - "freetype", "type1", - NULL - }; - void **optarray; - XF86LoadPtr modp; - Bool found; - - /* - * make sure the config file has been parsed and that we have a - * ModulePath set; if no ModulePath was given, use the default - * ModulePath - */ - if (xf86configptr == NULL) { - xf86Msg(X_ERROR, "Cannot access global config data structure\n"); - return NULL; - } - - if (xf86configptr->conf_modules) { - /* Walk the disable list and let people know what we've parsed to - * not be loaded - */ - modp = xf86configptr->conf_modules->mod_disable_lst; - while (modp) { - xf86Msg(X_WARNING, - "\"%s\" will not be loaded unless you've specified it to be loaded elsewhere.\n", - modp->load_name); - modp = (XF86LoadPtr) modp->list.next; - } - /* - * Walk the default settings table. For each module listed to be - * loaded, make sure it's in the mod_load_lst. If it's not, make - * sure it's not in the mod_no_load_lst. If it's not disabled, - * append it to mod_load_lst - */ - for (i = 0; ModuleDefaults[i].name != NULL; i++) { - if (ModuleDefaults[i].toLoad == FALSE) { - xf86Msg(X_WARNING, - "\"%s\" is not to be loaded by default. Skipping.\n", - ModuleDefaults[i].name); - continue; - } - found = FALSE; - modp = xf86configptr->conf_modules->mod_load_lst; - while (modp) { - if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) { - xf86Msg(X_INFO, - "\"%s\" will be loaded. This was enabled by default and also specified in the config file.\n", - ModuleDefaults[i].name); - found = TRUE; - break; - } - modp = (XF86LoadPtr) modp->list.next; - } - if (found == FALSE) { - modp = xf86configptr->conf_modules->mod_disable_lst; - while (modp) { - if (strcmp(modp->load_name, ModuleDefaults[i].name) == 0) { - xf86Msg(X_INFO, - "\"%s\" will be loaded even though the default is to disable it.\n", - ModuleDefaults[i].name); - found = TRUE; - break; - } - modp = (XF86LoadPtr) modp->list.next; - } - } - if (found == FALSE) { - XF86LoadPtr ptr = (XF86LoadPtr) xf86configptr->conf_modules; - - xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, - XF86_LOAD_MODULE, - ModuleDefaults[i].load_opt); - xf86Msg(X_INFO, "\"%s\" will be loaded by default.\n", - ModuleDefaults[i].name); - } - } - } - else { - xf86configptr->conf_modules = xnfcalloc(1, sizeof(XF86ConfModuleRec)); - for (i = 0; ModuleDefaults[i].name != NULL; i++) { - if (ModuleDefaults[i].toLoad == TRUE) { - XF86LoadPtr ptr = (XF86LoadPtr) xf86configptr->conf_modules; - - xf86addNewLoadDirective(ptr, ModuleDefaults[i].name, - XF86_LOAD_MODULE, - ModuleDefaults[i].load_opt); - } - } - } - - /* - * Walk the list of modules in the "Module" section to determine how - * many we have. - */ - modp = xf86configptr->conf_modules->mod_load_lst; - while (modp) { - for (i = 0; ignore[i]; i++) { - if (strcmp(modp->load_name, ignore[i]) == 0) - modp->ignore = 1; - } - if (!modp->ignore) - count++; - modp = (XF86LoadPtr) modp->list.next; - } - - /* - * allocate the memory and walk the list again to fill in the pointers - */ - modulearray = xnfallocarray(count + 1, sizeof(char *)); - optarray = xnfallocarray(count + 1, sizeof(void *)); - count = 0; - if (xf86configptr->conf_modules) { - modp = xf86configptr->conf_modules->mod_load_lst; - while (modp) { - if (!modp->ignore) { - modulearray[count] = modp->load_name; - optarray[count] = modp->load_opt; - count++; - } - modp = (XF86LoadPtr) modp->list.next; - } - } - modulearray[count] = NULL; - optarray[count] = NULL; - if (optlist) - *optlist = optarray; - else - free(optarray); - return modulearray; -} - -const char ** -xf86DriverlistFromConfig(void) -{ - int count = 0; - int j, k; - const char **modulearray; - screenLayoutPtr slp; - - /* - * make sure the config file has been parsed and that we have a - * ModulePath set; if no ModulePath was given, use the default - * ModulePath - */ - if (xf86configptr == NULL) { - xf86Msg(X_ERROR, "Cannot access global config data structure\n"); - return NULL; - } - - /* - * Walk the list of driver lines in active "Device" sections to - * determine now many implicitly loaded modules there are. - * - */ - if (xf86ConfigLayout.screens) { - slp = xf86ConfigLayout.screens; - while (slp->screen) { - count++; - count += slp->screen->num_gpu_devices; - slp++; - } - } - - /* - * Handle the set of inactive "Device" sections. - */ - j = 0; - while (xf86ConfigLayout.inactives[j++].identifier) - count++; - - if (count == 0) - return NULL; - - /* - * allocate the memory and walk the list again to fill in the pointers - */ - modulearray = xnfallocarray(count + 1, sizeof(char *)); - count = 0; - slp = xf86ConfigLayout.screens; - while (slp->screen) { - modulearray[count] = slp->screen->device->driver; - count++; - for (k = 0; k < slp->screen->num_gpu_devices; k++) { - modulearray[count] = slp->screen->gpu_devices[k]->driver; - count++; - } - slp++; - } - - j = 0; - - while (xf86ConfigLayout.inactives[j].identifier) - modulearray[count++] = xf86ConfigLayout.inactives[j++].driver; - - modulearray[count] = NULL; - - /* Remove duplicates */ - for (count = 0; modulearray[count] != NULL; count++) { - int i; - - for (i = 0; i < count; i++) - if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) { - modulearray[count] = ""; - break; - } - } - return modulearray; -} - -const char ** -xf86InputDriverlistFromConfig(void) -{ - int count = 0; - const char **modulearray; - InputInfoPtr *idp; - - /* - * make sure the config file has been parsed and that we have a - * ModulePath set; if no ModulePath was given, use the default - * ModulePath - */ - if (xf86configptr == NULL) { - xf86Msg(X_ERROR, "Cannot access global config data structure\n"); - return NULL; - } - - /* - * Walk the list of driver lines in active "InputDevice" sections to - * determine now many implicitly loaded modules there are. - */ - if (xf86ConfigLayout.inputs) { - idp = xf86ConfigLayout.inputs; - while (*idp) { - count++; - idp++; - } - } - - if (count == 0) - return NULL; - - /* - * allocate the memory and walk the list again to fill in the pointers - */ - modulearray = xnfallocarray(count + 1, sizeof(char *)); - count = 0; - idp = xf86ConfigLayout.inputs; - while (idp && *idp) { - modulearray[count] = (*idp)->driver; - count++; - idp++; - } - modulearray[count] = NULL; - - /* Remove duplicates */ - for (count = 0; modulearray[count] != NULL; count++) { - int i; - - for (i = 0; i < count; i++) - if (xf86NameCmp(modulearray[i], modulearray[count]) == 0) { - modulearray[count] = ""; - break; - } - } - return modulearray; -} - -static void -configFiles(XF86ConfFilesPtr fileconf) -{ - MessageType pathFrom; - Bool must_copy; - int size, countDirs; - char *temp_path, *log_buf, *start, *end; - - /* FontPath */ - must_copy = TRUE; - - temp_path = defaultFontPath ? (char *) defaultFontPath : (char *) ""; - if (xf86fpFlag) - pathFrom = X_CMDLINE; - else if (fileconf && fileconf->file_fontpath) { - pathFrom = X_CONFIG; - if (xf86Info.useDefaultFontPath) { - char *new_font_path; - if (asprintf(&new_font_path, "%s%s%s", fileconf->file_fontpath, - *temp_path ? "," : "", temp_path) == -1) - new_font_path = NULL; - else - must_copy = FALSE; - defaultFontPath = new_font_path; - } - else - defaultFontPath = fileconf->file_fontpath; - } - else - pathFrom = X_DEFAULT; - temp_path = defaultFontPath ? (char *) defaultFontPath : (char *) ""; - - /* xf86ValidateFontPath modifies its argument, but returns a copy of it. */ - temp_path = must_copy ? xnfstrdup(defaultFontPath) : (char *) defaultFontPath; - defaultFontPath = xf86ValidateFontPath(temp_path); - free(temp_path); - - /* make fontpath more readable in the logfiles */ - countDirs = 1; - temp_path = (char *) defaultFontPath; - while ((temp_path = index(temp_path, ',')) != NULL) { - countDirs++; - temp_path++; - } - - log_buf = xnfalloc(strlen(defaultFontPath) + (2 * countDirs) + 1); - temp_path = log_buf; - start = (char *) defaultFontPath; - while ((end = index(start, ',')) != NULL) { - size = (end - start) + 1; - *(temp_path++) = '\t'; - strncpy(temp_path, start, size); - temp_path += size; - *(temp_path++) = '\n'; - start += size; - } - /* copy last entry */ - *(temp_path++) = '\t'; - strcpy(temp_path, start); - xf86Msg(pathFrom, "FontPath set to:\n%s\n", log_buf); - free(log_buf); - - /* ModulePath */ - - if (fileconf) { - if (xf86ModPathFrom != X_CMDLINE && fileconf->file_modulepath) { - xf86ModulePath = fileconf->file_modulepath; - xf86ModPathFrom = X_CONFIG; - } - } - - xf86Msg(xf86ModPathFrom, "ModulePath set to \"%s\"\n", xf86ModulePath); - - if (!xf86xkbdirFlag && fileconf && fileconf->file_xkbdir) { - XkbBaseDirectory = fileconf->file_xkbdir; - xf86Msg(X_CONFIG, "XKB base directory set to \"%s\"\n", - XkbBaseDirectory); - } -#if 0 - /* LogFile */ - /* - * XXX The problem with this is that the log file is already open. - * One option might be to copy the exiting contents to the new location. - * and re-open it. The down side is that the default location would - * already have been overwritten. Another option would be to start with - * unique temporary location, then copy it once the correct name is known. - * A problem with this is what happens if the server exits before that - * happens. - */ - if (xf86LogFileFrom == X_DEFAULT && fileconf->file_logfile) { - xf86LogFile = fileconf->file_logfile; - xf86LogFileFrom = X_CONFIG; - } -#endif - - return; -} - -typedef enum { - FLAG_DONTVTSWITCH, - FLAG_DONTZAP, - FLAG_DONTZOOM, - FLAG_DISABLEVIDMODE, - FLAG_ALLOWNONLOCAL, - FLAG_ALLOWMOUSEOPENFAIL, - FLAG_SAVER_BLANKTIME, - FLAG_DPMS_STANDBYTIME, - FLAG_DPMS_SUSPENDTIME, - FLAG_DPMS_OFFTIME, - FLAG_NOPM, - FLAG_XINERAMA, - FLAG_LOG, - FLAG_RENDER_COLORMAP_MODE, - FLAG_IGNORE_ABI, - FLAG_ALLOW_EMPTY_INPUT, - FLAG_USE_DEFAULT_FONT_PATH, - FLAG_AUTO_ADD_DEVICES, - FLAG_AUTO_ENABLE_DEVICES, - FLAG_GLX_VISUALS, - FLAG_DRI2, - FLAG_USE_SIGIO, - FLAG_AUTO_ADD_GPU, - FLAG_AUTO_BIND_GPU, - FLAG_MAX_CLIENTS, - FLAG_IGLX, - FLAG_DEBUG, -} FlagValues; - -/** - * NOTE: the last value for each entry is NOT the default. It is set to TRUE - * if the parser found the option in the config file. - */ -static OptionInfoRec FlagOptions[] = { - {FLAG_DONTVTSWITCH, "DontVTSwitch", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_DONTZAP, "DontZap", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_DONTZOOM, "DontZoom", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_DISABLEVIDMODE, "DisableVidModeExtension", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_ALLOWNONLOCAL, "AllowNonLocalXvidtune", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_ALLOWMOUSEOPENFAIL, "AllowMouseOpenFail", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_SAVER_BLANKTIME, "BlankTime", OPTV_INTEGER, - {0}, FALSE}, - {FLAG_DPMS_STANDBYTIME, "StandbyTime", OPTV_INTEGER, - {0}, FALSE}, - {FLAG_DPMS_SUSPENDTIME, "SuspendTime", OPTV_INTEGER, - {0}, FALSE}, - {FLAG_DPMS_OFFTIME, "OffTime", OPTV_INTEGER, - {0}, FALSE}, - {FLAG_NOPM, "NoPM", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_XINERAMA, "Xinerama", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_LOG, "Log", OPTV_STRING, - {0}, FALSE}, - {FLAG_RENDER_COLORMAP_MODE, "RenderColormapMode", OPTV_STRING, - {0}, FALSE}, - {FLAG_IGNORE_ABI, "IgnoreABI", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_USE_DEFAULT_FONT_PATH, "UseDefaultFontPath", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_AUTO_ADD_DEVICES, "AutoAddDevices", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_AUTO_ENABLE_DEVICES, "AutoEnableDevices", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_GLX_VISUALS, "GlxVisuals", OPTV_STRING, - {0}, FALSE}, - {FLAG_DRI2, "DRI2", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_USE_SIGIO, "UseSIGIO", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_AUTO_ADD_GPU, "AutoAddGPU", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_AUTO_BIND_GPU, "AutoBindGPU", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_MAX_CLIENTS, "MaxClients", OPTV_INTEGER, - {0}, FALSE }, - {FLAG_IGLX, "IndirectGLX", OPTV_BOOLEAN, - {0}, FALSE}, - {FLAG_DEBUG, "Debug", OPTV_STRING, - {0}, FALSE}, - {-1, NULL, OPTV_NONE, - {0}, FALSE}, -}; - -static void -configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) -{ - XF86OptionPtr optp, tmp; - int i; - Bool value; - MessageType from; - const char *s; - XkbRMLVOSet set; - const char *rules; - - /* - * Merge the ServerLayout and ServerFlags options. The former have - * precedence over the latter. - */ - optp = NULL; - if (flagsconf && flagsconf->flg_option_lst) - optp = xf86optionListDup(flagsconf->flg_option_lst); - if (layoutopts) { - tmp = xf86optionListDup(layoutopts); - if (optp) - optp = xf86optionListMerge(optp, tmp); - else - optp = tmp; - } - - xf86ProcessOptions(-1, optp, FlagOptions); - - xf86GetOptValBool(FlagOptions, FLAG_DONTVTSWITCH, &xf86Info.dontVTSwitch); - xf86GetOptValBool(FlagOptions, FLAG_DONTZAP, &xf86Info.dontZap); - xf86GetOptValBool(FlagOptions, FLAG_DONTZOOM, &xf86Info.dontZoom); - - xf86GetOptValBool(FlagOptions, FLAG_IGNORE_ABI, &xf86Info.ignoreABI); - if (xf86Info.ignoreABI) { - xf86Msg(X_CONFIG, "Ignoring ABI Version\n"); - } - - if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ADD_DEVICES)) { - xf86GetOptValBool(FlagOptions, FLAG_AUTO_ADD_DEVICES, - &xf86Info.autoAddDevices); - from = X_CONFIG; - } - else { - from = X_DEFAULT; - } - xf86Msg(from, "%sutomatically adding devices\n", - xf86Info.autoAddDevices ? "A" : "Not a"); - - if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ENABLE_DEVICES)) { - xf86GetOptValBool(FlagOptions, FLAG_AUTO_ENABLE_DEVICES, - &xf86Info.autoEnableDevices); - from = X_CONFIG; - } - else { - from = X_DEFAULT; - } - xf86Msg(from, "%sutomatically enabling devices\n", - xf86Info.autoEnableDevices ? "A" : "Not a"); - - if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_ADD_GPU)) { - xf86GetOptValBool(FlagOptions, FLAG_AUTO_ADD_GPU, - &xf86Info.autoAddGPU); - from = X_CONFIG; - } - else { - from = X_DEFAULT; - } - xf86Msg(from, "%sutomatically adding GPU devices\n", - xf86Info.autoAddGPU ? "A" : "Not a"); - - if (xf86AutoBindGPUDisabled) { - xf86Info.autoBindGPU = FALSE; - from = X_CMDLINE; - } - else if (xf86IsOptionSet(FlagOptions, FLAG_AUTO_BIND_GPU)) { - xf86GetOptValBool(FlagOptions, FLAG_AUTO_BIND_GPU, - &xf86Info.autoBindGPU); - from = X_CONFIG; - } - else { - from = X_DEFAULT; - } - xf86Msg(from, "%sutomatically binding GPU devices\n", - xf86Info.autoBindGPU ? "A" : "Not a"); - - /* - * Set things up based on the config file information. Some of these - * settings may be overridden later when the command line options are - * checked. - */ -#ifdef XF86VIDMODE - if (xf86GetOptValBool(FlagOptions, FLAG_DISABLEVIDMODE, &value)) - xf86Info.vidModeEnabled = !value; - if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWNONLOCAL, &value)) - xf86Info.vidModeAllowNonLocal = value; -#endif - - if (xf86GetOptValBool(FlagOptions, FLAG_ALLOWMOUSEOPENFAIL, &value)) - xf86Info.allowMouseOpenFail = value; - - xf86Info.pmFlag = TRUE; - if (xf86GetOptValBool(FlagOptions, FLAG_NOPM, &value)) - xf86Info.pmFlag = !value; - { - if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) { - if (!xf86NameCmp(s, "flush")) { - xf86Msg(X_CONFIG, "Flushing logfile enabled\n"); - LogSetParameter(XLOG_FLUSH, TRUE); - } - else if (!xf86NameCmp(s, "sync")) { - xf86Msg(X_CONFIG, "Syncing logfile enabled\n"); - LogSetParameter(XLOG_FLUSH, TRUE); - LogSetParameter(XLOG_SYNC, TRUE); - } - else { - xf86Msg(X_WARNING, "Unknown Log option\n"); - } - } - } - - { - if ((s = xf86GetOptValString(FlagOptions, FLAG_RENDER_COLORMAP_MODE))) { - int policy = PictureParseCmapPolicy(s); - - if (policy == PictureCmapPolicyInvalid) - xf86Msg(X_WARNING, "Unknown colormap policy \"%s\"\n", s); - else { - xf86Msg(X_CONFIG, "Render colormap policy set to %s\n", s); - PictureCmapPolicy = policy; - } - } - } - -#ifdef GLXEXT - xf86Info.glxVisuals = XF86_GlxVisualsTypical; - xf86Info.glxVisualsFrom = X_DEFAULT; - if ((s = xf86GetOptValString(FlagOptions, FLAG_GLX_VISUALS))) { - if (!xf86NameCmp(s, "minimal")) { - xf86Info.glxVisuals = XF86_GlxVisualsMinimal; - } - else if (!xf86NameCmp(s, "typical")) { - xf86Info.glxVisuals = XF86_GlxVisualsTypical; - } - else if (!xf86NameCmp(s, "all")) { - xf86Info.glxVisuals = XF86_GlxVisualsAll; - } - else { - xf86Msg(X_WARNING, "Unknown GlxVisuals option\n"); - } - } - - if (xf86Info.iglxFrom != X_CMDLINE) { - if (xf86GetOptValBool(FlagOptions, FLAG_IGLX, &value)) { - enableIndirectGLX = value; - xf86Info.iglxFrom = X_CONFIG; - } - } -#endif - - xf86Info.debug = xf86GetOptValString(FlagOptions, FLAG_DEBUG); - - /* if we're not hotplugging, force some input devices to exist */ - xf86Info.forceInputDevices = !(xf86Info.autoAddDevices && - xf86Info.autoEnableDevices); - - /* when forcing input devices, we use kbd. otherwise evdev, so use the - * evdev rules set. */ -#if defined(__linux__) - if (!xf86Info.forceInputDevices) - rules = "evdev"; - else -#endif - rules = "base"; - - /* Xkb default options. */ - XkbInitRules(&set, rules, "pc105", "us", NULL, NULL); - XkbSetRulesDflts(&set); - XkbFreeRMLVOSet(&set, FALSE); - - xf86Info.useDefaultFontPath = TRUE; - if (xf86GetOptValBool(FlagOptions, FLAG_USE_DEFAULT_FONT_PATH, &value)) { - xf86Info.useDefaultFontPath = value; - } - -/* Make sure that timers don't overflow CARD32's after multiplying */ -#define MAX_TIME_IN_MIN (0x7fffffff / MILLI_PER_MIN) - - i = -1; - xf86GetOptValInteger(FlagOptions, FLAG_SAVER_BLANKTIME, &i); - if ((i >= 0) && (i < MAX_TIME_IN_MIN)) - ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN; - else if (i != -1) - ErrorF("BlankTime value %d outside legal range of 0 - %d minutes\n", - i, MAX_TIME_IN_MIN); - -#ifdef DPMSExtension - i = -1; - xf86GetOptValInteger(FlagOptions, FLAG_DPMS_STANDBYTIME, &i); - if ((i >= 0) && (i < MAX_TIME_IN_MIN)) - DPMSStandbyTime = i * MILLI_PER_MIN; - else if (i != -1) - ErrorF("StandbyTime value %d outside legal range of 0 - %d minutes\n", - i, MAX_TIME_IN_MIN); - i = -1; - xf86GetOptValInteger(FlagOptions, FLAG_DPMS_SUSPENDTIME, &i); - if ((i >= 0) && (i < MAX_TIME_IN_MIN)) - DPMSSuspendTime = i * MILLI_PER_MIN; - else if (i != -1) - ErrorF("SuspendTime value %d outside legal range of 0 - %d minutes\n", - i, MAX_TIME_IN_MIN); - i = -1; - xf86GetOptValInteger(FlagOptions, FLAG_DPMS_OFFTIME, &i); - if ((i >= 0) && (i < MAX_TIME_IN_MIN)) - DPMSOffTime = i * MILLI_PER_MIN; - else if (i != -1) - ErrorF("OffTime value %d outside legal range of 0 - %d minutes\n", - i, MAX_TIME_IN_MIN); -#endif - -#ifdef PANORAMIX - from = X_DEFAULT; - if (!noPanoramiXExtension) - from = X_CMDLINE; - else if (xf86GetOptValBool(FlagOptions, FLAG_XINERAMA, &value)) { - noPanoramiXExtension = !value; - from = X_CONFIG; - } - if (!noPanoramiXExtension) - xf86Msg(from, "Xinerama: enabled\n"); -#endif - -#ifdef DRI2 - xf86Info.dri2 = FALSE; - xf86Info.dri2From = X_DEFAULT; - if (xf86GetOptValBool(FlagOptions, FLAG_DRI2, &value)) { - xf86Info.dri2 = value; - xf86Info.dri2From = X_CONFIG; - } -#endif - - from = X_DEFAULT; - if (LimitClients != LIMITCLIENTS) - from = X_CMDLINE; - i = -1; - if (xf86GetOptValInteger(FlagOptions, FLAG_MAX_CLIENTS, &i)) { - if (Ones(i) != 1 || i < 64 || i > 2048) { - ErrorF("MaxClients must be one of 64, 128, 256, 512, 1024, or 2048\n"); - } else { - from = X_CONFIG; - LimitClients = i; - } - } - xf86Msg(from, "Max clients allowed: %i, resource mask: 0x%x\n", - LimitClients, RESOURCE_ID_MASK); -} - -Bool -xf86DRI2Enabled(void) -{ - return xf86Info.dri2; -} - -/** - * Search for the pInfo in the null-terminated list given and remove (and - * free) it if present. All other devices are moved forward. - */ -static void -freeDevice(InputInfoPtr * list, InputInfoPtr pInfo) -{ - InputInfoPtr *devs; - - for (devs = list; devs && *devs; devs++) { - if (*devs == pInfo) { - free(*devs); - for (; devs && *devs; devs++) - devs[0] = devs[1]; - break; - } - } -} - -/** - * Append pInfo to the null-terminated list, allocating space as necessary. - * pInfo is used as the last element. - */ -static InputInfoPtr * -addDevice(InputInfoPtr * list, InputInfoPtr pInfo) -{ - InputInfoPtr *devs; - int count = 1; - - for (devs = list; devs && *devs; devs++) - count++; - - list = xnfreallocarray(list, count + 1, sizeof(InputInfoPtr)); - list[count] = NULL; - - list[count - 1] = pInfo; - return list; -} - -/* - * Locate the core input devices. These can be specified/located in - * the following ways, in order of priority: - * - * 1. The InputDevices named by the -pointer and -keyboard command line - * options. - * 2. The "CorePointer" and "CoreKeyboard" InputDevices referred to by - * the active ServerLayout. - * 3. The first InputDevices marked as "CorePointer" and "CoreKeyboard". - * 4. The first InputDevices that use 'keyboard' or 'kbd' and a valid mouse - * driver (mouse, synaptics, evdev, vmmouse, void) - * 5. Default devices with an empty (default) configuration. These defaults - * will reference the 'mouse' and 'keyboard' drivers. - */ - -static Bool -checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout) -{ - InputInfoPtr corePointer = NULL, coreKeyboard = NULL; - Bool foundPointer = FALSE, foundKeyboard = FALSE; - const char *pointerMsg = NULL, *keyboardMsg = NULL; - InputInfoPtr *devs, /* iterator */ - indp; - InputInfoPtr Pointer, Keyboard; - XF86ConfInputPtr confInput; - XF86ConfInputRec defPtr, defKbd; - MessageType from = X_DEFAULT; - - const char *mousedrivers[] = { "mouse", "synaptics", "evdev", "vmmouse", - "void", NULL - }; - - /* - * First check if a core pointer or core keyboard have been specified - * in the active ServerLayout. If more than one is specified for either, - * remove the core attribute from the later ones. - */ - for (devs = servlayoutp->inputs; devs && *devs; devs++) { - indp = *devs; - if (indp->options && - xf86CheckBoolOption(indp->options, "CorePointer", FALSE)) { - if (!corePointer) { - corePointer = indp; - } - } - if (indp->options && - xf86CheckBoolOption(indp->options, "CoreKeyboard", FALSE)) { - if (!coreKeyboard) { - coreKeyboard = indp; - } - } - } - - confInput = NULL; - - /* 1. Check for the -pointer command line option. */ - if (xf86PointerName) { - confInput = xf86findInput(xf86PointerName, - xf86configptr->conf_input_lst); - if (!confInput) { - xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n", - xf86PointerName); - return FALSE; - } - from = X_CMDLINE; - /* - * If one was already specified in the ServerLayout, it needs to be - * removed. - */ - if (corePointer) { - freeDevice(servlayoutp->inputs, corePointer); - corePointer = NULL; - } - foundPointer = TRUE; - } - - /* 2. ServerLayout-specified core pointer. */ - if (corePointer) { - foundPointer = TRUE; - from = X_CONFIG; - } - - /* 3. First core pointer device. */ - if (!foundPointer && (xf86Info.forceInputDevices || implicitLayout)) { - XF86ConfInputPtr p; - - for (p = xf86configptr->conf_input_lst; p; p = p->list.next) { - if (p->inp_option_lst && - xf86CheckBoolOption(p->inp_option_lst, "CorePointer", FALSE)) { - confInput = p; - foundPointer = TRUE; - from = X_DEFAULT; - pointerMsg = "first core pointer device"; - break; - } - } - } - - /* 4. First pointer with an allowed mouse driver. */ - if (!foundPointer && xf86Info.forceInputDevices) { - const char **driver = mousedrivers; - - confInput = xf86findInput(CONF_IMPLICIT_POINTER, - xf86configptr->conf_input_lst); - while (*driver && !confInput) { - confInput = xf86findInputByDriver(*driver, - xf86configptr->conf_input_lst); - driver++; - } - if (confInput) { - foundPointer = TRUE; - from = X_DEFAULT; - pointerMsg = "first mouse device"; - } - } - - /* 5. Built-in default. */ - if (!foundPointer && xf86Info.forceInputDevices) { - memset(&defPtr, 0, sizeof(defPtr)); - defPtr.inp_identifier = strdup(""); - defPtr.inp_driver = strdup("mouse"); - confInput = &defPtr; - foundPointer = TRUE; - from = X_DEFAULT; - pointerMsg = "default mouse configuration"; - } - - /* Add the core pointer device to the layout, and set it to Core. */ - if (foundPointer && confInput) { - Pointer = xf86AllocateInput(); - if (Pointer) - foundPointer = configInput(Pointer, confInput, from); - if (foundPointer) { - Pointer->options = xf86AddNewOption(Pointer->options, - "CorePointer", "on"); - Pointer->options = xf86AddNewOption(Pointer->options, - "driver", - confInput->inp_driver); - Pointer->options = - xf86AddNewOption(Pointer->options, "identifier", - confInput->inp_identifier); - servlayoutp->inputs = addDevice(servlayoutp->inputs, Pointer); - } - } - - if (!foundPointer && xf86Info.forceInputDevices) { - /* This shouldn't happen. */ - xf86Msg(X_ERROR, "Cannot locate a core pointer device.\n"); - xf86DeleteInput(Pointer, 0); - return FALSE; - } - - confInput = NULL; - - /* 1. Check for the -keyboard command line option. */ - if (xf86KeyboardName) { - confInput = xf86findInput(xf86KeyboardName, - xf86configptr->conf_input_lst); - if (!confInput) { - xf86Msg(X_ERROR, "No InputDevice section called \"%s\"\n", - xf86KeyboardName); - return FALSE; - } - from = X_CMDLINE; - /* - * If one was already specified in the ServerLayout, it needs to be - * removed. - */ - if (coreKeyboard) { - freeDevice(servlayoutp->inputs, coreKeyboard); - coreKeyboard = NULL; - } - foundKeyboard = TRUE; - } - - /* 2. ServerLayout-specified core keyboard. */ - if (coreKeyboard) { - foundKeyboard = TRUE; - from = X_CONFIG; - } - - /* 3. First core keyboard device. */ - if (!foundKeyboard && (xf86Info.forceInputDevices || implicitLayout)) { - XF86ConfInputPtr p; - - for (p = xf86configptr->conf_input_lst; p; p = p->list.next) { - if (p->inp_option_lst && - xf86CheckBoolOption(p->inp_option_lst, "CoreKeyboard", FALSE)) { - confInput = p; - foundKeyboard = TRUE; - from = X_DEFAULT; - keyboardMsg = "first core keyboard device"; - break; - } - } - } - - /* 4. First keyboard with 'keyboard' or 'kbd' as the driver. */ - if (!foundKeyboard && xf86Info.forceInputDevices) { - confInput = xf86findInput(CONF_IMPLICIT_KEYBOARD, - xf86configptr->conf_input_lst); - if (!confInput) { - confInput = xf86findInputByDriver("kbd", - xf86configptr->conf_input_lst); - } - if (confInput) { - foundKeyboard = TRUE; - from = X_DEFAULT; - keyboardMsg = "first keyboard device"; - } - } - - /* 5. Built-in default. */ - if (!foundKeyboard && xf86Info.forceInputDevices) { - memset(&defKbd, 0, sizeof(defKbd)); - defKbd.inp_identifier = strdup(""); - defKbd.inp_driver = strdup("kbd"); - confInput = &defKbd; - foundKeyboard = TRUE; - keyboardMsg = "default keyboard configuration"; - from = X_DEFAULT; - } - - /* Add the core keyboard device to the layout, and set it to Core. */ - if (foundKeyboard && confInput) { - Keyboard = xf86AllocateInput(); - if (Keyboard) - foundKeyboard = configInput(Keyboard, confInput, from); - if (foundKeyboard) { - Keyboard->options = xf86AddNewOption(Keyboard->options, - "CoreKeyboard", "on"); - Keyboard->options = xf86AddNewOption(Keyboard->options, - "driver", - confInput->inp_driver); - Keyboard->options = - xf86AddNewOption(Keyboard->options, "identifier", - confInput->inp_identifier); - servlayoutp->inputs = addDevice(servlayoutp->inputs, Keyboard); - } - } - - if (!foundKeyboard && xf86Info.forceInputDevices) { - /* This shouldn't happen. */ - xf86Msg(X_ERROR, "Cannot locate a core keyboard device.\n"); - xf86DeleteInput(Keyboard, 0); - return FALSE; - } - - if (pointerMsg) { - if (implicitLayout) - xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n", - pointerMsg); - else - xf86Msg(X_DEFAULT, "The core pointer device wasn't specified " - "explicitly in the layout.\n" - "\tUsing the %s.\n", pointerMsg); - } - - if (keyboardMsg) { - if (implicitLayout) - xf86Msg(X_DEFAULT, "No Layout section. Using the %s.\n", - keyboardMsg); - else - xf86Msg(X_DEFAULT, "The core keyboard device wasn't specified " - "explicitly in the layout.\n" - "\tUsing the %s.\n", keyboardMsg); - } - - if (!xf86Info.forceInputDevices && !(foundPointer && foundKeyboard)) { -#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) - const char *config_backend; - -#if defined(CONFIG_HAL) - config_backend = "HAL"; -#elif defined(CONFIG_UDEV) - config_backend = "udev"; -#else - config_backend = "wscons"; -#endif - xf86Msg(X_INFO, "The server relies on %s to provide the list of " - "input devices.\n\tIf no devices become available, " - "reconfigure %s or disable AutoAddDevices.\n", - config_backend, config_backend); -#else - xf86Msg(X_WARNING, "Hotplugging requested but the server was " - "compiled without a config backend. " - "No input devices were configured, the server " - "will start without any input devices.\n"); -#endif - } - - return TRUE; -} - -typedef enum { - LAYOUT_ISOLATEDEVICE, - LAYOUT_SINGLECARD -} LayoutValues; - -static OptionInfoRec LayoutOptions[] = { - {LAYOUT_ISOLATEDEVICE, "IsolateDevice", OPTV_STRING, - {0}, FALSE}, - {LAYOUT_SINGLECARD, "SingleCard", OPTV_BOOLEAN, - {0}, FALSE}, - {-1, NULL, OPTV_NONE, - {0}, FALSE}, -}; - -static Bool -configInputDevices(XF86ConfLayoutPtr layout, serverLayoutPtr servlayoutp) -{ - XF86ConfInputrefPtr irp; - InputInfoPtr *indp; - int count = 0; - - /* - * Count the number of input devices. - */ - irp = layout->lay_input_lst; - while (irp) { - count++; - irp = (XF86ConfInputrefPtr) irp->list.next; - } - DebugF("Found %d input devices in the layout section %s\n", - count, layout->lay_identifier); - indp = xnfcalloc((count + 1), sizeof(InputInfoPtr)); - indp[count] = NULL; - irp = layout->lay_input_lst; - count = 0; - while (irp) { - indp[count] = xf86AllocateInput(); - if (!configInput(indp[count], irp->iref_inputdev, X_CONFIG)) { - do { - free(indp[count]); - } while (count--); - free(indp); - return FALSE; - } - indp[count]->options = xf86OptionListMerge(indp[count]->options, - irp->iref_option_lst); - count++; - irp = (XF86ConfInputrefPtr) irp->list.next; - } - servlayoutp->inputs = indp; - - return TRUE; -} - -/* - * figure out which layout is active, which screens are used in that layout, - * which drivers and monitors are used in these screens - */ -static Bool -configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout, - char *default_layout) -{ - XF86ConfAdjacencyPtr adjp; - XF86ConfInactivePtr idp; - int saved_count, count = 0; - int scrnum; - XF86ConfLayoutPtr l; - MessageType from; - screenLayoutPtr slp; - GDevPtr gdp; - int i = 0, j; - - if (!servlayoutp) - return FALSE; - - /* - * which layout section is the active one? - * - * If there is a -layout command line option, use that one, otherwise - * pick the first one. - */ - from = X_DEFAULT; - if (xf86LayoutName != NULL) - from = X_CMDLINE; - else if (default_layout) { - xf86LayoutName = default_layout; - from = X_CONFIG; - } - if (xf86LayoutName != NULL) { - if ((l = xf86findLayout(xf86LayoutName, conf_layout)) == NULL) { - xf86Msg(X_ERROR, "No ServerLayout section called \"%s\"\n", - xf86LayoutName); - return FALSE; - } - conf_layout = l; - } - xf86Msg(from, "ServerLayout \"%s\"\n", conf_layout->lay_identifier); - adjp = conf_layout->lay_adjacency_lst; - - /* - * we know that each screen is referenced exactly once on the left side - * of a layout statement in the Layout section. So to allocate the right - * size for the array we do a quick walk of the list to figure out how - * many sections we have - */ - while (adjp) { - count++; - adjp = (XF86ConfAdjacencyPtr) adjp->list.next; - } - - DebugF("Found %d screens in the layout section %s", - count, conf_layout->lay_identifier); - if (!count) /* alloc enough storage even if no screen is specified */ - count = 1; - - slp = xnfcalloc((count + 1), sizeof(screenLayoutRec)); - slp[count].screen = NULL; - /* - * now that we have storage, loop over the list again and fill in our - * data structure; at this point we do not fill in the adjacency - * information as it is not clear if we need it at all - */ - adjp = conf_layout->lay_adjacency_lst; - count = 0; - while (adjp) { - slp[count].screen = xnfcalloc(1, sizeof(confScreenRec)); - if (adjp->adj_scrnum < 0) - scrnum = count; - else - scrnum = adjp->adj_scrnum; - if (!configScreen(slp[count].screen, adjp->adj_screen, scrnum, - X_CONFIG, (scrnum == 0 && !adjp->list.next))) { - do { - free(slp[count].screen); - } while (count--); - free(slp); - return FALSE; - } - slp[count].x = adjp->adj_x; - slp[count].y = adjp->adj_y; - slp[count].refname = adjp->adj_refscreen; - switch (adjp->adj_where) { - case CONF_ADJ_OBSOLETE: - slp[count].where = PosObsolete; - slp[count].topname = adjp->adj_top_str; - slp[count].bottomname = adjp->adj_bottom_str; - slp[count].leftname = adjp->adj_left_str; - slp[count].rightname = adjp->adj_right_str; - break; - case CONF_ADJ_ABSOLUTE: - slp[count].where = PosAbsolute; - break; - case CONF_ADJ_RIGHTOF: - slp[count].where = PosRightOf; - break; - case CONF_ADJ_LEFTOF: - slp[count].where = PosLeftOf; - break; - case CONF_ADJ_ABOVE: - slp[count].where = PosAbove; - break; - case CONF_ADJ_BELOW: - slp[count].where = PosBelow; - break; - case CONF_ADJ_RELATIVE: - slp[count].where = PosRelative; - break; - } - count++; - adjp = (XF86ConfAdjacencyPtr) adjp->list.next; - } - - /* No screen was specified in the layout. take the first one from the - * config file, or - if it is NULL - configScreen autogenerates one for - * us */ - if (!count) { - XF86ConfScreenPtr screen; - - FIND_SUITABLE (XF86ConfScreenPtr, xf86configptr->conf_screen_lst, screen); - slp[0].screen = xnfcalloc(1, sizeof(confScreenRec)); - if (!configScreen(slp[0].screen, screen, - 0, X_CONFIG, TRUE)) { - free(slp[0].screen); - free(slp); - return FALSE; - } - } - - /* XXX Need to tie down the upper left screen. */ - - /* Fill in the refscreen and top/bottom/left/right values */ - for (i = 0; i < count; i++) { - for (j = 0; j < count; j++) { - if (slp[i].refname && - strcmp(slp[i].refname, slp[j].screen->id) == 0) { - slp[i].refscreen = slp[j].screen; - } - if (slp[i].topname && - strcmp(slp[i].topname, slp[j].screen->id) == 0) { - slp[i].top = slp[j].screen; - } - if (slp[i].bottomname && - strcmp(slp[i].bottomname, slp[j].screen->id) == 0) { - slp[i].bottom = slp[j].screen; - } - if (slp[i].leftname && - strcmp(slp[i].leftname, slp[j].screen->id) == 0) { - slp[i].left = slp[j].screen; - } - if (slp[i].rightname && - strcmp(slp[i].rightname, slp[j].screen->id) == 0) { - slp[i].right = slp[j].screen; - } - } - if (slp[i].where != PosObsolete - && slp[i].where != PosAbsolute && !slp[i].refscreen) { - xf86Msg(X_ERROR, "Screen %s doesn't exist: deleting placement\n", - slp[i].refname); - slp[i].where = PosAbsolute; - slp[i].x = 0; - slp[i].y = 0; - } - } - - if (!count) - saved_count = 1; - else - saved_count = count; - /* - * Count the number of inactive devices. - */ - count = 0; - idp = conf_layout->lay_inactive_lst; - while (idp) { - count++; - idp = (XF86ConfInactivePtr) idp->list.next; - } - DebugF("Found %d inactive devices in the layout section %s\n", - count, conf_layout->lay_identifier); - gdp = xnfallocarray(count + 1, sizeof(GDevRec)); - gdp[count].identifier = NULL; - idp = conf_layout->lay_inactive_lst; - count = 0; - while (idp) { - if (!configDevice(&gdp[count], idp->inactive_device, FALSE, FALSE)) - goto bail; - count++; - idp = (XF86ConfInactivePtr) idp->list.next; - } - - if (!configInputDevices(conf_layout, servlayoutp)) - goto bail; - - servlayoutp->id = conf_layout->lay_identifier; - servlayoutp->screens = slp; - servlayoutp->inactives = gdp; - servlayoutp->options = conf_layout->lay_option_lst; - from = X_DEFAULT; - - return TRUE; - - bail: - do { - free(slp[saved_count].screen); - } while (saved_count--); - free(slp); - free(gdp); - return FALSE; -} - -/* - * No layout section, so find the first Screen section and set that up as - * the only active screen. - */ -static Bool -configImpliedLayout(serverLayoutPtr servlayoutp, XF86ConfScreenPtr conf_screen, - XF86ConfigPtr conf_ptr) -{ - MessageType from; - XF86ConfScreenPtr s; - screenLayoutPtr slp; - InputInfoPtr *indp; - XF86ConfLayoutRec layout; - - if (!servlayoutp) - return FALSE; - - /* - * which screen section is the active one? - * - * If there is a -screen option, use that one, otherwise use the first - * one. - */ - - from = X_CONFIG; - if (xf86ScreenName != NULL) { - if ((s = xf86findScreen(xf86ScreenName, conf_screen)) == NULL) { - xf86Msg(X_ERROR, "No Screen section called \"%s\"\n", - xf86ScreenName); - return FALSE; - } - conf_screen = s; - from = X_CMDLINE; - } - - /* We have exactly one screen */ - - slp = xnfcalloc(1, 2 * sizeof(screenLayoutRec)); - slp[0].screen = xnfcalloc(1, sizeof(confScreenRec)); - slp[1].screen = NULL; - if (!configScreen(slp[0].screen, conf_screen, 0, from, TRUE)) { - free(slp); - return FALSE; - } - servlayoutp->id = "(implicit)"; - servlayoutp->screens = slp; - servlayoutp->inactives = xnfcalloc(1, sizeof(GDevRec)); - servlayoutp->options = NULL; - - memset(&layout, 0, sizeof(layout)); - layout.lay_identifier = servlayoutp->id; - if (xf86layoutAddInputDevices(conf_ptr, &layout) > 0) { - if (!configInputDevices(&layout, servlayoutp)) - return FALSE; - from = X_DEFAULT; - } - else { - /* Set up an empty input device list, then look for some core devices. */ - indp = xnfalloc(sizeof(InputInfoPtr)); - *indp = NULL; - servlayoutp->inputs = indp; - } - - return TRUE; -} - -static Bool -configXvAdaptor(confXvAdaptorPtr adaptor, XF86ConfVideoAdaptorPtr conf_adaptor) -{ - int count = 0; - XF86ConfVideoPortPtr conf_port; - - xf86Msg(X_CONFIG, "| |-->VideoAdaptor \"%s\"\n", - conf_adaptor->va_identifier); - adaptor->identifier = conf_adaptor->va_identifier; - adaptor->options = conf_adaptor->va_option_lst; - if (conf_adaptor->va_busid || conf_adaptor->va_driver) { - xf86Msg(X_CONFIG, "| | Unsupported device type, skipping entry\n"); - return FALSE; - } - - /* - * figure out how many videoport subsections there are and fill them in - */ - conf_port = conf_adaptor->va_port_lst; - while (conf_port) { - count++; - conf_port = (XF86ConfVideoPortPtr) conf_port->list.next; - } - adaptor->ports = xnfallocarray(count, sizeof(confXvPortRec)); - adaptor->numports = count; - count = 0; - conf_port = conf_adaptor->va_port_lst; - while (conf_port) { - adaptor->ports[count].identifier = conf_port->vp_identifier; - adaptor->ports[count].options = conf_port->vp_option_lst; - count++; - conf_port = (XF86ConfVideoPortPtr) conf_port->list.next; - } - - return TRUE; -} - -static Bool -configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum, - MessageType from, Bool auto_gpu_device) -{ - int count = 0; - XF86ConfDisplayPtr dispptr; - XF86ConfAdaptorLinkPtr conf_adaptor; - Bool defaultMonitor = FALSE; - XF86ConfScreenRec local_conf_screen; - int i; - - if (!conf_screen) { - memset(&local_conf_screen, 0, sizeof(local_conf_screen)); - conf_screen = &local_conf_screen; - conf_screen->scrn_identifier = "Default Screen Section"; - xf86Msg(X_DEFAULT, "No screen section available. Using defaults.\n"); - } - - xf86Msg(from, "|-->Screen \"%s\" (%d)\n", conf_screen->scrn_identifier, - scrnum); - /* - * now we fill in the elements of the screen - */ - screenp->id = conf_screen->scrn_identifier; - screenp->screennum = scrnum; - screenp->defaultdepth = conf_screen->scrn_defaultdepth; - screenp->defaultbpp = conf_screen->scrn_defaultbpp; - screenp->defaultfbbpp = conf_screen->scrn_defaultfbbpp; - screenp->monitor = xnfcalloc(1, sizeof(MonRec)); - /* If no monitor is specified, create a default one. */ - if (!conf_screen->scrn_monitor) { - XF86ConfMonitorRec defMon; - - memset(&defMon, 0, sizeof(defMon)); - defMon.mon_identifier = ""; - if (!configMonitor(screenp->monitor, &defMon)) - return FALSE; - defaultMonitor = TRUE; - } - else { - if (!configMonitor(screenp->monitor, conf_screen->scrn_monitor)) - return FALSE; - } - /* Configure the device. If there isn't one configured, attach to the - * first inactive one that we can configure. If there's none that work, - * set it to NULL so that the section can be autoconfigured later */ - screenp->device = xnfcalloc(1, sizeof(GDevRec)); - if ((!conf_screen->scrn_device) && (xf86configptr->conf_device_lst)) { - FIND_SUITABLE (XF86ConfDevicePtr, xf86configptr->conf_device_lst, conf_screen->scrn_device); - xf86Msg(X_DEFAULT, "No device specified for screen \"%s\".\n" - "\tUsing the first device section listed.\n", screenp->id); - } - if (configDevice(screenp->device, conf_screen->scrn_device, TRUE, FALSE)) { - screenp->device->myScreenSection = screenp; - } - else { - screenp->device = NULL; - } - - if (auto_gpu_device && conf_screen->num_gpu_devices == 0 && - xf86configptr->conf_device_lst) { - /* Loop through the entire device list and skip the primary device - * assigned to the screen. This is important because there are two - * cases where the assigned primary device is not the first device in - * the device list. Firstly, if the first device in the list is assigned - * to a different seat than this X server, it will not have been picked - * by the previous FIND_SUITABLE. Secondly, if the device was explicitly - * assigned in the config but there is still only one screen, this code - * path is executed but the explicitly assigned device may not be the - * first device in the list. */ - XF86ConfDevicePtr ptmp, sdevice = xf86configptr->conf_device_lst; - - for (i = 0; i < MAX_GPUDEVICES; i++) { - if (!sdevice) - break; - - FIND_SUITABLE (XF86ConfDevicePtr, sdevice, ptmp); - if (!ptmp) - break; - - /* skip the primary device on the screen */ - if (ptmp != conf_screen->scrn_device) { - conf_screen->scrn_gpu_devices[i] = ptmp; - } else { - sdevice = ptmp->list.next; - i--; /* run the next iteration with the same index */ - continue; - } - - screenp->gpu_devices[i] = xnfcalloc(1, sizeof(GDevRec)); - if (configDevice(screenp->gpu_devices[i], conf_screen->scrn_gpu_devices[i], TRUE, TRUE)) { - screenp->gpu_devices[i]->myScreenSection = screenp; - } - sdevice = conf_screen->scrn_gpu_devices[i]->list.next; - } - screenp->num_gpu_devices = i; - - } else { - for (i = 0; i < conf_screen->num_gpu_devices; i++) { - screenp->gpu_devices[i] = xnfcalloc(1, sizeof(GDevRec)); - if (configDevice(screenp->gpu_devices[i], conf_screen->scrn_gpu_devices[i], TRUE, TRUE)) { - screenp->gpu_devices[i]->myScreenSection = screenp; - } - } - screenp->num_gpu_devices = conf_screen->num_gpu_devices; - } - - screenp->options = conf_screen->scrn_option_lst; - - /* - * figure out how many display subsections there are and fill them in - */ - dispptr = conf_screen->scrn_display_lst; - while (dispptr) { - count++; - dispptr = (XF86ConfDisplayPtr) dispptr->list.next; - } - screenp->displays = xnfallocarray(count, sizeof(DispPtr)); - screenp->numdisplays = count; - - for (count = 0, dispptr = conf_screen->scrn_display_lst; - dispptr; - dispptr = (XF86ConfDisplayPtr) dispptr->list.next, count++) { - - /* Allocate individual Display records */ - screenp->displays[count] = xnfcalloc(1, sizeof(DispRec)); - - /* Fill in the default Virtual size, if any */ - if (conf_screen->scrn_virtualX && conf_screen->scrn_virtualY) { - screenp->displays[count]->virtualX = conf_screen->scrn_virtualX; - screenp->displays[count]->virtualY = conf_screen->scrn_virtualY; - } - - /* Now do the per-Display Virtual sizes */ - configDisplay(screenp->displays[count], dispptr); - } - - /* - * figure out how many videoadaptor references there are and fill them in - */ - count = 0; - conf_adaptor = conf_screen->scrn_adaptor_lst; - while (conf_adaptor) { - count++; - conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next; - } - screenp->xvadaptors = xnfallocarray(count, sizeof(confXvAdaptorRec)); - screenp->numxvadaptors = 0; - conf_adaptor = conf_screen->scrn_adaptor_lst; - while (conf_adaptor) { - if (configXvAdaptor(&(screenp->xvadaptors[screenp->numxvadaptors]), - conf_adaptor->al_adaptor)) - screenp->numxvadaptors++; - conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next; - } - - if (defaultMonitor) { - xf86Msg(X_DEFAULT, "No monitor specified for screen \"%s\".\n" - "\tUsing a default monitor configuration.\n", screenp->id); - } - return TRUE; -} - -typedef enum { - MON_REDUCEDBLANKING, - MON_MAX_PIX_CLOCK, -} MonitorValues; - -static OptionInfoRec MonitorOptions[] = { - {MON_REDUCEDBLANKING, "ReducedBlanking", OPTV_BOOLEAN, - {0}, FALSE}, - {MON_MAX_PIX_CLOCK, "MaxPixClock", OPTV_FREQ, - {0}, FALSE}, - {-1, NULL, OPTV_NONE, - {0}, FALSE}, -}; - -static Bool -configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor) -{ - int count; - DisplayModePtr mode, last = NULL; - XF86ConfModeLinePtr cmodep; - XF86ConfModesPtr modes; - XF86ConfModesLinkPtr modeslnk = conf_monitor->mon_modes_sect_lst; - Gamma zeros = { 0.0, 0.0, 0.0 }; - float badgamma = 0.0; - double maxPixClock; - - xf86Msg(X_CONFIG, "| |-->Monitor \"%s\"\n", conf_monitor->mon_identifier); - monitorp->id = conf_monitor->mon_identifier; - monitorp->vendor = conf_monitor->mon_vendor; - monitorp->model = conf_monitor->mon_modelname; - monitorp->Modes = NULL; - monitorp->Last = NULL; - monitorp->gamma = zeros; - monitorp->widthmm = conf_monitor->mon_width; - monitorp->heightmm = conf_monitor->mon_height; - monitorp->reducedblanking = FALSE; - monitorp->maxPixClock = 0; - monitorp->options = conf_monitor->mon_option_lst; - - /* - * fill in the monitor structure - */ - for (count = 0; - count < conf_monitor->mon_n_hsync && count < MAX_HSYNC; count++) { - monitorp->hsync[count].hi = conf_monitor->mon_hsync[count].hi; - monitorp->hsync[count].lo = conf_monitor->mon_hsync[count].lo; - } - monitorp->nHsync = count; - for (count = 0; - count < conf_monitor->mon_n_vrefresh && count < MAX_VREFRESH; - count++) { - monitorp->vrefresh[count].hi = conf_monitor->mon_vrefresh[count].hi; - monitorp->vrefresh[count].lo = conf_monitor->mon_vrefresh[count].lo; - } - monitorp->nVrefresh = count; - - /* - * first we collect the mode lines from the UseModes directive - */ - while (modeslnk) { - modes = xf86findModes(modeslnk->ml_modes_str, - xf86configptr->conf_modes_lst); - modeslnk->ml_modes = modes; - - /* now add the modes found in the modes - section to the list of modes for this - monitor unless it has been added before - because we are reusing the same section - for another screen */ - if (xf86itemNotSublist((GenericListPtr) conf_monitor->mon_modeline_lst, - (GenericListPtr) modes->mon_modeline_lst)) { - conf_monitor->mon_modeline_lst = (XF86ConfModeLinePtr) - xf86addListItem((GenericListPtr) conf_monitor->mon_modeline_lst, - (GenericListPtr) modes->mon_modeline_lst); - } - modeslnk = modeslnk->list.next; - } - - /* - * we need to hook in the mode lines now - * here both data structures use lists, only our internal one - * is double linked - */ - cmodep = conf_monitor->mon_modeline_lst; - while (cmodep) { - mode = xnfcalloc(1, sizeof(DisplayModeRec)); - mode->type = 0; - mode->Clock = cmodep->ml_clock; - mode->HDisplay = cmodep->ml_hdisplay; - mode->HSyncStart = cmodep->ml_hsyncstart; - mode->HSyncEnd = cmodep->ml_hsyncend; - mode->HTotal = cmodep->ml_htotal; - mode->VDisplay = cmodep->ml_vdisplay; - mode->VSyncStart = cmodep->ml_vsyncstart; - mode->VSyncEnd = cmodep->ml_vsyncend; - mode->VTotal = cmodep->ml_vtotal; - mode->Flags = cmodep->ml_flags; - mode->HSkew = cmodep->ml_hskew; - mode->VScan = cmodep->ml_vscan; - mode->name = xnfstrdup(cmodep->ml_identifier); - if (last) { - mode->prev = last; - last->next = mode; - } - else { - /* - * this is the first mode - */ - monitorp->Modes = mode; - mode->prev = NULL; - } - last = mode; - cmodep = (XF86ConfModeLinePtr) cmodep->list.next; - } - if (last) { - last->next = NULL; - } - monitorp->Last = last; - - /* add the (VESA) default modes */ - if (!addDefaultModes(monitorp)) - return FALSE; - - if (conf_monitor->mon_gamma_red > GAMMA_ZERO) - monitorp->gamma.red = conf_monitor->mon_gamma_red; - if (conf_monitor->mon_gamma_green > GAMMA_ZERO) - monitorp->gamma.green = conf_monitor->mon_gamma_green; - if (conf_monitor->mon_gamma_blue > GAMMA_ZERO) - monitorp->gamma.blue = conf_monitor->mon_gamma_blue; - - /* Check that the gamma values are within range */ - if (monitorp->gamma.red > GAMMA_ZERO && - (monitorp->gamma.red < GAMMA_MIN || monitorp->gamma.red > GAMMA_MAX)) { - badgamma = monitorp->gamma.red; - } - else if (monitorp->gamma.green > GAMMA_ZERO && - (monitorp->gamma.green < GAMMA_MIN || - monitorp->gamma.green > GAMMA_MAX)) { - badgamma = monitorp->gamma.green; - } - else if (monitorp->gamma.blue > GAMMA_ZERO && - (monitorp->gamma.blue < GAMMA_MIN || - monitorp->gamma.blue > GAMMA_MAX)) { - badgamma = monitorp->gamma.blue; - } - if (badgamma > GAMMA_ZERO) { - ErrorF("Gamma value %.f is out of range (%.2f - %.1f)\n", badgamma, - GAMMA_MIN, GAMMA_MAX); - return FALSE; - } - - xf86ProcessOptions(-1, monitorp->options, MonitorOptions); - xf86GetOptValBool(MonitorOptions, MON_REDUCEDBLANKING, - &monitorp->reducedblanking); - if (xf86GetOptValFreq(MonitorOptions, MON_MAX_PIX_CLOCK, OPTUNITS_KHZ, - &maxPixClock) == TRUE) { - monitorp->maxPixClock = (int) maxPixClock; - } - - return TRUE; -} - -static int -lookupVisual(const char *visname) -{ - int i; - - if (!visname || !*visname) - return -1; - - for (i = 0; i <= DirectColor; i++) { - if (!xf86nameCompare(visname, xf86VisualNames[i])) - break; - } - - if (i <= DirectColor) - return i; - - return -1; -} - -static Bool -configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display) -{ - int count = 0; - XF86ModePtr modep; - - displayp->frameX0 = conf_display->disp_frameX0; - displayp->frameY0 = conf_display->disp_frameY0; - displayp->virtualX = conf_display->disp_virtualX; - displayp->virtualY = conf_display->disp_virtualY; - displayp->depth = conf_display->disp_depth; - displayp->fbbpp = conf_display->disp_bpp; - displayp->weight.red = conf_display->disp_weight.red; - displayp->weight.green = conf_display->disp_weight.green; - displayp->weight.blue = conf_display->disp_weight.blue; - displayp->blackColour.red = conf_display->disp_black.red; - displayp->blackColour.green = conf_display->disp_black.green; - displayp->blackColour.blue = conf_display->disp_black.blue; - displayp->whiteColour.red = conf_display->disp_white.red; - displayp->whiteColour.green = conf_display->disp_white.green; - displayp->whiteColour.blue = conf_display->disp_white.blue; - displayp->options = conf_display->disp_option_lst; - if (conf_display->disp_visual) { - displayp->defaultVisual = lookupVisual(conf_display->disp_visual); - if (displayp->defaultVisual == -1) { - ErrorF("Invalid visual name: \"%s\"\n", conf_display->disp_visual); - return FALSE; - } - } - else { - displayp->defaultVisual = -1; - } - - /* - * now hook in the modes - */ - modep = conf_display->disp_mode_lst; - while (modep) { - count++; - modep = (XF86ModePtr) modep->list.next; - } - displayp->modes = xnfallocarray(count + 1, sizeof(char *)); - modep = conf_display->disp_mode_lst; - count = 0; - while (modep) { - displayp->modes[count] = modep->mode_name; - count++; - modep = (XF86ModePtr) modep->list.next; - } - displayp->modes[count] = NULL; - - return TRUE; -} - -static Bool -configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, Bool active, Bool gpu) -{ - int i; - - if (!conf_device) { - return FALSE; - } - - if (active) { - if (gpu) - xf86Msg(X_CONFIG, "| |-->GPUDevice \"%s\"\n", - conf_device->dev_identifier); - else - xf86Msg(X_CONFIG, "| |-->Device \"%s\"\n", - conf_device->dev_identifier); - } else - xf86Msg(X_CONFIG, "|-->Inactive Device \"%s\"\n", - conf_device->dev_identifier); - - devicep->identifier = conf_device->dev_identifier; - devicep->vendor = conf_device->dev_vendor; - devicep->board = conf_device->dev_board; - devicep->chipset = conf_device->dev_chipset; - devicep->ramdac = conf_device->dev_ramdac; - devicep->driver = conf_device->dev_driver; - devicep->active = active; - devicep->videoRam = conf_device->dev_videoram; - devicep->MemBase = conf_device->dev_mem_base; - devicep->IOBase = conf_device->dev_io_base; - devicep->clockchip = conf_device->dev_clockchip; - devicep->busID = conf_device->dev_busid; - devicep->chipID = conf_device->dev_chipid; - devicep->chipRev = conf_device->dev_chiprev; - devicep->options = conf_device->dev_option_lst; - devicep->irq = conf_device->dev_irq; - devicep->screen = conf_device->dev_screen; - - for (i = 0; i < MAXDACSPEEDS; i++) { - if (i < CONF_MAXDACSPEEDS) - devicep->dacSpeeds[i] = conf_device->dev_dacSpeeds[i]; - else - devicep->dacSpeeds[i] = 0; - } - devicep->numclocks = conf_device->dev_clocks; - if (devicep->numclocks > MAXCLOCKS) - devicep->numclocks = MAXCLOCKS; - for (i = 0; i < devicep->numclocks; i++) { - devicep->clock[i] = conf_device->dev_clock[i]; - } - devicep->claimed = FALSE; - - return TRUE; -} - -static void -configDRI(XF86ConfDRIPtr drip) -{ - struct group *grp; - - xf86ConfigDRI.group = -1; - xf86ConfigDRI.mode = 0; - - if (drip) { - if (drip->dri_group_name) { - if ((grp = getgrnam(drip->dri_group_name))) - xf86ConfigDRI.group = grp->gr_gid; - } - else { - if (drip->dri_group >= 0) - xf86ConfigDRI.group = drip->dri_group; - } - xf86ConfigDRI.mode = drip->dri_mode; - } -} - -static void -configExtensions(XF86ConfExtensionsPtr conf_ext) -{ - XF86OptionPtr o; - - if (conf_ext && conf_ext->ext_option_lst) { - for (o = conf_ext->ext_option_lst; o; o = xf86NextOption(o)) { - char *name = xf86OptionName(o); - char *val = xf86OptionValue(o); - char *n; - Bool enable = TRUE; - - /* Handle "No" */ - n = xf86NormalizeName(name); - if (strncmp(n, "no", 2) == 0) { - name += 2; - enable = FALSE; - } - - if (!val || - xf86NameCmp(val, "enable") == 0 || - xf86NameCmp(val, "enabled") == 0 || - xf86NameCmp(val, "on") == 0 || - xf86NameCmp(val, "1") == 0 || - xf86NameCmp(val, "yes") == 0 || xf86NameCmp(val, "true") == 0) { - /* NOTHING NEEDED -- enabling is handled below */ - } - else if (xf86NameCmp(val, "disable") == 0 || - xf86NameCmp(val, "disabled") == 0 || - xf86NameCmp(val, "off") == 0 || - xf86NameCmp(val, "0") == 0 || - xf86NameCmp(val, "no") == 0 || - xf86NameCmp(val, "false") == 0) { - enable = !enable; - } - else { - xf86Msg(X_WARNING, "Ignoring unrecognized value \"%s\"\n", val); - free(n); - continue; - } - - if (EnableDisableExtension(name, enable)) { - xf86Msg(X_CONFIG, "Extension \"%s\" is %s\n", - name, enable ? "enabled" : "disabled"); - } - else { - xf86Msg(X_WARNING, "Ignoring unrecognized extension \"%s\"\n", - name); - } - free(n); - } - } -} - -static Bool -configInput(InputInfoPtr inputp, XF86ConfInputPtr conf_input, MessageType from) -{ - xf86Msg(from, "|-->Input Device \"%s\"\n", conf_input->inp_identifier); - inputp->name = conf_input->inp_identifier; - inputp->driver = conf_input->inp_driver; - inputp->options = conf_input->inp_option_lst; - inputp->attrs = NULL; - - return TRUE; -} - -static Bool -modeIsPresent(DisplayModePtr mode, MonPtr monitorp) -{ - DisplayModePtr knownmodes = monitorp->Modes; - - /* all I can think of is a linear search... */ - while (knownmodes != NULL) { - if (!strcmp(mode->name, knownmodes->name) && - !(knownmodes->type & M_T_DEFAULT)) - return TRUE; - knownmodes = knownmodes->next; - } - return FALSE; -} - -static Bool -addDefaultModes(MonPtr monitorp) -{ - DisplayModePtr mode; - DisplayModePtr last = monitorp->Last; - int i = 0; - - for (i = 0; i < xf86NumDefaultModes; i++) { - mode = xf86DuplicateMode(&xf86DefaultModes[i]); - if (!modeIsPresent(mode, monitorp)) { - monitorp->Modes = xf86ModesAdd(monitorp->Modes, mode); - last = mode; - } - else { - free(mode); - } - } - monitorp->Last = last; - - return TRUE; -} - -static void -checkInput(serverLayoutPtr layout, Bool implicit_layout) -{ - checkCoreInputDevices(layout, implicit_layout); - - /* Unless we're forcing input devices, disable mouse/kbd devices in the - * config. Otherwise the same physical device is added multiple times, - * leading to duplicate events. - */ - if (!xf86Info.forceInputDevices && layout->inputs) { - InputInfoPtr *dev = layout->inputs; - BOOL warned = FALSE; - - while (*dev) { - if (strcmp((*dev)->driver, "kbd") == 0 || - strcmp((*dev)->driver, "mouse") == 0 || - strcmp((*dev)->driver, "vmmouse") == 0) { - InputInfoPtr *current; - - if (!warned) { - xf86Msg(X_WARNING, "Hotplugging is on, devices using " - "drivers 'kbd', 'mouse' or 'vmmouse' will be disabled.\n"); - warned = TRUE; - } - - xf86Msg(X_WARNING, "Disabling %s\n", (*dev)->name); - - current = dev; - free(*dev); - *dev = NULL; - - do { - *current = *(current + 1); - current++; - } while (*current); - } - else - dev++; - } - } -} - -/* - * load the config file and fill the global data structure - */ -ConfigStatus -xf86HandleConfigFile(Bool autoconfig) -{ -#ifdef XSERVER_LIBPCIACCESS - const char *scanptr; - Bool singlecard = 0; -#endif - Bool implicit_layout = FALSE; - XF86ConfLayoutPtr layout; - - if (!autoconfig) { - char *filename, *dirname, *sysdirname; - const char *filesearch, *dirsearch; - MessageType filefrom = X_DEFAULT; - MessageType dirfrom = X_DEFAULT; - - if (!PrivsElevated()) { - filesearch = ALL_CONFIGPATH; - dirsearch = ALL_CONFIGDIRPATH; - } - else { - filesearch = RESTRICTED_CONFIGPATH; - dirsearch = RESTRICTED_CONFIGDIRPATH; - } - - if (xf86ConfigFile) - filefrom = X_CMDLINE; - if (xf86ConfigDir) - dirfrom = X_CMDLINE; - - xf86initConfigFiles(); - sysdirname = xf86openConfigDirFiles(SYS_CONFIGDIRPATH, NULL, - PROJECTROOT); - dirname = xf86openConfigDirFiles(dirsearch, xf86ConfigDir, PROJECTROOT); - filename = xf86openConfigFile(filesearch, xf86ConfigFile, PROJECTROOT); - if (filename) { - xf86MsgVerb(filefrom, 0, "Using config file: \"%s\"\n", filename); - xf86ConfigFile = xnfstrdup(filename); - } - else { - if (xf86ConfigFile) - xf86Msg(X_ERROR, "Unable to locate/open config file: \"%s\"\n", - xf86ConfigFile); - } - if (dirname) { - xf86MsgVerb(dirfrom, 0, "Using config directory: \"%s\"\n", - dirname); - xf86ConfigDir = xnfstrdup(dirname); - } - else { - if (xf86ConfigDir) - xf86Msg(X_ERROR, - "Unable to locate/open config directory: \"%s\"\n", - xf86ConfigDir); - } - if (sysdirname) - xf86MsgVerb(X_DEFAULT, 0, "Using system config directory \"%s\"\n", - sysdirname); - if (!filename && !dirname && !sysdirname) - return CONFIG_NOFILE; - - free(filename); - free(dirname); - free(sysdirname); - } - - if ((xf86configptr = xf86readConfigFile()) == NULL) { - xf86Msg(X_ERROR, "Problem parsing the config file\n"); - return CONFIG_PARSE_ERROR; - } - xf86closeConfigFile(); - - /* Initialise a few things. */ - - /* - * now we convert part of the information contained in the parser - * structures into our own structures. - * The important part here is to figure out which Screen Sections - * in the XF86Config file are active so that we can piece together - * the modes that we need later down the road. - * And while we are at it, we'll decode the rest of the stuff as well - */ - - /* First check if a layout section is present, and if it is valid. */ - FIND_SUITABLE(XF86ConfLayoutPtr, xf86configptr->conf_layout_lst, layout); - if (layout == NULL || xf86ScreenName != NULL) { - XF86ConfScreenPtr screen; - - if (xf86ScreenName == NULL) { - xf86Msg(X_DEFAULT, - "No Layout section. Using the first Screen section.\n"); - } - FIND_SUITABLE (XF86ConfScreenPtr, xf86configptr->conf_screen_lst, screen); - if (!configImpliedLayout(&xf86ConfigLayout, - screen, - xf86configptr)) { - xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); - return CONFIG_PARSE_ERROR; - } - implicit_layout = TRUE; - } - else { - if (xf86configptr->conf_flags != NULL) { - char *dfltlayout = NULL; - void *optlist = xf86configptr->conf_flags->flg_option_lst; - - if (optlist && xf86FindOption(optlist, "defaultserverlayout")) - dfltlayout = - xf86SetStrOption(optlist, "defaultserverlayout", NULL); - if (!configLayout(&xf86ConfigLayout, layout, dfltlayout)) { - xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); - return CONFIG_PARSE_ERROR; - } - } - else { - if (!configLayout(&xf86ConfigLayout, layout, NULL)) { - xf86Msg(X_ERROR, "Unable to determine the screen layout\n"); - return CONFIG_PARSE_ERROR; - } - } - } - - xf86ProcessOptions(-1, xf86ConfigLayout.options, LayoutOptions); -#ifdef XSERVER_LIBPCIACCESS - if ((scanptr = xf86GetOptValString(LayoutOptions, LAYOUT_ISOLATEDEVICE))) { - ; /* IsolateDevice specified; overrides SingleCard */ - } - else { - xf86GetOptValBool(LayoutOptions, LAYOUT_SINGLECARD, &singlecard); - if (singlecard) - scanptr = xf86ConfigLayout.screens->screen->device->busID; - } - if (scanptr) { - if (strncmp(scanptr, "PCI:", 4) != 0) { - xf86Msg(X_WARNING, "Bus types other than PCI not yet isolable.\n" - "\tIgnoring IsolateDevice option.\n"); - } - else - xf86PciIsolateDevice(scanptr); - } -#endif - /* Now process everything else */ - configServerFlags(xf86configptr->conf_flags, xf86ConfigLayout.options); - configFiles(xf86configptr->conf_files); - configExtensions(xf86configptr->conf_extensions); - configDRI(xf86configptr->conf_dri); - - checkInput(&xf86ConfigLayout, implicit_layout); - - /* - * Handle some command line options that can override some of the - * ServerFlags settings. - */ -#ifdef XF86VIDMODE - if (xf86VidModeDisabled) - xf86Info.vidModeEnabled = FALSE; - if (xf86VidModeAllowNonLocal) - xf86Info.vidModeAllowNonLocal = TRUE; -#endif - - if (xf86AllowMouseOpenFail) - xf86Info.allowMouseOpenFail = TRUE; - - return CONFIG_OK; -} - -Bool -xf86PathIsSafe(const char *path) -{ - return (xf86pathIsSafe(path) != 0); -} diff --git a/hw/xfree86/common/xf86Config.h b/hw/xfree86/common/xf86Config.h deleted file mode 100644 index bbcb252ed..000000000 --- a/hw/xfree86/common/xf86Config.h +++ /dev/null @@ -1,71 +0,0 @@ - -/* - * Copyright (c) 1997-2000 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _xf86_config_h -#define _xf86_config_h - -#include "xf86Optrec.h" -#include "xf86Parser.h" -#include "xf86str.h" - -#ifdef HAVE_PARSER_DECLS -/* - * global structure that holds the result of parsing the config file - */ -extern _X_EXPORT XF86ConfigPtr xf86configptr; -#endif - -typedef enum _ConfigStatus { - CONFIG_OK = 0, - CONFIG_PARSE_ERROR, - CONFIG_NOFILE -} ConfigStatus; - -typedef struct _ModuleDefault { - const char *name; - Bool toLoad; - XF86OptionPtr load_opt; -} ModuleDefault; - -/* - * prototypes - */ -const char **xf86ModulelistFromConfig(void ***); -const char **xf86DriverlistFromConfig(void); -const char **xf86InputDriverlistFromConfig(void); -Bool xf86BuiltinInputDriver(const char *); -ConfigStatus xf86HandleConfigFile(Bool); - -Bool xf86AutoConfig(void); -GDevPtr autoConfigDevice(GDevPtr preconf_device); - -#endif /* _xf86_config_h */ diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c deleted file mode 100644 index 4347f6d2f..000000000 --- a/hw/xfree86/common/xf86Configure.c +++ /dev/null @@ -1,881 +0,0 @@ -/* - * Copyright 2000-2002 by Alan Hourihane, Flint Mountain, North Wales. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Alan Hourihane not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Alan Hourihane makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Author: Alan Hourihane, alanh@fairlite.demon.co.uk - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86Config.h" -#include "xf86_OSlib.h" -#include "xf86Priv.h" -#define IN_XSERVER -#include "Configint.h" -#include "xf86DDC.h" -#include "xf86pciBus.h" -#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) -#include "xf86Bus.h" -#include "xf86Sbus.h" -#endif -#include "misc.h" -#include "loaderProcs.h" - -typedef struct _DevToConfig { - GDevRec GDev; - struct pci_device *pVideo; -#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) - sbusDevicePtr sVideo; -#endif - int iDriver; -} DevToConfigRec, *DevToConfigPtr; - -static DevToConfigPtr DevToConfig = NULL; -static int nDevToConfig = 0, CurrentDriver; - -xf86MonPtr ConfiguredMonitor; -Bool xf86DoConfigurePass1 = TRUE; -static Bool foundMouse = FALSE; - -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) -static const char *DFLT_MOUSE_DEV = "/dev/sysmouse"; -static const char *DFLT_MOUSE_PROTO = "auto"; -#elif defined(__linux__) -static const char *DFLT_MOUSE_DEV = "/dev/input/mice"; -static const char *DFLT_MOUSE_PROTO = "auto"; -#elif defined(WSCONS_SUPPORT) -static const char *DFLT_MOUSE_DEV = "/dev/wsmouse"; -static const char *DFLT_MOUSE_PROTO = "wsmouse"; -#else -static const char *DFLT_MOUSE_DEV = "/dev/mouse"; -static const char *DFLT_MOUSE_PROTO = "auto"; -#endif - -/* - * This is called by the driver, either through xf86Match???Instances() or - * directly. We allocate a GDevRec and fill it in as much as we can, letting - * the caller fill in the rest and/or change it as it sees fit. - */ -GDevPtr -xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, - int chipset) -{ - int ret, i, j; - char *lower_driver; - - if (!xf86DoConfigure || !xf86DoConfigurePass1) - return NULL; - - /* Check for duplicates */ - for (i = 0; i < nDevToConfig; i++) { - switch (bus) { -#ifdef XSERVER_LIBPCIACCESS - case BUS_PCI: - ret = xf86PciConfigure(busData, DevToConfig[i].pVideo); - break; -#endif -#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) - case BUS_SBUS: - ret = xf86SbusConfigure(busData, DevToConfig[i].sVideo); - break; -#endif - default: - return NULL; - } - if (ret == 0) - goto out; - } - - /* Allocate new structure occurrence */ - i = nDevToConfig++; - DevToConfig = - xnfreallocarray(DevToConfig, nDevToConfig, sizeof(DevToConfigRec)); - memset(DevToConfig + i, 0, sizeof(DevToConfigRec)); - - DevToConfig[i].GDev.chipID = - DevToConfig[i].GDev.chipRev = DevToConfig[i].GDev.irq = -1; - - DevToConfig[i].iDriver = CurrentDriver; - - /* Fill in what we know, converting the driver name to lower case */ - lower_driver = xnfalloc(strlen(driver) + 1); - for (j = 0; (lower_driver[j] = tolower(driver[j])); j++); - DevToConfig[i].GDev.driver = lower_driver; - - switch (bus) { -#ifdef XSERVER_LIBPCIACCESS - case BUS_PCI: - DevToConfig[i].pVideo = busData; - xf86PciConfigureNewDev(busData, DevToConfig[i].pVideo, - &DevToConfig[i].GDev, &chipset); - break; -#endif -#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) - case BUS_SBUS: - DevToConfig[i].sVideo = busData; - xf86SbusConfigureNewDev(busData, DevToConfig[i].sVideo, - &DevToConfig[i].GDev); - break; -#endif - default: - break; - } - - /* Get driver's available options */ - if (xf86DriverList[CurrentDriver]->AvailableOptions) - DevToConfig[i].GDev.options = (OptionInfoPtr) - (*xf86DriverList[CurrentDriver]->AvailableOptions) (chipset, bus); - - return &DevToConfig[i].GDev; - - out: - return NULL; -} - -static XF86ConfInputPtr -configureInputSection(void) -{ - XF86ConfInputPtr mouse = NULL; - - parsePrologue(XF86ConfInputPtr, XF86ConfInputRec); - - ptr->inp_identifier = xnfstrdup("Keyboard0"); - ptr->inp_driver = xnfstrdup("kbd"); - ptr->list.next = NULL; - - /* Crude mechanism to auto-detect mouse (os dependent) */ - { - int fd; - - fd = open(DFLT_MOUSE_DEV, 0); - if (fd != -1) { - foundMouse = TRUE; - close(fd); - } - } - - mouse = calloc(1, sizeof(XF86ConfInputRec)); - mouse->inp_identifier = xnfstrdup("Mouse0"); - mouse->inp_driver = xnfstrdup("mouse"); - mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, xnfstrdup("Protocol"), - xnfstrdup(DFLT_MOUSE_PROTO)); - mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, xnfstrdup("Device"), - xnfstrdup(DFLT_MOUSE_DEV)); - mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, xnfstrdup("ZAxisMapping"), - xnfstrdup("4 5 6 7")); - ptr = (XF86ConfInputPtr) xf86addListItem((glp) ptr, (glp) mouse); - return ptr; -} - -static XF86ConfScreenPtr -configureScreenSection(int screennum) -{ - int i; - int depths[] = { 1, 4, 8, 15, 16, 24 /*, 32 */ }; - char *tmp; - parsePrologue(XF86ConfScreenPtr, XF86ConfScreenRec); - - XNFasprintf(&tmp, "Screen%d", screennum); - ptr->scrn_identifier = tmp; - XNFasprintf(&tmp, "Monitor%d", screennum); - ptr->scrn_monitor_str = tmp; - XNFasprintf(&tmp, "Card%d", screennum); - ptr->scrn_device_str = tmp; - - for (i = 0; i < ARRAY_SIZE(depths); i++) { - XF86ConfDisplayPtr conf_display; - - conf_display = calloc(1, sizeof(XF86ConfDisplayRec)); - conf_display->disp_depth = depths[i]; - conf_display->disp_black.red = conf_display->disp_white.red = -1; - conf_display->disp_black.green = conf_display->disp_white.green = -1; - conf_display->disp_black.blue = conf_display->disp_white.blue = -1; - ptr->scrn_display_lst = (XF86ConfDisplayPtr) xf86addListItem((glp) ptr-> - scrn_display_lst, - (glp) - conf_display); - } - - return ptr; -} - -static const char * -optionTypeToString(OptionValueType type) -{ - switch (type) { - case OPTV_NONE: - return ""; - case OPTV_INTEGER: - return ""; - case OPTV_STRING: - return ""; - case OPTV_ANYSTR: - return "[]"; - case OPTV_REAL: - return ""; - case OPTV_BOOLEAN: - return "[]"; - case OPTV_FREQ: - return ""; - case OPTV_PERCENT: - return ""; - default: - return ""; - } -} - -static XF86ConfDevicePtr -configureDeviceSection(int screennum) -{ - OptionInfoPtr p; - int i = 0; - char *identifier; - - parsePrologue(XF86ConfDevicePtr, XF86ConfDeviceRec); - - /* Move device info to parser structure */ - if (asprintf(&identifier, "Card%d", screennum) == -1) - identifier = NULL; - ptr->dev_identifier = identifier; - ptr->dev_chipset = DevToConfig[screennum].GDev.chipset; - ptr->dev_busid = DevToConfig[screennum].GDev.busID; - ptr->dev_driver = DevToConfig[screennum].GDev.driver; - ptr->dev_ramdac = DevToConfig[screennum].GDev.ramdac; - for (i = 0; i < MAXDACSPEEDS; i++) - ptr->dev_dacSpeeds[i] = DevToConfig[screennum].GDev.dacSpeeds[i]; - ptr->dev_videoram = DevToConfig[screennum].GDev.videoRam; - ptr->dev_mem_base = DevToConfig[screennum].GDev.MemBase; - ptr->dev_io_base = DevToConfig[screennum].GDev.IOBase; - ptr->dev_clockchip = DevToConfig[screennum].GDev.clockchip; - for (i = 0; (i < MAXCLOCKS) && (i < DevToConfig[screennum].GDev.numclocks); - i++) - ptr->dev_clock[i] = DevToConfig[screennum].GDev.clock[i]; - ptr->dev_clocks = i; - ptr->dev_chipid = DevToConfig[screennum].GDev.chipID; - ptr->dev_chiprev = DevToConfig[screennum].GDev.chipRev; - ptr->dev_irq = DevToConfig[screennum].GDev.irq; - - /* Make sure older drivers don't segv */ - if (DevToConfig[screennum].GDev.options) { - /* Fill in the available driver options for people to use */ - const char *descrip = - " ### Available Driver options are:-\n" - " ### Values: : integer, : float, " - ": \"True\"/\"False\",\n" - " ### : \"String\", : \" Hz/kHz/MHz\",\n" - " ### : \"%\"\n" - " ### [arg]: arg optional\n"; - ptr->dev_comment = xnfstrdup(descrip); - if (ptr->dev_comment) { - for (p = DevToConfig[screennum].GDev.options; p->name != NULL; p++) { - char *p_e; - const char *prefix = " #Option "; - const char *middle = " \t# "; - const char *suffix = "\n"; - const char *opttype = optionTypeToString(p->type); - char *optname; - int len = strlen(ptr->dev_comment) + strlen(prefix) + - strlen(middle) + strlen(suffix) + 1; - - if (asprintf(&optname, "\"%s\"", p->name) == -1) - break; - - len += max(20, strlen(optname)); - len += strlen(opttype); - - ptr->dev_comment = realloc(ptr->dev_comment, len); - if (!ptr->dev_comment) - break; - p_e = ptr->dev_comment + strlen(ptr->dev_comment); - sprintf(p_e, "%s%-20s%s%s%s", prefix, optname, middle, - opttype, suffix); - free(optname); - } - } - } - - return ptr; -} - -static XF86ConfLayoutPtr -configureLayoutSection(void) -{ - int scrnum = 0; - - parsePrologue(XF86ConfLayoutPtr, XF86ConfLayoutRec); - - ptr->lay_identifier = "X.org Configured"; - - { - XF86ConfInputrefPtr iptr; - - iptr = malloc(sizeof(XF86ConfInputrefRec)); - iptr->list.next = NULL; - iptr->iref_option_lst = NULL; - iptr->iref_inputdev_str = xnfstrdup("Mouse0"); - iptr->iref_option_lst = - xf86addNewOption(iptr->iref_option_lst, xnfstrdup("CorePointer"), - NULL); - ptr->lay_input_lst = (XF86ConfInputrefPtr) - xf86addListItem((glp) ptr->lay_input_lst, (glp) iptr); - } - - { - XF86ConfInputrefPtr iptr; - - iptr = malloc(sizeof(XF86ConfInputrefRec)); - iptr->list.next = NULL; - iptr->iref_option_lst = NULL; - iptr->iref_inputdev_str = xnfstrdup("Keyboard0"); - iptr->iref_option_lst = - xf86addNewOption(iptr->iref_option_lst, xnfstrdup("CoreKeyboard"), - NULL); - ptr->lay_input_lst = (XF86ConfInputrefPtr) - xf86addListItem((glp) ptr->lay_input_lst, (glp) iptr); - } - - for (scrnum = 0; scrnum < nDevToConfig; scrnum++) { - XF86ConfAdjacencyPtr aptr; - char *tmp; - - aptr = malloc(sizeof(XF86ConfAdjacencyRec)); - aptr->list.next = NULL; - aptr->adj_x = 0; - aptr->adj_y = 0; - aptr->adj_scrnum = scrnum; - XNFasprintf(&tmp, "Screen%d", scrnum); - aptr->adj_screen_str = tmp; - if (scrnum == 0) { - aptr->adj_where = CONF_ADJ_ABSOLUTE; - aptr->adj_refscreen = NULL; - } - else { - aptr->adj_where = CONF_ADJ_RIGHTOF; - XNFasprintf(&tmp, "Screen%d", scrnum - 1); - aptr->adj_refscreen = tmp; - } - ptr->lay_adjacency_lst = - (XF86ConfAdjacencyPtr) xf86addListItem((glp) ptr->lay_adjacency_lst, - (glp) aptr); - } - - return ptr; -} - -static XF86ConfFlagsPtr -configureFlagsSection(void) -{ - parsePrologue(XF86ConfFlagsPtr, XF86ConfFlagsRec); - - return ptr; -} - -static XF86ConfModulePtr -configureModuleSection(void) -{ - const char **elist, **el; - - parsePrologue(XF86ConfModulePtr, XF86ConfModuleRec); - - elist = LoaderListDir("extensions", NULL); - if (elist) { - for (el = elist; *el; el++) { - XF86LoadPtr module; - - module = calloc(1, sizeof(XF86LoadRec)); - module->load_name = *el; - ptr->mod_load_lst = (XF86LoadPtr) xf86addListItem((glp) ptr-> - mod_load_lst, - (glp) module); - } - free(elist); - } - - return ptr; -} - -static XF86ConfFilesPtr -configureFilesSection(void) -{ - parsePrologue(XF86ConfFilesPtr, XF86ConfFilesRec); - - if (xf86ModulePath) - ptr->file_modulepath = xnfstrdup(xf86ModulePath); - if (defaultFontPath) - ptr->file_fontpath = xnfstrdup(defaultFontPath); - - return ptr; -} - -static XF86ConfMonitorPtr -configureMonitorSection(int screennum) -{ - char *tmp; - parsePrologue(XF86ConfMonitorPtr, XF86ConfMonitorRec); - - XNFasprintf(&tmp, "Monitor%d", screennum); - ptr->mon_identifier = tmp; - ptr->mon_vendor = xnfstrdup("Monitor Vendor"); - ptr->mon_modelname = xnfstrdup("Monitor Model"); - - return ptr; -} - -/* Initialize Configure Monitor from Detailed Timing Block */ -static void -handle_detailed_input(struct detailed_monitor_section *det_mon, void *data) -{ - XF86ConfMonitorPtr ptr = (XF86ConfMonitorPtr) data; - - switch (det_mon->type) { - case DS_NAME: - ptr->mon_modelname = realloc(ptr->mon_modelname, - strlen((char *) (det_mon->section.name)) + - 1); - strcpy(ptr->mon_modelname, (char *) (det_mon->section.name)); - break; - case DS_RANGES: - ptr->mon_hsync[ptr->mon_n_hsync].lo = det_mon->section.ranges.min_h; - ptr->mon_hsync[ptr->mon_n_hsync].hi = det_mon->section.ranges.max_h; - ptr->mon_n_vrefresh = 1; - ptr->mon_vrefresh[ptr->mon_n_hsync].lo = det_mon->section.ranges.min_v; - ptr->mon_vrefresh[ptr->mon_n_hsync].hi = det_mon->section.ranges.max_v; - ptr->mon_n_hsync++; - default: - break; - } -} - -static XF86ConfMonitorPtr -configureDDCMonitorSection(int screennum) -{ - int len, mon_width, mon_height; - -#define displaySizeMaxLen 80 - char displaySize_string[displaySizeMaxLen]; - int displaySizeLen; - char *tmp; - - parsePrologue(XF86ConfMonitorPtr, XF86ConfMonitorRec); - - XNFasprintf(&tmp, "Monitor%d", screennum); - ptr->mon_identifier = tmp; - ptr->mon_vendor = xnfstrdup(ConfiguredMonitor->vendor.name); - XNFasprintf(&ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id); - - /* features in centimetres, we want millimetres */ - mon_width = 10 * ConfiguredMonitor->features.hsize; - mon_height = 10 * ConfiguredMonitor->features.vsize; - -#ifdef CONFIGURE_DISPLAYSIZE - ptr->mon_width = mon_width; - ptr->mon_height = mon_height; -#else - if (mon_width && mon_height) { - /* when values available add DisplaySize option AS A COMMENT */ - - displaySizeLen = snprintf(displaySize_string, displaySizeMaxLen, - "\t#DisplaySize\t%5d %5d\t# mm\n", - mon_width, mon_height); - - if (displaySizeLen > 0 && displaySizeLen < displaySizeMaxLen) { - if (ptr->mon_comment) { - len = strlen(ptr->mon_comment); - } - else { - len = 0; - } - if ((ptr->mon_comment = - realloc(ptr->mon_comment, - len + strlen(displaySize_string) + 1))) { - strcpy(ptr->mon_comment + len, displaySize_string); - } - } - } -#endif /* def CONFIGURE_DISPLAYSIZE */ - - xf86ForEachDetailedBlock(ConfiguredMonitor, handle_detailed_input, ptr); - - if (ConfiguredMonitor->features.dpms) { - ptr->mon_option_lst = - xf86addNewOption(ptr->mon_option_lst, xnfstrdup("DPMS"), NULL); - } - - return ptr; -} - -static int -is_fallback(const char *s) -{ - /* later entries are less preferred */ - const char *fallback[5] = { "modesetting", "fbdev", "vesa", "wsfb", NULL }; - int i; - - for (i = 0; fallback[i]; i++) - if (strstr(s, fallback[i])) - return i; - - return -1; -} - -static int -driver_sort(const void *_l, const void *_r) -{ - const char *l = *(const char **)_l; - const char *r = *(const char **)_r; - int left = is_fallback(l); - int right = is_fallback(r); - - /* neither is a fallback, asciibetize */ - if (left == -1 && right == -1) - return strcmp(l, r); - - /* left is a fallback, right is not */ - if (left >= 0 && right == -1) - return 1; - - /* right is a fallback, left is not */ - if (right >= 0 && left == -1) - return -1; - - /* both are fallbacks, decide which is worse */ - return left - right; -} - -static void -fixup_video_driver_list(const char **drivers) -{ - const char **end; - - /* walk to the end of the list */ - for (end = drivers; *end && **end; end++); - - qsort(drivers, end - drivers, sizeof(const char *), driver_sort); -} - -static const char ** -GenerateDriverList(void) -{ - const char **ret; - static const char *patlist[] = { "(.*)_drv\\.so", NULL }; - ret = LoaderListDir("drivers", patlist); - - /* fix up the probe order for video drivers */ - if (ret != NULL) - fixup_video_driver_list(ret); - - return ret; -} - -void -DoConfigure(void) -{ - int i, j, screennum = -1; - const char *home = NULL; - char filename[PATH_MAX]; - const char *addslash = ""; - XF86ConfigPtr xf86config = NULL; - const char **vlist, **vl; - int *dev2screen; - - vlist = GenerateDriverList(); - - if (!vlist) { - ErrorF("Missing output drivers. Configuration failed.\n"); - goto bail; - } - - ErrorF("List of video drivers:\n"); - for (vl = vlist; *vl; vl++) - ErrorF("\t%s\n", *vl); - - /* Load all the drivers that were found. */ - xf86LoadModules(vlist, NULL); - - free(vlist); - - xorgHWAccess = xf86EnableIO(); - - /* Create XF86Config file structure */ - xf86config = calloc(1, sizeof(XF86ConfigRec)); - - /* Call all of the probe functions, reporting the results. */ - for (CurrentDriver = 0; CurrentDriver < xf86NumDrivers; CurrentDriver++) { - Bool found_screen; - DriverRec *const drv = xf86DriverList[CurrentDriver]; - - found_screen = xf86CallDriverProbe(drv, TRUE); - if (found_screen && drv->Identify) { - (*drv->Identify) (0); - } - } - - if (nDevToConfig <= 0) { - ErrorF("No devices to configure. Configuration failed.\n"); - goto bail; - } - - /* Add device, monitor and screen sections for detected devices */ - for (screennum = 0; screennum < nDevToConfig; screennum++) { - XF86ConfDevicePtr device_ptr; - XF86ConfMonitorPtr monitor_ptr; - XF86ConfScreenPtr screen_ptr; - - device_ptr = configureDeviceSection(screennum); - xf86config->conf_device_lst = (XF86ConfDevicePtr) xf86addListItem((glp) - xf86config-> - conf_device_lst, - (glp) - device_ptr); - monitor_ptr = configureMonitorSection(screennum); - xf86config->conf_monitor_lst = (XF86ConfMonitorPtr) xf86addListItem((glp) xf86config->conf_monitor_lst, (glp) monitor_ptr); - screen_ptr = configureScreenSection(screennum); - xf86config->conf_screen_lst = (XF86ConfScreenPtr) xf86addListItem((glp) - xf86config-> - conf_screen_lst, - (glp) - screen_ptr); - } - - xf86config->conf_files = configureFilesSection(); - xf86config->conf_modules = configureModuleSection(); - xf86config->conf_flags = configureFlagsSection(); - xf86config->conf_videoadaptor_lst = NULL; - xf86config->conf_modes_lst = NULL; - xf86config->conf_vendor_lst = NULL; - xf86config->conf_dri = NULL; - xf86config->conf_input_lst = configureInputSection(); - xf86config->conf_layout_lst = configureLayoutSection(); - - home = getenv("HOME"); - if ((home == NULL) || (home[0] == '\0')) { - home = "/"; - } - else { - /* Determine if trailing slash is present or needed */ - int l = strlen(home); - - if (home[l - 1] != '/') { - addslash = "/"; - } - } - - snprintf(filename, sizeof(filename), "%s%s" XF86CONFIGFILE ".new", - home, addslash); - - if (xf86writeConfigFile(filename, xf86config) == 0) { - xf86Msg(X_ERROR, "Unable to write config file: \"%s\": %s\n", - filename, strerror(errno)); - goto bail; - } - - xf86DoConfigurePass1 = FALSE; - /* Try to get DDC information filled in */ - xf86ConfigFile = filename; - if (xf86HandleConfigFile(FALSE) != CONFIG_OK) { - goto bail; - } - - xf86DoConfigurePass1 = FALSE; - - dev2screen = xnfcalloc(nDevToConfig, sizeof(int)); - - { - Bool *driverProbed = xnfcalloc(xf86NumDrivers, sizeof(Bool)); - - for (screennum = 0; screennum < nDevToConfig; screennum++) { - int k, l, n, oldNumScreens; - - i = DevToConfig[screennum].iDriver; - - if (driverProbed[i]) - continue; - driverProbed[i] = TRUE; - - oldNumScreens = xf86NumScreens; - - xf86CallDriverProbe(xf86DriverList[i], FALSE); - - /* reorder */ - k = screennum > 0 ? screennum : 1; - for (l = oldNumScreens; l < xf86NumScreens; l++) { - /* is screen primary? */ - Bool primary = FALSE; - - for (n = 0; n < xf86Screens[l]->numEntities; n++) { - if (xf86IsEntityPrimary(xf86Screens[l]->entityList[n])) { - dev2screen[0] = l; - primary = TRUE; - break; - } - } - if (primary) - continue; - /* not primary: assign it to next device of same driver */ - /* - * NOTE: we assume that devices in DevToConfig - * and xf86Screens[] have the same order except - * for the primary device which always comes first. - */ - for (; k < nDevToConfig; k++) { - if (DevToConfig[k].iDriver == i) { - dev2screen[k++] = l; - break; - } - } - } - } - free(driverProbed); - } - - if (nDevToConfig != xf86NumScreens) { - ErrorF("Number of created screens does not match number of detected" - " devices.\n Configuration failed.\n"); - goto bail; - } - - xf86PostProbe(); - - for (j = 0; j < xf86NumScreens; j++) { - xf86Screens[j]->scrnIndex = j; - } - - xf86freeMonitorList(xf86config->conf_monitor_lst); - xf86config->conf_monitor_lst = NULL; - xf86freeScreenList(xf86config->conf_screen_lst); - xf86config->conf_screen_lst = NULL; - for (j = 0; j < xf86NumScreens; j++) { - XF86ConfMonitorPtr monitor_ptr; - XF86ConfScreenPtr screen_ptr; - - ConfiguredMonitor = NULL; - - if ((*xf86Screens[dev2screen[j]]->PreInit) && - (*xf86Screens[dev2screen[j]]->PreInit) (xf86Screens[dev2screen[j]], - PROBE_DETECT) && - ConfiguredMonitor) { - monitor_ptr = configureDDCMonitorSection(j); - } - else { - monitor_ptr = configureMonitorSection(j); - } - screen_ptr = configureScreenSection(j); - - xf86config->conf_monitor_lst = (XF86ConfMonitorPtr) xf86addListItem((glp) xf86config->conf_monitor_lst, (glp) monitor_ptr); - xf86config->conf_screen_lst = (XF86ConfScreenPtr) xf86addListItem((glp) - xf86config-> - conf_screen_lst, - (glp) - screen_ptr); - } - - if (xf86writeConfigFile(filename, xf86config) == 0) { - xf86Msg(X_ERROR, "Unable to write config file: \"%s\": %s\n", - filename, strerror(errno)); - goto bail; - } - - ErrorF("\n"); - - if (!foundMouse) { - ErrorF("\n" __XSERVERNAME__ " is not able to detect your mouse.\n" - "Edit the file and correct the Device.\n"); - } - else { - ErrorF("\n" __XSERVERNAME__ " detected your mouse at device %s.\n" - "Please check your config if the mouse is still not\n" - "operational, as by default " __XSERVERNAME__ - " tries to autodetect\n" "the protocol.\n", DFLT_MOUSE_DEV); - } - - if (xf86NumScreens > 1) { - ErrorF("\n" __XSERVERNAME__ - " has configured a multihead system, please check your config.\n"); - } - - ErrorF("\nYour %s file is %s\n\n", XF86CONFIGFILE, filename); - ErrorF("To test the server, run 'X -config %s'\n\n", filename); - - bail: - OsCleanup(TRUE); - ddxGiveUp(EXIT_ERR_CONFIGURE); - fflush(stderr); - exit(0); -} - -/* Xorg -showopts: - * For each driver module installed, print out the list - * of options and their argument types, then exit - * - * Author: Marcus Schaefer, ms@suse.de - */ - -void -DoShowOptions(void) -{ - int i = 0; - const char **vlist = NULL; - char *pSymbol = 0; - XF86ModuleData *initData = 0; - - if (!(vlist = GenerateDriverList())) { - ErrorF("Missing output drivers\n"); - goto bail; - } - xf86LoadModules(vlist, 0); - free(vlist); - for (i = 0; i < xf86NumDrivers; i++) { - if (xf86DriverList[i]->AvailableOptions) { - const OptionInfoRec *pOption = - (*xf86DriverList[i]->AvailableOptions) (0, 0); - if (!pOption) { - ErrorF("(EE) Couldn't read option table for %s driver\n", - xf86DriverList[i]->driverName); - continue; - } - XNFasprintf(&pSymbol, "%sModuleData", - xf86DriverList[i]->driverName); - initData = LoaderSymbol(pSymbol); - if (initData) { - XF86ModuleVersionInfo *vers = initData->vers; - const OptionInfoRec *p; - - ErrorF("Driver[%d]:%s[%s] {\n", - i, xf86DriverList[i]->driverName, vers->vendor); - for (p = pOption; p->name != NULL; p++) { - ErrorF("\t%s:%s\n", p->name, optionTypeToString(p->type)); - } - ErrorF("}\n"); - } - } - } - bail: - OsCleanup(TRUE); - ddxGiveUp(EXIT_ERR_DRIVERS); - fflush(stderr); - exit(0); -} diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c deleted file mode 100644 index 8bb68a56f..000000000 --- a/hw/xfree86/common/xf86Cursor.c +++ /dev/null @@ -1,858 +0,0 @@ -/* - * Copyright (c) 1994-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include "input.h" -#include "cursor.h" -#include "mipointer.h" -#include "scrnintstr.h" -#include "globals.h" - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSproc.h" - -#include -#include "xf86Xinput.h" - -#ifdef XFreeXDGA -#include "dgaproc.h" -#endif - -typedef struct _xf86EdgeRec { - short screen; - short start; - short end; - DDXPointRec offset; - struct _xf86EdgeRec *next; -} xf86EdgeRec, *xf86EdgePtr; - -typedef struct { - xf86EdgePtr left, right, up, down; -} xf86ScreenLayoutRec, *xf86ScreenLayoutPtr; - -static Bool xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y); -static void xf86CrossScreen(ScreenPtr pScreen, Bool entering); -static void xf86WarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y); - -static void xf86PointerMoved(ScrnInfoPtr pScrn, int x, int y); - -static miPointerScreenFuncRec xf86PointerScreenFuncs = { - xf86CursorOffScreen, - xf86CrossScreen, - xf86WarpCursor, -}; - -static xf86ScreenLayoutRec xf86ScreenLayout[MAXSCREENS]; - -/* - * xf86InitViewport -- - * Initialize paning & zooming parameters, so that a driver must only - * check what resolutions are possible and whether the virtual area - * is valid if specified. - */ - -void -xf86InitViewport(ScrnInfoPtr pScr) -{ - - pScr->PointerMoved = xf86PointerMoved; - - /* - * Compute the initial Viewport if necessary - */ - if (pScr->display) { - if (pScr->display->frameX0 < 0) { - pScr->frameX0 = (pScr->virtualX - pScr->modes->HDisplay) / 2; - pScr->frameY0 = (pScr->virtualY - pScr->modes->VDisplay) / 2; - } - else { - pScr->frameX0 = pScr->display->frameX0; - pScr->frameY0 = pScr->display->frameY0; - } - } - - pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1; - pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1; - - /* - * Now adjust the initial Viewport, so it lies within the virtual area - */ - if (pScr->frameX1 >= pScr->virtualX) { - pScr->frameX0 = pScr->virtualX - pScr->modes->HDisplay; - pScr->frameX1 = pScr->frameX0 + pScr->modes->HDisplay - 1; - } - - if (pScr->frameY1 >= pScr->virtualY) { - pScr->frameY0 = pScr->virtualY - pScr->modes->VDisplay; - pScr->frameY1 = pScr->frameY0 + pScr->modes->VDisplay - 1; - } -} - -/* - * xf86SetViewport -- - * Scroll the visual part of the screen so the pointer is visible. - */ - -void -xf86SetViewport(ScreenPtr pScreen, int x, int y) -{ - ScrnInfoPtr pScr = xf86ScreenToScrn(pScreen); - - (*pScr->PointerMoved) (pScr, x, y); -} - -static void -xf86PointerMoved(ScrnInfoPtr pScr, int x, int y) -{ - Bool frameChanged = FALSE; - - /* - * check whether (x,y) belongs to the visual part of the screen - * if not, change the base of the displayed frame occurring - */ - if (pScr->frameX0 > x) { - pScr->frameX0 = x; - pScr->frameX1 = x + pScr->currentMode->HDisplay - 1; - frameChanged = TRUE; - } - - if (pScr->frameX1 < x) { - pScr->frameX1 = x + 1; - pScr->frameX0 = x - pScr->currentMode->HDisplay + 1; - frameChanged = TRUE; - } - - if (pScr->frameY0 > y) { - pScr->frameY0 = y; - pScr->frameY1 = y + pScr->currentMode->VDisplay - 1; - frameChanged = TRUE; - } - - if (pScr->frameY1 < y) { - pScr->frameY1 = y; - pScr->frameY0 = y - pScr->currentMode->VDisplay + 1; - frameChanged = TRUE; - } - - if (frameChanged && pScr->AdjustFrame != NULL) - pScr->AdjustFrame(pScr, pScr->frameX0, pScr->frameY0); -} - -/* - * xf86LockZoom -- - * Enable/disable ZoomViewport - */ - -void -xf86LockZoom(ScreenPtr pScreen, Bool lock) -{ - ScrnInfoPtr pScr = xf86ScreenToScrn(pScreen); - pScr->zoomLocked = lock; -} - -/* - * xf86SwitchMode -- - * This is called by both keyboard processing and the VidMode extension to - * set a new mode. - */ - -Bool -xf86SwitchMode(ScreenPtr pScreen, DisplayModePtr mode) -{ - ScrnInfoPtr pScr = xf86ScreenToScrn(pScreen); - ScreenPtr pCursorScreen; - Bool Switched; - int px, py; - DeviceIntPtr dev, it; - - if (!pScr->vtSema || !mode || !pScr->SwitchMode) - return FALSE; - -#ifdef XFreeXDGA - if (DGAActive(pScr->scrnIndex)) - return FALSE; -#endif - - if (mode == pScr->currentMode) - return TRUE; - - if (mode->HDisplay > pScr->virtualX || mode->VDisplay > pScr->virtualY) - return FALSE; - - /* Let's take an educated guess for which pointer to take here. And about as - educated as it gets is to take the first pointer we find. - */ - for (dev = inputInfo.devices; dev; dev = dev->next) { - if (IsPointerDevice(dev) && dev->spriteInfo->spriteOwner) - break; - } - - pCursorScreen = miPointerGetScreen(dev); - if (pScreen == pCursorScreen) - miPointerGetPosition(dev, &px, &py); - - input_lock(); - Switched = (*pScr->SwitchMode) (pScr, mode); - if (Switched) { - pScr->currentMode = mode; - - /* - * Adjust frame for new display size. - * Frame is centered around cursor position if cursor is on same screen. - */ - if (pScreen == pCursorScreen) - pScr->frameX0 = px - (mode->HDisplay / 2) + 1; - else - pScr->frameX0 = - (pScr->frameX0 + pScr->frameX1 + 1 - mode->HDisplay) / 2; - - if (pScr->frameX0 < 0) - pScr->frameX0 = 0; - - pScr->frameX1 = pScr->frameX0 + mode->HDisplay - 1; - if (pScr->frameX1 >= pScr->virtualX) { - pScr->frameX0 = pScr->virtualX - mode->HDisplay; - pScr->frameX1 = pScr->virtualX - 1; - } - - if (pScreen == pCursorScreen) - pScr->frameY0 = py - (mode->VDisplay / 2) + 1; - else - pScr->frameY0 = - (pScr->frameY0 + pScr->frameY1 + 1 - mode->VDisplay) / 2; - - if (pScr->frameY0 < 0) - pScr->frameY0 = 0; - - pScr->frameY1 = pScr->frameY0 + mode->VDisplay - 1; - if (pScr->frameY1 >= pScr->virtualY) { - pScr->frameY0 = pScr->virtualY - mode->VDisplay; - pScr->frameY1 = pScr->virtualY - 1; - } - } - input_unlock(); - - if (pScr->AdjustFrame) - (*pScr->AdjustFrame) (pScr, pScr->frameX0, pScr->frameY0); - - /* The original code centered the frame around the cursor if possible. - * Since this is hard to achieve with multiple cursors, we do the following: - * - center around the first pointer - * - move all other pointers to the nearest edge on the screen (or leave - * them unmodified if they are within the boundaries). - */ - if (pScreen == pCursorScreen) { - xf86WarpCursor(dev, pScreen, px, py); - } - - for (it = inputInfo.devices; it; it = it->next) { - if (it == dev) - continue; - - if (IsPointerDevice(it) && it->spriteInfo->spriteOwner) { - pCursorScreen = miPointerGetScreen(it); - if (pScreen == pCursorScreen) { - miPointerGetPosition(it, &px, &py); - if (px < pScr->frameX0) - px = pScr->frameX0; - else if (px > pScr->frameX1) - px = pScr->frameX1; - - if (py < pScr->frameY0) - py = pScr->frameY0; - else if (py > pScr->frameY1) - py = pScr->frameY1; - - xf86WarpCursor(it, pScreen, px, py); - } - } - } - - return Switched; -} - -/* - * xf86ZoomViewport -- - * Reinitialize the visual part of the screen for another mode. - */ - -void -xf86ZoomViewport(ScreenPtr pScreen, int zoom) -{ - ScrnInfoPtr pScr = xf86ScreenToScrn(pScreen); - DisplayModePtr mode; - - if (pScr->zoomLocked || !(mode = pScr->currentMode)) - return; - - do { - if (zoom > 0) - mode = mode->next; - else - mode = mode->prev; - } while (mode != pScr->currentMode && !(mode->type & M_T_USERDEF)); - - (void) xf86SwitchMode(pScreen, mode); -} - -static xf86EdgePtr -FindEdge(xf86EdgePtr edge, int val) -{ - while (edge && (edge->end <= val)) - edge = edge->next; - - if (edge && (edge->start <= val)) - return edge; - - return NULL; -} - -/* - * xf86CursorOffScreen -- - * Check whether it is necessary to switch to another screen - */ - -static Bool -xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y) -{ - xf86EdgePtr edge; - int tmp; - - if (screenInfo.numScreens == 1) - return FALSE; - - if (*x < 0) { - tmp = *y; - if (tmp < 0) - tmp = 0; - if (tmp >= (*pScreen)->height) - tmp = (*pScreen)->height - 1; - - if ((edge = xf86ScreenLayout[(*pScreen)->myNum].left)) - edge = FindEdge(edge, tmp); - - if (!edge) - *x = 0; - else { - *x += edge->offset.x; - *y += edge->offset.y; - *pScreen = xf86Screens[edge->screen]->pScreen; - } - } - - if (*x >= (*pScreen)->width) { - tmp = *y; - if (tmp < 0) - tmp = 0; - if (tmp >= (*pScreen)->height) - tmp = (*pScreen)->height - 1; - - if ((edge = xf86ScreenLayout[(*pScreen)->myNum].right)) - edge = FindEdge(edge, tmp); - - if (!edge) - *x = (*pScreen)->width - 1; - else { - *x += edge->offset.x; - *y += edge->offset.y; - *pScreen = xf86Screens[edge->screen]->pScreen; - } - } - - if (*y < 0) { - tmp = *x; - if (tmp < 0) - tmp = 0; - if (tmp >= (*pScreen)->width) - tmp = (*pScreen)->width - 1; - - if ((edge = xf86ScreenLayout[(*pScreen)->myNum].up)) - edge = FindEdge(edge, tmp); - - if (!edge) - *y = 0; - else { - *x += edge->offset.x; - *y += edge->offset.y; - *pScreen = xf86Screens[edge->screen]->pScreen; - } - } - - if (*y >= (*pScreen)->height) { - tmp = *x; - if (tmp < 0) - tmp = 0; - if (tmp >= (*pScreen)->width) - tmp = (*pScreen)->width - 1; - - if ((edge = xf86ScreenLayout[(*pScreen)->myNum].down)) - edge = FindEdge(edge, tmp); - - if (!edge) - *y = (*pScreen)->height - 1; - else { - *x += edge->offset.x; - *y += edge->offset.y; - (*pScreen) = xf86Screens[edge->screen]->pScreen; - } - } - - return TRUE; -} - -/* - * xf86CrossScreen -- - * Switch to another screen - * - * Currently nothing special happens, but mi assumes the CrossScreen - * method exists. - */ - -static void -xf86CrossScreen(ScreenPtr pScreen, Bool entering) -{ -} - -/* - * xf86WarpCursor -- - * Warp possible to another screen - */ - -/* ARGSUSED */ -static void -xf86WarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) -{ - input_lock(); - miPointerWarpCursor(pDev, pScreen, x, y); - - xf86Info.currentScreen = pScreen; - input_unlock(); -} - -void * -xf86GetPointerScreenFuncs(void) -{ - return (void *) &xf86PointerScreenFuncs; -} - -static xf86EdgePtr -AddEdge(xf86EdgePtr edge, - short min, short max, short dx, short dy, short screen) -{ - xf86EdgePtr pEdge = edge, pPrev = NULL, pNew; - - while (1) { - while (pEdge && (min >= pEdge->end)) { - pPrev = pEdge; - pEdge = pEdge->next; - } - - if (!pEdge) { - if (!(pNew = malloc(sizeof(xf86EdgeRec)))) - break; - - pNew->screen = screen; - pNew->start = min; - pNew->end = max; - pNew->offset.x = dx; - pNew->offset.y = dy; - pNew->next = NULL; - - if (pPrev) - pPrev->next = pNew; - else - edge = pNew; - - break; - } - else if (min < pEdge->start) { - if (!(pNew = malloc(sizeof(xf86EdgeRec)))) - break; - - pNew->screen = screen; - pNew->start = min; - pNew->offset.x = dx; - pNew->offset.y = dy; - pNew->next = pEdge; - - if (pPrev) - pPrev->next = pNew; - else - edge = pNew; - - if (max <= pEdge->start) { - pNew->end = max; - break; - } - else { - pNew->end = pEdge->start; - min = pEdge->end; - } - } - else - min = pEdge->end; - - pPrev = pEdge; - pEdge = pEdge->next; - - if (max <= min) - break; - } - - return edge; -} - -static void -FillOutEdge(xf86EdgePtr pEdge, int limit) -{ - xf86EdgePtr pNext; - int diff; - - if (pEdge->start > 0) - pEdge->start = 0; - - while ((pNext = pEdge->next)) { - diff = pNext->start - pEdge->end; - if (diff > 0) { - pEdge->end += diff >> 1; - pNext->start -= diff - (diff >> 1); - } - pEdge = pNext; - } - - if (pEdge->end < limit) - pEdge->end = limit; -} - -/* - * xf86InitOrigins() can deal with a maximum of 32 screens - * on 32 bit architectures, 64 on 64 bit architectures. - */ - -void -xf86InitOrigins(void) -{ - unsigned long screensLeft, prevScreensLeft, mask; - screenLayoutPtr screen; - ScreenPtr pScreen, refScreen; - int x1, x2, y1, y2, left, right, top, bottom; - int i, j, ref, minX, minY, min, max; - xf86ScreenLayoutPtr pLayout; - Bool OldStyleConfig = FALSE; - - memset(xf86ScreenLayout, 0, MAXSCREENS * sizeof(xf86ScreenLayoutRec)); - - screensLeft = prevScreensLeft = (1 << xf86NumScreens) - 1; - - while (1) { - for (mask = screensLeft, i = 0; mask; mask >>= 1, i++) { - if (!(mask & 1L)) - continue; - - screen = &xf86ConfigLayout.screens[i]; - - if (screen->refscreen != NULL && - screen->refscreen->screennum >= xf86NumScreens) { - screensLeft &= ~(1 << i); - xf86Msg(X_WARNING, - "Not including screen \"%s\" in origins calculation.\n", - screen->screen->id); - continue; - } - - pScreen = xf86Screens[i]->pScreen; - switch (screen->where) { - case PosObsolete: - OldStyleConfig = TRUE; - pLayout = &xf86ScreenLayout[i]; - /* force edge lists */ - if (screen->left) { - ref = screen->left->screennum; - if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - pLayout->left = AddEdge(pLayout->left, - 0, pScreen->height, - xf86Screens[ref]->pScreen->width, 0, - ref); - } - if (screen->right) { - ref = screen->right->screennum; - if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - pLayout->right = AddEdge(pLayout->right, - 0, pScreen->height, - -pScreen->width, 0, ref); - } - if (screen->top) { - ref = screen->top->screennum; - if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - pLayout->up = AddEdge(pLayout->up, - 0, pScreen->width, - 0, xf86Screens[ref]->pScreen->height, - ref); - } - if (screen->bottom) { - ref = screen->bottom->screennum; - if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - pLayout->down = AddEdge(pLayout->down, - 0, pScreen->width, 0, - -pScreen->height, ref); - } - /* we could also try to place it based on those - relative locations if we wanted to */ - screen->x = screen->y = 0; - /* FALLTHROUGH */ - case PosAbsolute: - pScreen->x = screen->x; - pScreen->y = screen->y; - screensLeft &= ~(1 << i); - break; - case PosRelative: - ref = screen->refscreen->screennum; - if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if (screensLeft & (1 << ref)) - break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x + screen->x; - pScreen->y = refScreen->y + screen->y; - screensLeft &= ~(1 << i); - break; - case PosRightOf: - ref = screen->refscreen->screennum; - if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if (screensLeft & (1 << ref)) - break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x + refScreen->width; - pScreen->y = refScreen->y; - screensLeft &= ~(1 << i); - break; - case PosLeftOf: - ref = screen->refscreen->screennum; - if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if (screensLeft & (1 << ref)) - break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x - pScreen->width; - pScreen->y = refScreen->y; - screensLeft &= ~(1 << i); - break; - case PosBelow: - ref = screen->refscreen->screennum; - if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if (screensLeft & (1 << ref)) - break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x; - pScreen->y = refScreen->y + refScreen->height; - screensLeft &= ~(1 << i); - break; - case PosAbove: - ref = screen->refscreen->screennum; - if (!xf86Screens[ref] || !xf86Screens[ref]->pScreen) { - ErrorF("Referenced uninitialized screen in Layout!\n"); - break; - } - if (screensLeft & (1 << ref)) - break; - refScreen = xf86Screens[ref]->pScreen; - pScreen->x = refScreen->x; - pScreen->y = refScreen->y - pScreen->height; - screensLeft &= ~(1 << i); - break; - default: - ErrorF("Illegal placement keyword in Layout!\n"); - break; - } - - } - - if (!screensLeft) - break; - - if (screensLeft == prevScreensLeft) { - /* All the remaining screens are referencing each other. - Assign a value to one of them and go through again */ - i = 0; - while (!((1 << i) & screensLeft)) { - i++; - } - - ref = xf86ConfigLayout.screens[i].refscreen->screennum; - xf86Screens[ref]->pScreen->x = xf86Screens[ref]->pScreen->y = 0; - screensLeft &= ~(1 << ref); - } - - prevScreensLeft = screensLeft; - } - - /* justify the topmost and leftmost to (0,0) */ - minX = xf86Screens[0]->pScreen->x; - minY = xf86Screens[0]->pScreen->y; - - for (i = 1; i < xf86NumScreens; i++) { - if (xf86Screens[i]->pScreen->x < minX) - minX = xf86Screens[i]->pScreen->x; - if (xf86Screens[i]->pScreen->y < minY) - minY = xf86Screens[i]->pScreen->y; - } - - if (minX || minY) { - for (i = 0; i < xf86NumScreens; i++) { - xf86Screens[i]->pScreen->x -= minX; - xf86Screens[i]->pScreen->y -= minY; - } - } - - /* Create the edge lists */ - - if (!OldStyleConfig) { - for (i = 0; i < xf86NumScreens; i++) { - pLayout = &xf86ScreenLayout[i]; - - pScreen = xf86Screens[i]->pScreen; - - left = pScreen->x; - right = left + pScreen->width; - top = pScreen->y; - bottom = top + pScreen->height; - - for (j = 0; j < xf86NumScreens; j++) { - if (i == j) - continue; - - refScreen = xf86Screens[j]->pScreen; - - x1 = refScreen->x; - x2 = x1 + refScreen->width; - y1 = refScreen->y; - y2 = y1 + refScreen->height; - - if ((bottom > y1) && (top < y2)) { - min = y1 - top; - if (min < 0) - min = 0; - max = pScreen->height - (bottom - y2); - if (max > pScreen->height) - max = pScreen->height; - - if (((left - 1) >= x1) && ((left - 1) < x2)) - pLayout->left = AddEdge(pLayout->left, min, max, - pScreen->x - refScreen->x, - pScreen->y - refScreen->y, j); - - if ((right >= x1) && (right < x2)) - pLayout->right = AddEdge(pLayout->right, min, max, - pScreen->x - refScreen->x, - pScreen->y - refScreen->y, j); - } - - if ((left < x2) && (right > x1)) { - min = x1 - left; - if (min < 0) - min = 0; - max = pScreen->width - (right - x2); - if (max > pScreen->width) - max = pScreen->width; - - if (((top - 1) >= y1) && ((top - 1) < y2)) - pLayout->up = AddEdge(pLayout->up, min, max, - pScreen->x - refScreen->x, - pScreen->y - refScreen->y, j); - - if ((bottom >= y1) && (bottom < y2)) - pLayout->down = AddEdge(pLayout->down, min, max, - pScreen->x - refScreen->x, - pScreen->y - refScreen->y, j); - } - } - } - } - - if (!OldStyleConfig) { - for (i = 0; i < xf86NumScreens; i++) { - pLayout = &xf86ScreenLayout[i]; - pScreen = xf86Screens[i]->pScreen; - if (pLayout->left) - FillOutEdge(pLayout->left, pScreen->height); - if (pLayout->right) - FillOutEdge(pLayout->right, pScreen->height); - if (pLayout->up) - FillOutEdge(pLayout->up, pScreen->width); - if (pLayout->down) - FillOutEdge(pLayout->down, pScreen->width); - } - } - - update_desktop_dimensions(); -} - -void -xf86ReconfigureLayout(void) -{ - int i; - - for (i = 0; i < MAXSCREENS; i++) { - xf86ScreenLayoutPtr sl = &xf86ScreenLayout[i]; - - /* we don't have to zero these, xf86InitOrigins() takes care of that */ - free(sl->left); - free(sl->right); - free(sl->up); - free(sl->down); - } - - xf86InitOrigins(); -} diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c deleted file mode 100644 index fa70ba2f0..000000000 --- a/hw/xfree86/common/xf86DGA.c +++ /dev/null @@ -1,2179 +0,0 @@ -/* - * Copyright (c) 1995 Jon Tombs - * Copyright (c) 1995, 1996, 1999 XFree86 Inc - * Copyright (c) 1998-2002 by The XFree86 Project, 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). - * - * Written by Mark Vojkovich - */ - -/* - * This is quite literally just two files glued together: - * hw/xfree86/common/xf86DGA.c is the first part, and - * hw/xfree86/dixmods/extmod/xf86dga2.c is the second part. One day, if - * someone actually cares about DGA, it'd be nice to clean this up. But trust - * me, I am not that person. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include "xf86.h" -#include "xf86str.h" -#include "xf86Priv.h" -#include "dgaproc.h" -#include -#include "colormapst.h" -#include "pixmapstr.h" -#include "inputstr.h" -#include "globals.h" -#include "servermd.h" -#include "micmap.h" -#include "xkbsrv.h" -#include "xf86Xinput.h" -#include "exglobals.h" -#include "exevents.h" -#include "eventstr.h" -#include "eventconvert.h" -#include "xf86Extensions.h" - -#include "mi.h" - -#include "misc.h" -#include "dixstruct.h" -#include "dixevents.h" -#include "extnsionst.h" -#include "cursorstr.h" -#include "scrnintstr.h" -#include "swaprep.h" -#include "dgaproc.h" -#include "protocol-versions.h" - -#include - -#define DGA_PROTOCOL_OLD_SUPPORT 1 - -static DevPrivateKeyRec DGAScreenKeyRec; - -#define DGAScreenKeyRegistered dixPrivateKeyRegistered(&DGAScreenKeyRec) - -static Bool DGACloseScreen(ScreenPtr pScreen); -static void DGADestroyColormap(ColormapPtr pmap); -static void DGAInstallColormap(ColormapPtr pmap); -static void DGAUninstallColormap(ColormapPtr pmap); -static void DGAHandleEvent(int screen_num, InternalEvent *event, - DeviceIntPtr device); - -static void - DGACopyModeInfo(DGAModePtr mode, XDGAModePtr xmode); - -static unsigned char DGAReqCode = 0; -static int DGAErrorBase; -static int DGAEventBase; - -#define DGA_GET_SCREEN_PRIV(pScreen) ((DGAScreenPtr) \ - dixLookupPrivate(&(pScreen)->devPrivates, &DGAScreenKeyRec)) - -typedef struct _FakedVisualList { - Bool free; - VisualPtr pVisual; - struct _FakedVisualList *next; -} FakedVisualList; - -typedef struct { - ScrnInfoPtr pScrn; - int numModes; - DGAModePtr modes; - CloseScreenProcPtr CloseScreen; - DestroyColormapProcPtr DestroyColormap; - InstallColormapProcPtr InstallColormap; - UninstallColormapProcPtr UninstallColormap; - DGADevicePtr current; - DGAFunctionPtr funcs; - int input; - ClientPtr client; - int pixmapMode; - FakedVisualList *fakedVisuals; - ColormapPtr dgaColormap; - ColormapPtr savedColormap; - Bool grabMouse; - Bool grabKeyboard; -} DGAScreenRec, *DGAScreenPtr; - -Bool -DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs, DGAModePtr modes, int num) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - DGAScreenPtr pScreenPriv; - int i; - - if (!funcs || !funcs->SetMode || !funcs->OpenFramebuffer) - return FALSE; - - if (!modes || num <= 0) - return FALSE; - - if (!dixRegisterPrivateKey(&DGAScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - if (!pScreenPriv) { - if (!(pScreenPriv = (DGAScreenPtr) malloc(sizeof(DGAScreenRec)))) - return FALSE; - dixSetPrivate(&pScreen->devPrivates, &DGAScreenKeyRec, pScreenPriv); - pScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = DGACloseScreen; - pScreenPriv->DestroyColormap = pScreen->DestroyColormap; - pScreen->DestroyColormap = DGADestroyColormap; - pScreenPriv->InstallColormap = pScreen->InstallColormap; - pScreen->InstallColormap = DGAInstallColormap; - pScreenPriv->UninstallColormap = pScreen->UninstallColormap; - pScreen->UninstallColormap = DGAUninstallColormap; - } - - pScreenPriv->pScrn = pScrn; - pScreenPriv->numModes = num; - pScreenPriv->modes = modes; - pScreenPriv->current = NULL; - - pScreenPriv->funcs = funcs; - pScreenPriv->input = 0; - pScreenPriv->client = NULL; - pScreenPriv->fakedVisuals = NULL; - pScreenPriv->dgaColormap = NULL; - pScreenPriv->savedColormap = NULL; - pScreenPriv->grabMouse = FALSE; - pScreenPriv->grabKeyboard = FALSE; - - for (i = 0; i < num; i++) - modes[i].num = i + 1; - -#ifdef PANORAMIX - if (!noPanoramiXExtension) - for (i = 0; i < num; i++) - modes[i].flags &= ~DGA_PIXMAP_AVAILABLE; -#endif - - return TRUE; -} - -/* DGAReInitModes allows the driver to re-initialize - * the DGA mode list. - */ - -Bool -DGAReInitModes(ScreenPtr pScreen, DGAModePtr modes, int num) -{ - DGAScreenPtr pScreenPriv; - int i; - - /* No DGA? Ignore call (but don't make it look like it failed) */ - if (!DGAScreenKeyRegistered) - return TRUE; - - pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - /* Same as above */ - if (!pScreenPriv) - return TRUE; - - /* Can't do this while DGA is active */ - if (pScreenPriv->current) - return FALSE; - - /* Quick sanity check */ - if (!num) - modes = NULL; - else if (!modes) - num = 0; - - pScreenPriv->numModes = num; - pScreenPriv->modes = modes; - - /* This practically disables DGA. So be it. */ - if (!num) - return TRUE; - - for (i = 0; i < num; i++) - modes[i].num = i + 1; - -#ifdef PANORAMIX - if (!noPanoramiXExtension) - for (i = 0; i < num; i++) - modes[i].flags &= ~DGA_PIXMAP_AVAILABLE; -#endif - - return TRUE; -} - -static void -FreeMarkedVisuals(ScreenPtr pScreen) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - FakedVisualList *prev, *curr, *tmp; - - if (!pScreenPriv->fakedVisuals) - return; - - prev = NULL; - curr = pScreenPriv->fakedVisuals; - - while (curr) { - if (curr->free) { - tmp = curr; - curr = curr->next; - if (prev) - prev->next = curr; - else - pScreenPriv->fakedVisuals = curr; - free(tmp->pVisual); - free(tmp); - } - else { - prev = curr; - curr = curr->next; - } - } -} - -static Bool -DGACloseScreen(ScreenPtr pScreen) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - mieqSetHandler(ET_DGAEvent, NULL); - pScreenPriv->pScrn->SetDGAMode(pScreenPriv->pScrn, 0, NULL); - FreeMarkedVisuals(pScreen); - - pScreen->CloseScreen = pScreenPriv->CloseScreen; - pScreen->DestroyColormap = pScreenPriv->DestroyColormap; - pScreen->InstallColormap = pScreenPriv->InstallColormap; - pScreen->UninstallColormap = pScreenPriv->UninstallColormap; - - free(pScreenPriv); - - return ((*pScreen->CloseScreen) (pScreen)); -} - -static void -DGADestroyColormap(ColormapPtr pmap) -{ - ScreenPtr pScreen = pmap->pScreen; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - VisualPtr pVisual = pmap->pVisual; - - if (pScreenPriv->fakedVisuals) { - FakedVisualList *curr = pScreenPriv->fakedVisuals; - - while (curr) { - if (curr->pVisual == pVisual) { - /* We can't get rid of them yet since FreeColormap - still needs the pVisual during the cleanup */ - curr->free = TRUE; - break; - } - curr = curr->next; - } - } - - if (pScreenPriv->DestroyColormap) { - pScreen->DestroyColormap = pScreenPriv->DestroyColormap; - (*pScreen->DestroyColormap) (pmap); - pScreen->DestroyColormap = DGADestroyColormap; - } -} - -static void -DGAInstallColormap(ColormapPtr pmap) -{ - ScreenPtr pScreen = pmap->pScreen; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - if (pScreenPriv->current && pScreenPriv->dgaColormap) { - if (pmap != pScreenPriv->dgaColormap) { - pScreenPriv->savedColormap = pmap; - pmap = pScreenPriv->dgaColormap; - } - } - - pScreen->InstallColormap = pScreenPriv->InstallColormap; - (*pScreen->InstallColormap) (pmap); - pScreen->InstallColormap = DGAInstallColormap; -} - -static void -DGAUninstallColormap(ColormapPtr pmap) -{ - ScreenPtr pScreen = pmap->pScreen; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - if (pScreenPriv->current && pScreenPriv->dgaColormap) { - if (pmap == pScreenPriv->dgaColormap) { - pScreenPriv->dgaColormap = NULL; - } - } - - pScreen->UninstallColormap = pScreenPriv->UninstallColormap; - (*pScreen->UninstallColormap) (pmap); - pScreen->UninstallColormap = DGAUninstallColormap; -} - -int -xf86SetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr devRet) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - DGAScreenPtr pScreenPriv; - DGADevicePtr device; - PixmapPtr pPix = NULL; - DGAModePtr pMode = NULL; - - /* First check if DGAInit was successful on this screen */ - if (!DGAScreenKeyRegistered) - return BadValue; - pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - if (!pScreenPriv) - return BadValue; - - if (!num) { - if (pScreenPriv->current) { - PixmapPtr oldPix = pScreenPriv->current->pPix; - - if (oldPix) { - if (oldPix->drawable.id) - FreeResource(oldPix->drawable.id, RT_NONE); - else - (*pScreen->DestroyPixmap) (oldPix); - } - free(pScreenPriv->current); - pScreenPriv->current = NULL; - pScrn->vtSema = TRUE; - (*pScreenPriv->funcs->SetMode) (pScrn, NULL); - if (pScreenPriv->savedColormap) { - (*pScreen->InstallColormap) (pScreenPriv->savedColormap); - pScreenPriv->savedColormap = NULL; - } - pScreenPriv->dgaColormap = NULL; - (*pScrn->EnableDisableFBAccess) (pScrn, TRUE); - - FreeMarkedVisuals(pScreen); - } - - pScreenPriv->grabMouse = FALSE; - pScreenPriv->grabKeyboard = FALSE; - - return Success; - } - - if (!pScrn->vtSema && !pScreenPriv->current) /* Really switched away */ - return BadAlloc; - - if ((num > 0) && (num <= pScreenPriv->numModes)) - pMode = &(pScreenPriv->modes[num - 1]); - else - return BadValue; - - if (!(device = (DGADevicePtr) malloc(sizeof(DGADeviceRec)))) - return BadAlloc; - - if (!pScreenPriv->current) { - Bool oldVTSema = pScrn->vtSema; - - pScrn->vtSema = FALSE; /* kludge until we rewrite VT switching */ - (*pScrn->EnableDisableFBAccess) (pScrn, FALSE); - pScrn->vtSema = oldVTSema; - } - - if (!(*pScreenPriv->funcs->SetMode) (pScrn, pMode)) { - free(device); - return BadAlloc; - } - - pScrn->currentMode = pMode->mode; - - if (!pScreenPriv->current && !pScreenPriv->input) { - /* if it's multihead we need to warp the cursor off of - our screen so it doesn't get trapped */ - } - - pScrn->vtSema = FALSE; - - if (pScreenPriv->current) { - PixmapPtr oldPix = pScreenPriv->current->pPix; - - if (oldPix) { - if (oldPix->drawable.id) - FreeResource(oldPix->drawable.id, RT_NONE); - else - (*pScreen->DestroyPixmap) (oldPix); - } - free(pScreenPriv->current); - pScreenPriv->current = NULL; - } - - if (pMode->flags & DGA_PIXMAP_AVAILABLE) { - if ((pPix = (*pScreen->CreatePixmap) (pScreen, 0, 0, pMode->depth, 0))) { - (*pScreen->ModifyPixmapHeader) (pPix, - pMode->pixmapWidth, - pMode->pixmapHeight, pMode->depth, - pMode->bitsPerPixel, - pMode->bytesPerScanline, - (void *) (pMode->address)); - } - } - - devRet->mode = device->mode = pMode; - devRet->pPix = device->pPix = pPix; - pScreenPriv->current = device; - pScreenPriv->pixmapMode = FALSE; - pScreenPriv->grabMouse = TRUE; - pScreenPriv->grabKeyboard = TRUE; - - mieqSetHandler(ET_DGAEvent, DGAHandleEvent); - - return Success; -} - -/*********** exported ones ***************/ - -static void -DGASetInputMode(int index, Bool keyboard, Bool mouse) -{ - ScreenPtr pScreen = screenInfo.screens[index]; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - if (pScreenPriv) { - pScreenPriv->grabMouse = mouse; - pScreenPriv->grabKeyboard = keyboard; - - mieqSetHandler(ET_DGAEvent, DGAHandleEvent); - } -} - -static Bool -DGAChangePixmapMode(int index, int *x, int *y, int mode) -{ - DGAScreenPtr pScreenPriv; - DGADevicePtr pDev; - DGAModePtr pMode; - PixmapPtr pPix; - - if (!DGAScreenKeyRegistered) - return FALSE; - - pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - if (!pScreenPriv || !pScreenPriv->current || !pScreenPriv->current->pPix) - return FALSE; - - pDev = pScreenPriv->current; - pPix = pDev->pPix; - pMode = pDev->mode; - - if (mode) { - int shift = 2; - - if (*x > (pMode->pixmapWidth - pMode->viewportWidth)) - *x = pMode->pixmapWidth - pMode->viewportWidth; - if (*y > (pMode->pixmapHeight - pMode->viewportHeight)) - *y = pMode->pixmapHeight - pMode->viewportHeight; - - switch (xf86Screens[index]->bitsPerPixel) { - case 16: - shift = 1; - break; - case 32: - shift = 0; - break; - default: - break; - } - - if (BITMAP_SCANLINE_PAD == 64) - shift++; - - *x = (*x >> shift) << shift; - - pPix->drawable.x = *x; - pPix->drawable.y = *y; - pPix->drawable.width = pMode->viewportWidth; - pPix->drawable.height = pMode->viewportHeight; - } - else { - pPix->drawable.x = 0; - pPix->drawable.y = 0; - pPix->drawable.width = pMode->pixmapWidth; - pPix->drawable.height = pMode->pixmapHeight; - } - pPix->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pScreenPriv->pixmapMode = mode; - - return TRUE; -} - -Bool -DGAScreenAvailable(ScreenPtr pScreen) -{ - if (!DGAScreenKeyRegistered) - return FALSE; - - if (DGA_GET_SCREEN_PRIV(pScreen)) - return TRUE; - return FALSE; -} - -static Bool -DGAAvailable(int index) -{ - ScreenPtr pScreen; - - assert(index < MAXSCREENS); - pScreen = screenInfo.screens[index]; - return DGAScreenAvailable(pScreen); -} - -Bool -DGAActive(int index) -{ - DGAScreenPtr pScreenPriv; - - if (!DGAScreenKeyRegistered) - return FALSE; - - pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - if (pScreenPriv && pScreenPriv->current) - return TRUE; - - return FALSE; -} - -/* Called by the extension to initialize a mode */ - -static int -DGASetMode(int index, int num, XDGAModePtr mode, PixmapPtr *pPix) -{ - ScrnInfoPtr pScrn = xf86Screens[index]; - DGADeviceRec device; - int ret; - - /* We rely on the extension to check that DGA is available */ - - ret = (*pScrn->SetDGAMode) (pScrn, num, &device); - if ((ret == Success) && num) { - DGACopyModeInfo(device.mode, mode); - *pPix = device.pPix; - } - - return ret; -} - -/* Called from the extension to let the DDX know which events are requested */ - -static void -DGASelectInput(int index, ClientPtr client, long mask) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is available */ - pScreenPriv->client = client; - pScreenPriv->input = mask; -} - -static int -DGAGetViewportStatus(int index) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is active */ - - if (!pScreenPriv->funcs->GetViewport) - return 0; - - return (*pScreenPriv->funcs->GetViewport) (pScreenPriv->pScrn); -} - -static int -DGASetViewport(int index, int x, int y, int mode) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - if (pScreenPriv->funcs->SetViewport) - (*pScreenPriv->funcs->SetViewport) (pScreenPriv->pScrn, x, y, mode); - return Success; -} - -static int -BitsClear(CARD32 data) -{ - int bits = 0; - CARD32 mask; - - for (mask = 1; mask; mask <<= 1) { - if (!(data & mask)) - bits++; - else - break; - } - - return bits; -} - -static int -DGACreateColormap(int index, ClientPtr client, int id, int mode, int alloc) -{ - ScreenPtr pScreen = screenInfo.screens[index]; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - FakedVisualList *fvlp; - VisualPtr pVisual; - DGAModePtr pMode; - ColormapPtr pmap; - - if (!mode || (mode > pScreenPriv->numModes)) - return BadValue; - - if ((alloc != AllocNone) && (alloc != AllocAll)) - return BadValue; - - pMode = &(pScreenPriv->modes[mode - 1]); - - if (!(pVisual = malloc(sizeof(VisualRec)))) - return BadAlloc; - - pVisual->vid = FakeClientID(0); - pVisual->class = pMode->visualClass; - pVisual->nplanes = pMode->depth; - pVisual->ColormapEntries = 1 << pMode->depth; - pVisual->bitsPerRGBValue = (pMode->depth + 2) / 3; - - switch (pVisual->class) { - case PseudoColor: - case GrayScale: - case StaticGray: - pVisual->bitsPerRGBValue = 8; /* not quite */ - pVisual->redMask = 0; - pVisual->greenMask = 0; - pVisual->blueMask = 0; - pVisual->offsetRed = 0; - pVisual->offsetGreen = 0; - pVisual->offsetBlue = 0; - break; - case DirectColor: - case TrueColor: - pVisual->ColormapEntries = 1 << pVisual->bitsPerRGBValue; - /* fall through */ - case StaticColor: - pVisual->redMask = pMode->red_mask; - pVisual->greenMask = pMode->green_mask; - pVisual->blueMask = pMode->blue_mask; - pVisual->offsetRed = BitsClear(pVisual->redMask); - pVisual->offsetGreen = BitsClear(pVisual->greenMask); - pVisual->offsetBlue = BitsClear(pVisual->blueMask); - } - - if (!(fvlp = malloc(sizeof(FakedVisualList)))) { - free(pVisual); - return BadAlloc; - } - - fvlp->free = FALSE; - fvlp->pVisual = pVisual; - fvlp->next = pScreenPriv->fakedVisuals; - pScreenPriv->fakedVisuals = fvlp; - - LEGAL_NEW_RESOURCE(id, client); - - return CreateColormap(id, pScreen, pVisual, &pmap, alloc, client->index); -} - -/* Called by the extension to install a colormap on DGA active screens */ - -static void -DGAInstallCmap(ColormapPtr cmap) -{ - ScreenPtr pScreen = cmap->pScreen; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - /* We rely on the extension to check that DGA is active */ - - if (!pScreenPriv->dgaColormap) - pScreenPriv->savedColormap = GetInstalledmiColormap(pScreen); - - pScreenPriv->dgaColormap = cmap; - - (*pScreen->InstallColormap) (cmap); -} - -static int -DGASync(int index) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is active */ - - if (pScreenPriv->funcs->Sync) - (*pScreenPriv->funcs->Sync) (pScreenPriv->pScrn); - - return Success; -} - -static int -DGAFillRect(int index, int x, int y, int w, int h, unsigned long color) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is active */ - - if (pScreenPriv->funcs->FillRect && - (pScreenPriv->current->mode->flags & DGA_FILL_RECT)) { - - (*pScreenPriv->funcs->FillRect) (pScreenPriv->pScrn, x, y, w, h, color); - return Success; - } - return BadMatch; -} - -static int -DGABlitRect(int index, int srcx, int srcy, int w, int h, int dstx, int dsty) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is active */ - - if (pScreenPriv->funcs->BlitRect && - (pScreenPriv->current->mode->flags & DGA_BLIT_RECT)) { - - (*pScreenPriv->funcs->BlitRect) (pScreenPriv->pScrn, - srcx, srcy, w, h, dstx, dsty); - return Success; - } - return BadMatch; -} - -static int -DGABlitTransRect(int index, - int srcx, int srcy, - int w, int h, int dstx, int dsty, unsigned long color) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is active */ - - if (pScreenPriv->funcs->BlitTransRect && - (pScreenPriv->current->mode->flags & DGA_BLIT_RECT_TRANS)) { - - (*pScreenPriv->funcs->BlitTransRect) (pScreenPriv->pScrn, - srcx, srcy, w, h, dstx, dsty, - color); - return Success; - } - return BadMatch; -} - -static int -DGAGetModes(int index) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is available */ - - return pScreenPriv->numModes; -} - -static int -DGAGetModeInfo(int index, XDGAModePtr mode, int num) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is available */ - - if ((num <= 0) || (num > pScreenPriv->numModes)) - return BadValue; - - DGACopyModeInfo(&(pScreenPriv->modes[num - 1]), mode); - - return Success; -} - -static void -DGACopyModeInfo(DGAModePtr mode, XDGAModePtr xmode) -{ - DisplayModePtr dmode = mode->mode; - - xmode->num = mode->num; - xmode->name = dmode->name; - xmode->VSync_num = (int) (dmode->VRefresh * 1000.0); - xmode->VSync_den = 1000; - xmode->flags = mode->flags; - xmode->imageWidth = mode->imageWidth; - xmode->imageHeight = mode->imageHeight; - xmode->pixmapWidth = mode->pixmapWidth; - xmode->pixmapHeight = mode->pixmapHeight; - xmode->bytesPerScanline = mode->bytesPerScanline; - xmode->byteOrder = mode->byteOrder; - xmode->depth = mode->depth; - xmode->bitsPerPixel = mode->bitsPerPixel; - xmode->red_mask = mode->red_mask; - xmode->green_mask = mode->green_mask; - xmode->blue_mask = mode->blue_mask; - xmode->visualClass = mode->visualClass; - xmode->viewportWidth = mode->viewportWidth; - xmode->viewportHeight = mode->viewportHeight; - xmode->xViewportStep = mode->xViewportStep; - xmode->yViewportStep = mode->yViewportStep; - xmode->maxViewportX = mode->maxViewportX; - xmode->maxViewportY = mode->maxViewportY; - xmode->viewportFlags = mode->viewportFlags; - xmode->reserved1 = mode->reserved1; - xmode->reserved2 = mode->reserved2; - xmode->offset = mode->offset; - - if (dmode->Flags & V_INTERLACE) - xmode->flags |= DGA_INTERLACED; - if (dmode->Flags & V_DBLSCAN) - xmode->flags |= DGA_DOUBLESCAN; -} - -Bool -DGAVTSwitch(void) -{ - ScreenPtr pScreen; - int i; - - for (i = 0; i < screenInfo.numScreens; i++) { - pScreen = screenInfo.screens[i]; - - /* Alternatively, this could send events to DGA clients */ - - if (DGAScreenKeyRegistered) { - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - if (pScreenPriv && pScreenPriv->current) - return FALSE; - } - } - - return TRUE; -} - -Bool -DGAStealKeyEvent(DeviceIntPtr dev, int index, int key_code, int is_down) -{ - DGAScreenPtr pScreenPriv; - DGAEvent event; - - if (!DGAScreenKeyRegistered) /* no DGA */ - return FALSE; - - if (key_code < 8 || key_code > 255) - return FALSE; - - pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - if (!pScreenPriv || !pScreenPriv->grabKeyboard) /* no direct mode */ - return FALSE; - - event = (DGAEvent) { - .header = ET_Internal, - .type = ET_DGAEvent, - .length = sizeof(event), - .time = GetTimeInMillis(), - .subtype = (is_down ? ET_KeyPress : ET_KeyRelease), - .detail = key_code, - .dx = 0, - .dy = 0 - }; - mieqEnqueue(dev, (InternalEvent *) &event); - - return TRUE; -} - -Bool -DGAStealMotionEvent(DeviceIntPtr dev, int index, int dx, int dy) -{ - DGAScreenPtr pScreenPriv; - DGAEvent event; - - if (!DGAScreenKeyRegistered) /* no DGA */ - return FALSE; - - pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - if (!pScreenPriv || !pScreenPriv->grabMouse) /* no direct mode */ - return FALSE; - - event = (DGAEvent) { - .header = ET_Internal, - .type = ET_DGAEvent, - .length = sizeof(event), - .time = GetTimeInMillis(), - .subtype = ET_Motion, - .detail = 0, - .dx = dx, - .dy = dy - }; - mieqEnqueue(dev, (InternalEvent *) &event); - return TRUE; -} - -Bool -DGAStealButtonEvent(DeviceIntPtr dev, int index, int button, int is_down) -{ - DGAScreenPtr pScreenPriv; - DGAEvent event; - - if (!DGAScreenKeyRegistered) /* no DGA */ - return FALSE; - - pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - if (!pScreenPriv || !pScreenPriv->grabMouse) - return FALSE; - - event = (DGAEvent) { - .header = ET_Internal, - .type = ET_DGAEvent, - .length = sizeof(event), - .time = GetTimeInMillis(), - .subtype = (is_down ? ET_ButtonPress : ET_ButtonRelease), - .detail = button, - .dx = 0, - .dy = 0 - }; - mieqEnqueue(dev, (InternalEvent *) &event); - - return TRUE; -} - -/* We have the power to steal or modify events that are about to get queued */ - -#define NoSuchEvent 0x80000000 /* so doesn't match NoEventMask */ -static Mask filters[] = { - NoSuchEvent, /* 0 */ - NoSuchEvent, /* 1 */ - KeyPressMask, /* KeyPress */ - KeyReleaseMask, /* KeyRelease */ - ButtonPressMask, /* ButtonPress */ - ButtonReleaseMask, /* ButtonRelease */ - PointerMotionMask, /* MotionNotify (initial state) */ -}; - -static void -DGAProcessKeyboardEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr keybd) -{ - KeyClassPtr keyc = keybd->key; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - DeviceIntPtr pointer = GetMaster(keybd, POINTER_OR_FLOAT); - DeviceEvent ev = { - .header = ET_Internal, - .length = sizeof(ev), - .detail.key = event->detail, - .type = event->subtype, - .root_x = 0, - .root_y = 0, - .corestate = XkbStateFieldFromRec(&keyc->xkbInfo->state) - }; - ev.corestate |= pointer->button->state; - - UpdateDeviceState(keybd, &ev); - - if (!IsMaster(keybd)) - return; - - /* - * Deliver the DGA event - */ - if (pScreenPriv->client) { - dgaEvent de = { - .u.event.time = event->time, - .u.event.dx = event->dx, - .u.event.dy = event->dy, - .u.event.screen = pScreen->myNum, - .u.event.state = ev.corestate - }; - de.u.u.type = DGAEventBase + GetCoreType(ev.type); - de.u.u.detail = event->detail; - - /* If the DGA client has selected input, then deliver based on the usual filter */ - TryClientEvents(pScreenPriv->client, keybd, (xEvent *) &de, 1, - filters[ev.type], pScreenPriv->input, 0); - } - else { - /* If the keyboard is actively grabbed, deliver a grabbed core event */ - if (keybd->deviceGrab.grab && !keybd->deviceGrab.fromPassiveGrab) { - ev.detail.key = event->detail; - ev.time = event->time; - ev.root_x = event->dx; - ev.root_y = event->dy; - ev.corestate = event->state; - ev.deviceid = keybd->id; - DeliverGrabbedEvent((InternalEvent *) &ev, keybd, FALSE); - } - } -} - -static void -DGAProcessPointerEvent(ScreenPtr pScreen, DGAEvent * event, DeviceIntPtr mouse) -{ - ButtonClassPtr butc = mouse->button; - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - DeviceIntPtr master = GetMaster(mouse, MASTER_KEYBOARD); - DeviceEvent ev = { - .header = ET_Internal, - .length = sizeof(ev), - .detail.key = event->detail, - .type = event->subtype, - .corestate = butc ? butc->state : 0 - }; - - if (master && master->key) - ev.corestate |= XkbStateFieldFromRec(&master->key->xkbInfo->state); - - UpdateDeviceState(mouse, &ev); - - if (!IsMaster(mouse)) - return; - - /* - * Deliver the DGA event - */ - if (pScreenPriv->client) { - int coreEquiv = GetCoreType(ev.type); - dgaEvent de = { - .u.event.time = event->time, - .u.event.dx = event->dx, - .u.event.dy = event->dy, - .u.event.screen = pScreen->myNum, - .u.event.state = ev.corestate - }; - de.u.u.type = DGAEventBase + coreEquiv; - de.u.u.detail = event->detail; - - /* If the DGA client has selected input, then deliver based on the usual filter */ - TryClientEvents(pScreenPriv->client, mouse, (xEvent *) &de, 1, - filters[coreEquiv], pScreenPriv->input, 0); - } - else { - /* If the pointer is actively grabbed, deliver a grabbed core event */ - if (mouse->deviceGrab.grab && !mouse->deviceGrab.fromPassiveGrab) { - ev.detail.button = event->detail; - ev.time = event->time; - ev.root_x = event->dx; - ev.root_y = event->dy; - ev.corestate = event->state; - /* DGA is core only, so valuators.data doesn't actually matter. - * Mask must be set for EventToCore to create motion events. */ - SetBit(ev.valuators.mask, 0); - SetBit(ev.valuators.mask, 1); - DeliverGrabbedEvent((InternalEvent *) &ev, mouse, FALSE); - } - } -} - -static Bool -DGAOpenFramebuffer(int index, - char **name, - unsigned char **mem, int *size, int *offset, int *flags) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is available */ - - return (*pScreenPriv->funcs->OpenFramebuffer) (pScreenPriv->pScrn, - name, mem, size, offset, - flags); -} - -static void -DGACloseFramebuffer(int index) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - - /* We rely on the extension to check that DGA is available */ - if (pScreenPriv->funcs->CloseFramebuffer) - (*pScreenPriv->funcs->CloseFramebuffer) (pScreenPriv->pScrn); -} - -/* For DGA 1.0 backwards compatibility only */ - -static int -DGAGetOldDGAMode(int index) -{ - DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); - ScrnInfoPtr pScrn = pScreenPriv->pScrn; - DGAModePtr mode; - int i, w, h, p; - - /* We rely on the extension to check that DGA is available */ - - w = pScrn->currentMode->HDisplay; - h = pScrn->currentMode->VDisplay; - p = pad_to_int32(pScrn->displayWidth * bits_to_bytes(pScrn->bitsPerPixel)); - - for (i = 0; i < pScreenPriv->numModes; i++) { - mode = &(pScreenPriv->modes[i]); - - if ((mode->viewportWidth == w) && (mode->viewportHeight == h) && - (mode->bytesPerScanline == p) && - (mode->bitsPerPixel == pScrn->bitsPerPixel) && - (mode->depth == pScrn->depth)) { - - return mode->num; - } - } - - return 0; -} - -static void -DGAHandleEvent(int screen_num, InternalEvent *ev, DeviceIntPtr device) -{ - DGAEvent *event = &ev->dga_event; - ScreenPtr pScreen = screenInfo.screens[screen_num]; - DGAScreenPtr pScreenPriv; - - /* no DGA */ - if (!DGAScreenKeyRegistered || noXFree86DGAExtension) - return; - pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - /* DGA not initialized on this screen */ - if (!pScreenPriv) - return; - - switch (event->subtype) { - case KeyPress: - case KeyRelease: - DGAProcessKeyboardEvent(pScreen, event, device); - break; - case MotionNotify: - case ButtonPress: - case ButtonRelease: - DGAProcessPointerEvent(pScreen, event, device); - break; - default: - break; - } -} - -static void XDGAResetProc(ExtensionEntry * extEntry); - -static void DGAClientStateChange(CallbackListPtr *, void *, void *); - -static DevPrivateKeyRec DGAScreenPrivateKeyRec; - -#define DGAScreenPrivateKey (&DGAScreenPrivateKeyRec) -#define DGAScreenPrivateKeyRegistered (DGAScreenPrivateKeyRec.initialized) -static DevPrivateKeyRec DGAClientPrivateKeyRec; - -#define DGAClientPrivateKey (&DGAClientPrivateKeyRec) -static int DGACallbackRefCount = 0; - -/* This holds the client's version information */ -typedef struct { - int major; - int minor; -} DGAPrivRec, *DGAPrivPtr; - -#define DGA_GETCLIENT(idx) ((ClientPtr) \ - dixLookupPrivate(&screenInfo.screens[idx]->devPrivates, DGAScreenPrivateKey)) -#define DGA_SETCLIENT(idx,p) \ - dixSetPrivate(&screenInfo.screens[idx]->devPrivates, DGAScreenPrivateKey, p) - -#define DGA_GETPRIV(c) ((DGAPrivPtr) \ - dixLookupPrivate(&(c)->devPrivates, DGAClientPrivateKey)) -#define DGA_SETPRIV(c,p) \ - dixSetPrivate(&(c)->devPrivates, DGAClientPrivateKey, p) - -static void -XDGAResetProc(ExtensionEntry * extEntry) -{ - DeleteCallback(&ClientStateCallback, DGAClientStateChange, NULL); - DGACallbackRefCount = 0; -} - -static int -ProcXDGAQueryVersion(ClientPtr client) -{ - xXDGAQueryVersionReply rep; - - REQUEST_SIZE_MATCH(xXDGAQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.majorVersion = SERVER_XDGA_MAJOR_VERSION; - rep.minorVersion = SERVER_XDGA_MINOR_VERSION; - - WriteToClient(client, sizeof(xXDGAQueryVersionReply), (char *) &rep); - return Success; -} - -static int -ProcXDGAOpenFramebuffer(ClientPtr client) -{ - REQUEST(xXDGAOpenFramebufferReq); - xXDGAOpenFramebufferReply rep; - char *deviceName; - int nameSize; - - REQUEST_SIZE_MATCH(xXDGAOpenFramebufferReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (!DGAAvailable(stuff->screen)) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - - if (!DGAOpenFramebuffer(stuff->screen, &deviceName, - (unsigned char **) (&rep.mem1), - (int *) &rep.size, (int *) &rep.offset, - (int *) &rep.extra)) { - return BadAlloc; - } - - nameSize = deviceName ? (strlen(deviceName) + 1) : 0; - rep.length = bytes_to_int32(nameSize); - - WriteToClient(client, sizeof(xXDGAOpenFramebufferReply), (char *) &rep); - if (rep.length) - WriteToClient(client, nameSize, deviceName); - - return Success; -} - -static int -ProcXDGACloseFramebuffer(ClientPtr client) -{ - REQUEST(xXDGACloseFramebufferReq); - - REQUEST_SIZE_MATCH(xXDGACloseFramebufferReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (!DGAAvailable(stuff->screen)) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - DGACloseFramebuffer(stuff->screen); - - return Success; -} - -static int -ProcXDGAQueryModes(ClientPtr client) -{ - int i, num, size; - - REQUEST(xXDGAQueryModesReq); - xXDGAQueryModesReply rep; - xXDGAModeInfo info; - XDGAModePtr mode; - - REQUEST_SIZE_MATCH(xXDGAQueryModesReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - rep.type = X_Reply; - rep.length = 0; - rep.number = 0; - rep.sequenceNumber = client->sequence; - - if (!DGAAvailable(stuff->screen)) { - rep.number = 0; - rep.length = 0; - WriteToClient(client, sz_xXDGAQueryModesReply, (char *) &rep); - return Success; - } - - if (!(num = DGAGetModes(stuff->screen))) { - WriteToClient(client, sz_xXDGAQueryModesReply, (char *) &rep); - return Success; - } - - if (!(mode = xallocarray(num, sizeof(XDGAModeRec)))) - return BadAlloc; - - for (i = 0; i < num; i++) - DGAGetModeInfo(stuff->screen, mode + i, i + 1); - - size = num * sz_xXDGAModeInfo; - for (i = 0; i < num; i++) - size += pad_to_int32(strlen(mode[i].name) + 1); /* plus NULL */ - - rep.number = num; - rep.length = bytes_to_int32(size); - - WriteToClient(client, sz_xXDGAQueryModesReply, (char *) &rep); - - for (i = 0; i < num; i++) { - size = strlen(mode[i].name) + 1; - - info.byte_order = mode[i].byteOrder; - info.depth = mode[i].depth; - info.num = mode[i].num; - info.bpp = mode[i].bitsPerPixel; - info.name_size = (size + 3) & ~3L; - info.vsync_num = mode[i].VSync_num; - info.vsync_den = mode[i].VSync_den; - info.flags = mode[i].flags; - info.image_width = mode[i].imageWidth; - info.image_height = mode[i].imageHeight; - info.pixmap_width = mode[i].pixmapWidth; - info.pixmap_height = mode[i].pixmapHeight; - info.bytes_per_scanline = mode[i].bytesPerScanline; - info.red_mask = mode[i].red_mask; - info.green_mask = mode[i].green_mask; - info.blue_mask = mode[i].blue_mask; - info.visual_class = mode[i].visualClass; - info.viewport_width = mode[i].viewportWidth; - info.viewport_height = mode[i].viewportHeight; - info.viewport_xstep = mode[i].xViewportStep; - info.viewport_ystep = mode[i].yViewportStep; - info.viewport_xmax = mode[i].maxViewportX; - info.viewport_ymax = mode[i].maxViewportY; - info.viewport_flags = mode[i].viewportFlags; - info.reserved1 = mode[i].reserved1; - info.reserved2 = mode[i].reserved2; - - WriteToClient(client, sz_xXDGAModeInfo, (char *) (&info)); - WriteToClient(client, size, mode[i].name); - } - - free(mode); - - return Success; -} - -static void -DGAClientStateChange(CallbackListPtr *pcbl, void *nulldata, void *calldata) -{ - NewClientInfoRec *pci = (NewClientInfoRec *) calldata; - ClientPtr client = NULL; - int i; - - for (i = 0; i < screenInfo.numScreens; i++) { - if (DGA_GETCLIENT(i) == pci->client) { - client = pci->client; - break; - } - } - - if (client && - ((client->clientState == ClientStateGone) || - (client->clientState == ClientStateRetained))) { - XDGAModeRec mode; - PixmapPtr pPix; - - DGA_SETCLIENT(i, NULL); - DGASelectInput(i, NULL, 0); - DGASetMode(i, 0, &mode, &pPix); - - if (--DGACallbackRefCount == 0) - DeleteCallback(&ClientStateCallback, DGAClientStateChange, NULL); - } -} - -static int -ProcXDGASetMode(ClientPtr client) -{ - REQUEST(xXDGASetModeReq); - xXDGASetModeReply rep; - XDGAModeRec mode; - xXDGAModeInfo info; - PixmapPtr pPix; - ClientPtr owner; - int size; - - REQUEST_SIZE_MATCH(xXDGASetModeReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - owner = DGA_GETCLIENT(stuff->screen); - - rep.type = X_Reply; - rep.length = 0; - rep.offset = 0; - rep.flags = 0; - rep.sequenceNumber = client->sequence; - - if (!DGAAvailable(stuff->screen)) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - if (owner && owner != client) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - if (!stuff->mode) { - if (owner) { - if (--DGACallbackRefCount == 0) - DeleteCallback(&ClientStateCallback, DGAClientStateChange, - NULL); - } - DGA_SETCLIENT(stuff->screen, NULL); - DGASelectInput(stuff->screen, NULL, 0); - DGASetMode(stuff->screen, 0, &mode, &pPix); - WriteToClient(client, sz_xXDGASetModeReply, (char *) &rep); - return Success; - } - - if (Success != DGASetMode(stuff->screen, stuff->mode, &mode, &pPix)) - return BadValue; - - if (!owner) { - if (DGACallbackRefCount++ == 0) - AddCallback(&ClientStateCallback, DGAClientStateChange, NULL); - } - - DGA_SETCLIENT(stuff->screen, client); - - if (pPix) { - if (AddResource(stuff->pid, RT_PIXMAP, (void *) (pPix))) { - pPix->drawable.id = (int) stuff->pid; - rep.flags = DGA_PIXMAP_AVAILABLE; - } - } - - size = strlen(mode.name) + 1; - - info.byte_order = mode.byteOrder; - info.depth = mode.depth; - info.num = mode.num; - info.bpp = mode.bitsPerPixel; - info.name_size = (size + 3) & ~3L; - info.vsync_num = mode.VSync_num; - info.vsync_den = mode.VSync_den; - info.flags = mode.flags; - info.image_width = mode.imageWidth; - info.image_height = mode.imageHeight; - info.pixmap_width = mode.pixmapWidth; - info.pixmap_height = mode.pixmapHeight; - info.bytes_per_scanline = mode.bytesPerScanline; - info.red_mask = mode.red_mask; - info.green_mask = mode.green_mask; - info.blue_mask = mode.blue_mask; - info.visual_class = mode.visualClass; - info.viewport_width = mode.viewportWidth; - info.viewport_height = mode.viewportHeight; - info.viewport_xstep = mode.xViewportStep; - info.viewport_ystep = mode.yViewportStep; - info.viewport_xmax = mode.maxViewportX; - info.viewport_ymax = mode.maxViewportY; - info.viewport_flags = mode.viewportFlags; - info.reserved1 = mode.reserved1; - info.reserved2 = mode.reserved2; - - rep.length = bytes_to_int32(sz_xXDGAModeInfo + info.name_size); - - WriteToClient(client, sz_xXDGASetModeReply, (char *) &rep); - WriteToClient(client, sz_xXDGAModeInfo, (char *) (&info)); - WriteToClient(client, size, mode.name); - - return Success; -} - -static int -ProcXDGASetViewport(ClientPtr client) -{ - REQUEST(xXDGASetViewportReq); - - REQUEST_SIZE_MATCH(xXDGASetViewportReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - DGASetViewport(stuff->screen, stuff->x, stuff->y, stuff->flags); - - return Success; -} - -static int -ProcXDGAInstallColormap(ClientPtr client) -{ - ColormapPtr cmap; - int rc; - - REQUEST(xXDGAInstallColormapReq); - - REQUEST_SIZE_MATCH(xXDGAInstallColormapReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - rc = dixLookupResourceByType((void **) &cmap, stuff->cmap, RT_COLORMAP, - client, DixInstallAccess); - if (rc != Success) - return rc; - DGAInstallCmap(cmap); - return Success; -} - -static int -ProcXDGASelectInput(ClientPtr client) -{ - REQUEST(xXDGASelectInputReq); - - REQUEST_SIZE_MATCH(xXDGASelectInputReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - if (DGA_GETCLIENT(stuff->screen) == client) - DGASelectInput(stuff->screen, client, stuff->mask); - - return Success; -} - -static int -ProcXDGAFillRectangle(ClientPtr client) -{ - REQUEST(xXDGAFillRectangleReq); - - REQUEST_SIZE_MATCH(xXDGAFillRectangleReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - if (Success != DGAFillRect(stuff->screen, stuff->x, stuff->y, - stuff->width, stuff->height, stuff->color)) - return BadMatch; - - return Success; -} - -static int -ProcXDGACopyArea(ClientPtr client) -{ - REQUEST(xXDGACopyAreaReq); - - REQUEST_SIZE_MATCH(xXDGACopyAreaReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - if (Success != DGABlitRect(stuff->screen, stuff->srcx, stuff->srcy, - stuff->width, stuff->height, stuff->dstx, - stuff->dsty)) - return BadMatch; - - return Success; -} - -static int -ProcXDGACopyTransparentArea(ClientPtr client) -{ - REQUEST(xXDGACopyTransparentAreaReq); - - REQUEST_SIZE_MATCH(xXDGACopyTransparentAreaReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - if (Success != DGABlitTransRect(stuff->screen, stuff->srcx, stuff->srcy, - stuff->width, stuff->height, stuff->dstx, - stuff->dsty, stuff->key)) - return BadMatch; - - return Success; -} - -static int -ProcXDGAGetViewportStatus(ClientPtr client) -{ - REQUEST(xXDGAGetViewportStatusReq); - xXDGAGetViewportStatusReply rep; - - REQUEST_SIZE_MATCH(xXDGAGetViewportStatusReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - - rep.status = DGAGetViewportStatus(stuff->screen); - - WriteToClient(client, sizeof(xXDGAGetViewportStatusReply), (char *) &rep); - return Success; -} - -static int -ProcXDGASync(ClientPtr client) -{ - REQUEST(xXDGASyncReq); - xXDGASyncReply rep; - - REQUEST_SIZE_MATCH(xXDGASyncReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - - DGASync(stuff->screen); - - WriteToClient(client, sizeof(xXDGASyncReply), (char *) &rep); - return Success; -} - -static int -ProcXDGASetClientVersion(ClientPtr client) -{ - REQUEST(xXDGASetClientVersionReq); - - DGAPrivPtr pPriv; - - REQUEST_SIZE_MATCH(xXDGASetClientVersionReq); - if ((pPriv = DGA_GETPRIV(client)) == NULL) { - pPriv = malloc(sizeof(DGAPrivRec)); - /* XXX Need to look into freeing this */ - if (!pPriv) - return BadAlloc; - DGA_SETPRIV(client, pPriv); - } - pPriv->major = stuff->major; - pPriv->minor = stuff->minor; - - return Success; -} - -static int -ProcXDGAChangePixmapMode(ClientPtr client) -{ - REQUEST(xXDGAChangePixmapModeReq); - xXDGAChangePixmapModeReply rep; - int x, y; - - REQUEST_SIZE_MATCH(xXDGAChangePixmapModeReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - - x = stuff->x; - y = stuff->y; - - if (!DGAChangePixmapMode(stuff->screen, &x, &y, stuff->flags)) - return BadMatch; - - rep.x = x; - rep.y = y; - WriteToClient(client, sizeof(xXDGAChangePixmapModeReply), (char *) &rep); - - return Success; -} - -static int -ProcXDGACreateColormap(ClientPtr client) -{ - REQUEST(xXDGACreateColormapReq); - int result; - - REQUEST_SIZE_MATCH(xXDGACreateColormapReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - if (!stuff->mode) - return BadValue; - - result = DGACreateColormap(stuff->screen, client, stuff->id, - stuff->mode, stuff->alloc); - if (result != Success) - return result; - - return Success; -} - -/* - * - * Support for the old DGA protocol, used to live in xf86dga.c - * - */ - -#ifdef DGA_PROTOCOL_OLD_SUPPORT - -static int -ProcXF86DGAGetVideoLL(ClientPtr client) -{ - REQUEST(xXF86DGAGetVideoLLReq); - xXF86DGAGetVideoLLReply rep; - XDGAModeRec mode; - int num, offset, flags; - char *name; - - REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - - if (!DGAAvailable(stuff->screen)) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - if (!(num = DGAGetOldDGAMode(stuff->screen))) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - /* get the parameters for the mode that best matches */ - DGAGetModeInfo(stuff->screen, &mode, num); - - if (!DGAOpenFramebuffer(stuff->screen, &name, - (unsigned char **) (&rep.offset), - (int *) (&rep.bank_size), &offset, &flags)) - return BadAlloc; - - rep.offset += mode.offset; - rep.width = mode.bytesPerScanline / (mode.bitsPerPixel >> 3); - rep.ram_size = rep.bank_size >> 10; - - WriteToClient(client, SIZEOF(xXF86DGAGetVideoLLReply), (char *) &rep); - return Success; -} - -static int -ProcXF86DGADirectVideo(ClientPtr client) -{ - int num; - PixmapPtr pix; - XDGAModeRec mode; - ClientPtr owner; - - REQUEST(xXF86DGADirectVideoReq); - - REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (!DGAAvailable(stuff->screen)) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - owner = DGA_GETCLIENT(stuff->screen); - - if (owner && owner != client) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - if (stuff->enable & XF86DGADirectGraphics) { - if (!(num = DGAGetOldDGAMode(stuff->screen))) - return DGAErrorBase + XF86DGANoDirectVideoMode; - } - else - num = 0; - - if (Success != DGASetMode(stuff->screen, num, &mode, &pix)) - return DGAErrorBase + XF86DGAScreenNotActive; - - DGASetInputMode(stuff->screen, - (stuff->enable & XF86DGADirectKeyb) != 0, - (stuff->enable & XF86DGADirectMouse) != 0); - - /* We need to track the client and attach the teardown callback */ - if (stuff->enable & - (XF86DGADirectGraphics | XF86DGADirectKeyb | XF86DGADirectMouse)) { - if (!owner) { - if (DGACallbackRefCount++ == 0) - AddCallback(&ClientStateCallback, DGAClientStateChange, NULL); - } - - DGA_SETCLIENT(stuff->screen, client); - } - else { - if (owner) { - if (--DGACallbackRefCount == 0) - DeleteCallback(&ClientStateCallback, DGAClientStateChange, - NULL); - } - - DGA_SETCLIENT(stuff->screen, NULL); - } - - return Success; -} - -static int -ProcXF86DGAGetViewPortSize(ClientPtr client) -{ - int num; - XDGAModeRec mode; - - REQUEST(xXF86DGAGetViewPortSizeReq); - xXF86DGAGetViewPortSizeReply rep; - - REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - - if (!DGAAvailable(stuff->screen)) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - if (!(num = DGAGetOldDGAMode(stuff->screen))) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - DGAGetModeInfo(stuff->screen, &mode, num); - - rep.width = mode.viewportWidth; - rep.height = mode.viewportHeight; - - WriteToClient(client, SIZEOF(xXF86DGAGetViewPortSizeReply), (char *) &rep); - return Success; -} - -static int -ProcXF86DGASetViewPort(ClientPtr client) -{ - REQUEST(xXF86DGASetViewPortReq); - - REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - if (!DGAAvailable(stuff->screen)) - return DGAErrorBase + XF86DGANoDirectVideoMode; - - if (!DGAActive(stuff->screen)) - return DGAErrorBase + XF86DGADirectNotActivated; - - if (DGASetViewport(stuff->screen, stuff->x, stuff->y, DGA_FLIP_RETRACE) - != Success) - return DGAErrorBase + XF86DGADirectNotActivated; - - return Success; -} - -static int -ProcXF86DGAGetVidPage(ClientPtr client) -{ - REQUEST(xXF86DGAGetVidPageReq); - xXF86DGAGetVidPageReply rep; - - REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.vpage = 0; /* silently fail */ - - WriteToClient(client, SIZEOF(xXF86DGAGetVidPageReply), (char *) &rep); - return Success; -} - -static int -ProcXF86DGASetVidPage(ClientPtr client) -{ - REQUEST(xXF86DGASetVidPageReq); - - REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - /* silently fail */ - - return Success; -} - -static int -ProcXF86DGAInstallColormap(ClientPtr client) -{ - ColormapPtr pcmp; - int rc; - - REQUEST(xXF86DGAInstallColormapReq); - - REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - if (!DGAActive(stuff->screen)) - return DGAErrorBase + XF86DGADirectNotActivated; - - rc = dixLookupResourceByType((void **) &pcmp, stuff->id, RT_COLORMAP, - client, DixInstallAccess); - if (rc == Success) { - DGAInstallCmap(pcmp); - return Success; - } - else { - return rc; - } -} - -static int -ProcXF86DGAQueryDirectVideo(ClientPtr client) -{ - REQUEST(xXF86DGAQueryDirectVideoReq); - xXF86DGAQueryDirectVideoReply rep; - - REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.flags = 0; - - if (DGAAvailable(stuff->screen)) - rep.flags = XF86DGADirectPresent; - - WriteToClient(client, SIZEOF(xXF86DGAQueryDirectVideoReply), (char *) &rep); - return Success; -} - -static int -ProcXF86DGAViewPortChanged(ClientPtr client) -{ - REQUEST(xXF86DGAViewPortChangedReq); - xXF86DGAViewPortChangedReply rep; - - REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq); - - if (stuff->screen >= screenInfo.numScreens) - return BadValue; - - if (DGA_GETCLIENT(stuff->screen) != client) - return DGAErrorBase + XF86DGADirectNotActivated; - - if (!DGAActive(stuff->screen)) - return DGAErrorBase + XF86DGADirectNotActivated; - - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.result = 1; - - WriteToClient(client, SIZEOF(xXF86DGAViewPortChangedReply), (char *) &rep); - return Success; -} - -#endif /* DGA_PROTOCOL_OLD_SUPPORT */ - -static int _X_COLD -SProcXDGADispatch(ClientPtr client) -{ - return DGAErrorBase + XF86DGAClientNotLocal; -} - -#if 0 -#define DGA_REQ_DEBUG -#endif - -#ifdef DGA_REQ_DEBUG -static char *dgaMinor[] = { - "QueryVersion", - "GetVideoLL", - "DirectVideo", - "GetViewPortSize", - "SetViewPort", - "GetVidPage", - "SetVidPage", - "InstallColormap", - "QueryDirectVideo", - "ViewPortChanged", - "10", - "11", - "QueryModes", - "SetMode", - "SetViewport", - "InstallColormap", - "SelectInput", - "FillRectangle", - "CopyArea", - "CopyTransparentArea", - "GetViewportStatus", - "Sync", - "OpenFramebuffer", - "CloseFramebuffer", - "SetClientVersion", - "ChangePixmapMode", - "CreateColormap", -}; -#endif - -static int -ProcXDGADispatch(ClientPtr client) -{ - REQUEST(xReq); - - if (!client->local) - return DGAErrorBase + XF86DGAClientNotLocal; - -#ifdef DGA_REQ_DEBUG - if (stuff->data <= X_XDGACreateColormap) - fprintf(stderr, " DGA %s\n", dgaMinor[stuff->data]); -#endif - - switch (stuff->data) { - /* - * DGA2 Protocol - */ - case X_XDGAQueryVersion: - return ProcXDGAQueryVersion(client); - case X_XDGAQueryModes: - return ProcXDGAQueryModes(client); - case X_XDGASetMode: - return ProcXDGASetMode(client); - case X_XDGAOpenFramebuffer: - return ProcXDGAOpenFramebuffer(client); - case X_XDGACloseFramebuffer: - return ProcXDGACloseFramebuffer(client); - case X_XDGASetViewport: - return ProcXDGASetViewport(client); - case X_XDGAInstallColormap: - return ProcXDGAInstallColormap(client); - case X_XDGASelectInput: - return ProcXDGASelectInput(client); - case X_XDGAFillRectangle: - return ProcXDGAFillRectangle(client); - case X_XDGACopyArea: - return ProcXDGACopyArea(client); - case X_XDGACopyTransparentArea: - return ProcXDGACopyTransparentArea(client); - case X_XDGAGetViewportStatus: - return ProcXDGAGetViewportStatus(client); - case X_XDGASync: - return ProcXDGASync(client); - case X_XDGASetClientVersion: - return ProcXDGASetClientVersion(client); - case X_XDGAChangePixmapMode: - return ProcXDGAChangePixmapMode(client); - case X_XDGACreateColormap: - return ProcXDGACreateColormap(client); - /* - * Old DGA Protocol - */ -#ifdef DGA_PROTOCOL_OLD_SUPPORT - case X_XF86DGAGetVideoLL: - return ProcXF86DGAGetVideoLL(client); - case X_XF86DGADirectVideo: - return ProcXF86DGADirectVideo(client); - case X_XF86DGAGetViewPortSize: - return ProcXF86DGAGetViewPortSize(client); - case X_XF86DGASetViewPort: - return ProcXF86DGASetViewPort(client); - case X_XF86DGAGetVidPage: - return ProcXF86DGAGetVidPage(client); - case X_XF86DGASetVidPage: - return ProcXF86DGASetVidPage(client); - case X_XF86DGAInstallColormap: - return ProcXF86DGAInstallColormap(client); - case X_XF86DGAQueryDirectVideo: - return ProcXF86DGAQueryDirectVideo(client); - case X_XF86DGAViewPortChanged: - return ProcXF86DGAViewPortChanged(client); -#endif /* DGA_PROTOCOL_OLD_SUPPORT */ - default: - return BadRequest; - } -} - -void -XFree86DGAExtensionInit(void) -{ - ExtensionEntry *extEntry; - - if (!dixRegisterPrivateKey(&DGAClientPrivateKeyRec, PRIVATE_CLIENT, 0)) - return; - - if (!dixRegisterPrivateKey(&DGAScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) - return; - - if ((extEntry = AddExtension(XF86DGANAME, - XF86DGANumberEvents, - XF86DGANumberErrors, - ProcXDGADispatch, - SProcXDGADispatch, - XDGAResetProc, StandardMinorOpcode))) { - int i; - - DGAReqCode = (unsigned char) extEntry->base; - DGAErrorBase = extEntry->errorBase; - DGAEventBase = extEntry->eventBase; - for (i = KeyPress; i <= MotionNotify; i++) - SetCriticalEvent(DGAEventBase + i); - } -} diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c deleted file mode 100644 index ee495483e..000000000 --- a/hw/xfree86/common/xf86DPMS.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains the DPMS functions required by the extension. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "globals.h" -#include "windowstr.h" -#include "xf86.h" -#include "xf86Priv.h" -#ifdef DPMSExtension -#include -#include "dpmsproc.h" -#endif -#ifdef XSERVER_LIBPCIACCESS -#include "xf86VGAarbiter.h" -#endif - -#ifdef DPMSExtension -static void -xf86DPMS(ScreenPtr pScreen, int level) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - if (pScrn->DPMSSet && pScrn->vtSema) { - xf86VGAarbiterLock(pScrn); - pScrn->DPMSSet(pScrn, level, 0); - xf86VGAarbiterUnlock(pScrn); - } -} -#endif - -Bool -xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags) -{ -#ifdef DPMSExtension - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - void *DPMSOpt; - MessageType enabled_from = X_DEFAULT; - Bool enabled = TRUE; - - DPMSOpt = xf86FindOption(pScrn->options, "dpms"); - if (DPMSDisabledSwitch) { - enabled_from = X_CMDLINE; - enabled = FALSE; - } - else if (DPMSOpt) { - enabled_from = X_CONFIG; - enabled = xf86CheckBoolOption(pScrn->options, "dpms", FALSE); - xf86MarkOptionUsed(DPMSOpt); - } - if (enabled) { - xf86DrvMsg(pScreen->myNum, enabled_from, "DPMS enabled\n"); - pScrn->DPMSSet = set; - pScreen->DPMS = xf86DPMS; - } - return TRUE; -#else - return FALSE; -#endif -} diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c deleted file mode 100644 index 395bbc7b3..000000000 --- a/hw/xfree86/common/xf86Events.c +++ /dev/null @@ -1,723 +0,0 @@ -/* - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Thomas Roell not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Thomas Roell makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * Copyright (c) 1994-2003 by The XFree86 Project, 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). - */ - -/* [JCH-96/01/21] Extended std reverse map to four buttons. */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include "misc.h" -#include "xf86.h" -#include "xf86Priv.h" -#define XF86_OS_PRIVS -#include "xf86_OSlib.h" -#include - -#ifdef XFreeXDGA -#include "dgaproc.h" -#endif - -#include -#include -#include "inputstr.h" -#include "xf86Xinput.h" - -#include "mi.h" -#include "mipointer.h" - -#include "xkbsrv.h" -#include "xkbstr.h" - -#ifdef DPMSExtension -#include -#include "dpmsproc.h" -#endif - -#include "xf86platformBus.h" -#include "systemd-logind.h" - -extern void (*xf86OSPMClose) (void); - -static void xf86VTSwitch(void); - -/* - * Allow arbitrary drivers or other XFree86 code to register with our main - * Wakeup handler. - */ -typedef struct x_IHRec { - int fd; - InputHandlerProc ihproc; - void *data; - Bool enabled; - Bool is_input; - struct x_IHRec *next; -} IHRec, *IHPtr; - -static IHPtr InputHandlers = NULL; - -/* - * TimeSinceLastInputEvent -- - * Function used for screensaver purposes by the os module. Returns the - * time in milliseconds since there last was any input. - */ -int -TimeSinceLastInputEvent(void) -{ - if (xf86Info.lastEventTime == 0) { - xf86Info.lastEventTime = GetTimeInMillis(); - } - return GetTimeInMillis() - xf86Info.lastEventTime; -} - -/* - * SetTimeSinceLastInputEvent -- - * Set the lastEventTime to now. - */ -void -SetTimeSinceLastInputEvent(void) -{ - xf86Info.lastEventTime = GetTimeInMillis(); -} - -/* - * ProcessInputEvents -- - * Retrieve all waiting input events and pass them to DIX in their - * correct chronological order. Only reads from the system pointer - * and keyboard. - */ -void -ProcessInputEvents(void) -{ - int x, y; - - mieqProcessInputEvents(); - - /* FIXME: This is a problem if we have multiple pointers */ - miPointerGetPosition(inputInfo.pointer, &x, &y); - - xf86SetViewport(xf86Info.currentScreen, x, y); -} - -/* - * Handle keyboard events that cause some kind of "action" - * (i.e., server termination, video mode changes, VT switches, etc.) - */ -void -xf86ProcessActionEvent(ActionEvent action, void *arg) -{ - DebugF("ProcessActionEvent(%d,%p)\n", (int) action, arg); - switch (action) { - case ACTION_TERMINATE: - if (!xf86Info.dontZap) { - xf86Msg(X_INFO, "Server zapped. Shutting down.\n"); - GiveUp(0); - } - break; - case ACTION_NEXT_MODE: - if (!xf86Info.dontZoom) - xf86ZoomViewport(xf86Info.currentScreen, 1); - break; - case ACTION_PREV_MODE: - if (!xf86Info.dontZoom) - xf86ZoomViewport(xf86Info.currentScreen, -1); - break; - case ACTION_SWITCHSCREEN: - if (!xf86Info.dontVTSwitch && arg) { - int vtno = *((int *) arg); - - if (vtno != xf86Info.vtno) { - if (!xf86VTActivate(vtno)) { - ErrorF("Failed to switch from vt%02d to vt%02d: %s\n", - xf86Info.vtno, vtno, strerror(errno)); - } - } - } - break; - case ACTION_SWITCHSCREEN_NEXT: - if (!xf86Info.dontVTSwitch) { - if (!xf86VTActivate(xf86Info.vtno + 1)) { - /* If first try failed, assume this is the last VT and - * try wrapping around to the first vt. - */ - if (!xf86VTActivate(1)) { - ErrorF("Failed to switch from vt%02d to next vt: %s\n", - xf86Info.vtno, strerror(errno)); - } - } - } - break; - case ACTION_SWITCHSCREEN_PREV: - if (!xf86Info.dontVTSwitch && xf86Info.vtno > 0) { - if (!xf86VTActivate(xf86Info.vtno - 1)) { - /* Don't know what the maximum VT is, so can't wrap around */ - ErrorF("Failed to switch from vt%02d to previous vt: %s\n", - xf86Info.vtno, strerror(errno)); - } - } - break; - default: - break; - } -} - -/* - * xf86Wakeup -- - * Os wakeup handler. - */ - -/* ARGSUSED */ -void -xf86Wakeup(void *blockData, int err) -{ - if (xf86VTSwitchPending()) - xf86VTSwitch(); -} - -/* - * xf86ReadInput -- - * input thread handler - */ - -static void -xf86ReadInput(int fd, int ready, void *closure) -{ - InputInfoPtr pInfo = closure; - - pInfo->read_input(pInfo); -} - -/* - * xf86AddEnabledDevice -- - * - */ -void -xf86AddEnabledDevice(InputInfoPtr pInfo) -{ - InputThreadRegisterDev(pInfo->fd, xf86ReadInput, pInfo); -} - -/* - * xf86RemoveEnabledDevice -- - * - */ -void -xf86RemoveEnabledDevice(InputInfoPtr pInfo) -{ - InputThreadUnregisterDev(pInfo->fd); -} - -/* - * xf86PrintBacktrace -- - * Print a stack backtrace for debugging purposes. - */ -void -xf86PrintBacktrace(void) -{ - xorg_backtrace(); -} - -static void -xf86ReleaseKeys(DeviceIntPtr pDev) -{ - KeyClassPtr keyc; - int i; - - if (!pDev || !pDev->key) - return; - - keyc = pDev->key; - - /* - * Hmm... here is the biggest hack of every time ! - * It may be possible that a switch-vt procedure has finished BEFORE - * you released all keys necessary to do this. That peculiar behavior - * can fool the X-server pretty much, cause it assumes that some keys - * were not released. TWM may stuck almost completely.... - * OK, what we are doing here is after returning from the vt-switch - * explicitly unrelease all keyboard keys before the input-devices - * are re-enabled. - */ - - for (i = keyc->xkbInfo->desc->min_key_code; - i < keyc->xkbInfo->desc->max_key_code; i++) { - if (key_is_down(pDev, i, KEY_POSTED)) { - input_lock(); - QueueKeyboardEvents(pDev, KeyRelease, i); - input_unlock(); - } - } -} - -void -xf86DisableInputDeviceForVTSwitch(InputInfoPtr pInfo) -{ - if (!pInfo->dev) - return; - - if (!pInfo->dev->enabled) - pInfo->flags |= XI86_DEVICE_DISABLED; - - xf86ReleaseKeys(pInfo->dev); - ProcessInputEvents(); - DisableDevice(pInfo->dev, TRUE); -} - -void -xf86EnableInputDeviceForVTSwitch(InputInfoPtr pInfo) -{ - if (pInfo->dev && (pInfo->flags & XI86_DEVICE_DISABLED) == 0) - EnableDevice(pInfo->dev, TRUE); - pInfo->flags &= ~XI86_DEVICE_DISABLED; -} - -/* - * xf86UpdateHasVTProperty -- - * Update a flag property on the root window to say whether the server VT - * is currently the active one as some clients need to know this. - */ -static void -xf86UpdateHasVTProperty(Bool hasVT) -{ - Atom property_name; - int32_t value = hasVT ? 1 : 0; - int i; - - property_name = MakeAtom(HAS_VT_ATOM_NAME, sizeof(HAS_VT_ATOM_NAME) - 1, - FALSE); - if (property_name == BAD_RESOURCE) - FatalError("Failed to retrieve \"HAS_VT\" atom\n"); - for (i = 0; i < xf86NumScreens; i++) { - dixChangeWindowProperty(serverClient, - xf86ScrnToScreen(xf86Screens[i])->root, - property_name, XA_INTEGER, 32, - PropModeReplace, 1, &value, TRUE); - } -} - -void -xf86VTLeave(void) -{ - int i; - InputInfoPtr pInfo; - IHPtr ih; - - DebugF("xf86VTSwitch: Leaving, xf86Exiting is %s\n", - BOOLTOSTRING((dispatchException & DE_TERMINATE) ? TRUE : FALSE)); -#ifdef DPMSExtension - if (DPMSPowerLevel != DPMSModeOn) - DPMSSet(serverClient, DPMSModeOn); -#endif - for (i = 0; i < xf86NumScreens; i++) { - if (!(dispatchException & DE_TERMINATE)) - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], FALSE); - } - - /* - * Keep the order: Disable Device > LeaveVT - * EnterVT > EnableDevice - */ - for (ih = InputHandlers; ih; ih = ih->next) { - if (ih->is_input) - xf86DisableInputHandler(ih); - else - xf86DisableGeneralHandler(ih); - } - for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) - xf86DisableInputDeviceForVTSwitch(pInfo); - - input_lock(); - for (i = 0; i < xf86NumScreens; i++) - xf86Screens[i]->LeaveVT(xf86Screens[i]); - for (i = 0; i < xf86NumGPUScreens; i++) - xf86GPUScreens[i]->LeaveVT(xf86GPUScreens[i]); - - if (systemd_logind_controls_session()) { - systemd_logind_drop_master(); - } - - if (!xf86VTSwitchAway()) - goto switch_failed; - - if (xf86OSPMClose) - xf86OSPMClose(); - xf86OSPMClose = NULL; - - for (i = 0; i < xf86NumScreens; i++) { - /* - * zero all access functions to - * trap calls when switched away. - */ - xf86Screens[i]->vtSema = FALSE; - } - if (xorgHWAccess) - xf86DisableIO(); - - xf86UpdateHasVTProperty(FALSE); - - return; - -switch_failed: - DebugF("xf86VTSwitch: Leave failed\n"); - for (i = 0; i < xf86NumScreens; i++) { - if (!xf86Screens[i]->EnterVT(xf86Screens[i])) - FatalError("EnterVT failed for screen %d\n", i); - } - for (i = 0; i < xf86NumGPUScreens; i++) { - if (!xf86GPUScreens[i]->EnterVT(xf86GPUScreens[i])) - FatalError("EnterVT failed for gpu screen %d\n", i); - } - if (!(dispatchException & DE_TERMINATE)) { - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE); - } - } - dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); - - for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) - xf86EnableInputDeviceForVTSwitch(pInfo); - for (ih = InputHandlers; ih; ih = ih->next) { - if (ih->is_input) - xf86EnableInputHandler(ih); - else - xf86EnableGeneralHandler(ih); - } - input_unlock(); -} - -void -xf86VTEnter(void) -{ - int i; - InputInfoPtr pInfo; - IHPtr ih; - - DebugF("xf86VTSwitch: Entering\n"); - if (!xf86VTSwitchTo()) - return; - - xf86OSPMClose = xf86OSPMOpen(); - - if (xorgHWAccess) - xf86EnableIO(); - for (i = 0; i < xf86NumScreens; i++) { - xf86Screens[i]->vtSema = TRUE; - if (!xf86Screens[i]->EnterVT(xf86Screens[i])) - FatalError("EnterVT failed for screen %d\n", i); - } - for (i = 0; i < xf86NumGPUScreens; i++) { - xf86GPUScreens[i]->vtSema = TRUE; - if (!xf86GPUScreens[i]->EnterVT(xf86GPUScreens[i])) - FatalError("EnterVT failed for gpu screen %d\n", i); - } - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE); - } - - /* Turn screen saver off when switching back */ - dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); - - for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) { - /* Devices with server managed fds get enabled on logind resume */ - if (!(pInfo->flags & XI86_SERVER_FD)) - xf86EnableInputDeviceForVTSwitch(pInfo); - } - - for (ih = InputHandlers; ih; ih = ih->next) { - if (ih->is_input) - xf86EnableInputHandler(ih); - else - xf86EnableGeneralHandler(ih); - } -#ifdef XSERVER_PLATFORM_BUS - /* check for any new output devices */ - xf86platformVTProbe(); -#endif - - xf86UpdateHasVTProperty(TRUE); - - input_unlock(); -} - -/* - * xf86VTSwitch -- - * Handle requests for switching the vt. - */ -static void -xf86VTSwitch(void) -{ - DebugF("xf86VTSwitch()\n"); - -#ifdef XFreeXDGA - if (!DGAVTSwitch()) - return; -#endif - - /* - * Since all screens are currently all in the same state it is sufficient - * check the first. This might change in future. - * - * VTLeave is always handled here (VT_PROCESS guarantees this is safe), - * if we use systemd_logind xf86VTEnter() gets called by systemd-logind.c - * once it has resumed all drm nodes. - */ - if (xf86VTOwner()) - xf86VTLeave(); - else if (!systemd_logind_controls_session()) - xf86VTEnter(); -} - -/* Input handler registration */ - -static void -xf86InputHandlerNotify(int fd, int ready, void *data) -{ - IHPtr ih = data; - - if (ih->enabled && ih->fd >= 0 && ih->ihproc) { - ih->ihproc(ih->fd, ih->data); - } -} - -static void * -addInputHandler(int fd, InputHandlerProc proc, void *data) -{ - IHPtr ih; - - if (fd < 0 || !proc) - return NULL; - - ih = calloc(sizeof(*ih), 1); - if (!ih) - return NULL; - - ih->fd = fd; - ih->ihproc = proc; - ih->data = data; - ih->enabled = TRUE; - - if (!SetNotifyFd(fd, xf86InputHandlerNotify, X_NOTIFY_READ, ih)) { - free(ih); - return NULL; - } - - ih->next = InputHandlers; - InputHandlers = ih; - - return ih; -} - -void * -xf86AddInputHandler(int fd, InputHandlerProc proc, void *data) -{ - IHPtr ih = addInputHandler(fd, proc, data); - - if (ih) - ih->is_input = TRUE; - return ih; -} - -void * -xf86AddGeneralHandler(int fd, InputHandlerProc proc, void *data) -{ - IHPtr ih = addInputHandler(fd, proc, data); - - return ih; -} - -/** - * Set the handler for the console's fd. Replaces (and returns) the previous - * handler or NULL, whichever appropriate. - * proc may be NULL if the server should not handle events on the console. - */ -InputHandlerProc -xf86SetConsoleHandler(InputHandlerProc proc, void *data) -{ - static IHPtr handler = NULL; - InputHandlerProc old_proc = NULL; - - if (handler) { - old_proc = handler->ihproc; - xf86RemoveGeneralHandler(handler); - } - - handler = xf86AddGeneralHandler(xf86Info.consoleFd, proc, data); - - return old_proc; -} - -static void -removeInputHandler(IHPtr ih) -{ - IHPtr p; - - if (ih->fd >= 0) - RemoveNotifyFd(ih->fd); - if (ih == InputHandlers) - InputHandlers = ih->next; - else { - p = InputHandlers; - while (p && p->next != ih) - p = p->next; - if (ih) - p->next = ih->next; - } - free(ih); -} - -int -xf86RemoveInputHandler(void *handler) -{ - IHPtr ih; - int fd; - - if (!handler) - return -1; - - ih = handler; - fd = ih->fd; - - removeInputHandler(ih); - - return fd; -} - -int -xf86RemoveGeneralHandler(void *handler) -{ - IHPtr ih; - int fd; - - if (!handler) - return -1; - - ih = handler; - fd = ih->fd; - - removeInputHandler(ih); - - return fd; -} - -void -xf86DisableInputHandler(void *handler) -{ - IHPtr ih; - - if (!handler) - return; - - ih = handler; - ih->enabled = FALSE; - if (ih->fd >= 0) - RemoveNotifyFd(ih->fd); -} - -void -xf86DisableGeneralHandler(void *handler) -{ - IHPtr ih; - - if (!handler) - return; - - ih = handler; - ih->enabled = FALSE; - if (ih->fd >= 0) - RemoveNotifyFd(ih->fd); -} - -void -xf86EnableInputHandler(void *handler) -{ - IHPtr ih; - - if (!handler) - return; - - ih = handler; - ih->enabled = TRUE; - if (ih->fd >= 0) - SetNotifyFd(ih->fd, xf86InputHandlerNotify, X_NOTIFY_READ, ih); -} - -void -xf86EnableGeneralHandler(void *handler) -{ - IHPtr ih; - - if (!handler) - return; - - ih = handler; - ih->enabled = TRUE; - if (ih->fd >= 0) - SetNotifyFd(ih->fd, xf86InputHandlerNotify, X_NOTIFY_READ, ih); -} - -void -DDXRingBell(int volume, int pitch, int duration) -{ - xf86OSRingBell(volume, pitch, duration); -} - -Bool -xf86VTOwner(void) -{ - /* at system startup xf86Screens[0] won't be set - but we will own the VT */ - if (xf86NumScreens == 0) - return TRUE; - return xf86Screens[0]->vtSema; -} diff --git a/hw/xfree86/common/xf86Extensions.c b/hw/xfree86/common/xf86Extensions.c deleted file mode 100644 index 1b8b78505..000000000 --- a/hw/xfree86/common/xf86Extensions.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright © 2011 Daniel Stone - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Daniel Stone - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "extension.h" -#include "extinit.h" -#include "globals.h" - -#include "xf86.h" -#include "xf86Config.h" -#include "xf86Module.h" -#include "xf86Extensions.h" -#include "xf86Opt.h" -#include "optionstr.h" - -#ifdef XSELINUX -#include "xselinux.h" -#endif - -#ifdef XFreeXDGA -#include -#endif - -#ifdef XF86VIDMODE -#include -#include "vidmodestr.h" -#endif - -/* - * DDX-specific extensions. - */ -static const ExtensionModule extensionModules[] = { -#ifdef XF86VIDMODE - { - XFree86VidModeExtensionInit, - XF86VIDMODENAME, - &noXFree86VidModeExtension - }, -#endif -#ifdef XFreeXDGA - { - XFree86DGAExtensionInit, - XF86DGANAME, - &noXFree86DGAExtension - }, -#endif -#ifdef XF86DRI - { - XFree86DRIExtensionInit, - "XFree86-DRI", - &noXFree86DRIExtension - }, -#endif -#ifdef DRI2 - { - DRI2ExtensionInit, - DRI2_NAME, - &noDRI2Extension - } -#endif -}; - -static void -load_extension_config(void) -{ - XF86ConfModulePtr mod_con = xf86configptr->conf_modules; - XF86LoadPtr modp; - - /* Only the best. */ - if (!mod_con) - return; - - nt_list_for_each_entry(modp, mod_con->mod_load_lst, list.next) { - InputOption *opt; - - if (strcasecmp(modp->load_name, "extmod") != 0) - continue; - - /* extmod options are of the form "omit " */ - nt_list_for_each_entry(opt, modp->load_opt, list.next) { - const char *key = input_option_get_key(opt); - if (strncasecmp(key, "omit", 4) != 0 || strlen(key) < 5) - continue; - if (EnableDisableExtension(key + 4, FALSE)) - xf86MarkOptionUsed(opt); - } - -#ifdef XSELINUX - if ((opt = xf86FindOption(modp->load_opt, - "SELinux mode disabled"))) { - xf86MarkOptionUsed(opt); - selinuxEnforcingState = SELINUX_MODE_DISABLED; - } - if ((opt = xf86FindOption(modp->load_opt, - "SELinux mode permissive"))) { - xf86MarkOptionUsed(opt); - selinuxEnforcingState = SELINUX_MODE_PERMISSIVE; - } - if ((opt = xf86FindOption(modp->load_opt, - "SELinux mode enforcing"))) { - xf86MarkOptionUsed(opt); - selinuxEnforcingState = SELINUX_MODE_ENFORCING; - } -#endif - } -} - -void -xf86ExtensionInit(void) -{ - load_extension_config(); - - LoadExtensionList(extensionModules, ARRAY_SIZE(extensionModules), TRUE); -} diff --git a/hw/xfree86/common/xf86Extensions.h b/hw/xfree86/common/xf86Extensions.h deleted file mode 100644 index cad86c881..000000000 --- a/hw/xfree86/common/xf86Extensions.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © 2011 Daniel Stone - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Daniel Stone - */ - -#ifndef XF86EXTENSIONS_H -#define XF86EXTENSIONS_H - -#include "extnsionst.h" - -#ifdef XF86DRI -extern _X_EXPORT Bool noXFree86DRIExtension; -extern void XFree86DRIExtensionInit(void); -#endif - -#ifdef DRI2 -#include -extern _X_EXPORT Bool noDRI2Extension; -extern void DRI2ExtensionInit(void); -#endif - -#ifdef XF86VIDMODE -#include -extern _X_EXPORT Bool noXFree86VidModeExtension; -extern void XFree86VidModeExtensionInit(void); -#endif - -#ifdef XFreeXDGA -#include -extern _X_EXPORT Bool noXFree86DGAExtension; -extern void XFree86DGAExtensionInit(void); -extern void XFree86DGARegister(void); -#endif - -#endif diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c deleted file mode 100644 index 65a3192df..000000000 --- a/hw/xfree86/common/xf86Globals.c +++ /dev/null @@ -1,200 +0,0 @@ - -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains all the XFree86 global variables. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "windowstr.h" -#include "propertyst.h" -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86Parser.h" -#include "xf86Xinput.h" -#include "xf86InPriv.h" -#include "xf86Config.h" - -/* Globals that video drivers may access */ - -DevPrivateKeyRec xf86CreateRootWindowKeyRec; -DevPrivateKeyRec xf86ScreenKeyRec; - -ScrnInfoPtr *xf86Screens = NULL; /* List of ScrnInfos */ -ScrnInfoPtr *xf86GPUScreens = NULL; /* List of ScrnInfos */ - -int xf86DRMMasterFd = -1; /* Command line argument for DRM master file descriptor */ - -const unsigned char byte_reversed[256] = { - 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, - 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, - 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, - 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, - 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, - 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, - 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, - 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, - 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, - 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, - 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, - 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, - 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, - 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, - 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, - 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, - 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, - 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, - 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, - 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, - 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, - 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, - 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, - 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, - 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, - 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, - 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, - 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, - 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, - 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, - 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, - 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, -}; - -/* Globals that input drivers may access */ -InputInfoPtr xf86InputDevs = NULL; - -/* Globals that video drivers may not access */ - -xf86InfoRec xf86Info = { - .consoleFd = -1, - .vtno = -1, - .lastEventTime = -1, - .vtRequestsPending = FALSE, -#ifdef __sun - .vtPendingNum = -1, -#endif - .dontVTSwitch = FALSE, - .autoVTSwitch = TRUE, - .ShareVTs = FALSE, - .dontZap = FALSE, - .dontZoom = FALSE, - .currentScreen = NULL, -#ifdef CSRG_BASED - .consType = -1, -#endif - .allowMouseOpenFail = FALSE, - .vidModeEnabled = TRUE, - .vidModeAllowNonLocal = FALSE, - .miscModInDevEnabled = TRUE, - .miscModInDevAllowNonLocal = FALSE, - .pmFlag = TRUE, -#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) - .forceInputDevices = FALSE, - .autoAddDevices = TRUE, - .autoEnableDevices = TRUE, -#else - .forceInputDevices = TRUE, - .autoAddDevices = FALSE, - .autoEnableDevices = FALSE, -#endif -#if defined(CONFIG_UDEV_KMS) - .autoAddGPU = TRUE, -#else - .autoAddGPU = FALSE, -#endif - .autoBindGPU = TRUE, -}; - -const char *xf86ConfigFile = NULL; -const char *xf86ConfigDir = NULL; -const char *xf86ModulePath = DEFAULT_MODULE_PATH; -MessageType xf86ModPathFrom = X_DEFAULT; -const char *xf86LogFile = DEFAULT_LOGDIR "/" DEFAULT_LOGPREFIX; -MessageType xf86LogFileFrom = X_DEFAULT; -Bool xf86LogFileWasOpened = FALSE; -serverLayoutRec xf86ConfigLayout = { NULL, }; -confDRIRec xf86ConfigDRI = { 0, }; - -XF86ConfigPtr xf86configptr = NULL; -Bool xf86Resetting = FALSE; -Bool xf86Initialising = FALSE; -Bool xf86DoConfigure = FALSE; -Bool xf86ProbeIgnorePrimary = FALSE; -Bool xf86DoShowOptions = FALSE; -DriverPtr *xf86DriverList = NULL; -int xf86NumDrivers = 0; -InputDriverPtr *xf86InputDriverList = NULL; -int xf86NumInputDrivers = 0; -int xf86NumScreens = 0; -int xf86NumGPUScreens = 0; - -const char *xf86VisualNames[] = { - "StaticGray", - "GrayScale", - "StaticColor", - "PseudoColor", - "TrueColor", - "DirectColor" -}; - -/* Parameters set only from the command line */ -Bool xf86fpFlag = FALSE; -Bool xf86sFlag = FALSE; -Bool xf86bsEnableFlag = FALSE; -Bool xf86bsDisableFlag = FALSE; -Bool xf86silkenMouseDisableFlag = FALSE; -Bool xf86xkbdirFlag = FALSE; - -#ifdef HAVE_ACPI -Bool xf86acpiDisableFlag = FALSE; -#endif -char *xf86LayoutName = NULL; -char *xf86ScreenName = NULL; -char *xf86PointerName = NULL; -char *xf86KeyboardName = NULL; -int xf86Verbose = DEFAULT_VERBOSE; -int xf86LogVerbose = DEFAULT_LOG_VERBOSE; -int xf86FbBpp = -1; -int xf86Depth = -1; -rgb xf86Weight = { 0, 0, 0 }; - -Gamma xf86Gamma = { 0.0, 0.0, 0.0 }; - -Bool xf86AllowMouseOpenFail = FALSE; -Bool xf86AutoBindGPUDisabled = FALSE; - -#ifdef XF86VIDMODE -Bool xf86VidModeDisabled = FALSE; -Bool xf86VidModeAllowNonLocal = FALSE; -#endif -Bool xorgHWAccess = FALSE; diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c deleted file mode 100644 index 0389945a7..000000000 --- a/hw/xfree86/common/xf86Helper.c +++ /dev/null @@ -1,1755 +0,0 @@ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * Authors: Dirk Hohndel - * David Dawes - * ... and others - * - * This file includes the helper functions that the server provides for - * different drivers. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "mi.h" -#include "os.h" -#include "servermd.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "propertyst.h" -#include "gcstruct.h" -#include "loaderProcs.h" -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "micmap.h" -#include "xf86DDC.h" -#include "xf86Xinput.h" -#include "xf86InPriv.h" -#include "mivalidate.h" - -/* For xf86GetClocks */ -#if defined(CSRG_BASED) || defined(__GNU__) -#define HAS_SETPRIORITY -#include -#endif - -static int xf86ScrnInfoPrivateCount = 0; - -/* Add a pointer to a new DriverRec to xf86DriverList */ - -void -xf86AddDriver(DriverPtr driver, void *module, int flags) -{ - /* Don't add null entries */ - if (!driver) - return; - - if (xf86DriverList == NULL) - xf86NumDrivers = 0; - - xf86NumDrivers++; - xf86DriverList = xnfreallocarray(xf86DriverList, - xf86NumDrivers, sizeof(DriverPtr)); - xf86DriverList[xf86NumDrivers - 1] = xnfalloc(sizeof(DriverRec)); - *xf86DriverList[xf86NumDrivers - 1] = *driver; - xf86DriverList[xf86NumDrivers - 1]->module = module; - xf86DriverList[xf86NumDrivers - 1]->refCount = 0; -} - -void -xf86DeleteDriver(int drvIndex) -{ - if (xf86DriverList[drvIndex] - && (!xf86DriverHasEntities(xf86DriverList[drvIndex]))) { - if (xf86DriverList[drvIndex]->module) - UnloadModule(xf86DriverList[drvIndex]->module); - free(xf86DriverList[drvIndex]); - xf86DriverList[drvIndex] = NULL; - } -} - -/* Add a pointer to a new InputDriverRec to xf86InputDriverList */ - -void -xf86AddInputDriver(InputDriverPtr driver, void *module, int flags) -{ - /* Don't add null entries */ - if (!driver) - return; - - if (xf86InputDriverList == NULL) - xf86NumInputDrivers = 0; - - xf86NumInputDrivers++; - xf86InputDriverList = xnfreallocarray(xf86InputDriverList, - xf86NumInputDrivers, - sizeof(InputDriverPtr)); - xf86InputDriverList[xf86NumInputDrivers - 1] = - xnfalloc(sizeof(InputDriverRec)); - *xf86InputDriverList[xf86NumInputDrivers - 1] = *driver; - xf86InputDriverList[xf86NumInputDrivers - 1]->module = module; -} - -void -xf86DeleteInputDriver(int drvIndex) -{ - if (xf86InputDriverList[drvIndex] && xf86InputDriverList[drvIndex]->module) - UnloadModule(xf86InputDriverList[drvIndex]->module); - free(xf86InputDriverList[drvIndex]); - xf86InputDriverList[drvIndex] = NULL; -} - -InputDriverPtr -xf86LookupInputDriver(const char *name) -{ - int i; - - for (i = 0; i < xf86NumInputDrivers; i++) { - if (xf86InputDriverList[i] && xf86InputDriverList[i]->driverName && - xf86NameCmp(name, xf86InputDriverList[i]->driverName) == 0) - return xf86InputDriverList[i]; - } - return NULL; -} - -InputInfoPtr -xf86LookupInput(const char *name) -{ - InputInfoPtr p; - - for (p = xf86InputDevs; p != NULL; p = p->next) { - if (strcmp(name, p->name) == 0) - return p; - } - - return NULL; -} - -/* Allocate a new ScrnInfoRec in xf86Screens */ - -ScrnInfoPtr -xf86AllocateScreen(DriverPtr drv, int flags) -{ - int i; - ScrnInfoPtr pScrn; - - if (flags & XF86_ALLOCATE_GPU_SCREEN) { - if (xf86GPUScreens == NULL) - xf86NumGPUScreens = 0; - i = xf86NumGPUScreens++; - xf86GPUScreens = xnfreallocarray(xf86GPUScreens, xf86NumGPUScreens, - sizeof(ScrnInfoPtr)); - xf86GPUScreens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1); - pScrn = xf86GPUScreens[i]; - pScrn->scrnIndex = i + GPU_SCREEN_OFFSET; /* Changes when a screen is removed */ - pScrn->is_gpu = TRUE; - } else { - if (xf86Screens == NULL) - xf86NumScreens = 0; - - i = xf86NumScreens++; - xf86Screens = xnfreallocarray(xf86Screens, xf86NumScreens, - sizeof(ScrnInfoPtr)); - xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1); - pScrn = xf86Screens[i]; - - pScrn->scrnIndex = i; /* Changes when a screen is removed */ - } - - pScrn->origIndex = pScrn->scrnIndex; /* This never changes */ - pScrn->privates = xnfcalloc(sizeof(DevUnion), xf86ScrnInfoPrivateCount); - /* - * EnableDisableFBAccess now gets initialized in InitOutput() - * pScrn->EnableDisableFBAccess = xf86EnableDisableFBAccess; - */ - - pScrn->drv = drv; - drv->refCount++; - pScrn->module = DuplicateModule(drv->module, NULL); - - pScrn->DriverFunc = drv->driverFunc; - - return pScrn; -} - -/* - * Remove an entry from xf86Screens. Ideally it should free all allocated - * data. To do this properly may require a driver hook. - */ - -void -xf86DeleteScreen(ScrnInfoPtr pScrn) -{ - int i; - int scrnIndex; - Bool is_gpu = FALSE; - - if (!pScrn) - return; - - if (pScrn->is_gpu) { - /* First check if the screen is valid */ - if (xf86NumGPUScreens == 0 || xf86GPUScreens == NULL) - return; - is_gpu = TRUE; - } else { - /* First check if the screen is valid */ - if (xf86NumScreens == 0 || xf86Screens == NULL) - return; - } - - scrnIndex = pScrn->scrnIndex; - /* If a FreeScreen function is defined, call it here */ - if (pScrn->FreeScreen != NULL) - pScrn->FreeScreen(pScrn); - - while (pScrn->modes) - xf86DeleteMode(&pScrn->modes, pScrn->modes); - - while (pScrn->modePool) - xf86DeleteMode(&pScrn->modePool, pScrn->modePool); - - xf86OptionListFree(pScrn->options); - - if (pScrn->module) - UnloadModule(pScrn->module); - - if (pScrn->drv) - pScrn->drv->refCount--; - - free(pScrn->privates); - - xf86ClearEntityListForScreen(pScrn); - - free(pScrn); - - /* Move the other entries down, updating their scrnIndex fields */ - - if (is_gpu) { - xf86NumGPUScreens--; - scrnIndex -= GPU_SCREEN_OFFSET; - for (i = scrnIndex; i < xf86NumGPUScreens; i++) { - xf86GPUScreens[i] = xf86GPUScreens[i + 1]; - xf86GPUScreens[i]->scrnIndex = i + GPU_SCREEN_OFFSET; - /* Also need to take care of the screen layout settings */ - } - } - else { - xf86NumScreens--; - - for (i = scrnIndex; i < xf86NumScreens; i++) { - xf86Screens[i] = xf86Screens[i + 1]; - xf86Screens[i]->scrnIndex = i; - /* Also need to take care of the screen layout settings */ - } - } -} - -/* - * Allocate a private in ScrnInfoRec. - */ - -int -xf86AllocateScrnInfoPrivateIndex(void) -{ - int idx, i; - ScrnInfoPtr pScr; - DevUnion *nprivs; - - idx = xf86ScrnInfoPrivateCount++; - for (i = 0; i < xf86NumScreens; i++) { - pScr = xf86Screens[i]; - nprivs = xnfreallocarray(pScr->privates, - xf86ScrnInfoPrivateCount, sizeof(DevUnion)); - /* Zero the new private */ - memset(&nprivs[idx], 0, sizeof(DevUnion)); - pScr->privates = nprivs; - } - for (i = 0; i < xf86NumGPUScreens; i++) { - pScr = xf86GPUScreens[i]; - nprivs = xnfreallocarray(pScr->privates, - xf86ScrnInfoPrivateCount, sizeof(DevUnion)); - /* Zero the new private */ - memset(&nprivs[idx], 0, sizeof(DevUnion)); - pScr->privates = nprivs; - } - return idx; -} - -Bool -xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp, int pad) -{ - int i; - - if (pScrn->numFormats >= MAXFORMATS) - return FALSE; - - if (bpp <= 0) { - if (depth == 1) - bpp = 1; - else if (depth <= 8) - bpp = 8; - else if (depth <= 16) - bpp = 16; - else if (depth <= 32) - bpp = 32; - else - return FALSE; - } - if (pad <= 0) - pad = BITMAP_SCANLINE_PAD; - - i = pScrn->numFormats++; - pScrn->formats[i].depth = depth; - pScrn->formats[i].bitsPerPixel = bpp; - pScrn->formats[i].scanlinePad = pad; - return TRUE; -} - -/* - * Set the depth we are using based on (in the following order of preference): - * - values given on the command line - * - values given in the config file - * - values provided by the driver - * - an overall default when nothing else is given - * - * Also find a Display subsection matching the depth/bpp found. - * - * Sets the following ScrnInfoRec fields: - * bitsPerPixel, depth, display, imageByteOrder, - * bitmapScanlinePad, bitmapScanlineUnit, bitmapBitOrder, numFormats, - * formats, fbFormat. - */ - -/* Can the screen handle 32 bpp pixmaps */ -#define DO_PIX32(f) ((f & Support32bppFb) || \ - ((f & Support24bppFb) && (f & SupportConvert32to24))) - -#ifndef GLOBAL_DEFAULT_DEPTH -#define GLOBAL_DEFAULT_DEPTH 24 -#endif - -Bool -xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp, - int depth24flags) -{ - int i; - DispPtr disp; - - scrp->bitsPerPixel = -1; - scrp->depth = -1; - scrp->bitsPerPixelFrom = X_DEFAULT; - scrp->depthFrom = X_DEFAULT; - - if (xf86FbBpp > 0) { - if (xf86FbBpp == 24) /* lol no */ - xf86FbBpp = 32; - scrp->bitsPerPixel = xf86FbBpp; - scrp->bitsPerPixelFrom = X_CMDLINE; - } - - if (xf86Depth > 0) { - scrp->depth = xf86Depth; - scrp->depthFrom = X_CMDLINE; - } - - if (xf86FbBpp < 0 && xf86Depth < 0) { - if (scrp->confScreen->defaultfbbpp > 0) { - scrp->bitsPerPixel = scrp->confScreen->defaultfbbpp; - scrp->bitsPerPixelFrom = X_CONFIG; - } - if (scrp->confScreen->defaultdepth > 0) { - scrp->depth = scrp->confScreen->defaultdepth; - scrp->depthFrom = X_CONFIG; - } - - if (scrp->confScreen->defaultfbbpp <= 0 && - scrp->confScreen->defaultdepth <= 0) { - /* - * Check for DefaultDepth and DefaultFbBpp options in the - * Device sections. - */ - GDevPtr device; - Bool found = FALSE; - - for (i = 0; i < scrp->numEntities; i++) { - device = xf86GetDevFromEntity(scrp->entityList[i], - scrp->entityInstanceList[i]); - if (device && device->options) { - if (xf86FindOption(device->options, "DefaultDepth")) { - scrp->depth = xf86SetIntOption(device->options, - "DefaultDepth", -1); - scrp->depthFrom = X_CONFIG; - found = TRUE; - } - if (xf86FindOption(device->options, "DefaultFbBpp")) { - scrp->bitsPerPixel = xf86SetIntOption(device->options, - "DefaultFbBpp", - -1); - scrp->bitsPerPixelFrom = X_CONFIG; - found = TRUE; - } - } - if (found) - break; - } - } - } - - /* If none of these is set, pick a default */ - if (scrp->bitsPerPixel < 0 && scrp->depth < 0) { - if (fbbpp > 0 || depth > 0) { - if (fbbpp > 0) - scrp->bitsPerPixel = fbbpp; - if (depth > 0) - scrp->depth = depth; - } - else { - scrp->depth = GLOBAL_DEFAULT_DEPTH; - } - } - - /* If any are not given, determine a default for the others */ - - if (scrp->bitsPerPixel < 0) { - /* The depth must be set */ - if (scrp->depth > -1) { - if (scrp->depth == 1) - scrp->bitsPerPixel = 1; - else if (scrp->depth <= 4) - scrp->bitsPerPixel = 4; - else if (scrp->depth <= 8) - scrp->bitsPerPixel = 8; - else if (scrp->depth <= 16) - scrp->bitsPerPixel = 16; - else if (scrp->depth <= 24 && DO_PIX32(depth24flags)) { - scrp->bitsPerPixel = 32; - } - else if (scrp->depth <= 32) - scrp->bitsPerPixel = 32; - else { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "No bpp for depth (%d)\n", scrp->depth); - return FALSE; - } - } - else { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "xf86SetDepthBpp: internal error: depth and fbbpp" - " are both not set\n"); - return FALSE; - } - if (scrp->bitsPerPixel < 0) { - if ((depth24flags & (Support24bppFb | Support32bppFb)) == - NoDepth24Support) - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Driver can't support depth 24\n"); - else - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Can't find fbbpp for depth 24\n"); - return FALSE; - } - scrp->bitsPerPixelFrom = X_PROBED; - } - - if (scrp->depth <= 0) { - /* bitsPerPixel is already set */ - switch (scrp->bitsPerPixel) { - case 32: - scrp->depth = 24; - break; - default: - /* 1, 4, 8, 16 and 24 */ - scrp->depth = scrp->bitsPerPixel; - break; - } - scrp->depthFrom = X_PROBED; - } - - /* Sanity checks */ - if (scrp->depth < 1 || scrp->depth > 32) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Specified depth (%d) is not in the range 1-32\n", - scrp->depth); - return FALSE; - } - switch (scrp->bitsPerPixel) { - case 1: - case 4: - case 8: - case 16: - case 32: - break; - default: - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Specified fbbpp (%d) is not a permitted value\n", - scrp->bitsPerPixel); - return FALSE; - } - if (scrp->depth > scrp->bitsPerPixel) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Specified depth (%d) is greater than the fbbpp (%d)\n", - scrp->depth, scrp->bitsPerPixel); - return FALSE; - } - - /* - * Find the Display subsection matching the depth/fbbpp and initialise - * scrp->display with it. - */ - for (i = 0; i < scrp->confScreen->numdisplays; i++) { - disp = scrp->confScreen->displays[i]; - if ((disp->depth == scrp->depth && disp->fbbpp == scrp->bitsPerPixel) - || (disp->depth == scrp->depth && disp->fbbpp <= 0) - || (disp->fbbpp == scrp->bitsPerPixel && disp->depth <= 0)) { - scrp->display = disp; - break; - } - } - - /* - * If an exact match can't be found, see if there is one with no - * depth or fbbpp specified. - */ - if (i == scrp->confScreen->numdisplays) { - for (i = 0; i < scrp->confScreen->numdisplays; i++) { - disp = scrp->confScreen->displays[i]; - if (disp->depth <= 0 && disp->fbbpp <= 0) { - scrp->display = disp; - break; - } - } - } - - /* - * If all else fails, create a default one. - */ - if (i == scrp->confScreen->numdisplays) { - scrp->confScreen->numdisplays++; - scrp->confScreen->displays = - xnfreallocarray(scrp->confScreen->displays, - scrp->confScreen->numdisplays, sizeof(DispPtr)); - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Creating default Display subsection in Screen section\n" - "\t\"%s\" for depth/fbbpp %d/%d\n", - scrp->confScreen->id, scrp->depth, scrp->bitsPerPixel); - scrp->confScreen->displays[i] = xnfcalloc(1, sizeof(DispRec)); - memset(scrp->confScreen->displays[i], 0, sizeof(DispRec)); - scrp->confScreen->displays[i]->blackColour.red = -1; - scrp->confScreen->displays[i]->blackColour.green = -1; - scrp->confScreen->displays[i]->blackColour.blue = -1; - scrp->confScreen->displays[i]->whiteColour.red = -1; - scrp->confScreen->displays[i]->whiteColour.green = -1; - scrp->confScreen->displays[i]->whiteColour.blue = -1; - scrp->confScreen->displays[i]->defaultVisual = -1; - scrp->confScreen->displays[i]->modes = xnfalloc(sizeof(char *)); - scrp->confScreen->displays[i]->modes[0] = NULL; - scrp->confScreen->displays[i]->depth = depth; - scrp->confScreen->displays[i]->fbbpp = fbbpp; - scrp->display = scrp->confScreen->displays[i]; - } - - /* - * Setup defaults for the display-wide attributes the framebuffer will - * need. These defaults should eventually be set globally, and not - * dependent on the screens. - */ - scrp->imageByteOrder = IMAGE_BYTE_ORDER; - scrp->bitmapScanlinePad = BITMAP_SCANLINE_PAD; - if (scrp->depth < 8) { - /* Planar modes need these settings */ - scrp->bitmapScanlineUnit = 8; - scrp->bitmapBitOrder = MSBFirst; - } - else { - scrp->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; - scrp->bitmapBitOrder = BITMAP_BIT_ORDER; - } - - /* - * If an unusual depth is required, add it to scrp->formats. The formats - * for the common depths are handled globally in InitOutput - */ - switch (scrp->depth) { - case 1: - case 4: - case 8: - case 15: - case 16: - case 24: - /* Common depths. Nothing to do for them */ - break; - default: - if (!xf86AddPixFormat(scrp, scrp->depth, 0, 0)) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Can't add pixmap format for depth %d\n", scrp->depth); - return FALSE; - } - } - - /* Initialise the framebuffer format for this screen */ - scrp->fbFormat.depth = scrp->depth; - scrp->fbFormat.bitsPerPixel = scrp->bitsPerPixel; - scrp->fbFormat.scanlinePad = BITMAP_SCANLINE_PAD; - - return TRUE; -} - -/* - * Print out the selected depth and bpp. - */ -void -xf86PrintDepthBpp(ScrnInfoPtr scrp) -{ - xf86DrvMsg(scrp->scrnIndex, scrp->depthFrom, "Depth %d, ", scrp->depth); - xf86Msg(scrp->bitsPerPixelFrom, "framebuffer bpp %d\n", scrp->bitsPerPixel); -} - -/* - * xf86SetWeight sets scrp->weight, scrp->mask, scrp->offset, and for depths - * greater than MAX_PSEUDO_DEPTH also scrp->rgbBits. - */ -Bool -xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask) -{ - MessageType weightFrom = X_DEFAULT; - - scrp->weight.red = 0; - scrp->weight.green = 0; - scrp->weight.blue = 0; - - if (xf86Weight.red > 0 && xf86Weight.green > 0 && xf86Weight.blue > 0) { - scrp->weight = xf86Weight; - weightFrom = X_CMDLINE; - } - else if (scrp->display->weight.red > 0 && scrp->display->weight.green > 0 - && scrp->display->weight.blue > 0) { - scrp->weight = scrp->display->weight; - weightFrom = X_CONFIG; - } - else if (weight.red > 0 && weight.green > 0 && weight.blue > 0) { - scrp->weight = weight; - } - else { - switch (scrp->depth) { - case 1: - case 4: - case 8: - scrp->weight.red = scrp->weight.green = - scrp->weight.blue = scrp->rgbBits; - break; - case 15: - scrp->weight.red = scrp->weight.green = scrp->weight.blue = 5; - break; - case 16: - scrp->weight.red = scrp->weight.blue = 5; - scrp->weight.green = 6; - break; - case 18: - scrp->weight.red = scrp->weight.green = scrp->weight.blue = 6; - break; - case 24: - scrp->weight.red = scrp->weight.green = scrp->weight.blue = 8; - break; - case 30: - scrp->weight.red = scrp->weight.green = scrp->weight.blue = 10; - break; - } - } - - if (scrp->weight.red) - xf86DrvMsg(scrp->scrnIndex, weightFrom, "RGB weight %d%d%d\n", - (int) scrp->weight.red, (int) scrp->weight.green, - (int) scrp->weight.blue); - - if (scrp->depth > MAX_PSEUDO_DEPTH && - (scrp->depth != scrp->weight.red + scrp->weight.green + - scrp->weight.blue)) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Weight given (%d%d%d) is inconsistent with the " - "depth (%d)\n", - (int) scrp->weight.red, (int) scrp->weight.green, - (int) scrp->weight.blue, scrp->depth); - return FALSE; - } - if (scrp->depth > MAX_PSEUDO_DEPTH && scrp->weight.red) { - /* - * XXX Does this even mean anything for TrueColor visuals? - * If not, we shouldn't even be setting it here. However, this - * matches the behaviour of 3.x versions of XFree86. - */ - scrp->rgbBits = scrp->weight.red; - if (scrp->weight.green > scrp->rgbBits) - scrp->rgbBits = scrp->weight.green; - if (scrp->weight.blue > scrp->rgbBits) - scrp->rgbBits = scrp->weight.blue; - } - - /* Set the mask and offsets */ - if (mask.red == 0 || mask.green == 0 || mask.blue == 0) { - /* Default to a setting common to PC hardware */ - scrp->offset.red = scrp->weight.green + scrp->weight.blue; - scrp->offset.green = scrp->weight.blue; - scrp->offset.blue = 0; - scrp->mask.red = ((1 << scrp->weight.red) - 1) << scrp->offset.red; - scrp->mask.green = ((1 << scrp->weight.green) - 1) - << scrp->offset.green; - scrp->mask.blue = (1 << scrp->weight.blue) - 1; - } - else { - /* Initialise to the values passed */ - scrp->mask.red = mask.red; - scrp->mask.green = mask.green; - scrp->mask.blue = mask.blue; - scrp->offset.red = ffs(mask.red) - 1; - scrp->offset.green = ffs(mask.green) - 1; - scrp->offset.blue = ffs(mask.blue) - 1; - } - return TRUE; -} - -Bool -xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual) -{ - MessageType visualFrom = X_DEFAULT; - - if (defaultColorVisualClass >= 0) { - scrp->defaultVisual = defaultColorVisualClass; - visualFrom = X_CMDLINE; - } - else if (scrp->display->defaultVisual >= 0) { - scrp->defaultVisual = scrp->display->defaultVisual; - visualFrom = X_CONFIG; - } - else if (visual >= 0) { - scrp->defaultVisual = visual; - } - else { - if (scrp->depth == 1) - scrp->defaultVisual = StaticGray; - else if (scrp->depth == 4) - scrp->defaultVisual = StaticColor; - else if (scrp->depth <= MAX_PSEUDO_DEPTH) - scrp->defaultVisual = PseudoColor; - else - scrp->defaultVisual = TrueColor; - } - switch (scrp->defaultVisual) { - case StaticGray: - case GrayScale: - case StaticColor: - case PseudoColor: - case TrueColor: - case DirectColor: - xf86DrvMsg(scrp->scrnIndex, visualFrom, "Default visual is %s\n", - xf86VisualNames[scrp->defaultVisual]); - return TRUE; - default: - - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Invalid default visual class (%d)\n", scrp->defaultVisual); - return FALSE; - } -} - -#define TEST_GAMMA(g) \ - (g).red > GAMMA_ZERO || (g).green > GAMMA_ZERO || (g).blue > GAMMA_ZERO - -#define SET_GAMMA(g) \ - (g) > GAMMA_ZERO ? (g) : 1.0 - -Bool -xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma) -{ - MessageType from = X_DEFAULT; - -#if 0 - xf86MonPtr DDC = (xf86MonPtr) (scrp->monitor->DDC); -#endif - if (TEST_GAMMA(xf86Gamma)) { - from = X_CMDLINE; - scrp->gamma.red = SET_GAMMA(xf86Gamma.red); - scrp->gamma.green = SET_GAMMA(xf86Gamma.green); - scrp->gamma.blue = SET_GAMMA(xf86Gamma.blue); - } - else if (TEST_GAMMA(scrp->monitor->gamma)) { - from = X_CONFIG; - scrp->gamma.red = SET_GAMMA(scrp->monitor->gamma.red); - scrp->gamma.green = SET_GAMMA(scrp->monitor->gamma.green); - scrp->gamma.blue = SET_GAMMA(scrp->monitor->gamma.blue); -#if 0 - } - else if (DDC && DDC->features.gamma > GAMMA_ZERO) { - from = X_PROBED; - scrp->gamma.red = SET_GAMMA(DDC->features.gamma); - scrp->gamma.green = SET_GAMMA(DDC->features.gamma); - scrp->gamma.blue = SET_GAMMA(DDC->features.gamma); - /* EDID structure version 2 gives optional separate red, green & blue - * gamma values in bytes 0x57-0x59 */ -#endif - } - else if (TEST_GAMMA(gamma)) { - scrp->gamma.red = SET_GAMMA(gamma.red); - scrp->gamma.green = SET_GAMMA(gamma.green); - scrp->gamma.blue = SET_GAMMA(gamma.blue); - } - else { - scrp->gamma.red = 1.0; - scrp->gamma.green = 1.0; - scrp->gamma.blue = 1.0; - } - - xf86DrvMsg(scrp->scrnIndex, from, - "Using gamma correction (%.1f, %.1f, %.1f)\n", - scrp->gamma.red, scrp->gamma.green, scrp->gamma.blue); - - return TRUE; -} - -#undef TEST_GAMMA -#undef SET_GAMMA - -/* - * Set the DPI from the command line option. XXX should allow it to be - * calculated from the widthmm/heightmm values. - */ - -#undef MMPERINCH -#define MMPERINCH 25.4 - -void -xf86SetDpi(ScrnInfoPtr pScrn, int x, int y) -{ - MessageType from = X_DEFAULT; - xf86MonPtr DDC = (xf86MonPtr) (pScrn->monitor->DDC); - int ddcWidthmm, ddcHeightmm; - int widthErr, heightErr; - - /* XXX Maybe there is no need for widthmm/heightmm in ScrnInfoRec */ - pScrn->widthmm = pScrn->monitor->widthmm; - pScrn->heightmm = pScrn->monitor->heightmm; - - if (DDC && (DDC->features.hsize > 0 && DDC->features.vsize > 0)) { - /* DDC gives display size in mm for individual modes, - * but cm for monitor - */ - ddcWidthmm = DDC->features.hsize * 10; /* 10mm in 1cm */ - ddcHeightmm = DDC->features.vsize * 10; /* 10mm in 1cm */ - } - else { - ddcWidthmm = ddcHeightmm = 0; - } - - if (monitorResolution > 0) { - pScrn->xDpi = monitorResolution; - pScrn->yDpi = monitorResolution; - from = X_CMDLINE; - } - else if (pScrn->widthmm > 0 || pScrn->heightmm > 0) { - from = X_CONFIG; - if (pScrn->widthmm > 0) { - pScrn->xDpi = - (int) ((double) pScrn->virtualX * MMPERINCH / pScrn->widthmm); - } - if (pScrn->heightmm > 0) { - pScrn->yDpi = - (int) ((double) pScrn->virtualY * MMPERINCH / pScrn->heightmm); - } - if (pScrn->xDpi > 0 && pScrn->yDpi <= 0) - pScrn->yDpi = pScrn->xDpi; - if (pScrn->yDpi > 0 && pScrn->xDpi <= 0) - pScrn->xDpi = pScrn->yDpi; - xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n", - pScrn->widthmm, pScrn->heightmm); - - /* Warn if config and probe disagree about display size */ - if (ddcWidthmm && ddcHeightmm) { - if (pScrn->widthmm > 0) { - widthErr = abs(ddcWidthmm - pScrn->widthmm); - } - else { - widthErr = 0; - } - if (pScrn->heightmm > 0) { - heightErr = abs(ddcHeightmm - pScrn->heightmm); - } - else { - heightErr = 0; - } - if (widthErr > 10 || heightErr > 10) { - /* Should include config file name for monitor here */ - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "Probed monitor is %dx%d mm, using Displaysize %dx%d mm\n", - ddcWidthmm, ddcHeightmm, pScrn->widthmm, - pScrn->heightmm); - } - } - } - else if (ddcWidthmm && ddcHeightmm) { - from = X_PROBED; - xf86DrvMsg(pScrn->scrnIndex, from, "Display dimensions: (%d, %d) mm\n", - ddcWidthmm, ddcHeightmm); - pScrn->widthmm = ddcWidthmm; - pScrn->heightmm = ddcHeightmm; - if (pScrn->widthmm > 0) { - pScrn->xDpi = - (int) ((double) pScrn->virtualX * MMPERINCH / pScrn->widthmm); - } - if (pScrn->heightmm > 0) { - pScrn->yDpi = - (int) ((double) pScrn->virtualY * MMPERINCH / pScrn->heightmm); - } - if (pScrn->xDpi > 0 && pScrn->yDpi <= 0) - pScrn->yDpi = pScrn->xDpi; - if (pScrn->yDpi > 0 && pScrn->xDpi <= 0) - pScrn->xDpi = pScrn->yDpi; - } - else { - if (x > 0) - pScrn->xDpi = x; - else - pScrn->xDpi = DEFAULT_DPI; - if (y > 0) - pScrn->yDpi = y; - else - pScrn->yDpi = DEFAULT_DPI; - } - xf86DrvMsg(pScrn->scrnIndex, from, "DPI set to (%d, %d)\n", - pScrn->xDpi, pScrn->yDpi); -} - -#undef MMPERINCH - -void -xf86SetBlackWhitePixels(ScreenPtr pScreen) -{ - pScreen->whitePixel = 1; - pScreen->blackPixel = 0; -} - -/* - * Function to enable/disable access to the frame buffer - * - * This is used when VT switching and when entering/leaving DGA direct mode. - * - * This has been rewritten again to eliminate the saved pixmap. The - * devPrivate field in the screen pixmap is set to NULL to catch code - * accidentally referencing the frame buffer while the X server is not - * supposed to touch it. - * - * Here, we exchange the pixmap private data, rather than the pixmaps - * themselves to avoid having to find and change any references to the screen - * pixmap such as GC's, window privates etc. This also means that this code - * does not need to know exactly how the pixmap pixels are accessed. Further, - * this exchange is >not< done through the screen's ModifyPixmapHeader() - * vector. This means the called frame buffer code layers can determine - * whether they are switched in or out by keeping track of the root pixmap's - * private data, and therefore don't need to access pScrnInfo->vtSema. - */ -void -xf86EnableDisableFBAccess(ScrnInfoPtr pScrnInfo, Bool enable) -{ - ScreenPtr pScreen = pScrnInfo->pScreen; - - if (enable) { - /* - * Restore all of the clip lists on the screen - */ - if (!xf86Resetting) - SetRootClip(pScreen, ROOT_CLIP_FULL); - - } - else { - /* - * Empty all of the clip lists on the screen - */ - SetRootClip(pScreen, ROOT_CLIP_NONE); - } -} - -/* Print driver messages in the standard format of - () (): */ -void -xf86VDrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format, - va_list args) -{ - /* Prefix the scrnIndex name to the format string. */ - if (scrnIndex >= 0 && scrnIndex < xf86NumScreens && - xf86Screens[scrnIndex]->name) - LogHdrMessageVerb(type, verb, format, args, "%s(%d): ", - xf86Screens[scrnIndex]->name, scrnIndex); - else if (scrnIndex >= GPU_SCREEN_OFFSET && - scrnIndex < GPU_SCREEN_OFFSET + xf86NumGPUScreens && - xf86GPUScreens[scrnIndex - GPU_SCREEN_OFFSET]->name) - LogHdrMessageVerb(type, verb, format, args, "%s(G%d): ", - xf86GPUScreens[scrnIndex - GPU_SCREEN_OFFSET]->name, scrnIndex - GPU_SCREEN_OFFSET); - else - LogVMessageVerb(type, verb, format, args); -} - -/* Print driver messages, with verbose level specified directly */ -void -xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format, - ...) -{ - va_list ap; - - va_start(ap, format); - xf86VDrvMsgVerb(scrnIndex, type, verb, format, ap); - va_end(ap); -} - -/* Print driver messages, with verbose level of 1 (default) */ -void -xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - xf86VDrvMsgVerb(scrnIndex, type, 1, format, ap); - va_end(ap); -} - -/* Print input driver messages in the standard format of - () : : */ -void -xf86VIDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, - const char *format, va_list args) -{ - const char *driverName = NULL; - const char *deviceName = NULL; - - /* Prefix driver and device names to formatted message. */ - if (dev) { - deviceName = dev->name; - if (dev->drv) - driverName = dev->drv->driverName; - } - - LogHdrMessageVerb(type, verb, format, args, "%s: %s: ", driverName, - deviceName); -} - -/* Print input driver message, with verbose level specified directly */ -void -xf86IDrvMsgVerb(InputInfoPtr dev, MessageType type, int verb, - const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - xf86VIDrvMsgVerb(dev, type, verb, format, ap); - va_end(ap); -} - -/* Print input driver messages, with verbose level of 1 (default) */ -void -xf86IDrvMsg(InputInfoPtr dev, MessageType type, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - xf86VIDrvMsgVerb(dev, type, 1, format, ap); - va_end(ap); -} - -/* Print non-driver messages with verbose level specified directly */ -void -xf86MsgVerb(MessageType type, int verb, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - LogVMessageVerb(type, verb, format, ap); - va_end(ap); -} - -/* Print non-driver messages with verbose level of 1 (default) */ -void -xf86Msg(MessageType type, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - LogVMessageVerb(type, 1, format, ap); - va_end(ap); -} - -/* Just like ErrorF, but with the verbose level checked */ -void -xf86ErrorFVerb(int verb, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - if (xf86Verbose >= verb || xf86LogVerbose >= verb) - LogVWrite(verb, format, ap); - va_end(ap); -} - -/* Like xf86ErrorFVerb, but with an implied verbose level of 1 */ -void -xf86ErrorF(const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - if (xf86Verbose >= 1 || xf86LogVerbose >= 1) - LogVWrite(1, format, ap); - va_end(ap); -} - -/* Note temporarily modifies the passed in buffer! */ -static void xf86_mkdir_p(char *path) -{ - char *sep = path; - - while ((sep = strchr(sep + 1, '/'))) { - *sep = 0; - (void)mkdir(path, 0777); - *sep = '/'; - } - (void)mkdir(path, 0777); -} - -void -xf86LogInit(void) -{ - char *env, *lf = NULL; - char buf[PATH_MAX]; - -#define LOGSUFFIX ".log" -#define LOGOLDSUFFIX ".old" - - /* Get the log file name */ - if (xf86LogFileFrom == X_DEFAULT) { - /* When not running as root, we won't be able to write to /var/log */ - if (geteuid() != 0) { - if ((env = getenv("XDG_DATA_HOME"))) - snprintf(buf, sizeof(buf), "%s/%s", env, - DEFAULT_XDG_DATA_HOME_LOGDIR); - else if ((env = getenv("HOME"))) - snprintf(buf, sizeof(buf), "%s/%s/%s", env, - DEFAULT_XDG_DATA_HOME, DEFAULT_XDG_DATA_HOME_LOGDIR); - - if (env) { - xf86_mkdir_p(buf); - strlcat(buf, "/" DEFAULT_LOGPREFIX, sizeof(buf)); - xf86LogFile = buf; - } - } - /* Append the display number and ".log" */ - if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1) - FatalError("Cannot allocate space for the log file name\n"); - xf86LogFile = lf; - } - - xf86LogFile = LogInit(xf86LogFile, LOGOLDSUFFIX); - xf86LogFileWasOpened = TRUE; - - xf86SetVerbosity(xf86Verbose); - xf86SetLogVerbosity(xf86LogVerbose); - -#undef LOGSUFFIX -#undef LOGOLDSUFFIX - - free(lf); -} - -void -xf86CloseLog(enum ExitCode error) -{ - LogClose(error); -} - -/* - * Drivers can use these for using their own SymTabRecs. - */ - -const char * -xf86TokenToString(SymTabPtr table, int token) -{ - int i; - - for (i = 0; table[i].token >= 0 && table[i].token != token; i++); - - if (table[i].token < 0) - return NULL; - else - return table[i].name; -} - -int -xf86StringToToken(SymTabPtr table, const char *string) -{ - int i; - - if (string == NULL) - return -1; - - for (i = 0; table[i].token >= 0 && xf86NameCmp(string, table[i].name); i++); - - return table[i].token; -} - -/* - * helper to display the clocks found on a card - */ -void -xf86ShowClocks(ScrnInfoPtr scrp, MessageType from) -{ - int j; - - xf86DrvMsg(scrp->scrnIndex, from, "Pixel clocks available:"); - for (j = 0; j < scrp->numClocks; j++) { - if ((j % 4) == 0) { - xf86ErrorF("\n"); - xf86DrvMsg(scrp->scrnIndex, from, "pixel clocks:"); - } - xf86ErrorF(" %7.3f", (double) scrp->clock[j] / 1000.0); - } - xf86ErrorF("\n"); -} - -/* - * This prints out the driver identify message, including the names of - * the supported chipsets. - * - * XXX This makes assumptions about the line width, etc. Maybe we could - * use a more general "pretty print" function for messages. - */ -void -xf86PrintChipsets(const char *drvname, const char *drvmsg, SymTabPtr chips) -{ - int len, i; - - len = 6 + strlen(drvname) + 2 + strlen(drvmsg) + 2; - xf86Msg(X_INFO, "%s: %s:", drvname, drvmsg); - for (i = 0; chips[i].name != NULL; i++) { - if (i != 0) { - xf86ErrorF(","); - len++; - } - if (len + 2 + strlen(chips[i].name) < 78) { - xf86ErrorF(" "); - len++; - } - else { - xf86ErrorF("\n\t"); - len = 8; - } - xf86ErrorF("%s", chips[i].name); - len += strlen(chips[i].name); - } - xf86ErrorF("\n"); -} - -int -xf86MatchDevice(const char *drivername, GDevPtr ** sectlist) -{ - GDevPtr gdp, *pgdp = NULL; - confScreenPtr screensecptr; - int i, j, k; - - if (sectlist) - *sectlist = NULL; - - /* - * This can happen when running Xorg -showopts and a module like ati - * or vmware tries to load its submodules when xf86ConfigLayout is empty - */ - if (!xf86ConfigLayout.screens) - return 0; - - /* - * This is a very important function that matches the device sections - * as they show up in the config file with the drivers that the server - * loads at run time. - * - * ChipProbe can call - * int xf86MatchDevice(char * drivername, GDevPtr ** sectlist) - * with its driver name. The function allocates an array of GDevPtr and - * returns this via sectlist and returns the number of elements in - * this list as return value. 0 means none found, -1 means fatal error. - * - * It can figure out which of the Device sections to use for which card - * (using things like the Card statement, etc). For single headed servers - * there will of course be just one such Device section. - */ - i = 0; - - /* - * first we need to loop over all the Screens sections to get to all - * 'active' device sections - */ - for (j = 0; xf86ConfigLayout.screens[j].screen != NULL; j++) { - screensecptr = xf86ConfigLayout.screens[j].screen; - if ((screensecptr->device->driver != NULL) - && (xf86NameCmp(screensecptr->device->driver, drivername) == 0) - && (!screensecptr->device->claimed)) { - /* - * we have a matching driver that wasn't claimed, yet - */ - pgdp = xnfreallocarray(pgdp, i + 2, sizeof(GDevPtr)); - pgdp[i++] = screensecptr->device; - } - for (k = 0; k < screensecptr->num_gpu_devices; k++) { - if ((screensecptr->gpu_devices[k]->driver != NULL) - && (xf86NameCmp(screensecptr->gpu_devices[k]->driver, drivername) == 0) - && (!screensecptr->gpu_devices[k]->claimed)) { - /* - * we have a matching driver that wasn't claimed, yet - */ - pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr)); - pgdp[i++] = screensecptr->gpu_devices[k]; - } - } - } - - /* Then handle the inactive devices */ - j = 0; - while (xf86ConfigLayout.inactives[j].identifier) { - gdp = &xf86ConfigLayout.inactives[j]; - if (gdp->driver && !gdp->claimed && - !xf86NameCmp(gdp->driver, drivername)) { - /* we have a matching driver that wasn't claimed yet */ - pgdp = xnfreallocarray(pgdp, i + 2, sizeof(GDevPtr)); - pgdp[i++] = gdp; - } - j++; - } - - /* - * make the array NULL terminated and return its address - */ - if (i) - pgdp[i] = NULL; - - if (sectlist) - *sectlist = pgdp; - else - free(pgdp); - return i; -} - -const char * -xf86GetVisualName(int visual) -{ - if (visual < 0 || visual > DirectColor) - return NULL; - - return xf86VisualNames[visual]; -} - -int -xf86GetVerbosity(void) -{ - return max(xf86Verbose, xf86LogVerbose); -} - -int -xf86GetDepth(void) -{ - return xf86Depth; -} - -rgb -xf86GetWeight(void) -{ - return xf86Weight; -} - -Gamma -xf86GetGamma(void) -{ - return xf86Gamma; -} - -Bool -xf86ServerIsExiting(void) -{ - return (dispatchException & DE_TERMINATE) == DE_TERMINATE; -} - -Bool -xf86ServerIsResetting(void) -{ - return xf86Resetting; -} - -Bool -xf86ServerIsOnlyDetecting(void) -{ - return xf86DoConfigure; -} - -Bool -xf86GetVidModeAllowNonLocal(void) -{ - return xf86Info.vidModeAllowNonLocal; -} - -Bool -xf86GetVidModeEnabled(void) -{ - return xf86Info.vidModeEnabled; -} - -Bool -xf86GetModInDevAllowNonLocal(void) -{ - return xf86Info.miscModInDevAllowNonLocal; -} - -Bool -xf86GetModInDevEnabled(void) -{ - return xf86Info.miscModInDevEnabled; -} - -Bool -xf86GetAllowMouseOpenFail(void) -{ - return xf86Info.allowMouseOpenFail; -} - -CARD32 -xf86GetModuleVersion(void *module) -{ - return (CARD32) LoaderGetModuleVersion(module); -} - -void * -xf86LoadDrvSubModule(DriverPtr drv, const char *name) -{ - void *ret; - int errmaj = 0, errmin = 0; - - ret = LoadSubModule(drv->module, name, NULL, NULL, NULL, NULL, - &errmaj, &errmin); - if (!ret) - LoaderErrorMsg(NULL, name, errmaj, errmin); - return ret; -} - -void * -xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name) -{ - void *ret; - int errmaj = 0, errmin = 0; - - ret = LoadSubModule(pScrn->module, name, NULL, NULL, NULL, NULL, - &errmaj, &errmin); - if (!ret) - LoaderErrorMsg(pScrn->name, name, errmaj, errmin); - return ret; -} - -/* - * xf86LoadOneModule loads a single module. - */ -void * -xf86LoadOneModule(const char *name, void *opt) -{ - int errmaj; - char *Name; - void *mod; - - if (!name) - return NULL; - - /* Normalise the module name */ - Name = xf86NormalizeName(name); - - /* Skip empty names */ - if (Name == NULL) - return NULL; - if (*Name == '\0') { - free(Name); - return NULL; - } - - mod = LoadModule(Name, opt, NULL, &errmaj); - if (!mod) - LoaderErrorMsg(NULL, Name, errmaj, 0); - free(Name); - return mod; -} - -void -xf86UnloadSubModule(void *mod) -{ - UnloadSubModule(mod); -} - -Bool -xf86LoaderCheckSymbol(const char *name) -{ - return LoaderSymbol(name) != NULL; -} - -typedef enum { - OPTION_BACKING_STORE -} BSOpts; - -static const OptionInfoRec BSOptions[] = { - {OPTION_BACKING_STORE, "BackingStore", OPTV_BOOLEAN, {0}, FALSE}, - {-1, NULL, OPTV_NONE, {0}, FALSE} -}; - -void -xf86SetBackingStore(ScreenPtr pScreen) -{ - Bool useBS = FALSE; - MessageType from = X_DEFAULT; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - OptionInfoPtr options; - - options = xnfalloc(sizeof(BSOptions)); - (void) memcpy(options, BSOptions, sizeof(BSOptions)); - xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options); - - /* check for commandline option here */ - if (xf86bsEnableFlag) { - from = X_CMDLINE; - useBS = TRUE; - } - else if (xf86bsDisableFlag) { - from = X_CMDLINE; - useBS = FALSE; - } - else { - if (xf86GetOptValBool(options, OPTION_BACKING_STORE, &useBS)) - from = X_CONFIG; -#ifdef COMPOSITE - if (from != X_CONFIG) - useBS = xf86ReturnOptValBool(options, OPTION_BACKING_STORE, - !noCompositeExtension); -#endif - } - free(options); - pScreen->backingStoreSupport = useBS ? WhenMapped : NotUseful; - if (serverGeneration == 1) - xf86DrvMsg(pScreen->myNum, from, "Backing store %s\n", - useBS ? "enabled" : "disabled"); -} - -typedef enum { - OPTION_SILKEN_MOUSE -} SMOpts; - -static const OptionInfoRec SMOptions[] = { - {OPTION_SILKEN_MOUSE, "SilkenMouse", OPTV_BOOLEAN, {0}, FALSE}, - {-1, NULL, OPTV_NONE, {0}, FALSE} -}; - -void -xf86SetSilkenMouse(ScreenPtr pScreen) -{ - Bool useSM = TRUE; - MessageType from = X_DEFAULT; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - OptionInfoPtr options; - - options = xnfalloc(sizeof(SMOptions)); - (void) memcpy(options, SMOptions, sizeof(SMOptions)); - xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options); - - /* check for commandline option here */ - /* disable if screen shares resources */ - /* TODO VGA arb disable silken mouse */ - if (xf86silkenMouseDisableFlag) { - from = X_CMDLINE; - useSM = FALSE; - } - else { - if (xf86GetOptValBool(options, OPTION_SILKEN_MOUSE, &useSM)) - from = X_CONFIG; - } - free(options); - /* - * Use silken mouse if requested and if we have threaded input - */ - pScrn->silkenMouse = useSM && InputThreadEnable; - if (serverGeneration == 1) - xf86DrvMsg(pScreen->myNum, from, "Silken mouse %s\n", - pScrn->silkenMouse ? "enabled" : "disabled"); -} - -/* Wrote this function for the PM2 Xv driver, preliminary. */ - -void * -xf86FindXvOptions(ScrnInfoPtr pScrn, int adaptor_index, const char *port_name, - const char **adaptor_name, void **adaptor_options) -{ - confXvAdaptorPtr adaptor; - int i; - - if (adaptor_index >= pScrn->confScreen->numxvadaptors) { - if (adaptor_name) - *adaptor_name = NULL; - if (adaptor_options) - *adaptor_options = NULL; - return NULL; - } - - adaptor = &pScrn->confScreen->xvadaptors[adaptor_index]; - if (adaptor_name) - *adaptor_name = adaptor->identifier; - if (adaptor_options) - *adaptor_options = adaptor->options; - - for (i = 0; i < adaptor->numports; i++) - if (!xf86NameCmp(adaptor->ports[i].identifier, port_name)) - return adaptor->ports[i].options; - - return NULL; -} - -static void -xf86ConfigFbEntityInactive(EntityInfoPtr pEnt, EntityProc init, - EntityProc enter, EntityProc leave, void *private) -{ - ScrnInfoPtr pScrn; - - if ((pScrn = xf86FindScreenForEntity(pEnt->index))) - xf86RemoveEntityFromScreen(pScrn, pEnt->index); -} - -ScrnInfoPtr -xf86ConfigFbEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex, - EntityProc init, EntityProc enter, EntityProc leave, - void *private) -{ - EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex); - - if (init || enter || leave) - FatalError("Legacy entity access functions are unsupported\n"); - - if (!pEnt) - return pScrn; - - if (!(pEnt->location.type == BUS_NONE)) { - free(pEnt); - return pScrn; - } - - if (!pEnt->active) { - xf86ConfigFbEntityInactive(pEnt, init, enter, leave, private); - free(pEnt); - return pScrn; - } - - if (!pScrn) - pScrn = xf86AllocateScreen(pEnt->driver, scrnFlag); - xf86AddEntityToScreen(pScrn, entityIndex); - - free(pEnt); - return pScrn; -} - -Bool -xf86IsScreenPrimary(ScrnInfoPtr pScrn) -{ - int i; - - for (i = 0; i < pScrn->numEntities; i++) { - if (xf86IsEntityPrimary(i)) - return TRUE; - } - return FALSE; -} - -Bool -xf86IsUnblank(int mode) -{ - switch (mode) { - case SCREEN_SAVER_OFF: - case SCREEN_SAVER_FORCER: - return TRUE; - case SCREEN_SAVER_ON: - case SCREEN_SAVER_CYCLE: - return FALSE; - default: - xf86MsgVerb(X_WARNING, 0, "Unexpected save screen mode: %d\n", mode); - return TRUE; - } -} - -void -xf86MotionHistoryAllocate(InputInfoPtr pInfo) -{ - AllocateMotionHistory(pInfo->dev); -} - -ScrnInfoPtr -xf86ScreenToScrn(ScreenPtr pScreen) -{ - if (pScreen->isGPU) { - assert(pScreen->myNum - GPU_SCREEN_OFFSET < xf86NumGPUScreens); - return xf86GPUScreens[pScreen->myNum - GPU_SCREEN_OFFSET]; - } else { - assert(pScreen->myNum < xf86NumScreens); - return xf86Screens[pScreen->myNum]; - } -} - -ScreenPtr -xf86ScrnToScreen(ScrnInfoPtr pScrn) -{ - if (pScrn->is_gpu) { - assert(pScrn->scrnIndex - GPU_SCREEN_OFFSET < screenInfo.numGPUScreens); - return screenInfo.gpuscreens[pScrn->scrnIndex - GPU_SCREEN_OFFSET]; - } else { - assert(pScrn->scrnIndex < screenInfo.numScreens); - return screenInfo.screens[pScrn->scrnIndex]; - } -} - -void -xf86UpdateDesktopDimensions(void) -{ - update_desktop_dimensions(); -} - - -void -xf86AddInputEventDrainCallback(CallbackProcPtr callback, void *param) -{ - mieqAddCallbackOnDrained(callback, param); -} - -void -xf86RemoveInputEventDrainCallback(CallbackProcPtr callback, void *param) -{ - mieqRemoveCallbackOnDrained(callback, param); -} diff --git a/hw/xfree86/common/xf86InPriv.h b/hw/xfree86/common/xf86InPriv.h deleted file mode 100644 index b8229d2c1..000000000 --- a/hw/xfree86/common/xf86InPriv.h +++ /dev/null @@ -1,40 +0,0 @@ - -/* - * Copyright (c) 1999 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _xf86InPriv_h -#define _xf86InPriv_h - -/* xf86Globals.c */ -extern InputDriverPtr *xf86InputDriverList; -extern int xf86NumInputDrivers; - -#endif /* _xf86InPriv_h */ diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c deleted file mode 100644 index 5695e71ac..000000000 --- a/hw/xfree86/common/xf86Init.c +++ /dev/null @@ -1,1354 +0,0 @@ -/* - * Loosely based on code bearing the following copyright: - * - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. - */ -/* - * Copyright (c) 1992-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#undef HAS_UTSNAME -#if !defined(WIN32) -#define HAS_UTSNAME 1 -#include -#endif - -#include -#include -#include -#include -#include "input.h" -#include "servermd.h" -#include "windowstr.h" -#include "scrnintstr.h" -#include "mi.h" -#include "dbus-core.h" -#include "systemd-logind.h" - -#include "loaderProcs.h" - -#define XF86_OS_PRIVS -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86Config.h" -#include "xf86_OSlib.h" -#include "xf86cmap.h" -#include "xorgVersion.h" -#include "mipointer.h" -#include -#include -#include "xf86Extensions.h" -#include "xf86DDC.h" -#include "xf86Xinput.h" -#include "xf86InPriv.h" -#include "xf86Crtc.h" -#include "picturestr.h" -#include "randrstr.h" -#include "xf86Bus.h" -#ifdef XSERVER_LIBPCIACCESS -#include "xf86VGAarbiter.h" -#endif -#include "globals.h" -#include "xserver-properties.h" - -#ifdef DPMSExtension -#include -#include "dpmsproc.h" -#endif - -#ifdef __linux__ -#include -#include -#endif -#include - -void (*xf86OSPMClose) (void) = NULL; -static Bool xorgHWOpenConsole = FALSE; - -/* Common pixmap formats */ - -static PixmapFormatRec formats[MAXFORMATS] = { - {1, 1, BITMAP_SCANLINE_PAD}, - {4, 8, BITMAP_SCANLINE_PAD}, - {8, 8, BITMAP_SCANLINE_PAD}, - {15, 16, BITMAP_SCANLINE_PAD}, - {16, 16, BITMAP_SCANLINE_PAD}, - {24, 32, BITMAP_SCANLINE_PAD}, - {32, 32, BITMAP_SCANLINE_PAD}, -}; - -static int numFormats = 7; -static Bool formatsDone = FALSE; - - -static void -xf86PrintBanner(void) -{ - xf86ErrorFVerb(0, "\nX.Org X Server %d.%d.%d", - XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH); -#if XORG_VERSION_SNAP > 0 - xf86ErrorFVerb(0, ".%d", XORG_VERSION_SNAP); -#endif - -#if XORG_VERSION_SNAP >= 900 - /* When the minor number is 99, that signifies that the we are making - * a release candidate for a major version. (X.0.0) - * When the patch number is 99, that signifies that the we are making - * a release candidate for a minor version. (X.Y.0) - * When the patch number is < 99, then we are making a release - * candidate for the next point release. (X.Y.Z) - */ -#if XORG_VERSION_MINOR >= 99 - xf86ErrorFVerb(0, " (%d.0.0 RC %d)", XORG_VERSION_MAJOR + 1, - XORG_VERSION_SNAP - 900); -#elif XORG_VERSION_PATCH == 99 - xf86ErrorFVerb(0, " (%d.%d.0 RC %d)", XORG_VERSION_MAJOR, - XORG_VERSION_MINOR + 1, XORG_VERSION_SNAP - 900); -#else - xf86ErrorFVerb(0, " (%d.%d.%d RC %d)", XORG_VERSION_MAJOR, - XORG_VERSION_MINOR, XORG_VERSION_PATCH + 1, - XORG_VERSION_SNAP - 900); -#endif -#endif - -#ifdef XORG_CUSTOM_VERSION - xf86ErrorFVerb(0, " (%s)", XORG_CUSTOM_VERSION); -#endif - xf86ErrorFVerb(0, "\nX Protocol Version %d, Revision %d\n", - X_PROTOCOL, X_PROTOCOL_REVISION); -#ifdef HAS_UTSNAME - { - struct utsname name; - - /* Linux & BSD state that 0 is success, SysV (including Solaris, HP-UX, - and Irix) and Single Unix Spec 3 just say that non-negative is success. - All agree that failure is represented by a negative number. - */ - if (uname(&name) >= 0) { - xf86ErrorFVerb(0, "Current Operating System: %s %s %s %s %s\n", - name.sysname, name.nodename, name.release, - name.version, name.machine); -#ifdef __linux__ - do { - char buf[80]; - int fd = open("/proc/cmdline", O_RDONLY); - - if (fd != -1) { - xf86ErrorFVerb(0, "Kernel command line: "); - memset(buf, 0, 80); - while (read(fd, buf, 80) > 0) { - xf86ErrorFVerb(0, "%.80s", buf); - memset(buf, 0, 80); - } - close(fd); - } - } while (0); -#endif - } - } -#endif -#if defined(BUILDERSTRING) - xf86ErrorFVerb(0, "%s \n", BUILDERSTRING); -#endif - xf86ErrorFVerb(0, "Current version of pixman: %s\n", - pixman_version_string()); - xf86ErrorFVerb(0, "\tBefore reporting problems, check " - "" __VENDORDWEBSUPPORT__ "\n" - "\tto make sure that you have the latest version.\n"); -} - -Bool -xf86PrivsElevated(void) -{ - return PrivsElevated(); -} - -Bool -xf86HasTTYs(void) -{ -#ifdef __linux__ - struct stat tty0devAttributes; - return (stat("/dev/tty0", &tty0devAttributes) == 0 && major(tty0devAttributes.st_rdev) == TTY_MAJOR); -#else - return TRUE; -#endif -} - -static void -xf86AutoConfigOutputDevices(void) -{ - int i; - - if (!xf86Info.autoBindGPU) - return; - - for (i = 0; i < xf86NumGPUScreens; i++) { - int scrnum = xf86GPUScreens[i]->confScreen->screennum; - RRProviderAutoConfigGpuScreen(xf86ScrnToScreen(xf86GPUScreens[i]), - xf86ScrnToScreen(xf86Screens[scrnum])); - } -} - -static void -AddSeatId(CallbackListPtr *pcbl, void *data, void *screen) -{ - ScreenPtr pScreen = screen; - Atom SeatAtom = MakeAtom(SEAT_ATOM_NAME, sizeof(SEAT_ATOM_NAME) - 1, TRUE); - int err; - - err = dixChangeWindowProperty(serverClient, pScreen->root, SeatAtom, - XA_STRING, 8, PropModeReplace, - strlen(data) + 1, data, FALSE); - - if (err != Success) - xf86DrvMsg(pScreen->myNum, X_WARNING, - "Failed to register seat property\n"); -} - -static void -AddVTAtoms(CallbackListPtr *pcbl, void *data, void *screen) -{ -#define VT_ATOM_NAME "XFree86_VT" - int err, HasVT = 1; - ScreenPtr pScreen = screen; - Atom VTAtom = MakeAtom(VT_ATOM_NAME, sizeof(VT_ATOM_NAME) - 1, TRUE); - Atom HasVTAtom = MakeAtom(HAS_VT_ATOM_NAME, sizeof(HAS_VT_ATOM_NAME) - 1, - TRUE); - - err = dixChangeWindowProperty(serverClient, pScreen->root, VTAtom, - XA_INTEGER, 32, PropModeReplace, 1, - &xf86Info.vtno, FALSE); - - err |= dixChangeWindowProperty(serverClient, pScreen->root, HasVTAtom, - XA_INTEGER, 32, PropModeReplace, 1, - &HasVT, FALSE); - - if (err != Success) - xf86DrvMsg(pScreen->myNum, X_WARNING, - "Failed to register VT properties\n"); -} - -static Bool -xf86ScreenInit(ScreenPtr pScreen, int argc, char **argv) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - - pScrn->pScreen = pScreen; - return pScrn->ScreenInit (pScreen, argc, argv); -} - -static void -xf86EnsureRANDR(ScreenPtr pScreen) -{ -#ifdef RANDR - if (!dixPrivateKeyRegistered(rrPrivKey) || - !rrGetScrPriv(pScreen)) - xf86RandRInit(pScreen); -#endif -} - -/* - * InitOutput -- - * Initialize screenInfo for all actually accessible framebuffers. - * That includes vt-manager setup, querying all possible devices and - * collecting the pixmap formats. - */ -void -InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv) -{ - int i, j, k, scr_index; - const char **modulelist; - void **optionlist; - Bool autoconfig = FALSE; - Bool sigio_blocked = FALSE; - Bool want_hw_access = FALSE; - GDevPtr configured_device; - - xf86Initialising = TRUE; - - config_pre_init(); - - if (serverGeneration == 1) { - xf86PrintBanner(); - LogPrintMarkers(); - if (xf86LogFile) { - time_t t; - const char *ct; - - t = time(NULL); - ct = ctime(&t); - xf86MsgVerb(xf86LogFileFrom, 0, "Log file: \"%s\", Time: %s", - xf86LogFile, ct); - } - - /* Read and parse the config file */ - if (!xf86DoConfigure && !xf86DoShowOptions) { - switch (xf86HandleConfigFile(FALSE)) { - case CONFIG_OK: - break; - case CONFIG_PARSE_ERROR: - xf86Msg(X_ERROR, "Error parsing the config file\n"); - return; - case CONFIG_NOFILE: - autoconfig = TRUE; - break; - } - } - - /* Initialise the loader */ - LoaderInit(); - - /* Tell the loader the default module search path */ - LoaderSetPath(xf86ModulePath); - - if (xf86Info.ignoreABI) { - LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL); - } - - if (xf86DoShowOptions) - DoShowOptions(); - - dbus_core_init(); - systemd_logind_init(); - - /* Do a general bus probe. This will be a PCI probe for x86 platforms */ - xf86BusProbe(); - - if (xf86DoConfigure) - DoConfigure(); - - if (autoconfig) { - if (!xf86AutoConfig()) { - xf86Msg(X_ERROR, "Auto configuration failed\n"); - return; - } - } - - xf86OSPMClose = xf86OSPMOpen(); - - xf86ExtensionInit(); - - /* Load all modules specified explicitly in the config file */ - if ((modulelist = xf86ModulelistFromConfig(&optionlist))) { - xf86LoadModules(modulelist, optionlist); - free(modulelist); - free(optionlist); - } - - /* Load all driver modules specified in the config file */ - /* If there aren't any specified in the config file, autoconfig them */ - /* FIXME: Does not handle multiple active screen sections, but I'm not - * sure if we really want to handle that case*/ - configured_device = xf86ConfigLayout.screens->screen->device; - if ((!configured_device) || (!configured_device->driver)) { - if (!autoConfigDevice(configured_device)) { - xf86Msg(X_ERROR, "Automatic driver configuration failed\n"); - return; - } - } - if ((modulelist = xf86DriverlistFromConfig())) { - xf86LoadModules(modulelist, NULL); - free(modulelist); - } - - /* Load all input driver modules specified in the config file. */ - if ((modulelist = xf86InputDriverlistFromConfig())) { - xf86LoadModules(modulelist, NULL); - free(modulelist); - } - - /* - * It is expected that xf86AddDriver()/xf86AddInputDriver will be - * called for each driver as it is loaded. Those functions save the - * module pointers for drivers. - * XXX Nothing keeps track of them for other modules. - */ - /* XXX What do we do if not all of these could be loaded? */ - - /* - * At this point, xf86DriverList[] is all filled in with entries for - * each of the drivers to try and xf86NumDrivers has the number of - * drivers. If there are none, return now. - */ - - if (xf86NumDrivers == 0) { - xf86Msg(X_ERROR, "No drivers available.\n"); - return; - } - - /* - * Call each of the Identify functions and call the driverFunc to check - * if HW access is required. The Identify functions print out some - * identifying information, and anything else that might be - * needed at this early stage. - */ - - for (i = 0; i < xf86NumDrivers; i++) { - xorgHWFlags flags = HW_IO; - - if (xf86DriverList[i]->Identify != NULL) - xf86DriverList[i]->Identify(0); - - if (xf86DriverList[i]->driverFunc) - xf86DriverList[i]->driverFunc(NULL, - GET_REQUIRED_HW_INTERFACES, - &flags); - - if (NEED_IO_ENABLED(flags)) - want_hw_access = TRUE; - - /* Non-seat0 X servers should not open console */ - if (!(flags & HW_SKIP_CONSOLE) && !ServerIsNotSeat0() && xf86HasTTYs()) - xorgHWOpenConsole = TRUE; - } - - if (xorgHWOpenConsole) - xf86OpenConsole(); - else - xf86Info.dontVTSwitch = TRUE; - - /* Enable full I/O access */ - if (want_hw_access) - xorgHWAccess = xf86EnableIO(); - - if (xf86BusConfig() == FALSE) - return; - - xf86PostProbe(); - - /* - * Sort the drivers to match the requested ording. Using a slow - * bubble sort. - */ - for (j = 0; j < xf86NumScreens - 1; j++) { - for (i = 0; i < xf86NumScreens - j - 1; i++) { - if (xf86Screens[i + 1]->confScreen->screennum < - xf86Screens[i]->confScreen->screennum) { - ScrnInfoPtr tmpScrn = xf86Screens[i + 1]; - - xf86Screens[i + 1] = xf86Screens[i]; - xf86Screens[i] = tmpScrn; - } - } - } - /* Fix up the indexes */ - for (i = 0; i < xf86NumScreens; i++) { - xf86Screens[i]->scrnIndex = i; - } - - /* - * Call the driver's PreInit()'s to complete initialisation for the first - * generation. - */ - - for (i = 0; i < xf86NumScreens; i++) { - xf86VGAarbiterScrnInit(xf86Screens[i]); - xf86VGAarbiterLock(xf86Screens[i]); - if (xf86Screens[i]->PreInit && - xf86Screens[i]->PreInit(xf86Screens[i], 0)) - xf86Screens[i]->configured = TRUE; - xf86VGAarbiterUnlock(xf86Screens[i]); - } - for (i = 0; i < xf86NumScreens; i++) - if (!xf86Screens[i]->configured) - xf86DeleteScreen(xf86Screens[i--]); - - for (i = 0; i < xf86NumGPUScreens; i++) { - xf86VGAarbiterScrnInit(xf86GPUScreens[i]); - xf86VGAarbiterLock(xf86GPUScreens[i]); - if (xf86GPUScreens[i]->PreInit && - xf86GPUScreens[i]->PreInit(xf86GPUScreens[i], 0)) - xf86GPUScreens[i]->configured = TRUE; - xf86VGAarbiterUnlock(xf86GPUScreens[i]); - } - for (i = 0; i < xf86NumGPUScreens; i++) - if (!xf86GPUScreens[i]->configured) - xf86DeleteScreen(xf86GPUScreens[i--]); - - /* - * If no screens left, return now. - */ - - if (xf86NumScreens == 0) { - xf86Msg(X_ERROR, - "Screen(s) found, but none have a usable configuration.\n"); - return; - } - - /* Remove (unload) drivers that are not required */ - for (i = 0; i < xf86NumDrivers; i++) - if (xf86DriverList[i] && xf86DriverList[i]->refCount <= 0) - xf86DeleteDriver(i); - - /* - * At this stage we know how many screens there are. - */ - - for (i = 0; i < xf86NumScreens; i++) - xf86InitViewport(xf86Screens[i]); - - /* - * Collect all pixmap formats and check for conflicts at the display - * level. Should we die here? Or just delete the offending screens? - */ - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->imageByteOrder != - xf86Screens[0]->imageByteOrder) - FatalError("Inconsistent display bitmapBitOrder. Exiting\n"); - if (xf86Screens[i]->bitmapScanlinePad != - xf86Screens[0]->bitmapScanlinePad) - FatalError - ("Inconsistent display bitmapScanlinePad. Exiting\n"); - if (xf86Screens[i]->bitmapScanlineUnit != - xf86Screens[0]->bitmapScanlineUnit) - FatalError - ("Inconsistent display bitmapScanlineUnit. Exiting\n"); - if (xf86Screens[i]->bitmapBitOrder != - xf86Screens[0]->bitmapBitOrder) - FatalError("Inconsistent display bitmapBitOrder. Exiting\n"); - } - - /* Collect additional formats */ - for (i = 0; i < xf86NumScreens; i++) { - for (j = 0; j < xf86Screens[i]->numFormats; j++) { - for (k = 0;; k++) { - if (k >= numFormats) { - if (k >= MAXFORMATS) - FatalError("Too many pixmap formats! Exiting\n"); - formats[k] = xf86Screens[i]->formats[j]; - numFormats++; - break; - } - if (formats[k].depth == xf86Screens[i]->formats[j].depth) { - if ((formats[k].bitsPerPixel == - xf86Screens[i]->formats[j].bitsPerPixel) && - (formats[k].scanlinePad == - xf86Screens[i]->formats[j].scanlinePad)) - break; - FatalError("Inconsistent pixmap format for depth %d." - " Exiting\n", formats[k].depth); - } - } - } - } - formatsDone = TRUE; - } - else { - /* - * serverGeneration != 1; some OSs have to do things here, too. - */ - if (xorgHWOpenConsole) - xf86OpenConsole(); - - /* - should we reopen it here? We need to deal with an already opened - device. We could leave this to the OS layer. For now we simply - close it here - */ - if (xf86OSPMClose) - xf86OSPMClose(); - if ((xf86OSPMClose = xf86OSPMOpen()) != NULL) - xf86MsgVerb(X_INFO, 3, "APM registered successfully\n"); - - /* Make sure full I/O access is enabled */ - if (xorgHWAccess) - xf86EnableIO(); - } - - if (xf86Info.vtno >= 0) - AddCallback(&RootWindowFinalizeCallback, AddVTAtoms, NULL); - - if (SeatId) - AddCallback(&RootWindowFinalizeCallback, AddSeatId, SeatId); - - /* - * Use the previously collected parts to setup pScreenInfo - */ - - pScreenInfo->imageByteOrder = xf86Screens[0]->imageByteOrder; - pScreenInfo->bitmapScanlinePad = xf86Screens[0]->bitmapScanlinePad; - pScreenInfo->bitmapScanlineUnit = xf86Screens[0]->bitmapScanlineUnit; - pScreenInfo->bitmapBitOrder = xf86Screens[0]->bitmapBitOrder; - pScreenInfo->numPixmapFormats = numFormats; - for (i = 0; i < numFormats; i++) - pScreenInfo->formats[i] = formats[i]; - - /* Make sure the server's VT is active */ - - if (serverGeneration != 1) { - xf86Resetting = TRUE; - /* All screens are in the same state, so just check the first */ - if (!xf86VTOwner()) { -#ifdef HAS_USL_VTS - ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ); -#endif - input_lock(); - sigio_blocked = TRUE; - } - } - - for (i = 0; i < xf86NumScreens; i++) - if (!xf86ColormapAllocatePrivates(xf86Screens[i])) - FatalError("Cannot register DDX private keys"); - - if (!dixRegisterPrivateKey(&xf86ScreenKeyRec, PRIVATE_SCREEN, 0)) - FatalError("Cannot register DDX private keys"); - - for (i = 0; i < xf86NumScreens; i++) { - xf86VGAarbiterLock(xf86Screens[i]); - /* - * Almost everything uses these defaults, and many of those that - * don't, will wrap them. - */ - xf86Screens[i]->EnableDisableFBAccess = xf86EnableDisableFBAccess; -#ifdef XFreeXDGA - xf86Screens[i]->SetDGAMode = xf86SetDGAMode; -#endif - scr_index = AddScreen(xf86ScreenInit, argc, argv); - xf86VGAarbiterUnlock(xf86Screens[i]); - if (scr_index == i) { - /* - * Hook in our ScrnInfoRec, and initialise some other pScreen - * fields. - */ - dixSetPrivate(&screenInfo.screens[scr_index]->devPrivates, - xf86ScreenKey, xf86Screens[i]); - xf86Screens[i]->pScreen = screenInfo.screens[scr_index]; - /* The driver should set this, but make sure it is set anyway */ - xf86Screens[i]->vtSema = TRUE; - } - else { - /* This shouldn't normally happen */ - FatalError("AddScreen/ScreenInit failed for driver %d\n", i); - } - - if (PictureGetSubpixelOrder(xf86Screens[i]->pScreen) == SubPixelUnknown) { - xf86MonPtr DDC = (xf86MonPtr) (xf86Screens[i]->monitor->DDC); - - PictureSetSubpixelOrder(xf86Screens[i]->pScreen, - DDC ? - (DDC->features.input_type ? - SubPixelHorizontalRGB : SubPixelNone) : - SubPixelUnknown); - } - - /* - * If the driver hasn't set up its own RANDR support, install the - * fallback support. - */ - xf86EnsureRANDR(xf86Screens[i]->pScreen); - } - - for (i = 0; i < xf86NumGPUScreens; i++) { - ScrnInfoPtr pScrn = xf86GPUScreens[i]; - xf86VGAarbiterLock(pScrn); - - /* - * Almost everything uses these defaults, and many of those that - * don't, will wrap them. - */ - pScrn->EnableDisableFBAccess = xf86EnableDisableFBAccess; -#ifdef XFreeXDGA - pScrn->SetDGAMode = xf86SetDGAMode; -#endif - scr_index = AddGPUScreen(xf86ScreenInit, argc, argv); - xf86VGAarbiterUnlock(pScrn); - if (scr_index == i) { - dixSetPrivate(&screenInfo.gpuscreens[scr_index]->devPrivates, - xf86ScreenKey, xf86GPUScreens[i]); - pScrn->pScreen = screenInfo.gpuscreens[scr_index]; - /* The driver should set this, but make sure it is set anyway */ - pScrn->vtSema = TRUE; - } else { - FatalError("AddScreen/ScreenInit failed for gpu driver %d %d\n", i, scr_index); - } - } - - for (i = 0; i < xf86NumGPUScreens; i++) { - int scrnum = xf86GPUScreens[i]->confScreen->screennum; - AttachUnboundGPU(xf86Screens[scrnum]->pScreen, xf86GPUScreens[i]->pScreen); - } - - xf86AutoConfigOutputDevices(); - - xf86VGAarbiterWrapFunctions(); - if (sigio_blocked) - input_unlock(); - - xf86InitOrigins(); - - xf86Resetting = FALSE; - xf86Initialising = FALSE; - - RegisterBlockAndWakeupHandlers((ServerBlockHandlerProcPtr) NoopDDA, xf86Wakeup, - NULL); -} - -/** - * Initialize all supported input devices present and referenced in the - * xorg.conf. - */ -void -InitInput(int argc, char **argv) -{ - InputInfoPtr *pInfo; - DeviceIntPtr dev; - - xf86Info.vtRequestsPending = FALSE; - - /* Enable threaded input */ - InputThreadPreInit(); - - mieqInit(); - - /* Initialize all configured input devices */ - for (pInfo = xf86ConfigLayout.inputs; pInfo && *pInfo; pInfo++) { - (*pInfo)->options = - xf86AddNewOption((*pInfo)->options, "driver", (*pInfo)->driver); - (*pInfo)->options = - xf86AddNewOption((*pInfo)->options, "identifier", (*pInfo)->name); - /* If one fails, the others will too */ - if (NewInputDeviceRequest((*pInfo)->options, NULL, &dev) == BadAlloc) - break; - } - - config_init(); -} - -void -CloseInput(void) -{ - config_fini(); - mieqFini(); -} - -/* - * OsVendorInit -- - * OS/Vendor-specific initialisations. Called from OsInit(), which - * is called by dix before establishing the well known sockets. - */ - -void -OsVendorInit(void) -{ - static Bool beenHere = FALSE; - - OsSignal(SIGCHLD, SIG_DFL); /* Need to wait for child processes */ - - if (!beenHere) { - umask(022); - xf86LogInit(); - } - - /* Set stderr to non-blocking. */ -#ifndef O_NONBLOCK -#if defined(FNDELAY) -#define O_NONBLOCK FNDELAY -#elif defined(O_NDELAY) -#define O_NONBLOCK O_NDELAY -#endif - -#ifdef O_NONBLOCK - if (!beenHere) { - if (PrivsElevated()) { - int status; - - status = fcntl(fileno(stderr), F_GETFL, 0); - if (status != -1) { - fcntl(fileno(stderr), F_SETFL, status | O_NONBLOCK); - } - } - } -#endif -#endif - - beenHere = TRUE; -} - -/* - * ddxGiveUp -- - * Device dependent cleanup. Called by by dix before normal server death. - * For SYSV386 we must switch the terminal back to normal mode. No error- - * checking here, since there should be restored as much as possible. - */ - -void -ddxGiveUp(enum ExitCode error) -{ - int i; - - if (error == EXIT_ERR_ABORT) { - input_lock(); - - /* try to restore the original video state */ -#ifdef DPMSExtension /* Turn screens back on */ - if (DPMSPowerLevel != DPMSModeOn) - DPMSSet(serverClient, DPMSModeOn); -#endif - if (xf86Screens) { - for (i = 0; i < xf86NumScreens; i++) - if (xf86Screens[i]->vtSema) { - /* - * if we are aborting before ScreenInit() has finished we - * might not have been wrapped yet. Therefore enable screen - * explicitly. - */ - xf86VGAarbiterLock(xf86Screens[i]); - (xf86Screens[i]->LeaveVT) (xf86Screens[i]); - xf86VGAarbiterUnlock(xf86Screens[i]); - } - } - } - - xf86VGAarbiterFini(); - - if (xf86OSPMClose) - xf86OSPMClose(); - xf86OSPMClose = NULL; - - for (i = 0; i < xf86NumScreens; i++) { - /* - * zero all access functions to - * trap calls when switched away. - */ - xf86Screens[i]->vtSema = FALSE; - } - - if (xorgHWOpenConsole) - xf86CloseConsole(); - - systemd_logind_fini(); - dbus_core_fini(); - - xf86CloseLog(error); -} - -void -OsVendorFatalError(const char *f, va_list args) -{ -#ifdef VENDORSUPPORT - ErrorFSigSafe("\nPlease refer to your Operating System Vendor support " - "pages\nat %s for support on this crash.\n", VENDORSUPPORT); -#else - ErrorFSigSafe("\nPlease consult the " XVENDORNAME " support \n\t at " - __VENDORDWEBSUPPORT__ "\n for help. \n"); -#endif - if (xf86LogFile && xf86LogFileWasOpened) - ErrorFSigSafe("Please also check the log file at \"%s\" for additional " - "information.\n", xf86LogFile); - ErrorFSigSafe("\n"); -} - -int -xf86SetVerbosity(int verb) -{ - int save = xf86Verbose; - - xf86Verbose = verb; - LogSetParameter(XLOG_VERBOSITY, verb); - return save; -} - -int -xf86SetLogVerbosity(int verb) -{ - int save = xf86LogVerbose; - - xf86LogVerbose = verb; - LogSetParameter(XLOG_FILE_VERBOSITY, verb); - return save; -} - -static void -xf86PrintDefaultModulePath(void) -{ - ErrorF("%s\n", DEFAULT_MODULE_PATH); -} - -static void -xf86PrintDefaultLibraryPath(void) -{ - ErrorF("%s\n", DEFAULT_LIBRARY_PATH); -} - -static void -xf86CheckPrivs(const char *option, const char *arg) -{ - if (PrivsElevated() && !xf86PathIsSafe(arg)) { - FatalError("\nInvalid argument for %s - \"%s\"\n" - "\tWith elevated privileges %s must specify a relative path\n" - "\twithout any \"..\" elements.\n\n", option, arg, option); - } -} - -/* - * ddxProcessArgument -- - * Process device-dependent command line args. Returns 0 if argument is - * not device dependent, otherwise Count of number of elements of argv - * that are part of a device dependent commandline option. - * - */ - -/* ARGSUSED */ -int -ddxProcessArgument(int argc, char **argv, int i) -{ - /* First the options that are not allowed with elevated privileges */ - if (!strcmp(argv[i], "-modulepath")) { - CHECK_FOR_REQUIRED_ARGUMENTS(1); - if (xf86PrivsElevated()) - FatalError("\nInvalid argument -modulepath " - "with elevated privileges\n"); - xf86ModulePath = argv[i + 1]; - xf86ModPathFrom = X_CMDLINE; - return 2; - } - if (!strcmp(argv[i], "-logfile")) { - CHECK_FOR_REQUIRED_ARGUMENTS(1); - if (xf86PrivsElevated()) - FatalError("\nInvalid argument -logfile " - "with elevated privileges\n"); - xf86LogFile = argv[i + 1]; - xf86LogFileFrom = X_CMDLINE; - return 2; - } - if (!strcmp(argv[i], "-config") || !strcmp(argv[i], "-xf86config")) { - CHECK_FOR_REQUIRED_ARGUMENTS(1); - xf86CheckPrivs(argv[i], argv[i + 1]); - xf86ConfigFile = argv[i + 1]; - return 2; - } - if (!strcmp(argv[i], "-configdir")) { - CHECK_FOR_REQUIRED_ARGUMENTS(1); - xf86CheckPrivs(argv[i], argv[i + 1]); - xf86ConfigDir = argv[i + 1]; - return 2; - } -#ifdef XF86VIDMODE - if (!strcmp(argv[i], "-disableVidMode")) { - xf86VidModeDisabled = TRUE; - return 1; - } - if (!strcmp(argv[i], "-allowNonLocalXvidtune")) { - xf86VidModeAllowNonLocal = TRUE; - return 1; - } -#endif - if (!strcmp(argv[i], "-allowMouseOpenFail")) { - xf86AllowMouseOpenFail = TRUE; - return 1; - } - if (!strcmp(argv[i], "-ignoreABI")) { - LoaderSetOptions(LDR_OPT_ABI_MISMATCH_NONFATAL); - return 1; - } - if (!strcmp(argv[i], "-verbose")) { - if (++i < argc && argv[i]) { - char *end; - long val; - - val = strtol(argv[i], &end, 0); - if (*end == '\0') { - xf86SetVerbosity(val); - return 2; - } - } - xf86SetVerbosity(++xf86Verbose); - return 1; - } - if (!strcmp(argv[i], "-logverbose")) { - if (++i < argc && argv[i]) { - char *end; - long val; - - val = strtol(argv[i], &end, 0); - if (*end == '\0') { - xf86SetLogVerbosity(val); - return 2; - } - } - xf86SetLogVerbosity(++xf86LogVerbose); - return 1; - } - if (!strcmp(argv[i], "-quiet")) { - xf86SetVerbosity(-1); - return 1; - } - if (!strcmp(argv[i], "-showconfig") || !strcmp(argv[i], "-version")) { - xf86PrintBanner(); - exit(0); - } - if (!strcmp(argv[i], "-showDefaultModulePath")) { - xf86PrintDefaultModulePath(); - exit(0); - } - if (!strcmp(argv[i], "-showDefaultLibPath")) { - xf86PrintDefaultLibraryPath(); - exit(0); - } - /* Notice the -fp flag, but allow it to pass to the dix layer */ - if (!strcmp(argv[i], "-fp")) { - xf86fpFlag = TRUE; - return 0; - } - /* Notice the -bs flag, but allow it to pass to the dix layer */ - if (!strcmp(argv[i], "-bs")) { - xf86bsDisableFlag = TRUE; - return 0; - } - /* Notice the +bs flag, but allow it to pass to the dix layer */ - if (!strcmp(argv[i], "+bs")) { - xf86bsEnableFlag = TRUE; - return 0; - } - /* Notice the -s flag, but allow it to pass to the dix layer */ - if (!strcmp(argv[i], "-s")) { - xf86sFlag = TRUE; - return 0; - } - if (!strcmp(argv[i], "-pixmap32") || !strcmp(argv[i], "-pixmap24")) { - /* silently accept */ - return 1; - } - if (!strcmp(argv[i], "-fbbpp")) { - int bpp; - - CHECK_FOR_REQUIRED_ARGUMENTS(1); - if (sscanf(argv[++i], "%d", &bpp) == 1) { - xf86FbBpp = bpp; - return 2; - } - else { - ErrorF("Invalid fbbpp\n"); - return 0; - } - } - if (!strcmp(argv[i], "-depth")) { - int depth; - - CHECK_FOR_REQUIRED_ARGUMENTS(1); - if (sscanf(argv[++i], "%d", &depth) == 1) { - xf86Depth = depth; - return 2; - } - else { - ErrorF("Invalid depth\n"); - return 0; - } - } - if (!strcmp(argv[i], "-weight")) { - int red, green, blue; - - CHECK_FOR_REQUIRED_ARGUMENTS(1); - if (sscanf(argv[++i], "%1d%1d%1d", &red, &green, &blue) == 3) { - xf86Weight.red = red; - xf86Weight.green = green; - xf86Weight.blue = blue; - return 2; - } - else { - ErrorF("Invalid weighting\n"); - return 0; - } - } - if (!strcmp(argv[i], "-gamma") || !strcmp(argv[i], "-rgamma") || - !strcmp(argv[i], "-ggamma") || !strcmp(argv[i], "-bgamma")) { - double gamma; - - CHECK_FOR_REQUIRED_ARGUMENTS(1); - if (sscanf(argv[++i], "%lf", &gamma) == 1) { - if (gamma < GAMMA_MIN || gamma > GAMMA_MAX) { - ErrorF("gamma out of range, only %.2f <= gamma_value <= %.1f" - " is valid\n", GAMMA_MIN, GAMMA_MAX); - return 0; - } - if (!strcmp(argv[i - 1], "-gamma")) - xf86Gamma.red = xf86Gamma.green = xf86Gamma.blue = gamma; - else if (!strcmp(argv[i - 1], "-rgamma")) - xf86Gamma.red = gamma; - else if (!strcmp(argv[i - 1], "-ggamma")) - xf86Gamma.green = gamma; - else if (!strcmp(argv[i - 1], "-bgamma")) - xf86Gamma.blue = gamma; - return 2; - } - } - if (!strcmp(argv[i], "-layout")) { - CHECK_FOR_REQUIRED_ARGUMENTS(1); - xf86LayoutName = argv[++i]; - return 2; - } - if (!strcmp(argv[i], "-screen")) { - CHECK_FOR_REQUIRED_ARGUMENTS(1); - xf86ScreenName = argv[++i]; - return 2; - } - if (!strcmp(argv[i], "-pointer")) { - CHECK_FOR_REQUIRED_ARGUMENTS(1); - xf86PointerName = argv[++i]; - return 2; - } - if (!strcmp(argv[i], "-keyboard")) { - CHECK_FOR_REQUIRED_ARGUMENTS(1); - xf86KeyboardName = argv[++i]; - return 2; - } - if (!strcmp(argv[i], "-nosilk")) { - xf86silkenMouseDisableFlag = TRUE; - return 1; - } -#ifdef HAVE_ACPI - if (!strcmp(argv[i], "-noacpi")) { - xf86acpiDisableFlag = TRUE; - return 1; - } -#endif - if (!strcmp(argv[i], "-configure")) { - if (getuid() != 0 && geteuid() == 0) { - ErrorF("The '-configure' option can only be used by root.\n"); - exit(1); - } - xf86DoConfigure = TRUE; - xf86AllowMouseOpenFail = TRUE; - return 1; - } - if (!strcmp(argv[i], "-showopts")) { - if (getuid() != 0 && geteuid() == 0) { - ErrorF("The '-showopts' option can only be used by root.\n"); - exit(1); - } - xf86DoShowOptions = TRUE; - return 1; - } -#ifdef XSERVER_LIBPCIACCESS - if (!strcmp(argv[i], "-isolateDevice")) { - CHECK_FOR_REQUIRED_ARGUMENTS(1); - if (strncmp(argv[++i], "PCI:", 4)) { - FatalError("Bus types other than PCI not yet isolable\n"); - } - xf86PciIsolateDevice(argv[i]); - return 2; - } -#endif - /* Notice cmdline xkbdir, but pass to dix as well */ - if (!strcmp(argv[i], "-xkbdir")) { - xf86xkbdirFlag = TRUE; - return 0; - } - if (!strcmp(argv[i], "-novtswitch")) { - xf86Info.autoVTSwitch = FALSE; - return 1; - } - if (!strcmp(argv[i], "-sharevts")) { - xf86Info.ShareVTs = TRUE; - return 1; - } - if (!strcmp(argv[i], "-iglx") || !strcmp(argv[i], "+iglx")) { - xf86Info.iglxFrom = X_CMDLINE; - return 0; - } - if (!strcmp(argv[i], "-noautoBindGPU")) { - xf86AutoBindGPUDisabled = TRUE; - return 1; - } - - /* OS-specific processing */ - return xf86ProcessArgument(argc, argv, i); -} - -/* - * ddxUseMsg -- - * Print out correct use of device dependent commandline options. - * Maybe the user now knows what really to do ... - */ - -void -ddxUseMsg(void) -{ - ErrorF("\n"); - ErrorF("\n"); - ErrorF("Device Dependent Usage\n"); - if (!PrivsElevated()) { - ErrorF("-modulepath paths specify the module search path\n"); - ErrorF("-logfile file specify a log file name\n"); - ErrorF("-configure probe for devices and write an " - XCONFIGFILE "\n"); - ErrorF - ("-showopts print available options for all installed drivers\n"); - } - ErrorF - ("-config file specify a configuration file, relative to the\n"); - ErrorF(" " XCONFIGFILE - " search path, only root can use absolute\n"); - ErrorF - ("-configdir dir specify a configuration directory, relative to the\n"); - ErrorF(" " XCONFIGDIR - " search path, only root can use absolute\n"); - ErrorF("-verbose [n] verbose startup messages\n"); - ErrorF("-logverbose [n] verbose log messages\n"); - ErrorF("-quiet minimal startup messages\n"); - ErrorF("-fbbpp n set bpp for the framebuffer. Default: 8\n"); - ErrorF("-depth n set colour depth. Default: 8\n"); - ErrorF - ("-gamma f set gamma value (0.1 < f < 10.0) Default: 1.0\n"); - ErrorF("-rgamma f set gamma value for red phase\n"); - ErrorF("-ggamma f set gamma value for green phase\n"); - ErrorF("-bgamma f set gamma value for blue phase\n"); - ErrorF - ("-weight nnn set RGB weighting at 16 bpp. Default: 565\n"); - ErrorF("-layout name specify the ServerLayout section name\n"); - ErrorF("-screen name specify the Screen section name\n"); - ErrorF - ("-keyboard name specify the core keyboard InputDevice name\n"); - ErrorF - ("-pointer name specify the core pointer InputDevice name\n"); - ErrorF("-nosilk disable Silken Mouse\n"); -#ifdef XF86VIDMODE - ErrorF("-disableVidMode disable mode adjustments with xvidtune\n"); - ErrorF - ("-allowNonLocalXvidtune allow xvidtune to be run as a non-local client\n"); -#endif - ErrorF - ("-allowMouseOpenFail start server even if the mouse can't be initialized\n"); - ErrorF("-ignoreABI make module ABI mismatches non-fatal\n"); -#ifdef XSERVER_LIBPCIACCESS - ErrorF - ("-isolateDevice bus_id restrict device resets to bus_id (PCI only)\n"); -#endif - ErrorF("-version show the server version\n"); - ErrorF("-showDefaultModulePath show the server default module path\n"); - ErrorF("-showDefaultLibPath show the server default library path\n"); - ErrorF - ("-novtswitch don't automatically switch VT at reset & exit\n"); - ErrorF("-sharevts share VTs with another X server\n"); - /* OS-specific usage */ - xf86UseMsg(); - ErrorF("\n"); -} - -/* - * xf86LoadModules iterates over a list that is being passed in. - */ -Bool -xf86LoadModules(const char **list, void **optlist) -{ - int errmaj; - void *opt; - int i; - char *name; - Bool failed = FALSE; - - if (!list) - return TRUE; - - for (i = 0; list[i] != NULL; i++) { - - /* Normalise the module name */ - name = xf86NormalizeName(list[i]); - - /* Skip empty names */ - if (name == NULL || *name == '\0') { - free(name); - continue; - } - - /* Replace obsolete keyboard driver with kbd */ - if (!xf86NameCmp(name, "keyboard")) { - strcpy(name, "kbd"); - } - - if (optlist) - opt = optlist[i]; - else - opt = NULL; - - if (!LoadModule(name, opt, NULL, &errmaj)) { - LoaderErrorMsg(NULL, name, errmaj, 0); - failed = TRUE; - } - free(name); - } - return !failed; -} - -/* Pixmap format stuff */ - -PixmapFormatPtr -xf86GetPixFormat(ScrnInfoPtr pScrn, int depth) -{ - int i; - - for (i = 0; i < numFormats; i++) - if (formats[i].depth == depth) - break; - if (i != numFormats) - return &formats[i]; - else if (!formatsDone) { - /* Check for screen-specified formats */ - for (i = 0; i < pScrn->numFormats; i++) - if (pScrn->formats[i].depth == depth) - break; - if (i != pScrn->numFormats) - return &pScrn->formats[i]; - } - return NULL; -} - -int -xf86GetBppFromDepth(ScrnInfoPtr pScrn, int depth) -{ - PixmapFormatPtr format; - - format = xf86GetPixFormat(pScrn, depth); - if (format) - return format->bitsPerPixel; - else - return 0; -} - -#ifdef DDXBEFORERESET -void -ddxBeforeReset(void) -{ -} -#endif - -#if INPUTTHREAD -/** This function is called in Xserver/os/inputthread.c when starting - the input thread. */ -void -ddxInputThreadInit(void) -{ - xf86OSInputThreadInit(); -} -#endif diff --git a/hw/xfree86/common/xf86MatchDrivers.h b/hw/xfree86/common/xf86MatchDrivers.h deleted file mode 100644 index 4663af478..000000000 --- a/hw/xfree86/common/xf86MatchDrivers.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright © 2015 NVIDIA Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifndef _xf86_match_drivers_h -#define _xf86_match_drivers_h - -#define MATCH_DRIVERS_LIMIT 20 - -typedef struct _XF86MatchedDrivers { - char *matches[MATCH_DRIVERS_LIMIT]; - int nmatches; -} XF86MatchedDrivers; - -/* - * prototypes - */ -void xf86AddMatchedDriver(XF86MatchedDrivers *, const char *); - -#endif /* _xf86_match_drivers_h */ - diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c deleted file mode 100644 index eb0885571..000000000 --- a/hw/xfree86/common/xf86Mode.c +++ /dev/null @@ -1,2122 +0,0 @@ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * LCM() and scanLineWidth() are: - * - * Copyright 1997 through 2004 by Marc Aurele La France (TSI @ UQV), tsi@xfree86.org - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of Marc Aurele La France not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. Marc Aurele La France makes no representations - * about the suitability of this software for any purpose. It is provided - * "as-is" without express or implied warranty. - * - * MARC AURELE LA FRANCE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO - * EVENT SHALL MARC AURELE LA FRANCE BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Copyright 1990,91,92,93 by Thomas Roell, Germany. - * Copyright 1991,92,93 by SGCS (Snitily Graphics Consulting Services), USA. - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation, and that the name of Thomas Roell nor - * SGCS be used in advertising or publicity pertaining to distribution - * of the software without specific, written prior permission. - * Thomas Roell nor SGCS makes no representations about the suitability - * of this software for any purpose. It is provided "as is" without - * express or implied warranty. - * - * THOMAS ROELL AND SGCS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL THOMAS ROELL OR SGCS BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Authors: Dirk Hohndel - * David Dawes - * Marc La France - * ... and others - * - * This file includes helper functions for mode related things. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86Modes.h" -#include "xf86Crtc.h" -#include "os.h" -#include "servermd.h" -#include "globals.h" -#include "xf86.h" -#include "xf86Priv.h" -#include "edid.h" - -static void -printModeRejectMessage(int index, DisplayModePtr p, int status) -{ - const char *type; - - if (p->type & M_T_BUILTIN) - type = "built-in "; - else if (p->type & M_T_DEFAULT) - type = "default "; - else if (p->type & M_T_DRIVER) - type = "driver "; - else - type = ""; - - xf86DrvMsg(index, X_INFO, "Not using %smode \"%s\" (%s)\n", type, p->name, - xf86ModeStatusToString(status)); -} - -/* - * Find closest clock to given frequency (in kHz). This assumes the - * number of clocks is greater than zero. - */ -static int -xf86GetNearestClock(ScrnInfoPtr scrp, int freq, Bool allowDiv2, - int DivFactor, int MulFactor, int *divider) -{ - int nearestClock = 0, nearestDiv = 1; - int minimumGap = abs(freq - scrp->clock[0]); - int i, j, k, gap; - - if (allowDiv2) - k = 2; - else - k = 1; - - /* Must set this here in case the best match is scrp->clock[0] */ - if (divider != NULL) - *divider = 0; - - for (i = 0; i < scrp->numClocks; i++) { - for (j = 1; j <= k; j++) { - gap = abs((freq * j) - ((scrp->clock[i] * DivFactor) / MulFactor)); - if ((gap < minimumGap) || ((gap == minimumGap) && (j < nearestDiv))) { - minimumGap = gap; - nearestClock = i; - nearestDiv = j; - if (divider != NULL) - *divider = (j - 1) * V_CLKDIV2; - } - } - } - return nearestClock; -} - -/* - * xf86ModeStatusToString - * - * Convert a ModeStatus value to a printable message - */ - -const char * -xf86ModeStatusToString(ModeStatus status) -{ - switch (status) { - case MODE_OK: - return "Mode OK"; - case MODE_HSYNC: - return "hsync out of range"; - case MODE_VSYNC: - return "vrefresh out of range"; - case MODE_H_ILLEGAL: - return "illegal horizontal timings"; - case MODE_V_ILLEGAL: - return "illegal vertical timings"; - case MODE_BAD_WIDTH: - return "width requires unsupported line pitch"; - case MODE_NOMODE: - return "no mode of this name"; - case MODE_NO_INTERLACE: - return "interlace mode not supported"; - case MODE_NO_DBLESCAN: - return "doublescan mode not supported"; - case MODE_NO_VSCAN: - return "multiscan mode not supported"; - case MODE_MEM: - return "insufficient memory for mode"; - case MODE_VIRTUAL_X: - return "width too large for virtual size"; - case MODE_VIRTUAL_Y: - return "height too large for virtual size"; - case MODE_MEM_VIRT: - return "insufficient memory given virtual size"; - case MODE_NOCLOCK: - return "no clock available for mode"; - case MODE_CLOCK_HIGH: - return "mode clock too high"; - case MODE_CLOCK_LOW: - return "mode clock too low"; - case MODE_CLOCK_RANGE: - return "bad mode clock/interlace/doublescan"; - case MODE_BAD_HVALUE: - return "horizontal timing out of range"; - case MODE_BAD_VVALUE: - return "vertical timing out of range"; - case MODE_BAD_VSCAN: - return "VScan value out of range"; - case MODE_HSYNC_NARROW: - return "horizontal sync too narrow"; - case MODE_HSYNC_WIDE: - return "horizontal sync too wide"; - case MODE_HBLANK_NARROW: - return "horizontal blanking too narrow"; - case MODE_HBLANK_WIDE: - return "horizontal blanking too wide"; - case MODE_VSYNC_NARROW: - return "vertical sync too narrow"; - case MODE_VSYNC_WIDE: - return "vertical sync too wide"; - case MODE_VBLANK_NARROW: - return "vertical blanking too narrow"; - case MODE_VBLANK_WIDE: - return "vertical blanking too wide"; - case MODE_PANEL: - return "exceeds panel dimensions"; - case MODE_INTERLACE_WIDTH: - return "width too large for interlaced mode"; - case MODE_ONE_WIDTH: - return "all modes must have the same width"; - case MODE_ONE_HEIGHT: - return "all modes must have the same height"; - case MODE_ONE_SIZE: - return "all modes must have the same resolution"; - case MODE_NO_REDUCED: - return "monitor doesn't support reduced blanking"; - case MODE_BANDWIDTH: - return "mode requires too much memory bandwidth"; - case MODE_BAD: - return "unknown reason"; - case MODE_ERROR: - return "internal error"; - default: - return "unknown"; - } -} - -/* - * xf86ShowClockRanges() -- Print the clock ranges allowed - * and the clock values scaled by ClockMulFactor and ClockDivFactor - */ -void -xf86ShowClockRanges(ScrnInfoPtr scrp, ClockRangePtr clockRanges) -{ - ClockRangePtr cp; - int MulFactor = 1; - int DivFactor = 1; - int i, j; - int scaledClock; - - for (cp = clockRanges; cp != NULL; cp = cp->next) { - DivFactor = max(1, cp->ClockDivFactor); - MulFactor = max(1, cp->ClockMulFactor); - if (scrp->progClock) { - if (cp->minClock) { - if (cp->maxClock) { - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Clock range: %6.2f to %6.2f MHz\n", - (double) cp->minClock / 1000.0, - (double) cp->maxClock / 1000.0); - } - else { - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Minimum clock: %6.2f MHz\n", - (double) cp->minClock / 1000.0); - } - } - else { - if (cp->maxClock) { - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Maximum clock: %6.2f MHz\n", - (double) cp->maxClock / 1000.0); - } - } - } - else if (DivFactor > 1 || MulFactor > 1) { - j = 0; - for (i = 0; i < scrp->numClocks; i++) { - scaledClock = (scrp->clock[i] * DivFactor) / MulFactor; - if (scaledClock >= cp->minClock && scaledClock <= cp->maxClock) { - if ((j % 8) == 0) { - if (j > 0) - xf86ErrorF("\n"); - xf86DrvMsg(scrp->scrnIndex, X_INFO, "scaled clocks:"); - } - xf86ErrorF(" %6.2f", (double) scaledClock / 1000.0); - j++; - } - } - xf86ErrorF("\n"); - } - } -} - -static Bool -modeInClockRange(ClockRangePtr cp, DisplayModePtr p) -{ - return ((p->Clock >= cp->minClock) && - (p->Clock <= cp->maxClock) && - (cp->interlaceAllowed || !(p->Flags & V_INTERLACE)) && - (cp->doubleScanAllowed || - ((p->VScan <= 1) && !(p->Flags & V_DBLSCAN)))); -} - -/* - * xf86FindClockRangeForMode() [... like the name says ...] - */ -static ClockRangePtr -xf86FindClockRangeForMode(ClockRangePtr clockRanges, DisplayModePtr p) -{ - ClockRangePtr cp; - - for (cp = clockRanges;; cp = cp->next) - if (!cp || modeInClockRange(cp, p)) - return cp; -} - -/* - * xf86HandleBuiltinMode() - handles built-in modes - */ -static ModeStatus -xf86HandleBuiltinMode(ScrnInfoPtr scrp, - DisplayModePtr p, - DisplayModePtr modep, - ClockRangePtr clockRanges, Bool allowDiv2) -{ - ClockRangePtr cp; - int extraFlags = 0; - int MulFactor = 1; - int DivFactor = 1; - int clockIndex; - - /* Reject previously rejected modes */ - if (p->status != MODE_OK) - return p->status; - - /* Reject previously considered modes */ - if (p->prev) - return MODE_NOMODE; - - if ((p->type & M_T_CLOCK_C) == M_T_CLOCK_C) { - /* Check clock is in range */ - cp = xf86FindClockRangeForMode(clockRanges, p); - if (cp == NULL) { - modep->type = p->type; - p->status = MODE_CLOCK_RANGE; - return MODE_CLOCK_RANGE; - } - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - if (!scrp->progClock) { - clockIndex = xf86GetNearestClock(scrp, p->Clock, allowDiv2, - cp->ClockDivFactor, - cp->ClockMulFactor, &extraFlags); - modep->Clock = (scrp->clock[clockIndex] * DivFactor) - / MulFactor; - modep->ClockIndex = clockIndex; - modep->SynthClock = scrp->clock[clockIndex]; - if (extraFlags & V_CLKDIV2) { - modep->Clock /= 2; - modep->SynthClock /= 2; - } - } - else { - modep->Clock = p->Clock; - modep->ClockIndex = -1; - modep->SynthClock = (modep->Clock * MulFactor) - / DivFactor; - } - modep->PrivFlags = cp->PrivFlags; - } - else { - if (!scrp->progClock) { - modep->Clock = p->Clock; - modep->ClockIndex = p->ClockIndex; - modep->SynthClock = p->SynthClock; - } - else { - modep->Clock = p->Clock; - modep->ClockIndex = -1; - modep->SynthClock = p->SynthClock; - } - modep->PrivFlags = p->PrivFlags; - } - modep->type = p->type; - modep->HDisplay = p->HDisplay; - modep->HSyncStart = p->HSyncStart; - modep->HSyncEnd = p->HSyncEnd; - modep->HTotal = p->HTotal; - modep->HSkew = p->HSkew; - modep->VDisplay = p->VDisplay; - modep->VSyncStart = p->VSyncStart; - modep->VSyncEnd = p->VSyncEnd; - modep->VTotal = p->VTotal; - modep->VScan = p->VScan; - modep->Flags = p->Flags | extraFlags; - modep->CrtcHDisplay = p->CrtcHDisplay; - modep->CrtcHBlankStart = p->CrtcHBlankStart; - modep->CrtcHSyncStart = p->CrtcHSyncStart; - modep->CrtcHSyncEnd = p->CrtcHSyncEnd; - modep->CrtcHBlankEnd = p->CrtcHBlankEnd; - modep->CrtcHTotal = p->CrtcHTotal; - modep->CrtcHSkew = p->CrtcHSkew; - modep->CrtcVDisplay = p->CrtcVDisplay; - modep->CrtcVBlankStart = p->CrtcVBlankStart; - modep->CrtcVSyncStart = p->CrtcVSyncStart; - modep->CrtcVSyncEnd = p->CrtcVSyncEnd; - modep->CrtcVBlankEnd = p->CrtcVBlankEnd; - modep->CrtcVTotal = p->CrtcVTotal; - modep->CrtcHAdjusted = p->CrtcHAdjusted; - modep->CrtcVAdjusted = p->CrtcVAdjusted; - modep->HSync = p->HSync; - modep->VRefresh = p->VRefresh; - modep->Private = p->Private; - modep->PrivSize = p->PrivSize; - - p->prev = modep; - - return MODE_OK; -} - -/* - * xf86LookupMode - * - * This function returns a mode from the given list which matches the - * given name. When multiple modes with the same name are available, - * the method of picking the matching mode is determined by the - * strategy selected. - * - * This function takes the following parameters: - * scrp ScrnInfoPtr - * modep pointer to the returned mode, which must have the name - * field filled in. - * clockRanges a list of clock ranges. This is optional when all the - * modes are built-in modes. - * strategy how to decide which mode to use from multiple modes with - * the same name - * - * In addition, the following fields from the ScrnInfoRec are used: - * modePool the list of monitor modes compatible with the driver - * clocks a list of discrete clocks - * numClocks number of discrete clocks - * progClock clock is programmable - * - * If a mode was found, its values are filled in to the area pointed to - * by modep, If a mode was not found the return value indicates the - * reason. - */ - -static ModeStatus -xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep, - ClockRangePtr clockRanges, LookupModeFlags strategy) -{ - DisplayModePtr p, bestMode = NULL; - ClockRangePtr cp; - int i, k, gap, minimumGap = CLOCK_TOLERANCE + 1; - double refresh, bestRefresh = 0.0; - Bool found = FALSE; - int extraFlags = 0; - int clockIndex = -1; - int MulFactor = 1; - int DivFactor = 1; - int ModePrivFlags = 0; - ModeStatus status = MODE_NOMODE; - Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0; - int n; - - const int types[] = { - M_T_BUILTIN | M_T_PREFERRED, - M_T_BUILTIN, - M_T_USERDEF | M_T_PREFERRED, - M_T_USERDEF, - M_T_DRIVER | M_T_PREFERRED, - M_T_DRIVER, - 0 - }; - const int ntypes = ARRAY_SIZE(types); - - strategy &= ~(LOOKUP_CLKDIV2 | LOOKUP_OPTIONAL_TOLERANCES); - - /* Some sanity checking */ - if (scrp == NULL || scrp->modePool == NULL || - (!scrp->progClock && scrp->numClocks == 0)) { - ErrorF("xf86LookupMode: called with invalid scrnInfoRec\n"); - return MODE_ERROR; - } - if (modep == NULL || modep->name == NULL) { - ErrorF("xf86LookupMode: called with invalid modep\n"); - return MODE_ERROR; - } - for (cp = clockRanges; cp != NULL; cp = cp->next) { - /* DivFactor and MulFactor must be > 0 */ - cp->ClockDivFactor = max(1, cp->ClockDivFactor); - cp->ClockMulFactor = max(1, cp->ClockMulFactor); - } - - /* Scan the mode pool for matching names */ - for (n = 0; n < ntypes; n++) { - int type = types[n]; - - for (p = scrp->modePool; p != NULL; p = p->next) { - - /* scan through the modes in the sort order above */ - if ((p->type & type) != type) - continue; - - if (strcmp(p->name, modep->name) == 0) { - - /* Skip over previously rejected modes */ - if (p->status != MODE_OK) { - if (!found) - status = p->status; - continue; - } - - /* Skip over previously considered modes */ - if (p->prev) - continue; - - if (p->type & M_T_BUILTIN) { - return xf86HandleBuiltinMode(scrp, p, modep, clockRanges, - allowDiv2); - } - - /* Check clock is in range */ - cp = xf86FindClockRangeForMode(clockRanges, p); - if (cp == NULL) { - /* - * XXX Could do more here to provide a more detailed - * reason for not finding a mode. - */ - p->status = MODE_CLOCK_RANGE; - if (!found) - status = MODE_CLOCK_RANGE; - continue; - } - - /* - * If programmable clock and strategy is not - * LOOKUP_BEST_REFRESH, the required mode has been found, - * otherwise record the refresh and continue looking. - */ - if (scrp->progClock) { - found = TRUE; - if (strategy != LOOKUP_BEST_REFRESH) { - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - break; - } - refresh = xf86ModeVRefresh(p); - if (p->Flags & V_INTERLACE) - refresh /= INTERLACE_REFRESH_WEIGHT; - if (refresh > bestRefresh) { - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - bestRefresh = refresh; - } - continue; - } - - /* - * Clock is in range, so if it is not a programmable clock, find - * a matching clock. - */ - - i = xf86GetNearestClock(scrp, p->Clock, allowDiv2, - cp->ClockDivFactor, cp->ClockMulFactor, - &k); - /* - * If the clock is too far from the requested clock, this - * mode is no good. - */ - if (k & V_CLKDIV2) - gap = abs((p->Clock * 2) - - ((scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor)); - else - gap = abs(p->Clock - - ((scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor)); - if (gap > minimumGap) { - p->status = MODE_NOCLOCK; - if (!found) - status = MODE_NOCLOCK; - continue; - } - found = TRUE; - - if (strategy == LOOKUP_BEST_REFRESH) { - refresh = xf86ModeVRefresh(p); - if (p->Flags & V_INTERLACE) - refresh /= INTERLACE_REFRESH_WEIGHT; - if (refresh > bestRefresh) { - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - extraFlags = k; - clockIndex = i; - bestRefresh = refresh; - } - continue; - } - if (strategy == LOOKUP_CLOSEST_CLOCK) { - if (gap < minimumGap) { - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - extraFlags = k; - clockIndex = i; - minimumGap = gap; - } - continue; - } - /* - * If strategy is neither LOOKUP_BEST_REFRESH or - * LOOKUP_CLOSEST_CLOCK the required mode has been found. - */ - bestMode = p; - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - extraFlags = k; - clockIndex = i; - break; - } - } - if (found) - break; - } - if (!found || bestMode == NULL) - return status; - - /* Fill in the mode parameters */ - if (scrp->progClock) { - modep->Clock = bestMode->Clock; - modep->ClockIndex = -1; - modep->SynthClock = (modep->Clock * MulFactor) / DivFactor; - } - else { - modep->Clock = (scrp->clock[clockIndex] * DivFactor) / MulFactor; - modep->ClockIndex = clockIndex; - modep->SynthClock = scrp->clock[clockIndex]; - if (extraFlags & V_CLKDIV2) { - modep->Clock /= 2; - modep->SynthClock /= 2; - } - } - modep->type = bestMode->type; - modep->PrivFlags = ModePrivFlags; - modep->HDisplay = bestMode->HDisplay; - modep->HSyncStart = bestMode->HSyncStart; - modep->HSyncEnd = bestMode->HSyncEnd; - modep->HTotal = bestMode->HTotal; - modep->HSkew = bestMode->HSkew; - modep->VDisplay = bestMode->VDisplay; - modep->VSyncStart = bestMode->VSyncStart; - modep->VSyncEnd = bestMode->VSyncEnd; - modep->VTotal = bestMode->VTotal; - modep->VScan = bestMode->VScan; - modep->Flags = bestMode->Flags | extraFlags; - modep->CrtcHDisplay = bestMode->CrtcHDisplay; - modep->CrtcHBlankStart = bestMode->CrtcHBlankStart; - modep->CrtcHSyncStart = bestMode->CrtcHSyncStart; - modep->CrtcHSyncEnd = bestMode->CrtcHSyncEnd; - modep->CrtcHBlankEnd = bestMode->CrtcHBlankEnd; - modep->CrtcHTotal = bestMode->CrtcHTotal; - modep->CrtcHSkew = bestMode->CrtcHSkew; - modep->CrtcVDisplay = bestMode->CrtcVDisplay; - modep->CrtcVBlankStart = bestMode->CrtcVBlankStart; - modep->CrtcVSyncStart = bestMode->CrtcVSyncStart; - modep->CrtcVSyncEnd = bestMode->CrtcVSyncEnd; - modep->CrtcVBlankEnd = bestMode->CrtcVBlankEnd; - modep->CrtcVTotal = bestMode->CrtcVTotal; - modep->CrtcHAdjusted = bestMode->CrtcHAdjusted; - modep->CrtcVAdjusted = bestMode->CrtcVAdjusted; - modep->HSync = bestMode->HSync; - modep->VRefresh = bestMode->VRefresh; - modep->Private = bestMode->Private; - modep->PrivSize = bestMode->PrivSize; - - bestMode->prev = modep; - - return MODE_OK; -} - -/* - * xf86CheckModeForMonitor - * - * This function takes a mode and monitor description, and determines - * if the mode is valid for the monitor. - */ -ModeStatus -xf86CheckModeForMonitor(DisplayModePtr mode, MonPtr monitor) -{ - int i; - - /* Sanity checks */ - if (mode == NULL || monitor == NULL) { - ErrorF("xf86CheckModeForMonitor: called with invalid parameters\n"); - return MODE_ERROR; - } - - DebugF("xf86CheckModeForMonitor(%p %s, %p %s)\n", - mode, mode->name, monitor, monitor->id); - - /* Some basic mode validity checks */ - if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart || - mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal) - return MODE_H_ILLEGAL; - - if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart || - mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal) - return MODE_V_ILLEGAL; - - if (monitor->nHsync > 0) { - /* Check hsync against the allowed ranges */ - float hsync = xf86ModeHSync(mode); - - for (i = 0; i < monitor->nHsync; i++) - if ((hsync > monitor->hsync[i].lo * (1.0 - SYNC_TOLERANCE)) && - (hsync < monitor->hsync[i].hi * (1.0 + SYNC_TOLERANCE))) - break; - - /* Now see whether we ran out of sync ranges without finding a match */ - if (i == monitor->nHsync) - return MODE_HSYNC; - } - - if (monitor->nVrefresh > 0) { - /* Check vrefresh against the allowed ranges */ - float vrefrsh = xf86ModeVRefresh(mode); - - for (i = 0; i < monitor->nVrefresh; i++) - if ((vrefrsh > monitor->vrefresh[i].lo * (1.0 - SYNC_TOLERANCE)) && - (vrefrsh < monitor->vrefresh[i].hi * (1.0 + SYNC_TOLERANCE))) - break; - - /* Now see whether we ran out of refresh ranges without finding a match */ - if (i == monitor->nVrefresh) - return MODE_VSYNC; - } - - /* Force interlaced modes to have an odd VTotal */ - if (mode->Flags & V_INTERLACE) - mode->CrtcVTotal = mode->VTotal |= 1; - - /* - * This code stops cvt -r modes, and only cvt -r modes, from hitting 15y+ - * old CRTs which might, when there is a lot of solar flare activity and - * when the celestial bodies are unfavourably aligned, implode trying to - * sync to it. It's called "Protecting the user from doing anything stupid". - * -- libv - */ - - if (xf86ModeIsReduced(mode)) { - if (!monitor->reducedblanking && !(mode->type & M_T_DRIVER)) - return MODE_NO_REDUCED; - } - - if ((monitor->maxPixClock) && (mode->Clock > monitor->maxPixClock)) - return MODE_CLOCK_HIGH; - - return MODE_OK; -} - -/* - * xf86CheckModeSize - * - * An internal routine to check if a mode fits in video memory. This tries to - * avoid overflows that would otherwise occur when video memory size is greater - * than 256MB. - */ -static Bool -xf86CheckModeSize(ScrnInfoPtr scrp, int w, int x, int y) -{ - int bpp = scrp->fbFormat.bitsPerPixel, pad = scrp->fbFormat.scanlinePad; - int lineWidth, lastWidth; - - if (scrp->depth == 4) - pad *= 4; /* 4 planes */ - - /* Sanity check */ - if ((w < 0) || (x < 0) || (y <= 0)) - return FALSE; - - lineWidth = (((w * bpp) + pad - 1) / pad) * pad; - lastWidth = x * bpp; - - /* - * At this point, we need to compare - * - * (lineWidth * (y - 1)) + lastWidth - * - * against - * - * scrp->videoRam * (1024 * 8) - * - * These are bit quantities. To avoid overflows, do the comparison in - * terms of BITMAP_SCANLINE_PAD units. This assumes BITMAP_SCANLINE_PAD - * is a power of 2. We currently use 32, which limits us to a video - * memory size of 8GB. - */ - - lineWidth = (lineWidth + (BITMAP_SCANLINE_PAD - 1)) / BITMAP_SCANLINE_PAD; - lastWidth = (lastWidth + (BITMAP_SCANLINE_PAD - 1)) / BITMAP_SCANLINE_PAD; - - if ((lineWidth * (y - 1) + lastWidth) > - (scrp->videoRam * ((1024 * 8) / BITMAP_SCANLINE_PAD))) - return FALSE; - - return TRUE; -} - -/* - * xf86InitialCheckModeForDriver - * - * This function checks if a mode satisfies a driver's initial requirements: - * - mode size fits within the available pixel area (memory) - * - width lies within the range of supported line pitches - * - mode size fits within virtual size (if fixed) - * - horizontal timings are in range - * - * This function takes the following parameters: - * scrp ScrnInfoPtr - * mode mode to check - * maxPitch (optional) maximum line pitch - * virtualX (optional) virtual width requested - * virtualY (optional) virtual height requested - * - * In addition, the following fields from the ScrnInfoRec are used: - * monitor pointer to structure for monitor section - * fbFormat pixel format for the framebuffer - * videoRam video memory size (in kB) - */ - -static ModeStatus -xf86InitialCheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, - ClockRangePtr clockRanges, - LookupModeFlags strategy, - int maxPitch, int virtualX, int virtualY) -{ - ClockRangePtr cp; - ModeStatus status; - Bool allowDiv2 = (strategy & LOOKUP_CLKDIV2) != 0; - int i, needDiv2; - - /* Sanity checks */ - if (!scrp || !mode || !clockRanges) { - ErrorF("xf86InitialCheckModeForDriver: " - "called with invalid parameters\n"); - return MODE_ERROR; - } - - DebugF("xf86InitialCheckModeForDriver(%p, %p %s, %p, 0x%x, %d, %d, %d)\n", - scrp, mode, mode->name, clockRanges, strategy, maxPitch, virtualX, - virtualY); - - /* Some basic mode validity checks */ - if (0 >= mode->HDisplay || mode->HDisplay > mode->HSyncStart || - mode->HSyncStart >= mode->HSyncEnd || mode->HSyncEnd >= mode->HTotal) - return MODE_H_ILLEGAL; - - if (0 >= mode->VDisplay || mode->VDisplay > mode->VSyncStart || - mode->VSyncStart >= mode->VSyncEnd || mode->VSyncEnd >= mode->VTotal) - return MODE_V_ILLEGAL; - - if (!xf86CheckModeSize(scrp, mode->HDisplay, mode->HDisplay, - mode->VDisplay)) - return MODE_MEM; - - if (maxPitch > 0 && mode->HDisplay > maxPitch) - return MODE_BAD_WIDTH; - - if (virtualX > 0 && mode->HDisplay > virtualX) - return MODE_VIRTUAL_X; - - if (virtualY > 0 && mode->VDisplay > virtualY) - return MODE_VIRTUAL_Y; - - /* - * The use of the DisplayModeRec's Crtc* and SynthClock elements below is - * provisional, in that they are later reused by the driver at mode-set - * time. Here, they are temporarily enlisted to contain the mode timings - * as seen by the CRT or panel (rather than the CRTC). The driver's - * ValidMode() is allowed to modify these so it can deal with such things - * as mode stretching and/or centering. The driver should >NOT< modify the - * user-supplied values as these are reported back when mode validation is - * said and done. - */ - /* - * NOTE: We (ab)use the mode->Crtc* values here to store timing - * information for the calculation of Hsync and Vrefresh. Before - * these values are calculated the driver is given the opportunity - * to either set these HSync and VRefresh itself or modify the timing - * values. - * The difference to the final calculation is small but imortand: - * here we pass the flag INTERLACE_HALVE_V regardless if the driver - * sets it or not. This way our calculation of VRefresh has the same - * effect as if we do if (flags & V_INTERLACE) refresh *= 2.0 - * This dual use of the mode->Crtc* values will certainly create - * confusion and is bad software design. However since it's part of - * the driver API it's hard to change. - */ - - if (scrp->ValidMode) { - - xf86SetModeCrtc(mode, INTERLACE_HALVE_V); - - cp = xf86FindClockRangeForMode(clockRanges, mode); - if (!cp) - return MODE_CLOCK_RANGE; - - if (cp->ClockMulFactor < 1) - cp->ClockMulFactor = 1; - if (cp->ClockDivFactor < 1) - cp->ClockDivFactor = 1; - - /* - * XXX The effect of clock dividers and multipliers on the monitor's - * pixel clock needs to be verified. - */ - if (scrp->progClock) { - mode->SynthClock = mode->Clock; - } - else { - i = xf86GetNearestClock(scrp, mode->Clock, allowDiv2, - cp->ClockDivFactor, cp->ClockMulFactor, - &needDiv2); - mode->SynthClock = (scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor; - if (needDiv2 & V_CLKDIV2) - mode->SynthClock /= 2; - } - - status = (*scrp->ValidMode) (scrp, mode, FALSE, - MODECHECK_INITIAL); - if (status != MODE_OK) - return status; - - if (mode->HSync <= 0.0) - mode->HSync = (float) mode->SynthClock / (float) mode->CrtcHTotal; - if (mode->VRefresh <= 0.0) - mode->VRefresh = (mode->SynthClock * 1000.0) - / (mode->CrtcHTotal * mode->CrtcVTotal); - } - - mode->HSync = xf86ModeHSync(mode); - mode->VRefresh = xf86ModeVRefresh(mode); - - /* Assume it is OK */ - return MODE_OK; -} - -/* - * xf86CheckModeForDriver - * - * This function is for checking modes while the server is running (for - * use mainly by the VidMode extension). - * - * This function checks if a mode satisfies a driver's requirements: - * - width lies within the line pitch - * - mode size fits within virtual size - * - horizontal/vertical timings are in range - * - * This function takes the following parameters: - * scrp ScrnInfoPtr - * mode mode to check - * flags not (currently) used - * - * In addition, the following fields from the ScrnInfoRec are used: - * virtualX virtual width - * virtualY virtual height - * clockRanges allowable clock ranges - */ - -ModeStatus -xf86CheckModeForDriver(ScrnInfoPtr scrp, DisplayModePtr mode, int flags) -{ - ClockRangePtr cp; - int i, k, gap, minimumGap = CLOCK_TOLERANCE + 1; - int extraFlags = 0; - int clockIndex = -1; - int MulFactor = 1; - int DivFactor = 1; - int ModePrivFlags = 0; - ModeStatus status = MODE_NOMODE; - - /* Some sanity checking */ - if (scrp == NULL || (!scrp->progClock && scrp->numClocks == 0)) { - ErrorF("xf86CheckModeForDriver: called with invalid scrnInfoRec\n"); - return MODE_ERROR; - } - if (mode == NULL) { - ErrorF("xf86CheckModeForDriver: called with invalid modep\n"); - return MODE_ERROR; - } - - /* Check the mode size */ - if (mode->HDisplay > scrp->virtualX) - return MODE_VIRTUAL_X; - - if (mode->VDisplay > scrp->virtualY) - return MODE_VIRTUAL_Y; - - for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { - /* DivFactor and MulFactor must be > 0 */ - cp->ClockDivFactor = max(1, cp->ClockDivFactor); - cp->ClockMulFactor = max(1, cp->ClockMulFactor); - } - - if (scrp->progClock) { - /* Check clock is in range */ - for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { - if (modeInClockRange(cp, mode)) - break; - } - if (cp == NULL) { - return MODE_CLOCK_RANGE; - } - /* - * If programmable clock the required mode has been found - */ - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - } - else { - status = MODE_CLOCK_RANGE; - /* Check clock is in range */ - for (cp = scrp->clockRanges; cp != NULL; cp = cp->next) { - if (modeInClockRange(cp, mode)) { - /* - * Clock is in range, so if it is not a programmable clock, - * find a matching clock. - */ - - i = xf86GetNearestClock(scrp, mode->Clock, 0, - cp->ClockDivFactor, cp->ClockMulFactor, - &k); - /* - * If the clock is too far from the requested clock, this - * mode is no good. - */ - if (k & V_CLKDIV2) - gap = abs((mode->Clock * 2) - - ((scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor)); - else - gap = abs(mode->Clock - - ((scrp->clock[i] * cp->ClockDivFactor) / - cp->ClockMulFactor)); - if (gap > minimumGap) { - status = MODE_NOCLOCK; - continue; - } - - DivFactor = cp->ClockDivFactor; - MulFactor = cp->ClockMulFactor; - ModePrivFlags = cp->PrivFlags; - extraFlags = k; - clockIndex = i; - break; - } - } - if (cp == NULL) - return status; - } - - /* Fill in the mode parameters */ - if (scrp->progClock) { - mode->ClockIndex = -1; - mode->SynthClock = (mode->Clock * MulFactor) / DivFactor; - } - else { - mode->Clock = (scrp->clock[clockIndex] * DivFactor) / MulFactor; - mode->ClockIndex = clockIndex; - mode->SynthClock = scrp->clock[clockIndex]; - if (extraFlags & V_CLKDIV2) { - mode->Clock /= 2; - mode->SynthClock /= 2; - } - } - mode->PrivFlags = ModePrivFlags; - - return MODE_OK; -} - -static int -inferVirtualSize(ScrnInfoPtr scrp, DisplayModePtr modes, int *vx, int *vy) -{ - float aspect = 0.0; - MonPtr mon = scrp->monitor; - xf86MonPtr DDC; - int x = 0, y = 0; - DisplayModePtr mode; - - if (!mon) - return 0; - DDC = mon->DDC; - - if (DDC && DDC->ver.revision >= 4) { - /* For 1.4, we might actually get native pixel format. How novel. */ - if (PREFERRED_TIMING_MODE(DDC->features.msc)) { - for (mode = modes; mode; mode = mode->next) { - if (mode->type & (M_T_DRIVER | M_T_PREFERRED)) { - x = mode->HDisplay; - y = mode->VDisplay; - goto found; - } - } - } - /* - * Even if we don't, we might get aspect ratio from extra CVT info - * or from the monitor size fields. TODO. - */ - } - - /* - * Technically this triggers if either is zero. That wasn't legal - * before EDID 1.4, but right now we'll get that wrong. TODO. - */ - if (!aspect) { - if (!mon->widthmm || !mon->heightmm) - aspect = 4.0 / 3.0; - else - aspect = (float) mon->widthmm / (float) mon->heightmm; - } - - /* find the largest M_T_DRIVER mode with that aspect ratio */ - for (mode = modes; mode; mode = mode->next) { - float mode_aspect, metaspect; - - if (!(mode->type & (M_T_DRIVER | M_T_USERDEF))) - continue; - mode_aspect = (float) mode->HDisplay / (float) mode->VDisplay; - metaspect = aspect / mode_aspect; - /* 5% slop or so, since we only get size in centimeters */ - if (fabs(1.0 - metaspect) < 0.05) { - if ((mode->HDisplay > x) && (mode->VDisplay > y)) { - x = mode->HDisplay; - y = mode->VDisplay; - } - } - } - - if (!x || !y) { - xf86DrvMsg(scrp->scrnIndex, X_WARNING, - "Unable to estimate virtual size\n"); - return 0; - } - - found: - *vx = x; - *vy = y; - - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "Estimated virtual size for aspect ratio %.4f is %dx%d\n", - aspect, *vx, *vy); - - return 1; -} - -/* Least common multiple */ -static unsigned int -LCM(unsigned int x, unsigned int y) -{ - unsigned int m = x, n = y, o; - - while ((o = m % n)) { - m = n; - n = o; - } - - return (x / n) * y; -} - -/* - * Given various screen attributes, determine the minimum scanline width such - * that each scanline is server and DDX padded and any pixels with embedded - * bank boundaries are off-screen. This function returns -1 if such a width - * cannot exist. - */ -static int -scanLineWidth(unsigned int xsize, /* pixels */ - unsigned int ysize, /* pixels */ - unsigned int width, /* pixels */ - unsigned long BankSize, /* char's */ - PixmapFormatRec * pBankFormat, unsigned int nWidthUnit /* bits */ - ) -{ - unsigned long nBitsPerBank, nBitsPerScanline, nBitsPerScanlinePadUnit; - unsigned long minBitsPerScanline, maxBitsPerScanline; - - /* Sanity checks */ - - if (!nWidthUnit || !pBankFormat) - return -1; - - nBitsPerBank = BankSize * 8; - if (nBitsPerBank % pBankFormat->scanlinePad) - return -1; - - if (xsize > width) - width = xsize; - nBitsPerScanlinePadUnit = LCM(pBankFormat->scanlinePad, nWidthUnit); - nBitsPerScanline = - (((width * pBankFormat->bitsPerPixel) + nBitsPerScanlinePadUnit - 1) / - nBitsPerScanlinePadUnit) * nBitsPerScanlinePadUnit; - width = nBitsPerScanline / pBankFormat->bitsPerPixel; - - if (!xsize || !(nBitsPerBank % pBankFormat->bitsPerPixel)) - return (int) width; - - /* - * Scanlines will be server-pad aligned at this point. They will also be - * a multiple of nWidthUnit bits long. Ensure that pixels with embedded - * bank boundaries are off-screen. - * - * It seems reasonable to limit total frame buffer size to 1/16 of the - * theoretical maximum address space size. On a machine with 32-bit - * addresses (to 8-bit quantities) this turns out to be 256MB. Not only - * does this provide a simple limiting condition for the loops below, but - * it also prevents unsigned long wraparounds. - */ - if (!ysize) - return -1; - - minBitsPerScanline = xsize * pBankFormat->bitsPerPixel; - if (minBitsPerScanline > nBitsPerBank) - return -1; - - if (ysize == 1) - return (int) width; - - maxBitsPerScanline = - (((unsigned long) (-1) >> 1) - minBitsPerScanline) / (ysize - 1); - while (nBitsPerScanline <= maxBitsPerScanline) { - unsigned long BankBase, BankUnit; - - BankUnit = ((nBitsPerBank + nBitsPerScanline - 1) / nBitsPerBank) * - nBitsPerBank; - if (!(BankUnit % nBitsPerScanline)) - return (int) width; - - for (BankBase = BankUnit;; BankBase += nBitsPerBank) { - unsigned long x, y; - - y = BankBase / nBitsPerScanline; - if (y >= ysize) - return (int) width; - - x = BankBase % nBitsPerScanline; - if (!(x % pBankFormat->bitsPerPixel)) - continue; - - if (x < minBitsPerScanline) { - /* - * Skip ahead certain widths by dividing the excess scanline - * amongst the y's. - */ - y *= nBitsPerScanlinePadUnit; - nBitsPerScanline += ((x + y - 1) / y) * nBitsPerScanlinePadUnit; - width = nBitsPerScanline / pBankFormat->bitsPerPixel; - break; - } - - if (BankBase != BankUnit) - continue; - - if (!(nBitsPerScanline % x)) - return (int) width; - - BankBase = ((nBitsPerScanline - minBitsPerScanline) / - (nBitsPerScanline - x)) * BankUnit; - } - } - - return -1; -} - -/* - * xf86ValidateModes - * - * This function takes a set of mode names, modes and limiting conditions, - * and selects a set of modes and parameters based on those conditions. - * - * This function takes the following parameters: - * scrp ScrnInfoPtr - * availModes the list of modes available for the monitor - * modeNames (optional) list of mode names that the screen is requesting - * clockRanges a list of clock ranges - * linePitches (optional) a list of line pitches - * minPitch (optional) minimum line pitch (in pixels) - * maxPitch (optional) maximum line pitch (in pixels) - * pitchInc (mandatory) pitch increment (in bits) - * minHeight (optional) minimum virtual height (in pixels) - * maxHeight (optional) maximum virtual height (in pixels) - * virtualX (optional) virtual width requested (in pixels) - * virtualY (optional) virtual height requested (in pixels) - * apertureSize size of video aperture (in bytes) - * strategy how to decide which mode to use from multiple modes with - * the same name - * - * In addition, the following fields from the ScrnInfoRec are used: - * clocks a list of discrete clocks - * numClocks number of discrete clocks - * progClock clock is programmable - * monitor pointer to structure for monitor section - * fbFormat format of the framebuffer - * videoRam video memory size - * xInc horizontal timing increment (defaults to 8 pixels) - * - * The function fills in the following ScrnInfoRec fields: - * modePool A subset of the modes available to the monitor which - * are compatible with the driver. - * modes one mode entry for each of the requested modes, with the - * status field filled in to indicate if the mode has been - * accepted or not. - * virtualX the resulting virtual width - * virtualY the resulting virtual height - * displayWidth the resulting line pitch - * - * The function's return value is the number of matching modes found, or -1 - * if an unrecoverable error was encountered. - */ - -int -xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, - const char **modeNames, ClockRangePtr clockRanges, - int *linePitches, int minPitch, int maxPitch, int pitchInc, - int minHeight, int maxHeight, int virtualX, int virtualY, - int apertureSize, LookupModeFlags strategy) -{ - DisplayModePtr p, q, r, new, last, *endp; - int i, numModes = 0; - ModeStatus status; - int linePitch = -1, virtX = 0, virtY = 0; - int newLinePitch, newVirtX, newVirtY; - int modeSize; /* in pixels */ - Bool validateAllDefaultModes = FALSE; - Bool userModes = FALSE; - int saveType; - PixmapFormatRec *BankFormat; - ClockRangePtr cp; - int numTimings = 0; - range hsync[MAX_HSYNC]; - range vrefresh[MAX_VREFRESH]; - Bool inferred_virtual = FALSE; - - DebugF - ("xf86ValidateModes(%p, %p, %p, %p,\n\t\t %p, %d, %d, %d, %d, %d, %d, %d, %d, 0x%x)\n", - scrp, availModes, modeNames, clockRanges, linePitches, minPitch, - maxPitch, pitchInc, minHeight, maxHeight, virtualX, virtualY, - apertureSize, strategy); - - /* Some sanity checking */ - if (scrp == NULL || scrp->name == NULL || !scrp->monitor || - (!scrp->progClock && scrp->numClocks == 0)) { - ErrorF("xf86ValidateModes: called with invalid scrnInfoRec\n"); - return -1; - } - if (linePitches != NULL && linePitches[0] <= 0) { - ErrorF("xf86ValidateModes: called with invalid linePitches\n"); - return -1; - } - if (pitchInc <= 0) { - ErrorF("xf86ValidateModes: called with invalid pitchInc\n"); - return -1; - } - if ((virtualX > 0) != (virtualY > 0)) { - ErrorF("xf86ValidateModes: called with invalid virtual resolution\n"); - return -1; - } - - /* - * If requested by the driver, allow missing hsync and/or vrefresh ranges - * in the monitor section. - */ - if (strategy & LOOKUP_OPTIONAL_TOLERANCES) { - strategy &= ~LOOKUP_OPTIONAL_TOLERANCES; - } - else { - const char *type = ""; - Bool specified = FALSE; - - if (scrp->monitor->nHsync <= 0) { - if (numTimings > 0) { - scrp->monitor->nHsync = numTimings; - for (i = 0; i < numTimings; i++) { - scrp->monitor->hsync[i].lo = hsync[i].lo; - scrp->monitor->hsync[i].hi = hsync[i].hi; - } - } - else { - scrp->monitor->hsync[0].lo = 31.5; - scrp->monitor->hsync[0].hi = 48.0; - scrp->monitor->nHsync = 1; - } - type = "default "; - } - else { - specified = TRUE; - } - for (i = 0; i < scrp->monitor->nHsync; i++) { - if (scrp->monitor->hsync[i].lo == scrp->monitor->hsync[i].hi) - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %shsync value of %.2f kHz\n", - scrp->monitor->id, type, scrp->monitor->hsync[i].lo); - else - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %shsync range of %.2f-%.2f kHz\n", - scrp->monitor->id, type, - scrp->monitor->hsync[i].lo, - scrp->monitor->hsync[i].hi); - } - - type = ""; - if (scrp->monitor->nVrefresh <= 0) { - if (numTimings > 0) { - scrp->monitor->nVrefresh = numTimings; - for (i = 0; i < numTimings; i++) { - scrp->monitor->vrefresh[i].lo = vrefresh[i].lo; - scrp->monitor->vrefresh[i].hi = vrefresh[i].hi; - } - } - else { - scrp->monitor->vrefresh[0].lo = 50; - scrp->monitor->vrefresh[0].hi = 70; - scrp->monitor->nVrefresh = 1; - } - type = "default "; - } - else { - specified = TRUE; - } - for (i = 0; i < scrp->monitor->nVrefresh; i++) { - if (scrp->monitor->vrefresh[i].lo == scrp->monitor->vrefresh[i].hi) - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %svrefresh value of %.2f Hz\n", - scrp->monitor->id, type, - scrp->monitor->vrefresh[i].lo); - else - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %svrefresh range of %.2f-%.2f Hz\n", - scrp->monitor->id, type, - scrp->monitor->vrefresh[i].lo, - scrp->monitor->vrefresh[i].hi); - } - - type = ""; - if (!scrp->monitor->maxPixClock && !specified) { - type = "default "; - scrp->monitor->maxPixClock = 65000.0; - } - if (scrp->monitor->maxPixClock) { - xf86DrvMsg(scrp->scrnIndex, X_INFO, - "%s: Using %smaximum pixel clock of %.2f MHz\n", - scrp->monitor->id, type, - (float) scrp->monitor->maxPixClock / 1000.0); - } - } - - /* - * Store the clockRanges for later use by the VidMode extension. - */ - nt_list_for_each_entry(cp, clockRanges, next) { - ClockRangePtr newCR = xnfalloc(sizeof(ClockRange)); - memcpy(newCR, cp, sizeof(ClockRange)); - newCR->next = NULL; - if (scrp->clockRanges == NULL) - scrp->clockRanges = newCR; - else - nt_list_append(newCR, scrp->clockRanges, ClockRange, next); - } - - /* Determine which pixmap format to pass to scanLineWidth() */ - if (scrp->depth > 4) - BankFormat = &scrp->fbFormat; - else - BankFormat = xf86GetPixFormat(scrp, 1); /* >not< scrp->depth! */ - - if (scrp->xInc <= 0) - scrp->xInc = 8; /* Suitable for VGA and others */ - -#define _VIRTUALX(x) ((((x) + scrp->xInc - 1) / scrp->xInc) * scrp->xInc) - - /* - * Determine maxPitch if it wasn't given explicitly. Note linePitches - * always takes precedence if is non-NULL. In that case the minPitch and - * maxPitch values passed are ignored. - */ - if (linePitches) { - minPitch = maxPitch = linePitches[0]; - for (i = 1; linePitches[i] > 0; i++) { - if (linePitches[i] > maxPitch) - maxPitch = linePitches[i]; - if (linePitches[i] < minPitch) - minPitch = linePitches[i]; - } - } - - /* - * Initialise virtX and virtY if the values are fixed. - */ - if (virtualY > 0) { - if (maxHeight > 0 && virtualY > maxHeight) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual height (%d) is too large for the hardware " - "(max %d)\n", virtualY, maxHeight); - return -1; - } - - if (minHeight > 0 && virtualY < minHeight) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual height (%d) is too small for the hardware " - "(min %d)\n", virtualY, minHeight); - return -1; - } - - virtualX = _VIRTUALX(virtualX); - if (linePitches != NULL) { - for (i = 0; linePitches[i] != 0; i++) { - if ((linePitches[i] >= virtualX) && - (linePitches[i] == - scanLineWidth(virtualX, virtualY, linePitches[i], - apertureSize, BankFormat, pitchInc))) { - linePitch = linePitches[i]; - break; - } - } - } - else { - linePitch = scanLineWidth(virtualX, virtualY, minPitch, - apertureSize, BankFormat, pitchInc); - } - - if ((linePitch < minPitch) || (linePitch > maxPitch)) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual width (%d) is too large for the hardware " - "(max %d)\n", virtualX, maxPitch); - return -1; - } - - if (!xf86CheckModeSize(scrp, linePitch, virtualX, virtualY)) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual size (%dx%d) (pitch %d) exceeds video memory\n", - virtualX, virtualY, linePitch); - return -1; - } - - virtX = virtualX; - virtY = virtualY; - } - else if (!modeNames || !*modeNames) { - /* No virtual size given in the config, try to infer */ - /* XXX this doesn't take m{in,ax}Pitch into account; oh well */ - inferred_virtual = inferVirtualSize(scrp, availModes, &virtX, &virtY); - if (inferred_virtual) - linePitch = scanLineWidth(virtX, virtY, minPitch, apertureSize, - BankFormat, pitchInc); - } - - /* Print clock ranges and scaled clocks */ - xf86ShowClockRanges(scrp, clockRanges); - - /* - * If scrp->modePool hasn't been setup yet, set it up now. This allows the - * modes that the driver definitely can't use to be weeded out early. Note - * that a modePool mode's prev field is used to hold a pointer to the - * member of the scrp->modes list for which a match was considered. - */ - if (scrp->modePool == NULL) { - q = NULL; - for (p = availModes; p != NULL; p = p->next) { - status = xf86InitialCheckModeForDriver(scrp, p, clockRanges, - strategy, maxPitch, - virtX, virtY); - - if (status == MODE_OK) { - status = xf86CheckModeForMonitor(p, scrp->monitor); - } - - if (status == MODE_OK) { - new = xnfalloc(sizeof(DisplayModeRec)); - *new = *p; - new->next = NULL; - if (!q) { - scrp->modePool = new; - } - else { - q->next = new; - } - new->prev = NULL; - q = new; - q->name = xnfstrdup(p->name); - q->status = MODE_OK; - } - else { - printModeRejectMessage(scrp->scrnIndex, p, status); - } - } - - if (scrp->modePool == NULL) { - xf86DrvMsg(scrp->scrnIndex, X_WARNING, "Mode pool is empty\n"); - return 0; - } - } - else { - for (p = scrp->modePool; p != NULL; p = p->next) { - p->prev = NULL; - p->status = MODE_OK; - } - } - - /* - * Allocate one entry in scrp->modes for each named mode. - */ - while (scrp->modes) - xf86DeleteMode(&scrp->modes, scrp->modes); - endp = &scrp->modes; - last = NULL; - if (modeNames != NULL) { - for (i = 0; modeNames[i] != NULL; i++) { - userModes = TRUE; - new = xnfcalloc(1, sizeof(DisplayModeRec)); - new->prev = last; - new->type = M_T_USERDEF; - new->name = xnfstrdup(modeNames[i]); - if (new->prev) - new->prev->next = new; - *endp = last = new; - endp = &new->next; - } - } - - /* Lookup each mode */ -#ifdef PANORAMIX - if (noPanoramiXExtension) - validateAllDefaultModes = TRUE; -#endif - - for (p = scrp->modes;; p = p->next) { - Bool repeat; - - /* - * If the supplied mode names don't produce a valid mode, scan through - * unconsidered modePool members until one survives validation. This - * is done in decreasing order by mode pixel area. - */ - - if (p == NULL) { - if ((numModes > 0) && !validateAllDefaultModes) - break; - - validateAllDefaultModes = TRUE; - r = NULL; - modeSize = 0; - for (q = scrp->modePool; q != NULL; q = q->next) { - if ((q->prev == NULL) && (q->status == MODE_OK)) { - /* - * Deal with the case where this mode wasn't considered - * because of a builtin mode of the same name. - */ - for (p = scrp->modes; p != NULL; p = p->next) { - if ((p->status != MODE_OK) && !strcmp(p->name, q->name)) - break; - } - - if (p != NULL) - q->prev = p; - else { - /* - * A quick check to not allow default modes with - * horizontal timing parameters that CRTs may have - * problems with. - */ - if (!scrp->monitor->reducedblanking && - (q->type & M_T_DEFAULT) && - ((double) q->HTotal / (double) q->HDisplay) < 1.15) - continue; - - if (modeSize < (q->HDisplay * q->VDisplay)) { - r = q; - modeSize = q->HDisplay * q->VDisplay; - } - } - } - } - - if (r == NULL) - break; - - p = xnfcalloc(1, sizeof(DisplayModeRec)); - p->prev = last; - p->name = xnfstrdup(r->name); - if (!userModes) - p->type = M_T_USERDEF; - if (p->prev) - p->prev->next = p; - *endp = last = p; - endp = &p->next; - } - - repeat = FALSE; - lookupNext: - if (repeat && ((status = p->status) != MODE_OK)) - printModeRejectMessage(scrp->scrnIndex, p, status); - saveType = p->type; - status = xf86LookupMode(scrp, p, clockRanges, strategy); - if (repeat && status == MODE_NOMODE) - continue; - if (status != MODE_OK) - printModeRejectMessage(scrp->scrnIndex, p, status); - if (status == MODE_ERROR) { - ErrorF("xf86ValidateModes: " - "unexpected result from xf86LookupMode()\n"); - return -1; - } - if (status != MODE_OK) { - if (p->status == MODE_OK) - p->status = status; - continue; - } - p->type |= saveType; - repeat = TRUE; - - newLinePitch = linePitch; - newVirtX = virtX; - newVirtY = virtY; - - /* - * Don't let non-user defined modes increase the virtual size - */ - if (!(p->type & M_T_USERDEF) && (numModes > 0)) { - if (p->HDisplay > virtX) { - p->status = MODE_VIRTUAL_X; - goto lookupNext; - } - if (p->VDisplay > virtY) { - p->status = MODE_VIRTUAL_Y; - goto lookupNext; - } - } - /* - * Adjust virtual width and height if the mode is too large for the - * current values and if they are not fixed. - */ - if (virtualX <= 0 && p->HDisplay > newVirtX) - newVirtX = _VIRTUALX(p->HDisplay); - if (virtualY <= 0 && p->VDisplay > newVirtY) { - if (maxHeight > 0 && p->VDisplay > maxHeight) { - p->status = MODE_VIRTUAL_Y; /* ? */ - goto lookupNext; - } - newVirtY = p->VDisplay; - } - - /* - * If virtual resolution is to be increased, revalidate it. - */ - if ((virtX != newVirtX) || (virtY != newVirtY)) { - if (linePitches != NULL) { - newLinePitch = -1; - for (i = 0; linePitches[i] != 0; i++) { - if ((linePitches[i] >= newVirtX) && - (linePitches[i] >= linePitch) && - (linePitches[i] == - scanLineWidth(newVirtX, newVirtY, linePitches[i], - apertureSize, BankFormat, pitchInc))) { - newLinePitch = linePitches[i]; - break; - } - } - } - else { - if (linePitch < minPitch) - linePitch = minPitch; - newLinePitch = scanLineWidth(newVirtX, newVirtY, linePitch, - apertureSize, BankFormat, - pitchInc); - } - if ((newLinePitch < minPitch) || (newLinePitch > maxPitch)) { - p->status = MODE_BAD_WIDTH; - goto lookupNext; - } - - /* - * Check that the pixel area required by the new virtual height - * and line pitch isn't too large. - */ - if (!xf86CheckModeSize(scrp, newLinePitch, newVirtX, newVirtY)) { - p->status = MODE_MEM_VIRT; - goto lookupNext; - } - } - - if (scrp->ValidMode) { - /* - * Give the driver a final say, passing it the proposed virtual - * geometry. - */ - scrp->virtualX = newVirtX; - scrp->virtualY = newVirtY; - scrp->displayWidth = newLinePitch; - p->status = (scrp->ValidMode) (scrp, p, FALSE, - MODECHECK_FINAL); - - if (p->status != MODE_OK) { - goto lookupNext; - } - } - - /* Mode has passed all the tests */ - virtX = newVirtX; - virtY = newVirtY; - linePitch = newLinePitch; - p->status = MODE_OK; - numModes++; - } - - /* - * If we estimated the virtual size above, we may have filtered away all - * the modes that maximally match that size; scan again to find out and - * fix up if so. - */ - if (inferred_virtual) { - int vx = 0, vy = 0; - - for (p = scrp->modes; p; p = p->next) { - if (p->HDisplay > vx && p->VDisplay > vy) { - vx = p->HDisplay; - vy = p->VDisplay; - } - } - if (vx < virtX || vy < virtY) { - const int types[] = { - M_T_BUILTIN | M_T_PREFERRED, - M_T_BUILTIN, - M_T_DRIVER | M_T_PREFERRED, - M_T_DRIVER, - 0 - }; - const int ntypes = ARRAY_SIZE(types); - int n; - - /* - * We did not find the estimated virtual size. So now we want to - * find the largest mode available, but we want to search in the - * modes in the order of "types" listed above. - */ - for (n = 0; n < ntypes; n++) { - int type = types[n]; - - vx = 0; - vy = 0; - for (p = scrp->modes; p; p = p->next) { - /* scan through the modes in the sort order above */ - if ((p->type & type) != type) - continue; - if (p->HDisplay > vx && p->VDisplay > vy) { - vx = p->HDisplay; - vy = p->VDisplay; - } - } - if (vx && vy) - /* Found one */ - break; - } - xf86DrvMsg(scrp->scrnIndex, X_WARNING, - "Shrinking virtual size estimate from %dx%d to %dx%d\n", - virtX, virtY, vx, vy); - virtX = _VIRTUALX(vx); - virtY = vy; - for (p = scrp->modes; p; p = p->next) { - if (numModes > 0) { - if (p->HDisplay > virtX) - p->status = MODE_VIRTUAL_X; - if (p->VDisplay > virtY) - p->status = MODE_VIRTUAL_Y; - if (p->status != MODE_OK) { - numModes--; - printModeRejectMessage(scrp->scrnIndex, p, p->status); - } - } - } - if (linePitches != NULL) { - for (i = 0; linePitches[i] != 0; i++) { - if ((linePitches[i] >= virtX) && - (linePitches[i] == - scanLineWidth(virtX, virtY, linePitches[i], - apertureSize, BankFormat, pitchInc))) { - linePitch = linePitches[i]; - break; - } - } - } - else { - linePitch = scanLineWidth(virtX, virtY, minPitch, - apertureSize, BankFormat, pitchInc); - } - } - } - - /* Update the ScrnInfoRec parameters */ - - scrp->virtualX = virtX; - scrp->virtualY = virtY; - scrp->displayWidth = linePitch; - - if (numModes <= 0) - return 0; - - /* Make the mode list into a circular list by joining up the ends */ - p = scrp->modes; - while (p->next != NULL) - p = p->next; - /* p is now the last mode on the list */ - p->next = scrp->modes; - scrp->modes->prev = p; - - if (minHeight > 0 && virtY < minHeight) { - xf86DrvMsg(scrp->scrnIndex, X_ERROR, - "Virtual height (%d) is too small for the hardware " - "(min %d)\n", virtY, minHeight); - return -1; - } - - return numModes; -} - -/* - * xf86DeleteMode - * - * This function removes a mode from a list of modes. - * - * There are different types of mode lists: - * - * - singly linked linear lists, ending in NULL - * - doubly linked linear lists, starting and ending in NULL - * - doubly linked circular lists - * - */ - -void -xf86DeleteMode(DisplayModePtr * modeList, DisplayModePtr mode) -{ - /* Catch the easy/insane cases */ - if (modeList == NULL || *modeList == NULL || mode == NULL) - return; - - /* If the mode is at the start of the list, move the start of the list */ - if (*modeList == mode) - *modeList = mode->next; - - /* If mode is the only one on the list, set the list to NULL */ - if ((mode == mode->prev) && (mode == mode->next)) { - *modeList = NULL; - } - else { - if ((mode->prev != NULL) && (mode->prev->next == mode)) - mode->prev->next = mode->next; - if ((mode->next != NULL) && (mode->next->prev == mode)) - mode->next->prev = mode->prev; - } - - free((void *) mode->name); - free(mode); -} - -/* - * xf86PruneDriverModes - * - * Remove modes from the driver's mode list which have been marked as - * invalid. - */ - -void -xf86PruneDriverModes(ScrnInfoPtr scrp) -{ - DisplayModePtr first, p, n; - - p = scrp->modes; - if (p == NULL) - return; - - do { - if (!(first = scrp->modes)) - return; - n = p->next; - if (p->status != MODE_OK) { - xf86DeleteMode(&(scrp->modes), p); - } - p = n; - } while (p != NULL && p != first); - - /* modePool is no longer needed, turf it */ - while (scrp->modePool) { - /* - * A modePool mode's prev field is used to hold a pointer to the - * member of the scrp->modes list for which a match was considered. - * Clear that pointer first, otherwise xf86DeleteMode might get - * confused - */ - scrp->modePool->prev = NULL; - xf86DeleteMode(&scrp->modePool, scrp->modePool); - } -} - -/* - * xf86SetCrtcForModes - * - * Goes through the screen's mode list, and initialises the Crtc - * parameters for each mode. The initialisation includes adjustments - * for interlaced and double scan modes. - */ -void -xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags) -{ - DisplayModePtr p; - - /* - * Store adjustFlags for use with the VidMode extension. There is an - * implicit assumption here that SetCrtcForModes is called once. - */ - scrp->adjustFlags = adjustFlags; - - p = scrp->modes; - if (p == NULL) - return; - - do { - xf86SetModeCrtc(p, adjustFlags); - DebugF("%sMode %s: %d (%d) %d %d (%d) %d %d (%d) %d %d (%d) %d\n", - (p->type & M_T_DEFAULT) ? "Default " : "", - p->name, p->CrtcHDisplay, p->CrtcHBlankStart, - p->CrtcHSyncStart, p->CrtcHSyncEnd, p->CrtcHBlankEnd, - p->CrtcHTotal, p->CrtcVDisplay, p->CrtcVBlankStart, - p->CrtcVSyncStart, p->CrtcVSyncEnd, p->CrtcVBlankEnd, - p->CrtcVTotal); - p = p->next; - } while (p != NULL && p != scrp->modes); -} - -void -xf86PrintModes(ScrnInfoPtr scrp) -{ - DisplayModePtr p; - float hsync, refresh = 0; - const char *desc, *desc2, *prefix, *uprefix; - - if (scrp == NULL) - return; - - xf86DrvMsg(scrp->scrnIndex, X_INFO, "Virtual size is %dx%d (pitch %d)\n", - scrp->virtualX, scrp->virtualY, scrp->displayWidth); - - p = scrp->modes; - if (p == NULL) - return; - - do { - desc = desc2 = ""; - hsync = xf86ModeHSync(p); - refresh = xf86ModeVRefresh(p); - if (p->Flags & V_INTERLACE) { - desc = " (I)"; - } - if (p->Flags & V_DBLSCAN) { - desc = " (D)"; - } - if (p->VScan > 1) { - desc2 = " (VScan)"; - } - if (p->type & M_T_BUILTIN) - prefix = "Built-in mode"; - else if (p->type & M_T_DEFAULT) - prefix = "Default mode"; - else if (p->type & M_T_DRIVER) - prefix = "Driver mode"; - else - prefix = "Mode"; - if (p->type & M_T_USERDEF) - uprefix = "*"; - else - uprefix = " "; - if (hsync == 0 || refresh == 0) { - if (p->name) - xf86DrvMsg(scrp->scrnIndex, X_CONFIG, - "%s%s \"%s\"\n", uprefix, prefix, p->name); - else - xf86DrvMsg(scrp->scrnIndex, X_PROBED, - "%s%s %dx%d (unnamed)\n", - uprefix, prefix, p->HDisplay, p->VDisplay); - } - else if (p->Clock == p->SynthClock) { - xf86DrvMsg(scrp->scrnIndex, X_CONFIG, - "%s%s \"%s\": %.1f MHz, %.1f kHz, %.1f Hz%s%s\n", - uprefix, prefix, p->name, p->Clock / 1000.0, - hsync, refresh, desc, desc2); - } - else { - xf86DrvMsg(scrp->scrnIndex, X_CONFIG, - "%s%s \"%s\": %.1f MHz (scaled from %.1f MHz), " - "%.1f kHz, %.1f Hz%s%s\n", - uprefix, prefix, p->name, p->Clock / 1000.0, - p->SynthClock / 1000.0, hsync, refresh, desc, desc2); - } - if (hsync != 0 && refresh != 0) - xf86PrintModeline(scrp->scrnIndex, p); - p = p->next; - } while (p != NULL && p != scrp->modes); -} diff --git a/hw/xfree86/common/xf86Module.h b/hw/xfree86/common/xf86Module.h deleted file mode 100644 index 33cf0e56a..000000000 --- a/hw/xfree86/common/xf86Module.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains the parts of the loader interface that are visible - * to modules. This is the only loader-related header that modules should - * include. - * - * It should include a bare minimum of other headers. - * - * Longer term, the module/loader code should probably live directly under - * Xserver/. - * - * XXX This file arguably belongs in xfree86/loader/. - */ - -#ifndef _XF86MODULE_H -#define _XF86MODULE_H - -#include -#include -#include - -#ifndef NULL -#define NULL ((void *)0) -#endif - -#define DEFAULT_LIST ((char *)-1) - -/* Built-in ABI classes. These definitions must not be changed. */ -#define ABI_CLASS_NONE NULL -#define ABI_CLASS_ANSIC "X.Org ANSI C Emulation" -#define ABI_CLASS_VIDEODRV "X.Org Video Driver" -#define ABI_CLASS_XINPUT "X.Org XInput driver" -#define ABI_CLASS_EXTENSION "X.Org Server Extension" - -#define ABI_MINOR_MASK 0x0000FFFF -#define ABI_MAJOR_MASK 0xFFFF0000 -#define GET_ABI_MINOR(v) ((v) & ABI_MINOR_MASK) -#define GET_ABI_MAJOR(v) (((v) & ABI_MAJOR_MASK) >> 16) -#define SET_ABI_VERSION(maj, min) \ - ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK)) - -/* - * ABI versions. Each version has a major and minor revision. Modules - * using lower minor revisions must work with servers of a higher minor - * revision. There is no compatibility between different major revisions. - * Whenever the ABI_ANSIC_VERSION is changed, the others must also be - * changed. The minor revision mask is 0x0000FFFF and the major revision - * mask is 0xFFFF0000. - */ -#define ABI_ANSIC_VERSION SET_ABI_VERSION(0, 4) -#define ABI_VIDEODRV_VERSION SET_ABI_VERSION(25, 3) -#define ABI_XINPUT_VERSION SET_ABI_VERSION(24, 4) -#define ABI_EXTENSION_VERSION SET_ABI_VERSION(10, 0) - -#define MODINFOSTRING1 0xef23fdc5 -#define MODINFOSTRING2 0x10dc023a - -#ifndef MODULEVENDORSTRING -#define MODULEVENDORSTRING "X.Org Foundation" -#endif - -/* Error return codes for errmaj */ -typedef enum { - LDR_NOERROR = 0, - LDR_NOMEM, /* memory allocation failed */ - LDR_NOENT, /* Module file does not exist */ - LDR_NOLOAD, /* type specific loader failed */ - LDR_ONCEONLY, /* Module should only be loaded once (not an error) */ - LDR_MISMATCH, /* the module didn't match the spec'd requirements */ - LDR_BADUSAGE, /* LoadModule is called with bad arguments */ - LDR_INVALID, /* The module doesn't have a valid ModuleData object */ - LDR_BADOS, /* The module doesn't support the OS */ - LDR_MODSPECIFIC /* A module-specific error in the SetupProc */ -} LoaderErrorCode; - -/* - * Some common module classes. The moduleclass can be used to identify - * that modules loaded are of the correct type. This is a finer - * classification than the ABI classes even though the default set of - * classes have the same names. For example, not all modules that require - * the video driver ABI are themselves video drivers. - */ -#define MOD_CLASS_NONE NULL -#define MOD_CLASS_VIDEODRV "X.Org Video Driver" -#define MOD_CLASS_XINPUT "X.Org XInput Driver" -#define MOD_CLASS_EXTENSION "X.Org Server Extension" - -/* This structure is expected to be returned by the initfunc */ -typedef struct { - const char *modname; /* name of module, e.g. "foo" */ - const char *vendor; /* vendor specific string */ - CARD32 _modinfo1_; /* constant MODINFOSTRING1/2 to find */ - CARD32 _modinfo2_; /* infoarea with a binary editor or sign tool */ - CARD32 xf86version; /* contains XF86_VERSION_CURRENT */ - CARD8 majorversion; /* module-specific major version */ - CARD8 minorversion; /* module-specific minor version */ - CARD16 patchlevel; /* module-specific patch level */ - const char *abiclass; /* ABI class that the module uses */ - CARD32 abiversion; /* ABI version */ - const char *moduleclass; /* module class description */ - CARD32 checksum[4]; /* contains a digital signature of the */ - /* version info structure */ -} XF86ModuleVersionInfo; - -/* - * This structure can be used to callers of LoadModule and LoadSubModule to - * specify version and/or ABI requirements. - */ -typedef struct { - CARD8 majorversion; /* module-specific major version */ - CARD8 minorversion; /* moudle-specific minor version */ - CARD16 patchlevel; /* module-specific patch level */ - const char *abiclass; /* ABI class that the module uses */ - CARD32 abiversion; /* ABI version */ - const char *moduleclass; /* module class */ -} XF86ModReqInfo; - -#define MODULE_VERSION_NUMERIC(maj, min, patch) \ - ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF)) -#define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF) -#define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF) -#define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF) - -#define INITARGS void - -/* Prototypes for Loader functions that are exported to modules */ -extern _X_EXPORT void *LoadSubModule(void *, const char *, const char **, - const char **, void *, - const XF86ModReqInfo *, int *, int *); -extern _X_EXPORT void UnloadSubModule(void *); -extern _X_EXPORT void UnloadModule(void *); -extern _X_EXPORT void *LoaderSymbol(const char *); -extern _X_EXPORT void *LoaderSymbolFromModule(void *, const char *); -extern _X_EXPORT void LoaderErrorMsg(const char *, const char *, int, int); -extern _X_EXPORT Bool LoaderShouldIgnoreABI(void); -extern _X_EXPORT int LoaderGetABIVersion(const char *abiclass); - -typedef void *(*ModuleSetupProc) (void *, void *, int *, int *); -typedef void (*ModuleTearDownProc) (void *); - -#define MODULESETUPPROTO(func) void *func(void *, void *, int*, int*) -#define MODULETEARDOWNPROTO(func) void func(void *) - -typedef struct { - XF86ModuleVersionInfo *vers; - ModuleSetupProc setup; - ModuleTearDownProc teardown; -} XF86ModuleData; - -#endif /* _XF86STR_H */ diff --git a/hw/xfree86/common/xf86Opt.h b/hw/xfree86/common/xf86Opt.h deleted file mode 100644 index 3046fbd41..000000000 --- a/hw/xfree86/common/xf86Opt.h +++ /dev/null @@ -1,158 +0,0 @@ - -/* - * Copyright (c) 1998-2003 by The XFree86 Project, 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). - */ - -/* Option handling things that ModuleSetup procs can use */ - -#ifndef _XF86_OPT_H_ -#define _XF86_OPT_H_ -#include "xf86Optionstr.h" - -typedef struct { - double freq; - int units; -} OptFrequency; - -typedef union { - unsigned long num; - const char *str; - double realnum; - Bool boolean; - OptFrequency freq; -} ValueUnion; - -typedef enum { - OPTV_NONE = 0, - OPTV_INTEGER, - OPTV_STRING, /* a non-empty string */ - OPTV_ANYSTR, /* Any string, including an empty one */ - OPTV_REAL, - OPTV_BOOLEAN, - OPTV_PERCENT, - OPTV_FREQ -} OptionValueType; - -typedef enum { - OPTUNITS_HZ = 1, - OPTUNITS_KHZ, - OPTUNITS_MHZ -} OptFreqUnits; - -typedef struct { - int token; - const char *name; - OptionValueType type; - ValueUnion value; - Bool found; -} OptionInfoRec, *OptionInfoPtr; - -extern _X_EXPORT int xf86SetIntOption(XF86OptionPtr optlist, const char *name, - int deflt); -extern _X_EXPORT double xf86SetRealOption(XF86OptionPtr optlist, - const char *name, double deflt); -extern _X_EXPORT char *xf86SetStrOption(XF86OptionPtr optlist, const char *name, - const char *deflt); -extern _X_EXPORT int xf86SetBoolOption(XF86OptionPtr list, const char *name, - int deflt); -extern _X_EXPORT double xf86SetPercentOption(XF86OptionPtr list, - const char *name, double deflt); -extern _X_EXPORT int xf86CheckIntOption(XF86OptionPtr optlist, const char *name, - int deflt); -extern _X_EXPORT double xf86CheckRealOption(XF86OptionPtr optlist, - const char *name, double deflt); -extern _X_EXPORT char *xf86CheckStrOption(XF86OptionPtr optlist, - const char *name, const char *deflt); -extern _X_EXPORT int xf86CheckBoolOption(XF86OptionPtr list, const char *name, - int deflt); -extern _X_EXPORT double xf86CheckPercentOption(XF86OptionPtr list, - const char *name, double deflt); -extern _X_EXPORT XF86OptionPtr xf86AddNewOption(XF86OptionPtr head, - const char *name, - const char *val); -extern _X_EXPORT XF86OptionPtr xf86NewOption(char *name, char *value); -extern _X_EXPORT XF86OptionPtr xf86NextOption(XF86OptionPtr list); -extern _X_EXPORT XF86OptionPtr xf86OptionListCreate(const char **options, - int count, int used); -extern _X_EXPORT XF86OptionPtr xf86OptionListMerge(XF86OptionPtr head, - XF86OptionPtr tail); -extern _X_EXPORT XF86OptionPtr xf86OptionListDuplicate(XF86OptionPtr list); -extern _X_EXPORT void xf86OptionListFree(XF86OptionPtr opt); -extern _X_EXPORT char *xf86OptionName(XF86OptionPtr opt); -extern _X_EXPORT char *xf86OptionValue(XF86OptionPtr opt); -extern _X_EXPORT void xf86OptionListReport(XF86OptionPtr parm); -extern _X_EXPORT XF86OptionPtr xf86FindOption(XF86OptionPtr options, - const char *name); -extern _X_EXPORT const char *xf86FindOptionValue(XF86OptionPtr options, - const char *name); -extern _X_EXPORT void xf86MarkOptionUsed(XF86OptionPtr option); -extern _X_EXPORT void xf86MarkOptionUsedByName(XF86OptionPtr options, - const char *name); -extern _X_EXPORT Bool xf86CheckIfOptionUsed(XF86OptionPtr option); -extern _X_EXPORT Bool xf86CheckIfOptionUsedByName(XF86OptionPtr options, - const char *name); -extern _X_EXPORT void xf86ShowUnusedOptions(int scrnIndex, - XF86OptionPtr options); -extern _X_EXPORT void xf86ProcessOptions(int scrnIndex, XF86OptionPtr options, - OptionInfoPtr optinfo); -extern _X_EXPORT OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec * table, - int token); -extern _X_EXPORT const char *xf86TokenToOptName(const OptionInfoRec * table, - int token); -extern _X_EXPORT Bool xf86IsOptionSet(const OptionInfoRec * table, int token); -extern _X_EXPORT const char *xf86GetOptValString(const OptionInfoRec * table, - int token); -extern _X_EXPORT Bool xf86GetOptValInteger(const OptionInfoRec * table, - int token, int *value); -extern _X_EXPORT Bool xf86GetOptValULong(const OptionInfoRec * table, int token, - unsigned long *value); -extern _X_EXPORT Bool xf86GetOptValReal(const OptionInfoRec * table, int token, - double *value); -extern _X_EXPORT Bool xf86GetOptValFreq(const OptionInfoRec * table, int token, - OptFreqUnits expectedUnits, - double *value); -extern _X_EXPORT Bool xf86GetOptValBool(const OptionInfoRec * table, int token, - Bool *value); -extern _X_EXPORT Bool xf86ReturnOptValBool(const OptionInfoRec * table, - int token, Bool def); -extern _X_EXPORT int xf86NameCmp(const char *s1, const char *s2); -extern _X_EXPORT char *xf86NormalizeName(const char *s); -extern _X_EXPORT XF86OptionPtr xf86ReplaceIntOption(XF86OptionPtr optlist, - const char *name, - const int val); -extern _X_EXPORT XF86OptionPtr xf86ReplaceRealOption(XF86OptionPtr optlist, - const char *name, - const double val); -extern _X_EXPORT XF86OptionPtr xf86ReplaceBoolOption(XF86OptionPtr optlist, - const char *name, - const Bool val); -extern _X_EXPORT XF86OptionPtr xf86ReplacePercentOption(XF86OptionPtr optlist, - const char *name, - const double val); -extern _X_EXPORT XF86OptionPtr xf86ReplaceStrOption(XF86OptionPtr optlist, - const char *name, - const char *val); -#endif diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c deleted file mode 100644 index ca538cc57..000000000 --- a/hw/xfree86/common/xf86Option.c +++ /dev/null @@ -1,923 +0,0 @@ -/* - * Copyright (c) 1998-2003 by The XFree86 Project, 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). - */ - -/* - * Author: David Dawes - * - * This file includes public option handling functions. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include "os.h" -#include "xf86.h" -#include "xf86Opt.h" -#include "xf86Xinput.h" -#include "xf86Optrec.h" -#include "xf86Parser.h" -#include "xf86platformBus.h" /* For OutputClass functions */ -#include "optionstr.h" - -static Bool ParseOptionValue(int scrnIndex, XF86OptionPtr options, - OptionInfoPtr p, Bool markUsed); - -/* - * xf86CollectOptions collects the options from each of the config file - * sections used by the screen and puts the combined list in pScrn->options. - * This function requires that the following have been initialised: - * - * pScrn->confScreen - * pScrn->Entities[i]->device - * pScrn->display - * pScrn->monitor - * - * The extraOpts parameter may optionally contain a list of additional options - * to include. - * - * The order of precedence for options is: - * - * extraOpts, display, confScreen, monitor, device, outputClassOptions - */ - -void -xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts) -{ - XF86OptionPtr tmp; - XF86OptionPtr extras = (XF86OptionPtr) extraOpts; - GDevPtr device; - - int i; - - pScrn->options = NULL; - - for (i = pScrn->numEntities - 1; i >= 0; i--) { - xf86MergeOutputClassOptions(pScrn->entityList[i], &pScrn->options); - - device = xf86GetDevFromEntity(pScrn->entityList[i], - pScrn->entityInstanceList[i]); - if (device && device->options) { - tmp = xf86optionListDup(device->options); - if (pScrn->options) - pScrn->options = xf86optionListMerge(pScrn->options, tmp); - else - pScrn->options = tmp; - } - } - if (pScrn->monitor->options) { - tmp = xf86optionListDup(pScrn->monitor->options); - if (pScrn->options) - pScrn->options = xf86optionListMerge(pScrn->options, tmp); - else - pScrn->options = tmp; - } - if (pScrn->confScreen->options) { - tmp = xf86optionListDup(pScrn->confScreen->options); - if (pScrn->options) - pScrn->options = xf86optionListMerge(pScrn->options, tmp); - else - pScrn->options = tmp; - } - if (pScrn->display->options) { - tmp = xf86optionListDup(pScrn->display->options); - if (pScrn->options) - pScrn->options = xf86optionListMerge(pScrn->options, tmp); - else - pScrn->options = tmp; - } - if (extras) { - tmp = xf86optionListDup(extras); - if (pScrn->options) - pScrn->options = xf86optionListMerge(pScrn->options, tmp); - else - pScrn->options = tmp; - } -} - -/* - * xf86CollectInputOptions collects extra options for an InputDevice (other - * than those added by the config backend). - * The options are merged into the existing ones and thus take precedence - * over the others. - */ - -void -xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts) -{ - if (defaultOpts) { - XF86OptionPtr tmp = xf86optionListCreate(defaultOpts, -1, 0); - - if (pInfo->options) - pInfo->options = xf86optionListMerge(tmp, pInfo->options); - else - pInfo->options = tmp; - } -} - -/** - * Duplicate the option list passed in. The returned pointer will be a newly - * allocated option list and must be freed by the caller. - */ -XF86OptionPtr -xf86OptionListDuplicate(XF86OptionPtr options) -{ - XF86OptionPtr o = NULL; - - while (options) { - o = xf86AddNewOption(o, xf86OptionName(options), - xf86OptionValue(options)); - options = xf86nextOption(options); - } - - return o; -} - -/* Created for new XInput stuff -- essentially extensions to the parser */ - -static int -LookupIntOption(XF86OptionPtr optlist, const char *name, int deflt, - Bool markUsed) -{ - OptionInfoRec o; - - o.name = name; - o.type = OPTV_INTEGER; - if (ParseOptionValue(-1, optlist, &o, markUsed)) - deflt = o.value.num; - return deflt; -} - -static double -LookupRealOption(XF86OptionPtr optlist, const char *name, double deflt, - Bool markUsed) -{ - OptionInfoRec o; - - o.name = name; - o.type = OPTV_REAL; - if (ParseOptionValue(-1, optlist, &o, markUsed)) - deflt = o.value.realnum; - return deflt; -} - -static char * -LookupStrOption(XF86OptionPtr optlist, const char *name, const char *deflt, - Bool markUsed) -{ - OptionInfoRec o; - - o.name = name; - o.type = OPTV_STRING; - if (ParseOptionValue(-1, optlist, &o, markUsed)) - deflt = o.value.str; - if (deflt) - return strdup(deflt); - else - return NULL; -} - -static int -LookupBoolOption(XF86OptionPtr optlist, const char *name, int deflt, - Bool markUsed) -{ - OptionInfoRec o; - - o.name = name; - o.type = OPTV_BOOLEAN; - if (ParseOptionValue(-1, optlist, &o, markUsed)) - deflt = o.value.boolean; - return deflt; -} - -static double -LookupPercentOption(XF86OptionPtr optlist, const char *name, double deflt, - Bool markUsed) -{ - OptionInfoRec o; - - o.name = name; - o.type = OPTV_PERCENT; - if (ParseOptionValue(-1, optlist, &o, markUsed)) - deflt = o.value.realnum; - return deflt; -} - -/* These xf86Set* functions are intended for use by non-screen specific code */ - -int -xf86SetIntOption(XF86OptionPtr optlist, const char *name, int deflt) -{ - return LookupIntOption(optlist, name, deflt, TRUE); -} - -double -xf86SetRealOption(XF86OptionPtr optlist, const char *name, double deflt) -{ - return LookupRealOption(optlist, name, deflt, TRUE); -} - -char * -xf86SetStrOption(XF86OptionPtr optlist, const char *name, const char *deflt) -{ - return LookupStrOption(optlist, name, deflt, TRUE); -} - -int -xf86SetBoolOption(XF86OptionPtr optlist, const char *name, int deflt) -{ - return LookupBoolOption(optlist, name, deflt, TRUE); -} - -double -xf86SetPercentOption(XF86OptionPtr optlist, const char *name, double deflt) -{ - return LookupPercentOption(optlist, name, deflt, TRUE); -} - -/* - * These are like the Set*Option functions, but they don't mark the options - * as used. - */ -int -xf86CheckIntOption(XF86OptionPtr optlist, const char *name, int deflt) -{ - return LookupIntOption(optlist, name, deflt, FALSE); -} - -double -xf86CheckRealOption(XF86OptionPtr optlist, const char *name, double deflt) -{ - return LookupRealOption(optlist, name, deflt, FALSE); -} - -char * -xf86CheckStrOption(XF86OptionPtr optlist, const char *name, const char *deflt) -{ - return LookupStrOption(optlist, name, deflt, FALSE); -} - -int -xf86CheckBoolOption(XF86OptionPtr optlist, const char *name, int deflt) -{ - return LookupBoolOption(optlist, name, deflt, FALSE); -} - -double -xf86CheckPercentOption(XF86OptionPtr optlist, const char *name, double deflt) -{ - return LookupPercentOption(optlist, name, deflt, FALSE); -} - -/* - * xf86AddNewOption() has the required property of replacing the option value - * if the option is already present. - */ -XF86OptionPtr -xf86ReplaceIntOption(XF86OptionPtr optlist, const char *name, const int val) -{ - char tmp[16]; - - snprintf(tmp, sizeof(tmp), "%i", val); - return xf86AddNewOption(optlist, name, tmp); -} - -XF86OptionPtr -xf86ReplaceRealOption(XF86OptionPtr optlist, const char *name, const double val) -{ - char tmp[32]; - - snprintf(tmp, sizeof(tmp), "%f", val); - return xf86AddNewOption(optlist, name, tmp); -} - -XF86OptionPtr -xf86ReplaceBoolOption(XF86OptionPtr optlist, const char *name, const Bool val) -{ - return xf86AddNewOption(optlist, name, val ? "True" : "False"); -} - -XF86OptionPtr -xf86ReplacePercentOption(XF86OptionPtr optlist, const char *name, - const double val) -{ - char tmp[16]; - - snprintf(tmp, sizeof(tmp), "%lf%%", val); - return xf86AddNewOption(optlist, name, tmp); -} - -XF86OptionPtr -xf86ReplaceStrOption(XF86OptionPtr optlist, const char *name, const char *val) -{ - return xf86AddNewOption(optlist, name, val); -} - -XF86OptionPtr -xf86AddNewOption(XF86OptionPtr head, const char *name, const char *val) -{ - /* XXX These should actually be allocated in the parser library. */ - char *tmp = val ? strdup(val) : NULL; - char *tmp_name = strdup(name); - - return xf86addNewOption(head, tmp_name, tmp); -} - -XF86OptionPtr -xf86NewOption(char *name, char *value) -{ - return xf86newOption(name, value); -} - -XF86OptionPtr -xf86NextOption(XF86OptionPtr list) -{ - return xf86nextOption(list); -} - -XF86OptionPtr -xf86OptionListCreate(const char **options, int count, int used) -{ - return xf86optionListCreate(options, count, used); -} - -XF86OptionPtr -xf86OptionListMerge(XF86OptionPtr head, XF86OptionPtr tail) -{ - return xf86optionListMerge(head, tail); -} - -void -xf86OptionListFree(XF86OptionPtr opt) -{ - xf86optionListFree(opt); -} - -char * -xf86OptionName(XF86OptionPtr opt) -{ - return xf86optionName(opt); -} - -char * -xf86OptionValue(XF86OptionPtr opt) -{ - return xf86optionValue(opt); -} - -void -xf86OptionListReport(XF86OptionPtr parm) -{ - XF86OptionPtr opts = parm; - - while (opts) { - if (xf86optionValue(opts)) - xf86ErrorFVerb(5, "\tOption \"%s\" \"%s\"\n", - xf86optionName(opts), xf86optionValue(opts)); - else - xf86ErrorFVerb(5, "\tOption \"%s\"\n", xf86optionName(opts)); - opts = xf86nextOption(opts); - } -} - -/* End of XInput-caused section */ - -XF86OptionPtr -xf86FindOption(XF86OptionPtr options, const char *name) -{ - return xf86findOption(options, name); -} - -const char * -xf86FindOptionValue(XF86OptionPtr options, const char *name) -{ - return xf86findOptionValue(options, name); -} - -void -xf86MarkOptionUsed(XF86OptionPtr option) -{ - if (option != NULL) - option->opt_used = TRUE; -} - -void -xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name) -{ - XF86OptionPtr opt; - - opt = xf86findOption(options, name); - if (opt != NULL) - opt->opt_used = TRUE; -} - -Bool -xf86CheckIfOptionUsed(XF86OptionPtr option) -{ - if (option != NULL) - return option->opt_used; - else - return FALSE; -} - -Bool -xf86CheckIfOptionUsedByName(XF86OptionPtr options, const char *name) -{ - XF86OptionPtr opt; - - opt = xf86findOption(options, name); - if (opt != NULL) - return opt->opt_used; - else - return FALSE; -} - -void -xf86ShowUnusedOptions(int scrnIndex, XF86OptionPtr opt) -{ - while (opt) { - if (opt->opt_name && !opt->opt_used) { - xf86DrvMsg(scrnIndex, X_WARNING, "Option \"%s\" is not used\n", - opt->opt_name); - } - opt = opt->list.next; - } -} - -static Bool -GetBoolValue(OptionInfoPtr p, const char *s) -{ - return xf86getBoolValue(&p->value.boolean, s); -} - -static Bool -ParseOptionValue(int scrnIndex, XF86OptionPtr options, OptionInfoPtr p, - Bool markUsed) -{ - const char *s; - char *end; - Bool wasUsed = FALSE; - - if ((s = xf86findOptionValue(options, p->name)) != NULL) { - if (markUsed) { - wasUsed = xf86CheckIfOptionUsedByName(options, p->name); - xf86MarkOptionUsedByName(options, p->name); - } - switch (p->type) { - case OPTV_INTEGER: - if (*s == '\0') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires an integer value\n", - p->name); - } - p->found = FALSE; - } - else { - p->value.num = strtoul(s, &end, 0); - if (*end == '\0') { - p->found = TRUE; - } - else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires an integer value\n", - p->name); - } - p->found = FALSE; - } - } - break; - case OPTV_STRING: - if (*s == '\0') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a string value\n", - p->name); - } - p->found = FALSE; - } - else { - p->value.str = s; - p->found = TRUE; - } - break; - case OPTV_ANYSTR: - p->value.str = s; - p->found = TRUE; - break; - case OPTV_REAL: - if (*s == '\0') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a floating point " - "value\n", p->name); - } - p->found = FALSE; - } - else { - p->value.realnum = strtod(s, &end); - if (*end == '\0') { - p->found = TRUE; - } - else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a floating point " - "value\n", p->name); - } - p->found = FALSE; - } - } - break; - case OPTV_BOOLEAN: - if (GetBoolValue(p, s)) { - p->found = TRUE; - } - else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a boolean value\n", - p->name); - } - p->found = FALSE; - } - break; - case OPTV_PERCENT: - { - char tmp = 0; - - /* awkward match, but %% doesn't increase the match counter, - * hence 100 looks the same as 100% to the caller of sccanf - */ - if (sscanf(s, "%lf%c", &p->value.realnum, &tmp) != 2 || tmp != '%') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a percent value\n", - p->name); - } - p->found = FALSE; - } - else { - p->found = TRUE; - } - } - break; - case OPTV_FREQ: - if (*s == '\0') { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a frequency value\n", - p->name); - } - p->found = FALSE; - } - else { - double freq = strtod(s, &end); - int units = 0; - - if (end != s) { - p->found = TRUE; - if (!xf86NameCmp(end, "Hz")) - units = 1; - else if (!xf86NameCmp(end, "kHz") || !xf86NameCmp(end, "k")) - units = 1000; - else if (!xf86NameCmp(end, "MHz") || !xf86NameCmp(end, "M")) - units = 1000000; - else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a frequency value\n", - p->name); - } - p->found = FALSE; - } - if (p->found) - freq *= (double) units; - } - else { - if (markUsed) { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a frequency value\n", - p->name); - } - p->found = FALSE; - } - if (p->found) { - p->value.freq.freq = freq; - p->value.freq.units = units; - } - } - break; - case OPTV_NONE: - /* Should never get here */ - p->found = FALSE; - break; - } - if (p->found && markUsed) { - int verb = 2; - - if (wasUsed) - verb = 4; - xf86DrvMsgVerb(scrnIndex, X_CONFIG, verb, "Option \"%s\"", p->name); - if (!(p->type == OPTV_BOOLEAN && *s == 0)) { - xf86ErrorFVerb(verb, " \"%s\"", s); - } - xf86ErrorFVerb(verb, "\n"); - } - } - else if (p->type == OPTV_BOOLEAN) { - /* Look for matches with options with or without a "No" prefix. */ - char *n, *newn; - OptionInfoRec opt; - - n = xf86NormalizeName(p->name); - if (!n) { - p->found = FALSE; - return FALSE; - } - if (strncmp(n, "no", 2) == 0) { - newn = n + 2; - } - else { - free(n); - if (asprintf(&n, "No%s", p->name) == -1) { - p->found = FALSE; - return FALSE; - } - newn = n; - } - if ((s = xf86findOptionValue(options, newn)) != NULL) { - if (markUsed) - xf86MarkOptionUsedByName(options, newn); - if (GetBoolValue(&opt, s)) { - p->value.boolean = !opt.value.boolean; - p->found = TRUE; - } - else { - xf86DrvMsg(scrnIndex, X_WARNING, - "Option \"%s\" requires a boolean value\n", newn); - p->found = FALSE; - } - } - else { - p->found = FALSE; - } - if (p->found && markUsed) { - xf86DrvMsgVerb(scrnIndex, X_CONFIG, 2, "Option \"%s\"", newn); - if (*s != 0) { - xf86ErrorFVerb(2, " \"%s\"", s); - } - xf86ErrorFVerb(2, "\n"); - } - free(n); - } - else { - p->found = FALSE; - } - return p->found; -} - -void -xf86ProcessOptions(int scrnIndex, XF86OptionPtr options, OptionInfoPtr optinfo) -{ - OptionInfoPtr p; - - for (p = optinfo; p->name != NULL; p++) { - ParseOptionValue(scrnIndex, options, p, TRUE); - } -} - -OptionInfoPtr -xf86TokenToOptinfo(const OptionInfoRec * table, int token) -{ - const OptionInfoRec *p, *match = NULL, *set = NULL; - - if (!table) { - ErrorF("xf86TokenToOptinfo: table is NULL\n"); - return NULL; - } - - for (p = table; p->token >= 0; p++) { - if (p->token == token) { - match = p; - if (p->found) - set = p; - } - } - - if (set) - return (OptionInfoPtr) set; - else if (match) - return (OptionInfoPtr) match; - else - return NULL; -} - -const char * -xf86TokenToOptName(const OptionInfoRec * table, int token) -{ - const OptionInfoRec *p; - - p = xf86TokenToOptinfo(table, token); - return p ? p->name : NULL; -} - -Bool -xf86IsOptionSet(const OptionInfoRec * table, int token) -{ - OptionInfoPtr p; - - p = xf86TokenToOptinfo(table, token); - return p && p->found; -} - -const char * -xf86GetOptValString(const OptionInfoRec * table, int token) -{ - OptionInfoPtr p; - - p = xf86TokenToOptinfo(table, token); - if (p && p->found) - return p->value.str; - else - return NULL; -} - -Bool -xf86GetOptValInteger(const OptionInfoRec * table, int token, int *value) -{ - OptionInfoPtr p; - - p = xf86TokenToOptinfo(table, token); - if (p && p->found) { - *value = p->value.num; - return TRUE; - } - else - return FALSE; -} - -Bool -xf86GetOptValULong(const OptionInfoRec * table, int token, unsigned long *value) -{ - OptionInfoPtr p; - - p = xf86TokenToOptinfo(table, token); - if (p && p->found) { - *value = p->value.num; - return TRUE; - } - else - return FALSE; -} - -Bool -xf86GetOptValReal(const OptionInfoRec * table, int token, double *value) -{ - OptionInfoPtr p; - - p = xf86TokenToOptinfo(table, token); - if (p && p->found) { - *value = p->value.realnum; - return TRUE; - } - else - return FALSE; -} - -Bool -xf86GetOptValFreq(const OptionInfoRec * table, int token, - OptFreqUnits expectedUnits, double *value) -{ - OptionInfoPtr p; - - p = xf86TokenToOptinfo(table, token); - if (p && p->found) { - if (p->value.freq.units > 0) { - /* Units give, so the scaling is known. */ - switch (expectedUnits) { - case OPTUNITS_HZ: - *value = p->value.freq.freq; - break; - case OPTUNITS_KHZ: - *value = p->value.freq.freq / 1000.0; - break; - case OPTUNITS_MHZ: - *value = p->value.freq.freq / 1000000.0; - break; - } - } - else { - /* No units given, so try to guess the scaling. */ - switch (expectedUnits) { - case OPTUNITS_HZ: - *value = p->value.freq.freq; - break; - case OPTUNITS_KHZ: - if (p->value.freq.freq > 1000.0) - *value = p->value.freq.freq / 1000.0; - else - *value = p->value.freq.freq; - break; - case OPTUNITS_MHZ: - if (p->value.freq.freq > 1000000.0) - *value = p->value.freq.freq / 1000000.0; - else if (p->value.freq.freq > 1000.0) - *value = p->value.freq.freq / 1000.0; - else - *value = p->value.freq.freq; - } - } - return TRUE; - } - else - return FALSE; -} - -Bool -xf86GetOptValBool(const OptionInfoRec * table, int token, Bool *value) -{ - OptionInfoPtr p; - - p = xf86TokenToOptinfo(table, token); - if (p && p->found) { - *value = p->value.boolean; - return TRUE; - } - else - return FALSE; -} - -Bool -xf86ReturnOptValBool(const OptionInfoRec * table, int token, Bool def) -{ - OptionInfoPtr p; - - p = xf86TokenToOptinfo(table, token); - if (p && p->found) { - return p->value.boolean; - } - else - return def; -} - -int -xf86NameCmp(const char *s1, const char *s2) -{ - return xf86nameCompare(s1, s2); -} - -char * -xf86NormalizeName(const char *s) -{ - char *ret, *q; - const char *p; - - if (s == NULL) - return NULL; - - ret = malloc(strlen(s) + 1); - for (p = s, q = ret; *p != 0; p++) { - switch (*p) { - case '_': - case ' ': - case '\t': - continue; - default: - if (isupper(*p)) - *q++ = tolower(*p); - else - *q++ = *p; - } - } - *q = '\0'; - return ret; -} diff --git a/hw/xfree86/common/xf86Optionstr.h b/hw/xfree86/common/xf86Optionstr.h deleted file mode 100644 index 4ef917dee..000000000 --- a/hw/xfree86/common/xf86Optionstr.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright © 2011 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef XF86OPTIONSTR_H -#define XF86OPTIONSTR_H -#include "list.h" - -/* - * All options are stored using this data type. - */ -typedef struct _XF86OptionRec { - GenericListRec list; - const char *opt_name; - const char *opt_val; - int opt_used; - const char *opt_comment; -} XF86OptionRec; - -typedef struct _InputOption *XF86OptionPtr; - -#endif diff --git a/hw/xfree86/common/xf86PM.c b/hw/xfree86/common/xf86PM.c deleted file mode 100644 index ed7bdbd9f..000000000 --- a/hw/xfree86/common/xf86PM.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright (c) 2000-2002 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86Xinput.h" -#include "xf86_OSproc.h" - -int (*xf86PMGetEventFromOs) (int fd, pmEvent * events, int num) = NULL; -pmWait (*xf86PMConfirmEventToOs) (int fd, pmEvent event) = NULL; - -static Bool suspended = FALSE; - -static int -eventName(pmEvent event, const char **str) -{ - switch (event) { - case XF86_APM_SYS_STANDBY: - *str = "System Standby Request"; - return 0; - case XF86_APM_SYS_SUSPEND: - *str = "System Suspend Request"; - return 0; - case XF86_APM_CRITICAL_SUSPEND: - *str = "Critical Suspend"; - return 0; - case XF86_APM_USER_STANDBY: - *str = "User System Standby Request"; - return 0; - case XF86_APM_USER_SUSPEND: - *str = "User System Suspend Request"; - return 0; - case XF86_APM_STANDBY_RESUME: - *str = "System Standby Resume"; - return 0; - case XF86_APM_NORMAL_RESUME: - *str = "Normal Resume System"; - return 0; - case XF86_APM_CRITICAL_RESUME: - *str = "Critical Resume System"; - return 0; - case XF86_APM_LOW_BATTERY: - *str = "Battery Low"; - return 3; - case XF86_APM_POWER_STATUS_CHANGE: - *str = "Power Status Change"; - return 3; - case XF86_APM_UPDATE_TIME: - *str = "Update Time"; - return 3; - case XF86_APM_CAPABILITY_CHANGED: - *str = "Capability Changed"; - return 3; - case XF86_APM_STANDBY_FAILED: - *str = "Standby Request Failed"; - return 0; - case XF86_APM_SUSPEND_FAILED: - *str = "Suspend Request Failed"; - return 0; - default: - *str = "Unknown Event"; - return 0; - } -} - -static void -suspend(pmEvent event, Bool undo) -{ - int i; - InputInfoPtr pInfo; - - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], FALSE); - } - pInfo = xf86InputDevs; - while (pInfo) { - DisableDevice(pInfo->dev, TRUE); - pInfo = pInfo->next; - } - input_lock(); - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->PMEvent) - xf86Screens[i]->PMEvent(xf86Screens[i], event, undo); - else { - xf86Screens[i]->LeaveVT(xf86Screens[i]); - xf86Screens[i]->vtSema = FALSE; - } - } -} - -static void -resume(pmEvent event, Bool undo) -{ - int i; - InputInfoPtr pInfo; - - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->PMEvent) - xf86Screens[i]->PMEvent(xf86Screens[i], event, undo); - else { - xf86Screens[i]->vtSema = TRUE; - xf86Screens[i]->EnterVT(xf86Screens[i]); - } - } - input_unlock(); - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->EnableDisableFBAccess) - (*xf86Screens[i]->EnableDisableFBAccess) (xf86Screens[i], TRUE); - } - dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); - pInfo = xf86InputDevs; - while (pInfo) { - EnableDevice(pInfo->dev, TRUE); - pInfo = pInfo->next; - } -} - -static void -DoApmEvent(pmEvent event, Bool undo) -{ - int i; - - switch (event) { -#if 0 - case XF86_APM_SYS_STANDBY: - case XF86_APM_USER_STANDBY: -#endif - case XF86_APM_SYS_SUSPEND: - case XF86_APM_CRITICAL_SUSPEND: /*do we want to delay a critical suspend? */ - case XF86_APM_USER_SUSPEND: - /* should we do this ? */ - if (!undo && !suspended) { - suspend(event, undo); - suspended = TRUE; - } - else if (undo && suspended) { - resume(event, undo); - suspended = FALSE; - } - break; -#if 0 - case XF86_APM_STANDBY_RESUME: -#endif - case XF86_APM_NORMAL_RESUME: - case XF86_APM_CRITICAL_RESUME: - if (suspended) { - resume(event, undo); - suspended = FALSE; - } - break; - default: - input_lock(); - for (i = 0; i < xf86NumScreens; i++) { - if (xf86Screens[i]->PMEvent) { - xf86Screens[i]->PMEvent(xf86Screens[i], event, undo); - } - } - input_unlock(); - break; - } -} - -#define MAX_NO_EVENTS 8 - -void -xf86HandlePMEvents(int fd, void *data) -{ - pmEvent events[MAX_NO_EVENTS]; - int i, n; - Bool wait = FALSE; - - if (!xf86PMGetEventFromOs) - return; - - if ((n = xf86PMGetEventFromOs(fd, events, MAX_NO_EVENTS))) { - do { - for (i = 0; i < n; i++) { - const char *str = NULL; - int verb = eventName(events[i], &str); - - xf86MsgVerb(X_INFO, verb, "PM Event received: %s\n", str); - DoApmEvent(events[i], FALSE); - switch (xf86PMConfirmEventToOs(fd, events[i])) { - case PM_WAIT: - wait = TRUE; - break; - case PM_CONTINUE: - wait = FALSE; - break; - case PM_FAILED: - DoApmEvent(events[i], TRUE); - wait = FALSE; - break; - default: - break; - } - } - if (wait) - n = xf86PMGetEventFromOs(fd, events, MAX_NO_EVENTS); - else - break; - } while (1); - } -} diff --git a/hw/xfree86/common/xf86PciInfo.h b/hw/xfree86/common/xf86PciInfo.h deleted file mode 100644 index 0f5430868..000000000 --- a/hw/xfree86/common/xf86PciInfo.h +++ /dev/null @@ -1,732 +0,0 @@ - -/* - * Copyright (c) 1995-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains macros for the PCI Vendor and Device IDs for video - * cards plus a few other things that are needed in drivers or elsewhere. - * This information is used in several ways: - * 1. It is used by drivers and/or other code. - * 2. It is used by the pciid2c.pl script to determine what vendor data to - * include in the pcidata module that the X server loads. - * 3. A side-effect of 2. affects how config-generation works for - * otherwise "unknown" cards. - * - * Don't add entries here for vendors that don't make video cards, - * or for non-video devices unless they're needed by a driver or elsewhere. - * A comprehensive set of PCI vendor, device and subsystem data is - * auto-generated from the ../etc/pci.ids file using the pciids2c.pl script, - * and is used in scanpci utility. Don't modify the pci.ids file. If - * new/corrected entries are required, add them to ../etc/extrapci.ids. - */ - -#ifndef _XF86_PCIINFO_H -#define _XF86_PCIINFO_H - -#warning "xf86PciInfo.h is deprecated. For greater compatibility, drivers should include necessary PCI IDs locally rather than relying on this file from xorg-server." - -/* PCI Pseudo Vendor */ -#define PCI_VENDOR_GENERIC 0x00FF - -#define PCI_VENDOR_REAL3D 0x003D -#define PCI_VENDOR_COMPAQ 0x0E11 -#define PCI_VENDOR_ATI 0x1002 -#define PCI_VENDOR_AVANCE 0x1005 -#define PCI_VENDOR_TSENG 0x100C -#define PCI_VENDOR_NS 0x100B -#define PCI_VENDOR_WEITEK 0x100E -#define PCI_VENDOR_VIDEOLOGIC 0x1010 -#define PCI_VENDOR_DIGITAL 0x1011 -#define PCI_VENDOR_CIRRUS 0x1013 -#define PCI_VENDOR_AMD 0x1022 -#define PCI_VENDOR_TRIDENT 0x1023 -#define PCI_VENDOR_ALI 0x1025 -#define PCI_VENDOR_DELL 0x1028 -#define PCI_VENDOR_MATROX 0x102B -#define PCI_VENDOR_CHIPSTECH 0x102C -#define PCI_VENDOR_MIRO 0x1031 -#define PCI_VENDOR_NEC 0x1033 -#define PCI_VENDOR_SIS 0x1039 -#define PCI_VENDOR_HP 0x103C -#define PCI_VENDOR_SGS 0x104A -#define PCI_VENDOR_TI 0x104C -#define PCI_VENDOR_SONY 0x104D -#define PCI_VENDOR_OAK 0x104E -#define PCI_VENDOR_MOTOROLA 0x1057 -#define PCI_VENDOR_NUMNINE 0x105D -#define PCI_VENDOR_CYRIX 0x1078 -#define PCI_VENDOR_SUN 0x108E -#define PCI_VENDOR_DIAMOND 0x1092 -#define PCI_VENDOR_BROOKTREE 0x109E -#define PCI_VENDOR_NEOMAGIC 0x10C8 -#define PCI_VENDOR_NVIDIA 0x10DE -#define PCI_VENDOR_IMS 0x10E0 -#define PCI_VENDOR_INTEGRAPHICS 0x10EA -#define PCI_VENDOR_ALLIANCE 0x1142 -#define PCI_VENDOR_RENDITION 0x1163 -#define PCI_VENDOR_3DFX 0x121A -#define PCI_VENDOR_SMI 0x126F -#define PCI_VENDOR_TRITECH 0x1292 -#define PCI_VENDOR_NVIDIA_SGS 0x12D2 -#define PCI_VENDOR_VMWARE 0x15AD -#define PCI_VENDOR_AST 0x1A03 -#define PCI_VENDOR_3DLABS 0x3D3D -#define PCI_VENDOR_AVANCE_2 0x4005 -#define PCI_VENDOR_HERCULES 0x4843 -#define PCI_VENDOR_S3 0x5333 -#define PCI_VENDOR_INTEL 0x8086 -#define PCI_VENDOR_ARK 0xEDD8 - -/* Generic */ -#define PCI_CHIP_VGA 0x0000 -#define PCI_CHIP_8514 0x0001 - -/* Real 3D */ -#define PCI_CHIP_I740_PCI 0x00D1 - -/* Compaq */ -#define PCI_CHIP_QV1280 0x3033 - -/* ATI */ -#define PCI_CHIP_RV380_3150 0x3150 -#define PCI_CHIP_RV380_3151 0x3151 -#define PCI_CHIP_RV380_3152 0x3152 -#define PCI_CHIP_RV380_3153 0x3153 -#define PCI_CHIP_RV380_3154 0x3154 -#define PCI_CHIP_RV380_3156 0x3156 -#define PCI_CHIP_RV380_3E50 0x3E50 -#define PCI_CHIP_RV380_3E51 0x3E51 -#define PCI_CHIP_RV380_3E52 0x3E52 -#define PCI_CHIP_RV380_3E53 0x3E53 -#define PCI_CHIP_RV380_3E54 0x3E54 -#define PCI_CHIP_RV380_3E56 0x3E56 -#define PCI_CHIP_RS100_4136 0x4136 -#define PCI_CHIP_RS200_4137 0x4137 -#define PCI_CHIP_R300_AD 0x4144 -#define PCI_CHIP_R300_AE 0x4145 -#define PCI_CHIP_R300_AF 0x4146 -#define PCI_CHIP_R300_AG 0x4147 -#define PCI_CHIP_R350_AH 0x4148 -#define PCI_CHIP_R350_AI 0x4149 -#define PCI_CHIP_R350_AJ 0x414A -#define PCI_CHIP_R350_AK 0x414B -#define PCI_CHIP_RV350_AP 0x4150 -#define PCI_CHIP_RV350_AQ 0x4151 -#define PCI_CHIP_RV360_AR 0x4152 -#define PCI_CHIP_RV350_AS 0x4153 -#define PCI_CHIP_RV350_AT 0x4154 -#define PCI_CHIP_RV350_4155 0x4155 -#define PCI_CHIP_RV350_AV 0x4156 -#define PCI_CHIP_MACH32 0x4158 -#define PCI_CHIP_RS250_4237 0x4237 -#define PCI_CHIP_R200_BB 0x4242 -#define PCI_CHIP_R200_BC 0x4243 -#define PCI_CHIP_RS100_4336 0x4336 -#define PCI_CHIP_RS200_4337 0x4337 -#define PCI_CHIP_MACH64CT 0x4354 -#define PCI_CHIP_MACH64CX 0x4358 -#define PCI_CHIP_RS250_4437 0x4437 -#define PCI_CHIP_MACH64ET 0x4554 -#define PCI_CHIP_MACH64GB 0x4742 -#define PCI_CHIP_MACH64GD 0x4744 -#define PCI_CHIP_MACH64GI 0x4749 -#define PCI_CHIP_MACH64GL 0x474C -#define PCI_CHIP_MACH64GM 0x474D -#define PCI_CHIP_MACH64GN 0x474E -#define PCI_CHIP_MACH64GO 0x474F -#define PCI_CHIP_MACH64GP 0x4750 -#define PCI_CHIP_MACH64GQ 0x4751 -#define PCI_CHIP_MACH64GR 0x4752 -#define PCI_CHIP_MACH64GS 0x4753 -#define PCI_CHIP_MACH64GT 0x4754 -#define PCI_CHIP_MACH64GU 0x4755 -#define PCI_CHIP_MACH64GV 0x4756 -#define PCI_CHIP_MACH64GW 0x4757 -#define PCI_CHIP_MACH64GX 0x4758 -#define PCI_CHIP_MACH64GY 0x4759 -#define PCI_CHIP_MACH64GZ 0x475A -#define PCI_CHIP_RV250_Id 0x4964 -#define PCI_CHIP_RV250_Ie 0x4965 -#define PCI_CHIP_RV250_If 0x4966 -#define PCI_CHIP_RV250_Ig 0x4967 -#define PCI_CHIP_R420_JH 0x4A48 -#define PCI_CHIP_R420_JI 0x4A49 -#define PCI_CHIP_R420_JJ 0x4A4A -#define PCI_CHIP_R420_JK 0x4A4B -#define PCI_CHIP_R420_JL 0x4A4C -#define PCI_CHIP_R420_JM 0x4A4D -#define PCI_CHIP_R420_JN 0x4A4E -#define PCI_CHIP_R420_4A4F 0x4A4F -#define PCI_CHIP_R420_JP 0x4A50 -#define PCI_CHIP_R420_4A54 0x4A54 -#define PCI_CHIP_R481_4B49 0x4B49 -#define PCI_CHIP_R481_4B4A 0x4B4A -#define PCI_CHIP_R481_4B4B 0x4B4B -#define PCI_CHIP_R481_4B4C 0x4B4C -#define PCI_CHIP_MACH64LB 0x4C42 -#define PCI_CHIP_MACH64LD 0x4C44 -#define PCI_CHIP_RAGE128LE 0x4C45 -#define PCI_CHIP_RAGE128LF 0x4C46 -#define PCI_CHIP_MACH64LG 0x4C47 -#define PCI_CHIP_MACH64LI 0x4C49 -#define PCI_CHIP_MACH64LM 0x4C4D -#define PCI_CHIP_MACH64LN 0x4C4E -#define PCI_CHIP_MACH64LP 0x4C50 -#define PCI_CHIP_MACH64LQ 0x4C51 -#define PCI_CHIP_MACH64LR 0x4C52 -#define PCI_CHIP_MACH64LS 0x4C53 -#define PCI_CHIP_RADEON_LW 0x4C57 -#define PCI_CHIP_RADEON_LX 0x4C58 -#define PCI_CHIP_RADEON_LY 0x4C59 -#define PCI_CHIP_RADEON_LZ 0x4C5A -#define PCI_CHIP_RV250_Ld 0x4C64 -#define PCI_CHIP_RV250_Le 0x4C65 -#define PCI_CHIP_RV250_Lf 0x4C66 -#define PCI_CHIP_RV250_Lg 0x4C67 -#define PCI_CHIP_RV250_Ln 0x4C6E -#define PCI_CHIP_RAGE128MF 0x4D46 -#define PCI_CHIP_RAGE128ML 0x4D4C -#define PCI_CHIP_R300_ND 0x4E44 -#define PCI_CHIP_R300_NE 0x4E45 -#define PCI_CHIP_R300_NF 0x4E46 -#define PCI_CHIP_R300_NG 0x4E47 -#define PCI_CHIP_R350_NH 0x4E48 -#define PCI_CHIP_R350_NI 0x4E49 -#define PCI_CHIP_R360_NJ 0x4E4A -#define PCI_CHIP_R350_NK 0x4E4B -#define PCI_CHIP_RV350_NP 0x4E50 -#define PCI_CHIP_RV350_NQ 0x4E51 -#define PCI_CHIP_RV350_NR 0x4E52 -#define PCI_CHIP_RV350_NS 0x4E53 -#define PCI_CHIP_RV350_NT 0x4E54 -#define PCI_CHIP_RV350_NV 0x4E56 -#define PCI_CHIP_RAGE128PA 0x5041 -#define PCI_CHIP_RAGE128PB 0x5042 -#define PCI_CHIP_RAGE128PC 0x5043 -#define PCI_CHIP_RAGE128PD 0x5044 -#define PCI_CHIP_RAGE128PE 0x5045 -#define PCI_CHIP_RAGE128PF 0x5046 -#define PCI_CHIP_RAGE128PG 0x5047 -#define PCI_CHIP_RAGE128PH 0x5048 -#define PCI_CHIP_RAGE128PI 0x5049 -#define PCI_CHIP_RAGE128PJ 0x504A -#define PCI_CHIP_RAGE128PK 0x504B -#define PCI_CHIP_RAGE128PL 0x504C -#define PCI_CHIP_RAGE128PM 0x504D -#define PCI_CHIP_RAGE128PN 0x504E -#define PCI_CHIP_RAGE128PO 0x504F -#define PCI_CHIP_RAGE128PP 0x5050 -#define PCI_CHIP_RAGE128PQ 0x5051 -#define PCI_CHIP_RAGE128PR 0x5052 -#define PCI_CHIP_RAGE128PS 0x5053 -#define PCI_CHIP_RAGE128PT 0x5054 -#define PCI_CHIP_RAGE128PU 0x5055 -#define PCI_CHIP_RAGE128PV 0x5056 -#define PCI_CHIP_RAGE128PW 0x5057 -#define PCI_CHIP_RAGE128PX 0x5058 -#define PCI_CHIP_RADEON_QD 0x5144 -#define PCI_CHIP_RADEON_QE 0x5145 -#define PCI_CHIP_RADEON_QF 0x5146 -#define PCI_CHIP_RADEON_QG 0x5147 -#define PCI_CHIP_R200_QH 0x5148 -#define PCI_CHIP_R200_QI 0x5149 -#define PCI_CHIP_R200_QJ 0x514A -#define PCI_CHIP_R200_QK 0x514B -#define PCI_CHIP_R200_QL 0x514C -#define PCI_CHIP_R200_QM 0x514D -#define PCI_CHIP_R200_QN 0x514E -#define PCI_CHIP_R200_QO 0x514F -#define PCI_CHIP_RV200_QW 0x5157 -#define PCI_CHIP_RV200_QX 0x5158 -#define PCI_CHIP_RV100_QY 0x5159 -#define PCI_CHIP_RV100_QZ 0x515A -#define PCI_CHIP_RN50_515E 0x515E -#define PCI_CHIP_RAGE128RE 0x5245 -#define PCI_CHIP_RAGE128RF 0x5246 -#define PCI_CHIP_RAGE128RG 0x5247 -#define PCI_CHIP_RAGE128RK 0x524B -#define PCI_CHIP_RAGE128RL 0x524C -#define PCI_CHIP_RAGE128SE 0x5345 -#define PCI_CHIP_RAGE128SF 0x5346 -#define PCI_CHIP_RAGE128SG 0x5347 -#define PCI_CHIP_RAGE128SH 0x5348 -#define PCI_CHIP_RAGE128SK 0x534B -#define PCI_CHIP_RAGE128SL 0x534C -#define PCI_CHIP_RAGE128SM 0x534D -#define PCI_CHIP_RAGE128SN 0x534E -#define PCI_CHIP_RAGE128TF 0x5446 -#define PCI_CHIP_RAGE128TL 0x544C -#define PCI_CHIP_RAGE128TR 0x5452 -#define PCI_CHIP_RAGE128TS 0x5453 -#define PCI_CHIP_RAGE128TT 0x5454 -#define PCI_CHIP_RAGE128TU 0x5455 -#define PCI_CHIP_RV370_5460 0x5460 -#define PCI_CHIP_RV370_5461 0x5461 -#define PCI_CHIP_RV370_5462 0x5462 -#define PCI_CHIP_RV370_5463 0x5463 -#define PCI_CHIP_RV370_5464 0x5464 -#define PCI_CHIP_RV370_5465 0x5465 -#define PCI_CHIP_RV370_5466 0x5466 -#define PCI_CHIP_RV370_5467 0x5467 -#define PCI_CHIP_R423_UH 0x5548 -#define PCI_CHIP_R423_UI 0x5549 -#define PCI_CHIP_R423_UJ 0x554A -#define PCI_CHIP_R423_UK 0x554B -#define PCI_CHIP_R430_554C 0x554C -#define PCI_CHIP_R430_554D 0x554D -#define PCI_CHIP_R430_554E 0x554E -#define PCI_CHIP_R430_554F 0x554F -#define PCI_CHIP_R423_5550 0x5550 -#define PCI_CHIP_R423_UQ 0x5551 -#define PCI_CHIP_R423_UR 0x5552 -#define PCI_CHIP_R423_UT 0x5554 -#define PCI_CHIP_RV410_564A 0x564A -#define PCI_CHIP_RV410_564B 0x564B -#define PCI_CHIP_RV410_564F 0x564F -#define PCI_CHIP_RV410_5652 0x5652 -#define PCI_CHIP_RV410_5653 0x5653 -#define PCI_CHIP_MACH64VT 0x5654 -#define PCI_CHIP_MACH64VU 0x5655 -#define PCI_CHIP_MACH64VV 0x5656 -#define PCI_CHIP_RS300_5834 0x5834 -#define PCI_CHIP_RS300_5835 0x5835 -#define PCI_CHIP_RS300_5836 0x5836 -#define PCI_CHIP_RS300_5837 0x5837 -#define PCI_CHIP_RS480_5954 0x5954 -#define PCI_CHIP_RS480_5955 0x5955 -#define PCI_CHIP_RV280_5960 0x5960 -#define PCI_CHIP_RV280_5961 0x5961 -#define PCI_CHIP_RV280_5962 0x5962 -#define PCI_CHIP_RV280_5964 0x5964 -#define PCI_CHIP_RV280_5965 0x5965 -#define PCI_CHIP_RN50_5969 0x5969 -#define PCI_CHIP_RS482_5974 0x5974 -#define PCI_CHIP_RS482_5975 0x5975 -#define PCI_CHIP_RS400_5A41 0x5A41 -#define PCI_CHIP_RS400_5A42 0x5A42 -#define PCI_CHIP_RC410_5A61 0x5A61 -#define PCI_CHIP_RC410_5A62 0x5A62 -#define PCI_CHIP_RV370_5B60 0x5B60 -#define PCI_CHIP_RV370_5B61 0x5B61 -#define PCI_CHIP_RV370_5B62 0x5B62 -#define PCI_CHIP_RV370_5B63 0x5B63 -#define PCI_CHIP_RV370_5B64 0x5B64 -#define PCI_CHIP_RV370_5B65 0x5B65 -#define PCI_CHIP_RV370_5B66 0x5B66 -#define PCI_CHIP_RV370_5B67 0x5B67 -#define PCI_CHIP_RV280_5C61 0x5C61 -#define PCI_CHIP_RV280_5C63 0x5C63 -#define PCI_CHIP_R430_5D48 0x5D48 -#define PCI_CHIP_R430_5D49 0x5D49 -#define PCI_CHIP_R430_5D4A 0x5D4A -#define PCI_CHIP_R480_5D4C 0x5D4C -#define PCI_CHIP_R480_5D4D 0x5D4D -#define PCI_CHIP_R480_5D4E 0x5D4E -#define PCI_CHIP_R480_5D4F 0x5D4F -#define PCI_CHIP_R480_5D50 0x5D50 -#define PCI_CHIP_R480_5D52 0x5D52 -#define PCI_CHIP_R423_5D57 0x5D57 -#define PCI_CHIP_RV410_5E48 0x5E48 -#define PCI_CHIP_RV410_5E4A 0x5E4A -#define PCI_CHIP_RV410_5E4B 0x5E4B -#define PCI_CHIP_RV410_5E4C 0x5E4C -#define PCI_CHIP_RV410_5E4D 0x5E4D -#define PCI_CHIP_RV410_5E4F 0x5E4F -#define PCI_CHIP_RS350_7834 0x7834 -#define PCI_CHIP_RS350_7835 0x7835 - -/* ASPEED Technology (AST) */ -#define PCI_CHIP_AST2000 0x2000 - -/* Avance Logic */ -#define PCI_CHIP_ALG2064 0x2064 -#define PCI_CHIP_ALG2301 0x2301 -#define PCI_CHIP_ALG2501 0x2501 - -/* Tseng */ -#define PCI_CHIP_ET4000_W32P_A 0x3202 -#define PCI_CHIP_ET4000_W32P_B 0x3205 -#define PCI_CHIP_ET4000_W32P_D 0x3206 -#define PCI_CHIP_ET4000_W32P_C 0x3207 -#define PCI_CHIP_ET6000 0x3208 -#define PCI_CHIP_ET6300 0x4702 - -/* Weitek */ -#define PCI_CHIP_P9000 0x9001 -#define PCI_CHIP_P9100 0x9100 - -/* Digital */ -#define PCI_CHIP_DC21050 0x0001 -#define PCI_CHIP_DEC21030 0x0004 -#define PCI_CHIP_TGA2 0x000D - -/* Cirrus Logic */ -#define PCI_CHIP_GD7548 0x0038 -#define PCI_CHIP_GD7555 0x0040 -#define PCI_CHIP_GD5430 0x00A0 -#define PCI_CHIP_GD5434_4 0x00A4 -#define PCI_CHIP_GD5434_8 0x00A8 -#define PCI_CHIP_GD5436 0x00AC -#define PCI_CHIP_GD5446 0x00B8 -#define PCI_CHIP_GD5480 0x00BC -#define PCI_CHIP_GD5462 0x00D0 -#define PCI_CHIP_GD5464 0x00D4 -#define PCI_CHIP_GD5464BD 0x00D5 -#define PCI_CHIP_GD5465 0x00D6 -#define PCI_CHIP_6729 0x1100 -#define PCI_CHIP_6832 0x1110 -#define PCI_CHIP_GD7542 0x1200 -#define PCI_CHIP_GD7543 0x1202 -#define PCI_CHIP_GD7541 0x1204 - -/* AMD */ -#define PCI_CHIP_AMD761 0x700E - -/* Trident */ -#define PCI_CHIP_2100 0x2100 -#define PCI_CHIP_8400 0x8400 -#define PCI_CHIP_8420 0x8420 -#define PCI_CHIP_8500 0x8500 -#define PCI_CHIP_8520 0x8520 -#define PCI_CHIP_8600 0x8600 -#define PCI_CHIP_8620 0x8620 -#define PCI_CHIP_8820 0x8820 -#define PCI_CHIP_9320 0x9320 -#define PCI_CHIP_9388 0x9388 -#define PCI_CHIP_9397 0x9397 -#define PCI_CHIP_939A 0x939A -#define PCI_CHIP_9420 0x9420 -#define PCI_CHIP_9440 0x9440 -#define PCI_CHIP_9520 0x9520 -#define PCI_CHIP_9525 0x9525 -#define PCI_CHIP_9540 0x9540 -#define PCI_CHIP_9660 0x9660 -#define PCI_CHIP_9750 0x9750 -#define PCI_CHIP_9850 0x9850 -#define PCI_CHIP_9880 0x9880 -#define PCI_CHIP_9910 0x9910 - -/* ALI */ -#define PCI_CHIP_M1435 0x1435 - -/* Matrox */ -#define PCI_CHIP_MGA2085 0x0518 -#define PCI_CHIP_MGA2064 0x0519 -#define PCI_CHIP_MGA1064 0x051A -#define PCI_CHIP_MGA2164 0x051B -#define PCI_CHIP_MGA2164_AGP 0x051F -#define PCI_CHIP_MGAG200_PCI 0x0520 -#define PCI_CHIP_MGAG200 0x0521 -#define PCI_CHIP_MGAG400 0x0525 -#define PCI_CHIP_MGAG550 0x2527 -#define PCI_CHIP_IMPRESSION 0x0D10 -#define PCI_CHIP_MGAG100_PCI 0x1000 -#define PCI_CHIP_MGAG100 0x1001 - -#define PCI_CARD_G400_TH 0x2179 -#define PCI_CARD_MILL_G200_SD 0xFF00 -#define PCI_CARD_PROD_G100_SD 0xFF01 -#define PCI_CARD_MYST_G200_SD 0xFF02 -#define PCI_CARD_MILL_G200_SG 0xFF03 -#define PCI_CARD_MARV_G200_SD 0xFF04 - -/* Chips & Tech */ -#define PCI_CHIP_65545 0x00D8 -#define PCI_CHIP_65548 0x00DC -#define PCI_CHIP_65550 0x00E0 -#define PCI_CHIP_65554 0x00E4 -#define PCI_CHIP_65555 0x00E5 -#define PCI_CHIP_68554 0x00F4 -#define PCI_CHIP_69000 0x00C0 -#define PCI_CHIP_69030 0x0C30 - -/* Miro */ -#define PCI_CHIP_ZR36050 0x5601 - -/* NEC */ -#define PCI_CHIP_POWER_VR 0x0046 - -/* SiS */ -#define PCI_CHIP_SG86C201 0x0001 -#define PCI_CHIP_SG86C202 0x0002 -#define PCI_CHIP_SG85C503 0x0008 -#define PCI_CHIP_SIS5597 0x0200 -/* Agregado por Carlos Duclos & Manuel Jander */ -#define PCI_CHIP_SIS82C204 0x0204 -#define PCI_CHIP_SG86C205 0x0205 -#define PCI_CHIP_SG86C215 0x0215 -#define PCI_CHIP_SG86C225 0x0225 -#define PCI_CHIP_85C501 0x0406 -#define PCI_CHIP_85C496 0x0496 -#define PCI_CHIP_85C601 0x0601 -#define PCI_CHIP_85C5107 0x5107 -#define PCI_CHIP_85C5511 0x5511 -#define PCI_CHIP_85C5513 0x5513 -#define PCI_CHIP_SIS5571 0x5571 -#define PCI_CHIP_SIS5597_2 0x5597 -#define PCI_CHIP_SIS530 0x6306 -#define PCI_CHIP_SIS6326 0x6326 -#define PCI_CHIP_SIS7001 0x7001 -#define PCI_CHIP_SIS300 0x0300 -#define PCI_CHIP_SIS315H 0x0310 -#define PCI_CHIP_SIS315PRO 0x0325 -#define PCI_CHIP_SIS330 0x0330 -#define PCI_CHIP_SIS630 0x6300 -#define PCI_CHIP_SIS540 0x5300 -#define PCI_CHIP_SIS550 0x5315 -#define PCI_CHIP_SIS650 0x6325 -#define PCI_CHIP_SIS730 0x7300 - -/* Hewlett-Packard */ -#define PCI_CHIP_ELROY 0x1054 -#define PCI_CHIP_ZX1_SBA 0x1229 -#define PCI_CHIP_ZX1_IOC 0x122A -#define PCI_CHIP_ZX1_LBA 0x122E /* a.k.a. Mercury */ -#define PCI_CHIP_ZX1_AGP8 0x12B4 /* a.k.a. QuickSilver */ -#define PCI_CHIP_ZX2_LBA 0x12EE -#define PCI_CHIP_ZX2_SBA 0x4030 -#define PCI_CHIP_ZX2_IOC 0x4031 -#define PCI_CHIP_ZX2_PCIE 0x4037 - -/* SGS */ -#define PCI_CHIP_STG2000 0x0008 -#define PCI_CHIP_STG1764 0x0009 -#define PCI_CHIP_KYROII 0x0010 - -/* Texas Instruments */ -#define PCI_CHIP_TI_PERMEDIA 0x3D04 -#define PCI_CHIP_TI_PERMEDIA2 0x3D07 - -/* Oak */ -#define PCI_CHIP_OTI107 0x0107 - -/* Number Nine */ -#define PCI_CHIP_I128 0x2309 -#define PCI_CHIP_I128_2 0x2339 -#define PCI_CHIP_I128_T2R 0x493D -#define PCI_CHIP_I128_T2R4 0x5348 - -/* Sun */ -#define PCI_CHIP_EBUS 0x1000 -#define PCI_CHIP_HAPPY_MEAL 0x1001 -#define PCI_CHIP_SIMBA 0x5000 -#define PCI_CHIP_PSYCHO 0x8000 -#define PCI_CHIP_SCHIZO 0x8001 -#define PCI_CHIP_SABRE 0xA000 -#define PCI_CHIP_HUMMINGBIRD 0xA001 - -/* BrookTree */ -#define PCI_CHIP_BT848 0x0350 -#define PCI_CHIP_BT849 0x0351 - -/* NVIDIA */ -#define PCI_CHIP_NV1 0x0008 -#define PCI_CHIP_DAC64 0x0009 -#define PCI_CHIP_TNT 0x0020 -#define PCI_CHIP_TNT2 0x0028 -#define PCI_CHIP_UTNT2 0x0029 -#define PCI_CHIP_VTNT2 0x002C -#define PCI_CHIP_UVTNT2 0x002D -#define PCI_CHIP_ITNT2 0x00A0 -#define PCI_CHIP_GEFORCE_256 0x0100 -#define PCI_CHIP_GEFORCE_DDR 0x0101 -#define PCI_CHIP_QUADRO 0x0103 -#define PCI_CHIP_GEFORCE2_MX 0x0110 -#define PCI_CHIP_GEFORCE2_MX_100 0x0111 -#define PCI_CHIP_GEFORCE2_GO 0x0112 -#define PCI_CHIP_QUADRO2_MXR 0x0113 -#define PCI_CHIP_GEFORCE2_GTS 0x0150 -#define PCI_CHIP_GEFORCE2_TI 0x0151 -#define PCI_CHIP_GEFORCE2_ULTRA 0x0152 -#define PCI_CHIP_QUADRO2_PRO 0x0153 -#define PCI_CHIP_GEFORCE4_MX_460 0x0170 -#define PCI_CHIP_GEFORCE4_MX_440 0x0171 -#define PCI_CHIP_GEFORCE4_MX_420 0x0172 -#define PCI_CHIP_GEFORCE4_440_GO 0x0174 -#define PCI_CHIP_GEFORCE4_420_GO 0x0175 -#define PCI_CHIP_GEFORCE4_420_GO_M32 0x0176 -#define PCI_CHIP_QUADRO4_500XGL 0x0178 -#define PCI_CHIP_GEFORCE4_440_GO_M64 0x0179 -#define PCI_CHIP_QUADRO4_200 0x017A -#define PCI_CHIP_QUADRO4_550XGL 0x017B -#define PCI_CHIP_QUADRO4_500_GOGL 0x017C -#define PCI_CHIP_IGEFORCE2 0x01A0 -#define PCI_CHIP_GEFORCE3 0x0200 -#define PCI_CHIP_GEFORCE3_TI_200 0x0201 -#define PCI_CHIP_GEFORCE3_TI_500 0x0202 -#define PCI_CHIP_QUADRO_DCC 0x0203 -#define PCI_CHIP_GEFORCE4_TI_4600 0x0250 -#define PCI_CHIP_GEFORCE4_TI_4400 0x0251 -#define PCI_CHIP_GEFORCE4_TI_4200 0x0253 -#define PCI_CHIP_QUADRO4_900XGL 0x0258 -#define PCI_CHIP_QUADRO4_750XGL 0x0259 -#define PCI_CHIP_QUADRO4_700XGL 0x025B - -/* NVIDIA & SGS */ -#define PCI_CHIP_RIVA128 0x0018 - -/* IMS */ -#define PCI_CHIP_IMSTT128 0x9128 -#define PCI_CHIP_IMSTT3D 0x9135 - -/* Alliance Semiconductor */ -#define PCI_CHIP_AP6410 0x3210 -#define PCI_CHIP_AP6422 0x6422 -#define PCI_CHIP_AT24 0x6424 -#define PCI_CHIP_AT3D 0x643D - -/* 3dfx Interactive */ -#define PCI_CHIP_VOODOO_GRAPHICS 0x0001 -#define PCI_CHIP_VOODOO2 0x0002 -#define PCI_CHIP_BANSHEE 0x0003 -#define PCI_CHIP_VOODOO3 0x0005 -#define PCI_CHIP_VOODOO5 0x0009 - -#define PCI_CARD_VOODOO3_2000 0x0036 -#define PCI_CARD_VOODOO3_3000 0x003A - -/* Rendition */ -#define PCI_CHIP_V1000 0x0001 -#define PCI_CHIP_V2x00 0x2000 - -/* 3Dlabs */ -#define PCI_CHIP_300SX 0x0001 -#define PCI_CHIP_500TX 0x0002 -#define PCI_CHIP_DELTA 0x0003 -#define PCI_CHIP_PERMEDIA 0x0004 -#define PCI_CHIP_MX 0x0006 -#define PCI_CHIP_PERMEDIA2 0x0007 -#define PCI_CHIP_GAMMA 0x0008 -#define PCI_CHIP_PERMEDIA2V 0x0009 -#define PCI_CHIP_PERMEDIA3 0x000A -#define PCI_CHIP_PERMEDIA4 0x000C -#define PCI_CHIP_R4 0x000D -#define PCI_CHIP_GAMMA2 0x000E -#define PCI_CHIP_R4ALT 0x0011 - -/* S3 */ -#define PCI_CHIP_PLATO 0x0551 -#define PCI_CHIP_VIRGE 0x5631 -#define PCI_CHIP_TRIO 0x8811 -#define PCI_CHIP_AURORA64VP 0x8812 -#define PCI_CHIP_TRIO64UVP 0x8814 -#define PCI_CHIP_VIRGE_VX 0x883D -#define PCI_CHIP_868 0x8880 -#define PCI_CHIP_928 0x88B0 -#define PCI_CHIP_864_0 0x88C0 -#define PCI_CHIP_864_1 0x88C1 -#define PCI_CHIP_964_0 0x88D0 -#define PCI_CHIP_964_1 0x88D1 -#define PCI_CHIP_968 0x88F0 -#define PCI_CHIP_TRIO64V2_DXGX 0x8901 -#define PCI_CHIP_PLATO_PX 0x8902 -#define PCI_CHIP_Trio3D 0x8904 -#define PCI_CHIP_VIRGE_DXGX 0x8A01 -#define PCI_CHIP_VIRGE_GX2 0x8A10 -#define PCI_CHIP_Trio3D_2X 0x8A13 -#define PCI_CHIP_SAVAGE3D 0x8A20 -#define PCI_CHIP_SAVAGE3D_MV 0x8A21 -#define PCI_CHIP_SAVAGE4 0x8A22 -#define PCI_CHIP_PROSAVAGE_PM 0x8A25 -#define PCI_CHIP_PROSAVAGE_KM 0x8A26 -#define PCI_CHIP_VIRGE_MX 0x8C01 -#define PCI_CHIP_VIRGE_MXPLUS 0x8C02 -#define PCI_CHIP_VIRGE_MXP 0x8C03 -#define PCI_CHIP_SAVAGE_MX_MV 0x8C10 -#define PCI_CHIP_SAVAGE_MX 0x8C11 -#define PCI_CHIP_SAVAGE_IX_MV 0x8C12 -#define PCI_CHIP_SAVAGE_IX 0x8C13 -#define PCI_CHIP_SUPSAV_MX128 0x8C22 -#define PCI_CHIP_SUPSAV_MX64 0x8C24 -#define PCI_CHIP_SUPSAV_MX64C 0x8C26 -#define PCI_CHIP_SUPSAV_IX128SDR 0x8C2A -#define PCI_CHIP_SUPSAV_IX128DDR 0x8C2B -#define PCI_CHIP_SUPSAV_IX64SDR 0x8C2C -#define PCI_CHIP_SUPSAV_IX64DDR 0x8C2D -#define PCI_CHIP_SUPSAV_IXCSDR 0x8C2E -#define PCI_CHIP_SUPSAV_IXCDDR 0x8C2F -#define PCI_CHIP_S3TWISTER_P 0x8D01 -#define PCI_CHIP_S3TWISTER_K 0x8D02 -#define PCI_CHIP_PROSAVAGE_DDR 0x8D03 -#define PCI_CHIP_PROSAVAGE_DDRK 0x8D04 -#define PCI_CHIP_SAVAGE2000 0x9102 - -/* ARK Logic */ -#define PCI_CHIP_1000PV 0xA091 -#define PCI_CHIP_2000PV 0xA099 -#define PCI_CHIP_2000MT 0xA0A1 -#define PCI_CHIP_2000MI 0xA0A9 - -/* Tritech Microelectronics */ -#define PCI_CHIP_TR25202 0xFC02 - -/* Neomagic */ -#define PCI_CHIP_NM2070 0x0001 -#define PCI_CHIP_NM2090 0x0002 -#define PCI_CHIP_NM2093 0x0003 -#define PCI_CHIP_NM2097 0x0083 -#define PCI_CHIP_NM2160 0x0004 -#define PCI_CHIP_NM2200 0x0005 -#define PCI_CHIP_NM2230 0x0025 -#define PCI_CHIP_NM2360 0x0006 -#define PCI_CHIP_NM2380 0x0016 - -/* Intel */ -#define PCI_CHIP_I815_BRIDGE 0x1130 -#define PCI_CHIP_I815 0x1132 -#define PCI_CHIP_82801_P2P 0x244E -#define PCI_CHIP_845_G_BRIDGE 0x2560 -#define PCI_CHIP_845_G 0x2562 -#define PCI_CHIP_I830_M_BRIDGE 0x3575 -#define PCI_CHIP_I830_M 0x3577 -#define PCI_CHIP_I810_BRIDGE 0x7120 -#define PCI_CHIP_I810 0x7121 -#define PCI_CHIP_I810_DC100_BRIDGE 0x7122 -#define PCI_CHIP_I810_DC100 0x7123 -#define PCI_CHIP_I810_E_BRIDGE 0x7124 -#define PCI_CHIP_I810_E 0x7125 -#define PCI_CHIP_I740_AGP 0x7800 -#define PCI_CHIP_460GX_PXB 0x84CB -#define PCI_CHIP_460GX_SAC 0x84E0 -#define PCI_CHIP_460GX_GXB_2 0x84E2 /* PCI function 2 */ -#define PCI_CHIP_460GX_WXB 0x84E6 -#define PCI_CHIP_460GX_GXB_1 0x84EA /* PCI function 1 */ - -/* Silicon Motion Inc. */ -#define PCI_CHIP_SMI910 0x0910 -#define PCI_CHIP_SMI810 0x0810 -#define PCI_CHIP_SMI820 0x0820 -#define PCI_CHIP_SMI710 0x0710 -#define PCI_CHIP_SMI712 0x0712 -#define PCI_CHIP_SMI720 0x0720 -#define PCI_CHIP_SMI731 0x0730 - -/* VMware */ -#define PCI_CHIP_VMWARE0405 0x0405 -#define PCI_CHIP_VMWARE0710 0x0710 - -#endif /* _XF86_PCIINFO_H */ diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h deleted file mode 100644 index d5185d8df..000000000 --- a/hw/xfree86/common/xf86Priv.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 1997-2002 by The XFree86 Project, 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). - */ - -/* - * This file contains declarations for private XFree86 functions and variables, - * and definitions of private macros. - * - * "private" means not available to video drivers. - */ - -#ifndef _XF86PRIV_H -#define _XF86PRIV_H - -#include "xf86Privstr.h" -#include "propertyst.h" -#include "input.h" - -/* - * Parameters set ONLY from the command line options - * The global state of these things is held in xf86InfoRec (when appropriate). - */ -extern _X_EXPORT const char *xf86ConfigFile; -extern _X_EXPORT const char *xf86ConfigDir; -extern _X_EXPORT Bool xf86AllowMouseOpenFail; -extern _X_EXPORT Bool xf86AutoBindGPUDisabled; - -#ifdef XF86VIDMODE -extern _X_EXPORT Bool xf86VidModeDisabled; -extern _X_EXPORT Bool xf86VidModeAllowNonLocal; -#endif -extern _X_EXPORT Bool xf86fpFlag; -extern _X_EXPORT Bool xf86sFlag; -extern _X_EXPORT Bool xf86bsEnableFlag; -extern _X_EXPORT Bool xf86bsDisableFlag; -extern _X_EXPORT Bool xf86silkenMouseDisableFlag; -extern _X_EXPORT Bool xf86xkbdirFlag; - -#ifdef HAVE_ACPI -extern _X_EXPORT Bool xf86acpiDisableFlag; -#endif -extern _X_EXPORT char *xf86LayoutName; -extern _X_EXPORT char *xf86ScreenName; -extern _X_EXPORT char *xf86PointerName; -extern _X_EXPORT char *xf86KeyboardName; -extern _X_EXPORT int xf86FbBpp; -extern _X_EXPORT int xf86Depth; -extern _X_EXPORT rgb xf86Weight; -extern _X_EXPORT Gamma xf86Gamma; - -/* Other parameters */ - -extern _X_EXPORT xf86InfoRec xf86Info; -extern _X_EXPORT const char *xf86ModulePath; -extern _X_EXPORT MessageType xf86ModPathFrom; -extern _X_EXPORT const char *xf86LogFile; -extern _X_EXPORT MessageType xf86LogFileFrom; -extern _X_EXPORT Bool xf86LogFileWasOpened; -extern _X_EXPORT serverLayoutRec xf86ConfigLayout; - -extern _X_EXPORT DriverPtr *xf86DriverList; -extern _X_EXPORT int xf86NumDrivers; -extern _X_EXPORT Bool xf86Resetting; -extern Bool xf86Initialising; -extern _X_EXPORT int xf86NumScreens; -extern _X_EXPORT const char *xf86VisualNames[]; -extern _X_EXPORT int xf86Verbose; /* verbosity level */ -extern _X_EXPORT int xf86LogVerbose; /* log file verbosity level */ - -extern _X_EXPORT ScrnInfoPtr *xf86GPUScreens; /* List of pointers to ScrnInfoRecs */ -extern _X_EXPORT int xf86NumGPUScreens; -extern _X_EXPORT int xf86DRMMasterFd; /* Command line argument for DRM master file descriptor */ -#ifndef DEFAULT_VERBOSE -#define DEFAULT_VERBOSE 0 -#endif -#ifndef DEFAULT_LOG_VERBOSE -#define DEFAULT_LOG_VERBOSE 3 -#endif -#ifndef DEFAULT_DPI -#define DEFAULT_DPI 96 -#endif - -/* Function Prototypes */ -#ifndef _NO_XF86_PROTOTYPES - -/* xf86Bus.c */ -extern _X_EXPORT Bool xf86BusConfig(void); -extern _X_EXPORT void xf86BusProbe(void); -extern _X_EXPORT void xf86PostProbe(void); -extern _X_EXPORT void xf86ClearEntityListForScreen(ScrnInfoPtr pScrn); -extern _X_EXPORT void xf86AddDevToEntity(int entityIndex, GDevPtr dev); -extern _X_EXPORT void xf86RemoveDevFromEntity(int entityIndex, GDevPtr dev); - -/* xf86Config.c */ - -extern _X_EXPORT Bool xf86PathIsSafe(const char *path); - -/* xf86DefaultModes */ - -extern _X_EXPORT const DisplayModeRec xf86DefaultModes[]; -extern _X_EXPORT const int xf86NumDefaultModes; - -/* xf86Configure.c */ -extern _X_EXPORT void -DoConfigure(void) - _X_NORETURN; -extern _X_EXPORT void -DoShowOptions(void) - _X_NORETURN; - -/* xf86Events.c */ - -extern _X_EXPORT void -xf86Wakeup(void *blockData, int err); -extern _X_EXPORT void -xf86HandlePMEvents(int fd, void *data); -extern _X_EXPORT int (*xf86PMGetEventFromOs) (int fd, pmEvent * events, - int num); -extern _X_EXPORT pmWait (*xf86PMConfirmEventToOs) (int fd, pmEvent event); - -/* xf86Helper.c */ -extern _X_EXPORT void -xf86LogInit(void); -extern _X_EXPORT void -xf86CloseLog(enum ExitCode error); - -/* xf86Init.c */ -extern _X_EXPORT Bool -xf86LoadModules(const char **list, void **optlist); -extern _X_EXPORT int -xf86SetVerbosity(int verb); -extern _X_EXPORT int -xf86SetLogVerbosity(int verb); -extern _X_EXPORT Bool -xf86CallDriverProbe(struct _DriverRec *drv, Bool detect_only); -extern _X_EXPORT Bool -xf86PrivsElevated(void); -extern _X_EXPORT Bool -xf86HasTTYs(void); - -#endif /* _NO_XF86_PROTOTYPES */ - -#endif /* _XF86PRIV_H */ diff --git a/hw/xfree86/common/xf86Privstr.h b/hw/xfree86/common/xf86Privstr.h deleted file mode 100644 index 31861148f..000000000 --- a/hw/xfree86/common/xf86Privstr.h +++ /dev/null @@ -1,126 +0,0 @@ - -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains definitions of the private XFree86 data structures/types. - * None of the data structures here should be used by video drivers. - */ - -#ifndef _XF86PRIVSTR_H -#define _XF86PRIVSTR_H - -#include "xf86str.h" - -typedef enum { - XF86_GlxVisualsMinimal, - XF86_GlxVisualsTypical, - XF86_GlxVisualsAll, -} XF86_GlxVisuals; - -/* - * xf86InfoRec contains global parameters which the video drivers never - * need to access. Global parameters which the video drivers do need - * should be individual globals. - */ - -typedef struct { - int consoleFd; - int vtno; - - /* event handler part */ - int lastEventTime; - Bool vtRequestsPending; -#ifdef __sun - int vtPendingNum; -#endif - Bool dontVTSwitch; - Bool autoVTSwitch; - Bool ShareVTs; - Bool dontZap; - Bool dontZoom; - - /* graphics part */ - ScreenPtr currentScreen; -#if defined(CSRG_BASED) || defined(__FreeBSD_kernel__) - int consType; /* Which console driver? */ -#endif - - /* Other things */ - Bool allowMouseOpenFail; - Bool vidModeEnabled; /* VidMode extension enabled */ - Bool vidModeAllowNonLocal; /* allow non-local VidMode - * connections */ - Bool miscModInDevEnabled; /* Allow input devices to be - * changed */ - Bool miscModInDevAllowNonLocal; - Bool pmFlag; - MessageType iglxFrom; - XF86_GlxVisuals glxVisuals; - MessageType glxVisualsFrom; - - Bool useDefaultFontPath; - Bool ignoreABI; - - Bool forceInputDevices; /* force xorg.conf or built-in input devices */ - Bool autoAddDevices; /* Whether to succeed NIDR, or ignore. */ - Bool autoEnableDevices; /* Whether to enable, or let the client - * control. */ - - Bool dri2; - MessageType dri2From; - - Bool autoAddGPU; - const char *debug; - Bool autoBindGPU; -} xf86InfoRec, *xf86InfoPtr; - -/* ISC's cc can't handle ~ of UL constants, so explicitly type cast them. */ -#define XLED1 ((unsigned long) 0x00000001) -#define XLED2 ((unsigned long) 0x00000002) -#define XLED3 ((unsigned long) 0x00000004) -#define XLED4 ((unsigned long) 0x00000008) -#define XCAPS ((unsigned long) 0x20000000) -#define XNUM ((unsigned long) 0x40000000) -#define XSCR ((unsigned long) 0x80000000) -#define XCOMP ((unsigned long) 0x00008000) - -/* BSD console driver types (consType) */ -#if defined(CSRG_BASED) || defined(__FreeBSD_kernel__) -#define PCCONS 0 -#define CODRV011 1 -#define CODRV01X 2 -#define SYSCONS 8 -#define PCVT 16 -#define WSCONS 32 -#endif - -/* Root window property to tell clients whether our VT is currently active. - * Name chosen to match the "XFree86_VT" property. */ -#define HAS_VT_ATOM_NAME "XFree86_has_VT" - -#endif /* _XF86PRIVSTR_H */ diff --git a/hw/xfree86/common/xf86RandR.c b/hw/xfree86/common/xf86RandR.c deleted file mode 100644 index 08f656b30..000000000 --- a/hw/xfree86/common/xf86RandR.c +++ /dev/null @@ -1,444 +0,0 @@ -/* - * - * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "globals.h" -#include "xf86.h" -#include "xf86str.h" -#include "xf86Priv.h" -#include "xf86DDC.h" -#include "mipointer.h" -#include -#include "inputstr.h" - -typedef struct _xf86RandRInfo { - CloseScreenProcPtr CloseScreen; - int virtualX; - int virtualY; - int mmWidth; - int mmHeight; - Rotation rotation; -} XF86RandRInfoRec, *XF86RandRInfoPtr; - -static DevPrivateKeyRec xf86RandRKeyRec; -static DevPrivateKey xf86RandRKey; - -#define XF86RANDRINFO(p) ((XF86RandRInfoPtr)dixLookupPrivate(&(p)->devPrivates, xf86RandRKey)) - -static int -xf86RandRModeRefresh(DisplayModePtr mode) -{ - if (mode->VRefresh) - return (int) (mode->VRefresh + 0.5); - else if (mode->Clock == 0) - return 0; - else - return (int) (mode->Clock * 1000.0 / mode->HTotal / mode->VTotal + 0.5); -} - -static Bool -xf86RandRGetInfo(ScreenPtr pScreen, Rotation * rotations) -{ - RRScreenSizePtr pSize; - ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - DisplayModePtr mode; - int refresh0 = 60; - xorgRRModeMM RRModeMM; - - *rotations = RR_Rotate_0; - - for (mode = scrp->modes; mode != NULL; mode = mode->next) { - int refresh = xf86RandRModeRefresh(mode); - - if (mode == scrp->modes) - refresh0 = refresh; - - RRModeMM.mode = mode; - RRModeMM.virtX = randrp->virtualX; - RRModeMM.virtY = randrp->virtualY; - RRModeMM.mmWidth = randrp->mmWidth; - RRModeMM.mmHeight = randrp->mmHeight; - - if (scrp->DriverFunc) { - (*scrp->DriverFunc) (scrp, RR_GET_MODE_MM, &RRModeMM); - } - - pSize = RRRegisterSize(pScreen, - mode->HDisplay, mode->VDisplay, - RRModeMM.mmWidth, RRModeMM.mmHeight); - if (!pSize) - return FALSE; - RRRegisterRate(pScreen, pSize, refresh); - if (mode == scrp->currentMode && - mode->HDisplay == scrp->virtualX && - mode->VDisplay == scrp->virtualY) - RRSetCurrentConfig(pScreen, randrp->rotation, refresh, pSize); - if (mode->next == scrp->modes) - break; - } - if (scrp->currentMode->HDisplay != randrp->virtualX || - scrp->currentMode->VDisplay != randrp->virtualY) { - mode = scrp->modes; - - RRModeMM.mode = NULL; - RRModeMM.virtX = randrp->virtualX; - RRModeMM.virtY = randrp->virtualY; - RRModeMM.mmWidth = randrp->mmWidth; - RRModeMM.mmHeight = randrp->mmHeight; - - if (scrp->DriverFunc) { - (*scrp->DriverFunc) (scrp, RR_GET_MODE_MM, &RRModeMM); - } - - pSize = RRRegisterSize(pScreen, - randrp->virtualX, randrp->virtualY, - RRModeMM.mmWidth, RRModeMM.mmHeight); - if (!pSize) - return FALSE; - RRRegisterRate(pScreen, pSize, refresh0); - if (scrp->virtualX == randrp->virtualX && - scrp->virtualY == randrp->virtualY) { - RRSetCurrentConfig(pScreen, randrp->rotation, refresh0, pSize); - } - } - - /* If there is driver support for randr, let it set our supported rotations */ - if (scrp->DriverFunc) { - xorgRRRotation RRRotation; - - RRRotation.RRRotations = *rotations; - if (!(*scrp->DriverFunc) (scrp, RR_GET_INFO, &RRRotation)) - return TRUE; - *rotations = RRRotation.RRRotations; - } - - return TRUE; -} - -static Bool -xf86RandRSetMode(ScreenPtr pScreen, - DisplayModePtr mode, - Bool useVirtual, int mmWidth, int mmHeight) -{ - ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - int oldWidth = pScreen->width; - int oldHeight = pScreen->height; - int oldmmWidth = pScreen->mmWidth; - int oldmmHeight = pScreen->mmHeight; - int oldVirtualX = scrp->virtualX; - int oldVirtualY = scrp->virtualY; - WindowPtr pRoot = pScreen->root; - Bool ret = TRUE; - - if (pRoot && scrp->vtSema) - (*scrp->EnableDisableFBAccess) (scrp, FALSE); - if (useVirtual) { - scrp->virtualX = randrp->virtualX; - scrp->virtualY = randrp->virtualY; - } - else { - scrp->virtualX = mode->HDisplay; - scrp->virtualY = mode->VDisplay; - } - - /* - * The DIX forgets the physical dimensions we passed into RRRegisterSize, so - * reconstruct them if possible. - */ - if (scrp->DriverFunc) { - xorgRRModeMM RRModeMM; - - RRModeMM.mode = mode; - RRModeMM.virtX = scrp->virtualX; - RRModeMM.virtY = scrp->virtualY; - RRModeMM.mmWidth = mmWidth; - RRModeMM.mmHeight = mmHeight; - - (*scrp->DriverFunc) (scrp, RR_GET_MODE_MM, &RRModeMM); - - mmWidth = RRModeMM.mmWidth; - mmHeight = RRModeMM.mmHeight; - } - if (randrp->rotation & (RR_Rotate_90 | RR_Rotate_270)) { - /* If the screen is rotated 90 or 270 degrees, swap the sizes. */ - pScreen->width = scrp->virtualY; - pScreen->height = scrp->virtualX; - pScreen->mmWidth = mmHeight; - pScreen->mmHeight = mmWidth; - } - else { - pScreen->width = scrp->virtualX; - pScreen->height = scrp->virtualY; - pScreen->mmWidth = mmWidth; - pScreen->mmHeight = mmHeight; - } - if (!xf86SwitchMode(pScreen, mode)) { - pScreen->width = oldWidth; - pScreen->height = oldHeight; - pScreen->mmWidth = oldmmWidth; - pScreen->mmHeight = oldmmHeight; - scrp->virtualX = oldVirtualX; - scrp->virtualY = oldVirtualY; - ret = FALSE; - } - /* - * Make sure the layout is correct - */ - xf86ReconfigureLayout(); - - if (scrp->vtSema) { - /* - * Make sure the whole screen is visible - */ - xf86SetViewport (pScreen, pScreen->width, pScreen->height); - xf86SetViewport (pScreen, 0, 0); - if (pRoot) - (*scrp->EnableDisableFBAccess) (scrp, TRUE); - } - return ret; -} - -static Bool -xf86RandRSetConfig(ScreenPtr pScreen, - Rotation rotation, int rate, RRScreenSizePtr pSize) -{ - ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - DisplayModePtr mode; - int pos[MAXDEVICES][2]; - Bool useVirtual = FALSE; - Rotation oldRotation = randrp->rotation; - DeviceIntPtr dev; - Bool view_adjusted = FALSE; - - for (dev = inputInfo.devices; dev; dev = dev->next) { - if (!IsMaster(dev) && !IsFloating(dev)) - continue; - - miPointerGetPosition(dev, &pos[dev->id][0], &pos[dev->id][1]); - } - - for (mode = scrp->modes;; mode = mode->next) { - if (mode->HDisplay == pSize->width && - mode->VDisplay == pSize->height && - (rate == 0 || xf86RandRModeRefresh(mode) == rate)) - break; - if (mode->next == scrp->modes) { - if (pSize->width == randrp->virtualX && - pSize->height == randrp->virtualY) { - mode = scrp->modes; - useVirtual = TRUE; - break; - } - return FALSE; - } - } - - if (randrp->rotation != rotation) { - - /* Have the driver do its thing. */ - if (scrp->DriverFunc) { - xorgRRRotation RRRotation; - - RRRotation.RRConfig.rotation = rotation; - RRRotation.RRConfig.rate = rate; - RRRotation.RRConfig.width = pSize->width; - RRRotation.RRConfig.height = pSize->height; - - /* - * Currently we need to rely on HW support for rotation. - */ - if (!(*scrp->DriverFunc) (scrp, RR_SET_CONFIG, &RRRotation)) - return FALSE; - } - else - return FALSE; - - randrp->rotation = rotation; - } - - if (!xf86RandRSetMode - (pScreen, mode, useVirtual, pSize->mmWidth, pSize->mmHeight)) { - if (randrp->rotation != oldRotation) { - /* Have the driver undo its thing. */ - if (scrp->DriverFunc) { - xorgRRRotation RRRotation; - - RRRotation.RRConfig.rotation = oldRotation; - RRRotation.RRConfig.rate = - xf86RandRModeRefresh(scrp->currentMode); - RRRotation.RRConfig.width = scrp->virtualX; - RRRotation.RRConfig.height = scrp->virtualY; - (*scrp->DriverFunc) (scrp, RR_SET_CONFIG, &RRRotation); - } - - randrp->rotation = oldRotation; - } - return FALSE; - } - - update_desktop_dimensions(); - - /* - * Move the cursor back where it belongs; SwitchMode repositions it - * FIXME: duplicated code, see modes/xf86RandR12.c - */ - for (dev = inputInfo.devices; dev; dev = dev->next) { - if (!IsMaster(dev) && !IsFloating(dev)) - continue; - - if (pScreen == miPointerGetScreen(dev)) { - int px = pos[dev->id][0]; - int py = pos[dev->id][1]; - - px = (px >= pScreen->width ? (pScreen->width - 1) : px); - py = (py >= pScreen->height ? (pScreen->height - 1) : py); - - /* Setting the viewpoint makes only sense on one device */ - if (!view_adjusted && IsMaster(dev)) { - xf86SetViewport(pScreen, px, py); - view_adjusted = TRUE; - } - - (*pScreen->SetCursorPosition) (dev, pScreen, px, py, FALSE); - } - } - - return TRUE; -} - -/* - * Reset size back to original - */ -static Bool -xf86RandRCloseScreen(ScreenPtr pScreen) -{ - ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - - scrp->virtualX = pScreen->width = randrp->virtualX; - scrp->virtualY = pScreen->height = randrp->virtualY; - scrp->currentMode = scrp->modes; - pScreen->CloseScreen = randrp->CloseScreen; - free(randrp); - dixSetPrivate(&pScreen->devPrivates, xf86RandRKey, NULL); - return (*pScreen->CloseScreen) (pScreen); -} - -Rotation -xf86GetRotation(ScreenPtr pScreen) -{ - if (xf86RandRKey == NULL) - return RR_Rotate_0; - - return XF86RANDRINFO(pScreen)->rotation; -} - -/* Function to change RandR's idea of the virtual screen size */ -Bool -xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen, - int newvirtX, int newvirtY, int newmmWidth, - int newmmHeight, Bool resetMode) -{ - XF86RandRInfoPtr randrp; - - if (xf86RandRKey == NULL) - return FALSE; - - randrp = XF86RANDRINFO(pScreen); - if (randrp == NULL) - return FALSE; - - if (newvirtX > 0) - randrp->virtualX = newvirtX; - - if (newvirtY > 0) - randrp->virtualY = newvirtY; - - if (newmmWidth > 0) - randrp->mmWidth = newmmWidth; - - if (newmmHeight > 0) - randrp->mmHeight = newmmHeight; - - /* This is only for during server start */ - if (resetMode) { - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - return (xf86RandRSetMode(pScreen, - pScrn->currentMode, - TRUE, pScreen->mmWidth, pScreen->mmHeight)); - } - - return TRUE; -} - -Bool -xf86RandRInit(ScreenPtr pScreen) -{ - rrScrPrivPtr rp; - XF86RandRInfoPtr randrp; - ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen); - -#ifdef PANORAMIX - /* XXX disable RandR when using Xinerama */ - if (!noPanoramiXExtension) - return TRUE; -#endif - - xf86RandRKey = &xf86RandRKeyRec; - - if (!dixRegisterPrivateKey(&xf86RandRKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - randrp = malloc(sizeof(XF86RandRInfoRec)); - if (!randrp) - return FALSE; - - if (!RRScreenInit(pScreen)) { - free(randrp); - return FALSE; - } - rp = rrGetScrPriv(pScreen); - rp->rrGetInfo = xf86RandRGetInfo; - rp->rrSetConfig = xf86RandRSetConfig; - - randrp->virtualX = scrp->virtualX; - randrp->virtualY = scrp->virtualY; - randrp->mmWidth = pScreen->mmWidth; - randrp->mmHeight = pScreen->mmHeight; - - randrp->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = xf86RandRCloseScreen; - - randrp->rotation = RR_Rotate_0; - - dixSetPrivate(&pScreen->devPrivates, xf86RandRKey, randrp); - return TRUE; -} diff --git a/hw/xfree86/common/xf86VGAarbiter.c b/hw/xfree86/common/xf86VGAarbiter.c deleted file mode 100644 index 9db8d044f..000000000 --- a/hw/xfree86/common/xf86VGAarbiter.c +++ /dev/null @@ -1,1023 +0,0 @@ -/* - * This code was stolen from RAC and adapted to control the legacy vga - * interface. - * - * - * Copyright (c) 2007 Paulo R. Zanoni, Tiago Vignatti - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#include "xorg-config.h" - -#include "xf86VGAarbiter.h" -#include "xf86VGAarbiterPriv.h" -#include "xf86Bus.h" -#include "xf86Priv.h" -#include "pciaccess.h" - -static GCFuncs VGAarbiterGCFuncs = { - VGAarbiterValidateGC, VGAarbiterChangeGC, VGAarbiterCopyGC, - VGAarbiterDestroyGC, VGAarbiterChangeClip, VGAarbiterDestroyClip, - VGAarbiterCopyClip -}; - -static GCOps VGAarbiterGCOps = { - VGAarbiterFillSpans, VGAarbiterSetSpans, VGAarbiterPutImage, - VGAarbiterCopyArea, VGAarbiterCopyPlane, VGAarbiterPolyPoint, - VGAarbiterPolylines, VGAarbiterPolySegment, VGAarbiterPolyRectangle, - VGAarbiterPolyArc, VGAarbiterFillPolygon, VGAarbiterPolyFillRect, - VGAarbiterPolyFillArc, VGAarbiterPolyText8, VGAarbiterPolyText16, - VGAarbiterImageText8, VGAarbiterImageText16, VGAarbiterImageGlyphBlt, - VGAarbiterPolyGlyphBlt, VGAarbiterPushPixels, -}; - -static miPointerSpriteFuncRec VGAarbiterSpriteFuncs = { - VGAarbiterSpriteRealizeCursor, VGAarbiterSpriteUnrealizeCursor, - VGAarbiterSpriteSetCursor, VGAarbiterSpriteMoveCursor, - VGAarbiterDeviceCursorInitialize, VGAarbiterDeviceCursorCleanup -}; - -static DevPrivateKeyRec VGAarbiterScreenKeyRec; - -#define VGAarbiterScreenKey (&VGAarbiterScreenKeyRec) -static DevPrivateKeyRec VGAarbiterGCKeyRec; - -#define VGAarbiterGCKey (&VGAarbiterGCKeyRec) - -static int vga_no_arb = 0; -void -xf86VGAarbiterInit(void) -{ - if (pci_device_vgaarb_init() != 0) { - vga_no_arb = 1; - xf86Msg(X_WARNING, - "VGA arbiter: cannot open kernel arbiter, no multi-card support\n"); - } -} - -void -xf86VGAarbiterFini(void) -{ - if (vga_no_arb) - return; - pci_device_vgaarb_fini(); -} - -void -xf86VGAarbiterLock(ScrnInfoPtr pScrn) -{ - if (vga_no_arb) - return; - pci_device_vgaarb_set_target(pScrn->vgaDev); - pci_device_vgaarb_lock(); -} - -void -xf86VGAarbiterUnlock(ScrnInfoPtr pScrn) -{ - if (vga_no_arb) - return; - pci_device_vgaarb_unlock(); -} - -Bool -xf86VGAarbiterAllowDRI(ScreenPtr pScreen) -{ - int vga_count; - int rsrc_decodes = 0; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - - if (vga_no_arb) - return TRUE; - - pci_device_vgaarb_get_info(pScrn->vgaDev, &vga_count, &rsrc_decodes); - if (vga_count > 1) { - if (rsrc_decodes) { - return FALSE; - } - } - return TRUE; -} - -void -xf86VGAarbiterScrnInit(ScrnInfoPtr pScrn) -{ - struct pci_device *dev; - EntityPtr pEnt; - - if (vga_no_arb) - return; - - pEnt = xf86Entities[pScrn->entityList[0]]; - if (pEnt->bus.type != BUS_PCI) - return; - - dev = pEnt->bus.id.pci; - pScrn->vgaDev = dev; -} - -void -xf86VGAarbiterDeviceDecodes(ScrnInfoPtr pScrn, int rsrc) -{ - if (vga_no_arb) - return; - pci_device_vgaarb_set_target(pScrn->vgaDev); - pci_device_vgaarb_decodes(rsrc); -} - -Bool -xf86VGAarbiterWrapFunctions(void) -{ - ScrnInfoPtr pScrn; - VGAarbiterScreenPtr pScreenPriv; - miPointerScreenPtr PointPriv; - PictureScreenPtr ps; - ScreenPtr pScreen; - int vga_count, i; - - if (vga_no_arb) - return FALSE; - - /* - * we need to wrap the arbiter if we have more than - * one VGA card - hotplug cries. - */ - pci_device_vgaarb_get_info(NULL, &vga_count, NULL); - if (vga_count < 2 || !xf86Screens) - return FALSE; - - xf86Msg(X_INFO, "Found %d VGA devices: arbiter wrapping enabled\n", - vga_count); - - for (i = 0; i < xf86NumScreens; i++) { - pScreen = xf86Screens[i]->pScreen; - ps = GetPictureScreenIfSet(pScreen); - pScrn = xf86ScreenToScrn(pScreen); - PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); - - if (!dixRegisterPrivateKey - (&VGAarbiterGCKeyRec, PRIVATE_GC, sizeof(VGAarbiterGCRec))) - return FALSE; - - if (!dixRegisterPrivateKey(&VGAarbiterScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - if (!(pScreenPriv = malloc(sizeof(VGAarbiterScreenRec)))) - return FALSE; - - dixSetPrivate(&pScreen->devPrivates, VGAarbiterScreenKey, pScreenPriv); - - WRAP_SCREEN(CloseScreen, VGAarbiterCloseScreen); - WRAP_SCREEN(SaveScreen, VGAarbiterSaveScreen); - WRAP_SCREEN(WakeupHandler, VGAarbiterWakeupHandler); - WRAP_SCREEN(BlockHandler, VGAarbiterBlockHandler); - WRAP_SCREEN(CreateGC, VGAarbiterCreateGC); - WRAP_SCREEN(GetImage, VGAarbiterGetImage); - WRAP_SCREEN(GetSpans, VGAarbiterGetSpans); - WRAP_SCREEN(SourceValidate, VGAarbiterSourceValidate); - WRAP_SCREEN(CopyWindow, VGAarbiterCopyWindow); - WRAP_SCREEN(ClearToBackground, VGAarbiterClearToBackground); - WRAP_SCREEN(CreatePixmap, VGAarbiterCreatePixmap); - WRAP_SCREEN(StoreColors, VGAarbiterStoreColors); - WRAP_SCREEN(DisplayCursor, VGAarbiterDisplayCursor); - WRAP_SCREEN(RealizeCursor, VGAarbiterRealizeCursor); - WRAP_SCREEN(UnrealizeCursor, VGAarbiterUnrealizeCursor); - WRAP_SCREEN(RecolorCursor, VGAarbiterRecolorCursor); - WRAP_SCREEN(SetCursorPosition, VGAarbiterSetCursorPosition); - WRAP_PICT(Composite, VGAarbiterComposite); - WRAP_PICT(Glyphs, VGAarbiterGlyphs); - WRAP_PICT(CompositeRects, VGAarbiterCompositeRects); - WRAP_SCREEN_INFO(AdjustFrame, VGAarbiterAdjustFrame); - WRAP_SCREEN_INFO(SwitchMode, VGAarbiterSwitchMode); - WRAP_SCREEN_INFO(EnterVT, VGAarbiterEnterVT); - WRAP_SCREEN_INFO(LeaveVT, VGAarbiterLeaveVT); - WRAP_SCREEN_INFO(FreeScreen, VGAarbiterFreeScreen); - WRAP_SPRITE; - } - - return TRUE; -} - -/* Screen funcs */ -static Bool -VGAarbiterCloseScreen(ScreenPtr pScreen) -{ - Bool val; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - VGAarbiterScreenPtr pScreenPriv = - (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - VGAarbiterScreenKey); - miPointerScreenPtr PointPriv = - (miPointerScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - miPointerScreenKey); - PictureScreenPtr ps = GetPictureScreenIfSet(pScreen); - - UNWRAP_SCREEN(CreateGC); - UNWRAP_SCREEN(CloseScreen); - UNWRAP_SCREEN(GetImage); - UNWRAP_SCREEN(GetSpans); - UNWRAP_SCREEN(SourceValidate); - UNWRAP_SCREEN(CopyWindow); - UNWRAP_SCREEN(ClearToBackground); - UNWRAP_SCREEN(SaveScreen); - UNWRAP_SCREEN(StoreColors); - UNWRAP_SCREEN(DisplayCursor); - UNWRAP_SCREEN(RealizeCursor); - UNWRAP_SCREEN(UnrealizeCursor); - UNWRAP_SCREEN(RecolorCursor); - UNWRAP_SCREEN(SetCursorPosition); - UNWRAP_PICT(Composite); - UNWRAP_PICT(Glyphs); - UNWRAP_PICT(CompositeRects); - UNWRAP_SCREEN_INFO(AdjustFrame); - UNWRAP_SCREEN_INFO(SwitchMode); - UNWRAP_SCREEN_INFO(EnterVT); - UNWRAP_SCREEN_INFO(LeaveVT); - UNWRAP_SCREEN_INFO(FreeScreen); - UNWRAP_SPRITE; - - free((void *) pScreenPriv); - xf86VGAarbiterLock(xf86ScreenToScrn(pScreen)); - val = (*pScreen->CloseScreen) (pScreen); - xf86VGAarbiterUnlock(xf86ScreenToScrn(pScreen)); - return val; -} - -static void -VGAarbiterBlockHandler(ScreenPtr pScreen, void *pTimeout) -{ - SCREEN_PROLOG(BlockHandler); - VGAGet(pScreen); - pScreen->BlockHandler(pScreen, pTimeout); - VGAPut(); - SCREEN_EPILOG(BlockHandler, VGAarbiterBlockHandler); -} - -static void -VGAarbiterWakeupHandler(ScreenPtr pScreen, int result) -{ - SCREEN_PROLOG(WakeupHandler); - VGAGet(pScreen); - pScreen->WakeupHandler(pScreen, result); - VGAPut(); - SCREEN_EPILOG(WakeupHandler, VGAarbiterWakeupHandler); -} - -static void -VGAarbiterGetImage(DrawablePtr pDrawable, - int sx, int sy, int w, int h, - unsigned int format, unsigned long planemask, char *pdstLine) -{ - ScreenPtr pScreen = pDrawable->pScreen; - - SCREEN_PROLOG(GetImage); - VGAGet(pScreen); - (*pScreen->GetImage) (pDrawable, sx, sy, w, h, format, planemask, pdstLine); - VGAPut(); - SCREEN_EPILOG(GetImage, VGAarbiterGetImage); -} - -static void -VGAarbiterGetSpans(DrawablePtr pDrawable, - int wMax, - DDXPointPtr ppt, int *pwidth, int nspans, char *pdstStart) -{ - ScreenPtr pScreen = pDrawable->pScreen; - - SCREEN_PROLOG(GetSpans); - VGAGet(pScreen); - (*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans, pdstStart); - VGAPut(); - SCREEN_EPILOG(GetSpans, VGAarbiterGetSpans); -} - -static void -VGAarbiterSourceValidate(DrawablePtr pDrawable, - int x, int y, int width, int height, - unsigned int subWindowMode) -{ - ScreenPtr pScreen = pDrawable->pScreen; - - SCREEN_PROLOG(SourceValidate); - VGAGet(pScreen); - (*pScreen->SourceValidate) (pDrawable, x, y, width, height, - subWindowMode); - VGAPut(); - SCREEN_EPILOG(SourceValidate, VGAarbiterSourceValidate); -} - -static void -VGAarbiterCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - - SCREEN_PROLOG(CopyWindow); - VGAGet(pScreen); - (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc); - VGAPut(); - SCREEN_EPILOG(CopyWindow, VGAarbiterCopyWindow); -} - -static void -VGAarbiterClearToBackground(WindowPtr pWin, - int x, int y, int w, int h, Bool generateExposures) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - - SCREEN_PROLOG(ClearToBackground); - VGAGet(pScreen); - (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures); - VGAPut(); - SCREEN_EPILOG(ClearToBackground, VGAarbiterClearToBackground); -} - -static PixmapPtr -VGAarbiterCreatePixmap(ScreenPtr pScreen, int w, int h, int depth, - unsigned usage_hint) -{ - PixmapPtr pPix; - - SCREEN_PROLOG(CreatePixmap); - VGAGet(pScreen); - pPix = (*pScreen->CreatePixmap) (pScreen, w, h, depth, usage_hint); - VGAPut(); - SCREEN_EPILOG(CreatePixmap, VGAarbiterCreatePixmap); - - return pPix; -} - -static Bool -VGAarbiterSaveScreen(ScreenPtr pScreen, Bool unblank) -{ - Bool val; - - SCREEN_PROLOG(SaveScreen); - VGAGet(pScreen); - val = (*pScreen->SaveScreen) (pScreen, unblank); - VGAPut(); - SCREEN_EPILOG(SaveScreen, VGAarbiterSaveScreen); - - return val; -} - -static void -VGAarbiterStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs) -{ - ScreenPtr pScreen = pmap->pScreen; - - SCREEN_PROLOG(StoreColors); - VGAGet(pScreen); - (*pScreen->StoreColors) (pmap, ndef, pdefs); - VGAPut(); - SCREEN_EPILOG(StoreColors, VGAarbiterStoreColors); -} - -static void -VGAarbiterRecolorCursor(DeviceIntPtr pDev, - ScreenPtr pScreen, CursorPtr pCurs, Bool displayed) -{ - SCREEN_PROLOG(RecolorCursor); - VGAGet(pScreen); - (*pScreen->RecolorCursor) (pDev, pScreen, pCurs, displayed); - VGAPut(); - SCREEN_EPILOG(RecolorCursor, VGAarbiterRecolorCursor); -} - -static Bool -VGAarbiterRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) -{ - Bool val; - - SCREEN_PROLOG(RealizeCursor); - VGAGet(pScreen); - val = (*pScreen->RealizeCursor) (pDev, pScreen, pCursor); - VGAPut(); - SCREEN_EPILOG(RealizeCursor, VGAarbiterRealizeCursor); - return val; -} - -static Bool -VGAarbiterUnrealizeCursor(DeviceIntPtr pDev, - ScreenPtr pScreen, CursorPtr pCursor) -{ - Bool val; - - SCREEN_PROLOG(UnrealizeCursor); - VGAGet(pScreen); - val = (*pScreen->UnrealizeCursor) (pDev, pScreen, pCursor); - VGAPut(); - SCREEN_EPILOG(UnrealizeCursor, VGAarbiterUnrealizeCursor); - return val; -} - -static Bool -VGAarbiterDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) -{ - Bool val; - - SCREEN_PROLOG(DisplayCursor); - VGAGet(pScreen); - val = (*pScreen->DisplayCursor) (pDev, pScreen, pCursor); - VGAPut(); - SCREEN_EPILOG(DisplayCursor, VGAarbiterDisplayCursor); - return val; -} - -static Bool -VGAarbiterSetCursorPosition(DeviceIntPtr pDev, - ScreenPtr pScreen, int x, int y, Bool generateEvent) -{ - Bool val; - - SCREEN_PROLOG(SetCursorPosition); - VGAGet(pScreen); - val = (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent); - VGAPut(); - SCREEN_EPILOG(SetCursorPosition, VGAarbiterSetCursorPosition); - return val; -} - -static void -VGAarbiterAdjustFrame(ScrnInfoPtr pScrn, int x, int y) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - VGAarbiterScreenPtr pScreenPriv = - (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - VGAarbiterScreenKey); - - VGAGet(pScreen); - (*pScreenPriv->AdjustFrame) (pScrn, x, y); - VGAPut(); -} - -static Bool -VGAarbiterSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - Bool val; - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - VGAarbiterScreenPtr pScreenPriv = - (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - VGAarbiterScreenKey); - - VGAGet(pScreen); - val = (*pScreenPriv->SwitchMode) (pScrn, mode); - VGAPut(); - return val; -} - -static Bool -VGAarbiterEnterVT(ScrnInfoPtr pScrn) -{ - Bool val; - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - VGAarbiterScreenPtr pScreenPriv = - (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - VGAarbiterScreenKey); - - VGAGet(pScreen); - pScrn->EnterVT = pScreenPriv->EnterVT; - val = (*pScrn->EnterVT) (pScrn); - pScreenPriv->EnterVT = pScrn->EnterVT; - pScrn->EnterVT = VGAarbiterEnterVT; - VGAPut(); - return val; -} - -static void -VGAarbiterLeaveVT(ScrnInfoPtr pScrn) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - VGAarbiterScreenPtr pScreenPriv = - (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - VGAarbiterScreenKey); - - VGAGet(pScreen); - pScrn->LeaveVT = pScreenPriv->LeaveVT; - (*pScreenPriv->LeaveVT) (pScrn); - pScreenPriv->LeaveVT = pScrn->LeaveVT; - pScrn->LeaveVT = VGAarbiterLeaveVT; - VGAPut(); -} - -static void -VGAarbiterFreeScreen(ScrnInfoPtr pScrn) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - VGAarbiterScreenPtr pScreenPriv = - (VGAarbiterScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - VGAarbiterScreenKey); - - VGAGet(pScreen); - (*pScreenPriv->FreeScreen) (pScrn); - VGAPut(); -} - -static Bool -VGAarbiterCreateGC(GCPtr pGC) -{ - ScreenPtr pScreen = pGC->pScreen; - VGAarbiterGCPtr pGCPriv = - (VGAarbiterGCPtr) dixLookupPrivate(&pGC->devPrivates, VGAarbiterGCKey); - Bool ret; - - SCREEN_PROLOG(CreateGC); - ret = (*pScreen->CreateGC) (pGC); - GC_WRAP(pGC); - SCREEN_EPILOG(CreateGC, VGAarbiterCreateGC); - - return ret; -} - -/* GC funcs */ -static void -VGAarbiterValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDraw) -{ - GC_UNWRAP(pGC); - (*pGC->funcs->ValidateGC) (pGC, changes, pDraw); - GC_WRAP(pGC); -} - -static void -VGAarbiterDestroyGC(GCPtr pGC) -{ - GC_UNWRAP(pGC); - (*pGC->funcs->DestroyGC) (pGC); - GC_WRAP(pGC); -} - -static void -VGAarbiterChangeGC(GCPtr pGC, unsigned long mask) -{ - GC_UNWRAP(pGC); - (*pGC->funcs->ChangeGC) (pGC, mask); - GC_WRAP(pGC); -} - -static void -VGAarbiterCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst) -{ - GC_UNWRAP(pGCDst); - (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst); - GC_WRAP(pGCDst); -} - -static void -VGAarbiterChangeClip(GCPtr pGC, int type, void *pvalue, int nrects) -{ - GC_UNWRAP(pGC); - (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects); - GC_WRAP(pGC); -} - -static void -VGAarbiterCopyClip(GCPtr pgcDst, GCPtr pgcSrc) -{ - GC_UNWRAP(pgcDst); - (*pgcDst->funcs->CopyClip) (pgcDst, pgcSrc); - GC_WRAP(pgcDst); -} - -static void -VGAarbiterDestroyClip(GCPtr pGC) -{ - GC_UNWRAP(pGC); - (*pGC->funcs->DestroyClip) (pGC); - GC_WRAP(pGC); -} - -/* GC Ops */ -static void -VGAarbiterFillSpans(DrawablePtr pDraw, - GC * pGC, - int nInit, - DDXPointPtr pptInit, int *pwidthInit, int fSorted) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->FillSpans) (pDraw, pGC, nInit, pptInit, pwidthInit, fSorted); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterSetSpans(DrawablePtr pDraw, - GCPtr pGC, - char *pcharsrc, - register DDXPointPtr ppt, - int *pwidth, int nspans, int fSorted) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->SetSpans) (pDraw, pGC, pcharsrc, ppt, pwidth, nspans, fSorted); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterPutImage(DrawablePtr pDraw, - GCPtr pGC, - int depth, - int x, int y, int w, int h, - int leftPad, int format, char *pImage) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->PutImage) (pDraw, pGC, depth, x, y, w, h, - leftPad, format, pImage); - VGAPut(); - GC_WRAP(pGC); -} - -static RegionPtr -VGAarbiterCopyArea(DrawablePtr pSrc, - DrawablePtr pDst, - GC * pGC, - int srcx, int srcy, - int width, int height, int dstx, int dsty) -{ - RegionPtr ret; - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - ret = (*pGC->ops->CopyArea) (pSrc, pDst, - pGC, srcx, srcy, width, height, dstx, dsty); - VGAPut(); - GC_WRAP(pGC); - return ret; -} - -static RegionPtr -VGAarbiterCopyPlane(DrawablePtr pSrc, - DrawablePtr pDst, - GCPtr pGC, - int srcx, int srcy, - int width, int height, - int dstx, int dsty, unsigned long bitPlane) -{ - RegionPtr ret; - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - ret = (*pGC->ops->CopyPlane) (pSrc, pDst, pGC, srcx, srcy, - width, height, dstx, dsty, bitPlane); - VGAPut(); - GC_WRAP(pGC); - return ret; -} - -static void -VGAarbiterPolyPoint(DrawablePtr pDraw, - GCPtr pGC, int mode, int npt, xPoint * pptInit) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->PolyPoint) (pDraw, pGC, mode, npt, pptInit); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterPolylines(DrawablePtr pDraw, - GCPtr pGC, int mode, int npt, DDXPointPtr pptInit) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->Polylines) (pDraw, pGC, mode, npt, pptInit); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterPolySegment(DrawablePtr pDraw, GCPtr pGC, int nseg, xSegment * pSeg) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->PolySegment) (pDraw, pGC, nseg, pSeg); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterPolyRectangle(DrawablePtr pDraw, - GCPtr pGC, int nRectsInit, xRectangle *pRectsInit) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->PolyRectangle) (pDraw, pGC, nRectsInit, pRectsInit); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->PolyArc) (pDraw, pGC, narcs, parcs); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterFillPolygon(DrawablePtr pDraw, - GCPtr pGC, - int shape, int mode, int count, DDXPointPtr ptsIn) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->FillPolygon) (pDraw, pGC, shape, mode, count, ptsIn); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterPolyFillRect(DrawablePtr pDraw, - GCPtr pGC, int nrectFill, xRectangle *prectInit) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->PolyFillRect) (pDraw, pGC, nrectFill, prectInit); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterPolyFillArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, parcs); - VGAPut(); - GC_WRAP(pGC); -} - -static int -VGAarbiterPolyText8(DrawablePtr pDraw, - GCPtr pGC, int x, int y, int count, char *chars) -{ - int ret; - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - ret = (*pGC->ops->PolyText8) (pDraw, pGC, x, y, count, chars); - VGAPut(); - GC_WRAP(pGC); - return ret; -} - -static int -VGAarbiterPolyText16(DrawablePtr pDraw, - GCPtr pGC, int x, int y, int count, unsigned short *chars) -{ - int ret; - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - ret = (*pGC->ops->PolyText16) (pDraw, pGC, x, y, count, chars); - VGAPut(); - GC_WRAP(pGC); - return ret; -} - -static void -VGAarbiterImageText8(DrawablePtr pDraw, - GCPtr pGC, int x, int y, int count, char *chars) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->ImageText8) (pDraw, pGC, x, y, count, chars); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterImageText16(DrawablePtr pDraw, - GCPtr pGC, int x, int y, int count, unsigned short *chars) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->ImageText16) (pDraw, pGC, x, y, count, chars); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterImageGlyphBlt(DrawablePtr pDraw, - GCPtr pGC, - int xInit, int yInit, - unsigned int nglyph, - CharInfoPtr * ppci, void *pglyphBase) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->ImageGlyphBlt) (pDraw, pGC, xInit, yInit, - nglyph, ppci, pglyphBase); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterPolyGlyphBlt(DrawablePtr pDraw, - GCPtr pGC, - int xInit, int yInit, - unsigned int nglyph, - CharInfoPtr * ppci, void *pglyphBase) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->PolyGlyphBlt) (pDraw, pGC, xInit, yInit, - nglyph, ppci, pglyphBase); - VGAPut(); - GC_WRAP(pGC); -} - -static void -VGAarbiterPushPixels(GCPtr pGC, - PixmapPtr pBitMap, - DrawablePtr pDraw, int dx, int dy, int xOrg, int yOrg) -{ - ScreenPtr pScreen = pGC->pScreen; - - GC_UNWRAP(pGC); - VGAGet(pScreen); - (*pGC->ops->PushPixels) (pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg); - VGAPut(); - GC_WRAP(pGC); -} - -/* miSpriteFuncs */ -static Bool -VGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, - CursorPtr pCur) -{ - Bool val; - - SPRITE_PROLOG; - VGAGet(pScreen); - val = PointPriv->spriteFuncs->RealizeCursor(pDev, pScreen, pCur); - VGAPut(); - SPRITE_EPILOG; - return val; -} - -static Bool -VGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, - CursorPtr pCur) -{ - Bool val; - - SPRITE_PROLOG; - VGAGet(pScreen); - val = PointPriv->spriteFuncs->UnrealizeCursor(pDev, pScreen, pCur); - VGAPut(); - SPRITE_EPILOG; - return val; -} - -static void -VGAarbiterSpriteSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCur, - int x, int y) -{ - SPRITE_PROLOG; - VGAGet(pScreen); - PointPriv->spriteFuncs->SetCursor(pDev, pScreen, pCur, x, y); - VGAPut(); - SPRITE_EPILOG; -} - -static void -VGAarbiterSpriteMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) -{ - SPRITE_PROLOG; - VGAGet(pScreen); - PointPriv->spriteFuncs->MoveCursor(pDev, pScreen, x, y); - VGAPut(); - SPRITE_EPILOG; -} - -static Bool -VGAarbiterDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen) -{ - Bool val; - - SPRITE_PROLOG; - VGAGet(pScreen); - val = PointPriv->spriteFuncs->DeviceCursorInitialize(pDev, pScreen); - VGAPut(); - SPRITE_EPILOG; - return val; -} - -static void -VGAarbiterDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen) -{ - SPRITE_PROLOG; - VGAGet(pScreen); - PointPriv->spriteFuncs->DeviceCursorCleanup(pDev, pScreen); - VGAPut(); - SPRITE_EPILOG; -} - -static void -VGAarbiterComposite(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; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - PICTURE_PROLOGUE(Composite); - - VGAGet(pScreen); - (*ps->Composite) (op, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask, xDst, - yDst, width, height); - VGAPut(); - PICTURE_EPILOGUE(Composite, VGAarbiterComposite); -} - -static void -VGAarbiterGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst, - PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlist, - GlyphListPtr list, GlyphPtr * glyphs) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - PICTURE_PROLOGUE(Glyphs); - - VGAGet(pScreen); - (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc, nlist, list, glyphs); - VGAPut(); - PICTURE_EPILOGUE(Glyphs, VGAarbiterGlyphs); -} - -static void -VGAarbiterCompositeRects(CARD8 op, PicturePtr pDst, xRenderColor * color, - int nRect, xRectangle *rects) -{ - ScreenPtr pScreen = pDst->pDrawable->pScreen; - PictureScreenPtr ps = GetPictureScreen(pScreen); - - PICTURE_PROLOGUE(CompositeRects); - - VGAGet(pScreen); - (*ps->CompositeRects) (op, pDst, color, nRect, rects); - VGAPut(); - PICTURE_EPILOGUE(CompositeRects, VGAarbiterCompositeRects); -} diff --git a/hw/xfree86/common/xf86VGAarbiter.h b/hw/xfree86/common/xf86VGAarbiter.h deleted file mode 100644 index bb52cf78a..000000000 --- a/hw/xfree86/common/xf86VGAarbiter.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2009 Tiago Vignatti - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef __XF86VGAARBITER_H -#define __XF86VGAARBITER_H - -#include "screenint.h" -#include "misc.h" -#include "xf86.h" - -/* Functions */ -extern void xf86VGAarbiterInit(void); -extern void xf86VGAarbiterFini(void); -void xf86VGAarbiterScrnInit(ScrnInfoPtr pScrn); -extern Bool xf86VGAarbiterWrapFunctions(void); -extern void xf86VGAarbiterLock(ScrnInfoPtr pScrn); -extern void xf86VGAarbiterUnlock(ScrnInfoPtr pScrn); - -/* allow a driver to remove itself from arbiter - really should be - * done in the kernel though */ -extern _X_EXPORT void xf86VGAarbiterDeviceDecodes(ScrnInfoPtr pScrn, int rsrc); - -/* DRI and arbiter are really not possible together, - * you really want to remove the card from arbitration if you can */ -extern _X_EXPORT Bool xf86VGAarbiterAllowDRI(ScreenPtr pScreen); - -#endif /* __XF86VGAARBITER_H */ diff --git a/hw/xfree86/common/xf86VGAarbiterPriv.h b/hw/xfree86/common/xf86VGAarbiterPriv.h deleted file mode 100644 index 03db55700..000000000 --- a/hw/xfree86/common/xf86VGAarbiterPriv.h +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (c) 2009 Tiago Vignatti - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "misc.h" -#include "xf86.h" -#include "xf86_OSproc.h" -#include -#include "colormapst.h" -#include "scrnintstr.h" -#include "screenint.h" -#include "gcstruct.h" -#include "pixmapstr.h" -#include "pixmap.h" -#include "windowstr.h" -#include "window.h" -#include "xf86str.h" -#include "mipointer.h" -#include "mipointrst.h" -#include "picturestr.h" - -#define WRAP_SCREEN(x,y) {pScreenPriv->x = pScreen->x; pScreen->x = y;} - -#define UNWRAP_SCREEN(x) pScreen->x = pScreenPriv->x - -#define SCREEN_PRIV() ((VGAarbiterScreenPtr) dixLookupPrivate(&(pScreen)->devPrivates, VGAarbiterScreenKey)) - -#define SCREEN_PROLOG(x) (pScreen->x = SCREEN_PRIV()->x) - -#define SCREEN_EPILOG(x,y) do { \ - SCREEN_PRIV()->x = pScreen->x; \ - pScreen->x = y; \ - } while (0) - -#define WRAP_PICT(x,y) if (ps) {pScreenPriv->x = ps->x;\ - ps->x = y;} - -#define UNWRAP_PICT(x) if (ps) {ps->x = pScreenPriv->x;} - -#define PICTURE_PROLOGUE(field) ps->field = \ - ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \ - VGAarbiterScreenKey))->field - -#define PICTURE_EPILOGUE(field, wrap) ps->field = wrap - -#define WRAP_SCREEN_INFO(x,y) do {pScreenPriv->x = pScrn->x; pScrn->x = y;} while(0) - -#define UNWRAP_SCREEN_INFO(x) pScrn->x = pScreenPriv->x - -#define SPRITE_PROLOG \ - miPointerScreenPtr PointPriv; \ - VGAarbiterScreenPtr pScreenPriv; \ - input_lock(); \ - PointPriv = dixLookupPrivate(&pScreen->devPrivates, \ - miPointerScreenKey); \ - pScreenPriv = dixLookupPrivate(&(pScreen)->devPrivates, \ - VGAarbiterScreenKey); \ - PointPriv->spriteFuncs = pScreenPriv->miSprite; \ - -#define SPRITE_EPILOG \ - pScreenPriv->miSprite = PointPriv->spriteFuncs; \ - PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs; \ - input_unlock(); - -#define WRAP_SPRITE do { pScreenPriv->miSprite = PointPriv->spriteFuncs;\ - PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs; \ - } while (0) - -#define UNWRAP_SPRITE PointPriv->spriteFuncs = pScreenPriv->miSprite - -#define GC_WRAP(x) pGCPriv->wrapOps = (x)->ops;\ - pGCPriv->wrapFuncs = (x)->funcs; (x)->ops = &VGAarbiterGCOps;\ - (x)->funcs = &VGAarbiterGCFuncs; - -#define GC_UNWRAP(x) VGAarbiterGCPtr pGCPriv = \ - (VGAarbiterGCPtr)dixLookupPrivate(&(x)->devPrivates, VGAarbiterGCKey);\ - (x)->ops = pGCPriv->wrapOps; (x)->funcs = pGCPriv->wrapFuncs; - -static inline void -VGAGet(ScreenPtr pScreen) -{ - pci_device_vgaarb_set_target(xf86ScreenToScrn(pScreen)->vgaDev); - pci_device_vgaarb_lock(); -} - -static inline void -VGAPut(void) -{ - pci_device_vgaarb_unlock(); -} - -typedef struct _VGAarbiterScreen { - CreateGCProcPtr CreateGC; - CloseScreenProcPtr CloseScreen; - ScreenBlockHandlerProcPtr BlockHandler; - ScreenWakeupHandlerProcPtr WakeupHandler; - GetImageProcPtr GetImage; - GetSpansProcPtr GetSpans; - SourceValidateProcPtr SourceValidate; - CopyWindowProcPtr CopyWindow; - ClearToBackgroundProcPtr ClearToBackground; - CreatePixmapProcPtr CreatePixmap; - SaveScreenProcPtr SaveScreen; - /* Colormap */ - StoreColorsProcPtr StoreColors; - /* Cursor */ - DisplayCursorProcPtr DisplayCursor; - RealizeCursorProcPtr RealizeCursor; - UnrealizeCursorProcPtr UnrealizeCursor; - RecolorCursorProcPtr RecolorCursor; - SetCursorPositionProcPtr SetCursorPosition; - void (*AdjustFrame) (ScrnInfoPtr, int, int); - Bool (*SwitchMode) (ScrnInfoPtr, DisplayModePtr); - Bool (*EnterVT) (ScrnInfoPtr); - void (*LeaveVT) (ScrnInfoPtr); - void (*FreeScreen) (ScrnInfoPtr); - miPointerSpriteFuncPtr miSprite; - CompositeProcPtr Composite; - GlyphsProcPtr Glyphs; - CompositeRectsProcPtr CompositeRects; -} VGAarbiterScreenRec, *VGAarbiterScreenPtr; - -typedef struct _VGAarbiterGC { - const GCOps *wrapOps; - const GCFuncs *wrapFuncs; -} VGAarbiterGCRec, *VGAarbiterGCPtr; - -/* Screen funcs */ -static void VGAarbiterBlockHandler(ScreenPtr pScreen, void *pTimeout); -static void VGAarbiterWakeupHandler(ScreenPtr pScreen, int result); -static Bool VGAarbiterCloseScreen(ScreenPtr pScreen); -static void VGAarbiterGetImage(DrawablePtr pDrawable, int sx, int sy, int w, - int h, unsigned int format, - unsigned long planemask, char *pdstLine); -static void VGAarbiterGetSpans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt, - int *pwidth, int nspans, char *pdstStart); -static void VGAarbiterSourceValidate(DrawablePtr pDrawable, int x, int y, - int width, int height, - unsigned int subWindowMode); -static void VGAarbiterCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, - RegionPtr prgnSrc); -static void VGAarbiterClearToBackground(WindowPtr pWin, int x, int y, int w, - int h, Bool generateExposures); -static PixmapPtr VGAarbiterCreatePixmap(ScreenPtr pScreen, int w, int h, - int depth, unsigned int usage_hint); -static Bool VGAarbiterCreateGC(GCPtr pGC); -static Bool VGAarbiterSaveScreen(ScreenPtr pScreen, Bool unblank); -static void VGAarbiterStoreColors(ColormapPtr pmap, int ndef, xColorItem - * pdefs); -static void VGAarbiterRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScreen, - CursorPtr pCurs, Bool displayed); -static Bool VGAarbiterRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, - CursorPtr pCursor); -static Bool VGAarbiterUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, - CursorPtr pCursor); -static Bool VGAarbiterDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, - CursorPtr pCursor); -static Bool VGAarbiterSetCursorPosition(DeviceIntPtr pDev, ScreenPtr - pScreen, int x, int y, - Bool generateEvent); -static void VGAarbiterAdjustFrame(ScrnInfoPtr pScrn, int x, int y); -static Bool VGAarbiterSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode); -static Bool VGAarbiterEnterVT(ScrnInfoPtr pScrn); -static void VGAarbiterLeaveVT(ScrnInfoPtr pScrn); -static void VGAarbiterFreeScreen(ScrnInfoPtr pScrn); - -/* GC funcs */ -static void VGAarbiterValidateGC(GCPtr pGC, unsigned long changes, - DrawablePtr pDraw); -static void VGAarbiterChangeGC(GCPtr pGC, unsigned long mask); -static void VGAarbiterCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst); -static void VGAarbiterDestroyGC(GCPtr pGC); -static void VGAarbiterChangeClip(GCPtr pGC, int type, void *pvalue, - int nrects); -static void VGAarbiterDestroyClip(GCPtr pGC); -static void VGAarbiterCopyClip(GCPtr pgcDst, GCPtr pgcSrc); - -/* GC ops */ -static void VGAarbiterFillSpans(DrawablePtr pDraw, GC * pGC, int nInit, - DDXPointPtr pptInit, int *pwidthInit, - int fSorted); -static void VGAarbiterSetSpans(DrawablePtr pDraw, GCPtr pGC, char *pcharsrc, - register DDXPointPtr ppt, int *pwidth, - int nspans, int fSorted); -static void VGAarbiterPutImage(DrawablePtr pDraw, GCPtr pGC, int depth, int x, - int y, int w, int h, int leftPad, int format, - char *pImage); -static RegionPtr VGAarbiterCopyArea(DrawablePtr pSrc, DrawablePtr pDst, - GC * pGC, int srcx, int srcy, int width, - int height, int dstx, int dsty); -static RegionPtr VGAarbiterCopyPlane(DrawablePtr pSrc, DrawablePtr pDst, - GCPtr pGC, int srcx, int srcy, int width, - int height, int dstx, int dsty, - unsigned long bitPlane); -static void VGAarbiterPolyPoint(DrawablePtr pDraw, GCPtr pGC, int mode, int npt, - xPoint * pptInit); -static void VGAarbiterPolylines(DrawablePtr pDraw, GCPtr pGC, int mode, int npt, - DDXPointPtr pptInit); -static void VGAarbiterPolySegment(DrawablePtr pDraw, GCPtr pGC, int nseg, - xSegment * pSeg); -static void VGAarbiterPolyRectangle(DrawablePtr pDraw, GCPtr pGC, - int nRectsInit, xRectangle *pRectsInit); -static void VGAarbiterPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, - xArc * parcs); -static void VGAarbiterFillPolygon(DrawablePtr pDraw, GCPtr pGC, int shape, - int mode, int count, DDXPointPtr ptsIn); -static void VGAarbiterPolyFillRect(DrawablePtr pDraw, GCPtr pGC, int nrectFill, - xRectangle *prectInit); -static void VGAarbiterPolyFillArc(DrawablePtr pDraw, GCPtr pGC, int narcs, - xArc * parcs); -static int VGAarbiterPolyText8(DrawablePtr pDraw, GCPtr pGC, int x, int y, - int count, char *chars); -static int VGAarbiterPolyText16(DrawablePtr pDraw, GCPtr pGC, int x, int y, - int count, unsigned short *chars); -static void VGAarbiterImageText8(DrawablePtr pDraw, GCPtr pGC, int x, int y, - int count, char *chars); -static void VGAarbiterImageText16(DrawablePtr pDraw, GCPtr pGC, int x, int y, - int count, unsigned short *chars); -static void VGAarbiterImageGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int xInit, - int yInit, unsigned int nglyph, - CharInfoPtr * ppci, void *pglyphBase); -static void VGAarbiterPolyGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int xInit, - int yInit, unsigned int nglyph, - CharInfoPtr * ppci, void *pglyphBase); -static void VGAarbiterPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr - pDraw, int dx, int dy, int xOrg, int yOrg); - -/* miSpriteFuncs */ -static Bool VGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev, ScreenPtr - pScreen, CursorPtr pCur); -static Bool VGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr - pScreen, CursorPtr pCur); -static void VGAarbiterSpriteSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, - CursorPtr pCur, int x, int y); -static void VGAarbiterSpriteMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, - int x, int y); -static Bool VGAarbiterDeviceCursorInitialize(DeviceIntPtr pDev, - ScreenPtr pScreen); -static void VGAarbiterDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen); - -static void VGAarbiterComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask, - PicturePtr pDst, INT16 xSrc, INT16 ySrc, - INT16 xMask, INT16 yMask, INT16 xDst, - INT16 yDst, CARD16 width, CARD16 height); -static void VGAarbiterGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst, - PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, - int nlist, GlyphListPtr list, GlyphPtr * glyphs); -static void VGAarbiterCompositeRects(CARD8 op, PicturePtr pDst, - xRenderColor * color, int nRect, - xRectangle *rects); diff --git a/hw/xfree86/common/xf86VidMode.c b/hw/xfree86/common/xf86VidMode.c deleted file mode 100644 index 7e12ea2cc..000000000 --- a/hw/xfree86/common/xf86VidMode.c +++ /dev/null @@ -1,463 +0,0 @@ -/* - * Copyright (c) 1999-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains the VidMode functions required by the extension. - * These have been added to avoid the need for the higher level extension - * code to access the private XFree86 data structures directly. Wherever - * possible this code uses the functions in xf86Mode.c to do the work, - * so that two version of code that do similar things don't have to be - * maintained. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" -#include "extinit.h" - -#ifdef XF86VIDMODE -#include "vidmodestr.h" -#include "xf86Privstr.h" -#include "xf86Extensions.h" -#include "xf86cmap.h" - -static vidMonitorValue -xf86VidModeGetMonitorValue(ScreenPtr pScreen, int valtyp, int indx) -{ - vidMonitorValue ret = { NULL, }; - MonPtr monitor; - ScrnInfoPtr pScrn; - - pScrn = xf86ScreenToScrn(pScreen); - monitor = pScrn->monitor; - - switch (valtyp) { - case VIDMODE_MON_VENDOR: - ret.ptr = monitor->vendor; - break; - case VIDMODE_MON_MODEL: - ret.ptr = monitor->model; - break; - case VIDMODE_MON_NHSYNC: - ret.i = monitor->nHsync; - break; - case VIDMODE_MON_NVREFRESH: - ret.i = monitor->nVrefresh; - break; - case VIDMODE_MON_HSYNC_LO: - ret.f = (100.0 * monitor->hsync[indx].lo); - break; - case VIDMODE_MON_HSYNC_HI: - ret.f = (100.0 * monitor->hsync[indx].hi); - break; - case VIDMODE_MON_VREFRESH_LO: - ret.f = (100.0 * monitor->vrefresh[indx].lo); - break; - case VIDMODE_MON_VREFRESH_HI: - ret.f = (100.0 * monitor->vrefresh[indx].hi); - break; - } - return ret; -} - -static Bool -xf86VidModeGetCurrentModeline(ScreenPtr pScreen, DisplayModePtr *mode, int *dotClock) -{ - ScrnInfoPtr pScrn; - - pScrn = xf86ScreenToScrn(pScreen); - - if (pScrn->currentMode) { - *mode = pScrn->currentMode; - *dotClock = pScrn->currentMode->Clock; - - return TRUE; - } - return FALSE; -} - -static int -xf86VidModeGetDotClock(ScreenPtr pScreen, int Clock) -{ - ScrnInfoPtr pScrn; - - pScrn = xf86ScreenToScrn(pScreen); - if ((pScrn->progClock) || (Clock >= MAXCLOCKS)) - return Clock; - else - return pScrn->clock[Clock]; -} - -static int -xf86VidModeGetNumOfClocks(ScreenPtr pScreen, Bool *progClock) -{ - ScrnInfoPtr pScrn; - - pScrn = xf86ScreenToScrn(pScreen); - if (pScrn->progClock) { - *progClock = TRUE; - return 0; - } - else { - *progClock = FALSE; - return pScrn->numClocks; - } -} - -static Bool -xf86VidModeGetClocks(ScreenPtr pScreen, int *Clocks) -{ - ScrnInfoPtr pScrn; - int i; - - pScrn = xf86ScreenToScrn(pScreen); - - if (pScrn->progClock) - return FALSE; - - for (i = 0; i < pScrn->numClocks; i++) - *Clocks++ = pScrn->clock[i]; - - return TRUE; -} - -static Bool -xf86VidModeGetNextModeline(ScreenPtr pScreen, DisplayModePtr *mode, int *dotClock) -{ - VidModePtr pVidMode; - DisplayModePtr p; - - pVidMode = VidModeGetPtr(pScreen); - - for (p = pVidMode->Next; p != NULL && p != pVidMode->First; p = p->next) { - if (p->status == MODE_OK) { - pVidMode->Next = p->next; - *mode = p; - *dotClock = xf86VidModeGetDotClock(pScreen, p->Clock); - return TRUE; - } - } - - return FALSE; -} - -static Bool -xf86VidModeGetFirstModeline(ScreenPtr pScreen, DisplayModePtr *mode, int *dotClock) -{ - ScrnInfoPtr pScrn; - VidModePtr pVidMode; - - pScrn = xf86ScreenToScrn(pScreen); - if (pScrn->modes == NULL) - return FALSE; - - pVidMode = VidModeGetPtr(pScreen); - pVidMode->First = pScrn->modes; - pVidMode->Next = pVidMode->First->next; - - if (pVidMode->First->status == MODE_OK) { - *mode = pVidMode->First; - *dotClock = xf86VidModeGetDotClock(pScreen, pVidMode->First->Clock); - return TRUE; - } - - return xf86VidModeGetNextModeline(pScreen, mode, dotClock); -} - -static Bool -xf86VidModeDeleteModeline(ScreenPtr pScreen, DisplayModePtr mode) -{ - ScrnInfoPtr pScrn; - - if (mode == NULL) - return FALSE; - - pScrn = xf86ScreenToScrn(pScreen); - xf86DeleteMode(&(pScrn->modes), mode); - return TRUE; -} - -static Bool -xf86VidModeZoomViewport(ScreenPtr pScreen, int zoom) -{ - xf86ZoomViewport(pScreen, zoom); - return TRUE; -} - -static Bool -xf86VidModeSetViewPort(ScreenPtr pScreen, int x, int y) -{ - ScrnInfoPtr pScrn; - - pScrn = xf86ScreenToScrn(pScreen); - pScrn->frameX0 = min(max(x, 0), - pScrn->virtualX - pScrn->currentMode->HDisplay); - pScrn->frameX1 = pScrn->frameX0 + pScrn->currentMode->HDisplay - 1; - pScrn->frameY0 = min(max(y, 0), - pScrn->virtualY - pScrn->currentMode->VDisplay); - pScrn->frameY1 = pScrn->frameY0 + pScrn->currentMode->VDisplay - 1; - if (pScrn->AdjustFrame != NULL) - (pScrn->AdjustFrame) (pScrn, pScrn->frameX0, pScrn->frameY0); - - return TRUE; -} - -static Bool -xf86VidModeGetViewPort(ScreenPtr pScreen, int *x, int *y) -{ - ScrnInfoPtr pScrn; - - pScrn = xf86ScreenToScrn(pScreen); - *x = pScrn->frameX0; - *y = pScrn->frameY0; - return TRUE; -} - -static Bool -xf86VidModeSwitchMode(ScreenPtr pScreen, DisplayModePtr mode) -{ - ScrnInfoPtr pScrn; - DisplayModePtr pTmpMode; - Bool retval; - - pScrn = xf86ScreenToScrn(pScreen); - /* save in case we fail */ - pTmpMode = pScrn->currentMode; - /* Force a mode switch */ - pScrn->currentMode = NULL; - retval = xf86SwitchMode(pScrn->pScreen, mode); - /* we failed: restore it */ - if (retval == FALSE) - pScrn->currentMode = pTmpMode; - return retval; -} - -static Bool -xf86VidModeLockZoom(ScreenPtr pScreen, Bool lock) -{ - if (xf86Info.dontZoom) - return FALSE; - - xf86LockZoom(pScreen, lock); - return TRUE; -} - -static ModeStatus -xf86VidModeCheckModeForMonitor(ScreenPtr pScreen, DisplayModePtr mode) -{ - ScrnInfoPtr pScrn; - - if (mode == NULL) - return MODE_ERROR; - - pScrn = xf86ScreenToScrn(pScreen); - - return xf86CheckModeForMonitor(mode, pScrn->monitor); -} - -static ModeStatus -xf86VidModeCheckModeForDriver(ScreenPtr pScreen, DisplayModePtr mode) -{ - ScrnInfoPtr pScrn; - - if (mode == NULL) - return MODE_ERROR; - - pScrn = xf86ScreenToScrn(pScreen); - - return xf86CheckModeForDriver(pScrn, mode, 0); -} - -static void -xf86VidModeSetCrtcForMode(ScreenPtr pScreen, DisplayModePtr mode) -{ - ScrnInfoPtr pScrn; - DisplayModePtr ScreenModes; - - if (mode == NULL) - return; - - /* Ugly hack so that the xf86Mode.c function can be used without change */ - pScrn = xf86ScreenToScrn(pScreen); - ScreenModes = pScrn->modes; - pScrn->modes = mode; - - xf86SetCrtcForModes(pScrn, pScrn->adjustFlags); - pScrn->modes = ScreenModes; - return; -} - -static Bool -xf86VidModeAddModeline(ScreenPtr pScreen, DisplayModePtr mode) -{ - ScrnInfoPtr pScrn; - - if (mode == NULL) - return FALSE; - - pScrn = xf86ScreenToScrn(pScreen); - - mode->name = strdup(""); /* freed by deletemode */ - mode->status = MODE_OK; - mode->next = pScrn->modes->next; - mode->prev = pScrn->modes; - pScrn->modes->next = mode; - if (mode->next != NULL) - mode->next->prev = mode; - - return TRUE; -} - -static int -xf86VidModeGetNumOfModes(ScreenPtr pScreen) -{ - DisplayModePtr mode = NULL; - int dotClock = 0, nummodes = 0; - - if (!xf86VidModeGetFirstModeline(pScreen, &mode, &dotClock)) - return nummodes; - - do { - nummodes++; - if (!xf86VidModeGetNextModeline(pScreen, &mode, &dotClock)) - return nummodes; - } while (TRUE); -} - -static Bool -xf86VidModeSetGamma(ScreenPtr pScreen, float red, float green, float blue) -{ - Gamma gamma; - - gamma.red = red; - gamma.green = green; - gamma.blue = blue; - if (xf86ChangeGamma(pScreen, gamma) != Success) - return FALSE; - else - return TRUE; -} - -static Bool -xf86VidModeGetGamma(ScreenPtr pScreen, float *red, float *green, float *blue) -{ - ScrnInfoPtr pScrn; - - pScrn = xf86ScreenToScrn(pScreen); - *red = pScrn->gamma.red; - *green = pScrn->gamma.green; - *blue = pScrn->gamma.blue; - return TRUE; -} - -static Bool -xf86VidModeSetGammaRamp(ScreenPtr pScreen, int size, CARD16 *r, CARD16 *g, CARD16 *b) -{ - xf86ChangeGammaRamp(pScreen, size, r, g, b); - return TRUE; -} - -static Bool -xf86VidModeGetGammaRamp(ScreenPtr pScreen, int size, CARD16 *r, CARD16 *g, CARD16 *b) -{ - xf86GetGammaRamp(pScreen, size, r, g, b); - return TRUE; -} - -static Bool -xf86VidModeInit(ScreenPtr pScreen) -{ - VidModePtr pVidMode; - - if (!xf86GetVidModeEnabled()) { - DebugF("!xf86GetVidModeEnabled()\n"); - return FALSE; - } - - pVidMode = VidModeInit(pScreen); - if (!pVidMode) - return FALSE; - - pVidMode->Flags = 0; - pVidMode->Next = NULL; - - pVidMode->GetMonitorValue = xf86VidModeGetMonitorValue; - pVidMode->GetCurrentModeline = xf86VidModeGetCurrentModeline; - pVidMode->GetFirstModeline = xf86VidModeGetFirstModeline; - pVidMode->GetNextModeline = xf86VidModeGetNextModeline; - pVidMode->DeleteModeline = xf86VidModeDeleteModeline; - pVidMode->ZoomViewport = xf86VidModeZoomViewport; - pVidMode->GetViewPort = xf86VidModeGetViewPort; - pVidMode->SetViewPort = xf86VidModeSetViewPort; - pVidMode->SwitchMode = xf86VidModeSwitchMode; - pVidMode->LockZoom = xf86VidModeLockZoom; - pVidMode->GetNumOfClocks = xf86VidModeGetNumOfClocks; - pVidMode->GetClocks = xf86VidModeGetClocks; - pVidMode->CheckModeForMonitor = xf86VidModeCheckModeForMonitor; - pVidMode->CheckModeForDriver = xf86VidModeCheckModeForDriver; - pVidMode->SetCrtcForMode = xf86VidModeSetCrtcForMode; - pVidMode->AddModeline = xf86VidModeAddModeline; - pVidMode->GetDotClock = xf86VidModeGetDotClock; - pVidMode->GetNumOfModes = xf86VidModeGetNumOfModes; - pVidMode->SetGamma = xf86VidModeSetGamma; - pVidMode->GetGamma = xf86VidModeGetGamma; - pVidMode->SetGammaRamp = xf86VidModeSetGammaRamp; - pVidMode->GetGammaRamp = xf86VidModeGetGammaRamp; - pVidMode->GetGammaRampSize = xf86GetGammaRampSize; /* use xf86cmap API directly */ - - return TRUE; -} - -void -XFree86VidModeExtensionInit(void) -{ - int i; - Bool enabled = FALSE; - - DebugF("XFree86VidModeExtensionInit"); - - /* This means that the DDX doesn't want the vidmode extension enabled */ - if (!xf86GetVidModeEnabled()) - return; - - for (i = 0; i < screenInfo.numScreens; i++) { - if (xf86VidModeInit (screenInfo.screens[i])) - enabled = TRUE; - } - /* This means that the DDX doesn't want the vidmode extension enabled */ - if (!enabled) - return; - - VidModeAddExtension(xf86GetVidModeAllowNonLocal()); -} - -#endif /* XF86VIDMODE */ diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c deleted file mode 100644 index 8cf3f62f0..000000000 --- a/hw/xfree86/common/xf86Xinput.c +++ /dev/null @@ -1,1671 +0,0 @@ -/* - * Copyright 1995-1999 by Frederic Lepied, France. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Frederic Lepied not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Frederic Lepied makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * Copyright (c) 2000-2002 by The XFree86 Project, 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, - * 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86Config.h" -#include "xf86Xinput.h" -#include "xf86Optrec.h" -#include "mipointer.h" -#include "extinit.h" -#include "loaderProcs.h" -#include "systemd-logind.h" - -#include "exevents.h" /* AddInputDevice */ -#include "exglobals.h" -#include "eventstr.h" -#include "inpututils.h" -#include "optionstr.h" - -#include /* InputClassMatches */ -#ifdef HAVE_FNMATCH_H -#include -#endif -#ifdef HAVE_SYS_UTSNAME_H -#include -#endif - -#include -#include /* for int64_t */ -#include -#include -#include -#ifdef HAVE_SYS_SYSMACROS_H -#include -#endif -#ifdef HAVE_SYS_MKDEV_H -#include /* for major() & minor() on Solaris */ -#endif - -#include "mi.h" - -#include /* dix pointer acceleration */ -#include - -#ifdef XFreeXDGA -#include "dgaproc.h" -#endif - -#include "xkbsrv.h" - -/* Valuator verification macro */ -#define XI_VERIFY_VALUATORS(num_valuators) \ - if (num_valuators > MAX_VALUATORS) { \ - xf86Msg(X_ERROR, "%s: num_valuator %d is greater than" \ - " MAX_VALUATORS\n", __FUNCTION__, num_valuators); \ - return; \ - } - -static int - xf86InputDevicePostInit(DeviceIntPtr dev); - -typedef struct { - struct xorg_list node; - InputInfoPtr pInfo; -} PausedInputDeviceRec; -typedef PausedInputDeviceRec *PausedInputDevicePtr; - -static struct xorg_list new_input_devices_list = { - .next = &new_input_devices_list, - .prev = &new_input_devices_list, -}; - -/** - * Eval config and modify DeviceVelocityRec accordingly - */ -static void -ProcessVelocityConfiguration(DeviceIntPtr pDev, const char *devname, void *list, - DeviceVelocityPtr s) -{ - int tempi; - float tempf; - Atom float_prop = XIGetKnownProperty(XATOM_FLOAT); - Atom prop; - - if (!s) - return; - - /* common settings (available via device properties) */ - tempf = xf86SetRealOption(list, "ConstantDeceleration", 1.0); - if (tempf != 1.0) { - xf86Msg(X_CONFIG, "%s: (accel) constant deceleration by %.1f\n", - devname, tempf); - prop = XIGetKnownProperty(ACCEL_PROP_CONSTANT_DECELERATION); - XIChangeDeviceProperty(pDev, prop, float_prop, 32, - PropModeReplace, 1, &tempf, FALSE); - } - - tempf = xf86SetRealOption(list, "AdaptiveDeceleration", 1.0); - if (tempf > 1.0) { - xf86Msg(X_CONFIG, "%s: (accel) adaptive deceleration by %.1f\n", - devname, tempf); - prop = XIGetKnownProperty(ACCEL_PROP_ADAPTIVE_DECELERATION); - XIChangeDeviceProperty(pDev, prop, float_prop, 32, - PropModeReplace, 1, &tempf, FALSE); - } - - /* select profile by number */ - tempi = xf86SetIntOption(list, "AccelerationProfile", - s->statistics.profile_number); - - prop = XIGetKnownProperty(ACCEL_PROP_PROFILE_NUMBER); - if (XIChangeDeviceProperty(pDev, prop, XA_INTEGER, 32, - PropModeReplace, 1, &tempi, FALSE) == Success) { - xf86Msg(X_CONFIG, "%s: (accel) acceleration profile %i\n", devname, - tempi); - } - else { - xf86Msg(X_CONFIG, "%s: (accel) acceleration profile %i is unknown\n", - devname, tempi); - } - - /* set scaling */ - tempf = xf86SetRealOption(list, "ExpectedRate", 0); - prop = XIGetKnownProperty(ACCEL_PROP_VELOCITY_SCALING); - if (tempf > 0) { - tempf = 1000.0 / tempf; - XIChangeDeviceProperty(pDev, prop, float_prop, 32, - PropModeReplace, 1, &tempf, FALSE); - } - else { - tempf = xf86SetRealOption(list, "VelocityScale", s->corr_mul); - XIChangeDeviceProperty(pDev, prop, float_prop, 32, - PropModeReplace, 1, &tempf, FALSE); - } - - tempi = xf86SetIntOption(list, "VelocityTrackerCount", -1); - if (tempi > 1) - InitTrackers(s, tempi); - - s->initial_range = xf86SetIntOption(list, "VelocityInitialRange", - s->initial_range); - - s->max_diff = xf86SetRealOption(list, "VelocityAbsDiff", s->max_diff); - - tempf = xf86SetRealOption(list, "VelocityRelDiff", -1); - if (tempf >= 0) { - xf86Msg(X_CONFIG, "%s: (accel) max rel. velocity difference: %.1f%%\n", - devname, tempf * 100.0); - s->max_rel_diff = tempf; - } - - /* Configure softening. If const deceleration is used, this is expected - * to provide better subpixel information so we enable - * softening by default only if ConstantDeceleration is not used - */ - s->use_softening = xf86SetBoolOption(list, "Softening", - s->const_acceleration == 1.0); - - s->average_accel = xf86SetBoolOption(list, "AccelerationProfileAveraging", - s->average_accel); - - s->reset_time = xf86SetIntOption(list, "VelocityReset", s->reset_time); -} - -static void -ApplyAccelerationSettings(DeviceIntPtr dev) -{ - int scheme, i; - DeviceVelocityPtr pVel; - InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; - char *schemeStr; - - if (dev->valuator && dev->ptrfeed) { - schemeStr = xf86SetStrOption(pInfo->options, "AccelerationScheme", ""); - - scheme = dev->valuator->accelScheme.number; - - if (!xf86NameCmp(schemeStr, "predictable")) - scheme = PtrAccelPredictable; - - if (!xf86NameCmp(schemeStr, "lightweight")) - scheme = PtrAccelLightweight; - - if (!xf86NameCmp(schemeStr, "none")) - scheme = PtrAccelNoOp; - - /* reinit scheme if needed */ - if (dev->valuator->accelScheme.number != scheme) { - if (dev->valuator->accelScheme.AccelCleanupProc) { - dev->valuator->accelScheme.AccelCleanupProc(dev); - } - - if (InitPointerAccelerationScheme(dev, scheme)) { - xf86Msg(X_CONFIG, "%s: (accel) selected scheme %s/%i\n", - pInfo->name, schemeStr, scheme); - } - else { - xf86Msg(X_CONFIG, "%s: (accel) could not init scheme %s\n", - pInfo->name, schemeStr); - scheme = dev->valuator->accelScheme.number; - } - } - else { - xf86Msg(X_CONFIG, "%s: (accel) keeping acceleration scheme %i\n", - pInfo->name, scheme); - } - - free(schemeStr); - - /* process special configuration */ - switch (scheme) { - case PtrAccelPredictable: - pVel = GetDevicePredictableAccelData(dev); - ProcessVelocityConfiguration(dev, pInfo->name, pInfo->options, - pVel); - break; - } - - i = xf86SetIntOption(pInfo->options, "AccelerationNumerator", - dev->ptrfeed->ctrl.num); - if (i >= 0) - dev->ptrfeed->ctrl.num = i; - - i = xf86SetIntOption(pInfo->options, "AccelerationDenominator", - dev->ptrfeed->ctrl.den); - if (i > 0) - dev->ptrfeed->ctrl.den = i; - - i = xf86SetIntOption(pInfo->options, "AccelerationThreshold", - dev->ptrfeed->ctrl.threshold); - if (i >= 0) - dev->ptrfeed->ctrl.threshold = i; - - xf86Msg(X_CONFIG, "%s: (accel) acceleration factor: %.3f\n", - pInfo->name, ((float) dev->ptrfeed->ctrl.num) / - ((float) dev->ptrfeed->ctrl.den)); - xf86Msg(X_CONFIG, "%s: (accel) acceleration threshold: %i\n", - pInfo->name, dev->ptrfeed->ctrl.threshold); - } -} - -static void -ApplyTransformationMatrix(DeviceIntPtr dev) -{ - InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; - char *str; - int rc; - float matrix[9] = { 0 }; - - if (!dev->valuator) - return; - - str = xf86SetStrOption(pInfo->options, "TransformationMatrix", NULL); - if (!str) - return; - - rc = sscanf(str, "%f %f %f %f %f %f %f %f %f", &matrix[0], &matrix[1], - &matrix[2], &matrix[3], &matrix[4], &matrix[5], &matrix[6], - &matrix[7], &matrix[8]); - if (rc != 9) { - xf86Msg(X_ERROR, - "%s: invalid format for transformation matrix. Ignoring configuration.\n", - pInfo->name); - return; - } - - XIChangeDeviceProperty(dev, XIGetKnownProperty(XI_PROP_TRANSFORM), - XIGetKnownProperty(XATOM_FLOAT), 32, - PropModeReplace, 9, matrix, FALSE); -} - -static void -ApplyAutoRepeat(DeviceIntPtr dev) -{ - InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; - XkbSrvInfoPtr xkbi; - char *repeatStr; - long delay, rate; - - if (!dev->key) - return; - - xkbi = dev->key->xkbInfo; - - repeatStr = xf86SetStrOption(pInfo->options, "AutoRepeat", NULL); - if (!repeatStr) - return; - - if (sscanf(repeatStr, "%ld %ld", &delay, &rate) != 2) { - xf86Msg(X_ERROR, "\"%s\" is not a valid AutoRepeat value\n", repeatStr); - return; - } - - xf86Msg(X_CONFIG, "AutoRepeat: %ld %ld\n", delay, rate); - xkbi->desc->ctrls->repeat_delay = delay; - xkbi->desc->ctrls->repeat_interval = rate; -} - -/*********************************************************************** - * - * xf86ProcessCommonOptions -- - * - * Process global options. - * - *********************************************************************** - */ -void -xf86ProcessCommonOptions(InputInfoPtr pInfo, XF86OptionPtr list) -{ - if (xf86SetBoolOption(list, "Floating", 0) || - !xf86SetBoolOption(list, "AlwaysCore", 1) || - !xf86SetBoolOption(list, "SendCoreEvents", 1) || - !xf86SetBoolOption(list, "CorePointer", 1) || - !xf86SetBoolOption(list, "CoreKeyboard", 1)) { - xf86Msg(X_CONFIG, "%s: doesn't report core events\n", pInfo->name); - } - else { - pInfo->flags |= XI86_ALWAYS_CORE; - xf86Msg(X_CONFIG, "%s: always reports core events\n", pInfo->name); - } -} - -/*********************************************************************** - * - * xf86ActivateDevice -- - * - * Initialize an input device. - * - * Returns TRUE on success, or FALSE otherwise. - *********************************************************************** - */ -static DeviceIntPtr -xf86ActivateDevice(InputInfoPtr pInfo) -{ - DeviceIntPtr dev; - Atom atom; - - dev = AddInputDevice(serverClient, pInfo->device_control, TRUE); - - if (dev == NULL) { - xf86Msg(X_ERROR, "Too many input devices. Ignoring %s\n", pInfo->name); - pInfo->dev = NULL; - return NULL; - } - - atom = MakeAtom(pInfo->type_name, strlen(pInfo->type_name), TRUE); - AssignTypeAndName(dev, atom, pInfo->name); - dev->public.devicePrivate = pInfo; - pInfo->dev = dev; - - dev->coreEvents = pInfo->flags & XI86_ALWAYS_CORE; - dev->type = SLAVE; - dev->spriteInfo->spriteOwner = FALSE; - - dev->config_info = xf86SetStrOption(pInfo->options, "config_info", NULL); - - if (serverGeneration == 1) - xf86Msg(X_INFO, - "XINPUT: Adding extended input device \"%s\" (type: %s, id %d)\n", - pInfo->name, pInfo->type_name, dev->id); - - return dev; -} - -/**************************************************************************** - * - * Caller: ProcXSetDeviceMode - * - * Change the mode of an extension device. - * This function is used to change the mode of a device from reporting - * relative motion to reporting absolute positional information, and - * vice versa. - * The default implementation below is that no such devices are supported. - * - *********************************************************************** - */ - -int -SetDeviceMode(ClientPtr client, DeviceIntPtr dev, int mode) -{ - InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; - - if (pInfo->switch_mode) { - return (*pInfo->switch_mode) (client, dev, mode); - } - else - return BadMatch; -} - -/*********************************************************************** - * - * Caller: ProcXSetDeviceValuators - * - * Set the value of valuators on an extension input device. - * This function is used to set the initial value of valuators on - * those input devices that are capable of reporting either relative - * motion or an absolute position, and allow an initial position to be set. - * The default implementation below is that no such devices are supported. - * - *********************************************************************** - */ - -int -SetDeviceValuators(ClientPtr client, DeviceIntPtr dev, int *valuators, - int first_valuator, int num_valuators) -{ - InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; - - if (pInfo->set_device_valuators) - return (*pInfo->set_device_valuators) (pInfo, valuators, first_valuator, - num_valuators); - - return BadMatch; -} - -/*********************************************************************** - * - * Caller: ProcXChangeDeviceControl - * - * Change the specified device controls on an extension input device. - * - *********************************************************************** - */ - -int -ChangeDeviceControl(ClientPtr client, DeviceIntPtr dev, xDeviceCtl * control) -{ - InputInfoPtr pInfo = (InputInfoPtr) dev->public.devicePrivate; - - if (!pInfo->control_proc) { - switch (control->control) { - case DEVICE_CORE: - case DEVICE_ABS_CALIB: - case DEVICE_ABS_AREA: - return BadMatch; - case DEVICE_RESOLUTION: - case DEVICE_ENABLE: - return Success; - default: - return BadMatch; - } - } - else { - return (*pInfo->control_proc) (pInfo, control); - } -} - -/* - * Get the operating system name from uname and store it statically to avoid - * repeating the system call each time MatchOS is checked. - */ -static const char * -HostOS(void) -{ -#ifdef HAVE_SYS_UTSNAME_H - struct utsname name; - static char host_os[sizeof(name.sysname)] = ""; - - if (*host_os == '\0') { - if (uname(&name) >= 0) - strlcpy(host_os, name.sysname, sizeof(host_os)); - else { - strlcpy(host_os, "unknown", sizeof(host_os)); - } - } - return host_os; -#else - return ""; -#endif -} - -static int -match_substring(const char *attr, const char *pattern) -{ - return (strstr(attr, pattern)) ? 0 : -1; -} - -#ifdef HAVE_FNMATCH_H -static int -match_pattern(const char *attr, const char *pattern) -{ - return fnmatch(pattern, attr, 0); -} -#else -#define match_pattern match_substring -#endif - -#ifdef HAVE_FNMATCH_H -static int -match_path_pattern(const char *attr, const char *pattern) -{ - return fnmatch(pattern, attr, FNM_PATHNAME); -} -#else -#define match_path_pattern match_substring -#endif - -/* - * If no Layout section is found, xf86ServerLayout.id becomes "(implicit)" - * It is convenient that "" in patterns means "no explicit layout" - */ -static int -match_string_implicit(const char *attr, const char *pattern) -{ - if (strlen(pattern)) { - return strcmp(attr, pattern); - } - else { - return strcmp(attr, "(implicit)"); - } -} - -/* - * Match an attribute against a list of NULL terminated arrays of patterns. - * If a pattern in each list entry is matched, return TRUE. - */ -static Bool -MatchAttrToken(const char *attr, struct xorg_list *patterns, - int (*compare) (const char *attr, const char *pattern)) -{ - const xf86MatchGroup *group; - - /* If there are no patterns, accept the match */ - if (xorg_list_is_empty(patterns)) - return TRUE; - - /* - * Iterate the list of patterns ensuring each entry has a - * match. Each list entry is a separate Match line of the same type. - */ - xorg_list_for_each_entry(group, patterns, entry) { - char *const *cur; - Bool is_negated = group->is_negated; - Bool match = is_negated; - - /* If there's a pattern but no attribute, we reject the match for a - * MatchFoo directive, and accept it for a NoMatchFoo directive - */ - if (!attr) - return is_negated; - - for (cur = group->values; *cur; cur++) - if ((*compare) (attr, *cur) == 0) { - match = !is_negated; - break; - } - if (!match) - return FALSE; - } - - /* All the entries in the list matched the attribute */ - return TRUE; -} - -/* - * Classes without any Match statements match all devices. Otherwise, all - * statements must match. - */ -static Bool -InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev, - const InputAttributes * attrs) -{ - /* MatchProduct substring */ - if (!MatchAttrToken - (attrs->product, &iclass->match_product, match_substring)) - return FALSE; - - /* MatchVendor substring */ - if (!MatchAttrToken(attrs->vendor, &iclass->match_vendor, match_substring)) - return FALSE; - - /* MatchDevicePath pattern */ - if (!MatchAttrToken - (attrs->device, &iclass->match_device, match_path_pattern)) - return FALSE; - - /* MatchOS case-insensitive string */ - if (!MatchAttrToken(HostOS(), &iclass->match_os, strcasecmp)) - return FALSE; - - /* MatchPnPID pattern */ - if (!MatchAttrToken(attrs->pnp_id, &iclass->match_pnpid, match_pattern)) - return FALSE; - - /* MatchUSBID pattern */ - if (!MatchAttrToken(attrs->usb_id, &iclass->match_usbid, match_pattern)) - return FALSE; - - /* MatchDriver string */ - if (!MatchAttrToken(idev->driver, &iclass->match_driver, strcmp)) - return FALSE; - - /* - * MatchTag string - * See if any of the device's tags match any of the MatchTag tokens. - */ - if (!xorg_list_is_empty(&iclass->match_tag)) { - char *const *tag; - Bool match; - - if (!attrs->tags) - return FALSE; - for (tag = attrs->tags, match = FALSE; *tag; tag++) { - if (MatchAttrToken(*tag, &iclass->match_tag, strcmp)) { - match = TRUE; - break; - } - } - if (!match) - return FALSE; - } - - /* MatchLayout string */ - if (!xorg_list_is_empty(&iclass->match_layout)) { - if (!MatchAttrToken(xf86ConfigLayout.id, - &iclass->match_layout, match_string_implicit)) - return FALSE; - } - - /* MatchIs* booleans */ - if (iclass->is_keyboard.set && - iclass->is_keyboard.val != ! !(attrs->flags & (ATTR_KEY|ATTR_KEYBOARD))) - return FALSE; - if (iclass->is_pointer.set && - iclass->is_pointer.val != ! !(attrs->flags & ATTR_POINTER)) - return FALSE; - if (iclass->is_joystick.set && - iclass->is_joystick.val != ! !(attrs->flags & ATTR_JOYSTICK)) - return FALSE; - if (iclass->is_tablet.set && - iclass->is_tablet.val != ! !(attrs->flags & ATTR_TABLET)) - return FALSE; - if (iclass->is_tablet_pad.set && - iclass->is_tablet_pad.val != ! !(attrs->flags & ATTR_TABLET_PAD)) - return FALSE; - if (iclass->is_touchpad.set && - iclass->is_touchpad.val != ! !(attrs->flags & ATTR_TOUCHPAD)) - return FALSE; - if (iclass->is_touchscreen.set && - iclass->is_touchscreen.val != ! !(attrs->flags & ATTR_TOUCHSCREEN)) - return FALSE; - - return TRUE; -} - -/* - * Merge in any InputClass configurations. Options in each InputClass - * section have more priority than the original device configuration as - * well as any previous InputClass sections. - */ -static int -MergeInputClasses(const InputInfoPtr idev, const InputAttributes * attrs) -{ - XF86ConfInputClassPtr cl; - XF86OptionPtr classopts; - - for (cl = xf86configptr->conf_inputclass_lst; cl; cl = cl->list.next) { - if (!InputClassMatches(cl, idev, attrs)) - continue; - - /* Collect class options and driver settings */ - classopts = xf86optionListDup(cl->option_lst); - if (cl->driver) { - free((void *) idev->driver); - idev->driver = xstrdup(cl->driver); - if (!idev->driver) { - xf86Msg(X_ERROR, "Failed to allocate memory while merging " - "InputClass configuration"); - return BadAlloc; - } - classopts = xf86ReplaceStrOption(classopts, "driver", idev->driver); - } - - /* Apply options to device with InputClass settings preferred. */ - xf86Msg(X_CONFIG, "%s: Applying InputClass \"%s\"\n", - idev->name, cl->identifier); - idev->options = xf86optionListMerge(idev->options, classopts); - } - - return Success; -} - -/* - * Iterate the list of classes and look for Option "Ignore". Return the - * value of the last matching class and holler when returning TRUE. - */ -static Bool -IgnoreInputClass(const InputInfoPtr idev, const InputAttributes * attrs) -{ - XF86ConfInputClassPtr cl; - Bool ignore = FALSE; - const char *ignore_class; - - for (cl = xf86configptr->conf_inputclass_lst; cl; cl = cl->list.next) { - if (!InputClassMatches(cl, idev, attrs)) - continue; - if (xf86findOption(cl->option_lst, "Ignore")) { - ignore = xf86CheckBoolOption(cl->option_lst, "Ignore", FALSE); - ignore_class = cl->identifier; - } - } - - if (ignore) - xf86Msg(X_CONFIG, "%s: Ignoring device from InputClass \"%s\"\n", - idev->name, ignore_class); - return ignore; -} - -InputInfoPtr -xf86AllocateInput(void) -{ - InputInfoPtr pInfo; - - pInfo = calloc(sizeof(*pInfo), 1); - if (!pInfo) - return NULL; - - pInfo->fd = -1; - pInfo->type_name = "UNKNOWN"; - - return pInfo; -} - -/* Append InputInfoRec to the tail of xf86InputDevs. */ -static void -xf86AddInput(InputDriverPtr drv, InputInfoPtr pInfo) -{ - InputInfoPtr *prev = NULL; - - pInfo->drv = drv; - pInfo->module = DuplicateModule(drv->module, NULL); - - for (prev = &xf86InputDevs; *prev; prev = &(*prev)->next); - - *prev = pInfo; - pInfo->next = NULL; - - xf86CollectInputOptions(pInfo, (const char **) drv->default_options); - xf86OptionListReport(pInfo->options); - xf86ProcessCommonOptions(pInfo, pInfo->options); -} - -/* - * Remove an entry from xf86InputDevs and free all the device's information. - */ -void -xf86DeleteInput(InputInfoPtr pInp, int flags) -{ - /* First check if the inputdev is valid. */ - if (pInp == NULL) - return; - - if (pInp->module) - UnloadModule(pInp->module); - - /* This should *really* be handled in drv->UnInit(dev) call instead, but - * if the driver forgets about it make sure we free it or at least crash - * with flying colors */ - free(pInp->private); - - FreeInputAttributes(pInp->attrs); - - if (pInp->flags & XI86_SERVER_FD) - systemd_logind_release_fd(pInp->major, pInp->minor, pInp->fd); - - /* Remove the entry from the list. */ - if (pInp == xf86InputDevs) - xf86InputDevs = pInp->next; - else { - InputInfoPtr p = xf86InputDevs; - - while (p && p->next != pInp) - p = p->next; - if (p) - p->next = pInp->next; - /* Else the entry wasn't in the xf86InputDevs list (ignore this). */ - } - - free((void *) pInp->driver); - free((void *) pInp->name); - xf86optionListFree(pInp->options); - free(pInp); -} - -/* - * Apply backend-specific initialization. Invoked after ActivateDevice(), - * i.e. after the driver successfully completed DEVICE_INIT and the device - * is advertised. - * @param dev the device - * @return Success or an error code - */ -static int -xf86InputDevicePostInit(DeviceIntPtr dev) -{ - ApplyAccelerationSettings(dev); - ApplyTransformationMatrix(dev); - ApplyAutoRepeat(dev); - return Success; -} - -static void -xf86stat(const char *path, int *maj, int *min) -{ - struct stat st; - - if (stat(path, &st) == -1) - return; - - *maj = major(st.st_rdev); - *min = minor(st.st_rdev); -} - -static inline InputDriverPtr -xf86LoadInputDriver(const char *driver_name) -{ - InputDriverPtr drv = NULL; - - /* Memory leak for every attached device if we don't - * test if the module is already loaded first */ - drv = xf86LookupInputDriver(driver_name); - if (!drv) { - if (xf86LoadOneModule(driver_name, NULL)) - drv = xf86LookupInputDriver(driver_name); - } - - return drv; -} - -/** - * Create a new input device, activate and enable it. - * - * Possible return codes: - * BadName .. a bad driver name was supplied. - * BadImplementation ... The driver does not have a PreInit function. This - * is a driver bug. - * BadMatch .. device initialization failed. - * BadAlloc .. too many input devices - * - * @param idev The device, already set up with identifier, driver, and the - * options. - * @param pdev Pointer to the new device, if Success was reported. - * @param enable Enable the device after activating it. - * - * @return Success or an error code - */ -_X_INTERNAL int -xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable) -{ - InputDriverPtr drv = NULL; - DeviceIntPtr dev = NULL; - Bool paused = FALSE; - int rval; - char *path = NULL; - - drv = xf86LoadInputDriver(pInfo->driver); - if (!drv) { - xf86Msg(X_ERROR, "No input driver matching `%s'\n", pInfo->driver); - - if (strlen(FALLBACK_INPUT_DRIVER) > 0) { - xf86Msg(X_INFO, "Falling back to input driver `%s'\n", - FALLBACK_INPUT_DRIVER); - drv = xf86LoadInputDriver(FALLBACK_INPUT_DRIVER); - if (drv) { - free(pInfo->driver); - pInfo->driver = strdup(FALLBACK_INPUT_DRIVER); - } - } - if (!drv) { - rval = BadName; - goto unwind; - } - } - - xf86Msg(X_INFO, "Using input driver '%s' for '%s'\n", drv->driverName, - pInfo->name); - - if (!drv->PreInit) { - xf86Msg(X_ERROR, - "Input driver `%s' has no PreInit function (ignoring)\n", - drv->driverName); - rval = BadImplementation; - goto unwind; - } - - path = xf86CheckStrOption(pInfo->options, "Device", NULL); - if (path && pInfo->major == 0 && pInfo->minor == 0) - xf86stat(path, &pInfo->major, &pInfo->minor); - - if (path && (drv->capabilities & XI86_DRV_CAP_SERVER_FD)){ - int fd = systemd_logind_take_fd(pInfo->major, pInfo->minor, - path, &paused); - if (fd != -1) { - if (paused) { - /* Put on new_input_devices list for delayed probe */ - PausedInputDevicePtr new_device = xnfalloc(sizeof *new_device); - new_device->pInfo = pInfo; - - xorg_list_append(&new_device->node, &new_input_devices_list); - systemd_logind_release_fd(pInfo->major, pInfo->minor, fd); - free(path); - return BadMatch; - } - pInfo->fd = fd; - pInfo->flags |= XI86_SERVER_FD; - pInfo->options = xf86ReplaceIntOption(pInfo->options, "fd", fd); - } - } - - free(path); - - xf86AddInput(drv, pInfo); - - input_lock(); - rval = drv->PreInit(drv, pInfo, 0); - input_unlock(); - - if (rval != Success) { - xf86Msg(X_ERROR, "PreInit returned %d for \"%s\"\n", rval, pInfo->name); - goto unwind; - } - - if (!(dev = xf86ActivateDevice(pInfo))) { - rval = BadAlloc; - goto unwind; - } - - rval = ActivateDevice(dev, TRUE); - if (rval != Success) { - xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", pInfo->name); - RemoveDevice(dev, TRUE); - goto unwind; - } - - rval = xf86InputDevicePostInit(dev); - if (rval != Success) { - xf86Msg(X_ERROR, "Couldn't post-init device \"%s\"\n", pInfo->name); - RemoveDevice(dev, TRUE); - goto unwind; - } - - /* Enable it if it's properly initialised and we're currently in the VT */ - if (enable && dev->inited && dev->startup && xf86VTOwner()) { - input_lock(); - EnableDevice(dev, TRUE); - if (!dev->enabled) { - xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", pInfo->name); - RemoveDevice(dev, TRUE); - rval = BadMatch; - input_unlock(); - goto unwind; - } - /* send enter/leave event, update sprite window */ - CheckMotion(NULL, dev); - input_unlock(); - } - - *pdev = dev; - return Success; - - unwind: - if (pInfo) { - if (drv && drv->UnInit) - drv->UnInit(drv, pInfo, 0); - else - xf86DeleteInput(pInfo, 0); - } - return rval; -} - -int -NewInputDeviceRequest(InputOption *options, InputAttributes * attrs, - DeviceIntPtr *pdev) -{ - InputInfoPtr pInfo = NULL; - InputOption *option = NULL; - int rval = Success; - int is_auto = 0; - - pInfo = xf86AllocateInput(); - if (!pInfo) - return BadAlloc; - - nt_list_for_each_entry(option, options, list.next) { - const char *key = input_option_get_key(option); - const char *value = input_option_get_value(option); - - if (strcasecmp(key, "driver") == 0) { - if (pInfo->driver) { - rval = BadRequest; - goto unwind; - } - pInfo->driver = xstrdup(value); - if (!pInfo->driver) { - rval = BadAlloc; - goto unwind; - } - } - - if (strcasecmp(key, "name") == 0 || strcasecmp(key, "identifier") == 0) { - if (pInfo->name) { - rval = BadRequest; - goto unwind; - } - pInfo->name = xstrdup(value); - if (!pInfo->name) { - rval = BadAlloc; - goto unwind; - } - } - - if (strcmp(key, "_source") == 0 && - (strcmp(value, "server/hal") == 0 || - strcmp(value, "server/udev") == 0 || - strcmp(value, "server/wscons") == 0)) { - is_auto = 1; - if (!xf86Info.autoAddDevices) { - rval = BadMatch; - goto unwind; - } - } - - if (strcmp(key, "major") == 0) - pInfo->major = atoi(value); - - if (strcmp(key, "minor") == 0) - pInfo->minor = atoi(value); - } - - nt_list_for_each_entry(option, options, list.next) { - /* Copy option key/value strings from the provided list */ - pInfo->options = xf86AddNewOption(pInfo->options, - input_option_get_key(option), - input_option_get_value(option)); - } - - /* Apply InputClass settings */ - if (attrs) { - if (IgnoreInputClass(pInfo, attrs)) { - rval = BadIDChoice; - goto unwind; - } - - rval = MergeInputClasses(pInfo, attrs); - if (rval != Success) - goto unwind; - - pInfo->attrs = DuplicateInputAttributes(attrs); - } - - if (!pInfo->name) { - xf86Msg(X_INFO, "No identifier specified, ignoring this device.\n"); - rval = BadRequest; - goto unwind; - } - - if (!pInfo->driver) { - xf86Msg(X_INFO, "No input driver specified, ignoring this device.\n"); - xf86Msg(X_INFO, - "This device may have been added with another device file.\n"); - rval = BadRequest; - goto unwind; - } - - rval = xf86NewInputDevice(pInfo, pdev, - (!is_auto || - (is_auto && xf86Info.autoEnableDevices))); - - return rval; - - unwind: - if (is_auto && !xf86Info.autoAddDevices) - xf86Msg(X_INFO, "AutoAddDevices is off - not adding device.\n"); - xf86DeleteInput(pInfo, 0); - return rval; -} - -void -DeleteInputDeviceRequest(DeviceIntPtr pDev) -{ - InputInfoPtr pInfo = (InputInfoPtr) pDev->public.devicePrivate; - InputDriverPtr drv = NULL; - Bool isMaster = IsMaster(pDev); - - if (pInfo) /* need to get these before RemoveDevice */ - drv = pInfo->drv; - - input_lock(); - RemoveDevice(pDev, TRUE); - - if (!isMaster && pInfo != NULL) { - if (drv->UnInit) - drv->UnInit(drv, pInfo, 0); - else - xf86DeleteInput(pInfo, 0); - } - input_unlock(); -} - -void -RemoveInputDeviceTraces(const char *config_info) -{ - PausedInputDevicePtr d, tmp; - - xorg_list_for_each_entry_safe(d, tmp, &new_input_devices_list, node) { - const char *ci = xf86findOptionValue(d->pInfo->options, "config_info"); - if (!ci || strcmp(ci, config_info) != 0) - continue; - - xorg_list_del(&d->node); - free(d); - } -} - -/* - * convenient functions to post events - */ - -void -xf86PostMotionEvent(DeviceIntPtr device, - int is_absolute, int first_valuator, int num_valuators, ...) -{ - va_list var; - int i = 0; - ValuatorMask mask; - - XI_VERIFY_VALUATORS(num_valuators); - - valuator_mask_zero(&mask); - va_start(var, num_valuators); - for (i = 0; i < num_valuators; i++) - valuator_mask_set(&mask, first_valuator + i, va_arg(var, int)); - - va_end(var); - - xf86PostMotionEventM(device, is_absolute, &mask); -} - -void -xf86PostMotionEventP(DeviceIntPtr device, - int is_absolute, - int first_valuator, - int num_valuators, const int *valuators) -{ - ValuatorMask mask; - - XI_VERIFY_VALUATORS(num_valuators); - - valuator_mask_set_range(&mask, first_valuator, num_valuators, valuators); - xf86PostMotionEventM(device, is_absolute, &mask); -} - -static int -xf86CheckMotionEvent4DGA(DeviceIntPtr device, int is_absolute, - const ValuatorMask *mask) -{ - int stolen = 0; - -#ifdef XFreeXDGA - ScreenPtr scr = NULL; - int idx = 0, i; - - /* The evdev driver may not always send all axes across. */ - if (valuator_mask_isset(mask, 0) || valuator_mask_isset(mask, 1)) { - scr = miPointerGetScreen(device); - if (scr) { - int dx = 0, dy = 0; - - idx = scr->myNum; - - if (valuator_mask_isset(mask, 0)) { - dx = valuator_mask_get(mask, 0); - if (is_absolute) - dx -= device->last.valuators[0]; - else if (valuator_mask_has_unaccelerated(mask)) - dx = valuator_mask_get_unaccelerated(mask, 0); - } - - if (valuator_mask_isset(mask, 1)) { - dy = valuator_mask_get(mask, 1); - if (is_absolute) - dy -= device->last.valuators[1]; - else if (valuator_mask_has_unaccelerated(mask)) - dy = valuator_mask_get_unaccelerated(mask, 1); - } - - if (DGAStealMotionEvent(device, idx, dx, dy)) - stolen = 1; - } - } - - for (i = 2; i < valuator_mask_size(mask); i++) { - AxisInfoPtr ax; - double incr; - int val, button; - - if (i >= device->valuator->numAxes) - break; - - if (!valuator_mask_isset(mask, i)) - continue; - - ax = &device->valuator->axes[i]; - - if (ax->scroll.type == SCROLL_TYPE_NONE) - continue; - - if (!scr) { - scr = miPointerGetScreen(device); - if (!scr) - break; - idx = scr->myNum; - } - - incr = ax->scroll.increment; - val = valuator_mask_get(mask, i); - - if (ax->scroll.type == SCROLL_TYPE_VERTICAL) { - if (incr * val < 0) - button = 4; /* up */ - else - button = 5; /* down */ - } else { /* SCROLL_TYPE_HORIZONTAL */ - if (incr * val < 0) - button = 6; /* left */ - else - button = 7; /* right */ - } - - if (DGAStealButtonEvent(device, idx, button, 1) && - DGAStealButtonEvent(device, idx, button, 0)) - stolen = 1; - } - -#endif - - return stolen; -} - -void -xf86PostMotionEventM(DeviceIntPtr device, - int is_absolute, const ValuatorMask *mask) -{ - int flags = 0; - - if (xf86CheckMotionEvent4DGA(device, is_absolute, mask)) - return; - - if (valuator_mask_num_valuators(mask) > 0) { - if (is_absolute) - flags = POINTER_ABSOLUTE; - else - flags = POINTER_RELATIVE | POINTER_ACCELERATE; - } - - QueuePointerEvents(device, MotionNotify, 0, flags, mask); -} - -void -xf86PostProximityEvent(DeviceIntPtr device, - int is_in, int first_valuator, int num_valuators, ...) -{ - va_list var; - int i; - ValuatorMask mask; - - XI_VERIFY_VALUATORS(num_valuators); - - valuator_mask_zero(&mask); - va_start(var, num_valuators); - for (i = 0; i < num_valuators; i++) - valuator_mask_set(&mask, first_valuator + i, va_arg(var, int)); - - va_end(var); - - xf86PostProximityEventM(device, is_in, &mask); -} - -void -xf86PostProximityEventP(DeviceIntPtr device, - int is_in, - int first_valuator, - int num_valuators, const int *valuators) -{ - ValuatorMask mask; - - XI_VERIFY_VALUATORS(num_valuators); - - valuator_mask_set_range(&mask, first_valuator, num_valuators, valuators); - xf86PostProximityEventM(device, is_in, &mask); -} - -void -xf86PostProximityEventM(DeviceIntPtr device, - int is_in, const ValuatorMask *mask) -{ - QueueProximityEvents(device, is_in ? ProximityIn : ProximityOut, mask); -} - -void -xf86PostButtonEvent(DeviceIntPtr device, - int is_absolute, - int button, - int is_down, int first_valuator, int num_valuators, ...) -{ - va_list var; - ValuatorMask mask; - int i = 0; - - XI_VERIFY_VALUATORS(num_valuators); - - valuator_mask_zero(&mask); - - va_start(var, num_valuators); - for (i = 0; i < num_valuators; i++) - valuator_mask_set(&mask, first_valuator + i, va_arg(var, int)); - - va_end(var); - - xf86PostButtonEventM(device, is_absolute, button, is_down, &mask); -} - -void -xf86PostButtonEventP(DeviceIntPtr device, - int is_absolute, - int button, - int is_down, - int first_valuator, - int num_valuators, const int *valuators) -{ - ValuatorMask mask; - - XI_VERIFY_VALUATORS(num_valuators); - - valuator_mask_set_range(&mask, first_valuator, num_valuators, valuators); - xf86PostButtonEventM(device, is_absolute, button, is_down, &mask); -} - -void -xf86PostButtonEventM(DeviceIntPtr device, - int is_absolute, - int button, int is_down, const ValuatorMask *mask) -{ - int flags = 0; - - if (valuator_mask_num_valuators(mask) > 0) { - if (is_absolute) - flags = POINTER_ABSOLUTE; - else - flags = POINTER_RELATIVE | POINTER_ACCELERATE; - } - -#ifdef XFreeXDGA - if (miPointerGetScreen(device)) { - int index = miPointerGetScreen(device)->myNum; - - if (DGAStealButtonEvent(device, index, button, is_down)) - return; - } -#endif - - QueuePointerEvents(device, - is_down ? ButtonPress : ButtonRelease, button, - flags, mask); -} - -void -xf86PostKeyEvent(DeviceIntPtr device, unsigned int key_code, int is_down) -{ - xf86PostKeyEventM(device, key_code, is_down); -} - -void -xf86PostKeyEventP(DeviceIntPtr device, - unsigned int key_code, - int is_down) -{ - xf86PostKeyEventM(device, key_code, is_down); -} - -void -xf86PostKeyEventM(DeviceIntPtr device, unsigned int key_code, int is_down) -{ -#ifdef XFreeXDGA - DeviceIntPtr pointer; - - /* Some pointers send key events, paired device is wrong then. */ - pointer = GetMaster(device, POINTER_OR_FLOAT); - - if (miPointerGetScreen(pointer)) { - int index = miPointerGetScreen(pointer)->myNum; - - if (DGAStealKeyEvent(device, index, key_code, is_down)) - return; - } -#endif - - QueueKeyboardEvents(device, is_down ? KeyPress : KeyRelease, key_code); -} - -void -xf86PostKeyboardEvent(DeviceIntPtr device, unsigned int key_code, int is_down) -{ - ValuatorMask mask; - - valuator_mask_zero(&mask); - xf86PostKeyEventM(device, key_code, is_down); -} - -InputInfoPtr -xf86FirstLocalDevice(void) -{ - return xf86InputDevs; -} - -/* - * Cx - raw data from touch screen - * to_max - scaled highest dimension - * (remember, this is of rows - 1 because of 0 origin) - * to_min - scaled lowest dimension - * from_max - highest raw value from touch screen calibration - * from_min - lowest raw value from touch screen calibration - * - * This function is the same for X or Y coordinates. - * You may have to reverse the high and low values to compensate for - * different origins on the touch screen vs X. - * - * e.g. to scale from device coordinates into screen coordinates, call - * xf86ScaleAxis(x, 0, screen_width, dev_min, dev_max); - */ - -int -xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, int from_min) -{ - int X; - int64_t to_width = to_max - to_min; - int64_t from_width = from_max - from_min; - - if (from_width) { - X = (int) (((to_width * (Cx - from_min)) / from_width) + to_min); - } - else { - X = 0; - ErrorF("Divide by Zero in xf86ScaleAxis\n"); - } - - if (X > to_max) - X = to_max; - if (X < to_min) - X = to_min; - - return X; -} - -Bool -xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, Atom label, int minval, - int maxval, int resolution, int min_res, int max_res, - int mode) -{ - if (!dev || !dev->valuator) - return FALSE; - - return InitValuatorAxisStruct(dev, axnum, label, minval, maxval, resolution, - min_res, max_res, mode); -} - -/* - * Set the valuator values to be in sync with dix/event.c - * DefineInitialRootWindow(). - */ -void -xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum) -{ - if (axnum == 0) { - dev->valuator->axisVal[0] = screenInfo.screens[0]->width / 2; - dev->last.valuators[0] = dev->valuator->axisVal[0]; - } - else if (axnum == 1) { - dev->valuator->axisVal[1] = screenInfo.screens[0]->height / 2; - dev->last.valuators[1] = dev->valuator->axisVal[1]; - } -} - -/** - * Deactivate a device. Call this function from the driver if you receive a - * read error or something else that spoils your day. - * Device will be moved to the off_devices list, but it will still be there - * until you really clean up after it. - * Notifies the client about an inactive device. - * - * @param panic True if device is unrecoverable and needs to be removed. - */ -void -xf86DisableDevice(DeviceIntPtr dev, Bool panic) -{ - if (!panic) { - DisableDevice(dev, TRUE); - } - else { - SendDevicePresenceEvent(dev->id, DeviceUnrecoverable); - DeleteInputDeviceRequest(dev); - } -} - -/** - * Reactivate a device. Call this function from the driver if you just found - * out that the read error wasn't quite that bad after all. - * Device will be re-activated, and an event sent to the client. - */ -void -xf86EnableDevice(DeviceIntPtr dev) -{ - EnableDevice(dev, TRUE); -} - -/** - * Post a touch event with optional valuators. If this is the first touch in - * the sequence, at least x & y valuators must be provided. The driver is - * responsible for maintaining the correct event sequence (TouchBegin, TouchUpdate, - * TouchEnd). Submitting an update or end event for a unregistered touchid will - * result in errors. - * Touch IDs may be reused by the driver but only after a TouchEnd has been - * submitted for that touch ID. - * - * @param dev The device to post the event for - * @param touchid The touchid of the current touch event. Must be an - * existing ID for TouchUpdate or TouchEnd events - * @param type One of XI_TouchBegin, XI_TouchUpdate, XI_TouchEnd - * @param flags Flags for this event - * @param The valuator mask with all valuators set for this event. - */ -void -xf86PostTouchEvent(DeviceIntPtr dev, uint32_t touchid, uint16_t type, - uint32_t flags, const ValuatorMask *mask) -{ - - QueueTouchEvents(dev, type, touchid, flags, mask); -} - -/** - * Post a gesture pinch event. The driver is responsible for maintaining the - * correct event sequence (GesturePinchBegin, GesturePinchUpdate, - * GesturePinchEnd). - * - * @param dev The device to post the event for - * @param type One of XI_GesturePinchBegin, XI_GesturePinchUpdate, - * XI_GesturePinchEnd - * @param num_touches The number of touches in the gesture - * @param flags Flags for this event - * @param delta_x,delta_y accelerated relative motion delta - * @param delta_unaccel_x,delta_unaccel_y unaccelerated relative motion delta - * @param scale absolute scale of a pinch gesture - * @param delta_angle the ange delta in degrees between the last and the current pinch event. - */ -void -xf86PostGesturePinchEvent(DeviceIntPtr dev, uint16_t type, - uint16_t num_touches, uint32_t flags, - double delta_x, double delta_y, - double delta_unaccel_x, - double delta_unaccel_y, - double scale, double delta_angle) -{ - QueueGesturePinchEvents(dev, type, num_touches, flags, delta_x, delta_y, - delta_unaccel_x, delta_unaccel_y, - scale, delta_angle); -} - -/** - * Post a gesture swipe event. The driver is responsible for maintaining the - * correct event sequence (GestureSwipeBegin, GestureSwipeUpdate, - * GestureSwipeEnd). - * - * @param dev The device to post the event for - * @param type One of XI_GestureSwipeBegin, XI_GestureSwipeUpdate, - * XI_GestureSwipeEnd - * @param num_touches The number of touches in the gesture - * @param flags Flags for this event - * @param delta_x,delta_y accelerated relative motion delta - * @param delta_unaccel_x,delta_unaccel_y unaccelerated relative motion delta - */ -void -xf86PostGestureSwipeEvent(DeviceIntPtr dev, uint16_t type, - uint16_t num_touches, uint32_t flags, - double delta_x, double delta_y, - double delta_unaccel_x, - double delta_unaccel_y) -{ - QueueGestureSwipeEvents(dev, type, num_touches, flags, delta_x, delta_y, - delta_unaccel_x, delta_unaccel_y); -} - -void -xf86InputEnableVTProbe(void) -{ - int is_auto = 0; - DeviceIntPtr pdev; - PausedInputDevicePtr d, tmp; - - xorg_list_for_each_entry_safe(d, tmp, &new_input_devices_list, node) { - InputInfoPtr pInfo = d->pInfo; - const char *value = xf86findOptionValue(pInfo->options, "_source"); - - is_auto = 0; - if (value && - (strcmp(value, "server/hal") == 0 || - strcmp(value, "server/udev") == 0 || - strcmp(value, "server/wscons") == 0)) - is_auto = 1; - - xf86NewInputDevice(pInfo, &pdev, - (!is_auto || - (is_auto && xf86Info.autoEnableDevices))); - xorg_list_del(&d->node); - free(d); - } -} - -/* end of xf86Xinput.c */ diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h deleted file mode 100644 index e73aff269..000000000 --- a/hw/xfree86/common/xf86Xinput.h +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 1995-1999 by Frederic Lepied, France. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Frederic Lepied not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Frederic Lepied makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL FREDERIC LEPIED BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ - -/* - * Copyright (c) 2000-2002 by The XFree86 Project, 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). - */ - -#ifndef _xf86Xinput_h -#define _xf86Xinput_h - -#include "xf86.h" -#include "xf86str.h" -#include "inputstr.h" -#include -#include -#include "XIstubs.h" - -/* Input device flags */ -#define XI86_ALWAYS_CORE 0x04 /* device always controls the pointer */ -/* the device sends Xinput and core pointer events */ -#define XI86_SEND_CORE_EVENTS XI86_ALWAYS_CORE -/* 0x08 is reserved for legacy XI86_SEND_DRAG_EVENTS, do not use for now */ -/* server-internal only */ -#define XI86_DEVICE_DISABLED 0x10 /* device was disabled before vt switch */ -#define XI86_SERVER_FD 0x20 /* fd is managed by xserver */ - -/* Input device driver capabilities */ -#define XI86_DRV_CAP_SERVER_FD 0x01 - -/* This holds the input driver entry and module information. */ -typedef struct _InputDriverRec { - int driverVersion; - const char *driverName; - void (*Identify) (int flags); - int (*PreInit) (struct _InputDriverRec * drv, - struct _InputInfoRec * pInfo, int flags); - void (*UnInit) (struct _InputDriverRec * drv, - struct _InputInfoRec * pInfo, int flags); - void *module; - const char **default_options; - int capabilities; -} InputDriverRec, *InputDriverPtr; - -/* This is to input devices what the ScrnInfoRec is to screens. */ - -struct _InputInfoRec { - struct _InputInfoRec *next; - char *name; - char *driver; - - int flags; - - Bool (*device_control) (DeviceIntPtr device, int what); - void (*read_input) (struct _InputInfoRec * local); - int (*control_proc) (struct _InputInfoRec * local, xDeviceCtl * control); - int (*switch_mode) (ClientPtr client, DeviceIntPtr dev, int mode); - int (*set_device_valuators) - (struct _InputInfoRec * local, - int *valuators, int first_valuator, int num_valuators); - - int fd; - int major; - int minor; - DeviceIntPtr dev; - void *private; - const char *type_name; - InputDriverPtr drv; - void *module; - XF86OptionPtr options; - InputAttributes *attrs; -}; - -/* xf86Globals.c */ -extern InputInfoPtr xf86InputDevs; - -/* xf86Xinput.c */ -extern _X_EXPORT void xf86PostMotionEvent(DeviceIntPtr device, int is_absolute, - int first_valuator, int num_valuators, - ...); -extern _X_EXPORT void xf86PostMotionEventP(DeviceIntPtr device, int is_absolute, - int first_valuator, - int num_valuators, - const int *valuators); -extern _X_EXPORT void xf86PostMotionEventM(DeviceIntPtr device, int is_absolute, - const ValuatorMask *mask); -extern _X_EXPORT void xf86PostProximityEvent(DeviceIntPtr device, int is_in, - int first_valuator, - int num_valuators, ...); -extern _X_EXPORT void xf86PostProximityEventP(DeviceIntPtr device, int is_in, - int first_valuator, - int num_valuators, - const int *valuators); -extern _X_EXPORT void xf86PostProximityEventM(DeviceIntPtr device, int is_in, - const ValuatorMask *mask); -extern _X_EXPORT void xf86PostButtonEvent(DeviceIntPtr device, int is_absolute, - int button, int is_down, - int first_valuator, int num_valuators, - ...); -extern _X_EXPORT void xf86PostButtonEventP(DeviceIntPtr device, int is_absolute, - int button, int is_down, - int first_valuator, - int num_valuators, - const int *valuators); -extern _X_EXPORT void xf86PostButtonEventM(DeviceIntPtr device, int is_absolute, - int button, int is_down, - const ValuatorMask *mask); -extern _X_EXPORT void xf86PostKeyEvent(DeviceIntPtr device, - unsigned int key_code, int is_down); -extern _X_EXPORT void xf86PostKeyEventM(DeviceIntPtr device, - unsigned int key_code, int is_down); -extern _X_EXPORT void xf86PostKeyEventP(DeviceIntPtr device, - unsigned int key_code, int is_down); -extern _X_EXPORT void xf86PostKeyboardEvent(DeviceIntPtr device, - unsigned int key_code, int is_down); -extern _X_EXPORT void xf86PostTouchEvent(DeviceIntPtr dev, uint32_t touchid, - uint16_t type, uint32_t flags, - const ValuatorMask *mask); -extern _X_EXPORT void xf86PostGesturePinchEvent(DeviceIntPtr dev, uint16_t type, - uint16_t num_touches, - uint32_t flags, - double delta_x, double delta_y, - double delta_unaccel_x, - double delta_unaccel_y, - double scale, double delta_angle); -extern _X_EXPORT void xf86PostGestureSwipeEvent(DeviceIntPtr dev, uint16_t type, - uint16_t num_touches, - uint32_t flags, - double delta_x, double delta_y, - double delta_unaccel_x, - double delta_unaccel_y); - -extern _X_EXPORT InputInfoPtr xf86FirstLocalDevice(void); -extern _X_EXPORT int xf86ScaleAxis(int Cx, int to_max, int to_min, int from_max, - int from_min); -extern _X_EXPORT void xf86ProcessCommonOptions(InputInfoPtr pInfo, - XF86OptionPtr options); -extern _X_EXPORT Bool xf86InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, - Atom label, int minval, - int maxval, int resolution, - int min_res, int max_res, - int mode); -extern _X_EXPORT void xf86InitValuatorDefaults(DeviceIntPtr dev, int axnum); -extern _X_EXPORT void xf86AddEnabledDevice(InputInfoPtr pInfo); -extern _X_EXPORT void xf86RemoveEnabledDevice(InputInfoPtr pInfo); -extern _X_EXPORT void xf86DisableDevice(DeviceIntPtr dev, Bool panic); -extern _X_EXPORT void xf86EnableDevice(DeviceIntPtr dev); -extern _X_EXPORT void xf86InputEnableVTProbe(void); - -/* not exported */ -int xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL is_auto); -InputInfoPtr xf86AllocateInput(void); - -/* xf86Helper.c */ -extern _X_EXPORT void xf86AddInputDriver(InputDriverPtr driver, void *module, - int flags); -extern _X_EXPORT void xf86DeleteInputDriver(int drvIndex); -extern _X_EXPORT InputDriverPtr xf86LookupInputDriver(const char *name); -extern _X_EXPORT InputInfoPtr xf86LookupInput(const char *name); -extern _X_EXPORT void xf86DeleteInput(InputInfoPtr pInp, int flags); -extern _X_EXPORT void xf86MotionHistoryAllocate(InputInfoPtr pInfo); -extern _X_EXPORT void -xf86IDrvMsgVerb(InputInfoPtr dev, - MessageType type, int verb, const char *format, ...) -_X_ATTRIBUTE_PRINTF(4, 5); -extern _X_EXPORT void -xf86IDrvMsg(InputInfoPtr dev, MessageType type, const char *format, ...) -_X_ATTRIBUTE_PRINTF(3, 4); -extern _X_EXPORT void -xf86VIDrvMsgVerb(InputInfoPtr dev, - MessageType type, int verb, const char *format, va_list args) -_X_ATTRIBUTE_PRINTF(4, 0); - -extern _X_EXPORT void xf86AddInputEventDrainCallback(CallbackProcPtr callback, - void *param); -extern _X_EXPORT void xf86RemoveInputEventDrainCallback(CallbackProcPtr callback, - void *param); - -/* xf86Option.c */ -extern _X_EXPORT void -xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts); - -#endif /* _xf86Xinput_h */ diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c deleted file mode 100644 index 8588c9fba..000000000 --- a/hw/xfree86/common/xf86cmap.c +++ /dev/null @@ -1,1137 +0,0 @@ -/* - * Copyright (c) 1998-2001 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#if defined(_XOPEN_SOURCE) || defined(__sun) && defined(__SVR4) -#include -#else -#define _XOPEN_SOURCE /* to get prototype for pow on some systems */ -#include -#undef _XOPEN_SOURCE -#endif - -#include -#include "misc.h" -#include -#include "colormapst.h" -#include "scrnintstr.h" - -#include "resource.h" - -#include "xf86.h" -#include "xf86_OSproc.h" -#include "xf86str.h" -#include "micmap.h" -#include "xf86RandR12.h" -#include "xf86Crtc.h" - -#ifdef XFreeXDGA -#include -#include "dgaproc.h" -#endif - -#include "xf86cmap.h" - -#define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = \ - ((CMapScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, CMapScreenKey))->field) -#define SCREEN_EPILOGUE(pScreen, field, wrapper)\ - ((pScreen)->field = wrapper) - -#define LOAD_PALETTE(pmap) \ - ((pmap == GetInstalledmiColormap(pmap->pScreen)) && \ - ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) || \ - xf86ScreenToScrn(pmap->pScreen)->vtSema || pScreenPriv->isDGAmode)) - -typedef struct _CMapLink { - ColormapPtr cmap; - struct _CMapLink *next; -} CMapLink, *CMapLinkPtr; - -typedef struct { - CloseScreenProcPtr CloseScreen; - CreateColormapProcPtr CreateColormap; - DestroyColormapProcPtr DestroyColormap; - InstallColormapProcPtr InstallColormap; - StoreColorsProcPtr StoreColors; - Bool (*EnterVT) (ScrnInfoPtr); - Bool (*SwitchMode) (ScrnInfoPtr, DisplayModePtr); - int (*SetDGAMode) (ScrnInfoPtr, int, DGADevicePtr); - xf86ChangeGammaProc *ChangeGamma; - int maxColors; - int sigRGBbits; - int gammaElements; - LOCO *gamma; - int *PreAllocIndices; - CMapLinkPtr maps; - unsigned int flags; - Bool isDGAmode; -} CMapScreenRec, *CMapScreenPtr; - -typedef struct { - int numColors; - LOCO *colors; - Bool recalculate; - int overscan; -} CMapColormapRec, *CMapColormapPtr; - -static DevPrivateKeyRec CMapScreenKeyRec; - -#define CMapScreenKeyRegistered dixPrivateKeyRegistered(&CMapScreenKeyRec) -#define CMapScreenKey (&CMapScreenKeyRec) -static DevPrivateKeyRec CMapColormapKeyRec; - -#define CMapColormapKey (&CMapColormapKeyRec) - -static void CMapInstallColormap(ColormapPtr); -static void CMapStoreColors(ColormapPtr, int, xColorItem *); -static Bool CMapCloseScreen(ScreenPtr); -static Bool CMapCreateColormap(ColormapPtr); -static void CMapDestroyColormap(ColormapPtr); - -static Bool CMapEnterVT(ScrnInfoPtr); -static Bool CMapSwitchMode(ScrnInfoPtr, DisplayModePtr); - -#ifdef XFreeXDGA -static int CMapSetDGAMode(ScrnInfoPtr, int, DGADevicePtr); -#endif -static int CMapChangeGamma(ScrnInfoPtr, Gamma); - -static void ComputeGamma(ScrnInfoPtr, CMapScreenPtr); -static Bool CMapAllocateColormapPrivate(ColormapPtr); -static void CMapRefreshColors(ColormapPtr, int, int *); -static void CMapSetOverscan(ColormapPtr, int, int *); -static void CMapReinstallMap(ColormapPtr); -static void CMapUnwrapScreen(ScreenPtr pScreen); - -Bool -xf86ColormapAllocatePrivates(ScrnInfoPtr pScrn) -{ - if (!dixRegisterPrivateKey(&CMapScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - if (!dixRegisterPrivateKey(&CMapColormapKeyRec, PRIVATE_COLORMAP, 0)) - return FALSE; - return TRUE; -} - -Bool -xf86HandleColormaps(ScreenPtr pScreen, - int maxColors, - int sigRGBbits, - xf86LoadPaletteProc * loadPalette, - xf86SetOverscanProc * setOverscan, unsigned int flags) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - ColormapPtr pDefMap = NULL; - CMapScreenPtr pScreenPriv; - LOCO *gamma; - int *indices; - int elements; - - if (!maxColors || !sigRGBbits || - (!loadPalette && !xf86_crtc_supports_gamma(pScrn))) - return FALSE; - - elements = 1 << sigRGBbits; - - if (!(gamma = xallocarray(elements, sizeof(LOCO)))) - return FALSE; - - if (!(indices = xallocarray(maxColors, sizeof(int)))) { - free(gamma); - return FALSE; - } - - if (!(pScreenPriv = malloc(sizeof(CMapScreenRec)))) { - free(gamma); - free(indices); - return FALSE; - } - - dixSetPrivate(&pScreen->devPrivates, &CMapScreenKeyRec, pScreenPriv); - - pScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreenPriv->CreateColormap = pScreen->CreateColormap; - pScreenPriv->DestroyColormap = pScreen->DestroyColormap; - pScreenPriv->InstallColormap = pScreen->InstallColormap; - pScreenPriv->StoreColors = pScreen->StoreColors; - pScreen->CloseScreen = CMapCloseScreen; - pScreen->CreateColormap = CMapCreateColormap; - pScreen->DestroyColormap = CMapDestroyColormap; - pScreen->InstallColormap = CMapInstallColormap; - pScreen->StoreColors = CMapStoreColors; - - pScrn->LoadPalette = loadPalette; - pScrn->SetOverscan = setOverscan; - pScreenPriv->maxColors = maxColors; - pScreenPriv->sigRGBbits = sigRGBbits; - pScreenPriv->gammaElements = elements; - pScreenPriv->gamma = gamma; - pScreenPriv->PreAllocIndices = indices; - pScreenPriv->maps = NULL; - pScreenPriv->flags = flags; - pScreenPriv->isDGAmode = FALSE; - - pScreenPriv->EnterVT = pScrn->EnterVT; - pScreenPriv->SwitchMode = pScrn->SwitchMode; - pScreenPriv->SetDGAMode = pScrn->SetDGAMode; - pScreenPriv->ChangeGamma = pScrn->ChangeGamma; - - if (!(flags & CMAP_LOAD_EVEN_IF_OFFSCREEN)) { - pScrn->EnterVT = CMapEnterVT; - if ((flags & CMAP_RELOAD_ON_MODE_SWITCH) && pScrn->SwitchMode) - pScrn->SwitchMode = CMapSwitchMode; - } -#ifdef XFreeXDGA - pScrn->SetDGAMode = CMapSetDGAMode; -#endif - pScrn->ChangeGamma = CMapChangeGamma; - - ComputeGamma(pScrn, pScreenPriv); - - /* get the default map */ - dixLookupResourceByType((void **) &pDefMap, pScreen->defColormap, - RT_COLORMAP, serverClient, DixInstallAccess); - - if (!CMapAllocateColormapPrivate(pDefMap)) { - CMapUnwrapScreen(pScreen); - return FALSE; - } - - if (xf86_crtc_supports_gamma(pScrn)) { - pScrn->LoadPalette = xf86RandR12LoadPalette; - - if (!xf86RandR12InitGamma(pScrn, elements)) { - CMapUnwrapScreen(pScreen); - return FALSE; - } - } - - /* Force the initial map to be loaded */ - SetInstalledmiColormap(pScreen, NULL); - CMapInstallColormap(pDefMap); - return TRUE; -} - -/**** Screen functions ****/ - -static Bool -CMapCloseScreen(ScreenPtr pScreen) -{ - CMapUnwrapScreen(pScreen); - - return (*pScreen->CloseScreen) (pScreen); -} - -static Bool -CMapColormapUseMax(VisualPtr pVisual, CMapScreenPtr pScreenPriv) -{ - if (pVisual->nplanes > 16) - return TRUE; - return ((1 << pVisual->nplanes) > pScreenPriv->maxColors); -} - -static Bool -CMapAllocateColormapPrivate(ColormapPtr pmap) -{ - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates, - CMapScreenKey); - CMapColormapPtr pColPriv; - CMapLinkPtr pLink; - int numColors; - LOCO *colors; - - if (CMapColormapUseMax(pmap->pVisual, pScreenPriv)) - numColors = pmap->pVisual->ColormapEntries; - else - numColors = 1 << pmap->pVisual->nplanes; - - if (!(colors = xallocarray(numColors, sizeof(LOCO)))) - return FALSE; - - if (!(pColPriv = malloc(sizeof(CMapColormapRec)))) { - free(colors); - return FALSE; - } - - dixSetPrivate(&pmap->devPrivates, CMapColormapKey, pColPriv); - - pColPriv->numColors = numColors; - pColPriv->colors = colors; - pColPriv->recalculate = TRUE; - pColPriv->overscan = -1; - - /* add map to list */ - pLink = malloc(sizeof(CMapLink)); - if (pLink) { - pLink->cmap = pmap; - pLink->next = pScreenPriv->maps; - pScreenPriv->maps = pLink; - } - - return TRUE; -} - -static Bool -CMapCreateColormap(ColormapPtr pmap) -{ - ScreenPtr pScreen = pmap->pScreen; - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); - Bool ret = FALSE; - - pScreen->CreateColormap = pScreenPriv->CreateColormap; - if ((*pScreen->CreateColormap) (pmap)) { - if (CMapAllocateColormapPrivate(pmap)) - ret = TRUE; - } - pScreen->CreateColormap = CMapCreateColormap; - - return ret; -} - -static void -CMapDestroyColormap(ColormapPtr cmap) -{ - ScreenPtr pScreen = cmap->pScreen; - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); - CMapColormapPtr pColPriv = - (CMapColormapPtr) dixLookupPrivate(&cmap->devPrivates, CMapColormapKey); - CMapLinkPtr prevLink = NULL, pLink = pScreenPriv->maps; - - if (pColPriv) { - free(pColPriv->colors); - free(pColPriv); - } - - /* remove map from list */ - while (pLink) { - if (pLink->cmap == cmap) { - if (prevLink) - prevLink->next = pLink->next; - else - pScreenPriv->maps = pLink->next; - free(pLink); - break; - } - prevLink = pLink; - pLink = pLink->next; - } - - if (pScreenPriv->DestroyColormap) { - pScreen->DestroyColormap = pScreenPriv->DestroyColormap; - (*pScreen->DestroyColormap) (cmap); - pScreen->DestroyColormap = CMapDestroyColormap; - } -} - -static void -CMapStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs) -{ - ScreenPtr pScreen = pmap->pScreen; - VisualPtr pVisual = pmap->pVisual; - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); - int *indices = pScreenPriv->PreAllocIndices; - int num = ndef; - - /* At the moment this isn't necessary since there's nobody below us */ - pScreen->StoreColors = pScreenPriv->StoreColors; - (*pScreen->StoreColors) (pmap, ndef, pdefs); - pScreen->StoreColors = CMapStoreColors; - - /* should never get here for these */ - if ((pVisual->class == TrueColor) || - (pVisual->class == StaticColor) || (pVisual->class == StaticGray)) - return; - - if (pVisual->class == DirectColor) { - CMapColormapPtr pColPriv = - (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, - CMapColormapKey); - int i; - - if (CMapColormapUseMax(pVisual, pScreenPriv)) { - int index; - - num = 0; - while (ndef--) { - if (pdefs[ndef].flags & DoRed) { - index = (pdefs[ndef].pixel & pVisual->redMask) >> - pVisual->offsetRed; - i = num; - while (i--) - if (indices[i] == index) - break; - if (i == -1) - indices[num++] = index; - } - if (pdefs[ndef].flags & DoGreen) { - index = (pdefs[ndef].pixel & pVisual->greenMask) >> - pVisual->offsetGreen; - i = num; - while (i--) - if (indices[i] == index) - break; - if (i == -1) - indices[num++] = index; - } - if (pdefs[ndef].flags & DoBlue) { - index = (pdefs[ndef].pixel & pVisual->blueMask) >> - pVisual->offsetBlue; - i = num; - while (i--) - if (indices[i] == index) - break; - if (i == -1) - indices[num++] = index; - } - } - - } - else { - /* not really as overkill as it seems */ - num = pColPriv->numColors; - for (i = 0; i < pColPriv->numColors; i++) - indices[i] = i; - } - } - else { - while (ndef--) - indices[ndef] = pdefs[ndef].pixel; - } - - CMapRefreshColors(pmap, num, indices); -} - -static void -CMapInstallColormap(ColormapPtr pmap) -{ - ScreenPtr pScreen = pmap->pScreen; - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); - - if (pmap == GetInstalledmiColormap(pmap->pScreen)) - return; - - pScreen->InstallColormap = pScreenPriv->InstallColormap; - (*pScreen->InstallColormap) (pmap); - pScreen->InstallColormap = CMapInstallColormap; - - /* Important. We let the lower layers, namely DGA, - overwrite the choice of Colormap to install */ - if (GetInstalledmiColormap(pmap->pScreen)) - pmap = GetInstalledmiColormap(pmap->pScreen); - - if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) && - (pmap->pVisual->class == TrueColor) && - CMapColormapUseMax(pmap->pVisual, pScreenPriv)) - return; - - if (LOAD_PALETTE(pmap)) - CMapReinstallMap(pmap); -} - -/**** ScrnInfoRec functions ****/ - -static Bool -CMapEnterVT(ScrnInfoPtr pScrn) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - Bool ret; - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); - - pScrn->EnterVT = pScreenPriv->EnterVT; - ret = (*pScreenPriv->EnterVT) (pScrn); - pScreenPriv->EnterVT = pScrn->EnterVT; - pScrn->EnterVT = CMapEnterVT; - if (ret) { - if (GetInstalledmiColormap(pScreen)) - CMapReinstallMap(GetInstalledmiColormap(pScreen)); - return TRUE; - } - return FALSE; -} - -static Bool -CMapSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); - - if ((*pScreenPriv->SwitchMode) (pScrn, mode)) { - if (GetInstalledmiColormap(pScreen)) - CMapReinstallMap(GetInstalledmiColormap(pScreen)); - return TRUE; - } - return FALSE; -} - -#ifdef XFreeXDGA -static int -CMapSetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr dev) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); - int ret; - - ret = (*pScreenPriv->SetDGAMode) (pScrn, num, dev); - - pScreenPriv->isDGAmode = DGAActive(pScrn->scrnIndex); - - if (!pScreenPriv->isDGAmode && GetInstalledmiColormap(pScreen) - && xf86ScreenToScrn(pScreen)->vtSema) - CMapReinstallMap(GetInstalledmiColormap(pScreen)); - - return ret; -} -#endif - -/**** Utilities ****/ - -static void -CMapReinstallMap(ColormapPtr pmap) -{ - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates, - CMapScreenKey); - CMapColormapPtr cmapPriv = - (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen); - int i = cmapPriv->numColors; - int *indices = pScreenPriv->PreAllocIndices; - - while (i--) - indices[i] = i; - - if (cmapPriv->recalculate) - CMapRefreshColors(pmap, cmapPriv->numColors, indices); - else { - (*pScrn->LoadPalette) (pScrn, cmapPriv->numColors, - indices, cmapPriv->colors, pmap->pVisual); - if (pScrn->SetOverscan) { -#ifdef DEBUGOVERSCAN - ErrorF("SetOverscan() called from CMapReinstallMap\n"); -#endif - pScrn->SetOverscan(pScrn, cmapPriv->overscan); - } - } - - cmapPriv->recalculate = FALSE; -} - -static void -CMapRefreshColors(ColormapPtr pmap, int defs, int *indices) -{ - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates, - CMapScreenKey); - CMapColormapPtr pColPriv = - (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey); - VisualPtr pVisual = pmap->pVisual; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen); - int numColors, i; - LOCO *gamma, *colors; - EntryPtr entry; - int reds, greens, blues, maxValue, index, shift; - - numColors = pColPriv->numColors; - shift = 16 - pScreenPriv->sigRGBbits; - maxValue = (1 << pScreenPriv->sigRGBbits) - 1; - gamma = pScreenPriv->gamma; - colors = pColPriv->colors; - - reds = pVisual->redMask >> pVisual->offsetRed; - greens = pVisual->greenMask >> pVisual->offsetGreen; - blues = pVisual->blueMask >> pVisual->offsetBlue; - - switch (pVisual->class) { - case StaticGray: - for (i = 0; i < numColors; i++) { - index = (i + 1) * maxValue / numColors; - colors[i].red = gamma[index].red; - colors[i].green = gamma[index].green; - colors[i].blue = gamma[index].blue; - } - break; - case TrueColor: - if (CMapColormapUseMax(pVisual, pScreenPriv)) { - for (i = 0; i <= reds; i++) - colors[i].red = gamma[i * maxValue / reds].red; - for (i = 0; i <= greens; i++) - colors[i].green = gamma[i * maxValue / greens].green; - for (i = 0; i <= blues; i++) - colors[i].blue = gamma[i * maxValue / blues].blue; - break; - } - for (i = 0; i < numColors; i++) { - colors[i].red = gamma[((i >> pVisual->offsetRed) & reds) * - maxValue / reds].red; - colors[i].green = gamma[((i >> pVisual->offsetGreen) & greens) * - maxValue / greens].green; - colors[i].blue = gamma[((i >> pVisual->offsetBlue) & blues) * - maxValue / blues].blue; - } - break; - case StaticColor: - case PseudoColor: - case GrayScale: - for (i = 0; i < defs; i++) { - index = indices[i]; - entry = (EntryPtr) &pmap->red[index]; - - if (entry->fShared) { - colors[index].red = - gamma[entry->co.shco.red->color >> shift].red; - colors[index].green = - gamma[entry->co.shco.green->color >> shift].green; - colors[index].blue = - gamma[entry->co.shco.blue->color >> shift].blue; - } - else { - colors[index].red = gamma[entry->co.local.red >> shift].red; - colors[index].green = - gamma[entry->co.local.green >> shift].green; - colors[index].blue = gamma[entry->co.local.blue >> shift].blue; - } - } - break; - case DirectColor: - if (CMapColormapUseMax(pVisual, pScreenPriv)) { - for (i = 0; i < defs; i++) { - index = indices[i]; - if (index <= reds) - colors[index].red = - gamma[pmap->red[index].co.local.red >> shift].red; - if (index <= greens) - colors[index].green = - gamma[pmap->green[index].co.local.green >> shift].green; - if (index <= blues) - colors[index].blue = - gamma[pmap->blue[index].co.local.blue >> shift].blue; - - } - break; - } - for (i = 0; i < defs; i++) { - index = indices[i]; - - colors[index].red = gamma[pmap->red[(index >> pVisual-> - offsetRed) & reds].co.local. - red >> shift].red; - colors[index].green = - gamma[pmap->green[(index >> pVisual->offsetGreen) & greens].co. - local.green >> shift].green; - colors[index].blue = - gamma[pmap->blue[(index >> pVisual->offsetBlue) & blues].co. - local.blue >> shift].blue; - } - break; - } - - if (LOAD_PALETTE(pmap)) - (*pScrn->LoadPalette) (pScrn, defs, indices, colors, pmap->pVisual); - - if (pScrn->SetOverscan) - CMapSetOverscan(pmap, defs, indices); - -} - -static Bool -CMapCompareColors(LOCO * color1, LOCO * color2) -{ - /* return TRUE if the color1 is "closer" to black than color2 */ -#ifdef DEBUGOVERSCAN - ErrorF("#%02x%02x%02x vs #%02x%02x%02x (%d vs %d)\n", - color1->red, color1->green, color1->blue, - color2->red, color2->green, color2->blue, - color1->red + color1->green + color1->blue, - color2->red + color2->green + color2->blue); -#endif - return (color1->red + color1->green + color1->blue < - color2->red + color2->green + color2->blue); -} - -static void -CMapSetOverscan(ColormapPtr pmap, int defs, int *indices) -{ - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates, - CMapScreenKey); - CMapColormapPtr pColPriv = - (CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen); - VisualPtr pVisual = pmap->pVisual; - int i; - LOCO *colors; - int index; - Bool newOverscan = FALSE; - int overscan, tmpOverscan; - - colors = pColPriv->colors; - overscan = pColPriv->overscan; - - /* - * Search for a new overscan index in the following cases: - * - * - The index hasn't yet been initialised.  In this case search - * for an index that is black or a close match to black. - * - * - The colour of the old index is changed. In this case search - * all indices for a black or close match to black. - * - * - The colour of the old index wasn't black. In this case only - * search the indices that were changed for a better match to black. - */ - - switch (pVisual->class) { - case StaticGray: - case TrueColor: - /* Should only come here once. Initialise the overscan index to 0 */ - overscan = 0; - newOverscan = TRUE; - break; - case StaticColor: - /* - * Only come here once, but search for the overscan in the same way - * as for the other cases. - */ - case DirectColor: - case PseudoColor: - case GrayScale: - if (overscan < 0 || overscan > pScreenPriv->maxColors - 1) { - /* Uninitialised */ - newOverscan = TRUE; - } - else { - /* Check if the overscan was changed */ - for (i = 0; i < defs; i++) { - index = indices[i]; - if (index == overscan) { - newOverscan = TRUE; - break; - } - } - } - if (newOverscan) { - /* The overscan is either uninitialised or it has been changed */ - - if (overscan < 0 || overscan > pScreenPriv->maxColors - 1) - tmpOverscan = pScreenPriv->maxColors - 1; - else - tmpOverscan = overscan; - - /* search all entries for a close match to black */ - for (i = pScreenPriv->maxColors - 1; i >= 0; i--) { - if (colors[i].red == 0 && colors[i].green == 0 && - colors[i].blue == 0) { - overscan = i; -#ifdef DEBUGOVERSCAN - ErrorF("Black found at index 0x%02x\n", i); -#endif - break; - } - else { -#ifdef DEBUGOVERSCAN - ErrorF("0x%02x: ", i); -#endif - if (CMapCompareColors(&colors[i], &colors[tmpOverscan])) { - tmpOverscan = i; -#ifdef DEBUGOVERSCAN - ErrorF("possible \"Black\" at index 0x%02x\n", i); -#endif - } - } - } - if (i < 0) - overscan = tmpOverscan; - } - else { - /* Check of the old overscan wasn't black */ - if (colors[overscan].red != 0 || colors[overscan].green != 0 || - colors[overscan].blue != 0) { - int oldOverscan = tmpOverscan = overscan; - - /* See of there is now a better match */ - for (i = 0; i < defs; i++) { - index = indices[i]; - if (colors[index].red == 0 && colors[index].green == 0 && - colors[index].blue == 0) { - overscan = index; -#ifdef DEBUGOVERSCAN - ErrorF("Black found at index 0x%02x\n", index); -#endif - break; - } - else { -#ifdef DEBUGOVERSCAN - ErrorF("0x%02x: ", index); -#endif - if (CMapCompareColors(&colors[index], - &colors[tmpOverscan])) { - tmpOverscan = index; -#ifdef DEBUGOVERSCAN - ErrorF("possible \"Black\" at index 0x%02x\n", - index); -#endif - } - } - } - if (i == defs) - overscan = tmpOverscan; - if (overscan != oldOverscan) - newOverscan = TRUE; - } - } - break; - } - if (newOverscan) { - pColPriv->overscan = overscan; - if (LOAD_PALETTE(pmap)) { -#ifdef DEBUGOVERSCAN - ErrorF("SetOverscan() called from CmapSetOverscan\n"); -#endif - pScrn->SetOverscan(pScrn, overscan); - } - } -} - -static void -CMapUnwrapScreen(ScreenPtr pScreen) -{ - CMapScreenPtr pScreenPriv = - (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - - pScreen->CloseScreen = pScreenPriv->CloseScreen; - pScreen->CreateColormap = pScreenPriv->CreateColormap; - pScreen->DestroyColormap = pScreenPriv->DestroyColormap; - pScreen->InstallColormap = pScreenPriv->InstallColormap; - pScreen->StoreColors = pScreenPriv->StoreColors; - - pScrn->EnterVT = pScreenPriv->EnterVT; - pScrn->SwitchMode = pScreenPriv->SwitchMode; - pScrn->SetDGAMode = pScreenPriv->SetDGAMode; - pScrn->ChangeGamma = pScreenPriv->ChangeGamma; - - free(pScreenPriv->gamma); - free(pScreenPriv->PreAllocIndices); - free(pScreenPriv); -} - -static void -ComputeGamma(ScrnInfoPtr pScrn, CMapScreenPtr priv) -{ - int elements = priv->gammaElements - 1; - double RedGamma, GreenGamma, BlueGamma; - int i; - -#ifndef DONT_CHECK_GAMMA - /* This check is to catch drivers that are not initialising pScrn->gamma */ - if (pScrn->gamma.red < GAMMA_MIN || pScrn->gamma.red > GAMMA_MAX || - pScrn->gamma.green < GAMMA_MIN || pScrn->gamma.green > GAMMA_MAX || - pScrn->gamma.blue < GAMMA_MIN || pScrn->gamma.blue > GAMMA_MAX) { - - xf86DrvMsgVerb(pScrn->scrnIndex, X_WARNING, 0, - "The %s driver didn't call xf86SetGamma() to initialise\n" - "\tthe gamma values.\n", pScrn->driverName); - xf86DrvMsgVerb(pScrn->scrnIndex, X_WARNING, 0, - "PLEASE FIX THE `%s' DRIVER!\n", - pScrn->driverName); - pScrn->gamma.red = 1.0; - pScrn->gamma.green = 1.0; - pScrn->gamma.blue = 1.0; - } -#endif - - RedGamma = 1.0 / (double) pScrn->gamma.red; - GreenGamma = 1.0 / (double) pScrn->gamma.green; - BlueGamma = 1.0 / (double) pScrn->gamma.blue; - - for (i = 0; i <= elements; i++) { - if (RedGamma == 1.0) - priv->gamma[i].red = i; - else - priv->gamma[i].red = (CARD16) (pow((double) i / (double) elements, - RedGamma) * (double) elements + - 0.5); - - if (GreenGamma == 1.0) - priv->gamma[i].green = i; - else - priv->gamma[i].green = (CARD16) (pow((double) i / (double) elements, - GreenGamma) * - (double) elements + 0.5); - - if (BlueGamma == 1.0) - priv->gamma[i].blue = i; - else - priv->gamma[i].blue = (CARD16) (pow((double) i / (double) elements, - BlueGamma) * (double) elements + - 0.5); - } -} - -int -CMapChangeGamma(ScrnInfoPtr pScrn, Gamma gamma) -{ - int ret = Success; - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - CMapColormapPtr pColPriv; - CMapScreenPtr pScreenPriv; - CMapLinkPtr pLink; - - /* Is this sufficient checking ? */ - if (!CMapScreenKeyRegistered) - return BadImplementation; - - pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - CMapScreenKey); - if (!pScreenPriv) - return BadImplementation; - - if (gamma.red < GAMMA_MIN || gamma.red > GAMMA_MAX || - gamma.green < GAMMA_MIN || gamma.green > GAMMA_MAX || - gamma.blue < GAMMA_MIN || gamma.blue > GAMMA_MAX) - return BadValue; - - pScrn->gamma.red = gamma.red; - pScrn->gamma.green = gamma.green; - pScrn->gamma.blue = gamma.blue; - - ComputeGamma(pScrn, pScreenPriv); - - /* mark all colormaps on this screen */ - pLink = pScreenPriv->maps; - while (pLink) { - pColPriv = (CMapColormapPtr) dixLookupPrivate(&pLink->cmap->devPrivates, - CMapColormapKey); - pColPriv->recalculate = TRUE; - pLink = pLink->next; - } - - if (GetInstalledmiColormap(pScreen) && - ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) || - pScrn->vtSema || pScreenPriv->isDGAmode)) { - ColormapPtr pMap = GetInstalledmiColormap(pScreen); - - if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) && - (pMap->pVisual->class == TrueColor) && - CMapColormapUseMax(pMap->pVisual, pScreenPriv)) { - - /* if the current map doesn't have a palette look - for another map to change the gamma on. */ - - pLink = pScreenPriv->maps; - while (pLink) { - if (pLink->cmap->pVisual->class == PseudoColor) - break; - pLink = pLink->next; - } - - if (pLink) { - /* need to trick CMapRefreshColors() into thinking - this is the currently installed map */ - SetInstalledmiColormap(pScreen, pLink->cmap); - CMapReinstallMap(pLink->cmap); - SetInstalledmiColormap(pScreen, pMap); - } - } - else - CMapReinstallMap(pMap); - } - - pScrn->ChangeGamma = pScreenPriv->ChangeGamma; - if (pScrn->ChangeGamma) - ret = pScrn->ChangeGamma(pScrn, gamma); - pScrn->ChangeGamma = CMapChangeGamma; - - return ret; -} - -static void -ComputeGammaRamp(CMapScreenPtr priv, - unsigned short *red, - unsigned short *green, unsigned short *blue) -{ - int elements = priv->gammaElements; - LOCO *entry = priv->gamma; - int shift = 16 - priv->sigRGBbits; - - while (elements--) { - entry->red = *(red++) >> shift; - entry->green = *(green++) >> shift; - entry->blue = *(blue++) >> shift; - entry++; - } -} - -int -xf86ChangeGammaRamp(ScreenPtr pScreen, - int size, - unsigned short *red, - unsigned short *green, unsigned short *blue) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - CMapColormapPtr pColPriv; - CMapScreenPtr pScreenPriv; - CMapLinkPtr pLink; - - if (!CMapScreenKeyRegistered) - return BadImplementation; - - pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - CMapScreenKey); - if (!pScreenPriv) - return BadImplementation; - - if (pScreenPriv->gammaElements != size) - return BadValue; - - ComputeGammaRamp(pScreenPriv, red, green, blue); - - /* mark all colormaps on this screen */ - pLink = pScreenPriv->maps; - while (pLink) { - pColPriv = (CMapColormapPtr) dixLookupPrivate(&pLink->cmap->devPrivates, - CMapColormapKey); - pColPriv->recalculate = TRUE; - pLink = pLink->next; - } - - if (GetInstalledmiColormap(pScreen) && - ((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) || - pScrn->vtSema || pScreenPriv->isDGAmode)) { - ColormapPtr pMap = GetInstalledmiColormap(pScreen); - - if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) && - (pMap->pVisual->class == TrueColor) && - CMapColormapUseMax(pMap->pVisual, pScreenPriv)) { - - /* if the current map doesn't have a palette look - for another map to change the gamma on. */ - - pLink = pScreenPriv->maps; - while (pLink) { - if (pLink->cmap->pVisual->class == PseudoColor) - break; - pLink = pLink->next; - } - - if (pLink) { - /* need to trick CMapRefreshColors() into thinking - this is the currently installed map */ - SetInstalledmiColormap(pScreen, pLink->cmap); - CMapReinstallMap(pLink->cmap); - SetInstalledmiColormap(pScreen, pMap); - } - } - else - CMapReinstallMap(pMap); - } - - return Success; -} - -int -xf86GetGammaRampSize(ScreenPtr pScreen) -{ - CMapScreenPtr pScreenPriv; - - if (!CMapScreenKeyRegistered) - return 0; - - pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - CMapScreenKey); - if (!pScreenPriv) - return 0; - - return pScreenPriv->gammaElements; -} - -int -xf86GetGammaRamp(ScreenPtr pScreen, - int size, - unsigned short *red, - unsigned short *green, unsigned short *blue) -{ - CMapScreenPtr pScreenPriv; - LOCO *entry; - int shift, sigbits; - - if (!CMapScreenKeyRegistered) - return BadImplementation; - - pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - CMapScreenKey); - if (!pScreenPriv) - return BadImplementation; - - if (size > pScreenPriv->gammaElements) - return BadValue; - - entry = pScreenPriv->gamma; - sigbits = pScreenPriv->sigRGBbits; - - while (size--) { - *red = entry->red << (16 - sigbits); - *green = entry->green << (16 - sigbits); - *blue = entry->blue << (16 - sigbits); - shift = sigbits; - while (shift < 16) { - *red |= *red >> shift; - *green |= *green >> shift; - *blue |= *blue >> shift; - shift += sigbits; - } - red++; - green++; - blue++; - entry++; - } - - return Success; -} - -int -xf86ChangeGamma(ScreenPtr pScreen, Gamma gamma) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - - if (pScrn->ChangeGamma) - return (*pScrn->ChangeGamma) (pScrn, gamma); - - return BadImplementation; -} diff --git a/hw/xfree86/common/xf86cmap.h b/hw/xfree86/common/xf86cmap.h deleted file mode 100644 index 2661cf429..000000000 --- a/hw/xfree86/common/xf86cmap.h +++ /dev/null @@ -1,67 +0,0 @@ - -/* - * Copyright (c) 1998-2001 by The XFree86 Project, 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). - */ - -#ifndef _XF86CMAP_H -#define _XF86CMAP_H - -#include "xf86str.h" -#include "colormapst.h" - -#define CMAP_PALETTED_TRUECOLOR 0x0000001 -#define CMAP_RELOAD_ON_MODE_SWITCH 0x0000002 -#define CMAP_LOAD_EVEN_IF_OFFSCREEN 0x0000004 - -extern _X_EXPORT Bool xf86HandleColormaps(ScreenPtr pScreen, - int maxCol, - int sigRGBbits, - xf86LoadPaletteProc * loadPalette, - xf86SetOverscanProc * setOverscan, - unsigned int flags); - -extern _X_EXPORT Bool xf86ColormapAllocatePrivates(ScrnInfoPtr pScrn); - -extern _X_EXPORT int - xf86ChangeGamma(ScreenPtr pScreen, Gamma newGamma); - -extern _X_EXPORT int - -xf86ChangeGammaRamp(ScreenPtr pScreen, - int size, - unsigned short *red, - unsigned short *green, unsigned short *blue); - -extern _X_EXPORT int xf86GetGammaRampSize(ScreenPtr pScreen); - -extern _X_EXPORT int - -xf86GetGammaRamp(ScreenPtr pScreen, - int size, - unsigned short *red, - unsigned short *green, unsigned short *blue); - -#endif /* _XF86CMAP_H */ diff --git a/hw/xfree86/common/xf86fbBus.c b/hw/xfree86/common/xf86fbBus.c deleted file mode 100644 index 303b9c2f5..000000000 --- a/hw/xfree86/common/xf86fbBus.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2000-2001 by The XFree86 Project, 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). - */ - -/* - * This file contains the interfaces to the bus-specific code - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" - -#include "xf86Bus.h" - -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" - -Bool fbSlotClaimed = FALSE; - -int -xf86ClaimFbSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active) -{ - EntityPtr p; - int num; - -#ifdef XSERVER_PLATFORM_BUS - if (platformSlotClaimed) - return -1; -#endif -#ifdef XSERVER_LIBPCIACCESS - if (pciSlotClaimed) - return -1; -#endif -#if defined(__sparc__) || defined (__sparc64__) - if (sbusSlotClaimed) - return -1; -#endif - - num = xf86AllocateEntity(); - p = xf86Entities[num]; - p->driver = drvp; - p->chipset = 0; - p->bus.type = BUS_NONE; - p->active = active; - p->inUse = FALSE; - xf86AddDevToEntity(num, dev); - - fbSlotClaimed = TRUE; - return num; -} - -/* - * Get the list of FB "slots" claimed by a screen - */ -int -xf86GetFbInfoForScreen(int scrnIndex) -{ - int num = 0; - int i; - EntityPtr p; - - for (i = 0; i < xf86Screens[scrnIndex]->numEntities; i++) { - p = xf86Entities[xf86Screens[scrnIndex]->entityList[i]]; - if (p->bus.type == BUS_NONE) { - num++; - } - } - return num; -} diff --git a/hw/xfree86/common/xf86fbman.c b/hw/xfree86/common/xf86fbman.c deleted file mode 100644 index 25779e510..000000000 --- a/hw/xfree86/common/xf86fbman.c +++ /dev/null @@ -1,1431 +0,0 @@ - -/* - * Copyright (c) 1998-2001 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "misc.h" -#include "xf86.h" - -#include -#include "scrnintstr.h" -#include "regionstr.h" -#include "xf86fbman.h" - -/* -#define DEBUG -*/ - -static DevPrivateKeyRec xf86FBManagerKeyRec; -static DevPrivateKey xf86FBManagerKey; - -Bool -xf86RegisterOffscreenManager(ScreenPtr pScreen, FBManagerFuncsPtr funcs) -{ - - xf86FBManagerKey = &xf86FBManagerKeyRec; - - if (!dixRegisterPrivateKey(&xf86FBManagerKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - dixSetPrivate(&pScreen->devPrivates, xf86FBManagerKey, funcs); - - return TRUE; -} - -Bool -xf86FBManagerRunning(ScreenPtr pScreen) -{ - if (xf86FBManagerKey == NULL) - return FALSE; - - if (!dixLookupPrivate(&pScreen->devPrivates, xf86FBManagerKey)) - return FALSE; - - return TRUE; -} - -Bool -xf86RegisterFreeBoxCallback(ScreenPtr pScreen, - FreeBoxCallbackProcPtr FreeBoxCallback, - void *devPriv) -{ - FBManagerFuncsPtr funcs; - - if (xf86FBManagerKey == NULL) - return FALSE; - if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBManagerKey))) - return FALSE; - - return (*funcs->RegisterFreeBoxCallback) (pScreen, FreeBoxCallback, - devPriv); -} - -FBAreaPtr -xf86AllocateOffscreenArea(ScreenPtr pScreen, - int w, int h, - int gran, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, void *privData) -{ - FBManagerFuncsPtr funcs; - - if (xf86FBManagerKey == NULL) - return NULL; - if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBManagerKey))) - return NULL; - - return (*funcs->AllocateOffscreenArea) (pScreen, w, h, gran, moveCB, - removeCB, privData); -} - -FBLinearPtr -xf86AllocateOffscreenLinear(ScreenPtr pScreen, - int length, - int gran, - MoveLinearCallbackProcPtr moveCB, - RemoveLinearCallbackProcPtr removeCB, - void *privData) -{ - FBManagerFuncsPtr funcs; - - if (xf86FBManagerKey == NULL) - return NULL; - if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBManagerKey))) - return NULL; - - return (*funcs->AllocateOffscreenLinear) (pScreen, length, gran, moveCB, - removeCB, privData); -} - -void -xf86FreeOffscreenArea(FBAreaPtr area) -{ - FBManagerFuncsPtr funcs; - - if (!area) - return; - - if (xf86FBManagerKey == NULL) - return; - if (! - (funcs = - (FBManagerFuncsPtr) dixLookupPrivate(&area->pScreen->devPrivates, - xf86FBManagerKey))) - return; - - (*funcs->FreeOffscreenArea) (area); - - return; -} - -void -xf86FreeOffscreenLinear(FBLinearPtr linear) -{ - FBManagerFuncsPtr funcs; - - if (!linear) - return; - - if (xf86FBManagerKey == NULL) - return; - if (! - (funcs = - (FBManagerFuncsPtr) dixLookupPrivate(&linear->pScreen->devPrivates, - xf86FBManagerKey))) - return; - - (*funcs->FreeOffscreenLinear) (linear); - - return; -} - -Bool -xf86ResizeOffscreenArea(FBAreaPtr resize, int w, int h) -{ - FBManagerFuncsPtr funcs; - - if (!resize) - return FALSE; - - if (xf86FBManagerKey == NULL) - return FALSE; - if (! - (funcs = - (FBManagerFuncsPtr) dixLookupPrivate(&resize->pScreen->devPrivates, - xf86FBManagerKey))) - return FALSE; - - return (*funcs->ResizeOffscreenArea) (resize, w, h); -} - -Bool -xf86ResizeOffscreenLinear(FBLinearPtr resize, int size) -{ - FBManagerFuncsPtr funcs; - - if (!resize) - return FALSE; - - if (xf86FBManagerKey == NULL) - return FALSE; - if (! - (funcs = - (FBManagerFuncsPtr) dixLookupPrivate(&resize->pScreen->devPrivates, - xf86FBManagerKey))) - return FALSE; - - return (*funcs->ResizeOffscreenLinear) (resize, size); -} - -Bool -xf86QueryLargestOffscreenArea(ScreenPtr pScreen, - int *w, int *h, - int gran, int preferences, int severity) -{ - FBManagerFuncsPtr funcs; - - *w = 0; - *h = 0; - - if (xf86FBManagerKey == NULL) - return FALSE; - if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBManagerKey))) - return FALSE; - - return (*funcs->QueryLargestOffscreenArea) (pScreen, w, h, gran, - preferences, severity); -} - -Bool -xf86QueryLargestOffscreenLinear(ScreenPtr pScreen, - int *size, int gran, int severity) -{ - FBManagerFuncsPtr funcs; - - *size = 0; - - if (xf86FBManagerKey == NULL) - return FALSE; - if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBManagerKey))) - return FALSE; - - return (*funcs->QueryLargestOffscreenLinear) (pScreen, size, gran, - severity); -} - -Bool -xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen) -{ - FBManagerFuncsPtr funcs; - - if (xf86FBManagerKey == NULL) - return FALSE; - if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBManagerKey))) - return FALSE; - - return (*funcs->PurgeOffscreenAreas) (pScreen); -} - -/************************************************************\ - - Below is a specific implementation of an offscreen manager. - -\************************************************************/ - -static DevPrivateKeyRec xf86FBScreenKeyRec; - -#define xf86FBScreenKey (&xf86FBScreenKeyRec) - -typedef struct _FBLink { - FBArea area; - struct _FBLink *next; -} FBLink, *FBLinkPtr; - -typedef struct _FBLinearLink { - FBLinear linear; - int free; /* need to add free here as FBLinear is publicly accessible */ - FBAreaPtr area; /* only used if allocation came from XY area */ - struct _FBLinearLink *next; -} FBLinearLink, *FBLinearLinkPtr; - -typedef struct { - ScreenPtr pScreen; - RegionPtr InitialBoxes; - RegionPtr FreeBoxes; - FBLinkPtr UsedAreas; - int NumUsedAreas; - FBLinearLinkPtr LinearAreas; - CloseScreenProcPtr CloseScreen; - int NumCallbacks; - FreeBoxCallbackProcPtr *FreeBoxesUpdateCallback; - DevUnion *devPrivates; -} FBManager, *FBManagerPtr; - -static void -SendCallFreeBoxCallbacks(FBManagerPtr offman) -{ - int i = offman->NumCallbacks; - - while (i--) { - (*offman->FreeBoxesUpdateCallback[i]) (offman->pScreen, - offman->FreeBoxes, - offman->devPrivates[i].ptr); - } -} - -static Bool -localRegisterFreeBoxCallback(ScreenPtr pScreen, - FreeBoxCallbackProcPtr FreeBoxCallback, - void *devPriv) -{ - FBManagerPtr offman; - FreeBoxCallbackProcPtr *newCallbacks; - DevUnion *newPrivates; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - newCallbacks = reallocarray(offman->FreeBoxesUpdateCallback, - offman->NumCallbacks + 1, - sizeof(FreeBoxCallbackProcPtr)); - if (!newCallbacks) - return FALSE; - else - offman->FreeBoxesUpdateCallback = newCallbacks; - - newPrivates = reallocarray(offman->devPrivates, - offman->NumCallbacks + 1, - sizeof(DevUnion)); - if (!newPrivates) - return FALSE; - else - offman->devPrivates = newPrivates; - - offman->FreeBoxesUpdateCallback[offman->NumCallbacks] = FreeBoxCallback; - offman->devPrivates[offman->NumCallbacks].ptr = devPriv; - offman->NumCallbacks++; - - SendCallFreeBoxCallbacks(offman); - - return TRUE; -} - -static FBAreaPtr -AllocateArea(FBManagerPtr offman, - int w, int h, - int granularity, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, void *privData) -{ - ScreenPtr pScreen = offman->pScreen; - FBLinkPtr link = NULL; - FBAreaPtr area = NULL; - RegionRec NewReg; - int i, x = 0, num; - BoxPtr boxp; - - if (granularity <= 1) - granularity = 0; - - boxp = RegionRects(offman->FreeBoxes); - num = RegionNumRects(offman->FreeBoxes); - - /* look through the free boxes */ - for (i = 0; i < num; i++, boxp++) { - x = boxp->x1; - if (granularity > 1) - x = ((x + granularity - 1) / granularity) * granularity; - - if (((boxp->y2 - boxp->y1) < h) || ((boxp->x2 - x) < w)) - continue; - - link = malloc(sizeof(FBLink)); - if (!link) - return NULL; - - area = &(link->area); - link->next = offman->UsedAreas; - offman->UsedAreas = link; - offman->NumUsedAreas++; - break; - } - - /* try to boot a removable one out if we are not expendable ourselves */ - if (!area && !removeCB) { - link = offman->UsedAreas; - - while (link) { - if (!link->area.RemoveAreaCallback) { - link = link->next; - continue; - } - - boxp = &(link->area.box); - x = boxp->x1; - if (granularity > 1) - x = ((x + granularity - 1) / granularity) * granularity; - - if (((boxp->y2 - boxp->y1) < h) || ((boxp->x2 - x) < w)) { - link = link->next; - continue; - } - - /* bye, bye */ - (*link->area.RemoveAreaCallback) (&link->area); - RegionInit(&NewReg, &(link->area.box), 1); - RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &NewReg); - RegionUninit(&NewReg); - - area = &(link->area); - break; - } - } - - if (area) { - area->pScreen = pScreen; - area->granularity = granularity; - area->box.x1 = x; - area->box.x2 = x + w; - area->box.y1 = boxp->y1; - area->box.y2 = boxp->y1 + h; - area->MoveAreaCallback = moveCB; - area->RemoveAreaCallback = removeCB; - area->devPrivate.ptr = privData; - - RegionInit(&NewReg, &(area->box), 1); - RegionSubtract(offman->FreeBoxes, offman->FreeBoxes, &NewReg); - RegionUninit(&NewReg); - } - - return area; -} - -static FBAreaPtr -localAllocateOffscreenArea(ScreenPtr pScreen, - int w, int h, - int gran, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, void *privData) -{ - FBManagerPtr offman; - FBAreaPtr area = NULL; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - if ((area = AllocateArea(offman, w, h, gran, moveCB, removeCB, privData))) - SendCallFreeBoxCallbacks(offman); - - return area; -} - -static void -localFreeOffscreenArea(FBAreaPtr area) -{ - FBManagerPtr offman; - FBLinkPtr pLink, pLinkPrev = NULL; - RegionRec FreedRegion; - ScreenPtr pScreen; - - pScreen = area->pScreen; - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - pLink = offman->UsedAreas; - if (!pLink) - return; - - while (&(pLink->area) != area) { - pLinkPrev = pLink; - pLink = pLink->next; - if (!pLink) - return; - } - - /* put the area back into the pool */ - RegionInit(&FreedRegion, &(pLink->area.box), 1); - RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedRegion); - RegionUninit(&FreedRegion); - - if (pLinkPrev) - pLinkPrev->next = pLink->next; - else - offman->UsedAreas = pLink->next; - - free(pLink); - offman->NumUsedAreas--; - - SendCallFreeBoxCallbacks(offman); -} - -static Bool -localResizeOffscreenArea(FBAreaPtr resize, int w, int h) -{ - FBManagerPtr offman; - ScreenPtr pScreen; - BoxRec OrigArea; - RegionRec FreedReg; - FBAreaPtr area = NULL; - FBLinkPtr pLink, newLink, pLinkPrev = NULL; - - pScreen = resize->pScreen; - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - /* find this link */ - if (!(pLink = offman->UsedAreas)) - return FALSE; - - while (&(pLink->area) != resize) { - pLinkPrev = pLink; - pLink = pLink->next; - if (!pLink) - return FALSE; - } - - OrigArea.x1 = resize->box.x1; - OrigArea.x2 = resize->box.x2; - OrigArea.y1 = resize->box.y1; - OrigArea.y2 = resize->box.y2; - - /* if it's smaller, this is easy */ - - if ((w <= (resize->box.x2 - resize->box.x1)) && - (h <= (resize->box.y2 - resize->box.y1))) { - RegionRec NewReg; - - resize->box.x2 = resize->box.x1 + w; - resize->box.y2 = resize->box.y1 + h; - - if ((resize->box.y2 == OrigArea.y2) && (resize->box.x2 == OrigArea.x2)) - return TRUE; - - RegionInit(&FreedReg, &OrigArea, 1); - RegionInit(&NewReg, &(resize->box), 1); - RegionSubtract(&FreedReg, &FreedReg, &NewReg); - RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedReg); - RegionUninit(&FreedReg); - RegionUninit(&NewReg); - - SendCallFreeBoxCallbacks(offman); - - return TRUE; - } - - /* otherwise we remove the old region */ - - RegionInit(&FreedReg, &OrigArea, 1); - RegionUnion(offman->FreeBoxes, offman->FreeBoxes, &FreedReg); - - /* remove the old link */ - if (pLinkPrev) - pLinkPrev->next = pLink->next; - else - offman->UsedAreas = pLink->next; - - /* and try to add a new one */ - - if ((area = AllocateArea(offman, w, h, resize->granularity, - resize->MoveAreaCallback, - resize->RemoveAreaCallback, - resize->devPrivate.ptr))) { - - /* copy data over to our link and replace the new with old */ - memcpy(resize, area, sizeof(FBArea)); - - pLinkPrev = NULL; - newLink = offman->UsedAreas; - - while (&(newLink->area) != area) { - pLinkPrev = newLink; - newLink = newLink->next; - } - - if (pLinkPrev) - pLinkPrev->next = newLink->next; - else - offman->UsedAreas = newLink->next; - - pLink->next = offman->UsedAreas; - offman->UsedAreas = pLink; - - free(newLink); - - /* AllocateArea added one but we really only exchanged one */ - offman->NumUsedAreas--; - } - else { - /* reinstate the old region */ - RegionSubtract(offman->FreeBoxes, offman->FreeBoxes, &FreedReg); - RegionUninit(&FreedReg); - - pLink->next = offman->UsedAreas; - offman->UsedAreas = pLink; - return FALSE; - } - - RegionUninit(&FreedReg); - - SendCallFreeBoxCallbacks(offman); - - return TRUE; -} - -static Bool -localQueryLargestOffscreenArea(ScreenPtr pScreen, - int *width, int *height, - int granularity, int preferences, int severity) -{ - FBManagerPtr offman; - RegionPtr newRegion = NULL; - BoxPtr pbox; - int nbox; - int x, w, h, area, oldArea; - - *width = *height = oldArea = 0; - - if (granularity <= 1) - granularity = 0; - - if ((preferences < 0) || (preferences > 3)) - return FALSE; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - if (severity < 0) - severity = 0; - if (severity > 2) - severity = 2; - - switch (severity) { - case 2: - if (offman->NumUsedAreas) { - FBLinkPtr pLink; - RegionRec tmpRegion; - - newRegion = RegionCreate(NULL, 1); - RegionCopy(newRegion, offman->InitialBoxes); - pLink = offman->UsedAreas; - - while (pLink) { - if (!pLink->area.RemoveAreaCallback) { - RegionInit(&tmpRegion, &(pLink->area.box), 1); - RegionSubtract(newRegion, newRegion, &tmpRegion); - RegionUninit(&tmpRegion); - } - pLink = pLink->next; - } - - nbox = RegionNumRects(newRegion); - pbox = RegionRects(newRegion); - break; - } - case 1: - if (offman->NumUsedAreas) { - FBLinkPtr pLink; - RegionRec tmpRegion; - - newRegion = RegionCreate(NULL, 1); - RegionCopy(newRegion, offman->FreeBoxes); - pLink = offman->UsedAreas; - - while (pLink) { - if (pLink->area.RemoveAreaCallback) { - RegionInit(&tmpRegion, &(pLink->area.box), 1); - RegionAppend(newRegion, &tmpRegion); - RegionUninit(&tmpRegion); - } - pLink = pLink->next; - } - - nbox = RegionNumRects(newRegion); - pbox = RegionRects(newRegion); - break; - } - default: - nbox = RegionNumRects(offman->FreeBoxes); - pbox = RegionRects(offman->FreeBoxes); - break; - } - - while (nbox--) { - x = pbox->x1; - if (granularity > 1) - x = ((x + granularity - 1) / granularity) * granularity; - - w = pbox->x2 - x; - h = pbox->y2 - pbox->y1; - area = w * h; - - if (w > 0) { - Bool gotIt = FALSE; - - switch (preferences) { - case FAVOR_AREA_THEN_WIDTH: - if ((area > oldArea) || ((area == oldArea) && (w > *width))) - gotIt = TRUE; - break; - case FAVOR_AREA_THEN_HEIGHT: - if ((area > oldArea) || ((area == oldArea) && (h > *height))) - gotIt = TRUE; - break; - case FAVOR_WIDTH_THEN_AREA: - if ((w > *width) || ((w == *width) && (area > oldArea))) - gotIt = TRUE; - break; - case FAVOR_HEIGHT_THEN_AREA: - if ((h > *height) || ((h == *height) && (area > oldArea))) - gotIt = TRUE; - break; - } - if (gotIt) { - *width = w; - *height = h; - oldArea = area; - } - } - pbox++; - } - - if (newRegion) - RegionDestroy(newRegion); - - return TRUE; -} - -static Bool -localPurgeUnlockedOffscreenAreas(ScreenPtr pScreen) -{ - FBManagerPtr offman; - FBLinkPtr pLink, tmp, pPrev = NULL; - RegionRec FreedRegion; - Bool anyUsed = FALSE; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - pLink = offman->UsedAreas; - if (!pLink) - return TRUE; - - while (pLink) { - if (pLink->area.RemoveAreaCallback) { - (*pLink->area.RemoveAreaCallback) (&pLink->area); - - RegionInit(&FreedRegion, &(pLink->area.box), 1); - RegionAppend(offman->FreeBoxes, &FreedRegion); - RegionUninit(&FreedRegion); - - if (pPrev) - pPrev->next = pLink->next; - else - offman->UsedAreas = pLink->next; - - tmp = pLink; - pLink = pLink->next; - free(tmp); - offman->NumUsedAreas--; - anyUsed = TRUE; - } - else { - pPrev = pLink; - pLink = pLink->next; - } - } - - if (anyUsed) { - RegionValidate(offman->FreeBoxes, &anyUsed); - SendCallFreeBoxCallbacks(offman); - } - - return TRUE; -} - -static void -LinearMoveCBWrapper(FBAreaPtr from, FBAreaPtr to) -{ - /* this will never get called */ -} - -static void -LinearRemoveCBWrapper(FBAreaPtr area) -{ - FBManagerPtr offman; - FBLinearLinkPtr pLink, pLinkPrev = NULL; - ScreenPtr pScreen = area->pScreen; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - pLink = offman->LinearAreas; - if (!pLink) - return; - - while (pLink->area != area) { - pLinkPrev = pLink; - pLink = pLink->next; - if (!pLink) - return; - } - - /* give the user the callback it is expecting */ - (*pLink->linear.RemoveLinearCallback) (&(pLink->linear)); - - if (pLinkPrev) - pLinkPrev->next = pLink->next; - else - offman->LinearAreas = pLink->next; - - free(pLink); -} - -static void -DumpDebug(FBLinearLinkPtr pLink) -{ -#ifdef DEBUG - if (!pLink) - ErrorF("MMmm, PLINK IS NULL!\n"); - - while (pLink) { - ErrorF(" Offset:%08x, Size:%08x, %s,%s\n", - pLink->linear.offset, - pLink->linear.size, - pLink->free ? "Free" : "Used", pLink->area ? "Area" : "Linear"); - - pLink = pLink->next; - } -#endif -} - -static FBLinearPtr -AllocateLinear(FBManagerPtr offman, int size, int granularity, void *privData) -{ - ScreenPtr pScreen = offman->pScreen; - FBLinearLinkPtr linear = NULL; - FBLinearLinkPtr newlink = NULL; - int offset, end; - - if (size <= 0) - return NULL; - - if (!offman->LinearAreas) - return NULL; - - linear = offman->LinearAreas; - while (linear) { - /* Make sure we get a free area that's not an XY fallback case */ - if (!linear->area && linear->free) { - offset = linear->linear.offset; - if (granularity > 1) - offset = - ((offset + granularity - 1) / granularity) * granularity; - end = offset + size; - if (end <= (linear->linear.offset + linear->linear.size)) - break; - } - linear = linear->next; - } - if (!linear) - return NULL; - - /* break left */ - if (offset > linear->linear.offset) { - newlink = malloc(sizeof(FBLinearLink)); - if (!newlink) - return NULL; - newlink->area = NULL; - newlink->linear.offset = offset; - newlink->linear.size = - linear->linear.size - (offset - linear->linear.offset); - newlink->free = 1; - newlink->next = linear->next; - linear->linear.size -= newlink->linear.size; - linear->next = newlink; - linear = newlink; - } - - /* break right */ - if (size < linear->linear.size) { - newlink = malloc(sizeof(FBLinearLink)); - if (!newlink) - return NULL; - newlink->area = NULL; - newlink->linear.offset = offset + size; - newlink->linear.size = linear->linear.size - size; - newlink->free = 1; - newlink->next = linear->next; - linear->linear.size = size; - linear->next = newlink; - } - - /* p = middle block */ - linear->linear.granularity = granularity; - linear->free = 0; - linear->linear.pScreen = pScreen; - linear->linear.MoveLinearCallback = NULL; - linear->linear.RemoveLinearCallback = NULL; - linear->linear.devPrivate.ptr = NULL; - - DumpDebug(offman->LinearAreas); - - return &(linear->linear); -} - -static FBLinearPtr -localAllocateOffscreenLinear(ScreenPtr pScreen, - int length, - int gran, - MoveLinearCallbackProcPtr moveCB, - RemoveLinearCallbackProcPtr removeCB, - void *privData) -{ - FBManagerPtr offman; - FBLinearLinkPtr link; - FBAreaPtr area; - FBLinearPtr linear = NULL; - BoxPtr extents; - int w, h, pitch; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - - /* Try to allocate from linear memory first...... */ - DebugF("ALLOCATING LINEAR\n"); - if ((linear = AllocateLinear(offman, length, gran, privData))) - return linear; - - DebugF("NOPE, ALLOCATING AREA\n"); - - if (!(link = malloc(sizeof(FBLinearLink)))) - return NULL; - - /* No linear available, so try and pinch some from the XY areas */ - extents = RegionExtents(offman->InitialBoxes); - pitch = extents->x2 - extents->x1; - - if (gran > 1) { - if (gran > pitch) { - /* we can't match the specified alignment with XY allocations */ - free(link); - return NULL; - } - - if (pitch % gran) { - /* pitch and granularity aren't a perfect match, let's allocate - * a bit more so we can align later on - */ - length += gran - 1; - } - } - - if (length < pitch) { /* special case */ - w = length; - h = 1; - } - else { - w = pitch; - h = (length + pitch - 1) / pitch; - } - - if ((area = localAllocateOffscreenArea(pScreen, w, h, gran, - moveCB ? LinearMoveCBWrapper : NULL, - removeCB ? LinearRemoveCBWrapper : - NULL, privData))) { - link->area = area; - link->free = 0; - link->next = offman->LinearAreas; - offman->LinearAreas = link; - linear = &(link->linear); - linear->pScreen = pScreen; - linear->size = h * w; - linear->offset = (pitch * area->box.y1) + area->box.x1; - if (gran > 1) - linear->offset = ((linear->offset + gran - 1) / gran) * gran; - linear->granularity = gran; - linear->MoveLinearCallback = moveCB; - linear->RemoveLinearCallback = removeCB; - linear->devPrivate.ptr = privData; - } - else - free(link); - - DumpDebug(offman->LinearAreas); - - return linear; -} - -static void -localFreeOffscreenLinear(FBLinearPtr linear) -{ - FBManagerPtr offman; - FBLinearLinkPtr pLink, pLinkPrev = NULL; - ScreenPtr pScreen = linear->pScreen; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - pLink = offman->LinearAreas; - if (!pLink) - return; - - while (&(pLink->linear) != linear) { - pLinkPrev = pLink; - pLink = pLink->next; - if (!pLink) - return; - } - - if (pLink->area) { /* really an XY area */ - DebugF("FREEING AREA\n"); - localFreeOffscreenArea(pLink->area); - if (pLinkPrev) - pLinkPrev->next = pLink->next; - else - offman->LinearAreas = pLink->next; - free(pLink); - DumpDebug(offman->LinearAreas); - return; - } - - pLink->free = 1; - - if (pLink->next && pLink->next->free) { - FBLinearLinkPtr p = pLink->next; - - pLink->linear.size += p->linear.size; - pLink->next = p->next; - free(p); - } - - if (pLinkPrev) { - if (pLinkPrev->next && pLinkPrev->next->free && !pLinkPrev->area) { - FBLinearLinkPtr p = pLinkPrev->next; - - pLinkPrev->linear.size += p->linear.size; - pLinkPrev->next = p->next; - free(p); - } - } - - DebugF("FREEING LINEAR\n"); - DumpDebug(offman->LinearAreas); -} - -static Bool -localResizeOffscreenLinear(FBLinearPtr resize, int length) -{ - FBManagerPtr offman; - FBLinearLinkPtr pLink; - ScreenPtr pScreen = resize->pScreen; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - pLink = offman->LinearAreas; - if (!pLink) - return FALSE; - - while (&(pLink->linear) != resize) { - pLink = pLink->next; - if (!pLink) - return FALSE; - } - - /* This could actually be a lot smarter and try to move allocations - from XY to linear when available. For now if it was XY, we keep - it XY */ - - if (pLink->area) { /* really an XY area */ - BoxPtr extents; - int pitch, w, h; - - extents = RegionExtents(offman->InitialBoxes); - pitch = extents->x2 - extents->x1; - - if (length < pitch) { /* special case */ - w = length; - h = 1; - } - else { - w = pitch; - h = (length + pitch - 1) / pitch; - } - - if (localResizeOffscreenArea(pLink->area, w, h)) { - resize->size = h * w; - resize->offset = - (pitch * pLink->area->box.y1) + pLink->area->box.x1; - return TRUE; - } - } - else { - /* TODO!!!! resize the linear area */ - } - - return FALSE; -} - -static Bool -localQueryLargestOffscreenLinear(ScreenPtr pScreen, - int *size, int gran, int priority) -{ - FBManagerPtr offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - FBLinearLinkPtr pLink; - FBLinearLinkPtr pLinkRet; - - *size = 0; - - pLink = offman->LinearAreas; - - if (pLink && !pLink->area) { - pLinkRet = pLink; - while (pLink) { - if (pLink->free) { - if (pLink->linear.size > pLinkRet->linear.size) - pLinkRet = pLink; - } - pLink = pLink->next; - } - - if (pLinkRet->free) { - *size = pLinkRet->linear.size; - return TRUE; - } - } - else { - int w, h; - - if (localQueryLargestOffscreenArea(pScreen, &w, &h, gran, - FAVOR_WIDTH_THEN_AREA, priority)) { - BoxPtr extents; - - extents = RegionExtents(offman->InitialBoxes); - if ((extents->x2 - extents->x1) == w) - *size = w * h; - return TRUE; - } - } - - return FALSE; -} - -static FBManagerFuncs xf86FBManFuncs = { - localAllocateOffscreenArea, - localFreeOffscreenArea, - localResizeOffscreenArea, - localQueryLargestOffscreenArea, - localRegisterFreeBoxCallback, - localAllocateOffscreenLinear, - localFreeOffscreenLinear, - localResizeOffscreenLinear, - localQueryLargestOffscreenLinear, - localPurgeUnlockedOffscreenAreas -}; - -static Bool -xf86FBCloseScreen(ScreenPtr pScreen) -{ - FBLinkPtr pLink, tmp; - FBLinearLinkPtr pLinearLink, tmp2; - FBManagerPtr offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - - pScreen->CloseScreen = offman->CloseScreen; - - pLink = offman->UsedAreas; - while (pLink) { - tmp = pLink; - pLink = pLink->next; - free(tmp); - } - - pLinearLink = offman->LinearAreas; - while (pLinearLink) { - tmp2 = pLinearLink; - pLinearLink = pLinearLink->next; - free(tmp2); - } - - RegionDestroy(offman->InitialBoxes); - RegionDestroy(offman->FreeBoxes); - - free(offman->FreeBoxesUpdateCallback); - free(offman->devPrivates); - free(offman); - dixSetPrivate(&pScreen->devPrivates, xf86FBScreenKey, NULL); - - return (*pScreen->CloseScreen) (pScreen); -} - -Bool -xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - RegionRec ScreenRegion; - RegionRec FullRegion; - BoxRec ScreenBox; - Bool ret; - - ScreenBox.x1 = 0; - ScreenBox.y1 = 0; - ScreenBox.x2 = pScrn->virtualX; - ScreenBox.y2 = pScrn->virtualY; - - if ((FullBox->x1 > ScreenBox.x1) || (FullBox->y1 > ScreenBox.y1) || - (FullBox->x2 < ScreenBox.x2) || (FullBox->y2 < ScreenBox.y2)) { - return FALSE; - } - - if (FullBox->y2 < FullBox->y1) - return FALSE; - if (FullBox->x2 < FullBox->x1) - return FALSE; - - RegionInit(&ScreenRegion, &ScreenBox, 1); - RegionInit(&FullRegion, FullBox, 1); - - RegionSubtract(&FullRegion, &FullRegion, &ScreenRegion); - - ret = xf86InitFBManagerRegion(pScreen, &FullRegion); - - RegionUninit(&ScreenRegion); - RegionUninit(&FullRegion); - - return ret; -} - -Bool -xf86InitFBManagerArea(ScreenPtr pScreen, int PixelArea, int Verbosity) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xRectangle Rect[3]; - RegionPtr pRegion, pScreenRegion; - int nRect; - Bool ret = FALSE; - - if (PixelArea < (pScrn->displayWidth * pScrn->virtualY)) - return FALSE; - - Rect[0].x = Rect[0].y = 0; - Rect[0].width = pScrn->displayWidth; - Rect[0].height = PixelArea / pScrn->displayWidth; - nRect = 1; - - /* Add a possible partial scanline */ - if ((Rect[1].height = Rect[1].width = PixelArea % pScrn->displayWidth)) { - Rect[1].x = 0; - Rect[1].y = Rect[0].height; - Rect[1].height = 1; - nRect++; - } - - /* Factor out virtual resolution */ - pRegion = RegionFromRects(nRect, Rect, 0); - if (pRegion) { - if (!RegionNar(pRegion)) { - Rect[2].x = Rect[2].y = 0; - Rect[2].width = pScrn->virtualX; - Rect[2].height = pScrn->virtualY; - - pScreenRegion = RegionFromRects(1, &Rect[2], 0); - if (pScreenRegion) { - if (!RegionNar(pScreenRegion)) { - RegionSubtract(pRegion, pRegion, pScreenRegion); - - ret = xf86InitFBManagerRegion(pScreen, pRegion); - - if (ret && xf86GetVerbosity() >= Verbosity) { - int scrnIndex = pScrn->scrnIndex; - - xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, - "Largest offscreen areas (with overlaps):\n"); - - if (Rect[2].width < Rect[0].width) { - xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, - "\t%d x %d rectangle at %d,0\n", - Rect[0].width - Rect[2].width, - Rect[0].height, Rect[2].width); - } - if (Rect[2].width < Rect[1].width) { - xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, - "\t%d x %d rectangle at %d,0\n", - Rect[1].width - Rect[2].width, - Rect[0].height + Rect[1].height, - Rect[2].width); - } - if (Rect[2].height < Rect[0].height) { - xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, - "\t%d x %d rectangle at 0,%d\n", - Rect[0].width, - Rect[0].height - Rect[2].height, - Rect[2].height); - } - if (Rect[1].height) { - xf86DrvMsgVerb(scrnIndex, X_INFO, Verbosity, - "\t%d x %d rectangle at 0,%d\n", - Rect[1].width, - Rect[0].height - Rect[2].height + - Rect[1].height, Rect[2].height); - } - } - } - - RegionDestroy(pScreenRegion); - } - } - - RegionDestroy(pRegion); - } - - return ret; -} - -Bool -xf86InitFBManagerRegion(ScreenPtr pScreen, RegionPtr FullRegion) -{ - FBManagerPtr offman; - - if (RegionNil(FullRegion)) - return FALSE; - - if (!dixRegisterPrivateKey(&xf86FBScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - if (!xf86RegisterOffscreenManager(pScreen, &xf86FBManFuncs)) - return FALSE; - - offman = malloc(sizeof(FBManager)); - if (!offman) - return FALSE; - - dixSetPrivate(&pScreen->devPrivates, xf86FBScreenKey, offman); - - offman->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = xf86FBCloseScreen; - - offman->InitialBoxes = RegionCreate(NULL, 1); - offman->FreeBoxes = RegionCreate(NULL, 1); - - RegionCopy(offman->InitialBoxes, FullRegion); - RegionCopy(offman->FreeBoxes, FullRegion); - - offman->pScreen = pScreen; - offman->UsedAreas = NULL; - offman->LinearAreas = NULL; - offman->NumUsedAreas = 0; - offman->NumCallbacks = 0; - offman->FreeBoxesUpdateCallback = NULL; - offman->devPrivates = NULL; - - return TRUE; -} - -Bool -xf86InitFBManagerLinear(ScreenPtr pScreen, int offset, int size) -{ - FBManagerPtr offman; - FBLinearLinkPtr link; - FBLinearPtr linear; - - if (size <= 0) - return FALSE; - - /* we expect people to have called the Area setup first for pixmap cache */ - if (!dixLookupPrivate(&pScreen->devPrivates, xf86FBScreenKey)) - return FALSE; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - offman->LinearAreas = malloc(sizeof(FBLinearLink)); - if (!offman->LinearAreas) - return FALSE; - - link = offman->LinearAreas; - link->area = NULL; - link->next = NULL; - link->free = 1; - linear = &(link->linear); - linear->pScreen = pScreen; - linear->size = size; - linear->offset = offset; - linear->granularity = 0; - linear->MoveLinearCallback = NULL; - linear->RemoveLinearCallback = NULL; - linear->devPrivate.ptr = NULL; - - return TRUE; -} - -/* This is an implementation specific function and should - disappear after the next release. People should use the - real linear functions instead */ - -FBAreaPtr -xf86AllocateLinearOffscreenArea(ScreenPtr pScreen, - int length, - int gran, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, - void *privData) -{ - FBManagerFuncsPtr funcs; - FBManagerPtr offman; - BoxPtr extents; - int w, h; - - if (xf86FBManagerKey == NULL) - return NULL; - if (!(funcs = (FBManagerFuncsPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBManagerKey))) - return NULL; - - offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86FBScreenKey); - extents = RegionExtents(offman->InitialBoxes); - w = extents->x2 - extents->x1; - - if (gran > 1) { - if (gran > w) - return NULL; - - if (w % gran) - length += gran - 1; - } - - if (length <= w) { /* special case */ - h = 1; - w = length; - } - else { - h = (length + w - 1) / w; - } - - return (*funcs->AllocateOffscreenArea) (pScreen, w, h, gran, moveCB, - removeCB, privData); -} diff --git a/hw/xfree86/common/xf86fbman.h b/hw/xfree86/common/xf86fbman.h deleted file mode 100644 index 092c2e2dd..000000000 --- a/hw/xfree86/common/xf86fbman.h +++ /dev/null @@ -1,171 +0,0 @@ - -/* - * Copyright (c) 1998-2001 by The XFree86 Project, 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). - */ - -#ifndef _XF86FBMAN_H -#define _XF86FBMAN_H - -#include "scrnintstr.h" -#include "regionstr.h" - -#define FAVOR_AREA_THEN_WIDTH 0 -#define FAVOR_AREA_THEN_HEIGHT 1 -#define FAVOR_WIDTH_THEN_AREA 2 -#define FAVOR_HEIGHT_THEN_AREA 3 - -#define PRIORITY_LOW 0 -#define PRIORITY_NORMAL 1 -#define PRIORITY_EXTREME 2 - -typedef struct _FBArea { - ScreenPtr pScreen; - BoxRec box; - int granularity; - void (*MoveAreaCallback) (struct _FBArea *, struct _FBArea *); - void (*RemoveAreaCallback) (struct _FBArea *); - DevUnion devPrivate; -} FBArea, *FBAreaPtr; - -typedef struct _FBLinear { - ScreenPtr pScreen; - int size; - int offset; - int granularity; - void (*MoveLinearCallback) (struct _FBLinear *, struct _FBLinear *); - void (*RemoveLinearCallback) (struct _FBLinear *); - DevUnion devPrivate; -} FBLinear, *FBLinearPtr; - -typedef void (*FreeBoxCallbackProcPtr) (ScreenPtr, RegionPtr, void *); -typedef void (*MoveAreaCallbackProcPtr) (FBAreaPtr, FBAreaPtr); -typedef void (*RemoveAreaCallbackProcPtr) (FBAreaPtr); - -typedef void (*MoveLinearCallbackProcPtr) (FBLinearPtr, FBLinearPtr); -typedef void (*RemoveLinearCallbackProcPtr) (FBLinearPtr); - -typedef struct { - FBAreaPtr(*AllocateOffscreenArea) (ScreenPtr pScreen, - int w, int h, - int granularity, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, - void *privData); - void (*FreeOffscreenArea) (FBAreaPtr area); - Bool (*ResizeOffscreenArea) (FBAreaPtr area, int w, int h); - Bool (*QueryLargestOffscreenArea) (ScreenPtr pScreen, - int *width, int *height, - int granularity, - int preferences, int priority); - Bool (*RegisterFreeBoxCallback) (ScreenPtr pScreen, - FreeBoxCallbackProcPtr FreeBoxCallback, - void *devPriv); -/* linear functions */ - FBLinearPtr(*AllocateOffscreenLinear) (ScreenPtr pScreen, - int size, - int granularity, - MoveLinearCallbackProcPtr moveCB, - RemoveLinearCallbackProcPtr - removeCB, void *privData); - void (*FreeOffscreenLinear) (FBLinearPtr area); - Bool (*ResizeOffscreenLinear) (FBLinearPtr area, int size); - Bool (*QueryLargestOffscreenLinear) (ScreenPtr pScreen, - int *size, - int granularity, int priority); - Bool (*PurgeOffscreenAreas) (ScreenPtr); -} FBManagerFuncs, *FBManagerFuncsPtr; - -extern _X_EXPORT Bool xf86RegisterOffscreenManager(ScreenPtr pScreen, - FBManagerFuncsPtr funcs); - -extern _X_EXPORT Bool - xf86InitFBManagerRegion(ScreenPtr pScreen, RegionPtr ScreenRegion); - -extern _X_EXPORT Bool - xf86InitFBManagerArea(ScreenPtr pScreen, int PixalArea, int Verbosity); - -extern _X_EXPORT Bool - xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox); - -extern _X_EXPORT Bool - xf86InitFBManagerLinear(ScreenPtr pScreen, int offset, int size); - -extern _X_EXPORT Bool - xf86FBManagerRunning(ScreenPtr pScreen); - -extern _X_EXPORT FBAreaPtr -xf86AllocateOffscreenArea(ScreenPtr pScreen, - int w, int h, - int granularity, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, void *privData); - -extern _X_EXPORT FBAreaPtr -xf86AllocateLinearOffscreenArea(ScreenPtr pScreen, - int length, - int granularity, - MoveAreaCallbackProcPtr moveCB, - RemoveAreaCallbackProcPtr removeCB, - void *privData); - -extern _X_EXPORT FBLinearPtr -xf86AllocateOffscreenLinear(ScreenPtr pScreen, - int length, - int granularity, - MoveLinearCallbackProcPtr moveCB, - RemoveLinearCallbackProcPtr removeCB, - void *privData); - -extern _X_EXPORT void xf86FreeOffscreenArea(FBAreaPtr area); -extern _X_EXPORT void xf86FreeOffscreenLinear(FBLinearPtr area); - -extern _X_EXPORT Bool - xf86ResizeOffscreenArea(FBAreaPtr resize, int w, int h); - -extern _X_EXPORT Bool - xf86ResizeOffscreenLinear(FBLinearPtr resize, int size); - -extern _X_EXPORT Bool - -xf86RegisterFreeBoxCallback(ScreenPtr pScreen, - FreeBoxCallbackProcPtr FreeBoxCallback, - void *devPriv); - -extern _X_EXPORT Bool - xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen); - -extern _X_EXPORT Bool - -xf86QueryLargestOffscreenArea(ScreenPtr pScreen, - int *width, int *height, - int granularity, int preferences, int priority); - -extern _X_EXPORT Bool - -xf86QueryLargestOffscreenLinear(ScreenPtr pScreen, - int *size, int granularity, int priority); - -#endif /* _XF86FBMAN_H */ diff --git a/hw/xfree86/common/xf86noBus.c b/hw/xfree86/common/xf86noBus.c deleted file mode 100644 index 4f55def7b..000000000 --- a/hw/xfree86/common/xf86noBus.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2000-2002 by The XFree86 Project, 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). - */ - -/* - * This file contains the interfaces to the bus-specific code - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" - -#include "xf86Bus.h" - -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" - -int -xf86ClaimNoSlot(DriverPtr drvp, int chipset, GDevPtr dev, Bool active) -{ - EntityPtr p; - int num; - - num = xf86AllocateEntity(); - p = xf86Entities[num]; - p->driver = drvp; - p->chipset = 0; - p->bus.type = BUS_NONE; - p->active = active; - p->inUse = FALSE; - xf86AddDevToEntity(num, dev); - - return num; -} diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c deleted file mode 100644 index aeeed8be6..000000000 --- a/hw/xfree86/common/xf86pciBus.c +++ /dev/null @@ -1,1475 +0,0 @@ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains the interfaces to the bus-specific code - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include "os.h" -#include "Pci.h" -#include "xf86.h" -#include "xf86Priv.h" -#include "dirent.h" /* DIR, FILE type definitions */ - -/* Bus-specific headers */ -#include "xf86Bus.h" - -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" - -#define PCI_VENDOR_GENERIC 0x00FF - -/* Bus-specific globals */ -int pciSlotClaimed = 0; - -#define PCIINFOCLASSES(c) \ - ( (((c) & 0x00ff0000) == (PCI_CLASS_PREHISTORIC << 16)) \ - || (((c) & 0x00ff0000) == (PCI_CLASS_DISPLAY << 16)) \ - || ((((c) & 0x00ffff00) \ - == ((PCI_CLASS_MULTIMEDIA << 16) | (PCI_SUBCLASS_MULTIMEDIA_VIDEO << 8)))) \ - || ((((c) & 0x00ffff00) \ - == ((PCI_CLASS_PROCESSOR << 16) | (PCI_SUBCLASS_PROCESSOR_COPROC << 8)))) ) - -/* - * PCI classes that have messages printed always. The others are only - * have a message printed when the vendor/dev IDs are recognised. - */ -#define PCIALWAYSPRINTCLASSES(c) \ - ( (((c) & 0x00ffff00) \ - == ((PCI_CLASS_PREHISTORIC << 16) | (PCI_SUBCLASS_PREHISTORIC_VGA << 8))) \ - || (((c) & 0x00ff0000) == (PCI_CLASS_DISPLAY << 16)) \ - || ((((c) & 0x00ffff00) \ - == ((PCI_CLASS_MULTIMEDIA << 16) | (PCI_SUBCLASS_MULTIMEDIA_VIDEO << 8)))) ) - -#define IS_VGA(c) \ - (((c) & 0x00ffff00) \ - == ((PCI_CLASS_DISPLAY << 16) | (PCI_SUBCLASS_DISPLAY_VGA << 8))) - -static struct pci_slot_match xf86IsolateDevice = { - PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0 -}; - -/* - * xf86Bus.c interface - */ - -void -xf86PciProbe(void) -{ - int i = 0, k; - int num = 0; - struct pci_device *info; - struct pci_device_iterator *iter; - struct pci_device **xf86PciVideoInfo = NULL; - - if (!xf86scanpci()) { - xf86PciVideoInfo = NULL; - return; - } - - iter = pci_slot_match_iterator_create(&xf86IsolateDevice); - while ((info = pci_device_next(iter)) != NULL) { - if (PCIINFOCLASSES(info->device_class)) { - num++; - xf86PciVideoInfo = xnfreallocarray(xf86PciVideoInfo, - num + 1, - sizeof(struct pci_device *)); - xf86PciVideoInfo[num] = NULL; - xf86PciVideoInfo[num - 1] = info; - - pci_device_probe(info); - if (primaryBus.type == BUS_NONE && pci_device_is_boot_vga(info)) { - primaryBus.type = BUS_PCI; - primaryBus.id.pci = info; - } - info->user_data = 0; - } - } - free(iter); - - /* If we haven't found a primary device try a different heuristic */ - if (primaryBus.type == BUS_NONE && num) { - for (i = 0; i < num; i++) { - uint16_t command; - - info = xf86PciVideoInfo[i]; - pci_device_cfg_read_u16(info, &command, 4); - - if ((command & PCI_CMD_MEM_ENABLE) - && ((num == 1) || IS_VGA(info->device_class))) { - if (primaryBus.type == BUS_NONE) { - primaryBus.type = BUS_PCI; - primaryBus.id.pci = info; - } - else { - xf86Msg(X_NOTICE, - "More than one possible primary device found\n"); - primaryBus.type ^= (BusType) (-1); - } - } - } - } - - /* Print a summary of the video devices found */ - for (k = 0; k < num; k++) { - const char *prim = " "; - Bool memdone = FALSE, iodone = FALSE; - - info = xf86PciVideoInfo[k]; - - if (!PCIALWAYSPRINTCLASSES(info->device_class)) - continue; - - if (xf86IsPrimaryPci(info)) - prim = "*"; - - xf86Msg(X_PROBED, "PCI:%s(%u@%u:%u:%u) %04x:%04x:%04x:%04x ", prim, - info->bus, info->domain, info->dev, info->func, - info->vendor_id, info->device_id, - info->subvendor_id, info->subdevice_id); - - xf86ErrorF("rev %d", info->revision); - - for (i = 0; i < 6; i++) { - struct pci_mem_region *r = &info->regions[i]; - - if (r->size && !r->is_IO) { - if (!memdone) { - xf86ErrorF(", Mem @ "); - memdone = TRUE; - } - else - xf86ErrorF(", "); - xf86ErrorF("0x%08lx/%ld", (long) r->base_addr, (long) r->size); - } - } - - for (i = 0; i < 6; i++) { - struct pci_mem_region *r = &info->regions[i]; - - if (r->size && r->is_IO) { - if (!iodone) { - xf86ErrorF(", I/O @ "); - iodone = TRUE; - } - else - xf86ErrorF(", "); - xf86ErrorF("0x%08lx/%ld", (long) r->base_addr, (long) r->size); - } - } - - if (info->rom_size) { - xf86ErrorF(", BIOS @ 0x\?\?\?\?\?\?\?\?/%ld", - (long) info->rom_size); - } - - xf86ErrorF("\n"); - } - free(xf86PciVideoInfo); -} - -/* - * If the slot requested is already in use, return -1. - * Otherwise, claim the slot for the screen requesting it. - */ - -int -xf86ClaimPciSlot(struct pci_device *d, DriverPtr drvp, - int chipset, GDevPtr dev, Bool active) -{ - EntityPtr p = NULL; - int num; - - if (xf86CheckPciSlot(d)) { - num = xf86AllocateEntity(); - p = xf86Entities[num]; - p->driver = drvp; - p->chipset = chipset; - p->bus.type = BUS_PCI; - p->bus.id.pci = d; - p->active = active; - p->inUse = FALSE; - if (dev) - xf86AddDevToEntity(num, dev); - pciSlotClaimed++; - - return num; - } - else - return -1; -} - -/* - * Unclaim PCI slot, e.g. if probing failed, so that a different driver can claim. - */ -void -xf86UnclaimPciSlot(struct pci_device *d, GDevPtr dev) -{ - int i; - - for (i = 0; i < xf86NumEntities; i++) { - const EntityPtr p = xf86Entities[i]; - - if ((p->bus.type == BUS_PCI) && (p->bus.id.pci == d)) { - /* Probably the slot should be deallocated? */ - xf86RemoveDevFromEntity(i, dev); - pciSlotClaimed--; - p->bus.type = BUS_NONE; - return; - } - } -} - -/* - * Parse a BUS ID string, and return the PCI bus parameters if it was - * in the correct format for a PCI bus id. - */ - -Bool -xf86ParsePciBusString(const char *busID, int *bus, int *device, int *func) -{ - /* - * The format is assumed to be "bus[@domain]:device[:func]", where domain, - * bus, device and func are decimal integers. domain and func may be - * omitted and assumed to be zero, although doing this isn't encouraged. - */ - - char *p, *s, *d; - const char *id; - int i; - - if (StringToBusType(busID, &id) != BUS_PCI) - return FALSE; - - s = xstrdup(id); - p = strtok(s, ":"); - if (p == NULL || *p == 0) { - free(s); - return FALSE; - } - d = strpbrk(p, "@"); - if (d != NULL) { - *(d++) = 0; - for (i = 0; d[i] != 0; i++) { - if (!isdigit(d[i])) { - free(s); - return FALSE; - } - } - } - for (i = 0; p[i] != 0; i++) { - if (!isdigit(p[i])) { - free(s); - return FALSE; - } - } - *bus = atoi(p); - if (d != NULL && *d != 0) - *bus += atoi(d) << 8; - p = strtok(NULL, ":"); - if (p == NULL || *p == 0) { - free(s); - return FALSE; - } - for (i = 0; p[i] != 0; i++) { - if (!isdigit(p[i])) { - free(s); - return FALSE; - } - } - *device = atoi(p); - *func = 0; - p = strtok(NULL, ":"); - if (p == NULL || *p == 0) { - free(s); - return TRUE; - } - for (i = 0; p[i] != 0; i++) { - if (!isdigit(p[i])) { - free(s); - return FALSE; - } - } - *func = atoi(p); - free(s); - return TRUE; -} - -/* - * Compare a BUS ID string with a PCI bus id. Return TRUE if they match. - */ - -Bool -xf86ComparePciBusString(const char *busID, int bus, int device, int func) -{ - int ibus, idevice, ifunc; - - if (xf86ParsePciBusString(busID, &ibus, &idevice, &ifunc)) { - return bus == ibus && device == idevice && func == ifunc; - } - else { - return FALSE; - } -} - -/* - * xf86IsPrimaryPci() -- return TRUE if primary device - * is PCI and bus, dev and func numbers match. - */ - -Bool -xf86IsPrimaryPci(struct pci_device *pPci) -{ - /* Add max. 1 screen for the IgnorePrimary fallback path */ - if (xf86ProbeIgnorePrimary && xf86NumScreens == 0) - return TRUE; - - if (primaryBus.type == BUS_PCI) - return pPci == primaryBus.id.pci; -#ifdef XSERVER_PLATFORM_BUS - if (primaryBus.type == BUS_PLATFORM) - if (primaryBus.id.plat->pdev) - if (MATCH_PCI_DEVICES(primaryBus.id.plat->pdev, pPci)) - return TRUE; -#endif - return FALSE; -} - -/* - * xf86GetPciInfoForEntity() -- Get the pciVideoRec of entity. - */ -struct pci_device * -xf86GetPciInfoForEntity(int entityIndex) -{ - EntityPtr p; - - if (entityIndex >= xf86NumEntities) - return NULL; - - p = xf86Entities[entityIndex]; - switch (p->bus.type) { - case BUS_PCI: - return p->bus.id.pci; - case BUS_PLATFORM: - return p->bus.id.plat->pdev; - default: - break; - } - return NULL; -} - -/* - * xf86CheckPciMemBase() checks that the memory base value matches one of the - * PCI base address register values for the given PCI device. - */ -Bool -xf86CheckPciMemBase(struct pci_device *pPci, memType base) -{ - int i; - - for (i = 0; i < 6; i++) - if (base == pPci->regions[i].base_addr) - return TRUE; - return FALSE; -} - -/* - * Check if the slot requested is free. If it is already in use, return FALSE. - */ - -Bool -xf86CheckPciSlot(const struct pci_device *d) -{ - int i; - - for (i = 0; i < xf86NumEntities; i++) { - const EntityPtr p = xf86Entities[i]; - - if ((p->bus.type == BUS_PCI) && (p->bus.id.pci == d)) { - return FALSE; - } -#ifdef XSERVER_PLATFORM_BUS - if ((p->bus.type == BUS_PLATFORM) && (p->bus.id.plat->pdev)) { - struct pci_device *ud = p->bus.id.plat->pdev; - if (MATCH_PCI_DEVICES(ud, d)) - return FALSE; - } -#endif - } - return TRUE; -} - -#define END_OF_MATCHES(m) \ - (((m).vendor_id == 0) && ((m).device_id == 0) && ((m).subvendor_id == 0)) - -Bool -xf86PciAddMatchingDev(DriverPtr drvp) -{ - const struct pci_id_match *const devices = drvp->supported_devices; - int j; - struct pci_device *pPci; - struct pci_device_iterator *iter; - int numFound = 0; - - iter = pci_id_match_iterator_create(NULL); - while ((pPci = pci_device_next(iter)) != NULL) { - /* Determine if this device is supported by the driver. If it is, - * add it to the list of devices to configure. - */ - for (j = 0; !END_OF_MATCHES(devices[j]); j++) { - if (PCI_ID_COMPARE(devices[j].vendor_id, pPci->vendor_id) - && PCI_ID_COMPARE(devices[j].device_id, pPci->device_id) - && ((devices[j].device_class_mask & pPci->device_class) - == devices[j].device_class)) { - if (xf86CheckPciSlot(pPci)) { - GDevPtr pGDev = - xf86AddBusDeviceToConfigure(drvp->driverName, BUS_PCI, - pPci, -1); - if (pGDev != NULL) { - /* After configure pass 1, chipID and chipRev are - * treated as over-rides, so clobber them here. - */ - pGDev->chipID = -1; - pGDev->chipRev = -1; - } - - numFound++; - } - - break; - } - } - } - - pci_iterator_destroy(iter); - - return numFound != 0; -} - -Bool -xf86PciProbeDev(DriverPtr drvp) -{ - int i, j; - struct pci_device *pPci; - Bool foundScreen = FALSE; - const struct pci_id_match *const devices = drvp->supported_devices; - GDevPtr *devList; - const unsigned numDevs = xf86MatchDevice(drvp->driverName, &devList); - - for (i = 0; i < numDevs; i++) { - struct pci_device_iterator *iter; - unsigned device_id; - - /* Find the pciVideoRec associated with this device section. - */ - iter = pci_id_match_iterator_create(NULL); - while ((pPci = pci_device_next(iter)) != NULL) { - if (devList[i]->busID && *devList[i]->busID) { - if (xf86ComparePciBusString(devList[i]->busID, - ((pPci->domain << 8) - | pPci->bus), - pPci->dev, pPci->func)) { - break; - } - } - else if (xf86IsPrimaryPci(pPci)) { - break; - } - } - - pci_iterator_destroy(iter); - - if (pPci == NULL) { - continue; - } - device_id = (devList[i]->chipID > 0) - ? devList[i]->chipID : pPci->device_id; - - /* Once the pciVideoRec is found, determine if the device is supported - * by the driver. If it is, probe it! - */ - for (j = 0; !END_OF_MATCHES(devices[j]); j++) { - if (PCI_ID_COMPARE(devices[j].vendor_id, pPci->vendor_id) - && PCI_ID_COMPARE(devices[j].device_id, device_id) - && ((devices[j].device_class_mask & pPci->device_class) - == devices[j].device_class)) { - int entry; - - /* Allow the same entity to be used more than once for - * devices with multiple screens per entity. This assumes - * implicitly that there will be a screen == 0 instance. - * - * FIXME Need to make sure that two different drivers don't - * FIXME claim the same screen > 0 instance. - */ - if ((devList[i]->screen == 0) && !xf86CheckPciSlot(pPci)) - continue; - - DebugF("%s: card at %d:%d:%d is claimed by a Device section\n", - drvp->driverName, pPci->bus, pPci->dev, pPci->func); - - /* Allocate an entry in the lists to be returned */ - entry = xf86ClaimPciSlot(pPci, drvp, device_id, - devList[i], devList[i]->active); - - if ((entry == -1) && (devList[i]->screen > 0)) { - unsigned k; - - for (k = 0; k < xf86NumEntities; k++) { - EntityPtr pEnt = xf86Entities[k]; - - if (pEnt->bus.type != BUS_PCI) - continue; - if (pEnt->bus.id.pci == pPci) { - entry = k; - xf86AddDevToEntity(k, devList[i]); - break; - } - } - } - - if (entry != -1) { - if ((*drvp->PciProbe) (drvp, entry, pPci, - devices[j].match_data)) { - foundScreen = TRUE; - } - else - xf86UnclaimPciSlot(pPci, devList[i]); - } - - break; - } - } - } - free(devList); - - return foundScreen; -} - -void -xf86PciIsolateDevice(const char *argument) -{ - int bus, device, func; - - if (sscanf(argument, "PCI:%d:%d:%d", &bus, &device, &func) == 3) { - xf86IsolateDevice.domain = PCI_DOM_FROM_BUS(bus); - xf86IsolateDevice.bus = PCI_BUS_NO_DOMAIN(bus); - xf86IsolateDevice.dev = device; - xf86IsolateDevice.func = func; - } - else - FatalError("Invalid isolated device specification\n"); -} - -static Bool -pciDeviceHasBars(struct pci_device *pci) -{ - int i; - - for (i = 0; i < 6; i++) - if (pci->regions[i].size) - return TRUE; - - if (pci->rom_size) - return TRUE; - - return FALSE; -} - -struct Inst { - struct pci_device *pci; - GDevPtr dev; - Bool foundHW; /* PCIid in list of supported chipsets */ - Bool claimed; /* BusID matches with a device section */ - int chip; - int screen; -}; - -/** - * Find set of unclaimed devices matching a given vendor ID. - * - * Used by drivers to find as yet unclaimed devices matching the specified - * vendor ID. - * - * \param driverName Name of the driver. This is used to find Device - * sections in the config file. - * \param vendorID PCI vendor ID of associated devices. If zero, then - * the true vendor ID must be encoded in the \c PCIid - * fields of the \c PCIchipsets entries. - * \param chipsets Symbol table used to associate chipset names with - * PCI IDs. - * \param devList List of Device sections parsed from the config file. - * \param numDevs Number of entries in \c devList. - * \param drvp Pointer the driver's control structure. - * \param foundEntities Returned list of entity indices associated with the - * driver. - * - * \returns - * The number of elements in returned in \c foundEntities on success or zero - * on failure. - * - * \todo - * This function does a bit more than short description says. Fill in some - * more of the details of its operation. - * - * \todo - * The \c driverName parameter is redundant. It is the same as - * \c DriverRec::driverName. In a future version of this function, remove - * that parameter. - */ -int -xf86MatchPciInstances(const char *driverName, int vendorID, - SymTabPtr chipsets, PciChipsets * PCIchipsets, - GDevPtr * devList, int numDevs, DriverPtr drvp, - int **foundEntities) -{ - int i, j; - struct pci_device *pPci; - struct pci_device_iterator *iter; - struct Inst *instances = NULL; - int numClaimedInstances = 0; - int allocatedInstances = 0; - int numFound = 0; - SymTabRec *c; - PciChipsets *id; - int *retEntities = NULL; - - *foundEntities = NULL; - - /* Each PCI device will contribute at least one entry. Each device - * section can contribute at most one entry. The sum of the two is - * guaranteed to be larger than the maximum possible number of entries. - * Do this calculation and memory allocation once now to eliminate the - * need for realloc calls inside the loop. - */ - if (!(xf86DoConfigure && xf86DoConfigurePass1)) { - unsigned max_entries = numDevs; - - iter = pci_slot_match_iterator_create(NULL); - while ((pPci = pci_device_next(iter)) != NULL) { - max_entries++; - } - - pci_iterator_destroy(iter); - instances = xnfallocarray(max_entries, sizeof(struct Inst)); - } - - iter = pci_slot_match_iterator_create(NULL); - while ((pPci = pci_device_next(iter)) != NULL) { - unsigned device_class = pPci->device_class; - Bool foundVendor = FALSE; - - /* Convert the pre-PCI 2.0 device class for a VGA adapter to the - * 2.0 version of the same class. - */ - if (device_class == 0x00000101) { - device_class = 0x00030000; - } - - /* Find PCI devices that match the given vendor ID. The vendor ID is - * either specified explicitly as a parameter to the function or - * implicitly encoded in the high bits of id->PCIid. - * - * The first device with a matching vendor is recorded, even if the - * device ID doesn't match. This is done because the Device section - * in the xorg.conf file can over-ride the device ID. A matching PCI - * ID might not be found now, but after the device ID over-ride is - * applied there /might/ be a match. - */ - for (id = PCIchipsets; id->PCIid != -1; id++) { - const unsigned vendor_id = ((id->PCIid & 0xFFFF0000) >> 16) - | vendorID; - const unsigned device_id = (id->PCIid & 0x0000FFFF); - const unsigned match_class = 0x00030000 | id->PCIid; - - if ((vendor_id == pPci->vendor_id) - || ((vendorID == PCI_VENDOR_GENERIC) && - (match_class == device_class))) { - if (!foundVendor && (instances != NULL)) { - ++allocatedInstances; - instances[allocatedInstances - 1].pci = pPci; - instances[allocatedInstances - 1].dev = NULL; - instances[allocatedInstances - 1].claimed = FALSE; - instances[allocatedInstances - 1].foundHW = FALSE; - instances[allocatedInstances - 1].screen = 0; - } - - foundVendor = TRUE; - - if ((device_id == pPci->device_id) - || ((vendorID == PCI_VENDOR_GENERIC) - && (match_class == device_class))) { - if (instances != NULL) { - instances[allocatedInstances - 1].foundHW = TRUE; - instances[allocatedInstances - 1].chip = id->numChipset; - } - - if (xf86DoConfigure && xf86DoConfigurePass1) { - if (xf86CheckPciSlot(pPci)) { - GDevPtr pGDev = - xf86AddBusDeviceToConfigure(drvp->driverName, - BUS_PCI, pPci, -1); - - if (pGDev) { - /* After configure pass 1, chipID and chipRev - * are treated as over-rides, so clobber them - * here. - */ - pGDev->chipID = -1; - pGDev->chipRev = -1; - } - - numFound++; - } - } - else { - numFound++; - } - - break; - } - } - } - } - - pci_iterator_destroy(iter); - - /* In "probe only" or "configure" mode (signaled by instances being NULL), - * our work is done. Return the number of detected devices. - */ - if (instances == NULL) { - return numFound; - } - - /* - * This may be debatable, but if no PCI devices with a matching vendor - * type is found, return zero now. It is probably not desirable to - * allow the config file to override this. - */ - if (allocatedInstances <= 0) { - free(instances); - return 0; - } - - DebugF("%s instances found: %d\n", driverName, allocatedInstances); - - /* - * Check for devices that need duplicated instances. This is required - * when there is more than one screen per entity. - * - * XXX This currently doesn't work for cases where the BusID isn't - * specified explicitly in the config file. - */ - - for (j = 0; j < numDevs; j++) { - if (devList[j]->screen > 0 && devList[j]->busID && *devList[j]->busID) { - for (i = 0; i < allocatedInstances; i++) { - pPci = instances[i].pci; - if (xf86ComparePciBusString(devList[j]->busID, - PCI_MAKE_BUS(pPci->domain, - pPci->bus), pPci->dev, - pPci->func)) { - allocatedInstances++; - instances[allocatedInstances - 1] = instances[i]; - instances[allocatedInstances - 1].screen = - devList[j]->screen; - numFound++; - break; - } - } - } - } - - for (i = 0; i < allocatedInstances; i++) { - GDevPtr dev = NULL; - GDevPtr devBus = NULL; - - pPci = instances[i].pci; - for (j = 0; j < numDevs; j++) { - if (devList[j]->busID && *devList[j]->busID) { - if (xf86ComparePciBusString(devList[j]->busID, - PCI_MAKE_BUS(pPci->domain, - pPci->bus), pPci->dev, - pPci->func) && - devList[j]->screen == instances[i].screen) { - - if (devBus) - xf86MsgVerb(X_WARNING, 0, - "%s: More than one matching Device section for " - "instances\n\t(BusID: %s) found: %s\n", - driverName, devList[j]->busID, - devList[j]->identifier); - else - devBus = devList[j]; - } - } - else { - /* - * if device section without BusID is found - * only assign to it to the primary device. - */ - if (xf86IsPrimaryPci(pPci)) { - xf86Msg(X_PROBED, "Assigning device section with no busID" - " to primary device\n"); - if (dev || devBus) - xf86MsgVerb(X_WARNING, 0, - "%s: More than one matching Device section " - "found: %s\n", driverName, - devList[j]->identifier); - else - dev = devList[j]; - } - } - } - if (devBus) - dev = devBus; /* busID preferred */ - if (!dev) { - if (xf86CheckPciSlot(pPci) && pciDeviceHasBars(pPci)) { - xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " - "for instance (BusID PCI:%u@%u:%u:%u) found\n", - driverName, pPci->bus, pPci->domain, pPci->dev, - pPci->func); - } - } - else { - numClaimedInstances++; - instances[i].claimed = TRUE; - instances[i].dev = dev; - } - } - DebugF("%s instances found: %d\n", driverName, numClaimedInstances); - /* - * Now check that a chipset or chipID override in the device section - * is valid. Chipset has precedence over chipID. - * If chipset is not valid ignore BusSlot completely. - */ - for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) { - MessageType from = X_PROBED; - - if (!instances[i].claimed) { - continue; - } - if (instances[i].dev->chipset) { - for (c = chipsets; c->token >= 0; c++) { - if (xf86NameCmp(c->name, instances[i].dev->chipset) == 0) - break; - } - if (c->token == -1) { - instances[i].claimed = FALSE; - numClaimedInstances--; - xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device " - "section \"%s\" isn't valid for this driver\n", - driverName, instances[i].dev->chipset, - instances[i].dev->identifier); - } - else { - instances[i].chip = c->token; - - for (id = PCIchipsets; id->numChipset >= 0; id++) { - if (id->numChipset == instances[i].chip) - break; - } - if (id->numChipset >= 0) { - xf86Msg(X_CONFIG, "Chipset override: %s\n", - instances[i].dev->chipset); - from = X_CONFIG; - } - else { - instances[i].claimed = FALSE; - numClaimedInstances--; - xf86MsgVerb(X_WARNING, 0, "%s: Chipset \"%s\" in Device " - "section \"%s\" isn't a valid PCI chipset\n", - driverName, instances[i].dev->chipset, - instances[i].dev->identifier); - } - } - } - else if (instances[i].dev->chipID > 0) { - for (id = PCIchipsets; id->numChipset >= 0; id++) { - if (id->PCIid == instances[i].dev->chipID) - break; - } - if (id->numChipset == -1) { - instances[i].claimed = FALSE; - numClaimedInstances--; - xf86MsgVerb(X_WARNING, 0, "%s: ChipID 0x%04X in Device " - "section \"%s\" isn't valid for this driver\n", - driverName, instances[i].dev->chipID, - instances[i].dev->identifier); - } - else { - instances[i].chip = id->numChipset; - - xf86Msg(X_CONFIG, "ChipID override: 0x%04X\n", - instances[i].dev->chipID); - from = X_CONFIG; - } - } - else if (!instances[i].foundHW) { - /* - * This means that there was no override and the PCI chipType - * doesn't match one that is supported - */ - instances[i].claimed = FALSE; - numClaimedInstances--; - } - if (instances[i].claimed == TRUE) { - for (c = chipsets; c->token >= 0; c++) { - if (c->token == instances[i].chip) - break; - } - xf86Msg(from, "Chipset %s found\n", c->name); - } - } - - /* - * Of the claimed instances, check that another driver hasn't already - * claimed its slot. - */ - numFound = 0; - for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) { - if (!instances[i].claimed) - continue; - pPci = instances[i].pci; - - /* - * Allow the same entity to be used more than once for devices with - * multiple screens per entity. This assumes implicitly that there - * will be a screen == 0 instance. - * - * XXX Need to make sure that two different drivers don't claim - * the same screen > 0 instance. - */ - if (instances[i].screen == 0 && !xf86CheckPciSlot(pPci)) - continue; - - DebugF("%s: card at %d:%d:%d is claimed by a Device section\n", - driverName, pPci->bus, pPci->dev, pPci->func); - - /* Allocate an entry in the lists to be returned */ - numFound++; - retEntities = xnfreallocarray(retEntities, numFound, sizeof(int)); - retEntities[numFound - 1] = xf86ClaimPciSlot(pPci, drvp, - instances[i].chip, - instances[i].dev, - instances[i].dev->active); - if (retEntities[numFound - 1] == -1 && instances[i].screen > 0) { - for (j = 0; j < xf86NumEntities; j++) { - EntityPtr pEnt = xf86Entities[j]; - - if (pEnt->bus.type != BUS_PCI) - continue; - if (pEnt->bus.id.pci == pPci) { - retEntities[numFound - 1] = j; - xf86AddDevToEntity(j, instances[i].dev); - break; - } - } - } - } - free(instances); - if (numFound > 0) { - *foundEntities = retEntities; - } - - return numFound; -} - -/* - * xf86ConfigPciEntityInactive() -- This function can be used - * to configure an inactive entity as well as to reconfigure an - * previously active entity inactive. If the entity has been - * assigned to a screen before it will be removed. If p_chip is - * non-NULL all static resources listed there will be registered. - */ -static void -xf86ConfigPciEntityInactive(EntityInfoPtr pEnt, PciChipsets * p_chip, - EntityProc init, EntityProc enter, - EntityProc leave, void *private) -{ - ScrnInfoPtr pScrn; - - if ((pScrn = xf86FindScreenForEntity(pEnt->index))) - xf86RemoveEntityFromScreen(pScrn, pEnt->index); -} - -ScrnInfoPtr -xf86ConfigPciEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex, - PciChipsets * p_chip, void *dummy, EntityProc init, - EntityProc enter, EntityProc leave, void *private) -{ - EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex); - - if (dummy || init || enter || leave) - FatalError("Legacy entity access functions are unsupported\n"); - - if (!pEnt) - return pScrn; - - if (!(pEnt->location.type == BUS_PCI) - || !xf86GetPciInfoForEntity(entityIndex)) { - free(pEnt); - return pScrn; - } - if (!pEnt->active) { - xf86ConfigPciEntityInactive(pEnt, p_chip, init, enter, leave, private); - free(pEnt); - return pScrn; - } - - if (!pScrn) - pScrn = xf86AllocateScreen(pEnt->driver, scrnFlag); - if (xf86IsEntitySharable(entityIndex)) { - xf86SetEntityShared(entityIndex); - } - xf86AddEntityToScreen(pScrn, entityIndex); - if (xf86IsEntityShared(entityIndex)) { - return pScrn; - } - free(pEnt); - - return pScrn; -} - -void -xf86VideoPtrToDriverList(struct pci_device *dev, XF86MatchedDrivers *md) -{ - int i; - - /* Add more entries here if we ever return more than 4 drivers for - any device */ - const char *driverList[5] = { NULL, NULL, NULL, NULL, NULL }; - - switch (dev->vendor_id) { - /* AMD Geode LX */ - case 0x1022: - if (dev->device_id == 0x2081) - driverList[0] = "geode"; - break; - /* older Geode products acquired by AMD still carry an NSC vendor_id */ - case 0x100b: - if (dev->device_id == 0x0030) { - /* NSC Geode GX2 specifically */ - driverList[0] = "geode"; - /* GX2 support started its life in the NSC tree and was later - forked by AMD for GEODE so we keep it as a backup */ - driverList[1] = "nsc"; - } - else - /* other NSC variant e.g. 0x0104 (SC1400), 0x0504 (SCx200) */ - driverList[0] = "nsc"; - break; - /* Cyrix Geode GX1 */ - case 0x1078: - if (dev->device_id == 0x0104) - driverList[0] = "cyrix"; - break; - case 0x1142: - driverList[0] = "apm"; - break; - case 0xedd8: - driverList[0] = "ark"; - break; - case 0x1a03: - driverList[0] = "ast"; - break; - case 0x1002: - driverList[0] = "ati"; - break; - case 0x102c: - driverList[0] = "chips"; - break; - case 0x1013: - driverList[0] = "cirrus"; - break; - case 0x3d3d: - driverList[0] = "glint"; - break; - case 0x105d: - driverList[0] = "i128"; - break; - case 0x8086: - switch (dev->device_id) - { - /* Intel i740 */ - case 0x00d1: - case 0x7800: - driverList[0] = "i740"; - break; - /* GMA500/Poulsbo */ - case 0x8108: - case 0x8109: - /* Try psb driver on Poulsbo - if available */ - driverList[0] = "psb"; - driverList[1] = "psb_drv"; - break; - /* GMA600/Oaktrail */ - case 0x4100: - case 0x4101: - case 0x4102: - case 0x4103: - case 0x4104: - case 0x4105: - case 0x4106: - case 0x4107: - /* Atom E620/Oaktrail */ - case 0x4108: - /* Medfield */ - case 0x0130: - case 0x0131: - case 0x0132: - case 0x0133: - case 0x0134: - case 0x0135: - case 0x0136: - case 0x0137: - /* GMA 3600/CDV */ - case 0x0be0: - case 0x0be1: - case 0x0be2: - case 0x0be3: - case 0x0be4: - case 0x0be5: - case 0x0be6: - case 0x0be7: - case 0x0be8: - case 0x0be9: - case 0x0bea: - case 0x0beb: - case 0x0bec: - case 0x0bed: - case 0x0bee: - case 0x0bef: - /* Use fbdev/vesa driver on Oaktrail, Medfield, CDV */ - break; - default: - driverList[0] = "intel"; - break; - } - break; - case 0x102b: - driverList[0] = "mga"; - break; - case 0x10c8: - driverList[0] = "neomagic"; - break; - case 0x10de: - case 0x12d2: - { - int idx = 0; - -#if defined(__linux__) || defined(__NetBSD__) - driverList[idx++] = "nouveau"; -#endif - driverList[idx++] = "nv"; - break; - } - case 0x1106: - driverList[0] = "openchrome"; - break; - case 0x1b36: - driverList[0] = "qxl"; - break; - case 0x1163: - driverList[0] = "rendition"; - break; - case 0x5333: - switch (dev->device_id) { - case 0x88d0: - case 0x88d1: - case 0x88f0: - case 0x8811: - case 0x8812: - case 0x8814: - case 0x8901: - driverList[0] = "s3"; - break; - case 0x5631: - case 0x883d: - case 0x8a01: - case 0x8a10: - case 0x8c01: - case 0x8c03: - case 0x8904: - case 0x8a13: - driverList[0] = "s3virge"; - break; - default: - driverList[0] = "savage"; - break; - } - break; - case 0x1039: - driverList[0] = "sis"; - break; - case 0x126f: - driverList[0] = "siliconmotion"; - break; - case 0x121a: - if (dev->device_id < 0x0003) - driverList[0] = "voodoo"; - else - driverList[0] = "tdfx"; - break; - case 0x1011: - driverList[0] = "tga"; - break; - case 0x1023: - driverList[0] = "trident"; - break; - case 0x100c: - driverList[0] = "tseng"; - break; - case 0x80ee: - driverList[0] = "vboxvideo"; - break; - case 0x15ad: - driverList[0] = "vmware"; - break; - case 0x18ca: - if (dev->device_id == 0x47) - driverList[0] = "xgixp"; - else - driverList[0] = "xgi"; - break; - default: - break; - } - for (i = 0; driverList[i] != NULL; i++) { - xf86AddMatchedDriver(md, driverList[i]); - } -} - -#ifdef __linux__ -static int -xchomp(char *line) -{ - size_t len = 0; - - if (!line) { - return 1; - } - - len = strlen(line); - if (line[len - 1] == '\n' && len > 0) { - line[len - 1] = '\0'; - } - return 0; -} - -/* This function is used to provide a workaround for binary drivers that - * don't export their PCI ID's properly. If distros don't end up using this - * feature it can and should be removed because the symbol-based resolution - * scheme should be the primary one */ -void -xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip, - XF86MatchedDrivers *md) -{ - DIR *idsdir; - FILE *fp; - struct dirent *direntry; - char *line = NULL, *tmpMatch; - size_t len; - ssize_t read; - char path_name[512], vendor_str[5], chip_str[5]; - uint16_t vendor, chip; - int j; - - idsdir = opendir(PCI_TXT_IDS_PATH); - if (!idsdir) - return; - - xf86Msg(X_INFO, - "Scanning %s directory for additional PCI ID's supported by the drivers\n", - PCI_TXT_IDS_PATH); - direntry = readdir(idsdir); - /* Read the directory */ - while (direntry) { - if (direntry->d_name[0] == '.') { - direntry = readdir(idsdir); - continue; - } - len = strlen(direntry->d_name); - /* A tiny bit of sanity checking. We should probably do better */ - if (strncmp(&(direntry->d_name[len - 4]), ".ids", 4) == 0) { - /* We need the full path name to open the file */ - snprintf(path_name, sizeof(path_name), "%s/%s", - PCI_TXT_IDS_PATH, direntry->d_name); - fp = fopen(path_name, "r"); - if (fp == NULL) { - xf86Msg(X_ERROR, "Could not open %s for reading. Exiting.\n", - path_name); - goto end; - } - /* Read the file */ -#ifdef __GLIBC__ - while ((read = getline(&line, &len, fp)) != -1) { -#else - while ((line = fgetln(fp, &len)) != (char *) NULL) { -#endif /* __GLIBC __ */ - xchomp(line); - if (isdigit(line[0])) { - strlcpy(vendor_str, line, sizeof(vendor_str)); - vendor = (int) strtol(vendor_str, NULL, 16); - if ((strlen(&line[4])) == 0) { - chip_str[0] = '\0'; - chip = -1; - } - else { - /* Handle trailing whitespace */ - if (isspace(line[4])) { - chip_str[0] = '\0'; - chip = -1; - } - else { - /* Ok, it's a real ID */ - strlcpy(chip_str, &line[4], sizeof(chip_str)); - chip = (int) strtol(chip_str, NULL, 16); - } - } - if (vendor == match_vendor && chip == match_chip) { - tmpMatch = - (char *) malloc(sizeof(char) * - strlen(direntry->d_name) - 3); - if (!tmpMatch) { - xf86Msg(X_ERROR, - "Could not allocate space for the module name. Exiting.\n"); - goto end; - } - /* hack off the .ids suffix. This should guard - * against other problems, but it will end up - * taking off anything after the first '.' */ - for (j = 0; j < (strlen(direntry->d_name) - 3); j++) { - if (direntry->d_name[j] == '.') { - tmpMatch[j] = '\0'; - break; - } - else { - tmpMatch[j] = direntry->d_name[j]; - } - } - xf86AddMatchedDriver(md, tmpMatch); - xf86Msg(X_INFO, "Matched %s from file name %s\n", - tmpMatch, direntry->d_name); - free(tmpMatch); - } - } - else { - /* TODO Handle driver overrides here */ - } - } - fclose(fp); - } - direntry = readdir(idsdir); - } - end: - free(line); - closedir(idsdir); -} -#endif /* __linux__ */ - -void -xf86PciMatchDriver(XF86MatchedDrivers *md) -{ - struct pci_device *info = NULL; - struct pci_device_iterator *iter; - - /* Find the primary device, and get some information about it. */ - iter = pci_slot_match_iterator_create(NULL); - while ((info = pci_device_next(iter)) != NULL) { - if (xf86IsPrimaryPci(info)) { - break; - } - } - - pci_iterator_destroy(iter); -#ifdef __linux__ - if (info) - xf86MatchDriverFromFiles(info->vendor_id, info->device_id, md); -#endif - - if (info != NULL) { - xf86VideoPtrToDriverList(info, md); - } -} - -Bool -xf86PciConfigure(void *busData, struct pci_device *pDev) -{ - struct pci_device *pVideo = NULL; - - pVideo = (struct pci_device *) busData; - if (pDev && - (pDev->domain == pVideo->domain) && - (pDev->bus == pVideo->bus) && - (pDev->dev == pVideo->dev) && (pDev->func == pVideo->func)) - return 0; - - return 1; -} - -void -xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo, - GDevRec * GDev, int *chipset) -{ - char busnum[8]; - char *tmp; - - pVideo = (struct pci_device *) busData; - - snprintf(busnum, sizeof(busnum), "%d", pVideo->bus); - - XNFasprintf(&tmp, "PCI:%s:%d:%d", - busnum, pVideo->dev, pVideo->func); - GDev->busID = tmp; - - GDev->chipID = pVideo->device_id; - GDev->chipRev = pVideo->revision; - - if (*chipset < 0) - *chipset = (pVideo->vendor_id << 16) | pVideo->device_id; -} - -char * -DRICreatePCIBusID(const struct pci_device *dev) -{ - char *busID; - - if (asprintf(&busID, "pci:%04x:%02x:%02x.%d", - dev->domain, dev->bus, dev->dev, dev->func) == -1) - return NULL; - - return busID; -} diff --git a/hw/xfree86/common/xf86pciBus.h b/hw/xfree86/common/xf86pciBus.h deleted file mode 100644 index 14ae9760e..000000000 --- a/hw/xfree86/common/xf86pciBus.h +++ /dev/null @@ -1,57 +0,0 @@ - -/* - * Copyright (c) 1999-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _XF86_PCI_BUS_H -#define _XF86_PCI_BUS_H - -#include "xf86MatchDrivers.h" - -void xf86PciProbe(void); -Bool xf86PciAddMatchingDev(DriverPtr drvp); -Bool xf86PciProbeDev(DriverPtr drvp); -void xf86PciIsolateDevice(const char *argument); -void xf86PciMatchDriver(XF86MatchedDrivers *md); -Bool xf86PciConfigure(void *busData, struct pci_device *pDev); -void xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo, - GDevRec * GDev, int *chipset); - -#define MATCH_PCI_DEVICES(x, y) (((x)->domain == (y)->domain) && \ - ((x)->bus == (y)->bus) && \ - ((x)->func == (y)->func) && \ - ((x)->dev == (y)->dev)) - -void -xf86MatchDriverFromFiles(uint16_t match_vendor, uint16_t match_chip, - XF86MatchedDrivers *md); -void -xf86VideoPtrToDriverList(struct pci_device *dev, XF86MatchedDrivers *md); -#endif /* _XF86_PCI_BUS_H */ diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c deleted file mode 100644 index 45028f7a6..000000000 --- a/hw/xfree86/common/xf86platformBus.c +++ /dev/null @@ -1,771 +0,0 @@ -/* - * Copyright © 2012 Red Hat. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Dave Airlie - */ - -/* - * This file contains the interfaces to the bus-specific code - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifdef XSERVER_PLATFORM_BUS -#include - -#include -#include -#include -#include "os.h" -#include "hotplug.h" -#include "systemd-logind.h" - -#include "loaderProcs.h" -#include "xf86.h" -#include "xf86_OSproc.h" -#include "xf86Priv.h" -#include "xf86str.h" -#include "xf86Bus.h" -#include "Pci.h" -#include "xf86platformBus.h" -#include "xf86Config.h" -#include "xf86Crtc.h" - -#include "randrstr.h" -int platformSlotClaimed; - -int xf86_num_platform_devices; - -struct xf86_platform_device *xf86_platform_devices; - -int -xf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned) -{ - xf86_platform_devices = xnfreallocarray(xf86_platform_devices, - xf86_num_platform_devices + 1, - sizeof(struct xf86_platform_device)); - - xf86_platform_devices[xf86_num_platform_devices].attribs = attribs; - xf86_platform_devices[xf86_num_platform_devices].pdev = NULL; - xf86_platform_devices[xf86_num_platform_devices].flags = - unowned ? XF86_PDEV_UNOWNED : 0; - - xf86_num_platform_devices++; - return 0; -} - -int -xf86_remove_platform_device(int dev_index) -{ - int j; - - config_odev_free_attributes(xf86_platform_devices[dev_index].attribs); - - for (j = dev_index; j < xf86_num_platform_devices - 1; j++) - memcpy(&xf86_platform_devices[j], &xf86_platform_devices[j + 1], sizeof(struct xf86_platform_device)); - xf86_num_platform_devices--; - return 0; -} - -Bool -xf86_get_platform_device_unowned(int index) -{ - return (xf86_platform_devices[index].flags & XF86_PDEV_UNOWNED) ? - TRUE : FALSE; -} - -struct xf86_platform_device * -xf86_find_platform_device_by_devnum(int major, int minor) -{ - int i, attr_major, attr_minor; - - for (i = 0; i < xf86_num_platform_devices; i++) { - attr_major = xf86_platform_odev_attributes(i)->major; - attr_minor = xf86_platform_odev_attributes(i)->minor; - if (attr_major == major && attr_minor == minor) - return &xf86_platform_devices[i]; - } - return NULL; -} - -/* - * xf86IsPrimaryPlatform() -- return TRUE if primary device - * is a platform device and it matches this one. - */ - -static Bool -xf86IsPrimaryPlatform(struct xf86_platform_device *plat) -{ - /* Add max. 1 screen for the IgnorePrimary fallback path */ - if (xf86ProbeIgnorePrimary && xf86NumScreens == 0) - return TRUE; - - if (primaryBus.type == BUS_PLATFORM) - return plat == primaryBus.id.plat; -#ifdef XSERVER_LIBPCIACCESS - if (primaryBus.type == BUS_PCI) - if (plat->pdev) - if (MATCH_PCI_DEVICES(primaryBus.id.pci, plat->pdev)) - return TRUE; -#endif - return FALSE; -} - -static void -platform_find_pci_info(struct xf86_platform_device *pd, char *busid) -{ - struct pci_slot_match devmatch; - struct pci_device *info; - struct pci_device_iterator *iter; - int ret; - - ret = sscanf(busid, "pci:%04x:%02x:%02x.%u", - &devmatch.domain, &devmatch.bus, &devmatch.dev, - &devmatch.func); - if (ret != 4) - return; - - iter = pci_slot_match_iterator_create(&devmatch); - info = pci_device_next(iter); - if (info) - pd->pdev = info; - pci_iterator_destroy(iter); -} - -static Bool -xf86_check_platform_slot(const struct xf86_platform_device *pd) -{ - int i; - - for (i = 0; i < xf86NumEntities; i++) { - const EntityPtr u = xf86Entities[i]; - - if (pd->pdev && u->bus.type == BUS_PCI && - MATCH_PCI_DEVICES(pd->pdev, u->bus.id.pci)) { - return FALSE; - } - if ((u->bus.type == BUS_PLATFORM) && (pd == u->bus.id.plat)) { - return FALSE; - } - } - return TRUE; -} - -static Bool -MatchToken(const char *value, struct xorg_list *patterns, - int (*compare)(const char *, const char *)) -{ - const xf86MatchGroup *group; - - /* If there are no patterns, accept the match */ - if (xorg_list_is_empty(patterns)) - return TRUE; - - /* If there are patterns but no attribute, reject the match */ - if (!value) - return FALSE; - - /* - * Otherwise, iterate the list of patterns ensuring each entry has a - * match. Each list entry is a separate Match line of the same type. - */ - xorg_list_for_each_entry(group, patterns, entry) { - Bool match = FALSE; - char *const *cur; - - for (cur = group->values; *cur; cur++) { - if ((*compare)(value, *cur) == 0) { - match = TRUE; - break; - } - } - - if (!match) - return FALSE; - } - - /* All the entries in the list matched the attribute */ - return TRUE; -} - -static Bool -OutputClassMatches(const XF86ConfOutputClassPtr oclass, - struct xf86_platform_device *dev) -{ - char *driver = dev->attribs->driver; - - if (!MatchToken(driver, &oclass->match_driver, strcmp)) - return FALSE; - - return TRUE; -} - -static void -xf86OutputClassDriverList(int index, XF86MatchedDrivers *md) -{ - XF86ConfOutputClassPtr cl; - - for (cl = xf86configptr->conf_outputclass_lst; cl; cl = cl->list.next) { - if (OutputClassMatches(cl, &xf86_platform_devices[index])) { - char *path = xf86_platform_odev_attributes(index)->path; - - xf86Msg(X_INFO, "Applying OutputClass \"%s\" to %s\n", - cl->identifier, path); - xf86Msg(X_NONE, "\tloading driver: %s\n", cl->driver); - - xf86AddMatchedDriver(md, cl->driver); - } - } -} - -/** - * @return The numbers of found devices that match with the current system - * drivers. - */ -void -xf86PlatformMatchDriver(XF86MatchedDrivers *md) -{ - int i; - struct pci_device *info = NULL; - int pass = 0; - - for (pass = 0; pass < 2; pass++) { - for (i = 0; i < xf86_num_platform_devices; i++) { - - if (xf86IsPrimaryPlatform(&xf86_platform_devices[i]) && (pass == 1)) - continue; - else if (!xf86IsPrimaryPlatform(&xf86_platform_devices[i]) && (pass == 0)) - continue; - - xf86OutputClassDriverList(i, md); - - info = xf86_platform_devices[i].pdev; -#ifdef __linux__ - if (info) - xf86MatchDriverFromFiles(info->vendor_id, info->device_id, md); -#endif - - if (info != NULL) { - xf86VideoPtrToDriverList(info, md); - } - } - } -} - -int -xf86platformProbe(void) -{ - int i; - Bool pci = TRUE; - XF86ConfOutputClassPtr cl, cl_head = (xf86configptr) ? - xf86configptr->conf_outputclass_lst : NULL; - char *old_path, *path = NULL; - - config_odev_probe(xf86PlatformDeviceProbe); - - if (!xf86scanpci()) { - pci = FALSE; - } - - for (i = 0; i < xf86_num_platform_devices; i++) { - char *busid = xf86_platform_odev_attributes(i)->busid; - - if (pci && busid && (strncmp(busid, "pci:", 4) == 0)) { - platform_find_pci_info(&xf86_platform_devices[i], busid); - } - - /* - * Deal with OutputClass ModulePath directives, these must be - * processed before we do any module loading. - */ - for (cl = cl_head; cl; cl = cl->list.next) { - if (!OutputClassMatches(cl, &xf86_platform_devices[i])) - continue; - - if (cl->modulepath && xf86ModPathFrom != X_CMDLINE) { - old_path = path; - XNFasprintf(&path, "%s,%s", cl->modulepath, - path ? path : xf86ModulePath); - free(old_path); - xf86Msg(X_CONFIG, "OutputClass \"%s\" ModulePath extended to \"%s\"\n", - cl->identifier, path); - LoaderSetPath(path); - } - } - } - - free(path); - - /* First see if there is an OutputClass match marking a device as primary */ - for (i = 0; i < xf86_num_platform_devices; i++) { - struct xf86_platform_device *dev = &xf86_platform_devices[i]; - for (cl = cl_head; cl; cl = cl->list.next) { - if (!OutputClassMatches(cl, dev)) - continue; - - if (xf86CheckBoolOption(cl->option_lst, "PrimaryGPU", FALSE)) { - xf86Msg(X_CONFIG, "OutputClass \"%s\" setting %s as PrimaryGPU\n", - cl->identifier, dev->attribs->path); - primaryBus.type = BUS_PLATFORM; - primaryBus.id.plat = dev; - return 0; - } - } - } - - /* Then check for pci_device_is_boot_vga() */ - for (i = 0; i < xf86_num_platform_devices; i++) { - struct xf86_platform_device *dev = &xf86_platform_devices[i]; - - if (!dev->pdev) - continue; - - pci_device_probe(dev->pdev); - if (pci_device_is_boot_vga(dev->pdev)) { - primaryBus.type = BUS_PLATFORM; - primaryBus.id.plat = dev; - } - } - - return 0; -} - -void -xf86MergeOutputClassOptions(int entityIndex, void **options) -{ - const EntityPtr entity = xf86Entities[entityIndex]; - struct xf86_platform_device *dev = NULL; - XF86ConfOutputClassPtr cl; - XF86OptionPtr classopts; - int i = 0; - - switch (entity->bus.type) { - case BUS_PLATFORM: - dev = entity->bus.id.plat; - break; - case BUS_PCI: - for (i = 0; i < xf86_num_platform_devices; i++) { - if (xf86_platform_devices[i].pdev) { - if (MATCH_PCI_DEVICES(xf86_platform_devices[i].pdev, - entity->bus.id.pci)) { - dev = &xf86_platform_devices[i]; - break; - } - } - } - break; - default: - xf86Msg(X_DEBUG, "xf86MergeOutputClassOptions unsupported bus type %d\n", - entity->bus.type); - } - - if (!dev) - return; - - for (cl = xf86configptr->conf_outputclass_lst; cl; cl = cl->list.next) { - if (!OutputClassMatches(cl, dev) || !cl->option_lst) - continue; - - xf86Msg(X_INFO, "Applying OutputClass \"%s\" options to %s\n", - cl->identifier, dev->attribs->path); - - classopts = xf86optionListDup(cl->option_lst); - *options = xf86optionListMerge(*options, classopts); - } -} - -static int -xf86ClaimPlatformSlot(struct xf86_platform_device * d, DriverPtr drvp, - int chipset, GDevPtr dev, Bool active) -{ - EntityPtr p = NULL; - int num; - - if (xf86_check_platform_slot(d)) { - num = xf86AllocateEntity(); - p = xf86Entities[num]; - p->driver = drvp; - p->chipset = chipset; - p->bus.type = BUS_PLATFORM; - p->bus.id.plat = d; - p->active = active; - p->inUse = FALSE; - if (dev) - xf86AddDevToEntity(num, dev); - - platformSlotClaimed++; - return num; - } - else - return -1; -} - -static int -xf86UnclaimPlatformSlot(struct xf86_platform_device *d, GDevPtr dev) -{ - int i; - - for (i = 0; i < xf86NumEntities; i++) { - const EntityPtr p = xf86Entities[i]; - - if ((p->bus.type == BUS_PLATFORM) && (p->bus.id.plat == d)) { - if (dev) - xf86RemoveDevFromEntity(i, dev); - platformSlotClaimed--; - p->bus.type = BUS_NONE; - return 0; - } - } - return 0; -} - - -#define END_OF_MATCHES(m) \ - (((m).vendor_id == 0) && ((m).device_id == 0) && ((m).subvendor_id == 0)) - -static Bool doPlatformProbe(struct xf86_platform_device *dev, DriverPtr drvp, - GDevPtr gdev, int flags, intptr_t match_data) -{ - Bool foundScreen = FALSE; - int entity; - - if (gdev && gdev->screen == 0 && !xf86_check_platform_slot(dev)) - return FALSE; - - entity = xf86ClaimPlatformSlot(dev, drvp, 0, - gdev, gdev ? gdev->active : 0); - - if ((entity == -1) && gdev && (gdev->screen > 0)) { - unsigned nent; - - for (nent = 0; nent < xf86NumEntities; nent++) { - EntityPtr pEnt = xf86Entities[nent]; - - if (pEnt->bus.type != BUS_PLATFORM) - continue; - if (pEnt->bus.id.plat == dev) { - entity = nent; - xf86AddDevToEntity(nent, gdev); - break; - } - } - } - if (entity != -1) { - if ((dev->flags & XF86_PDEV_SERVER_FD) && (!drvp->driverFunc || - !drvp->driverFunc(NULL, SUPPORTS_SERVER_FDS, NULL))) { - systemd_logind_release_fd(dev->attribs->major, dev->attribs->minor, dev->attribs->fd); - dev->attribs->fd = -1; - dev->flags &= ~XF86_PDEV_SERVER_FD; - } - - if (drvp->platformProbe(drvp, entity, flags, dev, match_data)) - foundScreen = TRUE; - else - xf86UnclaimPlatformSlot(dev, gdev); - } - return foundScreen; -} - -static Bool -probeSingleDevice(struct xf86_platform_device *dev, DriverPtr drvp, GDevPtr gdev, int flags) -{ - int k; - Bool foundScreen = FALSE; - struct pci_device *pPci; - const struct pci_id_match *const devices = drvp->supported_devices; - - if (dev->pdev && devices) { - int device_id = dev->pdev->device_id; - pPci = dev->pdev; - for (k = 0; !END_OF_MATCHES(devices[k]); k++) { - if (PCI_ID_COMPARE(devices[k].vendor_id, pPci->vendor_id) - && PCI_ID_COMPARE(devices[k].device_id, device_id) - && ((devices[k].device_class_mask & pPci->device_class) - == devices[k].device_class)) { - foundScreen = doPlatformProbe(dev, drvp, gdev, flags, devices[k].match_data); - if (foundScreen) - break; - } - } - } - else if (dev->pdev && !devices) - return FALSE; - else - foundScreen = doPlatformProbe(dev, drvp, gdev, flags, 0); - return foundScreen; -} - -static Bool -isGPUDevice(GDevPtr gdev) -{ - int i; - - for (i = 0; i < gdev->myScreenSection->num_gpu_devices; i++) { - if (gdev == gdev->myScreenSection->gpu_devices[i]) - return TRUE; - } - - return FALSE; -} - -int -xf86platformProbeDev(DriverPtr drvp) -{ - Bool foundScreen = FALSE; - GDevPtr *devList; - const unsigned numDevs = xf86MatchDevice(drvp->driverName, &devList); - int i, j; - - /* find the main device or any device specified in xorg.conf */ - for (i = 0; i < numDevs; i++) { - const char *devpath; - - /* skip inactive devices */ - if (!devList[i]->active) - continue; - - /* This is specific to modesetting. */ - devpath = xf86FindOptionValue(devList[i]->options, "kmsdev"); - - for (j = 0; j < xf86_num_platform_devices; j++) { - if (devpath && *devpath) { - if (strcmp(xf86_platform_devices[j].attribs->path, devpath) == 0) - break; - } else if (devList[i]->busID && *devList[i]->busID) { - if (xf86PlatformDeviceCheckBusID(&xf86_platform_devices[j], devList[i]->busID)) - break; - } - else { - /* for non-seat0 servers assume first device is the master */ - if (ServerIsNotSeat0()) { - break; - } else { - /* Accept the device if the driver is simpledrm */ - if (strcmp(xf86_platform_devices[j].attribs->driver, "simpledrm") == 0) - break; - } - - if (xf86IsPrimaryPlatform(&xf86_platform_devices[j])) - break; - } - } - - if (j == xf86_num_platform_devices) - continue; - - foundScreen = probeSingleDevice(&xf86_platform_devices[j], drvp, devList[i], - isGPUDevice(devList[i]) ? PLATFORM_PROBE_GPU_SCREEN : 0); - } - - free(devList); - - return foundScreen; -} - -int -xf86platformAddGPUDevices(DriverPtr drvp) -{ - Bool foundScreen = FALSE; - GDevPtr *devList; - int j; - - if (!drvp->platformProbe) - return FALSE; - - xf86MatchDevice(drvp->driverName, &devList); - - /* if autoaddgpu devices is enabled then go find any unclaimed platform - * devices and add them as GPU screens */ - if (xf86Info.autoAddGPU) { - for (j = 0; j < xf86_num_platform_devices; j++) { - if (probeSingleDevice(&xf86_platform_devices[j], drvp, - devList ? devList[0] : NULL, - PLATFORM_PROBE_GPU_SCREEN)) - foundScreen = TRUE; - } - } - - free(devList); - - return foundScreen; -} - -int -xf86platformAddDevice(int index) -{ - int i, old_screens, scr_index, scrnum; - DriverPtr drvp = NULL; - screenLayoutPtr layout; - static const char *hotplug_driver_name = "modesetting"; - - if (!xf86Info.autoAddGPU) - return -1; - - /* force load the driver for now */ - xf86LoadOneModule(hotplug_driver_name, NULL); - - for (i = 0; i < xf86NumDrivers; i++) { - if (!xf86DriverList[i]) - continue; - - if (!strcmp(xf86DriverList[i]->driverName, hotplug_driver_name)) { - drvp = xf86DriverList[i]; - break; - } - } - if (i == xf86NumDrivers) - return -1; - - old_screens = xf86NumGPUScreens; - doPlatformProbe(&xf86_platform_devices[index], drvp, NULL, - PLATFORM_PROBE_GPU_SCREEN, 0); - if (old_screens == xf86NumGPUScreens) - return -1; - i = old_screens; - - for (layout = xf86ConfigLayout.screens; layout->screen != NULL; - layout++) { - xf86GPUScreens[i]->confScreen = layout->screen; - break; - } - - if (xf86GPUScreens[i]->PreInit && - xf86GPUScreens[i]->PreInit(xf86GPUScreens[i], 0)) - xf86GPUScreens[i]->configured = TRUE; - - if (!xf86GPUScreens[i]->configured) { - ErrorF("hotplugged device %d didn't configure\n", i); - xf86DeleteScreen(xf86GPUScreens[i]); - return -1; - } - - scr_index = AddGPUScreen(xf86GPUScreens[i]->ScreenInit, 0, NULL); - if (scr_index == -1) { - xf86DeleteScreen(xf86GPUScreens[i]); - xf86UnclaimPlatformSlot(&xf86_platform_devices[index], NULL); - xf86NumGPUScreens = old_screens; - return -1; - } - dixSetPrivate(&xf86GPUScreens[i]->pScreen->devPrivates, - xf86ScreenKey, xf86GPUScreens[i]); - - CreateScratchPixmapsForScreen(xf86GPUScreens[i]->pScreen); - - if (xf86GPUScreens[i]->pScreen->CreateScreenResources && - !(*xf86GPUScreens[i]->pScreen->CreateScreenResources) (xf86GPUScreens[i]->pScreen)) { - RemoveGPUScreen(xf86GPUScreens[i]->pScreen); - xf86DeleteScreen(xf86GPUScreens[i]); - xf86UnclaimPlatformSlot(&xf86_platform_devices[index], NULL); - xf86NumGPUScreens = old_screens; - return -1; - } - /* attach unbound to the configured protocol screen (or 0) */ - scrnum = xf86GPUScreens[i]->confScreen->screennum; - AttachUnboundGPU(xf86Screens[scrnum]->pScreen, xf86GPUScreens[i]->pScreen); - if (xf86Info.autoBindGPU) - RRProviderAutoConfigGpuScreen(xf86ScrnToScreen(xf86GPUScreens[i]), - xf86ScrnToScreen(xf86Screens[scrnum])); - - RRResourcesChanged(xf86Screens[scrnum]->pScreen); - RRTellChanged(xf86Screens[scrnum]->pScreen); - - return 0; -} - -void -xf86platformRemoveDevice(int index) -{ - EntityPtr entity; - int ent_num, i, j, scrnum; - Bool found; - - for (ent_num = 0; ent_num < xf86NumEntities; ent_num++) { - entity = xf86Entities[ent_num]; - if (entity->bus.type == BUS_PLATFORM && - entity->bus.id.plat == &xf86_platform_devices[index]) - break; - } - if (ent_num == xf86NumEntities) - goto out; - - found = FALSE; - for (i = 0; i < xf86NumGPUScreens; i++) { - for (j = 0; j < xf86GPUScreens[i]->numEntities; j++) - if (xf86GPUScreens[i]->entityList[j] == ent_num) { - found = TRUE; - break; - } - if (found) - break; - } - if (!found) { - ErrorF("failed to find screen to remove\n"); - goto out; - } - - scrnum = xf86GPUScreens[i]->confScreen->screennum; - - xf86GPUScreens[i]->pScreen->CloseScreen(xf86GPUScreens[i]->pScreen); - - RemoveGPUScreen(xf86GPUScreens[i]->pScreen); - xf86DeleteScreen(xf86GPUScreens[i]); - - xf86UnclaimPlatformSlot(&xf86_platform_devices[index], NULL); - - xf86_remove_platform_device(index); - - RRResourcesChanged(xf86Screens[scrnum]->pScreen); - RRTellChanged(xf86Screens[scrnum]->pScreen); - out: - return; -} - -/* called on return from VT switch to find any new devices */ -void xf86platformVTProbe(void) -{ - int i; - - for (i = 0; i < xf86_num_platform_devices; i++) { - if (!(xf86_platform_devices[i].flags & XF86_PDEV_UNOWNED)) - continue; - - xf86_platform_devices[i].flags &= ~XF86_PDEV_UNOWNED; - xf86PlatformReprobeDevice(i, xf86_platform_devices[i].attribs); - } -} - -void xf86platformPrimary(void) -{ - /* use the first platform device as a fallback */ - if (primaryBus.type == BUS_NONE) { - xf86Msg(X_INFO, "no primary bus or device found\n"); - - if (xf86_num_platform_devices > 0) { - primaryBus.id.plat = &xf86_platform_devices[0]; - primaryBus.type = BUS_PLATFORM; - - xf86Msg(X_NONE, "\tfalling back to %s\n", primaryBus.id.plat->attribs->syspath); - } - } -} -#endif diff --git a/hw/xfree86/common/xf86platformBus.h b/hw/xfree86/common/xf86platformBus.h deleted file mode 100644 index 1e75e6352..000000000 --- a/hw/xfree86/common/xf86platformBus.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright © 2012 Red Hat. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Dave Airlie - */ -#ifndef XF86_PLATFORM_BUS_H -#define XF86_PLATFORM_BUS_H - -#include "hotplug.h" -#include "xf86MatchDrivers.h" - -struct xf86_platform_device { - struct OdevAttributes *attribs; - /* for PCI devices */ - struct pci_device *pdev; - int flags; -}; - -/* xf86_platform_device flags */ -#define XF86_PDEV_UNOWNED 0x01 -#define XF86_PDEV_SERVER_FD 0x02 -#define XF86_PDEV_PAUSED 0x04 - -#ifdef XSERVER_PLATFORM_BUS -int xf86platformProbe(void); -int xf86platformProbeDev(DriverPtr drvp); -int xf86platformAddGPUDevices(DriverPtr drvp); -void xf86MergeOutputClassOptions(int entityIndex, void **options); - -extern int xf86_num_platform_devices; -extern struct xf86_platform_device *xf86_platform_devices; - -extern int -xf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned); -extern int -xf86_remove_platform_device(int dev_index); -extern Bool -xf86_get_platform_device_unowned(int index); - -extern int -xf86platformAddDevice(int index); -extern void -xf86platformRemoveDevice(int index); - -static inline struct OdevAttributes * -xf86_platform_device_odev_attributes(struct xf86_platform_device *device) -{ - return device->attribs; -} - -static inline struct OdevAttributes * -xf86_platform_odev_attributes(int index) -{ - struct xf86_platform_device *device = &xf86_platform_devices[index]; - - return device->attribs; -} - -#ifndef _XORG_CONFIG_H_ -/* - * Define the legacy API only for external builds - */ - -/* path to kernel device node - Linux e.g. /dev/dri/card0 */ -#define ODEV_ATTRIB_PATH 1 -/* system device path - Linux e.g. /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card1 */ -#define ODEV_ATTRIB_SYSPATH 2 -/* DRI-style bus id */ -#define ODEV_ATTRIB_BUSID 3 -/* Server managed FD */ -#define ODEV_ATTRIB_FD 4 -/* Major number of the device node pointed to by ODEV_ATTRIB_PATH */ -#define ODEV_ATTRIB_MAJOR 5 -/* Minor number of the device node pointed to by ODEV_ATTRIB_PATH */ -#define ODEV_ATTRIB_MINOR 6 -/* kernel driver name */ -#define ODEV_ATTRIB_DRIVER 7 - -/* Protect against a mismatch attribute type by generating a compiler - * error using a negative array size when an incorrect attribute is - * passed - */ - -#define _ODEV_ATTRIB_IS_STRING(x) ((x) == ODEV_ATTRIB_PATH || \ - (x) == ODEV_ATTRIB_SYSPATH || \ - (x) == ODEV_ATTRIB_BUSID || \ - (x) == ODEV_ATTRIB_DRIVER) - -#define _ODEV_ATTRIB_STRING_CHECK(x) ((int (*)[_ODEV_ATTRIB_IS_STRING(x)-1]) 0) - -static inline char * -_xf86_get_platform_device_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0]) -{ - switch (attrib) { - case ODEV_ATTRIB_PATH: - return xf86_platform_device_odev_attributes(device)->path; - case ODEV_ATTRIB_SYSPATH: - return xf86_platform_device_odev_attributes(device)->syspath; - case ODEV_ATTRIB_BUSID: - return xf86_platform_device_odev_attributes(device)->busid; - case ODEV_ATTRIB_DRIVER: - return xf86_platform_device_odev_attributes(device)->driver; - default: - assert(FALSE); - return NULL; - } -} - -#define xf86_get_platform_device_attrib(device, attrib) _xf86_get_platform_device_attrib(device,attrib,_ODEV_ATTRIB_STRING_CHECK(attrib)) - -#define _ODEV_ATTRIB_IS_INT(x) ((x) == ODEV_ATTRIB_FD || (x) == ODEV_ATTRIB_MAJOR || (x) == ODEV_ATTRIB_MINOR) -#define _ODEV_ATTRIB_INT_DEFAULT(x) ((x) == ODEV_ATTRIB_FD ? -1 : 0) -#define _ODEV_ATTRIB_DEFAULT_CHECK(x,def) (_ODEV_ATTRIB_INT_DEFAULT(x) == (def)) -#define _ODEV_ATTRIB_INT_CHECK(x,def) ((int (*)[_ODEV_ATTRIB_IS_INT(x)*_ODEV_ATTRIB_DEFAULT_CHECK(x,def)-1]) 0) - -static inline int -_xf86_get_platform_device_int_attrib(struct xf86_platform_device *device, int attrib, int (*fake)[0]) -{ - switch (attrib) { - case ODEV_ATTRIB_FD: - return xf86_platform_device_odev_attributes(device)->fd; - case ODEV_ATTRIB_MAJOR: - return xf86_platform_device_odev_attributes(device)->major; - case ODEV_ATTRIB_MINOR: - return xf86_platform_device_odev_attributes(device)->minor; - default: - assert(FALSE); - return 0; - } -} - -#define xf86_get_platform_device_int_attrib(device, attrib, def) _xf86_get_platform_device_int_attrib(device,attrib,_ODEV_ATTRIB_INT_CHECK(attrib,def)) - -#endif - -extern _X_EXPORT Bool -xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid); - -extern _X_EXPORT void -xf86PlatformMatchDriver(XF86MatchedDrivers *); - -extern void xf86platformVTProbe(void); -extern void xf86platformPrimary(void); - -#else - -static inline int xf86platformAddGPUDevices(DriverPtr drvp) { return FALSE; } -static inline void xf86MergeOutputClassOptions(int index, void **options) {} - -#endif - -#endif diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c deleted file mode 100644 index 119211dc5..000000000 --- a/hw/xfree86/common/xf86sbusBus.c +++ /dev/null @@ -1,757 +0,0 @@ -/* - * SBUS bus-specific code. - * - * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * JAKUB JELINEK 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. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86cmap.h" - -#include "xf86Bus.h" - -#include "xf86sbusBus.h" -#include "xf86Sbus.h" - -Bool sbusSlotClaimed = FALSE; - -static int xf86nSbusInfo; - -static void -CheckSbusDevice(const char *device, int fbNum) -{ - int fd, i; - struct fbgattr fbattr; - sbusDevicePtr psdp; - - fd = open(device, O_RDONLY, 0); - if (fd < 0) - return; - memset(&fbattr, 0, sizeof(fbattr)); - if (ioctl(fd, FBIOGATTR, &fbattr) < 0) { - if (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0) { - close(fd); - return; - } - } - close(fd); - for (i = 0; sbusDeviceTable[i].devId; i++) - if (sbusDeviceTable[i].fbType == fbattr.fbtype.fb_type) - break; - if (!sbusDeviceTable[i].devId) - return; - xf86SbusInfo = - xnfreallocarray(xf86SbusInfo, ++xf86nSbusInfo + 1, sizeof(psdp)); - xf86SbusInfo[xf86nSbusInfo] = NULL; - xf86SbusInfo[xf86nSbusInfo - 1] = psdp = xnfcalloc(sizeof(sbusDevice), 1); - psdp->devId = sbusDeviceTable[i].devId; - psdp->fbNum = fbNum; - psdp->device = xnfstrdup(device); - psdp->width = fbattr.fbtype.fb_width; - psdp->height = fbattr.fbtype.fb_height; - psdp->fd = -1; -} - -void -xf86SbusProbe(void) -{ - int i, useProm = 0; - char fbDevName[32]; - sbusDevicePtr psdp, *psdpp; - - xf86SbusInfo = malloc(sizeof(psdp)); - *xf86SbusInfo = NULL; - for (i = 0; i < 32; i++) { - snprintf(fbDevName, sizeof(fbDevName), "/dev/fb%d", i); - CheckSbusDevice(fbDevName, i); - } - if (sparcPromInit() >= 0) { - useProm = 1; - sparcPromAssignNodes(); - } - for (psdpp = xf86SbusInfo; (psdp = *psdpp); psdpp++) { - for (i = 0; sbusDeviceTable[i].devId; i++) - if (sbusDeviceTable[i].devId == psdp->devId) - psdp->descr = sbusDeviceTable[i].descr; - /* - * If we can use PROM information and found the PROM node for this - * device, we can tell more about the card. - */ - if (useProm && psdp->node.node) { - char *prop, *promPath; - int len, chiprev, vmsize; - - switch (psdp->devId) { - case SBUS_DEVICE_MGX: - prop = sparcPromGetProperty(&psdp->node, "fb_size", &len); - if (prop && len == 4 && *(int *) prop == 0x400000) - psdp->descr = "Quantum 3D MGXplus with 4M VRAM"; - break; - case SBUS_DEVICE_CG6: - chiprev = 0; - vmsize = 0; - prop = sparcPromGetProperty(&psdp->node, "chiprev", &len); - if (prop && len == 4) - chiprev = *(int *) prop; - prop = sparcPromGetProperty(&psdp->node, "vmsize", &len); - if (prop && len == 4) - vmsize = *(int *) prop; - switch (chiprev) { - case 1: - case 2: - case 3: - case 4: - psdp->descr = "Sun Double width GX"; - break; - case 5: - case 6: - case 7: - case 8: - case 9: - psdp->descr = "Sun Single width GX"; - break; - case 11: - switch (vmsize) { - case 2: - psdp->descr = "Sun Turbo GX with 1M VSIMM"; - break; - case 4: - psdp->descr = "Sun Turbo GX Plus"; - break; - default: - psdp->descr = "Sun Turbo GX"; - break; - } - } - break; - case SBUS_DEVICE_CG14: - prop = sparcPromGetProperty(&psdp->node, "reg", &len); - vmsize = 0; - if (prop && !(len % 12) && len > 0) - vmsize = *(int *) (prop + len - 4); - switch (vmsize) { - case 0x400000: - psdp->descr = "Sun SX with 4M VSIMM"; - break; - case 0x800000: - psdp->descr = "Sun SX with 8M VSIMM"; - break; - } - break; - case SBUS_DEVICE_LEO: - prop = sparcPromGetProperty(&psdp->node, "model", &len); - if (prop && len > 0 && !strstr(prop, "501-2503")) - psdp->descr = "Sun Turbo ZX"; - break; - case SBUS_DEVICE_TCX: - if (sparcPromGetBool(&psdp->node, "tcx-8-bit")) - psdp->descr = "Sun TCX (8bit)"; - else - psdp->descr = "Sun TCX (S24)"; - break; - case SBUS_DEVICE_FFB: - prop = sparcPromGetProperty(&psdp->node, "name", &len); - chiprev = 0; - prop = sparcPromGetProperty(&psdp->node, "board_type", &len); - if (prop && len == 4) - chiprev = *(int *) prop; - if (strstr(prop, "afb")) { - if (chiprev == 3) - psdp->descr = "Sun|Elite3D-M6 Horizontal"; - } - else { - switch (chiprev) { - case 0x08: - psdp->descr = "Sun FFB 67MHz Creator"; - break; - case 0x0b: - psdp->descr = "Sun FFB 67MHz Creator 3D"; - break; - case 0x1b: - psdp->descr = "Sun FFB 75MHz Creator 3D"; - break; - case 0x20: - case 0x28: - psdp->descr = "Sun FFB2 Vertical Creator"; - break; - case 0x23: - case 0x2b: - psdp->descr = "Sun FFB2 Vertical Creator 3D"; - break; - case 0x30: - psdp->descr = "Sun FFB2+ Vertical Creator"; - break; - case 0x33: - psdp->descr = "Sun FFB2+ Vertical Creator 3D"; - break; - case 0x40: - case 0x48: - psdp->descr = "Sun FFB2 Horizontal Creator"; - break; - case 0x43: - case 0x4b: - psdp->descr = "Sun FFB2 Horizontal Creator 3D"; - break; - } - } - break; - } - - xf86Msg(X_PROBED, "SBUS:(0x%08x) %s", psdp->node.node, psdp->descr); - promPath = sparcPromNode2Pathname(&psdp->node); - if (promPath) { - xf86ErrorF(" at %s", promPath); - free(promPath); - } - } - else - xf86Msg(X_PROBED, "SBUS: %s", psdp->descr); - xf86ErrorF("\n"); - } - if (useProm) - sparcPromClose(); -} - -/* - * Parse a BUS ID string, and return the SBUS bus parameters if it was - * in the correct format for a SBUS bus id. - */ - -Bool -xf86ParseSbusBusString(const char *busID, int *fbNum) -{ - /* - * The format is assumed to be one of: - * "fbN", e.g. "fb1", which means the device corresponding to /dev/fbN - * "nameN", e.g. "cgsix0", which means Nth instance of card NAME - * "/prompath", e.g. "/sbus@0,10001000/cgsix@3,0" which is PROM pathname - * to the device. - */ - - const char *id; - int i, len; - - if (StringToBusType(busID, &id) != BUS_SBUS) - return FALSE; - - if (*id != '/') { - if (!strncmp(id, "fb", 2)) { - if (!isdigit(id[2])) - return FALSE; - *fbNum = atoi(id + 2); - return TRUE; - } - else { - sbusDevicePtr *psdpp; - int devId; - - for (i = 0, len = 0; sbusDeviceTable[i].devId; i++) { - len = strlen(sbusDeviceTable[i].promName); - if (!strncmp(sbusDeviceTable[i].promName, id, len) - && isdigit(id[len])) - break; - } - devId = sbusDeviceTable[i].devId; - if (!devId) - return FALSE; - i = atoi(id + len); - for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) { - if ((*psdpp)->devId != devId) - continue; - if (!i) { - *fbNum = (*psdpp)->fbNum; - return TRUE; - } - i--; - } - } - return FALSE; - } - - if (sparcPromInit() >= 0) { - i = sparcPromPathname2Node(id); - sparcPromClose(); - if (i) { - sbusDevicePtr *psdpp; - - for (psdpp = xf86SbusInfo; *psdpp; ++psdpp) { - if ((*psdpp)->node.node == i) { - *fbNum = (*psdpp)->fbNum; - return TRUE; - } - } - } - } - return FALSE; -} - -/* - * Compare a BUS ID string with a SBUS bus id. Return TRUE if they match. - */ - -Bool -xf86CompareSbusBusString(const char *busID, int fbNum) -{ - int iFbNum; - - if (xf86ParseSbusBusString(busID, &iFbNum)) { - return fbNum == iFbNum; - } - else { - return FALSE; - } -} - -/* - * Check if the slot requested is free. If it is already in use, return FALSE. - */ - -Bool -xf86CheckSbusSlot(int fbNum) -{ - int i; - EntityPtr p; - - for (i = 0; i < xf86NumEntities; i++) { - p = xf86Entities[i]; - /* Check if this SBUS slot is taken */ - if (p->bus.type == BUS_SBUS && p->bus.id.sbus.fbNum == fbNum) - return FALSE; - } - - return TRUE; -} - -/* - * If the slot requested is already in use, return -1. - * Otherwise, claim the slot for the screen requesting it. - */ - -int -xf86ClaimSbusSlot(sbusDevicePtr psdp, DriverPtr drvp, GDevPtr dev, Bool active) -{ - EntityPtr p = NULL; - - int num; - - if (xf86CheckSbusSlot(psdp->fbNum)) { - num = xf86AllocateEntity(); - p = xf86Entities[num]; - p->driver = drvp; - p->chipset = -1; - p->bus.type = BUS_SBUS; - xf86AddDevToEntity(num, dev); - p->bus.id.sbus.fbNum = psdp->fbNum; - p->active = active; - p->inUse = FALSE; - sbusSlotClaimed = TRUE; - return num; - } - else - return -1; -} - -int -xf86MatchSbusInstances(const char *driverName, int sbusDevId, - GDevPtr * devList, int numDevs, DriverPtr drvp, - int **foundEntities) -{ - int i, j; - sbusDevicePtr psdp, *psdpp; - int numClaimedInstances = 0; - int allocatedInstances = 0; - int numFound = 0; - GDevPtr devBus = NULL; - GDevPtr dev = NULL; - int *retEntities = NULL; - int useProm = 0; - - struct Inst { - sbusDevicePtr sbus; - GDevPtr dev; - Bool claimed; /* BusID matches with a device section */ - } *instances = NULL; - - *foundEntities = NULL; - for (psdpp = xf86SbusInfo, psdp = *psdpp; psdp; psdp = *++psdpp) { - if (psdp->devId != sbusDevId) - continue; - if (psdp->fd == -2) - continue; - ++allocatedInstances; - instances = xnfreallocarray(instances, - allocatedInstances, sizeof(struct Inst)); - instances[allocatedInstances - 1].sbus = psdp; - instances[allocatedInstances - 1].dev = NULL; - instances[allocatedInstances - 1].claimed = FALSE; - numFound++; - } - - /* - * This may be debatable, but if no SBUS devices with a matching vendor - * type is found, return zero now. It is probably not desirable to - * allow the config file to override this. - */ - if (allocatedInstances <= 0) { - free(instances); - return 0; - } - - if (sparcPromInit() >= 0) - useProm = 1; - - if (xf86DoConfigure && xf86DoConfigurePass1) { - GDevPtr pGDev; - int actualcards = 0; - - for (i = 0; i < allocatedInstances; i++) { - actualcards++; - pGDev = xf86AddBusDeviceToConfigure(drvp->driverName, BUS_SBUS, - instances[i].sbus, -1); - if (pGDev) { - /* - * XF86Match???Instances() treat chipID and chipRev as - * overrides, so clobber them here. - */ - pGDev->chipID = pGDev->chipRev = -1; - } - } - free(instances); - if (useProm) - sparcPromClose(); - return actualcards; - } - - DebugF("%s instances found: %d\n", driverName, allocatedInstances); - - for (i = 0; i < allocatedInstances; i++) { - char *promPath = NULL; - - psdp = instances[i].sbus; - devBus = NULL; - dev = NULL; - if (useProm && psdp->node.node) - promPath = sparcPromNode2Pathname(&psdp->node); - - for (j = 0; j < numDevs; j++) { - if (devList[j]->busID && *devList[j]->busID) { - if (xf86CompareSbusBusString(devList[j]->busID, psdp->fbNum)) { - if (devBus) - xf86MsgVerb(X_WARNING, 0, - "%s: More than one matching Device section for " - "instance (BusID: %s) found: %s\n", - driverName, devList[j]->identifier, - devList[j]->busID); - else - devBus = devList[j]; - } - } - else { - if (!dev && !devBus) { - if (promPath) - xf86Msg(X_PROBED, - "Assigning device section with no busID to SBUS:%s\n", - promPath); - else - xf86Msg(X_PROBED, - "Assigning device section with no busID to SBUS:fb%d\n", - psdp->fbNum); - dev = devList[j]; - } - else - xf86MsgVerb(X_WARNING, 0, - "%s: More than one matching Device section " - "found: %s\n", driverName, - devList[j]->identifier); - } - } - if (devBus) - dev = devBus; /* busID preferred */ - if (!dev && psdp->fd != -2) { - if (promPath) { - xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " - "for instance (BusID SBUS:%s) found\n", - driverName, promPath); - } - else - xf86MsgVerb(X_WARNING, 0, "%s: No matching Device section " - "for instance (BusID SBUS:fb%d) found\n", - driverName, psdp->fbNum); - } - else if (dev) { - numClaimedInstances++; - instances[i].claimed = TRUE; - instances[i].dev = dev; - } - free(promPath); - } - - DebugF("%s instances found: %d\n", driverName, numClaimedInstances); - - /* - * Of the claimed instances, check that another driver hasn't already - * claimed its slot. - */ - numFound = 0; - for (i = 0; i < allocatedInstances && numClaimedInstances > 0; i++) { - if (!instances[i].claimed) - continue; - psdp = instances[i].sbus; - if (!xf86CheckSbusSlot(psdp->fbNum)) - continue; - - DebugF("%s: card at fb%d %08x is claimed by a Device section\n", - driverName, psdp->fbNum, psdp->node.node); - - /* Allocate an entry in the lists to be returned */ - numFound++; - retEntities = xnfreallocarray(retEntities, numFound, sizeof(int)); - retEntities[numFound - 1] - = xf86ClaimSbusSlot(psdp, drvp, instances[i].dev, - instances[i].dev->active ? TRUE : FALSE); - } - free(instances); - if (numFound > 0) { - *foundEntities = retEntities; - } - - if (useProm) - sparcPromClose(); - - return numFound; -} - -/* - * xf86GetSbusInfoForEntity() -- Get the sbusDevicePtr of entity. - */ -sbusDevicePtr -xf86GetSbusInfoForEntity(int entityIndex) -{ - sbusDevicePtr *psdpp; - EntityPtr p = xf86Entities[entityIndex]; - - if (entityIndex >= xf86NumEntities || p->bus.type != BUS_SBUS) - return NULL; - - for (psdpp = xf86SbusInfo; *psdpp != NULL; psdpp++) { - if (p->bus.id.sbus.fbNum == (*psdpp)->fbNum) - return *psdpp; - } - return NULL; -} - -int -xf86GetEntityForSbusInfo(sbusDevicePtr psdp) -{ - int i; - - for (i = 0; i < xf86NumEntities; i++) { - EntityPtr p = xf86Entities[i]; - - if (p->bus.type != BUS_SBUS) - continue; - - if (p->bus.id.sbus.fbNum == psdp->fbNum) - return i; - } - return -1; -} - -void -xf86SbusUseBuiltinMode(ScrnInfoPtr pScrn, sbusDevicePtr psdp) -{ - DisplayModePtr mode; - - mode = xnfcalloc(sizeof(DisplayModeRec), 1); - mode->name = "current"; - mode->next = mode; - mode->prev = mode; - mode->type = M_T_BUILTIN; - mode->Clock = 100000000; - mode->HDisplay = psdp->width; - mode->HSyncStart = psdp->width; - mode->HSyncEnd = psdp->width; - mode->HTotal = psdp->width; - mode->VDisplay = psdp->height; - mode->VSyncStart = psdp->height; - mode->VSyncEnd = psdp->height; - mode->VTotal = psdp->height; - mode->SynthClock = mode->Clock; - mode->CrtcHDisplay = mode->HDisplay; - mode->CrtcHSyncStart = mode->HSyncStart; - mode->CrtcHSyncEnd = mode->HSyncEnd; - mode->CrtcHTotal = mode->HTotal; - mode->CrtcVDisplay = mode->VDisplay; - mode->CrtcVSyncStart = mode->VSyncStart; - mode->CrtcVSyncEnd = mode->VSyncEnd; - mode->CrtcVTotal = mode->VTotal; - mode->CrtcHAdjusted = FALSE; - mode->CrtcVAdjusted = FALSE; - pScrn->modes = mode; - pScrn->virtualX = psdp->width; - pScrn->virtualY = psdp->height; -} - -static DevPrivateKeyRec sbusPaletteKeyRec; -#define sbusPaletteKey (&sbusPaletteKeyRec) - -typedef struct _sbusCmap { - sbusDevicePtr psdp; - CloseScreenProcPtr CloseScreen; - Bool origCmapValid; - unsigned char origRed[16]; - unsigned char origGreen[16]; - unsigned char origBlue[16]; -} sbusCmapRec, *sbusCmapPtr; - -#define SBUSCMAPPTR(pScreen) ((sbusCmapPtr) \ - dixLookupPrivate(&(pScreen)->devPrivates, sbusPaletteKey)) - -static void -xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, - LOCO * colors, VisualPtr pVisual) -{ - int i, index; - sbusCmapPtr cmap; - struct fbcmap fbcmap; - unsigned char *data; - - cmap = SBUSCMAPPTR(pScrn->pScreen); - if (!cmap) - return; - fbcmap.count = 0; - fbcmap.index = indices[0]; - fbcmap.red = data = xallocarray(numColors, 3); - if (!data) - return; - fbcmap.green = data + numColors; - fbcmap.blue = fbcmap.green + numColors; - for (i = 0; i < numColors; i++) { - index = indices[i]; - if (fbcmap.count && index != fbcmap.index + fbcmap.count) { - ioctl(cmap->psdp->fd, FBIOPUTCMAP, &fbcmap); - fbcmap.count = 0; - fbcmap.index = index; - } - fbcmap.red[fbcmap.count] = colors[index].red; - fbcmap.green[fbcmap.count] = colors[index].green; - fbcmap.blue[fbcmap.count++] = colors[index].blue; - } - ioctl(cmap->psdp->fd, FBIOPUTCMAP, &fbcmap); - free(data); -} - -static Bool -xf86SbusCmapCloseScreen(ScreenPtr pScreen) -{ - sbusCmapPtr cmap; - struct fbcmap fbcmap; - - cmap = SBUSCMAPPTR(pScreen); - if (cmap->origCmapValid) { - fbcmap.index = 0; - fbcmap.count = 16; - fbcmap.red = cmap->origRed; - fbcmap.green = cmap->origGreen; - fbcmap.blue = cmap->origBlue; - ioctl(cmap->psdp->fd, FBIOPUTCMAP, &fbcmap); - } - pScreen->CloseScreen = cmap->CloseScreen; - free(cmap); - return (*pScreen->CloseScreen) (pScreen); -} - -Bool -xf86SbusHandleColormaps(ScreenPtr pScreen, sbusDevicePtr psdp) -{ - sbusCmapPtr cmap; - struct fbcmap fbcmap; - unsigned char data[2]; - - if (!dixRegisterPrivateKey(sbusPaletteKey, PRIVATE_SCREEN, 0)) - FatalError("Cannot register sbus private key"); - - cmap = xnfcalloc(1, sizeof(sbusCmapRec)); - dixSetPrivate(&pScreen->devPrivates, sbusPaletteKey, cmap); - cmap->psdp = psdp; - fbcmap.index = 0; - fbcmap.count = 16; - fbcmap.red = cmap->origRed; - fbcmap.green = cmap->origGreen; - fbcmap.blue = cmap->origBlue; - if (ioctl(psdp->fd, FBIOGETCMAP, &fbcmap) >= 0) - cmap->origCmapValid = TRUE; - fbcmap.index = 0; - fbcmap.count = 2; - fbcmap.red = data; - fbcmap.green = data; - fbcmap.blue = data; - if (pScreen->whitePixel == 0) { - data[0] = 255; - data[1] = 0; - } - else { - data[0] = 0; - data[1] = 255; - } - ioctl(psdp->fd, FBIOPUTCMAP, &fbcmap); - cmap->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = xf86SbusCmapCloseScreen; - return xf86HandleColormaps(pScreen, 256, 8, - xf86SbusCmapLoadPalette, NULL, 0); -} - -Bool -xf86SbusConfigure(void *busData, sbusDevicePtr sBus) -{ - if (sBus && sBus->fbNum == ((sbusDevicePtr) busData)->fbNum) - return 0; - return 1; -} - -void -xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec * GDev) -{ - char *promPath = NULL; - - sBus = (sbusDevicePtr) busData; - GDev->identifier = sBus->descr; - if (sparcPromInit() >= 0) { - promPath = sparcPromNode2Pathname(&sBus->node); - sparcPromClose(); - } - if (promPath) { - XNFasprintf(&GDev->busID, "SBUS:%s", promPath); - free(promPath); - } - else { - XNFasprintf(&GDev->busID, "SBUS:fb%d", sBus->fbNum); - } -} diff --git a/hw/xfree86/common/xf86sbusBus.h b/hw/xfree86/common/xf86sbusBus.h deleted file mode 100644 index 9cfcbc574..000000000 --- a/hw/xfree86/common/xf86sbusBus.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * SBUS bus-specific declarations - * - * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * JAKUB JELINEK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef _XF86_SBUSBUS_H -#define _XF86_SBUSBUS_H - -#include "xf86str.h" - -#define SBUS_DEVICE_BW2 0x0001 -#define SBUS_DEVICE_CG2 0x0002 -#define SBUS_DEVICE_CG3 0x0003 -#define SBUS_DEVICE_CG4 0x0004 -#define SBUS_DEVICE_CG6 0x0005 -#define SBUS_DEVICE_CG8 0x0006 -#define SBUS_DEVICE_CG12 0x0007 -#define SBUS_DEVICE_CG14 0x0008 -#define SBUS_DEVICE_LEO 0x0009 -#define SBUS_DEVICE_TCX 0x000a -#define SBUS_DEVICE_FFB 0x000b -#define SBUS_DEVICE_GT 0x000c -#define SBUS_DEVICE_MGX 0x000d - -typedef struct sbus_prom_node { - int node; - /* Because of misdesigned openpromio */ - int cookie[2]; -} sbusPromNode, *sbusPromNodePtr; - -typedef struct sbus_device { - int devId; - int fbNum; - int fd; - int width, height; - sbusPromNode node; - const char *descr; - const char *device; -} sbusDevice, *sbusDevicePtr; - -struct sbus_devtable { - int devId; - int fbType; - const char *promName; - const char *driverName; - const char *descr; -}; - -extern _X_EXPORT void xf86SbusProbe(void); -extern _X_EXPORT sbusDevicePtr *xf86SbusInfo; -extern _X_EXPORT struct sbus_devtable sbusDeviceTable[]; - -extern _X_EXPORT int xf86MatchSbusInstances(const char *driverName, - int sbusDevId, GDevPtr * devList, - int numDevs, DriverPtr drvp, - int **foundEntities); -extern _X_EXPORT sbusDevicePtr xf86GetSbusInfoForEntity(int entityIndex); -extern _X_EXPORT int xf86GetEntityForSbusInfo(sbusDevicePtr psdp); -extern _X_EXPORT void xf86SbusUseBuiltinMode(ScrnInfoPtr pScrn, - sbusDevicePtr psdp); -extern _X_EXPORT void *xf86MapSbusMem(sbusDevicePtr psdp, - unsigned long offset, - unsigned long size); -extern _X_EXPORT void xf86UnmapSbusMem(sbusDevicePtr psdp, void *addr, - unsigned long size); -extern _X_EXPORT void xf86SbusHideOsHwCursor(sbusDevicePtr psdp); -extern _X_EXPORT void xf86SbusSetOsHwCursorCmap(sbusDevicePtr psdp, int bg, - int fg); -extern _X_EXPORT Bool xf86SbusHandleColormaps(ScreenPtr pScreen, - sbusDevicePtr psdp); - -extern _X_EXPORT int promRootNode; - -extern _X_EXPORT int promGetSibling(int node); -extern _X_EXPORT int promGetChild(int node); -extern _X_EXPORT char *promGetProperty(const char *prop, int *lenp); -extern _X_EXPORT int promGetBool(const char *prop); - -extern _X_EXPORT int sparcPromInit(void); -extern _X_EXPORT void sparcPromClose(void); -extern _X_EXPORT char *sparcPromGetProperty(sbusPromNodePtr pnode, - const char *prop, int *lenp); -extern _X_EXPORT int sparcPromGetBool(sbusPromNodePtr pnode, const char *prop); -extern _X_EXPORT void sparcPromAssignNodes(void); -extern _X_EXPORT char *sparcPromNode2Pathname(sbusPromNodePtr pnode); -extern _X_EXPORT int sparcPromPathname2Node(const char *pathName); -extern _X_EXPORT char *sparcDriverName(void); - -extern Bool xf86SbusConfigure(void *busData, sbusDevicePtr sBus); -extern void xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, - GDevRec * GDev); - -#endif /* _XF86_SBUSBUS_H */ diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h deleted file mode 100644 index 9072932cb..000000000 --- a/hw/xfree86/common/xf86str.h +++ /dev/null @@ -1,775 +0,0 @@ - -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains definitions of the public XFree86 data structures/types. - * Any data structures that video drivers need to access should go here. - */ - -#ifndef _XF86STR_H -#define _XF86STR_H - -#include "misc.h" -#include "input.h" -#include "scrnintstr.h" -#include "pixmapstr.h" -#include "colormapst.h" -#include "xf86Module.h" -#include "xf86Opt.h" -#include "displaymode.h" - -/** - * Integer type that is of the size of the addressable memory (machine size). - * On most platforms \c uintptr_t will suffice. However, on some mixed - * 32-bit / 64-bit platforms, such as 32-bit binaries on 64-bit PowerPC, this - * must be 64-bits. - */ -#include -#if defined(__powerpc__) -typedef uint64_t memType; -#else -typedef uintptr_t memType; -#endif - -/* Video mode flags */ - -typedef enum { - V_PHSYNC = 0x0001, - V_NHSYNC = 0x0002, - V_PVSYNC = 0x0004, - V_NVSYNC = 0x0008, - V_INTERLACE = 0x0010, - V_DBLSCAN = 0x0020, - V_CSYNC = 0x0040, - V_PCSYNC = 0x0080, - V_NCSYNC = 0x0100, - V_HSKEW = 0x0200, /* hskew provided */ - V_BCAST = 0x0400, - V_PIXMUX = 0x1000, - V_DBLCLK = 0x2000, - V_CLKDIV2 = 0x4000 -} ModeFlags; - -typedef enum { - INTERLACE_HALVE_V = 0x0001 /* Halve V values for interlacing */ -} CrtcAdjustFlags; - -/* Flags passed to ChipValidMode() */ -typedef enum { - MODECHECK_INITIAL = 0, - MODECHECK_FINAL = 1 -} ModeCheckFlags; - -/* - * The mode sets are, from best to worst: USERDEF, DRIVER, and DEFAULT/BUILTIN. - * Preferred will bubble a mode to the top within a set. - */ -#define M_T_BUILTIN 0x01 /* built-in mode */ -#define M_T_CLOCK_C (0x02 | M_T_BUILTIN) /* built-in mode - configure clock */ -#define M_T_CRTC_C (0x04 | M_T_BUILTIN) /* built-in mode - configure CRTC */ -#define M_T_CLOCK_CRTC_C (M_T_CLOCK_C | M_T_CRTC_C) - /* built-in mode - configure CRTC and clock */ -#define M_T_PREFERRED 0x08 /* preferred mode within a set */ -#define M_T_DEFAULT 0x10 /* (VESA) default modes */ -#define M_T_USERDEF 0x20 /* One of the modes from the config file */ -#define M_T_DRIVER 0x40 /* Supplied by the driver (EDID, etc) */ -#define M_T_USERPREF 0x80 /* mode preferred by the user config */ - -/* The monitor description */ - -#define MAX_HSYNC 8 -#define MAX_VREFRESH 8 - -typedef struct { - float hi, lo; -} range; - -typedef struct { - CARD32 red, green, blue; -} rgb; - -typedef struct { - float red, green, blue; -} Gamma; - -/* The permitted gamma range is 1 / GAMMA_MAX <= g <= GAMMA_MAX */ -#define GAMMA_MAX 10.0 -#define GAMMA_MIN (1.0 / GAMMA_MAX) -#define GAMMA_ZERO (GAMMA_MIN / 100.0) - -typedef struct { - const char *id; - const char *vendor; - const char *model; - int nHsync; - range hsync[MAX_HSYNC]; - int nVrefresh; - range vrefresh[MAX_VREFRESH]; - DisplayModePtr Modes; /* Start of the monitor's mode list */ - DisplayModePtr Last; /* End of the monitor's mode list */ - Gamma gamma; /* Gamma of the monitor */ - int widthmm; - int heightmm; - void *options; - void *DDC; - Bool reducedblanking; /* Allow CVT reduced blanking modes? */ - int maxPixClock; /* in kHz, like mode->Clock */ -} MonRec, *MonPtr; - -/* the list of clock ranges */ -typedef struct x_ClockRange { - struct x_ClockRange *next; - int minClock; /* (kHz) */ - int maxClock; /* (kHz) */ - int clockIndex; /* -1 for programmable clocks */ - Bool interlaceAllowed; - Bool doubleScanAllowed; - int ClockMulFactor; - int ClockDivFactor; - int PrivFlags; -} ClockRange, *ClockRangePtr; - -/* - * The driverFunc. xorgDriverFuncOp specifies the action driver should - * perform. If requested option is not supported function should return - * FALSE. pointer can be used to pass arguments to the function or - * to return data to the caller. - */ -typedef struct _ScrnInfoRec *ScrnInfoPtr; - -/* do not change order */ -typedef enum { - RR_GET_INFO, - RR_SET_CONFIG, - RR_GET_MODE_MM, - GET_REQUIRED_HW_INTERFACES = 10, - SUPPORTS_SERVER_FDS = 11, -} xorgDriverFuncOp; - -typedef Bool xorgDriverFuncProc(ScrnInfoPtr, xorgDriverFuncOp, void *); - -/* RR_GET_INFO, RR_SET_CONFIG */ -typedef struct { - int rotation; - int rate; - int width; - int height; -} xorgRRConfig; - -typedef union { - short RRRotations; - xorgRRConfig RRConfig; -} xorgRRRotation, *xorgRRRotationPtr; - -/* RR_GET_MODE_MM */ -typedef struct { - DisplayModePtr mode; - int virtX; - int virtY; - int mmWidth; - int mmHeight; -} xorgRRModeMM, *xorgRRModeMMPtr; - -/* GET_REQUIRED_HW_INTERFACES */ -#define HW_IO 1 -#define HW_MMIO 2 -#define HW_SKIP_CONSOLE 4 -#define NEED_IO_ENABLED(x) (x & HW_IO) - -typedef CARD32 xorgHWFlags; - -/* - * The driver list struct. This contains the information required for each - * driver before a ScrnInfoRec has been allocated. - */ -struct _DriverRec; - -struct _SymTabRec; -struct _PciChipsets; - -struct pci_device; -struct xf86_platform_device; - -typedef struct _DriverRec { - int driverVersion; - const char *driverName; - void (*Identify) (int flags); - Bool (*Probe) (struct _DriverRec * drv, int flags); - const OptionInfoRec *(*AvailableOptions) (int chipid, int bustype); - void *module; - int refCount; - xorgDriverFuncProc *driverFunc; - - const struct pci_id_match *supported_devices; - Bool (*PciProbe) (struct _DriverRec * drv, int entity_num, - struct pci_device * dev, intptr_t match_data); - Bool (*platformProbe) (struct _DriverRec * drv, int entity_num, int flags, - struct xf86_platform_device * dev, intptr_t match_data); -} DriverRec, *DriverPtr; - -/* - * platform probe flags - */ -#define PLATFORM_PROBE_GPU_SCREEN 1 - -/* - * AddDriver flags - */ -#define HaveDriverFuncs 1 - -/* - * These are the private bus types. New types can be added here. Types - * required for the public interface should be added to xf86str.h, with - * function prototypes added to xf86.h. - */ - -/* Tolerate prior #include */ -#if defined(__linux__) -#undef BUS_NONE -#undef BUS_PCI -#undef BUS_SBUS -#undef BUS_PLATFORM -#undef BUS_USB -#undef BUS_last -#endif - -typedef enum { - BUS_NONE, - BUS_PCI, - BUS_SBUS, - BUS_PLATFORM, - BUS_USB, - BUS_last /* Keep last */ -} BusType; - -typedef struct { - int fbNum; -} SbusBusId; - -typedef struct _bus { - BusType type; - union { - struct pci_device *pci; - SbusBusId sbus; - struct xf86_platform_device *plat; - } id; -} BusRec, *BusPtr; - -typedef enum { - DAC_BPP8 = 0, - DAC_BPP16, - DAC_BPP24, - DAC_BPP32, - MAXDACSPEEDS -} DacSpeedIndex; - -typedef struct { - const char *identifier; - const char *vendor; - const char *board; - const char *chipset; - const char *ramdac; - const char *driver; - struct _confscreenrec *myScreenSection; - Bool claimed; - int dacSpeeds[MAXDACSPEEDS]; - int numclocks; - int clock[MAXCLOCKS]; - const char *clockchip; - const char *busID; - Bool active; - Bool inUse; - int videoRam; - unsigned long MemBase; /* Frame buffer base address */ - unsigned long IOBase; - int chipID; - int chipRev; - void *options; - int irq; - int screen; /* For multi-CRTC cards */ -} GDevRec, *GDevPtr; - -typedef struct { - int frameX0; - int frameY0; - int virtualX; - int virtualY; - int depth; - int fbbpp; - rgb weight; - rgb blackColour; - rgb whiteColour; - int defaultVisual; - const char **modes; - void *options; -} DispRec, *DispPtr; - -typedef struct _confxvportrec { - const char *identifier; - void *options; -} confXvPortRec, *confXvPortPtr; - -typedef struct _confxvadaptrec { - const char *identifier; - int numports; - confXvPortPtr ports; - void *options; -} confXvAdaptorRec, *confXvAdaptorPtr; - -#define MAX_GPUDEVICES 4 -typedef struct _confscreenrec { - const char *id; - int screennum; - int defaultdepth; - int defaultbpp; - int defaultfbbpp; - MonPtr monitor; - GDevPtr device; - int numdisplays; - DispPtr *displays; - int numxvadaptors; - confXvAdaptorPtr xvadaptors; - void *options; - - int num_gpu_devices; - GDevPtr gpu_devices[MAX_GPUDEVICES]; -} confScreenRec, *confScreenPtr; - -typedef enum { - PosObsolete = -1, - PosAbsolute = 0, - PosRightOf, - PosLeftOf, - PosAbove, - PosBelow, - PosRelative -} PositionType; - -typedef struct _screenlayoutrec { - confScreenPtr screen; - const char *topname; - confScreenPtr top; - const char *bottomname; - confScreenPtr bottom; - const char *leftname; - confScreenPtr left; - const char *rightname; - confScreenPtr right; - PositionType where; - int x; - int y; - const char *refname; - confScreenPtr refscreen; -} screenLayoutRec, *screenLayoutPtr; - -typedef struct _InputInfoRec InputInfoRec; - -typedef struct _serverlayoutrec { - const char *id; - screenLayoutPtr screens; - GDevPtr inactives; - InputInfoRec **inputs; /* NULL terminated */ - void *options; -} serverLayoutRec, *serverLayoutPtr; - -typedef struct _confdribufferrec { - int count; - int size; - enum { - XF86DRI_WC_HINT = 0x0001 /* Placeholder: not implemented */ - } flags; -} confDRIBufferRec, *confDRIBufferPtr; - -typedef struct _confdrirec { - int group; - int mode; - int bufs_count; - confDRIBufferRec *bufs; -} confDRIRec, *confDRIPtr; - -#define NUM_RESERVED_INTS 4 -#define NUM_RESERVED_POINTERS 4 -#define NUM_RESERVED_FUNCS 4 - -/* let clients know they can use this */ -#define XF86_SCRN_HAS_PREFER_CLONE 1 - -typedef void *(*funcPointer) (void); - -/* Power management events: so far we only support APM */ - -typedef enum { - XF86_APM_UNKNOWN = -1, - XF86_APM_SYS_STANDBY, - XF86_APM_SYS_SUSPEND, - XF86_APM_CRITICAL_SUSPEND, - XF86_APM_USER_STANDBY, - XF86_APM_USER_SUSPEND, - XF86_APM_STANDBY_RESUME, - XF86_APM_NORMAL_RESUME, - XF86_APM_CRITICAL_RESUME, - XF86_APM_LOW_BATTERY, - XF86_APM_POWER_STATUS_CHANGE, - XF86_APM_UPDATE_TIME, - XF86_APM_CAPABILITY_CHANGED, - XF86_APM_STANDBY_FAILED, - XF86_APM_SUSPEND_FAILED -} pmEvent; - -typedef enum { - PM_WAIT, - PM_CONTINUE, - PM_FAILED, - PM_NONE -} pmWait; - -typedef struct _PciChipsets { - /** - * Key used to match this device with its name in an array of - * \c SymTabRec. - */ - int numChipset; - - /** - * This value is quirky. Depending on the driver, it can take on one of - * three meanings. In drivers that have exactly one vendor ID (e.g., - * radeon, mga, i810) the low 16-bits are the device ID. - * - * In drivers that can have multiple vendor IDs (e.g., the glint driver - * can have either 3dlabs' ID or TI's ID, the i740 driver can have either - * Intel's ID or Real3D's ID, etc.) the low 16-bits are the device ID and - * the high 16-bits are the vendor ID. - * - * In drivers that don't have a specific vendor (e.g., vga) contains the - * device ID for either the generic VGA or generic 8514 devices. This - * turns out to be the same as the subclass and programming interface - * value (e.g., the full 24-bit class for the VGA device is 0x030000 (or - * 0x000101) and for 8514 is 0x030001). - */ - int PCIid; - -/* dummy place holders for drivers to build against old/new servers */ -#define RES_UNDEFINED NULL -#define RES_EXCLUSIVE_VGA NULL -#define RES_SHARED_VGA NULL - void *dummy; -} PciChipsets; - -/* Entity properties */ -typedef void (*EntityProc) (int entityIndex, void *private); - -typedef struct _entityInfo { - int index; - BusRec location; - int chipset; - Bool active; - GDevPtr device; - DriverPtr driver; -} EntityInfoRec, *EntityInfoPtr; - -/* DGA */ - -typedef struct { - int num; /* A unique identifier for the mode (num > 0) */ - DisplayModePtr mode; - int flags; /* DGA_CONCURRENT_ACCESS, etc... */ - int imageWidth; /* linear accessible portion (pixels) */ - int imageHeight; - int pixmapWidth; /* Xlib accessible portion (pixels) */ - int pixmapHeight; /* both fields ignored if no concurrent access */ - int bytesPerScanline; - int byteOrder; /* MSBFirst, LSBFirst */ - int depth; - int bitsPerPixel; - unsigned long red_mask; - unsigned long green_mask; - unsigned long blue_mask; - short visualClass; - int viewportWidth; - int viewportHeight; - int xViewportStep; /* viewport position granularity */ - int yViewportStep; - int maxViewportX; /* max viewport origin */ - int maxViewportY; - int viewportFlags; /* types of page flipping possible */ - int offset; /* offset into physical memory */ - unsigned char *address; /* server's mapped framebuffer */ - int reserved1; - int reserved2; -} DGAModeRec, *DGAModePtr; - -typedef struct { - DGAModePtr mode; - PixmapPtr pPix; -} DGADeviceRec, *DGADevicePtr; - -/* - * Flags for driver Probe() functions. - */ -#define PROBE_DEFAULT 0x00 -#define PROBE_DETECT 0x01 -#define PROBE_TRYHARD 0x02 - -/* - * Driver entry point types - */ - -typedef Bool xf86ProbeProc(DriverPtr, int); -typedef Bool xf86PreInitProc(ScrnInfoPtr, int); -typedef Bool xf86ScreenInitProc(ScreenPtr, int, char **); -typedef Bool xf86SwitchModeProc(ScrnInfoPtr, DisplayModePtr); -typedef void xf86AdjustFrameProc(ScrnInfoPtr, int, int); -typedef Bool xf86EnterVTProc(ScrnInfoPtr); -typedef void xf86LeaveVTProc(ScrnInfoPtr); -typedef void xf86FreeScreenProc(ScrnInfoPtr); -typedef ModeStatus xf86ValidModeProc(ScrnInfoPtr, DisplayModePtr, Bool, int); -typedef void xf86EnableDisableFBAccessProc(ScrnInfoPtr, Bool); -typedef int xf86SetDGAModeProc(ScrnInfoPtr, int, DGADevicePtr); -typedef int xf86ChangeGammaProc(ScrnInfoPtr, Gamma); -typedef void xf86PointerMovedProc(ScrnInfoPtr, int, int); -typedef Bool xf86PMEventProc(ScrnInfoPtr, pmEvent, Bool); -typedef void xf86DPMSSetProc(ScrnInfoPtr, int, int); -typedef void xf86LoadPaletteProc(ScrnInfoPtr, int, int *, LOCO *, VisualPtr); -typedef void xf86SetOverscanProc(ScrnInfoPtr, int); -typedef void xf86ModeSetProc(ScrnInfoPtr); - -/* - * ScrnInfoRec - * - * There is one of these for each screen, and it holds all the screen-specific - * information. Note: No fields are to be dependent on compile-time defines. - */ - -typedef struct _ScrnInfoRec { - int driverVersion; - const char *driverName; /* canonical name used in */ - /* the config file */ - ScreenPtr pScreen; /* Pointer to the ScreenRec */ - int scrnIndex; /* Number of this screen */ - Bool configured; /* Is this screen valid */ - int origIndex; /* initial number assigned to - * this screen before - * finalising the number of - * available screens */ - - /* Display-wide screenInfo values needed by this screen */ - int imageByteOrder; - int bitmapScanlineUnit; - int bitmapScanlinePad; - int bitmapBitOrder; - int numFormats; - PixmapFormatRec formats[MAXFORMATS]; - PixmapFormatRec fbFormat; - - int bitsPerPixel; /* fb bpp */ - int depth; /* depth of default visual */ - MessageType depthFrom; /* set from config? */ - MessageType bitsPerPixelFrom; /* set from config? */ - rgb weight; /* r/g/b weights */ - rgb mask; /* rgb masks */ - rgb offset; /* rgb offsets */ - int rgbBits; /* Number of bits in r/g/b */ - Gamma gamma; /* Gamma of the monitor */ - int defaultVisual; /* default visual class */ - int virtualX; /* Virtual width */ - int virtualY; /* Virtual height */ - int xInc; /* Horizontal timing increment */ - int displayWidth; /* memory pitch */ - int frameX0; /* viewport position */ - int frameY0; - int frameX1; - int frameY1; - int zoomLocked; /* Disallow mode changes */ - DisplayModePtr modePool; /* list of compatible modes */ - DisplayModePtr modes; /* list of actual modes */ - DisplayModePtr currentMode; /* current mode - * This was previously - * overloaded with the modes - * field, which is a pointer - * into a circular list */ - confScreenPtr confScreen; /* Screen config info */ - MonPtr monitor; /* Monitor information */ - DispPtr display; /* Display information */ - int *entityList; /* List of device entities */ - int numEntities; - int widthmm; /* physical display dimensions - * in mm */ - int heightmm; - int xDpi; /* width DPI */ - int yDpi; /* height DPI */ - const char *name; /* Name to prefix messages */ - void *driverPrivate; /* Driver private area */ - DevUnion *privates; /* Other privates can hook in - * here */ - DriverPtr drv; /* xf86DriverList[] entry */ - void *module; /* Pointer to module head */ - int colorKey; - int overlayFlags; - - /* Some of these may be moved out of here into the driver private area */ - - const char *chipset; /* chipset name */ - const char *ramdac; /* ramdac name */ - const char *clockchip; /* clock name */ - Bool progClock; /* clock is programmable */ - int numClocks; /* number of clocks */ - int clock[MAXCLOCKS]; /* list of clock frequencies */ - int videoRam; /* amount of video ram (kb) */ - unsigned long memPhysBase; /* Physical address of FB */ - unsigned long fbOffset; /* Offset of FB in the above */ - void *options; - - /* Allow screens to be enabled/disabled individually */ - Bool vtSema; - - /* hw cursor moves from input thread */ - Bool silkenMouse; - - /* Storage for clockRanges and adjustFlags for use with the VidMode ext */ - ClockRangePtr clockRanges; - int adjustFlags; - - /* initial rightof support disable */ - int preferClone; - - Bool is_gpu; - uint32_t capabilities; - - int *entityInstanceList; - struct pci_device *vgaDev; - - /* - * Driver entry points. - * - */ - - xf86ProbeProc *Probe; - xf86PreInitProc *PreInit; - xf86ScreenInitProc *ScreenInit; - xf86SwitchModeProc *SwitchMode; - xf86AdjustFrameProc *AdjustFrame; - xf86EnterVTProc *EnterVT; - xf86LeaveVTProc *LeaveVT; - xf86FreeScreenProc *FreeScreen; - xf86ValidModeProc *ValidMode; - xf86EnableDisableFBAccessProc *EnableDisableFBAccess; - xf86SetDGAModeProc *SetDGAMode; - xf86ChangeGammaProc *ChangeGamma; - xf86PointerMovedProc *PointerMoved; - xf86PMEventProc *PMEvent; - xf86DPMSSetProc *DPMSSet; - xf86LoadPaletteProc *LoadPalette; - xf86SetOverscanProc *SetOverscan; - xorgDriverFuncProc *DriverFunc; - xf86ModeSetProc *ModeSet; - - int reservedInt[NUM_RESERVED_INTS]; - void *reservedPtr[NUM_RESERVED_POINTERS]; - funcPointer reservedFuncs[NUM_RESERVED_FUNCS]; -} ScrnInfoRec; - -typedef struct { - Bool (*OpenFramebuffer) (ScrnInfoPtr pScrn, - char **name, - unsigned char **mem, - int *size, int *offset, int *extra); - void (*CloseFramebuffer) (ScrnInfoPtr pScrn); - Bool (*SetMode) (ScrnInfoPtr pScrn, DGAModePtr pMode); - void (*SetViewport) (ScrnInfoPtr pScrn, int x, int y, int flags); - int (*GetViewport) (ScrnInfoPtr pScrn); - void (*Sync) (ScrnInfoPtr); - void (*FillRect) (ScrnInfoPtr pScrn, - int x, int y, int w, int h, unsigned long color); - void (*BlitRect) (ScrnInfoPtr pScrn, - int srcx, int srcy, int w, int h, int dstx, int dsty); - void (*BlitTransRect) (ScrnInfoPtr pScrn, - int srcx, int srcy, - int w, int h, - int dstx, int dsty, unsigned long color); -} DGAFunctionRec, *DGAFunctionPtr; - -typedef struct _SymTabRec { - int token; /* id of the token */ - const char *name; /* token name */ -} SymTabRec, *SymTabPtr; - -/* flags for xf86LookupMode */ -typedef enum { - LOOKUP_DEFAULT = 0, /* Use default mode lookup method */ - LOOKUP_BEST_REFRESH, /* Pick modes with best refresh */ - LOOKUP_CLOSEST_CLOCK, /* Pick modes with the closest clock */ - LOOKUP_LIST_ORDER, /* Pick first useful mode in list */ - LOOKUP_CLKDIV2 = 0x0100, /* Allow half clocks */ - LOOKUP_OPTIONAL_TOLERANCES = 0x0200 /* Allow missing hsync/vrefresh */ -} LookupModeFlags; - -#define NoDepth24Support 0x00 -#define Support24bppFb 0x01 /* 24bpp framebuffer supported */ -#define Support32bppFb 0x02 /* 32bpp framebuffer supported */ -#define SupportConvert24to32 0x04 /* Can convert 24bpp pixmap to 32bpp */ -#define SupportConvert32to24 0x08 /* Can convert 32bpp pixmap to 24bpp */ -#define PreferConvert24to32 0x10 /* prefer 24bpp pixmap to 32bpp conv */ -#define PreferConvert32to24 0x20 /* prefer 32bpp pixmap to 24bpp conv */ - -/* For DPMS */ -typedef void (*DPMSSetProcPtr) (ScrnInfoPtr, int, int); - -/* Input handler proc */ -typedef void (*InputHandlerProc) (int fd, void *data); - -/* These are used by xf86GetClocks */ -#define CLK_REG_SAVE -1 -#define CLK_REG_RESTORE -2 - -/* - * misc constants - */ -#define INTERLACE_REFRESH_WEIGHT 1.5 -#define SYNC_TOLERANCE 0.01 /* 1 percent */ -#define CLOCK_TOLERANCE 2000 /* Clock matching tolerance (2MHz) */ - -#define OVERLAY_8_32_DUALFB 0x00000001 -#define OVERLAY_8_24_DUALFB 0x00000002 -#define OVERLAY_8_16_DUALFB 0x00000004 -#define OVERLAY_8_32_PLANAR 0x00000008 - -/* Values of xf86Info.mouseFlags */ -#define MF_CLEAR_DTR 1 -#define MF_CLEAR_RTS 2 - -/* Action Events */ -typedef enum { - ACTION_TERMINATE = 0, /* Terminate Server */ - ACTION_NEXT_MODE = 10, /* Switch to next video mode */ - ACTION_PREV_MODE, - ACTION_SWITCHSCREEN = 100, /* VT switch */ - ACTION_SWITCHSCREEN_NEXT, - ACTION_SWITCHSCREEN_PREV, -} ActionEvent; - -#endif /* _XF86STR_H */ diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c deleted file mode 100644 index 8a8c5939d..000000000 --- a/hw/xfree86/common/xf86xv.c +++ /dev/null @@ -1,1958 +0,0 @@ -/* - * XFree86 Xv DDX written by Mark Vojkovich (markv@valinux.com) - */ -/* - * Copyright (c) 1998-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "misc.h" -#include "xf86.h" -#include "xf86_OSproc.h" - -#include -#include -#include "scrnintstr.h" -#include "regionstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "mivalidate.h" -#include "validate.h" -#include "resource.h" -#include "gcstruct.h" -#include "dixstruct.h" - -#include -#include -#include "xvdix.h" - -#include "xf86xvpriv.h" - -/* XvAdaptorRec fields */ - -static int xf86XVPutVideo(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int xf86XVPutStill(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int xf86XVGetVideo(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int xf86XVGetStill(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int xf86XVStopVideo(XvPortPtr, DrawablePtr); -static int xf86XVSetPortAttribute(XvPortPtr, Atom, INT32); -static int xf86XVGetPortAttribute(XvPortPtr, Atom, INT32 *); -static int xf86XVQueryBestSize(XvPortPtr, CARD8, - CARD16, CARD16, CARD16, CARD16, - unsigned int *, unsigned int *); -static int xf86XVPutImage(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16, - XvImagePtr, unsigned char *, Bool, CARD16, CARD16); -static int xf86XVQueryImageAttributes(XvPortPtr, XvImagePtr, - CARD16 *, CARD16 *, int *, int *); - -/* ScreenRec fields */ - -static Bool xf86XVDestroyWindow(WindowPtr pWin); -static void xf86XVWindowExposures(WindowPtr pWin, RegionPtr r1); -static void xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin, - VTKind kind); -static void xf86XVClipNotify(WindowPtr pWin, int dx, int dy); -static Bool xf86XVCloseScreen(ScreenPtr); - -#define PostValidateTreeUndefined ((PostValidateTreeProcPtr)-1) - -/* ScrnInfoRec functions */ - -static Bool xf86XVEnterVT(ScrnInfoPtr); -static void xf86XVLeaveVT(ScrnInfoPtr); -static void xf86XVAdjustFrame(ScrnInfoPtr, int x, int y); -static void xf86XVModeSet(ScrnInfoPtr pScrn); - -/* misc */ - -static Bool xf86XVInitAdaptors(ScreenPtr, XF86VideoAdaptorPtr *, int); - -static DevPrivateKeyRec XF86XVWindowKeyRec; - -#define XF86XVWindowKey (&XF86XVWindowKeyRec) - -/* dixmain.c XvScreenPtr screen private */ -DevPrivateKey XF86XvScreenKey; -/** xf86xv.c XF86XVScreenPtr screen private */ -static DevPrivateKeyRec XF86XVScreenPrivateKey; - -static unsigned long PortResource = 0; - -#define GET_XV_SCREEN(pScreen) \ - ((XvScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XF86XvScreenKey)) - -#define GET_XF86XV_SCREEN(pScreen) \ - ((XF86XVScreenPtr)(dixGetPrivate(&pScreen->devPrivates, &XF86XVScreenPrivateKey))) - -#define GET_XF86XV_WINDOW(pWin) \ - ((XF86XVWindowPtr)dixLookupPrivate(&(pWin)->devPrivates, XF86XVWindowKey)) - -static xf86XVInitGenericAdaptorPtr *GenDrivers = NULL; -static int NumGenDrivers = 0; - -int -xf86XVRegisterGenericAdaptorDriver(xf86XVInitGenericAdaptorPtr InitFunc) -{ - xf86XVInitGenericAdaptorPtr *newdrivers; - - newdrivers = reallocarray(GenDrivers, 1 + NumGenDrivers, - sizeof(xf86XVInitGenericAdaptorPtr)); - if (!newdrivers) - return 0; - GenDrivers = newdrivers; - - GenDrivers[NumGenDrivers++] = InitFunc; - - return 1; -} - -int -xf86XVListGenericAdaptors(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr ** adaptors) -{ - int i, j, n, num; - XF86VideoAdaptorPtr *DrivAdap, *new; - - num = 0; - *adaptors = NULL; - /* - * The v4l driver registers itself first, but can use surfaces registered - * by other drivers. So, call the v4l driver last. - */ - for (i = NumGenDrivers; --i >= 0;) { - DrivAdap = NULL; - n = (*GenDrivers[i]) (pScrn, &DrivAdap); - if (0 == n) - continue; - new = reallocarray(*adaptors, num + n, sizeof(XF86VideoAdaptorPtr)); - if (NULL == new) - continue; - *adaptors = new; - for (j = 0; j < n; j++, num++) - (*adaptors)[num] = DrivAdap[j]; - } - return num; -} - -/**************** Offscreen surface stuff *******************/ - -typedef struct { - XF86OffscreenImagePtr images; - int num; -} OffscreenImageRec; - -static DevPrivateKeyRec OffscreenPrivateKeyRec; - -#define OffscreenPrivateKey (&OffscreenPrivateKeyRec) -#define GetOffscreenImage(pScreen) ((OffscreenImageRec *) dixLookupPrivate(&(pScreen)->devPrivates, OffscreenPrivateKey)) - -Bool -xf86XVRegisterOffscreenImages(ScreenPtr pScreen, - XF86OffscreenImagePtr images, int num) -{ - OffscreenImageRec *OffscreenImage; - - /* This function may be called before xf86XVScreenInit, so there's - * no better place than this to call dixRegisterPrivateKey to ensure we - * have space reserved. After the first call it is a no-op. */ - if (!dixRegisterPrivateKey - (OffscreenPrivateKey, PRIVATE_SCREEN, sizeof(OffscreenImageRec)) || - !(OffscreenImage = GetOffscreenImage(pScreen))) - /* Every X.org driver assumes this function always succeeds, so - * just die on allocation failure. */ - FatalError - ("Could not allocate private storage for XV offscreen images.\n"); - - OffscreenImage->num = num; - OffscreenImage->images = images; - return TRUE; -} - -XF86OffscreenImagePtr -xf86XVQueryOffscreenImages(ScreenPtr pScreen, int *num) -{ - OffscreenImageRec *OffscreenImage = GetOffscreenImage(pScreen); - - *num = OffscreenImage->num; - return OffscreenImage->images; -} - -XF86VideoAdaptorPtr -xf86XVAllocateVideoAdaptorRec(ScrnInfoPtr pScrn) -{ - return calloc(1, sizeof(XF86VideoAdaptorRec)); -} - -void -xf86XVFreeVideoAdaptorRec(XF86VideoAdaptorPtr ptr) -{ - free(ptr); -} - -Bool -xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num) -{ - ScrnInfoPtr pScrn; - XF86XVScreenPtr ScreenPriv; - - if (num <= 0 || noXvExtension) - return FALSE; - - if (Success != XvScreenInit(pScreen)) - return FALSE; - - if (!dixRegisterPrivateKey(&XF86XVWindowKeyRec, PRIVATE_WINDOW, 0)) - return FALSE; - if (!dixRegisterPrivateKey(&XF86XVScreenPrivateKey, PRIVATE_SCREEN, 0)) - return FALSE; - - XF86XvScreenKey = XvGetScreenKey(); - - PortResource = XvGetRTPort(); - - ScreenPriv = malloc(sizeof(XF86XVScreenRec)); - dixSetPrivate(&pScreen->devPrivates, &XF86XVScreenPrivateKey, ScreenPriv); - - if (!ScreenPriv) - return FALSE; - - pScrn = xf86ScreenToScrn(pScreen); - - ScreenPriv->DestroyWindow = pScreen->DestroyWindow; - ScreenPriv->WindowExposures = pScreen->WindowExposures; - ScreenPriv->PostValidateTree = PostValidateTreeUndefined; - ScreenPriv->ClipNotify = pScreen->ClipNotify; - ScreenPriv->CloseScreen = pScreen->CloseScreen; - ScreenPriv->EnterVT = pScrn->EnterVT; - ScreenPriv->LeaveVT = pScrn->LeaveVT; - ScreenPriv->AdjustFrame = pScrn->AdjustFrame; - ScreenPriv->ModeSet = pScrn->ModeSet; - - pScreen->DestroyWindow = xf86XVDestroyWindow; - pScreen->WindowExposures = xf86XVWindowExposures; - pScreen->ClipNotify = xf86XVClipNotify; - pScreen->CloseScreen = xf86XVCloseScreen; - pScrn->EnterVT = xf86XVEnterVT; - pScrn->LeaveVT = xf86XVLeaveVT; - if (pScrn->AdjustFrame) - pScrn->AdjustFrame = xf86XVAdjustFrame; - pScrn->ModeSet = xf86XVModeSet; - - if (!xf86XVInitAdaptors(pScreen, adaptors, num)) - return FALSE; - - return TRUE; -} - -static void -xf86XVFreeAdaptor(XvAdaptorPtr pAdaptor) -{ - int i; - - if (pAdaptor->pPorts) { - XvPortPtr pPort = pAdaptor->pPorts; - XvPortRecPrivatePtr pPriv; - - for (i = 0; i < pAdaptor->nPorts; i++, pPort++) { - pPriv = (XvPortRecPrivatePtr) pPort->devPriv.ptr; - if (pPriv) { - if (pPriv->clientClip) - RegionDestroy(pPriv->clientClip); - if (pPriv->pCompositeClip && pPriv->FreeCompositeClip) - RegionDestroy(pPriv->pCompositeClip); - if (pPriv->ckeyFilled) - RegionDestroy(pPriv->ckeyFilled); - free(pPriv); - } - } - } - - XvFreeAdaptor(pAdaptor); -} - -static Bool -xf86XVInitAdaptors(ScreenPtr pScreen, XF86VideoAdaptorPtr * infoPtr, int number) -{ - XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - XF86VideoAdaptorPtr adaptorPtr; - XvAdaptorPtr pAdaptor, pa; - XvAdaptorRecPrivatePtr adaptorPriv; - int na, numAdaptor; - XvPortRecPrivatePtr portPriv; - XvPortPtr pPort, pp; - int numPort; - XF86VideoFormatPtr formatPtr; - XvFormatPtr pFormat, pf; - int numFormat, totFormat; - XF86VideoEncodingPtr encodingPtr; - XvEncodingPtr pEncode, pe; - int numVisuals; - VisualPtr pVisual; - int i; - - pxvs->nAdaptors = 0; - pxvs->pAdaptors = NULL; - - if (!(pAdaptor = calloc(number, sizeof(XvAdaptorRec)))) - return FALSE; - - for (pa = pAdaptor, na = 0, numAdaptor = 0; na < number; na++, adaptorPtr++) { - adaptorPtr = infoPtr[na]; - - if (!adaptorPtr->StopVideo || !adaptorPtr->SetPortAttribute || - !adaptorPtr->GetPortAttribute || !adaptorPtr->QueryBestSize) - continue; - - /* client libs expect at least one encoding */ - if (!adaptorPtr->nEncodings || !adaptorPtr->pEncodings) - continue; - - pa->type = adaptorPtr->type; - - if (!adaptorPtr->PutVideo && !adaptorPtr->GetVideo) - pa->type &= ~XvVideoMask; - - if (!adaptorPtr->PutStill && !adaptorPtr->GetStill) - pa->type &= ~XvStillMask; - - if (!adaptorPtr->PutImage || !adaptorPtr->QueryImageAttributes) - pa->type &= ~XvImageMask; - - if (!adaptorPtr->PutVideo && !adaptorPtr->PutImage && - !adaptorPtr->PutStill) - pa->type &= ~XvInputMask; - - if (!adaptorPtr->GetVideo && !adaptorPtr->GetStill) - pa->type &= ~XvOutputMask; - - if (!(adaptorPtr->type & (XvPixmapMask | XvWindowMask))) - continue; - if (!(adaptorPtr->type & (XvImageMask | XvVideoMask | XvStillMask))) - continue; - - pa->pScreen = pScreen; - pa->ddPutVideo = xf86XVPutVideo; - pa->ddPutStill = xf86XVPutStill; - pa->ddGetVideo = xf86XVGetVideo; - pa->ddGetStill = xf86XVGetStill; - pa->ddStopVideo = xf86XVStopVideo; - pa->ddPutImage = xf86XVPutImage; - pa->ddSetPortAttribute = xf86XVSetPortAttribute; - pa->ddGetPortAttribute = xf86XVGetPortAttribute; - pa->ddQueryBestSize = xf86XVQueryBestSize; - pa->ddQueryImageAttributes = xf86XVQueryImageAttributes; - pa->name = strdup(adaptorPtr->name); - - if (adaptorPtr->nEncodings && - (pEncode = calloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) { - - for (pe = pEncode, encodingPtr = adaptorPtr->pEncodings, i = 0; - i < adaptorPtr->nEncodings; pe++, i++, encodingPtr++) { - pe->id = encodingPtr->id; - pe->pScreen = pScreen; - pe->name = strdup(encodingPtr->name); - pe->width = encodingPtr->width; - pe->height = encodingPtr->height; - pe->rate.numerator = encodingPtr->rate.numerator; - pe->rate.denominator = encodingPtr->rate.denominator; - } - pa->nEncodings = adaptorPtr->nEncodings; - pa->pEncodings = pEncode; - } - - if (adaptorPtr->nImages && - (pa->pImages = calloc(adaptorPtr->nImages, sizeof(XvImageRec)))) { - memcpy(pa->pImages, adaptorPtr->pImages, - adaptorPtr->nImages * sizeof(XvImageRec)); - pa->nImages = adaptorPtr->nImages; - } - - if (adaptorPtr->nAttributes && - (pa->pAttributes = calloc(adaptorPtr->nAttributes, - sizeof(XvAttributeRec)))) { - memcpy(pa->pAttributes, adaptorPtr->pAttributes, - adaptorPtr->nAttributes * sizeof(XvAttributeRec)); - - for (i = 0; i < adaptorPtr->nAttributes; i++) { - pa->pAttributes[i].name = - strdup(adaptorPtr->pAttributes[i].name); - } - - pa->nAttributes = adaptorPtr->nAttributes; - } - - totFormat = adaptorPtr->nFormats; - - if (!(pFormat = calloc(totFormat, sizeof(XvFormatRec)))) { - xf86XVFreeAdaptor(pa); - continue; - } - for (pf = pFormat, i = 0, numFormat = 0, formatPtr = - adaptorPtr->pFormats; i < adaptorPtr->nFormats; i++, formatPtr++) { - numVisuals = pScreen->numVisuals; - pVisual = pScreen->visuals; - - while (numVisuals--) { - if ((pVisual->class == formatPtr->class) && - (pVisual->nplanes == formatPtr->depth)) { - - if (numFormat >= totFormat) { - void *moreSpace; - - totFormat *= 2; - moreSpace = reallocarray(pFormat, totFormat, - sizeof(XvFormatRec)); - if (!moreSpace) - break; - pFormat = moreSpace; - pf = pFormat + numFormat; - } - - pf->visual = pVisual->vid; - pf->depth = formatPtr->depth; - - pf++; - numFormat++; - } - pVisual++; - } - } - pa->nFormats = numFormat; - pa->pFormats = pFormat; - if (!numFormat) { - xf86XVFreeAdaptor(pa); - continue; - } - - if (!(adaptorPriv = calloc(1, sizeof(XvAdaptorRecPrivate)))) { - xf86XVFreeAdaptor(pa); - continue; - } - - adaptorPriv->flags = adaptorPtr->flags; - adaptorPriv->PutVideo = adaptorPtr->PutVideo; - adaptorPriv->PutStill = adaptorPtr->PutStill; - adaptorPriv->GetVideo = adaptorPtr->GetVideo; - adaptorPriv->GetStill = adaptorPtr->GetStill; - adaptorPriv->StopVideo = adaptorPtr->StopVideo; - adaptorPriv->SetPortAttribute = adaptorPtr->SetPortAttribute; - adaptorPriv->GetPortAttribute = adaptorPtr->GetPortAttribute; - adaptorPriv->QueryBestSize = adaptorPtr->QueryBestSize; - adaptorPriv->QueryImageAttributes = adaptorPtr->QueryImageAttributes; - adaptorPriv->PutImage = adaptorPtr->PutImage; - adaptorPriv->ReputImage = adaptorPtr->ReputImage; /* image/still */ - - pa->devPriv.ptr = (void *) adaptorPriv; - - if (!(pPort = calloc(adaptorPtr->nPorts, sizeof(XvPortRec)))) { - xf86XVFreeAdaptor(pa); - continue; - } - for (pp = pPort, i = 0, numPort = 0; i < adaptorPtr->nPorts; i++) { - - if (!(pp->id = FakeClientID(0))) - continue; - - if (!(portPriv = calloc(1, sizeof(XvPortRecPrivate)))) - continue; - - if (!AddResource(pp->id, PortResource, pp)) { - free(portPriv); - continue; - } - - pp->pAdaptor = pa; - pp->pNotify = (XvPortNotifyPtr) NULL; - pp->pDraw = (DrawablePtr) NULL; - pp->client = (ClientPtr) NULL; - pp->grab.client = (ClientPtr) NULL; - pp->time = currentTime; - pp->devPriv.ptr = portPriv; - - portPriv->pScrn = pScrn; - portPriv->AdaptorRec = adaptorPriv; - portPriv->DevPriv.ptr = adaptorPtr->pPortPrivates[i].ptr; - - pp++; - numPort++; - } - pa->nPorts = numPort; - pa->pPorts = pPort; - if (!numPort) { - xf86XVFreeAdaptor(pa); - continue; - } - - pa->base_id = pPort->id; - - pa++; - numAdaptor++; - } - - if (numAdaptor) { - pxvs->nAdaptors = numAdaptor; - pxvs->pAdaptors = pAdaptor; - } - else { - free(pAdaptor); - return FALSE; - } - - return TRUE; -} - -/* Video should be clipped to the intersection of the window cliplist - and the client cliplist specified in the GC for which the video was - initialized. When we need to reclip a window, the GC that started - the video may not even be around anymore. That's why we save the - client clip from the GC when the video is initialized. We then - use xf86XVUpdateCompositeClip to calculate the new composite clip - when we need it. This is different from what DEC did. They saved - the GC and used its clip list when they needed to reclip the window, - even if the client clip was different from the one the video was - initialized with. If the original GC was destroyed, they had to stop - the video. I like the new method better (MArk). - - This function only works for windows. Will need to rewrite when - (if) we support pixmap rendering. -*/ - -static void -xf86XVUpdateCompositeClip(XvPortRecPrivatePtr portPriv) -{ - RegionPtr pregWin, pCompositeClip; - WindowPtr pWin; - Bool freeCompClip = FALSE; - - if (portPriv->pCompositeClip) - return; - - pWin = (WindowPtr) portPriv->pDraw; - - /* get window clip list */ - if (portPriv->subWindowMode == IncludeInferiors) { - pregWin = NotClippedByChildren(pWin); - freeCompClip = TRUE; - } - else - pregWin = &pWin->clipList; - - if (!portPriv->clientClip) { - portPriv->pCompositeClip = pregWin; - portPriv->FreeCompositeClip = freeCompClip; - return; - } - - pCompositeClip = RegionCreate(NullBox, 1); - RegionCopy(pCompositeClip, portPriv->clientClip); - RegionTranslate(pCompositeClip, portPriv->pDraw->x, portPriv->pDraw->y); - RegionIntersect(pCompositeClip, pregWin, pCompositeClip); - - portPriv->pCompositeClip = pCompositeClip; - portPriv->FreeCompositeClip = TRUE; - - if (freeCompClip) { - RegionDestroy(pregWin); - } -} - -/* Save the current clientClip and update the CompositeClip whenever - we have a fresh GC */ - -static void -xf86XVCopyClip(XvPortRecPrivatePtr portPriv, GCPtr pGC) -{ - /* copy the new clip if it exists */ - if (pGC->clientClip) { - if (!portPriv->clientClip) - portPriv->clientClip = RegionCreate(NullBox, 1); - /* Note: this is in window coordinates */ - RegionCopy(portPriv->clientClip, pGC->clientClip); - RegionTranslate(portPriv->clientClip, pGC->clipOrg.x, pGC->clipOrg.y); - } - else if (portPriv->clientClip) { /* free the old clientClip */ - RegionDestroy(portPriv->clientClip); - portPriv->clientClip = NULL; - } - - /* get rid of the old clip list */ - if (portPriv->pCompositeClip && portPriv->FreeCompositeClip) { - RegionDestroy(portPriv->pCompositeClip); - } - - portPriv->pCompositeClip = pGC->pCompositeClip; - portPriv->FreeCompositeClip = FALSE; - portPriv->subWindowMode = pGC->subWindowMode; -} - -static void -xf86XVCopyCompositeClip(XvPortRecPrivatePtr portPriv, - GCPtr pGC, DrawablePtr pDraw) -{ - if (!portPriv->clientClip) - portPriv->clientClip = RegionCreate(NullBox, 1); - /* Keep the original GC composite clip around for ReputImage */ - RegionCopy(portPriv->clientClip, pGC->pCompositeClip); - RegionTranslate(portPriv->clientClip, -pDraw->x, -pDraw->y); - - /* get rid of the old clip list */ - if (portPriv->pCompositeClip && portPriv->FreeCompositeClip) - RegionDestroy(portPriv->pCompositeClip); - - portPriv->pCompositeClip = pGC->pCompositeClip; - portPriv->FreeCompositeClip = FALSE; - portPriv->subWindowMode = pGC->subWindowMode; -} - -static int -xf86XVRegetVideo(XvPortRecPrivatePtr portPriv) -{ - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - xf86XVUpdateCompositeClip(portPriv); - - /* translate the video region to the screen */ - WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; - WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; - WinBox.x2 = WinBox.x1 + portPriv->drw_w; - WinBox.y2 = WinBox.y1 + portPriv->drw_h; - - /* clip to the window composite clip */ - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); - - /* that's all if it's totally obscured */ - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->GetVideo) (portPriv->pScrn, - portPriv->vid_x, portPriv->vid_y, - WinBox.x1, WinBox.y1, - portPriv->vid_w, portPriv->vid_h, - portPriv->drw_w, portPriv->drw_h, - &ClipRegion, portPriv->DevPriv.ptr, - portPriv->pDraw); - - if (ret == Success) - portPriv->isOn = XV_ON; - - CLIP_VIDEO_BAILOUT: - - if ((clippedAway || (ret != Success)) && portPriv->isOn == XV_ON) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if (!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -xf86XVReputVideo(XvPortRecPrivatePtr portPriv) -{ - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - xf86XVUpdateCompositeClip(portPriv); - - /* translate the video region to the screen */ - WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; - WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; - WinBox.x2 = WinBox.x1 + portPriv->drw_w; - WinBox.y2 = WinBox.y1 + portPriv->drw_h; - - /* clip to the window composite clip */ - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); - - /* clip and translate to the viewport */ - if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = portPriv->pScrn->frameX0; - VPBox.y1 = portPriv->pScrn->frameY0; - VPBox.x2 = portPriv->pScrn->frameX1 + 1; - VPBox.y2 = portPriv->pScrn->frameY1 + 1; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - /* that's all if it's totally obscured */ - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->PutVideo) (portPriv->pScrn, - portPriv->vid_x, portPriv->vid_y, - WinBox.x1, WinBox.y1, - portPriv->vid_w, portPriv->vid_h, - portPriv->drw_w, portPriv->drw_h, - &ClipRegion, portPriv->DevPriv.ptr, - portPriv->pDraw); - - if (ret == Success) - portPriv->isOn = XV_ON; - - CLIP_VIDEO_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if (!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -/* Reput image/still */ -static int -xf86XVReputImage(XvPortRecPrivatePtr portPriv) -{ - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - xf86XVUpdateCompositeClip(portPriv); - - /* the clip can get smaller over time */ - RegionCopy(portPriv->clientClip, portPriv->pCompositeClip); - RegionTranslate(portPriv->clientClip, - -portPriv->pDraw->x, -portPriv->pDraw->y); - - /* translate the video region to the screen */ - WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; - WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; - WinBox.x2 = WinBox.x1 + portPriv->drw_w; - WinBox.y2 = WinBox.y1 + portPriv->drw_h; - - /* clip to the window composite clip */ - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); - - /* clip and translate to the viewport */ - if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = portPriv->pScrn->frameX0; - VPBox.y1 = portPriv->pScrn->frameY0; - VPBox.x2 = portPriv->pScrn->frameX1 + 1; - VPBox.y2 = portPriv->pScrn->frameY1 + 1; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - /* that's all if it's totally obscured */ - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->ReputImage) (portPriv->pScrn, - portPriv->vid_x, portPriv->vid_y, - WinBox.x1, WinBox.y1, - portPriv->vid_w, portPriv->vid_h, - portPriv->drw_w, portPriv->drw_h, - &ClipRegion, - portPriv->DevPriv.ptr, - portPriv->pDraw); - - portPriv->isOn = (ret == Success) ? XV_ON : XV_OFF; - - CLIP_VIDEO_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if (!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -xf86XVReputAllVideo(WindowPtr pWin, void *data) -{ - XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); - - while (WinPriv) { - if (WinPriv->PortRec->type == XvInputMask) - xf86XVReputVideo(WinPriv->PortRec); - else - xf86XVRegetVideo(WinPriv->PortRec); - WinPriv = WinPriv->next; - } - - return WT_WALKCHILDREN; -} - -static int -xf86XVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv) -{ - XF86XVWindowPtr winPriv, PrivRoot; - - winPriv = PrivRoot = GET_XF86XV_WINDOW(pWin); - - /* Enlist our port in the window private */ - while (winPriv) { - if (winPriv->PortRec == portPriv) /* we're already listed */ - break; - winPriv = winPriv->next; - } - - if (!winPriv) { - winPriv = calloc(1, sizeof(XF86XVWindowRec)); - if (!winPriv) - return BadAlloc; - winPriv->PortRec = portPriv; - winPriv->next = PrivRoot; - dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, winPriv); - } - - portPriv->pDraw = (DrawablePtr) pWin; - - return Success; -} - -static void -xf86XVRemovePortFromWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv) -{ - XF86XVWindowPtr winPriv, prevPriv = NULL; - - winPriv = GET_XF86XV_WINDOW(pWin); - - while (winPriv) { - if (winPriv->PortRec == portPriv) { - if (prevPriv) - prevPriv->next = winPriv->next; - else - dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, - winPriv->next); - free(winPriv); - break; - } - prevPriv = winPriv; - winPriv = winPriv->next; - } - portPriv->pDraw = NULL; - if (portPriv->ckeyFilled) { - RegionDestroy(portPriv->ckeyFilled); - portPriv->ckeyFilled = NULL; - } - portPriv->clipChanged = FALSE; -} - -static void -xf86XVReputOrStopPort(XvPortRecPrivatePtr pPriv, WindowPtr pWin, Bool visible) -{ - if (!visible) { - if (pPriv->isOn == XV_ON) { - (*pPriv->AdaptorRec->StopVideo) (pPriv->pScrn, pPriv->DevPriv.ptr, - FALSE); - pPriv->isOn = XV_PENDING; - } - - if (!pPriv->type) /* overlaid still/image */ - xf86XVRemovePortFromWindow(pWin, pPriv); - - return; - } - - switch (pPriv->type) { - case XvInputMask: - xf86XVReputVideo(pPriv); - break; - case XvOutputMask: - xf86XVRegetVideo(pPriv); - break; - default: /* overlaid still/image */ - if (pPriv->AdaptorRec->ReputImage) - xf86XVReputImage(pPriv); - break; - } -} - -static void -xf86XVReputOrStopAllPorts(ScrnInfoPtr pScrn, Bool onlyChanged) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); - XvAdaptorPtr pa; - int c, i; - - for (c = pxvs->nAdaptors, pa = pxvs->pAdaptors; c > 0; c--, pa++) { - XvPortPtr pPort = pa->pPorts; - - for (i = pa->nPorts; i > 0; i--, pPort++) { - XvPortRecPrivatePtr pPriv = - (XvPortRecPrivatePtr) pPort->devPriv.ptr; - WindowPtr pWin = (WindowPtr) pPriv->pDraw; - Bool visible; - - if (pPriv->isOn == XV_OFF || !pWin) - continue; - - if (onlyChanged && !pPriv->clipChanged) - continue; - - visible = pWin->visibility == VisibilityUnobscured || - pWin->visibility == VisibilityPartiallyObscured; - - /* - * Stop and remove still/images if - * ReputImage isn't supported. - */ - if (!pPriv->type && !pPriv->AdaptorRec->ReputImage) - visible = FALSE; - - xf86XVReputOrStopPort(pPriv, pWin, visible); - - pPriv->clipChanged = FALSE; - } - } -} - -/**** ScreenRec fields ****/ - -static Bool -xf86XVDestroyWindow(WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - XF86XVWindowPtr tmp, WinPriv = GET_XF86XV_WINDOW(pWin); - int ret; - - while (WinPriv) { - XvPortRecPrivatePtr pPriv = WinPriv->PortRec; - - if (pPriv->isOn > XV_OFF) { - (*pPriv->AdaptorRec->StopVideo) (pPriv->pScrn, pPriv->DevPriv.ptr, - TRUE); - pPriv->isOn = XV_OFF; - } - - pPriv->pDraw = NULL; - tmp = WinPriv; - WinPriv = WinPriv->next; - free(tmp); - } - - dixSetPrivate(&pWin->devPrivates, XF86XVWindowKey, NULL); - - pScreen->DestroyWindow = ScreenPriv->DestroyWindow; - ret = (*pScreen->DestroyWindow) (pWin); - pScreen->DestroyWindow = xf86XVDestroyWindow; - - return ret; -} - -static void -xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin, VTKind kind) -{ - ScreenPtr pScreen; - XF86XVScreenPtr ScreenPriv; - ScrnInfoPtr pScrn; - - if (pWin) - pScreen = pWin->drawable.pScreen; - else - pScreen = pLayerWin->drawable.pScreen; - - ScreenPriv = GET_XF86XV_SCREEN(pScreen); - pScrn = xf86ScreenToScrn(pScreen); - - xf86XVReputOrStopAllPorts(pScrn, TRUE); - - pScreen->PostValidateTree = ScreenPriv->PostValidateTree; - if (pScreen->PostValidateTree) { - (*pScreen->PostValidateTree) (pWin, pLayerWin, kind); - } - ScreenPriv->PostValidateTree = PostValidateTreeUndefined; -} - -static void -xf86XVWindowExposures(WindowPtr pWin, RegionPtr reg1) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); - XvPortRecPrivatePtr pPriv; - Bool AreasExposed; - - AreasExposed = (WinPriv && reg1 && RegionNotEmpty(reg1)); - - pScreen->WindowExposures = ScreenPriv->WindowExposures; - (*pScreen->WindowExposures) (pWin, reg1); - pScreen->WindowExposures = xf86XVWindowExposures; - - /* filter out XClearWindow/Area */ - if (!pWin->valdata) - return; - - while (WinPriv) { - Bool visible = TRUE; - - pPriv = WinPriv->PortRec; - - /* - * Stop and remove still/images if areas were exposed and - * ReputImage isn't supported. - */ - if (!pPriv->type && !pPriv->AdaptorRec->ReputImage) - visible = !AreasExposed; - - /* - * Subtract exposed areas from overlaid image to match textured video - * behavior. - */ - if (!pPriv->type && pPriv->clientClip) - RegionSubtract(pPriv->clientClip, pPriv->clientClip, reg1); - - if (visible && pPriv->ckeyFilled) { - RegionRec tmp; - - RegionNull(&tmp); - RegionCopy(&tmp, reg1); - RegionTranslate(&tmp, pWin->drawable.x, pWin->drawable.y); - RegionSubtract(pPriv->ckeyFilled, pPriv->ckeyFilled, &tmp); - } - - WinPriv = WinPriv->next; - xf86XVReputOrStopPort(pPriv, pWin, visible); - - pPriv->clipChanged = FALSE; - } -} - -static void -xf86XVClipNotify(WindowPtr pWin, int dx, int dy) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); - XvPortRecPrivatePtr pPriv; - - while (WinPriv) { - pPriv = WinPriv->PortRec; - - if (pPriv->pCompositeClip && pPriv->FreeCompositeClip) - RegionDestroy(pPriv->pCompositeClip); - - pPriv->pCompositeClip = NULL; - - pPriv->clipChanged = TRUE; - - if (ScreenPriv->PostValidateTree == PostValidateTreeUndefined) { - ScreenPriv->PostValidateTree = pScreen->PostValidateTree; - pScreen->PostValidateTree = xf86XVPostValidateTree; - } - - WinPriv = WinPriv->next; - } - - if (ScreenPriv->ClipNotify) { - pScreen->ClipNotify = ScreenPriv->ClipNotify; - (*pScreen->ClipNotify) (pWin, dx, dy); - pScreen->ClipNotify = xf86XVClipNotify; - } -} - -/**** Required XvScreenRec fields ****/ - -static Bool -xf86XVCloseScreen(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - XvAdaptorPtr pa; - int c; - - if (!ScreenPriv) - return TRUE; - - pScreen->DestroyWindow = ScreenPriv->DestroyWindow; - pScreen->WindowExposures = ScreenPriv->WindowExposures; - pScreen->ClipNotify = ScreenPriv->ClipNotify; - pScreen->CloseScreen = ScreenPriv->CloseScreen; - - pScrn->EnterVT = ScreenPriv->EnterVT; - pScrn->LeaveVT = ScreenPriv->LeaveVT; - pScrn->AdjustFrame = ScreenPriv->AdjustFrame; - pScrn->ModeSet = ScreenPriv->ModeSet; - - for (c = 0, pa = pxvs->pAdaptors; c < pxvs->nAdaptors; c++, pa++) { - xf86XVFreeAdaptor(pa); - } - - free(pxvs->pAdaptors); - free(ScreenPriv); - - return pScreen->CloseScreen(pScreen); -} - -/**** ScrnInfoRec fields ****/ - -static Bool -xf86XVEnterVT(ScrnInfoPtr pScrn) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - Bool ret; - - pScrn->EnterVT = ScreenPriv->EnterVT; - ret = (*ScreenPriv->EnterVT) (pScrn); - ScreenPriv->EnterVT = pScrn->EnterVT; - pScrn->EnterVT = xf86XVEnterVT; - - if (ret) - WalkTree(pScreen, xf86XVReputAllVideo, 0); - - return ret; -} - -static void -xf86XVLeaveVT(ScrnInfoPtr pScrn) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - XvAdaptorPtr pAdaptor; - XvPortPtr pPort; - XvPortRecPrivatePtr pPriv; - int i, j; - - for (i = 0; i < pxvs->nAdaptors; i++) { - pAdaptor = &pxvs->pAdaptors[i]; - for (j = 0; j < pAdaptor->nPorts; j++) { - pPort = &pAdaptor->pPorts[j]; - pPriv = (XvPortRecPrivatePtr) pPort->devPriv.ptr; - if (pPriv->isOn > XV_OFF) { - - (*pPriv->AdaptorRec->StopVideo) (pPriv->pScrn, - pPriv->DevPriv.ptr, TRUE); - pPriv->isOn = XV_OFF; - - if (pPriv->pCompositeClip && pPriv->FreeCompositeClip) - RegionDestroy(pPriv->pCompositeClip); - - pPriv->pCompositeClip = NULL; - - if (!pPriv->type && pPriv->pDraw) { /* still */ - xf86XVRemovePortFromWindow((WindowPtr) pPriv->pDraw, pPriv); - } - } - } - } - - pScrn->LeaveVT = ScreenPriv->LeaveVT; - (*ScreenPriv->LeaveVT) (pScrn); - ScreenPriv->LeaveVT = pScrn->LeaveVT; - pScrn->LeaveVT = xf86XVLeaveVT; -} - -static void -xf86XVAdjustFrame(ScrnInfoPtr pScrn, int x, int y) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen); - - if (ScreenPriv->AdjustFrame) { - pScrn->AdjustFrame = ScreenPriv->AdjustFrame; - (*pScrn->AdjustFrame) (pScrn, x, y); - pScrn->AdjustFrame = xf86XVAdjustFrame; - } - - xf86XVReputOrStopAllPorts(pScrn, FALSE); -} - -static void -xf86XVModeSet(ScrnInfoPtr pScrn) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - XF86XVScreenPtr ScreenPriv; - - /* Can be called before pScrn->pScreen is set */ - if (!pScreen) - return; - - ScreenPriv = GET_XF86XV_SCREEN(pScreen); - - if (ScreenPriv->ModeSet) { - pScrn->ModeSet = ScreenPriv->ModeSet; - (*pScrn->ModeSet) (pScrn); - pScrn->ModeSet = xf86XVModeSet; - } - - xf86XVReputOrStopAllPorts(pScrn, FALSE); -} - -/**** XvAdaptorRec fields ****/ - -static int -xf86XVPutVideo(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - int result; - - /* No dumping video to pixmaps... For now anyhow */ - if (pDraw->type != DRAWABLE_WINDOW) { - pPort->pDraw = (DrawablePtr) NULL; - return BadAlloc; - } - - /* If we are changing windows, unregister our port in the old window */ - if (portPriv->pDraw && (portPriv->pDraw != pDraw)) - xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - - /* Register our port with the new window */ - result = xf86XVEnlistPortInWindow((WindowPtr) pDraw, portPriv); - if (result != Success) - return result; - - portPriv->type = XvInputMask; - - /* save a copy of these parameters */ - portPriv->vid_x = vid_x; - portPriv->vid_y = vid_y; - portPriv->vid_w = vid_w; - portPriv->vid_h = vid_h; - portPriv->drw_x = drw_x; - portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; - portPriv->drw_h = drw_h; - - /* make sure we have the most recent copy of the clientClip */ - xf86XVCopyClip(portPriv, pGC); - - /* To indicate to the DI layer that we were successful */ - pPort->pDraw = pDraw; - - if (!portPriv->pScrn->vtSema) - return Success; /* Success ? */ - - return (xf86XVReputVideo(portPriv)); -} - -static int -xf86XVPutStill(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - if (!portPriv->pScrn->vtSema) - return Success; /* Success ? */ - - WinBox.x1 = pDraw->x + drw_x; - WinBox.y1 = pDraw->y + drw_y; - WinBox.x2 = WinBox.x1 + drw_w; - WinBox.y2 = WinBox.y1 + drw_h; - - xf86XVCopyCompositeClip(portPriv, pGC, pDraw); - - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); - - if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = portPriv->pScrn->frameX0; - VPBox.y1 = portPriv->pScrn->frameY0; - VPBox.x2 = portPriv->pScrn->frameX1 + 1; - VPBox.y2 = portPriv->pScrn->frameY1 + 1; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - if (portPriv->pDraw) { - xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - } - - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto PUT_STILL_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->PutStill) (portPriv->pScrn, - vid_x, vid_y, WinBox.x1, WinBox.y1, - vid_w, vid_h, drw_w, drw_h, - &ClipRegion, portPriv->DevPriv.ptr, - pDraw); - - if ((ret == Success) && - (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_STILLS)) { - - xf86XVEnlistPortInWindow((WindowPtr) pDraw, portPriv); - portPriv->isOn = XV_ON; - portPriv->vid_x = vid_x; - portPriv->vid_y = vid_y; - portPriv->vid_w = vid_w; - portPriv->vid_h = vid_h; - portPriv->drw_x = drw_x; - portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; - portPriv->drw_h = drw_h; - portPriv->type = 0; /* no mask means it's transient and should - not be reput once it's removed */ - pPort->pDraw = pDraw; /* make sure we can get stop requests */ - } - - PUT_STILL_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if (!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -xf86XVGetVideo(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - int result; - - /* No pixmaps... For now anyhow */ - if (pDraw->type != DRAWABLE_WINDOW) { - pPort->pDraw = (DrawablePtr) NULL; - return BadAlloc; - } - - /* If we are changing windows, unregister our port in the old window */ - if (portPriv->pDraw && (portPriv->pDraw != pDraw)) - xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - - /* Register our port with the new window */ - result = xf86XVEnlistPortInWindow((WindowPtr) pDraw, portPriv); - if (result != Success) - return result; - - portPriv->type = XvOutputMask; - - /* save a copy of these parameters */ - portPriv->vid_x = vid_x; - portPriv->vid_y = vid_y; - portPriv->vid_w = vid_w; - portPriv->vid_h = vid_h; - portPriv->drw_x = drw_x; - portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; - portPriv->drw_h = drw_h; - - /* make sure we have the most recent copy of the clientClip */ - xf86XVCopyClip(portPriv, pGC); - - /* To indicate to the DI layer that we were successful */ - pPort->pDraw = pDraw; - - if (!portPriv->pScrn->vtSema) - return Success; /* Success ? */ - - return (xf86XVRegetVideo(portPriv)); -} - -static int -xf86XVGetStill(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - if (!portPriv->pScrn->vtSema) - return Success; /* Success ? */ - - WinBox.x1 = pDraw->x + drw_x; - WinBox.y1 = pDraw->y + drw_y; - WinBox.x2 = WinBox.x1 + drw_w; - WinBox.y2 = WinBox.y1 + drw_h; - - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); - - if (portPriv->pDraw) { - xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - } - - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto GET_STILL_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->GetStill) (portPriv->pScrn, - vid_x, vid_y, WinBox.x1, WinBox.y1, - vid_w, vid_h, drw_w, drw_h, - &ClipRegion, portPriv->DevPriv.ptr, - pDraw); - - GET_STILL_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -xf86XVStopVideo(XvPortPtr pPort, DrawablePtr pDraw) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - xf86XVRemovePortFromWindow((WindowPtr) pDraw, portPriv); - - if (!portPriv->pScrn->vtSema) - return Success; /* Success ? */ - - /* Must free resources. */ - - if (portPriv->isOn > XV_OFF) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, - portPriv->DevPriv.ptr, TRUE); - portPriv->isOn = XV_OFF; - } - - return Success; -} - -static int -xf86XVSetPortAttribute(XvPortPtr pPort, Atom attribute, INT32 value) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - return ((*portPriv->AdaptorRec->SetPortAttribute) (portPriv->pScrn, - attribute, value, - portPriv->DevPriv.ptr)); -} - -static int -xf86XVGetPortAttribute(XvPortPtr pPort, Atom attribute, INT32 *p_value) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - return ((*portPriv->AdaptorRec->GetPortAttribute) (portPriv->pScrn, - attribute, p_value, - portPriv->DevPriv.ptr)); -} - -static int -xf86XVQueryBestSize(XvPortPtr pPort, - CARD8 motion, - CARD16 vid_w, CARD16 vid_h, - CARD16 drw_w, CARD16 drw_h, - unsigned int *p_w, unsigned int *p_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - (*portPriv->AdaptorRec->QueryBestSize) (portPriv->pScrn, - (Bool) motion, vid_w, vid_h, drw_w, - drw_h, p_w, p_h, - portPriv->DevPriv.ptr); - - return Success; -} - -static int -xf86XVPutImage(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 src_x, INT16 src_y, - CARD16 src_w, CARD16 src_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h, - XvImagePtr format, - unsigned char *data, Bool sync, CARD16 width, CARD16 height) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - if (!portPriv->pScrn->vtSema) - return Success; /* Success ? */ - - xf86XVCopyCompositeClip(portPriv, pGC, pDraw); - - WinBox.x1 = pDraw->x + drw_x; - WinBox.y1 = pDraw->y + drw_y; - WinBox.x2 = WinBox.x1 + drw_w; - WinBox.y2 = WinBox.y1 + drw_h; - - RegionInit(&WinRegion, &WinBox, 1); - RegionNull(&ClipRegion); - RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); - - if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = portPriv->pScrn->frameX0; - VPBox.y1 = portPriv->pScrn->frameY0; - VPBox.x2 = portPriv->pScrn->frameX1 + 1; - VPBox.y2 = portPriv->pScrn->frameY1 + 1; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - /* If we are changing windows, unregister our port in the old window */ - if (portPriv->pDraw && (portPriv->pDraw != pDraw)) - xf86XVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - - /* Register our port with the new window */ - ret = xf86XVEnlistPortInWindow((WindowPtr) pDraw, portPriv); - if (ret != Success) - goto PUT_IMAGE_BAILOUT; - - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto PUT_IMAGE_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->PutImage) (portPriv->pScrn, - src_x, src_y, WinBox.x1, WinBox.y1, - src_w, src_h, drw_w, drw_h, - format->id, data, width, height, - sync, &ClipRegion, - portPriv->DevPriv.ptr, pDraw); - - if ((ret == Success) && - (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_IMAGES)) { - - portPriv->isOn = XV_ON; - portPriv->vid_x = src_x; - portPriv->vid_y = src_y; - portPriv->vid_w = src_w; - portPriv->vid_h = src_h; - portPriv->drw_x = drw_x; - portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; - portPriv->drw_h = drw_h; - portPriv->type = 0; /* no mask means it's transient and should - not be reput once it's removed */ - pPort->pDraw = pDraw; /* make sure we can get stop requests */ - } - - PUT_IMAGE_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->pScrn, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if (!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -xf86XVQueryImageAttributes(XvPortPtr pPort, - XvImagePtr format, - CARD16 *width, - CARD16 *height, int *pitches, int *offsets) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - return (*portPriv->AdaptorRec->QueryImageAttributes) (portPriv->pScrn, - format->id, width, - height, pitches, - offsets); -} - -void -xf86XVFillKeyHelperDrawable(DrawablePtr pDraw, CARD32 key, RegionPtr fillboxes) -{ - ScreenPtr pScreen = pDraw->pScreen; - - if (!xf86ScreenToScrn(pScreen)->vtSema) - return; - - XvFillColorKey(pDraw, key, fillboxes); -} - -void -xf86XVFillKeyHelper(ScreenPtr pScreen, CARD32 key, RegionPtr fillboxes) -{ - xf86XVFillKeyHelperDrawable(&pScreen->root->drawable, key, fillboxes); -} - -void -xf86XVFillKeyHelperPort(DrawablePtr pDraw, void *data, CARD32 key, - RegionPtr clipboxes, Bool fillEverything) -{ - WindowPtr pWin = (WindowPtr) pDraw; - XF86XVWindowPtr WinPriv = GET_XF86XV_WINDOW(pWin); - XvPortRecPrivatePtr portPriv = NULL; - RegionRec reg; - RegionPtr fillboxes; - - while (WinPriv) { - XvPortRecPrivatePtr pPriv = WinPriv->PortRec; - - if (data == pPriv->DevPriv.ptr) { - portPriv = pPriv; - break; - } - - WinPriv = WinPriv->next; - } - - if (!portPriv) - return; - - if (!portPriv->ckeyFilled) - portPriv->ckeyFilled = RegionCreate(NULL, 0); - - if (!fillEverything) { - RegionNull(®); - fillboxes = ® - RegionSubtract(fillboxes, clipboxes, portPriv->ckeyFilled); - - if (!RegionNotEmpty(fillboxes)) - goto out; - } - else - fillboxes = clipboxes; - - RegionCopy(portPriv->ckeyFilled, clipboxes); - - xf86XVFillKeyHelperDrawable(pDraw, key, fillboxes); - out: - if (!fillEverything) - RegionUninit(®); -} - -/* xf86XVClipVideoHelper - - - Takes the dst box in standard X BoxRec form (top and left - edges inclusive, bottom and right exclusive). The new dst - box is returned. The source boundaries are given (x1, y1 - inclusive, x2, y2 exclusive) and returned are the new source - boundaries in 16.16 fixed point. -*/ - -Bool -xf86XVClipVideoHelper(BoxPtr dst, - INT32 *xa, - INT32 *xb, - INT32 *ya, - INT32 *yb, RegionPtr reg, INT32 width, INT32 height) -{ - double xsw, xdw, ysw, ydw; - INT32 delta; - BoxPtr extents = RegionExtents(reg); - int diff; - - xsw = (*xb - *xa) << 16; - xdw = dst->x2 - dst->x1; - ysw = (*yb - *ya) << 16; - ydw = dst->y2 - dst->y1; - - *xa <<= 16; - *xb <<= 16; - *ya <<= 16; - *yb <<= 16; - - diff = extents->x1 - dst->x1; - if (diff > 0) { - dst->x1 = extents->x1; - *xa += (diff * xsw) / xdw; - } - diff = dst->x2 - extents->x2; - if (diff > 0) { - dst->x2 = extents->x2; - *xb -= (diff * xsw) / xdw; - } - diff = extents->y1 - dst->y1; - if (diff > 0) { - dst->y1 = extents->y1; - *ya += (diff * ysw) / ydw; - } - diff = dst->y2 - extents->y2; - if (diff > 0) { - dst->y2 = extents->y2; - *yb -= (diff * ysw) / ydw; - } - - if (*xa < 0) { - diff = (((-*xa) * xdw) + xsw - 1) / xsw; - dst->x1 += diff; - *xa += (diff * xsw) / xdw; - } - delta = *xb - (width << 16); - if (delta > 0) { - diff = ((delta * xdw) + xsw - 1) / xsw; - dst->x2 -= diff; - *xb -= (diff * xsw) / xdw; - } - if (*xa >= *xb) - return FALSE; - - if (*ya < 0) { - diff = (((-*ya) * ydw) + ysw - 1) / ysw; - dst->y1 += diff; - *ya += (diff * ysw) / ydw; - } - delta = *yb - (height << 16); - if (delta > 0) { - diff = ((delta * ydw) + ysw - 1) / ysw; - dst->y2 -= diff; - *yb -= (diff * ysw) / ydw; - } - if (*ya >= *yb) - return FALSE; - - if ((dst->x1 > extents->x1) || (dst->x2 < extents->x2) || - (dst->y1 > extents->y1) || (dst->y2 < extents->y2)) { - RegionRec clipReg; - - RegionInit(&clipReg, dst, 1); - RegionIntersect(reg, reg, &clipReg); - RegionUninit(&clipReg); - } - return TRUE; -} - -void -xf86XVCopyYUV12ToPacked(const void *srcy, - const void *srcv, - const void *srcu, - void *dst, - int srcPitchy, - int srcPitchuv, int dstPitch, int h, int w) -{ - CARD32 *Dst; - const CARD8 *Y, *U, *V; - int i, j; - - w >>= 1; - - for (j = 0; j < h; j++) { - Dst = dst; - Y = srcy; - V = srcv; - U = srcu; - i = w; - while (i >= 4) { -#if X_BYTE_ORDER == X_LITTLE_ENDIAN - Dst[0] = Y[0] | (Y[1] << 16) | (U[0] << 8) | (V[0] << 24); - Dst[1] = Y[2] | (Y[3] << 16) | (U[1] << 8) | (V[1] << 24); - Dst[2] = Y[4] | (Y[5] << 16) | (U[2] << 8) | (V[2] << 24); - Dst[3] = Y[6] | (Y[7] << 16) | (U[3] << 8) | (V[3] << 24); -#else - /* This assumes a little-endian framebuffer */ - Dst[0] = (Y[0] << 24) | (Y[1] << 8) | (U[0] << 16) | V[0]; - Dst[1] = (Y[2] << 24) | (Y[3] << 8) | (U[1] << 16) | V[1]; - Dst[2] = (Y[4] << 24) | (Y[5] << 8) | (U[2] << 16) | V[2]; - Dst[3] = (Y[6] << 24) | (Y[7] << 8) | (U[3] << 16) | V[3]; -#endif - Dst += 4; - Y += 8; - V += 4; - U += 4; - i -= 4; - } - - while (i--) { -#if X_BYTE_ORDER == X_LITTLE_ENDIAN - Dst[0] = Y[0] | (Y[1] << 16) | (U[0] << 8) | (V[0] << 24); -#else - /* This assumes a little-endian framebuffer */ - Dst[0] = (Y[0] << 24) | (Y[1] << 8) | (U[0] << 16) | V[0]; -#endif - Dst++; - Y += 2; - V++; - U++; - } - - dst = (CARD8 *) dst + dstPitch; - srcy = (const CARD8 *) srcy + srcPitchy; - if (j & 1) { - srcu = (const CARD8 *) srcu + srcPitchuv; - srcv = (const CARD8 *) srcv + srcPitchuv; - } - } -} - -void -xf86XVCopyPacked(const void *src, - void *dst, int srcPitch, int dstPitch, int h, int w) -{ - const CARD32 *Src; - CARD32 *Dst; - int i; - - w >>= 1; - while (--h >= 0) { - do { - Dst = dst; - Src = src; - i = w; - while (i >= 4) { - Dst[0] = Src[0]; - Dst[1] = Src[1]; - Dst[2] = Src[2]; - Dst[3] = Src[3]; - Dst += 4; - Src += 4; - i -= 4; - } - if (!i) - break; - Dst[0] = Src[0]; - if (i == 1) - break; - Dst[1] = Src[1]; - if (i == 2) - break; - Dst[2] = Src[2]; - } while (0); - - src = (const CARD8 *) src + srcPitch; - dst = (CARD8 *) dst + dstPitch; - } -} diff --git a/hw/xfree86/common/xf86xv.h b/hw/xfree86/common/xf86xv.h deleted file mode 100644 index 6f8662c04..000000000 --- a/hw/xfree86/common/xf86xv.h +++ /dev/null @@ -1,229 +0,0 @@ - -/* - * Copyright (c) 1998-2003 by The XFree86 Project, 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). - */ - -#ifndef _XF86XV_H_ -#define _XF86XV_H_ - -#include "xvdix.h" -#include "xf86str.h" - -#define VIDEO_OVERLAID_IMAGES 0x00000004 -#define VIDEO_OVERLAID_STILLS 0x00000008 -/* - * Usage of VIDEO_CLIP_TO_VIEWPORT is not recommended. - * It can make reput behaviour inconsistent. - */ -#define VIDEO_CLIP_TO_VIEWPORT 0x00000010 - -typedef XvImageRec XF86ImageRec, *XF86ImagePtr; - -typedef struct { - ScrnInfoPtr pScrn; - int id; - unsigned short width, height; - int *pitches; /* bytes */ - int *offsets; /* in bytes from start of framebuffer */ - DevUnion devPrivate; -} XF86SurfaceRec, *XF86SurfacePtr; - -typedef int (*PutVideoFuncPtr) (ScrnInfoPtr pScrn, - short vid_x, short vid_y, short drw_x, - short drw_y, short vid_w, short vid_h, - short drw_w, short drw_h, RegionPtr clipBoxes, - void *data, DrawablePtr pDraw); -typedef int (*PutStillFuncPtr) (ScrnInfoPtr pScrn, short vid_x, short vid_y, - short drw_x, short drw_y, short vid_w, - short vid_h, short drw_w, short drw_h, - RegionPtr clipBoxes, void *data, - DrawablePtr pDraw); -typedef int (*GetVideoFuncPtr) (ScrnInfoPtr pScrn, short vid_x, short vid_y, - short drw_x, short drw_y, short vid_w, - short vid_h, short drw_w, short drw_h, - RegionPtr clipBoxes, void *data, - DrawablePtr pDraw); -typedef int (*GetStillFuncPtr) (ScrnInfoPtr pScrn, short vid_x, short vid_y, - short drw_x, short drw_y, short vid_w, - short vid_h, short drw_w, short drw_h, - RegionPtr clipBoxes, void *data, - DrawablePtr pDraw); -typedef void (*StopVideoFuncPtr) (ScrnInfoPtr pScrn, void *data, Bool Exit); -typedef int (*SetPortAttributeFuncPtr) (ScrnInfoPtr pScrn, Atom attribute, - INT32 value, void *data); -typedef int (*GetPortAttributeFuncPtr) (ScrnInfoPtr pScrn, Atom attribute, - INT32 *value, void *data); -typedef void (*QueryBestSizeFuncPtr) (ScrnInfoPtr pScrn, Bool motion, - short vid_w, short vid_h, short drw_w, - short drw_h, unsigned int *p_w, - unsigned int *p_h, void *data); -typedef int (*PutImageFuncPtr) (ScrnInfoPtr pScrn, short src_x, short src_y, - short drw_x, short drw_y, short src_w, - short src_h, short drw_w, short drw_h, - int image, unsigned char *buf, short width, - short height, Bool Sync, RegionPtr clipBoxes, - void *data, DrawablePtr pDraw); -typedef int (*ReputImageFuncPtr) (ScrnInfoPtr pScrn, short src_x, short src_y, - short drw_x, short drw_y, short src_w, - short src_h, short drw_w, short drw_h, - RegionPtr clipBoxes, void *data, - DrawablePtr pDraw); -typedef int (*QueryImageAttributesFuncPtr) (ScrnInfoPtr pScrn, int image, - unsigned short *width, - unsigned short *height, - int *pitches, int *offsets); - -typedef enum { - XV_OFF, - XV_PENDING, - XV_ON -} XvStatus; - -/*** this is what the driver needs to fill out ***/ - -typedef struct { - int id; - const char *name; - unsigned short width, height; - XvRationalRec rate; -} XF86VideoEncodingRec, *XF86VideoEncodingPtr; - -typedef struct { - char depth; - short class; -} XF86VideoFormatRec, *XF86VideoFormatPtr; - -typedef XvAttributeRec XF86AttributeRec, *XF86AttributePtr; - -typedef struct { - unsigned int type; - int flags; - const char *name; - int nEncodings; - XF86VideoEncodingPtr pEncodings; - int nFormats; - XF86VideoFormatPtr pFormats; - int nPorts; - DevUnion *pPortPrivates; - int nAttributes; - XF86AttributePtr pAttributes; - int nImages; - XF86ImagePtr pImages; - PutVideoFuncPtr PutVideo; - PutStillFuncPtr PutStill; - GetVideoFuncPtr GetVideo; - GetStillFuncPtr GetStill; - StopVideoFuncPtr StopVideo; - SetPortAttributeFuncPtr SetPortAttribute; - GetPortAttributeFuncPtr GetPortAttribute; - QueryBestSizeFuncPtr QueryBestSize; - PutImageFuncPtr PutImage; - ReputImageFuncPtr ReputImage; /* image/still */ - QueryImageAttributesFuncPtr QueryImageAttributes; -} XF86VideoAdaptorRec, *XF86VideoAdaptorPtr; - -typedef struct { - XF86ImagePtr image; - int flags; - int (*alloc_surface) (ScrnInfoPtr pScrn, - int id, - unsigned short width, - unsigned short height, XF86SurfacePtr surface); - int (*free_surface) (XF86SurfacePtr surface); - int (*display) (XF86SurfacePtr surface, - short vid_x, short vid_y, - short drw_x, short drw_y, - short vid_w, short vid_h, - short drw_w, short drw_h, RegionPtr clipBoxes); - int (*stop) (XF86SurfacePtr surface); - int (*getAttribute) (ScrnInfoPtr pScrn, Atom attr, INT32 *value); - int (*setAttribute) (ScrnInfoPtr pScrn, Atom attr, INT32 value); - int max_width; - int max_height; - int num_attributes; - XF86AttributePtr attributes; -} XF86OffscreenImageRec, *XF86OffscreenImagePtr; - -extern _X_EXPORT Bool - xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * Adaptors, int num); - -typedef int (*xf86XVInitGenericAdaptorPtr) (ScrnInfoPtr pScrn, - XF86VideoAdaptorPtr ** Adaptors); - -extern _X_EXPORT int - xf86XVRegisterGenericAdaptorDriver(xf86XVInitGenericAdaptorPtr InitFunc); - -extern _X_EXPORT int - xf86XVListGenericAdaptors(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr ** Adaptors); - -extern _X_EXPORT Bool - -xf86XVRegisterOffscreenImages(ScreenPtr pScreen, - XF86OffscreenImagePtr images, int num); - -extern _X_EXPORT XF86OffscreenImagePtr -xf86XVQueryOffscreenImages(ScreenPtr pScreen, int *num); - -extern _X_EXPORT XF86VideoAdaptorPtr xf86XVAllocateVideoAdaptorRec(ScrnInfoPtr - pScrn); - -extern _X_EXPORT void xf86XVFreeVideoAdaptorRec(XF86VideoAdaptorPtr ptr); - -extern _X_EXPORT void - xf86XVFillKeyHelper(ScreenPtr pScreen, CARD32 key, RegionPtr clipboxes); - -extern _X_EXPORT void - -xf86XVFillKeyHelperDrawable(DrawablePtr pDraw, CARD32 key, RegionPtr clipboxes); - -extern _X_EXPORT void - -xf86XVFillKeyHelperPort(DrawablePtr pDraw, void *data, CARD32 key, - RegionPtr clipboxes, Bool fillEverything); - -extern _X_EXPORT Bool - -xf86XVClipVideoHelper(BoxPtr dst, - INT32 *xa, - INT32 *xb, - INT32 *ya, - INT32 *yb, RegionPtr reg, INT32 width, INT32 height); - -extern _X_EXPORT void - -xf86XVCopyYUV12ToPacked(const void *srcy, - const void *srcv, - const void *srcu, - void *dst, - int srcPitchy, - int srcPitchuv, int dstPitch, int h, int w); - -extern _X_EXPORT void - -xf86XVCopyPacked(const void *src, - void *dst, int srcPitch, int dstPitch, int h, int w); - -#endif /* _XF86XV_H_ */ diff --git a/hw/xfree86/common/xf86xvmc.c b/hw/xfree86/common/xf86xvmc.c deleted file mode 100644 index c67418bf4..000000000 --- a/hw/xfree86/common/xf86xvmc.c +++ /dev/null @@ -1,223 +0,0 @@ - -/* - * Copyright (c) 2001-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "misc.h" -#include "xf86.h" -#include "xf86_OSproc.h" - -#include -#include -#include "scrnintstr.h" -#include "resource.h" -#include "dixstruct.h" - -#include "xf86xvpriv.h" -#include "xf86xvmc.h" - -typedef struct { - CloseScreenProcPtr CloseScreen; - int num_adaptors; - XF86MCAdaptorPtr *adaptors; - XvMCAdaptorPtr dixinfo; -} xf86XvMCScreenRec, *xf86XvMCScreenPtr; - -static DevPrivateKeyRec XF86XvMCScreenKeyRec; - -#define XF86XvMCScreenKey (&XF86XvMCScreenKeyRec) - -#define XF86XVMC_GET_PRIVATE(pScreen) (xf86XvMCScreenPtr) \ - dixLookupPrivate(&(pScreen)->devPrivates, XF86XvMCScreenKey) - -static int -xf86XvMCCreateContext(XvPortPtr pPort, - XvMCContextPtr pContext, int *num_priv, CARD32 **priv) -{ - xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); - - pContext->port_priv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateContext) (pScrn, - pContext, - num_priv, - priv); -} - -static void -xf86XvMCDestroyContext(XvMCContextPtr pContext) -{ - xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); - - (*pScreenPriv->adaptors[pContext->adapt_num]->DestroyContext) (pScrn, - pContext); -} - -static int -xf86XvMCCreateSurface(XvMCSurfacePtr pSurface, int *num_priv, CARD32 **priv) -{ - XvMCContextPtr pContext = pSurface->context; - xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); - - return (*pScreenPriv->adaptors[pContext->adapt_num]->CreateSurface) (pScrn, - pSurface, - num_priv, - priv); -} - -static void -xf86XvMCDestroySurface(XvMCSurfacePtr pSurface) -{ - XvMCContextPtr pContext = pSurface->context; - xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); - - (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySurface) (pScrn, - pSurface); -} - -static int -xf86XvMCCreateSubpicture(XvMCSubpicturePtr pSubpicture, - int *num_priv, CARD32 **priv) -{ - XvMCContextPtr pContext = pSubpicture->context; - xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); - - return (*pScreenPriv->adaptors[pContext->adapt_num]-> - CreateSubpicture) (pScrn, pSubpicture, num_priv, priv); -} - -static void -xf86XvMCDestroySubpicture(XvMCSubpicturePtr pSubpicture) -{ - XvMCContextPtr pContext = pSubpicture->context; - xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pContext->pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pContext->pScreen); - - (*pScreenPriv->adaptors[pContext->adapt_num]->DestroySubpicture) (pScrn, - pSubpicture); -} - -static Bool -xf86XvMCCloseScreen(ScreenPtr pScreen) -{ - xf86XvMCScreenPtr pScreenPriv = XF86XVMC_GET_PRIVATE(pScreen); - - pScreen->CloseScreen = pScreenPriv->CloseScreen; - - free(pScreenPriv->dixinfo); - free(pScreenPriv); - - return (*pScreen->CloseScreen) (pScreen); -} - -Bool -xf86XvMCScreenInit(ScreenPtr pScreen, - int num_adaptors, XF86MCAdaptorPtr * adaptors) -{ - XvMCAdaptorPtr pAdapt; - xf86XvMCScreenPtr pScreenPriv; - XvScreenPtr pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - XF86XvScreenKey); - int i, j; - - if (noXvExtension) - return FALSE; - - if (!(pAdapt = xallocarray(num_adaptors, sizeof(XvMCAdaptorRec)))) - return FALSE; - - if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) { - free(pAdapt); - return FALSE; - } - - if (!(pScreenPriv = malloc(sizeof(xf86XvMCScreenRec)))) { - free(pAdapt); - return FALSE; - } - - dixSetPrivate(&pScreen->devPrivates, XF86XvMCScreenKey, pScreenPriv); - - pScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = xf86XvMCCloseScreen; - - pScreenPriv->num_adaptors = num_adaptors; - pScreenPriv->adaptors = adaptors; - pScreenPriv->dixinfo = pAdapt; - - for (i = 0; i < num_adaptors; i++) { - pAdapt[i].xv_adaptor = NULL; - for (j = 0; j < pxvs->nAdaptors; j++) { - if (!strcmp((*adaptors)->name, pxvs->pAdaptors[j].name)) { - pAdapt[i].xv_adaptor = &(pxvs->pAdaptors[j]); - break; - } - } - if (!pAdapt[i].xv_adaptor) { - /* no adaptor by that name */ - pScreenPriv->dixinfo = FALSE; - free(pAdapt); - return FALSE; - } - pAdapt[i].num_surfaces = (*adaptors)->num_surfaces; - pAdapt[i].surfaces = (XvMCSurfaceInfoPtr *) ((*adaptors)->surfaces); - pAdapt[i].num_subpictures = (*adaptors)->num_subpictures; - pAdapt[i].subpictures = (XvImagePtr *) ((*adaptors)->subpictures); - pAdapt[i].CreateContext = xf86XvMCCreateContext; - pAdapt[i].DestroyContext = xf86XvMCDestroyContext; - pAdapt[i].CreateSurface = xf86XvMCCreateSurface; - pAdapt[i].DestroySurface = xf86XvMCDestroySurface; - pAdapt[i].CreateSubpicture = xf86XvMCCreateSubpicture; - pAdapt[i].DestroySubpicture = xf86XvMCDestroySubpicture; - adaptors++; - } - - if (Success != XvMCScreenInit(pScreen, num_adaptors, pAdapt)) - return FALSE; - - return TRUE; -} - -XF86MCAdaptorPtr -xf86XvMCCreateAdaptorRec(void) -{ - return calloc(1, sizeof(XF86MCAdaptorRec)); -} - -void -xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor) -{ - free(adaptor); -} diff --git a/hw/xfree86/common/xf86xvmc.h b/hw/xfree86/common/xf86xvmc.h deleted file mode 100644 index 023aff526..000000000 --- a/hw/xfree86/common/xf86xvmc.h +++ /dev/null @@ -1,141 +0,0 @@ - -/* - * Copyright (c) 2001 by The XFree86 Project, 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). - */ - -#ifndef _XF86XVMC_H -#define _XF86XVMC_H - -#include "xvmcext.h" -#include "xf86xv.h" - -typedef struct { - int num_xvimages; - int *xvimage_ids; /* reference the subpictures in the XF86MCAdaptorRec */ -} XF86MCImageIDList; - -typedef struct { - int surface_type_id; /* Driver generated. Must be unique on the port */ - int chroma_format; - int color_description; /* no longer used */ - unsigned short max_width; - unsigned short max_height; - unsigned short subpicture_max_width; - unsigned short subpicture_max_height; - int mc_type; - int flags; - XF86MCImageIDList *compatible_subpictures; /* can be null, if none */ -} XF86MCSurfaceInfoRec, *XF86MCSurfaceInfoPtr; - -/* - xf86XvMCCreateContextProc - - DIX will fill everything out in the context except the driver_priv. - The port_priv holds the private data specified for the port when - Xv was initialized by the driver. - The driver may store whatever it wants in driver_priv and edit - the width, height and flags. If the driver wants to return something - to the client it can allocate space in priv and specify the number - of 32 bit words in num_priv. This must be dynamically allocated - space because DIX will free it after it passes it to the client. -*/ - -typedef int (*xf86XvMCCreateContextProcPtr) (ScrnInfoPtr pScrn, - XvMCContextPtr context, - int *num_priv, CARD32 **priv); - -typedef void (*xf86XvMCDestroyContextProcPtr) (ScrnInfoPtr pScrn, - XvMCContextPtr context); - -/* - xf86XvMCCreateSurfaceProc - - DIX will fill everything out in the surface except the driver_priv. - The driver may store whatever it wants in driver_priv. The driver - may pass data back to the client in the same manner as the - xf86XvMCCreateContextProc. -*/ - -typedef int (*xf86XvMCCreateSurfaceProcPtr) (ScrnInfoPtr pScrn, - XvMCSurfacePtr surface, - int *num_priv, CARD32 **priv); - -typedef void (*xf86XvMCDestroySurfaceProcPtr) (ScrnInfoPtr pScrn, - XvMCSurfacePtr surface); - -/* - xf86XvMCCreateSubpictureProc - - DIX will fill everything out in the subpicture except the driver_priv, - num_palette_entries, entry_bytes and component_order. The driver may - store whatever it wants in driver_priv and edit the width and height. - If it is a paletted subpicture the driver needs to fill out the - num_palette_entries, entry_bytes and component_order. These are - not communicated to the client until the time the surface is - created. - - The driver may pass data back to the client in the same manner as the - xf86XvMCCreateContextProc. -*/ - -typedef int (*xf86XvMCCreateSubpictureProcPtr) (ScrnInfoPtr pScrn, - XvMCSubpicturePtr subpicture, - int *num_priv, CARD32 **priv); - -typedef void (*xf86XvMCDestroySubpictureProcPtr) (ScrnInfoPtr pScrn, - XvMCSubpicturePtr subpicture); - -typedef struct { - const char *name; - int num_surfaces; - XF86MCSurfaceInfoPtr *surfaces; - int num_subpictures; - XF86ImagePtr *subpictures; - xf86XvMCCreateContextProcPtr CreateContext; - xf86XvMCDestroyContextProcPtr DestroyContext; - xf86XvMCCreateSurfaceProcPtr CreateSurface; - xf86XvMCDestroySurfaceProcPtr DestroySurface; - xf86XvMCCreateSubpictureProcPtr CreateSubpicture; - xf86XvMCDestroySubpictureProcPtr DestroySubpicture; -} XF86MCAdaptorRec, *XF86MCAdaptorPtr; - -/* - xf86XvMCScreenInit - - Unlike Xv, the adaptor data is not copied from this structure. - This structure's data is used so it must stick around for the - life of the server. Note that it's an array of pointers not - an array of structures. -*/ - -extern _X_EXPORT Bool xf86XvMCScreenInit(ScreenPtr pScreen, - int num_adaptors, - XF86MCAdaptorPtr * adaptors); - -extern _X_EXPORT XF86MCAdaptorPtr xf86XvMCCreateAdaptorRec(void); -extern _X_EXPORT void xf86XvMCDestroyAdaptorRec(XF86MCAdaptorPtr adaptor); - -#endif /* _XF86XVMC_H */ diff --git a/hw/xfree86/common/xf86xvpriv.h b/hw/xfree86/common/xf86xvpriv.h deleted file mode 100644 index 8fb22e60e..000000000 --- a/hw/xfree86/common/xf86xvpriv.h +++ /dev/null @@ -1,88 +0,0 @@ - -/* - * Copyright (c) 2003 by The XFree86 Project, 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). - */ - -#ifndef _XF86XVPRIV_H_ -#define _XF86XVPRIV_H_ - -#include "xf86xv.h" -#include "privates.h" - -/*** These are DDX layer privates ***/ - -extern _X_EXPORT DevPrivateKey XF86XvScreenKey; - -typedef struct { - DestroyWindowProcPtr DestroyWindow; - ClipNotifyProcPtr ClipNotify; - WindowExposuresProcPtr WindowExposures; - PostValidateTreeProcPtr PostValidateTree; - void (*AdjustFrame) (ScrnInfoPtr, int, int); - Bool (*EnterVT) (ScrnInfoPtr); - void (*LeaveVT) (ScrnInfoPtr); - xf86ModeSetProc *ModeSet; - CloseScreenProcPtr CloseScreen; -} XF86XVScreenRec, *XF86XVScreenPtr; - -typedef struct { - int flags; - PutVideoFuncPtr PutVideo; - PutStillFuncPtr PutStill; - GetVideoFuncPtr GetVideo; - GetStillFuncPtr GetStill; - StopVideoFuncPtr StopVideo; - SetPortAttributeFuncPtr SetPortAttribute; - GetPortAttributeFuncPtr GetPortAttribute; - QueryBestSizeFuncPtr QueryBestSize; - PutImageFuncPtr PutImage; - ReputImageFuncPtr ReputImage; - QueryImageAttributesFuncPtr QueryImageAttributes; -} XvAdaptorRecPrivate, *XvAdaptorRecPrivatePtr; - -typedef struct { - ScrnInfoPtr pScrn; - DrawablePtr pDraw; - unsigned char type; - unsigned int subWindowMode; - RegionPtr clientClip; - RegionPtr ckeyFilled; - RegionPtr pCompositeClip; - Bool FreeCompositeClip; - XvAdaptorRecPrivatePtr AdaptorRec; - XvStatus isOn; - Bool clipChanged; - int vid_x, vid_y, vid_w, vid_h; - int drw_x, drw_y, drw_w, drw_h; - DevUnion DevPriv; -} XvPortRecPrivate, *XvPortRecPrivatePtr; - -typedef struct _XF86XVWindowRec { - XvPortRecPrivatePtr PortRec; - struct _XF86XVWindowRec *next; -} XF86XVWindowRec, *XF86XVWindowPtr; - -#endif /* _XF86XVPRIV_H_ */ diff --git a/hw/xfree86/common/xisb.c b/hw/xfree86/common/xisb.c deleted file mode 100644 index f35a6825a..000000000 --- a/hw/xfree86/common/xisb.c +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ - -/* - X Input Serial Buffer routines for use in any XInput driver that accesses - a serial device. -*/ - -/***************************************************************************** - * Standard Headers - ****************************************************************************/ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include "xisb.h" - -/***************************************************************************** - * Local Headers - ****************************************************************************/ - -/***************************************************************************** - * Variables without includable headers - ****************************************************************************/ - -/***************************************************************************** - * Local Variables - ****************************************************************************/ - -/***************************************************************************** - * Function Definitions - ****************************************************************************/ - -XISBuffer * -XisbNew(int fd, ssize_t size) -{ - XISBuffer *b; - - b = malloc(sizeof(XISBuffer)); - if (!b) - return NULL; - b->buf = malloc((sizeof(unsigned char) * size)); - if (!b->buf) { - free(b); - return NULL; - } - - b->fd = fd; - b->trace = 0; - b->block_duration = 0; - b->current = 1; /* force it to be past the end to trigger initial read */ - b->end = 0; - b->buffer_size = size; - return b; -} - -void -XisbFree(XISBuffer * b) -{ - free(b->buf); - free(b); -} - -int -XisbRead(XISBuffer * b) -{ - int ret; - - if (b->current >= b->end) { - if (b->block_duration >= 0) { - if (xf86WaitForInput(b->fd, b->block_duration) < 1) - return -1; - } - else { - /* - * automatically clear it so if XisbRead is called in a loop - * the next call will make sure there is data with select and - * thus prevent a blocking read - */ - b->block_duration = 0; - } - - ret = xf86ReadSerial(b->fd, b->buf, b->buffer_size); - switch (ret) { - case 0: - return -1; /* timeout */ - case -1: - return -2; /* error */ - default: - b->end = ret; - b->current = 0; - break; - } - } - if (b->trace) - ErrorF("read 0x%02x (%c)\n", b->buf[b->current], - isprint(b->buf[b->current]) ? b->buf[b->current] : '.'); - - return b->buf[b->current++]; -} - -/* the only purpose of this function is to provide output tracing */ -ssize_t -XisbWrite(XISBuffer * b, unsigned char *msg, ssize_t len) -{ - if (b->trace) { - int i = 0; - - for (i = 0; i < len; i++) - ErrorF("\t\twrote 0x%02x (%c)\n", msg[i], msg[i]); - } - return (xf86WriteSerial(b->fd, msg, len)); -} - -/* turn tracing of this buffer on (1) or off (0) */ -void -XisbTrace(XISBuffer * b, int trace) -{ - b->trace = trace; -} - -/* - * specify a block_duration of -1 when you know the buffer's fd is ready to - * read. After a read, it is automatically set to 0 so that the next read - * will use check to select for data and prevent a block. - * It is the caller's responsibility to set the block_duration to -1 if it - * knows that there is data to read (because the main select loop triggered - * the read) and wants to avoid the unnecessary overhead of the select call - * - * a zero or positive block duration will cause the select to block for the - * give duration in usecs. - */ - -void -XisbBlockDuration(XISBuffer * b, int block_duration) -{ - b->block_duration = block_duration; -} diff --git a/hw/xfree86/common/xisb.h b/hw/xfree86/common/xisb.h deleted file mode 100644 index 6ac1a6e37..000000000 --- a/hw/xfree86/common/xisb.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ - -#ifndef _xisb_H_ -#define _xisb_H_ - -#include - -/****************************************************************************** - * Definitions - * structs, typedefs, #defines, enums - *****************************************************************************/ - -typedef struct _XISBuffer { - int fd; - int trace; - int block_duration; - ssize_t current; /* bytes read */ - ssize_t end; - ssize_t buffer_size; - unsigned char *buf; -} XISBuffer; - -/****************************************************************************** - * Declarations - * variables: use xisb_LOC in front - * of globals. - * put locals in the .c file. - *****************************************************************************/ -extern _X_EXPORT XISBuffer *XisbNew(int fd, ssize_t size); -extern _X_EXPORT void XisbFree(XISBuffer * b); -extern _X_EXPORT int XisbRead(XISBuffer * b); -extern _X_EXPORT ssize_t XisbWrite(XISBuffer * b, unsigned char *msg, - ssize_t len); -extern _X_EXPORT void XisbTrace(XISBuffer * b, int trace); -extern _X_EXPORT void XisbBlockDuration(XISBuffer * b, int block_duration); - -/* - * DO NOT PUT ANYTHING AFTER THIS ENDIF - */ -#endif diff --git a/hw/xfree86/common/xorgHelper.c b/hw/xfree86/common/xorgHelper.c deleted file mode 100644 index 174ca6bb7..000000000 --- a/hw/xfree86/common/xorgHelper.c +++ /dev/null @@ -1,22 +0,0 @@ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "servermd.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "propertyst.h" -#include "gcstruct.h" -#include "loaderProcs.h" -#include "xf86.h" -#include "xf86Priv.h" -#include "xorgVersion.h" - -CARD32 -xorgGetVersion(void) -{ - return XORG_VERSION_CURRENT; -} diff --git a/hw/xfree86/common/xorgVersion.h b/hw/xfree86/common/xorgVersion.h deleted file mode 100644 index e34ddecdf..000000000 --- a/hw/xfree86/common/xorgVersion.h +++ /dev/null @@ -1,49 +0,0 @@ - -/* - * Copyright (c) 2004, X.Org Foundation - * - * 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). - */ - -#ifndef XORG_VERSION_H -#define XORG_VERSION_H - -#ifndef XORG_VERSION_CURRENT -#error -#endif - -#define XORG_VERSION_NUMERIC(major,minor,patch,snap,dummy) \ - (((major) * 10000000) + ((minor) * 100000) + ((patch) * 1000) + snap) - -#define XORG_GET_MAJOR_VERSION(vers) ((vers) / 10000000) -#define XORG_GET_MINOR_VERSION(vers) (((vers) % 10000000) / 100000) -#define XORG_GET_PATCH_VERSION(vers) (((vers) % 100000) / 1000) -#define XORG_GET_SNAP_VERSION(vers) ((vers) % 1000) - -#define XORG_VERSION_MAJOR XORG_GET_MAJOR_VERSION(XORG_VERSION_CURRENT) -#define XORG_VERSION_MINOR XORG_GET_MINOR_VERSION(XORG_VERSION_CURRENT) -#define XORG_VERSION_PATCH XORG_GET_PATCH_VERSION(XORG_VERSION_CURRENT) -#define XORG_VERSION_SNAP XORG_GET_SNAP_VERSION(XORG_VERSION_CURRENT) - -#endif diff --git a/hw/xfree86/ddc/DDC.HOWTO b/hw/xfree86/ddc/DDC.HOWTO deleted file mode 100644 index 1d06ca124..000000000 --- a/hw/xfree86/ddc/DDC.HOWTO +++ /dev/null @@ -1,97 +0,0 @@ - DDC.HOWTO - - This file describes how to add DDC support to a chipset driver. - -1) DDC INITIALIZATION - - When implementing DDC in the driver one has the choice between - DDC1 and DDC2. - DDC1 data is continuously transmitted by a DDC1 capable display - device. The data is send serially over a data line; the Vsync - signal serves as clock. Only one EDID 1.x data block can be - transmitted using DDC1. Since transmission of an EDID1 block - using a regular Vsync frequency would take up several seconds - the driver can increase the Vsync frequency to up to 25 kHz as - soon as it detects DDC1 activity on the data line. - DDC2 data is transmitted using the I2C protocol. This requires - an additional clock line. DDC2 is capable of transmitting EDID1 - and EDID2 block as well as a VDIF block on display devices that - support these. - Display devices switch into the DDC2 mode as soon as they detect - activity on the DDC clock line. Once the are in DDC2 mode they - stop transmitting DDC1 signals until the next power cycle. - - Some graphics chipset configurations which are not capable of - DDC2 might still be able to read DDC1 data. Where available - DDC2 it is preferable. - - All relevant prototypes and defines are in xf86DDC.h. - DDC2 additionally requires I2C support. The I2C prototypes - are in xf86i2c.h. - - DDC1 Support: - - The driver has to provide a read function which waits for the - end of the next Vsync signal and reads in and returns the status - of the DDC line: - - unsigned int XXX_ddc1Read(ScrnInfoPtr pScrn) - - Additionally a function is required to increase the Vsync - frequency to max. 25 kHz. - - void XXX_ddc1SetSpeed(ScrnInfoPtr pScrn, xf86ddcSpeed speed) - - If the speed argument is DDC_FAST the function should increase - the Vsync frequency on DDC_SLOW it should restore the original - value. For convenience a generic ddc1SetSpeed() function is provided - in the vga module for VGA-like chipsets. - - void vgaHWddc1SetSpeed(ScrnInfoPtr pScrn, sf86ddcSpeed speed). - - To read out the DDC1 data the driver should call - - xf86MonPtr xf86DoEDID_DDC1(int scrnIndex, - void (*DDC1SetSpeed)(ScrnInfoPtr, xf86ddcSpeed), - unsigned int (*DDC1Read)(ScrnInfoPtr)) - - in PreInit(). DDC1SetSpeed is a pointer to the SetSpeed() - function, DDC1Read has to point to the DDC1 read function. - The function will return a pointer to the xf86Monitor structure - which contains all information retrieved by DDC. - NULL will be returned on failure. - - DDC2 Support - - To read out DDC2 information I2C has to be initialized first. - (See documentation for the i2c module). - The function - - xf86MonPtr xf86DoEDID_DDC2(int scrnIndex, I2CBusPtr pBus) - - is provided to read out and process DDC2 data. A pointer - to the I2CBusRec of the appropriate I2C Bus has to be passed - as the second argument. - The function will return a pointer to the xf86Monitor structure - which contains all information retrieved by DDC. - NULL will be returned on failure. - - Printing monitor parameters - - To print out the information contained in the xf86Monitor - structure the function - - xf86MonPtr xf86PrintEDID(xf86MonPtr monitor) - - is provided. - - Further processing of the xf86Monitor structure is not yet - implemented. However, it is planned to use the information - about video modes, gamma values etc. - Therefore it is strongly recommended to read out DDC data - before any video mode processing is done. - - - - -$XFree86: xc/programs/Xserver/hw/xfree86/ddc/DDC.HOWTO,v 1.2 1998/12/06 13:30:39 dawes Exp $ diff --git a/hw/xfree86/ddc/ddc.c b/hw/xfree86/ddc/ddc.c deleted file mode 100644 index b82dfc185..000000000 --- a/hw/xfree86/ddc/ddc.c +++ /dev/null @@ -1,470 +0,0 @@ -/* xf86DDC.c - * - * Copyright 1998,1999 by Egbert Eich - */ - -/* - * A note on terminology. DDC1 is the original dumb serial protocol, and - * can only do up to 128 bytes of EDID. DDC2 is I2C-encapsulated and - * introduces extension blocks. EDID is the old display identification - * block, DisplayID is the new one. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "misc.h" -#include "xf86.h" -#include "xf86_OSproc.h" -#include "xf86DDC.h" -#include - -#define RETRIES 4 - -typedef enum { - DDCOPT_NODDC1, - DDCOPT_NODDC2, - DDCOPT_NODDC -} DDCOpts; - -static const OptionInfoRec DDCOptions[] = { - {DDCOPT_NODDC1, "NoDDC1", OPTV_BOOLEAN, {0}, FALSE}, - {DDCOPT_NODDC2, "NoDDC2", OPTV_BOOLEAN, {0}, FALSE}, - {DDCOPT_NODDC, "NoDDC", OPTV_BOOLEAN, {0}, FALSE}, - {-1, NULL, OPTV_NONE, {0}, FALSE}, -}; - -/* DDC1 */ - -static int -find_start(unsigned int *ptr) -{ - unsigned int comp[9], test[9]; - int i, j; - - for (i = 0; i < 9; i++) { - comp[i] = *(ptr++); - test[i] = 1; - } - for (i = 0; i < 127; i++) { - for (j = 0; j < 9; j++) { - test[j] = test[j] & !(comp[j] ^ *(ptr++)); - } - } - for (i = 0; i < 9; i++) - if (test[i]) - return i + 1; - return -1; -} - -static unsigned char * -find_header(unsigned char *block) -{ - unsigned char *ptr, *head_ptr, *end; - unsigned char header[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }; - - ptr = block; - end = block + EDID1_LEN; - while (ptr < end) { - int i; - - head_ptr = ptr; - for (i = 0; i < 8; i++) { - if (header[i] != *(head_ptr++)) - break; - if (head_ptr == end) - head_ptr = block; - } - if (i == 8) - break; - ptr++; - } - if (ptr == end) - return NULL; - return ptr; -} - -static unsigned char * -resort(unsigned char *s_block) -{ - unsigned char *d_new, *d_ptr, *d_end, *s_ptr, *s_end; - unsigned char tmp; - - s_ptr = find_header(s_block); - if (!s_ptr) - return NULL; - s_end = s_block + EDID1_LEN; - - d_new = malloc(EDID1_LEN); - if (!d_new) - return NULL; - d_end = d_new + EDID1_LEN; - - for (d_ptr = d_new; d_ptr < d_end; d_ptr++) { - tmp = *(s_ptr++); - *d_ptr = tmp; - if (s_ptr == s_end) - s_ptr = s_block; - } - free(s_block); - return d_new; -} - -static int -DDC_checksum(const unsigned char *block, int len) -{ - int i, result = 0; - int not_null = 0; - - for (i = 0; i < len; i++) { - not_null |= block[i]; - result += block[i]; - } - -#ifdef DEBUG - if (result & 0xFF) - ErrorF("DDC checksum not correct\n"); - if (!not_null) - ErrorF("DDC read all Null\n"); -#endif - - /* catch the trivial case where all bytes are 0 */ - if (!not_null) - return 1; - - return result & 0xFF; -} - -static unsigned char * -GetEDID_DDC1(unsigned int *s_ptr) -{ - unsigned char *d_block, *d_pos; - unsigned int *s_pos, *s_end; - int s_start; - int i, j; - - s_start = find_start(s_ptr); - if (s_start == -1) - return NULL; - s_end = s_ptr + NUM; - s_pos = s_ptr + s_start; - d_block = calloc(1, EDID1_LEN); - if (!d_block) - return NULL; - d_pos = d_block; - for (i = 0; i < EDID1_LEN; i++) { - for (j = 0; j < 8; j++) { - *d_pos <<= 1; - if (*s_pos) { - *d_pos |= 0x01; - } - s_pos++; - if (s_pos == s_end) - s_pos = s_ptr; - }; - s_pos++; - if (s_pos == s_end) - s_pos = s_ptr; - d_pos++; - } - free(s_ptr); - if (d_block && DDC_checksum(d_block, EDID1_LEN)) { - free(d_block); - return NULL; - } - return (resort(d_block)); -} - -/* fetch entire EDID record; DDC bit needs to be masked */ -static unsigned int * -FetchEDID_DDC1(register ScrnInfoPtr pScrn, - register unsigned int (*read_DDC) (ScrnInfoPtr)) -{ - int count = NUM; - unsigned int *ptr, *xp; - - ptr = xp = malloc(sizeof(int) * NUM); - - if (!ptr) - return NULL; - do { - /* wait for next retrace */ - *xp = read_DDC(pScrn); - xp++; - } while (--count); - return ptr; -} - -/* test if DDC1 return 0 if not */ -static Bool -TestDDC1(ScrnInfoPtr pScrn, unsigned int (*read_DDC) (ScrnInfoPtr)) -{ - int old, count; - - old = read_DDC(pScrn); - count = HEADER * BITS_PER_BYTE; - do { - /* wait for next retrace */ - if (old != read_DDC(pScrn)) - break; - } while (count--); - return count; -} - -/* - * read EDID record , pass it to callback function to interpret. - * callback function will store it for further use by calling - * function; it will also decide if we need to reread it - */ -static unsigned char * -EDIDRead_DDC1(ScrnInfoPtr pScrn, DDC1SetSpeedProc DDCSpeed, - unsigned int (*read_DDC) (ScrnInfoPtr)) -{ - unsigned char *EDID_block = NULL; - int count = RETRIES; - - if (!read_DDC) { - xf86DrvMsg(pScrn->scrnIndex, X_PROBED, - "chipset doesn't support DDC1\n"); - return NULL; - }; - - if (TestDDC1(pScrn, read_DDC) == -1) { - xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "No DDC signal\n"); - return NULL; - }; - - if (DDCSpeed) - DDCSpeed(pScrn, DDC_FAST); - do { - EDID_block = GetEDID_DDC1(FetchEDID_DDC1(pScrn, read_DDC)); - count--; - } while (!EDID_block && count); - if (DDCSpeed) - DDCSpeed(pScrn, DDC_SLOW); - - return EDID_block; -} - -/** - * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC1 are - * unset. EDID information blocks are interpreted and the results returned in - * an xf86MonPtr. - * - * This function does not affect the list of modes used by drivers -- it is up - * to the driver to decide policy on what to do with EDID information. - * - * @return pointer to a new xf86MonPtr containing the EDID information. - * @return NULL if no monitor attached or failure to interpret the EDID. - */ -xf86MonPtr -xf86DoEDID_DDC1(ScrnInfoPtr pScrn, DDC1SetSpeedProc DDC1SetSpeed, - unsigned int (*DDC1Read) (ScrnInfoPtr)) -{ - unsigned char *EDID_block = NULL; - xf86MonPtr tmp = NULL; - - /* Default DDC and DDC1 to enabled. */ - Bool noddc = FALSE, noddc1 = FALSE; - OptionInfoPtr options; - - options = xnfalloc(sizeof(DDCOptions)); - (void) memcpy(options, DDCOptions, sizeof(DDCOptions)); - xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options); - - xf86GetOptValBool(options, DDCOPT_NODDC, &noddc); - xf86GetOptValBool(options, DDCOPT_NODDC1, &noddc1); - free(options); - - if (noddc || noddc1) - return NULL; - - OsBlockSignals(); - EDID_block = EDIDRead_DDC1(pScrn, DDC1SetSpeed, DDC1Read); - OsReleaseSignals(); - - if (EDID_block) { - tmp = xf86InterpretEDID(pScrn->scrnIndex, EDID_block); - } -#ifdef DEBUG - else - ErrorF("No EDID block returned\n"); - if (!tmp) - ErrorF("Cannot interpret EDID block\n"); -#endif - return tmp; -} - -/* DDC2 */ - -static I2CDevPtr -DDC2MakeDevice(I2CBusPtr pBus, int address, const char *name) -{ - I2CDevPtr dev = NULL; - - if (!(dev = xf86I2CFindDev(pBus, address))) { - dev = xf86CreateI2CDevRec(); - dev->DevName = name; - dev->SlaveAddr = address; - dev->ByteTimeout = 2200; /* VESA DDC spec 3 p. 43 (+10 %) */ - dev->StartTimeout = 550; - dev->BitTimeout = 40; - dev->AcknTimeout = 40; - - dev->pI2CBus = pBus; - if (!xf86I2CDevInit(dev)) { - xf86DrvMsg(pBus->scrnIndex, X_PROBED, "No DDC2 device\n"); - return NULL; - } - } - - return dev; -} - -static I2CDevPtr -DDC2Init(I2CBusPtr pBus) -{ - I2CDevPtr dev = NULL; - - /* - * Slow down the bus so that older monitors don't - * miss things. - */ - pBus->RiseFallTime = 20; - - dev = DDC2MakeDevice(pBus, 0x00A0, "ddc2"); - if (xf86I2CProbeAddress(pBus, 0x0060)) - DDC2MakeDevice(pBus, 0x0060, "E-EDID segment register"); - - return dev; -} - -/* Mmmm, smell the hacks */ -static void -EEDIDStop(I2CDevPtr d) -{ -} - -/* block is the EDID block number. a segment is two blocks. */ -static Bool -DDC2Read(I2CDevPtr dev, int block, unsigned char *R_Buffer) -{ - unsigned char W_Buffer[1]; - int i, segment; - I2CDevPtr seg; - void (*stop) (I2CDevPtr); - - for (i = 0; i < RETRIES; i++) { - /* Stop bits reset the segment pointer to 0, so be careful here. */ - segment = block >> 1; - if (segment) { - Bool b; - - if (!(seg = xf86I2CFindDev(dev->pI2CBus, 0x0060))) - return FALSE; - - W_Buffer[0] = segment; - - stop = dev->pI2CBus->I2CStop; - dev->pI2CBus->I2CStop = EEDIDStop; - - b = xf86I2CWriteRead(seg, W_Buffer, 1, NULL, 0); - - dev->pI2CBus->I2CStop = stop; - if (!b) { - dev->pI2CBus->I2CStop(dev); - continue; - } - } - - W_Buffer[0] = (block & 0x01) * EDID1_LEN; - - if (xf86I2CWriteRead(dev, W_Buffer, 1, R_Buffer, EDID1_LEN)) { - if (!DDC_checksum(R_Buffer, EDID1_LEN)) - return TRUE; - } - } - - return FALSE; -} - -/** - * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC2 are - * unset. EDID information blocks are interpreted and the results returned in - * an xf86MonPtr. Unlike xf86DoEDID_DDC[12](), this function will return - * the complete EDID data, including all extension blocks, if the 'complete' - * parameter is TRUE; - * - * This function does not affect the list of modes used by drivers -- it is up - * to the driver to decide policy on what to do with EDID information. - * - * @return pointer to a new xf86MonPtr containing the EDID information. - * @return NULL if no monitor attached or failure to interpret the EDID. - */ -xf86MonPtr -xf86DoEEDID(ScrnInfoPtr pScrn, I2CBusPtr pBus, Bool complete) -{ - unsigned char *EDID_block = NULL; - xf86MonPtr tmp = NULL; - I2CDevPtr dev = NULL; - - /* Default DDC and DDC2 to enabled. */ - Bool noddc = FALSE, noddc2 = FALSE; - OptionInfoPtr options; - - options = malloc(sizeof(DDCOptions)); - if (!options) - return NULL; - memcpy(options, DDCOptions, sizeof(DDCOptions)); - xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options); - - xf86GetOptValBool(options, DDCOPT_NODDC, &noddc); - xf86GetOptValBool(options, DDCOPT_NODDC2, &noddc2); - free(options); - - if (noddc || noddc2) - return NULL; - - if (!(dev = DDC2Init(pBus))) - return NULL; - - EDID_block = calloc(1, EDID1_LEN); - if (!EDID_block) - return NULL; - - if (DDC2Read(dev, 0, EDID_block)) { - int i, n = EDID_block[0x7e]; - - if (complete && n) { - EDID_block = reallocarray(EDID_block, 1 + n, EDID1_LEN); - - for (i = 0; i < n; i++) - DDC2Read(dev, i + 1, EDID_block + (EDID1_LEN * (1 + i))); - } - - tmp = xf86InterpretEEDID(pScrn->scrnIndex, EDID_block); - } - - if (tmp && complete) - tmp->flags |= MONITOR_EDID_COMPLETE_RAWDATA; - - return tmp; -} - -/** - * Attempts to probe the monitor for EDID information, if NoDDC and NoDDC2 are - * unset. EDID information blocks are interpreted and the results returned in - * an xf86MonPtr. - * - * This function does not affect the list of modes used by drivers -- it is up - * to the driver to decide policy on what to do with EDID information. - * - * @return pointer to a new xf86MonPtr containing the EDID information. - * @return NULL if no monitor attached or failure to interpret the EDID. - */ -xf86MonPtr -xf86DoEDID_DDC2(ScrnInfoPtr pScrn, I2CBusPtr pBus) -{ - return xf86DoEEDID(pScrn, pBus, FALSE); -} diff --git a/hw/xfree86/ddc/ddcProperty.c b/hw/xfree86/ddc/ddcProperty.c deleted file mode 100644 index e68672e43..000000000 --- a/hw/xfree86/ddc/ddcProperty.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2006 Luc Verhaegen. - * - * 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, 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 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86DDC.h" -#include "xf86Priv.h" -#include -#include "property.h" -#include "propertyst.h" -#include - -#define EDID1_ATOM_NAME "XFree86_DDC_EDID1_RAWDATA" - -static int -edidSize(const xf86MonPtr DDC) -{ - int ret = 128; - - if (DDC->flags & EDID_COMPLETE_RAWDATA) - ret += DDC->no_sections * 128; - - return ret; -} - -static void -setRootWindowEDID(ScreenPtr pScreen, xf86MonPtr DDC) -{ - Atom atom = MakeAtom(EDID1_ATOM_NAME, strlen(EDID1_ATOM_NAME), TRUE); - - dixChangeWindowProperty(serverClient, pScreen->root, atom, XA_INTEGER, - 8, PropModeReplace, edidSize(DDC), DDC->rawData, - FALSE); -} - -static void -addEDIDProp(CallbackListPtr *pcbl, void *scrn, void *screen) -{ - ScreenPtr pScreen = screen; - ScrnInfoPtr pScrn = scrn; - - if (xf86ScreenToScrn(pScreen) == pScrn) - setRootWindowEDID(pScreen, pScrn->monitor->DDC); -} - -Bool -xf86SetDDCproperties(ScrnInfoPtr pScrn, xf86MonPtr DDC) -{ - if (!pScrn || !pScrn->monitor || !DDC) - return FALSE; - - xf86EdidMonitorSet(pScrn->scrnIndex, pScrn->monitor, DDC); - - if (xf86Initialising) - AddCallback(&RootWindowFinalizeCallback, addEDIDProp, pScrn); - else - setRootWindowEDID(pScrn->pScreen, DDC); - - return TRUE; -} diff --git a/hw/xfree86/ddc/edid.h b/hw/xfree86/ddc/edid.h deleted file mode 100644 index adc9bf71c..000000000 --- a/hw/xfree86/ddc/edid.h +++ /dev/null @@ -1,671 +0,0 @@ -/* - * edid.h: defines to parse an EDID block - * - * This file contains all information to interpret a standard EDIC block - * transmitted by a display device via DDC (Display Data Channel). So far - * there is no information to deal with optional EDID blocks. - * DDC is a Trademark of VESA (Video Electronics Standard Association). - * - * Copyright 1998 by Egbert Eich - */ - -#ifndef _EDID_H_ -#define _EDID_H_ - -#include - -#ifndef _X_EXPORT -#include -#endif - -/* read complete EDID record */ -#define EDID1_LEN 128 -#define BITS_PER_BYTE 9 -#define NUM BITS_PER_BYTE*EDID1_LEN -#define HEADER 6 - -#define STD_TIMINGS 8 -#define DET_TIMINGS 4 - -#ifdef _PARSE_EDID_ - -/* header: 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x00 */ -#define HEADER_SECTION 0 -#define HEADER_LENGTH 8 - -/* vendor section */ -#define VENDOR_SECTION (HEADER_SECTION + HEADER_LENGTH) -#define V_MANUFACTURER 0 -#define V_PROD_ID (V_MANUFACTURER + 2) -#define V_SERIAL (V_PROD_ID + 2) -#define V_WEEK (V_SERIAL + 4) -#define V_YEAR (V_WEEK + 1) -#define VENDOR_LENGTH (V_YEAR + 1) - -/* EDID version */ -#define VERSION_SECTION (VENDOR_SECTION + VENDOR_LENGTH) -#define V_VERSION 0 -#define V_REVISION (V_VERSION + 1) -#define VERSION_LENGTH (V_REVISION + 1) - -/* display information */ -#define DISPLAY_SECTION (VERSION_SECTION + VERSION_LENGTH) -#define D_INPUT 0 -#define D_HSIZE (D_INPUT + 1) -#define D_VSIZE (D_HSIZE + 1) -#define D_GAMMA (D_VSIZE + 1) -#define FEAT_S (D_GAMMA + 1) -#define D_RG_LOW (FEAT_S + 1) -#define D_BW_LOW (D_RG_LOW + 1) -#define D_REDX (D_BW_LOW + 1) -#define D_REDY (D_REDX + 1) -#define D_GREENX (D_REDY + 1) -#define D_GREENY (D_GREENX + 1) -#define D_BLUEX (D_GREENY + 1) -#define D_BLUEY (D_BLUEX + 1) -#define D_WHITEX (D_BLUEY + 1) -#define D_WHITEY (D_WHITEX + 1) -#define DISPLAY_LENGTH (D_WHITEY + 1) - -/* supported VESA and other standard timings */ -#define ESTABLISHED_TIMING_SECTION (DISPLAY_SECTION + DISPLAY_LENGTH) -#define E_T1 0 -#define E_T2 (E_T1 + 1) -#define E_TMANU (E_T2 + 1) -#define E_TIMING_LENGTH (E_TMANU + 1) - -/* non predefined standard timings supported by display */ -#define STD_TIMING_SECTION (ESTABLISHED_TIMING_SECTION + E_TIMING_LENGTH) -#define STD_TIMING_INFO_LEN 2 -#define STD_TIMING_INFO_NUM STD_TIMINGS -#define STD_TIMING_LENGTH (STD_TIMING_INFO_LEN * STD_TIMING_INFO_NUM) - -/* detailed timing info of non standard timings */ -#define DET_TIMING_SECTION (STD_TIMING_SECTION + STD_TIMING_LENGTH) -#define DET_TIMING_INFO_LEN 18 -#define MONITOR_DESC_LEN DET_TIMING_INFO_LEN -#define DET_TIMING_INFO_NUM DET_TIMINGS -#define DET_TIMING_LENGTH (DET_TIMING_INFO_LEN * DET_TIMING_INFO_NUM) - -/* number of EDID sections to follow */ -#define NO_EDID (DET_TIMING_SECTION + DET_TIMING_LENGTH) -/* one byte checksum */ -#define CHECKSUM (NO_EDID + 1) - -#if (CHECKSUM != (EDID1_LEN - 1)) -#error "EDID1 length != 128!" -#endif - -#define SECTION(x,y) (Uchar *)(x + y) -#define GET_ARRAY(y) ((Uchar *)(c + y)) -#define GET(y) *(Uchar *)(c + y) - -/* extract information from vendor section */ -#define _PROD_ID(x) x[0] + (x[1] << 8); -#define PROD_ID _PROD_ID(GET_ARRAY(V_PROD_ID)) -#define _SERIAL_NO(x) x[0] + (x[1] << 8) + (x[2] << 16) + (x[3] << 24) -#define SERIAL_NO _SERIAL_NO(GET_ARRAY(V_SERIAL)) -#define _YEAR(x) (x & 0xFF) + 1990 -#define YEAR _YEAR(GET(V_YEAR)) -#define WEEK GET(V_WEEK) & 0xFF -#define _L1(x) ((x[0] & 0x7C) >> 2) + '@' -#define _L2(x) ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@' -#define _L3(x) (x[1] & 0x1F) + '@'; -#define L1 _L1(GET_ARRAY(V_MANUFACTURER)) -#define L2 _L2(GET_ARRAY(V_MANUFACTURER)) -#define L3 _L3(GET_ARRAY(V_MANUFACTURER)) - -/* extract information from version section */ -#define VERSION GET(V_VERSION) -#define REVISION GET(V_REVISION) - -/* extract information from display section */ -#define _INPUT_TYPE(x) ((x & 0x80) >> 7) -#define INPUT_TYPE _INPUT_TYPE(GET(D_INPUT)) -#define _INPUT_VOLTAGE(x) ((x & 0x60) >> 5) -#define INPUT_VOLTAGE _INPUT_VOLTAGE(GET(D_INPUT)) -#define _SETUP(x) ((x & 0x10) >> 4) -#define SETUP _SETUP(GET(D_INPUT)) -#define _SYNC(x) (x & 0x0F) -#define SYNC _SYNC(GET(D_INPUT)) -#define _DFP(x) (x & 0x01) -#define DFP _DFP(GET(D_INPUT)) -#define _BPC(x) ((x & 0x70) >> 4) -#define BPC _BPC(GET(D_INPUT)) -#define _DIGITAL_INTERFACE(x) (x & 0x0F) -#define DIGITAL_INTERFACE _DIGITAL_INTERFACE(GET(D_INPUT)) -#define _GAMMA(x) (x == 0xff ? 0.0 : ((x + 100.0)/100.0)) -#define GAMMA _GAMMA(GET(D_GAMMA)) -#define HSIZE_MAX GET(D_HSIZE) -#define VSIZE_MAX GET(D_VSIZE) -#define _DPMS(x) ((x & 0xE0) >> 5) -#define DPMS _DPMS(GET(FEAT_S)) -#define _DISPLAY_TYPE(x) ((x & 0x18) >> 3) -#define DISPLAY_TYPE _DISPLAY_TYPE(GET(FEAT_S)) -#define _MSC(x) (x & 0x7) -#define MSC _MSC(GET(FEAT_S)) - -/* color characteristics */ -#define CC_L(x,y) ((x & (0x03 << y)) >> y) -#define CC_H(x) (x << 2) -#define I_CC(x,y,z) CC_H(y) | CC_L(x,z) -#define F_CC(x) ((x)/1024.0) -#define REDX F_CC(I_CC((GET(D_RG_LOW)),(GET(D_REDX)),6)) -#define REDY F_CC(I_CC((GET(D_RG_LOW)),(GET(D_REDY)),4)) -#define GREENX F_CC(I_CC((GET(D_RG_LOW)),(GET(D_GREENX)),2)) -#define GREENY F_CC(I_CC((GET(D_RG_LOW)),(GET(D_GREENY)),0)) -#define BLUEX F_CC(I_CC((GET(D_BW_LOW)),(GET(D_BLUEX)),6)) -#define BLUEY F_CC(I_CC((GET(D_BW_LOW)),(GET(D_BLUEY)),4)) -#define WHITEX F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEX)),2)) -#define WHITEY F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEY)),0)) - -/* extract information from standard timing section */ -#define T1 GET(E_T1) -#define T2 GET(E_T2) -#define T_MANU GET(E_TMANU) - -/* extract information from established timing section */ -#define _VALID_TIMING(x) !(((x[0] == 0x01) && (x[1] == 0x01)) \ - || ((x[0] == 0x00) && (x[1] == 0x00)) \ - || ((x[0] == 0x20) && (x[1] == 0x20)) ) -#define VALID_TIMING _VALID_TIMING(c) -#define _HSIZE1(x) ((x[0] + 31) * 8) -#define HSIZE1 _HSIZE1(c) -#define RATIO(x) ((x[1] & 0xC0) >> 6) -#define RATIO1_1 0 -/* EDID Ver. 1.3 redefined this */ -#define RATIO16_10 RATIO1_1 -#define RATIO4_3 1 -#define RATIO5_4 2 -#define RATIO16_9 3 -#define _VSIZE1(x,y,r) switch(RATIO(x)){ \ - case RATIO1_1: y = ((v->version > 1 || v->revision > 2) \ - ? (_HSIZE1(x) * 10) / 16 : _HSIZE1(x)); break; \ - case RATIO4_3: y = _HSIZE1(x) * 3 / 4; break; \ - case RATIO5_4: y = _HSIZE1(x) * 4 / 5; break; \ - case RATIO16_9: y = _HSIZE1(x) * 9 / 16; break; \ - } -#define VSIZE1(x) _VSIZE1(c,x,v) -#define _REFRESH_R(x) (x[1] & 0x3F) + 60 -#define REFRESH_R _REFRESH_R(c) -#define _ID_LOW(x) x[0] -#define ID_LOW _ID_LOW(c) -#define _ID_HIGH(x) (x[1] << 8) -#define ID_HIGH _ID_HIGH(c) -#define STD_TIMING_ID (ID_LOW | ID_HIGH) -#define _NEXT_STD_TIMING(x) (x = (x + STD_TIMING_INFO_LEN)) -#define NEXT_STD_TIMING _NEXT_STD_TIMING(c) - -/* EDID Ver. >= 1.2 */ -/** - * Returns true if the pointer is the start of a monitor descriptor block - * instead of a detailed timing descriptor. - * - * Checking the reserved pad fields for zeroes fails on some monitors with - * broken empty ASCII strings. Only the first two bytes are reliable. - */ -#define _IS_MONITOR_DESC(x) (x[0] == 0 && x[1] == 0) -#define IS_MONITOR_DESC _IS_MONITOR_DESC(c) -#define _PIXEL_CLOCK(x) (x[0] + (x[1] << 8)) * 10000 -#define PIXEL_CLOCK _PIXEL_CLOCK(c) -#define _H_ACTIVE(x) (x[2] + ((x[4] & 0xF0) << 4)) -#define H_ACTIVE _H_ACTIVE(c) -#define _H_BLANK(x) (x[3] + ((x[4] & 0x0F) << 8)) -#define H_BLANK _H_BLANK(c) -#define _V_ACTIVE(x) (x[5] + ((x[7] & 0xF0) << 4)) -#define V_ACTIVE _V_ACTIVE(c) -#define _V_BLANK(x) (x[6] + ((x[7] & 0x0F) << 8)) -#define V_BLANK _V_BLANK(c) -#define _H_SYNC_OFF(x) (x[8] + ((x[11] & 0xC0) << 2)) -#define H_SYNC_OFF _H_SYNC_OFF(c) -#define _H_SYNC_WIDTH(x) (x[9] + ((x[11] & 0x30) << 4)) -#define H_SYNC_WIDTH _H_SYNC_WIDTH(c) -#define _V_SYNC_OFF(x) ((x[10] >> 4) + ((x[11] & 0x0C) << 2)) -#define V_SYNC_OFF _V_SYNC_OFF(c) -#define _V_SYNC_WIDTH(x) ((x[10] & 0x0F) + ((x[11] & 0x03) << 4)) -#define V_SYNC_WIDTH _V_SYNC_WIDTH(c) -#define _H_SIZE(x) (x[12] + ((x[14] & 0xF0) << 4)) -#define H_SIZE _H_SIZE(c) -#define _V_SIZE(x) (x[13] + ((x[14] & 0x0F) << 8)) -#define V_SIZE _V_SIZE(c) -#define _H_BORDER(x) (x[15]) -#define H_BORDER _H_BORDER(c) -#define _V_BORDER(x) (x[16]) -#define V_BORDER _V_BORDER(c) -#define _INTERLACED(x) ((x[17] & 0x80) >> 7) -#define INTERLACED _INTERLACED(c) -#define _STEREO(x) ((x[17] & 0x60) >> 5) -#define STEREO _STEREO(c) -#define _STEREO1(x) (x[17] & 0x1) -#define STEREO1 _STEREO(c) -#define _SYNC_T(x) ((x[17] & 0x18) >> 3) -#define SYNC_T _SYNC_T(c) -#define _MISC(x) ((x[17] & 0x06) >> 1) -#define MISC _MISC(c) - -#define _MONITOR_DESC_TYPE(x) x[3] -#define MONITOR_DESC_TYPE _MONITOR_DESC_TYPE(c) -#define SERIAL_NUMBER 0xFF -#define ASCII_STR 0xFE -#define MONITOR_RANGES 0xFD -#define _MIN_V_OFFSET(x) ((!!(x[4] & 0x01)) * 255) -#define _MAX_V_OFFSET(x) ((!!(x[4] & 0x02)) * 255) -#define _MIN_H_OFFSET(x) ((!!(x[4] & 0x04)) * 255) -#define _MAX_H_OFFSET(x) ((!!(x[4] & 0x08)) * 255) -#define _MIN_V(x) x[5] -#define MIN_V (_MIN_V(c) + _MIN_V_OFFSET(c)) -#define _MAX_V(x) x[6] -#define MAX_V (_MAX_V(c) + _MAX_V_OFFSET(c)) -#define _MIN_H(x) x[7] -#define MIN_H (_MIN_H(c) + _MIN_H_OFFSET(c)) -#define _MAX_H(x) x[8] -#define MAX_H (_MAX_H(c) + _MAX_H_OFFSET(c)) -#define _MAX_CLOCK(x) x[9] -#define MAX_CLOCK _MAX_CLOCK(c) -#define _DEFAULT_GTF(x) (x[10] == 0x00) -#define DEFAULT_GTF _DEFAULT_GTF(c) -#define _RANGE_LIMITS_ONLY(x) (x[10] == 0x01) -#define RANGE_LIMITS_ONLY _RANGE_LIMITS_ONLY(c) -#define _HAVE_2ND_GTF(x) (x[10] == 0x02) -#define HAVE_2ND_GTF _HAVE_2ND_GTF(c) -#define _F_2ND_GTF(x) (x[12] * 2) -#define F_2ND_GTF _F_2ND_GTF(c) -#define _C_2ND_GTF(x) (x[13] / 2) -#define C_2ND_GTF _C_2ND_GTF(c) -#define _M_2ND_GTF(x) (x[14] + (x[15] << 8)) -#define M_2ND_GTF _M_2ND_GTF(c) -#define _K_2ND_GTF(x) (x[16]) -#define K_2ND_GTF _K_2ND_GTF(c) -#define _J_2ND_GTF(x) (x[17] / 2) -#define J_2ND_GTF _J_2ND_GTF(c) -#define _HAVE_CVT(x) (x[10] == 0x04) -#define HAVE_CVT _HAVE_CVT(c) -#define _MAX_CLOCK_KHZ(x) (x[12] >> 2) -#define MAX_CLOCK_KHZ (MAX_CLOCK * 10000) - (_MAX_CLOCK_KHZ(c) * 250) -#define _MAXWIDTH(x) ((x[13] == 0 ? 0 : x[13] + ((x[12] & 0x03) << 8)) * 8) -#define MAXWIDTH _MAXWIDTH(c) -#define _SUPPORTED_ASPECT(x) x[14] -#define SUPPORTED_ASPECT _SUPPORTED_ASPECT(c) -#define SUPPORTED_ASPECT_4_3 0x80 -#define SUPPORTED_ASPECT_16_9 0x40 -#define SUPPORTED_ASPECT_16_10 0x20 -#define SUPPORTED_ASPECT_5_4 0x10 -#define SUPPORTED_ASPECT_15_9 0x08 -#define _PREFERRED_ASPECT(x) ((x[15] & 0xe0) >> 5) -#define PREFERRED_ASPECT _PREFERRED_ASPECT(c) -#define PREFERRED_ASPECT_4_3 0 -#define PREFERRED_ASPECT_16_9 1 -#define PREFERRED_ASPECT_16_10 2 -#define PREFERRED_ASPECT_5_4 3 -#define PREFERRED_ASPECT_15_9 4 -#define _SUPPORTED_BLANKING(x) ((x[15] & 0x18) >> 3) -#define SUPPORTED_BLANKING _SUPPORTED_BLANKING(c) -#define CVT_STANDARD 0x01 -#define CVT_REDUCED 0x02 -#define _SUPPORTED_SCALING(x) ((x[16] & 0xf0) >> 4) -#define SUPPORTED_SCALING _SUPPORTED_SCALING(c) -#define SCALING_HSHRINK 0x08 -#define SCALING_HSTRETCH 0x04 -#define SCALING_VSHRINK 0x02 -#define SCALING_VSTRETCH 0x01 -#define _PREFERRED_REFRESH(x) x[17] -#define PREFERRED_REFRESH _PREFERRED_REFRESH(c) - -#define MONITOR_NAME 0xFC -#define ADD_COLOR_POINT 0xFB -#define WHITEX F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEX)),2)) -#define WHITEY F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEY)),0)) -#define _WHITEX_ADD(x,y) F_CC(I_CC(((*(x + y))),(*(x + y + 1)),2)) -#define _WHITEY_ADD(x,y) F_CC(I_CC(((*(x + y))),(*(x + y + 2)),0)) -#define _WHITE_INDEX1(x) x[5] -#define WHITE_INDEX1 _WHITE_INDEX1(c) -#define _WHITE_INDEX2(x) x[10] -#define WHITE_INDEX2 _WHITE_INDEX2(c) -#define WHITEX1 _WHITEX_ADD(c,6) -#define WHITEY1 _WHITEY_ADD(c,6) -#define WHITEX2 _WHITEX_ADD(c,12) -#define WHITEY2 _WHITEY_ADD(c,12) -#define _WHITE_GAMMA1(x) _GAMMA(x[9]) -#define WHITE_GAMMA1 _WHITE_GAMMA1(c) -#define _WHITE_GAMMA2(x) _GAMMA(x[14]) -#define WHITE_GAMMA2 _WHITE_GAMMA2(c) -#define ADD_STD_TIMINGS 0xFA -#define COLOR_MANAGEMENT_DATA 0xF9 -#define CVT_3BYTE_DATA 0xF8 -#define ADD_EST_TIMINGS 0xF7 -#define ADD_DUMMY 0x10 - -#define _NEXT_DT_MD_SECTION(x) (x = (x + DET_TIMING_INFO_LEN)) -#define NEXT_DT_MD_SECTION _NEXT_DT_MD_SECTION(c) - -#endif /* _PARSE_EDID_ */ - -/* input type */ -#define DIGITAL(x) x - -/* DFP */ -#define DFP1(x) x - -/* input voltage level */ -#define V070 0 /* 0.700V/0.300V */ -#define V071 1 /* 0.714V/0.286V */ -#define V100 2 /* 1.000V/0.400V */ -#define V007 3 /* 0.700V/0.000V */ - -/* Signal level setup */ -#define SIG_SETUP(x) (x) - -/* sync characteristics */ -#define SEP_SYNC(x) (x & 0x08) -#define COMP_SYNC(x) (x & 0x04) -#define SYNC_O_GREEN(x) (x & 0x02) -#define SYNC_SERR(x) (x & 0x01) - -/* DPMS features */ -#define DPMS_STANDBY(x) (x & 0x04) -#define DPMS_SUSPEND(x) (x & 0x02) -#define DPMS_OFF(x) (x & 0x01) - -/* display type, analog */ -#define DISP_MONO 0 -#define DISP_RGB 1 -#define DISP_MULTCOLOR 2 - -/* display color encodings, digital */ -#define DISP_YCRCB444 0x01 -#define DISP_YCRCB422 0x02 - -/* Msc stuff EDID Ver > 1.1 */ -#define STD_COLOR_SPACE(x) (x & 0x4) -#define PREFERRED_TIMING_MODE(x) (x & 0x2) -#define GFT_SUPPORTED(x) (x & 0x1) -#define GTF_SUPPORTED(x) (x & 0x1) -#define CVT_SUPPORTED(x) (x & 0x1) - -/* detailed timing misc */ -#define IS_INTERLACED(x) (x) -#define IS_STEREO(x) (x) -#define IS_RIGHT_STEREO(x) (x & 0x01) -#define IS_LEFT_STEREO(x) (x & 0x02) -#define IS_4WAY_STEREO(x) (x & 0x03) -#define IS_RIGHT_ON_SYNC(x) IS_RIGHT_STEREO(x) -#define IS_LEFT_ON_SYNC(x) IS_LEFT_STEREO(x) - -typedef unsigned int Uint; -typedef unsigned char Uchar; - -struct vendor { - char name[4]; - int prod_id; - Uint serial; - int week; - int year; -}; - -struct edid_version { - int version; - int revision; -}; - -struct disp_features { - unsigned int input_type:1; - unsigned int input_voltage:2; - unsigned int input_setup:1; - unsigned int input_sync:5; - unsigned int input_dfp:1; - unsigned int input_bpc:3; - unsigned int input_interface:4; - /* 15 bit hole */ - int hsize; - int vsize; - float gamma; - unsigned int dpms:3; - unsigned int display_type:2; - unsigned int msc:3; - float redx; - float redy; - float greenx; - float greeny; - float bluex; - float bluey; - float whitex; - float whitey; -}; - -struct established_timings { - Uchar t1; - Uchar t2; - Uchar t_manu; -}; - -struct std_timings { - int hsize; - int vsize; - int refresh; - CARD16 id; -}; - -struct detailed_timings { - int clock; - int h_active; - int h_blanking; - int v_active; - int v_blanking; - int h_sync_off; - int h_sync_width; - int v_sync_off; - int v_sync_width; - int h_size; - int v_size; - int h_border; - int v_border; - unsigned int interlaced:1; - unsigned int stereo:2; - unsigned int sync:2; - unsigned int misc:2; - unsigned int stereo_1:1; -}; - -#define DT 0 -#define DS_SERIAL 0xFF -#define DS_ASCII_STR 0xFE -#define DS_NAME 0xFC -#define DS_RANGES 0xFD -#define DS_WHITE_P 0xFB -#define DS_STD_TIMINGS 0xFA -#define DS_CMD 0xF9 -#define DS_CVT 0xF8 -#define DS_EST_III 0xF7 -#define DS_DUMMY 0x10 -#define DS_UNKOWN 0x100 /* type is an int */ -#define DS_VENDOR 0x101 -#define DS_VENDOR_MAX 0x110 - -/* - * Display range limit Descriptor of EDID version1, reversion 4 - */ -typedef enum { - DR_DEFAULT_GTF, - DR_LIMITS_ONLY, - DR_SECONDARY_GTF, - DR_CVT_SUPPORTED = 4, -} DR_timing_flags; - -struct monitor_ranges { - int min_v; - int max_v; - int min_h; - int max_h; - int max_clock; /* in mhz */ - int gtf_2nd_f; - int gtf_2nd_c; - int gtf_2nd_m; - int gtf_2nd_k; - int gtf_2nd_j; - int max_clock_khz; - int maxwidth; /* in pixels */ - char supported_aspect; - char preferred_aspect; - char supported_blanking; - char supported_scaling; - int preferred_refresh; /* in hz */ - DR_timing_flags display_range_timing_flags; -}; - -struct whitePoints { - int index; - float white_x; - float white_y; - float white_gamma; -}; - -struct cvt_timings { - int width; - int height; - int rate; - int rates; -}; - -/* - * Be careful when adding new sections; this structure can't grow, it's - * embedded in the middle of xf86Monitor which is ABI. Sizes below are - * in bytes, for ILP32 systems. If all else fails just copy the section - * literally like serial and friends. - */ -struct detailed_monitor_section { - int type; - union { - struct detailed_timings d_timings; /* 56 */ - Uchar serial[13]; - Uchar ascii_data[13]; - Uchar name[13]; - struct monitor_ranges ranges; /* 60 */ - struct std_timings std_t[5]; /* 80 */ - struct whitePoints wp[2]; /* 32 */ - /* color management data */ - struct cvt_timings cvt[4]; /* 64 */ - Uchar est_iii[6]; /* 6 */ - } section; /* max: 80 */ -}; - -/* flags */ -#define MONITOR_EDID_COMPLETE_RAWDATA 0x01 -/* old, don't use */ -#define EDID_COMPLETE_RAWDATA 0x01 - -/* - * For DisplayID devices, only the scrnIndex, flags, and rawData fields - * are meaningful. For EDID, they all are. - */ -typedef struct { - int scrnIndex; - struct vendor vendor; - struct edid_version ver; - struct disp_features features; - struct established_timings timings1; - struct std_timings timings2[8]; - struct detailed_monitor_section det_mon[4]; - unsigned long flags; - int no_sections; - Uchar *rawData; -} xf86Monitor, *xf86MonPtr; - -extern _X_EXPORT xf86MonPtr ConfiguredMonitor; - -#define EXT_TAG 0 -#define EXT_REV 1 -#define CEA_EXT 0x02 -#define VTB_EXT 0x10 -#define DI_EXT 0x40 -#define LS_EXT 0x50 -#define MI_EXT 0x60 - -#define CEA_EXT_MIN_DATA_OFFSET 4 -#define CEA_EXT_MAX_DATA_OFFSET 127 -#define CEA_EXT_DET_TIMING_NUM 6 - -#define IEEE_ID_HDMI 0x000C03 -#define CEA_AUDIO_BLK 1 -#define CEA_VIDEO_BLK 2 -#define CEA_VENDOR_BLK 3 -#define CEA_SPEAKER_ALLOC_BLK 4 -#define CEA_VESA_DTC_BLK 5 -#define VENDOR_SUPPORT_AI(x) ((x) >> 7) -#define VENDOR_SUPPORT_DC_48bit(x) ( ( (x) >> 6) & 0x01) -#define VENDOR_SUPPORT_DC_36bit(x) ( ( (x) >> 5) & 0x01) -#define VENDOR_SUPPORT_DC_30bit(x) ( ( (x) >> 4) & 0x01) -#define VENDOR_SUPPORT_DC_Y444(x) ( ( (x) >> 3) & 0x01) -#define VENDOR_LATENCY_PRESENT(x) ( (x) >> 7) -#define VENDOR_LATENCY_PRESENT_I(x) ( ( (x) >> 6) & 0x01) -#define HDMI_MAX_TMDS_UNIT (5000) - -struct cea_video_block { - Uchar video_code; -}; - -struct cea_audio_block_descriptor { - Uchar audio_code[3]; -}; - -struct cea_audio_block { - struct cea_audio_block_descriptor descriptor[10]; -}; - -struct cea_vendor_block_hdmi { - Uchar portB:4; - Uchar portA:4; - Uchar portD:4; - Uchar portC:4; - Uchar support_flags; - Uchar max_tmds_clock; - Uchar latency_present; - Uchar video_latency; - Uchar audio_latency; - Uchar interlaced_video_latency; - Uchar interlaced_audio_latency; -}; - -struct cea_vendor_block { - unsigned char ieee_id[3]; - union { - struct cea_vendor_block_hdmi hdmi; - /* any other vendor blocks we know about */ - }; -}; - -struct cea_speaker_block { - Uchar FLR:1; - Uchar LFE:1; - Uchar FC:1; - Uchar RLR:1; - Uchar RC:1; - Uchar FLRC:1; - Uchar RLRC:1; - Uchar FLRW:1; - Uchar FLRH:1; - Uchar TC:1; - Uchar FCH:1; - Uchar Resv:5; - Uchar ResvByte; -}; - -struct cea_data_block { - Uchar len:5; - Uchar tag:3; - union { - struct cea_video_block video; - struct cea_audio_block audio; - struct cea_vendor_block vendor; - struct cea_speaker_block speaker; - } u; -}; - -struct cea_ext_body { - Uchar tag; - Uchar rev; - Uchar dt_offset; - Uchar flags; - struct cea_data_block data_collection; -}; - -#endif /* _EDID_H_ */ diff --git a/hw/xfree86/ddc/interpret_edid.c b/hw/xfree86/ddc/interpret_edid.c deleted file mode 100644 index 7259d2192..000000000 --- a/hw/xfree86/ddc/interpret_edid.c +++ /dev/null @@ -1,788 +0,0 @@ -/* - * Copyright 1998 by Egbert Eich - * Copyright 2007 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * interpret_edid.c: interpret a primary EDID block - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "misc.h" -#include "xf86.h" -#include "xf86_OSproc.h" -#define _PARSE_EDID_ -#include "xf86DDC.h" -#include - -static void get_vendor_section(Uchar *, struct vendor *); -static void get_version_section(Uchar *, struct edid_version *); -static void get_display_section(Uchar *, struct disp_features *, - struct edid_version *); -static void get_established_timing_section(Uchar *, - struct established_timings *); -static void get_std_timing_section(Uchar *, struct std_timings *, - struct edid_version *); -static void fetch_detailed_block(Uchar * c, struct edid_version *ver, - struct detailed_monitor_section *det_mon); -static void get_dt_md_section(Uchar *, struct edid_version *, - struct detailed_monitor_section *det_mon); -static void copy_string(Uchar *, Uchar *); -static void get_dst_timing_section(Uchar *, struct std_timings *, - struct edid_version *); -static void get_monitor_ranges(Uchar *, struct monitor_ranges *); -static void get_whitepoint_section(Uchar *, struct whitePoints *); -static void get_detailed_timing_section(Uchar *, struct detailed_timings *); -static Bool validate_version(int scrnIndex, struct edid_version *); - -static void -find_ranges_section(struct detailed_monitor_section *det, void *ranges) -{ - if (det->type == DS_RANGES && det->section.ranges.max_clock) - *(struct monitor_ranges **) ranges = &det->section.ranges; -} - -static void -find_max_detailed_clock(struct detailed_monitor_section *det, void *ret) -{ - if (det->type == DT) { - *(int *) ret = max(*((int *) ret), det->section.d_timings.clock); - } -} - -static void -handle_edid_quirks(xf86MonPtr m) -{ - struct monitor_ranges *ranges = NULL; - - /* - * max_clock is only encoded in EDID in tens of MHz, so occasionally we - * find a monitor claiming a max of 160 with a mode requiring 162, or - * similar. Strictly we should refuse to round up too far, but let's - * see how well this works. - */ - - /* Try to find Monitor Range and max clock, then re-set range value */ - xf86ForEachDetailedBlock(m, find_ranges_section, &ranges); - if (ranges && ranges->max_clock) { - int clock = 0; - - xf86ForEachDetailedBlock(m, find_max_detailed_clock, &clock); - if (clock && (ranges->max_clock * 1e6 < clock)) { - xf86Msg(X_WARNING, "EDID timing clock %.2f exceeds claimed max " - "%dMHz, fixing\n", clock / 1.0e6, ranges->max_clock); - ranges->max_clock = (clock + 999999) / 1e6; - } - } -} - -struct det_hv_parameter { - int real_hsize; - int real_vsize; - float target_aspect; -}; - -static void -handle_detailed_hvsize(struct detailed_monitor_section *det_mon, void *data) -{ - struct det_hv_parameter *p = (struct det_hv_parameter *) data; - float timing_aspect; - - if (det_mon->type == DT) { - struct detailed_timings *timing; - - timing = &det_mon->section.d_timings; - - if (!timing->v_size) - return; - - timing_aspect = (float) timing->h_size / timing->v_size; - if (fabs(1 - (timing_aspect / p->target_aspect)) < 0.05) { - p->real_hsize = max(p->real_hsize, timing->h_size); - p->real_vsize = max(p->real_vsize, timing->v_size); - } - } -} - -static void -encode_aspect_ratio(xf86MonPtr m) -{ - /* - * some monitors encode the aspect ratio instead of the physical size. - * try to find the largest detailed timing that matches that aspect - * ratio and use that to fill in the feature section. - */ - if ((m->features.hsize == 16 && m->features.vsize == 9) || - (m->features.hsize == 16 && m->features.vsize == 10) || - (m->features.hsize == 4 && m->features.vsize == 3) || - (m->features.hsize == 5 && m->features.vsize == 4)) { - - struct det_hv_parameter p; - - p.real_hsize = 0; - p.real_vsize = 0; - p.target_aspect = (float) m->features.hsize / m->features.vsize; - - xf86ForEachDetailedBlock(m, handle_detailed_hvsize, &p); - - if (!p.real_hsize || !p.real_vsize) { - m->features.hsize = m->features.vsize = 0; - } - else if ((m->features.hsize * 10 == p.real_hsize) && - (m->features.vsize * 10 == p.real_vsize)) { - /* exact match is just unlikely, should do a better check though */ - m->features.hsize = m->features.vsize = 0; - } - else { - /* convert mm to cm */ - m->features.hsize = (p.real_hsize + 5) / 10; - m->features.vsize = (p.real_vsize + 5) / 10; - } - - xf86Msg(X_INFO, "Quirked EDID physical size to %dx%d cm\n", - m->features.hsize, m->features.vsize); - } -} - -xf86MonPtr -xf86InterpretEDID(int scrnIndex, Uchar * block) -{ - xf86MonPtr m; - - if (!block) - return NULL; - if (!(m = xnfcalloc(sizeof(xf86Monitor), 1))) - return NULL; - m->scrnIndex = scrnIndex; - m->rawData = block; - - get_vendor_section(SECTION(VENDOR_SECTION, block), &m->vendor); - get_version_section(SECTION(VERSION_SECTION, block), &m->ver); - if (!validate_version(scrnIndex, &m->ver)) - goto error; - get_display_section(SECTION(DISPLAY_SECTION, block), &m->features, &m->ver); - get_established_timing_section(SECTION(ESTABLISHED_TIMING_SECTION, block), - &m->timings1); - get_std_timing_section(SECTION(STD_TIMING_SECTION, block), m->timings2, - &m->ver); - get_dt_md_section(SECTION(DET_TIMING_SECTION, block), &m->ver, m->det_mon); - m->no_sections = (int) *(char *) SECTION(NO_EDID, block); - - handle_edid_quirks(m); - encode_aspect_ratio(m); - - return m; - - error: - free(m); - return NULL; -} - -static int -get_cea_detail_timing(Uchar * blk, xf86MonPtr mon, - struct detailed_monitor_section *det_mon) -{ - int dt_num; - int dt_offset = ((struct cea_ext_body *) blk)->dt_offset; - - dt_num = 0; - - if (dt_offset < CEA_EXT_MIN_DATA_OFFSET) - return dt_num; - - for (; dt_offset < (CEA_EXT_MAX_DATA_OFFSET - DET_TIMING_INFO_LEN) && - dt_num < CEA_EXT_DET_TIMING_NUM; _NEXT_DT_MD_SECTION(dt_offset)) { - - fetch_detailed_block(blk + dt_offset, &mon->ver, det_mon + dt_num); - dt_num = dt_num + 1; - } - - return dt_num; -} - -static void -handle_cea_detail_block(Uchar * ext, xf86MonPtr mon, - handle_detailed_fn fn, void *data) -{ - int i; - struct detailed_monitor_section det_mon[CEA_EXT_DET_TIMING_NUM]; - int det_mon_num; - - det_mon_num = get_cea_detail_timing(ext, mon, det_mon); - - for (i = 0; i < det_mon_num; i++) - fn(det_mon + i, data); -} - -void -xf86ForEachDetailedBlock(xf86MonPtr mon, handle_detailed_fn fn, void *data) -{ - int i; - Uchar *ext; - - if (mon == NULL) - return; - - for (i = 0; i < DET_TIMINGS; i++) - fn(mon->det_mon + i, data); - - for (i = 0; i < mon->no_sections; i++) { - ext = mon->rawData + EDID1_LEN * (i + 1); - switch (ext[EXT_TAG]) { - case CEA_EXT: - handle_cea_detail_block(ext, mon, fn, data); - break; - case VTB_EXT: - case DI_EXT: - case LS_EXT: - case MI_EXT: - break; - } - } -} - -static struct cea_data_block * -extract_cea_data_block(Uchar * ext, int data_type) -{ - struct cea_ext_body *cea; - struct cea_data_block *data_collection; - struct cea_data_block *data_end; - - cea = (struct cea_ext_body *) ext; - - if (cea->dt_offset <= CEA_EXT_MIN_DATA_OFFSET) - return NULL; - - data_collection = &cea->data_collection; - data_end = (struct cea_data_block *) (cea->dt_offset + ext); - - for (; data_collection < data_end;) { - - if (data_type == data_collection->tag) { - return data_collection; - } - data_collection = (void *) ((unsigned char *) data_collection + - data_collection->len + 1); - } - - return NULL; -} - -static void -handle_cea_video_block(Uchar * ext, handle_video_fn fn, void *data) -{ - struct cea_video_block *video; - struct cea_video_block *video_end; - struct cea_data_block *data_collection; - - data_collection = extract_cea_data_block(ext, CEA_VIDEO_BLK); - if (data_collection == NULL) - return; - - video = &data_collection->u.video; - video_end = (struct cea_video_block *) - ((Uchar *) video + data_collection->len); - - for (; video < video_end; video = video + 1) { - fn(video, data); - } -} - -void -xf86ForEachVideoBlock(xf86MonPtr mon, handle_video_fn fn, void *data) -{ - int i; - Uchar *ext; - - if (mon == NULL) - return; - - for (i = 0; i < mon->no_sections; i++) { - ext = mon->rawData + EDID1_LEN * (i + 1); - switch (ext[EXT_TAG]) { - case CEA_EXT: - handle_cea_video_block(ext, fn, data); - break; - case VTB_EXT: - case DI_EXT: - case LS_EXT: - case MI_EXT: - break; - } - } -} - -static Bool -cea_db_offsets(Uchar *cea, int *start, int *end) -{ - /* Data block offset in CEA extension block */ - *start = CEA_EXT_MIN_DATA_OFFSET; - *end = cea[2]; - if (*end == 0) - *end = CEA_EXT_MAX_DATA_OFFSET; - if (*end < CEA_EXT_MIN_DATA_OFFSET || *end > CEA_EXT_MAX_DATA_OFFSET) - return FALSE; - return TRUE; -} - -static int -cea_db_len(Uchar *db) -{ - return db[0] & 0x1f; -} - -static int -cea_db_tag(Uchar *db) -{ - return db[0] >> 5; -} - -typedef void (*handle_cea_db_fn) (Uchar *, void *); - -static void -cea_for_each_db(xf86MonPtr mon, handle_cea_db_fn fn, void *data) -{ - int i; - - if (!mon) - return; - - if (!(mon->flags & EDID_COMPLETE_RAWDATA)) - return; - - if (!mon->no_sections) - return; - - if (!mon->rawData) - return; - - for (i = 0; i < mon->no_sections; i++) { - int start, end, offset; - Uchar *ext; - - ext = mon->rawData + EDID1_LEN * (i + 1); - if (ext[EXT_TAG] != CEA_EXT) - continue; - - if (!cea_db_offsets(ext, &start, &end)) - continue; - - for (offset = start; - offset < end && offset + cea_db_len(&ext[offset]) < end; - offset += cea_db_len(&ext[offset]) + 1) - fn(&ext[offset], data); - } -} - -struct find_hdmi_block_data { - struct cea_data_block *hdmi; -}; - -static void find_hdmi_block(Uchar *db, void *data) -{ - struct find_hdmi_block_data *result = data; - int oui; - - if (cea_db_tag(db) != CEA_VENDOR_BLK) - return; - - if (cea_db_len(db) < 5) - return; - - oui = (db[3] << 16) | (db[2] << 8) | db[1]; - if (oui == IEEE_ID_HDMI) - result->hdmi = (struct cea_data_block *)db; -} - -struct cea_data_block *xf86MonitorFindHDMIBlock(xf86MonPtr mon) -{ - struct find_hdmi_block_data result = { NULL }; - - cea_for_each_db(mon, find_hdmi_block, &result); - - return result.hdmi; -} - -xf86MonPtr -xf86InterpretEEDID(int scrnIndex, Uchar * block) -{ - xf86MonPtr m; - - m = xf86InterpretEDID(scrnIndex, block); - if (!m) - return NULL; - - /* extension parse */ - - return m; -} - -static void -get_vendor_section(Uchar * c, struct vendor *r) -{ - r->name[0] = L1; - r->name[1] = L2; - r->name[2] = L3; - r->name[3] = '\0'; - - r->prod_id = PROD_ID; - r->serial = SERIAL_NO; - r->week = WEEK; - r->year = YEAR; -} - -static void -get_version_section(Uchar * c, struct edid_version *r) -{ - r->version = VERSION; - r->revision = REVISION; -} - -static void -get_display_section(Uchar * c, struct disp_features *r, struct edid_version *v) -{ - r->input_type = INPUT_TYPE; - if (!DIGITAL(r->input_type)) { - r->input_voltage = INPUT_VOLTAGE; - r->input_setup = SETUP; - r->input_sync = SYNC; - } - else if (v->revision == 2 || v->revision == 3) { - r->input_dfp = DFP; - } - else if (v->revision >= 4) { - r->input_bpc = BPC; - r->input_interface = DIGITAL_INTERFACE; - } - r->hsize = HSIZE_MAX; - r->vsize = VSIZE_MAX; - r->gamma = GAMMA; - r->dpms = DPMS; - r->display_type = DISPLAY_TYPE; - r->msc = MSC; - r->redx = REDX; - r->redy = REDY; - r->greenx = GREENX; - r->greeny = GREENY; - r->bluex = BLUEX; - r->bluey = BLUEY; - r->whitex = WHITEX; - r->whitey = WHITEY; -} - -static void -get_established_timing_section(Uchar * c, struct established_timings *r) -{ - r->t1 = T1; - r->t2 = T2; - r->t_manu = T_MANU; -} - -static void -get_cvt_timing_section(Uchar * c, struct cvt_timings *r) -{ - int i; - - for (i = 0; i < 4; i++) { - if (c[0] && c[1] && c[2]) { - r[i].height = (c[0] + ((c[1] & 0xF0) << 8) + 1) * 2; - switch (c[1] & 0xc0) { - case 0x00: - r[i].width = r[i].height * 4 / 3; - break; - case 0x40: - r[i].width = r[i].height * 16 / 9; - break; - case 0x80: - r[i].width = r[i].height * 16 / 10; - break; - case 0xc0: - r[i].width = r[i].height * 15 / 9; - break; - } - switch (c[2] & 0x60) { - case 0x00: - r[i].rate = 50; - break; - case 0x20: - r[i].rate = 60; - break; - case 0x40: - r[i].rate = 75; - break; - case 0x60: - r[i].rate = 85; - break; - } - r[i].rates = c[2] & 0x1f; - } - else { - return; - } - c += 3; - } -} - -static void -get_std_timing_section(Uchar * c, struct std_timings *r, struct edid_version *v) -{ - int i; - - for (i = 0; i < STD_TIMINGS; i++) { - if (VALID_TIMING) { - r[i].hsize = HSIZE1; - VSIZE1(r[i].vsize); - r[i].refresh = REFRESH_R; - r[i].id = STD_TIMING_ID; - } - else { - r[i].hsize = r[i].vsize = r[i].refresh = r[i].id = 0; - } - NEXT_STD_TIMING; - } -} - -static const unsigned char empty_block[18]; - -static void -fetch_detailed_block(Uchar * c, struct edid_version *ver, - struct detailed_monitor_section *det_mon) -{ - if (ver->version == 1 && ver->revision >= 1 && IS_MONITOR_DESC) { - switch (MONITOR_DESC_TYPE) { - case SERIAL_NUMBER: - det_mon->type = DS_SERIAL; - copy_string(c, det_mon->section.serial); - break; - case ASCII_STR: - det_mon->type = DS_ASCII_STR; - copy_string(c, det_mon->section.ascii_data); - break; - case MONITOR_RANGES: - det_mon->type = DS_RANGES; - get_monitor_ranges(c, &det_mon->section.ranges); - break; - case MONITOR_NAME: - det_mon->type = DS_NAME; - copy_string(c, det_mon->section.name); - break; - case ADD_COLOR_POINT: - det_mon->type = DS_WHITE_P; - get_whitepoint_section(c, det_mon->section.wp); - break; - case ADD_STD_TIMINGS: - det_mon->type = DS_STD_TIMINGS; - get_dst_timing_section(c, det_mon->section.std_t, ver); - break; - case COLOR_MANAGEMENT_DATA: - det_mon->type = DS_CMD; - break; - case CVT_3BYTE_DATA: - det_mon->type = DS_CVT; - get_cvt_timing_section(c, det_mon->section.cvt); - break; - case ADD_EST_TIMINGS: - det_mon->type = DS_EST_III; - memcpy(det_mon->section.est_iii, c + 6, 6); - break; - case ADD_DUMMY: - det_mon->type = DS_DUMMY; - break; - default: - det_mon->type = DS_UNKOWN; - break; - } - if (c[3] <= 0x0F && memcmp(c, empty_block, sizeof(empty_block))) { - det_mon->type = DS_VENDOR + c[3]; - } - } - else { - det_mon->type = DT; - get_detailed_timing_section(c, &det_mon->section.d_timings); - } -} - -static void -get_dt_md_section(Uchar * c, struct edid_version *ver, - struct detailed_monitor_section *det_mon) -{ - int i; - - for (i = 0; i < DET_TIMINGS; i++) { - fetch_detailed_block(c, ver, det_mon + i); - NEXT_DT_MD_SECTION; - } -} - -static void -copy_string(Uchar * c, Uchar * s) -{ - int i; - - c = c + 5; - for (i = 0; (i < 13 && *c != 0x0A); i++) - *(s++) = *(c++); - *s = 0; - while (i-- && (*--s == 0x20)) - *s = 0; -} - -static void -get_dst_timing_section(Uchar * c, struct std_timings *t, struct edid_version *v) -{ - int j; - - c = c + 5; - for (j = 0; j < 5; j++) { - t[j].hsize = HSIZE1; - VSIZE1(t[j].vsize); - t[j].refresh = REFRESH_R; - t[j].id = STD_TIMING_ID; - NEXT_STD_TIMING; - } -} - -static void -get_monitor_ranges(Uchar * c, struct monitor_ranges *r) -{ - r->min_v = MIN_V; - r->max_v = MAX_V; - r->min_h = MIN_H; - r->max_h = MAX_H; - r->max_clock = 0; - if (MAX_CLOCK != 0xff) /* is specified? */ - r->max_clock = MAX_CLOCK * 10 + 5; - - r->display_range_timing_flags = c[10]; - - if (HAVE_2ND_GTF) { - r->gtf_2nd_f = F_2ND_GTF; - r->gtf_2nd_c = C_2ND_GTF; - r->gtf_2nd_m = M_2ND_GTF; - r->gtf_2nd_k = K_2ND_GTF; - r->gtf_2nd_j = J_2ND_GTF; - } - else { - r->gtf_2nd_f = 0; - } - if (HAVE_CVT) { - r->max_clock_khz = MAX_CLOCK_KHZ; - r->max_clock = r->max_clock_khz / 1000; - r->maxwidth = MAXWIDTH; - r->supported_aspect = SUPPORTED_ASPECT; - r->preferred_aspect = PREFERRED_ASPECT; - r->supported_blanking = SUPPORTED_BLANKING; - r->supported_scaling = SUPPORTED_SCALING; - r->preferred_refresh = PREFERRED_REFRESH; - } - else { - r->max_clock_khz = 0; - } -} - -static void -get_whitepoint_section(Uchar * c, struct whitePoints *wp) -{ - wp[0].white_x = WHITEX1; - wp[0].white_y = WHITEY1; - wp[1].white_x = WHITEX2; - wp[1].white_y = WHITEY2; - wp[0].index = WHITE_INDEX1; - wp[1].index = WHITE_INDEX2; - wp[0].white_gamma = WHITE_GAMMA1; - wp[1].white_gamma = WHITE_GAMMA2; -} - -static void -get_detailed_timing_section(Uchar * c, struct detailed_timings *r) -{ - r->clock = PIXEL_CLOCK; - r->h_active = H_ACTIVE; - r->h_blanking = H_BLANK; - r->v_active = V_ACTIVE; - r->v_blanking = V_BLANK; - r->h_sync_off = H_SYNC_OFF; - r->h_sync_width = H_SYNC_WIDTH; - r->v_sync_off = V_SYNC_OFF; - r->v_sync_width = V_SYNC_WIDTH; - r->h_size = H_SIZE; - r->v_size = V_SIZE; - r->h_border = H_BORDER; - r->v_border = V_BORDER; - r->interlaced = INTERLACED; - r->stereo = STEREO; - r->stereo_1 = STEREO1; - r->sync = SYNC_T; - r->misc = MISC; -} - -#define MAX_EDID_MINOR 4 - -static Bool -validate_version(int scrnIndex, struct edid_version *r) -{ - if (r->version != 1) { - xf86DrvMsg(scrnIndex, X_ERROR, "Unknown EDID version %d\n", r->version); - return FALSE; - } - - if (r->revision > MAX_EDID_MINOR) - xf86DrvMsg(scrnIndex, X_WARNING, - "Assuming version 1.%d is compatible with 1.%d\n", - r->revision, MAX_EDID_MINOR); - - return TRUE; -} - -Bool -gtf_supported(xf86MonPtr mon) -{ - int i; - - if (!mon) - return FALSE; - - if ((mon->ver.version == 1) && (mon->ver.revision < 4)) { - if (mon->features.msc & 0x1) - return TRUE; - } else { - for (i = 0; i < DET_TIMINGS; i++) { - struct detailed_monitor_section *det_timing_des = &(mon->det_mon[i]); - if (det_timing_des && (det_timing_des->type == DS_RANGES) && (mon->features.msc & 0x1) && - (det_timing_des->section.ranges.display_range_timing_flags == DR_DEFAULT_GTF - || det_timing_des->section.ranges.display_range_timing_flags == DR_SECONDARY_GTF)) - return TRUE; - } - } - - return FALSE; -} - -/* - * Returns true if HDMI, false if definitely not or unknown. - */ -Bool -xf86MonitorIsHDMI(xf86MonPtr mon) -{ - return xf86MonitorFindHDMIBlock(mon) != NULL; -} diff --git a/hw/xfree86/ddc/meson.build b/hw/xfree86/ddc/meson.build deleted file mode 100644 index c9b816f2e..000000000 --- a/hw/xfree86/ddc/meson.build +++ /dev/null @@ -1,15 +0,0 @@ -srcs_xorg_ddc = [ - 'ddc.c', - 'interpret_edid.c', - 'print_edid.c', - 'ddcProperty.c', -] - -xorg_ddc = static_library('xorg_ddc', - srcs_xorg_ddc, - include_directories: [inc, xorg_inc], - dependencies: common_dep, - c_args: xorg_c_args, -) - -install_data(['edid.h', 'xf86DDC.h'], install_dir: xorgsdkdir) diff --git a/hw/xfree86/ddc/print_edid.c b/hw/xfree86/ddc/print_edid.c deleted file mode 100644 index 699cbe11d..000000000 --- a/hw/xfree86/ddc/print_edid.c +++ /dev/null @@ -1,562 +0,0 @@ -/* - * Copyright 1998 by Egbert Eich - * Copyright 2007 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * print_edid.c: print out all information retrieved from display device - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -/* XXX kinda gross */ -#define _PARSE_EDID_ - -#include "misc.h" -#include "xf86.h" -#include "xf86_OSproc.h" -#include "xf86DDC.h" -#include "edid.h" - -#define EDID_WIDTH 16 - -static void -print_vendor(int scrnIndex, struct vendor *c) -{ - xf86DrvMsg(scrnIndex, X_INFO, "Manufacturer: %s Model: %x Serial#: %u\n", - (char *) &c->name, c->prod_id, c->serial); - xf86DrvMsg(scrnIndex, X_INFO, "Year: %u Week: %u\n", c->year, c->week); -} - -static void -print_version(int scrnIndex, struct edid_version *c) -{ - xf86DrvMsg(scrnIndex, X_INFO, "EDID Version: %u.%u\n", c->version, - c->revision); -} - -static const char *digital_interfaces[] = { - "undefined", - "DVI", - "HDMI-a", - "HDMI-b", - "MDDI", - "DisplayPort", - "unknown" -}; - -static void -print_input_features(int scrnIndex, struct disp_features *c, - struct edid_version *v) -{ - if (DIGITAL(c->input_type)) { - xf86DrvMsg(scrnIndex, X_INFO, "Digital Display Input\n"); - if (v->revision == 2 || v->revision == 3) { - if (DFP1(c->input_dfp)) - xf86DrvMsg(scrnIndex, X_INFO, "DFP 1.x compatible TMDS\n"); - } - else if (v->revision >= 4) { - int interface = c->input_interface; - int bpc = c->input_bpc; - - if (interface > 6) - interface = 6; /* unknown */ - if (bpc == 0 || bpc == 7) - xf86DrvMsg(scrnIndex, X_INFO, "Undefined color depth\n"); - else - xf86DrvMsg(scrnIndex, X_INFO, "%d bits per channel\n", - bpc * 2 + 4); - xf86DrvMsg(scrnIndex, X_INFO, "Digital interface is %s\n", - digital_interfaces[interface]); - } - } - else { - xf86DrvMsg(scrnIndex, X_INFO, "Analog Display Input, "); - xf86ErrorF("Input Voltage Level: "); - switch (c->input_voltage) { - case V070: - xf86ErrorF("0.700/0.300 V\n"); - break; - case V071: - xf86ErrorF("0.714/0.286 V\n"); - break; - case V100: - xf86ErrorF("1.000/0.400 V\n"); - break; - case V007: - xf86ErrorF("0.700/0.700 V\n"); - break; - default: - xf86ErrorF("undefined\n"); - } - if (SIG_SETUP(c->input_setup)) - xf86DrvMsg(scrnIndex, X_INFO, "Signal levels configurable\n"); - xf86DrvMsg(scrnIndex, X_INFO, "Sync:"); - if (SEP_SYNC(c->input_sync)) - xf86ErrorF(" Separate"); - if (COMP_SYNC(c->input_sync)) - xf86ErrorF(" Composite"); - if (SYNC_O_GREEN(c->input_sync)) - xf86ErrorF(" SyncOnGreen"); - if (SYNC_SERR(c->input_sync)) - xf86ErrorF("Serration on. " - "V.Sync Pulse req. if CompSync or SyncOnGreen\n"); - else - xf86ErrorF("\n"); - } -} - -static void -print_dpms_features(int scrnIndex, struct disp_features *c, - struct edid_version *v) -{ - if (c->dpms) { - xf86DrvMsg(scrnIndex, X_INFO, "DPMS capabilities:"); - if (DPMS_STANDBY(c->dpms)) - xf86ErrorF(" StandBy"); - if (DPMS_SUSPEND(c->dpms)) - xf86ErrorF(" Suspend"); - if (DPMS_OFF(c->dpms)) - xf86ErrorF(" Off"); - } - else - xf86DrvMsg(scrnIndex, X_INFO, "No DPMS capabilities specified"); - if (!c->input_type) { /* analog */ - switch (c->display_type) { - case DISP_MONO: - xf86ErrorF("; Monochrome/GrayScale Display\n"); - break; - case DISP_RGB: - xf86ErrorF("; RGB/Color Display\n"); - break; - case DISP_MULTCOLOR: - xf86ErrorF("; Non RGB Multicolor Display\n"); - break; - default: - xf86ErrorF("\n"); - break; - } - } - else { - int enc = c->display_type; - - xf86ErrorF("\n"); - xf86DrvMsg(scrnIndex, X_INFO, "Supported color encodings: " - "RGB 4:4:4 %s%s\n", - enc & DISP_YCRCB444 ? "YCrCb 4:4:4 " : "", - enc & DISP_YCRCB422 ? "YCrCb 4:2:2" : ""); - } - - if (STD_COLOR_SPACE(c->msc)) - xf86DrvMsg(scrnIndex, X_INFO, - "Default color space is primary color space\n"); - - if (PREFERRED_TIMING_MODE(c->msc) || v->revision >= 4) { - xf86DrvMsg(scrnIndex, X_INFO, - "First detailed timing is preferred mode\n"); - if (v->revision >= 4) - xf86DrvMsg(scrnIndex, X_INFO, - "Preferred mode is native pixel format and refresh rate\n"); - } - else if (v->revision == 3) { - xf86DrvMsg(scrnIndex, X_INFO, - "First detailed timing not preferred " - "mode in violation of standard!\n"); - } - - if (v->revision >= 4) { - if (GFT_SUPPORTED(c->msc)) { - xf86DrvMsg(scrnIndex, X_INFO, "Display is continuous-frequency\n"); - } - } - else { - if (GFT_SUPPORTED(c->msc)) - xf86DrvMsg(scrnIndex, X_INFO, "GTF timings supported\n"); - } -} - -static void -print_whitepoint(int scrnIndex, struct disp_features *disp) -{ - xf86DrvMsg(scrnIndex, X_INFO, "redX: %.3f redY: %.3f ", - disp->redx, disp->redy); - xf86ErrorF("greenX: %.3f greenY: %.3f\n", disp->greenx, disp->greeny); - xf86DrvMsg(scrnIndex, X_INFO, "blueX: %.3f blueY: %.3f ", - disp->bluex, disp->bluey); - xf86ErrorF("whiteX: %.3f whiteY: %.3f\n", disp->whitex, disp->whitey); -} - -static void -print_display(int scrnIndex, struct disp_features *disp, struct edid_version *v) -{ - print_input_features(scrnIndex, disp, v); - if (disp->hsize && disp->vsize) { - xf86DrvMsg(scrnIndex, X_INFO, "Max Image Size [cm]: "); - xf86ErrorF("horiz.: %i ", disp->hsize); - xf86ErrorF("vert.: %i\n", disp->vsize); - } - else if (v->revision >= 4 && (disp->hsize || disp->vsize)) { - if (disp->hsize) - xf86DrvMsg(scrnIndex, X_INFO, "Aspect ratio: %.2f (landscape)\n", - (disp->hsize + 99) / 100.0); - if (disp->vsize) - xf86DrvMsg(scrnIndex, X_INFO, "Aspect ratio: %.2f (portrait)\n", - 100.0 / (float) (disp->vsize + 99)); - - } - else { - xf86DrvMsg(scrnIndex, X_INFO, "Indeterminate output size\n"); - } - - if (!disp->gamma && v->revision >= 1.4) - xf86DrvMsg(scrnIndex, X_INFO, "Gamma defined in extension block\n"); - else - xf86DrvMsg(scrnIndex, X_INFO, "Gamma: %.2f\n", disp->gamma); - - print_dpms_features(scrnIndex, disp, v); - print_whitepoint(scrnIndex, disp); -} - -static void -print_established_timings(int scrnIndex, struct established_timings *t) -{ - unsigned char c; - - if (t->t1 || t->t2 || t->t_manu) - xf86DrvMsg(scrnIndex, X_INFO, "Supported established timings:\n"); - c = t->t1; - if (c & 0x80) - xf86DrvMsg(scrnIndex, X_INFO, "720x400@70Hz\n"); - if (c & 0x40) - xf86DrvMsg(scrnIndex, X_INFO, "720x400@88Hz\n"); - if (c & 0x20) - xf86DrvMsg(scrnIndex, X_INFO, "640x480@60Hz\n"); - if (c & 0x10) - xf86DrvMsg(scrnIndex, X_INFO, "640x480@67Hz\n"); - if (c & 0x08) - xf86DrvMsg(scrnIndex, X_INFO, "640x480@72Hz\n"); - if (c & 0x04) - xf86DrvMsg(scrnIndex, X_INFO, "640x480@75Hz\n"); - if (c & 0x02) - xf86DrvMsg(scrnIndex, X_INFO, "800x600@56Hz\n"); - if (c & 0x01) - xf86DrvMsg(scrnIndex, X_INFO, "800x600@60Hz\n"); - c = t->t2; - if (c & 0x80) - xf86DrvMsg(scrnIndex, X_INFO, "800x600@72Hz\n"); - if (c & 0x40) - xf86DrvMsg(scrnIndex, X_INFO, "800x600@75Hz\n"); - if (c & 0x20) - xf86DrvMsg(scrnIndex, X_INFO, "832x624@75Hz\n"); - if (c & 0x10) - xf86DrvMsg(scrnIndex, X_INFO, "1024x768@87Hz (interlaced)\n"); - if (c & 0x08) - xf86DrvMsg(scrnIndex, X_INFO, "1024x768@60Hz\n"); - if (c & 0x04) - xf86DrvMsg(scrnIndex, X_INFO, "1024x768@70Hz\n"); - if (c & 0x02) - xf86DrvMsg(scrnIndex, X_INFO, "1024x768@75Hz\n"); - if (c & 0x01) - xf86DrvMsg(scrnIndex, X_INFO, "1280x1024@75Hz\n"); - c = t->t_manu; - if (c & 0x80) - xf86DrvMsg(scrnIndex, X_INFO, "1152x864@75Hz\n"); - xf86DrvMsg(scrnIndex, X_INFO, "Manufacturer's mask: %X\n", c & 0x7F); -} - -static void -print_std_timings(int scrnIndex, struct std_timings *t) -{ - int i; - char done = 0; - - for (i = 0; i < STD_TIMINGS; i++) { - if (t[i].hsize > 256) { /* sanity check */ - if (!done) { - xf86DrvMsg(scrnIndex, X_INFO, "Supported standard timings:\n"); - done = 1; - } - xf86DrvMsg(scrnIndex, X_INFO, - "#%i: hsize: %i vsize %i refresh: %i vid: %i\n", - i, t[i].hsize, t[i].vsize, t[i].refresh, t[i].id); - } - } -} - -static void -print_cvt_timings(int si, struct cvt_timings *t) -{ - int i; - - for (i = 0; i < 4; i++) { - if (t[i].height) { - xf86DrvMsg(si, X_INFO, "%dx%d @ %s%s%s%s%s Hz\n", - t[i].width, t[i].height, - t[i].rates & 0x10 ? "50," : "", - t[i].rates & 0x08 ? "60," : "", - t[i].rates & 0x04 ? "75," : "", - t[i].rates & 0x02 ? "85," : "", - t[i].rates & 0x01 ? "60RB" : ""); - } - else - break; - } -} - -static void -print_detailed_timings(int scrnIndex, struct detailed_timings *t) -{ - - if (t->clock > 15000000) { /* sanity check */ - xf86DrvMsg(scrnIndex, X_INFO, "Supported detailed timing:\n"); - xf86DrvMsg(scrnIndex, X_INFO, "clock: %.1f MHz ", - t->clock / 1000000.0); - xf86ErrorF("Image Size: %i x %i mm\n", t->h_size, t->v_size); - xf86DrvMsg(scrnIndex, X_INFO, - "h_active: %i h_sync: %i h_sync_end %i h_blank_end %i ", - t->h_active, t->h_sync_off + t->h_active, - t->h_sync_off + t->h_sync_width + t->h_active, - t->h_active + t->h_blanking); - xf86ErrorF("h_border: %i\n", t->h_border); - xf86DrvMsg(scrnIndex, X_INFO, - "v_active: %i v_sync: %i v_sync_end %i v_blanking: %i ", - t->v_active, t->v_sync_off + t->v_active, - t->v_sync_off + t->v_sync_width + t->v_active, - t->v_active + t->v_blanking); - xf86ErrorF("v_border: %i\n", t->v_border); - if (IS_STEREO(t->stereo)) { - xf86DrvMsg(scrnIndex, X_INFO, "Stereo: "); - if (IS_RIGHT_STEREO(t->stereo)) { - if (!t->stereo_1) - xf86ErrorF("right channel on sync\n"); - else - xf86ErrorF("left channel on sync\n"); - } - else if (IS_LEFT_STEREO(t->stereo)) { - if (!t->stereo_1) - xf86ErrorF("right channel on even line\n"); - else - xf86ErrorF("left channel on evel line\n"); - } - if (IS_4WAY_STEREO(t->stereo)) { - if (!t->stereo_1) - xf86ErrorF("4-way interleaved\n"); - else - xf86ErrorF("side-by-side interleaved"); - } - } - } -} - -/* This function handle all detailed patchs, - * including EDID and EDID-extension - */ -struct det_print_parameter { - xf86MonPtr m; - int index; - ddc_quirk_t quirks; -}; - -static void -handle_detailed_print(struct detailed_monitor_section *det_mon, void *data) -{ - int j, scrnIndex; - struct det_print_parameter *p; - - p = (struct det_print_parameter *) data; - scrnIndex = p->m->scrnIndex; - xf86DetTimingApplyQuirks(det_mon, p->quirks, - p->m->features.hsize, p->m->features.vsize); - - switch (det_mon->type) { - case DT: - print_detailed_timings(scrnIndex, &det_mon->section.d_timings); - break; - case DS_SERIAL: - xf86DrvMsg(scrnIndex, X_INFO, "Serial No: %s\n", - det_mon->section.serial); - break; - case DS_ASCII_STR: - xf86DrvMsg(scrnIndex, X_INFO, " %s\n", det_mon->section.ascii_data); - break; - case DS_NAME: - xf86DrvMsg(scrnIndex, X_INFO, "Monitor name: %s\n", - det_mon->section.name); - break; - case DS_RANGES: - { - struct monitor_ranges *r = &det_mon->section.ranges; - - xf86DrvMsg(scrnIndex, X_INFO, - "Ranges: V min: %i V max: %i Hz, H min: %i H max: %i kHz,", - r->min_v, r->max_v, r->min_h, r->max_h); - if (r->max_clock_khz != 0) { - xf86ErrorF(" PixClock max %i kHz\n", r->max_clock_khz); - if (r->maxwidth) - xf86DrvMsg(scrnIndex, X_INFO, "Maximum pixel width: %d\n", - r->maxwidth); - xf86DrvMsg(scrnIndex, X_INFO, "Supported aspect ratios:"); - if (r->supported_aspect & SUPPORTED_ASPECT_4_3) - xf86ErrorF(" 4:3%s", - r->preferred_aspect == - PREFERRED_ASPECT_4_3 ? "*" : ""); - if (r->supported_aspect & SUPPORTED_ASPECT_16_9) - xf86ErrorF(" 16:9%s", - r->preferred_aspect == - PREFERRED_ASPECT_16_9 ? "*" : ""); - if (r->supported_aspect & SUPPORTED_ASPECT_16_10) - xf86ErrorF(" 16:10%s", - r->preferred_aspect == - PREFERRED_ASPECT_16_10 ? "*" : ""); - if (r->supported_aspect & SUPPORTED_ASPECT_5_4) - xf86ErrorF(" 5:4%s", - r->preferred_aspect == - PREFERRED_ASPECT_5_4 ? "*" : ""); - if (r->supported_aspect & SUPPORTED_ASPECT_15_9) - xf86ErrorF(" 15:9%s", - r->preferred_aspect == - PREFERRED_ASPECT_15_9 ? "*" : ""); - xf86ErrorF("\n"); - xf86DrvMsg(scrnIndex, X_INFO, "Supported blankings:"); - if (r->supported_blanking & CVT_STANDARD) - xf86ErrorF(" standard"); - if (r->supported_blanking & CVT_REDUCED) - xf86ErrorF(" reduced"); - xf86ErrorF("\n"); - xf86DrvMsg(scrnIndex, X_INFO, "Supported scalings:"); - if (r->supported_scaling & SCALING_HSHRINK) - xf86ErrorF(" hshrink"); - if (r->supported_scaling & SCALING_HSTRETCH) - xf86ErrorF(" hstretch"); - if (r->supported_scaling & SCALING_VSHRINK) - xf86ErrorF(" vshrink"); - if (r->supported_scaling & SCALING_VSTRETCH) - xf86ErrorF(" vstretch"); - xf86ErrorF("\n"); - if (r->preferred_refresh) - xf86DrvMsg(scrnIndex, X_INFO, "Preferred refresh rate: %d\n", - r->preferred_refresh); - else - xf86DrvMsg(scrnIndex, X_INFO, "Buggy monitor, no preferred " - "refresh rate given\n"); - } - else if (r->max_clock != 0) { - xf86ErrorF(" PixClock max %i MHz\n", r->max_clock); - } - else { - xf86ErrorF("\n"); - } - if (r->gtf_2nd_f > 0) - xf86DrvMsg(scrnIndex, X_INFO, " 2nd GTF parameters: f: %i kHz " - "c: %i m: %i k %i j %i\n", r->gtf_2nd_f, - r->gtf_2nd_c, r->gtf_2nd_m, r->gtf_2nd_k, r->gtf_2nd_j); - break; - } - case DS_STD_TIMINGS: - for (j = 0; j < 5; j++) - xf86DrvMsg(scrnIndex, X_INFO, - "#%i: hsize: %i vsize %i refresh: %i " - "vid: %i\n", p->index, det_mon->section.std_t[j].hsize, - det_mon->section.std_t[j].vsize, - det_mon->section.std_t[j].refresh, - det_mon->section.std_t[j].id); - break; - case DS_WHITE_P: - for (j = 0; j < 2; j++) - if (det_mon->section.wp[j].index != 0) - xf86DrvMsg(scrnIndex, X_INFO, - "White point %i: whiteX: %f, whiteY: %f; gamma: %f\n", - det_mon->section.wp[j].index, - det_mon->section.wp[j].white_x, - det_mon->section.wp[j].white_y, - det_mon->section.wp[j].white_gamma); - break; - case DS_CMD: - xf86DrvMsg(scrnIndex, X_INFO, "Color management data: (not decoded)\n"); - break; - case DS_CVT: - xf86DrvMsg(scrnIndex, X_INFO, "CVT 3-byte-code modes:\n"); - print_cvt_timings(scrnIndex, det_mon->section.cvt); - break; - case DS_EST_III: - xf86DrvMsg(scrnIndex, X_INFO, - "Established timings III: (not decoded)\n"); - break; - case DS_DUMMY: - default: - break; - } - if (det_mon->type >= DS_VENDOR && det_mon->type <= DS_VENDOR_MAX) { - xf86DrvMsg(scrnIndex, X_INFO, - "Unknown vendor-specific block %hx\n", - det_mon->type - DS_VENDOR); - } - - p->index = p->index + 1; -} - -static void -print_number_sections(int scrnIndex, int num) -{ - if (num) - xf86DrvMsg(scrnIndex, X_INFO, "Number of EDID sections to follow: %i\n", - num); -} - -xf86MonPtr -xf86PrintEDID(xf86MonPtr m) -{ - CARD16 i, j, n; - char buf[EDID_WIDTH * 2 + 1]; - struct det_print_parameter p; - - if (!m) - return NULL; - - print_vendor(m->scrnIndex, &m->vendor); - print_version(m->scrnIndex, &m->ver); - print_display(m->scrnIndex, &m->features, &m->ver); - print_established_timings(m->scrnIndex, &m->timings1); - print_std_timings(m->scrnIndex, m->timings2); - p.m = m; - p.index = 0; - p.quirks = xf86DDCDetectQuirks(m->scrnIndex, m, FALSE); - xf86ForEachDetailedBlock(m, handle_detailed_print, &p); - print_number_sections(m->scrnIndex, m->no_sections); - - /* extension block section stuff */ - - xf86DrvMsg(m->scrnIndex, X_INFO, "EDID (in hex):\n"); - - n = 128; - if (m->flags & EDID_COMPLETE_RAWDATA) - n += m->no_sections * 128; - - for (i = 0; i < n; i += j) { - for (j = 0; j < EDID_WIDTH; ++j) { - sprintf(&buf[j * 2], "%02x", m->rawData[i + j]); - } - xf86DrvMsg(m->scrnIndex, X_INFO, "\t%s\n", buf); - } - - return m; -} diff --git a/hw/xfree86/ddc/xf86DDC.h b/hw/xfree86/ddc/xf86DDC.h deleted file mode 100644 index 6eb2f0ba2..000000000 --- a/hw/xfree86/ddc/xf86DDC.h +++ /dev/null @@ -1,101 +0,0 @@ - -/* xf86DDC.h - * - * This file contains all information to interpret a standard EDIC block - * transmitted by a display device via DDC (Display Data Channel). So far - * there is no information to deal with optional EDID blocks. - * DDC is a Trademark of VESA (Video Electronics Standard Association). - * - * Copyright 1998 by Egbert Eich - */ - -#ifndef XF86_DDC_H -#define XF86_DDC_H - -#include "edid.h" -#include "xf86i2c.h" -#include "xf86str.h" - -/* speed up / slow down */ -typedef enum { - DDC_SLOW, - DDC_FAST -} xf86ddcSpeed; - -typedef void (*DDC1SetSpeedProc) (ScrnInfoPtr, xf86ddcSpeed); - -extern _X_EXPORT xf86MonPtr xf86DoEDID_DDC1(ScrnInfoPtr pScrn, - DDC1SetSpeedProc DDC1SetSpeed, - unsigned - int (*DDC1Read) (ScrnInfoPtr) - ); - -extern _X_EXPORT xf86MonPtr xf86DoEDID_DDC2(ScrnInfoPtr pScrn, I2CBusPtr pBus); - -extern _X_EXPORT xf86MonPtr xf86DoEEDID(ScrnInfoPtr pScrn, I2CBusPtr pBus, Bool); - -extern _X_EXPORT xf86MonPtr xf86PrintEDID(xf86MonPtr monPtr); - -extern _X_EXPORT xf86MonPtr xf86InterpretEDID(int screenIndex, Uchar * block); - -extern _X_EXPORT xf86MonPtr xf86InterpretEEDID(int screenIndex, Uchar * block); - -extern _X_EXPORT void - xf86EdidMonitorSet(int scrnIndex, MonPtr Monitor, xf86MonPtr DDC); - -extern _X_EXPORT Bool xf86SetDDCproperties(ScrnInfoPtr pScreen, xf86MonPtr DDC); - -extern _X_EXPORT Bool - xf86MonitorIsHDMI(xf86MonPtr mon); - -extern _X_EXPORT Bool -gtf_supported(xf86MonPtr mon); - -extern _X_EXPORT DisplayModePtr -FindDMTMode(int hsize, int vsize, int refresh, Bool rb); - -extern _X_EXPORT const DisplayModeRec DMTModes[]; - -/* - * Quirks to work around broken EDID data from various monitors. - */ -typedef enum { - DDC_QUIRK_NONE = 0, - /* First detailed mode is bogus, prefer largest mode at 60hz */ - DDC_QUIRK_PREFER_LARGE_60 = 1 << 0, - /* 135MHz clock is too high, drop a bit */ - DDC_QUIRK_135_CLOCK_TOO_HIGH = 1 << 1, - /* Prefer the largest mode at 75 Hz */ - DDC_QUIRK_PREFER_LARGE_75 = 1 << 2, - /* Convert detailed timing's horizontal from units of cm to mm */ - DDC_QUIRK_DETAILED_H_IN_CM = 1 << 3, - /* Convert detailed timing's vertical from units of cm to mm */ - DDC_QUIRK_DETAILED_V_IN_CM = 1 << 4, - /* Detailed timing descriptors have bogus size values, so just take the - * maximum size and use that. - */ - DDC_QUIRK_DETAILED_USE_MAXIMUM_SIZE = 1 << 5, - /* Monitor forgot to set the first detailed is preferred bit. */ - DDC_QUIRK_FIRST_DETAILED_PREFERRED = 1 << 6, - /* use +hsync +vsync for detailed mode */ - DDC_QUIRK_DETAILED_SYNC_PP = 1 << 7, - /* Force single-link DVI bandwidth limit */ - DDC_QUIRK_DVI_SINGLE_LINK = 1 << 8, -} ddc_quirk_t; - -typedef void (*handle_detailed_fn) (struct detailed_monitor_section *, void *); - -void xf86ForEachDetailedBlock(xf86MonPtr mon, handle_detailed_fn, void *data); - -ddc_quirk_t xf86DDCDetectQuirks(int scrnIndex, xf86MonPtr DDC, Bool verbose); - -void xf86DetTimingApplyQuirks(struct detailed_monitor_section *det_mon, - ddc_quirk_t quirks, int hsize, int vsize); - -typedef void (*handle_video_fn) (struct cea_video_block *, void *); - -void xf86ForEachVideoBlock(xf86MonPtr, handle_video_fn, void *); - -struct cea_data_block *xf86MonitorFindHDMIBlock(xf86MonPtr mon); - -#endif diff --git a/hw/xfree86/dixmods/fbmodule.c b/hw/xfree86/dixmods/fbmodule.c deleted file mode 100644 index 5895ba296..000000000 --- a/hw/xfree86/dixmods/fbmodule.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 1998 The XFree86 Project, Inc. All Rights Reserved. - * - * 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 - * XFREE86 PROJECT 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 XFree86 Project 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 - * XFree86 Project. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Module.h" -#include "fb.h" - -static XF86ModuleVersionInfo VersRec = { -#ifdef FB_ACCESS_WRAPPER - "wfb", -#else - "fb", -#endif - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 1, 0, 0, - ABI_CLASS_ANSIC, /* Only need the ansic layer */ - ABI_ANSIC_VERSION, - MOD_CLASS_NONE, - {0, 0, 0, 0} /* signature, to be patched into the file by a tool */ -}; - -_X_EXPORT XF86ModuleData FBPREFIX(ModuleData) = { -&VersRec, NULL, NULL}; diff --git a/hw/xfree86/dixmods/glxmodule.c b/hw/xfree86/dixmods/glxmodule.c deleted file mode 100644 index 2215c8867..000000000 --- a/hw/xfree86/dixmods/glxmodule.c +++ /dev/null @@ -1,85 +0,0 @@ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -All Rights Reserved. - -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, 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 PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Kevin E. Martin - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Module.h" -#include "xf86Priv.h" -#include "xf86.h" -#include "colormap.h" -#include "micmap.h" -#include "globals.h" -#include "glxserver.h" -#include "extinit.h" -#include "glx_extinit.h" - -static MODULESETUPPROTO(glxSetup); - -static XF86ModuleVersionInfo VersRec = { - "glx", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 1, 0, 0, - ABI_CLASS_EXTENSION, - ABI_EXTENSION_VERSION, - MOD_CLASS_NONE, - {0, 0, 0, 0} -}; - -_X_EXPORT XF86ModuleData glxModuleData = { &VersRec, glxSetup, NULL }; - -static void * -glxSetup(void *module, void *opts, int *errmaj, int *errmin) -{ - static Bool setupDone = FALSE; - __GLXprovider *provider; - - if (setupDone) { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } - - setupDone = TRUE; - - provider = LoaderSymbol("__glXDRI2Provider"); - if (provider) - GlxPushProvider(provider); - xorgGlxCreateVendor(); - - return module; -} diff --git a/hw/xfree86/dixmods/meson.build b/hw/xfree86/dixmods/meson.build deleted file mode 100644 index a1afbe8b9..000000000 --- a/hw/xfree86/dixmods/meson.build +++ /dev/null @@ -1,43 +0,0 @@ -shared_module( - 'wfb', - 'fbmodule.c', - - include_directories: [inc, xorg_inc], - c_args: [ xorg_c_args, wfb_args ], - dependencies: common_dep, - link_whole: libxserver_wfb, - link_with: e, - - install: true, - install_dir: module_dir, -) - -shared_module( - 'shadow', - 'shmodule.c', - - include_directories: [inc, xorg_inc], - c_args: xorg_c_args, - dependencies: common_dep, - link_whole: libxserver_miext_shadow, - link_with: e, - - install: true, - install_dir: module_dir, -) - -if build_glx - shared_module( - 'glx', - [ 'glxmodule.c', srcs_glxdri2 ], - - include_directories: [ inc, xorg_inc, glx_inc ], - c_args: [ xorg_c_args, glx_align64 ], - dependencies: [ common_dep, dl_dep, dri_dep ], - link_whole: libxserver_glx, - link_with: e, - - install: true, - install_dir: join_paths(module_dir, 'extensions') - ) -endif diff --git a/hw/xfree86/dixmods/shmodule.c b/hw/xfree86/dixmods/shmodule.c deleted file mode 100644 index 0cbb9df71..000000000 --- a/hw/xfree86/dixmods/shmodule.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright © 2000 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Module.h" -#include -#include "scrnintstr.h" -#include "windowstr.h" -#include -#include "dixfontstr.h" -#include -#include "mi.h" -#include "regionstr.h" -#include "globals.h" -#include "gcstruct.h" -#include "shadow.h" - -static XF86ModuleVersionInfo VersRec = { - "shadow", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 1, 1, 0, - ABI_CLASS_ANSIC, /* Only need the ansic layer */ - ABI_ANSIC_VERSION, - MOD_CLASS_NONE, - {0, 0, 0, 0} /* signature, to be patched into the file by a tool */ -}; - -_X_EXPORT XF86ModuleData shadowModuleData = { &VersRec, NULL, NULL }; diff --git a/hw/xfree86/doc/.gitignore b/hw/xfree86/doc/.gitignore deleted file mode 100644 index 63eee5960..000000000 --- a/hw/xfree86/doc/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -ddxDesign.html -ddxDesign.pdf -ddxDesign.ps -ddxDesign.txt diff --git a/hw/xfree86/doc/README.modes b/hw/xfree86/doc/README.modes deleted file mode 100644 index 54543bf0a..000000000 --- a/hw/xfree86/doc/README.modes +++ /dev/null @@ -1,473 +0,0 @@ - Multi-monitor Mode Setting APIs - Keith Packard, SaveScreen and the core X screen saver will be -implemented by disabling outputs and crtcs using their dpms functions. - - void - xf86DPMSSet(ScrnInfoPtr scrn, int mode, int flags) - -Pass this function to xf86DPMSInit and all DPMS mode switching will be -managed by using the dpms functions provided by the Outputs and CRTCs. - - Bool - xf86CrtcScreenInit (ScreenPtr screen) - -This function completes the screen initialization process for the crtc and -output objects. Call it near the end of the ScreenInit function, after the -frame buffer and acceleration layers have been added. - -3.3 EnterVT functions - -Functions used during EnterVT, or whenever the current configuration needs -to be applied to the hardware. - - Bool - xf86SetDesiredModes (ScrnInfoPtr scrn) - -xf86InitialConfiguration selects the desired configuration at PreInit time; -when the server finally hits ScreenInit, xf86SetDesiredModes is used by the -driver to take that configuration and apply it to the hardware. In addition, -successful mode selection at other times updates the configuration that will -be used by this function, so LeaveVT/EnterVT pairs can simply invoke this -and return to the previous configuration. - -3.4 SwitchMode functions - -Functions called from the pScrn->SwitchMode hook, which is used by the -XFree86-VidModeExtension and the keypad mode switch commands. - - Bool - xf86SetSingleMode (ScrnInfoPtr scrn, - DisplayModePtr desired, - Rotation rotation) - -This function applies the specified mode to all active outputs. Which is to -say, it picks reasonable modes for all active outputs, attempting to get the -screen to the specified size while not breaking anything that is currently -working. - -3.7 get_modes functions - -Functions called during output->get_modes to help build lists of modes - - xf86MonPtr - xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus) - -This returns the EDID data structure for the 'output' using the I2C bus -'pDDCBus'. This has no effect on 'output' itself. - - void - xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon) - -Once the EDID data has been fetched, this call applies the EDID data to the -output object, setting the physical size and also various properties, like -the DDC root window property (when output is the 'compat' output), and the -RandR 1.2 EDID output properties. - - DisplayModePtr - xf86OutputGetEDIDModes (xf86OutputPtr output) - -Given an EDID data structure, this function computes a list of suitable -modes. This function also applies a sequence of 'quirks' during this process -so that the returned modes may not actually match the mode data present in -the EDID data. - -3.6 Other functions - -These remaining functions in the API can be used by the driver as needed. - - Bool - xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, - int x, int y) - -Applies a mode to a CRTC. All of the outputs which are currently using the -specified CRTC are included in the mode setting process. 'x' and 'y' are the -offset within the frame buffer that the crtc is placed at. No checking is -done in this function to ensure that the mode is usable by the active -outputs. - - void - xf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY) - -This discards the mode lists for all outputs, re-detects monitor presence -and then acquires new mode lists for all monitors which are not disconnected. -Monitor configuration data is used to modify the mode lists returned by the -outputs. 'maxX' and 'maxY' limit the maximum size modes that will be -returned. - - void - xf86SetScrnInfoModes (ScrnInfoPtr pScrn) - -This copies the 'compat' output mode list into the pScrn modes list which is -used by the XFree86-VidModeExtension and the keypad mode switching -operations. The current 'desired' mode for the CRTC associated with the -'compat' output is placed first in this list to indicate the current mode. -Usually, the driver won't need to call this function as -xf86InitialConfiguration will do so automatically, as well as any RandR -functions which reprobe for modes. However, if the driver reprobes for modes -at other times using xf86ProbeOutputModes, this function needs to be called. - - Bool - xf86DiDGAReInit (ScreenPtr pScreen) - -This is similar to xf86SetScrnInfoModes, but it applies the 'compat' output -mode list to the set of modes advertised by the DGA extension; it needs to -be called whenever xf86ProbeOutputModes is invoked. - - void - xf86DisableUnusedFunctions(ScrnInfoPtr pScrn) - -After any sequence of calls using xf86CrtcSetMode, this function cleans up -any leftover Output and CRTC objects by disabling them, saving power. It is -safe to call this whenever the server is running as it only disables objects -which are not currently in use. - -4. CRTC operations - -4.1 CRTC functions - -These functions provide an abstract interface for the CRTC object; most -manipulation of the CRTC object is done through these functions. - - void - crtc->funcs->dpms (xf86CrtcPtr crtc, int mode) - -Where 'mode' is one of DPMSModeOff, DPMSModeSuspend, DPMSModeStandby or -DPMSModeOn. This requests that the crtc go to the specified power state. -When changing power states, the output dpms functions are invoked before the -crtc dpms functions. - - void - crtc->funcs->save (xf86CrtcPtr crtc) - - void - crtc->funcs->restore (xf86CrtcPtr crtc) - -Preserve/restore any register contents related to the CRTC. These are -strictly a convenience for the driver writer; if the existing driver has -fully operation save/restore functions, you need not place any additional -code here. In particular, the server itself never uses this function. - - Bool - crtc->funcs->lock (xf86CrtcPtr crtc) - - void - crtc->funcs->unlock (xf86CrtcPtr crtc) - -These functions are invoked around mode setting operations; the intent is -that DRI locking be done here to prevent DRI applications from manipulating -the hardware while the server is busy changing the output configuration. If -the lock function returns FALSE, the unlock function will not be invoked. - - Bool - crtc->funcs->mode_fixup (xf86CrtcPtr crtc, - DisplayModePtr mode, - DisplayModePtr adjusted_mode) - -This call gives the CRTC a chance to see what mode will be set and to -comment on the mode by changing 'adjusted_mode' as needed. This function -shall not modify the state of the crtc hardware at all. If the CRTC cannot -accept this mode, this function may return FALSE. - - void - crtc->funcs->prepare (xf86CrtcPtr crtc) - -This call is made just before the mode is set to make the hardware ready for -the operation. A usual function to perform here is to disable the crtc so -that mode setting can occur with clocks turned off and outputs deactivated. - - void - crtc->funcs->mode_set (xf86CrtcPtr crtc, - DisplayModePtr mode, - DisplayModePtr adjusted_mode) - -This function applies the specified mode (possibly adjusted by the CRTC -and/or Outputs). - - void - crtc->funcs->commit (xf86CrtcPtr crtc) - -Once the mode has been applied to the CRTC and Outputs, this function is -invoked to let the hardware turn things back on. - - void - crtc->funcs->gamma_set (xf86CrtcPtr crtc, CARD16 *red, - CARD16 *green, CARD16 *blue, int size) - -This function adjusts the gamma ramps for the specified crtc. - - void * - crtc->funcs->shadow_allocate (xf86CrtcPtr crtc, int width, int height) - -This function allocates frame buffer space for a shadow frame buffer. When -allocated, the crtc must scan from the shadow instead of the main frame -buffer. This is used for rotation. The address returned is passed to the -shadow_create function. This function should return NULL on failure. - - PixmapPtr - crtc->funcs->shadow_create (xf86CrtcPtr crtc, void *data, - int width, int height) - -This function creates a pixmap object that will be used as a shadow of the -main frame buffer for CRTCs which are rotated or reflected. 'data' is the -value returned by shadow_allocate. - - void - crtc->funcs->shadow_destroy (xf86CrtcPtr crtc, PixmapPtr pPixmap, - void *data) - -Destroys any associated shadow objects. If pPixmap is NULL, then a pixmap -was not created, but 'data' may still be non-NULL indicating that the shadow -had been allocated. - - void - crtc->funcs->destroy (xf86CrtcPtr crtc) - -When a CRTC is destroyed (which only happens in error cases), this function -can clean up any driver-specific data. - -4.2 CRTC fields - -The CRTC object is not opaque; there are several fields of interest to the -driver writer. - - struct _xf86Crtc { - /** - * Associated ScrnInfo - */ - ScrnInfoPtr scrn; - - /** - * Active state of this CRTC - * - * Set when this CRTC is driving one or more outputs - */ - Bool enabled; - - /** Track whether cursor is within CRTC range */ - Bool cursorInRange; - - /** Track state of cursor associated with this CRTC */ - Bool cursorShown; - - /** - * Active mode - * - * This reflects the mode as set in the CRTC currently - * It will be cleared when the VT is not active or - * during server startup - */ - DisplayModeRec mode; - Rotation rotation; - PixmapPtr rotatedPixmap; - void *rotatedData; - - /** - * Position on screen - * - * Locates this CRTC within the frame buffer - */ - int x, y; - - /** - * Desired mode - * - * This is set to the requested mode, independent of - * whether the VT is active. In particular, it receives - * the startup configured mode and saves the active mode - * on VT switch. - */ - DisplayModeRec desiredMode; - Rotation desiredRotation; - int desiredX, desiredY; - - /** crtc-specific functions */ - const xf86CrtcFuncsRec *funcs; - - /** - * Driver private - * - * Holds driver-private information - */ - void *driver_private; - #ifdef RANDR_12_INTERFACE - /** - * RandR crtc - * - * When RandR 1.2 is available, this - * points at the associated crtc object - */ - RRCrtcPtr randr_crtc; - #else - void *randr_crtc; - #endif - }; - - -5. Output functions. - -6. Configuration - -Because the configuration file syntax is fixed, -this was done by creating new "Driver" section options that hook specific -outputs to specific "Monitor" sections in the file. The option: -section of the form: - - Option "monitor-VGA" "My VGA Monitor" - -connects the VGA output of this driver to the "Monitor" section with -Identifier "My VGA Monitor". All of the usual monitor options can now be -placed in that "Monitor" section and will be applied to the VGA output -configuration. diff --git a/hw/xfree86/doc/Registry b/hw/xfree86/doc/Registry deleted file mode 100644 index 9c6b11473..000000000 --- a/hw/xfree86/doc/Registry +++ /dev/null @@ -1,407 +0,0 @@ -This is the XFree86 driver/module registry. To avoid name space clashes and -to maintain some consistency between drivers the important name spaces are -maintained here. - -1. Module Names. - -Each module is required to have a unique name. Registered names are: - -GLcore -acecad -afb -apm -ark -ati -atimisc -bitmap -bt8xx -calcomp -cfb -cfb16 -cfb24 -cfb32 -chips -cirrus -citron -cyrix -dbe -ddc -digitaledge -dmc -dri -drm -dynapro -elo2300 -elographics -extmod -fb -fbdev -fbdevhw -fi12x6 -freetype -glide -glint -glx -hyperpen -i128 -i2c -i740 -i810 -imstt -int10 -joystick -keyboard -layer -magellan -magictouch -mfb -mga -microtouch -mouse -msp34xx -mutouch -neomagic -newport -nv -pcidata -penmount -pex5 -r128 -radeon -rac -ramdac -record -rendition -s3 -s3virge -savage -shadow -shadowfb -siliconmotion -sis -spaceorb -speedo -summa -sunbw2 -suncg14 -suncg3 -suncg6 -sunffb -sunleo -suntcx -tdfx -tga -trident -tseng -type1 -v4l -vbe -vesa -vga -vgahw -vmware -void -wacom -xaa -xf1bpp -xf24_32bpp -xf4bpp -xf8_16bpp -xf8_32bpp -xf8_32wid -xie -xtrap -xtt - -2. External Module Object Symbols. - -Each module is required to use a unique prefix or prefixes for all of -its externally visible symbols. They should be unique without regard to -case. Registered prefixes are: - -ati -bt8xx -cfb -chips -fi12x6 -glide -glint -mfb -mga -msp34xx -neo -permedia -tseng -vga -vgahw -vmware -xaa -xf1bpp -xf4bpp - -3. Chipset Names. - -Each video driver is required to use a unique set of chipset names. Case, -white space and underscore characters are ignored when comparing chipset -names. All names listed here are in lower case with all white space and -underscores removed. Registered chipset names are: - -ati -ativga -ct64200 -ct64300 -ct65520 -ct65525 -ct65530 -ct65535 -ct65540 -ct65545 -ct65546 -ct65548 -ct65550 -ct65554 -ct65555 -ct68554 -ct69000 -et4000 -et4000w32 -et4000w32i -et4000w32p -et6000 -et6100 -generic -ibmvga -ibm8514 -mach32 -mach64 -mach8 -mga2064w -mga1064sg -mga2164w -mga2164wagp -neo2070 -neo2090 -neo2093 -neo2097 -neo2160 -neo2200 -tipm2 -vgawonder -voodoo - -4. Option Names. - -Option names and their usage should be consistent between drivers. -Case, white space and underscore characters are ignored when comparing -option names. The prefix "no" may be added or removed from boolean -option names. All names listed here are in their preferred user-visible -form. Some registered option names are: - -Types are: B = boolean, O = set/unset (no value), I = integer, S = string, - A = optional string, F = floating point number Q = frequency - -Scopes are: F = global flags, V = video driver, C = common (per screen), - I = input drivers, X = XAA, Xv = Xv extension, M = misc. - -Names currently in use: - -Name Type Scope Description ----------------------------------------------------------------------------- -AllowMouseOpenFail B F ignore mouse dev open failure -AllowNonLocalModInDev B F allow non-local mod of input devs -AllowNonLocalXvidtune B F allow non-local VidMode connections -BlankTime I F Screen saver timeout (min) -DisableModInDev B F disallow changing input devs -DisableVidModeExtension B F disable VidMode extension -DontVTSwitch B F disable Ctrl-Alt-Fn -DontZap B F disable Ctrl-Alt-BS sequence -DontZoom B F disable Ctrl-Alt-+/- -OffTime I F Time before DPMS off mode active (min) -PciProbe1 O F use PCI probe algorithm 1 -PciProbe2 O F use PCI probe algorithm 2 -PciForceConfig1 O F force PCI config type 1 -PciForceConfig2 O F force PCI config type 2 -Pixmap I F depth 24 pixmap size (24 or 32) -StandbyTime I F Time before DPMS standby active (min) -SuspendTime I F Time before DPMS suspend mode active (min) - -BackingStore B C Enable backing store -DDC B C Enable/disable DDC -DDC1 B C Enable/disable DDC1 -DDC2 B C Enable/disable DDC2 -DPMS O C Enable DPMS - -BaudRate I I Serial port baud rate -ButtonNumber I I Button number (for touch screen?) -ButtonThreshold I I ?? -ClearDTR O I Clear serial port DTR -ClearRTS O I Clear serial port RTS -DataBits I I Serial port data bits -DemandLoad O I ?? -Device S I Device file name -DeviceName S I Input device name -FlowControl S I Serial flow control ("xon", "none") -Floating B I Device initialised as floating -HistorySize I I ?? -MaxX I I Maximum X coordinate -MaxY I I Maximum Y coordinate -MinX I I Minimum X coordinate -MinY I I Minimum Y coordinate -Parity S I Serial port parity ("odd", "even", "none") -ReportDelay I I ?? -ReportingMode S I may be "raw" or "scaled" -ScreenNumber I I Screen number (for touch screen) -SendCoreEvents B I Send core events -StopBits I I Serial port stop bits -SwapXY B I Swap the X and Y axes -UntouchDelay I I ?? -Vmin I I Tty VMIN -Vtime I I Tty VTIME - - -18BitBus B V ?? -8Plus16 B V Enable depth 8 + depth 16 with overlay -8Plus24 B V Enable depth 8 + depth 24 with overlay -BlockWrite B V Enable/disable block write -ColorKey I V Set the color key for overlay modes -CompositeSync B V Composite sync -CRTDisplay B V Force display on CRT, not LCD -CRTScreen B V Display on CRT, not LCD (Obsolete) -EarlyRasPrecharge O V Early RAS pre-charge -FastDRAM O V Fast DRAM -FifoAggressive O V Aggressive FIFO setting -FifoConservative O V Conservative FIFO setting -FifoModerate O V Moderate FIFO setting -FireGL3000 B V Card is Diamond FireGL3000 -FixPanelSize B V ?? -FPClock8 Q V Flat panel clock for 8bpp fb (MHz) -FPClock16 Q V Flat panel clock for 16bpp fb (MHz) -FPClock24 Q V Flat panel clock for 24bpp fb (MHz) -FPClock32 Q V Flat panel clock for 32bpp fb (MHz) -FPMVRAM O V Fast page mode VRAM -FramebufferWC B V Enable/disable WC for the framebuffer -GlideDevice I V Selects which Voodoo board to use -HiBitHigh O V High clock bit default to set -HiBitLow O V High clock bit default to cleared -HWClocks B V Enable/disable HW clocks -HWCursor B V Enable/disable HW cursor -LateRasPrecharge O V Late RAS pre-charge -Legend O V Card is Legend ET4000 -LCDCenter B V Enable/disable centering for LCD displays -Linear B V Enable/disable linear framebuffer -MCLK Q V Specify the current MCLK value (MHz) -MedDRAM B V Medium speed DRAM -MemCfg1 I V ?? -MemCfg2 I V ?? -MGASDRAM B V Mga card has SDRAM -MMIO B V Enable/disable memory mapped I/O -MMIOCache B V Enable/Disable MMIO cache -MuxThreshold I V Multiplexing threshold (kHz) -NoAccel B V Disable/enable acceleration -NoClockChip B V ?? -NoStretch B V Disable/enable stretching for LCD displays -OnAtExit B V Leave video signal on when exiting server -OverclockMem B V Enable memory overclocking -Overlay A V Enable multi-depth/overlay. An optional - string "M,N" may be specified, where - M, N are the depths. -PanelDisplay B V Force display on LCD -PciBurst B V Enable/disable PCI burst mode -PciRetry B V Enable/disable PCI retries -ProbeClocks B V Force probe for non-programmable clocks -ReferenceClock Q V Clock generator reference frequency -RGBbits I V Number of significant bits per rgb -Rotate S V Rotate the virtual display (CW or CCW) -SetLCDClk Q V Set LCD clock (MHz) -SetMclk Q V Set Memory Clock (MHz) -ShadowFB B V Enable shadow framebuffer layer -ShowCache B V Enable viewing of offscreen memory -ShowOverscan O V Set the overscan area to a visible colour -SlowDRAM O V Slow DRAM -SlowEDODRAM O V Slow EDO DRAM -STN B V STN screen type (??) -SWCursor B V Enable/disable SW cursor -SuspendHack B V ?? -SyncOnGreen B V Enable/disable sync on green -TurboQueue B V Enable/disable turbo queue -UseFBDev B V Use the fbdev driver interface -UseModeLine B V Use Modeline (??) -W32Interleave B V ?? - -Buffers I Xv Number of buffers -Device S Xv Device file name -Expose B Xv Disable occlusion clipping (see DESIGN) -FramesPerSec I Xv Max. refresh frequency - -XAA options. All are of type "O" and scope "X", and are self-explanatory - -XaaNoColor8x8PatternFillRect -XaaNoColor8x8PatternFillTrap -XaaNoCPUToScreenColorExpandFill -XaaNoDashedBresenhamLine -XaaNoDashedTwoPointLine -XaaNoScreenToScreenCopy -XaaNoImageReadRect -XaaNoImageWriteRect -XaaNoMono8x8PatternFillRect -XaaNoMono8x8PatternFillTrap -XaaNoOffscreenPixmaps -XaaNoPixmapCache -XaaNoScanlineCPUToScreenColorExpandFill -XaaNoScanlineImageWriteRect -XaaNoScreenToScreenColorExpandFill -XaaNoSolidBresenhamLine -XaaNoSolidFillRect -XaaNoSolidFillTrap -XaaNoSolidHorVertLine -XaaNoSolidTwoPointLine - - -Names used in previous versions: - -16Clocks -8Clocks -ClkDiv2 -EDO VRAM -ExternDisp -ExtFramBuf -FastVRAM -FavorBitBlt -InternDisp -NoBitBlt -NoFontCache -NoImageBlt -NoMemAccess -NoPciDisconnect -NoPixmapCache -NoProgramClocks -NoSplitXfer -OverrideBIOS -OverrideValidateMode -ProgLcdModeRegs -ProgLcdModeStretch -SlowDRAMrefresh -SlowVRAM -SwapHiBit - - -5. Ramdac Names. - -Ramdac names should be consistent between drivers. Case, white space -and underscore characters are ignored when comparing ramdac names. All -names listed here are in lower case with all white space and underscores -removed. - - -6. Clock Chip Names. - -Clock chip names should be consistent between drivers. Case, white -space and underscore characters are ignored when comparing clock chip -names. All names listed here are in lower case with all white space -and underscores removed. - - - - - -$XFree86: xc/programs/Xserver/hw/xfree86/Registry,v 1.18 2002/04/06 18:31:09 tsi Exp $ diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml deleted file mode 100644 index 1eed293fe..000000000 --- a/hw/xfree86/doc/ddxDesign.xml +++ /dev/null @@ -1,8692 +0,0 @@ - - %xorg-defs; - %defs; - - - Device"> - Monitor"> - Display"> - InputDevice"> - Screen"> - ServerLayout"> - Driver"> - Module"> - Identifier"> - ServerFlags"> -] > - -
- - - XFree86 DDX Design - - - The XFree86 Project - The X.Org Foundation - - - JimGettys - Updates for X11R6.7 - - - - &xserver.reldate; - X Version 11, Release &fullrelvers; - X Server Version &xserver.version; - - - - -This document describes software undergoing continual evolution, and -the interfaces described here are subject to change without notice. -This document is intended to cover the interfaces as found in the -xorg-server-&xserver.version; release, but is probably not completely -in sync with the code base. - - - - - Preface - - -This document was originally the design spec for the DDX layer of the -XFree86 4.0 X server. The X.Org Foundation adopted the XFree86 4.4rc2 -version of that server as the basis of the Xorg server project, and has -evolved the XFree86 DDX layer greatly since forking. This document thus -covers only the current implementation of the XFree86 DDX as found in the -Xorg server &xserver.version; release, and no longer matches the XFree86 -server itself. - - - -The XFree86 Project's broad design principles for XFree86 4.0 were: - - keep it reasonable - - We cannot rewrite the complete server - - We don't want to re-invent the wheel - - - keep it modular - - As many things as possible should go into modules - - The basic loader binary should be minimal - - A clean design with well defined layering is - important - DDX specific global variables are a nono - - The structure should be flexible enough to allow - future extensions - The structure should minimize duplication of - common code - - keep important features in mind - - multiple screens, including multiple instances - of drivers - mixing different color depths and visuals on - different and ideally even on the same screen - - better control of the PCI device used - - better config file parser - get rid of all VGA compatibility assumptions - - - - - - -While the XFree86 project had a goal of avoiding changes to the DIX -layer unless they found major deficiencies there, to avoid divergence from -the X.Org sample implementation they were integrating changes from, the -X.Org developers now maintain both sides, and make changes where they are -most appropriate. This document concentrates on the XFree86 DDX layer used -in the Xorg server itself (the code found in hw/xfree86 -in the source tree), and developers will also want to refer to the -Xserver-spec documentation that covers the DIX layer -routines common to all the X servers in the sample implementation. - - - - - The xorg.conf File - - -The xorg.conf file format is based on the XF86Config format from XFree86 4.4, -which is in turn similar to the old XFree86 3.x XF86Config format, with the -following changes: - - - - &k.device; section - - - The &k.device; sections are similar to what they used to be, and - describe hardware-specific information for a single video card. - &k.device; - Some new keywords are added: - - - - Driver "drivername" - - Specifies the name of the driver to be used for the card. This - is mandatory. - - BusID "busslot" - - Specifies uniquely the location of the card on the bus. The - purpose is to identify particular cards in a multi-headed - configuration. The format of the argument is intentionally - vague, and may be architecture dependent. For a PCI bus, it - is something like "bus@domain:slot:func". The "@domain" part - can be left out for domain 0. - - - - - - A &k.device; section is considered active if there is a reference - to it in an active &k.screen; section. - - - - - &k.screen; section - - - The &k.screen; sections are similar to what they used to be. They - no longer have a &k.driver; keyword, but an &k.identifier; keyword - is added. (The &k.driver; keyword may be accepted in place of the - &k.identifier; keyword for compatibility purposes.) The identifier - can be used to identify which screen is to be active when multiple - &k.screen; sections are present. It is possible to specify the active - screen from the command line. A default is chosen in the absence - of one being specified. A &k.screen; section is considered active - if there is a reference to it either from the command line, or from - an active &k.serverlayout; section. - - - - - &k.inputdevice; section - - - The &k.inputdevice; section is a new section that describes - configuration information for input devices. It replaces the old - Keyboard, Pointer and XInput - sections. Like the &k.device; section, it has two mandatory keywords: - &k.identifier; and &k.driver;. For compatibility purposes the old - Keyboard and Pointer sections are - converted by the parser into &k.inputdevice; sections as follows: - - - Keyboard - - &k.identifier; "Implicit Core Keyboard" - &k.driver; "kbd" - - Pointer - - &k.identifier; "Implicit Core Pointer" - &k.driver; "mouse" - - - - - - An &k.inputdevice; section is considered active if there is a - reference to it in an active &k.serverlayout; section. An - &k.inputdevice; section may also be referenced implicitly if there - is no &k.serverlayout; section, if the command - line options is used, or if the &k.serverlayout; section doesn't - reference any &k.inputdevice; sections. In this case, the first - sections with drivers "kbd" and "mouse" are used as the core - keyboard and pointer respectively. - - - - - &k.serverlayout; section - - - The &k.serverlayout; section is a new section that is used to identify - which &k.screen; sections are to be used in a multi-headed configuration, - and the relative layout of those screens. It also identifies which - &k.inputdevice; sections are to be used. Each &k.serverlayout; section - has an identifier, a list of &k.screen; section identifiers, and a list of - &k.inputdevice; section identifiers. &k.serverflags; options may also be - included in a &k.serverlayout; section, making it possible to override - the global values in the &k.serverflags; section. - - - - A &k.serverlayout; section can be made active by being referenced on - the command line. In the absence of this, a default will be chosen - (the first one found). The screen names may optionally be followed - by a number specifying the preferred screen number, and optionally - by information specifying the physical positioning of the screen, - either in absolute terms or relative to another screen (or screens). - When no screen number is specified, they are numbered according to - the order in which they are listed. The old (now obsolete) method - of providing the positioning information is to give the names of - the four adjacent screens. The order of these is top, bottom, left, - right. Here is an example of a &k.serverlayout; section for two - screens using the old method, with the second located to the right - of the first: - - - Section "ServerLayout" - Identifier "Main Layout" - Screen 0 "Screen 1" "" "" "" "Screen 2" - Screen 1 "Screen 2" - Screen "Screen 3" - EndSection - - - - - The preferred way of specifying the layout is to explicitly specify - the screen's location in absolute terms or relative to another - screen. - - - - In the absolute case, the upper left corner's coordinates are given - after the Absolute keyword. If the coordinates are - omitted, a value of (0,0) is assumed. An example - of absolute positioning follows: - - - Section "ServerLayout" - Identifier "Main Layout" - Screen 0 "Screen 1" Absolute 0 0 - Screen 1 "Screen 2" Absolute 1024 0 - Screen "Screen 3" Absolute 2048 0 - EndSection - - - - - In the relative case, the position is specified by either using one of - the following keywords followed by the name of the reference screen: - - - RightOf - LeftOf - Above - Below - Relative - - - - - When the Relative keyword is used, the reference screen - name is followed by the coordinates of the new screen's origin - relative to reference screen. The following example shows how to use - some of the relative positioning options. - - - Section "ServerLayout" - Identifier "Main Layout" - Screen 0 "Screen 1" - Screen 1 "Screen 2" RightOf "Screen 1" - Screen "Screen 3" Relative "Screen 1" 2048 0 - EndSection - - - - - - Options - - - Options are used more extensively. They may appear in most sections - now. Options related to drivers can be present in the &k.screen;, - &k.device; and &k.monitor; sections and the &k.display; subsections. - The order of precedence is &k.display;, &k.screen;, &k.monitor;, - &k.device;. Options have been extended to allow an optional value - to be specified in addition to the option name. For more details - about options, see the Options section - for details. - - - - - - Driver Interface - - -The driver interface consists of a minimal set of entry points that are -required based on the external events that the driver must react to. -No non-essential structure is imposed on the way they are used beyond -that. This is a significant difference compared with the old design. - - - -The entry points for drawing operations are already taken care of by -the framebuffer code. Extensions and enhancements to framebuffer code -are outside the scope of this document. - - - -This approach to the driver interface provides good flexibility, but does -increase the complexity of drivers. To help address this, the XFree86 -common layer provides a set of helper functions to take care of things -that most drivers need. These helpers help minimise the amount of code -duplication between drivers. The use of helper functions by drivers is -however optional, though encouraged. The basic philosophy behind the -helper functions is that they should be useful to many drivers, that -they should balance this against the complexity of their interface. It -is inevitable that some drivers may find some helpers unsuitable and -need to provide their own code. - - - -Events that a driver needs to react to are: - - - ScreenInit - - - An initialisation function is called from the DIX layer for each - screen at the start of each server generation. - - - Enter VT - - - The server takes control of the console. - - - Leave VT - - - The server releases control of the console. - - - Mode Switch - - - Change video mode. - - - ViewPort change - - - Change the origin of the physical view port. - - - ScreenSaver state change - - - Screen saver activation/deactivation. - - - CloseScreen - - - A close screen function is called from the DIX layer for each screen - at the end of each server generation. - - - - - - -In addition to these events, the following functions are required by -the XFree86 common layer: - - - Identify - - - Print a driver identifying message. - - - Probe - - - This is how a driver identifies if there is any hardware present that - it knows how to drive. - - - PreInit - - - Process information from the xorg.conf file, determine the - full characteristics of the hardware, and determine if a valid - configuration is present. - - - - - -The VidMode extension also requires: - - - ValidMode - - - Identify if a new mode is usable with the current configuration. - The PreInit function (and/or helpers it calls) may also make use - of the ValidMode function or something similar. - - - - - - -Other extensions may require other entry points. The drivers will -inform the common layer of these in such cases. - - - - - Resource Access Control Introduction - - -Graphics devices are accessed through ranges in I/O or memory space. -While most modern graphics devices allow relocation of such ranges many -of them still require the use of well established interfaces such as -VGA memory and IO ranges or 8514/A IO ranges. With modern buses (like -PCI) it is possible for multiple video devices to share access to these -resources. The RAC (Resource Access Control) subsystem provides a -mechanism for this. - - - - Terms and Definitions - - - Bus - - - Bus is ambiguous as it is used for different things: it may refer - to physical incompatible extension connectors in a computer system. - The RAC system knows two such systems: The ISA bus and the PCI bus. - (On the software level EISA, MCA and VL buses are currently treated - like ISA buses). Bus may also refer to logically different - entities on a single bus system which are connected via bridges. A - PCI system may have several distinct PCI buses connecting each other - by PCI-PCI bridges or to the host CPU by HOST-PCI bridges. - - - - Systems that host more than one bus system link these together using - bridges. Bridges are a concern to RAC as they might block or pass - specific resources. PCI-PCI bridges may be set up to pass VGA - resources to the secondary bus. PCI-ISA buses pass any resources not - decoded on the primary PCI bus to the ISA bus. This way VGA resources - (although exclusive on the ISA bus) can be shared by ISA and PCI - cards. Currently HOST-PCI bridges are not yet handled by RAC as they - require specific drivers. - - - - - Entity - - - The smallest independently addressable unit on a system bus is - referred to as an entity. So far we know ISA and PCI entities. PCI - entities can be located on the PCI bus by an unique ID consisting of - the bus, card and function number. - - - - - Resource - - - Resource refers to a range of memory or I/O addresses an entity - can decode. - - - - If a device is capable of disabling this decoding the resource is - called shareable. For PCI devices a generic method is provided to - control resource decoding. Other devices will have to provide a - device specific function to control decoding. - - - - If the entity is capable of decoding this range at a different - location this resource is considered relocatable. - - - - Resources which start at a specific address and occupy a single - continuous range are called block resources. - - - - Alternatively resource addresses can be decoded in a way that they - satisfy the conditions: - - address & mask == base - - and - - base & mask == base - - Resources addressed in such a way are called sparse resources. - - - - - - Server States - - - The resource access control system knows two server states: the - SETUP and the OPERATING state. The SETUP state is entered whenever - a mode change takes place or the server exits or does VT switching. - During this state all entity resources are under resource access - control. During OPERATING state only those entities are controlled - which actually have shared resources that conflict with others. - - - - - - - Control Flow in the Server and Mandatory Driver Functions - - -At the start of each server generation, main() -(dix/main.c) calls the DDX function -InitOutput(). This is the first place that the DDX gets -control. InitOutput() is expected to fill in the global -screenInfo struct, and one -screenInfo.screen[] entry for each screen present. -Here is what InitOutput() does: - - - - Parse the xorg.conf file - - - This is done at the start of the first server generation only. - - - - The xorg.conf file is read in full, and the resulting information - stored in data structures. None of the parsed information is - processed at this point. The parser data structures are opaque to - the video drivers and to most of the common layer code. - - - - The entire file is parsed first to remove any section ordering - requirements. - - - - - - Initial processing of parsed information and command line options - - - - This is done at the start of the first server generation only. - - - - The initial processing is to determine paths like the - ModulePath, etc, and to determine which &k.serverlayout;, - &k.screen; and &k.device; sections are active. - - - - - - Enable port I/O access - - - Port I/O access is controlled from the XFree86 common layer, and is - all or nothing. It is enabled prior to calling driver probes, at - the start of subsequent server generations, and when VT switching - back to the Xserver. It is disabled at the end of server generations, - and when VT switching away from the Xserver. - - - - The implementation details of this may vary on different platforms. - - - - - - General bus probe - - - This is done at the start of the first server generation only. - - - - In the case of ix86 machines, this will be a general PCI probe. - The full information obtained here will be available to the drivers. - This information persists for the life of the Xserver. In the PCI - case, the PCI information for all video cards found is available by - calling xf86GetPciVideoInfo(). - - -
- - pciVideoPtr *xf86GetPciVideoInfo(void); - -
- returns a pointer to a list of pointers to - pciVideoRec entries, of which there is one for - each detected PCI video card. The list is terminated with a - NULL pointer. If no PCI video cards were - detected, the return value is NULL. - -
-
- - - After the bus probe, the resource broker is initialised. - -
- - - - Load initial set of modules - - - This is done at the start of the first server generation only. - - - - The next set of modules loaded are those specified explicitly in the - &k.module; section of the config file. - - - - The final set of initial modules are the driver modules referenced - by the active &k.device; and &k.inputdevice; sections in the config - file. Each of these modules is loaded exactly once. - - - - - - Register Video and Input Drivers - - - This is done at the start of the first server generation only. - - - - When a driver module is loaded, the loader calls its - Setup function. For video drivers, this function - calls xf86AddDriver() to register the driver's - DriverRec, which contains a small set of essential - details and driver entry points required during the early phase of - InitOutput(). xf86AddDriver() - adds it to the global xf86DriverList[] array. - - - - The DriverRec contains the driver canonical name, - the Identify(), - Probe() and AvailableOptions() - function entry points as well as a pointer - to the driver's module (as returned from the loader when the driver - was loaded) and a reference count which keeps track of how many - screens are using the driver. The entry driver entry points are - those required prior to the driver allocating and filling in its - ScrnInfoRec. - - - - For a static server, the xf86DriverList[] array is - initialised at build time, and the loading of modules is not done. - - - - A similar procedure is used for input drivers. The input driver's - Setup function calls - xf86AddInputDriver() to register the driver's - InputDriverRec, which contains a small set of - essential details and driver entry points required during the early - phase of InitInput(). - xf86AddInputDriver() adds it to the global - xf86InputDriverList[] array. For a static server, - the xf86InputDriverList[] array is initialised at - build time. - - - - Both the xf86DriverList[] and - xf86InputDriverList[] arrays have been initialised - by the end of this stage. - - - - Once all the drivers are registered, their - ChipIdentify() functions are called. - - -
- - void ChipIdentify(int flags); - -
- This is expected to print a message indicating the driver name, - a short summary of what it supports, and a list of the chipset - names that it supports. It may use the xf86PrintChipsets() helper - to do this. -
-
- -
- - void xf86PrintChipsets(const char *drvname, const char *drvmsg, - SymTabPtr chips); - -
- This function provides an easy way for a driver's ChipIdentify - function to format the identification message. -
-
-
- - - Initialise Access Control - - - This is done at the start of the first server generation only. - - - - The Resource Access Control (RAC) subsystem is initialised before - calling any driver functions that may access hardware. All generic - bus information is probed and saved (for restoration later). All - (shared resource) video devices are disabled at the generic bus - level, and a probe is done to find the primary video device. These - devices remain disabled for the next step. - - - - - - Video Driver Probe - - - This is done at the start of the first server generation only. The - ChipProbe() function of each registered video driver - is called. - - -
- - Bool ChipProbe(DriverPtr drv, int flags); - -
- The purpose of this is to identify all instances of hardware - supported by the driver. The flags value is currently either 0, - PROBE_DEFAULT or PROBE_DETECT. - PROBE_DETECT is used if "-configure" or "-probe" - command line arguments are given and indicates to the - Probe() function that it should not configure the - bus entities and that no xorg.conf information is available. - - - - The probe must find the active device sections that match the - driver by calling xf86MatchDevice(). The number - of matches found limits the maximum number of instances for this - driver. If no matches are found, the function should return - FALSE immediately. - - - - Devices that cannot be identified by using device-independent - methods should be probed at this stage (keeping in mind that access - to all resources that can be disabled in a device-independent way - are disabled during this phase). The probe must be a minimal - probe. It should just determine if there is a card present that - the driver can drive. It should use the least intrusive probe - methods possible. It must not do anything that is not essential, - like probing for other details such as the amount of memory - installed, etc. It is recommended that the - xf86MatchPciInstances() helper function be used - for identifying matching PCI devices - (see the RAC section). These helpers also - checks and claims the appropriate entity. When not using the - helper, that should be done with xf86CheckPciSlot() - and xf86ClaimPciSlot() for PCI devices (see the - RAC section). - - - - The probe must register all non-relocatable resources at this - stage. If a resource conflict is found between exclusive resources - the driver will fail immediately. This is usually best done with - the xf86ConfigPciEntity() helper function - for PCI. - - - - If a chipset is specified in an active device section which the - driver considers relevant (ie it has no driver specified, or the - driver specified matches the driver doing the probe), the Probe - must return FALSE if the chipset doesn't match - one supported by the driver. - - - - If there are no active device sections that the driver considers - relevant, it must return FALSE. - - - - Allocate a ScrnInfoRec for each active instance of the - hardware found, and fill in the basic information, including the - other driver entry points. This is best done with the - xf86ConfigPciEntity() for PCI instances. - These functions allocate a ScrnInfoRec for active - entities. Optionally xf86AllocateScreen() - function may also be used to allocate the ScrnInfoRec. - Any of these functions take care of initialising fields to defined - unused values. - - - - Claim the entities for each instance of the hardware found. This - prevents other drivers from claiming the same hardware. - - - - Must leave hardware in the same state it found it in, and must not - do any hardware initialisation. - - - - All detection can be overridden via the config file, and that - parsed information is available to the driver at this stage. - - - - Returns TRUE if one or more instances are found, - and FALSE otherwise. - - -
- -
- - int xf86MatchDevice(const char *drivername, - GDevPtr **driversectlist) - -
- This function takes the name of the driver and returns via - driversectlist a list of device sections that - match the driver name. The function return value is the number - of matches found. If a fatal error is encountered the return - value is -1. - - - - The caller should use xfree() to free - *driversectlist when it is no longer needed. - - -
- -
- - ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags) - -
- This function allocates a new ScrnInfoRec in the - xf86Screens[] array. This function is normally - called by the video driver ChipProbe() functions. - The return value is a pointer to the newly allocated - ScrnInfoRec. The scrnIndex, - origIndex, module and - drv fields are initialised. The reference count - in drv is incremented. The storage for any - currently allocated privates pointers is also allocated and - the privates field initialised (the privates data - is of course not allocated or initialised). This function never - returns on failure. If the allocation fails, the server exits - with a fatal error. The flags value is not currently used, and - should be set to zero. -
-
- - - At the completion of this, a list of ScrnInfoRecs - have been allocated in the xf86Screens[] array, and - the associated entities and fixed resources have been claimed. The - following ScrnInfoRec fields must be initialised at - this point: - - - driverVersion - driverName - scrnIndex(*) - origIndex(*) - drv(*) - module(*) - name - Probe - PreInit - ScreenInit - EnterVT - LeaveVT - numEntities - entityList - access - - - (*) These are initialised when the ScrnInfoRec - is allocated, and not explicitly by the driver. - - - - The following ScrnInfoRec fields must be initialised - if the driver is going to use them: - - - SwitchMode - AdjustFrame - FreeScreen - ValidMode - - -
- - - Matching Screens - - - This is done at the start of the first server generation only. - - - - After the Probe phase is finished, there will be some number of - ScrnInfoRecs. These are then matched with the active - &k.screen; sections in the xorg.conf, and those not having an active - &k.screen; section are deleted. If the number of remaining screens - is 0, InitOutput() sets - screenInfo.numScreens to 0 and - returns. - - - - At this point the following fields of the ScrnInfoRecs - must be initialised: - - - confScreen - - - - - - - Allocate non-conflicting resources - - - This is done at the start of the first server generation only. - - - - Before calling the drivers again, the resource information collected - from the Probe phase is processed. This includes checking the extent - of PCI resources for the probed devices, and resolving any conflicts - in the relocatable PCI resources. It also reports conflicts, checks - bus routing issues, and anything else that is needed to enable the - entities for the next phase. - - - - If any drivers registered an EntityInit() function - during the Probe phase, then they are called here. - - - - - - Sort the Screens and pre-check Monitor Information - - - This is done at the start of the first server generation only. - - - - The list of screens is sorted to match the ordering requested in the - config file. - - - - The list of modes for each active monitor is checked against the - monitor's parameters. Invalid modes are pruned. - - - - - - PreInit - - - This is done at the start of the first server generation only. - - - - For each ScrnInfoRec, enable access to the screens entities and call - the ChipPreInit() function. - - -
- - Bool ChipPreInit(ScrnInfoRec screen, int flags); - -
- The purpose of this function is to find out all the information - required to determine if the configuration is usable, and to - initialise those parts of the ScrnInfoRec that - can be set once at the beginning of the first server generation. - - - - The number of entities registered for the screen should be checked - against the expected number (most drivers expect only one). The - entity information for each of them should be retrieved (with - xf86GetEntityInfo()) and checked for the correct - bus type and that none of the shareable resources registered during - the Probe phase was rejected. - - - - Access to resources for the entities that can be controlled in a - device-independent way are enabled before this function is called. - If the driver needs to access any resources that it has disabled - in an EntityInit() function that it registered, - then it may enable them here providing that it disables them before - this function returns. - - - - This includes probing for video memory, clocks, ramdac, and all - other HW info that is needed. It includes determining the - depth/bpp/visual and related info. It includes validating and - determining the set of video modes that will be used (and anything - that is required to determine that). - - - - This information should be determined in the least intrusive way - possible. The state of the HW must remain unchanged by this - function. Although video memory (including MMIO) may be mapped - within this function, it must be unmapped before returning. Driver - specific information should be stored in a structure hooked into - the ScrnInfoRec's driverPrivate - field. Any other modules which require persistent data (ie data - that persists across server generations) should be initialised in - this function, and they should allocate a privates index to - hook their data into by calling - xf86AllocateScrnInfoPrivateIndex(). The privates - data is persistent. - - - - Helper functions for some of these things are provided at the - XFree86 common level, and the driver can choose to make use of - them. - - - - Modules may be loaded at any point in this function, and all - modules that the driver will need must be loaded before the end - of this function. Either the xf86LoadSubModule() - or the xf86LoadDrvSubModule() function should be - used to load modules depending on whether a - ScrnInfoRec has been set up. A driver may unload - a module within this function if it was only needed temporarily, - and the xf86UnloadSubModule() function should be used - to do that. Otherwise there is no need to explicitly unload modules - because the loader takes care of module dependencies and will - unload submodules automatically if/when the driver module is - unloaded. - - - - The bulk of the ScrnInfoRec fields should be filled - out in this function. - - - - ChipPreInit() returns FALSE when - the configuration is unusable in some way (unsupported depth, no - valid modes, not enough video memory, etc), and TRUE - if it is usable. - - - - It is expected that if the ChipPreInit() function - returns TRUE, then the only reasons that subsequent - stages in the driver might fail are lack or resources (like xalloc - failures). All other possible reasons for failure should be - determined by the ChipPreInit() function. -
-
- - - The ScrnInfoRecs for screens where the ChipPreInit() fails are removed. - If none remain, InitOutput() sets screenInfo.numScreens to 0 and returns. - - - - At this point, further fields of the ScrnInfoRecs would normally be - filled in. Most are not strictly mandatory, but many are required - by other layers and/or helper functions that the driver may choose - to use. The documentation for those layers and helper functions - indicates which they require. - - - - The following fields of the ScrnInfoRecs should be filled in if the - driver is going to use them: - - - monitor - display - depth - pixmapBPP - bitsPerPixel - weight (>8bpp only) - mask (>8bpp only) - offset (>8bpp only) - rgbBits (8bpp only) - gamma - defaultVisual - virtualX - virtualY - displayWidth - frameX0 - frameY0 - frameX1 - frameY1 - zoomLocked - modePool - modes - currentMode - progClock (TRUE if clock is programmable) - chipset - ramdac - clockchip - numClocks (if not programmable) - clock[] (if not programmable) - videoRam - memBase - driverPrivate - chipID - chipRev - - - -
- - pointer xf86LoadSubModule(ScrnInfoPtr pScrn, const char *name); - and - pointer xf86LoadDrvSubModule(DriverPtr drv, const char *name); - -
- Load a module that a driver depends on. This function loads the - module name as a sub module of the driver. The - return value is a handle identifying the new module. If the load - fails, the return value will be NULL. If a driver - needs to explicitly unload a module it has loaded in this way, - the return value must be saved and passed to - xf86UnloadSubModule() when unloading. - -
-
- -
- - void xf86UnloadSubModule(pointer module); - -
- Unloads the module referenced by module. - module should be a pointer returned previously - by xf86LoadSubModule() or - xf86LoadDrvSubModule() . - -
-
-
- - - Cleaning up Unused Drivers - - - At this point it is known which screens will be in use, and which - drivers are being used. Unreferenced drivers (and modules they - may have loaded) are unloaded here. - - - - - - Consistency Checks - - - The parameters that must be global to the server, like pixmap formats, - bitmap bit order, bitmap scanline unit and image byte order are - compared for each of the screens. If a mismatch is found, the server - exits with an appropriate message. - - - - - - Check if Resource Control is Needed - - - Determine if resource access control is needed. This is the case - if more than one screen is used. If necessary the RAC wrapper module - is loaded. - - - - - AddScreen (ScreenInit) - - - At this point, the valid screens are known. - AddScreen() is called for each of them, passing - ChipScreenInit() as the argument. - AddScreen() is a DIX function that allocates a new - screenInfo.screen[] entry (aka - pScreen), and does some basic initialisation of it. - It then calls the ChipScreenInit() function, with - pScreen as one of its arguments. If - ChipScreenInit() returns FALSE, - AddScreen() returns -1. Otherwise - it returns the index of the screen. AddScreen() - should only fail because of programming errors or failure to allocate - resources (like memory). All configuration problems should be - detected BEFORE this point. - - -
- - Bool ChipScreenInit(ScreenPtr pScreen, - int argc, char **argv); - -
- This is called at the start of each server generation. - - - - Fill in all of pScreen, possibly doing some of - this by calling ScreenInit functions from other layers like mi, - framebuffers (cfb, etc), and extensions. - - - - Decide which operations need to be placed under resource access - control. The classes of operations are the frame buffer operations - (RAC_FB), the pointer operations - (RAC_CURSOR), the viewport change operations - (RAC_VIEWPORT) and the colormap operations - (RAC_COLORMAP). Any operation that requires - resources which might be disabled during OPERATING state should - be set to use RAC. This can be specified separately for memory - and IO resources (the racMemFlags and - racIoFlags fields of the ScrnInfoRec - respectively). - - - - Map any video memory or other memory regions. - - - - Save the video card state. Enough state must be saved so that - the original state can later be restored. - - - - Initialise the initial video mode. The ScrnInfoRec's - vtSema field should be set to TRUE - just prior to changing the video hardware's state. - -
-
- - - - The ChipScreenInit() function (or functions from other - layers that it calls) should allocate entries in the - ScreenRec's devPrivates area by - calling AllocateScreenPrivateIndex() if it needs - per-generation storage. Since the ScreenRec's - devPrivates information is cleared for each server - generation, this is the correct place to initialise it. - - - - After AddScreen() has successfully returned, the - following ScrnInfoRec fields are initialised: - - - pScreen - racMemFlags - racIoFlags - - - - - The ChipScreenInit() function should initialise the - CloseScreen and SaveScreen fields - of pScreen. The old value of - pScreen->CloseScreen should be saved as part of - the driver's per-screen private data, allowing it to be called from - ChipCloseScreen(). This means that the existing - CloseScreen() function is wrapped. - -
- - - Finalising RAC Initialisation - - - After all the ChipScreenInit() functions have been - called, each screen has registered its RAC requirements. This - information is used to determine which shared resources are requested - by more than one driver and set the access functions accordingly. - This is done following these rules: - - - - The shareable resources registered by each entity are compared. - If a resource is registered by more than one entity the entity - will be marked to indicate that it needs to share this resources - type (IO or MEM). - - - - A resource marked disabled during OPERATING state will be - ignored entirely. - - - - A resource marked unused will only conflict with an overlapping - resource of an other entity if the second is actually in use - during OPERATING state. - - - - If an unused resource was found to conflict but the entity - does not use any other resource of this type the entire resource - type will be disabled for that entity. - - - - - - - - Finishing InitOutput() - - - At this point InitOutput() is finished, and all the - screens have been setup in their initial video mode. - - - - - - Mode Switching - - - When a SwitchMode event is received, ChipSwitchMode() - is called (when it exists): - - -
- - Bool ChipSwitchMode(int index, DisplayModePtr mode); - -
- Initialises the new mode for the screen identified by - index;. The viewport may need to be adjusted - also. - -
-
- -
- - - Changing Viewport - - - When a Change Viewport event is received, - ChipAdjustFrame() is called (when it exists): - - -
- - void ChipAdjustFrame(int index, int x, int y); - -
- Changes the viewport for the screen identified by - index;. - - - - It should be noted that many chipsets impose restrictions on where the - viewport may be placed in the virtual resolution, either for alignment - reasons, or to prevent the start of the viewport from being positioned - within a pixel (as can happen in a 24bpp mode). After calculating the - value the chipset's panning registers need to be set to for non-DGA - modes, this function should recalculate the ScrnInfoRec's - frameX0, frameY0, frameX1 - and frameY1 fields to correspond to that value. If - this is not done, switching to another mode might cause the position - of a hardware cursor to change. - -
-
- -
- - - VT Switching - - - When a VT switch event is received, xf86VTSwitch() - is called. xf86VTSwitch() does the following: - - - On ENTER: - - - - enable port I/O access - - - - save and initialise the bus/resource state - - - - enter the SETUP server state - - - - calls ChipEnterVT() for each screen - - - - enter the OPERATING server state - - - - validate GCs - - - - Restore fb from saved pixmap for each screen - - - - Enable all input devices - - - - - - On LEAVE: - - - - Save fb to pixmap for each screen - - - - validate GCs - - - - enter the SETUP server state - - - - calls ChipLeaveVT() for each screen - - - - disable all input devices - - - - restore bus/resource state - - - - disables port I/O access - - - - - - - -
- - Bool ChipEnterVT(ScrnInfoPtr pScrn); - -
- This function should initialise the current video mode and - initialise the viewport, turn on the HW cursor if appropriate, - etc. - - - - Should it re-save the video state before initialising the video - mode? - - -
- -
- - void ChipLeaveVT(ScrnInfoPtr pScrn); - -
- This function should restore the saved video state. If - appropriate it should also turn off the HW cursor, and invalidate - any pixmap/font caches. - - -
- - - Optionally, ChipLeaveVT() may also unmap memory - regions. If so, ChipEnterVT() will need to remap - them. Additionally, if an aperture used to access video memory is - unmapped and remapped in this fashion, ChipEnterVT() - will also need to notify the framebuffer layers of the aperture's new - location in virtual memory. This is done with a call to the screen's - ModifyPixmapHeader() function, as follows - - -
- - (*pScreen->ModifyPixmapHeader)(pScrn->ppix, - -1, -1, -1, -1, -1, NewApertureAddress); - -
- where the ppix field in a ScrnInfoRec - points to the pixmap used by the screen's - SaveRestoreImage() function to hold the screen's - contents while switched out. - - -
- - - Other layers may wrap the ChipEnterVT() and - ChipLeaveVT() functions if they need to take some - action when these events are received. - -
- - - End of server generation - - - At the end of each server generation, the DIX layer calls - ChipCloseScreen() for each screen: - - -
- - Bool ChipCloseScreen(int index, ScreenPtr pScreen); - -
- This function should restore the saved video state and unmap the - memory regions. - - - - It should also free per-screen data structures allocated by the - driver. Note that the persistent data held in the - ScrnInfoRec's driverPrivate field - should not be freed here because it is needed by subsequent server - generations. - - - - The ScrnInfoRec's vtSema field - should be set to FALSE once the video HW state - has been restored. - - - - Before freeing the per-screen driver data the saved - CloseScreen value should be restored to - pScreen->CloseScreen, and that function should - be called after freeing the data. - -
-
-
-
- - - Optional Driver Functions - - -The functions outlined here can be called from the XFree86 common layer, -but their presence is optional. - - - - Mode Validation - - - When a mode validation helper supplied by the XFree86-common layer is - being used, it can be useful to provide a function to check for hw - specific mode constraints: - - -
- - ModeStatus ChipValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, - Bool verbose, int flags); - -
- Check the passed mode for hw-specific constraints, and return the - appropriate status value. - -
-
- - -This function may also modify the effective timings and clock of the passed -mode. These have been stored in the mode's Crtc* and -SynthClock elements, and have already been adjusted for -interlacing, doublescanning, multiscanning and clock multipliers and dividers. -The function should not modify any other mode field, unless it wants to modify -the mode timings reported to the user by xf86PrintModes(). - - - -The function is called once for every mode in the xorg.conf Monitor section -assigned to the screen, with flags set to -MODECHECK_INITIAL. It is subsequently called for every mode -in the xorg.conf Display subsection assigned to the screen, with -flags set to MODECHECK_FINAL. In the second -case, the mode will have successfully passed all other tests. In addition, -the ScrnInfoRec's virtualX, -virtualY and displayWidth fields will have been -set as if the mode to be validated were to be the last mode accepted. - - - -In effect, calls with MODECHECK_INITIAL are intended for checks that do not -depend on any mode other than the one being validated, while calls with -MODECHECK_FINAL are intended for checks that may involve more than one mode. - -
- - - Free screen data - - - When a screen is deleted prior to the completion of the ScreenInit - phase the ChipFreeScreen() function is called when defined. - - -
- - void ChipFreeScreen(ScrnInfoPtr pScrn); - -
- Free any driver-allocated data that may have been allocated up to - and including an unsuccessful ChipScreenInit() - call. This would predominantly be data allocated by - ChipPreInit() that persists across server - generations. It would include the driverPrivate, - and any privates entries that modules may have allocated. - -
-
- -
-
- - - Recommended driver functions - - -The functions outlined here are for internal use by the driver only. -They are entirely optional, and are never accessed directly from higher -layers. The sample function declarations shown here are just examples. -The interface (if any) used is up to the driver. - - - - Save - - - Save the video state. This could be called from ChipScreenInit() and - (possibly) ChipEnterVT(). - - -
- - void ChipSave(ScrnInfoPtr pScrn); - -
- Saves the current state. This will only be saving pre-server - states or states before returning to the server. There is only - one current saved state per screen and it is stored in private - storage in the screen. - -
-
-
- - - Restore - - - Restore the original video state. This could be called from the - ChipLeaveVT() and ChipCloseScreen() - functions. - - -
- - void ChipRestore(ScrnInfoPtr pScrn); - -
- Restores the saved state from the private storage. Usually only - used for restoring text modes. - -
-
- -
- - - Initialise Mode - - - Initialise a video mode. This could be called from the - ChipScreenInit(), ChipSwitchMode() - and ChipEnterVT() functions. - - -
- - Bool ChipModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode); - -
- Programs the hardware for the given video mode. - -
-
- -
-
- - - Data and Data Structures - - - Command line data - - -Command line options are typically global, and are stored in global -variables. These variables are read-only and are available to drivers -via a function call interface. Most of these command line values are -processed via helper functions to ensure that they are treated consistently -by all drivers. The other means of access is provided for cases where -the supplied helper functions might not be appropriate. - - - -Some of them are: - - - xf86Verbose verbosity level - xf86Bpp -bpp from the command line - xf86Depth -depth from the command line - xf86Weight -weight from the command line - xf86Gamma -{r,g,b,}gamma from the command line - xf86ProbeOnly -probeonly from the command line - defaultColorVisualClass -cc from the command line - - - - -If we ever do allow for screen-specific command line options, we may -need to rethink this. - - - -These can be accessed in a read-only manner by drivers with the following -functions: - - -
- - int xf86GetVerbosity(); - -
- Returns the value of xf86Verbose. -
- -
- -
- - int xf86GetDepth(); - -
- Returns the command line setting. If not - set on the command line, -1 is returned. -
- -
- -
- - rgb xf86GetWeight(); - -
- Returns the command line setting. If not - set on the command line, {0, 0, 0} is returned. -
- -
- -
- - Gamma xf86GetGamma(); - -
- Returns the or , - , command line settings. - If not set on the command line, {0.0, 0.0, 0.0} - is returned. -
- -
- -
- - - Data handling - - -Config file data contains parts that are global, and parts that are -Screen specific. All of it is parsed into data structures that neither -the drivers or most other parts of the server need to know about. - - - -The global data is typically not required by drivers, and as such, most -of it is stored in the private xf86InfoRec. - - - -The screen-specific data collected from the config file is stored in -screen, device, display, monitor-specific data structures that are separate -from the ScrnInfoRecs, with the appropriate elements/fields -hooked into the ScrnInfoRecs as required. The screen -config data is held in confScreenRec, device data in -the GDevRec, monitor data in the MonRec, -and display data in the DispRec. - - - -The XFree86 common layer's screen specific data (the actual data in use -for each screen) is held in the ScrnInfoRecs. As has -been outlined above, the ScrnInfoRecs are allocated at probe -time, and it is the responsibility of the Drivers' Probe() -and PreInit() functions to finish filling them in based -on both data provided on the command line and data provided from the -Config file. The precedence for this is: - -
- command line -> config file -> probed/default data -
-
- - -For most things in this category there are helper functions that the -drivers can use to ensure that the above precedence is consistently -used. - - - -As well as containing screen-specific data that the XFree86 common layer -(including essential parts of the server infrastructure as well as helper -functions) needs to access, it also contains some data that drivers use -internally. When considering whether to add a new field to the -ScrnInfoRec, consider the balance between the convenience -of things that lots of drivers need and the size/obscurity of the -ScrnInfoRec. - - - -Per-screen driver specific data that cannot be accommodated with the -static ScrnInfoRec fields is held in a driver-defined -data structure, a pointer to which is assigned to the -ScrnInfoRec's driverPrivate field. This -is per-screen data that persists across server generations (as does the -bulk of the static ScrnInfoRec data). It would typically -also include the video card's saved state. - - - -Per-screen data for other modules that the driver uses that is reset for each -server generation is hooked into the ScrnInfoRec -through its privates field. - - - -Once it has stabilised, the data structures and variables accessible to -video drivers will be documented here. In the meantime, those things -defined in the xf86.h and xf86str.h -files are visible to video drivers. Things defined in -xf86Priv.h and xf86Privstr.h are NOT -intended to be visible to video drivers, and it is an error for a driver -to include those files. - - -
- - - Accessing global data - - -Some other global state information that the drivers may access via -functions is as follows: - - -
- - Bool xf86ServerIsExiting(); - -
- Returns TRUE if the server is at the end of a - generation and is in the process of exiting, and - FALSE otherwise. -
- -
- -
- - Bool xf86ServerIsResetting(); - -
- Returns TRUE if the server is at the end of a - generation and is in the process of resetting, and - FALSE otherwise. -
- -
- -
- - Bool xf86ServerIsOnlyProbing(); - -
- Returns TRUE if the -probeonly command line flag - was specified, and FALSE otherwise. -
- -
- -
- - - Allocating private data - - -A driver and any module it uses may allocate per-screen private storage -in either the ScreenRec (DIX level) or -ScrnInfoRec (XFree86 common layer level). -ScreenRec storage persists only for a single server -generation, and ScrnInfoRec storage persists across -generations for the lifetime of the server. - - - -The ScreenRec devPrivates data must be -reallocated/initialised at the start of each new generation. This is -normally done from the ChipScreenInit() function, and -Init functions for other modules that it calls. Data allocated in this -way should be freed by the driver's ChipCloseScreen() -functions, and Close functions for other modules that it calls. A new -devPrivates entry is allocated by calling the -AllocateScreenPrivateIndex() function. - - -
- - int AllocateScreenPrivateIndex(); - -
- This function allocates a new element in the - devPrivates field of all currently existing - ScreenRecs. The return value is the index of this - new element in the devPrivates array. The - devPrivates field is of type - DevUnion: - - - typedef union _DevUnion { - pointer ptr; - long val; - unsigned long uval; - pointer (*fptr)(void); - } DevUnion; - - - which allows the element to be used for any of the above types. - It is commonly used as a pointer to data that the caller allocates - after the new index has been allocated. - - - - This function will return -1 when there is an - error allocating the new index. - - -
-
- - -The ScrnInfoRec privates data persists -for the life of the server, so only needs to be allocated once. This -should be done from the ChipPreInit() function, and Init -functions for other modules that it calls. Data allocated in this way -should be freed by the driver's ChipFreeScreen() functions, -and Free functions for other modules that it calls. A new -privates entry is allocated by calling the -xf86AllocateScrnInfoPrivateIndex() function. - - -
- - int xf86AllocateScrnInfoPrivateIndex(); - -
- This function allocates a new element in the privates - field of all currently existing ScrnInfoRecs. - The return value is the index of this new element in the - privates array. The privates - field is of type DevUnion: - - - typedef union _DevUnion { - pointer ptr; - long val; - unsigned long uval; - pointer (*fptr)(void); - } DevUnion; - - - which allows the element to be used for any of the above types. - It is commonly used as a pointer to data that the caller allocates - after the new index has been allocated. - - - - This function will not return when there is an error allocating - the new index. When there is an error it will cause the server - to exit with a fatal error. The similar function for allocation - privates in the ScreenRec - (AllocateScreenPrivateIndex()) differs in this - respect by returning -1 when the allocation fails. - - -
-
-
-
- - - Keeping Track of Bus Resources - - - Theory of Operation - - -The XFree86 common layer has knowledge of generic access control mechanisms -for devices on certain bus systems (currently the PCI bus) as well as -of methods to enable or disable access to the buses itself. Furthermore -it can access information on resources decoded by these devices and if -necessary modify it. - - - -When first starting the Xserver collects all this information, saves it -for restoration, checks it for consistency, and if necessary, corrects -it. Finally it disables all resources on a generic level prior to -calling any driver function. - - - -When the Probe() function of each driver is called the -device sections are matched against the devices found in the system. -The driver may probe devices at this stage that cannot be identified by -using device independent methods. Access to all resources that can be -controlled in a device independent way is disabled. The -Probe() function should register all non-relocatable -resources at this stage. If a resource conflict is found between -exclusive resources the driver will fail immediately. Optionally the -driver might specify an EntityInit(), -EntityLeave() and EntityEnter() function. - - - -EntityInit() can be used to disable any shared resources -that are not controlled by the generic access control functions. It is -called prior to the PreInit phase regardless if an entity is active or -not. When calling the EntityInit(), -EntityEnter() and EntityLeave() functions -the common level will disable access to all other entities on a generic -level. Since the common level has no knowledge of device specific -methods to disable access to resources it cannot be guaranteed that -certain resources are not decoded by any other entity until the -EntityInit() or EntityEnter() phase is -finished. Device drivers should therefore register all those resources -which they are going to disable. If these resources are never to be -used by any driver function they may be flagged ResInit -so that they can be removed from the resource list after processing all -EntityInit() functions. EntityEnter() -should disable decoding of all resources which are not registered as -exclusive and which are not handled by the generic access control in -the common level. The difference to EntityInit() is -that the latter one is only called once during lifetime of the server. -It can therefore be used to set up variables prior to disabling resources. -EntityLeave() should restore the original state when -exiting the server or switching to a different VT. It also needs to -disable device specific access functions if they need to be disabled on -server exit or VT switch. The default state is to enable them before -giving up the VT. - - - -In PreInit() phase each driver should check if any -shareable resources it has registered during Probe() has -been denied and take appropriate action which could simply be to fail. -If it needs to access resources it has disabled during -EntitySetup() it can do so provided it has registered -these and will disable them before returning from -PreInit(). This also applies to all other driver -functions. Several functions are provided to request resource ranges, -register these, correct PCI config space and add replacements for the -generic access functions. Resources may be marked disabled or -unused during OPERATING stage. Although these steps could also be -performed in ScreenInit(), this is not desirable. - - - -Following PreInit() phase the common level determines -if resource access control is needed. This is the case if more than -one screen is used. If necessary the RAC wrapper module is loaded. In -ScreenInit() the drivers can decide which operations -need to be placed under RAC. Available are the frame buffer operations, -the pointer operations and the colormap operations. Any operation that -requires resources which might be disabled during OPERATING state should -be set to use RAC. This can be specified separately for memory and IO -resources. - - - -When ScreenInit() phase is done the common level will -determine which shared resources are requested by more than one driver -and set the access functions accordingly. This is done following these -rules: - - - - The shareable resources registered by each entity are compared. If - a resource is registered by more than one entity the entity will be - marked to need to share this resources type (IO or - MEM). - - - - A resource marked disabled during OPERATING state will be ignored - entirely. - - - - A resource marked unused will only conflicts with an overlapping - resource of an other entity if the second is actually in use during - OPERATING state. - - - - If an unused resource was found to conflict however the entity - does not use any other resource of this type the entire resource type - will be disabled for that entity. - - - - - -The driver has the choice among different ways to control access to -certain resources: - - - - It can rely on the generic access functions. This is probably the - most common case. Here the driver only needs to register any resource - it is going to use. - - - - It can replace the generic access functions by driver specific - ones. This will mostly be used in cases where no generic access - functions are available. In this case the driver has to make sure - these resources are disabled when entering the PreInit() - stage. Since the replacement functions are registered in - PreInit() the driver will have to enable these - resources itself if it needs to access them during this state. The - driver can specify if the replacement functions can control memory - and/or I/O resources separately. - - - - The driver can enable resources itself when it needs them. Each - driver function enabling them needs to disable them before it will - return. This should be used if a resource which can be controlled - in a device dependent way is only required during SETUP state. This - way it can be marked unused during OPERATING state. - - - - - -A resource which is decoded during OPERATING state however never accessed -by the driver should be marked unused. - - - -Since access switching latencies are an issue during Xserver operation, -the common level attempts to minimize the number of entities that need -to be placed under RAC control. When a wrapped operation is called, -the EnableAccess() function is called before control is -passed on. EnableAccess() checks if a screen is under -access control. If not it just establishes bus routing and returns. -If the screen needs to be under access control, -EnableAccess() determines which resource types -(MEM, IO) are required. Then it tests -if this access is already established. If so it simply returns. If -not it disables the currently established access, fixes bus routing and -enables access to all entities registered for this screen. - - - -Whenever a mode switch or a VT-switch is performed the common level will -return to SETUP state. - - - - - Resource Types - - -Resource have certain properties. When registering resources each range -is accompanied by a flag consisting of the ORed flags of the different -properties the resource has. Each resource range may be classified -according to - - - - its physical properties i.e., if it addresses - memory (ResMem) or - I/O space (ResIo), - - - if it addresses a - block (ResBlock) or - sparse (ResSparse) - range, - - - its access properties. - - - - - -There are two known access properties: - - - - ResExclusive - for resources which may not be shared with any other device and - - - ResShared - for resources which can be disabled and therefore can be shared. - - - - - -If it is necessary to test a resource against any type a generic access -type ResAny is provided. If this is set the resource -will conflict with any resource of a different entity intersecting its -range. Further it can be specified that a resource is decoded however -never used during any stage (ResUnused) or during -OPERATING state (ResUnusedOpr). A resource only visible -during the init functions (ie. EntityInit(), -EntityEnter() and EntityLeave() should -be registered with the flag ResInit. A resource that -might conflict with background resource ranges may be flagged with -ResBios. This might be useful when registering resources -ranges that were assigned by the system Bios. - - - -Several predefined resource lists are available for VGA and 8514/A -resources in common/xf86Resources.h. - - - - - Available Functions - - -The functions provided for resource management are listed in their order -of use in the driver. - - - - Probe Phase - - -In this phase each driver detects those resources it is able to drive, -creates an entity record for each of them, registers non-relocatable -resources and allocates screens and adds the resources to screens. - - - -Two helper functions are provided for matching device sections in the -xorg.conf file to the devices: - - -
- - int xf86MatchPciInstances(const char *driverName, int vendorID, - SymTabPtr chipsets, PciChipsets *PCIchipsets, - GDevPtr *devList, int numDevs, DriverPtr drvp, - int **foundEntities); - -
- This function finds matches between PCI cards that a driver supports - and config file device sections. It is intended for use in the - ChipProbe() function of drivers for PCI cards. - Only probed PCI devices with a vendor ID matching - vendorID are considered. devList - and numDevs are typically those found from - calling xf86MatchDevice(), and represent the active - config file device sections relevant to the driver. - PCIchipsets is a table that provides a mapping - between the PCI device IDs, the driver's internal chipset tokens - and a list of fixed resources. - - - - When a device section doesn't have a BusID entry it - can only match the primary video device. Secondary devices are - only matched with device sections that have a matching - BusID entry. - - - - Once the preliminary matches have been found, a final match is - confirmed by checking if the chipset override, ChipID override or - probed PCI chipset type match one of those given in the - chipsets and PCIchipsets lists. - The PCIchipsets list includes a list of the PCI - device IDs supported by the driver. The list should be terminated - with an entry with PCI ID -1". The - chipsets list is a table mapping the driver's - internal chipset tokens to names, and should be terminated with - a NULL entry. Only those entries with a - corresponding entry in the PCIchipsets list are - considered. The order of precedence is: config file chipset, - config file ChipID, probed PCI device ID. - - - - In cases where a driver handles PCI chipsets with more than one - vendor ID, it may set vendorID to - 0, and OR each devID in the list with (the - vendor ID << 16). - - - - Entity index numbers for confirmed matches are returned as an - array via foundEntities. The PCI information, - chipset token and device section for each match are found in the - EntityInfoRec referenced by the indices. - - - - The function return value is the number of confirmed matches. A - return value of -1 indicates an internal error. - The returned foundEntities array should be freed - by the driver with xfree() when it is no longer - needed in cases where the return value is greater than zero. - - -
- - -These two helper functions make use of several core functions that are -available at the driver level: - - -
- - Bool xf86ParsePciBusString(const char *busID, int *bus, - int *device, int *func); - -
- Takes a BusID string, and if it is in the correct - format, returns the PCI bus, device, - func values that it indicates. The format of the - string is expected to be "PCI:bus:device:func" where each of bus, - device and func are decimal integers. The ":func" part may - be omitted, and the func value assumed to be zero, but this isn't - encouraged. The "PCI" prefix may also be omitted. The prefix - "AGP" is currently equivalent to the "PCI" prefix. If the string - isn't a valid PCI BusID, the return value is FALSE. - - -
- -
- - Bool xf86ComparePciBusString(const char *busID, int bus, - int device, int func); - -
- Compares a BusID string with PCI bus, - device, func values. If they - match TRUE is returned, and FALSE - if they don't. - - -
- -
- - Bool xf86CheckPciSlot(int bus, int device, int func); - -
- Checks if the PCI slot bus:device:func has been - claimed. If so, it returns FALSE, and otherwise - TRUE. - - -
- -
- - int xf86ClaimPciSlot(int bus, int device, int func, DriverPtr drvp, - int chipset, GDevPtr dev, Bool active); - -
- This function is used to claim a PCI slot, allocate the associated - entity record and initialise their data structures. The return - value is the index of the newly allocated entity record, or - -1 if the claim fails. This function should always - succeed if xf86CheckPciSlot() returned - TRUE for the same PCI slot. - - -
- -
- - Bool xf86IsPrimaryPci(void); - -
- This function returns TRUE if the primary card is - a PCI device, and FALSE otherwise. - - -
- - -Two helper functions are provided to aid configuring entities: - - -
- - ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn, - int scrnFlag, int entityIndex, - PciChipsets *p_chip, - void *res, EntityProc init, - EntityProc enter, EntityProc leave, - pointer private); - - -
- This functions is used to register the entity. The res, init, enter, and leave arguments are unused, and should be NULL. - For active entities a ScrnInfoRec is allocated - if the pScrn argument is NULL. -The - return value is TRUE when successful. - - -
- - -These two helper functions make use of several core functions that are -available at the driver level: - -
- - void xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex); - -
- This function associates the entity referenced by - entityIndex with the screen. - - -
-
-
- - - PreInit Phase - - -During this phase the remaining resources should be registered. -PreInit() should call xf86GetEntityInfo() -to obtain a pointer to an EntityInfoRec for each entity -it is able to drive and check if any resource are listed in its -resources field. If resources registered in the Probe -phase have been rejected in the post-Probe phase -(resources is non-NULL), then the driver should -decide if it can continue without using these or if it should fail. - - -
- - EntityInfoPtr xf86GetEntityInfo(int entityIndex); - -
- This function returns a pointer to the EntityInfoRec - referenced by entityIndex. The returned - EntityInfoRec should be freed with - xfree() when no longer needed. - - -
- - -Several functions are provided to simplify resource registration: -
- - Bool xf86IsEntityPrimary(int entityIndex); - -
- This function returns TRUE if the entity referenced - by entityIndex is the primary display device (i.e., - the one initialised at boot time and used in text mode). - - -
- -
- - Bool xf86IsScreenPrimary(ScrnInfoPtr pScrn); - -
- This function returns TRUE if the primary entity - is registered with the screen referenced by - pScrn. - - -
- -
- - pciVideoPtr xf86GetPciInfoForEntity(int entityIndex); - -
- This function returns a pointer to the pciVideoRec - for the specified entity. If the entity is not a PCI device, - NULL is returned. - - -
-
- - -Two functions are provided to obtain a resource range of a given type: -
- - resRange xf86GetBlock(long type, memType size, - memType window_start, memType window_end, - memType align_mask, resPtr avoid); - -
- This function tries to find a block range of size - size and type type in a window - bound by window_start and window_end - with the alignment specified in align_mask. - Optionally a list of resource ranges which should be avoided within - the window can be supplied. On failure a zero-length range of - type ResEnd will be returned. - -
- -
- - resRange xf86GetSparse(long type, memType fixed_bits, - memType decode_mask, memType address_mask, - resPtr avoid); - -
- This function is like the previous one, but attempts to find a - sparse range instead of a block range. Here three values have to - be specified: the address_mask which marks all - bits of the mask part of the address, the decode_mask - which masks out the bits which are hardcoded and are therefore - not available for relocation and the values of the fixed bits. - The function tries to find a base that satisfies the given condition. - If the function fails it will return a zero range of type - ResEnd. Optionally it might be passed a list of - resource ranges to avoid. - - -
-
- - -
- - Bool xf86CheckPciMemBase(pciVideoPtr pPci, memType base); - -
- This function checks that the memory base address specified matches - one of the PCI base address register values for the given PCI - device. This is mostly used to check that an externally provided - base address (e.g., from a config file) matches an actual value - allocated to a device. - - -
-
- - -The following two functions are provided for special cases: -
- - void xf86RemoveEntityFromScreen(ScrnInfoPtr pScrn, int entityIndex); - -
- This function may be used to remove an entity from a screen. This - only makes sense if a screen has more than one entity assigned or - the screen is to be deleted. No test is made if the screen has - any entities left. - - -
-
- -
- - - ScreenInit Phase - - -All that is required in this phase is to setup the RAC flags. Note that -it is also permissible to set these flags up in the PreInit phase. The -RAC flags are held in the racIoFlags and racMemFlags fields of the -ScrnInfoRec for each screen. They specify which graphics operations -might require the use of shared resources. This can be specified -separately for memory and I/O resources. The available flags are defined -in rac/xf86RAC.h. They are: - - - RAC_FB - - for framebuffer operations (including hw acceleration) - - RAC_CURSOR - - for Cursor operations - (??? I'm not sure if we need this for SW cursor it depends - on which level the sw cursor is drawn) - - RAC_COLORMAP - - for colormap operations - - RAC_VIEWPORT - - for the call to ChipAdjustFrame() - - - - -The flags are ORed together. - - -
-
- - - Config file <quote>Option</quote> entries - - -Option entries are permitted in most sections and subsections of the -config file. There are two forms of option entries: - - - Option "option-name" - - A boolean option. - - Option "option-name" "option-value" - - An option with an arbitrary value. - - - - - -The option entries are handled by the parser, and a list of the parsed -options is included with each of the appropriate data structures that -the drivers have access to. The data structures used to hold the option -information are opaque to the driver, and a driver must not access the -option data directly. Instead, the common layer provides a set of -functions that may be used to access, check and manipulate the option -data. - - - -First, the low level option handling functions. In most cases drivers -would not need to use these directly. - - -
- - XF86OptionPtr xf86FindOption(XF86OptionPtr options, const char *name); - -
- Takes a list of options and an option name, and returns a handle - for the first option entry in the list matching the name. Returns - NULL if no match is found. - - -
- -
- - const char *xf86FindOptionValue(XF86OptionPtr options, const char *name); - -
- Takes a list of options and an option name, and returns the value - associated with the first option entry in the list matching the - name. If the matching option has no value, an empty string - ("") is returned. Returns NULL - if no match is found. - - -
- -
- - void xf86MarkOptionUsed(XF86OptionPtr option); - -
- Takes a handle for an option, and marks that option as used. - - -
- -
- - void xf86MarkOptionUsedByName(XF86OptionPtr options, const char *name); - -
- Takes a list of options and an option name and marks the first - option entry in the list matching the name as used. - - -
- - -Next, the higher level functions that most drivers would use. - -
- - void xf86CollectOptions(ScrnInfoPtr pScrn, XF86OptionPtr extraOpts); - -
- Collect the options from each of the config file sections used by - the screen (pScrn) and return the merged list as - pScrn->options. This function requires that - pScrn->confScreen, pScrn->display, - pScrn->monitor, - pScrn->numEntities, and - pScrn->entityList are initialised. - extraOpts may optionally be set to an additional - list of options to be combined with the others. The order of - precedence for options is extraOpts, display, - confScreen, monitor, device. - - -
- -
- - void xf86ProcessOptions(int scrnIndex, XF86OptionPtr options, - OptionInfoPtr optinfo); - -
- Processes a list of options according to the information in the - array of OptionInfoRecs (optinfo). - The resulting information is stored in the value - fields of the appropriate optinfo entries. The - found fields are set to TRUE - when an option with a value of the correct type if found, and - FALSE otherwise. The type field - is used to determine the expected value type for each option. - Each option in the list of options for which there is a name match - (but not necessarily a value type match) is marked as used. - Warning messages are printed when option values don't match the - types specified in the optinfo data. - - - - NOTE: If this function is called before a driver's screen number - is known (e.g., from the ChipProbe() function) a - scrnIndex value of -1 should be - used. - - - - NOTE 2: Given that this function stores into the - OptionInfoRecs pointed to by optinfo, - the caller should ensure the OptionInfoRecs are - (re-)initialised before the call, especially if the caller expects - to use the predefined option values as defaults. - - - - The OptionInfoRec is defined as follows: - - - typedef struct { - double freq; - int units; - } OptFrequency; - - typedef union { - unsigned long num; - char * str; - double realnum; - Bool bool; - OptFrequency freq; - } ValueUnion; - - typedef enum { - OPTV_NONE = 0, - OPTV_INTEGER, - OPTV_STRING, /* a non-empty string */ - OPTV_ANYSTR, /* Any string, including an empty one */ - OPTV_REAL, - OPTV_BOOLEAN, - OPTV_PERCENT, - OPTV_FREQ - } OptionValueType; - - typedef enum { - OPTUNITS_HZ = 1, - OPTUNITS_KHZ, - OPTUNITS_MHZ - } OptFreqUnits; - - typedef struct { - int token; - const char* name; - OptionValueType type; - ValueUnion value; - Bool found; - } OptionInfoRec, *OptionInfoPtr; - - - - OPTV_FREQ can be used for options values that are - frequencies. These values are a floating point number with an - optional unit name appended. The unit name can be one of "Hz", - "kHz", "k", "MHz", "M". The multiplier associated with the unit - is stored in freq.units, and the scaled frequency - is stored in freq.freq. When no unit is specified, - freq.units is set to 0, and - freq.freq is unscaled. - - - - OPTV_PERCENT can be used for option values that are - specified in percent (e.g. "20%"). These values are a floating point - number with a percent sign appended. If the percent sign is missing, - the parser will fail to match the value. - - - - Typical usage is to setup an array of - OptionInfoRecs with all fields initialised. - The value and found fields get - set by xf86ProcessOptions(). For cases where the - value parsing is more complex, the driver should specify - OPTV_STRING, and parse the string itself. An - example of using this option handling is included in the - Sample Driver section. - - -
- -
- - void xf86ShowUnusedOptions(int scrnIndex, XF86OptionPtr options); - -
- Prints out warning messages for each option in the list of options - that isn't marked as used. This is intended to show options that - the driver hasn't recognised. It would normally be called near - the end of the ChipScreenInit() function, but only - when serverGeneration == 1 - -
- -
- - OptionInfoPtr xf86TokenToOptinfo(const OptionInfoRec *table, - int token); - -
- Returns a pointer to the OptionInfoRec in - table with a token field matching - token. Returns NULL if no match - is found. - - -
- -
- - Bool xf86IsOptionSet(const OptionInfoRec *table, int token); - -
- Returns the found field of the - OptionInfoRec in table with a - token field matching token. This - can be used for options of all types. Note that for options of - type OPTV_BOOLEAN, it isn't sufficient to check - this to determine the value of the option. Returns - FALSE if no match is found. - - -
- -
- - char *xf86GetOptValString(const OptionInfoRec *table, int token); - -
- Returns the value.str field of the - OptionInfoRec in table with a - token field matching token. Returns - NULL if no match is found. - - -
- -
- - Bool xf86GetOptValInteger(const OptionInfoRec *table, int token, - - int *value); - -
- Returns via *value the value.num - field of the OptionInfoRec in table - with a token field matching token. - *value is only changed when a match is found so - it can be safely initialised with a default prior to calling this - function. The function return value is as for - xf86IsOptionSet(). - - -
- -
- - Bool xf86GetOptValULong(const OptionInfoRec *table, int token, - unsigned long *value); - -
- Like xf86GetOptValInteger(), except the value is - treated as an unsigned long. - - -
- -
- - Bool xf86GetOptValReal(const OptionInfoRec *table, int token, - double *value); - -
- Like xf86GetOptValInteger(), except that - value.realnum is used. - - -
- -
- - Bool xf86GetOptValFreq(const OptionInfoRec *table, int token, - OptFreqUnits expectedUnits, double *value); - -
- Like xf86GetOptValInteger(), except that the - value.freq data is returned. The frequency value - is scaled to the units indicated by expectedUnits. - The scaling is exact when the units were specified explicitly in - the option's value. Otherwise, the expectedUnits - field is used as a hint when doing the scaling. In this case, - values larger than 1000 are assumed to have be - specified in the next smallest units. For example, if the Option - value is "10000" and expectedUnits is OPTUNITS_MHZ, - the value returned is 10. - - -
- -
- - Bool xf86GetOptValBool(const OptionInfoRec *table, int token, Bool *value); - -
- This function is used to check boolean options - (OPTV_BOOLEAN). If the function return value is - FALSE, it means the option wasn't set. Otherwise - *value is set to the boolean value indicated by - the option's value. No option value is interpreted - as TRUE. Option values meaning TRUE - are "1", "yes", "on", "true", and option values meaning - FALSE are "0", "no", "off", "false". Option names - both with the "no" prefix in their names, and with that prefix - removed are also checked and handled in the obvious way. - *value is not changed when the option isn't present. - It should normally be set to a default value before calling this - function. - - -
- -
- - Bool xf86ReturnOptValBool(const OptionInfoRec *table, int token, Bool def); - -
- This function is used to check boolean options - (OPTV_BOOLEAN). If the option is set, its value - is returned. If the options is not set, the default value specified - by def is returned. The option interpretation is - the same as for xf86GetOptValBool(). - - -
- -
- - int xf86NameCmp(const char *s1, const char *s2); - -
- This function should be used when comparing strings from the config - file with expected values. It works like strcmp(), - but is not case sensitive and space, tab, and _ characters - are ignored in the comparison. The use of this function isn't - restricted to parsing option values. It may be used anywhere - where this functionality required. - - -
-
- - - Modules, Drivers, Include Files and Interface Issues - - -NOTE: this section is incomplete. - - - - - Include files - - -The following include files are typically required by video drivers: - -
- All drivers should include these: - - "xf86.h" - "xf86_OSproc.h" - "xf86_ansic.h" - "xf86Resources.h" - - Wherever inb/outb (and related things) are used the following should be - included: - - "compiler.h" - - Note: in drivers, this must be included after "xf86_ansic.h". - - - - Drivers that need to access the PCI config space need this: - - "xf86Pci.h" - - - - - Drivers that initialise a SW cursor need this: - - "mipointer.h" - - - - - All drivers using the mi colourmap code need this: - - "micmap.h" - - - - - If a driver uses the vgahw module, it needs this: - - "vgaHW.h" - - - - - Drivers supporting VGA or Hercules monochrome screens need: - - "xf1bpp.h" - - - - - Drivers supporting VGA or EGC 16-colour screens need: - - "xf4bpp.h" - - - - - Drivers using cfb need: - - #define PSZ 8 - #include "cfb.h" - #undef PSZ - - - - - Drivers supporting bpp 16, 24 or 32 with cfb need one or more of: - - "cfb16.h" - "cfb24.h" - "cfb32.h" - - - - - If a driver uses the fb manager, it needs this: - - "xf86fbman.h" - - -
-
- - -Non-driver modules should include "xf86_ansic.h" to get the correct -wrapping of ANSI C/libc functions. - - - -All modules must NOT include any system include files, or the following: - - - "xf86Priv.h" - "xf86Privstr.h" - "xf86_OSlib.h" - "Xos.h" - - - - -In addition, "xf86_libc.h" must not be included explicitly. It is -included implicitly by "xf86_ansic.h". - - -
-
- - - Offscreen Memory Manager - - -Management of offscreen video memory may be handled by the XFree86 -framebuffer manager. Once the offscreen memory manager is running, -drivers or extensions may allocate, free or resize areas of offscreen -video memory using the following functions (definitions taken from -xf86fbman.h): - - - typedef struct _FBArea { - ScreenPtr pScreen; - BoxRec box; - int granularity; - void (*MoveAreaCallback)(struct _FBArea*, struct _FBArea*) - void (*RemoveAreaCallback)(struct _FBArea*) - DevUnion devPrivate; - } FBArea, *FBAreaPtr; - - typedef void (*MoveAreaCallbackProcPtr)(FBAreaPtr from, FBAreaPtr to) - typedef void (*RemoveAreaCallbackProcPtr)(FBAreaPtr) - - FBAreaPtr xf86AllocateOffscreenArea ( - ScreenPtr pScreen, - int width, int height, - int granularity, - MoveAreaCallbackProcPtr MoveAreaCallback, - RemoveAreaCallbackProcPtr RemoveAreaCallback, - pointer privData - ) - - void xf86FreeOffscreenArea (FBAreaPtr area) - - Bool xf86ResizeOffscreenArea ( - FBAreaPtr area - int w, int h - ) - - - - -The function: - - Bool xf86FBManagerRunning(ScreenPtr pScreen); - - -can be used by an extension to check if the driver has initialized -the memory manager. The manager is not available if this returns -FALSE and the functions above will all fail. - - - - -xf86AllocateOffscreenArea() can be used to request a -rectangle of dimensions width × height -(in pixels) from unused offscreen memory. granularity -specifies that the leftmost edge of the rectangle must lie on some -multiple of granularity pixels. A granularity of zero -means the same thing as a granularity of one - no alignment preference. -A MoveAreaCallback can be provided to notify the requester -when the offscreen area is moved. If no MoveAreaCallback -is supplied then the area is considered to be immovable. The -privData field will be stored in the manager's internal -structure for that allocated area and will be returned to the requester -in the FBArea passed via the -MoveAreaCallback. An optional -RemoveAreaCallback is provided. If the driver provides -this it indicates that the area should be allocated with a lower priority. -Such an area may be removed when a higher priority request (one that -doesn't have a RemoveAreaCallback) is made. When this -function is called, the driver will have an opportunity to do whatever -cleanup it needs to do to deal with the loss of the area, but it must -finish its cleanup before the function exits since the offscreen memory -manager will free the area immediately after. - - - -xf86AllocateOffscreenArea() returns NULL -if it was unable to allocate the requested area. When no longer needed, -areas should be freed with xf86FreeOffscreenArea(). - - - -xf86ResizeOffscreenArea() resizes an existing -FBArea. xf86ResizeOffscreenArea() -returns TRUE if the resize was successful. If -xf86ResizeOffscreenArea() returns FALSE, -the original FBArea is left unmodified. Resizing an -area maintains the area's original granularity, -devPrivate, and MoveAreaCallback. -xf86ResizeOffscreenArea() has considerably less overhead -than freeing the old area then reallocating the new size, so it should -be used whenever possible. - - - -The function: - - Bool xf86QueryLargestOffscreenArea( - ScreenPtr pScreen, - int *width, int *height, - int granularity, - int preferences, - int priority - ); - - -is provided to query the width and height of the largest single -FBArea allocatable given a particular priority. -preferences can be one of the following to indicate -whether width, height or area should be considered when determining -which is the largest single FBArea available. - - - FAVOR_AREA_THEN_WIDTH - FAVOR_AREA_THEN_HEIGHT - FAVOR_WIDTH_THEN_AREA - FAVOR_HEIGHT_THEN_AREA - - - - -priority is one of the following: - -
- - PRIORITY_LOW -
- Return the largest block available without stealing anyone else's - space. This corresponds to the priority of allocating a - FBArea when a RemoveAreaCallback - is provided. -
-
- - - PRIORITY_NORMAL -
- Return the largest block available if it is acceptable to steal a - lower priority area from someone. This corresponds to the priority - of allocating a FBArea without providing a - RemoveAreaCallback. -
-
- - - PRIORITY_EXTREME -
- Return the largest block available if all FBAreas - that aren't locked down were expunged from memory first. This - corresponds to any allocation made directly after a call to - xf86PurgeUnlockedOffscreenAreas(). -
-
- -
-
- - - -The function: - - - Bool xf86PurgeUnlockedOffscreenAreas(ScreenPtr pScreen); - - -is provided as an extreme method to free up offscreen memory. This -will remove all removable FBArea allocations. - - - - -Initialization of the XFree86 framebuffer manager is done via - - - Bool xf86InitFBManager(ScreenPtr pScreen, BoxPtr FullBox); - - -FullBox represents the area of the framebuffer that the -manager is allowed to manage. This is typically a box with a width of -pScrn->displayWidth and a height of as many lines as -can be fit within the total video memory, however, the driver can reserve -areas at the extremities by passing a smaller area to the manager. - -
- - - Colormap Handling - - -A generic colormap handling layer is provided within the XFree86 common -layer. This layer takes care of most of the details, and only requires -a function from the driver that loads the hardware palette when required. -To use the colormap layer, a driver calls the -xf86HandleColormaps() function. - -
- - Bool xf86HandleColormaps(ScreenPtr pScreen, int maxColors, - int sigRGBbits, LoadPaletteFuncPtr loadPalette, - SetOverscanFuncPtr setOverscan, - unsigned int flags); - -
- This function must be called after the default colormap has been - initialised. The pScrn->gamma field must also - be initialised, preferably by calling xf86SetGamma(). - maxColors is the number of entries in the palette. - sigRGBbits is the size in bits of each color - component in the DAC's palette. loadPalette - is a driver-provided function for loading a colormap into the - hardware, and is described below. setOverscan is - an optional function that may be provided when the overscan color - is an index from the standard LUT and when it needs to be adjusted - to keep it as close to black as possible. The - setOverscan function programs the overscan index. - It shouldn't normally be used for depths other than 8. - setOverscan should be set to NULL - when it isn't needed. flags may be set to the - following (which may be ORed together): - - - - CMAP_PALETTED_TRUECOLOR - - the TrueColor visual is paletted and is - just a special case of DirectColor. - This flag is only valid for - bpp > 8. - - - - CMAP_RELOAD_ON_MODE_SWITCH - - reload the colormap automatically - after mode switches. This is useful - for when the driver is resetting the - hardware during mode switches and - corrupting or erasing the hardware - palette. - - - - CMAP_LOAD_EVEN_IF_OFFSCREEN - - reload the colormap even if the screen - is switched out of the server's VC. - The palette is not reloaded when - the screen is switched back in, nor after - mode switches. This is useful when the - driver needs to keep track of palette - changes. - - - - - - - The colormap layer normally reloads the palette after VT enters so it - is not necessary for the driver to save and restore the palette - when switching VTs. The driver must, however, still save the - initial palette during server start up and restore it during - server exit. - - -
- -
- - void LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, - LOCO *colors, VisualPtr pVisual); - -
- LoadPalette() is a driver-provided function for - loading a colormap into hardware. colors is the - array of RGB values that represent the full colormap. - indices is a list of index values into the colors - array. These indices indicate the entries that need to be updated. - numColors is the number of the indices to be - updated. - - -
- -
- - void SetOverscan(ScrnInfoPtr pScrn, int overscan); - -
- SetOverscan() is a driver-provided function for - programming the overscan index. As described - above, it is normally only appropriate for LUT modes where all - colormap entries are available for the display, but where one of - them is also used for the overscan (typically 8bpp for VGA compatible - LUTs). It isn't required in cases where the overscan area is - never visible. - - -
-
- -
- - - DPMS Extension - - -Support code for the DPMS extension is included in the XFree86 common layer. -This code provides an interface between the main extension code, and a means -for drivers to initialise DPMS when they support it. One function is -available to drivers to do this initialisation, and it is always available, -even when the DPMS extension is not supported by the core server (in -which case it returns a failure result). - - -
- - Bool xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags); - -
- This function registers a driver's DPMS level programming function - set. It also checks - pScrn->options for the "dpms" option, and when - present marks DPMS as being enabled for that screen. The - set function is called whenever the DPMS level - changes, and is used to program the requested level. - flags is currently not used, and should be - 0. If the initialisation fails for any reason, - including when there is no DPMS support in the core server, the - function returns FALSE. - - -
- - - -Drivers that implement DPMS support must provide the following function, -that gets called when the DPMS level is changed: - - -
- - void ChipDPMSSet(ScrnInfoPtr pScrn, int level, int flags); - -
- Program the DPMS level specified by level. Valid - values of level are DPMSModeOn, - DPMSModeStandby, DPMSModeSuspend, - DPMSModeOff. These values are defined in - "extensions/dpms.h". - - -
-
- -
- - - DGA Extension - - -Drivers can support the XFree86 Direct Graphics Architecture (DGA) by -filling out a structure of function pointers and a list of modes and -passing them to DGAInit. - - -
- - Bool DGAInit(ScreenPtr pScreen, DGAFunctionPtr funcs, - DGAModePtr modes, int num); - -/** The DGAModeRec **/ - -typedef struct { - int num; - DisplayModePtr mode; - int flags; - int imageWidth; - int imageHeight; - int pixmapWidth; - int pixmapHeight; - int bytesPerScanline; - int byteOrder; - int depth; - int bitsPerPixel; - unsigned long red_mask; - unsigned long green_mask; - unsigned long blue_mask; - int viewportWidth; - int viewportHeight; - int xViewportStep; - int yViewportStep; - int maxViewportX; - int maxViewportY; - int viewportFlags; - int offset; - unsigned char *address; - int reserved1; - int reserved2; -} DGAModeRec, *DGAModePtr; - - - - - num - - Can be ignored. The DGA DDX will assign these numbers. - - - - mode - - A pointer to the DisplayModeRec for this mode. - - - - flags - - The following flags are defined and may be OR'd together: - - - - DGA_CONCURRENT_ACCESS - - Indicates that the driver supports concurrent graphics - accelerator and linear framebuffer access. - - - - - DGA_FILL_RECT - DGA_BLIT_RECT - DGA_BLIT_RECT_TRANS - - Indicates that the driver supports the FillRect, BlitRect - or BlitTransRect functions in this mode. - - - - - DGA_PIXMAP_AVAILABLE - - Indicates that Xlib may be used on the framebuffer. - This flag will usually be set unless the driver wishes - to prohibit this for some reason. - - - - - DGA_INTERLACED - DGA_DOUBLESCAN - - Indicates that these are interlaced or double scan modes. - - - - - - - imageWidth - imageHeight - - These are the dimensions of the linear framebuffer - accessible by the client. - - - - - pixmapWidth - pixmapHeight - - These are the dimensions of the area of the - framebuffer accessible by the graphics accelerator. - - - - - bytesPerScanline - - Pitch of the framebuffer in bytes. - - - - - byteOrder - - Usually the same as - pScrn->imageByteOrder. - - - - - depth - - The depth of the framebuffer in this mode. - - - - - bitsPerPixel - - The number of bits per pixel in this mode. - - - - - red_mask - green_mask - blue_mask - - The RGB masks for this mode, if applicable. - - - - - viewportWidth - viewportHeight - - Dimensions of the visible part of the framebuffer. - Usually mode->HDisplay and - mode->VDisplay. - - - - - xViewportStep - yViewportStep - - The granularity of x and y viewport positions that - the driver supports in this mode. - - - - - maxViewportX - maxViewportY - - The maximum viewport position supported by the - driver in this mode. - - - - viewportFlags - - The following may be OR'd together: - - - - DGA_FLIP_IMMEDIATE - - The driver supports immediate viewport changes. - - - - DGA_FLIP_RETRACE - - - The driver supports viewport changes at retrace. - - - - - - offset - - The offset into the linear framebuffer that corresponds to - pixel (0,0) for this mode. - - - - address - - The virtual address of the framebuffer as mapped by the driver. - This is needed when DGA_PIXMAP_AVAILABLE is set. - - - - - -/** The DGAFunctionRec **/ - -typedef struct { - Bool (*OpenFramebuffer)( - ScrnInfoPtr pScrn, - char **name, - unsigned char **mem, - int *size, - int *offset, - int *extra - ); - void (*CloseFramebuffer)(ScrnInfoPtr pScrn); - Bool (*SetMode)(ScrnInfoPtr pScrn, DGAModePtr pMode); - void (*SetViewport)(ScrnInfoPtr pScrn, int x, int y, int flags); - int (*GetViewport)(ScrnInfoPtr pScrn); - void (*Sync)(ScrnInfoPtr); - void (*FillRect)( - ScrnInfoPtr pScrn, - int x, int y, int w, int h, - unsigned long color - ); - void (*BlitRect)( - ScrnInfoPtr pScrn, - int srcx, int srcy, - int w, int h, - int dstx, int dsty - ); - void (*BlitTransRect)( - ScrnInfoPtr pScrn, - int srcx, int srcy, - int w, int h, - int dstx, int dsty, - unsigned long color - ); -} DGAFunctionRec, *DGAFunctionPtr; - - - -
- - Bool OpenFramebuffer (pScrn, name, mem, size, offset, extra); - -
- OpenFramebuffer() should pass the client everything - it needs to know to be able to open the framebuffer. These - parameters are OS specific and their meanings are to be interpreted - by an OS specific client library. - - - - name - - The name of the device to open or NULL if - there is no special device to open. A NULL - name tells the client that it should open whatever device - one would usually open to access physical memory. - - - - mem - - The physical address of the start of the framebuffer. - - - - size - - The size of the framebuffer in bytes. - - - - offset - - Any offset into the device, if applicable. - - - - flags - - Any additional information that the client may need. - Currently, only the DGA_NEED_ROOT flag is - defined. - - - -
-
- -
- - void CloseFramebuffer (pScrn); - -
- CloseFramebuffer() merely informs the driver (if it - even cares) that client no longer needs to access the framebuffer - directly. This function is optional. - - -
- -
- - Bool SetMode (pScrn, pMode); - -
- SetMode() tells the driver to initialize the mode - passed to it. If pMode is NULL, - then the driver should restore the original pre-DGA mode. - - -
- -
- - void SetViewport (pScrn, x, y, flags); - -
- SetViewport() tells the driver to make the upper - left-hand corner of the visible screen correspond to coordinate - (x,y) on the framebuffer. flags - currently defined are: - - - - DGA_FLIP_IMMEDIATE - - The viewport change should occur immediately. - - - - DGA_FLIP_RETRACE - - The viewport change should occur at the - vertical retrace, but this function should - return sooner if possible. - - - - - - The (x,y) locations will be passed as the client - specified them, however, the driver is expected to round these - locations down to the next supported location as specified by the - xViewportStep and yViewportStep - for the current mode. - -
- -
- - int GetViewport (pScrn); - -
- GetViewport() gets the current page flip status. - Set bits in the returned int correspond to viewport change requests - still pending. For instance, set bit zero if the last SetViewport - request is still pending, bit one if the one before that is still - pending, etc. - - -
- -
- - void Sync (pScrn); - -
- This function should ensure that any graphics accelerator operations - have finished. This function should not return until the graphics - accelerator is idle. - - -
- -
- - void FillRect (pScrn, x, y, w, h, color); - -
- This optional function should fill a rectangle - w × h located at - (x,y) in the given color. - - -
- -
- - void BlitRect (pScrn, srcx, srcy, w, h, dstx, dsty); - -
- This optional function should copy an area - w × h located at - (srcx,srcy) to location (dstx,dsty). - This function will need to handle copy directions as appropriate. - - -
- -
- - void BlitTransRect (pScrn, srcx, srcy, w, h, dstx, dsty, color); - -
- This optional function is the same as BlitRect except that pixels - in the source corresponding to the color key color - should be skipped. - - -
-
- -
- - - The XFree86 X Video Extension (Xv) Device Dependent Layer - - -XFree86 offers the X Video Extension which allows clients to treat video -as any another primitive and Put video into drawables. By default, -the extension reports no video adaptors as being available since the -DDX layer has not been initialized. The driver can initialize the DDX -layer by filling out one or more XF86VideoAdaptorRecs -as described later in this document and passing a list of -XF86VideoAdaptorPtr pointers to the following function: - - - Bool xf86XVScreenInit(ScreenPtr pScreen, - XF86VideoAdaptorPtr *adaptPtrs, - int num); - - - - -After doing this, the extension will report video adaptors as being -available, providing the data in their respective -XF86VideoAdaptorRecs was valid. -xf86XVScreenInit() copies data from the structure -passed to it so the driver may free it after the initialization. At -the moment, the DDX only supports rendering into Window drawables. -Pixmap rendering will be supported after a sufficient survey of suitable -hardware is completed. - - - -The XF86VideoAdaptorRec: - - -typedef struct { - unsigned int type; - int flags; - char *name; - int nEncodings; - XF86VideoEncodingPtr pEncodings; - int nFormats; - XF86VideoFormatPtr pFormats; - int nPorts; - DevUnion *pPortPrivates; - int nAttributes; - XF86AttributePtr pAttributes; - int nImages; - XF86ImagePtr pImages; - PutVideoFuncPtr PutVideo; - PutStillFuncPtr PutStill; - GetVideoFuncPtr GetVideo; - GetStillFuncPtr GetStill; - StopVideoFuncPtr StopVideo; - SetPortAttributeFuncPtr SetPortAttribute; - GetPortAttributeFuncPtr GetPortAttribute; - QueryBestSizeFuncPtr QueryBestSize; - PutImageFuncPtr PutImage; - QueryImageAttributesFuncPtr QueryImageAttributes; -} XF86VideoAdaptorRec, *XF86VideoAdaptorPtr; - - - -Each adaptor will have its own XF86VideoAdaptorRec. The fields are -as follows: - - - - type - - This can be any of the following flags OR'd together. - - - - XvInputMask - XvOutputMask - - These refer to the target drawable and are similar to a Window's - class. XvInputMask indicates that the adaptor - can put video into a drawable. XvOutputMask - indicates that the adaptor can get video from a drawable. - - - - XvVideoMask - XvStillMask - XvImageMask - - These indicate that the adaptor supports video, still or - image primitives respectively. - - - - XvWindowMask - XvPixmapMask - - These indicate the types of drawables the adaptor is capable - of rendering into. At the moment, Pixmap rendering is not - supported and the XvPixmapMask flag is ignored. - - - - - - - flags - - Currently, the following flags are defined: - - - - VIDEO_OVERLAID_STILLS - - Implementing PutStill for hardware that does video as an - overlay can be awkward since it's unclear how long to leave - the video up for. When this flag is set, StopVideo will be - called whenever the destination gets clipped or moved so that - the still can be left up until then. - - - - - - VIDEO_OVERLAID_IMAGES - - Same as VIDEO_OVERLAID_STILLS but for images. - - - - - VIDEO_CLIP_TO_VIEWPORT - - Indicates that the clip region passed to the driver functions - should be clipped to the visible portion of the screen in the - case where the viewport is smaller than the virtual desktop. - - - - - - - name - - The name of the adaptor. - - - - - nEncodings - pEncodings - - The number of encodings the adaptor is capable of and pointer - to the XF86VideoEncodingRec array. The - XF86VideoEncodingRec is described later on. - For drivers that only support XvImages there should be an encoding - named "XV_IMAGE" and the width and height should specify - the maximum size source image supported. - - - - - nFormats - pFormats - - The number of formats the adaptor is capable of and pointer to - the XF86VideoFormatRec array. The - XF86VideoFormatRec is described later on. - - - - - nPorts - pPortPrivates - - The number of ports is the number of separate data streams which - the adaptor can handle simultaneously. If you have more than - one port, the adaptor is expected to be able to render into more - than one window at a time. pPortPrivates is - an array of pointers or ints - one for each port. A port's - private data will be passed to the driver any time the port is - requested to do something like put the video or stop the video. - In the case where there may be many ports, this enables the - driver to know which port the request is intended for. Most - commonly, this will contain a pointer to the data structure - containing information about the port. In Xv, all ports on - a particular adaptor are expected to be identical in their - functionality. - - - - - nAttributes - pAttributes - - The number of attributes recognized by the adaptor and a pointer to - the array of XF86AttributeRecs. The - XF86AttributeRec is described later on. - - - - - nImages - pImages - - The number of XF86ImageRecs supported by the adaptor - and a pointer to the array of XF86ImageRecs. The - XF86ImageRec is described later on. - - - - - - PutVideo PutStill GetVideo GetStill StopVideo - SetPortAttribute GetPortAttribute QueryBestSize PutImage - QueryImageAttributes - - - These functions define the DDX->driver interface. In each - case, the pointer data is passed to the driver. - This is the port private for that port as described above. All - fields are required except under the following conditions: - - - - PutVideo, PutStill and - the image routines PutImage and - QueryImageAttributes are not required when the - adaptor type does not contain XvInputMask. - - - - GetVideo and GetStill - are not required when the adaptor type does not contain - XvOutputMask. - - - - GetVideo and PutVideo - are not required when the adaptor type does not contain - XvVideoMask. - - - - GetStill and PutStill - are not required when the adaptor type does not contain - XvStillMask. - - - - PutImage and QueryImageAttributes - are not required when the adaptor type does not contain - XvImageMask. - - - - - - - - With the exception of QueryImageAttributes, these - functions should return Success if the operation was - completed successfully. They can return XvBadAlloc - otherwise. QueryImageAttributes returns the size - of the XvImage queried. - - - - ClipBoxes is an X-Y - banded region identical to those used throughout the server. - The clipBoxes represent the visible portions of the area determined - by drw_x, drw_y, - drw_w and drw_h in the Get/Put - function. The boxes are in screen coordinates, are guaranteed - not to overlap and an empty region will never be passed. - - - - -
- - typedef int (* PutVideoFuncPtr)( ScrnInfoPtr pScrn, - short vid_x, short vid_y, short drw_x, short drw_y, - short vid_w, short vid_h, short drw_w, short drw_h, - RegionPtr clipBoxes, pointer data ); - -
- This indicates that the driver should take a subsection - vid_w by vid_h at location - (vid_x,vid_y) from the video stream and direct - it into the rectangle drw_w by drw_h - at location (drw_x,drw_y) on the screen, scaling as - necessary. Due to the large variations in capabilities of - the various hardware expected to be used with this extension, - it is not expected that all hardware will be able to do this - exactly as described. In that case the driver should just do - the best it can, scaling as closely to the target rectangle - as it can without rendering outside of it. In the worst case, - the driver can opt to just not turn on the video. - - -
- -
- - typedef int (* PutStillFuncPtr)( ScrnInfoPtr pScrn, - short vid_x, short vid_y, short drw_x, short drw_y, - short vid_w, short vid_h, short drw_w, short drw_h, - RegionPtr clipBoxes, pointer data ); - -
- This is same as PutVideo except that the driver - should place only one frame from the stream on the screen. - - -
- -
- - typedef int (* GetVideoFuncPtr)( ScrnInfoPtr pScrn, - short vid_x, short vid_y, short drw_x, short drw_y, - short vid_w, short vid_h, short drw_w, short drw_h, - RegionPtr clipBoxes, pointer data ); - -
- This is same as PutVideo except that the driver - gets video from the screen and outputs it. The driver should - do the best it can to get the requested dimensions correct - without reading from an area larger than requested. - - -
- -
- - typedef int (* GetStillFuncPtr)( ScrnInfoPtr pScrn, - short vid_x, short vid_y, short drw_x, short drw_y, - short vid_w, short vid_h, short drw_w, short drw_h, - RegionPtr clipBoxes, pointer data ); - -
- This is the same as GetVideo except that the - driver should place only one frame from the screen into the - output stream. - - -
- -
- - typedef void (* StopVideoFuncPtr)(ScrnInfoPtr pScrn, - pointer data, Bool cleanup); - -
- This indicates the driver should stop displaying the video. - This is used to stop both input and output video. The - cleanup field indicates that the video is - being stopped because the client requested it to stop or - because the server is exiting the current VT. In that case - the driver should deallocate any offscreen memory areas (if - there are any) being used to put the video to the screen. If - cleanup is not set, the video is being stopped - temporarily due to clipping or moving of the window, etc... - and video will likely be restarted soon so the driver should - not deallocate any offscreen areas associated with that port. - - -
-
- - typedef int (* SetPortAttributeFuncPtr)(ScrnInfoPtr pScrn, - Atom attribute,INT32 value, pointer data); - - - - typedef int (* GetPortAttributeFuncPtr)(ScrnInfoPtr pScrn, - Atom attribute,INT32 *value, pointer data); - -
- A port may have particular attributes such as hue, - saturation, brightness or contrast. Xv clients set and - get these attribute values by sending attribute strings - (Atoms) to the server. Such requests end up at these - driver functions. It is recommended that the driver provide - at least the following attributes mentioned in the Xv client - library docs: - - XV_ENCODING - XV_HUE - XV_SATURATION - XV_BRIGHTNESS - XV_CONTRAST - - but the driver may recognize as many atoms as it wishes. If - a requested attribute is unknown by the driver it should return - BadMatch. XV_ENCODING is the - attribute intended to let the client specify which video - encoding the particular port should be using (see the description - of XF86VideoEncodingRec below). If the - requested encoding is unsupported, the driver should return - XvBadEncoding. If the value lies outside the - advertised range BadValue may be returned. - Success should be returned otherwise. - - -
- -
- - typedef void (* QueryBestSizeFuncPtr)(ScrnInfoPtr pScrn, - Bool motion, short vid_w, short vid_h, - short drw_w, short drw_h, - unsigned int *p_w, unsigned int *p_h, pointer data); - -
- QueryBestSize provides the client with a way - to query what the destination dimensions would end up being - if they were to request that an area - vid_w by vid_h from the video - stream be scaled to rectangle of - drw_w by drw_h on the screen. - Since it is not expected that all hardware will be able to - get the target dimensions exactly, it is important that the - driver provide this function. - - -
- -
- - typedef int (* PutImageFuncPtr)( ScrnInfoPtr pScrn, - short src_x, short src_y, short drw_x, short drw_y, - short src_w, short src_h, short drw_w, short drw_h, - int image, char *buf, short width, short height, - Bool sync, RegionPtr clipBoxes, pointer data ); - -
- This is similar to PutStill except that the - source of the video is not a port but the data stored in a system - memory buffer at buf. The data is in the format - indicated by the image descriptor and represents a - source of size width by height. - If sync is TRUE the driver should not return - from this function until it is through reading the data - from buf. Returning when sync - is TRUE indicates that it is safe for the data at buf - to be replaced, freed, or modified. - - -
- -
- - typedef int (* QueryImageAttributesFuncPtr)( ScrnInfoPtr pScrn, - int image, short *width, short *height, - int *pitches, int *offsets); - -
- This function is called to let the driver specify how data for - a particular image of size width - by height should be stored. Sometimes only - the size and corrected width and height are needed. In that - case pitches and offsets are - NULL. The size of the memory required for the image is returned - by this function. The width and - height of the requested image can be altered by - the driver to reflect format limitations (such as component - sampling periods that are larger than one). If - pitches and offsets are not NULL, - these will be arrays with as many elements in them as there - are planes in the image format. The driver - should specify the pitch (in bytes) of each scanline in the - particular plane as well as the offset to that plane (in bytes) - from the beginning of the image. - - -
-
- - -The XF86VideoEncodingRec: - -
- -typedef struct { - int id; - char *name; - unsigned short width, height; - XvRationalRec rate; -} XF86VideoEncodingRec, *XF86VideoEncodingPtr; - - -
- The XF86VideoEncodingRec specifies what encodings - the adaptor can support. Most of this data is just informational - and for the client's benefit, and is what will be reported by - XvQueryEncodings. The id field is - expected to be a unique identifier to allow the client to request a - certain encoding via the XV_ENCODING attribute string. - - -
-
- - -The XF86VideoFormatRec: - -
- -typedef struct { - char depth; - short class; -} XF86VideoFormatRec, *XF86VideoFormatPtr; - - -
- This specifies what visuals the video is viewable in. - depth is the depth of the visual (not bpp). - class is the visual class such as - TrueColor, DirectColor or - PseudoColor. Initialization of an adaptor will fail - if none of the visuals on that screen are supported. - - -
-
- - -The XF86AttributeRec: - -
- -typedef struct { - int flags; - int min_value; - int max_value; - char *name; -} XF86AttributeListRec, *XF86AttributeListPtr; - - -
- Each adaptor may have an array of these advertising the attributes - for its ports. Currently defined flags are XvGettable - and XvSettable which may be OR'd together indicating that - attribute is gettable or settable by the client. The - min and max field specify the valid range - for the value. Name is a text string describing the - attribute by name. - - -
- -
- - -The XF86ImageRec: - -
- -typedef struct { - int id; - int type; - int byte_order; - char guid[16]; - int bits_per_pixel; - int format; - int num_planes; - - /* for RGB formats */ - int depth; - unsigned int red_mask; - unsigned int green_mask; - unsigned int blue_mask; - - /* for YUV formats */ - unsigned int y_sample_bits; - unsigned int u_sample_bits; - unsigned int v_sample_bits; - unsigned int horz_y_period; - unsigned int horz_u_period; - unsigned int horz_v_period; - unsigned int vert_y_period; - unsigned int vert_u_period; - unsigned int vert_v_period; - char component_order[32]; - int scanline_order; -} XF86ImageRec, *XF86ImagePtr; - - -
- XF86ImageRec describes how video source data is laid out in memory. - The fields are as follows: - - - - id - - This is a unique descriptor for the format. It is often good to - set this value to the FOURCC for the format when applicable. - - - - type - - This is XvRGB or XvYUV. - - - - byte_order - - This is LSBFirst or MSBFirst. - - - - guid - - This is the Globally Unique IDentifier for the format. When - not applicable, all characters should be NULL. - - - - bits_per_pixel - - The number of bits taken up (but not necessarily used) by each - pixel. Note that for some planar formats which have fractional - bits per pixel (such as IF09) this number may be rounded _down_. - - - - format - - This is XvPlanar or XvPacked. - - - - num_planes - - The number of planes in planar formats. This should be set to - one for packed formats. - - - - depth - - The significant bits per pixel in RGB formats (analogous to the - depth of a pixmap format). - - - - red_mask - green_mask - blue_mask - - The red, green and blue bitmasks for packed RGB formats. - - - - y_sample_bits - u_sample_bits - v_sample_bits - - The y, u and v sample sizes (in bits). - - - - horz_y_period - horz_u_period - horz_v_period - - The y, u and v sampling periods in the horizontal direction. - - - - vert_y_period - vert_u_period - vert_v_period - - The y, u and v sampling periods in the vertical direction. - - - - component_order - - Uppercase ascii characters representing the order that - samples are stored within packed formats. For planar formats - this represents the ordering of the planes. Unused characters - in the 32 byte string should be set to NULL. - - - - scanline_order - - This is XvTopToBottom or XvBottomToTop. - - - - - - - Since some formats (particular some planar YUV formats) may not -be completely defined by the parameters above, the guid, when -available, should provide the most accurate description of the -format. - - -
-
-
- - - The Loader - - -This section describes the interfaces to the module loader. The loader -interfaces can be divided into two groups: those that are only available to -the XFree86 common layer, and those that are also available to modules. - - - - Loader Overview - - -The loader is capable of loading modules in a range of object formats, -and knowledge of these formats is built in to the loader. Knowledge of -new object formats can be added to the loader in a straightforward -manner. This makes it possible to provide OS-independent modules (for -a given CPU architecture type). In addition to this, the loader can -load modules via the OS-provided dlopen(3) service where -available. Such modules are not platform independent, and the semantics -of dlopen() on most systems results in significant -limitations in the use of modules of this type. Support for -dlopen() modules in the loader is primarily for -experimental and development purposes. - - - -Symbols exported by the loader (on behalf of the core X server) to -modules are determined at compile time. Only those symbols explicitly -exported are available to modules. All external symbols of loaded -modules are exported to other modules, and to the core X server. The -loader can be requested to check for unresolved symbols at any time, -and the action to be taken for unresolved symbols can be controlled by -the caller of the loader. Typically the caller identifies which symbols -can safely remain unresolved and which cannot. - - - -NOTE: Now that ISO-C allows pointers to functions and pointers to data to -have different internal representations, some of the following interfaces -will need to be revisited. - - - - - Semi-private Loader Interface - - -The following is the semi-private loader interface that is available to the -XFree86 common layer. - - -
- - void LoaderInit(void); - -
- The LoaderInit() function initialises the loader, - and it must be called once before calling any other loader functions. - This function initialises the tables of exported symbols, and anything - else that might need to be initialised. - - -
- -
- - void LoaderSetPath(const char *path); - -
- The LoaderSetPath() function initialises a default - module search path. This must be called if calls to other functions - are to be made without explicitly specifying a module search path. - The search path path must be a string of one or more - comma separated absolute paths. Modules are expected to be located - below these paths, possibly in subdirectories of these paths. - - -
- -
- - pointer LoadModule(const char *module, pointer options, - const XF86ModReqInfo * modreq, int *errmaj); - -
- The LoadModule() function loads the module called - module. The return value is a module handle, and - may be used in future calls to the loader that require a reference - to a loaded module. The module name module is - normally the module's canonical name, which doesn't contain any - directory path information, or any object/library file prefixes of - suffixes. Currently a full pathname and/or filename is also accepted. - This might change. The other parameters are: - - - - - options - - An optional parameter that is passed to the newly - loaded module's SetupProc function - (if it has one). This argument is normally a - NULL terminated list of - Options, and must be interpreted that - way by modules loaded directly by the XFree86 common - layer. However, it may be used for application-specific - parameter passing in other situations. - - - - - modreq - - An optional XF86ModReqInfo* containing - version/ABI/vendor information to requirements to - check the newly loaded module against. The main - purpose of this is to allow the loader to verify that - a module of the correct type/version before running - its SetupProc function. - - - - The XF86ModReqInfo struct is defined - as follows: - -typedef struct { - CARD8 majorversion; - CARD8 minorversion; - CARD16 patchlevel; - const char * abiclass; - CARD32 abiversion; - const char * moduleclass; -} XF86ModReqInfo; - - - The information here is compared against the equivalent - information in the module's - XF86ModuleVersionInfo record (which - is described below). The values in comments above - indicate don't care settings for each of the fields. - The comparisons made are as follows: - - - - majorversion - - Must match the module's majorversion - exactly. - - - - minorversion - - The module's minor version must be - no less than this value. This - comparison is only made if - majorversion - matches. - - - - patchlevel - - The module's patchlevel must be no - less than this value. This comparison - is only made if - minorversion - matches. - - - - abiclass - - String must match the module's abiclass - string. - - - - abiversion - - Must be consistent with the module's - abiversion (major equal, minor no - older). - - - - moduleclass - - String must match the module's - moduleclass string. - - - - - - - errmaj - - An optional pointer to a variable holding the major - part or the error code. When provided, - *errmaj is filled in when - LoadModule() fails. - - - - -
-
- -
- - void UnloadModule(pointer mod); - -
- This function unloads the module referred to by the handle mod. - All child modules are also unloaded recursively. This function must - not be used to directly unload modules that are child modules (i.e., - those that have been loaded with the LoadSubModule() - described below). - - -
-
- - - Module Requirements - - -Modules must provide information about themselves to the loader, and -may optionally provide entry points for "setup" and "teardown" functions -(those two functions are referred to here as SetupProc -and TearDownProc). - - - -The module information is contained in the -XF86ModuleVersionInfo struct, which is defined as follows: - - -typedef struct { - const char * modname; /* name of module, e.g. "foo" */ - const char * vendor; /* vendor specific string */ - CARD32 _modinfo1_; /* constant MODINFOSTRING1/2 to find */ - CARD32 _modinfo2_; /* infoarea with a binary editor/sign tool */ - CARD32 xf86version; /* contains XF86_VERSION_CURRENT */ - CARD8 majorversion; /* module-specific major version */ - CARD8 minorversion; /* module-specific minor version */ - CARD16 patchlevel; /* module-specific patch level */ - const char * abiclass; /* ABI class that the module uses */ - CARD32 abiversion; /* ABI version */ - const char * moduleclass; /* module class */ - CARD32 checksum[4]; /* contains a digital signature of the */ - /* version info structure */ -} XF86ModuleVersionInfo; - - -The fields are used as follows: - - - - modname - - The module's name. This field is currently only for - informational purposes, but the loader may be modified - in future to require it to match the module's canonical - name. - - - - - vendor - - The module vendor. This field is for informational purposes - only. - - - - - _modinfo1_ - - This field holds the first part of a signature that can - be used to locate this structure in the binary. It should - always be initialised to MODINFOSTRING1. - - - - - _modinfo2_ - - This field holds the second part of a signature that can - be used to locate this structure in the binary. It should - always be initialised to MODINFOSTRING2. - - - - - xf86version - - The XFree86 version against which the module was compiled. - This is mostly for informational/diagnostic purposes. It - should be initialised to XF86_VERSION_CURRENT, which is - defined in xf86Version.h. - - - - - majorversion - - The module-specific major version. For modules where this - version is used for more than simply informational - purposes, the major version should only change (be - incremented) when ABI incompatibilities are introduced, - or ABI components are removed. - - - - - minorversion - - The module-specific minor version. For modules where this - version is used for more than simply informational - purposes, the minor version should only change (be - incremented) when ABI additions are made in a backward - compatible way. It should be reset to zero when the major - version is increased. - - - - - patchlevel - - The module-specific patch level. The patch level should - increase with new revisions of the module where there - are no ABI changes, and it should be reset to zero when - the minor version is increased. - - - - - abiclass - - The ABI class that the module requires. The class is - specified as a string for easy extensibility. It should - indicate which (if any) of the X server's built-in ABI - classes that the module relies on, or a third-party ABI - if appropriate. Built-in ABI classes currently defined are: - - - - ABI_CLASS_NONE - no class - - - ABI_CLASS_ANSIC - only requires the ANSI C interfaces - - - ABI_CLASS_VIDEODRV - requires the video driver ABI - - - ABI_CLASS_XINPUT - requires the XInput driver ABI - - - ABI_CLASS_EXTENSION - requires the extension module ABI - - - - - - - abiversion - - The version of abiclass that the module requires. The - version consists of major and minor components. The - major version must match and the minor version must be - no newer than that provided by the server or parent - module. Version identifiers for the built-in classes - currently defined are: - - - ABI_ANSIC_VERSION - ABI_VIDEODRV_VERSION - ABI_XINPUT_VERSION - ABI_EXTENSION_VERSION - - - - - - moduleclass - - This is similar to the abiclass field, except that it - defines the type of module rather than the ABI it - requires. For example, although all video drivers require - the video driver ABI, not all modules that require the - video driver ABI are video drivers. This distinction - can be made with the moduleclass. Currently pre-defined - module classes are: - - - MOD_CLASS_NONE - MOD_CLASS_VIDEODRV - MOD_CLASS_XINPUT - MOD_CLASS_EXTENSION - - - - - - checksum - - Not currently used. - - - - - - -The module version information, and the optional SetupProc -and TearDownProc entry points are found by the loader -by locating a data object in the module called "modnameModuleData", -where "modname" is the canonical name of the module. Modules must -contain such a data object, and it must be declared with global scope, -be compile-time initialised, and is of the following type: - - -typedef struct { - XF86ModuleVersionInfo * vers; - ModuleSetupProc setup; - ModuleTearDownProc teardown; -} XF86ModuleData; - - - - -The vers parameter must be initialised to a pointer to a correctly -initialised XF86ModuleVersionInfo struct. The other -two parameter are optional, and should be initialised to -NULL when not required. The other parameters are defined -as - -
- - typedef pointer (*ModuleSetupProc)(pointer, pointer, int *, int *); - - typedef void (*ModuleTearDownProc)(pointer); - - pointer SetupProc(pointer module, pointer options, - int *errmaj, int *errmin); - -
- When defined, this function is called by the loader after successfully - loading a module. module is a handle for the newly loaded module, - and maybe used by the SetupProc if it calls other - loader functions that require a reference to it. The remaining - arguments are those that were passed to the - LoadModule() (or LoadSubModule()), - and are described above. When the SetupProc is - successful it must return a non-NULL value. The - loader checks this, and if it is NULL it unloads - the module and reports the failure to the caller of - LoadModule(). If the SetupProc - does things that need to be undone when the module is unloaded, - it should define a TearDownProc, and return a - pointer that the TearDownProc can use to undo what - has been done. - - - - When a module is loaded multiple times, the SetupProc - is called once for each time it is loaded. - - -
- -
- - void TearDownProc(pointer tearDownData); - -
- When defined, this function is called when the loader unloads a - module. The tearDownData parameter is the return - value of the SetupProc() that was called when the - module was loaded. The purpose of this function is to clean up - before the module is unloaded (for example, by freeing allocated - resources). - - -
-
-
- - - Public Loader Interface - - -The following is the Loader interface that is available to any part of -the server, and may also be used from within modules. - - -
- - pointer LoadSubModule(pointer parent, const char *module, - const char **subdirlist, const char **patternlist, - pointer options, const XF86ModReqInfo * modreq, - int *errmaj, int *errmin); - -
- This function is like the LoadModule() function - described above, except that the module loaded is registered as a - child of the calling module. The parent parameter - is the calling module's handle. Modules loaded with this function - are automatically unloaded when the parent module is unloaded. - - -
- -
- - void UnloadSubModule(pointer module); - -
- This function unloads the module with handle module. - If that module itself has children, they are also unloaded. It is - like UnloadModule(), except that it is safe to use - for unloading child modules. - - -
- -
- - pointer LoaderSymbol(const char *symbol); - -
- This function returns the address of the symbol with name - symbol. This may be used to locate a module entry - point with a known name. - - -
- -
- - char **LoaderlistDirs(const char **subdirlist, - const char **patternlist); - -
- This function returns a NULL terminated list of - canonical modules names for modules found in the default module - search path. The subdirlist and - patternlist parameters are as described above, and - can be used to control the locations and names that are searched. - If no modules are found, the return value is NULL. - The returned list should be freed by calling - LoaderFreeDirList() when it is no longer needed. - - -
- -
- - void LoaderFreeDirList(char **list); - -
- This function frees a module list created by - LoaderlistDirs(). - - -
- -
- - void LoaderReqSymLists(const char **list0, ...); - -
- This function allows the registration of required symbols with the - loader. It is normally used by a caller of - LoadSubModule(). If any symbols registered in this - way are found to be unresolved when - LoaderCheckUnresolved() is called then - LoaderCheckUnresolved() will report a failure. - The function takes one or more NULL terminated - lists of symbols. The end of the argument list is indicated by a - NULL argument. - - -
- -
- - void LoaderReqSymbols(const char *sym0, ...); - -
- This function is like LoaderReqSymLists() except - that its arguments are symbols rather than lists of symbols. This - function is more convenient when single functions are to be registered, - especially when the single function might depend on runtime factors. - The end of the argument list is indicated by a NULL - argument. - - -
- -
- - void LoaderRefSymLists(const char **list0, ...); - -
- This function allows the registration of possibly unresolved symbols - with the loader. When LoaderCheckUnresolved() is - run it won't generate warnings for symbols registered in this way - unless they were also registered as required symbols. - The function takes one or more NULL terminated - lists of symbols. The end of the argument list is indicated by a - NULL argument. - - -
- -
- - void LoaderRefSymbols(const char *sym0, ...); - -
- This function is like LoaderRefSymLists() except - that its arguments are symbols rather than lists of symbols. This - function is more convenient when single functions are to be registered, - especially when the single function might depend on runtime factors. - The end of the argument list is indicated by a NULL - argument. - - -
- -
- - int LoaderCheckUnresolved(int delayflag); - -
- This function checks for unresolved symbols. It generates warnings - for unresolved symbols that have not been registered with - LoaderRefSymLists(), and maps them to a dummy - function. This behaviour may change in future. If unresolved - symbols are found that have been registered with - LoaderReqSymLists() or - LoaderReqSymbols() then this function returns a - non-zero value. If none of these symbols are unresolved the return - value is zero, indicating success. - - - - The delayflag parameter should normally be set to - LD_RESOLV_IFDONE. - - -
- -
- - LoaderErrorMsg(const char *name, const char *modname, - int errmaj, int errmin); - -
- This function prints an error message that includes the text Failed - to load module, the module name modname, a message - specific to the errmaj value, and the value if - errmin. If name is - non-NULL, it is printed as an identifying prefix - to the message (followed by a :). - - -
-
- - - Special Registration Functions - - -The loader contains some functions for registering some classes of modules. -These may be moved out of the loader at some point. - - -
- - void LoadExtensionList(const ExtensionModule ext[], int size, Bool builtin); - -
- This registers the entry points for the extension array identified by - ext. The ExtensionModule struct is - defined as: - - -typedef struct { - InitExtension initFunc; - char * name; - Bool *disablePtr; -} ExtensionModule; - - - -
- -
- -
- - - Helper Functions - - -This section describe helper functions that video driver -might find useful. While video drivers are not required to use any of -these to be considered compliant, the use of appropriate helpers is -strongly encouraged to improve the consistency of driver behaviour. - - - - Functions for printing messages - -
- - ErrorF(const char *format, ...); - -
- This is the basic function for writing to the error log (typically - stderr and/or a log file). Video drivers should usually avoid - using this directly in favour of the more specialised functions - described below. This function is useful for printing messages - while debugging a driver. - - -
- -
- - FatalError(const char *format, ...); - -
- This prints a message and causes the Xserver to abort. It should - rarely be used within a video driver, as most error conditions - should be flagged by the return values of the driver functions. - This allows the higher layers to decide how to proceed. In rare - cases, this can be used within a driver if a fatal unexpected - condition is found. - - -
- -
- - xf86ErrorF(const char *format, ...); - -
- This is like ErrorF(), except that the message is - only printed when the Xserver's verbosity level is set to the - default (1) or higher. It means that the messages - are not printed when the server is started with the - flag. Typically this function would only be - used for continuing messages started with one of the more specialised - functions described below. - - -
- -
- - xf86ErrorFVerb(int verb, const char *format, ...); - -
- Like xf86ErrorF(), except the minimum verbosity - level for which the message is to be printed is given explicitly. - Passing a verb value of zero means the message - is always printed. A value higher than 1 can be - used for information would normally not be needed, but which might - be useful when diagnosing problems. - - -
- - -
- - xf86Msg(MessageType type, const char *format, ...); - -
- This is like xf86ErrorF(), except that the message - is prefixed with a marker determined by the value of - type. The marker is used to indicate the type of - message (warning, error, probed value, config value, etc). Note - the xf86Verbose value is ignored for messages of - type X_ERROR. - - - - The marker values are: - - - - X_PROBED - Value was probed. - - - X_CONFIG - Value was given in the config file. - - - X_DEFAULT - Value is a default. - - - X_CMDLINE - Value was given on the command line. - - - X_NOTICE - Notice. - - - X_ERROR - Error message. - - - X_WARNING - Warning message. - - - X_INFO - Informational message. - - - X_NONE - No prefix. - - - X_NOT_IMPLEMENTED - The message relates to functionality - that is not yetimplemented. - - - - - -
- -
- - xf86MsgVerb(MessageType type, int verb, const char *format, ...); - -
- Like xf86Msg(), but with the verbosity level given - explicitly. - - -
- -
- - xf86DrvMsg(int scrnIndex, MessageType type, const char *format, ...); - -
- This is like xf86Msg() except that the driver's - name (the name field of the - ScrnInfoRec) followed by the - scrnIndex in parentheses is printed following the - prefix. This should be used by video drivers in most cases as it - clearly indicates which driver/screen the message is for. If - scrnIndex is negative, this function behaves - exactly like xf86Msg(). - - - - NOTE: This function can only be used after the - ScrnInfoRec and its name field - have been allocated. Normally, this means that it can not be - used before the END of the ChipProbe() function. - Prior to that, use xf86Msg(), providing the - driver's name explicitly. No screen number can be supplied at - that point. - - -
- -
- - xf86DrvMsgVerb(int scrnIndex, MessageType type, int verb, - const char *format, ...); - -
- Like xf86DrvMsg(), but with the verbosity level - given explicitly. - - -
-
- - - - Functions for setting values based on command line and config file - -
- - Bool xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int bpp, - - int fbbpp, int depth24flags); - -
- This function sets the depth, pixmapBPP and bitsPerPixel fields - of the ScrnInfoRec. It also determines the defaults for display-wide - attributes and pixmap formats the screen will support, and finds - the Display subsection that matches the depth/bpp. This function - should normally be called very early from the - ChipPreInit() function. - - - - It requires that the confScreen field of the ScrnInfoRec be - initialised prior to calling it. This is done by the XFree86 - common layer prior to calling ChipPreInit(). - - - - The parameters passed are: - - - - depth - - driver's preferred default depth if no other is given. - If zero, use the overall server default. - - - - bpp - - Same, but for the pixmap bpp. - - - - fbbpp - - Same, but for the framebuffer bpp. - - - - depth24flags - - Flags that indicate the level of 24/32bpp support - and whether conversion between different framebuffer - and pixmap formats is supported. The flags for this - argument are defined as follows, and multiple flags - may be ORed together: - - - - NoDepth24Support - No depth 24 formats supported - - - Support24bppFb - 24bpp framebuffer supported - - - Support32bppFb - 32bpp framebuffer supported - - - SupportConvert24to32 - Can convert 24bpp pixmap to 32bpp fb - - - SupportConvert32to24 - Can convert 32bpp pixmap to 24bpp fb - - - ForceConvert24to32 - Force 24bpp pixmap to 32bpp fb conversion - - - ForceConvert32to24 - Force 32bpp pixmap to 24bpp fb conversion - - - - - - - - - It uses the command line, config file, and default values in the - correct order of precedence to determine the depth and bpp values. - It is up to the driver to check the results to see that it supports - them. If not the ChipPreInit() function should - return FALSE. - - - - If only one of depth/bpp is given, the other is set to a reasonable - (and consistent) default. - - - - If a driver finds that the initial depth24flags - it uses later results in a fb format that requires more video - memory than is available it may call this function a second time - with a different depth24flags setting. - - - - On success, the return value is TRUE. On failure - it prints an error message and returns FALSE. - - - - The following fields of the ScrnInfoRec are - initialised by this function: - -
-depth, bitsPerPixel, -display, imageByteOrder, -bitmapScanlinePad, -bitmapScanlineUnit, bitmapBitOrder, -numFormats, formats, -fbFormat. -
-
- -
- -
- - void xf86PrintDepthBpp(scrnInfoPtr scrp); - -
- This function can be used to print out the depth and bpp settings. - It should be called after the final call to - xf86SetDepthBpp(). - - -
- -
- - Bool xf86SetWeight(ScrnInfoPtr scrp, rgb weight, rgb mask); - -
- This function sets the weight, mask, - offset and rgbBits fields of the - ScrnInfoRec. It would normally be called fairly - early in the ChipPreInit() function for - depths > 8bpp. - - - - It requires that the depth and - display fields of the ScrnInfoRec - be initialised prior to calling it. - - - - The parameters passed are: - - - - weight - - driver's preferred default weight if no other is given. - If zero, use the overall server default. - - - - - mask - - Same, but for mask. - - - - - - - It uses the command line, config file, and default values in the - correct order of precedence to determine the weight value. It - derives the mask and offset values from the weight and the defaults. - It is up to the driver to check the results to see that it supports - them. If not the ChipPreInit() function should - return FALSE. - - - - On success, this function prints a message showing the weight - values selected, and returns TRUE. - - - - On failure it prints an error message and returns FALSE. - - - - The following fields of the ScrnInfoRec are - initialised by this function: - -
- weight, - mask, - offset. -
-
- -
- -
- - Bool xf86SetDefaultVisual(ScrnInfoPtr scrp, int visual); - -
- This function sets the defaultVisual field of the - ScrnInfoRec. It would normally be called fairly - early from the ChipPreInit() function. - - - - It requires that the depth and - display fields of the ScrnInfoRec - be initialised prior to calling it. - - - - The parameters passed are: - - - - visual - - driver's preferred default visual if no other is given. - If -1, use the overall server default. - - - - - - - It uses the command line, config file, and default values in the - correct order of precedence to determine the default visual value. - It is up to the driver to check the result to see that it supports - it. If not the ChipPreInit() function should - return FALSE. - - - - On success, this function prints a message showing the default visual - selected, and returns TRUE. - - - - On failure it prints an error message and returns FALSE. - - -
- -
- - Bool xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma); - -
- This function sets the gamma field of the - ScrnInfoRec. It would normally be called fairly - early from the ChipPreInit() function in cases - where the driver supports gamma correction. - - - - It requires that the monitor field of the - ScrnInfoRec be initialised prior to calling it. - - - - The parameters passed are: - - - - gamma - - driver's preferred default gamma if no other is given. - If zero (< 0.01), use the overall server - default. - - - - - - - It uses the command line, config file, and default values in the - correct order of precedence to determine the gamma value. It is - up to the driver to check the results to see that it supports - them. If not the ChipPreInit() function should - return FALSE. - - - - On success, this function prints a message showing the gamma - value selected, and returns TRUE. - - - - On failure it prints an error message and returns FALSE. - - -
- - -
- - void xf86SetDpi(ScrnInfoPtr pScrn, int x, int y); - -
- This function sets the xDpi and yDpi - fields of the ScrnInfoRec. The driver can specify - preferred defaults by setting x and y - to non-zero values. The command line option - overrides all other settings. Otherwise, if the - DisplaySize entry is present in the screen's &k.monitor; - config file section, it is used together with the virtual size to - calculate the dpi values. This function should be called after - all the mode resolution has been done. - - -
- -
- - const char *xf86GetVisualName(int visual); - -
- Returns a printable string with the visual name matching the - numerical visual class provided. If the value is outside the - range of valid visual classes, NULL is returned. - - -
- -
- - - Primary Mode functions - - -The primary mode helper functions are those which would normally be -used by a driver, unless it has unusual requirements which cannot -be catered for the by the helpers. - - -
- - int xf86ValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, - char **modeNames, ClockRangePtr clockRanges, - int *linePitches, int minPitch, int maxPitch, - int pitchInc, int minHeight, int maxHeight, - int virtualX, int virtualY, - unsigned long apertureSize, - LookupModeFlags strategy); - -
- This function basically selects the set of modes to use based on - those available and the various constraints. It also sets some - other related parameters. It is normally called near the end of - the ChipPreInit() function. - - - - The parameters passed to the function are: - - - - availModes - - List of modes available for the monitor. - - - - modeNames - - List of mode names that the screen is requesting. - - - - clockRanges - - A list of clock ranges allowed by the driver. Each - range includes whether interlaced or multiscan modes - are supported for that range. See below for more on - clockRanges. - - - - linePitches - - List of line pitches supported by the driver. - This is optional and should be NULL when - not used. - - - - minPitch - - Minimum line pitch supported by the driver. This must - be supplied when linePitches is - NULL, and is ignored otherwise. - - - - maxPitch - - Maximum line pitch supported by the driver. This is - required when minPitch is required. - - - - pitchInc - - Granularity of horizontal pitch values as supported by - the chipset. This is expressed in bits. This must be - supplied. - - - - minHeight - - minimum virtual height allowed. If zero, no limit is - imposed. - - - - maxHeight - - maximum virtual height allowed. If zero, no limit is - imposed. - - - - virtualX - - If greater than zero, this is the virtual width value - that will be used. Otherwise, the virtual width is - chosen to be the smallest that can accommodate the modes - selected. - - - - virtualY - - If greater than zero, this is the virtual height value - that will be used. Otherwise, the virtual height is - chosen to be the smallest that can accommodate the modes - selected. - - - - apertureSize - - The size (in bytes) of the aperture used to access video - memory. - - - - strategy - - The strategy to use when choosing from multiple modes - with the same name. The options are: - - - - LOOKUP_DEFAULT - ??? - - - LOOKUP_BEST_REFRESH - mode with best refresh rate - - - LOOKUP_CLOSEST_CLOCK - mode with closest matching clock - - - LOOKUP_LIST_ORDER - first usable mode in list - - - - The following options can also be combined (OR'ed) with - one of the above: - - - - LOOKUP_CLKDIV2 - Allow halved clocks - - - LOOKUP_OPTIONAL_TOLERANCES - - Allow missing horizontal sync and/or vertical refresh - ranges in the xorg.conf Monitor section - - - - LOOKUP_OPTIONAL_TOLERANCES should only be - specified when the driver can ensure all modes it generates - can sync on, or at least not damage, the monitor or digital - flat panel. Horizontal sync and/or vertical refresh ranges - specified by the user will still be honoured (and acted upon). - - - - - - - This function requires that the following fields of the - ScrnInfoRec are initialised prior to calling it: - - - - clock[] - - List of discrete clocks (when non-programmable) - - - numClocks - - Number of discrete clocks (when non-programmable) - - - progClock - - Whether the clock is programmable or not - - - monitor - - Pointer to the applicable xorg.conf monitor section - - - fdFormat - - Format of the screen buffer - - - videoRam - - total video memory size (in bytes) - - - xInc - - Horizontal timing increment in pixels (defaults to 8) - - - - - - This function fills in the following ScrnInfoRec - fields: - - - - modePool - - A subset of the modes available to the monitor which - are compatible with the driver. - - - - modes - - One mode entry for each of the requested modes, with - the status field of each filled in to indicate if - the mode has been accepted or not. This list of - modes is a circular list. - - - - virtualX - - The resulting virtual width. - - - - virtualY - - The resulting virtual height. - - - - displayWidth - - The resulting line pitch. - - - - - - - The first stage of this function checks that the - virtualX and virtualY values - supplied (if greater than zero) are consistent with the line pitch - and maxHeight limitations. If not, an error - message is printed, and the return value is -1. - - - - The second stage sets up the mode pool, eliminating immediately - any modes that exceed the driver's line pitch limits, and also - the virtual width and height limits (if greater than zero). For - each mode removed an informational message is printed at verbosity - level 2. If the mode pool ends up being empty, - a warning message is printed, and the return value is - 0. - - - - The final stage is to lookup each mode name, and fill in the remaining - parameters. If an error condition is encountered, a message is - printed, and the return value is -1. Otherwise, - the return value is the number of valid modes found - (0 if none are found). - - - - Even if the supplied mode names include duplicates, no two names will - ever match the same mode. Furthermore, if the supplied mode names do not - yield a valid mode (including the case where no names are passed at all), - the function will continue looking through the mode pool until it finds - a mode that survives all checks, or until the mode pool is exhausted. - - - - A message is only printed by this function when a fundamental - problem is found. It is intended that this function may be called - more than once if there is more than one set of constraints that - the driver can work within. - - - - If this function returns -1, the - ChipPreInit() function should return - FALSE. - - - - clockRanges is a linked list of clock ranges - allowed by the driver. If a mode doesn't fit in any of the defined - clockRanges, it is rejected. The first - clockRange that matches all requirements is used. - This structure needs to be initialized to NULL when allocated. - - - - clockRanges contains the following fields: - - - - minClock - maxClock - - The lower and upper mode clock bounds for which the rest - of the clockRange parameters apply. - Since these are the mode clocks, they are not scaled - with the ClockMulFactor and - ClockDivFactor. It is up to the driver - to adjust these values if they depend on the clock - scaling factors. - - - - clockIndex - - (not used yet) -1 for programmable clocks - - - - interlaceAllowed - - TRUE if interlacing is allowed for this - range - - - - doubleScanAllowed - - TRUE if doublescan or multiscan is allowed - for this range - - - - ClockMulFactor - ClockDivFactor - - Scaling factors that are applied to the mode clocks ONLY - before selecting a clock index (when there is no - programmable clock) or a SynthClock - value. This is useful for drivers that support pixel - multiplexing or that need to scale the clocks because - of hardware restrictions (like sending 24bpp data to an - 8 bit RAMDAC using a tripled clock). - - - - Note that these parameters describe what must be done - to the mode clock to achieve the data transport clock - between graphics controller and RAMDAC. For example - for 2:1 pixel multiplexing, two pixels - are sent to the RAMDAC on each clock. This allows the - RAMDAC clock to be half of the actual pixel clock. - Hence, ClockMulFactor=1 and - ClockDivFactor=2. This means that the - clock used for clock selection (ie, determining the - correct clock index from the list of discrete clocks) - or for the SynthClock field in case of - a programmable clock is: (mode->Clock * - ClockMulFactor) / ClockDivFactor. - - - - PrivFlags - - This field is copied into the - mode->PrivFlags field when this - clockRange is selected by - xf86ValidateModes(). It allows the - driver to find out what clock range was selected, so it - knows it needs to set up pixel multiplexing or any other - range-dependent feature. This field is purely - driver-defined: it may contain flag bits, an index or - anything else (as long as it is an INT). - - - - - - Note that the mode->SynthClock field is always - filled in by xf86ValidateModes(): it will contain - the data transport clock, which is the clock that will have - to be programmed in the chip when it has a programmable clock, or - the clock that will be picked from the clocks list when it is not - a programmable one. Thus: - - - mode->SynthClock = (mode->Clock * ClockMulFactor) / ClockDivFactor - - - -
- -
- - void xf86PruneDriverModes(ScrnInfoPtr scrp); - -
- This function deletes modes in the modes field of the - ScrnInfoRec that have been marked as invalid. - This is normally run after having run - xf86ValidateModes() for the last time. For each - mode that is deleted, a warning message is printed out indicating - the reason for it being deleted. - - -
- -
- - void xf86SetCrtcForModes(ScrnInfoPtr scrp, int adjustFlags); - -
- This function fills in the Crtc* fields for all - the modes in the modes field of the - ScrnInfoRec. The adjustFlags - parameter determines how the vertical CRTC values are scaled for - interlaced modes. They are halved if it is - INTERLACE_HALVE_V. The vertical CRTC values are - doubled for doublescan modes, and are further multiplied by the - VScan value. - - - - This function is normally called after calling - xf86PruneDriverModes(). - - -
- -
- - void xf86PrintModes(ScrnInfoPtr scrp); - -
- This function prints out the virtual size setting, and the line - pitch being used. It also prints out two lines for each mode being - used. The first line includes the mode's pixel clock, horizontal sync - rate, refresh rate, and whether it is interlaced, doublescanned and/or - multi-scanned. The second line is the mode's Modeline. - - - - This function is normally called after calling - xf86SetCrtcForModes(). - - -
- -
- - - Secondary Mode functions - - -The secondary mode helper functions are functions which are normally -used by the primary mode helper functions, and which are not normally -called directly by a driver. If a driver has unusual requirements -and needs to do its own mode validation, it might be able to make -use of some of these secondary mode helper functions. - - -
- - const char *xf86ModeStatusToString(ModeStatus status); - -
- This function converts the status value to a - descriptive printable string. - - -
- -
- - void xf86DeleteMode(DisplayModePtr *modeList, DisplayModePtr mode); - -
- This function deletes the mode given from the - modeList. It never prints any messages, so it is - up to the caller to print a message if required. - - -
-
- - - Functions for handling strings and tokens - - - Tables associating strings and numerical tokens combined with the - following functions provide a compact way of handling strings from - the config file, and for converting tokens into printable strings. - The table data structure is: - - -typedef struct { - int token; - const char * name; -} SymTabRec, *SymTabPtr; - - - - - A table is an initialised array of SymTabRec. The - tokens must be non-negative integers. Multiple names may be mapped - to a single token. The table is terminated with an element with a - token value of -1 and - NULL for the name. - - -
- - const char *xf86TokenToString(SymTabPtr table, int token); - -
- This function returns the first string in table - that matches token. If no match is found, - NULL is returned (NOTE, older versions of this - function would return the string "unknown" when no match is found). - - -
- -
- - int xf86StringToToken(SymTabPtr table, const char *string); - -
- This function returns the first token in table - that matches string. The - xf86NameCmp() function is used to determine the - match. If no match is found, -1 is returned. - - -
- -
- - - Functions for finding which config file entries to use - - - These functions can be used to select the appropriate config file - entries that match the detected hardware. They are described above - in the Probe and - Available Functions sections. - - - - - - Probing discrete clocks on old hardware - - - The xf86GetClocks() function may be used to assist - in finding the discrete pixel clock values on older hardware. - - -
- - void xf86GetClocks(ScrnInfoPtr pScrn, int num, - Bool (*ClockFunc)(ScrnInfoPtr, int), - void (*ProtectRegs)(ScrnInfoPtr, Bool), - void (*BlankScreen)(ScrnInfoPtr, Bool), - int vertsyncreg, int maskval, int knownclkindex, - int knownclkvalue); - -
- This function uses a comparative sampling method to measure the - discrete pixel clock values. The number of discrete clocks to - measure is given by num. clockFunc - is a function that selects the n'th clock. It - should also save or restore any state affected by programming the - clocks when the index passed is CLK_REG_SAVE or - CLK_REG_RESTORE. ProtectRegs is - a function that does whatever is required to protect the hardware - state while selecting a new clock. BlankScreen - is a function that blanks the screen. vertsyncreg - and maskval are the register and bitmask to - check for the presence of vertical sync pulses. - knownclkindex and knownclkvalue - are the index and value of a known clock. These are the known - references on which the comparative measurements are based. The - number of clocks probed is set in pScrn->numClocks, - and the probed clocks are set in the pScrn->clock[] - array. All of the clock values are in units of kHz. - - -
- -
- - void xf86ShowClocks(ScrnInfoPtr scrp, MessageType from); - -
- Print out the pixel clocks scrp->clock[]. - from indicates whether the clocks were probed - or from the config file. - - -
-
- - - Other helper functions - -
- - Bool xf86IsUnblank(int mode); - -
- Returns TRUE when the screen saver mode specified - by mode requires the screen be unblanked, - and FALSE otherwise. The screen saver modes that - require blanking are SCREEN_SAVER_ON and - SCREEN_SAVER_CYCLE, and the screen saver modes that - require unblanking are SCREEN_SAVER_OFF and - SCREEN_SAVER_FORCER. Drivers may call this helper - from their SaveScreen() function to interpret the - screen saver modes. - - -
-
-
- - - The vgahw module - - -The vgahw modules provides an interface for saving, restoring and -programming the standard VGA registers, and for handling VGA colourmaps. - - - - Data Structures - - - The public data structures used by the vgahw module are - vgaRegRec and vgaHWRec. They are - defined in vgaHW.h. - - - - - - General vgahw Functions - -
- - Bool vgaHWGetHWRec(ScrnInfoPtr pScrn); - -
- This function allocates a vgaHWRec structure, and - hooks it into the ScrnInfoRec's - privates. Like all information hooked into the - privates, it is persistent, and only needs to be - allocated once per screen. This function should normally be called - from the driver's ChipPreInit() function. The - vgaHWRec is zero-allocated, and the following - fields are explicitly initialised: - - - - ModeReg.DAC[] - initialised with a default colourmap - - - ModeReg.Attribute[0x11] - initialised with the default overscan index - - - ShowOverscan - initialised according to the "ShowOverscan" option - - - paletteEnabled - initialised to FALSE - - - cmapSaved - initialised to FALSE - - - pScrn - initialised to pScrn - - - - - - In addition to the above, vgaHWSetStdFuncs() is - called to initialise the register access function fields with the - standard VGA set of functions. - - - - Once allocated, a pointer to the vgaHWRec can be - obtained from the ScrnInfoPtr with the - VGAHWPTR(pScrn) macro. - - -
- -
- - void vgaHWFreeHWRec(ScrnInfoPtr pScrn); - -
- This function frees a vgaHWRec structure. It - should be called from a driver's ChipFreeScreen() - function. - - -
- -
- - Bool vgaHWSetRegCounts(ScrnInfoPtr pScrn, int numCRTC, - int numSequencer, int numGraphics, int numAttribute); - -
- This function allows the number of CRTC, Sequencer, Graphics and - Attribute registers to be changed. This makes it possible for - extended registers to be saved and restored with - vgaHWSave() and vgaHWRestore(). - This function should be called after a vgaHWRec - has been allocated with vgaHWGetHWRec(). The - default values are defined in vgaHW.h as follows: - - -#define VGA_NUM_CRTC 25 -#define VGA_NUM_SEQ 5 -#define VGA_NUM_GFX 9 -#define VGA_NUM_ATTR 21 - - - -
- -
- - Bool vgaHWCopyReg(vgaRegPtr dst, vgaRegPtr src); - -
- This function copies the contents of the VGA saved registers in - src to dst. Note that it isn't - possible to simply do this with memcpy() (or - similar). This function returns TRUE unless there - is a problem allocating space for the CRTC and - related fields in dst. - - -
- -
- - void vgaHWSetStdFuncs(vgaHWPtr hwp); - -
- This function initialises the register access function fields of - hwp with the standard VGA set of functions. This - is called by vgaHWGetHWRec(), so there is usually - no need to call this explicitly. The register access functions - are described below. If the registers are shadowed in some other - port I/O space (for example a PCI I/O region), these functions - can be used to access the shadowed registers if - hwp->PIOOffset is initialised with - offset, calculated in such a way that when the - standard VGA I/O port value is added to it the correct offset into - the PIO area results. This value is initialised to zero in - vgaHWGetHWRec(). (Note: the PIOOffset functionality - is present in XFree86 4.1.0 and later.) - - -
- -
- - void vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset); - -
- This function initialised the register access function fields of - hwp with a generic MMIO set of functions. - hwp->MMIOBase is initialised with - base, which must be the virtual address that the - start of MMIO area is mapped to. hwp->MMIOOffset - is initialised with offset, which must be calculated - in such a way that when the standard VGA I/O port value is added - to it the correct offset into the MMIO area results. That means - that these functions are only suitable when the VGA I/O ports are - made available in a direct mapping to the MMIO space. If that is - not the case, the driver will need to provide its own register - access functions. The register access functions are described - below. - - -
- -
- - Bool vgaHWMapMem(ScrnInfoPtr pScrn); - -
- This function maps the VGA memory window. It requires that the - vgaHWRec be allocated. If a driver requires - non-default MapPhys or MapSize - settings (the physical location and size of the VGA memory window) - then those fields of the vgaHWRec must be initialised - before calling this function. Otherwise, this function initialiases - the default values of 0xA0000 for - MapPhys and (64 * 1024) for - MapSize. This function must be called before - attempting to save or restore the VGA state. If the driver doesn't - call it explicitly, the vgaHWSave() and - vgaHWRestore() functions may call it if they need - to access the VGA memory (in which case they will also call - vgaHWUnmapMem() to unmap the VGA memory before - exiting). - - -
- -
- - void vgaHWUnmapMem(ScrnInfoPtr pScrn); - -
- This function unmaps the VGA memory window. It must only be called - after the memory has been mapped. The Base field - of the vgaHWRec field is set to NULL - to indicate that the memory is no longer mapped. - - -
- -
- - void vgaHWGetIOBase(vgaHWPtr hwp); - -
- This function initialises the IOBase field of the - vgaHWRec. This function must be called before - using any other functions that access the video hardware. - - - - A macro VGAHW_GET_IOBASE() is also available in - vgaHW.h that returns the I/O base, and this may - be used when the vgahw module is not loaded (for example, in the - ChipProbe() function). - - -
- -
- - void vgaHWUnlock(vgaHWPtr hwp); - -
- This function unlocks the VGA CRTC[0-7] registers, - and must be called before attempting to write to those registers. - - -
- -
- - void vgaHWLock(vgaHWPtr hwp); - -
- This function locks the VGA CRTC[0-7] registers. - - -
- -
- - void vgaHWEnable(vgaHWPtr hwp); - -
- This function enables the VGA subsystem. (Note, this function is - present in XFree86 4.1.0 and later.). - - -
- -
- - void vgaHWDisable(vgaHWPtr hwp); - -
- This function disables the VGA subsystem. (Note, this function is - present in XFree86 4.1.0 and later.). - - -
- -
- - void vgaHWSave(ScrnInfoPtr pScrn, vgaRegPtr save, int flags); - -
- This function saves the VGA state. The state is written to the - vgaRegRec pointed to by save. - flags is set to one or more of the following flags - ORed together: - - - - VGA_SR_MODE - the mode setting registers are saved - - - VGA_SR_FONTS - the text mode font/text data is saved - - - VGA_SR_CMAP - the colourmap (LUT) is saved - - - VGA_SR_ALL - all of the above are saved - - - - - - The vgaHWRec and its IOBase fields - must be initialised before this function is called. If - VGA_SR_FONTS is set in flags, the - VGA memory window must be mapped. If it isn't then - vgaHWMapMem() will be called to map it, and - vgaHWUnmapMem() will be called to unmap it - afterwards. vgaHWSave() uses the three functions - below in the order vgaHWSaveColormap(), - vgaHWSaveMode(), vgaHWSaveFonts() to - carry out the different save phases. It is undecided at this - stage whether they will remain part of the vgahw module's public - interface or not. - - -
- -
- - void vgaHWSaveMode(ScrnInfoPtr pScrn, vgaRegPtr save); - -
- This function saves the VGA mode registers. They are saved to - the vgaRegRec pointed to by save. - The registers saved are: - - - MiscOut - CRTC[0-0x18] - Attribute[0-0x14] - Graphics[0-8] - Sequencer[0-4] - - - - - The number of registers actually saved may be modified by a prior call - to vgaHWSetRegCounts(). - - -
- -
- - void vgaHWSaveFonts(ScrnInfoPtr pScrn, vgaRegPtr save); - -
- This function saves the text mode font and text data held in the - video memory. If called while in a graphics mode, no save is - done. The VGA memory window must be mapped with - vgaHWMapMem() before to calling this function. - - - - On some platforms, one or more of the font/text plane saves may be - no-ops. This is the case when the platform's VC driver already - takes care of this. - - -
- -
- - void vgaHWSaveColormap(ScrnInfoPtr pScrn, vgaRegPtr save); - -
- This function saves the VGA colourmap (LUT). Before saving it, it - attempts to verify that the colourmap is readable. In rare cases - where it isn't readable, a default colourmap is saved instead. - - -
- -
- - void vgaHWRestore(ScrnInfoPtr pScrn, vgaRegPtr restore, int flags); - -
- This function programs the VGA state. The state programmed is - that contained in the vgaRegRec pointed to by - restore. flags is the same - as described above for the vgaHWSave() function. - - - - The vgaHWRec and its IOBase fields - must be initialised before this function is called. If - VGA_SR_FONTS is set in flags, the - VGA memory window must be mapped. If it isn't then - vgaHWMapMem() will be called to map it, and - vgaHWUnmapMem() will be called to unmap it - afterwards. vgaHWRestore() uses the three functions - below in the order vgaHWRestoreFonts(), - vgaHWRestoreMode(), - vgaHWRestoreColormap() to carry out the different - restore phases. It is undecided at this stage whether they will - remain part of the vgahw module's public interface or not. - - -
- -
- - void vgaHWRestoreMode(ScrnInfoPtr pScrn, vgaRegPtr restore); - -
- This function restores the VGA mode registers. They are restored - from the data in the vgaRegRec pointed to by - restore. The registers restored are: - - - MiscOut - CRTC[0-0x18] - Attribute[0-0x14] - Graphics[0-8] - Sequencer[0-4] - - - - - The number of registers actually restored may be modified by a prior call - to vgaHWSetRegCounts(). - - -
- -
- - void vgaHWRestoreFonts(ScrnInfoPtr pScrn, vgaRegPtr restore); - -
- This function restores the text mode font and text data to the - video memory. The VGA memory window must be mapped with - vgaHWMapMem() before to calling this function. - - - - On some platforms, one or more of the font/text plane restores - may be no-ops. This is the case when the platform's VC driver - already takes care of this. - - -
- -
- - void vgaHWRestoreColormap(ScrnInfoPtr pScrn, vgaRegPtr restore); - -
- This function restores the VGA colourmap (LUT). - - -
- -
- - void vgaHWInit(ScrnInfoPtr pScrn, DisplayModePtr mode); - -
- This function fills in the vgaHWRec's - ModeReg field with the values appropriate for - programming the given video mode. It requires that the - ScrnInfoRec's depth field is - initialised, which determines how the registers are programmed. - - -
- -
- - void vgaHWSeqReset(vgaHWPtr hwp, Bool start); - -
- Do a VGA sequencer reset. If start is TRUE, the - reset is started. If start is FALSE, the reset - is ended. - - -
- -
- - void vgaHWProtect(ScrnInfoPtr pScrn, Bool on); - -
- This function protects VGA registers and memory from corruption - during loads. It is typically called with on set to - TRUE before programming, and with on set to - FALSE after programming. - - -
- -
- - Bool vgaHWSaveScreen(ScreenPtr pScreen, int mode); - -
- This function blanks and unblanks the screen. It is blanked when - mode is SCREEN_SAVER_ON or - SCREEN_SAVER_CYCLE, and unblanked when - mode is SCREEN_SAVER_OFF or - SCREEN_SAVER_FORCER. - - -
- -
- - void vgaHWBlankScreen(ScrnInfoPtr pScrn, Bool on); - -
- This function blanks and unblanks the screen. It is blanked when - on is FALSE, and unblanked when - on is TRUE. This function is - provided for use in cases where the ScrnInfoRec - can't be derived from the ScreenRec (while probing - for clocks, for example). - - -
- -
- - - VGA Colormap Functions - - - The vgahw module uses the standard colormap support (see the - Colormap Handling section. This is initialised - with the following function: - -
- - Bool vgaHWHandleColormaps(ScreenPtr pScreen); - -
-
- -
- - - VGA Register Access Functions - - - The vgahw module abstracts access to the standard VGA registers by - using a set of functions held in the vgaHWRec. When - the vgaHWRec is created these function pointers are - initialised with the set of standard VGA I/O register access functions. - In addition to these, the vgahw module includes a basic set of MMIO - register access functions, and the vgaHWRec function - pointers can be initialised to these by calling the - vgaHWSetMmioFuncs() function described above. Some - drivers/platforms may require a different set of functions for VGA - access. The access functions are described here. - - - -
- - void writeCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value); - -
- Write value to CRTC register index. - - -
- -
- - CARD8 readCrtc(vgaHWPtr hwp, CARD8 index); - -
- Return the value read from CRTC register index. - - -
- -
- - void writeGr(vgaHWPtr hwp, CARD8 index, CARD8 value); - -
- Write value to Graphics Controller register - index. - - -
- -
- - CARD8 readGR(vgaHWPtr hwp, CARD8 index); - -
- Return the value read from Graphics Controller register - index. - - -
- -
- - void writeSeq(vgaHWPtr hwp, CARD8 index, CARD8, value); - -
- Write value to Sequencer register - index. - - -
- -
- - CARD8 readSeq(vgaHWPtr hwp, CARD8 index); - -
- Return the value read from Sequencer register index. - - -
- -
- - void writeAttr(vgaHWPtr hwp, CARD8 index, CARD8, value); - -
- Write value to Attribute Controller register - index. When writing out the index value this - function should set bit 5 (0x20) according to the - setting of hwp->paletteEnabled in order to - preserve the palette access state. It should be cleared when - hwp->paletteEnabled is TRUE - and set when it is FALSE. - - -
- -
- - CARD8 readAttr(vgaHWPtr hwp, CARD8 index); - -
- Return the value read from Attribute Controller register - index. When writing out the index value this - function should set bit 5 (0x20) according to the - setting of hwp->paletteEnabled in order to - preserve the palette access state. It should be cleared when - hwp->paletteEnabled is TRUE - and set when it is FALSE. - - -
- -
- - void writeMiscOut(vgaHWPtr hwp, CARD8 value); - -
- Write value to the Miscellaneous Output register. - - -
- -
- - CARD8 readMiscOut(vgwHWPtr hwp); - -
- Return the value read from the Miscellaneous Output register. - - -
- -
- - void enablePalette(vgaHWPtr hwp); - -
- Clear the palette address source bit in the Attribute Controller - index register and set hwp->paletteEnabled to - TRUE. - - -
- -
- - void disablePalette(vgaHWPtr hwp); - -
- Set the palette address source bit in the Attribute Controller - index register and set hwp->paletteEnabled to - FALSE. - - -
- -
- - void writeDacMask(vgaHWPtr hwp, CARD8 value); - -
- Write value to the DAC Mask register. - - -
- -
- - CARD8 readDacMask(vgaHWptr hwp); - -
- Return the value read from the DAC Mask register. - - -
- -
- - void writeDacReadAddress(vgaHWPtr hwp, CARD8 value); - -
- Write value to the DAC Read Address register. - - -
- -
- - void writeDacWriteAddress(vgaHWPtr hwp, CARD8 value); - -
- Write value to the DAC Write Address register. - - -
- -
- - void writeDacData(vgaHWPtr hwp, CARD8 value); - -
- Write value to the DAC Data register. - - -
- -
- - CARD8 readDacData(vgaHWptr hwp); - -
- Return the value read from the DAC Data register. - - -
- -
- - CARD8 readEnable(vgaHWptr hwp); - -
- Return the value read from the VGA Enable register. (Note: This - function is present in XFree86 4.1.0 and later.) - - -
- -
- - void writeEnable(vgaHWPtr hwp, CARD8 value); - -
- Write value to the VGA Enable register. (Note: This - function is present in XFree86 4.1.0 and later.) - - -
-
-
- - - Some notes about writing a driver - - NOTE: some parts of this are not up to date - - -The following is an outline for writing a basic unaccelerated driver -for a PCI video card with a linear mapped framebuffer, and which has a -VGA core. It is includes some general information that is relevant to -most drivers (even those which don't fit that basic description). - - - -The information here is based on the initial conversion of the Matrox -Millennium driver to the new design. For a fleshing out and sample -implementation of some of the bits outlined here, refer to that driver. -Note that this is an example only. The approach used here will not be -appropriate for all drivers. - - - -Each driver must reserve a unique driver name, and a string that is used -to prefix all of its externally visible symbols. This is to avoid name -space clashes when loading multiple drivers. The examples here are for -the ZZZ driver, which uses the ZZZ or zzz prefix for its externally -visible symbols. - - - - Include files - - - All drivers normally include the following headers: - - "xf86.h" - "xf86_OSproc.h" - "xf86_ansic.h" - "xf86Resources.h" - - Wherever inb/outb (and related things) are used the following should be - included: - - "compiler.h" - - Note: in drivers, this must be included after "xf86_ansic.h". - - - - Drivers that need to access PCI vendor/device definitions need this: - - "xf86PciInfo.h" - - - - - Drivers that need to access the PCI config space need this: - - "xf86Pci.h" - - - - - Drivers using the mi banking wrapper need: - - - "mibank.h" - - - - - Drivers that initialise a SW cursor need this: - - "mipointer.h" - - - - - All drivers using the mi colourmap code need this: - - "micmap.h" - - - - - If a driver uses the vgahw module, it needs this: - - "vgaHW.h" - - - - - Drivers supporting VGA or Hercules monochrome screens need: - - "xf1bpp.h" - - - - - Drivers supporting VGA or EGC 16-colour screens need: - - "xf4bpp.h" - - - - - Drivers using cfb need: - - #define PSZ 8 - #include "cfb.h" - #undef PSZ - - - - - Drivers supporting bpp 16, 24 or 32 with cfb need one or more of: - - "cfb16.h" - "cfb24.h" - "cfb32.h" - - - - - The driver's own header file: - - "zzz.h" - - - - - Drivers must NOT include the following: - - - "xf86Priv.h" - "xf86Privstr.h" - "xf86_libc.h" - "xf86_OSlib.h" - "Xos.h" - any OS header - - - - - - - Data structures and initialisation - - - - The following macros should be defined: - -#define VERSION <version-as-an-int> -#define ZZZ_NAME "ZZZ" /* the name used to prefix messages */ -#define ZZZ_DRIVER_NAME "zzz" /* the driver name as used in config file */ -#define ZZZ_MAJOR_VERSION <int> -#define ZZZ_MINOR_VERSION <int> -#define ZZZ_PATCHLEVEL <int> - - - - NOTE: ZZZ_DRIVER_NAME should match the name of the - driver module without things like the "lib" prefix, the "_drv" suffix - or filename extensions. - - - - - - A DriverRec must be defined, which includes the functions required - at the pre-probe phase. The name of this DriverRec must be an - upper-case version of ZZZ_DRIVER_NAME (for the purposes of static - linking). - -DriverRec ZZZ = { - VERSION, - ZZZ_DRIVER_NAME, - ZZZIdentify, - ZZZProbe, - ZZZAvailableOptions, - NULL, - 0 -}; - - - - - - Define list of supported chips and their matching ID: - -static SymTabRec ZZZChipsets[] = { - { PCI_CHIP_ZZZ1234, "zzz1234a" }, - { PCI_CHIP_ZZZ5678, "zzz5678a" }, - { -1, NULL } -}; - - - - The token field may be any integer value that the driver may use to - uniquely identify the supported chipsets. For drivers that support - only PCI devices using the PCI device IDs might be a natural choice, - but this isn't mandatory. For drivers that support both PCI and other - devices (like ISA), some other ID should probably used. When other - IDs are used as the tokens it is recommended that the names be - defined as an enum type. - - - - - - If the driver uses the xf86MatchPciInstances() - helper (recommended for drivers that support PCI cards) a list that - maps PCI IDs to chip IDs and fixed resources must be defined: - -static PciChipsets ZZZPciChipsets[] = { - { PCI_CHIP_ZZZ1234, PCI_CHIP_ZZZ1234, RES_SHARED_VGA }, - { PCI_CHIP_ZZZ5678, PCI_CHIP_ZZZ5678, RES_SHARED_VGA }, - { -1, -1, RES_UNDEFINED } -} - - - - - - - Define the XF86ModuleVersionInfo struct for the - driver. This is required for the dynamically loaded version: - -static XF86ModuleVersionInfo zzzVersRec = -{ - "zzz", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XF86_VERSION_CURRENT, - ZZZ_MAJOR_VERSION, ZZZ_MINOR_VERSION, ZZZ_PATCHLEVEL, - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0,0,0,0} -}; - - - - - - - Define a data structure to hold the driver's screen-specific data. - This must be used instead of global variables. This would be defined - in the "zzz.h" file, something like: - -typedef struct { - type1 field1; - type2 field2; - int fooHack; - Bool pciRetry; - Bool noAccel; - Bool hwCursor; - CloseScreenProcPtr CloseScreen; - OptionInfoPtr Options; - ... -} ZZZRec, *ZZZPtr; - - - - - - - Define the list of config file Options that the driver accepts. For - consistency between drivers those in the list of standard options - should be used where appropriate before inventing new options. - - -typedef enum { - OPTION_FOO_HACK, - OPTION_PCI_RETRY, - OPTION_HW_CURSOR, - OPTION_NOACCEL -} ZZZOpts; - -static const OptionInfoRec ZZZOptions[] = { - { OPTION_FOO_HACK, "FooHack", OPTV_INTEGER, {0}, FALSE }, - { OPTION_PCI_RETRY, "PciRetry", OPTV_BOOLEAN, {0}, FALSE }, - { OPTION_HW_CURSOR, "HWcursor", OPTV_BOOLEAN, {0}, FALSE }, - { OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE }, - { -1, NULL, OPTV_NONE, {0}, FALSE } -}; - - - - - - - - Functions - - - - SetupProc - - - For dynamically loaded modules, a ModuleData - variable is required. It is should be the name of the driver - prepended to "ModuleData". A Setup() function is - also required, which calls xf86AddDriver() to add - the driver to the main list of drivers. - - - -static MODULESETUPPROTO(zzzSetup); - -XF86ModuleData zzzModuleData = { &zzzVersRec, zzzSetup, NULL }; - -static pointer -zzzSetup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = FALSE; - - /* This module should be loaded only once, but check to be sure. */ - - if (!setupDone) { - /* - * Modules that this driver always requires may be loaded - * here by calling LoadSubModule(). - */ - - setupDone = TRUE; - xf86AddDriver(&MGA, module, 0); - - /* - * The return value must be non-NULL on success even though - * there is no TearDownProc. - */ - return (pointer)1; - } else { - if (errmaj) *errmaj = LDR_ONCEONLY; - return NULL; - } -} - - - - - GetRec, FreeRec - - - A function is usually required to allocate the driver's - screen-specific data structure and hook it into the - ScrnInfoRec's driverPrivate field. - The ScrnInfoRec's driverPrivate is - initialised to NULL, so it is easy to check if the - initialisation has already been done. After allocating it, initialise - the fields. By using xnfcalloc() to do the allocation - it is zeroed, and if the allocation fails the server exits. - - - - NOTE: - When allocating structures from inside the driver which are defined - on the common level it is important to initialize the structure to - zero. - Only this guarantees that the server remains source compatible to - future changes in common level structures. - - - -static Bool -ZZZGetRec(ScrnInfoPtr pScrn) -{ - if (pScrn->driverPrivate != NULL) - return TRUE; - pScrn->driverPrivate = xnfcalloc(sizeof(ZZZRec), 1); - /* Initialise as required */ - ... - return TRUE; -} - - - - Define a macro in "zzz.h" which gets a pointer to - the ZZZRec when given pScrn: - - -#define ZZZPTR(p) ((ZZZPtr)((p)->driverPrivate)) - - - - - Define a function to free the above, setting it to NULL - once it has been freed: - - -static void -ZZZFreeRec(ScrnInfoPtr pScrn) -{ - if (pScrn->driverPrivate == NULL) - return; - xfree(pScrn->driverPrivate); - pScrn->driverPrivate = NULL; -} - - - - - - Identify - - - Define the Identify() function. It is run before - the Probe, and typically prints out an identifying message, which - might include the chipsets it supports. This function is mandatory: - - -static void -ZZZIdentify(int flags) -{ - xf86PrintChipsets(ZZZ_NAME, "driver for ZZZ Tech chipsets", - ZZZChipsets); -} - - - - - - Probe - - - Define the Probe() function. The purpose of this - is to find all instances of the hardware that the driver supports, - and for the ones not already claimed by another driver, claim the - slot, and allocate a ScrnInfoRec. This should be - a minimal probe, and it should under no circumstances leave the - state of the hardware changed. Because a device is found, don't - assume that it will be used. Don't do any initialisations other - than the required ScrnInfoRec initialisations. - Don't allocate any new data structures. - - - - This function is mandatory. - - - - NOTE: The xf86DrvMsg() functions cannot be used from - the Probe. - - - -static Bool -ZZZProbe(DriverPtr drv, int flags) -{ - Bool foundScreen = FALSE; - int numDevSections, numUsed; - GDevPtr *devSections; - int *usedChips; - int i; - - /* - * Find the config file Device sections that match this - * driver, and return if there are none. - */ - if ((numDevSections = xf86MatchDevice(ZZZ_DRIVER_NAME, - &devSections)) <= 0) { - return FALSE; - } - - /* - * Since this is a PCI card, "probing" just amounts to checking - * the PCI data that the server has already collected. If there - * is none, return. - * - * Although the config file is allowed to override things, it - * is reasonable to not allow it to override the detection - * of no PCI video cards. - * - * The provided xf86MatchPciInstances() helper takes care of - * the details. - */ - /* test if PCI bus present */ - if (xf86GetPciVideoInfo()) { - - numUsed = xf86MatchPciInstances(ZZZ_NAME, PCI_VENDOR_ZZZ, - ZZZChipsets, ZZZPciChipsets, devSections, - numDevSections, drv, &usedChips); - - for (i = 0; i < numUsed; i++) { - ScrnInfoPtr pScrn = NULL; - if ((pScrn = xf86ConfigPciEntity(pScrn, flags, usedChips[i], - ZZZPciChipsets, NULL, NULL, - NULL, NULL, NULL))) { - /* Allocate a ScrnInfoRec */ - pScrn->driverVersion = VERSION; - pScrn->driverName = ZZZ_DRIVER_NAME; - pScrn->name = ZZZ_NAME; - pScrn->Probe = ZZZProbe; - pScrn->PreInit = ZZZPreInit; - pScrn->ScreenInit = ZZZScreenInit; - pScrn->SwitchMode = ZZZSwitchMode; - pScrn->AdjustFrame = ZZZAdjustFrame; - pScrn->EnterVT = ZZZEnterVT; - pScrn->LeaveVT = ZZZLeaveVT; - pScrn->FreeScreen = ZZZFreeScreen; - pScrn->ValidMode = ZZZValidMode; - foundScreen = TRUE; - /* add screen to entity */ - } - } - xfree(usedChips); - } - - xfree(devSections); - return foundScreen; - - - - - AvailableOptions - - - Define the AvailableOptions() function. The purpose - of this is to return the available driver options back to the - -configure option, so that an xorg.conf file can be built and the - user can see which options are available for them to use. - - - - - PreInit - - - Define the PreInit() function. The purpose of - this is to find all the information required to determine if the - configuration is usable, and to initialise those parts of the - ScrnInfoRec that can be set once at the beginning - of the first server generation. The information should be found in - the least intrusive way possible. - - - - This function is mandatory. - - - - NOTES: - - - The PreInit() function is only called once - during the life of the X server (at the start of the first - generation). - - - - Data allocated here must be of the type that persists for - the life of the X server. This means that data that hooks into - the ScrnInfoRec's privates - field should be allocated here, but data that hooks into the - ScreenRec's devPrivates field - should not be allocated here. The driverPrivate - field should also be allocated here. - - - - Although the ScrnInfoRec has been allocated - before this function is called, the ScreenRec - has not been allocated. That means that things requiring it - cannot be used in this function. - - - - Very little of the ScrnInfoRec has been - initialised when this function is called. It is important to - get the order of doing things right in this function. - - - - - - -static Bool -ZZZPreInit(ScrnInfoPtr pScrn, int flags) -{ - /* Fill in the monitor field */ - pScrn->monitor = pScrn->confScreen->monitor; - - /* - * If using the vgahw module, it will typically be loaded - * here by calling xf86LoadSubModule(pScrn, "vgahw"); - */ - - /* - * Set the depth/bpp. Use the globally preferred depth/bpp. If the - * driver has special default depth/bpp requirements, the defaults should - * be specified here explicitly. - * We support both 24bpp and 32bpp framebuffer layouts. - * This sets pScrn->display also. - */ - if (!xf86SetDepthBpp(pScrn, 0, 0, 0, - Support24bppFb | Support32bppFb)) { - return FALSE; - } else { - if (depth/bpp isn't one we support) { - print error message; - return FALSE; - } - } - /* Print out the depth/bpp that was set */ - xf86PrintDepthBpp(pScrn); - - /* Set bits per RGB for 8bpp */ - if (pScrn->depth <= 8) { - /* Take into account a dac_6_bit option here */ - pScrn->rgbBits = 6 or 8; - } - - /* - * xf86SetWeight() and xf86SetDefaultVisual() must be called - * after pScrn->display is initialised. - */ - - /* Set weight/mask/offset for depth > 8 */ - if (pScrn->depth > 8) { - if (!xf86SetWeight(pScrn, defaultWeight, defaultMask)) { - return FALSE; - } else { - if (weight isn't one we support) { - print error message; - return FALSE; - } - } - } - - /* Set the default visual. */ - if (!xf86SetDefaultVisual(pScrn, -1)) { - return FALSE; - } else { - if (visual isn't one we support) { - print error message; - return FALSE; - } - } - - /* If the driver supports gamma correction, set the gamma. */ - if (!xf86SetGamma(pScrn, default_gamma)) { - return FALSE; - } - - /* This driver uses a programmable clock */ - pScrn->progClock = TRUE; - - /* Allocate the ZZZRec driverPrivate */ - if (!ZZZGetRec(pScrn)) { - return FALSE; - } - - pZzz = ZZZPTR(pScrn); - - /* Collect all of the option flags (fill in pScrn->options) */ - xf86CollectOptions(pScrn, NULL); - - /* - * Process the options based on the information in ZZZOptions. - * The results are written to pZzz->Options. If all of the options - * processing is done within this function a local variable "options" - * can be used instead of pZzz->Options. - */ - if (!(pZzz->Options = xalloc(sizeof(ZZZOptions)))) - return FALSE; - (void)memcpy(pZzz->Options, ZZZOptions, sizeof(ZZZOptions)); - xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pZzz->Options); - - /* - * Set various fields of ScrnInfoRec and/or ZZZRec based on - * the options found. - */ - from = X_DEFAULT; - pZzz->hwCursor = FALSE; - if (xf86IsOptionSet(pZzz->Options, OPTION_HW_CURSOR)) { - from = X_CONFIG; - pZzz->hwCursor = TRUE; - } - xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n", - pZzz->hwCursor ? "HW" : "SW"); - if (xf86IsOptionSet(pZzz->Options, OPTION_NOACCEL)) { - pZzz->noAccel = TRUE; - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, - "Acceleration disabled\n"); - } else { - pZzz->noAccel = FALSE; - } - if (xf86IsOptionSet(pZzz->Options, OPTION_PCI_RETRY)) { - pZzz->UsePCIRetry = TRUE; - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "PCI retry enabled\n"); - } - pZzz->fooHack = 0; - if (xf86GetOptValInteger(pZzz->Options, OPTION_FOO_HACK, - &pZzz->fooHack)) { - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Foo Hack set to %d\n", - pZzz->fooHack); - } - - /* - * Find the PCI slot(s) that this screen claimed in the probe. - * In this case, exactly one is expected, so complain otherwise. - * Note in this case we're not interested in the card types so - * that parameter is set to NULL. - */ - if ((i = xf86GetPciInfoForScreen(pScrn->scrnIndex, &pciList, NULL)) - != 1) { - print error message; - ZZZFreeRec(pScrn); - if (i > 0) - xfree(pciList); - return FALSE; - } - /* Note that pciList should be freed below when no longer needed */ - - /* - * Determine the chipset, allowing config file chipset and - * chipid values to override the probed information. The config - * chipset value has precedence over its chipid value if both - * are present. - * - * It isn't necessary to fill in pScrn->chipset if the driver - * keeps track of the chipset in its ZZZRec. - */ - - ... - - /* - * Determine video memory, fb base address, I/O addresses, etc, - * allowing the config file to override probed values. - * - * Set the appropriate pScrn fields (videoRam is probably the - * most important one that other code might require), and - * print out the settings. - */ - - ... - - /* Initialise a clockRanges list. */ - - ... - - /* Set any other chipset specific things in the ZZZRec */ - - ... - - /* Select valid modes from those available */ - - i = xf86ValidateModes(pScrn, pScrn->monitor->Modes, - pScrn->display->modes, clockRanges, - NULL, minPitch, maxPitch, rounding, - minHeight, maxHeight, - pScrn->display->virtualX, - pScrn->display->virtualY, - pScrn->videoRam * 1024, - LOOKUP_BEST_REFRESH); - if (i == -1) { - ZZZFreeRec(pScrn); - return FALSE; - } - - /* Prune the modes marked as invalid */ - - xf86PruneDriverModes(pScrn); - - /* If no valid modes, return */ - - if (i == 0 || pScrn->modes == NULL) { - print error message; - ZZZFreeRec(pScrn); - return FALSE; - } - - /* - * Initialise the CRTC fields for the modes. This driver expects - * vertical values to be halved for interlaced modes. - */ - xf86SetCrtcForModes(pScrn, INTERLACE_HALVE_V); - - /* Set the current mode to the first in the list. */ - pScrn->currentMode = pScrn->modes; - - /* Print the list of modes being used. */ - xf86PrintModes(pScrn); - - /* Set the DPI */ - xf86SetDpi(pScrn, 0, 0); - - /* Load bpp-specific modules */ - switch (pScrn->bitsPerPixel) { - case 1: - mod = "xf1bpp"; - break; - case 4: - mod = "xf4bpp"; - break; - case 8: - mod = "cfb"; - break; - case 16: - mod = "cfb16"; - break; - case 24: - mod = "cfb24"; - break; - case 32: - mod = "cfb32"; - break; - } - if (mod && !xf86LoadSubModule(pScrn, mod)) - ZZZFreeRec(pScrn); - return FALSE; - - - /* Done */ - return TRUE; -} - - - - - MapMem, UnmapMem - - - Define functions to map and unmap the video memory and any other - memory apertures required. These functions are not mandatory, but - it is often useful to have such functions. - - - -static Bool -ZZZMapMem(ScrnInfoPtr pScrn) -{ - /* Call xf86MapPciMem() to map each PCI memory area */ - ... - return TRUE or FALSE; -} - -static Bool -ZZZUnmapMem(ScrnInfoPtr pScrn) -{ - /* Call xf86UnMapVidMem() to unmap each memory area */ - ... - return TRUE or FALSE; -} - - - - - Save, Restore - - - Define functions to save and restore the original video state. These - functions are not mandatory, but are often useful. - - - -static void -ZZZSave(ScrnInfoPtr pScrn) -{ - /* - * Save state into per-screen data structures. - * If using the vgahw module, vgaHWSave will typically be - * called here. - */ - ... -} - -static void -ZZZRestore(ScrnInfoPtr pScrn) -{ - /* - * Restore state from per-screen data structures. - * If using the vgahw module, vgaHWRestore will typically be - * called here. - */ - ... -} - - - - - ModeInit - - - Define a function to initialise a new video mode. This function isn't - mandatory, but is often useful. - - - -static Bool -ZZZModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - /* - * Program a video mode. If using the vgahw module, - * vgaHWInit and vgaRestore will typically be called here. - * Once up to the point where there can't be a failure - * set pScrn->vtSema to TRUE. - */ - ... -} - - - - - ScreenInit - - - Define the ScreenInit() function. This is called - at the start of each server generation, and should fill in as much - of the ScreenRec as possible as well as any other - data that is initialised once per generation. It should initialise - the framebuffer layers it is using, and initialise the initial video - mode. - - - - This function is mandatory. - - - - NOTE: The ScreenRec (pScreen) is - passed to this driver, but it and the - ScrnInfoRecs are not yet hooked into each - other. This means that in this function, and functions it - calls, one cannot be found from the other. - - - -static Bool -ZZZScreenInit(ScreenPtr pScreen, int argc, char **argv) -{ - /* Get the ScrnInfoRec */ - pScrn = xf86ScreenToScrn(pScreen); - - /* - * If using the vgahw module, its data structures and related - * things are typically initialised/mapped here. - */ - - /* Save the current video state */ - ZZZSave(pScrn); - - /* Initialise the first mode */ - ZZZModeInit(pScrn, pScrn->currentMode); - - /* Set the viewport if supported */ - - ZZZAdjustFrame(pScrn, pScrn->frameX0, pScrn->frameY0); - - /* - * Setup the screen's visuals, and initialise the framebuffer - * code. - */ - - /* 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; - } - - /* - * Initialise the framebuffer. - */ - - switch (pScrn->bitsPerPixel) { - case 1: - ret = xf1bppScreenInit(pScreen, FbBase, - pScrn->virtualX, pScrn->virtualY, - pScrn->xDpi, pScrn->yDpi, - pScrn->displayWidth); - break; - case 4: - ret = xf4bppScreenInit(pScreen, FbBase, - pScrn->virtualX, pScrn->virtualY, - pScrn->xDpi, pScrn->yDpi, - pScrn->displayWidth); - break; - case 8: - ret = cfbScreenInit(pScreen, FbBase, - pScrn->virtualX, pScrn->virtualY, - pScrn->xDpi, pScrn->yDpi, - pScrn->displayWidth); - break; - case 16: - ret = cfb16ScreenInit(pScreen, FbBase, - pScrn->virtualX, pScrn->virtualY, - pScrn->xDpi, pScrn->yDpi, - pScrn->displayWidth); - break; - case 24: - ret = cfb24ScreenInit(pScreen, FbBase, - pScrn->virtualX, pScrn->virtualY, - pScrn->xDpi, pScrn->yDpi, - pScrn->displayWidth); - break; - case 32: - ret = cfb32ScreenInit(pScreen, FbBase, - pScrn->virtualX, pScrn->virtualY, - pScrn->xDpi, pScrn->yDpi, - pScrn->displayWidth); - break; - default: - print a message about an internal error; - ret = FALSE; - break; - } - - if (!ret) - return FALSE; - - /* Override the default mask/offset settings */ - if (pScrn->bitsPerPixel > 8) { - 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; - } - } - } - - /* - * If banking is needed, initialise an miBankInfoRec (defined in - * "mibank.h"), and call miInitializeBanking(). - */ - if (!miInitializeBanking(pScreen, pScrn->virtualX, pScrn->virtualY, - pScrn->displayWidth, pBankInfo)) - return FALSE; - - /* - * Set initial black & white colourmap indices. - */ - xf86SetBlackWhitePixels(pScreen); - - /* - * Install colourmap functions. - */ - - ... - - /* - * Initialise cursor functions. This example is for the mi - * software cursor. - */ - miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); - - /* Initialise the default colourmap */ - switch (pScrn->depth) { - case 1: - if (!xf1bppCreateDefColormap(pScreen)) - return FALSE; - break; - case 4: - if (!xf4bppCreateDefColormap(pScreen)) - return FALSE; - break; - default: - if (!cfbCreateDefColormap(pScreen)) - return FALSE; - break; - } - - /* - * Wrap the CloseScreen vector and set SaveScreen. - */ - ZZZPTR(pScrn)->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = ZZZCloseScreen; - pScreen->SaveScreen = ZZZSaveScreen; - - /* Report any unused options (only for the first generation) */ - if (serverGeneration == 1) { - xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); - } - - /* Done */ - return TRUE; -} - - - - - SwitchMode - - - Define the SwitchMode() function if mode switching - is supported by the driver. - - - -static Bool -ZZZSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - return ZZZModeInit(pScrn, mode); -} - - - - - AdjustFrame - - - Define the AdjustFrame() function if the driver - supports this. - - - -static void -ZZZAdjustFrame(ScrnInfoPtr pScrn, int x, int y) -{ - /* Adjust the viewport */ -} - - - - - EnterVT, LeaveVT - - - Define the EnterVT() and LeaveVT() - functions. - - - - These functions are mandatory. - - - -static Bool -ZZZEnterVT(ScrnInfoPtr pScrn) -{ - return ZZZModeInit(pScrn, pScrn->currentMode); -} - -static void -ZZZLeaveVT(ScrnInfoPtr pScrn) -{ - ZZZRestore(pScrn); -} - - - - - CloseScreen - - - Define the CloseScreen() function: - - - - This function is mandatory. Note that it unwraps the previously - wrapped pScreen->CloseScreen, and finishes by - calling it. - - - -static Bool -ZZZCloseScreen(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - if (pScrn->vtSema) { - ZZZRestore(pScrn); - ZZZUnmapMem(pScrn); - } - pScrn->vtSema = FALSE; - pScreen->CloseScreen = ZZZPTR(pScrn)->CloseScreen; - return (*pScreen->CloseScreen)(pScreen); -} - - - - - SaveScreen - - - Define the SaveScreen() function (the screen - blanking function). When using the vgahw module, this will typically - be: - - -static Bool -ZZZSaveScreen(ScreenPtr pScreen, int mode) -{ - return vgaHWSaveScreen(pScreen, mode); -} - - - - - This function is mandatory. Before modifying any hardware register - directly this function needs to make sure that the Xserver is active - by checking if pScrn is non-NULL and for - pScrn->vtSema == TRUE. - - - - - FreeScreen - - - Define the FreeScreen() function. This function - is optional. It should be defined if the ScrnInfoRec - driverPrivate field is used so that it can be freed - when a screen is deleted by the common layer for reasons possibly - beyond the driver's control. This function is not used in during - normal (error free) operation. The per-generation data is freed by - the CloseScreen() function. - - - -static void -ZZZFreeScreen(ScrnInfoPtr pScrn) -{ - /* - * If the vgahw module is used vgaHWFreeHWRec() would be called - * here. - */ - ZZZFreeRec(pScrn); -} - - - - - - - - - -
diff --git a/hw/xfree86/doc/exa-driver.txt b/hw/xfree86/doc/exa-driver.txt deleted file mode 100644 index da39d3f91..000000000 --- a/hw/xfree86/doc/exa-driver.txt +++ /dev/null @@ -1,89 +0,0 @@ -Adding EXA support to your X.Org video driver ---------------------------------------------- -EXA (for EXcellent Architecture or Ex-kaa aXeleration Architecture or -whatever) aims to extend the life of the venerable XFree86 video drivers by -introducing a new set of acceleration hooks that efficiently accelerate the X -Render extension, including solid fills, blits within screen memory and to and -from system memory, and Porter-Duff compositing and transform operations. - -Configuration -------------- -Some drivers implement a per-instance useEXA flag to track whether EXA is -active or not. - -Setting the flag can be done in the driver's Options parsing routine. - -Loading EXA ------------- -EXA drivers in the XFree86 DDX should use the loadable module loader to load -the EXA core. Careful versioning allows the EXA API to be extended without -breaking the ABI for older versions of drivers. Example code for loading EXA: - -static const char *exaSymbols[] = { - "exaDriverAlloc", - "exaDriverInit", - "exaDriverFini", - "exaOffscreenAlloc", - "exaOffscreenFree", - "exaGetPixmapOffset", - "exaGetPixmapPitch", - "exaGetPixmapSize", - "exaMarkSync", - "exaWaitSync", - NULL -}; - - if (info->useEXA) { - info->exaReq.majorversion = 2; - info->exaReq.minorversion = 0; - - if (!LoadSubModule(pScrn->module, "exa", NULL, NULL, NULL, - &info->exaReq, &errmaj, &errmin)) { - LoaderErrorMsg(NULL, "exa", errmaj, errmin); - return FALSE; - } - xf86LoaderReqSymLists(exaSymbols, NULL); - } - -EXA is then initialized using exaDriverAlloc and exaDriverInit. See doxygen -documentation for getting started there. - -Further documentation ------------- -The EXA driver interface and public API is documented using doxygen in -xserver/xorg/exa/. To build the documentation, run: - doxygen -g - doxygen Doxyfile -The resulting documentation will appear an html/index.html under the current -directory. - -EXA initialization ------------------- -Your driver's AccelInit routine must initialize an ExaDriverRec structure if -EXA support is enabled, with appropriate error handling (i.e. NoAccel and -NoXvideo should be set to true if EXA fails to initialize for whatever -reason). - -The AccelInit routine also needs to make sure that there's enough offscreen -memory for certain operations to function, like Xvideo, which should advertise -a maximum size no larger than can be dealt with given the amount of offscreen -memory available. - -EXA and Xv ----------- -Video support becomes easier with EXA since AllocateFBMemory can use -exaOffscreenAlloc directly, freeing a previous area if necessary and -allocating a new one. Likewise, FreeFBMemory can call exaOffscreenFree. - -EXA teardown ------------- -At screen close time, EXA drivers should call exaDriverFini with their screen -pointer, free their EXADriver structure, and do any other necessary teardown. - -EXA misc. ---------- -In many drivers, DGA support will need to be changed to be aware of the new -EXA support. - -Send updates and corrections to Jesse Barnes or -just check them in if you have permission. diff --git a/hw/xfree86/doc/meson.build b/hw/xfree86/doc/meson.build deleted file mode 100644 index df1d5e215..000000000 --- a/hw/xfree86/doc/meson.build +++ /dev/null @@ -1,35 +0,0 @@ - -if build_docs_devel - basename = 'ddxDesign' - input_xml = basename + '.xml' - - custom_target( - basename + '.html', - output: basename + '.html', - input: [input_xml], - command: [xmlto] + docs_xmlto_search_flags + [ - '-x', join_paths(doc_stylesheet_srcdir, 'xorg-xhtml.xsl'), - '-o', meson.current_build_dir(), - 'xhtml-nochunks', '@INPUT0@'], - build_by_default: true, - install: false, - ) - - if build_docs_pdf - foreach format : ['ps', 'pdf'] - output_fn = basename + '.' + format - custom_target( - output_fn, - output: output_fn, - input: [input_xml], - command: [xmlto] + docs_xmlto_search_flags + [ - '-x', join_paths(doc_stylesheet_srcdir, 'xorg-fo.xsl'), - '--stringparam', 'img.src.path=' + meson.current_build_dir(), - '-o', meson.current_build_dir(), - '--with-fop', format, '@INPUT0@'], - build_by_default: true, - install: false, - ) - endforeach - endif -endif diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c deleted file mode 100644 index d1b092bdb..000000000 --- a/hw/xfree86/dri/dri.c +++ /dev/null @@ -1,2406 +0,0 @@ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -Copyright 2000 VA Linux Systems, Inc. -All Rights Reserved. - -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, 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 PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Jens Owen - * Rickard E. (Rik) Faith - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include -#include -#include -#include -#include -#include - -#include -#include -#include "xf86drm.h" -#include "misc.h" -#include "dixstruct.h" -#include "extnsionst.h" -#include "extinit.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "servermd.h" -#define _XF86DRI_SERVER_ -#include -#include "swaprep.h" -#include "xf86str.h" -#include "dri.h" -#include "sarea.h" -#include "dristruct.h" -#include "mi.h" -#include "mipointer.h" -#include "xf86_OSproc.h" -#include "inputstr.h" -#include "xf86VGAarbiter.h" -#include "xf86Extensions.h" - -static int DRIEntPrivIndex = -1; -static DevPrivateKeyRec DRIScreenPrivKeyRec; - -#define DRIScreenPrivKey (&DRIScreenPrivKeyRec) -static DevPrivateKeyRec DRIWindowPrivKeyRec; - -#define DRIWindowPrivKey (&DRIWindowPrivKeyRec) -static unsigned long DRIGeneration = 0; -static unsigned int DRIDrawableValidationStamp = 0; - -static RESTYPE DRIDrawablePrivResType; -static RESTYPE DRIContextPrivResType; -static void DRIDestroyDummyContext(ScreenPtr pScreen, Bool hasCtxPriv); - -drmServerInfo DRIDRMServerInfo; - - /* Wrapper just like xf86DrvMsg, but - without the verbosity level checking. - This will make it easy to turn off some - messages later, based on verbosity - level. */ - -/* - * Since we're already referencing things from the XFree86 common layer in - * this file, we'd might as well just call xf86VDrvMsgVerb, and have - * consistent message formatting. The verbosity of these messages can be - * easily changed here. - */ -#define DRI_MSG_VERBOSITY 1 - -static void -DRIDrvMsg(int scrnIndex, MessageType type, const char *format, ...) - _X_ATTRIBUTE_PRINTF(3,4); - -static void -DRIDrvMsg(int scrnIndex, MessageType type, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - xf86VDrvMsgVerb(scrnIndex, type, DRI_MSG_VERBOSITY, format, ap); - va_end(ap); -} - -static void -DRIOpenDRMCleanup(DRIEntPrivPtr pDRIEntPriv) -{ - if (pDRIEntPriv->pLSAREA != NULL) { - drmUnmap(pDRIEntPriv->pLSAREA, pDRIEntPriv->sAreaSize); - pDRIEntPriv->pLSAREA = NULL; - } - if (pDRIEntPriv->hLSAREA != 0) { - drmRmMap(pDRIEntPriv->drmFD, pDRIEntPriv->hLSAREA); - } - if (pDRIEntPriv->drmFD >= 0) { - drmClose(pDRIEntPriv->drmFD); - pDRIEntPriv->drmFD = 0; - } -} - -int -DRIMasterFD(ScrnInfoPtr pScrn) -{ - return DRI_ENT_PRIV(pScrn)->drmFD; -} - -void * -DRIMasterSareaPointer(ScrnInfoPtr pScrn) -{ - return DRI_ENT_PRIV(pScrn)->pLSAREA; -} - -drm_handle_t -DRIMasterSareaHandle(ScrnInfoPtr pScrn) -{ - return DRI_ENT_PRIV(pScrn)->hLSAREA; -} - -Bool -DRIOpenDRMMaster(ScrnInfoPtr pScrn, - unsigned long sAreaSize, - const char *busID, const char *drmDriverName) -{ - drmSetVersion saveSv, sv; - Bool drmWasAvailable; - DRIEntPrivPtr pDRIEntPriv; - DRIEntPrivRec tmp; - int count; - int err; - - if (DRIEntPrivIndex == -1) - DRIEntPrivIndex = xf86AllocateEntityPrivateIndex(); - - pDRIEntPriv = DRI_ENT_PRIV(pScrn); - - if (pDRIEntPriv && pDRIEntPriv->drmFD != -1) - return TRUE; - - drmWasAvailable = drmAvailable(); - - memset(&tmp, 0, sizeof(tmp)); - - tmp.drmFD = -1; - sv.drm_di_major = 1; - sv.drm_di_minor = 1; - sv.drm_dd_major = -1; - - saveSv = sv; - count = 10; - while (count--) { - tmp.drmFD = drmOpen(drmDriverName, busID); - - if (tmp.drmFD < 0) { - DRIDrvMsg(-1, X_ERROR, "[drm] drmOpen failed.\n"); - goto out_err; - } - - err = drmSetInterfaceVersion(tmp.drmFD, &sv); - - if (err != -EPERM) - break; - - sv = saveSv; - drmClose(tmp.drmFD); - tmp.drmFD = -1; - usleep(100000); - } - - if (tmp.drmFD <= 0) { - DRIDrvMsg(-1, X_ERROR, "[drm] DRM was busy with another master.\n"); - goto out_err; - } - - if (!drmWasAvailable) { - DRIDrvMsg(-1, X_INFO, - "[drm] loaded kernel module for \"%s\" driver.\n", - drmDriverName); - } - - if (err != 0) { - sv.drm_di_major = 1; - sv.drm_di_minor = 0; - } - - DRIDrvMsg(-1, X_INFO, "[drm] DRM interface version %d.%d\n", - sv.drm_di_major, sv.drm_di_minor); - - if (sv.drm_di_major == 1 && sv.drm_di_minor >= 1) - err = 0; - else - err = drmSetBusid(tmp.drmFD, busID); - - if (err) { - DRIDrvMsg(-1, X_ERROR, "[drm] Could not set DRM device bus ID.\n"); - goto out_err; - } - - /* - * Create a lock-containing sarea. - */ - - if (drmAddMap(tmp.drmFD, 0, sAreaSize, DRM_SHM, - DRM_CONTAINS_LOCK, &tmp.hLSAREA) < 0) { - DRIDrvMsg(-1, X_INFO, "[drm] Could not create SAREA for DRM lock.\n"); - tmp.hLSAREA = 0; - goto out_err; - } - - if (drmMap(tmp.drmFD, tmp.hLSAREA, sAreaSize, - (drmAddressPtr) (&tmp.pLSAREA)) < 0) { - DRIDrvMsg(-1, X_INFO, "[drm] Mapping SAREA for DRM lock failed.\n"); - tmp.pLSAREA = NULL; - goto out_err; - } - - memset(tmp.pLSAREA, 0, sAreaSize); - - /* - * Reserved contexts are handled by the first opened screen. - */ - - tmp.resOwner = NULL; - - if (!pDRIEntPriv) - pDRIEntPriv = xnfcalloc(sizeof(*pDRIEntPriv), 1); - - if (!pDRIEntPriv) { - DRIDrvMsg(-1, X_INFO, "[drm] Failed to allocate memory for " - "DRM device.\n"); - goto out_err; - } - *pDRIEntPriv = tmp; - xf86GetEntityPrivate((pScrn)->entityList[0], DRIEntPrivIndex)->ptr = - pDRIEntPriv; - - DRIDrvMsg(-1, X_INFO, "[drm] DRM open master succeeded.\n"); - return TRUE; - - out_err: - - DRIOpenDRMCleanup(&tmp); - return FALSE; -} - -static void - DRIClipNotifyAllDrawables(ScreenPtr pScreen); - -static void -dri_crtc_notify(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - DRIClipNotifyAllDrawables(pScreen); - xf86_unwrap_crtc_notify(pScreen, pDRIPriv->xf86_crtc_notify); - xf86_crtc_notify(pScreen); - pDRIPriv->xf86_crtc_notify = - xf86_wrap_crtc_notify(pScreen, dri_crtc_notify); -} - -static void -drmSIGIOHandler(int interrupt, void *closure) -{ - unsigned long key; - void *value; - ssize_t count; - drm_ctx_t ctx; - typedef void (*_drmCallback) (int, void *, void *); - char buf[256]; - drm_context_t old; - drm_context_t new; - void *oldctx; - void *newctx; - char *pt; - drmHashEntry *entry; - void *hash_table; - - hash_table = drmGetHashTable(); - - if (!hash_table) - return; - if (drmHashFirst(hash_table, &key, &value)) { - entry = value; - do { - if ((count = read(entry->fd, buf, sizeof(buf) - 1)) > 0) { - buf[count] = '\0'; - - for (pt = buf; *pt != ' '; ++pt); /* Find first space */ - ++pt; - old = strtol(pt, &pt, 0); - new = strtol(pt, NULL, 0); - oldctx = drmGetContextTag(entry->fd, old); - newctx = drmGetContextTag(entry->fd, new); - ((_drmCallback) entry->f) (entry->fd, oldctx, newctx); - ctx.handle = new; - ioctl(entry->fd, DRM_IOCTL_NEW_CTX, &ctx); - } - } while (drmHashNext(hash_table, &key, &value)); - } -} - -static int -drmInstallSIGIOHandler(int fd, void (*f) (int, void *, void *)) -{ - drmHashEntry *entry; - - entry = drmGetEntry(fd); - entry->f = f; - - return xf86InstallSIGIOHandler(fd, drmSIGIOHandler, 0); -} - -static int -drmRemoveSIGIOHandler(int fd) -{ - drmHashEntry *entry = drmGetEntry(fd); - - entry->f = NULL; - - return xf86RemoveSIGIOHandler(fd); -} - -Bool -DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) -{ - DRIScreenPrivPtr pDRIPriv; - drm_context_t *reserved; - int reserved_count; - int i; - DRIEntPrivPtr pDRIEntPriv; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - DRIContextFlags flags = 0; - DRIContextPrivPtr pDRIContextPriv; - static Bool drm_server_inited; - - /* If the DRI extension is disabled, do not initialize the DRI */ - if (noXFree86DRIExtension) { - DRIDrvMsg(pScreen->myNum, X_WARNING, - "Direct rendering has been disabled.\n"); - return FALSE; - } - - if (!xf86VGAarbiterAllowDRI(pScreen)) { - DRIDrvMsg(pScreen->myNum, X_WARNING, - "Direct rendering is not supported when VGA arb is necessary for the device\n"); - return FALSE; - } - -#ifdef PANORAMIX - /* - * If Xinerama is on, don't allow DRI to initialise. It won't be usable - * anyway. - */ - if (!noPanoramiXExtension) { - DRIDrvMsg(pScreen->myNum, X_WARNING, - "Direct rendering is not supported when Xinerama is enabled\n"); - return FALSE; - } -#endif - if (drm_server_inited == FALSE) { - drmSetServerInfo(&DRIDRMServerInfo); - drm_server_inited = TRUE; - } - - if (!DRIOpenDRMMaster(pScrn, pDRIInfo->SAREASize, - pDRIInfo->busIdString, pDRIInfo->drmDriverName)) - return FALSE; - - pDRIEntPriv = DRI_ENT_PRIV(pScrn); - - if (DRIGeneration != serverGeneration) - DRIGeneration = serverGeneration; - - if (!dixRegisterPrivateKey(&DRIScreenPrivKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - if (!dixRegisterPrivateKey(&DRIWindowPrivKeyRec, PRIVATE_WINDOW, 0)) - return FALSE; - - pDRIPriv = (DRIScreenPrivPtr) calloc(1, sizeof(DRIScreenPrivRec)); - if (!pDRIPriv) { - dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL); - return FALSE; - } - - dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, pDRIPriv); - pDRIPriv->drmFD = pDRIEntPriv->drmFD; - pDRIPriv->directRenderingSupport = TRUE; - pDRIPriv->pDriverInfo = pDRIInfo; - pDRIPriv->nrWindows = 0; - pDRIPriv->nrWindowsVisible = 0; - pDRIPriv->fullscreen = NULL; - - pDRIPriv->createDummyCtx = pDRIInfo->createDummyCtx; - pDRIPriv->createDummyCtxPriv = pDRIInfo->createDummyCtxPriv; - - pDRIPriv->grabbedDRILock = FALSE; - pDRIPriv->drmSIGIOHandlerInstalled = FALSE; - *pDRMFD = pDRIPriv->drmFD; - - if (pDRIEntPriv->sAreaGrabbed || pDRIInfo->allocSarea) { - - if (drmAddMap(pDRIPriv->drmFD, - 0, - pDRIPriv->pDriverInfo->SAREASize, - DRM_SHM, 0, &pDRIPriv->hSAREA) < 0) { - pDRIPriv->directRenderingSupport = FALSE; - dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL); - drmClose(pDRIPriv->drmFD); - DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] drmAddMap failed\n"); - return FALSE; - } - DRIDrvMsg(pScreen->myNum, X_INFO, - "[drm] added %d byte SAREA at %p\n", - (int) pDRIPriv->pDriverInfo->SAREASize, (void *) (uintptr_t) pDRIPriv->hSAREA); - - /* Backwards compat. */ - if (drmMap(pDRIPriv->drmFD, - pDRIPriv->hSAREA, - pDRIPriv->pDriverInfo->SAREASize, - (drmAddressPtr) (&pDRIPriv->pSAREA)) < 0) { - pDRIPriv->directRenderingSupport = FALSE; - dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL); - drmClose(pDRIPriv->drmFD); - DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] drmMap failed\n"); - return FALSE; - } - DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] mapped SAREA %p to %p\n", - (void *) (uintptr_t) pDRIPriv->hSAREA, pDRIPriv->pSAREA); - memset(pDRIPriv->pSAREA, 0, pDRIPriv->pDriverInfo->SAREASize); - } - else { - DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] Using the DRM lock " - "SAREA also for drawables.\n"); - pDRIPriv->hSAREA = pDRIEntPriv->hLSAREA; - pDRIPriv->pSAREA = (XF86DRISAREAPtr) pDRIEntPriv->pLSAREA; - pDRIEntPriv->sAreaGrabbed = TRUE; - } - - pDRIPriv->hLSAREA = pDRIEntPriv->hLSAREA; - pDRIPriv->pLSAREA = pDRIEntPriv->pLSAREA; - - if (!pDRIPriv->pDriverInfo->dontMapFrameBuffer) { - if (drmAddMap(pDRIPriv->drmFD, - (uintptr_t) pDRIPriv->pDriverInfo-> - frameBufferPhysicalAddress, - pDRIPriv->pDriverInfo->frameBufferSize, DRM_FRAME_BUFFER, - 0, &pDRIPriv->pDriverInfo->hFrameBuffer) < 0) { - pDRIPriv->directRenderingSupport = FALSE; - dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL); - drmUnmap(pDRIPriv->pSAREA, pDRIPriv->pDriverInfo->SAREASize); - drmClose(pDRIPriv->drmFD); - DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] drmAddMap failed\n"); - return FALSE; - } - DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] framebuffer handle = %p\n", - (void *) (uintptr_t) pDRIPriv->pDriverInfo->hFrameBuffer); - } - else { - DRIDrvMsg(pScreen->myNum, X_INFO, - "[drm] framebuffer mapped by ddx driver\n"); - } - - if (pDRIEntPriv->resOwner == NULL) { - pDRIEntPriv->resOwner = pScreen; - - /* Add tags for reserved contexts */ - if ((reserved = drmGetReservedContextList(pDRIPriv->drmFD, - &reserved_count))) { - int r; - void *tag; - - for (r = 0; r < reserved_count; r++) { - tag = DRICreateContextPrivFromHandle(pScreen, - reserved[r], - DRI_CONTEXT_RESERVED); - drmAddContextTag(pDRIPriv->drmFD, reserved[r], tag); - } - drmFreeReservedContextList(reserved); - DRIDrvMsg(pScreen->myNum, X_INFO, - "[drm] added %d reserved context%s for kernel\n", - reserved_count, reserved_count > 1 ? "s" : ""); - } - } - - /* validate max drawable table entry set by driver */ - if ((pDRIPriv->pDriverInfo->maxDrawableTableEntry <= 0) || - (pDRIPriv->pDriverInfo->maxDrawableTableEntry > SAREA_MAX_DRAWABLES)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "Invalid max drawable table size set by driver: %d\n", - pDRIPriv->pDriverInfo->maxDrawableTableEntry); - } - - /* Initialize drawable tables (screen private and SAREA) */ - for (i = 0; i < pDRIPriv->pDriverInfo->maxDrawableTableEntry; i++) { - pDRIPriv->DRIDrawables[i] = NULL; - pDRIPriv->pSAREA->drawableTable[i].stamp = 0; - pDRIPriv->pSAREA->drawableTable[i].flags = 0; - } - - pDRIPriv->pLockRefCount = &pDRIEntPriv->lockRefCount; - pDRIPriv->pLockingContext = &pDRIEntPriv->lockingContext; - - if (!pDRIEntPriv->keepFDOpen) - pDRIEntPriv->keepFDOpen = pDRIInfo->keepFDOpen; - - pDRIEntPriv->refCount++; - - /* Set up flags for DRICreateContextPriv */ - switch (pDRIInfo->driverSwapMethod) { - case DRI_KERNEL_SWAP: - flags = DRI_CONTEXT_2DONLY; - break; - case DRI_HIDE_X_CONTEXT: - flags = DRI_CONTEXT_PRESERVED; - break; - } - - if (!(pDRIContextPriv = DRICreateContextPriv(pScreen, - &pDRIPriv->myContext, - flags))) { - DRIDrvMsg(pScreen->myNum, X_ERROR, "failed to create server context\n"); - return FALSE; - } - pDRIPriv->myContextPriv = pDRIContextPriv; - - DRIDrvMsg(pScreen->myNum, X_INFO, - "X context handle = %p\n", (void *) (uintptr_t) pDRIPriv->myContext); - - /* Now that we have created the X server's context, we can grab the - * hardware lock for the X server. - */ - DRILock(pScreen, 0); - pDRIPriv->grabbedDRILock = TRUE; - - /* pointers so that we can prevent memory leaks later */ - pDRIPriv->hiddenContextStore = NULL; - pDRIPriv->partial3DContextStore = NULL; - - switch (pDRIInfo->driverSwapMethod) { - case DRI_HIDE_X_CONTEXT: - /* Server will handle 3D swaps, and hide 2D swaps from kernel. - * Register server context as a preserved context. - */ - - /* allocate memory for hidden context store */ - pDRIPriv->hiddenContextStore - = (void *) calloc(1, pDRIInfo->contextSize); - if (!pDRIPriv->hiddenContextStore) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "failed to allocate hidden context\n"); - DRIDestroyContextPriv(pDRIContextPriv); - return FALSE; - } - - /* allocate memory for partial 3D context store */ - pDRIPriv->partial3DContextStore - = (void *) calloc(1, pDRIInfo->contextSize); - if (!pDRIPriv->partial3DContextStore) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[DRI] failed to allocate partial 3D context\n"); - free(pDRIPriv->hiddenContextStore); - DRIDestroyContextPriv(pDRIContextPriv); - return FALSE; - } - - /* save initial context store */ - if (pDRIInfo->SwapContext) { - (*pDRIInfo->SwapContext) (pScreen, - DRI_NO_SYNC, - DRI_2D_CONTEXT, - pDRIPriv->hiddenContextStore, - DRI_NO_CONTEXT, NULL); - } - /* fall through */ - - case DRI_SERVER_SWAP: - /* For swap methods of DRI_SERVER_SWAP and DRI_HIDE_X_CONTEXT - * setup signal handler for receiving swap requests from kernel - */ - if (!(pDRIPriv->drmSIGIOHandlerInstalled = - drmInstallSIGIOHandler(pDRIPriv->drmFD, DRISwapContext))) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[drm] failed to setup DRM signal handler\n"); - free(pDRIPriv->hiddenContextStore); - free(pDRIPriv->partial3DContextStore); - DRIDestroyContextPriv(pDRIContextPriv); - return FALSE; - } - else { - DRIDrvMsg(pScreen->myNum, X_INFO, - "[drm] installed DRM signal handler\n"); - } - - default: - break; - } - - return TRUE; -} - -Bool -DRIFinishScreenInit(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - - /* Wrap DRI support */ - if (pDRIInfo->wrap.WindowExposures) { - pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures; - pScreen->WindowExposures = pDRIInfo->wrap.WindowExposures; - } - - pDRIPriv->DestroyWindow = pScreen->DestroyWindow; - pScreen->DestroyWindow = DRIDestroyWindow; - - pDRIPriv->xf86_crtc_notify = xf86_wrap_crtc_notify(pScreen, - dri_crtc_notify); - - if (pDRIInfo->wrap.CopyWindow) { - pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow; - pScreen->CopyWindow = pDRIInfo->wrap.CopyWindow; - } - if (pDRIInfo->wrap.ClipNotify) { - pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify; - pScreen->ClipNotify = pDRIInfo->wrap.ClipNotify; - } - if (pDRIInfo->wrap.AdjustFrame) { - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - - pDRIPriv->wrap.AdjustFrame = pScrn->AdjustFrame; - pScrn->AdjustFrame = pDRIInfo->wrap.AdjustFrame; - } - pDRIPriv->wrapped = TRUE; - - DRIDrvMsg(pScreen->myNum, X_INFO, "[DRI] installation complete\n"); - - return TRUE; -} - -void -DRICloseScreen(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIInfoPtr pDRIInfo; - drm_context_t *reserved; - int reserved_count; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - DRIEntPrivPtr pDRIEntPriv = DRI_ENT_PRIV(pScrn); - Bool closeMaster; - - if (pDRIPriv) { - - pDRIInfo = pDRIPriv->pDriverInfo; - - if (pDRIPriv->wrapped) { - /* Unwrap DRI Functions */ - if (pDRIInfo->wrap.WindowExposures) { - pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures; - pDRIPriv->wrap.WindowExposures = NULL; - } - if (pDRIPriv->DestroyWindow) { - pScreen->DestroyWindow = pDRIPriv->DestroyWindow; - pDRIPriv->DestroyWindow = NULL; - } - - xf86_unwrap_crtc_notify(pScreen, pDRIPriv->xf86_crtc_notify); - - if (pDRIInfo->wrap.CopyWindow) { - pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow; - pDRIPriv->wrap.CopyWindow = NULL; - } - if (pDRIInfo->wrap.ClipNotify) { - pScreen->ClipNotify = pDRIPriv->wrap.ClipNotify; - pDRIPriv->wrap.ClipNotify = NULL; - } - if (pDRIInfo->wrap.AdjustFrame) { - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - - scrn->AdjustFrame = pDRIPriv->wrap.AdjustFrame; - pDRIPriv->wrap.AdjustFrame = NULL; - } - - pDRIPriv->wrapped = FALSE; - } - - if (pDRIPriv->drmSIGIOHandlerInstalled) { - if (!drmRemoveSIGIOHandler(pDRIPriv->drmFD)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[drm] failed to remove DRM signal handler\n"); - } - } - - if (pDRIPriv->dummyCtxPriv && pDRIPriv->createDummyCtx) { - DRIDestroyDummyContext(pScreen, pDRIPriv->createDummyCtxPriv); - } - - if (!DRIDestroyContextPriv(pDRIPriv->myContextPriv)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "failed to destroy server context\n"); - } - - /* Remove tags for reserved contexts */ - if (pDRIEntPriv->resOwner == pScreen) { - pDRIEntPriv->resOwner = NULL; - - if ((reserved = drmGetReservedContextList(pDRIPriv->drmFD, - &reserved_count))) { - int i; - - for (i = 0; i < reserved_count; i++) { - DRIDestroyContextPriv(drmGetContextTag(pDRIPriv->drmFD, - reserved[i])); - } - drmFreeReservedContextList(reserved); - DRIDrvMsg(pScreen->myNum, X_INFO, - "[drm] removed %d reserved context%s for kernel\n", - reserved_count, reserved_count > 1 ? "s" : ""); - } - } - - /* Make sure signals get unblocked etc. */ - drmUnlock(pDRIPriv->drmFD, pDRIPriv->myContext); - pDRIPriv->pLockRefCount = NULL; - closeMaster = (--pDRIEntPriv->refCount == 0) && - !pDRIEntPriv->keepFDOpen; - if (closeMaster || pDRIPriv->hSAREA != pDRIEntPriv->hLSAREA) { - DRIDrvMsg(pScreen->myNum, X_INFO, - "[drm] unmapping %d bytes of SAREA %p at %p\n", - (int) pDRIInfo->SAREASize, (void *) (uintptr_t) pDRIPriv->hSAREA, pDRIPriv->pSAREA); - if (drmUnmap(pDRIPriv->pSAREA, pDRIInfo->SAREASize)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[drm] unable to unmap %d bytes" - " of SAREA %p at %p\n", - (int) pDRIInfo->SAREASize, - (void *) (uintptr_t) pDRIPriv->hSAREA, pDRIPriv->pSAREA); - } - } - else { - pDRIEntPriv->sAreaGrabbed = FALSE; - } - - if (closeMaster || (pDRIEntPriv->drmFD != pDRIPriv->drmFD)) { - drmClose(pDRIPriv->drmFD); - if (pDRIEntPriv->drmFD == pDRIPriv->drmFD) { - DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] Closed DRM master.\n"); - pDRIEntPriv->drmFD = -1; - } - } - - free(pDRIPriv); - dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL); - } -} - -#define DRM_MSG_VERBOSITY 3 - -static int -dri_drm_debug_print(const char *format, va_list ap) - _X_ATTRIBUTE_PRINTF(1,0); - -static int -dri_drm_debug_print(const char *format, va_list ap) -{ - xf86VDrvMsgVerb(-1, X_NONE, DRM_MSG_VERBOSITY, format, ap); - return 0; -} - -static void -dri_drm_get_perms(gid_t * group, mode_t * mode) -{ - *group = xf86ConfigDRI.group; - *mode = xf86ConfigDRI.mode; -} - -drmServerInfo DRIDRMServerInfo = { - dri_drm_debug_print, - xf86LoadKernelModule, - dri_drm_get_perms, -}; - -Bool -DRIExtensionInit(void) -{ - if (DRIGeneration != serverGeneration) { - return FALSE; - } - - DRIDrawablePrivResType = CreateNewResourceType(DRIDrawablePrivDelete, - "DRIDrawable"); - DRIContextPrivResType = CreateNewResourceType(DRIContextPrivDelete, - "DRIContext"); - - if (!DRIDrawablePrivResType || !DRIContextPrivResType) - return FALSE; - - RegisterBlockAndWakeupHandlers(DRIBlockHandler, DRIWakeupHandler, NULL); - - return TRUE; -} - -void -DRIReset(void) -{ - /* - * This stub routine is called when the X Server recycles, resources - * allocated by DRIExtensionInit need to be managed here. - * - * Currently this routine is a stub because all the interesting resources - * are managed via the screen init process. - */ -} - -Bool -DRIQueryDirectRenderingCapable(ScreenPtr pScreen, Bool *isCapable) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (pDRIPriv) - *isCapable = pDRIPriv->directRenderingSupport; - else - *isCapable = FALSE; - - return TRUE; -} - -Bool -DRIOpenConnection(ScreenPtr pScreen, drm_handle_t * hSAREA, char **busIdString) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - *hSAREA = pDRIPriv->hSAREA; - *busIdString = pDRIPriv->pDriverInfo->busIdString; - - return TRUE; -} - -Bool -DRIAuthConnection(ScreenPtr pScreen, drm_magic_t magic) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (drmAuthMagic(pDRIPriv->drmFD, magic)) - return FALSE; - return TRUE; -} - -Bool -DRICloseConnection(ScreenPtr pScreen) -{ - return TRUE; -} - -Bool -DRIGetClientDriverName(ScreenPtr pScreen, - int *ddxDriverMajorVersion, - int *ddxDriverMinorVersion, - int *ddxDriverPatchVersion, char **clientDriverName) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - *ddxDriverMajorVersion = pDRIPriv->pDriverInfo->ddxDriverMajorVersion; - *ddxDriverMinorVersion = pDRIPriv->pDriverInfo->ddxDriverMinorVersion; - *ddxDriverPatchVersion = pDRIPriv->pDriverInfo->ddxDriverPatchVersion; - *clientDriverName = pDRIPriv->pDriverInfo->clientDriverName; - - return TRUE; -} - -/* DRICreateContextPriv and DRICreateContextPrivFromHandle are helper - functions that layer on drmCreateContext and drmAddContextTag. - - DRICreateContextPriv always creates a kernel drm_context_t and then calls - DRICreateContextPrivFromHandle to create a DRIContextPriv structure for - DRI tracking. For the SIGIO handler, the drm_context_t is associated with - DRIContextPrivPtr. Any special flags are stored in the DRIContextPriv - area and are passed to the kernel (if necessary). - - DRICreateContextPriv returns a pointer to newly allocated - DRIContextPriv, and returns the kernel drm_context_t in pHWContext. */ - -DRIContextPrivPtr -DRICreateContextPriv(ScreenPtr pScreen, - drm_context_t * pHWContext, DRIContextFlags flags) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (drmCreateContext(pDRIPriv->drmFD, pHWContext)) { - return NULL; - } - - return DRICreateContextPrivFromHandle(pScreen, *pHWContext, flags); -} - -DRIContextPrivPtr -DRICreateContextPrivFromHandle(ScreenPtr pScreen, - drm_context_t hHWContext, DRIContextFlags flags) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIContextPrivPtr pDRIContextPriv; - int contextPrivSize; - - contextPrivSize = sizeof(DRIContextPrivRec) + - pDRIPriv->pDriverInfo->contextSize; - if (!(pDRIContextPriv = calloc(1, contextPrivSize))) { - return NULL; - } - pDRIContextPriv->pContextStore = (void *) (pDRIContextPriv + 1); - - drmAddContextTag(pDRIPriv->drmFD, hHWContext, pDRIContextPriv); - - pDRIContextPriv->hwContext = hHWContext; - pDRIContextPriv->pScreen = pScreen; - pDRIContextPriv->flags = flags; - pDRIContextPriv->valid3D = FALSE; - - if (flags & DRI_CONTEXT_2DONLY) { - if (drmSetContextFlags(pDRIPriv->drmFD, hHWContext, DRM_CONTEXT_2DONLY)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[drm] failed to set 2D context flag\n"); - DRIDestroyContextPriv(pDRIContextPriv); - return NULL; - } - } - if (flags & DRI_CONTEXT_PRESERVED) { - if (drmSetContextFlags(pDRIPriv->drmFD, - hHWContext, DRM_CONTEXT_PRESERVED)) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[drm] failed to set preserved flag\n"); - DRIDestroyContextPriv(pDRIContextPriv); - return NULL; - } - } - return pDRIContextPriv; -} - -Bool -DRIDestroyContextPriv(DRIContextPrivPtr pDRIContextPriv) -{ - DRIScreenPrivPtr pDRIPriv; - - if (!pDRIContextPriv) - return TRUE; - - pDRIPriv = DRI_SCREEN_PRIV(pDRIContextPriv->pScreen); - - if (!(pDRIContextPriv->flags & DRI_CONTEXT_RESERVED)) { - /* Don't delete reserved contexts from - kernel area -- the kernel manages its - reserved contexts itself. */ - if (drmDestroyContext(pDRIPriv->drmFD, pDRIContextPriv->hwContext)) - return FALSE; - } - - /* Remove the tag last to prevent a race - condition where the context has pending - buffers. The context can't be re-used - while in this thread, but buffers can be - dispatched asynchronously. */ - drmDelContextTag(pDRIPriv->drmFD, pDRIContextPriv->hwContext); - free(pDRIContextPriv); - return TRUE; -} - -static Bool -DRICreateDummyContext(ScreenPtr pScreen, Bool needCtxPriv) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIContextPrivPtr pDRIContextPriv; - void *contextStore; - - if (!(pDRIContextPriv = - DRICreateContextPriv(pScreen, &pDRIPriv->pSAREA->dummy_context, 0))) { - return FALSE; - } - - contextStore = DRIGetContextStore(pDRIContextPriv); - if (pDRIPriv->pDriverInfo->CreateContext && needCtxPriv) { - if (!pDRIPriv->pDriverInfo->CreateContext(pScreen, NULL, - pDRIPriv->pSAREA-> - dummy_context, NULL, - (DRIContextType) (long) - contextStore)) { - DRIDestroyContextPriv(pDRIContextPriv); - return FALSE; - } - } - - pDRIPriv->dummyCtxPriv = pDRIContextPriv; - return TRUE; -} - -static void -DRIDestroyDummyContext(ScreenPtr pScreen, Bool hasCtxPriv) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIContextPrivPtr pDRIContextPriv = pDRIPriv->dummyCtxPriv; - void *contextStore; - - if (!pDRIContextPriv) - return; - if (pDRIPriv->pDriverInfo->DestroyContext && hasCtxPriv) { - contextStore = DRIGetContextStore(pDRIContextPriv); - pDRIPriv->pDriverInfo->DestroyContext(pDRIContextPriv->pScreen, - pDRIContextPriv->hwContext, - (DRIContextType) (long) - contextStore); - } - - DRIDestroyContextPriv(pDRIPriv->dummyCtxPriv); - pDRIPriv->dummyCtxPriv = NULL; -} - -Bool -DRICreateContext(ScreenPtr pScreen, VisualPtr visual, - XID context, drm_context_t * pHWContext) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIContextPrivPtr pDRIContextPriv; - void *contextStore; - - if (pDRIPriv->createDummyCtx && !pDRIPriv->dummyCtxPriv) { - if (!DRICreateDummyContext(pScreen, pDRIPriv->createDummyCtxPriv)) { - DRIDrvMsg(pScreen->myNum, X_INFO, - "[drm] Could not create dummy context\n"); - return FALSE; - } - } - - if (!(pDRIContextPriv = DRICreateContextPriv(pScreen, pHWContext, 0))) { - return FALSE; - } - - contextStore = DRIGetContextStore(pDRIContextPriv); - if (pDRIPriv->pDriverInfo->CreateContext) { - if (!((*pDRIPriv->pDriverInfo->CreateContext) (pScreen, NULL, - *pHWContext, NULL, - (DRIContextType) (long) - contextStore))) { - DRIDestroyContextPriv(pDRIContextPriv); - return FALSE; - } - } - - /* track this in case the client dies before cleanup */ - if (!AddResource(context, DRIContextPrivResType, (void *) pDRIContextPriv)) - return FALSE; - - return TRUE; -} - -Bool -DRIDestroyContext(ScreenPtr pScreen, XID context) -{ - FreeResourceByType(context, DRIContextPrivResType, FALSE); - - return TRUE; -} - -/* DRIContextPrivDelete is called by the resource manager. */ -Bool -DRIContextPrivDelete(void *pResource, XID id) -{ - DRIContextPrivPtr pDRIContextPriv = (DRIContextPrivPtr) pResource; - DRIScreenPrivPtr pDRIPriv; - void *contextStore; - - pDRIPriv = DRI_SCREEN_PRIV(pDRIContextPriv->pScreen); - if (pDRIPriv->pDriverInfo->DestroyContext) { - contextStore = DRIGetContextStore(pDRIContextPriv); - pDRIPriv->pDriverInfo->DestroyContext(pDRIContextPriv->pScreen, - pDRIContextPriv->hwContext, - (DRIContextType) (long) - contextStore); - } - return DRIDestroyContextPriv(pDRIContextPriv); -} - -/* This walks the drawable timestamp array and invalidates all of them - * in the case of transition from private to shared backbuffers. It's - * not necessary for correctness, because DRIClipNotify gets called in - * time to prevent any conflict, but the transition from - * shared->private is sometimes missed if we don't do this. - */ -static void -DRIClipNotifyAllDrawables(ScreenPtr pScreen) -{ - int i; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - for (i = 0; i < pDRIPriv->pDriverInfo->maxDrawableTableEntry; i++) { - pDRIPriv->pSAREA->drawableTable[i].stamp = DRIDrawableValidationStamp++; - } -} - -static void -DRITransitionToSharedBuffers(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - - DRIClipNotifyAllDrawables(pScreen); - - if (pDRIInfo->TransitionSingleToMulti3D) - pDRIInfo->TransitionSingleToMulti3D(pScreen); -} - -static void -DRITransitionToPrivateBuffers(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - - DRIClipNotifyAllDrawables(pScreen); - - if (pDRIInfo->TransitionMultiToSingle3D) - pDRIInfo->TransitionMultiToSingle3D(pScreen); -} - -static void -DRITransitionTo3d(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - - DRIClipNotifyAllDrawables(pScreen); - - if (pDRIInfo->TransitionTo3d) - pDRIInfo->TransitionTo3d(pScreen); -} - -static void -DRITransitionTo2d(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - - DRIClipNotifyAllDrawables(pScreen); - - if (pDRIInfo->TransitionTo2d) - pDRIInfo->TransitionTo2d(pScreen); -} - -static int -DRIDCNTreeTraversal(WindowPtr pWin, void *data) -{ - DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); - - if (pDRIDrawablePriv) { - ScreenPtr pScreen = pWin->drawable.pScreen; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (RegionNumRects(&pWin->clipList) > 0) { - WindowPtr *pDRIWindows = (WindowPtr *) data; - int i = 0; - - while (pDRIWindows[i]) - i++; - - pDRIWindows[i] = pWin; - - pDRIPriv->nrWalked++; - } - - if (pDRIPriv->nrWindows == pDRIPriv->nrWalked) - return WT_STOPWALKING; - } - - return WT_WALKCHILDREN; -} - -static void -DRIDriverClipNotify(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (pDRIPriv->pDriverInfo->ClipNotify) { - WindowPtr *pDRIWindows = calloc(sizeof(WindowPtr), pDRIPriv->nrWindows); - DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; - - if (pDRIPriv->nrWindows > 0) { - pDRIPriv->nrWalked = 0; - TraverseTree(pScreen->root, DRIDCNTreeTraversal, - (void *) pDRIWindows); - } - - pDRIInfo->ClipNotify(pScreen, pDRIWindows, pDRIPriv->nrWindows); - - free(pDRIWindows); - } -} - -static void -DRIIncreaseNumberVisible(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - switch (++pDRIPriv->nrWindowsVisible) { - case 1: - DRITransitionTo3d(pScreen); - break; - case 2: - DRITransitionToSharedBuffers(pScreen); - break; - default: - break; - } - - DRIDriverClipNotify(pScreen); -} - -static void -DRIDecreaseNumberVisible(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - switch (--pDRIPriv->nrWindowsVisible) { - case 0: - DRITransitionTo2d(pScreen); - break; - case 1: - DRITransitionToPrivateBuffers(pScreen); - break; - default: - break; - } - - DRIDriverClipNotify(pScreen); -} - -Bool -DRICreateDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable, - drm_drawable_t * hHWDrawable) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIDrawablePrivPtr pDRIDrawablePriv; - WindowPtr pWin; - - if (pDrawable->type == DRAWABLE_WINDOW) { - pWin = (WindowPtr) pDrawable; - if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) { - pDRIDrawablePriv->refCount++; - - if (!pDRIDrawablePriv->hwDrawable) { - drmCreateDrawable(pDRIPriv->drmFD, - &pDRIDrawablePriv->hwDrawable); - } - } - else { - /* allocate a DRI Window Private record */ - if (!(pDRIDrawablePriv = malloc(sizeof(DRIDrawablePrivRec)))) { - return FALSE; - } - - /* Only create a drm_drawable_t once */ - if (drmCreateDrawable(pDRIPriv->drmFD, - &pDRIDrawablePriv->hwDrawable)) { - free(pDRIDrawablePriv); - return FALSE; - } - - /* add it to the list of DRI drawables for this screen */ - pDRIDrawablePriv->pScreen = pScreen; - pDRIDrawablePriv->refCount = 1; - pDRIDrawablePriv->drawableIndex = -1; - pDRIDrawablePriv->nrects = RegionNumRects(&pWin->clipList); - - /* save private off of preallocated index */ - dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, - pDRIDrawablePriv); - pDRIPriv->nrWindows++; - - if (pDRIDrawablePriv->nrects) - DRIIncreaseNumberVisible(pScreen); - } - - /* track this in case the client dies */ - if (!AddResource(FakeClientID(client->index), DRIDrawablePrivResType, - (void *) (intptr_t) pDrawable->id)) - return FALSE; - - if (pDRIDrawablePriv->hwDrawable) { - drmUpdateDrawableInfo(pDRIPriv->drmFD, - pDRIDrawablePriv->hwDrawable, - DRM_DRAWABLE_CLIPRECTS, - RegionNumRects(&pWin->clipList), - RegionRects(&pWin->clipList)); - *hHWDrawable = pDRIDrawablePriv->hwDrawable; - } - } - else if (pDrawable->type != DRAWABLE_PIXMAP) { /* PBuffer */ - /* NOT_DONE */ - return FALSE; - } - - return TRUE; -} - -static void -DRIDrawablePrivDestroy(WindowPtr pWin) -{ - DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); - ScreenPtr pScreen; - DRIScreenPrivPtr pDRIPriv; - - if (!pDRIDrawablePriv) - return; - - pScreen = pWin->drawable.pScreen; - pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (pDRIDrawablePriv->drawableIndex != -1) { - /* bump stamp to force outstanding 3D requests to resync */ - pDRIPriv->pSAREA->drawableTable[pDRIDrawablePriv->drawableIndex].stamp - = DRIDrawableValidationStamp++; - - /* release drawable table entry */ - pDRIPriv->DRIDrawables[pDRIDrawablePriv->drawableIndex] = NULL; - } - - pDRIPriv->nrWindows--; - - if (pDRIDrawablePriv->nrects) - DRIDecreaseNumberVisible(pScreen); - - drmDestroyDrawable(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable); - - free(pDRIDrawablePriv); - dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL); -} - -static Bool -DRIDestroyDrawableCB(void *value, XID id, void *data) -{ - if (value == data) { - /* This calls back DRIDrawablePrivDelete which frees private area */ - FreeResourceByType(id, DRIDrawablePrivResType, FALSE); - - return TRUE; - } - - return FALSE; -} - -Bool -DRIDestroyDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable) -{ - if (pDrawable->type == DRAWABLE_WINDOW) { - LookupClientResourceComplex(client, DRIDrawablePrivResType, - DRIDestroyDrawableCB, - (void *) (intptr_t) pDrawable->id); - } - else { /* pixmap (or for GLX 1.3, a PBuffer) */ - /* NOT_DONE */ - return FALSE; - } - - return TRUE; -} - -Bool -DRIDrawablePrivDelete(void *pResource, XID id) -{ - WindowPtr pWin; - int rc; - - /* For DRIDrawablePrivResType, the XID is the client's fake ID. The - * important XID is the value in pResource. */ - id = (XID) (intptr_t) pResource; - rc = dixLookupWindow(&pWin, id, serverClient, DixGetAttrAccess); - - if (rc == Success) { - DRIDrawablePrivPtr pDRIDrwPriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); - - if (!pDRIDrwPriv) - return FALSE; - - if (--pDRIDrwPriv->refCount == 0) - DRIDrawablePrivDestroy(pWin); - - return TRUE; - } - else { /* pixmap (or for GLX 1.3, a PBuffer) */ - /* NOT_DONE */ - return FALSE; - } -} - -Bool -DRIGetDrawableInfo(ScreenPtr pScreen, - DrawablePtr pDrawable, - unsigned int *index, - unsigned int *stamp, - int *X, - int *Y, - int *W, - int *H, - int *numClipRects, - drm_clip_rect_t ** pClipRects, - int *backX, - int *backY, - int *numBackClipRects, drm_clip_rect_t ** pBackClipRects) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIDrawablePrivPtr pDRIDrawablePriv, pOldDrawPriv; - WindowPtr pWin, pOldWin; - int i; - -#if 0 - printf("maxDrawableTableEntry = %d\n", - pDRIPriv->pDriverInfo->maxDrawableTableEntry); -#endif - - if (pDrawable->type == DRAWABLE_WINDOW) { - pWin = (WindowPtr) pDrawable; - if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) { - - /* Manage drawable table */ - if (pDRIDrawablePriv->drawableIndex == -1) { /* load SAREA table */ - - /* Search table for empty entry */ - i = 0; - while (i < pDRIPriv->pDriverInfo->maxDrawableTableEntry) { - if (!(pDRIPriv->DRIDrawables[i])) { - pDRIPriv->DRIDrawables[i] = pDrawable; - pDRIDrawablePriv->drawableIndex = i; - pDRIPriv->pSAREA->drawableTable[i].stamp = - DRIDrawableValidationStamp++; - break; - } - i++; - } - - /* Search table for oldest entry */ - if (i == pDRIPriv->pDriverInfo->maxDrawableTableEntry) { - unsigned int oldestStamp = ~0; - int oldestIndex = 0; - - i = pDRIPriv->pDriverInfo->maxDrawableTableEntry; - while (i--) { - if (pDRIPriv->pSAREA->drawableTable[i].stamp < - oldestStamp) { - oldestIndex = i; - oldestStamp = - pDRIPriv->pSAREA->drawableTable[i].stamp; - } - } - pDRIDrawablePriv->drawableIndex = oldestIndex; - - /* release oldest drawable table entry */ - pOldWin = (WindowPtr) pDRIPriv->DRIDrawables[oldestIndex]; - pOldDrawPriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pOldWin); - pOldDrawPriv->drawableIndex = -1; - - /* claim drawable table entry */ - pDRIPriv->DRIDrawables[oldestIndex] = pDrawable; - - /* validate SAREA entry */ - pDRIPriv->pSAREA->drawableTable[oldestIndex].stamp = - DRIDrawableValidationStamp++; - - /* check for stamp wrap around */ - if (oldestStamp > DRIDrawableValidationStamp) { - - /* walk SAREA table and invalidate all drawables */ - for (i = 0; - i < pDRIPriv->pDriverInfo->maxDrawableTableEntry; - i++) { - pDRIPriv->pSAREA->drawableTable[i].stamp = - DRIDrawableValidationStamp++; - } - } - } - - /* If the driver wants to be notified when the index is - * set for a drawable, let it know now. - */ - if (pDRIPriv->pDriverInfo->SetDrawableIndex) - pDRIPriv->pDriverInfo->SetDrawableIndex(pWin, - pDRIDrawablePriv-> - drawableIndex); - - /* reinit drawable ID if window is visible */ - if ((pWin->viewable) && - (pDRIPriv->pDriverInfo->bufferRequests != DRI_NO_WINDOWS)) { - (*pDRIPriv->pDriverInfo->InitBuffers) (pWin, - &pWin->clipList, - pDRIDrawablePriv-> - drawableIndex); - } - } - - *index = pDRIDrawablePriv->drawableIndex; - *stamp = pDRIPriv->pSAREA->drawableTable[*index].stamp; - *X = (int) (pWin->drawable.x); - *Y = (int) (pWin->drawable.y); - *W = (int) (pWin->drawable.width); - *H = (int) (pWin->drawable.height); - *numClipRects = RegionNumRects(&pWin->clipList); - *pClipRects = (drm_clip_rect_t *) RegionRects(&pWin->clipList); - - if (!*numClipRects && pDRIPriv->fullscreen) { - /* use fake full-screen clip rect */ - pDRIPriv->fullscreen_rect.x1 = *X; - pDRIPriv->fullscreen_rect.y1 = *Y; - pDRIPriv->fullscreen_rect.x2 = *X + *W; - pDRIPriv->fullscreen_rect.y2 = *Y + *H; - - *numClipRects = 1; - *pClipRects = &pDRIPriv->fullscreen_rect; - } - - *backX = *X; - *backY = *Y; - - if (pDRIPriv->nrWindowsVisible == 1 && *numClipRects) { - /* Use a single cliprect. */ - - int x0 = *X; - int y0 = *Y; - int x1 = x0 + *W; - int y1 = y0 + *H; - - if (x0 < 0) - x0 = 0; - if (y0 < 0) - y0 = 0; - if (x1 > pScreen->width) - x1 = pScreen->width; - if (y1 > pScreen->height) - y1 = pScreen->height; - - if (y0 >= y1 || x0 >= x1) { - *numBackClipRects = 0; - *pBackClipRects = NULL; - } - else { - pDRIPriv->private_buffer_rect.x1 = x0; - pDRIPriv->private_buffer_rect.y1 = y0; - pDRIPriv->private_buffer_rect.x2 = x1; - pDRIPriv->private_buffer_rect.y2 = y1; - - *numBackClipRects = 1; - *pBackClipRects = &(pDRIPriv->private_buffer_rect); - } - } - else { - /* Use the frontbuffer cliprects for back buffers. */ - *numBackClipRects = 0; - *pBackClipRects = 0; - } - } - else { - /* Not a DRIDrawable */ - return FALSE; - } - } - else { /* pixmap (or for GLX 1.3, a PBuffer) */ - /* NOT_DONE */ - return FALSE; - } - - return TRUE; -} - -Bool -DRIGetDeviceInfo(ScreenPtr pScreen, - drm_handle_t * hFrameBuffer, - int *fbOrigin, - int *fbSize, - int *fbStride, int *devPrivateSize, void **pDevPrivate) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - *hFrameBuffer = pDRIPriv->pDriverInfo->hFrameBuffer; - *fbOrigin = 0; - *fbSize = pDRIPriv->pDriverInfo->frameBufferSize; - *fbStride = pDRIPriv->pDriverInfo->frameBufferStride; - *devPrivateSize = pDRIPriv->pDriverInfo->devPrivateSize; - *pDevPrivate = pDRIPriv->pDriverInfo->devPrivate; - - return TRUE; -} - -DRIInfoPtr -DRICreateInfoRec(void) -{ - DRIInfoPtr inforec = (DRIInfoPtr) calloc(1, sizeof(DRIInfoRec)); - - if (!inforec) - return NULL; - - /* Initialize defaults */ - inforec->busIdString = NULL; - - /* Wrapped function defaults */ - inforec->wrap.WakeupHandler = DRIDoWakeupHandler; - inforec->wrap.BlockHandler = DRIDoBlockHandler; - inforec->wrap.WindowExposures = DRIWindowExposures; - inforec->wrap.CopyWindow = DRICopyWindow; - inforec->wrap.ClipNotify = DRIClipNotify; - inforec->wrap.AdjustFrame = DRIAdjustFrame; - - inforec->TransitionTo2d = 0; - inforec->TransitionTo3d = 0; - inforec->SetDrawableIndex = 0; - - return inforec; -} - -void -DRIDestroyInfoRec(DRIInfoPtr DRIInfo) -{ - free(DRIInfo->busIdString); - free((char *) DRIInfo); -} - -void -DRIWakeupHandler(void *wakeupData, int result) -{ - int i; - - for (i = 0; i < screenInfo.numScreens; i++) { - ScreenPtr pScreen = screenInfo.screens[i]; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (pDRIPriv && pDRIPriv->pDriverInfo->wrap.WakeupHandler) - (*pDRIPriv->pDriverInfo->wrap.WakeupHandler) (pScreen, result); - } -} - -void -DRIBlockHandler(void *blockData, void *pTimeout) -{ - int i; - - for (i = 0; i < screenInfo.numScreens; i++) { - ScreenPtr pScreen = screenInfo.screens[i]; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (pDRIPriv && pDRIPriv->pDriverInfo->wrap.BlockHandler) - (*pDRIPriv->pDriverInfo->wrap.BlockHandler) (pScreen, pTimeout); - } -} - -void -DRIDoWakeupHandler(ScreenPtr pScreen, int result) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - DRILock(pScreen, 0); - if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) { - /* hide X context by swapping 2D component here */ - (*pDRIPriv->pDriverInfo->SwapContext) (pScreen, - DRI_3D_SYNC, - DRI_2D_CONTEXT, - pDRIPriv->partial3DContextStore, - DRI_2D_CONTEXT, - pDRIPriv->hiddenContextStore); - } -} - -void -DRIDoBlockHandler(ScreenPtr pScreen, void *timeout) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) { - /* hide X context by swapping 2D component here */ - (*pDRIPriv->pDriverInfo->SwapContext) (pScreen, - DRI_2D_SYNC, - DRI_NO_CONTEXT, - NULL, - DRI_2D_CONTEXT, - pDRIPriv->partial3DContextStore); - } - - if (pDRIPriv->windowsTouched) - DRM_SPINUNLOCK(&pDRIPriv->pSAREA->drawable_lock, 1); - pDRIPriv->windowsTouched = FALSE; - - DRIUnlock(pScreen); -} - -void -DRISwapContext(int drmFD, void *oldctx, void *newctx) -{ - DRIContextPrivPtr oldContext = (DRIContextPrivPtr) oldctx; - DRIContextPrivPtr newContext = (DRIContextPrivPtr) newctx; - ScreenPtr pScreen = newContext->pScreen; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - void *oldContextStore = NULL; - DRIContextType oldContextType; - void *newContextStore = NULL; - DRIContextType newContextType; - DRISyncType syncType; - -#ifdef DEBUG - static int count = 0; - - if (!newContext) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[DRI] Context Switch Error: oldContext=%p, newContext=%p\n", - oldContext, newContext); - return; - } - - /* useful for debugging, just print out after n context switches */ - if (!count || !(count % 1)) { - DRIDrvMsg(pScreen->myNum, X_INFO, - "[DRI] Context switch %5d from %p/0x%08x (%d)\n", - count, - oldContext, - oldContext ? oldContext->flags : 0, - oldContext ? oldContext->hwContext : -1); - DRIDrvMsg(pScreen->myNum, X_INFO, - "[DRI] Context switch %5d to %p/0x%08x (%d)\n", - count, - newContext, - newContext ? newContext->flags : 0, - newContext ? newContext->hwContext : -1); - } - ++count; -#endif - - if (!pDRIPriv->pDriverInfo->SwapContext) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[DRI] DDX driver missing context swap call back\n"); - return; - } - - if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) { - - /* only 3D contexts are swapped in this case */ - if (oldContext) { - oldContextStore = DRIGetContextStore(oldContext); - oldContext->valid3D = TRUE; - oldContextType = DRI_3D_CONTEXT; - } - else { - oldContextType = DRI_NO_CONTEXT; - } - newContextStore = DRIGetContextStore(newContext); - if ((newContext->valid3D) && - (newContext->hwContext != pDRIPriv->myContext)) { - newContextType = DRI_3D_CONTEXT; - } - else { - newContextType = DRI_2D_CONTEXT; - } - syncType = DRI_3D_SYNC; - } - else { /* default: driverSwapMethod == DRI_SERVER_SWAP */ - - /* optimize 2D context swaps */ - - if (newContext->flags & DRI_CONTEXT_2DONLY) { - /* go from 3D context to 2D context and only save 2D - * subset of 3D state - */ - oldContextStore = DRIGetContextStore(oldContext); - oldContextType = DRI_2D_CONTEXT; - newContextStore = DRIGetContextStore(newContext); - newContextType = DRI_2D_CONTEXT; - syncType = DRI_3D_SYNC; - pDRIPriv->lastPartial3DContext = oldContext; - } - else if (oldContext->flags & DRI_CONTEXT_2DONLY) { - if (pDRIPriv->lastPartial3DContext == newContext) { - /* go from 2D context back to previous 3D context and - * only restore 2D subset of previous 3D state - */ - oldContextStore = DRIGetContextStore(oldContext); - oldContextType = DRI_2D_CONTEXT; - newContextStore = DRIGetContextStore(newContext); - newContextType = DRI_2D_CONTEXT; - syncType = DRI_2D_SYNC; - } - else { - /* go from 2D context to a different 3D context */ - - /* call DDX driver to do partial restore */ - oldContextStore = DRIGetContextStore(oldContext); - newContextStore = - DRIGetContextStore(pDRIPriv->lastPartial3DContext); - (*pDRIPriv->pDriverInfo->SwapContext) (pScreen, - DRI_2D_SYNC, - DRI_2D_CONTEXT, - oldContextStore, - DRI_2D_CONTEXT, - newContextStore); - - /* now setup for a complete 3D swap */ - oldContextStore = newContextStore; - oldContext->valid3D = TRUE; - oldContextType = DRI_3D_CONTEXT; - newContextStore = DRIGetContextStore(newContext); - if ((newContext->valid3D) && - (newContext->hwContext != pDRIPriv->myContext)) { - newContextType = DRI_3D_CONTEXT; - } - else { - newContextType = DRI_2D_CONTEXT; - } - syncType = DRI_NO_SYNC; - } - } - else { - /* now setup for a complete 3D swap */ - oldContextStore = newContextStore; - oldContext->valid3D = TRUE; - oldContextType = DRI_3D_CONTEXT; - newContextStore = DRIGetContextStore(newContext); - if ((newContext->valid3D) && - (newContext->hwContext != pDRIPriv->myContext)) { - newContextType = DRI_3D_CONTEXT; - } - else { - newContextType = DRI_2D_CONTEXT; - } - syncType = DRI_3D_SYNC; - } - } - - /* call DDX driver to perform the swap */ - (*pDRIPriv->pDriverInfo->SwapContext) (pScreen, - syncType, - oldContextType, - oldContextStore, - newContextType, newContextStore); -} - -void * -DRIGetContextStore(DRIContextPrivPtr context) -{ - return ((void *) context->pContextStore); -} - -void -DRIWindowExposures(WindowPtr pWin, RegionPtr prgn) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); - - if (pDRIDrawablePriv) { - (*pDRIPriv->pDriverInfo->InitBuffers) (pWin, prgn, - pDRIDrawablePriv->drawableIndex); - } - - /* call lower wrapped functions */ - if (pDRIPriv && pDRIPriv->wrap.WindowExposures) { - - /* unwrap */ - pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures; - - /* call lower layers */ - (*pScreen->WindowExposures) (pWin, prgn); - - /* rewrap */ - pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures; - pScreen->WindowExposures = DRIWindowExposures; - } -} - -static int -DRITreeTraversal(WindowPtr pWin, void *data) -{ - DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); - - if (pDRIDrawablePriv) { - ScreenPtr pScreen = pWin->drawable.pScreen; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (RegionNumRects(&(pWin->clipList)) > 0) { - RegionPtr reg = (RegionPtr) data; - - RegionUnion(reg, reg, &(pWin->clipList)); - pDRIPriv->nrWalked++; - } - - if (pDRIPriv->nrWindows == pDRIPriv->nrWalked) - return WT_STOPWALKING; - } - return WT_WALKCHILDREN; -} - -Bool -DRIDestroyWindow(WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - Bool retval = TRUE; - - DRIDrawablePrivDestroy(pWin); - - /* call lower wrapped functions */ - if (pDRIPriv->DestroyWindow) { - /* unwrap */ - pScreen->DestroyWindow = pDRIPriv->DestroyWindow; - - /* call lower layers */ - retval = (*pScreen->DestroyWindow) (pWin); - - /* rewrap */ - pDRIPriv->DestroyWindow = pScreen->DestroyWindow; - pScreen->DestroyWindow = DRIDestroyWindow; - } - - return retval; -} - -void -DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (!pDRIPriv) - return; - - if (pDRIPriv->nrWindowsVisible > 0) { - RegionRec reg; - - RegionNull(®); - pDRIPriv->nrWalked = 0; - TraverseTree(pWin, DRITreeTraversal, (void *) (®)); - - if (RegionNotEmpty(®)) { - RegionTranslate(®, ptOldOrg.x - pWin->drawable.x, - ptOldOrg.y - pWin->drawable.y); - RegionIntersect(®, ®, prgnSrc); - - /* The MoveBuffers interface is not ideal */ - (*pDRIPriv->pDriverInfo->MoveBuffers) (pWin, ptOldOrg, ®, - pDRIPriv->pDriverInfo-> - ddxDrawableTableEntry); - } - - RegionUninit(®); - } - - /* call lower wrapped functions */ - if (pDRIPriv->wrap.CopyWindow) { - /* unwrap */ - pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow; - - /* call lower layers */ - (*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc); - - /* rewrap */ - pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow; - pScreen->CopyWindow = DRICopyWindow; - } -} - -static void -DRIGetSecs(long *secs, long *usecs) -{ - struct timeval tv; - - gettimeofday(&tv, NULL); - - *secs = tv.tv_sec; - *usecs = tv.tv_usec; -} - -static unsigned long -DRIComputeMilliSeconds(unsigned long s_secs, unsigned long s_usecs, - unsigned long f_secs, unsigned long f_usecs) -{ - if (f_usecs < s_usecs) { - --f_secs; - f_usecs += 1000000; - } - return (f_secs - s_secs) * 1000 + (f_usecs - s_usecs) / 1000; -} - -static void -DRISpinLockTimeout(drmLock * lock, int val, unsigned long timeout /* in mS */ ) -{ - int count = 10000; - -#if !defined(__alpha__) && !defined(__powerpc__) - char ret; -#else - int ret; -#endif - long s_secs, s_usecs; - long f_secs, f_usecs; - long msecs; - long prev = 0; - - DRIGetSecs(&s_secs, &s_usecs); - - do { - DRM_SPINLOCK_COUNT(lock, val, count, ret); - if (!ret) - return; /* Got lock */ - DRIGetSecs(&f_secs, &f_usecs); - msecs = DRIComputeMilliSeconds(s_secs, s_usecs, f_secs, f_usecs); - if (msecs - prev < 250) - count *= 2; /* Not more than 0.5S */ - } while (msecs < timeout); - - /* Didn't get lock, so take it. The worst - that can happen is that there is some - garbage written to the wrong part of the - framebuffer that a refresh will repair. - That's undesirable, but better than - locking the server. This should be a - very rare event. */ - DRM_SPINLOCK_TAKE(lock, val); -} - -static void -DRILockTree(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (!pDRIPriv) - return; - - /* Restore the last known 3D context if the X context is hidden */ - if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) { - (*pDRIPriv->pDriverInfo->SwapContext) (pScreen, - DRI_2D_SYNC, - DRI_NO_CONTEXT, - NULL, - DRI_2D_CONTEXT, - pDRIPriv->partial3DContextStore); - } - - /* Call kernel to release lock */ - DRIUnlock(pScreen); - - /* Grab drawable spin lock: a time out between 10 and 30 seconds is - appropriate, since this should never time out except in the case of - client death while the lock is being held. The timeout must be - greater than any reasonable rendering time. */ - DRISpinLockTimeout(&pDRIPriv->pSAREA->drawable_lock, 1, 10000); /*10 secs */ - - /* Call kernel flush outstanding buffers and relock */ - DRILock(pScreen, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH_ALL); - - /* Switch back to our 2D context if the X context is hidden */ - if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) { - /* hide X context by swapping 2D component here */ - (*pDRIPriv->pDriverInfo->SwapContext) (pScreen, - DRI_3D_SYNC, - DRI_2D_CONTEXT, - pDRIPriv->partial3DContextStore, - DRI_2D_CONTEXT, - pDRIPriv->hiddenContextStore); - } -} - -void -DRIClipNotify(WindowPtr pWin, int dx, int dy) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIDrawablePrivPtr pDRIDrawablePriv; - - if (!pDRIPriv) - return; - - if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) { - int nrects = RegionNumRects(&pWin->clipList); - - if (!pDRIPriv->windowsTouched) { - DRILockTree(pScreen); - pDRIPriv->windowsTouched = TRUE; - } - - if (nrects && !pDRIDrawablePriv->nrects) - DRIIncreaseNumberVisible(pScreen); - else if (!nrects && pDRIDrawablePriv->nrects) - DRIDecreaseNumberVisible(pScreen); - else - DRIDriverClipNotify(pScreen); - - pDRIDrawablePriv->nrects = nrects; - - pDRIPriv->pSAREA->drawableTable[pDRIDrawablePriv->drawableIndex].stamp - = DRIDrawableValidationStamp++; - - drmUpdateDrawableInfo(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable, - DRM_DRAWABLE_CLIPRECTS, - nrects, RegionRects(&pWin->clipList)); - } - - /* call lower wrapped functions */ - if (pDRIPriv->wrap.ClipNotify) { - - /* unwrap */ - pScreen->ClipNotify = pDRIPriv->wrap.ClipNotify; - - /* call lower layers */ - (*pScreen->ClipNotify) (pWin, dx, dy); - - /* rewrap */ - pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify; - pScreen->ClipNotify = DRIClipNotify; - } -} - -CARD32 -DRIGetDrawableIndex(WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); - CARD32 index; - - if (pDRIDrawablePriv) { - index = pDRIDrawablePriv->drawableIndex; - } - else { - index = pDRIPriv->pDriverInfo->ddxDrawableTableEntry; - } - - return index; -} - -unsigned int -DRIGetDrawableStamp(ScreenPtr pScreen, CARD32 drawable_index) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - return pDRIPriv->pSAREA->drawableTable[drawable_index].stamp; -} - -void -DRIPrintDrawableLock(ScreenPtr pScreen, char *msg) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - ErrorF("%s: %d\n", msg, pDRIPriv->pSAREA->drawable_lock.lock); -} - -void -DRILock(ScreenPtr pScreen, int flags) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (!pDRIPriv || !pDRIPriv->pLockRefCount) - return; - - if (!*pDRIPriv->pLockRefCount) { - DRM_LOCK(pDRIPriv->drmFD, pDRIPriv->pLSAREA, pDRIPriv->myContext, - flags); - *pDRIPriv->pLockingContext = pDRIPriv->myContext; - } - else if (*pDRIPriv->pLockingContext != pDRIPriv->myContext) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[DRI] Locking deadlock.\n" - "\tAlready locked with context %p,\n" - "\ttrying to lock with context %p.\n", - pDRIPriv->pLockingContext, (void *) (uintptr_t) pDRIPriv->myContext); - } - (*pDRIPriv->pLockRefCount)++; -} - -void -DRIUnlock(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (!pDRIPriv || !pDRIPriv->pLockRefCount) - return; - - if (*pDRIPriv->pLockRefCount > 0) { - if (pDRIPriv->myContext != *pDRIPriv->pLockingContext) { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "[DRI] Unlocking inconsistency:\n" - "\tContext %p trying to unlock lock held by context %p\n", - pDRIPriv->pLockingContext, (void *) (uintptr_t) pDRIPriv->myContext); - } - (*pDRIPriv->pLockRefCount)--; - } - else { - DRIDrvMsg(pScreen->myNum, X_ERROR, - "DRIUnlock called when not locked.\n"); - return; - } - if (!*pDRIPriv->pLockRefCount) - DRM_UNLOCK(pDRIPriv->drmFD, pDRIPriv->pLSAREA, pDRIPriv->myContext); -} - -void * -DRIGetSAREAPrivate(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (!pDRIPriv) - return 0; - - return (void *) (((char *) pDRIPriv->pSAREA) + sizeof(XF86DRISAREARec)); -} - -drm_context_t -DRIGetContext(ScreenPtr pScreen) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (!pDRIPriv) - return 0; - - return pDRIPriv->myContext; -} - -void -DRIGetTexOffsetFuncs(ScreenPtr pScreen, - DRITexOffsetStartProcPtr * texOffsetStartFunc, - DRITexOffsetFinishProcPtr * texOffsetFinishFunc) -{ - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - - if (!pDRIPriv) - return; - - *texOffsetStartFunc = pDRIPriv->pDriverInfo->texOffsetStart; - *texOffsetFinishFunc = pDRIPriv->pDriverInfo->texOffsetFinish; -} - -/* This lets get at the unwrapped functions so that they can correctly - * call the lowerlevel functions, and choose whether they will be - * called at every level of recursion (eg in validatetree). - */ -DRIWrappedFuncsRec * -DRIGetWrappedFuncs(ScreenPtr pScreen) -{ - return &(DRI_SCREEN_PRIV(pScreen)->wrap); -} - -/* note that this returns the library version, not the protocol version */ -void -DRIQueryVersion(int *majorVersion, int *minorVersion, int *patchVersion) -{ - *majorVersion = DRIINFO_MAJOR_VERSION; - *minorVersion = DRIINFO_MINOR_VERSION; - *patchVersion = DRIINFO_PATCH_VERSION; -} - -static void -_DRIAdjustFrame(ScrnInfoPtr pScrn, DRIScreenPrivPtr pDRIPriv, int x, int y) -{ - pDRIPriv->pSAREA->frame.x = x; - pDRIPriv->pSAREA->frame.y = y; - pDRIPriv->pSAREA->frame.width = pScrn->frameX1 - x + 1; - pDRIPriv->pSAREA->frame.height = pScrn->frameY1 - y + 1; -} - -void -DRIAdjustFrame(ScrnInfoPtr pScrn, int x, int y) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); - int px, py; - - if (!pDRIPriv || !pDRIPriv->pSAREA) { - DRIDrvMsg(pScrn->scrnIndex, X_ERROR, "[DRI] No SAREA (%p %p)\n", - pDRIPriv, pDRIPriv ? pDRIPriv->pSAREA : NULL); - return; - } - - if (pDRIPriv->fullscreen) { - /* Fix up frame */ - pScrn->frameX0 = pDRIPriv->pSAREA->frame.x; - pScrn->frameY0 = pDRIPriv->pSAREA->frame.y; - pScrn->frameX1 = pScrn->frameX0 + pDRIPriv->pSAREA->frame.width - 1; - pScrn->frameY1 = pScrn->frameY0 + pDRIPriv->pSAREA->frame.height - 1; - - /* Fix up cursor */ - miPointerGetPosition(inputInfo.pointer, &px, &py); - - if (px < pScrn->frameX0) - px = pScrn->frameX0; - if (px > pScrn->frameX1) - px = pScrn->frameX1; - if (py < pScrn->frameY0) - py = pScrn->frameY0; - if (py > pScrn->frameY1) - py = pScrn->frameY1; - pScreen->SetCursorPosition(inputInfo.pointer, pScreen, px, py, TRUE); - - return; - } - - if (pDRIPriv->wrap.AdjustFrame) { - /* unwrap */ - pScrn->AdjustFrame = pDRIPriv->wrap.AdjustFrame; - /* call lower layers */ - (*pScrn->AdjustFrame) (pScrn, x, y); - /* rewrap */ - pDRIPriv->wrap.AdjustFrame = pScrn->AdjustFrame; - pScrn->AdjustFrame = DRIAdjustFrame; - } - - _DRIAdjustFrame(pScrn, pDRIPriv, x, y); -} - -/* - * DRIMoveBuffersHelper swaps the regions rects in place leaving you - * a region with the rects in the order that you need to blit them, - * but it is possibly (likely) an invalid region afterwards. If you - * need to use the region again for anything you have to call - * REGION_VALIDATE on it, or better yet, save a copy first. - */ - -void -DRIMoveBuffersHelper(ScreenPtr pScreen, - int dx, int dy, int *xdir, int *ydir, RegionPtr reg) -{ - BoxPtr extents, pbox, firstBox, lastBox; - BoxRec tmpBox; - int y, nbox; - - extents = RegionExtents(reg); - nbox = RegionNumRects(reg); - pbox = RegionRects(reg); - - if ((dy > 0) && (dy < (extents->y2 - extents->y1))) { - *ydir = -1; - if (nbox > 1) { - firstBox = pbox; - lastBox = pbox + nbox - 1; - while ((unsigned long) firstBox < (unsigned long) lastBox) { - tmpBox = *firstBox; - *firstBox = *lastBox; - *lastBox = tmpBox; - firstBox++; - lastBox--; - } - } - } - else - *ydir = 1; - - if ((dx > 0) && (dx < (extents->x2 - extents->x1))) { - *xdir = -1; - if (nbox > 1) { - firstBox = lastBox = pbox; - y = pbox->y1; - while (--nbox) { - pbox++; - if (pbox->y1 == y) - lastBox++; - else { - while ((unsigned long) firstBox < (unsigned long) lastBox) { - tmpBox = *firstBox; - *firstBox = *lastBox; - *lastBox = tmpBox; - firstBox++; - lastBox--; - } - - firstBox = lastBox = pbox; - y = pbox->y1; - } - } - while ((unsigned long) firstBox < (unsigned long) lastBox) { - tmpBox = *firstBox; - *firstBox = *lastBox; - *lastBox = tmpBox; - firstBox++; - lastBox--; - } - } - } - else - *xdir = 1; - -} diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h deleted file mode 100644 index 2ec1c76ea..000000000 --- a/hw/xfree86/dri/dri.h +++ /dev/null @@ -1,342 +0,0 @@ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -All Rights Reserved. - -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, 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 PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Jens Owen - * - */ - -/* Prototypes for DRI functions */ - -#ifndef _DRI_H_ - -#include - -#include "scrnintstr.h" -#include "xf86dri.h" - -typedef int DRISyncType; - -#define DRI_NO_SYNC 0 -#define DRI_2D_SYNC 1 -#define DRI_3D_SYNC 2 - -typedef int DRIContextType; - -typedef struct _DRIContextPrivRec DRIContextPrivRec, *DRIContextPrivPtr; - -typedef enum _DRIContextFlags { - DRI_CONTEXT_2DONLY = 0x01, - DRI_CONTEXT_PRESERVED = 0x02, - DRI_CONTEXT_RESERVED = 0x04 /* DRI Only -- no kernel equivalent */ -} DRIContextFlags; - -#define DRI_NO_CONTEXT 0 -#define DRI_2D_CONTEXT 1 -#define DRI_3D_CONTEXT 2 - -typedef int DRISwapMethod; - -#define DRI_HIDE_X_CONTEXT 0 -#define DRI_SERVER_SWAP 1 -#define DRI_KERNEL_SWAP 2 - -typedef int DRIWindowRequests; - -#define DRI_NO_WINDOWS 0 -#define DRI_3D_WINDOWS_ONLY 1 -#define DRI_ALL_WINDOWS 2 - -typedef void (*ClipNotifyPtr) (WindowPtr, int, int); -typedef void (*AdjustFramePtr) (ScrnInfoPtr pScrn, int x, int y); - -/* - * These functions can be wrapped by the DRI. Each of these have - * generic default funcs (initialized in DRICreateInfoRec) and can be - * overridden by the driver in its [driver]DRIScreenInit function. - */ -typedef struct { - ScreenWakeupHandlerProcPtr WakeupHandler; - ScreenBlockHandlerProcPtr BlockHandler; - WindowExposuresProcPtr WindowExposures; - CopyWindowProcPtr CopyWindow; - ClipNotifyProcPtr ClipNotify; - AdjustFramePtr AdjustFrame; -} DRIWrappedFuncsRec, *DRIWrappedFuncsPtr; - -/* - * Prior to Xorg 6.8.99.8, the DRIInfoRec structure was implicitly versioned - * by the XF86DRI_*_VERSION defines in xf86dristr.h. These numbers were also - * being used to version the XFree86-DRI protocol. Bugs #3066 and #3163 - * showed that this was inadequate. The DRIInfoRec structure is now versioned - * by the DRIINFO_*_VERSION defines in this file. - ajax, 2005-05-18. - * - * Revision history: - * 4.1.0 and earlier: DRIQueryVersion returns XF86DRI_*_VERSION. - * 4.2.0: DRIQueryVersion begins returning DRIINFO_*_VERSION. - * 5.0.0: frameBufferPhysicalAddress changed from CARD32 to pointer. - */ - -#define DRIINFO_MAJOR_VERSION 5 -#define DRIINFO_MINOR_VERSION 4 -#define DRIINFO_PATCH_VERSION 0 - -typedef unsigned long long (*DRITexOffsetStartProcPtr) (PixmapPtr pPix); -typedef void (*DRITexOffsetFinishProcPtr) (PixmapPtr pPix); - -typedef struct { - /* driver call back functions - * - * New fields should be added at the end for backwards compatibility. - * Bump the DRIINFO patch number to indicate bugfixes. - * Bump the DRIINFO minor number to indicate new fields. - * Bump the DRIINFO major number to indicate binary-incompatible changes. - */ - Bool (*CreateContext) (ScreenPtr pScreen, - VisualPtr visual, - drm_context_t hHWContext, - void *pVisualConfigPriv, DRIContextType context); - void (*DestroyContext) (ScreenPtr pScreen, - drm_context_t hHWContext, DRIContextType context); - void (*SwapContext) (ScreenPtr pScreen, - DRISyncType syncType, - DRIContextType readContextType, - void *readContextStore, - DRIContextType writeContextType, - void *writeContextStore); - void (*InitBuffers) (WindowPtr pWin, RegionPtr prgn, CARD32 indx); - void (*MoveBuffers) (WindowPtr pWin, - DDXPointRec ptOldOrg, RegionPtr prgnSrc, CARD32 indx); - void (*TransitionTo3d) (ScreenPtr pScreen); - void (*TransitionTo2d) (ScreenPtr pScreen); - - void (*SetDrawableIndex) (WindowPtr pWin, CARD32 indx); - Bool (*OpenFullScreen) (ScreenPtr pScreen); - Bool (*CloseFullScreen) (ScreenPtr pScreen); - - /* wrapped functions */ - DRIWrappedFuncsRec wrap; - - /* device info */ - char *drmDriverName; - char *clientDriverName; - char *busIdString; - int ddxDriverMajorVersion; - int ddxDriverMinorVersion; - int ddxDriverPatchVersion; - void *frameBufferPhysicalAddress; - long frameBufferSize; - long frameBufferStride; - long SAREASize; - int maxDrawableTableEntry; - int ddxDrawableTableEntry; - long contextSize; - DRISwapMethod driverSwapMethod; - DRIWindowRequests bufferRequests; - int devPrivateSize; - void *devPrivate; - Bool createDummyCtx; - Bool createDummyCtxPriv; - - /* New with DRI version 4.1.0 */ - void (*TransitionSingleToMulti3D) (ScreenPtr pScreen); - void (*TransitionMultiToSingle3D) (ScreenPtr pScreen); - - /* New with DRI version 5.1.0 */ - void (*ClipNotify) (ScreenPtr pScreen, WindowPtr *ppWin, int num); - - /* New with DRI version 5.2.0 */ - Bool allocSarea; - Bool keepFDOpen; - - /* New with DRI version 5.3.0 */ - DRITexOffsetStartProcPtr texOffsetStart; - DRITexOffsetFinishProcPtr texOffsetFinish; - - /* New with DRI version 5.4.0 */ - int dontMapFrameBuffer; - drm_handle_t hFrameBuffer; /* Handle to framebuffer, either - * mapped by DDX driver or DRI */ - -} DRIInfoRec, *DRIInfoPtr; - -extern _X_EXPORT Bool DRIOpenDRMMaster(ScrnInfoPtr pScrn, - unsigned long sAreaSize, - const char *busID, - const char *drmDriverName); - -extern _X_EXPORT Bool DRIScreenInit(ScreenPtr pScreen, - DRIInfoPtr pDRIInfo, int *pDRMFD); - -extern _X_EXPORT void DRICloseScreen(ScreenPtr pScreen); - -extern Bool DRIExtensionInit(void); - -extern _X_EXPORT void DRIReset(void); - -extern _X_EXPORT Bool DRIQueryDirectRenderingCapable(ScreenPtr pScreen, - Bool *isCapable); - -extern _X_EXPORT Bool DRIOpenConnection(ScreenPtr pScreen, - drm_handle_t * hSAREA, - char **busIdString); - -extern _X_EXPORT Bool DRIAuthConnection(ScreenPtr pScreen, drm_magic_t magic); - -extern _X_EXPORT Bool DRICloseConnection(ScreenPtr pScreen); - -extern _X_EXPORT Bool DRIGetClientDriverName(ScreenPtr pScreen, - int *ddxDriverMajorVersion, - int *ddxDriverMinorVersion, - int *ddxDriverPatchVersion, - char **clientDriverName); - -extern _X_EXPORT Bool DRICreateContext(ScreenPtr pScreen, - VisualPtr visual, - XID context, drm_context_t * pHWContext); - -extern _X_EXPORT Bool DRIDestroyContext(ScreenPtr pScreen, XID context); - -extern _X_EXPORT Bool DRIContextPrivDelete(void *pResource, XID id); - -extern _X_EXPORT Bool DRICreateDrawable(ScreenPtr pScreen, - ClientPtr client, - DrawablePtr pDrawable, - drm_drawable_t * hHWDrawable); - -extern _X_EXPORT Bool DRIDestroyDrawable(ScreenPtr pScreen, - ClientPtr client, - DrawablePtr pDrawable); - -extern _X_EXPORT Bool DRIDrawablePrivDelete(void *pResource, XID id); - -extern _X_EXPORT Bool DRIGetDrawableInfo(ScreenPtr pScreen, - DrawablePtr pDrawable, - unsigned int *indx, - unsigned int *stamp, - int *X, - int *Y, - int *W, - int *H, - int *numClipRects, - drm_clip_rect_t ** pClipRects, - int *backX, - int *backY, - int *numBackClipRects, - drm_clip_rect_t ** pBackClipRects); - -extern _X_EXPORT Bool DRIGetDeviceInfo(ScreenPtr pScreen, - drm_handle_t * hFrameBuffer, - int *fbOrigin, - int *fbSize, - int *fbStride, - int *devPrivateSize, void **pDevPrivate); - -extern _X_EXPORT DRIInfoPtr DRICreateInfoRec(void); - -extern _X_EXPORT void DRIDestroyInfoRec(DRIInfoPtr DRIInfo); - -extern _X_EXPORT Bool DRIFinishScreenInit(ScreenPtr pScreen); - -extern _X_EXPORT void DRIWakeupHandler(void *wakeupData, int result); - -extern _X_EXPORT void DRIBlockHandler(void *blockData, void *timeout); - -extern _X_EXPORT void DRIDoWakeupHandler(ScreenPtr pScreen, int result); - -extern _X_EXPORT void DRIDoBlockHandler(ScreenPtr pScreen, void *timeout); - -extern _X_EXPORT void DRISwapContext(int drmFD, void *oldctx, void *newctx); - -extern _X_EXPORT void *DRIGetContextStore(DRIContextPrivPtr context); - -extern _X_EXPORT void DRIWindowExposures(WindowPtr pWin, RegionPtr prgn); - -extern _X_EXPORT Bool DRIDestroyWindow(WindowPtr pWin); - -extern _X_EXPORT void DRICopyWindow(WindowPtr pWin, - DDXPointRec ptOldOrg, RegionPtr prgnSrc); - -extern _X_EXPORT void DRIClipNotify(WindowPtr pWin, int dx, int dy); - -extern _X_EXPORT CARD32 DRIGetDrawableIndex(WindowPtr pWin); - -extern _X_EXPORT void DRIPrintDrawableLock(ScreenPtr pScreen, char *msg); - -extern _X_EXPORT void DRILock(ScreenPtr pScreen, int flags); - -extern _X_EXPORT void DRIUnlock(ScreenPtr pScreen); - -extern _X_EXPORT DRIWrappedFuncsRec *DRIGetWrappedFuncs(ScreenPtr pScreen); - -extern _X_EXPORT void *DRIGetSAREAPrivate(ScreenPtr pScreen); - -extern _X_EXPORT unsigned int DRIGetDrawableStamp(ScreenPtr pScreen, - CARD32 drawable_index); - -extern _X_EXPORT DRIContextPrivPtr DRICreateContextPriv(ScreenPtr pScreen, - drm_context_t * - pHWContext, - DRIContextFlags flags); - -extern _X_EXPORT DRIContextPrivPtr DRICreateContextPrivFromHandle(ScreenPtr - pScreen, - drm_context_t - hHWContext, - DRIContextFlags - flags); - -extern _X_EXPORT Bool DRIDestroyContextPriv(DRIContextPrivPtr pDRIContextPriv); - -extern _X_EXPORT drm_context_t DRIGetContext(ScreenPtr pScreen); - -extern _X_EXPORT void DRIQueryVersion(int *majorVersion, - int *minorVersion, int *patchVersion); - -extern _X_EXPORT void DRIAdjustFrame(ScrnInfoPtr pScrn, int x, int y); - -extern _X_EXPORT void DRIMoveBuffersHelper(ScreenPtr pScreen, - int dx, - int dy, - int *xdir, int *ydir, RegionPtr reg); - -extern _X_EXPORT int DRIMasterFD(ScrnInfoPtr pScrn); - -extern _X_EXPORT void *DRIMasterSareaPointer(ScrnInfoPtr pScrn); - -extern _X_EXPORT drm_handle_t DRIMasterSareaHandle(ScrnInfoPtr pScrn); - -extern _X_EXPORT void DRIGetTexOffsetFuncs(ScreenPtr pScreen, - DRITexOffsetStartProcPtr * - texOffsetStartFunc, - DRITexOffsetFinishProcPtr * - texOffsetFinishFunc); - -#define _DRI_H_ - -#endif diff --git a/hw/xfree86/dri/dristruct.h b/hw/xfree86/dri/dristruct.h deleted file mode 100644 index 9f944a793..000000000 --- a/hw/xfree86/dri/dristruct.h +++ /dev/null @@ -1,124 +0,0 @@ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -All Rights Reserved. - -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, 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 PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Jens Owen - * - */ - -#ifndef DRI_STRUCT_H -#define DRI_STRUCT_H - -#include "xf86drm.h" -#include "xf86Crtc.h" - -#define DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin) ((DRIDrawablePrivPtr) \ - dixLookupPrivate(&(pWin)->devPrivates, DRIWindowPrivKey)) -#define DRI_DRAWABLE_PRIV_FROM_PIXMAP(pPix) ((DRIDrawablePrivPtr) \ - dixLookupPrivate(&(pPix)->devPrivates, DRIWindowPrivKey)) - -typedef struct _DRIDrawablePrivRec { - drm_drawable_t hwDrawable; - int drawableIndex; - ScreenPtr pScreen; - int refCount; - int nrects; -} DRIDrawablePrivRec, *DRIDrawablePrivPtr; - -struct _DRIContextPrivRec { - drm_context_t hwContext; - ScreenPtr pScreen; - Bool valid3D; - DRIContextFlags flags; - void **pContextStore; -}; - -#define DRI_SCREEN_PRIV(pScreen) ((DRIScreenPrivPtr) \ - (dixPrivateKeyRegistered(DRIScreenPrivKey) ? \ - dixLookupPrivate(&(pScreen)->devPrivates, DRIScreenPrivKey) : NULL)) - -#define DRI_SCREEN_PRIV_FROM_INDEX(screenIndex) ((DRIScreenPrivPtr) \ - dixLookupPrivate(&screenInfo.screens[screenIndex]->devPrivates, \ - DRIScreenPrivKey)) - -#define DRI_ENT_PRIV(pScrn) \ - ((DRIEntPrivIndex < 0) ? \ - NULL: \ - ((DRIEntPrivPtr)(xf86GetEntityPrivate((pScrn)->entityList[0], \ - DRIEntPrivIndex)->ptr))) - -typedef struct _DRIScreenPrivRec { - Bool directRenderingSupport; - int drmFD; /* File descriptor for /dev/video/? */ - drm_handle_t hSAREA; /* Handle to SAREA, for mapping */ - XF86DRISAREAPtr pSAREA; /* Mapped pointer to SAREA */ - drm_context_t myContext; /* DDX Driver's context */ - DRIContextPrivPtr myContextPriv; /* Pointer to server's private area */ - DRIContextPrivPtr lastPartial3DContext; /* last one partially saved */ - void **hiddenContextStore; /* hidden X context */ - void **partial3DContextStore; /* parital 3D context */ - DRIInfoPtr pDriverInfo; - int nrWindows; - int nrWindowsVisible; - int nrWalked; - drm_clip_rect_t private_buffer_rect; /* management of private buffers */ - DrawablePtr fullscreen; /* pointer to fullscreen drawable */ - drm_clip_rect_t fullscreen_rect; /* fake rect for fullscreen mode */ - DRIWrappedFuncsRec wrap; - DestroyWindowProcPtr DestroyWindow; - DrawablePtr DRIDrawables[SAREA_MAX_DRAWABLES]; - DRIContextPrivPtr dummyCtxPriv; /* Pointer to dummy context */ - Bool createDummyCtx; - Bool createDummyCtxPriv; - Bool grabbedDRILock; - Bool drmSIGIOHandlerInstalled; - Bool wrapped; - Bool windowsTouched; - int lockRefCount; - drm_handle_t hLSAREA; /* Handle to SAREA containing lock, for mapping */ - XF86DRILSAREAPtr pLSAREA; /* Mapped pointer to SAREA containing lock */ - int *pLockRefCount; - int *pLockingContext; - xf86_crtc_notify_proc_ptr xf86_crtc_notify; -} DRIScreenPrivRec, *DRIScreenPrivPtr; - -typedef struct _DRIEntPrivRec { - int drmFD; - Bool drmOpened; - Bool sAreaGrabbed; - drm_handle_t hLSAREA; - XF86DRILSAREAPtr pLSAREA; - unsigned long sAreaSize; - int lockRefCount; - int lockingContext; - ScreenPtr resOwner; - Bool keepFDOpen; - int refCount; -} DRIEntPrivRec, *DRIEntPrivPtr; - -#endif /* DRI_STRUCT_H */ diff --git a/hw/xfree86/dri/meson.build b/hw/xfree86/dri/meson.build deleted file mode 100644 index 53d1e4f26..000000000 --- a/hw/xfree86/dri/meson.build +++ /dev/null @@ -1,23 +0,0 @@ -srcs_xorg_dri = [ - 'dri.c', - 'xf86dri.c', -] - -xorg_dri = static_library('xorg_dri', - srcs_xorg_dri, - include_directories: [inc, xorg_inc], - dependencies: [ - common_dep, - libdrm_dep, - ], - c_args: xorg_c_args, -) - -install_data( - [ - 'dri.h', - 'sarea.h', - 'dristruct.h', - ], - install_dir: xorgsdkdir, -) diff --git a/hw/xfree86/dri/sarea.h b/hw/xfree86/dri/sarea.h deleted file mode 100644 index 1bef2421e..000000000 --- a/hw/xfree86/dri/sarea.h +++ /dev/null @@ -1,96 +0,0 @@ -/** - * \file sarea.h - * SAREA definitions. - * - * \author Kevin E. Martin - * \author Jens Owen - * \author Rickard E. (Rik) Faith - */ - -/* - * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. - * Copyright 2000 VA Linux Systems, Inc. - * All Rights Reserved. - * - * 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, 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 PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef _SAREA_H_ -#define _SAREA_H_ - -#include "xf86drm.h" - -/* SAREA area needs to be at least a page */ -#if defined(__alpha__) -#define SAREA_MAX 0x2000 -#elif defined(__ia64__) -#define SAREA_MAX 0x10000 /* 64kB */ -#else -/* Intel 830M driver needs at least 8k SAREA */ -#define SAREA_MAX 0x2000 -#endif - -#define SAREA_MAX_DRAWABLES 256 - -#define SAREA_DRAWABLE_CLAIMED_ENTRY 0x80000000 - -/** - * SAREA per drawable information. - * - * \sa _XF86DRISAREA. - */ -typedef struct _XF86DRISAREADrawable { - unsigned int stamp; - unsigned int flags; -} XF86DRISAREADrawableRec, *XF86DRISAREADrawablePtr; - -/** - * SAREA frame information. - * - * \sa _XF86DRISAREA. - */ -typedef struct _XF86DRISAREAFrame { - unsigned int x; - unsigned int y; - unsigned int width; - unsigned int height; - unsigned int fullscreen; -} XF86DRISAREAFrameRec, *XF86DRISAREAFramePtr; - -/** - * SAREA definition. - */ -typedef struct _XF86DRISAREA { - /** first thing is always the DRM locking structure */ - drmLock lock; - /** \todo Use readers/writer lock for drawable_lock */ - drmLock drawable_lock; - XF86DRISAREADrawableRec drawableTable[SAREA_MAX_DRAWABLES]; - XF86DRISAREAFrameRec frame; - drm_context_t dummy_context; -} XF86DRISAREARec, *XF86DRISAREAPtr; - -typedef struct _XF86DRILSAREA { - drmLock lock; - drmLock otherLocks[31]; -} XF86DRILSAREARec, *XF86DRILSAREAPtr; - -#endif diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c deleted file mode 100644 index d356db990..000000000 --- a/hw/xfree86/dri/xf86dri.c +++ /dev/null @@ -1,613 +0,0 @@ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -Copyright 2000 VA Linux Systems, Inc. -All Rights Reserved. - -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, 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 PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Kevin E. Martin - * Jens Owen - * Rickard E. (Rik) Faith - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "xf86.h" - -#include -#include -#include "misc.h" -#include "dixstruct.h" -#include "extnsionst.h" -#include "extinit.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "scrnintstr.h" -#include "servermd.h" -#define _XF86DRI_SERVER_ -#include -#include "swaprep.h" -#include "xf86str.h" -#include "dri.h" -#include "sarea.h" -#include "dristruct.h" -#include "xf86drm.h" -#include "protocol-versions.h" -#include "xf86Extensions.h" - -static int DRIErrorBase; - -static void XF86DRIResetProc(ExtensionEntry *extEntry); - -static unsigned char DRIReqCode = 0; - -/*ARGSUSED*/ -static void -XF86DRIResetProc(ExtensionEntry *extEntry) -{ - DRIReset(); -} - -static int -ProcXF86DRIQueryVersion(register ClientPtr client) -{ - xXF86DRIQueryVersionReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0, - .majorVersion = SERVER_XF86DRI_MAJOR_VERSION, - .minorVersion = SERVER_XF86DRI_MINOR_VERSION, - .patchVersion = SERVER_XF86DRI_PATCH_VERSION - }; - - REQUEST_SIZE_MATCH(xXF86DRIQueryVersionReq); - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swaps(&rep.majorVersion); - swaps(&rep.minorVersion); - swapl(&rep.patchVersion); - } - WriteToClient(client, sizeof(xXF86DRIQueryVersionReply), &rep); - return Success; -} - -static int -ProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client) -{ - xXF86DRIQueryDirectRenderingCapableReply rep; - Bool isCapable; - - REQUEST(xXF86DRIQueryDirectRenderingCapableReq); - REQUEST_SIZE_MATCH(xXF86DRIQueryDirectRenderingCapableReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - if (!DRIQueryDirectRenderingCapable(screenInfo.screens[stuff->screen], - &isCapable)) { - return BadValue; - } - - if (!client->local || client->swapped) - isCapable = 0; - - rep = (xXF86DRIQueryDirectRenderingCapableReply) { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0, - .isCapable = isCapable - }; - - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - } - - WriteToClient(client, - sizeof(xXF86DRIQueryDirectRenderingCapableReply), - &rep); - return Success; -} - -static int -ProcXF86DRIOpenConnection(register ClientPtr client) -{ - xXF86DRIOpenConnectionReply rep; - drm_handle_t hSAREA; - char *busIdString; - CARD32 busIdStringLength = 0; - - REQUEST(xXF86DRIOpenConnectionReq); - REQUEST_SIZE_MATCH(xXF86DRIOpenConnectionReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - if (!DRIOpenConnection(screenInfo.screens[stuff->screen], - &hSAREA, &busIdString)) { - return BadValue; - } - - if (busIdString) - busIdStringLength = strlen(busIdString); - - rep = (xXF86DRIOpenConnectionReply) { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = bytes_to_int32(SIZEOF(xXF86DRIOpenConnectionReply) - - SIZEOF(xGenericReply) + - pad_to_int32(busIdStringLength)), - .busIdStringLength = busIdStringLength, - - .hSAREALow = (CARD32) (hSAREA & 0xffffffff), -#if defined(LONG64) && !defined(__linux__) - .hSAREAHigh = (CARD32) (hSAREA >> 32), -#else - .hSAREAHigh = 0 -#endif - }; - - WriteToClient(client, sizeof(xXF86DRIOpenConnectionReply), &rep); - if (busIdStringLength) - WriteToClient(client, busIdStringLength, busIdString); - return Success; -} - -static int -ProcXF86DRIAuthConnection(register ClientPtr client) -{ - xXF86DRIAuthConnectionReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0, - .authenticated = 1 - }; - - REQUEST(xXF86DRIAuthConnectionReq); - REQUEST_SIZE_MATCH(xXF86DRIAuthConnectionReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - if (!DRIAuthConnection(screenInfo.screens[stuff->screen], stuff->magic)) { - ErrorF("Failed to authenticate %lu\n", (unsigned long) stuff->magic); - rep.authenticated = 0; - } - WriteToClient(client, sizeof(xXF86DRIAuthConnectionReply), &rep); - return Success; -} - -static int -ProcXF86DRICloseConnection(register ClientPtr client) -{ - REQUEST(xXF86DRICloseConnectionReq); - REQUEST_SIZE_MATCH(xXF86DRICloseConnectionReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - DRICloseConnection(screenInfo.screens[stuff->screen]); - - return Success; -} - -static int -ProcXF86DRIGetClientDriverName(register ClientPtr client) -{ - xXF86DRIGetClientDriverNameReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .clientDriverNameLength = 0 - }; - char *clientDriverName; - - REQUEST(xXF86DRIGetClientDriverNameReq); - REQUEST_SIZE_MATCH(xXF86DRIGetClientDriverNameReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - DRIGetClientDriverName(screenInfo.screens[stuff->screen], - (int *) &rep.ddxDriverMajorVersion, - (int *) &rep.ddxDriverMinorVersion, - (int *) &rep.ddxDriverPatchVersion, - &clientDriverName); - - if (clientDriverName) - rep.clientDriverNameLength = strlen(clientDriverName); - rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetClientDriverNameReply) - - SIZEOF(xGenericReply) + - pad_to_int32(rep.clientDriverNameLength)); - - WriteToClient(client, sizeof(xXF86DRIGetClientDriverNameReply), &rep); - if (rep.clientDriverNameLength) - WriteToClient(client, rep.clientDriverNameLength, clientDriverName); - return Success; -} - -static int -ProcXF86DRICreateContext(register ClientPtr client) -{ - xXF86DRICreateContextReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0 - }; - ScreenPtr pScreen; - - REQUEST(xXF86DRICreateContextReq); - REQUEST_SIZE_MATCH(xXF86DRICreateContextReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - pScreen = screenInfo.screens[stuff->screen]; - - if (!DRICreateContext(pScreen, - NULL, - stuff->context, (drm_context_t *) &rep.hHWContext)) { - return BadValue; - } - - WriteToClient(client, sizeof(xXF86DRICreateContextReply), &rep); - return Success; -} - -static int -ProcXF86DRIDestroyContext(register ClientPtr client) -{ - REQUEST(xXF86DRIDestroyContextReq); - REQUEST_SIZE_MATCH(xXF86DRIDestroyContextReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - if (!DRIDestroyContext(screenInfo.screens[stuff->screen], stuff->context)) { - return BadValue; - } - - return Success; -} - -static int -ProcXF86DRICreateDrawable(ClientPtr client) -{ - xXF86DRICreateDrawableReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0 - }; - DrawablePtr pDrawable; - int rc; - - REQUEST(xXF86DRICreateDrawableReq); - REQUEST_SIZE_MATCH(xXF86DRICreateDrawableReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0, - DixReadAccess); - if (rc != Success) - return rc; - - if (!DRICreateDrawable(screenInfo.screens[stuff->screen], client, - pDrawable, (drm_drawable_t *) &rep.hHWDrawable)) { - return BadValue; - } - - WriteToClient(client, sizeof(xXF86DRICreateDrawableReply), &rep); - return Success; -} - -static int -ProcXF86DRIDestroyDrawable(register ClientPtr client) -{ - REQUEST(xXF86DRIDestroyDrawableReq); - DrawablePtr pDrawable; - int rc; - - REQUEST_SIZE_MATCH(xXF86DRIDestroyDrawableReq); - - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0, - DixReadAccess); - if (rc != Success) - return rc; - - if (!DRIDestroyDrawable(screenInfo.screens[stuff->screen], client, - pDrawable)) { - return BadValue; - } - - return Success; -} - -static int -ProcXF86DRIGetDrawableInfo(register ClientPtr client) -{ - xXF86DRIGetDrawableInfoReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0 - }; - DrawablePtr pDrawable; - int X, Y, W, H; - drm_clip_rect_t *pClipRects, *pClippedRects; - drm_clip_rect_t *pBackClipRects; - int backX, backY, rc; - - REQUEST(xXF86DRIGetDrawableInfoReq); - REQUEST_SIZE_MATCH(xXF86DRIGetDrawableInfoReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0, - DixReadAccess); - if (rc != Success) - return rc; - - if (!DRIGetDrawableInfo(screenInfo.screens[stuff->screen], - pDrawable, - (unsigned int *) &rep.drawableTableIndex, - (unsigned int *) &rep.drawableTableStamp, - (int *) &X, - (int *) &Y, - (int *) &W, - (int *) &H, - (int *) &rep.numClipRects, - &pClipRects, - &backX, - &backY, - (int *) &rep.numBackClipRects, &pBackClipRects)) { - return BadValue; - } - - rep.drawableX = X; - rep.drawableY = Y; - rep.drawableWidth = W; - rep.drawableHeight = H; - rep.length = (SIZEOF(xXF86DRIGetDrawableInfoReply) - SIZEOF(xGenericReply)); - - rep.backX = backX; - rep.backY = backY; - - if (rep.numBackClipRects) - rep.length += sizeof(drm_clip_rect_t) * rep.numBackClipRects; - - pClippedRects = pClipRects; - - if (rep.numClipRects) { - /* Clip cliprects to screen dimensions (redirected windows) */ - pClippedRects = xallocarray(rep.numClipRects, sizeof(drm_clip_rect_t)); - - if (pClippedRects) { - ScreenPtr pScreen = screenInfo.screens[stuff->screen]; - int i, j; - - for (i = 0, j = 0; i < rep.numClipRects; i++) { - pClippedRects[j].x1 = max(pClipRects[i].x1, 0); - pClippedRects[j].y1 = max(pClipRects[i].y1, 0); - pClippedRects[j].x2 = min(pClipRects[i].x2, pScreen->width); - pClippedRects[j].y2 = min(pClipRects[i].y2, pScreen->height); - - if (pClippedRects[j].x1 < pClippedRects[j].x2 && - pClippedRects[j].y1 < pClippedRects[j].y2) { - j++; - } - } - - rep.numClipRects = j; - } - else { - rep.numClipRects = 0; - } - - rep.length += sizeof(drm_clip_rect_t) * rep.numClipRects; - } - - rep.length = bytes_to_int32(rep.length); - - WriteToClient(client, sizeof(xXF86DRIGetDrawableInfoReply), &rep); - - if (rep.numClipRects) { - WriteToClient(client, - sizeof(drm_clip_rect_t) * rep.numClipRects, - pClippedRects); - free(pClippedRects); - } - - if (rep.numBackClipRects) { - WriteToClient(client, - sizeof(drm_clip_rect_t) * rep.numBackClipRects, - pBackClipRects); - } - - return Success; -} - -static int -ProcXF86DRIGetDeviceInfo(register ClientPtr client) -{ - xXF86DRIGetDeviceInfoReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0 - }; - drm_handle_t hFrameBuffer; - void *pDevPrivate; - - REQUEST(xXF86DRIGetDeviceInfoReq); - REQUEST_SIZE_MATCH(xXF86DRIGetDeviceInfoReq); - if (stuff->screen >= screenInfo.numScreens) { - client->errorValue = stuff->screen; - return BadValue; - } - - if (!DRIGetDeviceInfo(screenInfo.screens[stuff->screen], - &hFrameBuffer, - (int *) &rep.framebufferOrigin, - (int *) &rep.framebufferSize, - (int *) &rep.framebufferStride, - (int *) &rep.devPrivateSize, &pDevPrivate)) { - return BadValue; - } - - rep.hFrameBufferLow = (CARD32) (hFrameBuffer & 0xffffffff); -#if defined(LONG64) && !defined(__linux__) - rep.hFrameBufferHigh = (CARD32) (hFrameBuffer >> 32); -#else - rep.hFrameBufferHigh = 0; -#endif - - if (rep.devPrivateSize) { - rep.length = bytes_to_int32(SIZEOF(xXF86DRIGetDeviceInfoReply) - - SIZEOF(xGenericReply) + - pad_to_int32(rep.devPrivateSize)); - } - - WriteToClient(client, sizeof(xXF86DRIGetDeviceInfoReply), &rep); - if (rep.length) { - WriteToClient(client, rep.devPrivateSize, pDevPrivate); - } - return Success; -} - -static int -ProcXF86DRIDispatch(register ClientPtr client) -{ - REQUEST(xReq); - - switch (stuff->data) { - case X_XF86DRIQueryVersion: - return ProcXF86DRIQueryVersion(client); - case X_XF86DRIQueryDirectRenderingCapable: - return ProcXF86DRIQueryDirectRenderingCapable(client); - } - - if (!client->local) - return DRIErrorBase + XF86DRIClientNotLocal; - - switch (stuff->data) { - case X_XF86DRIOpenConnection: - return ProcXF86DRIOpenConnection(client); - case X_XF86DRICloseConnection: - return ProcXF86DRICloseConnection(client); - case X_XF86DRIGetClientDriverName: - return ProcXF86DRIGetClientDriverName(client); - case X_XF86DRICreateContext: - return ProcXF86DRICreateContext(client); - case X_XF86DRIDestroyContext: - return ProcXF86DRIDestroyContext(client); - case X_XF86DRICreateDrawable: - return ProcXF86DRICreateDrawable(client); - case X_XF86DRIDestroyDrawable: - return ProcXF86DRIDestroyDrawable(client); - case X_XF86DRIGetDrawableInfo: - return ProcXF86DRIGetDrawableInfo(client); - case X_XF86DRIGetDeviceInfo: - return ProcXF86DRIGetDeviceInfo(client); - case X_XF86DRIAuthConnection: - return ProcXF86DRIAuthConnection(client); - /* {Open,Close}FullScreen are deprecated now */ - default: - return BadRequest; - } -} - -static int _X_COLD -SProcXF86DRIQueryVersion(register ClientPtr client) -{ - REQUEST(xXF86DRIQueryVersionReq); - swaps(&stuff->length); - return ProcXF86DRIQueryVersion(client); -} - -static int _X_COLD -SProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client) -{ - REQUEST(xXF86DRIQueryDirectRenderingCapableReq); - REQUEST_SIZE_MATCH(xXF86DRIQueryDirectRenderingCapableReq); - swaps(&stuff->length); - swapl(&stuff->screen); - return ProcXF86DRIQueryDirectRenderingCapable(client); -} - -static int _X_COLD -SProcXF86DRIDispatch(register ClientPtr client) -{ - REQUEST(xReq); - - /* - * Only local clients are allowed DRI access, but remote clients still need - * these requests to find out cleanly. - */ - switch (stuff->data) { - case X_XF86DRIQueryVersion: - return SProcXF86DRIQueryVersion(client); - case X_XF86DRIQueryDirectRenderingCapable: - return SProcXF86DRIQueryDirectRenderingCapable(client); - default: - return DRIErrorBase + XF86DRIClientNotLocal; - } -} - -void -XFree86DRIExtensionInit(void) -{ - ExtensionEntry *extEntry; - - if (DRIExtensionInit() && - (extEntry = AddExtension(XF86DRINAME, - XF86DRINumberEvents, - XF86DRINumberErrors, - ProcXF86DRIDispatch, - SProcXF86DRIDispatch, - XF86DRIResetProc, StandardMinorOpcode))) { - DRIReqCode = (unsigned char) extEntry->base; - DRIErrorBase = extEntry->errorBase; - } -} diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c deleted file mode 100644 index 3397bb50c..000000000 --- a/hw/xfree86/dri2/dri2.c +++ /dev/null @@ -1,1721 +0,0 @@ -/* - * Copyright © 2007, 2008 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Soft- - * ware"), to deal in the Software without restriction, including without - * limitation the rights to use, copy, modify, merge, publish, distribute, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, provided that the above copyright - * notice(s) and this permission notice appear in all copies of the Soft- - * ware and that both the above copyright notice(s) and this permission - * notice appear in supporting documentation. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- - * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY - * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN - * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- - * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- - * MANCE OF THIS SOFTWARE. - * - * Except as contained in this notice, the name of a copyright holder shall - * not be used in advertising or otherwise to promote the sale, use or - * other dealings in this Software without prior written authorization of - * the copyright holder. - * - * Authors: - * Kristian Høgsberg (krh@redhat.com) - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#ifdef WITH_LIBDRM -#include -#endif -#include "list.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "dixstruct.h" -#include "dri2.h" -#include "dri2int.h" -#include "damage.h" -#include "xf86.h" - -CARD8 dri2_major; /* version of DRI2 supported by DDX */ -CARD8 dri2_minor; - -uint32_t prime_id_allocate_bitmask; - -static DevPrivateKeyRec dri2ScreenPrivateKeyRec; - -#define dri2ScreenPrivateKey (&dri2ScreenPrivateKeyRec) - -static DevPrivateKeyRec dri2WindowPrivateKeyRec; - -#define dri2WindowPrivateKey (&dri2WindowPrivateKeyRec) - -static DevPrivateKeyRec dri2PixmapPrivateKeyRec; - -#define dri2PixmapPrivateKey (&dri2PixmapPrivateKeyRec) - -static DevPrivateKeyRec dri2ClientPrivateKeyRec; - -#define dri2ClientPrivateKey (&dri2ClientPrivateKeyRec) - -#define dri2ClientPrivate(_pClient) (dixLookupPrivate(&(_pClient)->devPrivates, \ - dri2ClientPrivateKey)) - -typedef struct _DRI2Client { - int prime_id; -} DRI2ClientRec, *DRI2ClientPtr; - -static RESTYPE dri2DrawableRes; - -typedef struct _DRI2Screen *DRI2ScreenPtr; - -typedef struct _DRI2Drawable { - DRI2ScreenPtr dri2_screen; - DrawablePtr drawable; - struct xorg_list reference_list; - int width; - int height; - DRI2BufferPtr *buffers; - int bufferCount; - unsigned int swapsPending; - int swap_interval; - CARD64 swap_count; - int64_t target_sbc; /* -1 means no SBC wait outstanding */ - CARD64 last_swap_target; /* most recently queued swap target */ - CARD64 last_swap_msc; /* msc at completion of most recent swap */ - CARD64 last_swap_ust; /* ust at completion of most recent swap */ - int swap_limit; /* for N-buffering */ - unsigned blocked[3]; - Bool needInvalidate; - int prime_id; - PixmapPtr prime_secondary_pixmap; - PixmapPtr redirectpixmap; -} DRI2DrawableRec, *DRI2DrawablePtr; - -typedef struct _DRI2Screen { - ScreenPtr screen; - int refcnt; - unsigned int numDrivers; - const char **driverNames; - const char *deviceName; - int fd; - unsigned int lastSequence; - int prime_id; - - DRI2CreateBufferProcPtr CreateBuffer; - DRI2DestroyBufferProcPtr DestroyBuffer; - DRI2CopyRegionProcPtr CopyRegion; - DRI2ScheduleSwapProcPtr ScheduleSwap; - DRI2GetMSCProcPtr GetMSC; - DRI2ScheduleWaitMSCProcPtr ScheduleWaitMSC; - DRI2AuthMagic2ProcPtr AuthMagic; - DRI2AuthMagicProcPtr LegacyAuthMagic; - DRI2ReuseBufferNotifyProcPtr ReuseBufferNotify; - DRI2SwapLimitValidateProcPtr SwapLimitValidate; - DRI2GetParamProcPtr GetParam; - - HandleExposuresProcPtr HandleExposures; - - ConfigNotifyProcPtr ConfigNotify; - SetWindowPixmapProcPtr SetWindowPixmap; - DRI2CreateBuffer2ProcPtr CreateBuffer2; - DRI2DestroyBuffer2ProcPtr DestroyBuffer2; - DRI2CopyRegion2ProcPtr CopyRegion2; -} DRI2ScreenRec; - -static void -destroy_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, int prime_id); - -enum DRI2WakeType { - WAKE_SBC, - WAKE_MSC, - WAKE_SWAP, -}; - -#define Wake(c, t) (void *)((uintptr_t)(c) | (t)) - -static Bool -dri2WakeClient(ClientPtr client, void *closure) -{ - ClientWakeup(client); - return TRUE; -} - -static Bool -dri2WakeAll(ClientPtr client, DRI2DrawablePtr pPriv, enum DRI2WakeType t) -{ - int count; - - if (!pPriv->blocked[t]) - return FALSE; - - count = ClientSignalAll(client, dri2WakeClient, Wake(pPriv, t)); - pPriv->blocked[t] -= count; - return count; -} - -static Bool -dri2Sleep(ClientPtr client, DRI2DrawablePtr pPriv, enum DRI2WakeType t) -{ - if (ClientSleep(client, dri2WakeClient, Wake(pPriv, t))) { - pPriv->blocked[t]++; - return TRUE; - } - return FALSE; -} - -static DRI2ScreenPtr -DRI2GetScreen(ScreenPtr pScreen) -{ - return dixLookupPrivate(&pScreen->devPrivates, dri2ScreenPrivateKey); -} - -static ScreenPtr -GetScreenPrime(ScreenPtr primary, int prime_id) -{ - ScreenPtr secondary; - if (prime_id == 0) { - return primary; - } - xorg_list_for_each_entry(secondary, &primary->secondary_list, secondary_head) { - DRI2ScreenPtr ds; - - if (!secondary->is_offload_secondary) - continue; - - ds = DRI2GetScreen(secondary); - if (ds == NULL) - continue; - - if (ds->prime_id == prime_id) - return secondary; - } - return primary; -} - -static DRI2ScreenPtr -DRI2GetScreenPrime(ScreenPtr primary, int prime_id) -{ - ScreenPtr secondary = GetScreenPrime(primary, prime_id); - return DRI2GetScreen(secondary); -} - -static DRI2DrawablePtr -DRI2GetDrawable(DrawablePtr pDraw) -{ - WindowPtr pWin; - PixmapPtr pPixmap; - - switch (pDraw->type) { - case DRAWABLE_WINDOW: - pWin = (WindowPtr) pDraw; - return dixLookupPrivate(&pWin->devPrivates, dri2WindowPrivateKey); - case DRAWABLE_PIXMAP: - pPixmap = (PixmapPtr) pDraw; - return dixLookupPrivate(&pPixmap->devPrivates, dri2PixmapPrivateKey); - default: - return NULL; - } -} - -static DRI2DrawablePtr -DRI2AllocateDrawable(DrawablePtr pDraw) -{ - DRI2ScreenPtr ds = DRI2GetScreen(pDraw->pScreen); - DRI2DrawablePtr pPriv; - CARD64 ust; - WindowPtr pWin; - PixmapPtr pPixmap; - - pPriv = malloc(sizeof *pPriv); - if (pPriv == NULL) - return NULL; - - pPriv->dri2_screen = ds; - pPriv->drawable = pDraw; - pPriv->width = pDraw->width; - pPriv->height = pDraw->height; - pPriv->buffers = NULL; - pPriv->bufferCount = 0; - pPriv->swapsPending = 0; - pPriv->swap_count = 0; - pPriv->target_sbc = -1; - pPriv->swap_interval = 1; - /* Initialize last swap target from DDX if possible */ - if (!ds->GetMSC || !(*ds->GetMSC) (pDraw, &ust, &pPriv->last_swap_target)) - pPriv->last_swap_target = 0; - - memset(pPriv->blocked, 0, sizeof(pPriv->blocked)); - pPriv->swap_limit = 1; /* default to double buffering */ - pPriv->last_swap_msc = 0; - pPriv->last_swap_ust = 0; - xorg_list_init(&pPriv->reference_list); - pPriv->needInvalidate = FALSE; - pPriv->redirectpixmap = NULL; - pPriv->prime_secondary_pixmap = NULL; - if (pDraw->type == DRAWABLE_WINDOW) { - pWin = (WindowPtr) pDraw; - dixSetPrivate(&pWin->devPrivates, dri2WindowPrivateKey, pPriv); - } - else { - pPixmap = (PixmapPtr) pDraw; - dixSetPrivate(&pPixmap->devPrivates, dri2PixmapPrivateKey, pPriv); - } - - return pPriv; -} - -Bool -DRI2SwapLimit(DrawablePtr pDraw, int swap_limit) -{ - DRI2DrawablePtr pPriv = DRI2GetDrawable(pDraw); - DRI2ScreenPtr ds; - - if (!pPriv) - return FALSE; - - ds = pPriv->dri2_screen; - - if (!ds->SwapLimitValidate || !ds->SwapLimitValidate(pDraw, swap_limit)) - return FALSE; - - pPriv->swap_limit = swap_limit; - - /* Check throttling */ - if (pPriv->swapsPending >= pPriv->swap_limit) - return TRUE; - - dri2WakeAll(CLIENT_SIGNAL_ANY, pPriv, WAKE_SWAP); - return TRUE; -} - -typedef struct DRI2DrawableRefRec { - XID id; - XID dri2_id; - DRI2InvalidateProcPtr invalidate; - void *priv; - struct xorg_list link; -} DRI2DrawableRefRec, *DRI2DrawableRefPtr; - -static DRI2DrawableRefPtr -DRI2LookupDrawableRef(DRI2DrawablePtr pPriv, XID id) -{ - DRI2DrawableRefPtr ref; - - xorg_list_for_each_entry(ref, &pPriv->reference_list, link) { - if (ref->id == id) - return ref; - } - - return NULL; -} - -static int -DRI2AddDrawableRef(DRI2DrawablePtr pPriv, XID id, XID dri2_id, - DRI2InvalidateProcPtr invalidate, void *priv) -{ - DRI2DrawableRefPtr ref; - - ref = malloc(sizeof *ref); - if (ref == NULL) - return BadAlloc; - - if (!AddResource(dri2_id, dri2DrawableRes, pPriv)) { - free(ref); - return BadAlloc; - } - if (!DRI2LookupDrawableRef(pPriv, id)) - if (!AddResource(id, dri2DrawableRes, pPriv)) { - FreeResourceByType(dri2_id, dri2DrawableRes, TRUE); - free(ref); - return BadAlloc; - } - - ref->id = id; - ref->dri2_id = dri2_id; - ref->invalidate = invalidate; - ref->priv = priv; - xorg_list_add(&ref->link, &pPriv->reference_list); - - return Success; -} - -int -DRI2CreateDrawable2(ClientPtr client, DrawablePtr pDraw, XID id, - DRI2InvalidateProcPtr invalidate, void *priv, - XID *dri2_id_out) -{ - DRI2DrawablePtr pPriv; - DRI2ClientPtr dri2_client = dri2ClientPrivate(client); - XID dri2_id; - int rc; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) - pPriv = DRI2AllocateDrawable(pDraw); - if (pPriv == NULL) - return BadAlloc; - - pPriv->prime_id = dri2_client->prime_id; - - dri2_id = FakeClientID(client->index); - rc = DRI2AddDrawableRef(pPriv, id, dri2_id, invalidate, priv); - if (rc != Success) - return rc; - - if (dri2_id_out) - *dri2_id_out = dri2_id; - - return Success; -} - -int -DRI2CreateDrawable(ClientPtr client, DrawablePtr pDraw, XID id, - DRI2InvalidateProcPtr invalidate, void *priv) -{ - return DRI2CreateDrawable2(client, pDraw, id, invalidate, priv, NULL); -} - -static int -DRI2DrawableGone(void *p, XID id) -{ - DRI2DrawablePtr pPriv = p; - DRI2DrawableRefPtr ref, next; - WindowPtr pWin; - PixmapPtr pPixmap; - DrawablePtr pDraw; - int i; - - xorg_list_for_each_entry_safe(ref, next, &pPriv->reference_list, link) { - if (ref->dri2_id == id) { - xorg_list_del(&ref->link); - /* If this was the last ref under this X drawable XID, - * unregister the X drawable resource. */ - if (!DRI2LookupDrawableRef(pPriv, ref->id)) - FreeResourceByType(ref->id, dri2DrawableRes, TRUE); - free(ref); - break; - } - - if (ref->id == id) { - xorg_list_del(&ref->link); - FreeResourceByType(ref->dri2_id, dri2DrawableRes, TRUE); - free(ref); - } - } - - if (!xorg_list_is_empty(&pPriv->reference_list)) - return Success; - - pDraw = pPriv->drawable; - if (pDraw->type == DRAWABLE_WINDOW) { - pWin = (WindowPtr) pDraw; - dixSetPrivate(&pWin->devPrivates, dri2WindowPrivateKey, NULL); - } - else { - pPixmap = (PixmapPtr) pDraw; - dixSetPrivate(&pPixmap->devPrivates, dri2PixmapPrivateKey, NULL); - } - - if (pPriv->prime_secondary_pixmap) { - (*pPriv->prime_secondary_pixmap->primary_pixmap->drawable.pScreen->DestroyPixmap)(pPriv->prime_secondary_pixmap->primary_pixmap); - (*pPriv->prime_secondary_pixmap->drawable.pScreen->DestroyPixmap)(pPriv->prime_secondary_pixmap); - } - - if (pPriv->buffers != NULL) { - for (i = 0; i < pPriv->bufferCount; i++) - destroy_buffer(pDraw, pPriv->buffers[i], pPriv->prime_id); - - free(pPriv->buffers); - } - - if (pPriv->redirectpixmap) { - (*pDraw->pScreen->ReplaceScanoutPixmap)(pDraw, pPriv->redirectpixmap, FALSE); - (*pDraw->pScreen->DestroyPixmap)(pPriv->redirectpixmap); - } - - dri2WakeAll(CLIENT_SIGNAL_ANY, pPriv, WAKE_SWAP); - dri2WakeAll(CLIENT_SIGNAL_ANY, pPriv, WAKE_MSC); - dri2WakeAll(CLIENT_SIGNAL_ANY, pPriv, WAKE_SBC); - - free(pPriv); - - return Success; -} - -static DRI2BufferPtr -create_buffer(DRI2ScreenPtr ds, DrawablePtr pDraw, - unsigned int attachment, unsigned int format) -{ - DRI2BufferPtr buffer; - if (ds->CreateBuffer2) - buffer = (*ds->CreateBuffer2)(GetScreenPrime(pDraw->pScreen, - DRI2GetDrawable(pDraw)->prime_id), - pDraw, attachment, format); - else - buffer = (*ds->CreateBuffer)(pDraw, attachment, format); - return buffer; -} - -static void -destroy_buffer(DrawablePtr pDraw, DRI2BufferPtr buffer, int prime_id) -{ - ScreenPtr primeScreen; - DRI2ScreenPtr ds; - primeScreen = GetScreenPrime(pDraw->pScreen, prime_id); - ds = DRI2GetScreen(primeScreen); - if (ds->DestroyBuffer2) - (*ds->DestroyBuffer2)(primeScreen, pDraw, buffer); - else - (*ds->DestroyBuffer)(pDraw, buffer); -} - -static int -find_attachment(DRI2DrawablePtr pPriv, unsigned attachment) -{ - int i; - - if (pPriv->buffers == NULL) { - return -1; - } - - for (i = 0; i < pPriv->bufferCount; i++) { - if ((pPriv->buffers[i] != NULL) - && (pPriv->buffers[i]->attachment == attachment)) { - return i; - } - } - - return -1; -} - -static Bool -allocate_or_reuse_buffer(DrawablePtr pDraw, DRI2ScreenPtr ds, - DRI2DrawablePtr pPriv, - unsigned int attachment, unsigned int format, - int dimensions_match, DRI2BufferPtr * buffer) -{ - int old_buf = find_attachment(pPriv, attachment); - - if ((old_buf < 0) - || attachment == DRI2BufferFrontLeft - || !dimensions_match || (pPriv->buffers[old_buf]->format != format)) { - *buffer = create_buffer(ds, pDraw, attachment, format); - return TRUE; - - } - else { - *buffer = pPriv->buffers[old_buf]; - - if (ds->ReuseBufferNotify) - (*ds->ReuseBufferNotify) (pDraw, *buffer); - - pPriv->buffers[old_buf] = NULL; - return FALSE; - } -} - -static void -update_dri2_drawable_buffers(DRI2DrawablePtr pPriv, DrawablePtr pDraw, - DRI2BufferPtr * buffers, int out_count, int *width, - int *height) -{ - int i; - - if (pPriv->buffers != NULL) { - for (i = 0; i < pPriv->bufferCount; i++) { - if (pPriv->buffers[i] != NULL) { - destroy_buffer(pDraw, pPriv->buffers[i], pPriv->prime_id); - } - } - - free(pPriv->buffers); - } - - pPriv->buffers = buffers; - pPriv->bufferCount = out_count; - pPriv->width = pDraw->width; - pPriv->height = pDraw->height; - *width = pPriv->width; - *height = pPriv->height; -} - -static DRI2BufferPtr * -do_get_buffers(DrawablePtr pDraw, int *width, int *height, - unsigned int *attachments, int count, int *out_count, - int has_format) -{ - DRI2DrawablePtr pPriv = DRI2GetDrawable(pDraw); - DRI2ScreenPtr ds; - DRI2BufferPtr *buffers; - int need_real_front = 0; - int need_fake_front = 0; - int have_fake_front = 0; - int front_format = 0; - int dimensions_match; - int buffers_changed = 0; - int i; - - if (!pPriv) { - *width = pDraw->width; - *height = pDraw->height; - *out_count = 0; - return NULL; - } - - ds = DRI2GetScreenPrime(pDraw->pScreen, pPriv->prime_id); - - dimensions_match = (pDraw->width == pPriv->width) - && (pDraw->height == pPriv->height); - - buffers = calloc((count + 1), sizeof(buffers[0])); - if (!buffers) - goto err_out; - - for (i = 0; i < count; i++) { - const unsigned attachment = *(attachments++); - const unsigned format = (has_format) ? *(attachments++) : 0; - - if (allocate_or_reuse_buffer(pDraw, ds, pPriv, attachment, - format, dimensions_match, &buffers[i])) - buffers_changed = 1; - - if (buffers[i] == NULL) - goto err_out; - - /* If the drawable is a window and the front-buffer is requested, - * silently add the fake front-buffer to the list of requested - * attachments. The counting logic in the loop accounts for the case - * where the client requests both the fake and real front-buffer. - */ - if (attachment == DRI2BufferBackLeft) { - need_real_front++; - front_format = format; - } - - if (attachment == DRI2BufferFrontLeft) { - need_real_front--; - front_format = format; - - if (pDraw->type == DRAWABLE_WINDOW) { - need_fake_front++; - } - } - - if (pDraw->type == DRAWABLE_WINDOW) { - if (attachment == DRI2BufferFakeFrontLeft) { - need_fake_front--; - have_fake_front = 1; - } - } - } - - if (need_real_front > 0) { - if (allocate_or_reuse_buffer(pDraw, ds, pPriv, DRI2BufferFrontLeft, - front_format, dimensions_match, - &buffers[i])) - buffers_changed = 1; - - if (buffers[i] == NULL) - goto err_out; - i++; - } - - if (need_fake_front > 0) { - if (allocate_or_reuse_buffer(pDraw, ds, pPriv, DRI2BufferFakeFrontLeft, - front_format, dimensions_match, - &buffers[i])) - buffers_changed = 1; - - if (buffers[i] == NULL) - goto err_out; - - i++; - have_fake_front = 1; - } - - *out_count = i; - - update_dri2_drawable_buffers(pPriv, pDraw, buffers, *out_count, width, - height); - - /* If the client is getting a fake front-buffer, pre-fill it with the - * contents of the real front-buffer. This ensures correct operation of - * applications that call glXWaitX before calling glDrawBuffer. - */ - if (have_fake_front && buffers_changed) { - BoxRec box; - RegionRec region; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pPriv->width; - box.y2 = pPriv->height; - RegionInit(®ion, &box, 0); - - DRI2CopyRegion(pDraw, ®ion, DRI2BufferFakeFrontLeft, - DRI2BufferFrontLeft); - } - - pPriv->needInvalidate = TRUE; - - return pPriv->buffers; - - err_out: - - *out_count = 0; - - if (buffers) { - for (i = 0; i < count; i++) { - if (buffers[i] != NULL) - destroy_buffer(pDraw, buffers[i], 0); - } - - free(buffers); - buffers = NULL; - } - - update_dri2_drawable_buffers(pPriv, pDraw, buffers, *out_count, width, - height); - - return buffers; -} - -DRI2BufferPtr * -DRI2GetBuffers(DrawablePtr pDraw, int *width, int *height, - unsigned int *attachments, int count, int *out_count) -{ - return do_get_buffers(pDraw, width, height, attachments, count, - out_count, FALSE); -} - -DRI2BufferPtr * -DRI2GetBuffersWithFormat(DrawablePtr pDraw, int *width, int *height, - unsigned int *attachments, int count, int *out_count) -{ - return do_get_buffers(pDraw, width, height, attachments, count, - out_count, TRUE); -} - -static void -DRI2InvalidateDrawable(DrawablePtr pDraw) -{ - DRI2DrawablePtr pPriv = DRI2GetDrawable(pDraw); - DRI2DrawableRefPtr ref; - - if (!pPriv || !pPriv->needInvalidate) - return; - - pPriv->needInvalidate = FALSE; - - xorg_list_for_each_entry(ref, &pPriv->reference_list, link) - ref->invalidate(pDraw, ref->priv, ref->id); -} - -/* - * In the direct rendered case, we throttle the clients that have more - * than their share of outstanding swaps (and thus busy buffers) when a - * new GetBuffers request is received. In the AIGLX case, we allow the - * client to get the new buffers, but throttle when the next GLX request - * comes in (see __glXDRIcontextWait()). - */ -Bool -DRI2ThrottleClient(ClientPtr client, DrawablePtr pDraw) -{ - DRI2DrawablePtr pPriv; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) - return FALSE; - - /* Throttle to swap limit */ - if (pPriv->swapsPending >= pPriv->swap_limit) { - if (dri2Sleep(client, pPriv, WAKE_SWAP)) { - ResetCurrentRequest(client); - client->sequence--; - return TRUE; - } - } - - return FALSE; -} - -void -DRI2BlockClient(ClientPtr client, DrawablePtr pDraw) -{ - DRI2DrawablePtr pPriv; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) - return; - - dri2Sleep(client, pPriv, WAKE_MSC); -} - -static inline PixmapPtr GetDrawablePixmap(DrawablePtr drawable) -{ - if (drawable->type == DRAWABLE_PIXMAP) - return (PixmapPtr)drawable; - else { - struct _Window *pWin = (struct _Window *)drawable; - return drawable->pScreen->GetWindowPixmap(pWin); - } -} - -/* - * A TraverseTree callback to invalidate all windows using the same - * pixmap - */ -static int -DRI2InvalidateWalk(WindowPtr pWin, void *data) -{ - if (pWin->drawable.pScreen->GetWindowPixmap(pWin) != data) - return WT_DONTWALKCHILDREN; - DRI2InvalidateDrawable(&pWin->drawable); - return WT_WALKCHILDREN; -} - -static void -DRI2InvalidateDrawableAll(DrawablePtr pDraw) -{ - if (pDraw->type == DRAWABLE_WINDOW) { - WindowPtr pWin = (WindowPtr) pDraw; - PixmapPtr pPixmap = pDraw->pScreen->GetWindowPixmap(pWin); - - /* - * Find the top-most window using this pixmap - */ - while (pWin->parent && - pDraw->pScreen->GetWindowPixmap(pWin->parent) == pPixmap) - pWin = pWin->parent; - - /* - * Walk the sub-tree to invalidate all of the - * windows using the same pixmap - */ - TraverseTree(pWin, DRI2InvalidateWalk, pPixmap); - DRI2InvalidateDrawable(&pPixmap->drawable); - } - else - DRI2InvalidateDrawable(pDraw); -} - -DrawablePtr DRI2UpdatePrime(DrawablePtr pDraw, DRI2BufferPtr pDest) -{ - DRI2DrawablePtr pPriv = DRI2GetDrawable(pDraw); - PixmapPtr spix; - PixmapPtr mpix = GetDrawablePixmap(pDraw); - ScreenPtr primary, secondary; - Bool ret; - - primary = mpix->drawable.pScreen; - - if (pDraw->type == DRAWABLE_WINDOW) { - WindowPtr pWin = (WindowPtr)pDraw; - PixmapPtr pPixmap = pDraw->pScreen->GetWindowPixmap(pWin); - - if (pDraw->pScreen->GetScreenPixmap(pDraw->pScreen) == pPixmap) { - if (pPriv->redirectpixmap && - pPriv->redirectpixmap->drawable.width == pDraw->width && - pPriv->redirectpixmap->drawable.height == pDraw->height && - pPriv->redirectpixmap->drawable.depth == pDraw->depth) { - mpix = pPriv->redirectpixmap; - } else { - if (primary->ReplaceScanoutPixmap) { - mpix = (*primary->CreatePixmap)(primary, pDraw->width, pDraw->height, - pDraw->depth, CREATE_PIXMAP_USAGE_SHARED); - if (!mpix) - return NULL; - - ret = (*primary->ReplaceScanoutPixmap)(pDraw, mpix, TRUE); - if (ret == FALSE) { - (*primary->DestroyPixmap)(mpix); - return NULL; - } - pPriv->redirectpixmap = mpix; - } else - return NULL; - } - } else if (pPriv->redirectpixmap) { - (*primary->ReplaceScanoutPixmap)(pDraw, pPriv->redirectpixmap, FALSE); - (*primary->DestroyPixmap)(pPriv->redirectpixmap); - pPriv->redirectpixmap = NULL; - } - } - - secondary = GetScreenPrime(pDraw->pScreen, pPriv->prime_id); - - /* check if the pixmap is still fine */ - if (pPriv->prime_secondary_pixmap) { - if (pPriv->prime_secondary_pixmap->primary_pixmap == mpix) - return &pPriv->prime_secondary_pixmap->drawable; - else { - PixmapUnshareSecondaryPixmap(pPriv->prime_secondary_pixmap); - (*pPriv->prime_secondary_pixmap->primary_pixmap->drawable.pScreen->DestroyPixmap)(pPriv->prime_secondary_pixmap->primary_pixmap); - (*secondary->DestroyPixmap)(pPriv->prime_secondary_pixmap); - pPriv->prime_secondary_pixmap = NULL; - } - } - - spix = PixmapShareToSecondary(mpix, secondary); - if (!spix) - return NULL; - - pPriv->prime_secondary_pixmap = spix; -#ifdef COMPOSITE - spix->screen_x = mpix->screen_x; - spix->screen_y = mpix->screen_y; -#endif - - DRI2InvalidateDrawableAll(pDraw); - return &spix->drawable; -} - -static void dri2_copy_region(DrawablePtr pDraw, RegionPtr pRegion, - DRI2BufferPtr pDest, DRI2BufferPtr pSrc) -{ - DRI2DrawablePtr pPriv = DRI2GetDrawable(pDraw); - DRI2ScreenPtr ds; - ScreenPtr primeScreen; - - primeScreen = GetScreenPrime(pDraw->pScreen, pPriv->prime_id); - ds = DRI2GetScreen(primeScreen); - - if (ds->CopyRegion2) - (*ds->CopyRegion2)(primeScreen, pDraw, pRegion, pDest, pSrc); - else - (*ds->CopyRegion) (pDraw, pRegion, pDest, pSrc); - - /* cause damage to the box */ - if (pPriv->prime_id) { - BoxRec box; - RegionRec region; - box.x1 = 0; - box.x2 = box.x1 + pDraw->width; - box.y1 = 0; - box.y2 = box.y1 + pDraw->height; - RegionInit(®ion, &box, 1); - RegionTranslate(®ion, pDraw->x, pDraw->y); - DamageRegionAppend(pDraw, ®ion); - DamageRegionProcessPending(pDraw); - RegionUninit(®ion); - } -} - -int -DRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion, - unsigned int dest, unsigned int src) -{ - DRI2DrawablePtr pPriv; - DRI2BufferPtr pDestBuffer, pSrcBuffer; - int i; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) - return BadDrawable; - - pDestBuffer = NULL; - pSrcBuffer = NULL; - for (i = 0; i < pPriv->bufferCount; i++) { - if (pPriv->buffers[i]->attachment == dest) - pDestBuffer = (DRI2BufferPtr) pPriv->buffers[i]; - if (pPriv->buffers[i]->attachment == src) - pSrcBuffer = (DRI2BufferPtr) pPriv->buffers[i]; - } - if (pSrcBuffer == NULL || pDestBuffer == NULL) - return BadValue; - - dri2_copy_region(pDraw, pRegion, pDestBuffer, pSrcBuffer); - - return Success; -} - -/* Can this drawable be page flipped? */ -Bool -DRI2CanFlip(DrawablePtr pDraw) -{ - ScreenPtr pScreen = pDraw->pScreen; - WindowPtr pWin, pRoot; - PixmapPtr pWinPixmap, pRootPixmap; - - if (pDraw->type == DRAWABLE_PIXMAP) - return TRUE; - - pRoot = pScreen->root; - pRootPixmap = pScreen->GetWindowPixmap(pRoot); - - pWin = (WindowPtr) pDraw; - pWinPixmap = pScreen->GetWindowPixmap(pWin); - if (pRootPixmap != pWinPixmap) - return FALSE; - if (!RegionEqual(&pWin->clipList, &pRoot->winSize)) - return FALSE; - - /* Does the window match the pixmap exactly? */ - if (pDraw->x != 0 || pDraw->y != 0 || -#ifdef COMPOSITE - pDraw->x != pWinPixmap->screen_x || pDraw->y != pWinPixmap->screen_y || -#endif - pDraw->width != pWinPixmap->drawable.width || - pDraw->height != pWinPixmap->drawable.height) - return FALSE; - - return TRUE; -} - -/* Can we do a pixmap exchange instead of a blit? */ -Bool -DRI2CanExchange(DrawablePtr pDraw) -{ - return FALSE; -} - -void -DRI2WaitMSCComplete(ClientPtr client, DrawablePtr pDraw, int frame, - unsigned int tv_sec, unsigned int tv_usec) -{ - DRI2DrawablePtr pPriv; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) - return; - - ProcDRI2WaitMSCReply(client, ((CARD64) tv_sec * 1000000) + tv_usec, - frame, pPriv->swap_count); - - dri2WakeAll(client, pPriv, WAKE_MSC); -} - -static void -DRI2WakeClient(ClientPtr client, DrawablePtr pDraw, int frame, - unsigned int tv_sec, unsigned int tv_usec) -{ - ScreenPtr pScreen = pDraw->pScreen; - DRI2DrawablePtr pPriv; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[DRI2] %s: bad drawable\n", __func__); - return; - } - - /* - * Swap completed. - * Wake the client iff: - * - it was waiting on SBC - * - was blocked due to GLX make current - * - was blocked due to swap throttling - * - is not blocked due to an MSC wait - */ - if (pPriv->target_sbc != -1 && pPriv->target_sbc <= pPriv->swap_count) { - if (dri2WakeAll(client, pPriv, WAKE_SBC)) { - ProcDRI2WaitMSCReply(client, ((CARD64) tv_sec * 1000000) + tv_usec, - frame, pPriv->swap_count); - pPriv->target_sbc = -1; - } - } - - dri2WakeAll(CLIENT_SIGNAL_ANY, pPriv, WAKE_SWAP); -} - -void -DRI2SwapComplete(ClientPtr client, DrawablePtr pDraw, int frame, - unsigned int tv_sec, unsigned int tv_usec, int type, - DRI2SwapEventPtr swap_complete, void *swap_data) -{ - ScreenPtr pScreen = pDraw->pScreen; - DRI2DrawablePtr pPriv; - CARD64 ust = 0; - BoxRec box; - RegionRec region; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[DRI2] %s: bad drawable\n", __func__); - return; - } - - pPriv->swapsPending--; - pPriv->swap_count++; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pDraw->width; - box.y2 = pDraw->height; - RegionInit(®ion, &box, 0); - DRI2CopyRegion(pDraw, ®ion, DRI2BufferFakeFrontLeft, - DRI2BufferFrontLeft); - - ust = ((CARD64) tv_sec * 1000000) + tv_usec; - if (swap_complete) - swap_complete(client, swap_data, type, ust, frame, pPriv->swap_count); - - pPriv->last_swap_msc = frame; - pPriv->last_swap_ust = ust; - - DRI2WakeClient(client, pDraw, frame, tv_sec, tv_usec); -} - -Bool -DRI2WaitSwap(ClientPtr client, DrawablePtr pDrawable) -{ - DRI2DrawablePtr pPriv = DRI2GetDrawable(pDrawable); - - /* If we're currently waiting for a swap on this drawable, reset - * the request and suspend the client. */ - if (pPriv && pPriv->swapsPending) { - if (dri2Sleep(client, pPriv, WAKE_SWAP)) { - ResetCurrentRequest(client); - client->sequence--; - return TRUE; - } - } - - return FALSE; -} - - - -int -DRI2SwapBuffers(ClientPtr client, DrawablePtr pDraw, CARD64 target_msc, - CARD64 divisor, CARD64 remainder, CARD64 * swap_target, - DRI2SwapEventPtr func, void *data) -{ - ScreenPtr pScreen = pDraw->pScreen; - DRI2ScreenPtr ds = DRI2GetScreen(pDraw->pScreen); - DRI2DrawablePtr pPriv; - DRI2BufferPtr pDestBuffer = NULL, pSrcBuffer = NULL; - int ret, i; - CARD64 ust, current_msc; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[DRI2] %s: bad drawable\n", __func__); - return BadDrawable; - } - - /* According to spec, return expected swapbuffers count SBC after this swap - * will complete. This is ignored unless we return Success, but it must be - * initialized on every path where we return Success or the caller will send - * an uninitialized value off the stack to the client. So let's initialize - * it as early as possible, just to be sure. - */ - *swap_target = pPriv->swap_count + pPriv->swapsPending + 1; - - for (i = 0; i < pPriv->bufferCount; i++) { - if (pPriv->buffers[i]->attachment == DRI2BufferFrontLeft) - pDestBuffer = (DRI2BufferPtr) pPriv->buffers[i]; - if (pPriv->buffers[i]->attachment == DRI2BufferBackLeft) - pSrcBuffer = (DRI2BufferPtr) pPriv->buffers[i]; - } - if (pSrcBuffer == NULL || pDestBuffer == NULL) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[DRI2] %s: drawable has no back or front?\n", __func__); - return BadDrawable; - } - - /* Old DDX or no swap interval, just blit */ - if (!ds->ScheduleSwap || !pPriv->swap_interval || pPriv->prime_id) { - BoxRec box; - RegionRec region; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pDraw->width; - box.y2 = pDraw->height; - RegionInit(®ion, &box, 0); - - pPriv->swapsPending++; - - dri2_copy_region(pDraw, ®ion, pDestBuffer, pSrcBuffer); - DRI2SwapComplete(client, pDraw, target_msc, 0, 0, DRI2_BLIT_COMPLETE, - func, data); - return Success; - } - - /* - * In the simple glXSwapBuffers case, all params will be 0, and we just - * need to schedule a swap for the last swap target + the swap interval. - */ - if (target_msc == 0 && divisor == 0 && remainder == 0) { - /* If the current vblank count of the drawable's crtc is lower - * than the count stored in last_swap_target from a previous swap - * then reinitialize last_swap_target to the current crtc's msc, - * otherwise the swap will hang. This will happen if the drawable - * is moved to a crtc with a lower refresh rate, or a crtc that just - * got enabled. - */ - if (ds->GetMSC) { - if (!(*ds->GetMSC) (pDraw, &ust, ¤t_msc)) - pPriv->last_swap_target = 0; - - if (current_msc < pPriv->last_swap_target) - pPriv->last_swap_target = current_msc; - - } - - /* - * Swap target for this swap is last swap target + swap interval since - * we have to account for the current swap count, interval, and the - * number of pending swaps. - */ - target_msc = pPriv->last_swap_target + pPriv->swap_interval; - - } - - pPriv->swapsPending++; - ret = (*ds->ScheduleSwap) (client, pDraw, pDestBuffer, pSrcBuffer, - &target_msc, divisor, remainder, func, data); - if (!ret) { - pPriv->swapsPending--; /* didn't schedule */ - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[DRI2] %s: driver failed to schedule swap\n", __func__); - return BadDrawable; - } - - pPriv->last_swap_target = target_msc; - - DRI2InvalidateDrawableAll(pDraw); - - return Success; -} - -void -DRI2SwapInterval(DrawablePtr pDrawable, int interval) -{ - ScreenPtr pScreen = pDrawable->pScreen; - DRI2DrawablePtr pPriv = DRI2GetDrawable(pDrawable); - - if (pPriv == NULL) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[DRI2] %s: bad drawable\n", __func__); - return; - } - - /* fixme: check against arbitrary max? */ - pPriv->swap_interval = interval; -} - -int -DRI2GetMSC(DrawablePtr pDraw, CARD64 * ust, CARD64 * msc, CARD64 * sbc) -{ - ScreenPtr pScreen = pDraw->pScreen; - DRI2ScreenPtr ds = DRI2GetScreen(pDraw->pScreen); - DRI2DrawablePtr pPriv; - Bool ret; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[DRI2] %s: bad drawable\n", __func__); - return BadDrawable; - } - - if (!ds->GetMSC) { - *ust = 0; - *msc = 0; - *sbc = pPriv->swap_count; - return Success; - } - - /* - * Spec needs to be updated to include unmapped or redirected - * drawables - */ - - ret = (*ds->GetMSC) (pDraw, ust, msc); - if (!ret) - return BadDrawable; - - *sbc = pPriv->swap_count; - - return Success; -} - -int -DRI2WaitMSC(ClientPtr client, DrawablePtr pDraw, CARD64 target_msc, - CARD64 divisor, CARD64 remainder) -{ - DRI2ScreenPtr ds = DRI2GetScreen(pDraw->pScreen); - DRI2DrawablePtr pPriv; - Bool ret; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) - return BadDrawable; - - /* Old DDX just completes immediately */ - if (!ds->ScheduleWaitMSC) { - DRI2WaitMSCComplete(client, pDraw, target_msc, 0, 0); - - return Success; - } - - ret = - (*ds->ScheduleWaitMSC) (client, pDraw, target_msc, divisor, remainder); - if (!ret) - return BadDrawable; - - return Success; -} - -int -DRI2WaitSBC(ClientPtr client, DrawablePtr pDraw, CARD64 target_sbc) -{ - DRI2DrawablePtr pPriv; - - pPriv = DRI2GetDrawable(pDraw); - if (pPriv == NULL) - return BadDrawable; - - if (pPriv->target_sbc != -1) /* already in use */ - return BadDrawable; - - /* target_sbc == 0 means to block until all pending swaps are - * finished. Recalculate target_sbc to get that behaviour. - */ - if (target_sbc == 0) - target_sbc = pPriv->swap_count + pPriv->swapsPending; - - /* If current swap count already >= target_sbc, reply and - * return immediately with (ust, msc, sbc) triplet of - * most recent completed swap. - */ - if (pPriv->swap_count >= target_sbc) { - ProcDRI2WaitMSCReply(client, pPriv->last_swap_ust, - pPriv->last_swap_msc, pPriv->swap_count); - return Success; - } - - if (!dri2Sleep(client, pPriv, WAKE_SBC)) - return BadAlloc; - - pPriv->target_sbc = target_sbc; - return Success; -} - -Bool -DRI2HasSwapControl(ScreenPtr pScreen) -{ - DRI2ScreenPtr ds = DRI2GetScreen(pScreen); - - return ds->ScheduleSwap && ds->GetMSC; -} - -Bool -DRI2Connect(ClientPtr client, ScreenPtr pScreen, - unsigned int driverType, int *fd, - const char **driverName, const char **deviceName) -{ - DRI2ScreenPtr ds; - uint32_t prime_id = DRI2DriverPrimeId(driverType); - uint32_t driver_id = driverType & 0xffff; - - if (!dixPrivateKeyRegistered(dri2ScreenPrivateKey)) - return FALSE; - - ds = DRI2GetScreenPrime(pScreen, prime_id); - if (ds == NULL) - return FALSE; - - if (driver_id >= ds->numDrivers || - !ds->driverNames[driver_id]) - return FALSE; - - *driverName = ds->driverNames[driver_id]; - *deviceName = ds->deviceName; - *fd = ds->fd; - - if (client) { - DRI2ClientPtr dri2_client; - dri2_client = dri2ClientPrivate(client); - dri2_client->prime_id = prime_id; - } - - return TRUE; -} - -static int -DRI2AuthMagic (ScreenPtr pScreen, uint32_t magic) -{ - DRI2ScreenPtr ds = DRI2GetScreen(pScreen); - if (ds == NULL) - return -EINVAL; - - return (*ds->LegacyAuthMagic) (ds->fd, magic); -} - -Bool -DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic) -{ - DRI2ScreenPtr ds; - DRI2ClientPtr dri2_client = dri2ClientPrivate(client); - ScreenPtr primescreen; - - ds = DRI2GetScreenPrime(pScreen, dri2_client->prime_id); - if (ds == NULL) - return FALSE; - - primescreen = GetScreenPrime(pScreen, dri2_client->prime_id); - if ((*ds->AuthMagic)(primescreen, magic)) - return FALSE; - return TRUE; -} - -static int -DRI2ConfigNotify(WindowPtr pWin, int x, int y, int w, int h, int bw, - WindowPtr pSib) -{ - DrawablePtr pDraw = (DrawablePtr) pWin; - ScreenPtr pScreen = pDraw->pScreen; - DRI2ScreenPtr ds = DRI2GetScreen(pScreen); - DRI2DrawablePtr dd = DRI2GetDrawable(pDraw); - int ret; - - if (ds->ConfigNotify) { - pScreen->ConfigNotify = ds->ConfigNotify; - - ret = (*pScreen->ConfigNotify) (pWin, x, y, w, h, bw, pSib); - - ds->ConfigNotify = pScreen->ConfigNotify; - pScreen->ConfigNotify = DRI2ConfigNotify; - if (ret) - return ret; - } - - if (!dd || (dd->width == w && dd->height == h)) - return Success; - - DRI2InvalidateDrawable(pDraw); - return Success; -} - -static void -DRI2SetWindowPixmap(WindowPtr pWin, PixmapPtr pPix) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - DRI2ScreenPtr ds = DRI2GetScreen(pScreen); - - pScreen->SetWindowPixmap = ds->SetWindowPixmap; - (*pScreen->SetWindowPixmap) (pWin, pPix); - ds->SetWindowPixmap = pScreen->SetWindowPixmap; - pScreen->SetWindowPixmap = DRI2SetWindowPixmap; - - DRI2InvalidateDrawable(&pWin->drawable); -} - -#define MAX_PRIME DRI2DriverPrimeMask -static int -get_prime_id(void) -{ - int i; - /* start at 1, prime id 0 is just normal driver */ - for (i = 1; i < MAX_PRIME; i++) { - if (prime_id_allocate_bitmask & (1 << i)) - continue; - - prime_id_allocate_bitmask |= (1 << i); - return i; - } - return -1; -} - -#include "pci_ids/pci_id_driver_map.h" - -static char * -dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info) -{ -#ifdef WITH_LIBDRM - int i, j; - char *driver = NULL; - drmDevicePtr dev; - - /* For non-PCI devices and drmGetDevice fail, just assume that - * the 3D driver is named the same as the kernel driver. This is - * currently true for vc4 and msm (freedreno). - */ - if (drmGetDevice(info->fd, &dev) || dev->bustype != DRM_BUS_PCI) { - drmVersionPtr version = drmGetVersion(info->fd); - - if (!version) { - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[DRI2] Couldn't drmGetVersion() on non-PCI device, " - "no driver name found.\n"); - return NULL; - } - - driver = strndup(version->name, version->name_len); - drmFreeVersion(version); - return driver; - } - - for (i = 0; driver_map[i].driver; i++) { - if (dev->deviceinfo.pci->vendor_id != driver_map[i].vendor_id) - continue; - - if (driver_map[i].num_chips_ids == -1) { - driver = strdup(driver_map[i].driver); - goto out; - } - - for (j = 0; j < driver_map[i].num_chips_ids; j++) { - if (driver_map[i].chip_ids[j] == dev->deviceinfo.pci->device_id) { - driver = strdup(driver_map[i].driver); - goto out; - } - } - } - - xf86DrvMsg(pScreen->myNum, X_ERROR, - "[DRI2] No driver mapping found for PCI device " - "0x%04x / 0x%04x\n", - dev->deviceinfo.pci->vendor_id, dev->deviceinfo.pci->device_id); -out: - drmFreeDevice(&dev); - return driver; -#else - return NULL; -#endif -} - -Bool -DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info) -{ - DRI2ScreenPtr ds; - - const char *driverTypeNames[] = { - "DRI", /* DRI2DriverDRI */ - "VDPAU", /* DRI2DriverVDPAU */ - }; - unsigned int i; - CARD8 cur_minor; - - if (info->version < 3) - return FALSE; - - if (!dixRegisterPrivateKey(&dri2ScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - if (!dixRegisterPrivateKey(&dri2WindowPrivateKeyRec, PRIVATE_WINDOW, 0)) - return FALSE; - - if (!dixRegisterPrivateKey(&dri2PixmapPrivateKeyRec, PRIVATE_PIXMAP, 0)) - return FALSE; - - if (!dixRegisterPrivateKey(&dri2ClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(DRI2ClientRec))) - return FALSE; - - ds = calloc(1, sizeof *ds); - if (!ds) - return FALSE; - - ds->screen = pScreen; - ds->fd = info->fd; - ds->deviceName = info->deviceName; - dri2_major = 1; - - ds->CreateBuffer = info->CreateBuffer; - ds->DestroyBuffer = info->DestroyBuffer; - ds->CopyRegion = info->CopyRegion; - cur_minor = 1; - - if (info->version >= 4) { - ds->ScheduleSwap = info->ScheduleSwap; - ds->ScheduleWaitMSC = info->ScheduleWaitMSC; - ds->GetMSC = info->GetMSC; - cur_minor = 3; - } - - if (info->version >= 5) { - ds->LegacyAuthMagic = info->AuthMagic; - } - - if (info->version >= 6) { - ds->ReuseBufferNotify = info->ReuseBufferNotify; - ds->SwapLimitValidate = info->SwapLimitValidate; - } - - if (info->version >= 7) { - ds->GetParam = info->GetParam; - cur_minor = 4; - } - - if (info->version >= 8) { - ds->AuthMagic = info->AuthMagic2; - } - - if (info->version >= 9) { - ds->CreateBuffer2 = info->CreateBuffer2; - if (info->CreateBuffer2 && pScreen->isGPU) { - ds->prime_id = get_prime_id(); - if (ds->prime_id == -1) { - free(ds); - return FALSE; - } - } - ds->DestroyBuffer2 = info->DestroyBuffer2; - ds->CopyRegion2 = info->CopyRegion2; - } - - /* - * if the driver doesn't provide an AuthMagic function or the info struct - * version is too low, call through LegacyAuthMagic - */ - if (!ds->AuthMagic) { - ds->AuthMagic = DRI2AuthMagic; - /* - * If the driver doesn't provide an AuthMagic function - * it relies on the old method (using libdrm) or fails - */ - if (!ds->LegacyAuthMagic) -#ifdef WITH_LIBDRM - ds->LegacyAuthMagic = drmAuthMagic; -#else - goto err_out; -#endif - } - - /* Initialize minor if needed and set to minimum provied by DDX */ - if (!dri2_minor || dri2_minor > cur_minor) - dri2_minor = cur_minor; - - if (info->version == 3 || info->numDrivers == 0) { - /* Driver too old: use the old-style driverName field */ - ds->numDrivers = info->driverName ? 1 : 2; - ds->driverNames = xallocarray(ds->numDrivers, sizeof(*ds->driverNames)); - if (!ds->driverNames) - goto err_out; - - if (info->driverName) { - ds->driverNames[0] = info->driverName; - } else { - /* FIXME dri2_probe_driver_name() returns a strdup-ed string, - * currently this gets leaked */ - ds->driverNames[0] = ds->driverNames[1] = dri2_probe_driver_name(pScreen, info); - if (!ds->driverNames[0]) - return FALSE; - - /* There is no VDPAU driver for i965, fallback to the generic - * OpenGL/VAAPI va_gl backend to emulate VDPAU on i965. */ - if (strcmp(ds->driverNames[0], "i965") == 0) - ds->driverNames[1] = "va_gl"; - } - } - else { - ds->numDrivers = info->numDrivers; - ds->driverNames = xallocarray(info->numDrivers, sizeof(*ds->driverNames)); - if (!ds->driverNames) - goto err_out; - memcpy(ds->driverNames, info->driverNames, - info->numDrivers * sizeof(*ds->driverNames)); - } - - dixSetPrivate(&pScreen->devPrivates, dri2ScreenPrivateKey, ds); - - ds->ConfigNotify = pScreen->ConfigNotify; - pScreen->ConfigNotify = DRI2ConfigNotify; - - ds->SetWindowPixmap = pScreen->SetWindowPixmap; - pScreen->SetWindowPixmap = DRI2SetWindowPixmap; - - xf86DrvMsg(pScreen->myNum, X_INFO, "[DRI2] Setup complete\n"); - for (i = 0; i < ARRAY_SIZE(driverTypeNames); i++) { - if (i < ds->numDrivers && ds->driverNames[i]) { - xf86DrvMsg(pScreen->myNum, X_INFO, "[DRI2] %s driver: %s\n", - driverTypeNames[i], ds->driverNames[i]); - } - } - - return TRUE; - - err_out: - xf86DrvMsg(pScreen->myNum, X_WARNING, - "[DRI2] Initialization failed for info version %d.\n", - info->version); - free(ds); - return FALSE; -} - -void -DRI2CloseScreen(ScreenPtr pScreen) -{ - DRI2ScreenPtr ds = DRI2GetScreen(pScreen); - - pScreen->ConfigNotify = ds->ConfigNotify; - pScreen->SetWindowPixmap = ds->SetWindowPixmap; - - if (ds->prime_id) - prime_id_allocate_bitmask &= ~(1 << ds->prime_id); - free(ds->driverNames); - free(ds); - dixSetPrivate(&pScreen->devPrivates, dri2ScreenPrivateKey, NULL); -} - -/* Called by InitExtensions() */ -Bool -DRI2ModuleSetup(void) -{ - dri2DrawableRes = CreateNewResourceType(DRI2DrawableGone, "DRI2Drawable"); - if (!dri2DrawableRes) - return FALSE; - - return TRUE; -} - -void -DRI2Version(int *major, int *minor) -{ - if (major != NULL) - *major = 1; - - if (minor != NULL) - *minor = 2; -} - -int -DRI2GetParam(ClientPtr client, - DrawablePtr drawable, - CARD64 param, - BOOL *is_param_recognized, - CARD64 *value) -{ - DRI2ScreenPtr ds = DRI2GetScreen(drawable->pScreen); - char high_byte = (param >> 24); - - switch (high_byte) { - case 0: - /* Parameter names whose high_byte is 0 are reserved for the X - * server. The server currently recognizes no parameters. - */ - goto not_recognized; - case 1: - /* Parameter names whose high byte is 1 are reserved for the DDX. */ - if (ds->GetParam) - return ds->GetParam(client, drawable, param, - is_param_recognized, value); - else - goto not_recognized; - default: - /* Other parameter names are reserved for future use. They are never - * recognized. - */ - goto not_recognized; - } - -not_recognized: - *is_param_recognized = FALSE; - return Success; -} diff --git a/hw/xfree86/dri2/dri2.h b/hw/xfree86/dri2/dri2.h deleted file mode 100644 index 4c14b705d..000000000 --- a/hw/xfree86/dri2/dri2.h +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright © 2007 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Soft- - * ware"), to deal in the Software without restriction, including without - * limitation the rights to use, copy, modify, merge, publish, distribute, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, provided that the above copyright - * notice(s) and this permission notice appear in all copies of the Soft- - * ware and that both the above copyright notice(s) and this permission - * notice appear in supporting documentation. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- - * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY - * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN - * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- - * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- - * MANCE OF THIS SOFTWARE. - * - * Except as contained in this notice, the name of a copyright holder shall - * not be used in advertising or otherwise to promote the sale, use or - * other dealings in this Software without prior written authorization of - * the copyright holder. - * - * Authors: - * Kristian Høgsberg (krh@redhat.com) - */ - -#ifndef _DRI2_H_ -#define _DRI2_H_ - -#include - -/* Version 2 structure (with format at the end) */ -typedef struct { - unsigned int attachment; - unsigned int name; - unsigned int pitch; - unsigned int cpp; - unsigned int flags; - unsigned int format; - void *driverPrivate; -} DRI2BufferRec, *DRI2BufferPtr; - -extern CARD8 dri2_major; /* version of DRI2 supported by DDX */ -extern CARD8 dri2_minor; - -typedef DRI2BufferRec DRI2Buffer2Rec, *DRI2Buffer2Ptr; -typedef void (*DRI2SwapEventPtr) (ClientPtr client, void *data, int type, - CARD64 ust, CARD64 msc, CARD32 sbc); - -typedef DRI2BufferPtr(*DRI2CreateBuffersProcPtr) (DrawablePtr pDraw, - unsigned int *attachments, - int count); -typedef void (*DRI2DestroyBuffersProcPtr) (DrawablePtr pDraw, - DRI2BufferPtr buffers, int count); -typedef void (*DRI2CopyRegionProcPtr) (DrawablePtr pDraw, - RegionPtr pRegion, - DRI2BufferPtr pDestBuffer, - DRI2BufferPtr pSrcBuffer); -typedef void (*DRI2WaitProcPtr) (WindowPtr pWin, unsigned int sequence); -typedef int (*DRI2AuthMagicProcPtr) (int fd, uint32_t magic); -typedef int (*DRI2AuthMagic2ProcPtr) (ScreenPtr pScreen, uint32_t magic); - -/** - * Schedule a buffer swap - * - * This callback is used to support glXSwapBuffers and the OML_sync_control - * extension (see it for a description of the params). - * - * Drivers should queue an event for the frame count that satisfies the - * parameters passed in. If the event is in the future (i.e. the conditions - * aren't currently satisfied), the server may block the client at the next - * GLX request using DRI2WaitSwap. When the event arrives, drivers should call - * \c DRI2SwapComplete, which will handle waking the client and returning - * the appropriate data. - * - * The DDX is responsible for doing a flip, exchange, or blit of the swap - * when the corresponding event arrives. The \c DRI2CanFlip and - * \c DRI2CanExchange functions can be used as helpers for this purpose. - * - * \param client client pointer (used for block/unblock) - * \param pDraw drawable whose count we want - * \param pDestBuffer current front buffer - * \param pSrcBuffer current back buffer - * \param target_msc frame count to wait for - * \param divisor divisor for condition equation - * \param remainder remainder for division equation - * \param func function to call when the swap completes - * \param data data for the callback \p func. - */ -typedef int (*DRI2ScheduleSwapProcPtr) (ClientPtr client, - DrawablePtr pDraw, - DRI2BufferPtr pDestBuffer, - DRI2BufferPtr pSrcBuffer, - CARD64 * target_msc, - CARD64 divisor, - CARD64 remainder, - DRI2SwapEventPtr func, void *data); -typedef DRI2BufferPtr(*DRI2CreateBufferProcPtr) (DrawablePtr pDraw, - unsigned int attachment, - unsigned int format); -typedef void (*DRI2DestroyBufferProcPtr) (DrawablePtr pDraw, - DRI2BufferPtr buffer); -/** - * Notifies driver when DRI2GetBuffers reuses a dri2 buffer. - * - * Driver may rename the dri2 buffer in this notify if it is required. - * - * \param pDraw drawable whose count we want - * \param buffer buffer that will be returned to client - */ -typedef void (*DRI2ReuseBufferNotifyProcPtr) (DrawablePtr pDraw, - DRI2BufferPtr buffer); -/** - * Get current media stamp counter values - * - * This callback is used to support the SGI_video_sync and OML_sync_control - * extensions. - * - * Drivers should return the current frame counter and the timestamp from - * when the returned frame count was last incremented. - * - * The count should correspond to the screen where the drawable is currently - * visible. If the drawable isn't visible (e.g. redirected), the server - * should return BadDrawable to the client, pending GLX spec updates to - * define this behavior. - * - * \param pDraw drawable whose count we want - * \param ust timestamp from when the count was last incremented. - * \param mst current frame count - */ -typedef int (*DRI2GetMSCProcPtr) (DrawablePtr pDraw, CARD64 * ust, - CARD64 * msc); -/** - * Schedule a frame count related wait - * - * This callback is used to support the SGI_video_sync and OML_sync_control - * extensions. See those specifications for details on how to handle - * the divisor and remainder parameters. - * - * Drivers should queue an event for the frame count that satisfies the - * parameters passed in. If the event is in the future (i.e. the conditions - * aren't currently satisfied), the driver should block the client using - * \c DRI2BlockClient. When the event arrives, drivers should call - * \c DRI2WaitMSCComplete, which will handle waking the client and returning - * the appropriate data. - * - * \param client client pointer (used for block/unblock) - * \param pDraw drawable whose count we want - * \param target_msc frame count to wait for - * \param divisor divisor for condition equation - * \param remainder remainder for division equation - */ -typedef int (*DRI2ScheduleWaitMSCProcPtr) (ClientPtr client, - DrawablePtr pDraw, - CARD64 target_msc, - CARD64 divisor, CARD64 remainder); - -typedef void (*DRI2InvalidateProcPtr) (DrawablePtr pDraw, void *data, XID id); - -/** - * DRI2 calls this hook when ever swap_limit is going to be changed. Default - * implementation for the hook only accepts one as swap_limit. If driver can - * support other swap_limits it has to implement supported limits with this - * callback. - * - * \param pDraw drawable whose swap_limit is going to be changed - * \param swap_limit new swap_limit that going to be set - * \return TRUE if limit is support, FALSE if not. - */ -typedef Bool (*DRI2SwapLimitValidateProcPtr) (DrawablePtr pDraw, - int swap_limit); - -typedef DRI2BufferPtr(*DRI2CreateBuffer2ProcPtr) (ScreenPtr pScreen, - DrawablePtr pDraw, - unsigned int attachment, - unsigned int format); -typedef void (*DRI2DestroyBuffer2ProcPtr) (ScreenPtr pScreen, DrawablePtr pDraw, - DRI2BufferPtr buffer); - -typedef void (*DRI2CopyRegion2ProcPtr) (ScreenPtr pScreen, DrawablePtr pDraw, - RegionPtr pRegion, - DRI2BufferPtr pDestBuffer, - DRI2BufferPtr pSrcBuffer); - -/** - * \brief Get the value of a parameter. - * - * The parameter's \a value is looked up on the screen associated with - * \a pDrawable. - * - * \return \c Success or error code. - */ -typedef int (*DRI2GetParamProcPtr) (ClientPtr client, - DrawablePtr pDrawable, - CARD64 param, - BOOL *is_param_recognized, - CARD64 *value); - -/** - * Version of the DRI2InfoRec structure defined in this header - */ -#define DRI2INFOREC_VERSION 9 - -typedef struct { - unsigned int version; /**< Version of this struct */ - int fd; - const char *driverName; - const char *deviceName; - - DRI2CreateBufferProcPtr CreateBuffer; - DRI2DestroyBufferProcPtr DestroyBuffer; - DRI2CopyRegionProcPtr CopyRegion; - DRI2WaitProcPtr Wait; - - /* added in version 4 */ - - DRI2ScheduleSwapProcPtr ScheduleSwap; - DRI2GetMSCProcPtr GetMSC; - DRI2ScheduleWaitMSCProcPtr ScheduleWaitMSC; - - /* number of drivers in the driverNames array */ - unsigned int numDrivers; - /* array of driver names, indexed by DRI2Driver* driver types */ - /* a name of NULL means that driver is not supported */ - const char *const *driverNames; - - /* added in version 5 */ - - DRI2AuthMagicProcPtr AuthMagic; - - /* added in version 6 */ - - DRI2ReuseBufferNotifyProcPtr ReuseBufferNotify; - DRI2SwapLimitValidateProcPtr SwapLimitValidate; - - /* added in version 7 */ - DRI2GetParamProcPtr GetParam; - - /* added in version 8 */ - /* AuthMagic callback which passes extra context */ - /* If this is NULL the AuthMagic callback is used */ - /* If this is non-NULL the AuthMagic callback is ignored */ - DRI2AuthMagic2ProcPtr AuthMagic2; - - /* added in version 9 */ - DRI2CreateBuffer2ProcPtr CreateBuffer2; - DRI2DestroyBuffer2ProcPtr DestroyBuffer2; - DRI2CopyRegion2ProcPtr CopyRegion2; -} DRI2InfoRec, *DRI2InfoPtr; - -extern _X_EXPORT Bool DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info); - -extern _X_EXPORT void DRI2CloseScreen(ScreenPtr pScreen); - -extern _X_EXPORT Bool DRI2HasSwapControl(ScreenPtr pScreen); - -extern _X_EXPORT Bool DRI2Connect(ClientPtr client, ScreenPtr pScreen, - unsigned int driverType, - int *fd, - const char **driverName, - const char **deviceName); - -extern _X_EXPORT Bool DRI2Authenticate(ClientPtr client, ScreenPtr pScreen, uint32_t magic); - -extern _X_EXPORT int DRI2CreateDrawable(ClientPtr client, - DrawablePtr pDraw, - XID id, - DRI2InvalidateProcPtr invalidate, - void *priv); - -extern _X_EXPORT int DRI2CreateDrawable2(ClientPtr client, - DrawablePtr pDraw, - XID id, - DRI2InvalidateProcPtr invalidate, - void *priv, - XID *dri2_id_out); - -extern _X_EXPORT DRI2BufferPtr *DRI2GetBuffers(DrawablePtr pDraw, - int *width, - int *height, - unsigned int *attachments, - int count, int *out_count); - -extern _X_EXPORT int DRI2CopyRegion(DrawablePtr pDraw, - RegionPtr pRegion, - unsigned int dest, unsigned int src); - -/** - * Determine the major and minor version of the DRI2 extension. - * - * Provides a mechanism to other modules (e.g., 2D drivers) to determine the - * version of the DRI2 extension. While it is possible to peek directly at - * the \c XF86ModuleData from a layered module, such a module will fail to - * load (due to an unresolved symbol) if the DRI2 extension is not loaded. - * - * \param major Location to store the major version of the DRI2 extension - * \param minor Location to store the minor version of the DRI2 extension - * - * \note - * This interface was added some time after the initial release of the DRI2 - * module. Layered modules that wish to use this interface must first test - * its existence by calling \c xf86LoaderCheckSymbol. - */ -extern _X_EXPORT void DRI2Version(int *major, int *minor); - -extern _X_EXPORT DRI2BufferPtr *DRI2GetBuffersWithFormat(DrawablePtr pDraw, - int *width, - int *height, - unsigned int - *attachments, - int count, - int *out_count); - -extern _X_EXPORT void DRI2SwapInterval(DrawablePtr pDrawable, int interval); -extern _X_EXPORT Bool DRI2SwapLimit(DrawablePtr pDraw, int swap_limit); -extern _X_EXPORT int DRI2SwapBuffers(ClientPtr client, DrawablePtr pDrawable, - CARD64 target_msc, CARD64 divisor, - CARD64 remainder, CARD64 * swap_target, - DRI2SwapEventPtr func, void *data); -extern _X_EXPORT Bool DRI2WaitSwap(ClientPtr client, DrawablePtr pDrawable); - -extern _X_EXPORT int DRI2GetMSC(DrawablePtr pDrawable, CARD64 * ust, - CARD64 * msc, CARD64 * sbc); -extern _X_EXPORT int DRI2WaitMSC(ClientPtr client, DrawablePtr pDrawable, - CARD64 target_msc, CARD64 divisor, - CARD64 remainder); -extern _X_EXPORT int ProcDRI2WaitMSCReply(ClientPtr client, CARD64 ust, - CARD64 msc, CARD64 sbc); -extern _X_EXPORT int DRI2WaitSBC(ClientPtr client, DrawablePtr pDraw, - CARD64 target_sbc); -extern _X_EXPORT Bool DRI2ThrottleClient(ClientPtr client, DrawablePtr pDraw); - -extern _X_EXPORT Bool DRI2CanFlip(DrawablePtr pDraw); - -extern _X_EXPORT Bool DRI2CanExchange(DrawablePtr pDraw); - -/* Note: use *only* for MSC related waits */ -extern _X_EXPORT void DRI2BlockClient(ClientPtr client, DrawablePtr pDraw); - -extern _X_EXPORT void DRI2SwapComplete(ClientPtr client, DrawablePtr pDraw, - int frame, unsigned int tv_sec, - unsigned int tv_usec, int type, - DRI2SwapEventPtr swap_complete, - void *swap_data); -extern _X_EXPORT void DRI2WaitMSCComplete(ClientPtr client, DrawablePtr pDraw, - int frame, unsigned int tv_sec, - unsigned int tv_usec); - -extern _X_EXPORT int DRI2GetParam(ClientPtr client, - DrawablePtr pDrawable, - CARD64 param, - BOOL *is_param_recognized, - CARD64 *value); - -extern _X_EXPORT DrawablePtr DRI2UpdatePrime(DrawablePtr pDraw, DRI2BufferPtr pDest); -#endif diff --git a/hw/xfree86/dri2/dri2ext.c b/hw/xfree86/dri2/dri2ext.c deleted file mode 100644 index 4f98639aa..000000000 --- a/hw/xfree86/dri2/dri2ext.c +++ /dev/null @@ -1,700 +0,0 @@ -/* - * Copyright © 2008 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Soft- - * ware"), to deal in the Software without restriction, including without - * limitation the rights to use, copy, modify, merge, publish, distribute, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, provided that the above copyright - * notice(s) and this permission notice appear in all copies of the Soft- - * ware and that both the above copyright notice(s) and this permission - * notice appear in supporting documentation. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- - * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY - * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN - * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE- - * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR- - * MANCE OF THIS SOFTWARE. - * - * Except as contained in this notice, the name of a copyright holder shall - * not be used in advertising or otherwise to promote the sale, use or - * other dealings in this Software without prior written authorization of - * the copyright holder. - * - * Authors: - * Kristian Høgsberg (krh@redhat.com) - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include "dixstruct.h" -#include "scrnintstr.h" -#include "pixmapstr.h" -#include "extnsionst.h" -#include "xfixes.h" -#include "dri2.h" -#include "dri2int.h" -#include "protocol-versions.h" - -/* The only xf86 includes */ -#include "xf86Module.h" -#include "xf86Extensions.h" - -static int DRI2EventBase; - - -static Bool -validDrawable(ClientPtr client, XID drawable, Mask access_mode, - DrawablePtr *pDrawable, int *status) -{ - *status = dixLookupDrawable(pDrawable, drawable, client, - M_DRAWABLE_WINDOW | M_DRAWABLE_PIXMAP, - access_mode); - if (*status != Success) { - client->errorValue = drawable; - return FALSE; - } - - return TRUE; -} - -static int -ProcDRI2QueryVersion(ClientPtr client) -{ - REQUEST(xDRI2QueryVersionReq); - xDRI2QueryVersionReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0, - .majorVersion = dri2_major, - .minorVersion = dri2_minor - }; - - if (client->swapped) - swaps(&stuff->length); - - REQUEST_SIZE_MATCH(xDRI2QueryVersionReq); - - if (client->swapped) { - swaps(&rep.sequenceNumber); - swapl(&rep.length); - swapl(&rep.majorVersion); - swapl(&rep.minorVersion); - } - - WriteToClient(client, sizeof(xDRI2QueryVersionReply), &rep); - - return Success; -} - -static int -ProcDRI2Connect(ClientPtr client) -{ - REQUEST(xDRI2ConnectReq); - xDRI2ConnectReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0, - .driverNameLength = 0, - .deviceNameLength = 0 - }; - DrawablePtr pDraw; - int fd, status; - const char *driverName; - const char *deviceName; - - REQUEST_SIZE_MATCH(xDRI2ConnectReq); - if (!validDrawable(client, stuff->window, DixGetAttrAccess, - &pDraw, &status)) - return status; - - if (!DRI2Connect(client, pDraw->pScreen, - stuff->driverType, &fd, &driverName, &deviceName)) - goto fail; - - rep.driverNameLength = strlen(driverName); - rep.deviceNameLength = strlen(deviceName); - rep.length = (rep.driverNameLength + 3) / 4 + - (rep.deviceNameLength + 3) / 4; - - fail: - WriteToClient(client, sizeof(xDRI2ConnectReply), &rep); - WriteToClient(client, rep.driverNameLength, driverName); - WriteToClient(client, rep.deviceNameLength, deviceName); - - return Success; -} - -static int -ProcDRI2Authenticate(ClientPtr client) -{ - REQUEST(xDRI2AuthenticateReq); - xDRI2AuthenticateReply rep; - DrawablePtr pDraw; - int status; - - REQUEST_SIZE_MATCH(xDRI2AuthenticateReq); - if (!validDrawable(client, stuff->window, DixGetAttrAccess, - &pDraw, &status)) - return status; - - rep = (xDRI2AuthenticateReply) { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0, - .authenticated = DRI2Authenticate(client, pDraw->pScreen, stuff->magic) - }; - WriteToClient(client, sizeof(xDRI2AuthenticateReply), &rep); - - return Success; -} - -static void -DRI2InvalidateBuffersEvent(DrawablePtr pDraw, void *priv, XID id) -{ - ClientPtr client = priv; - xDRI2InvalidateBuffers event = { - .type = DRI2EventBase + DRI2_InvalidateBuffers, - .drawable = id - }; - - WriteEventsToClient(client, 1, (xEvent *) &event); -} - -static int -ProcDRI2CreateDrawable(ClientPtr client) -{ - REQUEST(xDRI2CreateDrawableReq); - DrawablePtr pDrawable; - int status; - - REQUEST_SIZE_MATCH(xDRI2CreateDrawableReq); - - if (!validDrawable(client, stuff->drawable, DixAddAccess, - &pDrawable, &status)) - return status; - - status = DRI2CreateDrawable(client, pDrawable, stuff->drawable, - DRI2InvalidateBuffersEvent, client); - if (status != Success) - return status; - - return Success; -} - -static int -ProcDRI2DestroyDrawable(ClientPtr client) -{ - REQUEST(xDRI2DestroyDrawableReq); - DrawablePtr pDrawable; - int status; - - REQUEST_SIZE_MATCH(xDRI2DestroyDrawableReq); - if (!validDrawable(client, stuff->drawable, DixRemoveAccess, - &pDrawable, &status)) - return status; - - return Success; -} - -static int -send_buffers_reply(ClientPtr client, DrawablePtr pDrawable, - DRI2BufferPtr * buffers, int count, int width, int height) -{ - xDRI2GetBuffersReply rep; - int skip = 0; - int i; - - if (buffers == NULL) - return BadAlloc; - - if (pDrawable->type == DRAWABLE_WINDOW) { - for (i = 0; i < count; i++) { - /* Do not send the real front buffer of a window to the client. - */ - if (buffers[i]->attachment == DRI2BufferFrontLeft) { - skip++; - continue; - } - } - } - - rep = (xDRI2GetBuffersReply) { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = (count - skip) * sizeof(xDRI2Buffer) / 4, - .width = width, - .height = height, - .count = count - skip - }; - WriteToClient(client, sizeof(xDRI2GetBuffersReply), &rep); - - for (i = 0; i < count; i++) { - xDRI2Buffer buffer; - - /* Do not send the real front buffer of a window to the client. - */ - if ((pDrawable->type == DRAWABLE_WINDOW) - && (buffers[i]->attachment == DRI2BufferFrontLeft)) { - continue; - } - - buffer.attachment = buffers[i]->attachment; - buffer.name = buffers[i]->name; - buffer.pitch = buffers[i]->pitch; - buffer.cpp = buffers[i]->cpp; - buffer.flags = buffers[i]->flags; - WriteToClient(client, sizeof(xDRI2Buffer), &buffer); - } - return Success; -} - -static int -ProcDRI2GetBuffers(ClientPtr client) -{ - REQUEST(xDRI2GetBuffersReq); - DrawablePtr pDrawable; - DRI2BufferPtr *buffers; - int status, width, height, count; - unsigned int *attachments; - - REQUEST_AT_LEAST_SIZE(xDRI2GetBuffersReq); - /* stuff->count is a count of CARD32 attachments that follows */ - if (stuff->count > (INT_MAX / sizeof(CARD32))) - return BadLength; - REQUEST_FIXED_SIZE(xDRI2GetBuffersReq, stuff->count * sizeof(CARD32)); - - if (!validDrawable(client, stuff->drawable, DixReadAccess | DixWriteAccess, - &pDrawable, &status)) - return status; - - if (DRI2ThrottleClient(client, pDrawable)) - return Success; - - attachments = (unsigned int *) &stuff[1]; - buffers = DRI2GetBuffers(pDrawable, &width, &height, - attachments, stuff->count, &count); - - return send_buffers_reply(client, pDrawable, buffers, count, width, height); - -} - -static int -ProcDRI2GetBuffersWithFormat(ClientPtr client) -{ - REQUEST(xDRI2GetBuffersReq); - DrawablePtr pDrawable; - DRI2BufferPtr *buffers; - int status, width, height, count; - unsigned int *attachments; - - REQUEST_AT_LEAST_SIZE(xDRI2GetBuffersReq); - /* stuff->count is a count of pairs of CARD32s (attachments & formats) - that follows */ - if (stuff->count > (INT_MAX / (2 * sizeof(CARD32)))) - return BadLength; - REQUEST_FIXED_SIZE(xDRI2GetBuffersReq, - stuff->count * (2 * sizeof(CARD32))); - if (!validDrawable(client, stuff->drawable, DixReadAccess | DixWriteAccess, - &pDrawable, &status)) - return status; - - if (DRI2ThrottleClient(client, pDrawable)) - return Success; - - attachments = (unsigned int *) &stuff[1]; - buffers = DRI2GetBuffersWithFormat(pDrawable, &width, &height, - attachments, stuff->count, &count); - - return send_buffers_reply(client, pDrawable, buffers, count, width, height); -} - -static int -ProcDRI2CopyRegion(ClientPtr client) -{ - REQUEST(xDRI2CopyRegionReq); - xDRI2CopyRegionReply rep; - DrawablePtr pDrawable; - int status; - RegionPtr pRegion; - - REQUEST_SIZE_MATCH(xDRI2CopyRegionReq); - - if (!validDrawable(client, stuff->drawable, DixWriteAccess, - &pDrawable, &status)) - return status; - - VERIFY_REGION(pRegion, stuff->region, client, DixReadAccess); - - status = DRI2CopyRegion(pDrawable, pRegion, stuff->dest, stuff->src); - if (status != Success) - return status; - - /* CopyRegion needs to be a round trip to make sure the X server - * queues the swap buffer rendering commands before the DRI client - * continues rendering. The reply has a bitmask to signal the - * presence of optional return values as well, but we're not using - * that yet. - */ - - rep = (xDRI2CopyRegionReply) { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0 - }; - - WriteToClient(client, sizeof(xDRI2CopyRegionReply), &rep); - - return Success; -} - -static void -load_swap_reply(xDRI2SwapBuffersReply * rep, CARD64 sbc) -{ - rep->swap_hi = sbc >> 32; - rep->swap_lo = sbc & 0xffffffff; -} - -static CARD64 -vals_to_card64(CARD32 lo, CARD32 hi) -{ - return (CARD64) hi << 32 | lo; -} - -static void -DRI2SwapEvent(ClientPtr client, void *data, int type, CARD64 ust, CARD64 msc, - CARD32 sbc) -{ - DrawablePtr pDrawable = data; - xDRI2BufferSwapComplete2 event = { - .type = DRI2EventBase + DRI2_BufferSwapComplete, - .event_type = type, - .drawable = pDrawable->id, - .ust_hi = (CARD64) ust >> 32, - .ust_lo = ust & 0xffffffff, - .msc_hi = (CARD64) msc >> 32, - .msc_lo = msc & 0xffffffff, - .sbc = sbc - }; - - WriteEventsToClient(client, 1, (xEvent *) &event); -} - -static int -ProcDRI2SwapBuffers(ClientPtr client) -{ - REQUEST(xDRI2SwapBuffersReq); - xDRI2SwapBuffersReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0 - }; - DrawablePtr pDrawable; - CARD64 target_msc, divisor, remainder, swap_target; - int status; - - REQUEST_SIZE_MATCH(xDRI2SwapBuffersReq); - - if (!validDrawable(client, stuff->drawable, - DixReadAccess | DixWriteAccess, &pDrawable, &status)) - return status; - - /* - * Ensures an out of control client can't exhaust our swap queue, and - * also orders swaps. - */ - if (DRI2ThrottleClient(client, pDrawable)) - return Success; - - target_msc = vals_to_card64(stuff->target_msc_lo, stuff->target_msc_hi); - divisor = vals_to_card64(stuff->divisor_lo, stuff->divisor_hi); - remainder = vals_to_card64(stuff->remainder_lo, stuff->remainder_hi); - - status = DRI2SwapBuffers(client, pDrawable, target_msc, divisor, remainder, - &swap_target, DRI2SwapEvent, pDrawable); - if (status != Success) - return BadDrawable; - - load_swap_reply(&rep, swap_target); - - WriteToClient(client, sizeof(xDRI2SwapBuffersReply), &rep); - - return Success; -} - -static void -load_msc_reply(xDRI2MSCReply * rep, CARD64 ust, CARD64 msc, CARD64 sbc) -{ - rep->ust_hi = ust >> 32; - rep->ust_lo = ust & 0xffffffff; - rep->msc_hi = msc >> 32; - rep->msc_lo = msc & 0xffffffff; - rep->sbc_hi = sbc >> 32; - rep->sbc_lo = sbc & 0xffffffff; -} - -static int -ProcDRI2GetMSC(ClientPtr client) -{ - REQUEST(xDRI2GetMSCReq); - xDRI2MSCReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0 - }; - DrawablePtr pDrawable; - CARD64 ust, msc, sbc; - int status; - - REQUEST_SIZE_MATCH(xDRI2GetMSCReq); - - if (!validDrawable(client, stuff->drawable, DixReadAccess, &pDrawable, - &status)) - return status; - - status = DRI2GetMSC(pDrawable, &ust, &msc, &sbc); - if (status != Success) - return status; - - load_msc_reply(&rep, ust, msc, sbc); - - WriteToClient(client, sizeof(xDRI2MSCReply), &rep); - - return Success; -} - -static int -ProcDRI2WaitMSC(ClientPtr client) -{ - REQUEST(xDRI2WaitMSCReq); - DrawablePtr pDrawable; - CARD64 target, divisor, remainder; - int status; - - /* FIXME: in restart case, client may be gone at this point */ - - REQUEST_SIZE_MATCH(xDRI2WaitMSCReq); - - if (!validDrawable(client, stuff->drawable, DixReadAccess, &pDrawable, - &status)) - return status; - - target = vals_to_card64(stuff->target_msc_lo, stuff->target_msc_hi); - divisor = vals_to_card64(stuff->divisor_lo, stuff->divisor_hi); - remainder = vals_to_card64(stuff->remainder_lo, stuff->remainder_hi); - - status = DRI2WaitMSC(client, pDrawable, target, divisor, remainder); - if (status != Success) - return status; - - return Success; -} - -int -ProcDRI2WaitMSCReply(ClientPtr client, CARD64 ust, CARD64 msc, CARD64 sbc) -{ - xDRI2MSCReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0 - }; - - load_msc_reply(&rep, ust, msc, sbc); - - WriteToClient(client, sizeof(xDRI2MSCReply), &rep); - - return Success; -} - -static int -ProcDRI2SwapInterval(ClientPtr client) -{ - REQUEST(xDRI2SwapIntervalReq); - DrawablePtr pDrawable; - int status; - - /* FIXME: in restart case, client may be gone at this point */ - - REQUEST_SIZE_MATCH(xDRI2SwapIntervalReq); - - if (!validDrawable(client, stuff->drawable, DixReadAccess | DixWriteAccess, - &pDrawable, &status)) - return status; - - DRI2SwapInterval(pDrawable, stuff->interval); - - return Success; -} - -static int -ProcDRI2WaitSBC(ClientPtr client) -{ - REQUEST(xDRI2WaitSBCReq); - DrawablePtr pDrawable; - CARD64 target; - int status; - - REQUEST_SIZE_MATCH(xDRI2WaitSBCReq); - - if (!validDrawable(client, stuff->drawable, DixReadAccess, &pDrawable, - &status)) - return status; - - target = vals_to_card64(stuff->target_sbc_lo, stuff->target_sbc_hi); - status = DRI2WaitSBC(client, pDrawable, target); - - return status; -} - -static int -ProcDRI2GetParam(ClientPtr client) -{ - REQUEST(xDRI2GetParamReq); - xDRI2GetParamReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0 - }; - DrawablePtr pDrawable; - CARD64 value; - int status; - - REQUEST_SIZE_MATCH(xDRI2GetParamReq); - - if (!validDrawable(client, stuff->drawable, DixReadAccess, - &pDrawable, &status)) - return status; - - status = DRI2GetParam(client, pDrawable, stuff->param, - &rep.is_param_recognized, &value); - rep.value_hi = value >> 32; - rep.value_lo = value & 0xffffffff; - - if (status != Success) - return status; - - WriteToClient(client, sizeof(xDRI2GetParamReply), &rep); - - return status; -} - -static int -ProcDRI2Dispatch(ClientPtr client) -{ - REQUEST(xReq); - - switch (stuff->data) { - case X_DRI2QueryVersion: - return ProcDRI2QueryVersion(client); - } - - if (!client->local) - return BadRequest; - - switch (stuff->data) { - case X_DRI2Connect: - return ProcDRI2Connect(client); - case X_DRI2Authenticate: - return ProcDRI2Authenticate(client); - case X_DRI2CreateDrawable: - return ProcDRI2CreateDrawable(client); - case X_DRI2DestroyDrawable: - return ProcDRI2DestroyDrawable(client); - case X_DRI2GetBuffers: - return ProcDRI2GetBuffers(client); - case X_DRI2CopyRegion: - return ProcDRI2CopyRegion(client); - case X_DRI2GetBuffersWithFormat: - return ProcDRI2GetBuffersWithFormat(client); - case X_DRI2SwapBuffers: - return ProcDRI2SwapBuffers(client); - case X_DRI2GetMSC: - return ProcDRI2GetMSC(client); - case X_DRI2WaitMSC: - return ProcDRI2WaitMSC(client); - case X_DRI2WaitSBC: - return ProcDRI2WaitSBC(client); - case X_DRI2SwapInterval: - return ProcDRI2SwapInterval(client); - case X_DRI2GetParam: - return ProcDRI2GetParam(client); - default: - return BadRequest; - } -} - -static int _X_COLD -SProcDRI2Connect(ClientPtr client) -{ - REQUEST(xDRI2ConnectReq); - xDRI2ConnectReply rep = { - .type = X_Reply, - .sequenceNumber = client->sequence, - .length = 0, - .driverNameLength = 0, - .deviceNameLength = 0 - }; - - /* If the client is swapped, it's not local. Talk to the hand. */ - - swaps(&stuff->length); - if (sizeof(*stuff) / 4 != client->req_len) - return BadLength; - - swaps(&rep.sequenceNumber); - - WriteToClient(client, sizeof(xDRI2ConnectReply), &rep); - - return Success; -} - -static int _X_COLD -SProcDRI2Dispatch(ClientPtr client) -{ - REQUEST(xReq); - - /* - * Only local clients are allowed DRI access, but remote clients - * still need these requests to find out cleanly. - */ - switch (stuff->data) { - case X_DRI2QueryVersion: - return ProcDRI2QueryVersion(client); - case X_DRI2Connect: - return SProcDRI2Connect(client); - default: - return BadRequest; - } -} - -void -DRI2ExtensionInit(void) -{ - ExtensionEntry *dri2Extension; - -#ifdef PANORAMIX - if (!noPanoramiXExtension) - return; -#endif - - dri2Extension = AddExtension(DRI2_NAME, - DRI2NumberEvents, - DRI2NumberErrors, - ProcDRI2Dispatch, - SProcDRI2Dispatch, NULL, StandardMinorOpcode); - - DRI2EventBase = dri2Extension->eventBase; - - DRI2ModuleSetup(); -} diff --git a/hw/xfree86/dri2/dri2int.h b/hw/xfree86/dri2/dri2int.h deleted file mode 100644 index 7f53eba45..000000000 --- a/hw/xfree86/dri2/dri2int.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright © 2011 Daniel Stone - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Daniel Stone - */ - -extern Bool DRI2ModuleSetup(void); diff --git a/hw/xfree86/dri2/meson.build b/hw/xfree86/dri2/meson.build deleted file mode 100644 index 087a21131..000000000 --- a/hw/xfree86/dri2/meson.build +++ /dev/null @@ -1,16 +0,0 @@ -srcs_xorg_dri2 = [ - 'dri2.c', - 'dri2ext.c', -] - -xorg_dri2 = static_library('xorg_dri2', - srcs_xorg_dri2, - include_directories: [inc, xorg_inc], - dependencies: [ - common_dep, - libdrm_dep, - ], - c_args: xorg_c_args, -) - -install_data('dri2.h', install_dir: xorgsdkdir) diff --git a/hw/xfree86/dri2/pci_ids/i810_pci_ids.h b/hw/xfree86/dri2/pci_ids/i810_pci_ids.h deleted file mode 100644 index 7f681925d..000000000 --- a/hw/xfree86/dri2/pci_ids/i810_pci_ids.h +++ /dev/null @@ -1,4 +0,0 @@ -CHIPSET(0x7121, I810, i8xx) -CHIPSET(0x7123, I810_DC100, i8xx) -CHIPSET(0x7125, I810_E, i8xx) -CHIPSET(0x1132, I815, i8xx) diff --git a/hw/xfree86/dri2/pci_ids/i915_pci_ids.h b/hw/xfree86/dri2/pci_ids/i915_pci_ids.h deleted file mode 100644 index 1c43c8ec7..000000000 --- a/hw/xfree86/dri2/pci_ids/i915_pci_ids.h +++ /dev/null @@ -1,15 +0,0 @@ -CHIPSET(0x3577, I830_M, "Intel(R) 830M") -CHIPSET(0x2562, 845_G, "Intel(R) 845G") -CHIPSET(0x3582, I855_GM, "Intel(R) 852GM/855GM") -CHIPSET(0x2572, I865_G, "Intel(R) 865G") -CHIPSET(0x2582, I915_G, "Intel(R) 915G") -CHIPSET(0x258A, E7221_G, "Intel(R) E7221G (i915)") -CHIPSET(0x2592, I915_GM, "Intel(R) 915GM") -CHIPSET(0x2772, I945_G, "Intel(R) 945G") -CHIPSET(0x27A2, I945_GM, "Intel(R) 945GM") -CHIPSET(0x27AE, I945_GME, "Intel(R) 945GME") -CHIPSET(0x29B2, Q35_G, "Intel(R) Q35") -CHIPSET(0x29C2, G33_G, "Intel(R) G33") -CHIPSET(0x29D2, Q33_G, "Intel(R) Q33") -CHIPSET(0xA011, PNV_GM, "Intel(R) Pineview M") -CHIPSET(0xA001, PNV_G, "Intel(R) Pineview") diff --git a/hw/xfree86/dri2/pci_ids/i965_pci_ids.h b/hw/xfree86/dri2/pci_ids/i965_pci_ids.h deleted file mode 100644 index c4072e2ee..000000000 --- a/hw/xfree86/dri2/pci_ids/i965_pci_ids.h +++ /dev/null @@ -1,252 +0,0 @@ -#ifndef IRIS -CHIPSET(0x29A2, i965, "Intel(R) 965G") -CHIPSET(0x2992, i965, "Intel(R) 965Q") -CHIPSET(0x2982, i965, "Intel(R) 965G") -CHIPSET(0x2972, i965, "Intel(R) 946GZ") -CHIPSET(0x2A02, i965, "Intel(R) 965GM") -CHIPSET(0x2A12, i965, "Intel(R) 965GME/GLE") -CHIPSET(0x2A42, g4x, "Mobile Intel® GM45 Express Chipset") -CHIPSET(0x2E02, g4x, "Intel(R) Integrated Graphics Device") -CHIPSET(0x2E12, g4x, "Intel(R) Q45/Q43") -CHIPSET(0x2E22, g4x, "Intel(R) G45/G43") -CHIPSET(0x2E32, g4x, "Intel(R) G41") -CHIPSET(0x2E42, g4x, "Intel(R) B43") -CHIPSET(0x2E92, g4x, "Intel(R) B43") -CHIPSET(0x0042, ilk, "Intel(R) Ironlake Desktop") -CHIPSET(0x0046, ilk, "Intel(R) Ironlake Mobile") -CHIPSET(0x0102, snb_gt1, "Intel(R) Sandybridge Desktop") -CHIPSET(0x0112, snb_gt2, "Intel(R) Sandybridge Desktop") -CHIPSET(0x0122, snb_gt2, "Intel(R) Sandybridge Desktop") -CHIPSET(0x0106, snb_gt1, "Intel(R) Sandybridge Mobile") -CHIPSET(0x0116, snb_gt2, "Intel(R) Sandybridge Mobile") -CHIPSET(0x0126, snb_gt2, "Intel(R) Sandybridge Mobile") -CHIPSET(0x010A, snb_gt1, "Intel(R) Sandybridge Server") -CHIPSET(0x0152, ivb_gt1, "Intel(R) Ivybridge Desktop") -CHIPSET(0x0162, ivb_gt2, "Intel(R) Ivybridge Desktop") -CHIPSET(0x0156, ivb_gt1, "Intel(R) Ivybridge Mobile") -CHIPSET(0x0166, ivb_gt2, "Intel(R) Ivybridge Mobile") -CHIPSET(0x015a, ivb_gt1, "Intel(R) Ivybridge Server") -CHIPSET(0x016a, ivb_gt2, "Intel(R) Ivybridge Server") -CHIPSET(0x0402, hsw_gt1, "Intel(R) Haswell Desktop") -CHIPSET(0x0412, hsw_gt2, "Intel(R) Haswell Desktop") -CHIPSET(0x0422, hsw_gt3, "Intel(R) Haswell Desktop") -CHIPSET(0x0406, hsw_gt1, "Intel(R) Haswell Mobile") -CHIPSET(0x0416, hsw_gt2, "Intel(R) Haswell Mobile") -CHIPSET(0x0426, hsw_gt3, "Intel(R) Haswell Mobile") -CHIPSET(0x040A, hsw_gt1, "Intel(R) Haswell Server") -CHIPSET(0x041A, hsw_gt2, "Intel(R) Haswell Server") -CHIPSET(0x042A, hsw_gt3, "Intel(R) Haswell Server") -CHIPSET(0x040B, hsw_gt1, "Intel(R) Haswell") -CHIPSET(0x041B, hsw_gt2, "Intel(R) Haswell") -CHIPSET(0x042B, hsw_gt3, "Intel(R) Haswell") -CHIPSET(0x040E, hsw_gt1, "Intel(R) Haswell") -CHIPSET(0x041E, hsw_gt2, "Intel(R) Haswell") -CHIPSET(0x042E, hsw_gt3, "Intel(R) Haswell") -CHIPSET(0x0C02, hsw_gt1, "Intel(R) Haswell Desktop") -CHIPSET(0x0C12, hsw_gt2, "Intel(R) Haswell Desktop") -CHIPSET(0x0C22, hsw_gt3, "Intel(R) Haswell Desktop") -CHIPSET(0x0C06, hsw_gt1, "Intel(R) Haswell Mobile") -CHIPSET(0x0C16, hsw_gt2, "Intel(R) Haswell Mobile") -CHIPSET(0x0C26, hsw_gt3, "Intel(R) Haswell Mobile") -CHIPSET(0x0C0A, hsw_gt1, "Intel(R) Haswell Server") -CHIPSET(0x0C1A, hsw_gt2, "Intel(R) Haswell Server") -CHIPSET(0x0C2A, hsw_gt3, "Intel(R) Haswell Server") -CHIPSET(0x0C0B, hsw_gt1, "Intel(R) Haswell") -CHIPSET(0x0C1B, hsw_gt2, "Intel(R) Haswell") -CHIPSET(0x0C2B, hsw_gt3, "Intel(R) Haswell") -CHIPSET(0x0C0E, hsw_gt1, "Intel(R) Haswell") -CHIPSET(0x0C1E, hsw_gt2, "Intel(R) Haswell") -CHIPSET(0x0C2E, hsw_gt3, "Intel(R) Haswell") -CHIPSET(0x0A02, hsw_gt1, "Intel(R) Haswell Desktop") -CHIPSET(0x0A12, hsw_gt2, "Intel(R) Haswell Desktop") -CHIPSET(0x0A22, hsw_gt3, "Intel(R) Haswell Desktop") -CHIPSET(0x0A06, hsw_gt1, "Intel(R) Haswell Mobile") -CHIPSET(0x0A16, hsw_gt2, "Intel(R) Haswell Mobile") -CHIPSET(0x0A26, hsw_gt3, "Intel(R) Haswell Mobile") -CHIPSET(0x0A0A, hsw_gt1, "Intel(R) Haswell Server") -CHIPSET(0x0A1A, hsw_gt2, "Intel(R) Haswell Server") -CHIPSET(0x0A2A, hsw_gt3, "Intel(R) Haswell Server") -CHIPSET(0x0A0B, hsw_gt1, "Intel(R) Haswell") -CHIPSET(0x0A1B, hsw_gt2, "Intel(R) Haswell") -CHIPSET(0x0A2B, hsw_gt3, "Intel(R) Haswell") -CHIPSET(0x0A0E, hsw_gt1, "Intel(R) Haswell") -CHIPSET(0x0A1E, hsw_gt2, "Intel(R) Haswell") -CHIPSET(0x0A2E, hsw_gt3, "Intel(R) Haswell") -CHIPSET(0x0D02, hsw_gt1, "Intel(R) Haswell Desktop") -CHIPSET(0x0D12, hsw_gt2, "Intel(R) Haswell Desktop") -CHIPSET(0x0D22, hsw_gt3, "Intel(R) Haswell Desktop") -CHIPSET(0x0D06, hsw_gt1, "Intel(R) Haswell Mobile") -CHIPSET(0x0D16, hsw_gt2, "Intel(R) Haswell Mobile") -CHIPSET(0x0D26, hsw_gt3, "Intel(R) Haswell Mobile") -CHIPSET(0x0D0A, hsw_gt1, "Intel(R) Haswell Server") -CHIPSET(0x0D1A, hsw_gt2, "Intel(R) Haswell Server") -CHIPSET(0x0D2A, hsw_gt3, "Intel(R) Haswell") -CHIPSET(0x0D0B, hsw_gt1, "Intel(R) Haswell") -CHIPSET(0x0D1B, hsw_gt2, "Intel(R) Haswell") -CHIPSET(0x0D2B, hsw_gt3, "Intel(R) Haswell") -CHIPSET(0x0D0E, hsw_gt1, "Intel(R) Haswell") -CHIPSET(0x0D1E, hsw_gt2, "Intel(R) Haswell") -CHIPSET(0x0D2E, hsw_gt3, "Intel(R) Haswell") -CHIPSET(0x0F31, byt, "Intel(R) Bay Trail") -CHIPSET(0x0F32, byt, "Intel(R) Bay Trail") -CHIPSET(0x0F33, byt, "Intel(R) Bay Trail") -CHIPSET(0x0157, byt, "Intel(R) Bay Trail") -CHIPSET(0x0155, byt, "Intel(R) Bay Trail") -CHIPSET(0x22B0, chv, "Intel(R) HD Graphics (Cherrytrail)") -CHIPSET(0x22B1, chv, "Intel(R) HD Graphics XXX (Braswell)") /* Overridden in brw_get_renderer_string */ -CHIPSET(0x22B2, chv, "Intel(R) HD Graphics (Cherryview)") -CHIPSET(0x22B3, chv, "Intel(R) HD Graphics (Cherryview)") -#endif -CHIPSET(0x1602, bdw_gt1, "Intel(R) Broadwell GT1") -CHIPSET(0x1606, bdw_gt1, "Intel(R) Broadwell GT1") -CHIPSET(0x160A, bdw_gt1, "Intel(R) Broadwell GT1") -CHIPSET(0x160B, bdw_gt1, "Intel(R) Broadwell GT1") -CHIPSET(0x160D, bdw_gt1, "Intel(R) Broadwell GT1") -CHIPSET(0x160E, bdw_gt1, "Intel(R) Broadwell GT1") -CHIPSET(0x1612, bdw_gt2, "Intel(R) HD Graphics 5600 (Broadwell GT2)") -CHIPSET(0x1616, bdw_gt2, "Intel(R) HD Graphics 5500 (Broadwell GT2)") -CHIPSET(0x161A, bdw_gt2, "Intel(R) Broadwell GT2") -CHIPSET(0x161B, bdw_gt2, "Intel(R) Broadwell GT2") -CHIPSET(0x161D, bdw_gt2, "Intel(R) Broadwell GT2") -CHIPSET(0x161E, bdw_gt2, "Intel(R) HD Graphics 5300 (Broadwell GT2)") -CHIPSET(0x1622, bdw_gt3, "Intel(R) Iris Pro 6200 (Broadwell GT3e)") -CHIPSET(0x1626, bdw_gt3, "Intel(R) HD Graphics 6000 (Broadwell GT3)") -CHIPSET(0x162A, bdw_gt3, "Intel(R) Iris Pro P6300 (Broadwell GT3e)") -CHIPSET(0x162B, bdw_gt3, "Intel(R) Iris 6100 (Broadwell GT3)") -CHIPSET(0x162D, bdw_gt3, "Intel(R) Broadwell GT3") -CHIPSET(0x162E, bdw_gt3, "Intel(R) Broadwell GT3") -CHIPSET(0x1902, skl_gt1, "Intel(R) HD Graphics 510 (Skylake GT1)") -CHIPSET(0x1906, skl_gt1, "Intel(R) HD Graphics 510 (Skylake GT1)") -CHIPSET(0x190A, skl_gt1, "Intel(R) Skylake GT1") -CHIPSET(0x190B, skl_gt1, "Intel(R) HD Graphics 510 (Skylake GT1)") -CHIPSET(0x190E, skl_gt1, "Intel(R) Skylake GT1") -CHIPSET(0x1912, skl_gt2, "Intel(R) HD Graphics 530 (Skylake GT2)") -CHIPSET(0x1913, skl_gt2, "Intel(R) Skylake GT2f") -CHIPSET(0x1915, skl_gt2, "Intel(R) Skylake GT2f") -CHIPSET(0x1916, skl_gt2, "Intel(R) HD Graphics 520 (Skylake GT2)") -CHIPSET(0x1917, skl_gt2, "Intel(R) Skylake GT2f") -CHIPSET(0x191A, skl_gt2, "Intel(R) Skylake GT2") -CHIPSET(0x191B, skl_gt2, "Intel(R) HD Graphics 530 (Skylake GT2)") -CHIPSET(0x191D, skl_gt2, "Intel(R) HD Graphics P530 (Skylake GT2)") -CHIPSET(0x191E, skl_gt2, "Intel(R) HD Graphics 515 (Skylake GT2)") -CHIPSET(0x1921, skl_gt2, "Intel(R) HD Graphics 520 (Skylake GT2)") -CHIPSET(0x1923, skl_gt3, "Intel(R) Skylake GT3e") -CHIPSET(0x1926, skl_gt3, "Intel(R) Iris Graphics 540 (Skylake GT3e)") -CHIPSET(0x1927, skl_gt3, "Intel(R) Iris Graphics 550 (Skylake GT3e)") -CHIPSET(0x192A, skl_gt4, "Intel(R) Skylake GT4") -CHIPSET(0x192B, skl_gt3, "Intel(R) Iris Graphics 555 (Skylake GT3e)") -CHIPSET(0x192D, skl_gt3, "Intel(R) Iris Graphics P555 (Skylake GT3e)") -CHIPSET(0x1932, skl_gt4, "Intel(R) Iris Pro Graphics 580 (Skylake GT4e)") -CHIPSET(0x193A, skl_gt4, "Intel(R) Iris Pro Graphics P580 (Skylake GT4e)") -CHIPSET(0x193B, skl_gt4, "Intel(R) Iris Pro Graphics 580 (Skylake GT4e)") -CHIPSET(0x193D, skl_gt4, "Intel(R) Iris Pro Graphics P580 (Skylake GT4e)") -CHIPSET(0x0A84, bxt, "Intel(R) HD Graphics (Broxton)") -CHIPSET(0x1A84, bxt, "Intel(R) HD Graphics (Broxton)") -CHIPSET(0x1A85, bxt_2x6, "Intel(R) HD Graphics (Broxton 2x6)") -CHIPSET(0x5A84, bxt, "Intel(R) HD Graphics 505 (Broxton)") -CHIPSET(0x5A85, bxt_2x6, "Intel(R) HD Graphics 500 (Broxton 2x6)") -CHIPSET(0x5902, kbl_gt1, "Intel(R) HD Graphics 610 (Kaby Lake GT1)") -CHIPSET(0x5906, kbl_gt1, "Intel(R) HD Graphics 610 (Kaby Lake GT1)") -CHIPSET(0x590A, kbl_gt1, "Intel(R) Kabylake GT1") -CHIPSET(0x5908, kbl_gt1, "Intel(R) Kabylake GT1") -CHIPSET(0x590B, kbl_gt1, "Intel(R) Kabylake GT1") -CHIPSET(0x590E, kbl_gt1, "Intel(R) Kabylake GT1") -CHIPSET(0x5913, kbl_gt1_5, "Intel(R) Kabylake GT1.5") -CHIPSET(0x5915, kbl_gt1_5, "Intel(R) Kabylake GT1.5") -CHIPSET(0x5917, kbl_gt2, "Intel(R) UHD Graphics 620 (Kabylake GT2)") -CHIPSET(0x5912, kbl_gt2, "Intel(R) HD Graphics 630 (Kaby Lake GT2)") -CHIPSET(0x5916, kbl_gt2, "Intel(R) HD Graphics 620 (Kaby Lake GT2)") -CHIPSET(0x591A, kbl_gt2, "Intel(R) HD Graphics P630 (Kaby Lake GT2)") -CHIPSET(0x591B, kbl_gt2, "Intel(R) HD Graphics 630 (Kaby Lake GT2)") -CHIPSET(0x591D, kbl_gt2, "Intel(R) HD Graphics P630 (Kaby Lake GT2)") -CHIPSET(0x591E, kbl_gt2, "Intel(R) HD Graphics 615 (Kaby Lake GT2)") -CHIPSET(0x5921, kbl_gt2, "Intel(R) Kabylake GT2F") -CHIPSET(0x5923, kbl_gt3, "Intel(R) Kabylake GT3") -CHIPSET(0x5926, kbl_gt3, "Intel(R) Iris Plus Graphics 640 (Kaby Lake GT3e)") -CHIPSET(0x5927, kbl_gt3, "Intel(R) Iris Plus Graphics 650 (Kaby Lake GT3e)") -CHIPSET(0x593B, kbl_gt4, "Intel(R) Kabylake GT4") -CHIPSET(0x591C, kbl_gt2, "Intel(R) Amber Lake (Kabylake) GT2") -CHIPSET(0x87C0, kbl_gt2, "Intel(R) Amber Lake (Kabylake) GT2") -CHIPSET(0x87CA, cfl_gt2, "Intel(R) Amber Lake (Coffeelake) GT2") -CHIPSET(0x3184, glk, "Intel(R) UHD Graphics 605 (Geminilake)") -CHIPSET(0x3185, glk_2x6, "Intel(R) UHD Graphics 600 (Geminilake 2x6)") -CHIPSET(0x3E90, cfl_gt1, "Intel(R) UHD Graphics 610 (Coffeelake 2x6 GT1)") -CHIPSET(0x3E93, cfl_gt1, "Intel(R) UHD Graphics 610 (Coffeelake 2x6 GT1)") -CHIPSET(0x3E99, cfl_gt1, "Intel(R) HD Graphics (Coffeelake 2x6 GT1)") -CHIPSET(0x3E9C, cfl_gt1, "Intel(R) HD Graphics (Coffeelake 2x6 GT1)") -CHIPSET(0x3E91, cfl_gt2, "Intel(R) UHD Graphics 630 (Coffeelake 3x8 GT2)") -CHIPSET(0x3E92, cfl_gt2, "Intel(R) UHD Graphics 630 (Coffeelake 3x8 GT2)") -CHIPSET(0x3E96, cfl_gt2, "Intel(R) HD Graphics (Coffeelake 3x8 GT2)") -CHIPSET(0x3E98, cfl_gt2, "Intel(R) UHD Graphics 630 (Coffeelake 3x8 GT2)") -CHIPSET(0x3E9A, cfl_gt2, "Intel(R) HD Graphics (Coffeelake 3x8 GT2)") -CHIPSET(0x3E9B, cfl_gt2, "Intel(R) UHD Graphics 630 (Coffeelake 3x8 GT2)") -CHIPSET(0x3E94, cfl_gt2, "Intel(R) HD Graphics (Coffeelake 3x8 GT2)") -CHIPSET(0x3EA9, cfl_gt2, "Intel(R) HD Graphics (Coffeelake 3x8 GT2)") -CHIPSET(0x3EA5, cfl_gt3, "Intel(R) HD Graphics (Coffeelake 3x8 GT3)") -CHIPSET(0x3EA6, cfl_gt3, "Intel(R) HD Graphics (Coffeelake 3x8 GT3)") -CHIPSET(0x3EA7, cfl_gt3, "Intel(R) HD Graphics (Coffeelake 3x8 GT3)") -CHIPSET(0x3EA8, cfl_gt3, "Intel(R) HD Graphics (Coffeelake 3x8 GT3)") -CHIPSET(0x3EA1, cfl_gt1, "Intel(R) HD Graphics (Whiskey Lake 2x6 GT1)") -CHIPSET(0x3EA4, cfl_gt1, "Intel(R) HD Graphics (Whiskey Lake 3x8 GT1)") -CHIPSET(0x3EA0, cfl_gt2, "Intel(R) HD Graphics (Whiskey Lake 3x8 GT2)") -CHIPSET(0x3EA3, cfl_gt2, "Intel(R) HD Graphics (Whiskey Lake 3x8 GT2)") -CHIPSET(0x3EA2, cfl_gt3, "Intel(R) HD Graphics (Whiskey Lake 3x8 GT3)") -CHIPSET(0x9B21, cfl_gt1, "Intel(R) HD Graphics (Comet Lake 2x6 GT1)") -CHIPSET(0x9BA0, cfl_gt1, "Intel(R) HD Graphics (Comet Lake 2x6 GT1)") -CHIPSET(0x9BA2, cfl_gt1, "Intel(R) HD Graphics (Comet Lake 2x6 GT1)") -CHIPSET(0x9BA4, cfl_gt1, "Intel(R) HD Graphics (Comet Lake 2x6 GT1)") -CHIPSET(0x9BA5, cfl_gt1, "Intel(R) HD Graphics (Comet Lake 2x6 GT1)") -CHIPSET(0x9BA8, cfl_gt1, "Intel(R) HD Graphics (Comet Lake 2x6 GT1)") -CHIPSET(0x9BAA, cfl_gt1, "Intel(R) HD Graphics (Comet Lake 2x6 GT1)") -CHIPSET(0x9BAB, cfl_gt1, "Intel(R) HD Graphics (Comet Lake 2x6 GT1)") -CHIPSET(0x9BAC, cfl_gt1, "Intel(R) HD Graphics (Comet Lake 2x6 GT1)") -CHIPSET(0x9B41, cfl_gt2, "Intel(R) HD Graphics (Comet Lake 3x8 GT2)") -CHIPSET(0x9BC0, cfl_gt2, "Intel(R) HD Graphics (Comet Lake 3x8 GT2)") -CHIPSET(0x9BC2, cfl_gt2, "Intel(R) HD Graphics (Comet Lake 3x8 GT2)") -CHIPSET(0x9BC4, cfl_gt2, "Intel(R) HD Graphics (Comet Lake 3x8 GT2)") -CHIPSET(0x9BC5, cfl_gt2, "Intel(R) HD Graphics (Comet Lake 3x8 GT2)") -CHIPSET(0x9BC8, cfl_gt2, "Intel(R) HD Graphics (Comet Lake 3x8 GT2)") -CHIPSET(0x9BCA, cfl_gt2, "Intel(R) HD Graphics (Comet Lake 3x8 GT2)") -CHIPSET(0x9BCB, cfl_gt2, "Intel(R) HD Graphics (Comet Lake 3x8 GT2)") -CHIPSET(0x9BCC, cfl_gt2, "Intel(R) HD Graphics (Comet Lake 3x8 GT2)") -CHIPSET(0x5A49, cnl_2x8, "Intel(R) HD Graphics (Cannonlake 2x8 GT0.5)") -CHIPSET(0x5A4A, cnl_2x8, "Intel(R) HD Graphics (Cannonlake 2x8 GT0.5)") -CHIPSET(0x5A41, cnl_3x8, "Intel(R) HD Graphics (Cannonlake 3x8 GT1)") -CHIPSET(0x5A42, cnl_3x8, "Intel(R) HD Graphics (Cannonlake 3x8 GT1)") -CHIPSET(0x5A44, cnl_3x8, "Intel(R) HD Graphics (Cannonlake 3x8 GT1)") -CHIPSET(0x5A59, cnl_4x8, "Intel(R) HD Graphics (Cannonlake 4x8 GT1.5)") -CHIPSET(0x5A5A, cnl_4x8, "Intel(R) HD Graphics (Cannonlake 4x8 GT1.5)") -CHIPSET(0x5A5C, cnl_4x8, "Intel(R) HD Graphics (Cannonlake 4x8 GT1.5)") -CHIPSET(0x5A50, cnl_5x8, "Intel(R) HD Graphics (Cannonlake 5x8 GT2)") -CHIPSET(0x5A51, cnl_5x8, "Intel(R) HD Graphics (Cannonlake 5x8 GT2)") -CHIPSET(0x5A52, cnl_5x8, "Intel(R) HD Graphics (Cannonlake 5x8 GT2)") -CHIPSET(0x5A54, cnl_5x8, "Intel(R) HD Graphics (Cannonlake 5x8 GT2)") -CHIPSET(0x8A50, icl_8x8, "Intel(R) HD Graphics (Ice Lake 8x8 GT2)") -CHIPSET(0x8A51, icl_8x8, "Intel(R) HD Graphics (Ice Lake 8x8 GT2)") -CHIPSET(0x8A52, icl_8x8, "Intel(R) HD Graphics (Ice Lake 8x8 GT2)") -CHIPSET(0x8A53, icl_8x8, "Intel(R) HD Graphics (Ice Lake 8x8 GT2)") -CHIPSET(0x8A54, icl_6x8, "Intel(R) HD Graphics (Ice Lake 6x8 GT1.5)") -CHIPSET(0x8A56, icl_4x8, "Intel(R) HD Graphics (Ice Lake 4x8 GT1)") -CHIPSET(0x8A57, icl_6x8, "Intel(R) HD Graphics (Ice Lake 6x8 GT1.5)") -CHIPSET(0x8A58, icl_4x8, "Intel(R) HD Graphics (Ice Lake 4x8 GT1)") -CHIPSET(0x8A59, icl_6x8, "Intel(R) HD Graphics (Ice Lake 6x8 GT1.5)") -CHIPSET(0x8A5A, icl_6x8, "Intel(R) HD Graphics (Ice Lake 6x8 GT1.5)") -CHIPSET(0x8A5B, icl_4x8, "Intel(R) HD Graphics (Ice Lake 4x8 GT1)") -CHIPSET(0x8A5C, icl_6x8, "Intel(R) HD Graphics (Ice Lake 6x8 GT1.5)") -CHIPSET(0x8A5D, icl_4x8, "Intel(R) HD Graphics (Ice Lake 4x8 GT1)") -CHIPSET(0x8A71, icl_1x8, "Intel(R) HD Graphics (Ice Lake 1x8 GT0.5)") -CHIPSET(0x4500, ehl_4x8, "Intel(R) HD Graphics (Elkhart Lake 4x8)") -CHIPSET(0x4571, ehl_4x8, "Intel(R) HD Graphics (Elkhart Lake 4x8)") -CHIPSET(0x4551, ehl_4x4, "Intel(R) HD Graphics (Elkhart Lake 4x4)") -CHIPSET(0x4541, ehl_2x4, "Intel(R) HD Graphics (Elkhart Lake 2x4)") -CHIPSET(0x9A40, tgl_1x6x16, "Intel(R) HD Graphics (Tigerlake 1x6x16 GT2)") -CHIPSET(0x9A49, tgl_1x6x16, "Intel(R) HD Graphics (Tigerlake 1x6x16 GT2)") -CHIPSET(0x9A59, tgl_1x6x16, "Intel(R) HD Graphics (Tigerlake 1x6x16 GT2)") -CHIPSET(0x9A60, tgl_1x2x16, "Intel(R) HD Graphics (Tigerlake 1x2x16 GT1)") -CHIPSET(0x9A68, tgl_1x2x16, "Intel(R) HD Graphics (Tigerlake 1x2x16 GT1)") -CHIPSET(0x9A70, tgl_1x2x16, "Intel(R) HD Graphics (Tigerlake 1x2x16 GT1)") -CHIPSET(0x9A78, tgl_1x2x16, "Intel(R) HD Graphics (Tigerlake 1x2x16 GT1)") -CHIPSET(0x9AC0, tgl_1x2x16, "Intel(R) HD Graphics (Tigerlake 1x2x16 GT2)") -CHIPSET(0x9AC9, tg1_1x2x16, "Intel(R) HD Graphics (Tigerlake 1x2x16 GT2)") -CHIPSET(0x9AD9, tgl_1x2x16, "Intel(R) HD Graphics (Tigerlake 1x2x16 GT2)") -CHIPSET(0x9AF8, tgl_1x2x16, "Intel(R) HD Graphics (Tigerlake 1X2X16 GT2)") diff --git a/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h b/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h deleted file mode 100644 index 04f372279..000000000 --- a/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef _PCI_ID_DRIVER_MAP_H_ -#define _PCI_ID_DRIVER_MAP_H_ - -#include - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) -#endif - -static const int i915_chip_ids[] = { -#define CHIPSET(chip, desc, name) chip, -#include "pci_ids/i915_pci_ids.h" -#undef CHIPSET -}; - -static const int i965_chip_ids[] = { -#define CHIPSET(chip, family, name) chip, -#include "pci_ids/i965_pci_ids.h" -#undef CHIPSET -}; - -#ifndef DRIVER_MAP_GALLIUM_ONLY -static const int r100_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/radeon_pci_ids.h" -#undef CHIPSET -}; - -static const int r200_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/r200_pci_ids.h" -#undef CHIPSET -}; -#endif - -static const int r300_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/r300_pci_ids.h" -#undef CHIPSET -}; - -static const int r600_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/r600_pci_ids.h" -#undef CHIPSET -}; - -static const int virtio_gpu_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/virtio_gpu_pci_ids.h" -#undef CHIPSET -}; - -static const int vmwgfx_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/vmwgfx_pci_ids.h" -#undef CHIPSET -}; - -static const struct { - int vendor_id; - const char *driver; - const int *chip_ids; - int num_chips_ids; -} driver_map[] = { - { 0x8086, "i915", i915_chip_ids, ARRAY_SIZE(i915_chip_ids) }, - { 0x8086, "i965", i965_chip_ids, ARRAY_SIZE(i965_chip_ids) }, - { 0x8086, "i965", NULL, -1 }, -#ifndef DRIVER_MAP_GALLIUM_ONLY - { 0x1002, "radeon", r100_chip_ids, ARRAY_SIZE(r100_chip_ids) }, - { 0x1002, "r200", r200_chip_ids, ARRAY_SIZE(r200_chip_ids) }, -#endif - { 0x1002, "r300", r300_chip_ids, ARRAY_SIZE(r300_chip_ids) }, - { 0x1002, "r600", r600_chip_ids, ARRAY_SIZE(r600_chip_ids) }, - { 0x1002, "radeonsi", NULL, -1 }, - { 0x10de, "nouveau", NULL, -1 }, - { 0x1af4, "virtio_gpu", virtio_gpu_chip_ids, ARRAY_SIZE(virtio_gpu_chip_ids) }, - { 0x15ad, "vmwgfx", vmwgfx_chip_ids, ARRAY_SIZE(vmwgfx_chip_ids) }, - { 0x0000, NULL, NULL, 0 }, -}; - -#endif /* _PCI_ID_DRIVER_MAP_H_ */ diff --git a/hw/xfree86/dri2/pci_ids/r200_pci_ids.h b/hw/xfree86/dri2/pci_ids/r200_pci_ids.h deleted file mode 100644 index f857ca704..000000000 --- a/hw/xfree86/dri2/pci_ids/r200_pci_ids.h +++ /dev/null @@ -1,24 +0,0 @@ -CHIPSET(0x5148, R200_QH, R200) -CHIPSET(0x514C, R200_QL, R200) -CHIPSET(0x514D, R200_QM, R200) -CHIPSET(0x4242, R200_BB, R200) - -CHIPSET(0x4966, RV250_If, RV250) -CHIPSET(0x4967, RV250_Ig, RV250) -CHIPSET(0x4C64, RV250_Ld, RV250) -CHIPSET(0x4C66, RV250_Lf, RV250) -CHIPSET(0x4C67, RV250_Lg, RV250) - -CHIPSET(0x4C6E, RV280_4C6E, RV280) -CHIPSET(0x5960, RV280_5960, RV280) -CHIPSET(0x5961, RV280_5961, RV280) -CHIPSET(0x5962, RV280_5962, RV280) -CHIPSET(0x5964, RV280_5964, RV280) -CHIPSET(0x5965, RV280_5965, RV280) -CHIPSET(0x5C61, RV280_5C61, RV280) -CHIPSET(0x5C63, RV280_5C63, RV280) - -CHIPSET(0x5834, RS300_5834, RS300) -CHIPSET(0x5835, RS300_5835, RS300) -CHIPSET(0x7834, RS350_7834, RS300) -CHIPSET(0x7835, RS350_7835, RS300) diff --git a/hw/xfree86/dri2/pci_ids/r300_pci_ids.h b/hw/xfree86/dri2/pci_ids/r300_pci_ids.h deleted file mode 100644 index 791026ae7..000000000 --- a/hw/xfree86/dri2/pci_ids/r300_pci_ids.h +++ /dev/null @@ -1,227 +0,0 @@ -CHIPSET(0x4144, R300_AD, R300) -CHIPSET(0x4145, R300_AE, R300) -CHIPSET(0x4146, R300_AF, R300) -CHIPSET(0x4147, R300_AG, R300) -CHIPSET(0x4E44, R300_ND, R300) -CHIPSET(0x4E45, R300_NE, R300) -CHIPSET(0x4E46, R300_NF, R300) -CHIPSET(0x4E47, R300_NG, R300) - -CHIPSET(0x4E48, R350_NH, R350) -CHIPSET(0x4E49, R350_NI, R350) -CHIPSET(0x4E4B, R350_NK, R350) -CHIPSET(0x4148, R350_AH, R350) -CHIPSET(0x4149, R350_AI, R350) -CHIPSET(0x414A, R350_AJ, R350) -CHIPSET(0x414B, R350_AK, R350) -CHIPSET(0x4E4A, R360_NJ, R350) - -CHIPSET(0x4150, RV350_AP, RV350) -CHIPSET(0x4151, RV350_AQ, RV350) -CHIPSET(0x4152, RV350_AR, RV350) -CHIPSET(0x4153, RV350_AS, RV350) -CHIPSET(0x4154, RV350_AT, RV350) -CHIPSET(0x4155, RV350_AU, RV350) -CHIPSET(0x4156, RV350_AV, RV350) -CHIPSET(0x4E50, RV350_NP, RV350) -CHIPSET(0x4E51, RV350_NQ, RV350) -CHIPSET(0x4E52, RV350_NR, RV350) -CHIPSET(0x4E53, RV350_NS, RV350) -CHIPSET(0x4E54, RV350_NT, RV350) -CHIPSET(0x4E56, RV350_NV, RV350) - -CHIPSET(0x5460, RV370_5460, RV370) -CHIPSET(0x5462, RV370_5462, RV370) -CHIPSET(0x5464, RV370_5464, RV370) -CHIPSET(0x5B60, RV370_5B60, RV370) -CHIPSET(0x5B62, RV370_5B62, RV370) -CHIPSET(0x5B63, RV370_5B63, RV370) -CHIPSET(0x5B64, RV370_5B64, RV370) -CHIPSET(0x5B65, RV370_5B65, RV370) - -CHIPSET(0x3150, RV380_3150, RV380) -CHIPSET(0x3151, RV380_3151, RV380) -CHIPSET(0x3152, RV380_3152, RV380) -CHIPSET(0x3154, RV380_3154, RV380) -CHIPSET(0x3155, RV380_3155, RV380) -CHIPSET(0x3E50, RV380_3E50, RV380) -CHIPSET(0x3E54, RV380_3E54, RV380) - -CHIPSET(0x4A48, R420_JH, R420) -CHIPSET(0x4A49, R420_JI, R420) -CHIPSET(0x4A4A, R420_JJ, R420) -CHIPSET(0x4A4B, R420_JK, R420) -CHIPSET(0x4A4C, R420_JL, R420) -CHIPSET(0x4A4D, R420_JM, R420) -CHIPSET(0x4A4E, R420_JN, R420) -CHIPSET(0x4A4F, R420_JO, R420) -CHIPSET(0x4A50, R420_JP, R420) -CHIPSET(0x4A54, R420_JT, R420) - -CHIPSET(0x5548, R423_UH, R423) -CHIPSET(0x5549, R423_UI, R423) -CHIPSET(0x554A, R423_UJ, R423) -CHIPSET(0x554B, R423_UK, R423) -CHIPSET(0x5550, R423_5550, R423) -CHIPSET(0x5551, R423_UQ, R423) -CHIPSET(0x5552, R423_UR, R423) -CHIPSET(0x5554, R423_UT, R423) -CHIPSET(0x5D57, R423_5D57, R423) - -CHIPSET(0x554C, R430_554C, R430) -CHIPSET(0x554D, R430_554D, R430) -CHIPSET(0x554E, R430_554E, R430) -CHIPSET(0x554F, R430_554F, R430) -CHIPSET(0x5D48, R430_5D48, R430) -CHIPSET(0x5D49, R430_5D49, R430) -CHIPSET(0x5D4A, R430_5D4A, R430) - -CHIPSET(0x5D4C, R480_5D4C, R480) -CHIPSET(0x5D4D, R480_5D4D, R480) -CHIPSET(0x5D4E, R480_5D4E, R480) -CHIPSET(0x5D4F, R480_5D4F, R480) -CHIPSET(0x5D50, R480_5D50, R480) -CHIPSET(0x5D52, R480_5D52, R480) - -CHIPSET(0x4B48, R481_4B48, R481) -CHIPSET(0x4B49, R481_4B49, R481) -CHIPSET(0x4B4A, R481_4B4A, R481) -CHIPSET(0x4B4B, R481_4B4B, R481) -CHIPSET(0x4B4C, R481_4B4C, R481) - -CHIPSET(0x564A, RV410_564A, RV410) -CHIPSET(0x564B, RV410_564B, RV410) -CHIPSET(0x564F, RV410_564F, RV410) -CHIPSET(0x5652, RV410_5652, RV410) -CHIPSET(0x5653, RV410_5653, RV410) -CHIPSET(0x5657, RV410_5657, RV410) -CHIPSET(0x5E48, RV410_5E48, RV410) -CHIPSET(0x5E4A, RV410_5E4A, RV410) -CHIPSET(0x5E4B, RV410_5E4B, RV410) -CHIPSET(0x5E4C, RV410_5E4C, RV410) -CHIPSET(0x5E4D, RV410_5E4D, RV410) -CHIPSET(0x5E4F, RV410_5E4F, RV410) - -CHIPSET(0x5A41, RS400_5A41, RS400) -CHIPSET(0x5A42, RS400_5A42, RS400) - -CHIPSET(0x5A61, RC410_5A61, RC410) -CHIPSET(0x5A62, RC410_5A62, RC410) - -CHIPSET(0x5954, RS480_5954, RS480) -CHIPSET(0x5955, RS480_5955, RS480) -CHIPSET(0x5974, RS482_5974, RS480) -CHIPSET(0x5975, RS482_5975, RS480) - -CHIPSET(0x7100, R520_7100, R520) -CHIPSET(0x7101, R520_7101, R520) -CHIPSET(0x7102, R520_7102, R520) -CHIPSET(0x7103, R520_7103, R520) -CHIPSET(0x7104, R520_7104, R520) -CHIPSET(0x7105, R520_7105, R520) -CHIPSET(0x7106, R520_7106, R520) -CHIPSET(0x7108, R520_7108, R520) -CHIPSET(0x7109, R520_7109, R520) -CHIPSET(0x710A, R520_710A, R520) -CHIPSET(0x710B, R520_710B, R520) -CHIPSET(0x710C, R520_710C, R520) -CHIPSET(0x710E, R520_710E, R520) -CHIPSET(0x710F, R520_710F, R520) - -CHIPSET(0x7140, RV515_7140, RV515) -CHIPSET(0x7141, RV515_7141, RV515) -CHIPSET(0x7142, RV515_7142, RV515) -CHIPSET(0x7143, RV515_7143, RV515) -CHIPSET(0x7144, RV515_7144, RV515) -CHIPSET(0x7145, RV515_7145, RV515) -CHIPSET(0x7146, RV515_7146, RV515) -CHIPSET(0x7147, RV515_7147, RV515) -CHIPSET(0x7149, RV515_7149, RV515) -CHIPSET(0x714A, RV515_714A, RV515) -CHIPSET(0x714B, RV515_714B, RV515) -CHIPSET(0x714C, RV515_714C, RV515) -CHIPSET(0x714D, RV515_714D, RV515) -CHIPSET(0x714E, RV515_714E, RV515) -CHIPSET(0x714F, RV515_714F, RV515) -CHIPSET(0x7151, RV515_7151, RV515) -CHIPSET(0x7152, RV515_7152, RV515) -CHIPSET(0x7153, RV515_7153, RV515) -CHIPSET(0x715E, RV515_715E, RV515) -CHIPSET(0x715F, RV515_715F, RV515) -CHIPSET(0x7180, RV515_7180, RV515) -CHIPSET(0x7181, RV515_7181, RV515) -CHIPSET(0x7183, RV515_7183, RV515) -CHIPSET(0x7186, RV515_7186, RV515) -CHIPSET(0x7187, RV515_7187, RV515) -CHIPSET(0x7188, RV515_7188, RV515) -CHIPSET(0x718A, RV515_718A, RV515) -CHIPSET(0x718B, RV515_718B, RV515) -CHIPSET(0x718C, RV515_718C, RV515) -CHIPSET(0x718D, RV515_718D, RV515) -CHIPSET(0x718F, RV515_718F, RV515) -CHIPSET(0x7193, RV515_7193, RV515) -CHIPSET(0x7196, RV515_7196, RV515) -CHIPSET(0x719B, RV515_719B, RV515) -CHIPSET(0x719F, RV515_719F, RV515) -CHIPSET(0x7200, RV515_7200, RV515) -CHIPSET(0x7210, RV515_7210, RV515) -CHIPSET(0x7211, RV515_7211, RV515) - -CHIPSET(0x71C0, RV530_71C0, RV530) -CHIPSET(0x71C1, RV530_71C1, RV530) -CHIPSET(0x71C2, RV530_71C2, RV530) -CHIPSET(0x71C3, RV530_71C3, RV530) -CHIPSET(0x71C4, RV530_71C4, RV530) -CHIPSET(0x71C5, RV530_71C5, RV530) -CHIPSET(0x71C6, RV530_71C6, RV530) -CHIPSET(0x71C7, RV530_71C7, RV530) -CHIPSET(0x71CD, RV530_71CD, RV530) -CHIPSET(0x71CE, RV530_71CE, RV530) -CHIPSET(0x71D2, RV530_71D2, RV530) -CHIPSET(0x71D4, RV530_71D4, RV530) -CHIPSET(0x71D5, RV530_71D5, RV530) -CHIPSET(0x71D6, RV530_71D6, RV530) -CHIPSET(0x71DA, RV530_71DA, RV530) -CHIPSET(0x71DE, RV530_71DE, RV530) - -CHIPSET(0x7281, RV560_7281, RV560) -CHIPSET(0x7283, RV560_7283, RV560) -CHIPSET(0x7287, RV560_7287, RV560) -CHIPSET(0x7290, RV560_7290, RV560) -CHIPSET(0x7291, RV560_7291, RV560) -CHIPSET(0x7293, RV560_7293, RV560) -CHIPSET(0x7297, RV560_7297, RV560) - -CHIPSET(0x7280, RV570_7280, RV570) -CHIPSET(0x7288, RV570_7288, RV570) -CHIPSET(0x7289, RV570_7289, RV570) -CHIPSET(0x728B, RV570_728B, RV570) -CHIPSET(0x728C, RV570_728C, RV570) - -CHIPSET(0x7240, R580_7240, R580) -CHIPSET(0x7243, R580_7243, R580) -CHIPSET(0x7244, R580_7244, R580) -CHIPSET(0x7245, R580_7245, R580) -CHIPSET(0x7246, R580_7246, R580) -CHIPSET(0x7247, R580_7247, R580) -CHIPSET(0x7248, R580_7248, R580) -CHIPSET(0x7249, R580_7249, R580) -CHIPSET(0x724A, R580_724A, R580) -CHIPSET(0x724B, R580_724B, R580) -CHIPSET(0x724C, R580_724C, R580) -CHIPSET(0x724D, R580_724D, R580) -CHIPSET(0x724E, R580_724E, R580) -CHIPSET(0x724F, R580_724F, R580) -CHIPSET(0x7284, R580_7284, R580) - -CHIPSET(0x793F, RS600_793F, RS600) -CHIPSET(0x7941, RS600_7941, RS600) -CHIPSET(0x7942, RS600_7942, RS600) - -CHIPSET(0x791E, RS690_791E, RS690) -CHIPSET(0x791F, RS690_791F, RS690) - -CHIPSET(0x796C, RS740_796C, RS740) -CHIPSET(0x796D, RS740_796D, RS740) -CHIPSET(0x796E, RS740_796E, RS740) -CHIPSET(0x796F, RS740_796F, RS740) diff --git a/hw/xfree86/dri2/pci_ids/r600_pci_ids.h b/hw/xfree86/dri2/pci_ids/r600_pci_ids.h deleted file mode 100644 index 533c9f3fc..000000000 --- a/hw/xfree86/dri2/pci_ids/r600_pci_ids.h +++ /dev/null @@ -1,327 +0,0 @@ -CHIPSET(0x9400, R600_9400, R600) -CHIPSET(0x9401, R600_9401, R600) -CHIPSET(0x9402, R600_9402, R600) -CHIPSET(0x9403, R600_9403, R600) -CHIPSET(0x9405, R600_9405, R600) -CHIPSET(0x940A, R600_940A, R600) -CHIPSET(0x940B, R600_940B, R600) -CHIPSET(0x940F, R600_940F, R600) - -CHIPSET(0x94C0, RV610_94C0, RV610) -CHIPSET(0x94C1, RV610_94C1, RV610) -CHIPSET(0x94C3, RV610_94C3, RV610) -CHIPSET(0x94C4, RV610_94C4, RV610) -CHIPSET(0x94C5, RV610_94C5, RV610) -CHIPSET(0x94C6, RV610_94C6, RV610) -CHIPSET(0x94C7, RV610_94C7, RV610) -CHIPSET(0x94C8, RV610_94C8, RV610) -CHIPSET(0x94C9, RV610_94C9, RV610) -CHIPSET(0x94CB, RV610_94CB, RV610) -CHIPSET(0x94CC, RV610_94CC, RV610) -CHIPSET(0x94CD, RV610_94CD, RV610) - -CHIPSET(0x9580, RV630_9580, RV630) -CHIPSET(0x9581, RV630_9581, RV630) -CHIPSET(0x9583, RV630_9583, RV630) -CHIPSET(0x9586, RV630_9586, RV630) -CHIPSET(0x9587, RV630_9587, RV630) -CHIPSET(0x9588, RV630_9588, RV630) -CHIPSET(0x9589, RV630_9589, RV630) -CHIPSET(0x958A, RV630_958A, RV630) -CHIPSET(0x958B, RV630_958B, RV630) -CHIPSET(0x958C, RV630_958C, RV630) -CHIPSET(0x958D, RV630_958D, RV630) -CHIPSET(0x958E, RV630_958E, RV630) -CHIPSET(0x958F, RV630_958F, RV630) - -CHIPSET(0x9500, RV670_9500, RV670) -CHIPSET(0x9501, RV670_9501, RV670) -CHIPSET(0x9504, RV670_9504, RV670) -CHIPSET(0x9505, RV670_9505, RV670) -CHIPSET(0x9506, RV670_9506, RV670) -CHIPSET(0x9507, RV670_9507, RV670) -CHIPSET(0x9508, RV670_9508, RV670) -CHIPSET(0x9509, RV670_9509, RV670) -CHIPSET(0x950F, RV670_950F, RV670) -CHIPSET(0x9511, RV670_9511, RV670) -CHIPSET(0x9515, RV670_9515, RV670) -CHIPSET(0x9517, RV670_9517, RV670) -CHIPSET(0x9519, RV670_9519, RV670) - -CHIPSET(0x95C0, RV620_95C0, RV620) -CHIPSET(0x95C2, RV620_95C2, RV620) -CHIPSET(0x95C4, RV620_95C4, RV620) -CHIPSET(0x95C5, RV620_95C5, RV620) -CHIPSET(0x95C6, RV620_95C6, RV620) -CHIPSET(0x95C7, RV620_95C7, RV620) -CHIPSET(0x95C9, RV620_95C9, RV620) -CHIPSET(0x95CC, RV620_95CC, RV620) -CHIPSET(0x95CD, RV620_95CD, RV620) -CHIPSET(0x95CE, RV620_95CE, RV620) -CHIPSET(0x95CF, RV620_95CF, RV620) - -CHIPSET(0x9590, RV635_9590, RV635) -CHIPSET(0x9591, RV635_9591, RV635) -CHIPSET(0x9593, RV635_9593, RV635) -CHIPSET(0x9595, RV635_9595, RV635) -CHIPSET(0x9596, RV635_9596, RV635) -CHIPSET(0x9597, RV635_9597, RV635) -CHIPSET(0x9598, RV635_9598, RV635) -CHIPSET(0x9599, RV635_9599, RV635) -CHIPSET(0x959B, RV635_959B, RV635) - -CHIPSET(0x9610, RS780_9610, RS780) -CHIPSET(0x9611, RS780_9611, RS780) -CHIPSET(0x9612, RS780_9612, RS780) -CHIPSET(0x9613, RS780_9613, RS780) -CHIPSET(0x9614, RS780_9614, RS780) -CHIPSET(0x9615, RS780_9615, RS780) -CHIPSET(0x9616, RS780_9616, RS780) - -CHIPSET(0x9710, RS880_9710, RS880) -CHIPSET(0x9711, RS880_9711, RS880) -CHIPSET(0x9712, RS880_9712, RS880) -CHIPSET(0x9713, RS880_9713, RS880) -CHIPSET(0x9714, RS880_9714, RS880) -CHIPSET(0x9715, RS880_9715, RS880) - -CHIPSET(0x9440, RV770_9440, RV770) -CHIPSET(0x9441, RV770_9441, RV770) -CHIPSET(0x9442, RV770_9442, RV770) -CHIPSET(0x9443, RV770_9443, RV770) -CHIPSET(0x9444, RV770_9444, RV770) -CHIPSET(0x9446, RV770_9446, RV770) -CHIPSET(0x944A, RV770_944A, RV770) -CHIPSET(0x944B, RV770_944B, RV770) -CHIPSET(0x944C, RV770_944C, RV770) -CHIPSET(0x944E, RV770_944E, RV770) -CHIPSET(0x9450, RV770_9450, RV770) -CHIPSET(0x9452, RV770_9452, RV770) -CHIPSET(0x9456, RV770_9456, RV770) -CHIPSET(0x945A, RV770_945A, RV770) -CHIPSET(0x945B, RV770_945B, RV770) -CHIPSET(0x945E, RV770_945E, RV770) -CHIPSET(0x9460, RV790_9460, RV770) -CHIPSET(0x9462, RV790_9462, RV770) -CHIPSET(0x946A, RV770_946A, RV770) -CHIPSET(0x946B, RV770_946B, RV770) -CHIPSET(0x947A, RV770_947A, RV770) -CHIPSET(0x947B, RV770_947B, RV770) - -CHIPSET(0x9480, RV730_9480, RV730) -CHIPSET(0x9487, RV730_9487, RV730) -CHIPSET(0x9488, RV730_9488, RV730) -CHIPSET(0x9489, RV730_9489, RV730) -CHIPSET(0x948A, RV730_948A, RV730) -CHIPSET(0x948F, RV730_948F, RV730) -CHIPSET(0x9490, RV730_9490, RV730) -CHIPSET(0x9491, RV730_9491, RV730) -CHIPSET(0x9495, RV730_9495, RV730) -CHIPSET(0x9498, RV730_9498, RV730) -CHIPSET(0x949C, RV730_949C, RV730) -CHIPSET(0x949E, RV730_949E, RV730) -CHIPSET(0x949F, RV730_949F, RV730) - -CHIPSET(0x9540, RV710_9540, RV710) -CHIPSET(0x9541, RV710_9541, RV710) -CHIPSET(0x9542, RV710_9542, RV710) -CHIPSET(0x954E, RV710_954E, RV710) -CHIPSET(0x954F, RV710_954F, RV710) -CHIPSET(0x9552, RV710_9552, RV710) -CHIPSET(0x9553, RV710_9553, RV710) -CHIPSET(0x9555, RV710_9555, RV710) -CHIPSET(0x9557, RV710_9557, RV710) -CHIPSET(0x955F, RV710_955F, RV710) - -CHIPSET(0x94A0, RV740_94A0, RV740) -CHIPSET(0x94A1, RV740_94A1, RV740) -CHIPSET(0x94A3, RV740_94A3, RV740) -CHIPSET(0x94B1, RV740_94B1, RV740) -CHIPSET(0x94B3, RV740_94B3, RV740) -CHIPSET(0x94B4, RV740_94B4, RV740) -CHIPSET(0x94B5, RV740_94B5, RV740) -CHIPSET(0x94B9, RV740_94B9, RV740) - -CHIPSET(0x68E0, CEDAR_68E0, CEDAR) -CHIPSET(0x68E1, CEDAR_68E1, CEDAR) -CHIPSET(0x68E4, CEDAR_68E4, CEDAR) -CHIPSET(0x68E5, CEDAR_68E5, CEDAR) -CHIPSET(0x68E8, CEDAR_68E8, CEDAR) -CHIPSET(0x68E9, CEDAR_68E9, CEDAR) -CHIPSET(0x68F1, CEDAR_68F1, CEDAR) -CHIPSET(0x68F2, CEDAR_68F2, CEDAR) -CHIPSET(0x68F8, CEDAR_68F8, CEDAR) -CHIPSET(0x68F9, CEDAR_68F9, CEDAR) -CHIPSET(0x68FA, CEDAR_68FA, CEDAR) -CHIPSET(0x68FE, CEDAR_68FE, CEDAR) - -CHIPSET(0x68C0, REDWOOD_68C0, REDWOOD) -CHIPSET(0x68C1, REDWOOD_68C1, REDWOOD) -CHIPSET(0x68C7, REDWOOD_68C7, REDWOOD) -CHIPSET(0x68C8, REDWOOD_68C8, REDWOOD) -CHIPSET(0x68C9, REDWOOD_68C9, REDWOOD) -CHIPSET(0x68D8, REDWOOD_68D8, REDWOOD) -CHIPSET(0x68D9, REDWOOD_68D9, REDWOOD) -CHIPSET(0x68DA, REDWOOD_68DA, REDWOOD) -CHIPSET(0x68DE, REDWOOD_68DE, REDWOOD) - -CHIPSET(0x68A0, JUNIPER_68A0, JUNIPER) -CHIPSET(0x68A1, JUNIPER_68A1, JUNIPER) -CHIPSET(0x68A8, JUNIPER_68A8, JUNIPER) -CHIPSET(0x68A9, JUNIPER_68A9, JUNIPER) -CHIPSET(0x68B0, JUNIPER_68B0, JUNIPER) -CHIPSET(0x68B8, JUNIPER_68B8, JUNIPER) -CHIPSET(0x68B9, JUNIPER_68B9, JUNIPER) -CHIPSET(0x68BA, JUNIPER_68BA, JUNIPER) -CHIPSET(0x68BE, JUNIPER_68BE, JUNIPER) -CHIPSET(0x68BF, JUNIPER_68BF, JUNIPER) - -CHIPSET(0x6880, CYPRESS_6880, CYPRESS) -CHIPSET(0x6888, CYPRESS_6888, CYPRESS) -CHIPSET(0x6889, CYPRESS_6889, CYPRESS) -CHIPSET(0x688A, CYPRESS_688A, CYPRESS) -CHIPSET(0x688C, CYPRESS_688C, CYPRESS) -CHIPSET(0x688D, CYPRESS_688D, CYPRESS) -CHIPSET(0x6898, CYPRESS_6898, CYPRESS) -CHIPSET(0x6899, CYPRESS_6899, CYPRESS) -CHIPSET(0x689B, CYPRESS_689B, CYPRESS) -CHIPSET(0x689E, CYPRESS_689E, CYPRESS) - -CHIPSET(0x689C, HEMLOCK_689C, HEMLOCK) -CHIPSET(0x689D, HEMLOCK_689D, HEMLOCK) - -CHIPSET(0x9802, PALM_9802, PALM) -CHIPSET(0x9803, PALM_9803, PALM) -CHIPSET(0x9804, PALM_9804, PALM) -CHIPSET(0x9805, PALM_9805, PALM) -CHIPSET(0x9806, PALM_9806, PALM) -CHIPSET(0x9807, PALM_9807, PALM) -CHIPSET(0x9808, PALM_9808, PALM) -CHIPSET(0x9809, PALM_9809, PALM) -CHIPSET(0x980A, PALM_980A, PALM) - -CHIPSET(0x9640, SUMO_9640, SUMO) -CHIPSET(0x9641, SUMO_9641, SUMO) -CHIPSET(0x9642, SUMO2_9642, SUMO2) -CHIPSET(0x9643, SUMO2_9643, SUMO2) -CHIPSET(0x9644, SUMO2_9644, SUMO2) -CHIPSET(0x9645, SUMO2_9645, SUMO2) -CHIPSET(0x9647, SUMO_9647, SUMO) -CHIPSET(0x9648, SUMO_9648, SUMO) -CHIPSET(0x9649, SUMO2_9649, SUMO2) -CHIPSET(0x964a, SUMO_964A, SUMO) -CHIPSET(0x964b, SUMO_964B, SUMO) -CHIPSET(0x964c, SUMO_964C, SUMO) -CHIPSET(0x964e, SUMO_964E, SUMO) -CHIPSET(0x964f, SUMO_964F, SUMO) - -CHIPSET(0x6700, CAYMAN_6700, CAYMAN) -CHIPSET(0x6701, CAYMAN_6701, CAYMAN) -CHIPSET(0x6702, CAYMAN_6702, CAYMAN) -CHIPSET(0x6703, CAYMAN_6703, CAYMAN) -CHIPSET(0x6704, CAYMAN_6704, CAYMAN) -CHIPSET(0x6705, CAYMAN_6705, CAYMAN) -CHIPSET(0x6706, CAYMAN_6706, CAYMAN) -CHIPSET(0x6707, CAYMAN_6707, CAYMAN) -CHIPSET(0x6708, CAYMAN_6708, CAYMAN) -CHIPSET(0x6709, CAYMAN_6709, CAYMAN) -CHIPSET(0x6718, CAYMAN_6718, CAYMAN) -CHIPSET(0x6719, CAYMAN_6719, CAYMAN) -CHIPSET(0x671C, CAYMAN_671C, CAYMAN) -CHIPSET(0x671D, CAYMAN_671D, CAYMAN) -CHIPSET(0x671F, CAYMAN_671F, CAYMAN) - -CHIPSET(0x6720, BARTS_6720, BARTS) -CHIPSET(0x6721, BARTS_6721, BARTS) -CHIPSET(0x6722, BARTS_6722, BARTS) -CHIPSET(0x6723, BARTS_6723, BARTS) -CHIPSET(0x6724, BARTS_6724, BARTS) -CHIPSET(0x6725, BARTS_6725, BARTS) -CHIPSET(0x6726, BARTS_6726, BARTS) -CHIPSET(0x6727, BARTS_6727, BARTS) -CHIPSET(0x6728, BARTS_6728, BARTS) -CHIPSET(0x6729, BARTS_6729, BARTS) -CHIPSET(0x6738, BARTS_6738, BARTS) -CHIPSET(0x6739, BARTS_6739, BARTS) -CHIPSET(0x673E, BARTS_673E, BARTS) - -CHIPSET(0x6740, TURKS_6740, TURKS) -CHIPSET(0x6741, TURKS_6741, TURKS) -CHIPSET(0x6742, TURKS_6742, TURKS) -CHIPSET(0x6743, TURKS_6743, TURKS) -CHIPSET(0x6744, TURKS_6744, TURKS) -CHIPSET(0x6745, TURKS_6745, TURKS) -CHIPSET(0x6746, TURKS_6746, TURKS) -CHIPSET(0x6747, TURKS_6747, TURKS) -CHIPSET(0x6748, TURKS_6748, TURKS) -CHIPSET(0x6749, TURKS_6749, TURKS) -CHIPSET(0x674A, TURKS_674A, TURKS) -CHIPSET(0x6750, TURKS_6750, TURKS) -CHIPSET(0x6751, TURKS_6751, TURKS) -CHIPSET(0x6758, TURKS_6758, TURKS) -CHIPSET(0x6759, TURKS_6759, TURKS) -CHIPSET(0x675B, TURKS_675B, TURKS) -CHIPSET(0x675D, TURKS_675D, TURKS) -CHIPSET(0x675F, TURKS_675F, TURKS) -CHIPSET(0x6840, TURKS_6840, TURKS) -CHIPSET(0x6841, TURKS_6841, TURKS) -CHIPSET(0x6842, TURKS_6842, TURKS) -CHIPSET(0x6843, TURKS_6843, TURKS) -CHIPSET(0x6849, TURKS_6849, TURKS) -CHIPSET(0x6850, TURKS_6850, TURKS) -CHIPSET(0x6858, TURKS_6858, TURKS) -CHIPSET(0x6859, TURKS_6859, TURKS) - -CHIPSET(0x6760, CAICOS_6760, CAICOS) -CHIPSET(0x6761, CAICOS_6761, CAICOS) -CHIPSET(0x6762, CAICOS_6762, CAICOS) -CHIPSET(0x6763, CAICOS_6763, CAICOS) -CHIPSET(0x6764, CAICOS_6764, CAICOS) -CHIPSET(0x6765, CAICOS_6765, CAICOS) -CHIPSET(0x6766, CAICOS_6766, CAICOS) -CHIPSET(0x6767, CAICOS_6767, CAICOS) -CHIPSET(0x6768, CAICOS_6768, CAICOS) -CHIPSET(0x6770, CAICOS_6770, CAICOS) -CHIPSET(0x6771, CAICOS_6771, CAICOS) -CHIPSET(0x6772, CAICOS_6772, CAICOS) -CHIPSET(0x6778, CAICOS_6778, CAICOS) -CHIPSET(0x6779, CAICOS_6779, CAICOS) -CHIPSET(0x677B, CAICOS_677B, CAICOS) - -CHIPSET(0x9900, ARUBA_9900, ARUBA) -CHIPSET(0x9901, ARUBA_9901, ARUBA) -CHIPSET(0x9903, ARUBA_9903, ARUBA) -CHIPSET(0x9904, ARUBA_9904, ARUBA) -CHIPSET(0x9905, ARUBA_9905, ARUBA) -CHIPSET(0x9906, ARUBA_9906, ARUBA) -CHIPSET(0x9907, ARUBA_9907, ARUBA) -CHIPSET(0x9908, ARUBA_9908, ARUBA) -CHIPSET(0x9909, ARUBA_9909, ARUBA) -CHIPSET(0x990A, ARUBA_990A, ARUBA) -CHIPSET(0x990B, ARUBA_990B, ARUBA) -CHIPSET(0x990C, ARUBA_990C, ARUBA) -CHIPSET(0x990D, ARUBA_990D, ARUBA) -CHIPSET(0x990E, ARUBA_990E, ARUBA) -CHIPSET(0x990F, ARUBA_990F, ARUBA) -CHIPSET(0x9910, ARUBA_9910, ARUBA) -CHIPSET(0x9913, ARUBA_9913, ARUBA) -CHIPSET(0x9917, ARUBA_9917, ARUBA) -CHIPSET(0x9918, ARUBA_9918, ARUBA) -CHIPSET(0x9919, ARUBA_9919, ARUBA) -CHIPSET(0x9990, ARUBA_9990, ARUBA) -CHIPSET(0x9991, ARUBA_9991, ARUBA) -CHIPSET(0x9992, ARUBA_9992, ARUBA) -CHIPSET(0x9993, ARUBA_9993, ARUBA) -CHIPSET(0x9994, ARUBA_9994, ARUBA) -CHIPSET(0x9995, ARUBA_9995, ARUBA) -CHIPSET(0x9996, ARUBA_9996, ARUBA) -CHIPSET(0x9997, ARUBA_9997, ARUBA) -CHIPSET(0x9998, ARUBA_9998, ARUBA) -CHIPSET(0x9999, ARUBA_9999, ARUBA) -CHIPSET(0x999A, ARUBA_999A, ARUBA) -CHIPSET(0x999B, ARUBA_999B, ARUBA) -CHIPSET(0x999C, ARUBA_999C, ARUBA) -CHIPSET(0x999D, ARUBA_999D, ARUBA) -CHIPSET(0x99A0, ARUBA_99A0, ARUBA) -CHIPSET(0x99A2, ARUBA_99A2, ARUBA) -CHIPSET(0x99A4, ARUBA_99A4, ARUBA) diff --git a/hw/xfree86/dri2/pci_ids/radeon_pci_ids.h b/hw/xfree86/dri2/pci_ids/radeon_pci_ids.h deleted file mode 100644 index a9efc767d..000000000 --- a/hw/xfree86/dri2/pci_ids/radeon_pci_ids.h +++ /dev/null @@ -1,23 +0,0 @@ -CHIPSET(0x4C57, RADEON_LW, RV200) -CHIPSET(0x4C58, RADEON_LX, RV200) -CHIPSET(0x4C59, RADEON_LY, RV100) -CHIPSET(0x4C5A, RADEON_LZ, RV100) -CHIPSET(0x5144, RADEON_QD, R100) -CHIPSET(0x5145, RADEON_QE, R100) -CHIPSET(0x5146, RADEON_QF, R100) -CHIPSET(0x5147, RADEON_QG, R100) -CHIPSET(0x5159, RADEON_QY, RV100) -CHIPSET(0x515A, RADEON_QZ, RV100) - -CHIPSET(0x5157, RV200_QW, RV200) -CHIPSET(0x5158, RV200_QX, RV200) - -CHIPSET(0x515E, RN50_515E, UNKNOWN) -CHIPSET(0x5969, RN50_5969, UNKNOWN) - -CHIPSET(0x4136, RS100_4136, RS100) -CHIPSET(0x4336, RS100_4336, RS100) -CHIPSET(0x4137, RS200_4137, RS200) -CHIPSET(0x4337, RS200_4337, RS200) -CHIPSET(0x4237, RS250_4237, RS200) -CHIPSET(0x4437, RS250_4437, RS200) diff --git a/hw/xfree86/dri2/pci_ids/radeonsi_pci_ids.h b/hw/xfree86/dri2/pci_ids/radeonsi_pci_ids.h deleted file mode 100644 index 2ec8a1e24..000000000 --- a/hw/xfree86/dri2/pci_ids/radeonsi_pci_ids.h +++ /dev/null @@ -1,237 +0,0 @@ -CHIPSET(0x6780, TAHITI_6780, TAHITI) -CHIPSET(0x6784, TAHITI_6784, TAHITI) -CHIPSET(0x6788, TAHITI_6788, TAHITI) -CHIPSET(0x678A, TAHITI_678A, TAHITI) -CHIPSET(0x6790, TAHITI_6790, TAHITI) -CHIPSET(0x6791, TAHITI_6791, TAHITI) -CHIPSET(0x6792, TAHITI_6792, TAHITI) -CHIPSET(0x6798, TAHITI_6798, TAHITI) -CHIPSET(0x6799, TAHITI_6799, TAHITI) -CHIPSET(0x679A, TAHITI_679A, TAHITI) -CHIPSET(0x679B, TAHITI_679B, TAHITI) -CHIPSET(0x679E, TAHITI_679E, TAHITI) -CHIPSET(0x679F, TAHITI_679F, TAHITI) - -CHIPSET(0x6800, PITCAIRN_6800, PITCAIRN) -CHIPSET(0x6801, PITCAIRN_6801, PITCAIRN) -CHIPSET(0x6802, PITCAIRN_6802, PITCAIRN) -CHIPSET(0x6806, PITCAIRN_6806, PITCAIRN) -CHIPSET(0x6808, PITCAIRN_6808, PITCAIRN) -CHIPSET(0x6809, PITCAIRN_6809, PITCAIRN) -CHIPSET(0x6810, PITCAIRN_6810, PITCAIRN) -CHIPSET(0x6811, PITCAIRN_6811, PITCAIRN) -CHIPSET(0x6816, PITCAIRN_6816, PITCAIRN) -CHIPSET(0x6817, PITCAIRN_6817, PITCAIRN) -CHIPSET(0x6818, PITCAIRN_6818, PITCAIRN) -CHIPSET(0x6819, PITCAIRN_6819, PITCAIRN) -CHIPSET(0x684C, PITCAIRN_684C, PITCAIRN) - -CHIPSET(0x6820, VERDE_6820, VERDE) -CHIPSET(0x6821, VERDE_6821, VERDE) -CHIPSET(0x6822, VERDE_6822, VERDE) -CHIPSET(0x6823, VERDE_6823, VERDE) -CHIPSET(0x6824, VERDE_6824, VERDE) -CHIPSET(0x6825, VERDE_6825, VERDE) -CHIPSET(0x6826, VERDE_6826, VERDE) -CHIPSET(0x6827, VERDE_6827, VERDE) -CHIPSET(0x6828, VERDE_6828, VERDE) -CHIPSET(0x6829, VERDE_6829, VERDE) -CHIPSET(0x682A, VERDE_682A, VERDE) -CHIPSET(0x682B, VERDE_682B, VERDE) -CHIPSET(0x682C, VERDE_682C, VERDE) -CHIPSET(0x682D, VERDE_682D, VERDE) -CHIPSET(0x682F, VERDE_682F, VERDE) -CHIPSET(0x6830, VERDE_6830, VERDE) -CHIPSET(0x6831, VERDE_6831, VERDE) -CHIPSET(0x6835, VERDE_6835, VERDE) -CHIPSET(0x6837, VERDE_6837, VERDE) -CHIPSET(0x6838, VERDE_6838, VERDE) -CHIPSET(0x6839, VERDE_6839, VERDE) -CHIPSET(0x683B, VERDE_683B, VERDE) -CHIPSET(0x683D, VERDE_683D, VERDE) -CHIPSET(0x683F, VERDE_683F, VERDE) - -CHIPSET(0x6600, OLAND_6600, OLAND) -CHIPSET(0x6601, OLAND_6601, OLAND) -CHIPSET(0x6602, OLAND_6602, OLAND) -CHIPSET(0x6603, OLAND_6603, OLAND) -CHIPSET(0x6604, OLAND_6604, OLAND) -CHIPSET(0x6605, OLAND_6605, OLAND) -CHIPSET(0x6606, OLAND_6606, OLAND) -CHIPSET(0x6607, OLAND_6607, OLAND) -CHIPSET(0x6608, OLAND_6608, OLAND) -CHIPSET(0x6610, OLAND_6610, OLAND) -CHIPSET(0x6611, OLAND_6611, OLAND) -CHIPSET(0x6613, OLAND_6613, OLAND) -CHIPSET(0x6617, OLAND_6617, OLAND) -CHIPSET(0x6620, OLAND_6620, OLAND) -CHIPSET(0x6621, OLAND_6621, OLAND) -CHIPSET(0x6623, OLAND_6623, OLAND) -CHIPSET(0x6631, OLAND_6631, OLAND) - -CHIPSET(0x6660, HAINAN_6660, HAINAN) -CHIPSET(0x6663, HAINAN_6663, HAINAN) -CHIPSET(0x6664, HAINAN_6664, HAINAN) -CHIPSET(0x6665, HAINAN_6665, HAINAN) -CHIPSET(0x6667, HAINAN_6667, HAINAN) -CHIPSET(0x666F, HAINAN_666F, HAINAN) - -CHIPSET(0x6640, BONAIRE_6640, BONAIRE) -CHIPSET(0x6641, BONAIRE_6641, BONAIRE) -CHIPSET(0x6646, BONAIRE_6646, BONAIRE) -CHIPSET(0x6647, BONAIRE_6647, BONAIRE) -CHIPSET(0x6649, BONAIRE_6649, BONAIRE) -CHIPSET(0x6650, BONAIRE_6650, BONAIRE) -CHIPSET(0x6651, BONAIRE_6651, BONAIRE) -CHIPSET(0x6658, BONAIRE_6658, BONAIRE) -CHIPSET(0x665C, BONAIRE_665C, BONAIRE) -CHIPSET(0x665D, BONAIRE_665D, BONAIRE) -CHIPSET(0x665F, BONAIRE_665F, BONAIRE) - -CHIPSET(0x9830, KABINI_9830, KABINI) -CHIPSET(0x9831, KABINI_9831, KABINI) -CHIPSET(0x9832, KABINI_9832, KABINI) -CHIPSET(0x9833, KABINI_9833, KABINI) -CHIPSET(0x9834, KABINI_9834, KABINI) -CHIPSET(0x9835, KABINI_9835, KABINI) -CHIPSET(0x9836, KABINI_9836, KABINI) -CHIPSET(0x9837, KABINI_9837, KABINI) -CHIPSET(0x9838, KABINI_9838, KABINI) -CHIPSET(0x9839, KABINI_9839, KABINI) -CHIPSET(0x983A, KABINI_983A, KABINI) -CHIPSET(0x983B, KABINI_983B, KABINI) -CHIPSET(0x983C, KABINI_983C, KABINI) -CHIPSET(0x983D, KABINI_983D, KABINI) -CHIPSET(0x983E, KABINI_983E, KABINI) -CHIPSET(0x983F, KABINI_983F, KABINI) - -CHIPSET(0x9850, MULLINS_9850, MULLINS) -CHIPSET(0x9851, MULLINS_9851, MULLINS) -CHIPSET(0x9852, MULLINS_9852, MULLINS) -CHIPSET(0x9853, MULLINS_9853, MULLINS) -CHIPSET(0x9854, MULLINS_9854, MULLINS) -CHIPSET(0x9855, MULLINS_9855, MULLINS) -CHIPSET(0x9856, MULLINS_9856, MULLINS) -CHIPSET(0x9857, MULLINS_9857, MULLINS) -CHIPSET(0x9858, MULLINS_9858, MULLINS) -CHIPSET(0x9859, MULLINS_9859, MULLINS) -CHIPSET(0x985A, MULLINS_985A, MULLINS) -CHIPSET(0x985B, MULLINS_985B, MULLINS) -CHIPSET(0x985C, MULLINS_985C, MULLINS) -CHIPSET(0x985D, MULLINS_985D, MULLINS) -CHIPSET(0x985E, MULLINS_985E, MULLINS) -CHIPSET(0x985F, MULLINS_985F, MULLINS) - -CHIPSET(0x1304, KAVERI_1304, KAVERI) -CHIPSET(0x1305, KAVERI_1305, KAVERI) -CHIPSET(0x1306, KAVERI_1306, KAVERI) -CHIPSET(0x1307, KAVERI_1307, KAVERI) -CHIPSET(0x1309, KAVERI_1309, KAVERI) -CHIPSET(0x130A, KAVERI_130A, KAVERI) -CHIPSET(0x130B, KAVERI_130B, KAVERI) -CHIPSET(0x130C, KAVERI_130C, KAVERI) -CHIPSET(0x130D, KAVERI_130D, KAVERI) -CHIPSET(0x130E, KAVERI_130E, KAVERI) -CHIPSET(0x130F, KAVERI_130F, KAVERI) -CHIPSET(0x1310, KAVERI_1310, KAVERI) -CHIPSET(0x1311, KAVERI_1311, KAVERI) -CHIPSET(0x1312, KAVERI_1312, KAVERI) -CHIPSET(0x1313, KAVERI_1313, KAVERI) -CHIPSET(0x1315, KAVERI_1315, KAVERI) -CHIPSET(0x1316, KAVERI_1316, KAVERI) -CHIPSET(0x1317, KAVERI_1317, KAVERI) -CHIPSET(0x1318, KAVERI_1318, KAVERI) -CHIPSET(0x131B, KAVERI_131B, KAVERI) -CHIPSET(0x131C, KAVERI_131C, KAVERI) -CHIPSET(0x131D, KAVERI_131D, KAVERI) - -CHIPSET(0x67A0, HAWAII_67A0, HAWAII) -CHIPSET(0x67A1, HAWAII_67A1, HAWAII) -CHIPSET(0x67A2, HAWAII_67A2, HAWAII) -CHIPSET(0x67A8, HAWAII_67A8, HAWAII) -CHIPSET(0x67A9, HAWAII_67A9, HAWAII) -CHIPSET(0x67AA, HAWAII_67AA, HAWAII) -CHIPSET(0x67B0, HAWAII_67B0, HAWAII) -CHIPSET(0x67B1, HAWAII_67B1, HAWAII) -CHIPSET(0x67B8, HAWAII_67B8, HAWAII) -CHIPSET(0x67B9, HAWAII_67B9, HAWAII) -CHIPSET(0x67BA, HAWAII_67BA, HAWAII) -CHIPSET(0x67BE, HAWAII_67BE, HAWAII) - -CHIPSET(0x6900, ICELAND_, ICELAND) -CHIPSET(0x6901, ICELAND_, ICELAND) -CHIPSET(0x6902, ICELAND_, ICELAND) -CHIPSET(0x6903, ICELAND_, ICELAND) -CHIPSET(0x6907, ICELAND_, ICELAND) - -CHIPSET(0x6920, TONGA_, TONGA) -CHIPSET(0x6921, TONGA_, TONGA) -CHIPSET(0x6928, TONGA_, TONGA) -CHIPSET(0x6929, TONGA_, TONGA) -CHIPSET(0x692B, TONGA_, TONGA) -CHIPSET(0x692F, TONGA_, TONGA) -CHIPSET(0x6930, TONGA_, TONGA) -CHIPSET(0x6938, TONGA_, TONGA) -CHIPSET(0x6939, TONGA_, TONGA) - -CHIPSET(0x9870, CARRIZO_, CARRIZO) -CHIPSET(0x9874, CARRIZO_, CARRIZO) -CHIPSET(0x9875, CARRIZO_, CARRIZO) -CHIPSET(0x9876, CARRIZO_, CARRIZO) -CHIPSET(0x9877, CARRIZO_, CARRIZO) - -CHIPSET(0x7300, FIJI_, FIJI) - -CHIPSET(0x67E0, POLARIS11_, POLARIS11) -CHIPSET(0x67E1, POLARIS11_, POLARIS11) -CHIPSET(0x67E3, POLARIS11_, POLARIS11) -CHIPSET(0x67E7, POLARIS11_, POLARIS11) -CHIPSET(0x67E8, POLARIS11_, POLARIS11) -CHIPSET(0x67E9, POLARIS11_, POLARIS11) -CHIPSET(0x67EB, POLARIS11_, POLARIS11) -CHIPSET(0x67EF, POLARIS11_, POLARIS11) -CHIPSET(0x67FF, POLARIS11_, POLARIS11) - -CHIPSET(0x67C0, POLARIS10_, POLARIS10) -CHIPSET(0x67C1, POLARIS10_, POLARIS10) -CHIPSET(0x67C2, POLARIS10_, POLARIS10) -CHIPSET(0x67C4, POLARIS10_, POLARIS10) -CHIPSET(0x67C7, POLARIS10_, POLARIS10) -CHIPSET(0x67C8, POLARIS10_, POLARIS10) -CHIPSET(0x67C9, POLARIS10_, POLARIS10) -CHIPSET(0x67CA, POLARIS10_, POLARIS10) -CHIPSET(0x67CC, POLARIS10_, POLARIS10) -CHIPSET(0x67CF, POLARIS10_, POLARIS10) -CHIPSET(0x67DF, POLARIS10_, POLARIS10) - -CHIPSET(0x98E4, STONEY_, STONEY) - -CHIPSET(0x6980, POLARIS12_, POLARIS12) -CHIPSET(0x6981, POLARIS12_, POLARIS12) -CHIPSET(0x6985, POLARIS12_, POLARIS12) -CHIPSET(0x6986, POLARIS12_, POLARIS12) -CHIPSET(0x6987, POLARIS12_, POLARIS12) -CHIPSET(0x6995, POLARIS12_, POLARIS12) -CHIPSET(0x6997, POLARIS12_, POLARIS12) -CHIPSET(0x699F, POLARIS12_, POLARIS12) - -CHIPSET(0x694C, VEGAM_, VEGAM) -CHIPSET(0x694E, VEGAM_, VEGAM) - -CHIPSET(0x6860, VEGA10_, VEGA10) -CHIPSET(0x6861, VEGA10_, VEGA10) -CHIPSET(0x6862, VEGA10_, VEGA10) -CHIPSET(0x6863, VEGA10_, VEGA10) -CHIPSET(0x6864, VEGA10_, VEGA10) -CHIPSET(0x6867, VEGA10_, VEGA10) -CHIPSET(0x6868, VEGA10_, VEGA10) -CHIPSET(0x687F, VEGA10_, VEGA10) -CHIPSET(0x686C, VEGA10_, VEGA10) - -CHIPSET(0x69A0, VEGA12_, VEGA12) -CHIPSET(0x69A1, VEGA12_, VEGA12) -CHIPSET(0x69A2, VEGA12_, VEGA12) -CHIPSET(0x69A3, VEGA12_, VEGA12) -CHIPSET(0x69AF, VEGA12_, VEGA12) - -CHIPSET(0x15DD, RAVEN_, RAVEN) diff --git a/hw/xfree86/dri2/pci_ids/virtio_gpu_pci_ids.h b/hw/xfree86/dri2/pci_ids/virtio_gpu_pci_ids.h deleted file mode 100644 index 9232cd288..000000000 --- a/hw/xfree86/dri2/pci_ids/virtio_gpu_pci_ids.h +++ /dev/null @@ -1,2 +0,0 @@ -CHIPSET(0x0010, VIRTGL, VIRTGL) -CHIPSET(0x1050, VIRTGL, VIRTGL) diff --git a/hw/xfree86/dri2/pci_ids/vmwgfx_pci_ids.h b/hw/xfree86/dri2/pci_ids/vmwgfx_pci_ids.h deleted file mode 100644 index 124d75b72..000000000 --- a/hw/xfree86/dri2/pci_ids/vmwgfx_pci_ids.h +++ /dev/null @@ -1 +0,0 @@ -CHIPSET(0x0405, SVGAII, SVGAII) diff --git a/hw/xfree86/drivers/inputtest/inputtestdrv.man b/hw/xfree86/drivers/inputtest/inputtestdrv.man deleted file mode 100644 index b0aa76dd3..000000000 --- a/hw/xfree86/drivers/inputtest/inputtestdrv.man +++ /dev/null @@ -1,112 +0,0 @@ -.\" shorthand for double quote that works everywhere. -.ds q \N'34' -.TH INPUTTEST @drivermansuffix@ @vendorversion@ -.SH NAME -inputtest \- An X.Org input driver for testing -.SH SYNOPSIS -.nf -.B "Section \*qInputDevice\*q" -.BI " Identifier \*q" devname \*q -.B " Driver \*qinputtest\*q" -.BI " Option \*qSocketPath\*q \*q" path \*q -\ \ ... -.B EndSection -.fi - -.SH DESCRIPTION -.B inputtest -is an Xorg input driver that passes events received over a socket on to the -server as input events. It supports the full set of the xf86 driver APIs -exposed by Xorg. The primary use cases of this input driver are various -integration tests that need to interface with the input subsystem. - -.SH CONFIGURATION DETAILS -Please refer to @xconfigfile@(@filemansuffix@) for general configuration -details and for options that can be used with all input drivers. This -section only covers configuration details specific to this driver. -.PP -External process can communicate with the input driver via a named socket that -is created after the driver is initialized. The paths to the socket is passed -via input driver options. -.PP -The following driver -.B Options -are supported: -.TP 7 -.BI "Option \*qSocketPath\*q \*q" string \*q -Sets the path where the driver will create a named socket. Any existing file -at that location will be removed. -.TP 7 -.BI "Option \*qDeviceType\*q \*q" string \*q -Sets the type of the device to be emulated. -.IP -.BI Keyboard -Initializes a keyboard device. -.IP -.BI Pointer -Initializes a relative-mode pointer device. It will have four valuators - -a "Rel X" valuator at axis 0 and a "Rel Y" valuator at axis 1. -A horizontal scroll valuator will be set up at axis 2. -A vertical scroll valuator will be set up at axis 3. -.IP -.BI PointerAbsolute -Initializes an absolute-mode pointer device. It will have four valuators - -an "Abs X" valuator at axis 0 and an "Abs Y" valuator at axis 1. -A horizontal scroll valuator will be set up at axis 2. -A vertical scroll valuator will be set up at axis 3. -.IP -.BI PointerAbsoluteProximity -Initializes an absolute-mode pointer device with proximity support. -The valuators are initialized in the same way as for \fBPointerAbsolute\fR type. -.IP -.BI Touch -Initializes a touch device. -It will have 5 valuators: an "Abs MT Position X" at axis 0, -an "Abs MT Position Y" valuator at axis 1, -a horizontal scroll valuator on axis 2, -a vertical scroll valuator on axis 3 and an "Abs MT Pressure" valuator -at axis 4. -.TP 7 -.BI "Option \*qTouchCount\*q \*q" int \*q -Sets the maximum number of simultaneous touches for touch devices. -.TP 7 -.BI "Option \*qPointerButtonCount\*q \*q" int \*q -Sets the maximum number of buttons in pointer devices. -.TP 7 -.BI "Option \*qPointerHasPressure\*q \*q" bool \*q -Selects whether "Abs Pressure" is available at the axis 4 in pointer devices. - -.SH INTERFACE WITH THE DRIVER -The communication with the driver is a binary protocol defined in -include/xf86-input-inputtest-protocol.h -.PP -At the beginning, the client process that communicates with the driver must -connect to the socket that is created by the driver at SocketPath. -Once the connection is established, it must write a xf86ITEventClientVersion -event and read a xf86ITResponseServerVersion response where the driver -specifies the protocol version supported by it. If this version is lower than -requested by the client, then the driver will disconnect. -.PP -After receiving xf86ITResponseServerVersion message the client may send events -to the driver. Each event is an instance of one of the -.BI xf86ITEvent* -structs. The length field defines the full length of the struct in bytes and -the event field defines the type of the struct. -.PP -The responses from the server follow the same structure. Each response is an -instance of one of the -.BI xf86ITResponse* -structs. The length field defines the full length of the struct in bytes and -the event field defines the type of the struct. -.PP -The synchronization with Xorg is performed via -.BI xf86ITEventWaitForSync -event. After sending such event, the client must read of a -.BI xf86ITResponseSyncFinished event from the socket without sending additional -events. The completion of the read operation indicates that Xorg has fully -processed all input events sent to it so far. - -.SH AUTHORS -Povilas Kanapickas -.SH "SEE ALSO" -@xservername@(@appmansuffix@), @xconfigfile@(@filemansuffix@), Xserver(@appmansuffix@), X(@miscmansuffix@) diff --git a/hw/xfree86/drivers/inputtest/meson.build b/hw/xfree86/drivers/inputtest/meson.build deleted file mode 100644 index fa642c89f..000000000 --- a/hw/xfree86/drivers/inputtest/meson.build +++ /dev/null @@ -1,26 +0,0 @@ -inputtestdrv_srcs = [ - 'xf86-input-inputtest.c', -] - -shared_module( - 'inputtest_drv', - inputtestdrv_srcs, - name_prefix: '', - - include_directories: [inc, xorg_inc], - c_args: xorg_c_args, - dependencies: [common_dep], - - install: true, - install_dir: join_paths(module_dir, 'input'), - - link_with: e, -) - -install_man(configure_file( - input: 'inputtestdrv.man', - output: 'inputtestdrv.4', - configuration: manpage_config, -)) - -install_data('xf86-input-inputtest-protocol.h', install_dir: xorgsdkdir) diff --git a/hw/xfree86/drivers/inputtest/xf86-input-inputtest-protocol.h b/hw/xfree86/drivers/inputtest/xf86-input-inputtest-protocol.h deleted file mode 100644 index 46837f3ba..000000000 --- a/hw/xfree86/drivers/inputtest/xf86-input-inputtest-protocol.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright © 2020 Povilas Kanapickas - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of Red Hat - * not be used in advertising or publicity pertaining to distribution - * of the software without specific, written prior permission. Red - * Hat makes no representations about the suitability of this software - * for any purpose. It is provided "as is" without express or implied - * warranty. - * - * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN - * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef XF86_INPUT_INPUTTEST_PROTOCOL_H_ -#define XF86_INPUT_INPUTTEST_PROTOCOL_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define XF86IT_PROTOCOL_VERSION_MAJOR 1 -#define XF86IT_PROTOCOL_VERSION_MINOR 1 - -enum xf86ITResponseType { - XF86IT_RESPONSE_SERVER_VERSION, - XF86IT_RESPONSE_SYNC_FINISHED, -}; - -typedef struct { - uint32_t length; /* length of the whole event in bytes, including the header */ - enum xf86ITResponseType type; -} xf86ITResponseHeader; - -typedef struct { - xf86ITResponseHeader header; - uint16_t major; - uint16_t minor; -} xf86ITResponseServerVersion; - -typedef struct { - xf86ITResponseHeader header; -} xf86ITResponseSyncFinished; - -typedef union { - xf86ITResponseHeader header; - xf86ITResponseServerVersion version; -} xf86ITResponseAny; - -/* We care more about preserving the binary input driver protocol more than the - size of the messages, so hardcode a larger valuator count than the server has */ -#define XF86IT_MAX_VALUATORS 64 - -enum xf86ITEventType { - XF86IT_EVENT_CLIENT_VERSION, - XF86IT_EVENT_WAIT_FOR_SYNC, - XF86IT_EVENT_MOTION, - XF86IT_EVENT_PROXIMITY, - XF86IT_EVENT_BUTTON, - XF86IT_EVENT_KEY, - XF86IT_EVENT_TOUCH, - XF86IT_EVENT_GESTURE_PINCH, - XF86IT_EVENT_GESTURE_SWIPE, -}; - -typedef struct { - uint32_t length; /* length of the whole event in bytes, including the header */ - enum xf86ITEventType type; -} xf86ITEventHeader; - -typedef struct { - uint32_t has_unaccelerated; - uint8_t mask[(XF86IT_MAX_VALUATORS + 7) / 8]; - double valuators[XF86IT_MAX_VALUATORS]; - double unaccelerated[XF86IT_MAX_VALUATORS]; -} xf86ITValuatorData; - -typedef struct { - xf86ITEventHeader header; - uint16_t major; - uint16_t minor; -} xf86ITEventClientVersion; - -typedef struct { - xf86ITEventHeader header; -} xf86ITEventWaitForSync; - -typedef struct { - xf86ITEventHeader header; - uint32_t is_absolute; - xf86ITValuatorData valuators; -} xf86ITEventMotion; - -typedef struct { - xf86ITEventHeader header; - uint32_t is_prox_in; - xf86ITValuatorData valuators; -} xf86ITEventProximity; - -typedef struct { - xf86ITEventHeader header; - int32_t is_absolute; - int32_t button; - uint32_t is_press; - xf86ITValuatorData valuators; -} xf86ITEventButton; - -typedef struct { - xf86ITEventHeader header; - int32_t key_code; - uint32_t is_press; -} xf86ITEventKey; - -typedef struct { - xf86ITEventHeader header; - uint32_t touchid; - uint32_t touch_type; - xf86ITValuatorData valuators; -} xf86ITEventTouch; - -typedef struct { - xf86ITEventHeader header; - uint16_t gesture_type; - uint16_t num_touches; - uint32_t flags; - double delta_x; - double delta_y; - double delta_unaccel_x; - double delta_unaccel_y; - double scale; - double delta_angle; -} xf86ITEventGesturePinch; - -typedef struct { - xf86ITEventHeader header; - uint16_t gesture_type; - uint16_t num_touches; - uint32_t flags; - double delta_x; - double delta_y; - double delta_unaccel_x; - double delta_unaccel_y; -} xf86ITEventGestureSwipe; - -typedef union { - xf86ITEventHeader header; - xf86ITEventClientVersion version; - xf86ITEventMotion motion; - xf86ITEventProximity proximity; - xf86ITEventButton button; - xf86ITEventKey key; - xf86ITEventTouch touch; - xf86ITEventGesturePinch pinch; - xf86ITEventGestureSwipe swipe; -} xf86ITEventAny; - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* XF86_INPUT_INPUTTEST_PROTOCOL_H_ */ diff --git a/hw/xfree86/drivers/inputtest/xf86-input-inputtest.c b/hw/xfree86/drivers/inputtest/xf86-input-inputtest.c deleted file mode 100644 index 70f8fe964..000000000 --- a/hw/xfree86/drivers/inputtest/xf86-input-inputtest.c +++ /dev/null @@ -1,1114 +0,0 @@ -/* - * Copyright © 2013-2017 Red Hat, Inc. - * Copyright © 2020 Povilas Kanapickas - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of Red Hat - * not be used in advertising or publicity pertaining to distribution - * of the software without specific, written prior permission. Red - * Hat makes no representations about the suitability of this software - * for any purpose. It is provided "as is" without express or implied - * warranty. - * - * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN - * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include "xorgVersion.h" -#include -#include -#include - -#include -#include -#include -#include - -#include "xf86-input-inputtest-protocol.h" - -#define MAX_POINTER_NUM_AXES 5 /* x, y, hscroll, vscroll, [pressure] */ -#define MAX_TOUCH_NUM_AXES 5 /* x, y, hscroll, vscroll, pressure */ -#define TOUCH_MAX_SLOTS 15 - -#define TOUCH_AXIS_MAX 0xffff -#define TABLET_PRESSURE_AXIS_MAX 2047 - -#define EVENT_BUFFER_SIZE 4096 - -enum xf86ITDeviceType { - DEVICE_KEYBOARD = 1, - DEVICE_POINTER, - DEVICE_POINTER_GESTURE, - DEVICE_POINTER_ABS, - DEVICE_POINTER_ABS_PROXIMITY, - DEVICE_TOUCH, -}; - -enum xf86ITClientState { - CLIENT_STATE_NOT_CONNECTED = 0, - - /* connection_fd is valid */ - CLIENT_STATE_NEW, - - /* connection_fd is valid and client_protocol.{major,minor} are set */ - CLIENT_STATE_READY, -}; - -typedef struct { - InputInfoPtr pInfo; - - int socket_fd; /* for accepting new clients */ - int connection_fd; /* current client connection */ - - char *socket_path; - - enum xf86ITClientState client_state; - struct { - int major, minor; - } client_protocol; - - struct { - char data[EVENT_BUFFER_SIZE]; - int valid_length; - } buffer; - - uint32_t device_type; - - /* last_processed_event_num == last_event_num and waiting_for_drain != 0 must never be true - both at the same time. This would mean that we are waiting for the input queue to be - processed, yet all events have already been processed, i.e. a deadlock. - - waiting_for_drain_mutex protects concurrent access to waiting_for_drain variable which - may be modified from multiple threads. - */ - pthread_mutex_t waiting_for_drain_mutex; - bool waiting_for_drain; - int last_processed_event_num; - int last_event_num; - - ValuatorMask *valuators; - ValuatorMask *valuators_unaccelerated; -} xf86ITDevice, *xf86ITDevicePtr; - -static void -read_input_from_connection(InputInfoPtr pInfo); - -static Bool -notify_sync_finished(ClientPtr ptr, void *closure) -{ - int fd = (int)(intptr_t) closure; - xf86ITResponseSyncFinished response; - response.header.length = sizeof(response); - response.header.type = XF86IT_RESPONSE_SYNC_FINISHED; - - input_lock(); - /* we don't really care whether the write succeeds. It may fail if the device is - already shut down and the descriptor is closed. - */ - if (write(fd, &response, response.header.length) != response.header.length) { - LogMessageVerbSigSafe(X_ERROR, 0, - "inputtest: Failed to write sync response: %s\n", - strerror(errno)); - } - input_unlock(); - return TRUE; -} - -static void -input_drain_callback(CallbackListPtr *callback, void *data, void *call_data) -{ - void *drain_write_closure; - InputInfoPtr pInfo = data; - xf86ITDevicePtr driver_data = pInfo->private; - bool notify_synchronization = false; - - pthread_mutex_lock(&driver_data->waiting_for_drain_mutex); - driver_data->last_processed_event_num = driver_data->last_event_num; - if (driver_data->waiting_for_drain) { - driver_data->waiting_for_drain = false; - notify_synchronization = true; - } - pthread_mutex_unlock(&driver_data->waiting_for_drain_mutex); - - if (notify_synchronization) { - drain_write_closure = (void*)(intptr_t) driver_data->connection_fd; - /* One input event may result in additional sets of events being submitted to the - input queue from the input processing code itself. This results in - input_drain_callback being called multiple times. - - We therefore schedule a WorkProc (to be run when the server is no longer busy) - to notify the client when all current events have been processed. - */ - xf86IDrvMsg(pInfo, X_DEBUG, "Synchronization finished\n"); - QueueWorkProc(notify_sync_finished, NULL, drain_write_closure); - } -} - -static void -read_events(int fd, int ready, void *data) -{ - DeviceIntPtr dev = (DeviceIntPtr) data; - InputInfoPtr pInfo = dev->public.devicePrivate; - read_input_from_connection(pInfo); -} - -static void -try_accept_connection(int fd, int ready, void *data) -{ - DeviceIntPtr dev = (DeviceIntPtr) data; - InputInfoPtr pInfo = dev->public.devicePrivate; - xf86ITDevicePtr driver_data = pInfo->private; - int connection_fd; - int flags; - - if (driver_data->connection_fd >= 0) - return; - - connection_fd = accept(driver_data->socket_fd, NULL, NULL); - if (connection_fd < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) - return; - xf86IDrvMsg(pInfo, X_ERROR, "Failed to accept a connection\n"); - return; - } - - xf86IDrvMsg(pInfo, X_DEBUG, "Accepted input control connection\n"); - - flags = fcntl(connection_fd, F_GETFL, 0); - fcntl(connection_fd, F_SETFL, flags | O_NONBLOCK); - - driver_data->connection_fd = connection_fd; - xf86AddInputEventDrainCallback(input_drain_callback, pInfo); - SetNotifyFd(driver_data->connection_fd, read_events, X_NOTIFY_READ, dev); - - driver_data->client_state = CLIENT_STATE_NEW; -} - -static int -device_on(DeviceIntPtr dev) -{ - InputInfoPtr pInfo = dev->public.devicePrivate; - xf86ITDevicePtr driver_data = pInfo->private; - - xf86IDrvMsg(pInfo, X_DEBUG, "Device turned on\n"); - - xf86AddEnabledDevice(pInfo); - dev->public.on = TRUE; - driver_data->buffer.valid_length = 0; - - try_accept_connection(-1, 0, dev); - if (driver_data->connection_fd < 0) - SetNotifyFd(driver_data->socket_fd, try_accept_connection, X_NOTIFY_READ, dev); - - return Success; -} - -static void -teardown_client_connection(InputInfoPtr pInfo) -{ - xf86ITDevicePtr driver_data = pInfo->private; - if (driver_data->client_state != CLIENT_STATE_NOT_CONNECTED) { - RemoveNotifyFd(driver_data->connection_fd); - xf86RemoveInputEventDrainCallback(input_drain_callback, pInfo); - - close(driver_data->connection_fd); - driver_data->connection_fd = -1; - } - RemoveNotifyFd(driver_data->socket_fd); - driver_data->client_state = CLIENT_STATE_NOT_CONNECTED; -} - -static int -device_off(DeviceIntPtr dev) -{ - InputInfoPtr pInfo = dev->public.devicePrivate; - - xf86IDrvMsg(pInfo, X_DEBUG, "Device turned off\n"); - - if (dev->public.on) { - teardown_client_connection(pInfo); - xf86RemoveEnabledDevice(pInfo); - } - dev->public.on = FALSE; - return Success; -} - -static void -ptr_ctl(DeviceIntPtr dev, PtrCtrl *ctl) -{ -} - -static void -init_button_map(unsigned char *btnmap, size_t size) -{ - int i; - - memset(btnmap, 0, size); - for (i = 0; i < size; i++) - btnmap[i] = i; -} - -static void -init_button_labels(Atom *labels, size_t size) -{ - assert(size > 10); - - memset(labels, 0, size * sizeof(Atom)); - labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT); - labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE); - labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT); - labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP); - labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN); - labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT); - labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT); - labels[7] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_SIDE); - labels[8] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_EXTRA); - labels[9] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_FORWARD); - labels[10] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_BACK); -} - -static void -init_pointer(InputInfoPtr pInfo) -{ - DeviceIntPtr dev= pInfo->dev; - int min, max, res; - int nbuttons = 7; - bool has_pressure = false; - int num_axes = 0; - - unsigned char btnmap[MAX_BUTTONS + 1]; - Atom btnlabels[MAX_BUTTONS]; - Atom axislabels[MAX_POINTER_NUM_AXES]; - - nbuttons = xf86SetIntOption(pInfo->options, "PointerButtonCount", 7); - has_pressure = xf86SetBoolOption(pInfo->options, "PointerHasPressure", - false); - - init_button_map(btnmap, ARRAY_SIZE(btnmap)); - init_button_labels(btnlabels, ARRAY_SIZE(btnlabels)); - - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HSCROLL); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_VSCROLL); - if (has_pressure) - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE); - - InitPointerDeviceStruct((DevicePtr)dev, - btnmap, - nbuttons, - btnlabels, - ptr_ctl, - GetMotionHistorySize(), - num_axes, - axislabels); - min = -1; - max = -1; - res = 0; - - xf86InitValuatorAxisStruct(dev, 0, XIGetKnownProperty(AXIS_LABEL_PROP_REL_X), - min, max, res * 1000, 0, res * 1000, Relative); - xf86InitValuatorAxisStruct(dev, 1, XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y), - min, max, res * 1000, 0, res * 1000, Relative); - - SetScrollValuator(dev, 2, SCROLL_TYPE_HORIZONTAL, 120, 0); - SetScrollValuator(dev, 3, SCROLL_TYPE_VERTICAL, 120, 0); - - if (has_pressure) { - xf86InitValuatorAxisStruct(dev, 4, - XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE), - 0, 1000, 1, 1, 1, Absolute); - } -} - -static void -init_pointer_absolute(InputInfoPtr pInfo) -{ - DeviceIntPtr dev = pInfo->dev; - int min, max, res; - int nbuttons = 7; - bool has_pressure = false; - int num_axes = 0; - - unsigned char btnmap[MAX_BUTTONS + 1]; - Atom btnlabels[MAX_BUTTONS]; - Atom axislabels[MAX_POINTER_NUM_AXES]; - - nbuttons = xf86SetIntOption(pInfo->options, "PointerButtonCount", 7); - has_pressure = xf86SetBoolOption(pInfo->options, "PointerHasPressure", - false); - - init_button_map(btnmap, ARRAY_SIZE(btnmap)); - init_button_labels(btnlabels, ARRAY_SIZE(btnlabels)); - - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HSCROLL); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_VSCROLL); - if (has_pressure) - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE); - - InitPointerDeviceStruct((DevicePtr)dev, - btnmap, - nbuttons, - btnlabels, - ptr_ctl, - GetMotionHistorySize(), - num_axes , - axislabels); - min = 0; - max = TOUCH_AXIS_MAX; - res = 0; - - xf86InitValuatorAxisStruct(dev, 0, XIGetKnownProperty(AXIS_LABEL_PROP_ABS_X), - min, max, res * 1000, 0, res * 1000, Absolute); - xf86InitValuatorAxisStruct(dev, 1, XIGetKnownProperty(AXIS_LABEL_PROP_ABS_Y), - min, max, res * 1000, 0, res * 1000, Absolute); - - SetScrollValuator(dev, 2, SCROLL_TYPE_HORIZONTAL, 120, 0); - SetScrollValuator(dev, 3, SCROLL_TYPE_VERTICAL, 120, 0); - - if (has_pressure) { - xf86InitValuatorAxisStruct(dev, 4, - XIGetKnownProperty(AXIS_LABEL_PROP_ABS_PRESSURE), - 0, 1000, 1, 1, 1, Absolute); - } -} - -static void -init_proximity(InputInfoPtr pInfo) -{ - DeviceIntPtr dev = pInfo->dev; - InitProximityClassDeviceStruct(dev); -} - -static void -init_keyboard(InputInfoPtr pInfo) -{ - DeviceIntPtr dev= pInfo->dev; - XkbRMLVOSet rmlvo = {0}; - XkbRMLVOSet defaults = {0}; - - XkbGetRulesDflts(&defaults); - - rmlvo.rules = xf86SetStrOption(pInfo->options, "xkb_rules", defaults.rules); - rmlvo.model = xf86SetStrOption(pInfo->options, "xkb_model", defaults.model); - rmlvo.layout = xf86SetStrOption(pInfo->options, "xkb_layout", defaults.layout); - rmlvo.variant = xf86SetStrOption(pInfo->options, "xkb_variant", defaults.variant); - rmlvo.options = xf86SetStrOption(pInfo->options, "xkb_options", defaults.options); - - InitKeyboardDeviceStruct(dev, &rmlvo, NULL, NULL); - XkbFreeRMLVOSet(&rmlvo, FALSE); - XkbFreeRMLVOSet(&defaults, FALSE); -} - -static void -init_touch(InputInfoPtr pInfo) -{ - DeviceIntPtr dev = pInfo->dev; - int min, max, res; - unsigned char btnmap[MAX_BUTTONS + 1]; - Atom btnlabels[MAX_BUTTONS]; - Atom axislabels[MAX_TOUCH_NUM_AXES]; - int num_axes = 0; - int nbuttons = 7; - int ntouches = TOUCH_MAX_SLOTS; - - init_button_map(btnmap, ARRAY_SIZE(btnmap)); - init_button_labels(btnlabels, ARRAY_SIZE(btnlabels)); - - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_POSITION_X); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_POSITION_Y); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HSCROLL); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_VSCROLL); - axislabels[num_axes++] = XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_PRESSURE); - - InitPointerDeviceStruct((DevicePtr)dev, - btnmap, - nbuttons, - btnlabels, - ptr_ctl, - GetMotionHistorySize(), - num_axes, - axislabels); - min = 0; - max = TOUCH_AXIS_MAX; - res = 0; - - xf86InitValuatorAxisStruct(dev, 0, - XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_POSITION_X), - min, max, res * 1000, 0, res * 1000, Absolute); - xf86InitValuatorAxisStruct(dev, 1, - XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_POSITION_Y), - min, max, res * 1000, 0, res * 1000, Absolute); - - SetScrollValuator(dev, 2, SCROLL_TYPE_HORIZONTAL, 120, 0); - SetScrollValuator(dev, 3, SCROLL_TYPE_VERTICAL, 120, 0); - - xf86InitValuatorAxisStruct(dev, 4, - XIGetKnownProperty(AXIS_LABEL_PROP_ABS_MT_PRESSURE), - min, TABLET_PRESSURE_AXIS_MAX, res * 1000, 0, res * 1000, Absolute); - - ntouches = xf86SetIntOption(pInfo->options, "TouchCount", TOUCH_MAX_SLOTS); - if (ntouches == 0) /* unknown */ - ntouches = TOUCH_MAX_SLOTS; - InitTouchClassDeviceStruct(dev, ntouches, XIDirectTouch, 2); -} - -static void -init_gesture(InputInfoPtr pInfo) -{ - DeviceIntPtr dev = pInfo->dev; - int ntouches = TOUCH_MAX_SLOTS; - InitGestureClassDeviceStruct(dev, ntouches); -} - -static void -device_init(DeviceIntPtr dev) -{ - InputInfoPtr pInfo = dev->public.devicePrivate; - xf86ITDevicePtr driver_data = pInfo->private; - - dev->public.on = FALSE; - - switch (driver_data->device_type) { - case DEVICE_KEYBOARD: - init_keyboard(pInfo); - break; - case DEVICE_POINTER: - init_pointer(pInfo); - break; - case DEVICE_POINTER_GESTURE: - init_pointer(pInfo); - init_gesture(pInfo); - break; - case DEVICE_POINTER_ABS: - init_pointer_absolute(pInfo); - break; - case DEVICE_POINTER_ABS_PROXIMITY: - init_pointer_absolute(pInfo); - init_proximity(pInfo); - break; - case DEVICE_TOUCH: - init_touch(pInfo); - break; - } -} - -static void -device_destroy(DeviceIntPtr dev) -{ - InputInfoPtr pInfo = dev->public.devicePrivate; - xf86IDrvMsg(pInfo, X_INFO, "Close\n"); -} - -static int -device_control(DeviceIntPtr dev, int mode) -{ - switch (mode) { - case DEVICE_INIT: - device_init(dev); - break; - case DEVICE_ON: - device_on(dev); - break; - case DEVICE_OFF: - device_off(dev); - break; - case DEVICE_CLOSE: - device_destroy(dev); - break; - } - - return Success; -} - -static void -convert_to_valuator_mask(xf86ITValuatorData *event, ValuatorMask *mask) -{ - valuator_mask_zero(mask); - for (int i = 0; i < min(XF86IT_MAX_VALUATORS, MAX_VALUATORS); ++i) { - if (BitIsOn(event->mask, i)) { - if (event->has_unaccelerated) { - valuator_mask_set_unaccelerated(mask, i, event->valuators[i], - event->unaccelerated[i]); - } else { - valuator_mask_set_double(mask, i, event->valuators[i]); - } - } - } -} - -static void -handle_client_version(InputInfoPtr pInfo, xf86ITEventClientVersion *event) -{ - xf86ITDevicePtr driver_data = pInfo->private; - xf86ITResponseServerVersion response; - - response.header.length = sizeof(response); - response.header.type = XF86IT_RESPONSE_SERVER_VERSION; - response.major = XF86IT_PROTOCOL_VERSION_MAJOR; - response.minor = XF86IT_PROTOCOL_VERSION_MINOR; - - if (write(driver_data->connection_fd, &response, response.header.length) != response.header.length) { - xf86IDrvMsg(pInfo, X_ERROR, "Error writing driver version: %s\n", strerror(errno)); - teardown_client_connection(pInfo); - return; - } - - if (event->major != XF86IT_PROTOCOL_VERSION_MAJOR || - event->minor > XF86IT_PROTOCOL_VERSION_MINOR) - { - xf86IDrvMsg(pInfo, X_ERROR, "Unsupported protocol version: %d.%d (current %d.%d)\n", - event->major, event->minor, - XF86IT_PROTOCOL_VERSION_MAJOR, - XF86IT_PROTOCOL_VERSION_MINOR); - teardown_client_connection(pInfo); - return; - } - - driver_data->client_protocol.major = event->major; - driver_data->client_protocol.minor = event->minor; - - driver_data->client_state = CLIENT_STATE_READY; -} - -static void -handle_wait_for_sync(InputInfoPtr pInfo) -{ - xf86ITDevicePtr driver_data = pInfo->private; - bool notify_synchronization = false; - void *drain_write_closure; - - xf86IDrvMsg(pInfo, X_DEBUG, "Handling sync event\n"); - - pthread_mutex_lock(&driver_data->waiting_for_drain_mutex); - if (driver_data->last_processed_event_num == driver_data->last_event_num) { - notify_synchronization = true; - } else { - driver_data->waiting_for_drain = true; - } - pthread_mutex_unlock(&driver_data->waiting_for_drain_mutex); - - if (notify_synchronization) { - drain_write_closure = (void*)(intptr_t) driver_data->connection_fd; - xf86IDrvMsg(pInfo, X_DEBUG, "Synchronization finished\n"); - notify_sync_finished(NULL, drain_write_closure); - } -} - -static void -handle_motion(InputInfoPtr pInfo, xf86ITEventMotion *event) -{ - DeviceIntPtr dev = pInfo->dev; - xf86ITDevicePtr driver_data = pInfo->private; - ValuatorMask *mask = driver_data->valuators; - - xf86IDrvMsg(pInfo, X_DEBUG, "Handling motion event\n"); - - driver_data->last_event_num++; - - convert_to_valuator_mask(&event->valuators, mask); - xf86PostMotionEventM(dev, event->is_absolute ? Absolute : Relative, mask); -} - -static void -handle_proximity(InputInfoPtr pInfo, xf86ITEventProximity *event) -{ - DeviceIntPtr dev = pInfo->dev; - xf86ITDevicePtr driver_data = pInfo->private; - ValuatorMask *mask = driver_data->valuators; - - xf86IDrvMsg(pInfo, X_DEBUG, "Handling proximity event\n"); - - driver_data->last_event_num++; - - convert_to_valuator_mask(&event->valuators, mask); - xf86PostProximityEventM(dev, event->is_prox_in, mask); -} - -static void -handle_button(InputInfoPtr pInfo, xf86ITEventButton *event) -{ - DeviceIntPtr dev = pInfo->dev; - xf86ITDevicePtr driver_data = pInfo->private; - ValuatorMask *mask = driver_data->valuators; - - xf86IDrvMsg(pInfo, X_DEBUG, "Handling button event\n"); - - driver_data->last_event_num++; - - convert_to_valuator_mask(&event->valuators, mask); - xf86PostButtonEventM(dev, event->is_absolute ? Absolute : Relative, event->button, - event->is_press, mask); -} - -static void -handle_key(InputInfoPtr pInfo, xf86ITEventKey *event) -{ - DeviceIntPtr dev = pInfo->dev; - xf86ITDevicePtr driver_data = pInfo->private; - - xf86IDrvMsg(pInfo, X_DEBUG, "Handling key event\n"); - - driver_data->last_event_num++; - - xf86PostKeyboardEvent(dev, event->key_code, event->is_press); -} - -static void -handle_touch(InputInfoPtr pInfo, xf86ITEventTouch *event) -{ - DeviceIntPtr dev = pInfo->dev; - xf86ITDevicePtr driver_data = pInfo->private; - ValuatorMask *mask = driver_data->valuators; - - xf86IDrvMsg(pInfo, X_DEBUG, "Handling touch event\n"); - - driver_data->last_event_num++; - - convert_to_valuator_mask(&event->valuators, mask); - xf86PostTouchEvent(dev, event->touchid, event->touch_type, 0, mask); -} - -static void -handle_gesture_swipe(InputInfoPtr pInfo, xf86ITEventGestureSwipe *event) -{ - DeviceIntPtr dev = pInfo->dev; - xf86ITDevicePtr driver_data = pInfo->private; - - xf86IDrvMsg(pInfo, X_DEBUG, "Handling gesture swipe event\n"); - - driver_data->last_event_num++; - - xf86PostGestureSwipeEvent(dev, event->gesture_type, event->num_touches, event->flags, - event->delta_x, event->delta_y, - event->delta_unaccel_x, event->delta_unaccel_y); -} - -static void -handle_gesture_pinch(InputInfoPtr pInfo, xf86ITEventGesturePinch *event) -{ - DeviceIntPtr dev = pInfo->dev; - xf86ITDevicePtr driver_data = pInfo->private; - - xf86IDrvMsg(pInfo, X_DEBUG, "Handling gesture pinch event\n"); - - driver_data->last_event_num++; - - xf86PostGesturePinchEvent(dev, event->gesture_type, event->num_touches, event->flags, - event->delta_x, event->delta_y, - event->delta_unaccel_x, event->delta_unaccel_y, - event->scale, event->delta_angle); -} - -static void -client_new_handle_event(InputInfoPtr pInfo, xf86ITEventAny *event) -{ - switch (event->header.type) { - case XF86IT_EVENT_CLIENT_VERSION: - handle_client_version(pInfo, &event->version); - break; - default: - xf86IDrvMsg(pInfo, X_ERROR, "Event before client is ready: event type %d\n", - event->header.type); - teardown_client_connection(pInfo); - break; - } -} - -static void -client_ready_handle_event(InputInfoPtr pInfo, xf86ITEventAny *event) -{ - switch (event->header.type) { - case XF86IT_EVENT_WAIT_FOR_SYNC: - handle_wait_for_sync(pInfo); - break; - case XF86IT_EVENT_MOTION: - handle_motion(pInfo, &event->motion); - break; - case XF86IT_EVENT_PROXIMITY: - handle_proximity(pInfo, &event->proximity); - break; - case XF86IT_EVENT_BUTTON: - handle_button(pInfo, &event->button); - break; - case XF86IT_EVENT_KEY: - handle_key(pInfo, &event->key); - break; - case XF86IT_EVENT_TOUCH: - handle_touch(pInfo, &event->touch); - break; - case XF86IT_EVENT_GESTURE_PINCH: - handle_gesture_pinch(pInfo, &(event->pinch)); - break; - case XF86IT_EVENT_GESTURE_SWIPE: - handle_gesture_swipe(pInfo, &(event->swipe)); - break; - case XF86IT_EVENT_CLIENT_VERSION: - xf86IDrvMsg(pInfo, X_ERROR, "Only single ClientVersion event is allowed\n"); - teardown_client_connection(pInfo); - break; - default: - xf86IDrvMsg(pInfo, X_ERROR, "Invalid event when client is ready %d\n", - event->header.type); - teardown_client_connection(pInfo); - break; - } -} - -static void -handle_event(InputInfoPtr pInfo, xf86ITEventAny *event) -{ - xf86ITDevicePtr driver_data = pInfo->private; - - if (!pInfo->dev->public.on) - return; - - switch (driver_data->client_state) { - case CLIENT_STATE_NOT_CONNECTED: - xf86IDrvMsg(pInfo, X_ERROR, "Got event when client is not connected\n"); - break; - case CLIENT_STATE_NEW: - client_new_handle_event(pInfo, event); - break; - case CLIENT_STATE_READY: - client_ready_handle_event(pInfo, event); - break; - } -} - -static bool -is_supported_event(enum xf86ITEventType type) -{ - switch (type) { - case XF86IT_EVENT_CLIENT_VERSION: - case XF86IT_EVENT_WAIT_FOR_SYNC: - case XF86IT_EVENT_MOTION: - case XF86IT_EVENT_PROXIMITY: - case XF86IT_EVENT_BUTTON: - case XF86IT_EVENT_KEY: - case XF86IT_EVENT_TOUCH: - case XF86IT_EVENT_GESTURE_PINCH: - case XF86IT_EVENT_GESTURE_SWIPE: - return true; - } - return false; -} - -static int -get_event_size(enum xf86ITEventType type) -{ - switch (type) { - case XF86IT_EVENT_CLIENT_VERSION: return sizeof(xf86ITEventClientVersion); - case XF86IT_EVENT_WAIT_FOR_SYNC: return sizeof(xf86ITEventWaitForSync); - case XF86IT_EVENT_MOTION: return sizeof(xf86ITEventMotion); - case XF86IT_EVENT_PROXIMITY: return sizeof(xf86ITEventProximity); - case XF86IT_EVENT_BUTTON: return sizeof(xf86ITEventButton); - case XF86IT_EVENT_KEY: return sizeof(xf86ITEventKey); - case XF86IT_EVENT_TOUCH: return sizeof(xf86ITEventTouch); - case XF86IT_EVENT_GESTURE_PINCH: return sizeof(xf86ITEventGesturePinch); - case XF86IT_EVENT_GESTURE_SWIPE: return sizeof(xf86ITEventGestureSwipe); - } - abort(); -} - -static void -read_input_from_connection(InputInfoPtr pInfo) -{ - xf86ITDevicePtr driver_data = pInfo->private; - - while (1) { - int processed_size = 0; - int read_size = read(driver_data->connection_fd, - driver_data->buffer.data + driver_data->buffer.valid_length, - EVENT_BUFFER_SIZE - driver_data->buffer.valid_length); - - if (read_size < 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) - return; - - xf86IDrvMsg(pInfo, X_ERROR, "Error reading events: %s\n", strerror(errno)); - teardown_client_connection(pInfo); - return; - } - - driver_data->buffer.valid_length += read_size; - - while (1) { - xf86ITEventHeader *event_header; - char *event_begin = driver_data->buffer.data + processed_size; - - if (driver_data->buffer.valid_length - processed_size < sizeof(xf86ITEventHeader)) - break; - - event_header = (xf86ITEventHeader*) event_begin; - - if (event_header->length >= EVENT_BUFFER_SIZE) { - xf86IDrvMsg(pInfo, X_ERROR, "Received event with too long length: %d\n", - event_header->length); - teardown_client_connection(pInfo); - return; - } - - if (driver_data->buffer.valid_length - processed_size < event_header->length) - break; - - if (is_supported_event(event_header->type)) { - int expected_event_size = get_event_size(event_header->type); - - if (event_header->length != expected_event_size) { - xf86IDrvMsg(pInfo, X_ERROR, "Unexpected event length: was %d bytes, " - "expected %d (event type: %d)\n", - event_header->length, expected_event_size, - (int) event_header->type); - teardown_client_connection(pInfo); - return; - } - - handle_event(pInfo, (xf86ITEventAny*) event_begin); - } - processed_size += event_header->length; - } - - if (processed_size > 0) { - memmove(driver_data->buffer.data, - driver_data->buffer.data + processed_size, - driver_data->buffer.valid_length - processed_size); - driver_data->buffer.valid_length -= processed_size; - } - - if (read_size == 0) - break; - } -} - -static void -read_input(InputInfoPtr pInfo) -{ - /* The test input driver does not set up the pInfo->fd and use the regular - read_input callback because we want to only accept the connection to - the controlling socket after the device is turned on. - */ -} - -static const char* -get_type_name(InputInfoPtr pInfo, xf86ITDevicePtr driver_data) -{ - switch (driver_data->device_type) { - case DEVICE_TOUCH: return XI_TOUCHSCREEN; - case DEVICE_POINTER: return XI_MOUSE; - case DEVICE_POINTER_GESTURE: return XI_TOUCHPAD; - case DEVICE_POINTER_ABS: return XI_MOUSE; - case DEVICE_POINTER_ABS_PROXIMITY: return XI_TABLET; - case DEVICE_KEYBOARD: return XI_KEYBOARD; - } - xf86IDrvMsg(pInfo, X_ERROR, "Unexpected device type %d\n", - driver_data->device_type); - return XI_KEYBOARD; -} - -static xf86ITDevicePtr -device_alloc(void) -{ - xf86ITDevicePtr driver_data = calloc(sizeof(xf86ITDevice), 1); - - if (!driver_data) - return NULL; - - driver_data->socket_fd = -1; - driver_data->connection_fd = -1; - - return driver_data; -} - -static void -free_driver_data(xf86ITDevicePtr driver_data) -{ - if (driver_data) { - close(driver_data->connection_fd); - close(driver_data->socket_fd); - if (driver_data->socket_path) - unlink(driver_data->socket_path); - free(driver_data->socket_path); - pthread_mutex_destroy(&driver_data->waiting_for_drain_mutex); - - if (driver_data->valuators) - valuator_mask_free(&driver_data->valuators); - if (driver_data->valuators_unaccelerated) - valuator_mask_free(&driver_data->valuators_unaccelerated); - } - free(driver_data); -} - -static int -pre_init(InputDriverPtr drv, InputInfoPtr pInfo, int flags) -{ - xf86ITDevicePtr driver_data = NULL; - char *device_type_option; - struct sockaddr_un addr; - - pInfo->type_name = 0; - pInfo->device_control = device_control; - pInfo->read_input = read_input; - pInfo->control_proc = NULL; - pInfo->switch_mode = NULL; - - driver_data = device_alloc(); - if (!driver_data) - goto fail; - - driver_data->client_state = CLIENT_STATE_NOT_CONNECTED; - driver_data->last_event_num = 1; - driver_data->last_processed_event_num = 0; - driver_data->waiting_for_drain = false; - pthread_mutex_init(&driver_data->waiting_for_drain_mutex, NULL); - - driver_data->valuators = valuator_mask_new(6); - if (!driver_data->valuators) - goto fail; - - driver_data->valuators_unaccelerated = valuator_mask_new(2); - if (!driver_data->valuators_unaccelerated) - goto fail; - - driver_data->socket_path = xf86SetStrOption(pInfo->options, "SocketPath", NULL); - if (!driver_data->socket_path){ - xf86IDrvMsg(pInfo, X_ERROR, "SocketPath must be specified\n"); - goto fail; - } - - if (strlen(driver_data->socket_path) >= sizeof(addr.sun_path)) { - xf86IDrvMsg(pInfo, X_ERROR, "SocketPath is too long\n"); - goto fail; - } - - unlink(driver_data->socket_path); - - driver_data->socket_fd = socket(PF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0); - if (driver_data->socket_fd < 0) { - xf86IDrvMsg(pInfo, X_ERROR, "Failed to create a socket for communication: %s\n", - strerror(errno)); - goto fail; - } - - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, driver_data->socket_path, sizeof(addr.sun_path) - 1); - - if (bind(driver_data->socket_fd, (struct sockaddr*) &addr, sizeof(addr)) < 0) { - xf86IDrvMsg(pInfo, X_ERROR, "Failed to assign address to the socket\n"); - goto fail; - } - - if (chmod(driver_data->socket_path, 0777) != 0) { - xf86IDrvMsg(pInfo, X_ERROR, "Failed to chmod the socket path\n"); - goto fail; - } - - if (listen(driver_data->socket_fd, 1) != 0) { - xf86IDrvMsg(pInfo, X_ERROR, "Failed to listen on the socket\n"); - goto fail; - } - - device_type_option = xf86SetStrOption(pInfo->options, "DeviceType", NULL); - if (device_type_option == NULL) { - xf86IDrvMsg(pInfo, X_ERROR, "DeviceType option must be specified\n"); - goto fail; - } - - if (strcmp(device_type_option, "Keyboard") == 0) { - driver_data->device_type = DEVICE_KEYBOARD; - } else if (strcmp(device_type_option, "Pointer") == 0) { - driver_data->device_type = DEVICE_POINTER; - } else if (strcmp(device_type_option, "PointerGesture") == 0) { - driver_data->device_type = DEVICE_POINTER_GESTURE; - } else if (strcmp(device_type_option, "PointerAbsolute") == 0) { - driver_data->device_type = DEVICE_POINTER_ABS; - } else if (strcmp(device_type_option, "PointerAbsoluteProximity") == 0) { - driver_data->device_type = DEVICE_POINTER_ABS_PROXIMITY; - } else if (strcmp(device_type_option, "Touch") == 0) { - driver_data->device_type = DEVICE_TOUCH; - } else { - xf86IDrvMsg(pInfo, X_ERROR, "Unsupported DeviceType option.\n"); - goto fail; - } - free(device_type_option); - - pInfo->private = driver_data; - driver_data->pInfo = pInfo; - - pInfo->type_name = get_type_name(pInfo, driver_data); - - return Success; -fail: - free_driver_data(driver_data); - return BadValue; -} - -static void -uninit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) -{ - xf86ITDevicePtr driver_data = pInfo->private; - free_driver_data(driver_data); - pInfo->private = NULL; - xf86DeleteInput(pInfo, flags); -} - -InputDriverRec driver = { - .driverVersion = 1, - .driverName = "inputtest", - .PreInit = pre_init, - .UnInit = uninit, - .module = NULL, - .default_options = NULL, - .capabilities = 0 -}; - -static XF86ModuleVersionInfo version_info = { - "inputtest", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - XORG_VERSION_MAJOR, - XORG_VERSION_MINOR, - XORG_VERSION_PATCH, - ABI_CLASS_XINPUT, - ABI_XINPUT_VERSION, - MOD_CLASS_XINPUT, - {0, 0, 0, 0} -}; - -static void* -setup_proc(void *module, void *options, int *errmaj, int *errmin) -{ - xf86AddInputDriver(&driver, module, 0); - return module; -} - -_X_EXPORT XF86ModuleData inputtestModuleData = { - .vers = &version_info, - .setup = &setup_proc, - .teardown = NULL -}; diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c deleted file mode 100644 index 8d1b742ef..000000000 --- a/hw/xfree86/drivers/modesetting/dri2.c +++ /dev/null @@ -1,1115 +0,0 @@ -/* - * Copyright © 2013 Intel Corporation - * Copyright © 2014 Broadcom - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -/** - * @file dri2.c - * - * Implements generic support for DRI2 on KMS, using glamor pixmaps - * for color buffer management (no support for other aux buffers), and - * the DRM vblank ioctls. - * - * This doesn't implement pageflipping yet. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include "dix-config.h" -#endif - -#include -#include "list.h" -#include "xf86.h" -#include "driver.h" -#include "dri2.h" - -#ifdef GLAMOR_HAS_GBM - -enum ms_dri2_frame_event_type { - MS_DRI2_QUEUE_SWAP, - MS_DRI2_QUEUE_FLIP, - MS_DRI2_WAIT_MSC, -}; - -typedef struct ms_dri2_frame_event { - ScreenPtr screen; - - DrawablePtr drawable; - ClientPtr client; - enum ms_dri2_frame_event_type type; - int frame; - xf86CrtcPtr crtc; - - struct xorg_list drawable_resource, client_resource; - - /* for swaps & flips only */ - DRI2SwapEventPtr event_complete; - void *event_data; - DRI2BufferPtr front; - DRI2BufferPtr back; -} ms_dri2_frame_event_rec, *ms_dri2_frame_event_ptr; - -typedef struct { - int refcnt; - PixmapPtr pixmap; -} ms_dri2_buffer_private_rec, *ms_dri2_buffer_private_ptr; - -static DevPrivateKeyRec ms_dri2_client_key; -static RESTYPE frame_event_client_type, frame_event_drawable_type; -static int ms_dri2_server_generation; - -struct ms_dri2_resource { - XID id; - RESTYPE type; - struct xorg_list list; -}; - -static struct ms_dri2_resource * -ms_get_resource(XID id, RESTYPE type) -{ - struct ms_dri2_resource *resource; - void *ptr; - - ptr = NULL; - dixLookupResourceByType(&ptr, id, type, NULL, DixWriteAccess); - if (ptr) - return ptr; - - resource = malloc(sizeof(*resource)); - if (resource == NULL) - return NULL; - - if (!AddResource(id, type, resource)) - return NULL; - - resource->id = id; - resource->type = type; - xorg_list_init(&resource->list); - return resource; -} - -static inline PixmapPtr -get_drawable_pixmap(DrawablePtr drawable) -{ - ScreenPtr screen = drawable->pScreen; - - if (drawable->type == DRAWABLE_PIXMAP) - return (PixmapPtr) drawable; - else - return screen->GetWindowPixmap((WindowPtr) drawable); -} - -static DRI2Buffer2Ptr -ms_dri2_create_buffer2(ScreenPtr screen, DrawablePtr drawable, - unsigned int attachment, unsigned int format) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - DRI2Buffer2Ptr buffer; - PixmapPtr pixmap; - CARD32 size; - CARD16 pitch; - ms_dri2_buffer_private_ptr private; - - buffer = calloc(1, sizeof *buffer); - if (buffer == NULL) - return NULL; - - private = calloc(1, sizeof(*private)); - if (private == NULL) { - free(buffer); - return NULL; - } - - pixmap = NULL; - if (attachment == DRI2BufferFrontLeft) { - pixmap = get_drawable_pixmap(drawable); - if (pixmap && pixmap->drawable.pScreen != screen) - pixmap = NULL; - if (pixmap) - pixmap->refcnt++; - } - - if (pixmap == NULL) { - int pixmap_width = drawable->width; - int pixmap_height = drawable->height; - int pixmap_cpp = (format != 0) ? format : drawable->depth; - - /* Assume that non-color-buffers require special - * device-specific handling. Mesa currently makes no requests - * for non-color aux buffers. - */ - switch (attachment) { - case DRI2BufferAccum: - case DRI2BufferBackLeft: - case DRI2BufferBackRight: - case DRI2BufferFakeFrontLeft: - case DRI2BufferFakeFrontRight: - case DRI2BufferFrontLeft: - case DRI2BufferFrontRight: - break; - - case DRI2BufferStencil: - case DRI2BufferDepth: - case DRI2BufferDepthStencil: - case DRI2BufferHiz: - default: - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "Request for DRI2 buffer attachment %d unsupported\n", - attachment); - free(private); - free(buffer); - return NULL; - } - - pixmap = screen->CreatePixmap(screen, - pixmap_width, - pixmap_height, - pixmap_cpp, - 0); - if (pixmap == NULL) { - free(private); - free(buffer); - return NULL; - } - } - - buffer->attachment = attachment; - buffer->cpp = pixmap->drawable.bitsPerPixel / 8; - buffer->format = format; - /* The buffer's flags field is unused by the client drivers in - * Mesa currently. - */ - buffer->flags = 0; - - buffer->name = ms->glamor.name_from_pixmap(pixmap, &pitch, &size); - buffer->pitch = pitch; - if (buffer->name == -1) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Failed to get DRI2 name for pixmap\n"); - screen->DestroyPixmap(pixmap); - free(private); - free(buffer); - return NULL; - } - - buffer->driverPrivate = private; - private->refcnt = 1; - private->pixmap = pixmap; - - return buffer; -} - -static DRI2Buffer2Ptr -ms_dri2_create_buffer(DrawablePtr drawable, unsigned int attachment, - unsigned int format) -{ - return ms_dri2_create_buffer2(drawable->pScreen, drawable, attachment, - format); -} - -static void -ms_dri2_reference_buffer(DRI2Buffer2Ptr buffer) -{ - if (buffer) { - ms_dri2_buffer_private_ptr private = buffer->driverPrivate; - private->refcnt++; - } -} - -static void ms_dri2_destroy_buffer2(ScreenPtr unused, DrawablePtr unused2, - DRI2Buffer2Ptr buffer) -{ - if (!buffer) - return; - - if (buffer->driverPrivate) { - ms_dri2_buffer_private_ptr private = buffer->driverPrivate; - if (--private->refcnt == 0) { - ScreenPtr screen = private->pixmap->drawable.pScreen; - screen->DestroyPixmap(private->pixmap); - free(private); - free(buffer); - } - } else { - free(buffer); - } -} - -static void ms_dri2_destroy_buffer(DrawablePtr drawable, DRI2Buffer2Ptr buffer) -{ - ms_dri2_destroy_buffer2(NULL, drawable, buffer); -} - -static void -ms_dri2_copy_region2(ScreenPtr screen, DrawablePtr drawable, RegionPtr pRegion, - DRI2BufferPtr destBuffer, DRI2BufferPtr sourceBuffer) -{ - ms_dri2_buffer_private_ptr src_priv = sourceBuffer->driverPrivate; - ms_dri2_buffer_private_ptr dst_priv = destBuffer->driverPrivate; - PixmapPtr src_pixmap = src_priv->pixmap; - PixmapPtr dst_pixmap = dst_priv->pixmap; - DrawablePtr src = (sourceBuffer->attachment == DRI2BufferFrontLeft) - ? drawable : &src_pixmap->drawable; - DrawablePtr dst = (destBuffer->attachment == DRI2BufferFrontLeft) - ? drawable : &dst_pixmap->drawable; - int off_x = 0, off_y = 0; - Bool translate = FALSE; - RegionPtr pCopyClip; - GCPtr gc; - - if (destBuffer->attachment == DRI2BufferFrontLeft && - drawable->pScreen != screen) { - dst = DRI2UpdatePrime(drawable, destBuffer); - if (!dst) - return; - if (dst != drawable) - translate = TRUE; - } - - if (translate && drawable->type == DRAWABLE_WINDOW) { -#ifdef COMPOSITE - PixmapPtr pixmap = get_drawable_pixmap(drawable); - off_x = -pixmap->screen_x; - off_y = -pixmap->screen_y; -#endif - off_x += drawable->x; - off_y += drawable->y; - } - - gc = GetScratchGC(dst->depth, screen); - if (!gc) - return; - - pCopyClip = REGION_CREATE(screen, NULL, 0); - REGION_COPY(screen, pCopyClip, pRegion); - if (translate) - REGION_TRANSLATE(screen, pCopyClip, off_x, off_y); - (*gc->funcs->ChangeClip) (gc, CT_REGION, pCopyClip, 0); - ValidateGC(dst, gc); - - /* It's important that this copy gets submitted before the direct - * rendering client submits rendering for the next frame, but we - * don't actually need to submit right now. The client will wait - * for the DRI2CopyRegion reply or the swap buffer event before - * rendering, and we'll hit the flush callback chain before those - * messages are sent. We submit our batch buffers from the flush - * callback chain so we know that will happen before the client - * tries to render again. - */ - gc->ops->CopyArea(src, dst, gc, - 0, 0, - drawable->width, drawable->height, - off_x, off_y); - - FreeScratchGC(gc); -} - -static void -ms_dri2_copy_region(DrawablePtr drawable, RegionPtr pRegion, - DRI2BufferPtr destBuffer, DRI2BufferPtr sourceBuffer) -{ - ms_dri2_copy_region2(drawable->pScreen, drawable, pRegion, destBuffer, - sourceBuffer); -} - -static uint64_t -gettime_us(void) -{ - struct timespec tv; - - if (clock_gettime(CLOCK_MONOTONIC, &tv)) - return 0; - - return (uint64_t)tv.tv_sec * 1000000 + tv.tv_nsec / 1000; -} - -/** - * Get current frame count and frame count timestamp, based on drawable's - * crtc. - */ -static int -ms_dri2_get_msc(DrawablePtr draw, CARD64 *ust, CARD64 *msc) -{ - int ret; - xf86CrtcPtr crtc = ms_dri2_crtc_covering_drawable(draw); - - /* Drawable not displayed, make up a *monotonic* value */ - if (crtc == NULL) { - *ust = gettime_us(); - *msc = 0; - return TRUE; - } - - ret = ms_get_crtc_ust_msc(crtc, ust, msc); - - if (ret) - return FALSE; - - return TRUE; -} - -static XID -get_client_id(ClientPtr client) -{ - XID *ptr = dixGetPrivateAddr(&client->devPrivates, &ms_dri2_client_key); - if (*ptr == 0) - *ptr = FakeClientID(client->index); - return *ptr; -} - -/* - * Hook this frame event into the server resource - * database so we can clean it up if the drawable or - * client exits while the swap is pending - */ -static Bool -ms_dri2_add_frame_event(ms_dri2_frame_event_ptr info) -{ - struct ms_dri2_resource *resource; - - resource = ms_get_resource(get_client_id(info->client), - frame_event_client_type); - if (resource == NULL) - return FALSE; - - xorg_list_add(&info->client_resource, &resource->list); - - resource = ms_get_resource(info->drawable->id, frame_event_drawable_type); - if (resource == NULL) { - xorg_list_del(&info->client_resource); - return FALSE; - } - - xorg_list_add(&info->drawable_resource, &resource->list); - - return TRUE; -} - -static void -ms_dri2_del_frame_event(ms_dri2_frame_event_rec *info) -{ - xorg_list_del(&info->client_resource); - xorg_list_del(&info->drawable_resource); - - if (info->front) - ms_dri2_destroy_buffer(NULL, info->front); - if (info->back) - ms_dri2_destroy_buffer(NULL, info->back); - - free(info); -} - -static void -ms_dri2_blit_swap(DrawablePtr drawable, - DRI2BufferPtr dst, - DRI2BufferPtr src) -{ - BoxRec box; - RegionRec region; - - box.x1 = 0; - box.y1 = 0; - box.x2 = drawable->width; - box.y2 = drawable->height; - REGION_INIT(pScreen, ®ion, &box, 0); - - ms_dri2_copy_region(drawable, ®ion, dst, src); -} - -struct ms_dri2_vblank_event { - XID drawable_id; - ClientPtr client; - DRI2SwapEventPtr event_complete; - void *event_data; -}; - -static void -ms_dri2_flip_abort(modesettingPtr ms, void *data) -{ - struct ms_present_vblank_event *event = data; - - ms->drmmode.dri2_flipping = FALSE; - free(event); -} - -static void -ms_dri2_flip_handler(modesettingPtr ms, uint64_t msc, - uint64_t ust, void *data) -{ - struct ms_dri2_vblank_event *event = data; - uint32_t frame = msc; - uint32_t tv_sec = ust / 1000000; - uint32_t tv_usec = ust % 1000000; - DrawablePtr drawable; - int status; - - status = dixLookupDrawable(&drawable, event->drawable_id, serverClient, - M_ANY, DixWriteAccess); - if (status == Success) - DRI2SwapComplete(event->client, drawable, frame, tv_sec, tv_usec, - DRI2_FLIP_COMPLETE, event->event_complete, - event->event_data); - - ms->drmmode.dri2_flipping = FALSE; - free(event); -} - -static Bool -ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info) -{ - DrawablePtr draw = info->drawable; - ScreenPtr screen = draw->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - ms_dri2_buffer_private_ptr back_priv = info->back->driverPrivate; - struct ms_dri2_vblank_event *event; - drmmode_crtc_private_ptr drmmode_crtc = info->crtc->driver_private; - - event = calloc(1, sizeof(struct ms_dri2_vblank_event)); - if (!event) - return FALSE; - - event->drawable_id = draw->id; - event->client = info->client; - event->event_complete = info->event_complete; - event->event_data = info->event_data; - - if (ms_do_pageflip(screen, back_priv->pixmap, event, - drmmode_crtc->vblank_pipe, FALSE, - ms_dri2_flip_handler, - ms_dri2_flip_abort, - "DRI2-flip")) { - ms->drmmode.dri2_flipping = TRUE; - return TRUE; - } - return FALSE; -} - -static Bool -update_front(DrawablePtr draw, DRI2BufferPtr front) -{ - ScreenPtr screen = draw->pScreen; - PixmapPtr pixmap = get_drawable_pixmap(draw); - ms_dri2_buffer_private_ptr priv = front->driverPrivate; - modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(screen)); - CARD32 size; - CARD16 pitch; - int name; - - name = ms->glamor.name_from_pixmap(pixmap, &pitch, &size); - if (name < 0) - return FALSE; - - front->name = name; - - (*screen->DestroyPixmap) (priv->pixmap); - front->pitch = pixmap->devKind; - front->cpp = pixmap->drawable.bitsPerPixel / 8; - priv->pixmap = pixmap; - pixmap->refcnt++; - - return TRUE; -} - -static Bool -can_exchange(ScrnInfoPtr scrn, DrawablePtr draw, - DRI2BufferPtr front, DRI2BufferPtr back) -{ - ms_dri2_buffer_private_ptr front_priv = front->driverPrivate; - ms_dri2_buffer_private_ptr back_priv = back->driverPrivate; - PixmapPtr front_pixmap; - PixmapPtr back_pixmap = back_priv->pixmap; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int num_crtcs_on = 0; - int i; - - for (i = 0; i < config->num_crtc; i++) { - drmmode_crtc_private_ptr drmmode_crtc = config->crtc[i]->driver_private; - - /* Don't do pageflipping if CRTCs are rotated. */ -#ifdef GLAMOR_HAS_GBM - if (drmmode_crtc->rotate_bo.gbm) - return FALSE; -#endif - - if (xf86_crtc_on(config->crtc[i])) - num_crtcs_on++; - } - - /* We can't do pageflipping if all the CRTCs are off. */ - if (num_crtcs_on == 0) - return FALSE; - - if (!update_front(draw, front)) - return FALSE; - - front_pixmap = front_priv->pixmap; - - if (front_pixmap->drawable.width != back_pixmap->drawable.width) - return FALSE; - - if (front_pixmap->drawable.height != back_pixmap->drawable.height) - return FALSE; - - if (front_pixmap->drawable.bitsPerPixel != - back_pixmap->drawable.bitsPerPixel) - return FALSE; - - if (front_pixmap->devKind != back_pixmap->devKind) - return FALSE; - - return TRUE; -} - -static Bool -can_flip(ScrnInfoPtr scrn, DrawablePtr draw, - DRI2BufferPtr front, DRI2BufferPtr back) -{ - modesettingPtr ms = modesettingPTR(scrn); - - return draw->type == DRAWABLE_WINDOW && - ms->drmmode.pageflip && - !ms->drmmode.sprites_visible && - !ms->drmmode.present_flipping && - scrn->vtSema && - DRI2CanFlip(draw) && can_exchange(scrn, draw, front, back); -} - -static void -ms_dri2_exchange_buffers(DrawablePtr draw, DRI2BufferPtr front, - DRI2BufferPtr back) -{ - ms_dri2_buffer_private_ptr front_priv = front->driverPrivate; - ms_dri2_buffer_private_ptr back_priv = back->driverPrivate; - ScreenPtr screen = draw->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - msPixmapPrivPtr front_pix = msGetPixmapPriv(&ms->drmmode, front_priv->pixmap); - msPixmapPrivPtr back_pix = msGetPixmapPriv(&ms->drmmode, back_priv->pixmap); - msPixmapPrivRec tmp_pix; - RegionRec region; - int tmp; - - /* Swap BO names so DRI works */ - tmp = front->name; - front->name = back->name; - back->name = tmp; - - /* Swap pixmap privates */ - tmp_pix = *front_pix; - *front_pix = *back_pix; - *back_pix = tmp_pix; - - ms->glamor.egl_exchange_buffers(front_priv->pixmap, back_priv->pixmap); - - /* Post damage on the front buffer so that listeners, such - * as DisplayLink know take a copy and shove it over the USB. - */ - region.extents.x1 = region.extents.y1 = 0; - region.extents.x2 = front_priv->pixmap->drawable.width; - region.extents.y2 = front_priv->pixmap->drawable.height; - region.data = NULL; - DamageRegionAppend(&front_priv->pixmap->drawable, ®ion); - DamageRegionProcessPending(&front_priv->pixmap->drawable); -} - -static void -ms_dri2_frame_event_handler(uint64_t msc, - uint64_t usec, - void *data) -{ - ms_dri2_frame_event_ptr frame_info = data; - DrawablePtr drawable = frame_info->drawable; - ScreenPtr screen = frame_info->screen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - uint32_t tv_sec = usec / 1000000; - uint32_t tv_usec = usec % 1000000; - - if (!drawable) { - ms_dri2_del_frame_event(frame_info); - return; - } - - switch (frame_info->type) { - case MS_DRI2_QUEUE_FLIP: - if (can_flip(scrn, drawable, frame_info->front, frame_info->back) && - ms_dri2_schedule_flip(frame_info)) { - ms_dri2_exchange_buffers(drawable, frame_info->front, frame_info->back); - break; - } - /* else fall through to blit */ - case MS_DRI2_QUEUE_SWAP: - ms_dri2_blit_swap(drawable, frame_info->front, frame_info->back); - DRI2SwapComplete(frame_info->client, drawable, msc, tv_sec, tv_usec, - DRI2_BLIT_COMPLETE, - frame_info->client ? frame_info->event_complete : NULL, - frame_info->event_data); - break; - - case MS_DRI2_WAIT_MSC: - if (frame_info->client) - DRI2WaitMSCComplete(frame_info->client, drawable, - msc, tv_sec, tv_usec); - break; - - default: - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "%s: unknown vblank event (type %d) received\n", __func__, - frame_info->type); - break; - } - - ms_dri2_del_frame_event(frame_info); -} - -static void -ms_dri2_frame_event_abort(void *data) -{ - ms_dri2_frame_event_ptr frame_info = data; - - ms_dri2_del_frame_event(frame_info); -} - -/** - * Request a DRM event when the requested conditions will be satisfied. - * - * We need to handle the event and ask the server to wake up the client when - * we receive it. - */ -static int -ms_dri2_schedule_wait_msc(ClientPtr client, DrawablePtr draw, CARD64 target_msc, - CARD64 divisor, CARD64 remainder) -{ - ScreenPtr screen = draw->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - ms_dri2_frame_event_ptr wait_info; - int ret; - xf86CrtcPtr crtc = ms_dri2_crtc_covering_drawable(draw); - CARD64 current_msc, current_ust, request_msc; - uint32_t seq; - uint64_t queued_msc; - - /* Drawable not visible, return immediately */ - if (!crtc) - goto out_complete; - - wait_info = calloc(1, sizeof(*wait_info)); - if (!wait_info) - goto out_complete; - - wait_info->screen = screen; - wait_info->drawable = draw; - wait_info->client = client; - wait_info->type = MS_DRI2_WAIT_MSC; - - if (!ms_dri2_add_frame_event(wait_info)) { - free(wait_info); - wait_info = NULL; - goto out_complete; - } - - /* Get current count */ - ret = ms_get_crtc_ust_msc(crtc, ¤t_ust, ¤t_msc); - - /* - * If divisor is zero, or current_msc is smaller than target_msc, - * we just need to make sure target_msc passes before waking up the - * client. - */ - if (divisor == 0 || current_msc < target_msc) { - /* If target_msc already reached or passed, set it to - * current_msc to ensure we return a reasonable value back - * to the caller. This keeps the client from continually - * sending us MSC targets from the past by forcibly updating - * their count on this call. - */ - seq = ms_drm_queue_alloc(crtc, wait_info, - ms_dri2_frame_event_handler, - ms_dri2_frame_event_abort); - if (!seq) - goto out_free; - - if (current_msc >= target_msc) - target_msc = current_msc; - - ret = ms_queue_vblank(crtc, MS_QUEUE_ABSOLUTE, target_msc, &queued_msc, seq); - if (!ret) { - static int limit = 5; - if (limit) { - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "%s:%d get vblank counter failed: %s\n", - __FUNCTION__, __LINE__, - strerror(errno)); - limit--; - } - goto out_free; - } - - wait_info->frame = queued_msc; - DRI2BlockClient(client, draw); - return TRUE; - } - - /* - * If we get here, target_msc has already passed or we don't have one, - * so we queue an event that will satisfy the divisor/remainder equation. - */ - request_msc = current_msc - (current_msc % divisor) + - remainder; - /* - * If calculated remainder is larger than requested remainder, - * it means we've passed the last point where - * seq % divisor == remainder, so we need to wait for the next time - * that will happen. - */ - if ((current_msc % divisor) >= remainder) - request_msc += divisor; - - seq = ms_drm_queue_alloc(crtc, wait_info, - ms_dri2_frame_event_handler, - ms_dri2_frame_event_abort); - if (!seq) - goto out_free; - - if (!ms_queue_vblank(crtc, MS_QUEUE_ABSOLUTE, request_msc, &queued_msc, seq)) { - static int limit = 5; - if (limit) { - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "%s:%d get vblank counter failed: %s\n", - __FUNCTION__, __LINE__, - strerror(errno)); - limit--; - } - goto out_free; - } - - wait_info->frame = queued_msc; - - DRI2BlockClient(client, draw); - - return TRUE; - - out_free: - ms_dri2_del_frame_event(wait_info); - out_complete: - DRI2WaitMSCComplete(client, draw, target_msc, 0, 0); - return TRUE; -} - -/** - * ScheduleSwap is responsible for requesting a DRM vblank event for - * the appropriate frame, or executing the swap immediately if it - * doesn't need to wait. - * - * When the swap is complete, the driver should call into the server so it - * can send any swap complete events that have been requested. - */ -static int -ms_dri2_schedule_swap(ClientPtr client, DrawablePtr draw, - DRI2BufferPtr front, DRI2BufferPtr back, - CARD64 *target_msc, CARD64 divisor, - CARD64 remainder, DRI2SwapEventPtr func, void *data) -{ - ScreenPtr screen = draw->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - int ret, flip = 0; - xf86CrtcPtr crtc = ms_dri2_crtc_covering_drawable(draw); - ms_dri2_frame_event_ptr frame_info = NULL; - uint64_t current_msc, current_ust; - uint64_t request_msc; - uint32_t seq; - ms_queue_flag ms_flag = MS_QUEUE_ABSOLUTE; - uint64_t queued_msc; - - /* Drawable not displayed... just complete the swap */ - if (!crtc) - goto blit_fallback; - - frame_info = calloc(1, sizeof(*frame_info)); - if (!frame_info) - goto blit_fallback; - - frame_info->screen = screen; - frame_info->drawable = draw; - frame_info->client = client; - frame_info->event_complete = func; - frame_info->event_data = data; - frame_info->front = front; - frame_info->back = back; - frame_info->crtc = crtc; - frame_info->type = MS_DRI2_QUEUE_SWAP; - - if (!ms_dri2_add_frame_event(frame_info)) { - free(frame_info); - frame_info = NULL; - goto blit_fallback; - } - - ms_dri2_reference_buffer(front); - ms_dri2_reference_buffer(back); - - ret = ms_get_crtc_ust_msc(crtc, ¤t_ust, ¤t_msc); - if (ret != Success) - goto blit_fallback; - - /* Flips need to be submitted one frame before */ - if (can_flip(scrn, draw, front, back)) { - frame_info->type = MS_DRI2_QUEUE_FLIP; - flip = 1; - } - - /* Correct target_msc by 'flip' if frame_info->type == MS_DRI2_QUEUE_FLIP. - * Do it early, so handling of different timing constraints - * for divisor, remainder and msc vs. target_msc works. - */ - if (*target_msc > 0) - *target_msc -= flip; - - /* If non-pageflipping, but blitting/exchanging, we need to use - * DRM_VBLANK_NEXTONMISS to avoid unreliable timestamping later - * on. - */ - if (flip == 0) - ms_flag |= MS_QUEUE_NEXT_ON_MISS; - - /* - * If divisor is zero, or current_msc is smaller than target_msc - * we just need to make sure target_msc passes before initiating - * the swap. - */ - if (divisor == 0 || current_msc < *target_msc) { - - /* If target_msc already reached or passed, set it to - * current_msc to ensure we return a reasonable value back - * to the caller. This makes swap_interval logic more robust. - */ - if (current_msc >= *target_msc) - *target_msc = current_msc; - - seq = ms_drm_queue_alloc(crtc, frame_info, - ms_dri2_frame_event_handler, - ms_dri2_frame_event_abort); - if (!seq) - goto blit_fallback; - - if (!ms_queue_vblank(crtc, ms_flag, *target_msc, &queued_msc, seq)) { - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "divisor 0 get vblank counter failed: %s\n", - strerror(errno)); - goto blit_fallback; - } - - *target_msc = queued_msc + flip; - frame_info->frame = *target_msc; - - return TRUE; - } - - /* - * If we get here, target_msc has already passed or we don't have one, - * and we need to queue an event that will satisfy the divisor/remainder - * equation. - */ - - request_msc = current_msc - (current_msc % divisor) + - remainder; - - /* - * If the calculated deadline vbl.request.sequence is smaller than - * or equal to current_msc, it means we've passed the last point - * when effective onset frame seq could satisfy - * seq % divisor == remainder, so we need to wait for the next time - * this will happen. - - * This comparison takes the DRM_VBLANK_NEXTONMISS delay into account. - */ - if (request_msc <= current_msc) - request_msc += divisor; - - seq = ms_drm_queue_alloc(crtc, frame_info, - ms_dri2_frame_event_handler, - ms_dri2_frame_event_abort); - if (!seq) - goto blit_fallback; - - /* Account for 1 frame extra pageflip delay if flip > 0 */ - if (!ms_queue_vblank(crtc, ms_flag, request_msc - flip, &queued_msc, seq)) { - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "final get vblank counter failed: %s\n", - strerror(errno)); - goto blit_fallback; - } - - /* Adjust returned value for 1 fame pageflip offset of flip > 0 */ - *target_msc = queued_msc + flip; - frame_info->frame = *target_msc; - - return TRUE; - - blit_fallback: - ms_dri2_blit_swap(draw, front, back); - DRI2SwapComplete(client, draw, 0, 0, 0, DRI2_BLIT_COMPLETE, func, data); - if (frame_info) - ms_dri2_del_frame_event(frame_info); - *target_msc = 0; /* offscreen, so zero out target vblank count */ - return TRUE; -} - -static int -ms_dri2_frame_event_client_gone(void *data, XID id) -{ - struct ms_dri2_resource *resource = data; - - while (!xorg_list_is_empty(&resource->list)) { - ms_dri2_frame_event_ptr info = - xorg_list_first_entry(&resource->list, - ms_dri2_frame_event_rec, - client_resource); - - xorg_list_del(&info->client_resource); - info->client = NULL; - } - free(resource); - - return Success; -} - -static int -ms_dri2_frame_event_drawable_gone(void *data, XID id) -{ - struct ms_dri2_resource *resource = data; - - while (!xorg_list_is_empty(&resource->list)) { - ms_dri2_frame_event_ptr info = - xorg_list_first_entry(&resource->list, - ms_dri2_frame_event_rec, - drawable_resource); - - xorg_list_del(&info->drawable_resource); - info->drawable = NULL; - } - free(resource); - - return Success; -} - -static Bool -ms_dri2_register_frame_event_resource_types(void) -{ - frame_event_client_type = - CreateNewResourceType(ms_dri2_frame_event_client_gone, - "Frame Event Client"); - if (!frame_event_client_type) - return FALSE; - - frame_event_drawable_type = - CreateNewResourceType(ms_dri2_frame_event_drawable_gone, - "Frame Event Drawable"); - if (!frame_event_drawable_type) - return FALSE; - - return TRUE; -} - -Bool -ms_dri2_screen_init(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - DRI2InfoRec info; - const char *driver_names[2] = { NULL, NULL }; - - if (!ms->glamor.supports_pixmap_import_export(screen)) { - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "DRI2: glamor lacks support for pixmap import/export\n"); - } - - if (!xf86LoaderCheckSymbol("DRI2Version")) - return FALSE; - - if (!dixRegisterPrivateKey(&ms_dri2_client_key, - PRIVATE_CLIENT, sizeof(XID))) - return FALSE; - - if (serverGeneration != ms_dri2_server_generation) { - ms_dri2_server_generation = serverGeneration; - if (!ms_dri2_register_frame_event_resource_types()) { - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "Cannot register DRI2 frame event resources\n"); - return FALSE; - } - } - - memset(&info, '\0', sizeof(info)); - info.fd = ms->fd; - info.driverName = NULL; /* Compat field, unused. */ - info.deviceName = drmGetDeviceNameFromFd(ms->fd); - - info.version = 9; - info.CreateBuffer = ms_dri2_create_buffer; - info.DestroyBuffer = ms_dri2_destroy_buffer; - info.CopyRegion = ms_dri2_copy_region; - info.ScheduleSwap = ms_dri2_schedule_swap; - info.GetMSC = ms_dri2_get_msc; - info.ScheduleWaitMSC = ms_dri2_schedule_wait_msc; - info.CreateBuffer2 = ms_dri2_create_buffer2; - info.DestroyBuffer2 = ms_dri2_destroy_buffer2; - info.CopyRegion2 = ms_dri2_copy_region2; - - /* Ask Glamor to obtain the DRI driver name via EGL_MESA_query_driver, */ - if (ms->glamor.egl_get_driver_name) - driver_names[0] = ms->glamor.egl_get_driver_name(screen); - - if (driver_names[0]) { - /* There is no VDPAU driver for Intel, fallback to the generic - * OpenGL/VAAPI va_gl backend to emulate VDPAU. Otherwise, - * guess that the DRI and VDPAU drivers have the same name. - */ - if (strcmp(driver_names[0], "i965") == 0 || - strcmp(driver_names[0], "iris") == 0 || - strcmp(driver_names[0], "crocus") == 0) { - driver_names[1] = "va_gl"; - } else { - driver_names[1] = driver_names[0]; - } - - info.numDrivers = 2; - info.driverNames = driver_names; - } else { - /* EGL_MESA_query_driver was unavailable; let dri2.c select the - * driver and fill in these fields for us. - */ - info.numDrivers = 0; - info.driverNames = NULL; - } - - return DRI2ScreenInit(screen, &info); -} - -void -ms_dri2_close_screen(ScreenPtr screen) -{ - DRI2CloseScreen(screen); -} - -#endif /* GLAMOR_HAS_GBM */ diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c deleted file mode 100644 index fe3315a9c..000000000 --- a/hw/xfree86/drivers/modesetting/driver.c +++ /dev/null @@ -1,2178 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * Copyright 2011 Dave Airlie - * Copyright 2019 NVIDIA CORPORATION - * All Rights Reserved. - * - * 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, 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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Original Author: Alan Hourihane - * Rewrite: Dave Airlie - * Additional contributors: - * Aaron Plattner - * - */ - -#ifdef HAVE_DIX_CONFIG_H -#include "dix-config.h" -#endif - -#include -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSproc.h" -#include "compiler.h" -#include "xf86Pci.h" -#include "mipointer.h" -#include "mipointrst.h" -#include "micmap.h" -#include -#include "fb.h" -#include "edid.h" -#include "xf86i2c.h" -#include "xf86Crtc.h" -#include "miscstruct.h" -#include "dixstruct.h" -#include "xf86xv.h" -#include -#include -#ifdef XSERVER_PLATFORM_BUS -#include "xf86platformBus.h" -#endif -#ifdef XSERVER_LIBPCIACCESS -#include -#endif -#include "driver.h" - -static void AdjustFrame(ScrnInfoPtr pScrn, int x, int y); -static Bool CloseScreen(ScreenPtr pScreen); -static Bool EnterVT(ScrnInfoPtr pScrn); -static void Identify(int flags); -static const OptionInfoRec *AvailableOptions(int chipid, int busid); -static ModeStatus ValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, - Bool verbose, int flags); -static void FreeScreen(ScrnInfoPtr pScrn); -static void LeaveVT(ScrnInfoPtr pScrn); -static Bool SwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode); -static Bool ScreenInit(ScreenPtr pScreen, int argc, char **argv); -static Bool PreInit(ScrnInfoPtr pScrn, int flags); - -static Bool Probe(DriverPtr drv, int flags); -static Bool ms_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *device, - intptr_t match_data); -static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data); - -/* window wrapper functions used to get the notification when - * the window property changes */ -static Atom vrr_atom; -static Bool property_vectors_wrapped; -static Bool restore_property_vector; -static int (*saved_change_property) (ClientPtr client); -static int (*saved_delete_property) (ClientPtr client); - -#ifdef XSERVER_LIBPCIACCESS -static const struct pci_id_match ms_device_match[] = { - { - PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, - 0x00030000, 0x00ff0000, 0}, - - {0, 0, 0}, -}; -#endif - -#ifndef XSERVER_PLATFORM_BUS -struct xf86_platform_device; -#endif - -#ifdef XSERVER_PLATFORM_BUS -static Bool ms_platform_probe(DriverPtr driver, - int entity_num, int flags, - struct xf86_platform_device *device, - intptr_t match_data); -#endif - -_X_EXPORT DriverRec modesetting = { - 1, - "modesetting", - Identify, - Probe, - AvailableOptions, - NULL, - 0, - ms_driver_func, - ms_device_match, - ms_pci_probe, -#ifdef XSERVER_PLATFORM_BUS - ms_platform_probe, -#endif -}; - -static SymTabRec Chipsets[] = { - {0, "kms"}, - {-1, NULL} -}; - -static const OptionInfoRec Options[] = { - {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE}, - {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_ACCEL_METHOD, "AccelMethod", OPTV_STRING, {0}, FALSE}, - {OPTION_PAGEFLIP, "PageFlip", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_ZAPHOD_HEADS, "ZaphodHeads", OPTV_STRING, {0}, FALSE}, - {OPTION_DOUBLE_SHADOW, "DoubleShadow", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_ATOMIC, "Atomic", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_VARIABLE_REFRESH, "VariableRefresh", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_USE_GAMMA_LUT, "UseGammaLUT", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_ASYNC_FLIP_SECONDARIES, "AsyncFlipSecondaries", OPTV_BOOLEAN, {0}, FALSE}, - {-1, NULL, OPTV_NONE, {0}, FALSE} -}; - -int ms_entity_index = -1; - -static MODULESETUPPROTO(Setup); - -static XF86ModuleVersionInfo VersRec = { - "modesetting", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - XORG_VERSION_MAJOR, - XORG_VERSION_MINOR, - XORG_VERSION_PATCH, - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_VIDEODRV, - {0, 0, 0, 0} -}; - -_X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL }; - -static void * -Setup(void *module, void *opts, int *errmaj, int *errmin) -{ - static Bool setupDone = 0; - - /* This module should be loaded only once, but check to be sure. - */ - if (!setupDone) { - setupDone = 1; - xf86AddDriver(&modesetting, module, HaveDriverFuncs); - - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (void *) 1; - } - else { - if (errmaj) - *errmaj = LDR_ONCEONLY; - return NULL; - } -} - -static void -Identify(int flags) -{ - xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers", - Chipsets); -} - -modesettingEntPtr ms_ent_priv(ScrnInfoPtr scrn) -{ - DevUnion *pPriv; - modesettingPtr ms = modesettingPTR(scrn); - pPriv = xf86GetEntityPrivate(ms->pEnt->index, - ms_entity_index); - return pPriv->ptr; -} - -static int -get_passed_fd(void) -{ - if (xf86DRMMasterFd >= 0) { - xf86DrvMsg(-1, X_INFO, "Using passed DRM master file descriptor %d\n", xf86DRMMasterFd); - return dup(xf86DRMMasterFd); - } - return -1; -} - -static int -open_hw(const char *dev) -{ - int fd; - - if ((fd = get_passed_fd()) != -1) - return fd; - - if (dev) - fd = open(dev, O_RDWR | O_CLOEXEC, 0); - else { - dev = getenv("KMSDEVICE"); - if ((NULL == dev) || ((fd = open(dev, O_RDWR | O_CLOEXEC, 0)) == -1)) { - dev = "/dev/dri/card0"; - fd = open(dev, O_RDWR | O_CLOEXEC, 0); - } - } - if (fd == -1) - xf86DrvMsg(-1, X_ERROR, "open %s: %s\n", dev, strerror(errno)); - - return fd; -} - -static int -check_outputs(int fd, int *count) -{ - drmModeResPtr res = drmModeGetResources(fd); - int ret; - - if (!res) - return FALSE; - - if (count) - *count = res->count_connectors; - - ret = res->count_connectors > 0; -#if defined(GLAMOR_HAS_GBM_LINEAR) - if (ret == FALSE) { - uint64_t value = 0; - if (drmGetCap(fd, DRM_CAP_PRIME, &value) == 0 && - (value & DRM_PRIME_CAP_EXPORT)) - ret = TRUE; - } -#endif - drmModeFreeResources(res); - return ret; -} - -static Bool -probe_hw(const char *dev, struct xf86_platform_device *platform_dev) -{ - int fd; - -#ifdef XF86_PDEV_SERVER_FD - if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) { - fd = xf86_platform_device_odev_attributes(platform_dev)->fd; - if (fd == -1) - return FALSE; - return check_outputs(fd, NULL); - } -#endif - - fd = open_hw(dev); - if (fd != -1) { - int ret = check_outputs(fd, NULL); - - close(fd); - return ret; - } - return FALSE; -} - -static char * -ms_DRICreatePCIBusID(const struct pci_device *dev) -{ - char *busID; - - if (asprintf(&busID, "pci:%04x:%02x:%02x.%d", - dev->domain, dev->bus, dev->dev, dev->func) == -1) - return NULL; - - return busID; -} - -static Bool -probe_hw_pci(const char *dev, struct pci_device *pdev) -{ - int ret = FALSE, fd = open_hw(dev); - char *id, *devid; - drmSetVersion sv; - - if (fd == -1) - return FALSE; - - sv.drm_di_major = 1; - sv.drm_di_minor = 4; - sv.drm_dd_major = -1; - sv.drm_dd_minor = -1; - if (drmSetInterfaceVersion(fd, &sv)) { - close(fd); - return FALSE; - } - - id = drmGetBusid(fd); - devid = ms_DRICreatePCIBusID(pdev); - - if (id && devid && !strcmp(id, devid)) - ret = check_outputs(fd, NULL); - - close(fd); - free(id); - free(devid); - return ret; -} - -static const OptionInfoRec * -AvailableOptions(int chipid, int busid) -{ - return Options; -} - -static Bool -ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data) -{ - xorgHWFlags *flag; - - switch (op) { - case GET_REQUIRED_HW_INTERFACES: - flag = (CARD32 *) data; - (*flag) = 0; - return TRUE; - case SUPPORTS_SERVER_FDS: - return TRUE; - default: - return FALSE; - } -} - -static void -ms_setup_scrn_hooks(ScrnInfoPtr scrn) -{ - scrn->driverVersion = 1; - scrn->driverName = "modesetting"; - scrn->name = "modeset"; - - scrn->Probe = NULL; - scrn->PreInit = PreInit; - scrn->ScreenInit = ScreenInit; - scrn->SwitchMode = SwitchMode; - scrn->AdjustFrame = AdjustFrame; - scrn->EnterVT = EnterVT; - scrn->LeaveVT = LeaveVT; - scrn->FreeScreen = FreeScreen; - scrn->ValidMode = ValidMode; -} - -static void -ms_setup_entity(ScrnInfoPtr scrn, int entity_num) -{ - DevUnion *pPriv; - - xf86SetEntitySharable(entity_num); - - if (ms_entity_index == -1) - ms_entity_index = xf86AllocateEntityPrivateIndex(); - - pPriv = xf86GetEntityPrivate(entity_num, - ms_entity_index); - - xf86SetEntityInstanceForScreen(scrn, entity_num, xf86GetNumEntityInstances(entity_num) - 1); - - if (!pPriv->ptr) - pPriv->ptr = xnfcalloc(sizeof(modesettingEntRec), 1); -} - -#ifdef XSERVER_LIBPCIACCESS -static Bool -ms_pci_probe(DriverPtr driver, - int entity_num, struct pci_device *dev, intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - - scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL, - NULL, NULL, NULL, NULL, NULL); - if (scrn) { - const char *devpath; - GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0], - scrn->entityInstanceList[0]); - - devpath = xf86FindOptionValue(devSection->options, "kmsdev"); - if (probe_hw_pci(devpath, dev)) { - ms_setup_scrn_hooks(scrn); - - xf86DrvMsg(scrn->scrnIndex, X_CONFIG, - "claimed PCI slot %d@%d:%d:%d\n", - dev->bus, dev->domain, dev->dev, dev->func); - xf86DrvMsg(scrn->scrnIndex, X_INFO, - "using %s\n", devpath ? devpath : "default device"); - - ms_setup_entity(scrn, entity_num); - } - else - scrn = NULL; - } - return scrn != NULL; -} -#endif - -#ifdef XSERVER_PLATFORM_BUS -static Bool -ms_platform_probe(DriverPtr driver, - int entity_num, int flags, struct xf86_platform_device *dev, - intptr_t match_data) -{ - ScrnInfoPtr scrn = NULL; - const char *path = xf86_platform_device_odev_attributes(dev)->path; - int scr_flags = 0; - - if (flags & PLATFORM_PROBE_GPU_SCREEN) - scr_flags = XF86_ALLOCATE_GPU_SCREEN; - - if (probe_hw(path, dev)) { - scrn = xf86AllocateScreen(driver, scr_flags); - if (xf86IsEntitySharable(entity_num)) - xf86SetEntityShared(entity_num); - xf86AddEntityToScreen(scrn, entity_num); - - ms_setup_scrn_hooks(scrn); - - xf86DrvMsg(scrn->scrnIndex, X_INFO, - "using drv %s\n", path ? path : "default device"); - - ms_setup_entity(scrn, entity_num); - } - - return scrn != NULL; -} -#endif - -static Bool -Probe(DriverPtr drv, int flags) -{ - int i, numDevSections; - GDevPtr *devSections; - Bool foundScreen = FALSE; - const char *dev; - ScrnInfoPtr scrn = NULL; - - /* For now, just bail out for PROBE_DETECT. */ - if (flags & PROBE_DETECT) - return FALSE; - - /* - * Find the config file Device sections that match this - * driver, and return if there are none. - */ - if ((numDevSections = xf86MatchDevice("modesetting", &devSections)) <= 0) { - return FALSE; - } - - for (i = 0; i < numDevSections; i++) { - int entity_num; - dev = xf86FindOptionValue(devSections[i]->options, "kmsdev"); - if (probe_hw(dev, NULL)) { - - entity_num = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE); - scrn = xf86ConfigFbEntity(scrn, 0, entity_num, NULL, NULL, NULL, NULL); - } - - if (scrn) { - foundScreen = TRUE; - ms_setup_scrn_hooks(scrn); - scrn->Probe = Probe; - - xf86DrvMsg(scrn->scrnIndex, X_INFO, - "using %s\n", dev ? dev : "default device"); - ms_setup_entity(scrn, entity_num); - } - } - - free(devSections); - - return foundScreen; -} - -static Bool -GetRec(ScrnInfoPtr pScrn) -{ - if (pScrn->driverPrivate) - return TRUE; - - pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1); - - return TRUE; -} - -static void -rotate_clip(PixmapPtr pixmap, BoxPtr rect, drmModeClip *clip, Rotation rotation) -{ - int w = pixmap->drawable.width; - int h = pixmap->drawable.height; - - if (rotation == RR_Rotate_90) { - /* Rotate 90 degrees counter clockwise */ - clip->x1 = rect->y1; - clip->x2 = rect->y2; - clip->y1 = w - rect->x2; - clip->y2 = w - rect->x1; - } else if (rotation == RR_Rotate_180) { - /* Rotate 180 degrees */ - clip->x1 = w - rect->x2; - clip->x2 = w - rect->x1; - clip->y1 = h - rect->y2; - clip->y2 = h - rect->y1; - } else if (rotation == RR_Rotate_270) { - /* Rotate 90 degrees clockwise */ - clip->x1 = h - rect->y2; - clip->x2 = h - rect->y1; - clip->y1 = rect->x1; - clip->y2 = rect->x2; - } else { - clip->x1 = rect->x1; - clip->x2 = rect->x2; - clip->y1 = rect->y1; - clip->y2 = rect->y2; - } -} - -static int -dispatch_dirty_region(ScrnInfoPtr scrn, xf86CrtcPtr crtc, - PixmapPtr pixmap, DamagePtr damage, int fb_id) -{ - modesettingPtr ms = modesettingPTR(scrn); - RegionPtr dirty = DamageRegion(damage); - unsigned num_cliprects = REGION_NUM_RECTS(dirty); - int ret = 0; - - if (num_cliprects) { - drmModeClip *clip = xallocarray(num_cliprects, sizeof(drmModeClip)); - BoxPtr rect = REGION_RECTS(dirty); - int i; - - if (!clip) - return -ENOMEM; - - /* Rotate and copy rects into clips */ - for (i = 0; i < num_cliprects; i++, rect++) - rotate_clip(pixmap, rect, &clip[i], crtc->rotation); - - /* TODO query connector property to see if this is needed */ - ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects); - - /* if we're swamping it with work, try one at a time */ - if (ret == -EINVAL) { - for (i = 0; i < num_cliprects; i++) { - if ((ret = drmModeDirtyFB(ms->fd, fb_id, &clip[i], 1)) < 0) - break; - } - } - - free(clip); - DamageEmpty(damage); - } - return ret; -} - -static void -dispatch_dirty(ScreenPtr pScreen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - modesettingPtr ms = modesettingPTR(scrn); - PixmapPtr pixmap = pScreen->GetScreenPixmap(pScreen); - uint32_t fb_id; - int ret, c, x, y ; - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - if (!drmmode_crtc) - continue; - - drmmode_crtc_get_fb_id(crtc, &fb_id, &x, &y); - - ret = dispatch_dirty_region(scrn, crtc, pixmap, ms->damage, fb_id); - if (ret == -EINVAL || ret == -ENOSYS) { - ms->dirty_enabled = FALSE; - DamageUnregister(ms->damage); - DamageDestroy(ms->damage); - ms->damage = NULL; - xf86DrvMsg(scrn->scrnIndex, X_INFO, - "Disabling kernel dirty updates, not required.\n"); - return; - } - } -} - -static void -dispatch_dirty_pixmap(ScrnInfoPtr scrn, xf86CrtcPtr crtc, PixmapPtr ppix) -{ - modesettingPtr ms = modesettingPTR(scrn); - msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, ppix); - DamagePtr damage = ppriv->secondary_damage; - int fb_id = ppriv->fb_id; - - dispatch_dirty_region(scrn, crtc, ppix, damage, fb_id); -} - -static void -dispatch_secondary_dirty(ScreenPtr pScreen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - if (!drmmode_crtc) - continue; - - if (drmmode_crtc->prime_pixmap) - dispatch_dirty_pixmap(scrn, crtc, drmmode_crtc->prime_pixmap); - if (drmmode_crtc->prime_pixmap_back) - dispatch_dirty_pixmap(scrn, crtc, drmmode_crtc->prime_pixmap_back); - } -} - -static void -redisplay_dirty(ScreenPtr screen, PixmapDirtyUpdatePtr dirty, int *timeout) -{ - RegionRec pixregion; - - PixmapRegionInit(&pixregion, dirty->secondary_dst); - DamageRegionAppend(&dirty->secondary_dst->drawable, &pixregion); - PixmapSyncDirtyHelper(dirty); - - if (!screen->isGPU) { -#ifdef GLAMOR_HAS_GBM - modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(screen)); - /* - * When copying from the primary framebuffer to the shared pixmap, - * we must ensure the copy is complete before the secondary starts a - * copy to its own framebuffer (some secondarys scanout directly from - * the shared pixmap, but not all). - */ - if (ms->drmmode.glamor) - ms->glamor.finish(screen); -#endif - /* Ensure the secondary processes the damage immediately */ - if (timeout) - *timeout = 0; - } - - DamageRegionProcessPending(&dirty->secondary_dst->drawable); - RegionUninit(&pixregion); -} - -static void -ms_dirty_update(ScreenPtr screen, int *timeout) -{ - modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(screen)); - - RegionPtr region; - PixmapDirtyUpdatePtr ent; - - if (xorg_list_is_empty(&screen->pixmap_dirty_list)) - return; - - xorg_list_for_each_entry(ent, &screen->pixmap_dirty_list, ent) { - region = DamageRegion(ent->damage); - if (RegionNotEmpty(region)) { - if (!screen->isGPU) { - msPixmapPrivPtr ppriv = - msGetPixmapPriv(&ms->drmmode, ent->secondary_dst->primary_pixmap); - - if (ppriv->notify_on_damage) { - ppriv->notify_on_damage = FALSE; - - ent->secondary_dst->drawable.pScreen-> - SharedPixmapNotifyDamage(ent->secondary_dst); - } - - /* Requested manual updating */ - if (ppriv->defer_dirty_update) - continue; - } - - redisplay_dirty(screen, ent, timeout); - DamageEmpty(ent->damage); - } - } -} - -static PixmapDirtyUpdatePtr -ms_dirty_get_ent(ScreenPtr screen, PixmapPtr secondary_dst) -{ - PixmapDirtyUpdatePtr ent; - - if (xorg_list_is_empty(&screen->pixmap_dirty_list)) - return NULL; - - xorg_list_for_each_entry(ent, &screen->pixmap_dirty_list, ent) { - if (ent->secondary_dst == secondary_dst) - return ent; - } - - return NULL; -} - -static void -msBlockHandler(ScreenPtr pScreen, void *timeout) -{ - modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen)); - - pScreen->BlockHandler = ms->BlockHandler; - pScreen->BlockHandler(pScreen, timeout); - ms->BlockHandler = pScreen->BlockHandler; - pScreen->BlockHandler = msBlockHandler; - if (pScreen->isGPU && !ms->drmmode.reverse_prime_offload_mode) - dispatch_secondary_dirty(pScreen); - else if (ms->dirty_enabled) - dispatch_dirty(pScreen); - - ms_dirty_update(pScreen, timeout); -} - -static void -msBlockHandler_oneshot(ScreenPtr pScreen, void *pTimeout) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(pScrn); - - msBlockHandler(pScreen, pTimeout); - - drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE, FALSE); -} - -Bool -ms_window_has_variable_refresh(modesettingPtr ms, WindowPtr win) { - struct ms_vrr_priv *priv = dixLookupPrivate(&win->devPrivates, &ms->drmmode.vrrPrivateKeyRec); - - return priv->variable_refresh; -} - -static void -ms_vrr_property_update(WindowPtr window, Bool variable_refresh) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(window->drawable.pScreen); - modesettingPtr ms = modesettingPTR(scrn); - - struct ms_vrr_priv *priv = dixLookupPrivate(&window->devPrivates, - &ms->drmmode.vrrPrivateKeyRec); - priv->variable_refresh = variable_refresh; - - if (ms->flip_window == window && ms->drmmode.present_flipping) - ms_present_set_screen_vrr(scrn, variable_refresh); -} - -/* Wrapper for xserver/dix/property.c:ProcChangeProperty */ -static int -ms_change_property(ClientPtr client) -{ - WindowPtr window = NULL; - int ret = 0; - - REQUEST(xChangePropertyReq); - - client->requestVector[X_ChangeProperty] = saved_change_property; - ret = saved_change_property(client); - - if (restore_property_vector) - return ret; - - client->requestVector[X_ChangeProperty] = ms_change_property; - - if (ret != Success) - return ret; - - ret = dixLookupWindow(&window, stuff->window, client, DixSetPropAccess); - if (ret != Success) - return ret; - - // Checking for the VRR property change on the window - if (stuff->property == vrr_atom && - xf86ScreenToScrn(window->drawable.pScreen)->PreInit == PreInit && - stuff->format == 32 && stuff->nUnits == 1) { - uint32_t *value = (uint32_t *)(stuff + 1); - ms_vrr_property_update(window, *value != 0); - } - - return ret; -} - -/* Wrapper for xserver/dix/property.c:ProcDeleteProperty */ -static int -ms_delete_property(ClientPtr client) -{ - WindowPtr window; - int ret; - - REQUEST(xDeletePropertyReq); - - client->requestVector[X_DeleteProperty] = saved_delete_property; - ret = saved_delete_property(client); - - if (restore_property_vector) - return ret; - - client->requestVector[X_DeleteProperty] = ms_delete_property; - - if (ret != Success) - return ret; - - ret = dixLookupWindow(&window, stuff->window, client, DixSetPropAccess); - if (ret != Success) - return ret; - - if (stuff->property == vrr_atom && - xf86ScreenToScrn(window->drawable.pScreen)->PreInit == PreInit) - ms_vrr_property_update(window, FALSE); - - return ret; -} - -static void -ms_unwrap_property_requests(ScrnInfoPtr scrn) -{ - int i; - - if (!property_vectors_wrapped) - return; - - if (ProcVector[X_ChangeProperty] == ms_change_property) - ProcVector[X_ChangeProperty] = saved_change_property; - else - restore_property_vector = TRUE; - - if (ProcVector[X_DeleteProperty] == ms_delete_property) - ProcVector[X_DeleteProperty] = saved_delete_property; - else - restore_property_vector = TRUE; - - for (i = 0; i < currentMaxClients; i++) { - if (clients[i]->requestVector[X_ChangeProperty] == ms_change_property) { - clients[i]->requestVector[X_ChangeProperty] = saved_change_property; - } else { - restore_property_vector = TRUE; - } - - if (clients[i]->requestVector[X_DeleteProperty] == ms_delete_property) { - clients[i]->requestVector[X_DeleteProperty] = saved_delete_property; - } else { - restore_property_vector = TRUE; - } - } - - if (restore_property_vector) { - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "Couldn't unwrap some window property request vectors\n"); - } - - property_vectors_wrapped = FALSE; -} - -static void -FreeRec(ScrnInfoPtr pScrn) -{ - modesettingPtr ms; - - if (!pScrn) - return; - - ms = modesettingPTR(pScrn); - if (!ms) - return; - - if (ms->fd > 0) { - modesettingEntPtr ms_ent; - int ret; - - ms_ent = ms_ent_priv(pScrn); - ms_ent->fd_ref--; - if (!ms_ent->fd_ref) { - ms_unwrap_property_requests(pScrn); - if (ms->pEnt->location.type == BUS_PCI) - ret = drmClose(ms->fd); - else -#ifdef XF86_PDEV_SERVER_FD - if (!(ms->pEnt->location.type == BUS_PLATFORM && - (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))) -#endif - ret = close(ms->fd); - (void) ret; - ms_ent->fd = 0; - } - } - pScrn->driverPrivate = NULL; - free(ms->drmmode.Options); - free(ms); - -} - -#ifdef GLAMOR_HAS_GBM - -static Bool -load_glamor(ScrnInfoPtr pScrn) -{ - void *mod = xf86LoadSubModule(pScrn, GLAMOR_EGL_MODULE_NAME); - modesettingPtr ms = modesettingPTR(pScrn); - - if (!mod) - return FALSE; - - ms->glamor.back_pixmap_from_fd = LoaderSymbolFromModule(mod, "glamor_back_pixmap_from_fd"); - ms->glamor.block_handler = LoaderSymbolFromModule(mod, "glamor_block_handler"); - ms->glamor.clear_pixmap = LoaderSymbolFromModule(mod, "glamor_clear_pixmap"); - ms->glamor.egl_create_textured_pixmap = LoaderSymbolFromModule(mod, "glamor_egl_create_textured_pixmap"); - ms->glamor.egl_create_textured_pixmap_from_gbm_bo = LoaderSymbolFromModule(mod, "glamor_egl_create_textured_pixmap_from_gbm_bo"); - ms->glamor.egl_exchange_buffers = LoaderSymbolFromModule(mod, "glamor_egl_exchange_buffers"); - ms->glamor.egl_get_gbm_device = LoaderSymbolFromModule(mod, "glamor_egl_get_gbm_device"); - ms->glamor.egl_init = LoaderSymbolFromModule(mod, "glamor_egl_init"); - ms->glamor.finish = LoaderSymbolFromModule(mod, "glamor_finish"); - ms->glamor.gbm_bo_from_pixmap = LoaderSymbolFromModule(mod, "glamor_gbm_bo_from_pixmap"); - ms->glamor.init = LoaderSymbolFromModule(mod, "glamor_init"); - ms->glamor.name_from_pixmap = LoaderSymbolFromModule(mod, "glamor_name_from_pixmap"); - ms->glamor.set_drawable_modifiers_func = LoaderSymbolFromModule(mod, "glamor_set_drawable_modifiers_func"); - ms->glamor.shareable_fd_from_pixmap = LoaderSymbolFromModule(mod, "glamor_shareable_fd_from_pixmap"); - ms->glamor.supports_pixmap_import_export = LoaderSymbolFromModule(mod, "glamor_supports_pixmap_import_export"); - ms->glamor.xv_init = LoaderSymbolFromModule(mod, "glamor_xv_init"); - ms->glamor.egl_get_driver_name = LoaderSymbolFromModule(mod, "glamor_egl_get_driver_name"); - - return TRUE; -} - -#endif - -static void -try_enable_glamor(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - const char *accel_method_str = xf86GetOptValString(ms->drmmode.Options, - OPTION_ACCEL_METHOD); - Bool do_glamor = (!accel_method_str || - strcmp(accel_method_str, "glamor") == 0); - - ms->drmmode.glamor = FALSE; - -#ifdef GLAMOR_HAS_GBM - if (ms->drmmode.force_24_32) { - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Cannot use glamor with 24bpp packed fb\n"); - return; - } - - if (!do_glamor) { - xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "glamor disabled\n"); - return; - } - - if (load_glamor(pScrn)) { - if (ms->glamor.egl_init(pScrn, ms->fd)) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "glamor initialized\n"); - ms->drmmode.glamor = TRUE; - } else { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "glamor initialization failed\n"); - } - } else { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Failed to load glamor module.\n"); - } -#else - if (do_glamor) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "No glamor support in the X Server\n"); - } -#endif -} - -static Bool -msShouldDoubleShadow(ScrnInfoPtr pScrn, modesettingPtr ms) -{ - Bool ret = FALSE, asked; - int from; - drmVersionPtr v = drmGetVersion(ms->fd); - - if (!ms->drmmode.shadow_enable) - return FALSE; - - if (!strcmp(v->name, "mgag200") || - !strcmp(v->name, "ast")) /* XXX || rn50 */ - ret = TRUE; - - drmFreeVersion(v); - - asked = xf86GetOptValBool(ms->drmmode.Options, OPTION_DOUBLE_SHADOW, &ret); - - if (asked) - from = X_CONFIG; - else - from = X_INFO; - - xf86DrvMsg(pScrn->scrnIndex, from, - "Double-buffered shadow updates: %s\n", ret ? "on" : "off"); - - return ret; -} - -static Bool -ms_get_drm_master_fd(ScrnInfoPtr pScrn) -{ - EntityInfoPtr pEnt; - modesettingPtr ms; - modesettingEntPtr ms_ent; - - ms = modesettingPTR(pScrn); - ms_ent = ms_ent_priv(pScrn); - - pEnt = ms->pEnt; - - if (ms_ent->fd) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - " reusing fd for second head\n"); - ms->fd = ms_ent->fd; - ms_ent->fd_ref++; - return TRUE; - } - - ms->fd_passed = FALSE; - if ((ms->fd = get_passed_fd()) >= 0) { - ms->fd_passed = TRUE; - return TRUE; - } - -#ifdef XSERVER_PLATFORM_BUS - if (pEnt->location.type == BUS_PLATFORM) { -#ifdef XF86_PDEV_SERVER_FD - if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD) - ms->fd = - xf86_platform_device_odev_attributes(pEnt->location.id.plat)-> - fd; - else -#endif - { - char *path = - xf86_platform_device_odev_attributes(pEnt->location.id.plat)-> - path; - ms->fd = open_hw(path); - } - } - else -#endif -#ifdef XSERVER_LIBPCIACCESS - if (pEnt->location.type == BUS_PCI) { - char *BusID = NULL; - struct pci_device *PciInfo; - - PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index); - if (PciInfo) { - if ((BusID = ms_DRICreatePCIBusID(PciInfo)) != NULL) { - ms->fd = drmOpen(NULL, BusID); - free(BusID); - } - } - } - else -#endif - { - const char *devicename; - devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev"); - ms->fd = open_hw(devicename); - } - if (ms->fd < 0) - return FALSE; - - ms_ent->fd = ms->fd; - ms_ent->fd_ref = 1; - return TRUE; -} - -static Bool -PreInit(ScrnInfoPtr pScrn, int flags) -{ - modesettingPtr ms; - rgb defaultWeight = { 0, 0, 0 }; - EntityInfoPtr pEnt; - uint64_t value = 0; - int ret; - int bppflags, connector_count; - int defaultdepth, defaultbpp; - - if (pScrn->numEntities != 1) - return FALSE; - - if (flags & PROBE_DETECT) { - return FALSE; - } - - /* Allocate driverPrivate */ - if (!GetRec(pScrn)) - return FALSE; - - pEnt = xf86GetEntityInfo(pScrn->entityList[0]); - - ms = modesettingPTR(pScrn); - ms->SaveGeneration = -1; - ms->pEnt = pEnt; - ms->drmmode.is_secondary = FALSE; - pScrn->displayWidth = 640; /* default it */ - - if (xf86IsEntityShared(pScrn->entityList[0])) { - if (xf86IsPrimInitDone(pScrn->entityList[0])) - ms->drmmode.is_secondary = TRUE; - else - xf86SetPrimInitDone(pScrn->entityList[0]); - } - - pScrn->monitor = pScrn->confScreen->monitor; - pScrn->progClock = TRUE; - pScrn->rgbBits = 8; - - if (!ms_get_drm_master_fd(pScrn)) - return FALSE; - ms->drmmode.fd = ms->fd; - - if (!check_outputs(ms->fd, &connector_count)) - return FALSE; - - drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp); - if (defaultdepth == 24 && defaultbpp == 24) { - ms->drmmode.force_24_32 = TRUE; - ms->drmmode.kbpp = 24; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Using 24bpp hw front buffer with 32bpp shadow\n"); - defaultbpp = 32; - } else { - ms->drmmode.kbpp = 0; - } - bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb; - - if (!xf86SetDepthBpp - (pScrn, defaultdepth, defaultdepth, defaultbpp, bppflags)) - return FALSE; - - switch (pScrn->depth) { - case 15: - case 16: - case 24: - case 30: - break; - default: - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Given depth (%d) is not supported by the driver\n", - pScrn->depth); - return FALSE; - } - xf86PrintDepthBpp(pScrn); - if (!ms->drmmode.kbpp) - ms->drmmode.kbpp = pScrn->bitsPerPixel; - - /* Process the options */ - xf86CollectOptions(pScrn, NULL); - if (!(ms->drmmode.Options = malloc(sizeof(Options)))) - return FALSE; - memcpy(ms->drmmode.Options, Options, sizeof(Options)); - xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->drmmode.Options); - - if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight)) - return FALSE; - if (!xf86SetDefaultVisual(pScrn, -1)) - return FALSE; - - if (xf86ReturnOptValBool(ms->drmmode.Options, OPTION_SW_CURSOR, FALSE)) { - ms->drmmode.sw_cursor = TRUE; - } - - ms->cursor_width = 64; - ms->cursor_height = 64; - ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_WIDTH, &value); - if (!ret) { - ms->cursor_width = value; - } - ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_HEIGHT, &value); - if (!ret) { - ms->cursor_height = value; - } - - try_enable_glamor(pScrn); - - if (!ms->drmmode.glamor) { - Bool prefer_shadow = TRUE; - - if (ms->drmmode.force_24_32) { - prefer_shadow = TRUE; - ms->drmmode.shadow_enable = TRUE; - } else { - ret = drmGetCap(ms->fd, DRM_CAP_DUMB_PREFER_SHADOW, &value); - if (!ret) { - prefer_shadow = !!value; - } - - ms->drmmode.shadow_enable = - xf86ReturnOptValBool(ms->drmmode.Options, OPTION_SHADOW_FB, - prefer_shadow); - } - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "ShadowFB: preferred %s, enabled %s\n", - prefer_shadow ? "YES" : "NO", - ms->drmmode.force_24_32 ? "FORCE" : - ms->drmmode.shadow_enable ? "YES" : "NO"); - - ms->drmmode.shadow_enable2 = msShouldDoubleShadow(pScrn, ms); - } else { - if (!pScrn->is_gpu) { - MessageType from = xf86GetOptValBool(ms->drmmode.Options, OPTION_VARIABLE_REFRESH, - &ms->vrr_support) ? X_CONFIG : X_DEFAULT; - xf86DrvMsg(pScrn->scrnIndex, from, "VariableRefresh: %sabled\n", - ms->vrr_support ? "en" : "dis"); - - ms->drmmode.async_flip_secondaries = FALSE; - from = xf86GetOptValBool(ms->drmmode.Options, OPTION_ASYNC_FLIP_SECONDARIES, - &ms->drmmode.async_flip_secondaries) ? X_CONFIG : X_DEFAULT; - xf86DrvMsg(pScrn->scrnIndex, from, "AsyncFlipSecondaries: %sabled\n", - ms->drmmode.async_flip_secondaries ? "en" : "dis"); - } - } - - ms->drmmode.pageflip = - xf86ReturnOptValBool(ms->drmmode.Options, OPTION_PAGEFLIP, TRUE); - - pScrn->capabilities = 0; - ret = drmGetCap(ms->fd, DRM_CAP_PRIME, &value); - if (ret == 0) { - if (connector_count && (value & DRM_PRIME_CAP_IMPORT)) { - pScrn->capabilities |= RR_Capability_SinkOutput; - if (ms->drmmode.glamor) - pScrn->capabilities |= RR_Capability_SinkOffload; - } -#ifdef GLAMOR_HAS_GBM_LINEAR - if (value & DRM_PRIME_CAP_EXPORT && ms->drmmode.glamor) - pScrn->capabilities |= RR_Capability_SourceOutput | RR_Capability_SourceOffload; -#endif - } - - /* - * Use "atomic modesetting disable" request to detect if the kms driver is - * atomic capable, regardless if we will actually use atomic modesetting. - * This is effectively a no-op, we only care about the return status code. - */ - ret = drmSetClientCap(ms->fd, DRM_CLIENT_CAP_ATOMIC, 0); - ms->atomic_modeset_capable = (ret == 0); - - if (xf86ReturnOptValBool(ms->drmmode.Options, OPTION_ATOMIC, FALSE)) { - ret = drmSetClientCap(ms->fd, DRM_CLIENT_CAP_ATOMIC, 1); - ms->atomic_modeset = (ret == 0); - } else { - ms->atomic_modeset = FALSE; - } - - ms->kms_has_modifiers = FALSE; - ret = drmGetCap(ms->fd, DRM_CAP_ADDFB2_MODIFIERS, &value); - if (ret == 0 && value != 0) - ms->kms_has_modifiers = TRUE; - - if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n"); - goto fail; - } - - /* - * If the driver can do gamma correction, it should call xf86SetGamma() here. - */ - { - Gamma zeros = { 0.0, 0.0, 0.0 }; - - if (!xf86SetGamma(pScrn, zeros)) { - return FALSE; - } - } - - if (!(pScrn->is_gpu && connector_count == 0) && pScrn->modes == NULL) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n"); - return FALSE; - } - - pScrn->currentMode = pScrn->modes; - - /* Set display resolution */ - xf86SetDpi(pScrn, 0, 0); - - /* Load the required sub modules */ - if (!xf86LoadSubModule(pScrn, "fb")) { - return FALSE; - } - - if (ms->drmmode.shadow_enable) { - void *mod = xf86LoadSubModule(pScrn, "shadow"); - - if (!mod) - return FALSE; - - ms->shadow.Setup = LoaderSymbolFromModule(mod, "shadowSetup"); - ms->shadow.Add = LoaderSymbolFromModule(mod, "shadowAdd"); - ms->shadow.Remove = LoaderSymbolFromModule(mod, "shadowRemove"); - ms->shadow.Update32to24 = LoaderSymbolFromModule(mod, "shadowUpdate32to24"); - ms->shadow.UpdatePacked = LoaderSymbolFromModule(mod, "shadowUpdatePacked"); - } - - return TRUE; - fail: - return FALSE; -} - -static void * -msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode, - CARD32 *size, void *closure) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(pScrn); - int stride; - - stride = (pScrn->displayWidth * ms->drmmode.kbpp) / 8; - *size = stride; - - return ((uint8_t *) ms->drmmode.front_bo.dumb->ptr + row * stride + offset); -} - -/* somewhat arbitrary tile size, in pixels */ -#define TILE 16 - -static int -msUpdateIntersect(modesettingPtr ms, shadowBufPtr pBuf, BoxPtr box, - xRectangle *prect) -{ - int i, dirty = 0, stride = pBuf->pPixmap->devKind, cpp = ms->drmmode.cpp; - int width = (box->x2 - box->x1) * cpp; - unsigned char *old, *new; - - old = ms->drmmode.shadow_fb2; - old += (box->y1 * stride) + (box->x1 * cpp); - new = ms->drmmode.shadow_fb; - new += (box->y1 * stride) + (box->x1 * cpp); - - for (i = box->y2 - box->y1 - 1; i >= 0; i--) { - unsigned char *o = old + i * stride, - *n = new + i * stride; - if (memcmp(o, n, width) != 0) { - dirty = 1; - memcpy(o, n, width); - } - } - - if (dirty) { - prect->x = box->x1; - prect->y = box->y1; - prect->width = box->x2 - box->x1; - prect->height = box->y2 - box->y1; - } - - return dirty; -} - -static void -msUpdatePacked(ScreenPtr pScreen, shadowBufPtr pBuf) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(pScrn); - Bool use_3224 = ms->drmmode.force_24_32 && pScrn->bitsPerPixel == 32; - - if (ms->drmmode.shadow_enable2 && ms->drmmode.shadow_fb2) do { - RegionPtr damage = DamageRegion(pBuf->pDamage), tiles; - BoxPtr extents = RegionExtents(damage); - xRectangle *prect; - int nrects; - int i, j, tx1, tx2, ty1, ty2; - - tx1 = extents->x1 / TILE; - tx2 = (extents->x2 + TILE - 1) / TILE; - ty1 = extents->y1 / TILE; - ty2 = (extents->y2 + TILE - 1) / TILE; - - nrects = (tx2 - tx1) * (ty2 - ty1); - if (!(prect = calloc(nrects, sizeof(xRectangle)))) - break; - - nrects = 0; - for (j = ty2 - 1; j >= ty1; j--) { - for (i = tx2 - 1; i >= tx1; i--) { - BoxRec box; - - box.x1 = max(i * TILE, extents->x1); - box.y1 = max(j * TILE, extents->y1); - box.x2 = min((i+1) * TILE, extents->x2); - box.y2 = min((j+1) * TILE, extents->y2); - - if (RegionContainsRect(damage, &box) != rgnOUT) { - if (msUpdateIntersect(ms, pBuf, &box, prect + nrects)) { - nrects++; - } - } - } - } - - tiles = RegionFromRects(nrects, prect, CT_NONE); - RegionIntersect(damage, damage, tiles); - RegionDestroy(tiles); - free(prect); - } while (0); - - if (use_3224) - ms->shadow.Update32to24(pScreen, pBuf); - else - ms->shadow.UpdatePacked(pScreen, pBuf); -} - -static Bool -msEnableSharedPixmapFlipping(RRCrtcPtr crtc, PixmapPtr front, PixmapPtr back) -{ - ScreenPtr screen = crtc->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - EntityInfoPtr pEnt = ms->pEnt; - xf86CrtcPtr xf86Crtc = crtc->devPrivate; - - if (!xf86Crtc) - return FALSE; - - /* Not supported if we can't flip */ - if (!ms->drmmode.pageflip) - return FALSE; - - /* Not currently supported with reverse PRIME */ - if (ms->drmmode.reverse_prime_offload_mode) - return FALSE; - -#ifdef XSERVER_PLATFORM_BUS - if (pEnt->location.type == BUS_PLATFORM) { - char *syspath = - xf86_platform_device_odev_attributes(pEnt->location.id.plat)-> - syspath; - - /* Not supported for devices using USB transport due to misbehaved - * vblank events */ - if (syspath && strstr(syspath, "usb")) - return FALSE; - - /* EVDI uses USB transport but is platform device, not usb. - * Exclude it explicitly. */ - if (syspath && strstr(syspath, "evdi")) - return FALSE; - } -#endif - - return drmmode_EnableSharedPixmapFlipping(xf86Crtc, &ms->drmmode, - front, back); -} - -static void -msDisableSharedPixmapFlipping(RRCrtcPtr crtc) -{ - ScreenPtr screen = crtc->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - xf86CrtcPtr xf86Crtc = crtc->devPrivate; - - if (xf86Crtc) - drmmode_DisableSharedPixmapFlipping(xf86Crtc, &ms->drmmode); -} - -static Bool -msStartFlippingPixmapTracking(RRCrtcPtr crtc, DrawablePtr src, - PixmapPtr secondary_dst1, PixmapPtr secondary_dst2, - int x, int y, int dst_x, int dst_y, - Rotation rotation) -{ - ScreenPtr pScreen = src->pScreen; - modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen)); - - msPixmapPrivPtr ppriv1 = msGetPixmapPriv(&ms->drmmode, secondary_dst1->primary_pixmap), - ppriv2 = msGetPixmapPriv(&ms->drmmode, secondary_dst2->primary_pixmap); - - if (!PixmapStartDirtyTracking(src, secondary_dst1, x, y, - dst_x, dst_y, rotation)) { - return FALSE; - } - - if (!PixmapStartDirtyTracking(src, secondary_dst2, x, y, - dst_x, dst_y, rotation)) { - PixmapStopDirtyTracking(src, secondary_dst1); - return FALSE; - } - - ppriv1->secondary_src = src; - ppriv2->secondary_src = src; - - ppriv1->dirty = ms_dirty_get_ent(pScreen, secondary_dst1); - ppriv2->dirty = ms_dirty_get_ent(pScreen, secondary_dst2); - - ppriv1->defer_dirty_update = TRUE; - ppriv2->defer_dirty_update = TRUE; - - return TRUE; -} - -static Bool -msPresentSharedPixmap(PixmapPtr secondary_dst) -{ - ScreenPtr pScreen = secondary_dst->primary_pixmap->drawable.pScreen; - modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen)); - - msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, secondary_dst->primary_pixmap); - - RegionPtr region = DamageRegion(ppriv->dirty->damage); - - if (RegionNotEmpty(region)) { - redisplay_dirty(ppriv->secondary_src->pScreen, ppriv->dirty, NULL); - DamageEmpty(ppriv->dirty->damage); - - return TRUE; - } - - return FALSE; -} - -static Bool -msStopFlippingPixmapTracking(DrawablePtr src, - PixmapPtr secondary_dst1, PixmapPtr secondary_dst2) -{ - ScreenPtr pScreen = src->pScreen; - modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen)); - - msPixmapPrivPtr ppriv1 = msGetPixmapPriv(&ms->drmmode, secondary_dst1->primary_pixmap), - ppriv2 = msGetPixmapPriv(&ms->drmmode, secondary_dst2->primary_pixmap); - - Bool ret = TRUE; - - ret &= PixmapStopDirtyTracking(src, secondary_dst1); - ret &= PixmapStopDirtyTracking(src, secondary_dst2); - - if (ret) { - ppriv1->secondary_src = NULL; - ppriv2->secondary_src = NULL; - - ppriv1->dirty = NULL; - ppriv2->dirty = NULL; - - ppriv1->defer_dirty_update = FALSE; - ppriv2->defer_dirty_update = FALSE; - } - - return ret; -} - -static Bool -CreateScreenResources(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(pScrn); - PixmapPtr rootPixmap; - Bool ret; - void *pixels = NULL; - int err; - - pScreen->CreateScreenResources = ms->createScreenResources; - ret = pScreen->CreateScreenResources(pScreen); - pScreen->CreateScreenResources = CreateScreenResources; - - if (!drmmode_set_desired_modes(pScrn, &ms->drmmode, pScrn->is_gpu, FALSE)) - return FALSE; - - if (!drmmode_glamor_handle_new_screen_pixmap(&ms->drmmode)) - return FALSE; - - drmmode_uevent_init(pScrn, &ms->drmmode); - - if (!ms->drmmode.sw_cursor) - drmmode_map_cursor_bos(pScrn, &ms->drmmode); - - if (!ms->drmmode.gbm) { - pixels = drmmode_map_front_bo(&ms->drmmode); - if (!pixels) - return FALSE; - } - - rootPixmap = pScreen->GetScreenPixmap(pScreen); - - if (ms->drmmode.shadow_enable) - pixels = ms->drmmode.shadow_fb; - - if (ms->drmmode.shadow_enable2) { - ms->drmmode.shadow_fb2 = calloc(1, pScrn->displayWidth * pScrn->virtualY * ((pScrn->bitsPerPixel + 7) >> 3)); - if (!ms->drmmode.shadow_fb2) - ms->drmmode.shadow_enable2 = FALSE; - } - - if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels)) - FatalError("Couldn't adjust screen pixmap\n"); - - if (ms->drmmode.shadow_enable) { - if (!ms->shadow.Add(pScreen, rootPixmap, msUpdatePacked, msShadowWindow, - 0, 0)) - return FALSE; - } - - err = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, NULL, 0); - - if (err != -EINVAL && err != -ENOSYS) { - ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE, - pScreen, rootPixmap); - - if (ms->damage) { - DamageRegister(&rootPixmap->drawable, ms->damage); - ms->dirty_enabled = TRUE; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Damage tracking initialized\n"); - } - else { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Failed to create screen damage record\n"); - return FALSE; - } - } - - if (dixPrivateKeyRegistered(rrPrivKey)) { - rrScrPrivPtr pScrPriv = rrGetScrPriv(pScreen); - - pScrPriv->rrEnableSharedPixmapFlipping = msEnableSharedPixmapFlipping; - pScrPriv->rrDisableSharedPixmapFlipping = msDisableSharedPixmapFlipping; - - pScrPriv->rrStartFlippingPixmapTracking = msStartFlippingPixmapTracking; - } - - if (ms->vrr_support && - !dixRegisterPrivateKey(&ms->drmmode.vrrPrivateKeyRec, - PRIVATE_WINDOW, - sizeof(struct ms_vrr_priv))) - return FALSE; - - return ret; -} - -static Bool -msSharePixmapBacking(PixmapPtr ppix, ScreenPtr secondary, void **handle) -{ -#ifdef GLAMOR_HAS_GBM - modesettingPtr ms = - modesettingPTR(xf86ScreenToScrn(ppix->drawable.pScreen)); - int ret; - CARD16 stride; - CARD32 size; - ret = ms->glamor.shareable_fd_from_pixmap(ppix->drawable.pScreen, ppix, - &stride, &size); - if (ret == -1) - return FALSE; - - *handle = (void *)(long)(ret); - return TRUE; -#endif - return FALSE; -} - -static Bool -msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle) -{ -#ifdef GLAMOR_HAS_GBM - ScreenPtr screen = ppix->drawable.pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - Bool ret; - int ihandle = (int) (long) fd_handle; - - if (ihandle == -1) - if (!ms->drmmode.reverse_prime_offload_mode) - return drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, 0, 0); - - if (ms->drmmode.reverse_prime_offload_mode) { - ret = ms->glamor.back_pixmap_from_fd(ppix, ihandle, - ppix->drawable.width, - ppix->drawable.height, - ppix->devKind, - ppix->drawable.depth, - ppix->drawable.bitsPerPixel); - } else { - int size = ppix->devKind * ppix->drawable.height; - ret = drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, ppix->devKind, size); - } - if (ret == FALSE) - return ret; - - return TRUE; -#else - return FALSE; -#endif -} - -static Bool -msRequestSharedPixmapNotifyDamage(PixmapPtr ppix) -{ - ScreenPtr screen = ppix->drawable.pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - - msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, ppix->primary_pixmap); - - ppriv->notify_on_damage = TRUE; - - return TRUE; -} - -static Bool -msSharedPixmapNotifyDamage(PixmapPtr ppix) -{ - Bool ret = FALSE; - int c; - - ScreenPtr screen = ppix->drawable.pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - - msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, ppix); - - if (!ppriv->wait_for_damage) - return ret; - ppriv->wait_for_damage = FALSE; - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - if (!drmmode_crtc) - continue; - if (!(drmmode_crtc->prime_pixmap && drmmode_crtc->prime_pixmap_back)) - continue; - - // Received damage on primary screen pixmap, schedule present on vblank - ret |= drmmode_SharedPixmapPresentOnVBlank(ppix, crtc, &ms->drmmode); - } - - return ret; -} - -static Bool -SetMaster(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - int ret; - -#ifdef XF86_PDEV_SERVER_FD - if (ms->pEnt->location.type == BUS_PLATFORM && - (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)) - return TRUE; -#endif - - if (ms->fd_passed) - return TRUE; - - ret = drmSetMaster(ms->fd); - if (ret) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "drmSetMaster failed: %s\n", - strerror(errno)); - - return ret == 0; -} - -/* When the root window is created, initialize the screen contents from - * console if -background none was specified on the command line - */ -static Bool -CreateWindow_oneshot(WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(pScrn); - Bool ret; - - pScreen->CreateWindow = ms->CreateWindow; - ret = pScreen->CreateWindow(pWin); - - if (ret) - drmmode_copy_fb(pScrn, &ms->drmmode); - return ret; -} - -static Bool -ScreenInit(ScreenPtr pScreen, int argc, char **argv) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(pScrn); - VisualPtr visual; - - pScrn->pScreen = pScreen; - - if (!SetMaster(pScrn)) - return FALSE; - -#ifdef GLAMOR_HAS_GBM - if (ms->drmmode.glamor) - ms->drmmode.gbm = ms->glamor.egl_get_gbm_device(pScreen); -#endif - - /* HW dependent - FIXME */ - pScrn->displayWidth = pScrn->virtualX; - if (!drmmode_create_initial_bos(pScrn, &ms->drmmode)) - return FALSE; - - if (ms->drmmode.shadow_enable) { - ms->drmmode.shadow_fb = - calloc(1, - pScrn->displayWidth * pScrn->virtualY * - ((pScrn->bitsPerPixel + 7) >> 3)); - if (!ms->drmmode.shadow_fb) - ms->drmmode.shadow_enable = FALSE; - } - - miClearVisualTypes(); - - if (!miSetVisualTypes(pScrn->depth, - miGetDefaultVisualMask(pScrn->depth), - pScrn->rgbBits, pScrn->defaultVisual)) - return FALSE; - - if (!miSetPixmapDepths()) - return FALSE; - - if (!dixRegisterScreenSpecificPrivateKey - (pScreen, &ms->drmmode.pixmapPrivateKeyRec, PRIVATE_PIXMAP, - sizeof(msPixmapPrivRec))) { - return FALSE; - } - - pScrn->memPhysBase = 0; - pScrn->fbOffset = 0; - - if (!fbScreenInit(pScreen, NULL, - pScrn->virtualX, pScrn->virtualY, - pScrn->xDpi, pScrn->yDpi, - pScrn->displayWidth, pScrn->bitsPerPixel)) - return FALSE; - - if (pScrn->bitsPerPixel > 8) { - /* Fixup RGB ordering */ - visual = pScreen->visuals + pScreen->numVisuals; - while (--visual >= pScreen->visuals) { - if ((visual->class | DynamicClass) == DirectColor) { - visual->offsetRed = pScrn->offset.red; - visual->offsetGreen = pScrn->offset.green; - visual->offsetBlue = pScrn->offset.blue; - visual->redMask = pScrn->mask.red; - visual->greenMask = pScrn->mask.green; - visual->blueMask = pScrn->mask.blue; - } - } - } - - fbPictureInit(pScreen, NULL, 0); - - if (drmmode_init(pScrn, &ms->drmmode) == FALSE) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Failed to initialize glamor at ScreenInit() time.\n"); - return FALSE; - } - - if (ms->drmmode.shadow_enable && !ms->shadow.Setup(pScreen)) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "shadow fb init failed\n"); - return FALSE; - } - - ms->createScreenResources = pScreen->CreateScreenResources; - pScreen->CreateScreenResources = CreateScreenResources; - - xf86SetBlackWhitePixels(pScreen); - - xf86SetBackingStore(pScreen); - xf86SetSilkenMouse(pScreen); - miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); - - /* If pageflip is enabled hook the screen's cursor-sprite (swcursor) funcs. - * So that we can disable page-flipping on fallback to a swcursor. */ - if (ms->drmmode.pageflip) { - miPointerScreenPtr PointPriv = - dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); - - if (!dixRegisterScreenPrivateKey(&ms->drmmode.spritePrivateKeyRec, - pScreen, PRIVATE_DEVICE, - sizeof(msSpritePrivRec))) - return FALSE; - - ms->SpriteFuncs = PointPriv->spriteFuncs; - PointPriv->spriteFuncs = &drmmode_sprite_funcs; - } - - /* Need to extend HWcursor support to handle mask interleave */ - if (!ms->drmmode.sw_cursor) - xf86_cursors_init(pScreen, ms->cursor_width, ms->cursor_height, - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 | - HARDWARE_CURSOR_UPDATE_UNHIDDEN | - HARDWARE_CURSOR_ARGB); - - /* Must force it before EnterVT, so we are in control of VT and - * later memory should be bound when allocating, e.g rotate_mem */ - pScrn->vtSema = TRUE; - - if (serverGeneration == 1 && bgNoneRoot && ms->drmmode.glamor) { - ms->CreateWindow = pScreen->CreateWindow; - pScreen->CreateWindow = CreateWindow_oneshot; - } - - pScreen->SaveScreen = xf86SaveScreen; - ms->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = CloseScreen; - - ms->BlockHandler = pScreen->BlockHandler; - pScreen->BlockHandler = msBlockHandler_oneshot; - - pScreen->SharePixmapBacking = msSharePixmapBacking; - pScreen->SetSharedPixmapBacking = msSetSharedPixmapBacking; - pScreen->StartPixmapTracking = PixmapStartDirtyTracking; - pScreen->StopPixmapTracking = PixmapStopDirtyTracking; - - pScreen->SharedPixmapNotifyDamage = msSharedPixmapNotifyDamage; - pScreen->RequestSharedPixmapNotifyDamage = - msRequestSharedPixmapNotifyDamage; - - pScreen->PresentSharedPixmap = msPresentSharedPixmap; - pScreen->StopFlippingPixmapTracking = msStopFlippingPixmapTracking; - - if (!xf86CrtcScreenInit(pScreen)) - return FALSE; - - if (!drmmode_setup_colormap(pScreen, pScrn)) - return FALSE; - - if (ms->atomic_modeset) - xf86DPMSInit(pScreen, drmmode_set_dpms, 0); - else - xf86DPMSInit(pScreen, xf86DPMSSet, 0); - -#ifdef GLAMOR_HAS_GBM - if (ms->drmmode.glamor) { - XF86VideoAdaptorPtr glamor_adaptor; - - glamor_adaptor = ms->glamor.xv_init(pScreen, 16); - if (glamor_adaptor != NULL) - xf86XVScreenInit(pScreen, &glamor_adaptor, 1); - else - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Failed to initialize XV support.\n"); - } -#endif - - if (serverGeneration == 1) - xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); - - if (!ms_vblank_screen_init(pScreen)) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Failed to initialize vblank support.\n"); - return FALSE; - } - -#ifdef GLAMOR_HAS_GBM - if (ms->drmmode.glamor) { - if (!(ms->drmmode.dri2_enable = ms_dri2_screen_init(pScreen))) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Failed to initialize the DRI2 extension.\n"); - } - - /* enable reverse prime if we are a GPU screen, and accelerated, and not - * i915, evdi or udl. i915 is happy scanning out from sysmem. - * evdi and udl are virtual drivers scanning out from sysmem - * backed dumb buffers. - */ - if (pScreen->isGPU) { - drmVersionPtr version; - - /* enable if we are an accelerated GPU screen */ - ms->drmmode.reverse_prime_offload_mode = TRUE; - - if ((version = drmGetVersion(ms->drmmode.fd))) { - if (!strncmp("i915", version->name, version->name_len)) { - ms->drmmode.reverse_prime_offload_mode = FALSE; - } - if (!strncmp("evdi", version->name, version->name_len)) { - ms->drmmode.reverse_prime_offload_mode = FALSE; - } - if (!strncmp("udl", version->name, version->name_len)) { - ms->drmmode.reverse_prime_offload_mode = FALSE; - } - if (!ms->drmmode.reverse_prime_offload_mode) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Disable reverse prime offload mode for %s.\n", version->name); - } - drmFreeVersion(version); - } - } - } -#endif - if (!(ms->drmmode.present_enable = ms_present_screen_init(pScreen))) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Failed to initialize the Present extension.\n"); - } - - - pScrn->vtSema = TRUE; - - if (ms->vrr_support) { - if (!property_vectors_wrapped) { - saved_change_property = ProcVector[X_ChangeProperty]; - ProcVector[X_ChangeProperty] = ms_change_property; - saved_delete_property = ProcVector[X_DeleteProperty]; - ProcVector[X_DeleteProperty] = ms_delete_property; - property_vectors_wrapped = TRUE; - } - vrr_atom = MakeAtom("_VARIABLE_REFRESH", - strlen("_VARIABLE_REFRESH"), TRUE); - } - - return TRUE; -} - -static void -AdjustFrame(ScrnInfoPtr pScrn, int x, int y) -{ - modesettingPtr ms = modesettingPTR(pScrn); - - drmmode_adjust_frame(pScrn, &ms->drmmode, x, y); -} - -static void -FreeScreen(ScrnInfoPtr pScrn) -{ - FreeRec(pScrn); -} - -static void -LeaveVT(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - - xf86_hide_cursors(pScrn); - - pScrn->vtSema = FALSE; - -#ifdef XF86_PDEV_SERVER_FD - if (ms->pEnt->location.type == BUS_PLATFORM && - (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)) - return; -#endif - - if (!ms->fd_passed) - drmDropMaster(ms->fd); -} - -/* - * This gets called when gaining control of the VT, and from ScreenInit(). - */ -static Bool -EnterVT(ScrnInfoPtr pScrn) -{ - modesettingPtr ms = modesettingPTR(pScrn); - - pScrn->vtSema = TRUE; - - SetMaster(pScrn); - - drmmode_update_kms_state(&ms->drmmode); - - /* allow not all modes to be set successfully since some events might have - * happened while not being master that could prevent the previous - * configuration from being re-applied. - */ - if (!drmmode_set_desired_modes(pScrn, &ms->drmmode, TRUE, TRUE)) { - xf86DisableUnusedFunctions(pScrn); - - /* TODO: check that at least one screen is on, to allow the user to fix - * their setup if all modeset failed... - */ - - /* Tell the desktop environment that something changed, so that they - * can hopefully correct the situation - */ - RRSetChanged(xf86ScrnToScreen(pScrn)); - RRTellChanged(xf86ScrnToScreen(pScrn)); - } - - return TRUE; -} - -static Bool -SwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - return xf86SetSingleMode(pScrn, mode, RR_Rotate_0); -} - -static Bool -CloseScreen(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(pScrn); - modesettingEntPtr ms_ent = ms_ent_priv(pScrn); - - /* Clear mask of assigned crtc's in this generation */ - ms_ent->assigned_crtcs = 0; - -#ifdef GLAMOR_HAS_GBM - if (ms->drmmode.dri2_enable) { - ms_dri2_close_screen(pScreen); - } -#endif - - ms_vblank_close_screen(pScreen); - - if (ms->damage) { - DamageUnregister(ms->damage); - DamageDestroy(ms->damage); - ms->damage = NULL; - } - - if (ms->drmmode.shadow_enable) { - ms->shadow.Remove(pScreen, pScreen->GetScreenPixmap(pScreen)); - free(ms->drmmode.shadow_fb); - ms->drmmode.shadow_fb = NULL; - free(ms->drmmode.shadow_fb2); - ms->drmmode.shadow_fb2 = NULL; - } - - drmmode_uevent_fini(pScrn, &ms->drmmode); - - drmmode_free_bos(pScrn, &ms->drmmode); - - if (ms->drmmode.pageflip) { - miPointerScreenPtr PointPriv = - dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); - - if (PointPriv->spriteFuncs == &drmmode_sprite_funcs) - PointPriv->spriteFuncs = ms->SpriteFuncs; - } - - if (pScrn->vtSema) { - LeaveVT(pScrn); - } - - pScreen->CreateScreenResources = ms->createScreenResources; - pScreen->BlockHandler = ms->BlockHandler; - - pScrn->vtSema = FALSE; - pScreen->CloseScreen = ms->CloseScreen; - return (*pScreen->CloseScreen) (pScreen); -} - -static ModeStatus -ValidMode(ScrnInfoPtr arg, DisplayModePtr mode, Bool verbose, int flags) -{ - return MODE_OK; -} diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h deleted file mode 100644 index 71aa8730e..000000000 --- a/hw/xfree86/drivers/modesetting/driver.h +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. - * Copyright 2019 NVIDIA CORPORATION - * All Rights Reserved. - * - * 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, 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 TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * - * Author: Alan Hourihane - * Additional contributors: - * Aaron Plattner - */ - -#include -#include -#include -#include -#include -#include -#include -#ifdef GLAMOR_HAS_GBM -#define GLAMOR_FOR_XORG 1 -#include "glamor.h" -#include -#endif - -#include "drmmode_display.h" -#define MS_LOGLEVEL_DEBUG 4 - -struct ms_vrr_priv { - Bool variable_refresh; -}; - -typedef enum { - OPTION_SW_CURSOR, - OPTION_DEVICE_PATH, - OPTION_SHADOW_FB, - OPTION_ACCEL_METHOD, - OPTION_PAGEFLIP, - OPTION_ZAPHOD_HEADS, - OPTION_DOUBLE_SHADOW, - OPTION_ATOMIC, - OPTION_VARIABLE_REFRESH, - OPTION_USE_GAMMA_LUT, - OPTION_ASYNC_FLIP_SECONDARIES, -} modesettingOpts; - -typedef struct -{ - int fd; - int fd_ref; - unsigned long fd_wakeup_registered; /* server generation for which fd has been registered for wakeup handling */ - int fd_wakeup_ref; - unsigned int assigned_crtcs; -} modesettingEntRec, *modesettingEntPtr; - -typedef void (*ms_drm_handler_proc)(uint64_t frame, - uint64_t usec, - void *data); - -typedef void (*ms_drm_abort_proc)(void *data); - -/** - * A tracked handler for an event that will hopefully be generated by - * the kernel, and what to do when it is encountered. - */ -struct ms_drm_queue { - struct xorg_list list; - xf86CrtcPtr crtc; - uint32_t seq; - void *data; - ScrnInfoPtr scrn; - ms_drm_handler_proc handler; - ms_drm_abort_proc abort; -}; - -typedef struct _modesettingRec { - int fd; - Bool fd_passed; - - int Chipset; - EntityInfoPtr pEnt; - - Bool noAccel; - CloseScreenProcPtr CloseScreen; - CreateWindowProcPtr CreateWindow; - unsigned int SaveGeneration; - - CreateScreenResourcesProcPtr createScreenResources; - ScreenBlockHandlerProcPtr BlockHandler; - miPointerSpriteFuncPtr SpriteFuncs; - void *driver; - - drmmode_rec drmmode; - - drmEventContext event_context; - - /** - * Page flipping stuff. - * @{ - */ - Bool atomic_modeset_capable; - Bool atomic_modeset; - Bool pending_modeset; - /** @} */ - - DamagePtr damage; - Bool dirty_enabled; - - uint32_t cursor_width, cursor_height; - - Bool has_queue_sequence; - Bool tried_queue_sequence; - - Bool kms_has_modifiers; - - /* VRR support */ - Bool vrr_support; - WindowPtr flip_window; - - Bool is_connector_vrr_capable; - uint32_t connector_prop_id; - - /* shadow API */ - struct { - Bool (*Setup)(ScreenPtr); - Bool (*Add)(ScreenPtr, PixmapPtr, ShadowUpdateProc, ShadowWindowProc, - int, void *); - void (*Remove)(ScreenPtr, PixmapPtr); - void (*Update32to24)(ScreenPtr, shadowBufPtr); - void (*UpdatePacked)(ScreenPtr, shadowBufPtr); - } shadow; - -#ifdef GLAMOR_HAS_GBM - /* glamor API */ - struct { - Bool (*back_pixmap_from_fd)(PixmapPtr, int, CARD16, CARD16, CARD16, - CARD8, CARD8); - void (*block_handler)(ScreenPtr); - void (*clear_pixmap)(PixmapPtr); - Bool (*egl_create_textured_pixmap)(PixmapPtr, int, int); - Bool (*egl_create_textured_pixmap_from_gbm_bo)(PixmapPtr, - struct gbm_bo *, - Bool); - void (*egl_exchange_buffers)(PixmapPtr, PixmapPtr); - struct gbm_device *(*egl_get_gbm_device)(ScreenPtr); - Bool (*egl_init)(ScrnInfoPtr, int); - void (*finish)(ScreenPtr); - struct gbm_bo *(*gbm_bo_from_pixmap)(ScreenPtr, PixmapPtr); - Bool (*init)(ScreenPtr, unsigned int); - int (*name_from_pixmap)(PixmapPtr, CARD16 *, CARD32 *); - void (*set_drawable_modifiers_func)(ScreenPtr, - GetDrawableModifiersFuncPtr); - int (*shareable_fd_from_pixmap)(ScreenPtr, PixmapPtr, CARD16 *, - CARD32 *); - Bool (*supports_pixmap_import_export)(ScreenPtr); - XF86VideoAdaptorPtr (*xv_init)(ScreenPtr, int); - const char *(*egl_get_driver_name)(ScreenPtr); - } glamor; -#endif -} modesettingRec, *modesettingPtr; - -#define glamor_finish(screen) ms->glamor.finish(screen) - -#define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate)) -modesettingEntPtr ms_ent_priv(ScrnInfoPtr scrn); - -uint32_t ms_drm_queue_alloc(xf86CrtcPtr crtc, - void *data, - ms_drm_handler_proc handler, - ms_drm_abort_proc abort); - -typedef enum ms_queue_flag { - MS_QUEUE_ABSOLUTE = 0, - MS_QUEUE_RELATIVE = 1, - MS_QUEUE_NEXT_ON_MISS = 2 -} ms_queue_flag; - -Bool ms_queue_vblank(xf86CrtcPtr crtc, ms_queue_flag flags, - uint64_t msc, uint64_t *msc_queued, uint32_t seq); - -void ms_drm_abort(ScrnInfoPtr scrn, - Bool (*match)(void *data, void *match_data), - void *match_data); -void ms_drm_abort_seq(ScrnInfoPtr scrn, uint32_t seq); - -Bool xf86_crtc_on(xf86CrtcPtr crtc); - -xf86CrtcPtr ms_dri2_crtc_covering_drawable(DrawablePtr pDraw); -RRCrtcPtr ms_randr_crtc_covering_drawable(DrawablePtr pDraw); - -int ms_get_crtc_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc); - -uint64_t ms_kernel_msc_to_crtc_msc(xf86CrtcPtr crtc, uint64_t sequence, Bool is64bit); - - -Bool ms_dri2_screen_init(ScreenPtr screen); -void ms_dri2_close_screen(ScreenPtr screen); - -Bool ms_vblank_screen_init(ScreenPtr screen); -void ms_vblank_close_screen(ScreenPtr screen); - -Bool ms_present_screen_init(ScreenPtr screen); - -#ifdef GLAMOR_HAS_GBM - -typedef void (*ms_pageflip_handler_proc)(modesettingPtr ms, - uint64_t frame, - uint64_t usec, - void *data); - -typedef void (*ms_pageflip_abort_proc)(modesettingPtr ms, void *data); - -Bool ms_do_pageflip(ScreenPtr screen, - PixmapPtr new_front, - void *event, - int ref_crtc_vblank_pipe, - Bool async, - ms_pageflip_handler_proc pageflip_handler, - ms_pageflip_abort_proc pageflip_abort, - const char *log_prefix); - -#endif - -int ms_flush_drm_events(ScreenPtr screen); -Bool ms_window_has_variable_refresh(modesettingPtr ms, WindowPtr win); -void ms_present_set_screen_vrr(ScrnInfoPtr scrn, Bool vrr_enabled); diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c deleted file mode 100644 index 21c9222e1..000000000 --- a/hw/xfree86/drivers/modesetting/drmmode_display.c +++ /dev/null @@ -1,4416 +0,0 @@ -/* - * Copyright © 2007 Red Hat, Inc. - * Copyright © 2019 NVIDIA CORPORATION - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Authors: - * Dave Airlie - * Aaron Plattner - * - */ - -#ifdef HAVE_DIX_CONFIG_H -#include "dix-config.h" -#endif - -#include -#include -#include -#include -#include "dumb_bo.h" -#include "inputstr.h" -#include "xf86str.h" -#include "X11/Xatom.h" -#include "mi.h" -#include "micmap.h" -#include "xf86cmap.h" -#include "xf86DDC.h" -#include -#include - -#include -#include "xf86Crtc.h" -#include "drmmode_display.h" -#include "present.h" - -#include - -#include - -#include "driver.h" - -static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height); -static PixmapPtr drmmode_create_pixmap_header(ScreenPtr pScreen, int width, int height, - int depth, int bitsPerPixel, int devKind, - void *pPixData); - -static const struct drm_color_ctm ctm_identity = { { - 1UL << 32, 0, 0, - 0, 1UL << 32, 0, - 0, 0, 1UL << 32 -} }; - -static Bool ctm_is_identity(const struct drm_color_ctm *ctm) -{ - const size_t matrix_len = sizeof(ctm->matrix) / sizeof(ctm->matrix[0]); - const uint64_t one = 1ULL << 32; - const uint64_t neg_zero = 1ULL << 63; - int i; - - for (i = 0; i < matrix_len; i++) { - const Bool diagonal = i / 3 == i % 3; - const uint64_t val = ctm->matrix[i]; - - if ((diagonal && val != one) || - (!diagonal && val != 0 && val != neg_zero)) { - return FALSE; - } - } - - return TRUE; -} - -static inline uint32_t * -formats_ptr(struct drm_format_modifier_blob *blob) -{ - return (uint32_t *)(((char *)blob) + blob->formats_offset); -} - -static inline struct drm_format_modifier * -modifiers_ptr(struct drm_format_modifier_blob *blob) -{ - return (struct drm_format_modifier *)(((char *)blob) + blob->modifiers_offset); -} - -static uint32_t -get_opaque_format(uint32_t format) -{ - switch (format) { - case DRM_FORMAT_ARGB8888: - return DRM_FORMAT_XRGB8888; - case DRM_FORMAT_ARGB2101010: - return DRM_FORMAT_XRGB2101010; - default: - return format; - } -} - -Bool -drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format, uint64_t modifier) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c, i, j; - - /* BO are imported as opaque surface, so let's pretend there is no alpha */ - format = get_opaque_format(format); - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - Bool found = FALSE; - - if (!crtc->enabled) - continue; - - if (drmmode_crtc->num_formats == 0) - continue; - - for (i = 0; i < drmmode_crtc->num_formats; i++) { - drmmode_format_ptr iter = &drmmode_crtc->formats[i]; - - if (iter->format != format) - continue; - - if (modifier == DRM_FORMAT_MOD_INVALID || - iter->num_modifiers == 0) { - found = TRUE; - break; - } - - for (j = 0; j < iter->num_modifiers; j++) { - if (iter->modifiers[j] == modifier) { - found = TRUE; - break; - } - } - - break; - } - - if (!found) - return FALSE; - } - - return TRUE; -} - -#ifdef GBM_BO_WITH_MODIFIERS -static uint32_t -get_modifiers_set(ScrnInfoPtr scrn, uint32_t format, uint64_t **modifiers, - Bool enabled_crtc_only, Bool exclude_multiplane) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - modesettingPtr ms = modesettingPTR(scrn); - drmmode_ptr drmmode = &ms->drmmode; - int c, i, j, k, count_modifiers = 0; - uint64_t *tmp, *ret = NULL; - - /* BOs are imported as opaque surfaces, so pretend the same thing here */ - format = get_opaque_format(format); - - *modifiers = NULL; - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - if (enabled_crtc_only && !crtc->enabled) - continue; - - for (i = 0; i < drmmode_crtc->num_formats; i++) { - drmmode_format_ptr iter = &drmmode_crtc->formats[i]; - - if (iter->format != format) - continue; - - for (j = 0; j < iter->num_modifiers; j++) { - Bool found = FALSE; - - /* Don't choose multi-plane formats for our screen pixmap. - * These will get used with frontbuffer rendering, which will - * lead to worse-than-tearing with multi-plane formats, as the - * primary and auxiliary planes go out of sync. */ - if (exclude_multiplane && - gbm_device_get_format_modifier_plane_count(drmmode->gbm, - format, - iter->modifiers[j]) > 1) { - continue; - } - - for (k = 0; k < count_modifiers; k++) { - if (iter->modifiers[j] == ret[k]) - found = TRUE; - } - if (!found) { - count_modifiers++; - tmp = realloc(ret, count_modifiers * sizeof(uint64_t)); - if (!tmp) { - free(ret); - return 0; - } - ret = tmp; - ret[count_modifiers - 1] = iter->modifiers[j]; - } - } - } - } - - *modifiers = ret; - return count_modifiers; -} - -static Bool -get_drawable_modifiers(DrawablePtr draw, uint32_t format, - uint32_t *num_modifiers, uint64_t **modifiers) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(draw->pScreen); - modesettingPtr ms = modesettingPTR(scrn); - - if (!present_can_window_flip((WindowPtr) draw) || - !ms->drmmode.pageflip || ms->drmmode.dri2_flipping || !scrn->vtSema) { - *num_modifiers = 0; - *modifiers = NULL; - return TRUE; - } - - *num_modifiers = get_modifiers_set(scrn, format, modifiers, TRUE, FALSE); - return TRUE; -} -#endif - -static Bool -drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char *output_name) -{ - char **token = xstrtokenize(s, ", \t\n\r"); - Bool ret = FALSE; - - if (!token) - return FALSE; - - for (int i = 0; token[i]; i++) { - if (strcmp(token[i], output_name) == 0) - ret = TRUE; - - free(token[i]); - } - - free(token); - - return ret; -} - -static uint64_t -drmmode_prop_get_value(drmmode_prop_info_ptr info, - drmModeObjectPropertiesPtr props, - uint64_t def) -{ - unsigned int i; - - if (info->prop_id == 0) - return def; - - for (i = 0; i < props->count_props; i++) { - unsigned int j; - - if (props->props[i] != info->prop_id) - continue; - - /* Simple (non-enum) types can return the value directly */ - if (info->num_enum_values == 0) - return props->prop_values[i]; - - /* Map from raw value to enum value */ - for (j = 0; j < info->num_enum_values; j++) { - if (!info->enum_values[j].valid) - continue; - if (info->enum_values[j].value != props->prop_values[i]) - continue; - - return j; - } - } - - return def; -} - -static uint32_t -drmmode_prop_info_update(drmmode_ptr drmmode, - drmmode_prop_info_ptr info, - unsigned int num_infos, - drmModeObjectProperties *props) -{ - drmModePropertyRes *prop; - uint32_t valid_mask = 0; - unsigned i, j; - - assert(num_infos <= 32 && "update return type"); - - for (i = 0; i < props->count_props; i++) { - Bool props_incomplete = FALSE; - unsigned int k; - - for (j = 0; j < num_infos; j++) { - if (info[j].prop_id == props->props[i]) - break; - if (!info[j].prop_id) - props_incomplete = TRUE; - } - - /* We've already discovered this property. */ - if (j != num_infos) - continue; - - /* We haven't found this property ID, but as we've already - * found all known properties, we don't need to look any - * further. */ - if (!props_incomplete) - break; - - prop = drmModeGetProperty(drmmode->fd, props->props[i]); - if (!prop) - continue; - - for (j = 0; j < num_infos; j++) { - if (!strcmp(prop->name, info[j].name)) - break; - } - - /* We don't know/care about this property. */ - if (j == num_infos) { - drmModeFreeProperty(prop); - continue; - } - - info[j].prop_id = props->props[i]; - info[j].value = props->prop_values[i]; - valid_mask |= 1U << j; - - if (info[j].num_enum_values == 0) { - drmModeFreeProperty(prop); - continue; - } - - if (!(prop->flags & DRM_MODE_PROP_ENUM)) { - xf86DrvMsg(drmmode->scrn->scrnIndex, X_WARNING, - "expected property %s to be an enum," - " but it is not; ignoring\n", prop->name); - drmModeFreeProperty(prop); - continue; - } - - for (k = 0; k < info[j].num_enum_values; k++) { - int l; - - if (info[j].enum_values[k].valid) - continue; - - for (l = 0; l < prop->count_enums; l++) { - if (!strcmp(prop->enums[l].name, - info[j].enum_values[k].name)) - break; - } - - if (l == prop->count_enums) - continue; - - info[j].enum_values[k].valid = TRUE; - info[j].enum_values[k].value = prop->enums[l].value; - } - - drmModeFreeProperty(prop); - } - - return valid_mask; -} - -static Bool -drmmode_prop_info_copy(drmmode_prop_info_ptr dst, - const drmmode_prop_info_rec *src, - unsigned int num_props, - Bool copy_prop_id) -{ - unsigned int i; - - memcpy(dst, src, num_props * sizeof(*dst)); - - for (i = 0; i < num_props; i++) { - unsigned int j; - - if (copy_prop_id) - dst[i].prop_id = src[i].prop_id; - else - dst[i].prop_id = 0; - - if (src[i].num_enum_values == 0) - continue; - - dst[i].enum_values = - malloc(src[i].num_enum_values * - sizeof(*dst[i].enum_values)); - if (!dst[i].enum_values) - goto err; - - memcpy(dst[i].enum_values, src[i].enum_values, - src[i].num_enum_values * sizeof(*dst[i].enum_values)); - - for (j = 0; j < dst[i].num_enum_values; j++) - dst[i].enum_values[j].valid = FALSE; - } - - return TRUE; - -err: - while (i--) - free(dst[i].enum_values); - return FALSE; -} - -static void -drmmode_prop_info_free(drmmode_prop_info_ptr info, int num_props) -{ - int i; - - for (i = 0; i < num_props; i++) - free(info[i].enum_values); -} - -static void -drmmode_ConvertToKMode(ScrnInfoPtr scrn, - drmModeModeInfo * kmode, DisplayModePtr mode); - - -static int -plane_add_prop(drmModeAtomicReq *req, drmmode_crtc_private_ptr drmmode_crtc, - enum drmmode_plane_property prop, uint64_t val) -{ - drmmode_prop_info_ptr info = &drmmode_crtc->props_plane[prop]; - int ret; - - if (!info) - return -1; - - ret = drmModeAtomicAddProperty(req, drmmode_crtc->plane_id, - info->prop_id, val); - return (ret <= 0) ? -1 : 0; -} - -static int -plane_add_props(drmModeAtomicReq *req, xf86CrtcPtr crtc, - uint32_t fb_id, int x, int y) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - int ret = 0; - - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_FB_ID, - fb_id); - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_CRTC_ID, - fb_id ? drmmode_crtc->mode_crtc->crtc_id : 0); - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_SRC_X, x << 16); - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_SRC_Y, y << 16); - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_SRC_W, - crtc->mode.HDisplay << 16); - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_SRC_H, - crtc->mode.VDisplay << 16); - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_CRTC_X, 0); - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_CRTC_Y, 0); - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_CRTC_W, - crtc->mode.HDisplay); - ret |= plane_add_prop(req, drmmode_crtc, DRMMODE_PLANE_CRTC_H, - crtc->mode.VDisplay); - - return ret; -} - -static int -crtc_add_prop(drmModeAtomicReq *req, drmmode_crtc_private_ptr drmmode_crtc, - enum drmmode_crtc_property prop, uint64_t val) -{ - drmmode_prop_info_ptr info = &drmmode_crtc->props[prop]; - int ret; - - if (!info) - return -1; - - ret = drmModeAtomicAddProperty(req, drmmode_crtc->mode_crtc->crtc_id, - info->prop_id, val); - return (ret <= 0) ? -1 : 0; -} - -static int -connector_add_prop(drmModeAtomicReq *req, drmmode_output_private_ptr drmmode_output, - enum drmmode_connector_property prop, uint64_t val) -{ - drmmode_prop_info_ptr info = &drmmode_output->props_connector[prop]; - int ret; - - if (!info) - return -1; - - ret = drmModeAtomicAddProperty(req, drmmode_output->output_id, - info->prop_id, val); - return (ret <= 0) ? -1 : 0; -} - -static int -drmmode_CompareKModes(drmModeModeInfo * kmode, drmModeModeInfo * other) -{ - return memcmp(kmode, other, sizeof(*kmode)); -} - -static int -drm_mode_ensure_blob(xf86CrtcPtr crtc, drmModeModeInfo mode_info) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_mode_ptr mode; - int ret; - - if (drmmode_crtc->current_mode && - drmmode_CompareKModes(&drmmode_crtc->current_mode->mode_info, &mode_info) == 0) - return 0; - - mode = calloc(sizeof(drmmode_mode_rec), 1); - if (!mode) - return -1; - - mode->mode_info = mode_info; - ret = drmModeCreatePropertyBlob(ms->fd, - &mode->mode_info, - sizeof(mode->mode_info), - &mode->blob_id); - drmmode_crtc->current_mode = mode; - xorg_list_add(&mode->entry, &drmmode_crtc->mode_list); - - return ret; -} - -static int -crtc_add_dpms_props(drmModeAtomicReq *req, xf86CrtcPtr crtc, - int new_dpms, Bool *active) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - Bool crtc_active = FALSE; - int i; - int ret = 0; - - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - drmmode_output_private_ptr drmmode_output = output->driver_private; - - if (output->crtc != crtc) { - if (drmmode_output->current_crtc == crtc) { - ret |= connector_add_prop(req, drmmode_output, - DRMMODE_CONNECTOR_CRTC_ID, 0); - } - continue; - } - - if (drmmode_output->output_id == -1) - continue; - - if (new_dpms == DPMSModeOn) - crtc_active = TRUE; - - ret |= connector_add_prop(req, drmmode_output, - DRMMODE_CONNECTOR_CRTC_ID, - crtc_active ? - drmmode_crtc->mode_crtc->crtc_id : 0); - } - - if (crtc_active) { - drmModeModeInfo kmode; - - drmmode_ConvertToKMode(crtc->scrn, &kmode, &crtc->mode); - ret |= drm_mode_ensure_blob(crtc, kmode); - - ret |= crtc_add_prop(req, drmmode_crtc, - DRMMODE_CRTC_ACTIVE, 1); - ret |= crtc_add_prop(req, drmmode_crtc, - DRMMODE_CRTC_MODE_ID, - drmmode_crtc->current_mode->blob_id); - } else { - ret |= crtc_add_prop(req, drmmode_crtc, - DRMMODE_CRTC_ACTIVE, 0); - ret |= crtc_add_prop(req, drmmode_crtc, - DRMMODE_CRTC_MODE_ID, 0); - } - - if (active) - *active = crtc_active; - - return ret; -} - -static void -drm_mode_destroy(xf86CrtcPtr crtc, drmmode_mode_ptr mode) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - if (mode->blob_id) - drmModeDestroyPropertyBlob(ms->fd, mode->blob_id); - xorg_list_del(&mode->entry); - free(mode); -} - -static int -drmmode_crtc_can_test_mode(xf86CrtcPtr crtc) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - - return ms->atomic_modeset; -} - -Bool -drmmode_crtc_get_fb_id(xf86CrtcPtr crtc, uint32_t *fb_id, int *x, int *y) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - int ret; - - *fb_id = 0; - - if (drmmode_crtc->prime_pixmap) { - if (!drmmode->reverse_prime_offload_mode) { - msPixmapPrivPtr ppriv = - msGetPixmapPriv(drmmode, drmmode_crtc->prime_pixmap); - *fb_id = ppriv->fb_id; - *x = 0; - } else - *x = drmmode_crtc->prime_pixmap_x; - *y = 0; - } - else if (drmmode_crtc->rotate_fb_id) { - *fb_id = drmmode_crtc->rotate_fb_id; - *x = *y = 0; - } - else { - *fb_id = drmmode->fb_id; - *x = crtc->x; - *y = crtc->y; - } - - if (*fb_id == 0) { - ret = drmmode_bo_import(drmmode, &drmmode->front_bo, - &drmmode->fb_id); - if (ret < 0) { - ErrorF("failed to add fb %d\n", ret); - return FALSE; - } - *fb_id = drmmode->fb_id; - } - - return TRUE; -} - -void -drmmode_set_dpms(ScrnInfoPtr scrn, int dpms, int flags) -{ - modesettingPtr ms = modesettingPTR(scrn); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - drmModeAtomicReq *req = drmModeAtomicAlloc(); - uint32_t mode_flags = DRM_MODE_ATOMIC_ALLOW_MODESET; - int ret = 0; - int i; - - assert(ms->atomic_modeset); - - if (!req) - return; - - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - drmmode_output_private_ptr drmmode_output = output->driver_private; - - if (output->crtc != NULL) - continue; - - ret = connector_add_prop(req, drmmode_output, - DRMMODE_CONNECTOR_CRTC_ID, 0); - } - - for (i = 0; i < xf86_config->num_crtc; i++) { - xf86CrtcPtr crtc = xf86_config->crtc[i]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - Bool active = FALSE; - - ret |= crtc_add_dpms_props(req, crtc, dpms, &active); - - if (dpms == DPMSModeOn && active && drmmode_crtc->need_modeset) { - uint32_t fb_id; - int x, y; - - if (!drmmode_crtc_get_fb_id(crtc, &fb_id, &x, &y)) - continue; - ret |= plane_add_props(req, crtc, fb_id, x, y); - drmmode_crtc->need_modeset = FALSE; - } - } - - if (ret == 0) - drmModeAtomicCommit(ms->fd, req, mode_flags, NULL); - drmModeAtomicFree(req); - - ms->pending_modeset = TRUE; - xf86DPMSSet(scrn, dpms, flags); - ms->pending_modeset = FALSE; -} - -static int -drmmode_output_disable(xf86OutputPtr output) -{ - modesettingPtr ms = modesettingPTR(output->scrn); - drmmode_output_private_ptr drmmode_output = output->driver_private; - xf86CrtcPtr crtc = drmmode_output->current_crtc; - drmModeAtomicReq *req = drmModeAtomicAlloc(); - uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET; - int ret = 0; - - assert(ms->atomic_modeset); - - if (!req) - return 1; - - ret |= connector_add_prop(req, drmmode_output, - DRMMODE_CONNECTOR_CRTC_ID, 0); - if (crtc) - ret |= crtc_add_dpms_props(req, crtc, DPMSModeOff, NULL); - - if (ret == 0) - ret = drmModeAtomicCommit(ms->fd, req, flags, NULL); - - if (ret == 0) - drmmode_output->current_crtc = NULL; - - drmModeAtomicFree(req); - return ret; -} - -static int -drmmode_crtc_disable(xf86CrtcPtr crtc) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmModeAtomicReq *req = drmModeAtomicAlloc(); - uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET; - int ret = 0; - - assert(ms->atomic_modeset); - - if (!req) - return 1; - - ret |= crtc_add_prop(req, drmmode_crtc, - DRMMODE_CRTC_ACTIVE, 0); - ret |= crtc_add_prop(req, drmmode_crtc, - DRMMODE_CRTC_MODE_ID, 0); - - if (ret == 0) - ret = drmModeAtomicCommit(ms->fd, req, flags, NULL); - - drmModeAtomicFree(req); - return ret; -} - -static void -drmmode_set_ctm(xf86CrtcPtr crtc, const struct drm_color_ctm *ctm) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - drmmode_prop_info_ptr ctm_info = - &drmmode_crtc->props[DRMMODE_CRTC_CTM]; - int ret; - uint32_t blob_id = 0; - - if (ctm_info->prop_id == 0) - return; - - if (ctm && drmmode_crtc->use_gamma_lut && !ctm_is_identity(ctm)) { - ret = drmModeCreatePropertyBlob(drmmode->fd, ctm, sizeof(*ctm), &blob_id); - if (ret != 0) { - xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, - "Failed to create CTM property blob: %d\n", ret); - blob_id = 0; - } - } - - ret = drmModeObjectSetProperty(drmmode->fd, - drmmode_crtc->mode_crtc->crtc_id, - DRM_MODE_OBJECT_CRTC, ctm_info->prop_id, - blob_id); - if (ret != 0) - xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, - "Failed to set CTM property: %d\n", ret); - - drmModeDestroyPropertyBlob(drmmode->fd, blob_id); -} - -static int -drmmode_crtc_set_mode(xf86CrtcPtr crtc, Bool test_only) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - drmModeModeInfo kmode; - int output_count = 0; - uint32_t *output_ids = NULL; - uint32_t fb_id; - int x, y; - int i, ret = 0; - const struct drm_color_ctm *ctm = NULL; - - if (!drmmode_crtc_get_fb_id(crtc, &fb_id, &x, &y)) - return 1; - -#ifdef GLAMOR_HAS_GBM - /* Make sure any pending drawing will be visible in a new scanout buffer */ - if (drmmode->glamor) - glamor_finish(crtc->scrn->pScreen); -#endif - - if (ms->atomic_modeset) { - drmModeAtomicReq *req = drmModeAtomicAlloc(); - Bool active; - uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET; - - if (!req) - return 1; - - ret |= crtc_add_dpms_props(req, crtc, DPMSModeOn, &active); - ret |= plane_add_props(req, crtc, active ? fb_id : 0, x, y); - - /* Orphaned CRTCs need to be disabled right now in atomic mode */ - for (i = 0; i < xf86_config->num_crtc; i++) { - xf86CrtcPtr other_crtc = xf86_config->crtc[i]; - drmmode_crtc_private_ptr other_drmmode_crtc = other_crtc->driver_private; - int lost_outputs = 0; - int remaining_outputs = 0; - int j; - - if (other_crtc == crtc) - continue; - - for (j = 0; j < xf86_config->num_output; j++) { - xf86OutputPtr output = xf86_config->output[j]; - drmmode_output_private_ptr drmmode_output = output->driver_private; - - if (drmmode_output->current_crtc == other_crtc) { - if (output->crtc == crtc) - lost_outputs++; - else - remaining_outputs++; - } - } - - if (lost_outputs > 0 && remaining_outputs == 0) { - ret |= crtc_add_prop(req, other_drmmode_crtc, - DRMMODE_CRTC_ACTIVE, 0); - ret |= crtc_add_prop(req, other_drmmode_crtc, - DRMMODE_CRTC_MODE_ID, 0); - } - } - - if (test_only) - flags |= DRM_MODE_ATOMIC_TEST_ONLY; - - if (ret == 0) - ret = drmModeAtomicCommit(ms->fd, req, flags, NULL); - - if (ret == 0 && !test_only) { - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - drmmode_output_private_ptr drmmode_output = output->driver_private; - - if (output->crtc == crtc) - drmmode_output->current_crtc = crtc; - else if (drmmode_output->current_crtc == crtc) - drmmode_output->current_crtc = NULL; - } - } - - drmModeAtomicFree(req); - return ret; - } - - output_ids = calloc(sizeof(uint32_t), xf86_config->num_output); - if (!output_ids) - return -1; - - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - drmmode_output_private_ptr drmmode_output; - - if (output->crtc != crtc) - continue; - - drmmode_output = output->driver_private; - if (drmmode_output->output_id == -1) - continue; - output_ids[output_count] = drmmode_output->output_id; - output_count++; - - ctm = &drmmode_output->ctm; - } - - drmmode_ConvertToKMode(crtc->scrn, &kmode, &crtc->mode); - ret = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, - fb_id, x, y, output_ids, output_count, &kmode); - - drmmode_set_ctm(crtc, ctm); - - free(output_ids); - return ret; -} - -int -drmmode_crtc_flip(xf86CrtcPtr crtc, uint32_t fb_id, uint32_t flags, void *data) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - int ret; - - if (ms->atomic_modeset) { - drmModeAtomicReq *req = drmModeAtomicAlloc(); - - if (!req) - return 1; - - ret = plane_add_props(req, crtc, fb_id, crtc->x, crtc->y); - flags |= DRM_MODE_ATOMIC_NONBLOCK; - if (ret == 0) - ret = drmModeAtomicCommit(ms->fd, req, flags, data); - drmModeAtomicFree(req); - return ret; - } - - return drmModePageFlip(ms->fd, drmmode_crtc->mode_crtc->crtc_id, - fb_id, flags, data); -} - -int -drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo) -{ - int ret; - -#ifdef GLAMOR_HAS_GBM - if (bo->gbm) { - gbm_bo_destroy(bo->gbm); - bo->gbm = NULL; - } -#endif - - if (bo->dumb) { - ret = dumb_bo_destroy(drmmode->fd, bo->dumb); - if (ret == 0) - bo->dumb = NULL; - } - - return 0; -} - -uint32_t -drmmode_bo_get_pitch(drmmode_bo *bo) -{ -#ifdef GLAMOR_HAS_GBM - if (bo->gbm) - return gbm_bo_get_stride(bo->gbm); -#endif - - return bo->dumb->pitch; -} - -static Bool -drmmode_bo_has_bo(drmmode_bo *bo) -{ -#ifdef GLAMOR_HAS_GBM - if (bo->gbm) - return TRUE; -#endif - - return bo->dumb != NULL; -} - -uint32_t -drmmode_bo_get_handle(drmmode_bo *bo) -{ -#ifdef GLAMOR_HAS_GBM - if (bo->gbm) - return gbm_bo_get_handle(bo->gbm).u32; -#endif - - return bo->dumb->handle; -} - -static void * -drmmode_bo_map(drmmode_ptr drmmode, drmmode_bo *bo) -{ - int ret; - -#ifdef GLAMOR_HAS_GBM - if (bo->gbm) - return NULL; -#endif - - if (bo->dumb->ptr) - return bo->dumb->ptr; - - ret = dumb_bo_map(drmmode->fd, bo->dumb); - if (ret) - return NULL; - - return bo->dumb->ptr; -} - -int -drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo, - uint32_t *fb_id) -{ -#ifdef GBM_BO_WITH_MODIFIERS - modesettingPtr ms = modesettingPTR(drmmode->scrn); - if (bo->gbm && ms->kms_has_modifiers && - gbm_bo_get_modifier(bo->gbm) != DRM_FORMAT_MOD_INVALID) { - int num_fds; - - num_fds = gbm_bo_get_plane_count(bo->gbm); - if (num_fds > 0) { - int i; - uint32_t format; - uint32_t handles[4]; - uint32_t strides[4]; - uint32_t offsets[4]; - uint64_t modifiers[4]; - - memset(handles, 0, sizeof(handles)); - memset(strides, 0, sizeof(strides)); - memset(offsets, 0, sizeof(offsets)); - memset(modifiers, 0, sizeof(modifiers)); - - format = gbm_bo_get_format(bo->gbm); - format = get_opaque_format(format); - for (i = 0; i < num_fds; i++) { - handles[i] = gbm_bo_get_handle_for_plane(bo->gbm, i).u32; - strides[i] = gbm_bo_get_stride_for_plane(bo->gbm, i); - offsets[i] = gbm_bo_get_offset(bo->gbm, i); - modifiers[i] = gbm_bo_get_modifier(bo->gbm); - } - - return drmModeAddFB2WithModifiers(drmmode->fd, bo->width, bo->height, - format, handles, strides, - offsets, modifiers, fb_id, - DRM_MODE_FB_MODIFIERS); - } - } -#endif - return drmModeAddFB(drmmode->fd, bo->width, bo->height, - drmmode->scrn->depth, drmmode->kbpp, - drmmode_bo_get_pitch(bo), - drmmode_bo_get_handle(bo), fb_id); -} - -static Bool -drmmode_create_bo(drmmode_ptr drmmode, drmmode_bo *bo, - unsigned width, unsigned height, unsigned bpp) -{ - bo->width = width; - bo->height = height; - -#ifdef GLAMOR_HAS_GBM - if (drmmode->glamor) { -#ifdef GBM_BO_WITH_MODIFIERS - uint32_t num_modifiers; - uint64_t *modifiers = NULL; -#endif - uint32_t format; - - switch (drmmode->scrn->depth) { - case 15: - format = GBM_FORMAT_ARGB1555; - break; - case 16: - format = GBM_FORMAT_RGB565; - break; - case 30: - format = GBM_FORMAT_ARGB2101010; - break; - default: - format = GBM_FORMAT_ARGB8888; - break; - } - -#ifdef GBM_BO_WITH_MODIFIERS - num_modifiers = get_modifiers_set(drmmode->scrn, format, &modifiers, - FALSE, TRUE); - if (num_modifiers > 0 && - !(num_modifiers == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID)) { - bo->gbm = gbm_bo_create_with_modifiers(drmmode->gbm, width, height, - format, modifiers, - num_modifiers); - free(modifiers); - if (bo->gbm) { - bo->used_modifiers = TRUE; - return TRUE; - } - } -#endif - - bo->gbm = gbm_bo_create(drmmode->gbm, width, height, format, - GBM_BO_USE_RENDERING | GBM_BO_USE_SCANOUT); - bo->used_modifiers = FALSE; - return bo->gbm != NULL; - } -#endif - - bo->dumb = dumb_bo_create(drmmode->fd, width, height, bpp); - return bo->dumb != NULL; -} - -Bool -drmmode_SetSlaveBO(PixmapPtr ppix, - drmmode_ptr drmmode, int fd_handle, int pitch, int size) -{ - msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, ppix); - - if (fd_handle == -1) { - dumb_bo_destroy(drmmode->fd, ppriv->backing_bo); - ppriv->backing_bo = NULL; - return TRUE; - } - - ppriv->backing_bo = - dumb_get_bo_from_fd(drmmode->fd, fd_handle, pitch, size); - if (!ppriv->backing_bo) - return FALSE; - - close(fd_handle); - return TRUE; -} - -static Bool -drmmode_SharedPixmapPresent(PixmapPtr ppix, xf86CrtcPtr crtc, - drmmode_ptr drmmode) -{ - ScreenPtr primary = crtc->randr_crtc->pScreen->current_primary; - - if (primary->PresentSharedPixmap(ppix)) { - /* Success, queue flip to back target */ - if (drmmode_SharedPixmapFlip(ppix, crtc, drmmode)) - return TRUE; - - xf86DrvMsg(drmmode->scrn->scrnIndex, X_WARNING, - "drmmode_SharedPixmapFlip() failed, trying again next vblank\n"); - - return drmmode_SharedPixmapPresentOnVBlank(ppix, crtc, drmmode); - } - - /* Failed to present, try again on next vblank after damage */ - if (primary->RequestSharedPixmapNotifyDamage) { - msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, ppix); - - /* Set flag first in case we are immediately notified */ - ppriv->wait_for_damage = TRUE; - - if (primary->RequestSharedPixmapNotifyDamage(ppix)) - return TRUE; - else - ppriv->wait_for_damage = FALSE; - } - - /* Damage notification not available, just try again on vblank */ - return drmmode_SharedPixmapPresentOnVBlank(ppix, crtc, drmmode); -} - -struct vblank_event_args { - PixmapPtr frontTarget; - PixmapPtr backTarget; - xf86CrtcPtr crtc; - drmmode_ptr drmmode; - Bool flip; -}; -static void -drmmode_SharedPixmapVBlankEventHandler(uint64_t frame, uint64_t usec, - void *data) -{ - struct vblank_event_args *args = data; - - drmmode_crtc_private_ptr drmmode_crtc = args->crtc->driver_private; - - if (args->flip) { - /* frontTarget is being displayed, update crtc to reflect */ - drmmode_crtc->prime_pixmap = args->frontTarget; - drmmode_crtc->prime_pixmap_back = args->backTarget; - - /* Safe to present on backTarget, no longer displayed */ - drmmode_SharedPixmapPresent(args->backTarget, args->crtc, args->drmmode); - } else { - /* backTarget is still being displayed, present on frontTarget */ - drmmode_SharedPixmapPresent(args->frontTarget, args->crtc, args->drmmode); - } - - free(args); -} - -static void -drmmode_SharedPixmapVBlankEventAbort(void *data) -{ - struct vblank_event_args *args = data; - - msGetPixmapPriv(args->drmmode, args->frontTarget)->flip_seq = 0; - - free(args); -} - -Bool -drmmode_SharedPixmapPresentOnVBlank(PixmapPtr ppix, xf86CrtcPtr crtc, - drmmode_ptr drmmode) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, ppix); - struct vblank_event_args *event_args; - - if (ppix == drmmode_crtc->prime_pixmap) - return FALSE; /* Already flipped to this pixmap */ - if (ppix != drmmode_crtc->prime_pixmap_back) - return FALSE; /* Pixmap is not a scanout pixmap for CRTC */ - - event_args = calloc(1, sizeof(*event_args)); - if (!event_args) - return FALSE; - - event_args->frontTarget = ppix; - event_args->backTarget = drmmode_crtc->prime_pixmap; - event_args->crtc = crtc; - event_args->drmmode = drmmode; - event_args->flip = FALSE; - - ppriv->flip_seq = - ms_drm_queue_alloc(crtc, event_args, - drmmode_SharedPixmapVBlankEventHandler, - drmmode_SharedPixmapVBlankEventAbort); - - return ms_queue_vblank(crtc, MS_QUEUE_RELATIVE, 1, NULL, ppriv->flip_seq); -} - -Bool -drmmode_SharedPixmapFlip(PixmapPtr frontTarget, xf86CrtcPtr crtc, - drmmode_ptr drmmode) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - msPixmapPrivPtr ppriv_front = msGetPixmapPriv(drmmode, frontTarget); - - struct vblank_event_args *event_args; - - event_args = calloc(1, sizeof(*event_args)); - if (!event_args) - return FALSE; - - event_args->frontTarget = frontTarget; - event_args->backTarget = drmmode_crtc->prime_pixmap; - event_args->crtc = crtc; - event_args->drmmode = drmmode; - event_args->flip = TRUE; - - ppriv_front->flip_seq = - ms_drm_queue_alloc(crtc, event_args, - drmmode_SharedPixmapVBlankEventHandler, - drmmode_SharedPixmapVBlankEventAbort); - - if (drmModePageFlip(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, - ppriv_front->fb_id, DRM_MODE_PAGE_FLIP_EVENT, - (void *)(intptr_t) ppriv_front->flip_seq) < 0) { - ms_drm_abort_seq(crtc->scrn, ppriv_front->flip_seq); - return FALSE; - } - - return TRUE; -} - -static Bool -drmmode_InitSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - if (!drmmode_crtc->enable_flipping) - return FALSE; - - if (drmmode_crtc->flipping_active) - return TRUE; - - drmmode_crtc->flipping_active = - drmmode_SharedPixmapPresent(drmmode_crtc->prime_pixmap_back, - crtc, drmmode); - - return drmmode_crtc->flipping_active; -} - -static void -drmmode_FiniSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode) -{ - uint32_t seq; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - if (!drmmode_crtc->flipping_active) - return; - - drmmode_crtc->flipping_active = FALSE; - - /* Abort page flip event handler on prime_pixmap */ - seq = msGetPixmapPriv(drmmode, drmmode_crtc->prime_pixmap)->flip_seq; - if (seq) - ms_drm_abort_seq(crtc->scrn, seq); - - /* Abort page flip event handler on prime_pixmap_back */ - seq = msGetPixmapPriv(drmmode, - drmmode_crtc->prime_pixmap_back)->flip_seq; - if (seq) - ms_drm_abort_seq(crtc->scrn, seq); -} - -static Bool drmmode_set_target_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix, - PixmapPtr *target); - -Bool -drmmode_EnableSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode, - PixmapPtr front, PixmapPtr back) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - drmmode_crtc->enable_flipping = TRUE; - - /* Set front scanout pixmap */ - drmmode_crtc->enable_flipping &= - drmmode_set_target_scanout_pixmap(crtc, front, - &drmmode_crtc->prime_pixmap); - if (!drmmode_crtc->enable_flipping) - return FALSE; - - /* Set back scanout pixmap */ - drmmode_crtc->enable_flipping &= - drmmode_set_target_scanout_pixmap(crtc, back, - &drmmode_crtc->prime_pixmap_back); - if (!drmmode_crtc->enable_flipping) { - drmmode_set_target_scanout_pixmap(crtc, NULL, - &drmmode_crtc->prime_pixmap); - return FALSE; - } - - return TRUE; -} - -void -drmmode_DisableSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - drmmode_crtc->enable_flipping = FALSE; - - drmmode_FiniSharedPixmapFlipping(crtc, drmmode); - - drmmode_set_target_scanout_pixmap(crtc, NULL, &drmmode_crtc->prime_pixmap); - - drmmode_set_target_scanout_pixmap(crtc, NULL, - &drmmode_crtc->prime_pixmap_back); -} - -static void -drmmode_ConvertFromKMode(ScrnInfoPtr scrn, - drmModeModeInfo * kmode, DisplayModePtr mode) -{ - memset(mode, 0, sizeof(DisplayModeRec)); - mode->status = MODE_OK; - - mode->Clock = kmode->clock; - - mode->HDisplay = kmode->hdisplay; - mode->HSyncStart = kmode->hsync_start; - mode->HSyncEnd = kmode->hsync_end; - mode->HTotal = kmode->htotal; - mode->HSkew = kmode->hskew; - - mode->VDisplay = kmode->vdisplay; - mode->VSyncStart = kmode->vsync_start; - mode->VSyncEnd = kmode->vsync_end; - mode->VTotal = kmode->vtotal; - mode->VScan = kmode->vscan; - - mode->Flags = kmode->flags; //& FLAG_BITS; - mode->name = strdup(kmode->name); - - if (kmode->type & DRM_MODE_TYPE_DRIVER) - mode->type = M_T_DRIVER; - if (kmode->type & DRM_MODE_TYPE_PREFERRED) - mode->type |= M_T_PREFERRED; - xf86SetModeCrtc(mode, scrn->adjustFlags); -} - -static void -drmmode_ConvertToKMode(ScrnInfoPtr scrn, - drmModeModeInfo * kmode, DisplayModePtr mode) -{ - memset(kmode, 0, sizeof(*kmode)); - - kmode->clock = mode->Clock; - kmode->hdisplay = mode->HDisplay; - kmode->hsync_start = mode->HSyncStart; - kmode->hsync_end = mode->HSyncEnd; - kmode->htotal = mode->HTotal; - kmode->hskew = mode->HSkew; - - kmode->vdisplay = mode->VDisplay; - kmode->vsync_start = mode->VSyncStart; - kmode->vsync_end = mode->VSyncEnd; - kmode->vtotal = mode->VTotal; - kmode->vscan = mode->VScan; - - kmode->flags = mode->Flags; //& FLAG_BITS; - if (mode->name) - strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN); - kmode->name[DRM_DISPLAY_MODE_LEN - 1] = 0; - -} - -static void -drmmode_crtc_dpms(xf86CrtcPtr crtc, int mode) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - - /* XXX Check if DPMS mode is already the right one */ - - drmmode_crtc->dpms_mode = mode; - - if (ms->atomic_modeset) { - if (mode != DPMSModeOn && !ms->pending_modeset) - drmmode_crtc_disable(crtc); - } else if (crtc->enabled == FALSE) { - drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, - 0, 0, 0, NULL, 0, NULL); - } -} - -#ifdef GLAMOR_HAS_GBM -static PixmapPtr -create_pixmap_for_fbcon(drmmode_ptr drmmode, ScrnInfoPtr pScrn, int fbcon_id) -{ - PixmapPtr pixmap = drmmode->fbcon_pixmap; - drmModeFBPtr fbcon; - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - modesettingPtr ms = modesettingPTR(pScrn); - Bool ret; - - if (pixmap) - return pixmap; - - fbcon = drmModeGetFB(drmmode->fd, fbcon_id); - if (fbcon == NULL) - return NULL; - - if (fbcon->depth != pScrn->depth || - fbcon->width != pScrn->virtualX || - fbcon->height != pScrn->virtualY) - goto out_free_fb; - - pixmap = drmmode_create_pixmap_header(pScreen, fbcon->width, - fbcon->height, fbcon->depth, - fbcon->bpp, fbcon->pitch, NULL); - if (!pixmap) - goto out_free_fb; - - ret = ms->glamor.egl_create_textured_pixmap(pixmap, fbcon->handle, - fbcon->pitch); - if (!ret) { - FreePixmap(pixmap); - pixmap = NULL; - } - - drmmode->fbcon_pixmap = pixmap; -out_free_fb: - drmModeFreeFB(fbcon); - return pixmap; -} -#endif - -void -drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode) -{ -#ifdef GLAMOR_HAS_GBM - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - PixmapPtr src, dst; - int fbcon_id = 0; - GCPtr gc; - int i; - - for (i = 0; i < xf86_config->num_crtc; i++) { - drmmode_crtc_private_ptr drmmode_crtc = xf86_config->crtc[i]->driver_private; - if (drmmode_crtc->mode_crtc->buffer_id) - fbcon_id = drmmode_crtc->mode_crtc->buffer_id; - } - - if (!fbcon_id) - return; - - if (fbcon_id == drmmode->fb_id) { - /* in some rare case there might be no fbcon and we might already - * be the one with the current fb to avoid a false deadlck in - * kernel ttm code just do nothing as anyway there is nothing - * to do - */ - return; - } - - src = create_pixmap_for_fbcon(drmmode, pScrn, fbcon_id); - if (!src) - return; - - dst = pScreen->GetScreenPixmap(pScreen); - - gc = GetScratchGC(pScrn->depth, pScreen); - ValidateGC(&dst->drawable, gc); - - (*gc->ops->CopyArea)(&src->drawable, &dst->drawable, gc, 0, 0, - pScrn->virtualX, pScrn->virtualY, 0, 0); - - FreeScratchGC(gc); - - pScreen->canDoBGNoneRoot = TRUE; - - if (drmmode->fbcon_pixmap) - pScrn->pScreen->DestroyPixmap(drmmode->fbcon_pixmap); - drmmode->fbcon_pixmap = NULL; -#endif -} - -static Bool -drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, - Rotation rotation, int x, int y) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - int saved_x, saved_y; - Rotation saved_rotation; - DisplayModeRec saved_mode; - Bool ret = TRUE; - Bool can_test; - int i; - - saved_mode = crtc->mode; - saved_x = crtc->x; - saved_y = crtc->y; - saved_rotation = crtc->rotation; - - if (mode) { - crtc->mode = *mode; - crtc->x = x; - crtc->y = y; - crtc->rotation = rotation; - - if (!xf86CrtcRotate(crtc)) { - goto done; - } - - crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green, - crtc->gamma_blue, crtc->gamma_size); - - can_test = drmmode_crtc_can_test_mode(crtc); - if (drmmode_crtc_set_mode(crtc, can_test)) { - xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, - "failed to set mode: %s\n", strerror(errno)); - ret = FALSE; - goto done; - } else - ret = TRUE; - - if (crtc->scrn->pScreen) - xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen); - - ms->pending_modeset = TRUE; - drmmode_crtc->need_modeset = FALSE; - crtc->funcs->dpms(crtc, DPMSModeOn); - - if (drmmode_crtc->prime_pixmap_back) - drmmode_InitSharedPixmapFlipping(crtc, drmmode); - - /* go through all the outputs and force DPMS them back on? */ - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - drmmode_output_private_ptr drmmode_output; - - if (output->crtc != crtc) - continue; - - drmmode_output = output->driver_private; - if (drmmode_output->output_id == -1) - continue; - output->funcs->dpms(output, DPMSModeOn); - } - - /* if we only tested the mode previously, really set it now */ - if (can_test) - drmmode_crtc_set_mode(crtc, FALSE); - ms->pending_modeset = FALSE; - } - - done: - if (!ret) { - crtc->x = saved_x; - crtc->y = saved_y; - crtc->rotation = saved_rotation; - crtc->mode = saved_mode; - } else - crtc->active = TRUE; - - return ret; -} - -static void -drmmode_set_cursor_colors(xf86CrtcPtr crtc, int bg, int fg) -{ - -} - -static void -drmmode_set_cursor_position(xf86CrtcPtr crtc, int x, int y) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - - drmModeMoveCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, x, y); -} - -static Bool -drmmode_set_cursor(xf86CrtcPtr crtc) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - uint32_t handle = drmmode_crtc->cursor_bo->handle; - modesettingPtr ms = modesettingPTR(crtc->scrn); - CursorPtr cursor = xf86CurrentCursor(crtc->scrn->pScreen); - int ret = -EINVAL; - - if (cursor == NullCursor) - return TRUE; - - ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, - handle, ms->cursor_width, ms->cursor_height, - cursor->bits->xhot, cursor->bits->yhot); - - /* -EINVAL can mean that an old kernel supports drmModeSetCursor but - * not drmModeSetCursor2, though it can mean other things too. */ - if (ret == -EINVAL) - ret = drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, - handle, ms->cursor_width, ms->cursor_height); - - /* -ENXIO normally means that the current drm driver supports neither - * cursor_set nor cursor_set2. Disable hardware cursor support for - * the rest of the session in that case. */ - if (ret == -ENXIO) { - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - - cursor_info->MaxWidth = cursor_info->MaxHeight = 0; - drmmode_crtc->drmmode->sw_cursor = TRUE; - } - - if (ret) - /* fallback to swcursor */ - return FALSE; - return TRUE; -} - -static void drmmode_hide_cursor(xf86CrtcPtr crtc); - -/* - * The load_cursor_argb_check driver hook. - * - * Sets the hardware cursor by calling the drmModeSetCursor2 ioctl. - * On failure, returns FALSE indicating that the X server should fall - * back to software cursors. - */ -static Bool -drmmode_load_cursor_argb_check(xf86CrtcPtr crtc, CARD32 *image) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - int i; - uint32_t *ptr; - - /* cursor should be mapped already */ - ptr = (uint32_t *) (drmmode_crtc->cursor_bo->ptr); - - for (i = 0; i < ms->cursor_width * ms->cursor_height; i++) - ptr[i] = image[i]; // cpu_to_le32(image[i]); - - if (drmmode_crtc->cursor_up) - return drmmode_set_cursor(crtc); - return TRUE; -} - -static void -drmmode_hide_cursor(xf86CrtcPtr crtc) -{ - modesettingPtr ms = modesettingPTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - - drmmode_crtc->cursor_up = FALSE; - drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, - ms->cursor_width, ms->cursor_height); -} - -static Bool -drmmode_show_cursor(xf86CrtcPtr crtc) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_crtc->cursor_up = TRUE; - return drmmode_set_cursor(crtc); -} - -static void -drmmode_set_gamma_lut(drmmode_crtc_private_ptr drmmode_crtc, - uint16_t * red, uint16_t * green, uint16_t * blue, - int size) -{ - drmmode_ptr drmmode = drmmode_crtc->drmmode; - drmmode_prop_info_ptr gamma_lut_info = - &drmmode_crtc->props[DRMMODE_CRTC_GAMMA_LUT]; - const uint32_t crtc_id = drmmode_crtc->mode_crtc->crtc_id; - uint32_t blob_id; - struct drm_color_lut lut[size]; - - assert(gamma_lut_info->prop_id != 0); - - for (int i = 0; i < size; i++) { - lut[i].red = red[i]; - lut[i].green = green[i]; - lut[i].blue = blue[i]; - } - - if (drmModeCreatePropertyBlob(drmmode->fd, lut, sizeof(lut), &blob_id)) - return; - - drmModeObjectSetProperty(drmmode->fd, crtc_id, DRM_MODE_OBJECT_CRTC, - gamma_lut_info->prop_id, blob_id); - - drmModeDestroyPropertyBlob(drmmode->fd, blob_id); -} - -static void -drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t * red, uint16_t * green, - uint16_t * blue, int size) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - - if (drmmode_crtc->use_gamma_lut) { - drmmode_set_gamma_lut(drmmode_crtc, red, green, blue, size); - } else { - drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, - size, red, green, blue); - } -} - -static Bool -drmmode_set_target_scanout_pixmap_gpu(xf86CrtcPtr crtc, PixmapPtr ppix, - PixmapPtr *target) -{ - ScreenPtr screen = xf86ScrnToScreen(crtc->scrn); - PixmapPtr screenpix = screen->GetScreenPixmap(screen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - int c, total_width = 0, max_height = 0, this_x = 0; - - if (*target) { - PixmapStopDirtyTracking(&(*target)->drawable, screenpix); - if (drmmode->fb_id) { - drmModeRmFB(drmmode->fd, drmmode->fb_id); - drmmode->fb_id = 0; - } - drmmode_crtc->prime_pixmap_x = 0; - *target = NULL; - } - - if (!ppix) - return TRUE; - - /* iterate over all the attached crtcs to work out the bounding box */ - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr iter = xf86_config->crtc[c]; - if (!iter->enabled && iter != crtc) - continue; - if (iter == crtc) { - this_x = total_width; - total_width += ppix->drawable.width; - if (max_height < ppix->drawable.height) - max_height = ppix->drawable.height; - } else { - total_width += iter->mode.HDisplay; - if (max_height < iter->mode.VDisplay) - max_height = iter->mode.VDisplay; - } - } - - if (total_width != screenpix->drawable.width || - max_height != screenpix->drawable.height) { - - if (!drmmode_xf86crtc_resize(crtc->scrn, total_width, max_height)) - return FALSE; - - screenpix = screen->GetScreenPixmap(screen); - screen->width = screenpix->drawable.width = total_width; - screen->height = screenpix->drawable.height = max_height; - } - drmmode_crtc->prime_pixmap_x = this_x; - PixmapStartDirtyTracking(&ppix->drawable, screenpix, 0, 0, this_x, 0, - RR_Rotate_0); - *target = ppix; - return TRUE; -} - -static Bool -drmmode_set_target_scanout_pixmap_cpu(xf86CrtcPtr crtc, PixmapPtr ppix, - PixmapPtr *target) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - msPixmapPrivPtr ppriv; - void *ptr; - - if (*target) { - ppriv = msGetPixmapPriv(drmmode, *target); - drmModeRmFB(drmmode->fd, ppriv->fb_id); - ppriv->fb_id = 0; - if (ppriv->secondary_damage) { - DamageUnregister(ppriv->secondary_damage); - ppriv->secondary_damage = NULL; - } - *target = NULL; - } - - if (!ppix) - return TRUE; - - ppriv = msGetPixmapPriv(drmmode, ppix); - if (!ppriv->secondary_damage) { - ppriv->secondary_damage = DamageCreate(NULL, NULL, - DamageReportNone, - TRUE, - crtc->randr_crtc->pScreen, - NULL); - } - ptr = drmmode_map_secondary_bo(drmmode, ppriv); - ppix->devPrivate.ptr = ptr; - DamageRegister(&ppix->drawable, ppriv->secondary_damage); - - if (ppriv->fb_id == 0) { - drmModeAddFB(drmmode->fd, ppix->drawable.width, - ppix->drawable.height, - ppix->drawable.depth, - ppix->drawable.bitsPerPixel, - ppix->devKind, ppriv->backing_bo->handle, &ppriv->fb_id); - } - *target = ppix; - return TRUE; -} - -static Bool -drmmode_set_target_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix, - PixmapPtr *target) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - - if (drmmode->reverse_prime_offload_mode) - return drmmode_set_target_scanout_pixmap_gpu(crtc, ppix, target); - else - return drmmode_set_target_scanout_pixmap_cpu(crtc, ppix, target); -} - -static Bool -drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - /* Use DisableSharedPixmapFlipping before switching to single buf */ - if (drmmode_crtc->enable_flipping) - return FALSE; - - return drmmode_set_target_scanout_pixmap(crtc, ppix, - &drmmode_crtc->prime_pixmap); -} - -static void -drmmode_clear_pixmap(PixmapPtr pixmap) -{ - ScreenPtr screen = pixmap->drawable.pScreen; - GCPtr gc; -#ifdef GLAMOR_HAS_GBM - modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(screen)); - - if (ms->drmmode.glamor) { - ms->glamor.clear_pixmap(pixmap); - return; - } -#endif - - gc = GetScratchGC(pixmap->drawable.depth, screen); - if (gc) { - miClearDrawable(&pixmap->drawable, gc); - FreeScratchGC(gc); - } -} - -static void * -drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - int ret; - - if (!drmmode_create_bo(drmmode, &drmmode_crtc->rotate_bo, - width, height, drmmode->kbpp)) { - xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR, - "Couldn't allocate shadow memory for rotated CRTC\n"); - return NULL; - } - - ret = drmmode_bo_import(drmmode, &drmmode_crtc->rotate_bo, - &drmmode_crtc->rotate_fb_id); - - if (ret) { - ErrorF("failed to add rotate fb\n"); - drmmode_bo_destroy(drmmode, &drmmode_crtc->rotate_bo); - return NULL; - } - -#ifdef GLAMOR_HAS_GBM - if (drmmode->gbm) - return drmmode_crtc->rotate_bo.gbm; -#endif - return drmmode_crtc->rotate_bo.dumb; -} - -static PixmapPtr -drmmode_create_pixmap_header(ScreenPtr pScreen, int width, int height, - int depth, int bitsPerPixel, int devKind, - void *pPixData) -{ - PixmapPtr pixmap; - - /* width and height of 0 means don't allocate any pixmap data */ - pixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth, 0); - - if (pixmap) { - if ((*pScreen->ModifyPixmapHeader)(pixmap, width, height, depth, - bitsPerPixel, devKind, pPixData)) - return pixmap; - (*pScreen->DestroyPixmap)(pixmap); - } - return NullPixmap; -} - -static Bool -drmmode_set_pixmap_bo(drmmode_ptr drmmode, PixmapPtr pixmap, drmmode_bo *bo); - -static PixmapPtr -drmmode_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height) -{ - ScrnInfoPtr scrn = crtc->scrn; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - uint32_t rotate_pitch; - PixmapPtr rotate_pixmap; - void *pPixData = NULL; - - if (!data) { - data = drmmode_shadow_allocate(crtc, width, height); - if (!data) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Couldn't allocate shadow pixmap for rotated CRTC\n"); - return NULL; - } - } - - if (!drmmode_bo_has_bo(&drmmode_crtc->rotate_bo)) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Couldn't allocate shadow pixmap for rotated CRTC\n"); - return NULL; - } - - pPixData = drmmode_bo_map(drmmode, &drmmode_crtc->rotate_bo); - rotate_pitch = drmmode_bo_get_pitch(&drmmode_crtc->rotate_bo); - - rotate_pixmap = drmmode_create_pixmap_header(scrn->pScreen, - width, height, - scrn->depth, - drmmode->kbpp, - rotate_pitch, - pPixData); - - if (rotate_pixmap == NULL) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Couldn't allocate shadow pixmap for rotated CRTC\n"); - return NULL; - } - - drmmode_set_pixmap_bo(drmmode, rotate_pixmap, &drmmode_crtc->rotate_bo); - - return rotate_pixmap; -} - -static void -drmmode_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - - if (rotate_pixmap) { - rotate_pixmap->drawable.pScreen->DestroyPixmap(rotate_pixmap); - } - - if (data) { - drmModeRmFB(drmmode->fd, drmmode_crtc->rotate_fb_id); - drmmode_crtc->rotate_fb_id = 0; - - drmmode_bo_destroy(drmmode, &drmmode_crtc->rotate_bo); - memset(&drmmode_crtc->rotate_bo, 0, sizeof drmmode_crtc->rotate_bo); - } -} - -static void -drmmode_crtc_destroy(xf86CrtcPtr crtc) -{ - drmmode_mode_ptr iterator, next; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - modesettingPtr ms = modesettingPTR(crtc->scrn); - - if (!ms->atomic_modeset) - return; - - drmmode_prop_info_free(drmmode_crtc->props_plane, DRMMODE_PLANE__COUNT); - xorg_list_for_each_entry_safe(iterator, next, &drmmode_crtc->mode_list, entry) { - drm_mode_destroy(crtc, iterator); - } -} - -static const xf86CrtcFuncsRec drmmode_crtc_funcs = { - .dpms = drmmode_crtc_dpms, - .set_mode_major = drmmode_set_mode_major, - .set_cursor_colors = drmmode_set_cursor_colors, - .set_cursor_position = drmmode_set_cursor_position, - .show_cursor_check = drmmode_show_cursor, - .hide_cursor = drmmode_hide_cursor, - .load_cursor_argb_check = drmmode_load_cursor_argb_check, - - .gamma_set = drmmode_crtc_gamma_set, - .destroy = drmmode_crtc_destroy, - .set_scanout_pixmap = drmmode_set_scanout_pixmap, - .shadow_allocate = drmmode_shadow_allocate, - .shadow_create = drmmode_shadow_create, - .shadow_destroy = drmmode_shadow_destroy, -}; - -static uint32_t -drmmode_crtc_vblank_pipe(int crtc_id) -{ - if (crtc_id > 1) - return crtc_id << DRM_VBLANK_HIGH_CRTC_SHIFT; - else if (crtc_id > 0) - return DRM_VBLANK_SECONDARY; - else - return 0; -} - -static Bool -is_plane_assigned(ScrnInfoPtr scrn, int plane_id) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr iter = xf86_config->crtc[c]; - drmmode_crtc_private_ptr drmmode_crtc = iter->driver_private; - if (drmmode_crtc->plane_id == plane_id) - return TRUE; - } - - return FALSE; -} - -/** - * Populates the formats array, and the modifiers of each format for a drm_plane. - */ -static Bool -populate_format_modifiers(xf86CrtcPtr crtc, const drmModePlane *kplane, - uint32_t blob_id) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - unsigned i, j; - drmModePropertyBlobRes *blob; - struct drm_format_modifier_blob *fmt_mod_blob; - uint32_t *blob_formats; - struct drm_format_modifier *blob_modifiers; - - if (!blob_id) - return FALSE; - - blob = drmModeGetPropertyBlob(drmmode->fd, blob_id); - if (!blob) - return FALSE; - - fmt_mod_blob = blob->data; - blob_formats = formats_ptr(fmt_mod_blob); - blob_modifiers = modifiers_ptr(fmt_mod_blob); - - assert(drmmode_crtc->num_formats == fmt_mod_blob->count_formats); - - for (i = 0; i < fmt_mod_blob->count_formats; i++) { - uint32_t num_modifiers = 0; - uint64_t *modifiers = NULL; - uint64_t *tmp; - for (j = 0; j < fmt_mod_blob->count_modifiers; j++) { - struct drm_format_modifier *mod = &blob_modifiers[j]; - - if ((i < mod->offset) || (i > mod->offset + 63)) - continue; - if (!(mod->formats & (1 << (i - mod->offset)))) - continue; - - num_modifiers++; - tmp = realloc(modifiers, num_modifiers * sizeof(modifiers[0])); - if (!tmp) { - free(modifiers); - drmModeFreePropertyBlob(blob); - return FALSE; - } - modifiers = tmp; - modifiers[num_modifiers - 1] = mod->modifier; - } - - drmmode_crtc->formats[i].format = blob_formats[i]; - drmmode_crtc->formats[i].modifiers = modifiers; - drmmode_crtc->formats[i].num_modifiers = num_modifiers; - } - - drmModeFreePropertyBlob(blob); - - return TRUE; -} - -static void -drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - drmModePlaneRes *kplane_res; - drmModePlane *kplane, *best_kplane = NULL; - drmModeObjectProperties *props; - uint32_t i, type, blob_id; - int current_crtc, best_plane = 0; - - static drmmode_prop_enum_info_rec plane_type_enums[] = { - [DRMMODE_PLANE_TYPE_PRIMARY] = { - .name = "Primary", - }, - [DRMMODE_PLANE_TYPE_OVERLAY] = { - .name = "Overlay", - }, - [DRMMODE_PLANE_TYPE_CURSOR] = { - .name = "Cursor", - }, - }; - static const drmmode_prop_info_rec plane_props[] = { - [DRMMODE_PLANE_TYPE] = { - .name = "type", - .enum_values = plane_type_enums, - .num_enum_values = DRMMODE_PLANE_TYPE__COUNT, - }, - [DRMMODE_PLANE_FB_ID] = { .name = "FB_ID", }, - [DRMMODE_PLANE_CRTC_ID] = { .name = "CRTC_ID", }, - [DRMMODE_PLANE_IN_FORMATS] = { .name = "IN_FORMATS", }, - [DRMMODE_PLANE_SRC_X] = { .name = "SRC_X", }, - [DRMMODE_PLANE_SRC_Y] = { .name = "SRC_Y", }, - [DRMMODE_PLANE_SRC_W] = { .name = "SRC_W", }, - [DRMMODE_PLANE_SRC_H] = { .name = "SRC_H", }, - [DRMMODE_PLANE_CRTC_X] = { .name = "CRTC_X", }, - [DRMMODE_PLANE_CRTC_Y] = { .name = "CRTC_Y", }, - [DRMMODE_PLANE_CRTC_W] = { .name = "CRTC_W", }, - [DRMMODE_PLANE_CRTC_H] = { .name = "CRTC_H", }, - }; - drmmode_prop_info_rec tmp_props[DRMMODE_PLANE__COUNT]; - - if (!drmmode_prop_info_copy(tmp_props, plane_props, DRMMODE_PLANE__COUNT, 0)) { - xf86DrvMsg(drmmode->scrn->scrnIndex, X_ERROR, - "failed to copy plane property info\n"); - drmmode_prop_info_free(tmp_props, DRMMODE_PLANE__COUNT); - return; - } - - kplane_res = drmModeGetPlaneResources(drmmode->fd); - if (!kplane_res) { - xf86DrvMsg(drmmode->scrn->scrnIndex, X_ERROR, - "failed to get plane resources: %s\n", strerror(errno)); - drmmode_prop_info_free(tmp_props, DRMMODE_PLANE__COUNT); - return; - } - - for (i = 0; i < kplane_res->count_planes; i++) { - int plane_id; - - kplane = drmModeGetPlane(drmmode->fd, kplane_res->planes[i]); - if (!kplane) - continue; - - if (!(kplane->possible_crtcs & (1 << num)) || - is_plane_assigned(drmmode->scrn, kplane->plane_id)) { - drmModeFreePlane(kplane); - continue; - } - - plane_id = kplane->plane_id; - - props = drmModeObjectGetProperties(drmmode->fd, plane_id, - DRM_MODE_OBJECT_PLANE); - if (!props) { - xf86DrvMsg(drmmode->scrn->scrnIndex, X_ERROR, - "couldn't get plane properties\n"); - drmModeFreePlane(kplane); - continue; - } - - drmmode_prop_info_update(drmmode, tmp_props, DRMMODE_PLANE__COUNT, props); - - /* Only primary planes are important for atomic page-flipping */ - type = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_TYPE], - props, DRMMODE_PLANE_TYPE__COUNT); - if (type != DRMMODE_PLANE_TYPE_PRIMARY) { - drmModeFreePlane(kplane); - drmModeFreeObjectProperties(props); - continue; - } - - /* Check if plane is already on this CRTC */ - current_crtc = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_CRTC_ID], - props, 0); - if (current_crtc == drmmode_crtc->mode_crtc->crtc_id) { - if (best_plane) { - drmModeFreePlane(best_kplane); - drmmode_prop_info_free(drmmode_crtc->props_plane, DRMMODE_PLANE__COUNT); - } - best_plane = plane_id; - best_kplane = kplane; - blob_id = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_IN_FORMATS], - props, 0); - drmmode_prop_info_copy(drmmode_crtc->props_plane, tmp_props, - DRMMODE_PLANE__COUNT, 1); - drmModeFreeObjectProperties(props); - break; - } - - if (!best_plane) { - best_plane = plane_id; - best_kplane = kplane; - blob_id = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_IN_FORMATS], - props, 0); - drmmode_prop_info_copy(drmmode_crtc->props_plane, tmp_props, - DRMMODE_PLANE__COUNT, 1); - } else { - drmModeFreePlane(kplane); - } - - drmModeFreeObjectProperties(props); - } - - drmmode_crtc->plane_id = best_plane; - if (best_kplane) { - drmmode_crtc->num_formats = best_kplane->count_formats; - drmmode_crtc->formats = calloc(sizeof(drmmode_format_rec), - best_kplane->count_formats); - if (!populate_format_modifiers(crtc, best_kplane, blob_id)) { - for (i = 0; i < best_kplane->count_formats; i++) - drmmode_crtc->formats[i].format = best_kplane->formats[i]; - } - drmModeFreePlane(best_kplane); - } - - drmmode_prop_info_free(tmp_props, DRMMODE_PLANE__COUNT); - drmModeFreePlaneResources(kplane_res); -} - -static uint32_t -drmmode_crtc_get_prop_id(uint32_t drm_fd, - drmModeObjectPropertiesPtr props, - char const* name) -{ - uint32_t i, prop_id = 0; - - for (i = 0; !prop_id && i < props->count_props; ++i) { - drmModePropertyPtr drm_prop = - drmModeGetProperty(drm_fd, props->props[i]); - - if (!drm_prop) - continue; - - if (strcmp(drm_prop->name, name) == 0) - prop_id = drm_prop->prop_id; - - drmModeFreeProperty(drm_prop); - } - - return prop_id; -} - -static void -drmmode_crtc_vrr_init(int drm_fd, xf86CrtcPtr crtc) -{ - drmModeObjectPropertiesPtr drm_props; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - - if (drmmode->vrr_prop_id) - return; - - drm_props = drmModeObjectGetProperties(drm_fd, - drmmode_crtc->mode_crtc->crtc_id, - DRM_MODE_OBJECT_CRTC); - - if (!drm_props) - return; - - drmmode->vrr_prop_id = drmmode_crtc_get_prop_id(drm_fd, - drm_props, - "VRR_ENABLED"); - - drmModeFreeObjectProperties(drm_props); -} - -static unsigned int -drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, int num) -{ - xf86CrtcPtr crtc; - drmmode_crtc_private_ptr drmmode_crtc; - modesettingEntPtr ms_ent = ms_ent_priv(pScrn); - drmModeObjectPropertiesPtr props; - static const drmmode_prop_info_rec crtc_props[] = { - [DRMMODE_CRTC_ACTIVE] = { .name = "ACTIVE" }, - [DRMMODE_CRTC_MODE_ID] = { .name = "MODE_ID" }, - [DRMMODE_CRTC_GAMMA_LUT] = { .name = "GAMMA_LUT" }, - [DRMMODE_CRTC_GAMMA_LUT_SIZE] = { .name = "GAMMA_LUT_SIZE" }, - [DRMMODE_CRTC_CTM] = { .name = "CTM" }, - }; - - crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs); - if (crtc == NULL) - return 0; - drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1); - crtc->driver_private = drmmode_crtc; - drmmode_crtc->mode_crtc = - drmModeGetCrtc(drmmode->fd, mode_res->crtcs[num]); - drmmode_crtc->drmmode = drmmode; - drmmode_crtc->vblank_pipe = drmmode_crtc_vblank_pipe(num); - xorg_list_init(&drmmode_crtc->mode_list); - - props = drmModeObjectGetProperties(drmmode->fd, mode_res->crtcs[num], - DRM_MODE_OBJECT_CRTC); - if (!props || !drmmode_prop_info_copy(drmmode_crtc->props, crtc_props, - DRMMODE_CRTC__COUNT, 0)) { - xf86CrtcDestroy(crtc); - return 0; - } - - drmmode_prop_info_update(drmmode, drmmode_crtc->props, - DRMMODE_CRTC__COUNT, props); - drmModeFreeObjectProperties(props); - drmmode_crtc_create_planes(crtc, num); - - /* Hide any cursors which may be active from previous users */ - drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, 0, 0); - - drmmode_crtc_vrr_init(drmmode->fd, crtc); - - /* Mark num'th crtc as in use on this device. */ - ms_ent->assigned_crtcs |= (1 << num); - xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, MS_LOGLEVEL_DEBUG, - "Allocated crtc nr. %d to this screen.\n", num); - - if (drmmode_crtc->props[DRMMODE_CRTC_GAMMA_LUT_SIZE].prop_id && - drmmode_crtc->props[DRMMODE_CRTC_GAMMA_LUT_SIZE].value) { - /* - * GAMMA_LUT property supported, and so far tested to be safe to use by - * default for lut sizes up to 4096 slots. Intel Tigerlake+ has some - * issues, and a large GAMMA_LUT with 262145 slots, so keep GAMMA_LUT - * off for large lut sizes by default for now. - */ - drmmode_crtc->use_gamma_lut = drmmode_crtc->props[DRMMODE_CRTC_GAMMA_LUT_SIZE].value <= 4096; - - /* Allow config override. */ - drmmode_crtc->use_gamma_lut = xf86ReturnOptValBool(drmmode->Options, - OPTION_USE_GAMMA_LUT, - drmmode_crtc->use_gamma_lut); - } else { - drmmode_crtc->use_gamma_lut = FALSE; - } - - if (drmmode_crtc->use_gamma_lut && - drmmode_crtc->props[DRMMODE_CRTC_CTM].prop_id) { - drmmode->use_ctm = TRUE; - } - - return 1; -} - -/* - * Update all of the property values for an output - */ -static void -drmmode_output_update_properties(xf86OutputPtr output) -{ - drmmode_output_private_ptr drmmode_output = output->driver_private; - int i, j, k; - int err; - drmModeConnectorPtr koutput; - - /* Use the most recently fetched values from the kernel */ - koutput = drmmode_output->mode_output; - - if (!koutput) - return; - - for (i = 0; i < drmmode_output->num_props; i++) { - drmmode_prop_ptr p = &drmmode_output->props[i]; - - for (j = 0; koutput && j < koutput->count_props; j++) { - if (koutput->props[j] == p->mode_prop->prop_id) { - - /* Check to see if the property value has changed */ - if (koutput->prop_values[j] != p->value) { - - p->value = koutput->prop_values[j]; - - if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) { - INT32 value = p->value; - - err = RRChangeOutputProperty(output->randr_output, p->atoms[0], - XA_INTEGER, 32, PropModeReplace, 1, - &value, FALSE, TRUE); - - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - } - else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) { - for (k = 0; k < p->mode_prop->count_enums; k++) - if (p->mode_prop->enums[k].value == p->value) - break; - if (k < p->mode_prop->count_enums) { - err = RRChangeOutputProperty(output->randr_output, p->atoms[0], - XA_ATOM, 32, PropModeReplace, 1, - &p->atoms[k + 1], FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - } - } - } - break; - } - } - } - - /* Update the CTM property */ - if (drmmode_output->ctm_atom) { - err = RRChangeOutputProperty(output->randr_output, - drmmode_output->ctm_atom, - XA_INTEGER, 32, PropModeReplace, 18, - &drmmode_output->ctm, - FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - } - -} - -static xf86OutputStatus -drmmode_output_detect(xf86OutputPtr output) -{ - /* go to the hw and retrieve a new output struct */ - drmmode_output_private_ptr drmmode_output = output->driver_private; - drmmode_ptr drmmode = drmmode_output->drmmode; - xf86OutputStatus status; - - if (drmmode_output->output_id == -1) - return XF86OutputStatusDisconnected; - - drmModeFreeConnector(drmmode_output->mode_output); - - drmmode_output->mode_output = - drmModeGetConnector(drmmode->fd, drmmode_output->output_id); - - if (!drmmode_output->mode_output) { - drmmode_output->output_id = -1; - return XF86OutputStatusDisconnected; - } - - drmmode_output_update_properties(output); - - switch (drmmode_output->mode_output->connection) { - case DRM_MODE_CONNECTED: - status = XF86OutputStatusConnected; - break; - case DRM_MODE_DISCONNECTED: - status = XF86OutputStatusDisconnected; - break; - default: - case DRM_MODE_UNKNOWNCONNECTION: - status = XF86OutputStatusUnknown; - break; - } - return status; -} - -static Bool -drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes) -{ - return MODE_OK; -} - -static int -koutput_get_prop_idx(int fd, drmModeConnectorPtr koutput, - int type, const char *name) -{ - int idx = -1; - - for (int i = 0; i < koutput->count_props; i++) { - drmModePropertyPtr prop = drmModeGetProperty(fd, koutput->props[i]); - - if (!prop) - continue; - - if (drm_property_type_is(prop, type) && !strcmp(prop->name, name)) - idx = i; - - drmModeFreeProperty(prop); - - if (idx > -1) - break; - } - - return idx; -} - -static int -koutput_get_prop_id(int fd, drmModeConnectorPtr koutput, - int type, const char *name) -{ - int idx = koutput_get_prop_idx(fd, koutput, type, name); - - return (idx > -1) ? koutput->props[idx] : -1; -} - -static drmModePropertyBlobPtr -koutput_get_prop_blob(int fd, drmModeConnectorPtr koutput, const char *name) -{ - drmModePropertyBlobPtr blob = NULL; - int idx = koutput_get_prop_idx(fd, koutput, DRM_MODE_PROP_BLOB, name); - - if (idx > -1) - blob = drmModeGetPropertyBlob(fd, koutput->prop_values[idx]); - - return blob; -} - -static void -drmmode_output_attach_tile(xf86OutputPtr output) -{ - drmmode_output_private_ptr drmmode_output = output->driver_private; - drmModeConnectorPtr koutput = drmmode_output->mode_output; - drmmode_ptr drmmode = drmmode_output->drmmode; - struct xf86CrtcTileInfo tile_info, *set = NULL; - - if (!koutput) { - xf86OutputSetTile(output, NULL); - return; - } - - drmModeFreePropertyBlob(drmmode_output->tile_blob); - - /* look for a TILE property */ - drmmode_output->tile_blob = - koutput_get_prop_blob(drmmode->fd, koutput, "TILE"); - - if (drmmode_output->tile_blob) { - if (xf86OutputParseKMSTile(drmmode_output->tile_blob->data, drmmode_output->tile_blob->length, &tile_info) == TRUE) - set = &tile_info; - } - xf86OutputSetTile(output, set); -} - -static Bool -has_panel_fitter(xf86OutputPtr output) -{ - drmmode_output_private_ptr drmmode_output = output->driver_private; - drmModeConnectorPtr koutput = drmmode_output->mode_output; - drmmode_ptr drmmode = drmmode_output->drmmode; - int idx; - - /* Presume that if the output supports scaling, then we have a - * panel fitter capable of adjust any mode to suit. - */ - idx = koutput_get_prop_idx(drmmode->fd, koutput, - DRM_MODE_PROP_ENUM, "scaling mode"); - - return (idx > -1); -} - -static DisplayModePtr -drmmode_output_add_gtf_modes(xf86OutputPtr output, DisplayModePtr Modes) -{ - xf86MonPtr mon = output->MonInfo; - DisplayModePtr i, m, preferred = NULL; - int max_x = 0, max_y = 0; - float max_vrefresh = 0.0; - - if (mon && gtf_supported(mon)) - return Modes; - - if (!has_panel_fitter(output)) - return Modes; - - for (m = Modes; m; m = m->next) { - if (m->type & M_T_PREFERRED) - preferred = m; - max_x = max(max_x, m->HDisplay); - max_y = max(max_y, m->VDisplay); - max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(m)); - } - - max_vrefresh = max(max_vrefresh, 60.0); - max_vrefresh *= (1 + SYNC_TOLERANCE); - - m = xf86GetDefaultModes(); - xf86ValidateModesSize(output->scrn, m, max_x, max_y, 0); - - for (i = m; i; i = i->next) { - if (xf86ModeVRefresh(i) > max_vrefresh) - i->status = MODE_VSYNC; - if (preferred && - i->HDisplay >= preferred->HDisplay && - i->VDisplay >= preferred->VDisplay && - xf86ModeVRefresh(i) >= xf86ModeVRefresh(preferred)) - i->status = MODE_VSYNC; - } - - xf86PruneInvalidModes(output->scrn, &m, FALSE); - - return xf86ModesAdd(Modes, m); -} - -static DisplayModePtr -drmmode_output_get_modes(xf86OutputPtr output) -{ - drmmode_output_private_ptr drmmode_output = output->driver_private; - drmModeConnectorPtr koutput = drmmode_output->mode_output; - drmmode_ptr drmmode = drmmode_output->drmmode; - int i; - DisplayModePtr Modes = NULL, Mode; - xf86MonPtr mon = NULL; - - if (!koutput) - return NULL; - - drmModeFreePropertyBlob(drmmode_output->edid_blob); - - /* look for an EDID property */ - drmmode_output->edid_blob = - koutput_get_prop_blob(drmmode->fd, koutput, "EDID"); - - if (drmmode_output->edid_blob) { - mon = xf86InterpretEDID(output->scrn->scrnIndex, - drmmode_output->edid_blob->data); - if (mon && drmmode_output->edid_blob->length > 128) - mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA; - } - xf86OutputSetEDID(output, mon); - - drmmode_output_attach_tile(output); - - /* modes should already be available */ - for (i = 0; i < koutput->count_modes; i++) { - Mode = xnfalloc(sizeof(DisplayModeRec)); - - drmmode_ConvertFromKMode(output->scrn, &koutput->modes[i], Mode); - Modes = xf86ModesAdd(Modes, Mode); - - } - - return drmmode_output_add_gtf_modes(output, Modes); -} - -static void -drmmode_output_destroy(xf86OutputPtr output) -{ - drmmode_output_private_ptr drmmode_output = output->driver_private; - int i; - - drmModeFreePropertyBlob(drmmode_output->edid_blob); - drmModeFreePropertyBlob(drmmode_output->tile_blob); - - for (i = 0; i < drmmode_output->num_props; i++) { - drmModeFreeProperty(drmmode_output->props[i].mode_prop); - free(drmmode_output->props[i].atoms); - } - free(drmmode_output->props); - if (drmmode_output->mode_output) { - for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) { - drmModeFreeEncoder(drmmode_output->mode_encoders[i]); - } - drmModeFreeConnector(drmmode_output->mode_output); - } - free(drmmode_output->mode_encoders); - free(drmmode_output); - output->driver_private = NULL; -} - -static void -drmmode_output_dpms(xf86OutputPtr output, int mode) -{ - modesettingPtr ms = modesettingPTR(output->scrn); - drmmode_output_private_ptr drmmode_output = output->driver_private; - drmmode_ptr drmmode = drmmode_output->drmmode; - xf86CrtcPtr crtc = output->crtc; - drmModeConnectorPtr koutput = drmmode_output->mode_output; - - if (!koutput) - return; - - /* XXX Check if DPMS mode is already the right one */ - - drmmode_output->dpms = mode; - - if (ms->atomic_modeset) { - if (mode != DPMSModeOn && !ms->pending_modeset) - drmmode_output_disable(output); - } else { - drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id, - drmmode_output->dpms_enum_id, mode); - } - - if (crtc) { - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - if (mode == DPMSModeOn) { - if (drmmode_crtc->need_modeset) - drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation, - crtc->x, crtc->y); - - if (drmmode_crtc->enable_flipping) - drmmode_InitSharedPixmapFlipping(crtc, drmmode_crtc->drmmode); - } else { - if (drmmode_crtc->enable_flipping) - drmmode_FiniSharedPixmapFlipping(crtc, drmmode_crtc->drmmode); - } - } - - return; -} - -static Bool -drmmode_property_ignore(drmModePropertyPtr prop) -{ - if (!prop) - return TRUE; - /* ignore blob prop */ - if (prop->flags & DRM_MODE_PROP_BLOB) - return TRUE; - /* ignore standard property */ - if (!strcmp(prop->name, "EDID") || !strcmp(prop->name, "DPMS") || - !strcmp(prop->name, "CRTC_ID")) - return TRUE; - - return FALSE; -} - -static void -drmmode_output_create_resources(xf86OutputPtr output) -{ - drmmode_output_private_ptr drmmode_output = output->driver_private; - drmModeConnectorPtr mode_output = drmmode_output->mode_output; - drmmode_ptr drmmode = drmmode_output->drmmode; - drmModePropertyPtr drmmode_prop; - int i, j, err; - - drmmode_output->props = - calloc(mode_output->count_props, sizeof(drmmode_prop_rec)); - if (!drmmode_output->props) - return; - - drmmode_output->num_props = 0; - for (i = 0, j = 0; i < mode_output->count_props; i++) { - drmmode_prop = drmModeGetProperty(drmmode->fd, mode_output->props[i]); - if (drmmode_property_ignore(drmmode_prop)) { - drmModeFreeProperty(drmmode_prop); - continue; - } - drmmode_output->props[j].mode_prop = drmmode_prop; - drmmode_output->props[j].value = mode_output->prop_values[i]; - drmmode_output->num_props++; - j++; - } - - /* Create CONNECTOR_ID property */ - { - Atom name = MakeAtom("CONNECTOR_ID", 12, TRUE); - INT32 value = mode_output->connector_id; - - if (name != BAD_RESOURCE) { - err = RRConfigureOutputProperty(output->randr_output, name, - FALSE, FALSE, TRUE, - 1, &value); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - err = RRChangeOutputProperty(output->randr_output, name, - XA_INTEGER, 32, PropModeReplace, 1, - &value, FALSE, FALSE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - } - } - - if (drmmode->use_ctm) { - Atom name = MakeAtom("CTM", 3, TRUE); - - if (name != BAD_RESOURCE) { - drmmode_output->ctm_atom = name; - - err = RRConfigureOutputProperty(output->randr_output, name, - FALSE, FALSE, TRUE, 0, NULL); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - - err = RRChangeOutputProperty(output->randr_output, name, - XA_INTEGER, 32, PropModeReplace, 18, - &ctm_identity, FALSE, FALSE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - - drmmode_output->ctm = ctm_identity; - } - } - - for (i = 0; i < drmmode_output->num_props; i++) { - drmmode_prop_ptr p = &drmmode_output->props[i]; - - drmmode_prop = p->mode_prop; - - if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) { - INT32 prop_range[2]; - INT32 value = p->value; - - p->num_atoms = 1; - p->atoms = calloc(p->num_atoms, sizeof(Atom)); - if (!p->atoms) - continue; - p->atoms[0] = - MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE); - prop_range[0] = drmmode_prop->values[0]; - prop_range[1] = drmmode_prop->values[1]; - err = RRConfigureOutputProperty(output->randr_output, p->atoms[0], - FALSE, TRUE, - drmmode_prop-> - flags & DRM_MODE_PROP_IMMUTABLE ? - TRUE : FALSE, 2, prop_range); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - err = RRChangeOutputProperty(output->randr_output, p->atoms[0], - XA_INTEGER, 32, PropModeReplace, 1, - &value, FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - } - else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) { - p->num_atoms = drmmode_prop->count_enums + 1; - p->atoms = calloc(p->num_atoms, sizeof(Atom)); - if (!p->atoms) - continue; - p->atoms[0] = - MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE); - for (j = 1; j <= drmmode_prop->count_enums; j++) { - struct drm_mode_property_enum *e = &drmmode_prop->enums[j - 1]; - - p->atoms[j] = MakeAtom(e->name, strlen(e->name), TRUE); - } - err = RRConfigureOutputProperty(output->randr_output, p->atoms[0], - FALSE, FALSE, - drmmode_prop-> - flags & DRM_MODE_PROP_IMMUTABLE ? - TRUE : FALSE, p->num_atoms - 1, - (INT32 *) &p->atoms[1]); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRConfigureOutputProperty error, %d\n", err); - } - for (j = 0; j < drmmode_prop->count_enums; j++) - if (drmmode_prop->enums[j].value == p->value) - break; - /* there's always a matching value */ - err = RRChangeOutputProperty(output->randr_output, p->atoms[0], - XA_ATOM, 32, PropModeReplace, 1, - &p->atoms[j + 1], FALSE, TRUE); - if (err != 0) { - xf86DrvMsg(output->scrn->scrnIndex, X_ERROR, - "RRChangeOutputProperty error, %d\n", err); - } - } - } -} - -static Bool -drmmode_output_set_property(xf86OutputPtr output, Atom property, - RRPropertyValuePtr value) -{ - drmmode_output_private_ptr drmmode_output = output->driver_private; - drmmode_ptr drmmode = drmmode_output->drmmode; - int i; - - for (i = 0; i < drmmode_output->num_props; i++) { - drmmode_prop_ptr p = &drmmode_output->props[i]; - - if (p->atoms[0] != property) - continue; - - if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) { - uint32_t val; - - if (value->type != XA_INTEGER || value->format != 32 || - value->size != 1) - return FALSE; - val = *(uint32_t *) value->data; - - drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id, - p->mode_prop->prop_id, (uint64_t) val); - return TRUE; - } - else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) { - Atom atom; - const char *name; - int j; - - if (value->type != XA_ATOM || value->format != 32 || - value->size != 1) - return FALSE; - memcpy(&atom, value->data, 4); - if (!(name = NameForAtom(atom))) - return FALSE; - - /* search for matching name string, then set its value down */ - for (j = 0; j < p->mode_prop->count_enums; j++) { - if (!strcmp(p->mode_prop->enums[j].name, name)) { - drmModeConnectorSetProperty(drmmode->fd, - drmmode_output->output_id, - p->mode_prop->prop_id, - p->mode_prop->enums[j].value); - return TRUE; - } - } - } - } - - if (property == drmmode_output->ctm_atom) { - const size_t matrix_size = sizeof(drmmode_output->ctm); - - if (value->type != XA_INTEGER || value->format != 32 || - value->size * 4 != matrix_size) - return FALSE; - - memcpy(&drmmode_output->ctm, value->data, matrix_size); - - // Update the CRTC if there is one bound to this output. - if (output->crtc) { - drmmode_set_ctm(output->crtc, &drmmode_output->ctm); - } - } - - return TRUE; -} - -static Bool -drmmode_output_get_property(xf86OutputPtr output, Atom property) -{ - return TRUE; -} - -static const xf86OutputFuncsRec drmmode_output_funcs = { - .dpms = drmmode_output_dpms, - .create_resources = drmmode_output_create_resources, - .set_property = drmmode_output_set_property, - .get_property = drmmode_output_get_property, - .detect = drmmode_output_detect, - .mode_valid = drmmode_output_mode_valid, - - .get_modes = drmmode_output_get_modes, - .destroy = drmmode_output_destroy -}; - -static int subpixel_conv_table[7] = { - 0, - SubPixelUnknown, - SubPixelHorizontalRGB, - SubPixelHorizontalBGR, - SubPixelVerticalRGB, - SubPixelVerticalBGR, - SubPixelNone -}; - -static const char *const output_names[] = { - "None", - "VGA", - "DVI-I", - "DVI-D", - "DVI-A", - "Composite", - "SVIDEO", - "LVDS", - "Component", - "DIN", - "DP", - "HDMI", - "HDMI-B", - "TV", - "eDP", - "Virtual", - "DSI", - "DPI", -}; - -static xf86OutputPtr find_output(ScrnInfoPtr pScrn, int id) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int i; - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - drmmode_output_private_ptr drmmode_output; - - drmmode_output = output->driver_private; - if (drmmode_output->output_id == id) - return output; - } - return NULL; -} - -static int parse_path_blob(drmModePropertyBlobPtr path_blob, int *conn_base_id, char **path) -{ - char *conn; - char conn_id[5]; - int id, len; - char *blob_data; - - if (!path_blob) - return -1; - - blob_data = path_blob->data; - /* we only handle MST paths for now */ - if (strncmp(blob_data, "mst:", 4)) - return -1; - - conn = strchr(blob_data + 4, '-'); - if (!conn) - return -1; - len = conn - (blob_data + 4); - if (len + 1> 5) - return -1; - memcpy(conn_id, blob_data + 4, len); - conn_id[len] = '\0'; - id = strtoul(conn_id, NULL, 10); - - *conn_base_id = id; - - *path = conn + 1; - return 0; -} - -static void -drmmode_create_name(ScrnInfoPtr pScrn, drmModeConnectorPtr koutput, char *name, - drmModePropertyBlobPtr path_blob) -{ - int ret; - char *extra_path; - int conn_id; - xf86OutputPtr output; - - ret = parse_path_blob(path_blob, &conn_id, &extra_path); - if (ret == -1) - goto fallback; - - output = find_output(pScrn, conn_id); - if (!output) - goto fallback; - - snprintf(name, 32, "%s-%s", output->name, extra_path); - return; - - fallback: - if (koutput->connector_type >= ARRAY_SIZE(output_names)) - snprintf(name, 32, "Unknown%d-%d", koutput->connector_type, koutput->connector_type_id); - else if (pScrn->is_gpu) - snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id); - else - snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id); -} - -static Bool -drmmode_connector_check_vrr_capable(uint32_t drm_fd, int connector_id) -{ - uint32_t i; - Bool found = FALSE; - uint64_t prop_value = 0; - drmModeObjectPropertiesPtr props; - const char* prop_name = "VRR_CAPABLE"; - - props = drmModeObjectGetProperties(drm_fd, connector_id, - DRM_MODE_OBJECT_CONNECTOR); - - for (i = 0; !found && i < props->count_props; ++i) { - drmModePropertyPtr drm_prop = drmModeGetProperty(drm_fd, props->props[i]); - - if (!drm_prop) - continue; - - if (strcasecmp(drm_prop->name, prop_name) == 0) { - prop_value = props->prop_values[i]; - found = TRUE; - } - - drmModeFreeProperty(drm_prop); - } - - drmModeFreeObjectProperties(props); - - if(found) - return prop_value ? TRUE : FALSE; - - return FALSE; -} - -static unsigned int -drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res, int num, Bool dynamic, int crtcshift) -{ - xf86OutputPtr output; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - modesettingPtr ms = modesettingPTR(pScrn); - drmModeConnectorPtr koutput; - drmModeEncoderPtr *kencoders = NULL; - drmmode_output_private_ptr drmmode_output; - char name[32]; - int i; - Bool nonDesktop = FALSE; - drmModePropertyBlobPtr path_blob = NULL; - const char *s; - drmModeObjectPropertiesPtr props; - static const drmmode_prop_info_rec connector_props[] = { - [DRMMODE_CONNECTOR_CRTC_ID] = { .name = "CRTC_ID", }, - }; - - koutput = - drmModeGetConnector(drmmode->fd, mode_res->connectors[num]); - if (!koutput) - return 0; - - path_blob = koutput_get_prop_blob(drmmode->fd, koutput, "PATH"); - i = koutput_get_prop_idx(drmmode->fd, koutput, DRM_MODE_PROP_RANGE, RR_PROPERTY_NON_DESKTOP); - if (i >= 0) - nonDesktop = koutput->prop_values[i] != 0; - - drmmode_create_name(pScrn, koutput, name, path_blob); - - if (path_blob) - drmModeFreePropertyBlob(path_blob); - - if (path_blob && dynamic) { - /* see if we have an output with this name already - and hook stuff up */ - for (i = 0; i < xf86_config->num_output; i++) { - output = xf86_config->output[i]; - - if (strncmp(output->name, name, 32)) - continue; - - drmmode_output = output->driver_private; - drmmode_output->output_id = mode_res->connectors[num]; - drmmode_output->mode_output = koutput; - output->non_desktop = nonDesktop; - return 1; - } - } - - kencoders = calloc(sizeof(drmModeEncoderPtr), koutput->count_encoders); - if (!kencoders) { - goto out_free_encoders; - } - - for (i = 0; i < koutput->count_encoders; i++) { - kencoders[i] = drmModeGetEncoder(drmmode->fd, koutput->encoders[i]); - if (!kencoders[i]) { - goto out_free_encoders; - } - } - - if (xf86IsEntityShared(pScrn->entityList[0])) { - if ((s = xf86GetOptValString(drmmode->Options, OPTION_ZAPHOD_HEADS))) { - if (!drmmode_zaphod_string_matches(pScrn, s, name)) - goto out_free_encoders; - } else { - if (!drmmode->is_secondary && (num != 0)) - goto out_free_encoders; - else if (drmmode->is_secondary && (num != 1)) - goto out_free_encoders; - } - } - - output = xf86OutputCreate(pScrn, &drmmode_output_funcs, name); - if (!output) { - goto out_free_encoders; - } - - drmmode_output = calloc(sizeof(drmmode_output_private_rec), 1); - if (!drmmode_output) { - xf86OutputDestroy(output); - goto out_free_encoders; - } - - drmmode_output->output_id = mode_res->connectors[num]; - drmmode_output->mode_output = koutput; - drmmode_output->mode_encoders = kencoders; - drmmode_output->drmmode = drmmode; - output->mm_width = koutput->mmWidth; - output->mm_height = koutput->mmHeight; - - output->subpixel_order = subpixel_conv_table[koutput->subpixel]; - output->interlaceAllowed = TRUE; - output->doubleScanAllowed = TRUE; - output->driver_private = drmmode_output; - output->non_desktop = nonDesktop; - - output->possible_crtcs = 0; - for (i = 0; i < koutput->count_encoders; i++) { - output->possible_crtcs |= (kencoders[i]->possible_crtcs >> crtcshift) & 0x7f; - } - /* work out the possible clones later */ - output->possible_clones = 0; - - if (ms->atomic_modeset) { - if (!drmmode_prop_info_copy(drmmode_output->props_connector, - connector_props, DRMMODE_CONNECTOR__COUNT, - 0)) { - goto out_free_encoders; - } - props = drmModeObjectGetProperties(drmmode->fd, - drmmode_output->output_id, - DRM_MODE_OBJECT_CONNECTOR); - drmmode_prop_info_update(drmmode, drmmode_output->props_connector, - DRMMODE_CONNECTOR__COUNT, props); - } else { - drmmode_output->dpms_enum_id = - koutput_get_prop_id(drmmode->fd, koutput, DRM_MODE_PROP_ENUM, - "DPMS"); - } - - if (dynamic) { - output->randr_output = RROutputCreate(xf86ScrnToScreen(pScrn), output->name, strlen(output->name), output); - if (output->randr_output) { - drmmode_output_create_resources(output); - RRPostPendingProperties(output->randr_output); - } - } - - ms->is_connector_vrr_capable |= - drmmode_connector_check_vrr_capable(drmmode->fd, - drmmode_output->output_id); - return 1; - - out_free_encoders: - if (kencoders) { - for (i = 0; i < koutput->count_encoders; i++) - drmModeFreeEncoder(kencoders[i]); - free(kencoders); - } - drmModeFreeConnector(koutput); - - return 0; -} - -static uint32_t -find_clones(ScrnInfoPtr scrn, xf86OutputPtr output) -{ - drmmode_output_private_ptr drmmode_output = - output->driver_private, clone_drmout; - int i; - xf86OutputPtr clone_output; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int index_mask = 0; - - if (drmmode_output->enc_clone_mask == 0) - return index_mask; - - for (i = 0; i < xf86_config->num_output; i++) { - clone_output = xf86_config->output[i]; - clone_drmout = clone_output->driver_private; - if (output == clone_output) - continue; - - if (clone_drmout->enc_mask == 0) - continue; - if (drmmode_output->enc_clone_mask == clone_drmout->enc_mask) - index_mask |= (1 << i); - } - return index_mask; -} - -static void -drmmode_clones_init(ScrnInfoPtr scrn, drmmode_ptr drmmode, drmModeResPtr mode_res) -{ - int i, j; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - drmmode_output_private_ptr drmmode_output; - - drmmode_output = output->driver_private; - drmmode_output->enc_clone_mask = 0xff; - /* and all the possible encoder clones for this output together */ - for (j = 0; j < drmmode_output->mode_output->count_encoders; j++) { - int k; - - for (k = 0; k < mode_res->count_encoders; k++) { - if (mode_res->encoders[k] == - drmmode_output->mode_encoders[j]->encoder_id) - drmmode_output->enc_mask |= (1 << k); - } - - drmmode_output->enc_clone_mask &= - drmmode_output->mode_encoders[j]->possible_clones; - } - } - - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - - output->possible_clones = find_clones(scrn, output); - } -} - -static Bool -drmmode_set_pixmap_bo(drmmode_ptr drmmode, PixmapPtr pixmap, drmmode_bo *bo) -{ -#ifdef GLAMOR_HAS_GBM - ScrnInfoPtr scrn = drmmode->scrn; - modesettingPtr ms = modesettingPTR(scrn); - - if (!drmmode->glamor) - return TRUE; - - if (!ms->glamor.egl_create_textured_pixmap_from_gbm_bo(pixmap, bo->gbm, - bo->used_modifiers)) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, "Failed to create pixmap\n"); - return FALSE; - } -#endif - - return TRUE; -} - -Bool -drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode) -{ - ScreenPtr screen = xf86ScrnToScreen(drmmode->scrn); - PixmapPtr screen_pixmap = screen->GetScreenPixmap(screen); - - if (!drmmode_set_pixmap_bo(drmmode, screen_pixmap, &drmmode->front_bo)) - return FALSE; - - return TRUE; -} - -static Bool -drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - modesettingPtr ms = modesettingPTR(scrn); - drmmode_ptr drmmode = &ms->drmmode; - drmmode_bo old_front; - ScreenPtr screen = xf86ScrnToScreen(scrn); - uint32_t old_fb_id; - int i, pitch, old_width, old_height, old_pitch; - int cpp = (scrn->bitsPerPixel + 7) / 8; - int kcpp = (drmmode->kbpp + 7) / 8; - PixmapPtr ppix = screen->GetScreenPixmap(screen); - void *new_pixels = NULL; - - if (scrn->virtualX == width && scrn->virtualY == height) - return TRUE; - - xf86DrvMsg(scrn->scrnIndex, X_INFO, - "Allocate new frame buffer %dx%d stride\n", width, height); - - old_width = scrn->virtualX; - old_height = scrn->virtualY; - old_pitch = drmmode_bo_get_pitch(&drmmode->front_bo); - old_front = drmmode->front_bo; - old_fb_id = drmmode->fb_id; - drmmode->fb_id = 0; - - if (!drmmode_create_bo(drmmode, &drmmode->front_bo, - width, height, drmmode->kbpp)) - goto fail; - - pitch = drmmode_bo_get_pitch(&drmmode->front_bo); - - scrn->virtualX = width; - scrn->virtualY = height; - scrn->displayWidth = pitch / kcpp; - - if (!drmmode->gbm) { - new_pixels = drmmode_map_front_bo(drmmode); - if (!new_pixels) - goto fail; - } - - if (drmmode->shadow_enable) { - uint32_t size = scrn->displayWidth * scrn->virtualY * cpp; - new_pixels = calloc(1, size); - if (new_pixels == NULL) - goto fail; - free(drmmode->shadow_fb); - drmmode->shadow_fb = new_pixels; - } - - if (drmmode->shadow_enable2) { - uint32_t size = scrn->displayWidth * scrn->virtualY * cpp; - void *fb2 = calloc(1, size); - free(drmmode->shadow_fb2); - drmmode->shadow_fb2 = fb2; - } - - screen->ModifyPixmapHeader(ppix, width, height, -1, -1, - scrn->displayWidth * cpp, new_pixels); - - if (!drmmode_glamor_handle_new_screen_pixmap(drmmode)) - goto fail; - - drmmode_clear_pixmap(ppix); - - for (i = 0; i < xf86_config->num_crtc; i++) { - xf86CrtcPtr crtc = xf86_config->crtc[i]; - - if (!crtc->enabled) - continue; - - drmmode_set_mode_major(crtc, &crtc->mode, - crtc->rotation, crtc->x, crtc->y); - } - - if (old_fb_id) - drmModeRmFB(drmmode->fd, old_fb_id); - - drmmode_bo_destroy(drmmode, &old_front); - - return TRUE; - - fail: - drmmode_bo_destroy(drmmode, &drmmode->front_bo); - drmmode->front_bo = old_front; - scrn->virtualX = old_width; - scrn->virtualY = old_height; - scrn->displayWidth = old_pitch / kcpp; - drmmode->fb_id = old_fb_id; - - return FALSE; -} - -static void -drmmode_validate_leases(ScrnInfoPtr scrn) -{ - ScreenPtr screen = scrn->pScreen; - rrScrPrivPtr scr_priv; - modesettingPtr ms = modesettingPTR(scrn); - drmmode_ptr drmmode = &ms->drmmode; - drmModeLesseeListPtr lessees; - RRLeasePtr lease, next; - int l; - - /* Bail out if RandR wasn't initialized. */ - if (!dixPrivateKeyRegistered(rrPrivKey)) - return; - - scr_priv = rrGetScrPriv(screen); - - /* We can't talk to the kernel about leases when VT switched */ - if (!scrn->vtSema) - return; - - lessees = drmModeListLessees(drmmode->fd); - if (!lessees) - return; - - xorg_list_for_each_entry_safe(lease, next, &scr_priv->leases, list) { - drmmode_lease_private_ptr lease_private = lease->devPrivate; - - for (l = 0; l < lessees->count; l++) { - if (lessees->lessees[l] == lease_private->lessee_id) - break; - } - - /* check to see if the lease has gone away */ - if (l == lessees->count) { - free(lease_private); - lease->devPrivate = NULL; - xf86CrtcLeaseTerminated(lease); - } - } - - free(lessees); -} - -static int -drmmode_create_lease(RRLeasePtr lease, int *fd) -{ - ScreenPtr screen = lease->screen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - drmmode_ptr drmmode = &ms->drmmode; - int ncrtc = lease->numCrtcs; - int noutput = lease->numOutputs; - int nobjects; - int c, o; - int i; - int lease_fd; - uint32_t *objects; - drmmode_lease_private_ptr lease_private; - - nobjects = ncrtc + noutput; - - if (ms->atomic_modeset) - nobjects += ncrtc; /* account for planes as well */ - - if (nobjects == 0) - return BadValue; - - lease_private = calloc(1, sizeof (drmmode_lease_private_rec)); - if (!lease_private) - return BadAlloc; - - objects = xallocarray(nobjects, sizeof (uint32_t)); - - if (!objects) { - free(lease_private); - return BadAlloc; - } - - i = 0; - - /* Add CRTC and plane ids */ - for (c = 0; c < ncrtc; c++) { - xf86CrtcPtr crtc = lease->crtcs[c]->devPrivate; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - objects[i++] = drmmode_crtc->mode_crtc->crtc_id; - if (ms->atomic_modeset) - objects[i++] = drmmode_crtc->plane_id; - } - - /* Add connector ids */ - - for (o = 0; o < noutput; o++) { - xf86OutputPtr output = lease->outputs[o]->devPrivate; - drmmode_output_private_ptr drmmode_output = output->driver_private; - - objects[i++] = drmmode_output->mode_output->connector_id; - } - - /* call kernel to create lease */ - assert (i == nobjects); - - lease_fd = drmModeCreateLease(drmmode->fd, objects, nobjects, 0, &lease_private->lessee_id); - - free(objects); - - if (lease_fd < 0) { - free(lease_private); - return BadMatch; - } - - lease->devPrivate = lease_private; - - xf86CrtcLeaseStarted(lease); - - *fd = lease_fd; - return Success; -} - -static void -drmmode_terminate_lease(RRLeasePtr lease) -{ - ScreenPtr screen = lease->screen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - drmmode_ptr drmmode = &ms->drmmode; - drmmode_lease_private_ptr lease_private = lease->devPrivate; - - if (drmModeRevokeLease(drmmode->fd, lease_private->lessee_id) == 0) { - free(lease_private); - lease->devPrivate = NULL; - xf86CrtcLeaseTerminated(lease); - } -} - -static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = { - .resize = drmmode_xf86crtc_resize, - .create_lease = drmmode_create_lease, - .terminate_lease = drmmode_terminate_lease -}; - -Bool -drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp) -{ - modesettingEntPtr ms_ent = ms_ent_priv(pScrn); - int i; - int ret; - uint64_t value = 0; - unsigned int crtcs_needed = 0; - drmModeResPtr mode_res; - int crtcshift; - - /* check for dumb capability */ - ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value); - if (ret > 0 || value != 1) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "KMS doesn't support dumb interface\n"); - return FALSE; - } - - xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs); - - drmmode->scrn = pScrn; - drmmode->cpp = cpp; - mode_res = drmModeGetResources(drmmode->fd); - if (!mode_res) - return FALSE; - - crtcshift = ffs(ms_ent->assigned_crtcs ^ 0xffffffff) - 1; - for (i = 0; i < mode_res->count_connectors; i++) - crtcs_needed += drmmode_output_init(pScrn, drmmode, mode_res, i, FALSE, - crtcshift); - - xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, MS_LOGLEVEL_DEBUG, - "Up to %d crtcs needed for screen.\n", crtcs_needed); - - xf86CrtcSetSizeRange(pScrn, 320, 200, mode_res->max_width, - mode_res->max_height); - for (i = 0; i < mode_res->count_crtcs; i++) - if (!xf86IsEntityShared(pScrn->entityList[0]) || - (crtcs_needed && !(ms_ent->assigned_crtcs & (1 << i)))) - crtcs_needed -= drmmode_crtc_init(pScrn, drmmode, mode_res, i); - - /* All ZaphodHeads outputs provided with matching crtcs? */ - if (xf86IsEntityShared(pScrn->entityList[0]) && (crtcs_needed > 0)) - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "%d ZaphodHeads crtcs unavailable. Some outputs will stay off.\n", - crtcs_needed); - - /* workout clones */ - drmmode_clones_init(pScrn, drmmode, mode_res); - - drmModeFreeResources(mode_res); - xf86ProviderSetup(pScrn, NULL, "modesetting"); - - xf86InitialConfiguration(pScrn, TRUE); - - return TRUE; -} - -Bool -drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode) -{ -#ifdef GLAMOR_HAS_GBM - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - modesettingPtr ms = modesettingPTR(pScrn); - - if (drmmode->glamor) { - if (!ms->glamor.init(pScreen, GLAMOR_USE_EGL_SCREEN)) { - return FALSE; - } -#ifdef GBM_BO_WITH_MODIFIERS - ms->glamor.set_drawable_modifiers_func(pScreen, get_drawable_modifiers); -#endif - } -#endif - - return TRUE; -} - -void -drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - xf86OutputPtr output = config->output[config->compat_output]; - xf86CrtcPtr crtc = output->crtc; - - if (crtc && crtc->enabled) { - drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation, x, y); - } -} - -Bool -drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, Bool set_hw, - Bool ign_err) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - Bool success = TRUE; - int c; - - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - xf86OutputPtr output = NULL; - int o; - - /* Skip disabled CRTCs */ - if (!crtc->enabled) { - if (set_hw) { - drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, - 0, 0, 0, NULL, 0, NULL); - } - continue; - } - - if (config->output[config->compat_output]->crtc == crtc) - output = config->output[config->compat_output]; - else { - for (o = 0; o < config->num_output; o++) - if (config->output[o]->crtc == crtc) { - output = config->output[o]; - break; - } - } - /* paranoia */ - if (!output) - continue; - - /* Mark that we'll need to re-set the mode for sure */ - memset(&crtc->mode, 0, sizeof(crtc->mode)); - if (!crtc->desiredMode.CrtcHDisplay) { - DisplayModePtr mode = - xf86OutputFindClosestMode(output, pScrn->currentMode); - - if (!mode) - return FALSE; - crtc->desiredMode = *mode; - crtc->desiredRotation = RR_Rotate_0; - crtc->desiredX = 0; - crtc->desiredY = 0; - } - - if (set_hw) { - if (!crtc->funcs-> - set_mode_major(crtc, &crtc->desiredMode, crtc->desiredRotation, - crtc->desiredX, crtc->desiredY)) { - if (!ign_err) - return FALSE; - else { - success = FALSE; - crtc->enabled = FALSE; - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "Failed to set the desired mode on connector %s\n", - output->name); - } - } - } else { - crtc->mode = crtc->desiredMode; - crtc->rotation = crtc->desiredRotation; - crtc->x = crtc->desiredX; - crtc->y = crtc->desiredY; - if (!xf86CrtcRotate(crtc)) - return FALSE; - } - } - - /* Validate leases on VT re-entry */ - drmmode_validate_leases(pScrn); - - return success; -} - -static void -drmmode_load_palette(ScrnInfoPtr pScrn, int numColors, - int *indices, LOCO * colors, VisualPtr pVisual) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - uint16_t lut_r[256], lut_g[256], lut_b[256]; - int index, j, i; - int c; - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - for (i = 0; i < 256; i++) { - lut_r[i] = drmmode_crtc->lut_r[i] << 6; - lut_g[i] = drmmode_crtc->lut_g[i] << 6; - lut_b[i] = drmmode_crtc->lut_b[i] << 6; - } - - switch (pScrn->depth) { - case 15: - for (i = 0; i < numColors; i++) { - index = indices[i]; - for (j = 0; j < 8; j++) { - lut_r[index * 8 + j] = colors[index].red << 6; - lut_g[index * 8 + j] = colors[index].green << 6; - lut_b[index * 8 + j] = colors[index].blue << 6; - } - } - break; - case 16: - for (i = 0; i < numColors; i++) { - index = indices[i]; - - if (i <= 31) { - for (j = 0; j < 8; j++) { - lut_r[index * 8 + j] = colors[index].red << 6; - lut_b[index * 8 + j] = colors[index].blue << 6; - } - } - - for (j = 0; j < 4; j++) { - lut_g[index * 4 + j] = colors[index].green << 6; - } - } - break; - default: - for (i = 0; i < numColors; i++) { - index = indices[i]; - lut_r[index] = colors[index].red << 6; - lut_g[index] = colors[index].green << 6; - lut_b[index] = colors[index].blue << 6; - } - break; - } - - /* Make the change through RandR */ - if (crtc->randr_crtc) - RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b); - else - crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256); - } -} - -static Bool -drmmode_crtc_upgrade_lut(xf86CrtcPtr crtc, int num) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - uint64_t size; - - if (!drmmode_crtc->use_gamma_lut) - return TRUE; - - assert(drmmode_crtc->props[DRMMODE_CRTC_GAMMA_LUT_SIZE].prop_id); - - size = drmmode_crtc->props[DRMMODE_CRTC_GAMMA_LUT_SIZE].value; - - if (size != crtc->gamma_size) { - ScrnInfoPtr pScrn = crtc->scrn; - uint16_t *gamma = malloc(3 * size * sizeof(uint16_t)); - - if (gamma) { - free(crtc->gamma_red); - - crtc->gamma_size = size; - crtc->gamma_red = gamma; - crtc->gamma_green = gamma + size; - crtc->gamma_blue = gamma + size * 2; - - xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, MS_LOGLEVEL_DEBUG, - "Gamma ramp set to %ld entries on CRTC %d\n", - size, num); - } else { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Failed to allocate memory for %ld gamma ramp entries " - "on CRTC %d.\n", - size, num); - return FALSE; - } - } - - return TRUE; -} - -Bool -drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int i; - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Initializing kms color map for depth %d, %d bpc.\n", - pScrn->depth, pScrn->rgbBits); - if (!miCreateDefColormap(pScreen)) - return FALSE; - - /* If the GAMMA_LUT property is available, replace the server's default - * gamma ramps with ones of the appropriate size. */ - for (i = 0; i < xf86_config->num_crtc; i++) - if (!drmmode_crtc_upgrade_lut(xf86_config->crtc[i], i)) - return FALSE; - - /* Adapt color map size and depth to color depth of screen. */ - if (!xf86HandleColormaps(pScreen, 1 << pScrn->rgbBits, 10, - drmmode_load_palette, NULL, - CMAP_PALETTED_TRUECOLOR | - CMAP_RELOAD_ON_MODE_SWITCH)) - return FALSE; - return TRUE; -} - -#define DRM_MODE_LINK_STATUS_GOOD 0 -#define DRM_MODE_LINK_STATUS_BAD 1 - -void -drmmode_update_kms_state(drmmode_ptr drmmode) -{ - ScrnInfoPtr scrn = drmmode->scrn; - drmModeResPtr mode_res; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int i, j; - Bool found = FALSE; - Bool changed = FALSE; - - /* Try to re-set the mode on all the connectors with a BAD link-state: - * This may happen if a link degrades and a new modeset is necessary, using - * different link-training parameters. If the kernel found that the current - * mode is not achievable anymore, it should have pruned the mode before - * sending the hotplug event. Try to re-set the currently-set mode to keep - * the display alive, this will fail if the mode has been pruned. - * In any case, we will send randr events for the Desktop Environment to - * deal with it, if it wants to. - */ - for (i = 0; i < config->num_output; i++) { - xf86OutputPtr output = config->output[i]; - drmmode_output_private_ptr drmmode_output = output->driver_private; - - drmmode_output_detect(output); - - /* Get an updated view of the properties for the current connector and - * look for the link-status property - */ - for (j = 0; j < drmmode_output->num_props; j++) { - drmmode_prop_ptr p = &drmmode_output->props[j]; - - if (!strcmp(p->mode_prop->name, "link-status")) { - if (p->value == DRM_MODE_LINK_STATUS_BAD) { - xf86CrtcPtr crtc = output->crtc; - if (!crtc) - continue; - - /* the connector got a link failure, re-set the current mode */ - drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation, - crtc->x, crtc->y); - - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "hotplug event: connector %u's link-state is BAD, " - "tried resetting the current mode. You may be left" - "with a black screen if this fails...\n", - drmmode_output->mode_output->connector_id); - } - break; - } - } - } - - mode_res = drmModeGetResources(drmmode->fd); - if (!mode_res) - goto out; - - if (mode_res->count_crtcs != config->num_crtc) { - /* this triggers with Zaphod mode where we don't currently support connector hotplug or MST. */ - goto out_free_res; - } - - /* figure out if we have gotten rid of any connectors - traverse old output list looking for outputs */ - for (i = 0; i < config->num_output; i++) { - xf86OutputPtr output = config->output[i]; - drmmode_output_private_ptr drmmode_output; - - drmmode_output = output->driver_private; - found = FALSE; - for (j = 0; j < mode_res->count_connectors; j++) { - if (mode_res->connectors[j] == drmmode_output->output_id) { - found = TRUE; - break; - } - } - if (found) - continue; - - drmModeFreeConnector(drmmode_output->mode_output); - drmmode_output->mode_output = NULL; - drmmode_output->output_id = -1; - - changed = TRUE; - } - - /* find new output ids we don't have outputs for */ - for (i = 0; i < mode_res->count_connectors; i++) { - found = FALSE; - - for (j = 0; j < config->num_output; j++) { - xf86OutputPtr output = config->output[j]; - drmmode_output_private_ptr drmmode_output; - - drmmode_output = output->driver_private; - if (mode_res->connectors[i] == drmmode_output->output_id) { - found = TRUE; - break; - } - } - if (found) - continue; - - changed = TRUE; - drmmode_output_init(scrn, drmmode, mode_res, i, TRUE, 0); - } - - if (changed) { - RRSetChanged(xf86ScrnToScreen(scrn)); - RRTellChanged(xf86ScrnToScreen(scrn)); - } - -out_free_res: - - /* Check to see if a lessee has disappeared */ - drmmode_validate_leases(scrn); - - drmModeFreeResources(mode_res); -out: - RRGetInfo(xf86ScrnToScreen(scrn), TRUE); -} - -#undef DRM_MODE_LINK_STATUS_BAD -#undef DRM_MODE_LINK_STATUS_GOOD - -#ifdef CONFIG_UDEV_KMS - -static void -drmmode_handle_uevents(int fd, void *closure) -{ - drmmode_ptr drmmode = closure; - struct udev_device *dev; - Bool found = FALSE; - - while ((dev = udev_monitor_receive_device(drmmode->uevent_monitor))) { - udev_device_unref(dev); - found = TRUE; - } - if (!found) - return; - - drmmode_update_kms_state(drmmode); -} - -#endif - -void -drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode) -{ -#ifdef CONFIG_UDEV_KMS - struct udev *u; - struct udev_monitor *mon; - - u = udev_new(); - if (!u) - return; - mon = udev_monitor_new_from_netlink(u, "udev"); - if (!mon) { - udev_unref(u); - return; - } - - if (udev_monitor_filter_add_match_subsystem_devtype(mon, - "drm", - "drm_minor") < 0 || - udev_monitor_enable_receiving(mon) < 0) { - udev_monitor_unref(mon); - udev_unref(u); - return; - } - - drmmode->uevent_handler = - xf86AddGeneralHandler(udev_monitor_get_fd(mon), - drmmode_handle_uevents, drmmode); - - drmmode->uevent_monitor = mon; -#endif -} - -void -drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode) -{ -#ifdef CONFIG_UDEV_KMS - if (drmmode->uevent_handler) { - struct udev *u = udev_monitor_get_udev(drmmode->uevent_monitor); - - xf86RemoveGeneralHandler(drmmode->uevent_handler); - - udev_monitor_unref(drmmode->uevent_monitor); - udev_unref(u); - } -#endif -} - -/* create front and cursor BOs */ -Bool -drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) -{ - modesettingPtr ms = modesettingPTR(pScrn); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int width; - int height; - int bpp = ms->drmmode.kbpp; - int i; - int cpp = (bpp + 7) / 8; - - width = pScrn->virtualX; - height = pScrn->virtualY; - - if (!drmmode_create_bo(drmmode, &drmmode->front_bo, width, height, bpp)) - return FALSE; - pScrn->displayWidth = drmmode_bo_get_pitch(&drmmode->front_bo) / cpp; - - width = ms->cursor_width; - height = ms->cursor_height; - bpp = 32; - for (i = 0; i < xf86_config->num_crtc; i++) { - xf86CrtcPtr crtc = xf86_config->crtc[i]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - drmmode_crtc->cursor_bo = - dumb_bo_create(drmmode->fd, width, height, bpp); - } - return TRUE; -} - -void * -drmmode_map_front_bo(drmmode_ptr drmmode) -{ - return drmmode_bo_map(drmmode, &drmmode->front_bo); -} - -void * -drmmode_map_secondary_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv) -{ - int ret; - - if (ppriv->backing_bo->ptr) - return ppriv->backing_bo->ptr; - - ret = dumb_bo_map(drmmode->fd, ppriv->backing_bo); - if (ret) - return NULL; - - return ppriv->backing_bo->ptr; -} - -Bool -drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int i, ret; - - for (i = 0; i < xf86_config->num_crtc; i++) { - xf86CrtcPtr crtc = xf86_config->crtc[i]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - ret = dumb_bo_map(drmmode->fd, drmmode_crtc->cursor_bo); - if (ret) - return FALSE; - } - return TRUE; -} - -void -drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int i; - - if (drmmode->fb_id) { - drmModeRmFB(drmmode->fd, drmmode->fb_id); - drmmode->fb_id = 0; - } - - drmmode_bo_destroy(drmmode, &drmmode->front_bo); - - for (i = 0; i < xf86_config->num_crtc; i++) { - xf86CrtcPtr crtc = xf86_config->crtc[i]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo); - } -} - -/* ugly workaround to see if we can create 32bpp */ -void -drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth, - int *bpp) -{ - drmModeResPtr mode_res; - uint64_t value; - struct dumb_bo *bo; - uint32_t fb_id; - int ret; - - /* 16 is fine */ - ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_PREFERRED_DEPTH, &value); - if (!ret && (value == 16 || value == 8)) { - *depth = value; - *bpp = value; - return; - } - - *depth = 24; - mode_res = drmModeGetResources(drmmode->fd); - if (!mode_res) - return; - - if (mode_res->min_width == 0) - mode_res->min_width = 1; - if (mode_res->min_height == 0) - mode_res->min_height = 1; - /*create a bo */ - bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height, - 32); - if (!bo) { - *bpp = 24; - goto out; - } - - ret = drmModeAddFB(drmmode->fd, mode_res->min_width, mode_res->min_height, - 24, 32, bo->pitch, bo->handle, &fb_id); - - if (ret) { - *bpp = 24; - dumb_bo_destroy(drmmode->fd, bo); - goto out; - } - - drmModeRmFB(drmmode->fd, fb_id); - *bpp = 32; - - dumb_bo_destroy(drmmode->fd, bo); - out: - drmModeFreeResources(mode_res); - return; -} - -void -drmmode_crtc_set_vrr(xf86CrtcPtr crtc, Bool enabled) -{ - ScrnInfoPtr pScrn = crtc->scrn; - modesettingPtr ms = modesettingPTR(pScrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmmode_ptr drmmode = drmmode_crtc->drmmode; - - if (drmmode->vrr_prop_id && drmmode_crtc->vrr_enabled != enabled && - drmModeObjectSetProperty(ms->fd, - drmmode_crtc->mode_crtc->crtc_id, - DRM_MODE_OBJECT_CRTC, - drmmode->vrr_prop_id, - enabled) == 0) - drmmode_crtc->vrr_enabled = enabled; -} - -/* - * We hook the screen's cursor-sprite (swcursor) functions to see if a swcursor - * is active. When a swcursor is active we disable page-flipping. - */ - -static void drmmode_sprite_do_set_cursor(msSpritePrivPtr sprite_priv, - ScrnInfoPtr scrn, int x, int y) -{ - modesettingPtr ms = modesettingPTR(scrn); - CursorPtr cursor = sprite_priv->cursor; - Bool sprite_visible = sprite_priv->sprite_visible; - - if (cursor) { - x -= cursor->bits->xhot; - y -= cursor->bits->yhot; - - sprite_priv->sprite_visible = - x < scrn->virtualX && y < scrn->virtualY && - (x + cursor->bits->width > 0) && - (y + cursor->bits->height > 0); - } else { - sprite_priv->sprite_visible = FALSE; - } - - ms->drmmode.sprites_visible += sprite_priv->sprite_visible - sprite_visible; -} - -static void drmmode_sprite_set_cursor(DeviceIntPtr pDev, ScreenPtr pScreen, - CursorPtr pCursor, int x, int y) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(scrn); - msSpritePrivPtr sprite_priv = msGetSpritePriv(pDev, ms, pScreen); - - sprite_priv->cursor = pCursor; - drmmode_sprite_do_set_cursor(sprite_priv, scrn, x, y); - - ms->SpriteFuncs->SetCursor(pDev, pScreen, pCursor, x, y); -} - -static void drmmode_sprite_move_cursor(DeviceIntPtr pDev, ScreenPtr pScreen, - int x, int y) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(scrn); - msSpritePrivPtr sprite_priv = msGetSpritePriv(pDev, ms, pScreen); - - drmmode_sprite_do_set_cursor(sprite_priv, scrn, x, y); - - ms->SpriteFuncs->MoveCursor(pDev, pScreen, x, y); -} - -static Bool drmmode_sprite_realize_realize_cursor(DeviceIntPtr pDev, - ScreenPtr pScreen, - CursorPtr pCursor) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(scrn); - - return ms->SpriteFuncs->RealizeCursor(pDev, pScreen, pCursor); -} - -static Bool drmmode_sprite_realize_unrealize_cursor(DeviceIntPtr pDev, - ScreenPtr pScreen, - CursorPtr pCursor) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(scrn); - - return ms->SpriteFuncs->UnrealizeCursor(pDev, pScreen, pCursor); -} - -static Bool drmmode_sprite_device_cursor_initialize(DeviceIntPtr pDev, - ScreenPtr pScreen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(scrn); - - return ms->SpriteFuncs->DeviceCursorInitialize(pDev, pScreen); -} - -static void drmmode_sprite_device_cursor_cleanup(DeviceIntPtr pDev, - ScreenPtr pScreen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - modesettingPtr ms = modesettingPTR(scrn); - - ms->SpriteFuncs->DeviceCursorCleanup(pDev, pScreen); -} - -miPointerSpriteFuncRec drmmode_sprite_funcs = { - .RealizeCursor = drmmode_sprite_realize_realize_cursor, - .UnrealizeCursor = drmmode_sprite_realize_unrealize_cursor, - .SetCursor = drmmode_sprite_set_cursor, - .MoveCursor = drmmode_sprite_move_cursor, - .DeviceCursorInitialize = drmmode_sprite_device_cursor_initialize, - .DeviceCursorCleanup = drmmode_sprite_device_cursor_cleanup, -}; diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h deleted file mode 100644 index 2a9a91529..000000000 --- a/hw/xfree86/drivers/modesetting/drmmode_display.h +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright © 2007 Red Hat, Inc. - * Copyright © 2019 NVIDIA CORPORATION - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Authors: - * Dave Airlie - * Aaron Plattner - * - */ -#ifndef DRMMODE_DISPLAY_H -#define DRMMODE_DISPLAY_H - -#include "xf86drmMode.h" -#ifdef CONFIG_UDEV_KMS -#include "libudev.h" -#endif - -#include "dumb_bo.h" - -struct gbm_device; - -enum drmmode_plane_property { - DRMMODE_PLANE_TYPE = 0, - DRMMODE_PLANE_FB_ID, - DRMMODE_PLANE_IN_FORMATS, - DRMMODE_PLANE_CRTC_ID, - DRMMODE_PLANE_SRC_X, - DRMMODE_PLANE_SRC_Y, - DRMMODE_PLANE_SRC_W, - DRMMODE_PLANE_SRC_H, - DRMMODE_PLANE_CRTC_X, - DRMMODE_PLANE_CRTC_Y, - DRMMODE_PLANE_CRTC_W, - DRMMODE_PLANE_CRTC_H, - DRMMODE_PLANE__COUNT -}; - -enum drmmode_plane_type { - DRMMODE_PLANE_TYPE_PRIMARY = 0, - DRMMODE_PLANE_TYPE_CURSOR, - DRMMODE_PLANE_TYPE_OVERLAY, - DRMMODE_PLANE_TYPE__COUNT -}; - -enum drmmode_connector_property { - DRMMODE_CONNECTOR_CRTC_ID, - DRMMODE_CONNECTOR__COUNT -}; - -enum drmmode_crtc_property { - DRMMODE_CRTC_ACTIVE, - DRMMODE_CRTC_MODE_ID, - DRMMODE_CRTC_GAMMA_LUT, - DRMMODE_CRTC_GAMMA_LUT_SIZE, - DRMMODE_CRTC_CTM, - DRMMODE_CRTC__COUNT -}; - -typedef struct { - uint32_t width; - uint32_t height; - struct dumb_bo *dumb; -#ifdef GLAMOR_HAS_GBM - Bool used_modifiers; - struct gbm_bo *gbm; -#endif -} drmmode_bo; - -typedef struct { - int fd; - unsigned fb_id; - drmModeFBPtr mode_fb; - int cpp; - int kbpp; - ScrnInfoPtr scrn; - - struct gbm_device *gbm; - -#ifdef CONFIG_UDEV_KMS - struct udev_monitor *uevent_monitor; - InputHandlerProc uevent_handler; -#endif - drmEventContext event_context; - drmmode_bo front_bo; - Bool sw_cursor; - - /* Broken-out options. */ - OptionInfoPtr Options; - - Bool glamor; - Bool shadow_enable; - Bool shadow_enable2; - /** Is Option "PageFlip" enabled? */ - Bool pageflip; - Bool force_24_32; - void *shadow_fb; - void *shadow_fb2; - - DevPrivateKeyRec pixmapPrivateKeyRec; - DevScreenPrivateKeyRec spritePrivateKeyRec; - DevPrivateKeyRec vrrPrivateKeyRec; - /* Number of SW cursors currently visible on this screen */ - int sprites_visible; - - Bool reverse_prime_offload_mode; - - Bool is_secondary; - - PixmapPtr fbcon_pixmap; - - Bool dri2_flipping; - Bool present_flipping; - Bool flip_bo_import_failed; - - Bool can_async_flip; - Bool async_flip_secondaries; - Bool dri2_enable; - Bool present_enable; - - uint32_t vrr_prop_id; - Bool use_ctm; -} drmmode_rec, *drmmode_ptr; - -typedef struct { - const char *name; - Bool valid; - uint64_t value; -} drmmode_prop_enum_info_rec, *drmmode_prop_enum_info_ptr; - -typedef struct { - const char *name; - uint32_t prop_id; - uint64_t value; - unsigned int num_enum_values; - drmmode_prop_enum_info_rec *enum_values; -} drmmode_prop_info_rec, *drmmode_prop_info_ptr; - -typedef struct { - drmModeModeInfo mode_info; - uint32_t blob_id; - struct xorg_list entry; -} drmmode_mode_rec, *drmmode_mode_ptr; - -typedef struct { - uint32_t format; - uint32_t num_modifiers; - uint64_t *modifiers; -} drmmode_format_rec, *drmmode_format_ptr; - -typedef struct { - drmmode_ptr drmmode; - drmModeCrtcPtr mode_crtc; - uint32_t vblank_pipe; - int dpms_mode; - struct dumb_bo *cursor_bo; - Bool cursor_up; - uint16_t lut_r[256], lut_g[256], lut_b[256]; - - drmmode_prop_info_rec props[DRMMODE_CRTC__COUNT]; - drmmode_prop_info_rec props_plane[DRMMODE_PLANE__COUNT]; - uint32_t plane_id; - drmmode_mode_ptr current_mode; - uint32_t num_formats; - drmmode_format_rec *formats; - - drmmode_bo rotate_bo; - unsigned rotate_fb_id; - - PixmapPtr prime_pixmap; - PixmapPtr prime_pixmap_back; - unsigned prime_pixmap_x; - - /** - * @{ MSC (vblank count) handling for the PRESENT extension. - * - * The kernel's vblank counters are 32 bits and apparently full of - * lies, and we need to give a reliable 64-bit msc for GL, so we - * have to track and convert to a userland-tracked 64-bit msc. - */ - uint32_t msc_prev; - uint64_t msc_high; - /** @} */ - - Bool need_modeset; - struct xorg_list mode_list; - - Bool enable_flipping; - Bool flipping_active; - - Bool vrr_enabled; - Bool use_gamma_lut; -} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr; - -typedef struct { - drmModePropertyPtr mode_prop; - uint64_t value; - int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */ - Atom *atoms; -} drmmode_prop_rec, *drmmode_prop_ptr; - -typedef struct { - drmmode_ptr drmmode; - int output_id; - drmModeConnectorPtr mode_output; - drmModeEncoderPtr *mode_encoders; - drmModePropertyBlobPtr edid_blob; - drmModePropertyBlobPtr tile_blob; - int dpms_enum_id; - int dpms; - int num_props; - drmmode_prop_ptr props; - drmmode_prop_info_rec props_connector[DRMMODE_CONNECTOR__COUNT]; - int enc_mask; - int enc_clone_mask; - xf86CrtcPtr current_crtc; - Atom ctm_atom; - struct drm_color_ctm ctm; -} drmmode_output_private_rec, *drmmode_output_private_ptr; - -typedef struct { - uint32_t lessee_id; -} drmmode_lease_private_rec, *drmmode_lease_private_ptr; - -typedef struct _msPixmapPriv { - uint32_t fb_id; - struct dumb_bo *backing_bo; /* if this pixmap is backed by a dumb bo */ - - DamagePtr secondary_damage; - - /** Sink fields for flipping shared pixmaps */ - int flip_seq; /* seq of current page flip event handler */ - Bool wait_for_damage; /* if we have requested damage notification from source */ - - /** Source fields for flipping shared pixmaps */ - Bool defer_dirty_update; /* if we want to manually update */ - PixmapDirtyUpdatePtr dirty; /* cached dirty ent to avoid searching list */ - DrawablePtr secondary_src; /* if we exported shared pixmap, dirty tracking src */ - Bool notify_on_damage; /* if sink has requested damage notification */ -} msPixmapPrivRec, *msPixmapPrivPtr; - -#define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec)) - -typedef struct _msSpritePriv { - CursorPtr cursor; - Bool sprite_visible; -} msSpritePrivRec, *msSpritePrivPtr; - -#define msGetSpritePriv(dev, ms, screen) dixLookupScreenPrivate(&(dev)->devPrivates, &(ms)->drmmode.spritePrivateKeyRec, screen) - -extern miPointerSpriteFuncRec drmmode_sprite_funcs; - -Bool drmmode_is_format_supported(ScrnInfoPtr scrn, uint32_t format, - uint64_t modifier); -int drmmode_bo_import(drmmode_ptr drmmode, drmmode_bo *bo, - uint32_t *fb_id); -int drmmode_bo_destroy(drmmode_ptr drmmode, drmmode_bo *bo); -uint32_t drmmode_bo_get_pitch(drmmode_bo *bo); -uint32_t drmmode_bo_get_handle(drmmode_bo *bo); -Bool drmmode_glamor_handle_new_screen_pixmap(drmmode_ptr drmmode); -void *drmmode_map_secondary_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv); -Bool drmmode_SetSlaveBO(PixmapPtr ppix, - drmmode_ptr drmmode, - int fd_handle, int pitch, int size); - -Bool drmmode_EnableSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode, - PixmapPtr front, PixmapPtr back); -Bool drmmode_SharedPixmapPresentOnVBlank(PixmapPtr frontTarget, xf86CrtcPtr crtc, - drmmode_ptr drmmode); -Bool drmmode_SharedPixmapFlip(PixmapPtr frontTarget, xf86CrtcPtr crtc, - drmmode_ptr drmmode); -void drmmode_DisableSharedPixmapFlipping(xf86CrtcPtr crtc, drmmode_ptr drmmode); - -extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp); -extern Bool drmmode_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode); -void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y); -extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode, - Bool set_hw, Bool ign_err); -extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn); - -extern void drmmode_update_kms_state(drmmode_ptr drmmode); -extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode); -extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode); - -Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); -void *drmmode_map_front_bo(drmmode_ptr drmmode); -Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); -void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode); -void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, - int *depth, int *bpp); - -void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode); - -int drmmode_crtc_flip(xf86CrtcPtr crtc, uint32_t fb_id, uint32_t flags, void *data); - -Bool drmmode_crtc_get_fb_id(xf86CrtcPtr crtc, uint32_t *fb_id, int *x, int *y); - -void drmmode_set_dpms(ScrnInfoPtr scrn, int PowerManagementMode, int flags); -void drmmode_crtc_set_vrr(xf86CrtcPtr crtc, Bool enabled); - -#endif diff --git a/hw/xfree86/drivers/modesetting/dumb_bo.c b/hw/xfree86/drivers/modesetting/dumb_bo.c deleted file mode 100644 index cf13f0a9c..000000000 --- a/hw/xfree86/drivers/modesetting/dumb_bo.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright © 2007 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Authors: - * Dave Airlie - * - */ - -#ifdef HAVE_DIX_CONFIG_H -#include "dix-config.h" -#endif - -#include "dumb_bo.h" - -#include -#include -#include -#include -#include -#include -#include - -struct dumb_bo * -dumb_bo_create(int fd, - const unsigned width, const unsigned height, const unsigned bpp) -{ - struct drm_mode_create_dumb arg; - struct dumb_bo *bo; - int ret; - - bo = calloc(1, sizeof(*bo)); - if (!bo) - return NULL; - - memset(&arg, 0, sizeof(arg)); - arg.width = width; - arg.height = height; - arg.bpp = bpp; - - ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg); - if (ret) - goto err_free; - - bo->handle = arg.handle; - bo->size = arg.size; - bo->pitch = arg.pitch; - - return bo; - err_free: - free(bo); - return NULL; -} - -int -dumb_bo_map(int fd, struct dumb_bo *bo) -{ - struct drm_mode_map_dumb arg; - int ret; - void *map; - - if (bo->ptr) { - return 0; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->handle; - - ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg); - if (ret) - return ret; - - map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, arg.offset); - if (map == MAP_FAILED) - return -errno; - - bo->ptr = map; - return 0; -} - -int -dumb_bo_destroy(int fd, struct dumb_bo *bo) -{ - struct drm_mode_destroy_dumb arg; - int ret; - - if (bo->ptr) { - munmap(bo->ptr, bo->size); - bo->ptr = NULL; - } - - memset(&arg, 0, sizeof(arg)); - arg.handle = bo->handle; - ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg); - if (ret) - return -errno; - - free(bo); - return 0; -} - -struct dumb_bo * -dumb_get_bo_from_fd(int fd, int handle, int pitch, int size) -{ - struct dumb_bo *bo; - int ret; - - bo = calloc(1, sizeof(*bo)); - if (!bo) - return NULL; - - ret = drmPrimeFDToHandle(fd, handle, &bo->handle); - if (ret) { - free(bo); - return NULL; - } - bo->pitch = pitch; - bo->size = size; - return bo; -} diff --git a/hw/xfree86/drivers/modesetting/dumb_bo.h b/hw/xfree86/drivers/modesetting/dumb_bo.h deleted file mode 100644 index 9235e61e2..000000000 --- a/hw/xfree86/drivers/modesetting/dumb_bo.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2007 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Authors: - * Dave Airlie - * - */ -#ifndef DUMB_BO_H -#define DUMB_BO_H - -#include - -struct dumb_bo { - uint32_t handle; - uint32_t size; - void *ptr; - uint32_t pitch; -}; - -struct dumb_bo *dumb_bo_create(int fd, const unsigned width, - const unsigned height, const unsigned bpp); -int dumb_bo_map(int fd, struct dumb_bo *bo); -int dumb_bo_destroy(int fd, struct dumb_bo *bo); -struct dumb_bo *dumb_get_bo_from_fd(int fd, int handle, int pitch, int size); - -#endif diff --git a/hw/xfree86/drivers/modesetting/meson.build b/hw/xfree86/drivers/modesetting/meson.build deleted file mode 100644 index 02852a716..000000000 --- a/hw/xfree86/drivers/modesetting/meson.build +++ /dev/null @@ -1,48 +0,0 @@ -modesetting_srcs = [ - 'dri2.c', - 'driver.c', - 'drmmode_display.c', - 'dumb_bo.c', - 'pageflip.c', - 'present.c', - 'vblank.c', -] - -shared_module( - 'modesetting_drv', - modesetting_srcs, - name_prefix: '', - - include_directories: [inc, xorg_inc], - c_args: xorg_c_args, - dependencies: [ - common_dep, - udev_dep, - libdrm_dep, - gbm_dep, - ], - - install: true, - install_dir: join_paths(module_dir, 'drivers'), -) - -# Test that we don't have any unresolved symbols from our module to Xorg. -xorg_build_root = join_paths(meson.build_root(), 'hw', 'xfree86') -symbol_test_args = [] -symbol_test_args += join_paths(xorg_build_root, 'libxorgserver.so') -symbol_test_args += join_paths(xorg_build_root, 'dixmods', 'libshadow.so') -if gbm_dep.found() - symbol_test_args += join_paths(xorg_build_root, 'glamor_egl', 'libglamoregl.so') -endif -symbol_test_args += join_paths(xorg_build_root, 'drivers', 'modesetting', 'modesetting_drv.so') - -install_man(configure_file( - input: 'modesetting.man', - output: 'modesetting.4', - configuration: manpage_config, -)) - -test('modesetting symbol test', - xorg_symbol_test, - args: symbol_test_args, -) diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man deleted file mode 100644 index 71790011e..000000000 --- a/hw/xfree86/drivers/modesetting/modesetting.man +++ /dev/null @@ -1,116 +0,0 @@ -.\" shorthand for double quote that works everywhere. -.ds q \N'34' -.TH MODESETTING @drivermansuffix@ @vendorversion@ -.SH NAME -modesetting \- video driver for framebuffer device -.SH SYNOPSIS -.nf -.B "Section \*qDevice\*q" -.BI " Identifier \*q" devname \*q -.B " Driver \*qmodesetting\*q" -.BI " BusID \*qpci:" bus : dev : func \*q -\ \ ... -.B EndSection -.fi -.SH DESCRIPTION -.B modesetting -is an @xservername@ driver for KMS devices. This driver supports -TrueColor visuals at framebuffer depths of 15, 16, 24, and 30. RandR -1.2 is supported for multi-head configurations. Acceleration is available -through glamor for devices supporting at least OpenGL ES 2.0 or OpenGL 2.1. -If glamor is not enabled, a shadow framebuffer is configured based on the -KMS drivers' preference (unless the framebuffer is 24 bits per pixel, in -which case the shadow framebuffer is always used). -.SH SUPPORTED HARDWARE -The -.B modesetting -driver supports all hardware where a KMS driver is available. -modesetting uses the Linux DRM KMS ioctls and dumb object create/map. -.SH CONFIGURATION DETAILS -Please refer to @xconfigfile@(@filemansuffix@) for general configuration -details. This section only covers configuration details specific to -this driver. -.PP -For this driver it is not required to specify modes in the screen -section of the config file. The -.B modesetting -driver can pick up the currently used video mode from the kernel -driver and will use it if there are no video modes configured. -.PP -For PCI boards you might have to add a BusID line to the Device -section. See above for a sample line. -.PP -The following driver -.B Options -are supported: -.TP -.BI "Option \*qSWcursor\*q \*q" boolean \*q -Selects software cursor. The default is -.B off. -.TP -.BI "Option \*qkmsdev\*q \*q" string \*q -The framebuffer device to use. Default: /dev/dri/card0. -.TP -.BI "Option \*qShadowFB\*q \*q" boolean \*q -Enable or disable use of the shadow framebuffer layer. Default: on. -.TP -.BI "Option \*qDoubleShadow\*q \*q" boolean \*q -Double-buffer shadow updates. When enabled, the driver will keep two copies of -the shadow framebuffer. When the shadow framebuffer is flushed, the old and new -versions of the shadow are compared, and only tiles that have actually changed -are uploaded to the device. This is an optimization for server-class GPUs with -a remote display function (typically VNC), where remote updates are triggered -by any framebuffer write, so minimizing the amount of data uploaded is crucial. -This defaults to enabled for ASPEED and Matrox G200 devices, and disabled -otherwise. -.TP -.BI "Option \*qAccelMethod\*q \*q" string \*q -One of \*qglamor\*q or \*qnone\*q. Default: glamor. -.TP -.BI "Option \*qPageFlip\*q \*q" boolean \*q -Enable DRI3 page flipping. The default is -.B on. -.TP -.BI "Option \*qVariableRefresh\*q \*q" boolean \*q -Enables support for enabling variable refresh on the Screen's CRTCs -when an suitable application is flipping via the Present extension. -.br -The default is -.B off. -.TP -.BI "Option \*qAsyncFlipSecondaries\*q \*q" boolean \*q -Use async flips for secondary video outputs on multi-display setups. If a screen -has multiple displays attached and DRI3 page flipping is used, then only one of -the displays will have its page flip synchronized to vblank for tear-free -presentation. This is the display that is used for presentation timing and -timestamping, usually the one covering the biggest pixel area of the screen. -All other displays ("Secondaries") will not synchronize their flips. This may -cause some tearing on these displays, but it prevents a permanent or periodic -slowdown or irritating judder of animations if not all video outputs are running -synchronized with each other and with the same refresh rate. There is no perfect -solution apart from perfectly synchronized outputs, but this option may give -preferrable results if the displays in a multi-display setup mirror or clone -each other. The default is -.B off. -.TP -.BI "Option \*qZaphodHeads\*q \*q" string \*q -Specify the RandR output(s) to use with zaphod mode for a particular driver -instance. If you use this option you must use this option for all instances -of the driver. -.br -For example: -.B -Option \*qZaphodHeads\*q \*qLVDS,VGA-0\*q -will assign xrandr outputs LVDS and VGA-0 to this instance of the driver. -.TP -.BI "Option \*qUseGammaLUT\*q \*q" boolean \*q -Enable or disable use of the GAMMA_LUT property, when available. -When enabled, this option allows the driver to use gamma ramps with more -entries, if supported by the kernel. By default, GAMMA_LUT will be used for -kms drivers which are known to be safe for use of GAMMA_LUT. -.TP -.SH "SEE ALSO" -@xservername@(@appmansuffix@), @xconfigfile@(@filemansuffix@), Xserver(@appmansuffix@), -X(@miscmansuffix@) -.SH AUTHORS -Authors include: Dave Airlie diff --git a/hw/xfree86/drivers/modesetting/pageflip.c b/hw/xfree86/drivers/modesetting/pageflip.c deleted file mode 100644 index 23ee95f9a..000000000 --- a/hw/xfree86/drivers/modesetting/pageflip.c +++ /dev/null @@ -1,468 +0,0 @@ -/* - * Copyright © 2014 Intel Corporation - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include "dix-config.h" -#endif - -#include -#include - -#include "driver.h" - -/* - * Flush the DRM event queue when full; makes space for new events. - * - * Returns a negative value on error, 0 if there was nothing to process, - * or 1 if we handled any events. - */ -int -ms_flush_drm_events(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - - struct pollfd p = { .fd = ms->fd, .events = POLLIN }; - int r; - - do { - r = xserver_poll(&p, 1, 0); - } while (r == -1 && (errno == EINTR || errno == EAGAIN)); - - /* If there was an error, r will be < 0. Return that. If there was - * nothing to process, r == 0. Return that. - */ - if (r <= 0) - return r; - - /* Try to handle the event. If there was an error, return it. */ - r = drmHandleEvent(ms->fd, &ms->event_context); - if (r < 0) - return r; - - /* Otherwise return 1 to indicate that we handled an event. */ - return 1; -} - -#ifdef GLAMOR_HAS_GBM - -/* - * Event data for an in progress flip. - * This contains a pointer to the vblank event, - * and information about the flip in progress. - * a reference to this is stored in the per-crtc - * flips. - */ -struct ms_flipdata { - ScreenPtr screen; - void *event; - ms_pageflip_handler_proc event_handler; - ms_pageflip_abort_proc abort_handler; - /* number of CRTC events referencing this */ - int flip_count; - uint64_t fe_msc; - uint64_t fe_usec; - uint32_t old_fb_id; -}; - -/* - * Per crtc pageflipping information, - * These are submitted to the queuing code - * one of them per crtc per flip. - */ -struct ms_crtc_pageflip { - Bool on_reference_crtc; - /* reference to the ms_flipdata */ - struct ms_flipdata *flipdata; -}; - -/** - * Free an ms_crtc_pageflip. - * - * Drops the reference count on the flipdata. - */ -static void -ms_pageflip_free(struct ms_crtc_pageflip *flip) -{ - struct ms_flipdata *flipdata = flip->flipdata; - - free(flip); - if (--flipdata->flip_count > 0) - return; - free(flipdata); -} - -/** - * Callback for the DRM event queue when a single flip has completed - * - * Once the flip has been completed on all pipes, notify the - * extension code telling it when that happened - */ -static void -ms_pageflip_handler(uint64_t msc, uint64_t ust, void *data) -{ - struct ms_crtc_pageflip *flip = data; - struct ms_flipdata *flipdata = flip->flipdata; - ScreenPtr screen = flipdata->screen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - - if (flip->on_reference_crtc) { - flipdata->fe_msc = msc; - flipdata->fe_usec = ust; - } - - if (flipdata->flip_count == 1) { - flipdata->event_handler(ms, flipdata->fe_msc, - flipdata->fe_usec, - flipdata->event); - - drmModeRmFB(ms->fd, flipdata->old_fb_id); - } - ms_pageflip_free(flip); -} - -/* - * Callback for the DRM queue abort code. A flip has been aborted. - */ -static void -ms_pageflip_abort(void *data) -{ - struct ms_crtc_pageflip *flip = data; - struct ms_flipdata *flipdata = flip->flipdata; - ScreenPtr screen = flipdata->screen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - - if (flipdata->flip_count == 1) - flipdata->abort_handler(ms, flipdata->event); - - ms_pageflip_free(flip); -} - -static Bool -do_queue_flip_on_crtc(modesettingPtr ms, xf86CrtcPtr crtc, - uint32_t flags, uint32_t seq) -{ - return drmmode_crtc_flip(crtc, ms->drmmode.fb_id, flags, - (void *) (uintptr_t) seq); -} - -enum queue_flip_status { - QUEUE_FLIP_SUCCESS, - QUEUE_FLIP_ALLOC_FAILED, - QUEUE_FLIP_QUEUE_ALLOC_FAILED, - QUEUE_FLIP_DRM_FLUSH_FAILED, -}; - -static int -queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc, - struct ms_flipdata *flipdata, - int ref_crtc_vblank_pipe, uint32_t flags) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - struct ms_crtc_pageflip *flip; - uint32_t seq; - - flip = calloc(1, sizeof(struct ms_crtc_pageflip)); - if (flip == NULL) { - return QUEUE_FLIP_ALLOC_FAILED; - } - - /* Only the reference crtc will finally deliver its page flip - * completion event. All other crtc's events will be discarded. - */ - flip->on_reference_crtc = (drmmode_crtc->vblank_pipe == ref_crtc_vblank_pipe); - flip->flipdata = flipdata; - - seq = ms_drm_queue_alloc(crtc, flip, ms_pageflip_handler, ms_pageflip_abort); - if (!seq) { - free(flip); - return QUEUE_FLIP_QUEUE_ALLOC_FAILED; - } - - /* take a reference on flipdata for use in flip */ - flipdata->flip_count++; - - while (do_queue_flip_on_crtc(ms, crtc, flags, seq)) { - /* We may have failed because the event queue was full. Flush it - * and retry. If there was nothing to flush, then we failed for - * some other reason and should just return an error. - */ - if (ms_flush_drm_events(screen) <= 0) { - /* Aborting will also decrement flip_count and free(flip). */ - ms_drm_abort_seq(scrn, seq); - return QUEUE_FLIP_DRM_FLUSH_FAILED; - } - - /* We flushed some events, so try again. */ - xf86DrvMsg(scrn->scrnIndex, X_WARNING, "flip queue retry\n"); - } - - /* The page flip succeeded. */ - return QUEUE_FLIP_SUCCESS; -} - - -#define MS_ASYNC_FLIP_LOG_ENABLE_LOGS_INTERVAL_MS 10000 -#define MS_ASYNC_FLIP_LOG_FREQUENT_LOGS_INTERVAL_MS 1000 -#define MS_ASYNC_FLIP_FREQUENT_LOG_COUNT 10 - -static void -ms_print_pageflip_error(int screen_index, const char *log_prefix, - int crtc_index, int flags, int err) -{ - /* In certain circumstances we will have a lot of flip errors without a - * reasonable way to prevent them. In such case we reduce the number of - * logged messages to at least not fill the error logs. - * - * The details are as follows: - * - * At least on i915 hardware support for async page flip support depends - * on the used modifiers which themselves can change dynamically for a - * screen. This results in the following problems: - * - * - We can't know about whether a particular CRTC will be able to do an - * async flip without hardcoding the same logic as the kernel as there's - * no interface to query this information. - * - * - There is no way to give this information to an application, because - * the protocol of the present extension does not specify anything about - * changing of the capabilities on runtime or the need to re-query them. - * - * Even if the above was solved, the only benefit would be avoiding a - * roundtrip to the kernel and reduced amount of error logs. The former - * does not seem to be a good enough benefit compared to the amount of work - * that would need to be done. The latter is solved below. */ - - static CARD32 error_last_time_ms; - static int frequent_logs; - static Bool logs_disabled; - - if (flags & DRM_MODE_PAGE_FLIP_ASYNC) { - CARD32 curr_time_ms = GetTimeInMillis(); - int clocks_since_last_log = curr_time_ms - error_last_time_ms; - - if (clocks_since_last_log > - MS_ASYNC_FLIP_LOG_ENABLE_LOGS_INTERVAL_MS) { - frequent_logs = 0; - logs_disabled = FALSE; - } - if (!logs_disabled) { - if (clocks_since_last_log < - MS_ASYNC_FLIP_LOG_FREQUENT_LOGS_INTERVAL_MS) { - frequent_logs++; - } - - if (frequent_logs > MS_ASYNC_FLIP_FREQUENT_LOG_COUNT) { - xf86DrvMsg(screen_index, X_WARNING, - "%s: detected too frequent flip errors, disabling " - "logs until frequency is reduced\n", log_prefix); - logs_disabled = TRUE; - } else { - xf86DrvMsg(screen_index, X_WARNING, - "%s: queue async flip during flip on CRTC %d failed: %s\n", - log_prefix, crtc_index, strerror(err)); - } - } - error_last_time_ms = curr_time_ms; - } else { - xf86DrvMsg(screen_index, X_WARNING, - "%s: queue flip during flip on CRTC %d failed: %s\n", - log_prefix, crtc_index, strerror(err)); - } -} - - -Bool -ms_do_pageflip(ScreenPtr screen, - PixmapPtr new_front, - void *event, - int ref_crtc_vblank_pipe, - Bool async, - ms_pageflip_handler_proc pageflip_handler, - ms_pageflip_abort_proc pageflip_abort, - const char *log_prefix) -{ -#ifndef GLAMOR_HAS_GBM - return FALSE; -#else - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - drmmode_bo new_front_bo; - uint32_t flags; - int i; - struct ms_flipdata *flipdata; - ms->glamor.block_handler(screen); - - new_front_bo.gbm = ms->glamor.gbm_bo_from_pixmap(screen, new_front); - new_front_bo.dumb = NULL; - - if (!new_front_bo.gbm) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "%s: Failed to get GBM BO for flip to new front.\n", - log_prefix); - return FALSE; - } - - flipdata = calloc(1, sizeof(struct ms_flipdata)); - if (!flipdata) { - drmmode_bo_destroy(&ms->drmmode, &new_front_bo); - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "%s: Failed to allocate flipdata.\n", log_prefix); - return FALSE; - } - - flipdata->event = event; - flipdata->screen = screen; - flipdata->event_handler = pageflip_handler; - flipdata->abort_handler = pageflip_abort; - - /* - * Take a local reference on flipdata. - * if the first flip fails, the sequence abort - * code will free the crtc flip data, and drop - * its reference which would cause this to be - * freed when we still required it. - */ - flipdata->flip_count++; - - /* Create a new handle for the back buffer */ - flipdata->old_fb_id = ms->drmmode.fb_id; - - new_front_bo.width = new_front->drawable.width; - new_front_bo.height = new_front->drawable.height; - if (drmmode_bo_import(&ms->drmmode, &new_front_bo, - &ms->drmmode.fb_id)) { - if (!ms->drmmode.flip_bo_import_failed) { - xf86DrvMsg(scrn->scrnIndex, X_WARNING, "%s: Import BO failed: %s\n", - log_prefix, strerror(errno)); - ms->drmmode.flip_bo_import_failed = TRUE; - } - goto error_out; - } else { - if (ms->drmmode.flip_bo_import_failed && - new_front != screen->GetScreenPixmap(screen)) - ms->drmmode.flip_bo_import_failed = FALSE; - } - - /* Queue flips on all enabled CRTCs. - * - * Note that if/when we get per-CRTC buffers, we'll have to update this. - * Right now it assumes a single shared fb across all CRTCs, with the - * kernel fixing up the offset of each CRTC as necessary. - * - * Also, flips queued on disabled or incorrectly configured displays - * may never complete; this is a configuration error. - */ - for (i = 0; i < config->num_crtc; i++) { - enum queue_flip_status flip_status; - xf86CrtcPtr crtc = config->crtc[i]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - if (!xf86_crtc_on(crtc)) - continue; - - flags = DRM_MODE_PAGE_FLIP_EVENT; - if (ms->drmmode.can_async_flip && async) - flags |= DRM_MODE_PAGE_FLIP_ASYNC; - - /* - * If this is not the reference crtc used for flip timing and flip event - * delivery and timestamping, ie. not the one whose presentation timing - * we do really care about, and async flips are possible, and requested - * by an xorg.conf option, then we flip this "secondary" crtc without - * sync to vblank. This may cause tearing on such "secondary" outputs, - * but it will prevent throttling of multi-display flips to the refresh - * cycle of any of the secondary crtcs, avoiding periodic slowdowns and - * judder caused by unsynchronized outputs. This is especially useful for - * outputs in a "clone-mode" or "mirror-mode" configuration. - */ - if (ms->drmmode.can_async_flip && ms->drmmode.async_flip_secondaries && - (drmmode_crtc->vblank_pipe != ref_crtc_vblank_pipe) && - (ref_crtc_vblank_pipe >= 0)) - flags |= DRM_MODE_PAGE_FLIP_ASYNC; - - flip_status = queue_flip_on_crtc(screen, crtc, flipdata, - ref_crtc_vblank_pipe, - flags); - - switch (flip_status) { - case QUEUE_FLIP_ALLOC_FAILED: - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "%s: carrier alloc for queue flip on CRTC %d failed.\n", - log_prefix, i); - goto error_undo; - case QUEUE_FLIP_QUEUE_ALLOC_FAILED: - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "%s: entry alloc for queue flip on CRTC %d failed.\n", - log_prefix, i); - goto error_undo; - case QUEUE_FLIP_DRM_FLUSH_FAILED: - ms_print_pageflip_error(scrn->scrnIndex, log_prefix, i, flags, errno); - goto error_undo; - case QUEUE_FLIP_SUCCESS: - break; - } - } - - drmmode_bo_destroy(&ms->drmmode, &new_front_bo); - - /* - * Do we have more than our local reference, - * if so and no errors, then drop our local - * reference and return now. - */ - if (flipdata->flip_count > 1) { - flipdata->flip_count--; - return TRUE; - } - -error_undo: - - /* - * Have we just got the local reference? - * free the framebuffer if so since nobody successfully - * submitted anything - */ - if (flipdata->flip_count == 1) { - drmModeRmFB(ms->fd, ms->drmmode.fb_id); - ms->drmmode.fb_id = flipdata->old_fb_id; - } - -error_out: - drmmode_bo_destroy(&ms->drmmode, &new_front_bo); - /* if only the local reference - free the structure, - * else drop the local reference and return */ - if (flipdata->flip_count == 1) - free(flipdata); - else - flipdata->flip_count--; - - return FALSE; -#endif /* GLAMOR_HAS_GBM */ -} - -#endif diff --git a/hw/xfree86/drivers/modesetting/present.c b/hw/xfree86/drivers/modesetting/present.c deleted file mode 100644 index c3266d871..000000000 --- a/hw/xfree86/drivers/modesetting/present.c +++ /dev/null @@ -1,473 +0,0 @@ -/* - * Copyright © 2014 Intel Corporation - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include "dix-config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "driver.h" -#include "drmmode_display.h" - -#if 0 -#define DebugPresent(x) ErrorF x -#else -#define DebugPresent(x) -#endif - -struct ms_present_vblank_event { - uint64_t event_id; - Bool unflip; -}; - -static RRCrtcPtr -ms_present_get_crtc(WindowPtr window) -{ - return ms_randr_crtc_covering_drawable(&window->drawable); -} - -static int -ms_present_get_ust_msc(RRCrtcPtr crtc, CARD64 *ust, CARD64 *msc) -{ - xf86CrtcPtr xf86_crtc = crtc->devPrivate; - - return ms_get_crtc_ust_msc(xf86_crtc, ust, msc); -} - -/* - * Changes the variable refresh state for every CRTC on the screen. - */ -void -ms_present_set_screen_vrr(ScrnInfoPtr scrn, Bool vrr_enabled) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CrtcPtr crtc; - int i; - - for (i = 0; i < config->num_crtc; i++) { - crtc = config->crtc[i]; - drmmode_crtc_set_vrr(crtc, vrr_enabled); - } -} - -/* - * Called when the queued vblank event has occurred - */ -static void -ms_present_vblank_handler(uint64_t msc, uint64_t usec, void *data) -{ - struct ms_present_vblank_event *event = data; - - DebugPresent(("\t\tmh %lld msc %llu\n", - (long long) event->event_id, (long long) msc)); - - present_event_notify(event->event_id, usec, msc); - free(event); -} - -/* - * Called when the queued vblank is aborted - */ -static void -ms_present_vblank_abort(void *data) -{ - struct ms_present_vblank_event *event = data; - - DebugPresent(("\t\tma %lld\n", (long long) event->event_id)); - - free(event); -} - -/* - * Queue an event to report back to the Present extension when the specified - * MSC has past - */ -static int -ms_present_queue_vblank(RRCrtcPtr crtc, - uint64_t event_id, - uint64_t msc) -{ - xf86CrtcPtr xf86_crtc = crtc->devPrivate; - struct ms_present_vblank_event *event; - uint32_t seq; - - event = calloc(sizeof(struct ms_present_vblank_event), 1); - if (!event) - return BadAlloc; - event->event_id = event_id; - seq = ms_drm_queue_alloc(xf86_crtc, event, - ms_present_vblank_handler, - ms_present_vblank_abort); - if (!seq) { - free(event); - return BadAlloc; - } - - if (!ms_queue_vblank(xf86_crtc, MS_QUEUE_ABSOLUTE, msc, NULL, seq)) - return BadAlloc; - - DebugPresent(("\t\tmq %lld seq %u msc %llu\n", - (long long) event_id, seq, (long long) msc)); - return Success; -} - -static Bool -ms_present_event_match(void *data, void *match_data) -{ - struct ms_present_vblank_event *event = data; - uint64_t *match = match_data; - - return *match == event->event_id; -} - -/* - * Remove a pending vblank event from the DRM queue so that it is not reported - * to the extension - */ -static void -ms_present_abort_vblank(RRCrtcPtr crtc, uint64_t event_id, uint64_t msc) -{ - ScreenPtr screen = crtc->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - - ms_drm_abort(scrn, ms_present_event_match, &event_id); -} - -/* - * Flush our batch buffer when requested by the Present extension. - */ -static void -ms_present_flush(WindowPtr window) -{ -#ifdef GLAMOR_HAS_GBM - ScreenPtr screen = window->drawable.pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - - if (ms->drmmode.glamor) - ms->glamor.block_handler(screen); -#endif -} - -#ifdef GLAMOR_HAS_GBM - -/** - * Callback for the DRM event queue when a flip has completed on all pipes - * - * Notify the extension code - */ -static void -ms_present_flip_handler(modesettingPtr ms, uint64_t msc, - uint64_t ust, void *data) -{ - struct ms_present_vblank_event *event = data; - - DebugPresent(("\t\tms:fc %lld msc %llu ust %llu\n", - (long long) event->event_id, - (long long) msc, (long long) ust)); - - if (event->unflip) - ms->drmmode.present_flipping = FALSE; - - ms_present_vblank_handler(msc, ust, event); -} - -/* - * Callback for the DRM queue abort code. A flip has been aborted. - */ -static void -ms_present_flip_abort(modesettingPtr ms, void *data) -{ - struct ms_present_vblank_event *event = data; - - DebugPresent(("\t\tms:fa %lld\n", (long long) event->event_id)); - - free(event); -} - -/* - * Test to see if page flipping is possible on the target crtc - * - * We ignore sw-cursors when *disabling* flipping, we may very well be - * returning to scanning out the normal framebuffer *because* we just - * switched to sw-cursor mode and check_flip just failed because of that. - */ -static Bool -ms_present_check_unflip(RRCrtcPtr crtc, - WindowPtr window, - PixmapPtr pixmap, - Bool sync_flip, - PresentFlipReason *reason) -{ - ScreenPtr screen = window->drawable.pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int num_crtcs_on = 0; - int i; - struct gbm_bo *gbm; - - if (!ms->drmmode.pageflip) - return FALSE; - - if (ms->drmmode.dri2_flipping) - return FALSE; - - if (!scrn->vtSema) - return FALSE; - - for (i = 0; i < config->num_crtc; i++) { - drmmode_crtc_private_ptr drmmode_crtc = config->crtc[i]->driver_private; - - /* Don't do pageflipping if CRTCs are rotated. */ - if (drmmode_crtc->rotate_bo.gbm) - return FALSE; - - if (xf86_crtc_on(config->crtc[i])) - num_crtcs_on++; - } - - /* We can't do pageflipping if all the CRTCs are off. */ - if (num_crtcs_on == 0) - return FALSE; - - /* - * Check stride, can't change that reliably on flip on some drivers, unless - * the kms driver is atomic_modeset_capable. - */ - if (!ms->atomic_modeset_capable && - pixmap->devKind != drmmode_bo_get_pitch(&ms->drmmode.front_bo)) - return FALSE; - - if (!ms->drmmode.glamor) - return FALSE; - -#ifdef GBM_BO_WITH_MODIFIERS - /* Check if buffer format/modifier is supported by all active CRTCs */ - gbm = ms->glamor.gbm_bo_from_pixmap(screen, pixmap); - if (gbm) { - uint32_t format; - uint64_t modifier; - - format = gbm_bo_get_format(gbm); - modifier = gbm_bo_get_modifier(gbm); - gbm_bo_destroy(gbm); - - if (!drmmode_is_format_supported(scrn, format, modifier)) { - if (reason) - *reason = PRESENT_FLIP_REASON_BUFFER_FORMAT; - return FALSE; - } - } -#endif - - /* Make sure there's a bo we can get to */ - /* XXX: actually do this. also...is it sufficient? - * if (!glamor_get_pixmap_private(pixmap)) - * return FALSE; - */ - - return TRUE; -} - -static Bool -ms_present_check_flip(RRCrtcPtr crtc, - WindowPtr window, - PixmapPtr pixmap, - Bool sync_flip, - PresentFlipReason *reason) -{ - ScreenPtr screen = window->drawable.pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - - if (ms->drmmode.sprites_visible > 0) - return FALSE; - - if(!ms_present_check_unflip(crtc, window, pixmap, sync_flip, reason)) - return FALSE; - - ms->flip_window = window; - - return TRUE; -} - -/* - * Queue a flip on 'crtc' to 'pixmap' at 'target_msc'. If 'sync_flip' is true, - * then wait for vblank. Otherwise, flip immediately - */ -static Bool -ms_present_flip(RRCrtcPtr crtc, - uint64_t event_id, - uint64_t target_msc, - PixmapPtr pixmap, - Bool sync_flip) -{ - ScreenPtr screen = crtc->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - xf86CrtcPtr xf86_crtc = crtc->devPrivate; - drmmode_crtc_private_ptr drmmode_crtc = xf86_crtc->driver_private; - Bool ret; - struct ms_present_vblank_event *event; - - if (!ms_present_check_flip(crtc, ms->flip_window, pixmap, sync_flip, NULL)) - return FALSE; - - event = calloc(1, sizeof(struct ms_present_vblank_event)); - if (!event) - return FALSE; - - DebugPresent(("\t\tms:pf %lld msc %llu\n", - (long long) event_id, (long long) target_msc)); - - event->event_id = event_id; - event->unflip = FALSE; - - /* A window can only flip if it covers the entire X screen. - * Only one window can flip at a time. - * - * If the window also has the variable refresh property then - * variable refresh supported can be enabled on every CRTC. - */ - if (ms->vrr_support && ms->is_connector_vrr_capable && - ms_window_has_variable_refresh(ms, ms->flip_window)) { - ms_present_set_screen_vrr(scrn, TRUE); - } - - ret = ms_do_pageflip(screen, pixmap, event, drmmode_crtc->vblank_pipe, !sync_flip, - ms_present_flip_handler, ms_present_flip_abort, - "Present-flip"); - if (ret) - ms->drmmode.present_flipping = TRUE; - - return ret; -} - -/* - * Queue a flip back to the normal frame buffer - */ -static void -ms_present_unflip(ScreenPtr screen, uint64_t event_id) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - PixmapPtr pixmap = screen->GetScreenPixmap(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int i; - struct ms_present_vblank_event *event; - - ms_present_set_screen_vrr(scrn, FALSE); - - event = calloc(1, sizeof(struct ms_present_vblank_event)); - if (!event) - return; - - event->event_id = event_id; - event->unflip = TRUE; - - if (ms_present_check_unflip(NULL, screen->root, pixmap, TRUE, NULL) && - ms_do_pageflip(screen, pixmap, event, -1, FALSE, - ms_present_flip_handler, ms_present_flip_abort, - "Present-unflip")) { - return; - } - - for (i = 0; i < config->num_crtc; i++) { - xf86CrtcPtr crtc = config->crtc[i]; - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - if (!crtc->enabled) - continue; - - /* info->drmmode.fb_id still points to the FB for the last flipped BO. - * Clear it, drmmode_set_mode_major will re-create it - */ - if (drmmode_crtc->drmmode->fb_id) { - drmModeRmFB(drmmode_crtc->drmmode->fd, - drmmode_crtc->drmmode->fb_id); - drmmode_crtc->drmmode->fb_id = 0; - } - - if (drmmode_crtc->dpms_mode == DPMSModeOn) - crtc->funcs->set_mode_major(crtc, &crtc->mode, crtc->rotation, - crtc->x, crtc->y); - else - drmmode_crtc->need_modeset = TRUE; - } - - present_event_notify(event_id, 0, 0); - ms->drmmode.present_flipping = FALSE; -} -#endif - -static present_screen_info_rec ms_present_screen_info = { - .version = PRESENT_SCREEN_INFO_VERSION, - - .get_crtc = ms_present_get_crtc, - .get_ust_msc = ms_present_get_ust_msc, - .queue_vblank = ms_present_queue_vblank, - .abort_vblank = ms_present_abort_vblank, - .flush = ms_present_flush, - - .capabilities = PresentCapabilityNone, -#ifdef GLAMOR_HAS_GBM - .check_flip = NULL, - .check_flip2 = ms_present_check_flip, - .flip = ms_present_flip, - .unflip = ms_present_unflip, -#endif -}; - -Bool -ms_present_screen_init(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - uint64_t value; - int ret; - - ret = drmGetCap(ms->fd, DRM_CAP_ASYNC_PAGE_FLIP, &value); - if (ret == 0 && value == 1) { - ms_present_screen_info.capabilities |= PresentCapabilityAsync; - ms->drmmode.can_async_flip = TRUE; - } - - return present_screen_init(screen, &ms_present_screen_info); -} diff --git a/hw/xfree86/drivers/modesetting/vblank.c b/hw/xfree86/drivers/modesetting/vblank.c deleted file mode 100644 index ea9e7a88c..000000000 --- a/hw/xfree86/drivers/modesetting/vblank.c +++ /dev/null @@ -1,573 +0,0 @@ -/* - * Copyright © 2013 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -/** @file vblank.c - * - * Support for tracking the DRM's vblank events. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include "dix-config.h" -#endif - -#include -#include -#include -#include "driver.h" -#include "drmmode_display.h" - -/** - * Tracking for outstanding events queued to the kernel. - * - * Each list entry is a struct ms_drm_queue, which has a uint32_t - * value generated from drm_seq that identifies the event and a - * reference back to the crtc/screen associated with the event. It's - * done this way rather than in the screen because we want to be able - * to drain the list of event handlers that should be called at server - * regen time, even though we don't close the drm fd and have no way - * to actually drain the kernel events. - */ -static struct xorg_list ms_drm_queue; -static uint32_t ms_drm_seq; - -static void box_intersect(BoxPtr dest, BoxPtr a, BoxPtr b) -{ - dest->x1 = a->x1 > b->x1 ? a->x1 : b->x1; - dest->x2 = a->x2 < b->x2 ? a->x2 : b->x2; - if (dest->x1 >= dest->x2) { - dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0; - return; - } - - dest->y1 = a->y1 > b->y1 ? a->y1 : b->y1; - dest->y2 = a->y2 < b->y2 ? a->y2 : b->y2; - if (dest->y1 >= dest->y2) - dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0; -} - -static void rr_crtc_box(RRCrtcPtr crtc, BoxPtr crtc_box) -{ - if (crtc->mode) { - crtc_box->x1 = crtc->x; - crtc_box->y1 = crtc->y; - switch (crtc->rotation) { - case RR_Rotate_0: - case RR_Rotate_180: - default: - crtc_box->x2 = crtc->x + crtc->mode->mode.width; - crtc_box->y2 = crtc->y + crtc->mode->mode.height; - break; - case RR_Rotate_90: - case RR_Rotate_270: - crtc_box->x2 = crtc->x + crtc->mode->mode.height; - crtc_box->y2 = crtc->y + crtc->mode->mode.width; - break; - } - } else - crtc_box->x1 = crtc_box->x2 = crtc_box->y1 = crtc_box->y2 = 0; -} - -static int box_area(BoxPtr box) -{ - return (int)(box->x2 - box->x1) * (int)(box->y2 - box->y1); -} - -static Bool rr_crtc_on(RRCrtcPtr crtc, Bool crtc_is_xf86_hint) -{ - if (!crtc) { - return FALSE; - } - if (crtc_is_xf86_hint && crtc->devPrivate) { - return xf86_crtc_on(crtc->devPrivate); - } else { - return !!crtc->mode; - } -} - -Bool -xf86_crtc_on(xf86CrtcPtr crtc) -{ - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - - return crtc->enabled && drmmode_crtc->dpms_mode == DPMSModeOn; -} - - -/* - * Return the crtc covering 'box'. If two crtcs cover a portion of - * 'box', then prefer the crtc with greater coverage. - */ -static RRCrtcPtr -rr_crtc_covering_box(ScreenPtr pScreen, BoxPtr box, Bool screen_is_xf86_hint) -{ - rrScrPrivPtr pScrPriv; - RROutputPtr primary_output; - RRCrtcPtr crtc, best_crtc, primary_crtc; - int coverage, best_coverage; - int c; - BoxRec crtc_box, cover_box; - - best_crtc = NULL; - best_coverage = 0; - - if (!dixPrivateKeyRegistered(rrPrivKey)) - return NULL; - - pScrPriv = rrGetScrPriv(pScreen); - - if (!pScrPriv) - return NULL; - - primary_crtc = NULL; - primary_output = RRFirstOutput(pScreen); - if (primary_output) - primary_crtc = primary_output->crtc; - - for (c = 0; c < pScrPriv->numCrtcs; c++) { - crtc = pScrPriv->crtcs[c]; - - /* If the CRTC is off, treat it as not covering */ - if (!rr_crtc_on(crtc, screen_is_xf86_hint)) - continue; - - rr_crtc_box(crtc, &crtc_box); - box_intersect(&cover_box, &crtc_box, box); - coverage = box_area(&cover_box); - if ((coverage > best_coverage) || - (coverage == best_coverage && crtc == primary_crtc)) { - best_crtc = crtc; - best_coverage = coverage; - } - } - - return best_crtc; -} - -static RRCrtcPtr -rr_crtc_covering_box_on_secondary(ScreenPtr pScreen, BoxPtr box) -{ - if (!pScreen->isGPU) { - ScreenPtr secondary; - RRCrtcPtr crtc = NULL; - - xorg_list_for_each_entry(secondary, &pScreen->secondary_list, secondary_head) { - if (!secondary->is_output_secondary) - continue; - - crtc = rr_crtc_covering_box(secondary, box, FALSE); - if (crtc) - return crtc; - } - } - - return NULL; -} - -xf86CrtcPtr -ms_dri2_crtc_covering_drawable(DrawablePtr pDraw) -{ - ScreenPtr pScreen = pDraw->pScreen; - RRCrtcPtr crtc = NULL; - BoxRec box; - - box.x1 = pDraw->x; - box.y1 = pDraw->y; - box.x2 = box.x1 + pDraw->width; - box.y2 = box.y1 + pDraw->height; - - crtc = rr_crtc_covering_box(pScreen, &box, TRUE); - if (crtc) { - return crtc->devPrivate; - } - return NULL; -} - -RRCrtcPtr -ms_randr_crtc_covering_drawable(DrawablePtr pDraw) -{ - ScreenPtr pScreen = pDraw->pScreen; - RRCrtcPtr crtc = NULL; - BoxRec box; - - box.x1 = pDraw->x; - box.y1 = pDraw->y; - box.x2 = box.x1 + pDraw->width; - box.y2 = box.y1 + pDraw->height; - - crtc = rr_crtc_covering_box(pScreen, &box, TRUE); - if (!crtc) { - crtc = rr_crtc_covering_box_on_secondary(pScreen, &box); - } - return crtc; -} - -static Bool -ms_get_kernel_ust_msc(xf86CrtcPtr crtc, - uint64_t *msc, uint64_t *ust) -{ - ScreenPtr screen = crtc->randr_crtc->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmVBlank vbl; - int ret; - - if (ms->has_queue_sequence || !ms->tried_queue_sequence) { - uint64_t ns; - ms->tried_queue_sequence = TRUE; - - ret = drmCrtcGetSequence(ms->fd, drmmode_crtc->mode_crtc->crtc_id, - msc, &ns); - if (ret != -1 || (errno != ENOTTY && errno != EINVAL)) { - ms->has_queue_sequence = TRUE; - if (ret == 0) - *ust = ns / 1000; - return ret == 0; - } - } - /* Get current count */ - vbl.request.type = DRM_VBLANK_RELATIVE | drmmode_crtc->vblank_pipe; - vbl.request.sequence = 0; - vbl.request.signal = 0; - ret = drmWaitVBlank(ms->fd, &vbl); - if (ret) { - *msc = 0; - *ust = 0; - return FALSE; - } else { - *msc = vbl.reply.sequence; - *ust = (CARD64) vbl.reply.tval_sec * 1000000 + vbl.reply.tval_usec; - return TRUE; - } -} - -Bool -ms_queue_vblank(xf86CrtcPtr crtc, ms_queue_flag flags, - uint64_t msc, uint64_t *msc_queued, uint32_t seq) -{ - ScreenPtr screen = crtc->randr_crtc->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private; - drmVBlank vbl; - int ret; - - for (;;) { - /* Queue an event at the specified sequence */ - if (ms->has_queue_sequence || !ms->tried_queue_sequence) { - uint32_t drm_flags = 0; - uint64_t kernel_queued; - - ms->tried_queue_sequence = TRUE; - - if (flags & MS_QUEUE_RELATIVE) - drm_flags |= DRM_CRTC_SEQUENCE_RELATIVE; - if (flags & MS_QUEUE_NEXT_ON_MISS) - drm_flags |= DRM_CRTC_SEQUENCE_NEXT_ON_MISS; - - ret = drmCrtcQueueSequence(ms->fd, drmmode_crtc->mode_crtc->crtc_id, - drm_flags, msc, &kernel_queued, seq); - if (ret == 0) { - if (msc_queued) - *msc_queued = ms_kernel_msc_to_crtc_msc(crtc, kernel_queued, TRUE); - ms->has_queue_sequence = TRUE; - return TRUE; - } - - if (ret != -1 || (errno != ENOTTY && errno != EINVAL)) { - ms->has_queue_sequence = TRUE; - goto check; - } - } - vbl.request.type = DRM_VBLANK_EVENT | drmmode_crtc->vblank_pipe; - if (flags & MS_QUEUE_RELATIVE) - vbl.request.type |= DRM_VBLANK_RELATIVE; - else - vbl.request.type |= DRM_VBLANK_ABSOLUTE; - if (flags & MS_QUEUE_NEXT_ON_MISS) - vbl.request.type |= DRM_VBLANK_NEXTONMISS; - - vbl.request.sequence = msc; - vbl.request.signal = seq; - ret = drmWaitVBlank(ms->fd, &vbl); - if (ret == 0) { - if (msc_queued) - *msc_queued = ms_kernel_msc_to_crtc_msc(crtc, vbl.reply.sequence, FALSE); - return TRUE; - } - check: - if (errno != EBUSY) { - ms_drm_abort_seq(scrn, seq); - return FALSE; - } - ms_flush_drm_events(screen); - } -} - -/** - * Convert a 32-bit or 64-bit kernel MSC sequence number to a 64-bit local - * sequence number, adding in the high 32 bits, and dealing with 32-bit - * wrapping if needed. - */ -uint64_t -ms_kernel_msc_to_crtc_msc(xf86CrtcPtr crtc, uint64_t sequence, Bool is64bit) -{ - drmmode_crtc_private_rec *drmmode_crtc = crtc->driver_private; - - if (!is64bit) { - /* sequence is provided as a 32 bit value from one of the 32 bit apis, - * e.g., drmWaitVBlank(), classic vblank events, or pageflip events. - * - * Track and handle 32-Bit wrapping, somewhat robust against occasional - * out-of-order not always monotonically increasing sequence values. - */ - if ((int64_t) sequence < ((int64_t) drmmode_crtc->msc_prev - 0x40000000)) - drmmode_crtc->msc_high += 0x100000000L; - - if ((int64_t) sequence > ((int64_t) drmmode_crtc->msc_prev + 0x40000000)) - drmmode_crtc->msc_high -= 0x100000000L; - - drmmode_crtc->msc_prev = sequence; - - return drmmode_crtc->msc_high + sequence; - } - - /* True 64-Bit sequence from Linux 4.15+ 64-Bit drmCrtcGetSequence / - * drmCrtcQueueSequence apis and events. Pass through sequence unmodified, - * but update the 32-bit tracking variables with reliable ground truth. - * - * With 64-Bit api in use, the only !is64bit input is from pageflip events, - * and any pageflip event is usually preceded by some is64bit input from - * swap scheduling, so this should provide reliable mapping for pageflip - * events based on true 64-bit input as baseline as well. - */ - drmmode_crtc->msc_prev = sequence; - drmmode_crtc->msc_high = sequence & 0xffffffff00000000; - - return sequence; -} - -int -ms_get_crtc_ust_msc(xf86CrtcPtr crtc, CARD64 *ust, CARD64 *msc) -{ - ScreenPtr screen = crtc->randr_crtc->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - uint64_t kernel_msc; - - if (!ms_get_kernel_ust_msc(crtc, &kernel_msc, ust)) - return BadMatch; - *msc = ms_kernel_msc_to_crtc_msc(crtc, kernel_msc, ms->has_queue_sequence); - - return Success; -} - -/** - * Check for pending DRM events and process them. - */ -static void -ms_drm_socket_handler(int fd, int ready, void *data) -{ - ScreenPtr screen = data; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - - if (data == NULL) - return; - - drmHandleEvent(fd, &ms->event_context); -} - -/* - * Enqueue a potential drm response; when the associated response - * appears, we've got data to pass to the handler from here - */ -uint32_t -ms_drm_queue_alloc(xf86CrtcPtr crtc, - void *data, - ms_drm_handler_proc handler, - ms_drm_abort_proc abort) -{ - ScreenPtr screen = crtc->randr_crtc->pScreen; - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - struct ms_drm_queue *q; - - q = calloc(1, sizeof(struct ms_drm_queue)); - - if (!q) - return 0; - if (!ms_drm_seq) - ++ms_drm_seq; - q->seq = ms_drm_seq++; - q->scrn = scrn; - q->crtc = crtc; - q->data = data; - q->handler = handler; - q->abort = abort; - - xorg_list_add(&q->list, &ms_drm_queue); - - return q->seq; -} - -/** - * Abort one queued DRM entry, removing it - * from the list, calling the abort function and - * freeing the memory - */ -static void -ms_drm_abort_one(struct ms_drm_queue *q) -{ - xorg_list_del(&q->list); - q->abort(q->data); - free(q); -} - -/** - * Abort all queued entries on a specific scrn, used - * when resetting the X server - */ -static void -ms_drm_abort_scrn(ScrnInfoPtr scrn) -{ - struct ms_drm_queue *q, *tmp; - - xorg_list_for_each_entry_safe(q, tmp, &ms_drm_queue, list) { - if (q->scrn == scrn) - ms_drm_abort_one(q); - } -} - -/** - * Abort by drm queue sequence number. - */ -void -ms_drm_abort_seq(ScrnInfoPtr scrn, uint32_t seq) -{ - struct ms_drm_queue *q, *tmp; - - xorg_list_for_each_entry_safe(q, tmp, &ms_drm_queue, list) { - if (q->seq == seq) { - ms_drm_abort_one(q); - break; - } - } -} - -/* - * Externally usable abort function that uses a callback to match a single - * queued entry to abort - */ -void -ms_drm_abort(ScrnInfoPtr scrn, Bool (*match)(void *data, void *match_data), - void *match_data) -{ - struct ms_drm_queue *q; - - xorg_list_for_each_entry(q, &ms_drm_queue, list) { - if (match(q->data, match_data)) { - ms_drm_abort_one(q); - break; - } - } -} - -/* - * General DRM kernel handler. Looks for the matching sequence number in the - * drm event queue and calls the handler for it. - */ -static void -ms_drm_sequence_handler(int fd, uint64_t frame, uint64_t ns, Bool is64bit, uint64_t user_data) -{ - struct ms_drm_queue *q, *tmp; - uint32_t seq = (uint32_t) user_data; - - xorg_list_for_each_entry_safe(q, tmp, &ms_drm_queue, list) { - if (q->seq == seq) { - uint64_t msc; - - msc = ms_kernel_msc_to_crtc_msc(q->crtc, frame, is64bit); - xorg_list_del(&q->list); - q->handler(msc, ns / 1000, q->data); - free(q); - break; - } - } -} - -static void -ms_drm_sequence_handler_64bit(int fd, uint64_t frame, uint64_t ns, uint64_t user_data) -{ - /* frame is true 64 bit wrapped into 64 bit */ - ms_drm_sequence_handler(fd, frame, ns, TRUE, user_data); -} - -static void -ms_drm_handler(int fd, uint32_t frame, uint32_t sec, uint32_t usec, - void *user_ptr) -{ - /* frame is 32 bit wrapped into 64 bit */ - ms_drm_sequence_handler(fd, frame, ((uint64_t) sec * 1000000 + usec) * 1000, - FALSE, (uint32_t) (uintptr_t) user_ptr); -} - -Bool -ms_vblank_screen_init(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - modesettingEntPtr ms_ent = ms_ent_priv(scrn); - xorg_list_init(&ms_drm_queue); - - ms->event_context.version = 4; - ms->event_context.vblank_handler = ms_drm_handler; - ms->event_context.page_flip_handler = ms_drm_handler; - ms->event_context.sequence_handler = ms_drm_sequence_handler_64bit; - - /* We need to re-register the DRM fd for the synchronisation - * feedback on every server generation, so perform the - * registration within ScreenInit and not PreInit. - */ - if (ms_ent->fd_wakeup_registered != serverGeneration) { - SetNotifyFd(ms->fd, ms_drm_socket_handler, X_NOTIFY_READ, screen); - ms_ent->fd_wakeup_registered = serverGeneration; - ms_ent->fd_wakeup_ref = 1; - } else - ms_ent->fd_wakeup_ref++; - - return TRUE; -} - -void -ms_vblank_close_screen(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - modesettingPtr ms = modesettingPTR(scrn); - modesettingEntPtr ms_ent = ms_ent_priv(scrn); - - ms_drm_abort_scrn(scrn); - - if (ms_ent->fd_wakeup_registered == serverGeneration && - !--ms_ent->fd_wakeup_ref) { - RemoveNotifyFd(ms->fd); - } -} diff --git a/hw/xfree86/exa/examodule.c b/hw/xfree86/exa/examodule.c deleted file mode 100644 index 0bbd93e34..000000000 --- a/hw/xfree86/exa/examodule.c +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright © 2006 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Authors: - * Eric Anholt - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "exa_priv.h" - -#include "xf86str.h" -#include "xf86.h" - -typedef struct _ExaXorgScreenPrivRec { - CloseScreenProcPtr SavedCloseScreen; - xf86EnableDisableFBAccessProc *SavedEnableDisableFBAccess; - OptionInfoPtr options; -} ExaXorgScreenPrivRec, *ExaXorgScreenPrivPtr; - -static DevPrivateKeyRec exaXorgScreenPrivateKeyRec; - -#define exaXorgScreenPrivateKey (&exaXorgScreenPrivateKeyRec) - -typedef enum { - EXAOPT_MIGRATION_HEURISTIC, - EXAOPT_NO_COMPOSITE, - EXAOPT_NO_UTS, - EXAOPT_NO_DFS, - EXAOPT_OPTIMIZE_MIGRATION -} EXAOpts; - -static const OptionInfoRec EXAOptions[] = { - {EXAOPT_MIGRATION_HEURISTIC, "MigrationHeuristic", - OPTV_ANYSTR, {0}, FALSE}, - {EXAOPT_NO_COMPOSITE, "EXANoComposite", - OPTV_BOOLEAN, {0}, FALSE}, - {EXAOPT_NO_UTS, "EXANoUploadToScreen", - OPTV_BOOLEAN, {0}, FALSE}, - {EXAOPT_NO_DFS, "EXANoDownloadFromScreen", - OPTV_BOOLEAN, {0}, FALSE}, - {EXAOPT_OPTIMIZE_MIGRATION, "EXAOptimizeMigration", - OPTV_BOOLEAN, {0}, FALSE}, - {-1, NULL, - OPTV_NONE, {0}, FALSE} -}; - -static Bool -exaXorgCloseScreen(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr) - dixLookupPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey); - - pScreen->CloseScreen = pScreenPriv->SavedCloseScreen; - - pScrn->EnableDisableFBAccess = pScreenPriv->SavedEnableDisableFBAccess; - - free(pScreenPriv->options); - free(pScreenPriv); - - return pScreen->CloseScreen(pScreen); -} - -static void -exaXorgEnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - ExaXorgScreenPrivPtr pScreenPriv = (ExaXorgScreenPrivPtr) - dixLookupPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey); - - if (!enable) - exaEnableDisableFBAccess(pScreen, enable); - - if (pScreenPriv->SavedEnableDisableFBAccess) - pScreenPriv->SavedEnableDisableFBAccess(pScrn, enable); - - if (enable) - exaEnableDisableFBAccess(pScreen, enable); -} - -/** - * This will be called during exaDriverInit, giving us the chance to set options - * and hook in our EnableDisableFBAccess. - */ -void -exaDDXDriverInit(ScreenPtr pScreen) -{ - ExaScreenPriv(pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - ExaXorgScreenPrivPtr pScreenPriv; - - if (!dixRegisterPrivateKey(&exaXorgScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) - return; - - pScreenPriv = calloc(1, sizeof(ExaXorgScreenPrivRec)); - if (pScreenPriv == NULL) - return; - - pScreenPriv->options = xnfalloc(sizeof(EXAOptions)); - memcpy(pScreenPriv->options, EXAOptions, sizeof(EXAOptions)); - xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pScreenPriv->options); - - if (pExaScr->info->flags & EXA_OFFSCREEN_PIXMAPS) { - if (!(pExaScr->info->flags & EXA_HANDLES_PIXMAPS) && - pExaScr->info->offScreenBase < pExaScr->info->memorySize) { - const char *heuristicName; - - heuristicName = xf86GetOptValString(pScreenPriv->options, - EXAOPT_MIGRATION_HEURISTIC); - if (heuristicName != NULL) { - if (strcmp(heuristicName, "greedy") == 0) - pExaScr->migration = ExaMigrationGreedy; - else if (strcmp(heuristicName, "always") == 0) - pExaScr->migration = ExaMigrationAlways; - else if (strcmp(heuristicName, "smart") == 0) - pExaScr->migration = ExaMigrationSmart; - else { - xf86DrvMsg(pScreen->myNum, X_WARNING, - "EXA: unknown migration heuristic %s\n", - heuristicName); - } - } - } - - pExaScr->optimize_migration = - xf86ReturnOptValBool(pScreenPriv->options, - EXAOPT_OPTIMIZE_MIGRATION, TRUE); - } - - if (xf86ReturnOptValBool(pScreenPriv->options, EXAOPT_NO_COMPOSITE, FALSE)) { - xf86DrvMsg(pScreen->myNum, X_CONFIG, - "EXA: Disabling Composite operation " - "(RENDER acceleration)\n"); - pExaScr->info->CheckComposite = NULL; - pExaScr->info->PrepareComposite = NULL; - } - - if (xf86ReturnOptValBool(pScreenPriv->options, EXAOPT_NO_UTS, FALSE)) { - xf86DrvMsg(pScreen->myNum, X_CONFIG, "EXA: Disabling UploadToScreen\n"); - pExaScr->info->UploadToScreen = NULL; - } - - if (xf86ReturnOptValBool(pScreenPriv->options, EXAOPT_NO_DFS, FALSE)) { - xf86DrvMsg(pScreen->myNum, X_CONFIG, - "EXA: Disabling DownloadFromScreen\n"); - pExaScr->info->DownloadFromScreen = NULL; - } - - dixSetPrivate(&pScreen->devPrivates, exaXorgScreenPrivateKey, pScreenPriv); - - pScreenPriv->SavedEnableDisableFBAccess = pScrn->EnableDisableFBAccess; - pScrn->EnableDisableFBAccess = exaXorgEnableDisableFBAccess; - - pScreenPriv->SavedCloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = exaXorgCloseScreen; - -} - -static XF86ModuleVersionInfo exaVersRec = { - "exa", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - EXA_VERSION_MAJOR, EXA_VERSION_MINOR, EXA_VERSION_RELEASE, - ABI_CLASS_VIDEODRV, /* requires the video driver ABI */ - ABI_VIDEODRV_VERSION, - MOD_CLASS_NONE, - {0, 0, 0, 0} -}; - -_X_EXPORT XF86ModuleData exaModuleData = { &exaVersRec, NULL, NULL }; diff --git a/hw/xfree86/exa/man/exa.man b/hw/xfree86/exa/man/exa.man deleted file mode 100644 index c051b998b..000000000 --- a/hw/xfree86/exa/man/exa.man +++ /dev/null @@ -1,42 +0,0 @@ -.\" shorthand for double quote that works everywhere. -.ds q \N'34' -.TH EXA @drivermansuffix@ @vendorversion@ -.SH NAME -exa \- new 2D acceleration architecture for X.Org -.SH DESCRIPTION -.B EXA -provides a simple API for video drivers to implement for 2D acceleration. It -is a module loaded by drivers, and is not intended to be loaded on its own. -See your driver's manual page for how to enable -.BR EXA . -.PP -The -.B EXA -architecture is designed to make accelerating the Render extension simple and -efficient, and results in various performance tradeoffs compared to XAA. Some -xorg.conf options are available for debugging performance issues or -driver rendering problems. They are not intended for general use. -.TP -.BI "Option \*qEXANoComposite\*q \*q" boolean \*q -Disables acceleration of the Composite operation, which is at the heart of -the Render extension. Not related to the Composite extension. Default: No. -.TP -.BI "Option \*qEXANoUploadToScreen\*q \*q" boolean \*q -Disables acceleration of uploading pixmap data to the framebuffer. Default: No. -.TP -.BI "Option \*qEXANoDownloadFromScreen\*q \*q" boolean \*q -Disables acceleration of downloading of pixmap data from the framebuffer. -.B NOTE: -Not usable with drivers which rely on DownloadFromScreen succeeding. -Default: No. -.TP -.BI "Option \*qMigrationHeuristic\*q \*q" anystr \*q -Chooses an alternate pixmap migration heuristic, for debugging purposes. The -default is intended to be the best performing one for general use, though others -may help with specific use cases. Available options include \*qalways\*q, -\*qgreedy\*q, and \*qsmart\*q. Default: always. -.SH "SEE ALSO" -.BR Xorg (@appmansuffix@), -.BR xorg.conf(@filemansuffix@). -.SH AUTHORS -Authors include: Keith Packard, Eric Anholt, Zack Rusin, and Michel D\(:anzer diff --git a/hw/xfree86/exa/meson.build b/hw/xfree86/exa/meson.build deleted file mode 100644 index 75a5d429e..000000000 --- a/hw/xfree86/exa/meson.build +++ /dev/null @@ -1,15 +0,0 @@ -xorg_exa = shared_module('exa', - 'examodule.c', - include_directories: [inc, xorg_inc], - dependencies: common_dep, - link_with: [libxserver_exa, e], - c_args: xorg_c_args, - install: true, - install_dir: module_dir, -) - -install_man(configure_file( - input: 'man/exa.man', - output: 'exa.4', - configuration: manpage_config, -)) diff --git a/hw/xfree86/fbdevhw/README b/hw/xfree86/fbdevhw/README deleted file mode 100644 index 27cc337d4..000000000 --- a/hw/xfree86/fbdevhw/README +++ /dev/null @@ -1,16 +0,0 @@ - -This is a submodule to access linux framebuffer devices. -It is supported to work as helper module (like vgahw) -for the chipset drivers. There are functions for -saving/restoring/setting video modes, set palette entries, -and a few more helper functions. Some of them can be -hooked directly into ScrnInfoRec. - -In ../drivers/fbdev is a "chipset" driver. It is a simple, -non-accelerated and hardware-independent driver which works -on top of this fbdevhw submodule. - - Gerd - --- -Gerd Knorr diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c deleted file mode 100644 index 3d8b92e66..000000000 --- a/hw/xfree86/fbdevhw/fbdevhw.c +++ /dev/null @@ -1,978 +0,0 @@ -/* all drivers need this */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "xf86.h" -#include "xf86Modes.h" -#include "xf86_OSproc.h" - -/* pci stuff */ -#include "xf86Pci.h" - -#include "xf86cmap.h" - -#include "fbdevhw.h" -#include "fbpriv.h" -#include "globals.h" -#include - -#define PAGE_MASK (~(getpagesize() - 1)) - -static XF86ModuleVersionInfo fbdevHWVersRec = { - "fbdevhw", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 0, 2, - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_NONE, - {0, 0, 0, 0} -}; - -_X_EXPORT XF86ModuleData fbdevhwModuleData = { - &fbdevHWVersRec, - NULL, - NULL -}; - -#include -#include -#include -#include -#include -#include -#include - -/* -------------------------------------------------------------------- */ -/* our private data, and two functions to allocate/free this */ - -#define FBDEVHWPTRLVAL(p) (p)->privates[fbdevHWPrivateIndex].ptr -#define FBDEVHWPTR(p) ((fbdevHWPtr)(FBDEVHWPTRLVAL(p))) - -static int fbdevHWPrivateIndex = -1; - -typedef struct { - /* framebuffer device: filename (/dev/fb*), handle, more */ - char *device; - int fd; - void *fbmem; - unsigned int fbmem_len; - unsigned int fboff; - char *mmio; - unsigned int mmio_len; - - /* current hardware state */ - struct fb_fix_screeninfo fix; - struct fb_var_screeninfo var; - - /* saved video mode */ - struct fb_var_screeninfo saved_var; - - /* buildin video mode */ - DisplayModeRec buildin; - - /* disable non-fatal unsupported ioctls */ - CARD32 unsupported_ioctls; -} fbdevHWRec, *fbdevHWPtr; - -enum { - FBIOBLANK_UNSUPPORTED = 0, -}; - -Bool -fbdevHWGetRec(ScrnInfoPtr pScrn) -{ - if (fbdevHWPrivateIndex < 0) - fbdevHWPrivateIndex = xf86AllocateScrnInfoPrivateIndex(); - - if (FBDEVHWPTR(pScrn) != NULL) - return TRUE; - - FBDEVHWPTRLVAL(pScrn) = xnfcalloc(sizeof(fbdevHWRec), 1); - return TRUE; -} - -void -fbdevHWFreeRec(ScrnInfoPtr pScrn) -{ - if (fbdevHWPrivateIndex < 0) - return; - free(FBDEVHWPTR(pScrn)); - FBDEVHWPTRLVAL(pScrn) = NULL; -} - -int -fbdevHWGetFD(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr; - - fbdevHWGetRec(pScrn); - fPtr = FBDEVHWPTR(pScrn); - - return fPtr->fd; -} - -/* -------------------------------------------------------------------- */ -/* some helpers for printing debug information */ - -#ifdef DEBUG -static void -print_fbdev_mode(const char *txt, struct fb_var_screeninfo *var) -{ - ErrorF("fbdev %s mode:\t%d %d %d %d %d %d %d %d %d %d %d:%d:%d\n", - txt, var->pixclock, - var->xres, var->right_margin, var->hsync_len, var->left_margin, - var->yres, var->lower_margin, var->vsync_len, var->upper_margin, - var->bits_per_pixel, - var->red.length, var->green.length, var->blue.length); -} - -static void -print_xfree_mode(const char *txt, DisplayModePtr mode) -{ - ErrorF("xfree %s mode:\t%d %d %d %d %d %d %d %d %d\n", - txt, mode->Clock, - mode->HDisplay, mode->HSyncStart, mode->HSyncEnd, mode->HTotal, - mode->VDisplay, mode->VSyncStart, mode->VSyncEnd, mode->VTotal); -} -#endif - -/* -------------------------------------------------------------------- */ -/* Convert timings between the XFree and the Frame Buffer Device */ - -static void -xfree2fbdev_fblayout(ScrnInfoPtr pScrn, struct fb_var_screeninfo *var) -{ - var->xres_virtual = pScrn->displayWidth ? pScrn->displayWidth : - pScrn->virtualX; - var->yres_virtual = pScrn->virtualY; - var->bits_per_pixel = pScrn->bitsPerPixel; - if (pScrn->defaultVisual == TrueColor || - pScrn->defaultVisual == DirectColor) { - var->red.length = pScrn->weight.red; - var->green.length = pScrn->weight.green; - var->blue.length = pScrn->weight.blue; - } - else { - var->red.length = 8; - var->green.length = 8; - var->blue.length = 8; - } -} - -static void -xfree2fbdev_timing(DisplayModePtr mode, struct fb_var_screeninfo *var) -{ - var->xres = mode->HDisplay; - var->yres = mode->VDisplay; - if (var->xres_virtual < var->xres) - var->xres_virtual = var->xres; - if (var->yres_virtual < var->yres) - var->yres_virtual = var->yres; - var->xoffset = var->yoffset = 0; - var->pixclock = mode->Clock ? 1000000000 / mode->Clock : 0; - var->right_margin = mode->HSyncStart - mode->HDisplay; - var->hsync_len = mode->HSyncEnd - mode->HSyncStart; - var->left_margin = mode->HTotal - mode->HSyncEnd; - var->lower_margin = mode->VSyncStart - mode->VDisplay; - var->vsync_len = mode->VSyncEnd - mode->VSyncStart; - var->upper_margin = mode->VTotal - mode->VSyncEnd; - var->sync = 0; - if (mode->Flags & V_PHSYNC) - var->sync |= FB_SYNC_HOR_HIGH_ACT; - if (mode->Flags & V_PVSYNC) - var->sync |= FB_SYNC_VERT_HIGH_ACT; - if (mode->Flags & V_PCSYNC) - var->sync |= FB_SYNC_COMP_HIGH_ACT; - if (mode->Flags & V_BCAST) - var->sync |= FB_SYNC_BROADCAST; - if (mode->Flags & V_INTERLACE) - var->vmode = FB_VMODE_INTERLACED; - else if (mode->Flags & V_DBLSCAN) - var->vmode = FB_VMODE_DOUBLE; - else - var->vmode = FB_VMODE_NONINTERLACED; -} - -static Bool -fbdev_modes_equal(struct fb_var_screeninfo *set, struct fb_var_screeninfo *req) -{ - return (set->xres_virtual >= req->xres_virtual && - set->yres_virtual >= req->yres_virtual && - set->bits_per_pixel == req->bits_per_pixel && - set->red.length == req->red.length && - set->green.length == req->green.length && - set->blue.length == req->blue.length && - set->xres == req->xres && set->yres == req->yres && - set->right_margin == req->right_margin && - set->hsync_len == req->hsync_len && - set->left_margin == req->left_margin && - set->lower_margin == req->lower_margin && - set->vsync_len == req->vsync_len && - set->upper_margin == req->upper_margin && - set->sync == req->sync && set->vmode == req->vmode); -} - -static void -fbdev2xfree_timing(struct fb_var_screeninfo *var, DisplayModePtr mode) -{ - mode->Clock = var->pixclock ? 1000000000 / var->pixclock : 0; - mode->HDisplay = var->xres; - mode->HSyncStart = mode->HDisplay + var->right_margin; - mode->HSyncEnd = mode->HSyncStart + var->hsync_len; - mode->HTotal = mode->HSyncEnd + var->left_margin; - mode->VDisplay = var->yres; - mode->VSyncStart = mode->VDisplay + var->lower_margin; - mode->VSyncEnd = mode->VSyncStart + var->vsync_len; - mode->VTotal = mode->VSyncEnd + var->upper_margin; - mode->Flags = 0; - mode->Flags |= var->sync & FB_SYNC_HOR_HIGH_ACT ? V_PHSYNC : V_NHSYNC; - mode->Flags |= var->sync & FB_SYNC_VERT_HIGH_ACT ? V_PVSYNC : V_NVSYNC; - mode->Flags |= var->sync & FB_SYNC_COMP_HIGH_ACT ? V_PCSYNC : V_NCSYNC; - if (var->sync & FB_SYNC_BROADCAST) - mode->Flags |= V_BCAST; - if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) - mode->Flags |= V_INTERLACE; - else if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE) - mode->Flags |= V_DBLSCAN; - mode->SynthClock = mode->Clock; - mode->CrtcHDisplay = mode->HDisplay; - mode->CrtcHSyncStart = mode->HSyncStart; - mode->CrtcHSyncEnd = mode->HSyncEnd; - mode->CrtcHTotal = mode->HTotal; - mode->CrtcVDisplay = mode->VDisplay; - mode->CrtcVSyncStart = mode->VSyncStart; - mode->CrtcVSyncEnd = mode->VSyncEnd; - mode->CrtcVTotal = mode->VTotal; - mode->CrtcHAdjusted = FALSE; - mode->CrtcVAdjusted = FALSE; -} - -/* -------------------------------------------------------------------- */ -/* open correct framebuffer device */ - -/** - * Try to find the framebuffer device for a given PCI device - */ -static int -fbdev_open_pci(struct pci_device *pPci, char **namep) -{ - struct fb_fix_screeninfo fix; - char filename[256]; - int fd, i; - - for (i = 0; i < 8; i++) { - snprintf(filename, sizeof(filename), - "/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics/fb%d", - pPci->domain, pPci->bus, pPci->dev, pPci->func, i); - - fd = open(filename, O_RDONLY, 0); - if (fd < 0) { - snprintf(filename, sizeof(filename), - "/sys/bus/pci/devices/%04x:%02x:%02x.%d/graphics:fb%d", - pPci->domain, pPci->bus, pPci->dev, pPci->func, i); - fd = open(filename, O_RDONLY, 0); - } - if (fd >= 0) { - close(fd); - snprintf(filename, sizeof(filename), "/dev/fb%d", i); - - fd = open(filename, O_RDWR, 0); - if (fd != -1) { - if (ioctl(fd, FBIOGET_FSCREENINFO, (void *) &fix) != -1) { - if (namep) { - *namep = xnfalloc(16); - strncpy(*namep, fix.id, 16); - } - - return fd; - } - close(fd); - } - } - } - - if (namep) - *namep = NULL; - - xf86DrvMsg(-1, X_ERROR, "Unable to find a valid framebuffer device\n"); - return -1; -} - -static int -fbdev_open(int scrnIndex, const char *dev, char **namep) -{ - struct fb_fix_screeninfo fix; - int fd; - - /* try argument (from XF86Config) first */ - if (dev) { - fd = open(dev, O_RDWR, 0); - } - else { - /* second: environment variable */ - dev = getenv("FRAMEBUFFER"); - if ((NULL == dev) || ((fd = open(dev, O_RDWR, 0)) == -1)) { - /* last try: default device */ - dev = "/dev/fb0"; - fd = open(dev, O_RDWR, 0); - } - } - - if (fd == -1) { - xf86DrvMsg(scrnIndex, X_ERROR, "open %s: %s\n", dev, strerror(errno)); - return -1; - } - - /* only touch non-PCI devices on this path */ - { - char buf[PATH_MAX] = {0}; - char *sysfs_path = NULL; - char *node = strrchr(dev, '/') + 1; - - if (asprintf(&sysfs_path, "/sys/class/graphics/%s", node) < 0 || - readlink(sysfs_path, buf, sizeof(buf) - 1) < 0 || - strstr(buf, "devices/pci")) { - free(sysfs_path); - close(fd); - return -1; - } - free(sysfs_path); - } - - if (namep) { - if (-1 == ioctl(fd, FBIOGET_FSCREENINFO, (void *) (&fix))) { - *namep = NULL; - xf86DrvMsg(scrnIndex, X_ERROR, - "FBIOGET_FSCREENINFO: %s\n", strerror(errno)); - return -1; - } - else { - *namep = xnfalloc(16); - strncpy(*namep, fix.id, 16); - } - } - return fd; -} - -/* -------------------------------------------------------------------- */ - -Bool -fbdevHWProbe(struct pci_device *pPci, char *device, char **namep) -{ - int fd; - - if (pPci) - fd = fbdev_open_pci(pPci, namep); - else - fd = fbdev_open(-1, device, namep); - - if (-1 == fd) - return FALSE; - close(fd); - return TRUE; -} - -Bool -fbdevHWInit(ScrnInfoPtr pScrn, struct pci_device *pPci, char *device) -{ - fbdevHWPtr fPtr; - - fbdevHWGetRec(pScrn); - fPtr = FBDEVHWPTR(pScrn); - - /* open device */ - if (pPci) - fPtr->fd = fbdev_open_pci(pPci, NULL); - else - fPtr->fd = fbdev_open(pScrn->scrnIndex, device, NULL); - if (-1 == fPtr->fd) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "Failed to open framebuffer device, consult warnings" - " and/or errors above for possible reasons\n" - "\t(you may have to look at the server log to see" - " warnings)\n"); - return FALSE; - } - - /* get current fb device settings */ - if (-1 == ioctl(fPtr->fd, FBIOGET_FSCREENINFO, (void *) (&fPtr->fix))) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "ioctl FBIOGET_FSCREENINFO: %s\n", strerror(errno)); - return FALSE; - } - if (-1 == ioctl(fPtr->fd, FBIOGET_VSCREENINFO, (void *) (&fPtr->var))) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno)); - return FALSE; - } - - /* we can use the current settings as "buildin mode" */ - fbdev2xfree_timing(&fPtr->var, &fPtr->buildin); - fPtr->buildin.name = "current"; - fPtr->buildin.next = &fPtr->buildin; - fPtr->buildin.prev = &fPtr->buildin; - fPtr->buildin.type |= M_T_BUILTIN; - - return TRUE; -} - -char * -fbdevHWGetName(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - return fPtr->fix.id; -} - -int -fbdevHWGetDepth(ScrnInfoPtr pScrn, int *fbbpp) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - if (fbbpp) - *fbbpp = fPtr->var.bits_per_pixel; - - if (fPtr->fix.visual == FB_VISUAL_TRUECOLOR || - fPtr->fix.visual == FB_VISUAL_DIRECTCOLOR) - return fPtr->var.red.length + fPtr->var.green.length + - fPtr->var.blue.length; - else - return fPtr->var.bits_per_pixel; -} - -int -fbdevHWGetLineLength(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - if (fPtr->fix.line_length) - return fPtr->fix.line_length; - else - return fPtr->var.xres_virtual * fPtr->var.bits_per_pixel / 8; -} - -int -fbdevHWGetType(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - return fPtr->fix.type; -} - -int -fbdevHWGetVidmem(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - return fPtr->fix.smem_len; -} - -static Bool -fbdevHWSetMode(ScrnInfoPtr pScrn, DisplayModePtr mode, Bool check) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - struct fb_var_screeninfo req_var = fPtr->var, set_var; - - xfree2fbdev_fblayout(pScrn, &req_var); - xfree2fbdev_timing(mode, &req_var); - -#ifdef DEBUG - print_xfree_mode("init", mode); - print_fbdev_mode("init", &req_var); -#endif - - set_var = req_var; - - if (check) - set_var.activate = FB_ACTIVATE_TEST; - - if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *) (&set_var))) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "FBIOPUT_VSCREENINFO: %s\n", strerror(errno)); - return FALSE; - } - - if (!fbdev_modes_equal(&set_var, &req_var)) { - if (!check) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "FBIOPUT_VSCREENINFO succeeded but modified " "mode\n"); -#ifdef DEBUG - print_fbdev_mode("returned", &set_var); -#endif - return FALSE; - } - - if (!check) - fPtr->var = set_var; - - return TRUE; -} - -void -fbdevHWSetVideoModes(ScrnInfoPtr pScrn) -{ - const char **modename; - DisplayModePtr mode, this, last = pScrn->modes; - - if (NULL == pScrn->display->modes) - return; - - pScrn->virtualX = pScrn->display->virtualX; - pScrn->virtualY = pScrn->display->virtualY; - - for (modename = pScrn->display->modes; *modename != NULL; modename++) { - for (mode = pScrn->monitor->Modes; mode != NULL; mode = mode->next) { - if (0 == strcmp(mode->name, *modename)) { - if (fbdevHWSetMode(pScrn, mode, TRUE)) - break; - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "\tmode \"%s\" test failed\n", *modename); - } - } - - if (NULL == mode) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "\tmode \"%s\" not found\n", *modename); - continue; - } - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "\tmode \"%s\" ok\n", *modename); - - if (pScrn->virtualX < mode->HDisplay) - pScrn->virtualX = mode->HDisplay; - if (pScrn->virtualY < mode->VDisplay) - pScrn->virtualY = mode->VDisplay; - - if (NULL == pScrn->modes) { - this = pScrn->modes = xf86DuplicateMode(mode); - this->next = this; - this->prev = this; - } - else { - this = xf86DuplicateMode(mode); - this->next = pScrn->modes; - this->prev = last; - last->next = this; - pScrn->modes->prev = this; - } - last = this; - } -} - -DisplayModePtr -fbdevHWGetBuildinMode(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - return &fPtr->buildin; -} - -void -fbdevHWUseBuildinMode(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - pScrn->modes = &fPtr->buildin; - pScrn->virtualX = pScrn->display->virtualX; - pScrn->virtualY = pScrn->display->virtualY; - if (pScrn->virtualX < fPtr->buildin.HDisplay) - pScrn->virtualX = fPtr->buildin.HDisplay; - if (pScrn->virtualY < fPtr->buildin.VDisplay) - pScrn->virtualY = fPtr->buildin.VDisplay; -} - -/* -------------------------------------------------------------------- */ - -static void -calculateFbmem_len(fbdevHWPtr fPtr) -{ - fPtr->fboff = (unsigned long) fPtr->fix.smem_start & ~PAGE_MASK; - fPtr->fbmem_len = (fPtr->fboff + fPtr->fix.smem_len + ~PAGE_MASK) & - PAGE_MASK; -} - -void * -fbdevHWMapVidmem(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - if (NULL == fPtr->fbmem) { - calculateFbmem_len(fPtr); - fPtr->fbmem = mmap(NULL, fPtr->fbmem_len, PROT_READ | PROT_WRITE, - MAP_SHARED, fPtr->fd, 0); - if (-1 == (long) fPtr->fbmem) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "mmap fbmem: %s\n", strerror(errno)); - fPtr->fbmem = NULL; - } - else { - /* Perhaps we'd better add fboff to fbmem and return 0 in - fbdevHWLinearOffset()? Of course we then need to mask - fPtr->fbmem with PAGE_MASK in fbdevHWUnmapVidmem() as - well. [geert] */ - } - } - pScrn->memPhysBase = - (unsigned long) fPtr->fix.smem_start & (unsigned long) (PAGE_MASK); - pScrn->fbOffset = - (unsigned long) fPtr->fix.smem_start & (unsigned long) (~PAGE_MASK); - return fPtr->fbmem; -} - -int -fbdevHWLinearOffset(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - return fPtr->fboff; -} - -Bool -fbdevHWUnmapVidmem(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - if (NULL != fPtr->fbmem) { - if (-1 == munmap(fPtr->fbmem, fPtr->fbmem_len)) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "munmap fbmem: %s\n", strerror(errno)); - fPtr->fbmem = NULL; - } - return TRUE; -} - -void * -fbdevHWMapMMIO(ScrnInfoPtr pScrn) -{ - unsigned int mmio_off; - - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - if (NULL == fPtr->mmio) { - /* tell the kernel not to use accels to speed up console scrolling */ - fPtr->var.accel_flags = 0; - if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *) (&fPtr->var))) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "FBIOPUT_VSCREENINFO: %s\n", strerror(errno)); - return FALSE; - } - mmio_off = (unsigned long) fPtr->fix.mmio_start & ~PAGE_MASK; - fPtr->mmio_len = (mmio_off + fPtr->fix.mmio_len + ~PAGE_MASK) & - PAGE_MASK; - if (NULL == fPtr->fbmem) - calculateFbmem_len(fPtr); - fPtr->mmio = mmap(NULL, fPtr->mmio_len, PROT_READ | PROT_WRITE, - MAP_SHARED, fPtr->fd, fPtr->fbmem_len); - if (-1 == (long) fPtr->mmio) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "mmap mmio: %s\n", strerror(errno)); - fPtr->mmio = NULL; - } - else - fPtr->mmio += mmio_off; - } - return fPtr->mmio; -} - -Bool -fbdevHWUnmapMMIO(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - if (NULL != fPtr->mmio) { - if (-1 == - munmap((void *) ((unsigned long) fPtr->mmio & PAGE_MASK), - fPtr->mmio_len)) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "munmap mmio: %s\n", - strerror(errno)); - fPtr->mmio = NULL; - /* FIXME: restore var.accel_flags [geert] */ - } - return TRUE; -} - -/* -------------------------------------------------------------------- */ - -Bool -fbdevHWModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - pScrn->vtSema = TRUE; - - /* set */ - if (!fbdevHWSetMode(pScrn, mode, FALSE)) - return FALSE; - - /* read back */ - if (0 != ioctl(fPtr->fd, FBIOGET_FSCREENINFO, (void *) (&fPtr->fix))) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "FBIOGET_FSCREENINFO: %s\n", strerror(errno)); - return FALSE; - } - if (0 != ioctl(fPtr->fd, FBIOGET_VSCREENINFO, (void *) (&fPtr->var))) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "FBIOGET_VSCREENINFO: %s\n", strerror(errno)); - return FALSE; - } - - if (pScrn->defaultVisual == TrueColor || - pScrn->defaultVisual == DirectColor) { - /* XXX: This is a hack, but it should be a NOP for all the setups that - * worked before and actually seems to fix some others... - */ - pScrn->offset.red = fPtr->var.red.offset; - pScrn->offset.green = fPtr->var.green.offset; - pScrn->offset.blue = fPtr->var.blue.offset; - pScrn->mask.red = - ((1 << fPtr->var.red.length) - 1) << fPtr->var.red.offset; - pScrn->mask.green = - ((1 << fPtr->var.green.length) - 1) << fPtr->var.green.offset; - pScrn->mask.blue = - ((1 << fPtr->var.blue.length) - 1) << fPtr->var.blue.offset; - } - - return TRUE; -} - -/* -------------------------------------------------------------------- */ -/* video mode save/restore */ -void -fbdevHWSave(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - if (0 != ioctl(fPtr->fd, FBIOGET_VSCREENINFO, (void *) (&fPtr->saved_var))) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "FBIOGET_VSCREENINFO: %s\n", strerror(errno)); -} - -void -fbdevHWRestore(ScrnInfoPtr pScrn) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *) (&fPtr->saved_var))) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "FBIOPUT_VSCREENINFO: %s\n", strerror(errno)); -} - -/* -------------------------------------------------------------------- */ -/* callback for xf86HandleColormaps */ - -void -fbdevHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, - LOCO * colors, VisualPtr pVisual) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - struct fb_cmap cmap; - unsigned short red, green, blue; - int i; - - cmap.len = 1; - cmap.red = &red; - cmap.green = &green; - cmap.blue = &blue; - cmap.transp = NULL; - for (i = 0; i < numColors; i++) { - cmap.start = indices[i]; - red = (colors[indices[i]].red << 8) | colors[indices[i]].red; - green = (colors[indices[i]].green << 8) | colors[indices[i]].green; - blue = (colors[indices[i]].blue << 8) | colors[indices[i]].blue; - if (-1 == ioctl(fPtr->fd, FBIOPUTCMAP, (void *) &cmap)) - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "FBIOPUTCMAP: %s\n", strerror(errno)); - } -} - -/* -------------------------------------------------------------------- */ -/* these can be hooked directly into ScrnInfoRec */ - -ModeStatus -fbdevHWValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, Bool verbose, int flags) -{ - if (!fbdevHWSetMode(pScrn, mode, TRUE)) - return MODE_BAD; - - return MODE_OK; -} - -Bool -fbdevHWSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - if (!fbdevHWSetMode(pScrn, mode, FALSE)) - return FALSE; - - return TRUE; -} - -void -fbdevHWAdjustFrame(ScrnInfoPtr pScrn, int x, int y) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - - if (x < 0 || x + fPtr->var.xres > fPtr->var.xres_virtual || - y < 0 || y + fPtr->var.yres > fPtr->var.yres_virtual) - return; - - fPtr->var.xoffset = x; - fPtr->var.yoffset = y; - if (-1 == ioctl(fPtr->fd, FBIOPAN_DISPLAY, (void *) &fPtr->var)) - xf86DrvMsgVerb(pScrn->scrnIndex, X_WARNING, 5, - "FBIOPAN_DISPLAY: %s\n", strerror(errno)); -} - -Bool -fbdevHWEnterVT(ScrnInfoPtr pScrn) -{ - if (!fbdevHWModeInit(pScrn, pScrn->currentMode)) - return FALSE; - fbdevHWAdjustFrame(pScrn, pScrn->frameX0, pScrn->frameY0); - return TRUE; -} - -void -fbdevHWLeaveVT(ScrnInfoPtr pScrn) -{ - fbdevHWRestore(pScrn); -} - -void -fbdevHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags) -{ - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - unsigned long fbmode; - - if (!pScrn->vtSema) - return; - - if (fPtr->unsupported_ioctls & (1 << FBIOBLANK_UNSUPPORTED)) - return; - - switch (mode) { - case DPMSModeOn: - fbmode = 0; - break; - case DPMSModeStandby: - fbmode = 2; - break; - case DPMSModeSuspend: - fbmode = 3; - break; - case DPMSModeOff: - fbmode = 4; - break; - default: - return; - } - -RETRY: - if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *) fbmode)) { - switch (errno) { - case EAGAIN: - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "FBIOBLANK: %s\n", strerror(errno)); - break; - case EINTR: - case ERESTART: - goto RETRY; - default: - fPtr->unsupported_ioctls |= (1 << FBIOBLANK_UNSUPPORTED); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "FBIOBLANK: %s (Screen blanking not supported " - "by kernel - disabling)\n", strerror(errno)); - } - } -} - -Bool -fbdevHWSaveScreen(ScreenPtr pScreen, int mode) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - fbdevHWPtr fPtr = FBDEVHWPTR(pScrn); - unsigned long unblank; - - if (!pScrn->vtSema) - return TRUE; - - if (fPtr->unsupported_ioctls & (1 << FBIOBLANK_UNSUPPORTED)) - return FALSE; - - unblank = xf86IsUnblank(mode); - -RETRY: - if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *) (1 - unblank))) { - switch (errno) { - case EAGAIN: - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "FBIOBLANK: %s\n", strerror(errno)); - break; - case EINTR: - case ERESTART: - goto RETRY; - default: - fPtr->unsupported_ioctls |= (1 << FBIOBLANK_UNSUPPORTED); - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "FBIOBLANK: %s (Screen blanking not supported " - "by kernel - disabling)\n", strerror(errno)); - } - return FALSE; - } - - return TRUE; -} - -xf86SwitchModeProc * -fbdevHWSwitchModeWeak(void) -{ - return fbdevHWSwitchMode; -} - -xf86AdjustFrameProc * -fbdevHWAdjustFrameWeak(void) -{ - return fbdevHWAdjustFrame; -} - -xf86EnterVTProc * -fbdevHWEnterVTWeak(void) -{ - return fbdevHWEnterVT; -} - -xf86LeaveVTProc * -fbdevHWLeaveVTWeak(void) -{ - return fbdevHWLeaveVT; -} - -xf86ValidModeProc * -fbdevHWValidModeWeak(void) -{ - return fbdevHWValidMode; -} - -xf86DPMSSetProc * -fbdevHWDPMSSetWeak(void) -{ - return fbdevHWDPMSSet; -} - -xf86LoadPaletteProc * -fbdevHWLoadPaletteWeak(void) -{ - return fbdevHWLoadPalette; -} - -SaveScreenProcPtr -fbdevHWSaveScreenWeak(void) -{ - return fbdevHWSaveScreen; -} diff --git a/hw/xfree86/fbdevhw/fbdevhw.h b/hw/xfree86/fbdevhw/fbdevhw.h deleted file mode 100644 index 4984ccf89..000000000 --- a/hw/xfree86/fbdevhw/fbdevhw.h +++ /dev/null @@ -1,66 +0,0 @@ - -#ifndef _FBDEVHW_H_ -#define _FBDEVHW_H_ - -#include "xf86str.h" -#include "colormapst.h" - -#define FBDEVHW_PACKED_PIXELS 0 /* Packed Pixels */ -#define FBDEVHW_PLANES 1 /* Non interleaved planes */ -#define FBDEVHW_INTERLEAVED_PLANES 2 /* Interleaved planes */ -#define FBDEVHW_TEXT 3 /* Text/attributes */ -#define FBDEVHW_VGA_PLANES 4 /* EGA/VGA planes */ - -extern _X_EXPORT Bool fbdevHWGetRec(ScrnInfoPtr pScrn); -extern _X_EXPORT void fbdevHWFreeRec(ScrnInfoPtr pScrn); - -extern _X_EXPORT int fbdevHWGetFD(ScrnInfoPtr pScrn); - -extern _X_EXPORT Bool fbdevHWProbe(struct pci_device *pPci, char *device, - char **namep); -extern _X_EXPORT Bool fbdevHWInit(ScrnInfoPtr pScrn, struct pci_device *pPci, - char *device); - -extern _X_EXPORT char *fbdevHWGetName(ScrnInfoPtr pScrn); -extern _X_EXPORT int fbdevHWGetDepth(ScrnInfoPtr pScrn, int *fbbpp); -extern _X_EXPORT int fbdevHWGetLineLength(ScrnInfoPtr pScrn); -extern _X_EXPORT int fbdevHWGetType(ScrnInfoPtr pScrn); -extern _X_EXPORT int fbdevHWGetVidmem(ScrnInfoPtr pScrn); - -extern _X_EXPORT void *fbdevHWMapVidmem(ScrnInfoPtr pScrn); -extern _X_EXPORT int fbdevHWLinearOffset(ScrnInfoPtr pScrn); -extern _X_EXPORT Bool fbdevHWUnmapVidmem(ScrnInfoPtr pScrn); -extern _X_EXPORT void *fbdevHWMapMMIO(ScrnInfoPtr pScrn); -extern _X_EXPORT Bool fbdevHWUnmapMMIO(ScrnInfoPtr pScrn); - -extern _X_EXPORT void fbdevHWSetVideoModes(ScrnInfoPtr pScrn); -extern _X_EXPORT DisplayModePtr fbdevHWGetBuildinMode(ScrnInfoPtr pScrn); -extern _X_EXPORT void fbdevHWUseBuildinMode(ScrnInfoPtr pScrn); -extern _X_EXPORT Bool fbdevHWModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode); -extern _X_EXPORT void fbdevHWSave(ScrnInfoPtr pScrn); -extern _X_EXPORT void fbdevHWRestore(ScrnInfoPtr pScrn); - -extern _X_EXPORT void fbdevHWLoadPalette(ScrnInfoPtr pScrn, int numColors, - int *indices, LOCO * colors, - VisualPtr pVisual); - -extern _X_EXPORT ModeStatus fbdevHWValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, - Bool verbose, int flags); -extern _X_EXPORT Bool fbdevHWSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode); -extern _X_EXPORT void fbdevHWAdjustFrame(ScrnInfoPtr pScrn, int x, int y); -extern _X_EXPORT Bool fbdevHWEnterVT(ScrnInfoPtr pScrn); -extern _X_EXPORT void fbdevHWLeaveVT(ScrnInfoPtr pScrn); -extern _X_EXPORT void fbdevHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags); - -extern _X_EXPORT Bool fbdevHWSaveScreen(ScreenPtr pScreen, int mode); - -extern _X_EXPORT xf86SwitchModeProc *fbdevHWSwitchModeWeak(void); -extern _X_EXPORT xf86AdjustFrameProc *fbdevHWAdjustFrameWeak(void); -extern _X_EXPORT xf86EnterVTProc *fbdevHWEnterVTWeak(void); -extern _X_EXPORT xf86LeaveVTProc *fbdevHWLeaveVTWeak(void); -extern _X_EXPORT xf86ValidModeProc *fbdevHWValidModeWeak(void); -extern _X_EXPORT xf86DPMSSetProc *fbdevHWDPMSSetWeak(void); -extern _X_EXPORT xf86LoadPaletteProc *fbdevHWLoadPaletteWeak(void); -extern _X_EXPORT SaveScreenProcPtr fbdevHWSaveScreenWeak(void); - -#endif diff --git a/hw/xfree86/fbdevhw/fbdevhwstub.c b/hw/xfree86/fbdevhw/fbdevhwstub.c deleted file mode 100644 index 7d554e60a..000000000 --- a/hw/xfree86/fbdevhw/fbdevhwstub.c +++ /dev/null @@ -1,218 +0,0 @@ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86cmap.h" -#include "fbdevhw.h" - -/* Stubs for the static server on platforms that don't support fbdev */ - -Bool -fbdevHWGetRec(ScrnInfoPtr pScrn) -{ - return FALSE; -} - -void -fbdevHWFreeRec(ScrnInfoPtr pScrn) -{ -} - -Bool -fbdevHWProbe(struct pci_device *pPci, char *device, char **namep) -{ - return FALSE; -} - -Bool -fbdevHWInit(ScrnInfoPtr pScrn, struct pci_device *pPci, char *device) -{ - xf86Msg(X_ERROR, "fbdevhw is not available on this platform\n"); - return FALSE; -} - -char * -fbdevHWGetName(ScrnInfoPtr pScrn) -{ - return NULL; -} - -int -fbdevHWGetDepth(ScrnInfoPtr pScrn, int *fbbpp) -{ - return -1; -} - -int -fbdevHWGetLineLength(ScrnInfoPtr pScrn) -{ - return -1; /* Should cause something spectacular... */ -} - -int -fbdevHWGetType(ScrnInfoPtr pScrn) -{ - return -1; -} - -int -fbdevHWGetVidmem(ScrnInfoPtr pScrn) -{ - return -1; -} - -void -fbdevHWSetVideoModes(ScrnInfoPtr pScrn) -{ -} - -DisplayModePtr -fbdevHWGetBuildinMode(ScrnInfoPtr pScrn) -{ - return NULL; -} - -void -fbdevHWUseBuildinMode(ScrnInfoPtr pScrn) -{ -} - -void * -fbdevHWMapVidmem(ScrnInfoPtr pScrn) -{ - return NULL; -} - -int -fbdevHWLinearOffset(ScrnInfoPtr pScrn) -{ - return 0; -} - -Bool -fbdevHWUnmapVidmem(ScrnInfoPtr pScrn) -{ - return FALSE; -} - -void * -fbdevHWMapMMIO(ScrnInfoPtr pScrn) -{ - return NULL; -} - -Bool -fbdevHWUnmapMMIO(ScrnInfoPtr pScrn) -{ - return FALSE; -} - -Bool -fbdevHWModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - return FALSE; -} - -void -fbdevHWSave(ScrnInfoPtr pScrn) -{ -} - -void -fbdevHWRestore(ScrnInfoPtr pScrn) -{ -} - -void -fbdevHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, - LOCO * colors, VisualPtr pVisual) -{ -} - -ModeStatus -fbdevHWValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, Bool verbose, int flags) -{ - return MODE_ERROR; -} - -Bool -fbdevHWSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - return FALSE; -} - -void -fbdevHWAdjustFrame(ScrnInfoPtr pScrn, int x, int y) -{ -} - -Bool -fbdevHWEnterVT(ScrnInfoPtr pScrn) -{ - return FALSE; -} - -void -fbdevHWLeaveVT(ScrnInfoPtr pScrn) -{ -} - -void -fbdevHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags) -{ -} - -Bool -fbdevHWSaveScreen(ScreenPtr pScreen, int mode) -{ - return FALSE; -} - -xf86SwitchModeProc * -fbdevHWSwitchModeWeak(void) -{ - return fbdevHWSwitchMode; -} - -xf86AdjustFrameProc * -fbdevHWAdjustFrameWeak(void) -{ - return fbdevHWAdjustFrame; -} - -xf86EnterVTProc * -fbdevHWEnterVTWeak(void) -{ - return fbdevHWEnterVT; -} - -xf86LeaveVTProc * -fbdevHWLeaveVTWeak(void) -{ - return fbdevHWLeaveVT; -} - -xf86ValidModeProc * -fbdevHWValidModeWeak(void) -{ - return fbdevHWValidMode; -} - -xf86DPMSSetProc * -fbdevHWDPMSSetWeak(void) -{ - return fbdevHWDPMSSet; -} - -xf86LoadPaletteProc * -fbdevHWLoadPaletteWeak(void) -{ - return fbdevHWLoadPalette; -} - -SaveScreenProcPtr -fbdevHWSaveScreenWeak(void) -{ - return fbdevHWSaveScreen; -} diff --git a/hw/xfree86/fbdevhw/fbpriv.h b/hw/xfree86/fbdevhw/fbpriv.h deleted file mode 100644 index 8d224ae02..000000000 --- a/hw/xfree86/fbdevhw/fbpriv.h +++ /dev/null @@ -1,263 +0,0 @@ -/* - * copied from from linux kernel 2.2.4 - * removed internal stuff (#ifdef __KERNEL__) - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _LINUX_FB_H -#define _LINUX_FB_H - -#include - -/* Definitions of frame buffers */ - -#define FB_MAJOR 29 - -#define FB_MODES_SHIFT 5 /* 32 modes per framebuffer */ -#define FB_NUM_MINORS 256 /* 256 Minors */ -#define FB_MAX (FB_NUM_MINORS / (1 << FB_MODES_SHIFT)) -#define GET_FB_IDX(node) (MINOR(node) >> FB_MODES_SHIFT) - -/* ioctls - 0x46 is 'F' */ -#define FBIOGET_VSCREENINFO 0x4600 -#define FBIOPUT_VSCREENINFO 0x4601 -#define FBIOGET_FSCREENINFO 0x4602 -#define FBIOGETCMAP 0x4604 -#define FBIOPUTCMAP 0x4605 -#define FBIOPAN_DISPLAY 0x4606 -/* 0x4607-0x460B are defined below */ -/* #define FBIOGET_MONITORSPEC 0x460C */ -/* #define FBIOPUT_MONITORSPEC 0x460D */ -/* #define FBIOSWITCH_MONIBIT 0x460E */ -#define FBIOGET_CON2FBMAP 0x460F -#define FBIOPUT_CON2FBMAP 0x4610 -#define FBIOBLANK 0x4611 - -#define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */ -#define FB_TYPE_PLANES 1 /* Non interleaved planes */ -#define FB_TYPE_INTERLEAVED_PLANES 2 /* Interleaved planes */ -#define FB_TYPE_TEXT 3 /* Text/attributes */ - -#define FB_AUX_TEXT_MDA 0 /* Monochrome text */ -#define FB_AUX_TEXT_CGA 1 /* CGA/EGA/VGA Color text */ -#define FB_AUX_TEXT_S3_MMIO 2 /* S3 MMIO fasttext */ -#define FB_AUX_TEXT_MGA_STEP16 3 /* MGA Millenium I: text, attr, 14 reserved bytes */ -#define FB_AUX_TEXT_MGA_STEP8 4 /* other MGAs: text, attr, 6 reserved bytes */ - -#define FB_VISUAL_MONO01 0 /* Monochr. 1=Black 0=White */ -#define FB_VISUAL_MONO10 1 /* Monochr. 1=White 0=Black */ -#define FB_VISUAL_TRUECOLOR 2 /* True color */ -#define FB_VISUAL_PSEUDOCOLOR 3 /* Pseudo color (like atari) */ -#define FB_VISUAL_DIRECTCOLOR 4 /* Direct color */ -#define FB_VISUAL_STATIC_PSEUDOCOLOR 5 /* Pseudo color readonly */ - -#define FB_ACCEL_NONE 0 /* no hardware accelerator */ -#define FB_ACCEL_ATARIBLITT 1 /* Atari Blitter */ -#define FB_ACCEL_AMIGABLITT 2 /* Amiga Blitter */ -#define FB_ACCEL_S3_TRIO64 3 /* Cybervision64 (S3 Trio64) */ -#define FB_ACCEL_NCR_77C32BLT 4 /* RetinaZ3 (NCR 77C32BLT) */ -#define FB_ACCEL_S3_VIRGE 5 /* Cybervision64/3D (S3 ViRGE) */ -#define FB_ACCEL_ATI_MACH64GX 6 /* ATI Mach 64GX family */ -#define FB_ACCEL_DEC_TGA 7 /* DEC 21030 TGA */ -#define FB_ACCEL_ATI_MACH64CT 8 /* ATI Mach 64CT family */ -#define FB_ACCEL_ATI_MACH64VT 9 /* ATI Mach 64CT family VT class */ -#define FB_ACCEL_ATI_MACH64GT 10 /* ATI Mach 64CT family GT class */ -#define FB_ACCEL_SUN_CREATOR 11 /* Sun Creator/Creator3D */ -#define FB_ACCEL_SUN_CGSIX 12 /* Sun cg6 */ -#define FB_ACCEL_SUN_LEO 13 /* Sun leo/zx */ -#define FB_ACCEL_IMS_TWINTURBO 14 /* IMS Twin Turbo */ -#define FB_ACCEL_3DLABS_PERMEDIA2 15 /* 3Dlabs Permedia 2 */ -#define FB_ACCEL_MATROX_MGA2064W 16 /* Matrox MGA2064W (Millenium) */ -#define FB_ACCEL_MATROX_MGA1064SG 17 /* Matrox MGA1064SG (Mystique) */ -#define FB_ACCEL_MATROX_MGA2164W 18 /* Matrox MGA2164W (Millenium II) */ -#define FB_ACCEL_MATROX_MGA2164W_AGP 19 /* Matrox MGA2164W (Millenium II) */ -#define FB_ACCEL_MATROX_MGAG100 20 /* Matrox G100 (Productiva G100) */ -#define FB_ACCEL_MATROX_MGAG200 21 /* Matrox G200 (Myst, Mill, ...) */ -#define FB_ACCEL_SUN_CG14 22 /* Sun cgfourteen */ -#define FB_ACCEL_SUN_BWTWO 23 /* Sun bwtwo */ -#define FB_ACCEL_SUN_CGTHREE 24 /* Sun cgthree */ -#define FB_ACCEL_SUN_TCX 25 /* Sun tcx */ -#define FB_ACCEL_MATROX_MGAG400 26 /* Matrox G400 */ -#define FB_ACCEL_NV3 27 /* nVidia RIVA 128 */ -#define FB_ACCEL_NV4 28 /* nVidia RIVA TNT */ -#define FB_ACCEL_NV5 29 /* nVidia RIVA TNT2 */ -#define FB_ACCEL_CT_6555x 30 /* C&T 6555x */ -#define FB_ACCEL_3DFX_BANSHEE 31 /* 3Dfx Banshee */ -#define FB_ACCEL_ATI_RAGE128 32 /* ATI Rage128 family */ - -struct fb_fix_screeninfo { - char id[16]; /* identification string eg "TT Builtin" */ - char *smem_start; /* Start of frame buffer mem */ - /* (physical address) */ - __u32 smem_len; /* Length of frame buffer mem */ - __u32 type; /* see FB_TYPE_* */ - __u32 type_aux; /* Interleave for interleaved Planes */ - __u32 visual; /* see FB_VISUAL_* */ - __u16 xpanstep; /* zero if no hardware panning */ - __u16 ypanstep; /* zero if no hardware panning */ - __u16 ywrapstep; /* zero if no hardware ywrap */ - __u32 line_length; /* length of a line in bytes */ - char *mmio_start; /* Start of Memory Mapped I/O */ - /* (physical address) */ - __u32 mmio_len; /* Length of Memory Mapped I/O */ - __u32 accel; /* Type of acceleration available */ - __u16 reserved[3]; /* Reserved for future compatibility */ -}; - -/* Interpretation of offset for color fields: All offsets are from the right, - * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you - * can use the offset as right argument to <<). A pixel afterwards is a bit - * stream and is written to video memory as that unmodified. This implies - * big-endian byte order if bits_per_pixel is greater than 8. - */ -struct fb_bitfield { - __u32 offset; /* beginning of bitfield */ - __u32 length; /* length of bitfield */ - __u32 msb_right; /* != 0 : Most significant bit is */ - /* right */ -}; - -#define FB_NONSTD_HAM 1 /* Hold-And-Modify (HAM) */ - -#define FB_ACTIVATE_NOW 0 /* set values immediately (or vbl) */ -#define FB_ACTIVATE_NXTOPEN 1 /* activate on next open */ -#define FB_ACTIVATE_TEST 2 /* don't set, round up impossible */ -#define FB_ACTIVATE_MASK 15 - /* values */ -#define FB_ACTIVATE_VBL 16 /* activate values on next vbl */ -#define FB_CHANGE_CMAP_VBL 32 /* change colormap on vbl */ -#define FB_ACTIVATE_ALL 64 /* change all VCs on this fb */ - -#define FB_ACCELF_TEXT 1 /* text mode acceleration */ - -#define FB_SYNC_HOR_HIGH_ACT 1 /* horizontal sync high active */ -#define FB_SYNC_VERT_HIGH_ACT 2 /* vertical sync high active */ -#define FB_SYNC_EXT 4 /* external sync */ -#define FB_SYNC_COMP_HIGH_ACT 8 /* composite sync high active */ -#define FB_SYNC_BROADCAST 16 /* broadcast video timings */ - /* vtotal = 144d/288n/576i => PAL */ - /* vtotal = 121d/242n/484i => NTSC */ -#define FB_SYNC_ON_GREEN 32 /* sync on green */ - -#define FB_VMODE_NONINTERLACED 0 /* non interlaced */ -#define FB_VMODE_INTERLACED 1 /* interlaced */ -#define FB_VMODE_DOUBLE 2 /* double scan */ -#define FB_VMODE_MASK 255 - -#define FB_VMODE_YWRAP 256 /* ywrap instead of panning */ -#define FB_VMODE_SMOOTH_XPAN 512 /* smooth xpan possible (internally used) */ -#define FB_VMODE_CONUPDATE 512 /* don't update x/yoffset */ - -struct fb_var_screeninfo { - __u32 xres; /* visible resolution */ - __u32 yres; - __u32 xres_virtual; /* virtual resolution */ - __u32 yres_virtual; - __u32 xoffset; /* offset from virtual to visible */ - __u32 yoffset; /* resolution */ - - __u32 bits_per_pixel; /* guess what */ - __u32 grayscale; /* != 0 Graylevels instead of colors */ - - struct fb_bitfield red; /* bitfield in fb mem if true color, */ - struct fb_bitfield green; /* else only length is significant */ - struct fb_bitfield blue; - struct fb_bitfield transp; /* transparency */ - - __u32 nonstd; /* != 0 Non standard pixel format */ - - __u32 activate; /* see FB_ACTIVATE_* */ - - __u32 height; /* height of picture in mm */ - __u32 width; /* width of picture in mm */ - - __u32 accel_flags; /* acceleration flags (hints) */ - - /* Timing: All values in pixclocks, except pixclock (of course) */ - __u32 pixclock; /* pixel clock in ps (pico seconds) */ - __u32 left_margin; /* time from sync to picture */ - __u32 right_margin; /* time from picture to sync */ - __u32 upper_margin; /* time from sync to picture */ - __u32 lower_margin; - __u32 hsync_len; /* length of horizontal sync */ - __u32 vsync_len; /* length of vertical sync */ - __u32 sync; /* see FB_SYNC_* */ - __u32 vmode; /* see FB_VMODE_* */ - __u32 reserved[6]; /* Reserved for future compatibility */ -}; - -struct fb_cmap { - __u32 start; /* First entry */ - __u32 len; /* Number of entries */ - __u16 *red; /* Red values */ - __u16 *green; - __u16 *blue; - __u16 *transp; /* transparency, can be NULL */ -}; - -struct fb_con2fbmap { - __u32 console; - __u32 framebuffer; -}; - -struct fb_monspecs { - __u32 hfmin; /* hfreq lower limit (Hz) */ - __u32 hfmax; /* hfreq upper limit (Hz) */ - __u16 vfmin; /* vfreq lower limit (Hz) */ - __u16 vfmax; /* vfreq upper limit (Hz) */ - unsigned dpms:1; /* supports DPMS */ -}; - -#if 1 - -#define FBCMD_GET_CURRENTPAR 0xDEAD0005 -#define FBCMD_SET_CURRENTPAR 0xDEAD8005 - -#endif - -#if 1 /* Preliminary */ - - /* - * Hardware Cursor - */ - -#define FBIOGET_FCURSORINFO 0x4607 -#define FBIOGET_VCURSORINFO 0x4608 -#define FBIOPUT_VCURSORINFO 0x4609 -#define FBIOGET_CURSORSTATE 0x460A -#define FBIOPUT_CURSORSTATE 0x460B - -struct fb_fix_cursorinfo { - __u16 crsr_width; /* width and height of the cursor in */ - __u16 crsr_height; /* pixels (zero if no cursor) */ - __u16 crsr_xsize; /* cursor size in display pixels */ - __u16 crsr_ysize; - __u16 crsr_color1; /* colormap entry for cursor color1 */ - __u16 crsr_color2; /* colormap entry for cursor color2 */ -}; - -struct fb_var_cursorinfo { - __u16 width; - __u16 height; - __u16 xspot; - __u16 yspot; - __u8 data[1]; /* field with [height][width] */ -}; - -struct fb_cursorstate { - __s16 xoffset; - __s16 yoffset; - __u16 mode; -}; - -#define FB_CURSOR_OFF 0 -#define FB_CURSOR_ON 1 -#define FB_CURSOR_FLASH 2 - -#endif /* Preliminary */ - -#endif /* _LINUX_FB_H */ diff --git a/hw/xfree86/fbdevhw/man/fbdevhw.man b/hw/xfree86/fbdevhw/man/fbdevhw.man deleted file mode 100644 index f9e8aaf41..000000000 --- a/hw/xfree86/fbdevhw/man/fbdevhw.man +++ /dev/null @@ -1,22 +0,0 @@ -.\" $XFree86: xc/programs/Xserver/hw/xfree86/fbdevhw/fbdevhw.man,v 1.1 2001/01/24 00:06:34 dawes Exp $ -.TH FBDEVHW @drivermansuffix@ @vendorversion@ -.SH NAME -fbdevhw \- os-specific submodule for framebuffer device access -.SH DESCRIPTION -.B fbdevhw -provides functions for talking to a framebuffer device. It is -os-specific. It is a submodule used by other video drivers. -A -.B fbdevhw -module is currently available for linux framebuffer devices. -.PP -fbdev(@drivermansuffix@) is a non-accelerated driver which runs on top of the -fbdevhw module. fbdevhw can be used by other drivers too, this -is usually activated with `Option "UseFBDev"' in the device section. -.SH "SEE ALSO" -Xorg(@appmansuffix@), xorg.conf(@filemansuffix@), -xorgconfig(@appmansuffix@), Xserver(@appmansuffix@), X(@miscmansuffix@), -fbdev(@drivermansuffix@) -.SH AUTHORS -Authors include: Gerd Knorr, based on the XF68_FBDev Server code -(Martin Schaller, Geert Uytterhoeven). diff --git a/hw/xfree86/fbdevhw/meson.build b/hw/xfree86/fbdevhw/meson.build deleted file mode 100644 index f3146f3c9..000000000 --- a/hw/xfree86/fbdevhw/meson.build +++ /dev/null @@ -1,23 +0,0 @@ -if host_machine.system() == 'linux' - srcs_fbdevhw = 'fbdevhw.c' -else - srcs_fbdevhw = 'fbdevhwstub.c' -endif - -shared_module('fbdevhw', - srcs_fbdevhw, - include_directories: [ inc, xorg_inc ], - dependencies: common_dep, - c_args: xorg_c_args, - install: true, - install_dir: module_dir, - link_with: e, -) - -install_data('fbdevhw.h', install_dir: xorgsdkdir) - -install_man(configure_file( - input: 'man/fbdevhw.man', - output: 'fbdevhw.4', - configuration: manpage_config, -)) diff --git a/hw/xfree86/glamor_egl/glamor_xf86_xv.c b/hw/xfree86/glamor_egl/glamor_xf86_xv.c deleted file mode 100644 index 5f8bb8f15..000000000 --- a/hw/xfree86/glamor_egl/glamor_xf86_xv.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright © 2013 Red Hat - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - * - * Authors: - * Dave Airlie - * - * some code is derived from the xf86-video-ati radeon driver, mainly - * the calculations. - */ - -/** @file glamor_xf86_xv.c - * - * This implements the XF86 XV interface, and calls into glamor core - * for its support of the suspiciously similar XF86 and Kdrive - * device-dependent XV interfaces. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#define GLAMOR_FOR_XORG -#include "glamor_priv.h" - -#include -#include "fourcc.h" - -#define NUM_FORMATS 4 - -static XF86VideoFormatRec Formats[NUM_FORMATS] = { - {15, TrueColor}, {16, TrueColor}, {24, TrueColor}, {30, TrueColor} -}; - -static void -glamor_xf86_xv_stop_video(ScrnInfoPtr pScrn, void *data, Bool cleanup) -{ - if (!cleanup) - return; - - glamor_xv_stop_video(data); -} - -static int -glamor_xf86_xv_set_port_attribute(ScrnInfoPtr pScrn, - Atom attribute, INT32 value, void *data) -{ - return glamor_xv_set_port_attribute(data, attribute, value); -} - -static int -glamor_xf86_xv_get_port_attribute(ScrnInfoPtr pScrn, - Atom attribute, INT32 *value, void *data) -{ - return glamor_xv_get_port_attribute(data, attribute, value); -} - -static void -glamor_xf86_xv_query_best_size(ScrnInfoPtr pScrn, - Bool motion, - short vid_w, short vid_h, - short drw_w, short drw_h, - unsigned int *p_w, unsigned int *p_h, void *data) -{ - *p_w = drw_w; - *p_h = drw_h; -} - -static int -glamor_xf86_xv_query_image_attributes(ScrnInfoPtr pScrn, - int id, - unsigned short *w, unsigned short *h, - int *pitches, int *offsets) -{ - return glamor_xv_query_image_attributes(id, w, h, pitches, offsets); -} - -static int -glamor_xf86_xv_put_image(ScrnInfoPtr pScrn, - short src_x, short src_y, - short drw_x, short drw_y, - short src_w, short src_h, - short drw_w, short drw_h, - int id, - unsigned char *buf, - short width, - short height, - Bool sync, - RegionPtr clipBoxes, void *data, DrawablePtr pDrawable) -{ - return glamor_xv_put_image(data, pDrawable, - src_x, src_y, - drw_x, drw_y, - src_w, src_h, - drw_w, drw_h, - id, buf, width, height, sync, clipBoxes); -} - -static XF86VideoEncodingRec DummyEncodingGLAMOR[1] = { - { - 0, - "XV_IMAGE", - 8192, 8192, - {1, 1} - } -}; - -XF86VideoAdaptorPtr -glamor_xv_init(ScreenPtr screen, int num_texture_ports) -{ - glamor_port_private *port_priv; - XF86VideoAdaptorPtr adapt; - int i; - - glamor_xv_core_init(screen); - - adapt = calloc(1, sizeof(XF86VideoAdaptorRec) + num_texture_ports * - (sizeof(glamor_port_private) + sizeof(DevUnion))); - if (adapt == NULL) - return NULL; - - adapt->type = XvWindowMask | XvInputMask | XvImageMask; - adapt->flags = 0; - adapt->name = "GLAMOR Textured Video"; - adapt->nEncodings = 1; - adapt->pEncodings = DummyEncodingGLAMOR; - - adapt->nFormats = NUM_FORMATS; - adapt->pFormats = Formats; - adapt->nPorts = num_texture_ports; - adapt->pPortPrivates = (DevUnion *) (&adapt[1]); - - adapt->pAttributes = glamor_xv_attributes; - adapt->nAttributes = glamor_xv_num_attributes; - - port_priv = - (glamor_port_private *) (&adapt->pPortPrivates[num_texture_ports]); - adapt->pImages = glamor_xv_images; - adapt->nImages = glamor_xv_num_images; - adapt->PutVideo = NULL; - adapt->PutStill = NULL; - adapt->GetVideo = NULL; - adapt->GetStill = NULL; - adapt->StopVideo = glamor_xf86_xv_stop_video; - adapt->SetPortAttribute = glamor_xf86_xv_set_port_attribute; - adapt->GetPortAttribute = glamor_xf86_xv_get_port_attribute; - adapt->QueryBestSize = glamor_xf86_xv_query_best_size; - adapt->PutImage = glamor_xf86_xv_put_image; - adapt->ReputImage = NULL; - adapt->QueryImageAttributes = glamor_xf86_xv_query_image_attributes; - - for (i = 0; i < num_texture_ports; i++) { - glamor_port_private *pPriv = &port_priv[i]; - - pPriv->brightness = 0; - pPriv->contrast = 0; - pPriv->saturation = 0; - pPriv->hue = 0; - pPriv->gamma = 1000; - pPriv->transform_index = 0; - - REGION_NULL(pScreen, &pPriv->clip); - - adapt->pPortPrivates[i].ptr = (void *) (pPriv); - } - return adapt; -} diff --git a/hw/xfree86/glamor_egl/meson.build b/hw/xfree86/glamor_egl/meson.build deleted file mode 100644 index 7eae05812..000000000 --- a/hw/xfree86/glamor_egl/meson.build +++ /dev/null @@ -1,22 +0,0 @@ -glamoregl_src = [ - '../../../glamor/glamor_egl.c', - '../../../glamor/glamor_eglmodule.c', - 'glamor_xf86_xv.c', -] - -shared_module( - 'glamoregl', - glamoregl_src, - - include_directories: [inc, xorg_inc], - c_args: xorg_c_args, - dependencies: [ - common_dep, - dependency('libdrm', version: '>= 2.4.46'), - gbm_dep, - ], - link_with: glamor, - - install: true, - install_dir: module_dir, -) diff --git a/hw/xfree86/i2c/i2c_def.h b/hw/xfree86/i2c/i2c_def.h deleted file mode 100644 index 140a071d6..000000000 --- a/hw/xfree86/i2c/i2c_def.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __I2C_DEF_H__ -#define __I2C_DEF_H__ - -#include "xf86i2c.h" - -#endif diff --git a/hw/xfree86/i2c/meson.build b/hw/xfree86/i2c/meson.build deleted file mode 100644 index d22860e9e..000000000 --- a/hw/xfree86/i2c/meson.build +++ /dev/null @@ -1,12 +0,0 @@ -srcs_xorg_i2c = [ - 'xf86i2c.c' -] - -xorg_i2c = static_library('xorg_i2c', - srcs_xorg_i2c, - include_directories: [inc, xorg_inc], - dependencies: common_dep, - c_args: xorg_c_args, -) - -install_data(['xf86i2c.h', 'i2c_def.h'], install_dir: xorgsdkdir) diff --git a/hw/xfree86/i2c/xf86i2c.c b/hw/xfree86/i2c/xf86i2c.c deleted file mode 100644 index 59733b032..000000000 --- a/hw/xfree86/i2c/xf86i2c.c +++ /dev/null @@ -1,880 +0,0 @@ -/* - * Copyright (C) 1998 Itai Nahshon, Michael Schimek - * - * The original code was derived from and inspired by - * the I2C driver from the Linux kernel. - * (c) 1998 Gerd Knorr - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#include "misc.h" -#include "xf86.h" -#include "xf86_OSproc.h" - -#include -#include -#include -#include "scrnintstr.h" -#include "regionstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "validate.h" -#include "resource.h" -#include "gcstruct.h" -#include "dixstruct.h" - -#include "xf86i2c.h" - -#define I2C_TIMEOUT(x) /*(x)*/ /* Report timeouts */ -#define I2C_TRACE(x) /*(x)*/ /* Report progress */ - -/* This is the default I2CUDelay function if not supplied by the driver. - * High level I2C interfaces implementing the bus protocol in hardware - * should supply this function too. - * - * Delay execution at least usec microseconds. - * All values 0 to 1e6 inclusive must be expected. - */ - -static void -I2CUDelay(I2CBusPtr b, int usec) -{ - struct timeval begin, cur; - long d_secs, d_usecs; - long diff; - - if (usec > 0) { - X_GETTIMEOFDAY(&begin); - do { - /* It would be nice to use {xf86}usleep, - * but usleep (1) takes >10000 usec ! - */ - X_GETTIMEOFDAY(&cur); - d_secs = (cur.tv_sec - begin.tv_sec); - d_usecs = (cur.tv_usec - begin.tv_usec); - diff = d_secs * 1000000 + d_usecs; - } while (diff >= 0 && diff < (usec + 1)); - } -} - -/* Most drivers will register just with GetBits/PutBits functions. - * The following functions implement a software I2C protocol - * by using the promitive functions given by the driver. - * ================================================================ - * - * It is assumed that there is just one master on the I2C bus, therefore - * there is no explicit test for conflits. - */ - -#define RISEFALLTIME 2 /* usec, actually 300 to 1000 ns according to the i2c specs */ - -/* Some devices will hold SCL low to slow down the bus or until - * ready for transmission. - * - * This condition will be noticed when the master tries to raise - * the SCL line. You can set the timeout to zero if the slave device - * does not support this clock synchronization. - */ - -static Bool -I2CRaiseSCL(I2CBusPtr b, int sda, int timeout) -{ - int i, scl; - - b->I2CPutBits(b, 1, sda); - b->I2CUDelay(b, b->RiseFallTime); - - for (i = timeout; i > 0; i -= b->RiseFallTime) { - b->I2CGetBits(b, &scl, &sda); - if (scl) - break; - b->I2CUDelay(b, b->RiseFallTime); - } - - if (i <= 0) { - I2C_TIMEOUT(ErrorF - ("[I2CRaiseSCL(<%s>, %d, %d) timeout]", b->BusName, sda, - timeout)); - return FALSE; - } - - return TRUE; -} - -/* Send a start signal on the I2C bus. The start signal notifies - * devices that a new transaction is initiated by the bus master. - * - * The start signal is always followed by a slave address. - * Slave addresses are 8+ bits. The first 7 bits identify the - * device and the last bit signals if this is a read (1) or - * write (0) operation. - * - * There may be more than one start signal on one transaction. - * This happens for example on some devices that allow reading - * of registers. First send a start bit followed by the device - * address (with the last bit 0) and the register number. Then send - * a new start bit with the device address (with the last bit 1) - * and then read the value from the device. - * - * Note this is function does not implement a multiple master - * arbitration procedure. - */ - -static Bool -I2CStart(I2CBusPtr b, int timeout) -{ - if (!I2CRaiseSCL(b, 1, timeout)) - return FALSE; - - b->I2CPutBits(b, 1, 0); - b->I2CUDelay(b, b->HoldTime); - b->I2CPutBits(b, 0, 0); - b->I2CUDelay(b, b->HoldTime); - - I2C_TRACE(ErrorF("\ni2c: <")); - - return TRUE; -} - -/* This is the default I2CStop function if not supplied by the driver. - * - * Signal devices on the I2C bus that a transaction on the - * bus has finished. There may be more than one start signal - * on a transaction but only one stop signal. - */ - -static void -I2CStop(I2CDevPtr d) -{ - I2CBusPtr b = d->pI2CBus; - - b->I2CPutBits(b, 0, 0); - b->I2CUDelay(b, b->RiseFallTime); - - b->I2CPutBits(b, 1, 0); - b->I2CUDelay(b, b->HoldTime); - b->I2CPutBits(b, 1, 1); - b->I2CUDelay(b, b->HoldTime); - - I2C_TRACE(ErrorF(">\n")); -} - -/* Write/Read a single bit to/from a device. - * Return FALSE if a timeout occurs. - */ - -static Bool -I2CWriteBit(I2CBusPtr b, int sda, int timeout) -{ - Bool r; - - b->I2CPutBits(b, 0, sda); - b->I2CUDelay(b, b->RiseFallTime); - - r = I2CRaiseSCL(b, sda, timeout); - b->I2CUDelay(b, b->HoldTime); - - b->I2CPutBits(b, 0, sda); - b->I2CUDelay(b, b->HoldTime); - - return r; -} - -static Bool -I2CReadBit(I2CBusPtr b, int *psda, int timeout) -{ - Bool r; - int scl; - - r = I2CRaiseSCL(b, 1, timeout); - b->I2CUDelay(b, b->HoldTime); - - b->I2CGetBits(b, &scl, psda); - - b->I2CPutBits(b, 0, 1); - b->I2CUDelay(b, b->HoldTime); - - return r; -} - -/* This is the default I2CPutByte function if not supplied by the driver. - * - * A single byte is sent to the device. - * The function returns FALSE if a timeout occurs, you should send - * a stop condition afterwards to reset the bus. - * - * A timeout occurs, - * if the slave pulls SCL to slow down the bus more than ByteTimeout usecs, - * or slows down the bus for more than BitTimeout usecs for each bit, - * or does not send an ACK bit (0) to acknowledge the transmission within - * AcknTimeout usecs, but a NACK (1) bit. - * - * AcknTimeout must be at least b->HoldTime, the other timeouts can be - * zero according to the comment on I2CRaiseSCL. - */ - -static Bool -I2CPutByte(I2CDevPtr d, I2CByte data) -{ - Bool r; - int i, scl, sda; - I2CBusPtr b = d->pI2CBus; - - if (!I2CWriteBit(b, (data >> 7) & 1, d->ByteTimeout)) - return FALSE; - - for (i = 6; i >= 0; i--) - if (!I2CWriteBit(b, (data >> i) & 1, d->BitTimeout)) - return FALSE; - - b->I2CPutBits(b, 0, 1); - b->I2CUDelay(b, b->RiseFallTime); - - r = I2CRaiseSCL(b, 1, b->HoldTime); - - if (r) { - for (i = d->AcknTimeout; i > 0; i -= b->HoldTime) { - b->I2CUDelay(b, b->HoldTime); - b->I2CGetBits(b, &scl, &sda); - if (sda == 0) - break; - } - - if (i <= 0) { - I2C_TIMEOUT(ErrorF("[I2CPutByte(<%s>, 0x%02x, %d, %d, %d) timeout]", - b->BusName, data, d->BitTimeout, - d->ByteTimeout, d->AcknTimeout)); - r = FALSE; - } - - I2C_TRACE(ErrorF("W%02x%c ", (int) data, sda ? '-' : '+')); - } - - b->I2CPutBits(b, 0, 1); - b->I2CUDelay(b, b->HoldTime); - - return r; -} - -/* This is the default I2CGetByte function if not supplied by the driver. - * - * A single byte is read from the device. - * The function returns FALSE if a timeout occurs, you should send - * a stop condition afterwards to reset the bus. - * - * A timeout occurs, - * if the slave pulls SCL to slow down the bus more than ByteTimeout usecs, - * or slows down the bus for more than b->BitTimeout usecs for each bit. - * - * ByteTimeout must be at least b->HoldTime, the other timeouts can be - * zero according to the comment on I2CRaiseSCL. - * - * For the byte in a sequence the acknowledge bit NACK (1), - * otherwise ACK (0) will be sent. - */ - -static Bool -I2CGetByte(I2CDevPtr d, I2CByte * data, Bool last) -{ - int i, sda; - I2CBusPtr b = d->pI2CBus; - - b->I2CPutBits(b, 0, 1); - b->I2CUDelay(b, b->RiseFallTime); - - if (!I2CReadBit(b, &sda, d->ByteTimeout)) - return FALSE; - - *data = (sda > 0) << 7; - - for (i = 6; i >= 0; i--) - if (!I2CReadBit(b, &sda, d->BitTimeout)) - return FALSE; - else - *data |= (sda > 0) << i; - - if (!I2CWriteBit(b, last ? 1 : 0, d->BitTimeout)) - return FALSE; - - I2C_TRACE(ErrorF("R%02x%c ", (int) *data, last ? '+' : '-')); - - return TRUE; -} - -/* This is the default I2CAddress function if not supplied by the driver. - * - * It creates the start condition, followed by the d->SlaveAddr. - * Higher level functions must call this routine rather than - * I2CStart/PutByte because a hardware I2C master may not be able - * to send a slave address without a start condition. - * - * The same timeouts apply as with I2CPutByte and additional a - * StartTimeout, similar to the ByteTimeout but for the start - * condition. - * - * In case of a timeout, the bus is left in a clean idle condition. - * I. e. you *must not* send a Stop. If this function succeeds, you *must*. - * - * The slave address format is 16 bit, with the legacy _8_bit_ slave address - * in the least significant byte. This is, the slave address must include the - * R/_W flag as least significant bit. - * - * The most significant byte of the address will be sent _after_ the LSB, - * but only if the LSB indicates: - * a) an 11 bit address, this is LSB = 1111 0xxx. - * b) a 'general call address', this is LSB = 0000 000x - see the I2C specs - * for more. - */ - -static Bool -I2CAddress(I2CDevPtr d, I2CSlaveAddr addr) -{ - if (I2CStart(d->pI2CBus, d->StartTimeout)) { - if (I2CPutByte(d, addr & 0xFF)) { - if ((addr & 0xF8) != 0xF0 && (addr & 0xFE) != 0x00) - return TRUE; - - if (I2CPutByte(d, (addr >> 8) & 0xFF)) - return TRUE; - } - - I2CStop(d); - } - - return FALSE; -} - -/* These are the hardware independent I2C helper functions. - * ======================================================== - */ - -/* Function for probing. Just send the slave address - * and return true if the device responds. The slave address - * must have the lsb set to reflect a read (1) or write (0) access. - * Don't expect a read- or write-only device will respond otherwise. - */ - -Bool -xf86I2CProbeAddress(I2CBusPtr b, I2CSlaveAddr addr) -{ - int r; - I2CDevRec d; - - d.DevName = "Probing"; - d.BitTimeout = b->BitTimeout; - d.ByteTimeout = b->ByteTimeout; - d.AcknTimeout = b->AcknTimeout; - d.StartTimeout = b->StartTimeout; - d.SlaveAddr = addr; - d.pI2CBus = b; - d.NextDev = NULL; - - r = b->I2CAddress(&d, addr); - - if (r) - b->I2CStop(&d); - - return r; -} - -/* All functions below are related to devices and take the - * slave address and timeout values from an I2CDevRec. They - * return FALSE in case of an error (presumably a timeout). - */ - -/* General purpose read and write function. - * - * 1st, if nWrite > 0 - * Send a start condition - * Send the slave address (1 or 2 bytes) with write flag - * Write n bytes from WriteBuffer - * 2nd, if nRead > 0 - * Send a start condition [again] - * Send the slave address (1 or 2 bytes) with read flag - * Read n bytes to ReadBuffer - * 3rd, if a Start condition has been successfully sent, - * Send a Stop condition. - * - * The function exits immediately when an error occurs, - * not processing any data left. However, step 3 will - * be executed anyway to leave the bus in clean idle state. - */ - -static Bool -I2CWriteRead(I2CDevPtr d, - I2CByte * WriteBuffer, int nWrite, I2CByte * ReadBuffer, int nRead) -{ - Bool r = TRUE; - I2CBusPtr b = d->pI2CBus; - int s = 0; - - if (r && nWrite > 0) { - r = b->I2CAddress(d, d->SlaveAddr & ~1); - if (r) { - for (; nWrite > 0; WriteBuffer++, nWrite--) - if (!(r = b->I2CPutByte(d, *WriteBuffer))) - break; - s++; - } - } - - if (r && nRead > 0) { - r = b->I2CAddress(d, d->SlaveAddr | 1); - if (r) { - for (; nRead > 0; ReadBuffer++, nRead--) - if (!(r = b->I2CGetByte(d, ReadBuffer, nRead == 1))) - break; - s++; - } - } - - if (s) - b->I2CStop(d); - - return r; -} - -/* wrapper - for compatibility and convenience */ - -Bool -xf86I2CWriteRead(I2CDevPtr d, - I2CByte * WriteBuffer, int nWrite, - I2CByte * ReadBuffer, int nRead) -{ - I2CBusPtr b = d->pI2CBus; - - return b->I2CWriteRead(d, WriteBuffer, nWrite, ReadBuffer, nRead); -} - -/* Read a byte, the only readable register of a device. - */ - -Bool -xf86I2CReadStatus(I2CDevPtr d, I2CByte * pbyte) -{ - return xf86I2CWriteRead(d, NULL, 0, pbyte, 1); -} - -/* Read a byte from one of the registers determined by its sub-address. - */ - -Bool -xf86I2CReadByte(I2CDevPtr d, I2CByte subaddr, I2CByte * pbyte) -{ - return xf86I2CWriteRead(d, &subaddr, 1, pbyte, 1); -} - -/* Read bytes from subsequent registers determined by the - * sub-address of the first register. - */ - -Bool -xf86I2CReadBytes(I2CDevPtr d, I2CByte subaddr, I2CByte * pbyte, int n) -{ - return xf86I2CWriteRead(d, &subaddr, 1, pbyte, n); -} - -/* Read a word (high byte, then low byte) from one of the registers - * determined by its sub-address. - */ - -Bool -xf86I2CReadWord(I2CDevPtr d, I2CByte subaddr, unsigned short *pword) -{ - I2CByte rb[2]; - - if (!xf86I2CWriteRead(d, &subaddr, 1, rb, 2)) - return FALSE; - - *pword = (rb[0] << 8) | rb[1]; - - return TRUE; -} - -/* Write a byte to one of the registers determined by its sub-address. - */ - -Bool -xf86I2CWriteByte(I2CDevPtr d, I2CByte subaddr, I2CByte byte) -{ - I2CByte wb[2]; - - wb[0] = subaddr; - wb[1] = byte; - - return xf86I2CWriteRead(d, wb, 2, NULL, 0); -} - -/* Write bytes to subsequent registers determined by the - * sub-address of the first register. - */ - -Bool -xf86I2CWriteBytes(I2CDevPtr d, I2CByte subaddr, - I2CByte * WriteBuffer, int nWrite) -{ - I2CBusPtr b = d->pI2CBus; - Bool r = TRUE; - - if (nWrite > 0) { - r = b->I2CAddress(d, d->SlaveAddr & ~1); - if (r) { - if ((r = b->I2CPutByte(d, subaddr))) - for (; nWrite > 0; WriteBuffer++, nWrite--) - if (!(r = b->I2CPutByte(d, *WriteBuffer))) - break; - - b->I2CStop(d); - } - } - - return r; -} - -/* Write a word (high byte, then low byte) to one of the registers - * determined by its sub-address. - */ - -Bool -xf86I2CWriteWord(I2CDevPtr d, I2CByte subaddr, unsigned short word) -{ - I2CByte wb[3]; - - wb[0] = subaddr; - wb[1] = word >> 8; - wb[2] = word & 0xFF; - - return xf86I2CWriteRead(d, wb, 3, NULL, 0); -} - -/* Write a vector of bytes to not adjacent registers. This vector is, - * 1st byte sub-address, 2nd byte value, 3rd byte sub-address asf. - * This function is intended to initialize devices. Note this function - * exits immediately when an error occurs, some registers may - * remain uninitialized. - */ - -Bool -xf86I2CWriteVec(I2CDevPtr d, I2CByte * vec, int nValues) -{ - I2CBusPtr b = d->pI2CBus; - Bool r = TRUE; - int s = 0; - - if (nValues > 0) { - for (; nValues > 0; nValues--, vec += 2) { - if (!(r = b->I2CAddress(d, d->SlaveAddr & ~1))) - break; - - s++; - - if (!(r = b->I2CPutByte(d, vec[0]))) - break; - - if (!(r = b->I2CPutByte(d, vec[1]))) - break; - } - - if (s > 0) - b->I2CStop(d); - } - - return r; -} - -/* Administrative functions. - * ========================= - */ - -/* Allocates an I2CDevRec for you and initializes with proper defaults - * you may modify before calling xf86I2CDevInit. Your I2CDevRec must - * contain at least a SlaveAddr, and a pI2CBus pointer to the bus this - * device shall be linked to. - * - * See function I2CAddress for the slave address format. Always set - * the least significant bit, indicating a read or write access, to zero. - */ - -I2CDevPtr -xf86CreateI2CDevRec(void) -{ - return calloc(1, sizeof(I2CDevRec)); -} - -/* Unlink an I2C device. If you got the I2CDevRec from xf86CreateI2CDevRec - * you should set to free it. - */ - -void -xf86DestroyI2CDevRec(I2CDevPtr d, Bool unalloc) -{ - if (d && d->pI2CBus) { - I2CDevPtr *p; - - /* Remove this from the list of active I2C devices. */ - - for (p = &d->pI2CBus->FirstDev; *p != NULL; p = &(*p)->NextDev) - if (*p == d) { - *p = (*p)->NextDev; - break; - } - - xf86DrvMsg(d->pI2CBus->scrnIndex, X_INFO, - "I2C device \"%s:%s\" removed.\n", - d->pI2CBus->BusName, d->DevName); - } - - if (unalloc) - free(d); -} - -/* I2C transmissions are related to an I2CDevRec you must link to a - * previously registered bus (see xf86I2CBusInit) before attempting - * to read and write data. You may call xf86I2CProbeAddress first to - * see if the device in question is present on this bus. - * - * xf86I2CDevInit will not allocate an I2CBusRec for you, instead you - * may enter a pointer to a statically allocated I2CDevRec or the (modified) - * result of xf86CreateI2CDevRec. - * - * If you don't specify timeouts for the device (n <= 0), it will inherit - * the bus-wide defaults. The function returns TRUE on success. - */ - -Bool -xf86I2CDevInit(I2CDevPtr d) -{ - I2CBusPtr b; - - if (d == NULL || - (b = d->pI2CBus) == NULL || - (d->SlaveAddr & 1) || xf86I2CFindDev(b, d->SlaveAddr) != NULL) - return FALSE; - - if (d->BitTimeout <= 0) - d->BitTimeout = b->BitTimeout; - if (d->ByteTimeout <= 0) - d->ByteTimeout = b->ByteTimeout; - if (d->AcknTimeout <= 0) - d->AcknTimeout = b->AcknTimeout; - if (d->StartTimeout <= 0) - d->StartTimeout = b->StartTimeout; - - d->NextDev = b->FirstDev; - b->FirstDev = d; - - xf86DrvMsg(b->scrnIndex, X_INFO, - "I2C device \"%s:%s\" registered at address 0x%02X.\n", - b->BusName, d->DevName, d->SlaveAddr); - - return TRUE; -} - -I2CDevPtr -xf86I2CFindDev(I2CBusPtr b, I2CSlaveAddr addr) -{ - I2CDevPtr d; - - if (b) { - for (d = b->FirstDev; d != NULL; d = d->NextDev) - if (d->SlaveAddr == addr) - return d; - } - - return NULL; -} - -static I2CBusPtr I2CBusList; - -/* Allocates an I2CBusRec for you and initializes with proper defaults - * you may modify before calling xf86I2CBusInit. Your I2CBusRec must - * contain at least a BusName, a scrnIndex (or -1), and a complete set - * of either high or low level I2C function pointers. You may pass - * bus-wide timeouts, otherwise inplausible values will be replaced - * with safe defaults. - */ - -I2CBusPtr -xf86CreateI2CBusRec(void) -{ - I2CBusPtr b; - - b = (I2CBusPtr) calloc(1, sizeof(I2CBusRec)); - - if (b != NULL) { - b->scrnIndex = -1; - b->pScrn = NULL; - b->HoldTime = 5; /* 100 kHz bus */ - b->BitTimeout = 5; - b->ByteTimeout = 5; - b->AcknTimeout = 5; - b->StartTimeout = 5; - b->RiseFallTime = RISEFALLTIME; - } - - return b; -} - -/* Unregister an I2C bus. If you got the I2CBusRec from xf86CreateI2CBusRec - * you should set to free it. If you set , the function - * xf86DestroyI2CDevRec will be called for all devices linked to the bus - * first, passing down the option. - */ - -void -xf86DestroyI2CBusRec(I2CBusPtr b, Bool unalloc, Bool devs_too) -{ - if (b) { - I2CBusPtr *p; - - /* Remove this from the list of active I2C buses */ - - for (p = &I2CBusList; *p != NULL; p = &(*p)->NextBus) - if (*p == b) { - *p = (*p)->NextBus; - break; - } - - if (b->FirstDev != NULL) { - if (devs_too) { - I2CDevPtr d; - - while ((d = b->FirstDev) != NULL) { - b->FirstDev = d->NextDev; - xf86DestroyI2CDevRec(d, unalloc); - } - } - else { - if (unalloc) { - xf86Msg(X_ERROR, - "i2c bug: Attempt to remove I2C bus \"%s\", " - "but device list is not empty.\n", b->BusName); - return; - } - } - } - - xf86DrvMsg(b->scrnIndex, X_INFO, "I2C bus \"%s\" removed.\n", - b->BusName); - - if (unalloc) - free(b); - } -} - -/* I2C masters have to register themselves using this function. - * It will not allocate an I2CBusRec for you, instead you may enter - * a pointer to a statically allocated I2CBusRec or the (modified) - * result of xf86CreateI2CBusRec. Returns TRUE on success. - * - * At this point there won't be any traffic on the I2C bus. - */ - -Bool -xf86I2CBusInit(I2CBusPtr b) -{ - /* I2C buses must be identified by a unique scrnIndex - * and name. If scrnIndex is unspecified (a negative value), - * then the name must be unique throughout the server. - */ - - if (b->BusName == NULL || xf86I2CFindBus(b->scrnIndex, b->BusName) != NULL) - return FALSE; - - /* If the high level functions are not - * supplied, use the generic functions. - * In this case we need the low-level - * function. - */ - if (b->I2CWriteRead == NULL) { - b->I2CWriteRead = I2CWriteRead; - - if (b->I2CPutBits == NULL || b->I2CGetBits == NULL) { - if (b->I2CPutByte == NULL || - b->I2CGetByte == NULL || - b->I2CAddress == NULL || - b->I2CStart == NULL || b->I2CStop == NULL) - return FALSE; - } - else { - b->I2CPutByte = I2CPutByte; - b->I2CGetByte = I2CGetByte; - b->I2CAddress = I2CAddress; - b->I2CStop = I2CStop; - b->I2CStart = I2CStart; - } - } - - if (b->I2CUDelay == NULL) - b->I2CUDelay = I2CUDelay; - - if (b->HoldTime < 2) - b->HoldTime = 5; - if (b->BitTimeout <= 0) - b->BitTimeout = b->HoldTime; - if (b->ByteTimeout <= 0) - b->ByteTimeout = b->HoldTime; - if (b->AcknTimeout <= 0) - b->AcknTimeout = b->HoldTime; - if (b->StartTimeout <= 0) - b->StartTimeout = b->HoldTime; - - /* Put new bus on list. */ - - b->NextBus = I2CBusList; - I2CBusList = b; - - xf86DrvMsg(b->scrnIndex, X_INFO, "I2C bus \"%s\" initialized.\n", - b->BusName); - - return TRUE; -} - -I2CBusPtr -xf86I2CFindBus(int scrnIndex, char *name) -{ - I2CBusPtr p; - - if (name != NULL) - for (p = I2CBusList; p != NULL; p = p->NextBus) - if (scrnIndex < 0 || p->scrnIndex == scrnIndex) - if (!strcmp(p->BusName, name)) - return p; - - return NULL; -} - -/* - * Return an array of I2CBusPtr's related to a screen. The caller is - * responsible for freeing the array. - */ -int -xf86I2CGetScreenBuses(int scrnIndex, I2CBusPtr ** pppI2CBus) -{ - I2CBusPtr pI2CBus; - int n = 0; - - if (pppI2CBus) - *pppI2CBus = NULL; - - for (pI2CBus = I2CBusList; pI2CBus; pI2CBus = pI2CBus->NextBus) { - if ((pI2CBus->scrnIndex >= 0) && (pI2CBus->scrnIndex != scrnIndex)) - continue; - - n++; - - if (!pppI2CBus) - continue; - - *pppI2CBus = xnfreallocarray(*pppI2CBus, n, sizeof(I2CBusPtr)); - (*pppI2CBus)[n - 1] = pI2CBus; - } - - return n; -} diff --git a/hw/xfree86/i2c/xf86i2c.h b/hw/xfree86/i2c/xf86i2c.h deleted file mode 100644 index 7b0ccdf70..000000000 --- a/hw/xfree86/i2c/xf86i2c.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 1998 Itai Nahshon, Michael Schimek - */ - -#ifndef _XF86I2C_H -#define _XF86I2C_H - -#include "regionstr.h" -#include "xf86.h" - -typedef unsigned char I2CByte; -typedef unsigned short I2CSlaveAddr; - -typedef struct _I2CBusRec *I2CBusPtr; -typedef struct _I2CDevRec *I2CDevPtr; - -/* I2C masters have to register themselves */ - -typedef struct _I2CBusRec { - char *BusName; - int scrnIndex; - ScrnInfoPtr pScrn; - - void (*I2CUDelay) (I2CBusPtr b, int usec); - - void (*I2CPutBits) (I2CBusPtr b, int scl, int sda); - void (*I2CGetBits) (I2CBusPtr b, int *scl, int *sda); - - /* Look at the generic routines to see how these functions should behave. */ - - Bool (*I2CStart) (I2CBusPtr b, int timeout); - Bool (*I2CAddress) (I2CDevPtr d, I2CSlaveAddr); - void (*I2CStop) (I2CDevPtr d); - Bool (*I2CPutByte) (I2CDevPtr d, I2CByte data); - Bool (*I2CGetByte) (I2CDevPtr d, I2CByte * data, Bool); - - DevUnion DriverPrivate; - - int HoldTime; /* 1 / bus clock frequency, 5 or 2 usec */ - - int BitTimeout; /* usec */ - int ByteTimeout; /* usec */ - int AcknTimeout; /* usec */ - int StartTimeout; /* usec */ - int RiseFallTime; /* usec */ - - I2CDevPtr FirstDev; - I2CBusPtr NextBus; - Bool (*I2CWriteRead) (I2CDevPtr d, I2CByte * WriteBuffer, int nWrite, - I2CByte * ReadBuffer, int nRead); -} I2CBusRec; - -#define CreateI2CBusRec xf86CreateI2CBusRec -extern _X_EXPORT I2CBusPtr xf86CreateI2CBusRec(void); - -#define DestroyI2CBusRec xf86DestroyI2CBusRec -extern _X_EXPORT void xf86DestroyI2CBusRec(I2CBusPtr pI2CBus, Bool unalloc, - Bool devs_too); -#define I2CBusInit xf86I2CBusInit -extern _X_EXPORT Bool xf86I2CBusInit(I2CBusPtr pI2CBus); - -extern _X_EXPORT I2CBusPtr xf86I2CFindBus(int scrnIndex, char *name); -extern _X_EXPORT int xf86I2CGetScreenBuses(int scrnIndex, - I2CBusPtr ** pppI2CBus); - -/* I2C slave devices */ - -typedef struct _I2CDevRec { - const char *DevName; - - int BitTimeout; /* usec */ - int ByteTimeout; /* usec */ - int AcknTimeout; /* usec */ - int StartTimeout; /* usec */ - - I2CSlaveAddr SlaveAddr; - I2CBusPtr pI2CBus; - I2CDevPtr NextDev; - DevUnion DriverPrivate; -} I2CDevRec; - -#define CreateI2CDevRec xf86CreateI2CDevRec -extern _X_EXPORT I2CDevPtr xf86CreateI2CDevRec(void); -extern _X_EXPORT void xf86DestroyI2CDevRec(I2CDevPtr pI2CDev, Bool unalloc); - -#define I2CDevInit xf86I2CDevInit -extern _X_EXPORT Bool xf86I2CDevInit(I2CDevPtr pI2CDev); -extern _X_EXPORT I2CDevPtr xf86I2CFindDev(I2CBusPtr, I2CSlaveAddr); - -/* See descriptions of these functions in xf86i2c.c */ - -#define I2CProbeAddress xf86I2CProbeAddress -extern _X_EXPORT Bool xf86I2CProbeAddress(I2CBusPtr pI2CBus, I2CSlaveAddr); - -#define I2C_WriteRead xf86I2CWriteRead -extern _X_EXPORT Bool xf86I2CWriteRead(I2CDevPtr d, I2CByte * WriteBuffer, - int nWrite, I2CByte * ReadBuffer, - int nRead); -#define xf86I2CRead(d, rb, nr) xf86I2CWriteRead(d, NULL, 0, rb, nr) - -extern _X_EXPORT Bool xf86I2CReadStatus(I2CDevPtr d, I2CByte * pbyte); -extern _X_EXPORT Bool xf86I2CReadByte(I2CDevPtr d, I2CByte subaddr, - I2CByte * pbyte); -extern _X_EXPORT Bool xf86I2CReadBytes(I2CDevPtr d, I2CByte subaddr, - I2CByte * pbyte, int n); -extern _X_EXPORT Bool xf86I2CReadWord(I2CDevPtr d, I2CByte subaddr, - unsigned short *pword); -#define xf86I2CWrite(d, wb, nw) xf86I2CWriteRead(d, wb, nw, NULL, 0) -extern _X_EXPORT Bool xf86I2CWriteByte(I2CDevPtr d, I2CByte subaddr, - I2CByte byte); -extern _X_EXPORT Bool xf86I2CWriteBytes(I2CDevPtr d, I2CByte subaddr, - I2CByte * WriteBuffer, int nWrite); -extern _X_EXPORT Bool xf86I2CWriteWord(I2CDevPtr d, I2CByte subaddr, - unsigned short word); -extern _X_EXPORT Bool xf86I2CWriteVec(I2CDevPtr d, I2CByte * vec, int nValues); - -#endif /*_XF86I2C_H */ diff --git a/hw/xfree86/int10/INT10.HOWTO b/hw/xfree86/int10/INT10.HOWTO deleted file mode 100644 index 13477ce87..000000000 --- a/hw/xfree86/int10/INT10.HOWTO +++ /dev/null @@ -1,344 +0,0 @@ - - INT10 X86 Real Mode executor - ============================= - - PRELIMINARY - -INT10 is a XFree86 module for soft-booting and executing real mode -int10 BIOS calls. The BIOS call code is largely untested, yet. - -1. Usage -======== - -To use the int10 module in a driver the header file -xfree86/os-support/int10/xf86int10.h must be included. - - a. Initialization - ----------------- - -The int10-executer gets initialized by calling: - - xf86Int10InfoPtr xf86InitInt10(int entityIndex); - -The function will soft-boot any non-primary device and return a -pointer to a xf86Int10InfoRec on success. If anything fails or if -int10 execution is disabled by an option in the device section NULL -will be returned. The driver should store this pointer for later -calls to other int10 module functions. - - b. Memory allocation - -------------------- - -To allocate memory in the real mode execution environment - - void * xf86Int10AllocPages(xf86Int10InfoPtr pInt,int num, int *off); - -can be called. It allocates num consecutive pagesize chunks. It -returns the address of the allocated area. off is set to its offset in -the real mode memory space. - - void xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num); - -Is used to free num pages beginning at pbase. - - c. Doing int10 BIOS calls - ------------------------- - -The BIOS call is executed by calling: - - void xf86ExecX86int10(xf86Int10InfoPtr pInt); - -The number of the interrupt (normally 10) and the initial values of -the ax, bx, cx, dx, si, di and es x86-CPU registers can be set in the -xf86Int10InfoRec passed to the function. On return this structure -contains the exit values of the registers listed above and the CPU -flag register. - - d. De-initializing - ----------------- - -If no further int10 calls are required for a certain chipset -the driver should call: - - void xf86FreeInt10(xf86Int10InfoPtr pInt); - -to free the memory allocated for real mode int10 calls. - - -2. Porting issues -================= - -The int10 real mode executor is designed to run on top of various x86 -CPU emulators as well as in vm86 mode of a real x86 CPU. If used with -a CPU emulator the emulator and CPU specific interfaces can be held -separate thus requiring minimal efforts to port the int10 module to -new platforms. Currently an interface to the x86emu real mode -emulator is provided. Since details of setting up and running the -vm86 mode is platform dependent both the platform dependent -environment and the emulation layer have to be ported. Several helper -functions are provided for that. - -A CPU emulator should meet certain requirements to be usable -for the INT10 executor: - -1. It must trap calls to intXX instructions and pass execution to an - external function which is allowed to modify CPU registers - including the instruction pointer (IP) before returning to the - emulator for continuing execution. When the external function is - called the IP must point to the instruction past the intXX call. - -2. The emulator should use externally provided functions to handle - PIO. - -3. The emulator should be able to use externally provided functions - to access memory from the real mode memory environment. Note, that - the vm86 mode usually requires one hunk of consecutive memory - starting at address 0 in the process virtual memory space. Thus if - this mode is to be used, the OS environment has to be able to provide - that, ie. it must be able to remap the processes virtual memory space - onto itself. If the emulator is able to handle memory access through - externally provided functions the real mode process memory can be - located anywhere in the processes virtual memory. It does not even - have to be consecutive. - -4. The executor should terminate on encountering a 'hlt' instruction. - - -Functions to implement: - -To simplify development the code has been split into a general setup -part and an emulator specific one. A generic setup code is provided in -generic.c. It should be usable with any emulator satisfying the -conditions mentioned above. Therefore the following section on int10 -setup may be skipped when porting int10 to new emulator. - -If the vm86() is to be used no memory access functions can be used. -Therefore the layout of the real mode memory image has to meet certain -requirements. Therefore when porting to other platforms a new setup -code may have to be designed, too. The following section will give -guidelines how this may be done. A sample implementation using SysV -IPC to map the appropriate real mode memory image to address 0 in -virtual address space just prior to execution may be found in -xfree86/os-support/linux/int10/linux.c. - -On non-PC like platforms emulation of certain PC features such as -initialization of BIOS int vectors, sys_BIOS constants or PCI config -method 1 can be turned on by defining _PC. - -I. Setup Code -------------- - -This sets up the real mode memory image, calls the emulator to POST -the chipset if required and maintains memory allocations in real mode -address space. - -1. xf86Int10InfoPtr xf86InitInt10(int entityIndex); - -This function should first find the screen assigned to the entity -carrying entitiyIndex and then call - - Bool int10skip(ScrnInfoPtr pScrn) - -to find out if the user has requested not to initialize int10. If so -xf86InitInt10() should return NULL. Otherwise an xf86Int10InfoRec -should be allocated. This structure contains the following fields: - - a. int entityIndex - index of the entity whose BIOS is to be - executed. - b. int scrnIndex - index of the screen assigned the entity. - c. pointer cpuRegs - pointer to a emulator/vm86-mode private - structure. May hold cpu register values - for the emulator. - d. CARD16 BIOSseg - Video BIOS segment address. - e. pointer private - pointer to a os specific data structure. - f. struct _int10Mem* - pointer to a structure to hold the memory - access functions for use by an emulator. - g. int num - number of the int to be called. - h. int ax..es,flags - CPU register values to pass to int-call. - -The Init function should initialize a-f. To initialize the emulator -specific execute environment the function - - Bool xf86Int10ExecSetup(xf86Int10InfoPtr pInt) - -should be called. If this function returns FALSE any already allocated -memory should be freed and xf86Int10Init(0 should exit returning NULL. - -If the platform has a PC like system BIOS it may be copied to or -mapped into memory locations SYS_BIOS to SYS_SIZE-1 of the real mode -memory environment of this process. Otherwise the helper function: - -int setup_system_bios(CARD32 base_addr); - -may be called to set up a rudimentary system BIOS sufficient to be -used to boot video BIOSes. base_addr specifies the virtual address -corresponding to SYS_BIOS in the real mode environment. If a PC-like -int vector and BIOS data area is available it should be copied to 0 to -LOW_PAGE_SIZE of the entities real mode environment. In this case the -video interrupt related entries should be reset for all non-primary -cards by calling: - -void reset_int_vect(xf86Int10InfoPtr pInt); To initialize the - -correct video BIOS entry points the BIOS must be warm-booted. If no -PC-like int vector is available one can be set up by calling - -void setup_int_vect(xf86Int10InfoPtr pInt); - -In this case the video BIOS has to be warm-booted always. If the -video BIOS for this entity has been installed during boot it may be -mapped (or copied) directly to the correct address in the real mode -memory environment. Otherwise - -int mapPciRom(xf86Int10InfoPtr pInt, unsigned char * address); - -should be called to copy the BIOS image from PCI ROM. 'address' -specifies the address this image should be copied to. Sufficient space -to hold an entire BIOS image should be allocated prior to calling -mapPciRom(). This function will return the size of the BIOS image in -bytes if it was able to successfully copy the image and 0 -otherwise. To create a well defined point to exit the softbooter - -void set_return_trap(xf86Int10Ptr pInt); - -may be called. It sets up a 'hlt' instruction in the emulator memory -just above the BIOS variable area. Before entering real mode execution -this address will be pushed onto the return stack. If the BIOS needs -to be warm-booted this should be done before leaving xf86InitInt10() -by setting num in the xf86Int10InfoRec to 0xe6 and calling - -void xf86ExecX86int10(xf86Int10IfoPtr pInt); - -The implementation of this function will be discussed below. This -function should be wrapped by calls to void LockLegacyVGA(screen, -legacyVGAPtr vga); and void UnlockLegacyVGA(screen, legacyVGAPtr vga); -The struct vga is used to hold the state of the legacy VGA access -registers if a legacy VGA device exists. xf86InitInt10() should -return a pointer to the xf86Int10InfoRec allocated. - -2. Bool MapCurrentInt10(xf86Int10InfoPtr pInt); - -In case a platform specific mapping has to be performed to map the -memory allocated for the real mode memory environment into a specific -location prior to executing the x86 real mode code a function - - Bool MapCurrentInt10(xf86Int10InfoPtr pInt); - -has to be provided. It will be called by a helper function whenever -the active entity changes. If the vm86 mode is used it is most likely -that the 1MB real mode memory space located somewhere in the processes -virtual memory will have to be remapped to address 0 of the virtual -memory space. - -3. void xf86FreeInt10(xf86Int10InfoPtr pInt); - -To free all memory allocated for video BIOS calls of a specific entity -the function - - void xf86FreeInt10(xf86Int10InfoPtr pInt); - -should be provided. If the entity to be freed was mapped by -MapCurrentInt10() this mapping needs to be undone also. - -4. - void * xf86Int10AllocPages(xf86Int10InfoPtr pInt,int num, int *off) - void xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num) - -xf86Int10AllocPages() should allocate 'num' consecutive page-size -chunks of memory. In real mode memory space this range needs to occupy -consecutive addresses, too. The function must return the address of -this memory. The offset in real mode memory needs to be returned in -'off'. If no block of 'num' pages are available the function should -return NULL. - -xf86Int10FreePages() will free the 'num' pages starting at 'pbase'. -'num' is equal to the number of pages allocated by a single -xf86Int10AllocatePages() call. 'pbase' is the address of the range -previously returned by xf86Int10AllocatePages(). - -II. Emulator specific functions -------------------------------- - -1. Bool xf86Int10ExecSetup(xf86Int10InfoPtr pInt); - -This function will be called from xf86InitInt10(). It may be used to -set up the static emulator specific part of the real mode -environment. On success it should return TRUE. - -2. xf86ExecX86int10(xf86Int10InfoPtr pInt); - -This function gets called to execute an int call. It may call the -helper function: - - void setup_int(xf86Int10InfoPrt pInt); - -to copy the register values to the emulator specific locations and to -set up the non-static real mode execution environment. On return from -setup_int() 'Int10Current' holds a pointer to the current -xf86Int10InfoRec. - -It should start execution by calling - - Bool int_handler(xf86Int10InfoPtr pInt); - -and if this function returns TRUE it should call whatever necessary to -continue execution until a 'hlt' instruction is encountered. To copy -the resulting register values back to the xf86Int10InfoRec structure - - void finish_int(xf86Int10InfoPtr pInt); - -should be called. - -Helper functions are provided to aid the implementation of a vm86 -call: - - Bool vm86_GP_fault(xf86Int10InfoPtr pInt); - -This function handles instructions which cause a vm86 call to -trap. PIO access is handled by the in/out calls as defined in -compiler.h. Optionally the PIO instructions can be logged by defining -PRINT_PORT in xf86int10.h. This is meant for debugging purposes. - -Unknown instructions and 'hlt' cause vm86_GP_fault() to return -FALSE. Otherwise TRUE is returned. - -Note: This function is currently based on the Linux vm86 call. It -might have to be modified or even rewritten for other OS. So your -mileage may vary. - -Functions to dump memory, code, xf86 CPU register values and stack are -also provided. Take a look at helper.c To view a memory range the -function - - void dprint(unsigned long start, unsigned long size) - -is provided. The use should be self explanatory. - -Register and memory access functions are provided in helper_mem.c. -The PIO register access functions can trap access to PCI config space -access register (config method 1) if _PC is not defined. - -A header file 'defines.h' is required to define OS/emulator specific -ways to access memory and xf86 CPU registers: Defines need to be -provided for memory byte/work/long read/write access -(MEM_RB(name,addr),MEM_RW(name,addr),MEM_RL(name,addr), -MEM_WB(name,addr,val),MEM_WL(name,addr,val),MEM_WL(name,addr,val)) of -the real mode memory environment. 'name' will contain a pointer to the -current xf86Int10InfoRec. Currently defines are available for -vm86-mode under Linux and x86emu. They may be activated by defining -_X86EMU or _VM86_LINUX respectively. - -Note: Emulators usually are not able to pass this pointer when calling -memory access functions. In this case a global variable should be -defined which can hold this pointer. This variable can be set in -MapCurrentInt10(). It also must be set in xf86InitInt10() if this -function calls the memory access functions either directly or by -calling xf86ExecX86int10(pInt). Defines to access the emulator -specific xf86 CPU register locations are also required: -X86_EAX,...,X86_EFLAGS for access of the full 32 bit registers, -X86_AX...X86_FLAGS for access of the 16 bit registers and -XF86_AL,XF86_BL,XF86_CL,XF86_DL to access the lower byte of the -AX,BX,CX and DX register. - - -$XFree86: xc/programs/Xserver/hw/xfree86/int10/INT10.HOWTO,v 1.2 2000/02/08 13:13:22 eich Exp $ diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c deleted file mode 100644 index 191571192..000000000 --- a/hw/xfree86/int10/generic.c +++ /dev/null @@ -1,482 +0,0 @@ -/* - * XFree86 int10 module - * execute BIOS int 10h calls in x86 real mode environment - * Copyright 1999 Egbert Eich - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#include "xf86.h" -#include "xf86_OSproc.h" -#include "compiler.h" -#define _INT10_PRIVATE -#include "xf86int10.h" -#include "int10Defines.h" -#include "Pci.h" - -#define ALLOC_ENTRIES(x) ((V_RAM / x) - 1) - -#include /* needed for memmove */ - -static __inline__ uint32_t -ldl_u(uint32_t * p) -{ - uint32_t ret; - - memmove(&ret, p, sizeof(*p)); - return ret; -} - -static __inline__ uint16_t -ldw_u(uint16_t * p) -{ - uint16_t ret; - - memmove(&ret, p, sizeof(*p)); - return ret; -} - -static __inline__ void -stl_u(uint32_t val, uint32_t * p) -{ - uint32_t tmp = val; - - memmove(p, &tmp, sizeof(*p)); -} - -static __inline__ void -stw_u(uint16_t val, uint16_t * p) -{ - uint16_t tmp = val; - - memmove(p, &tmp, sizeof(*p)); -} - -static uint8_t read_b(xf86Int10InfoPtr pInt, int addr); -static uint16_t read_w(xf86Int10InfoPtr pInt, int addr); -static uint32_t read_l(xf86Int10InfoPtr pInt, int addr); -static void write_b(xf86Int10InfoPtr pInt, int addr, uint8_t val); -static void write_w(xf86Int10InfoPtr pInt, int addr, uint16_t val); -static void write_l(xf86Int10InfoPtr pInt, int addr, uint32_t val); - -/* - * the emulator cannot pass a pointer to the current xf86Int10InfoRec - * to the memory access functions therefore store it here. - */ - -typedef struct { - int shift; - int entries; - void *base; - void *vRam; - int highMemory; - void *sysMem; - char *alloc; -} genericInt10Priv; - -#define INTPriv(x) ((genericInt10Priv*)x->private) - -int10MemRec genericMem = { - read_b, - read_w, - read_l, - write_b, - write_w, - write_l -}; - -static void MapVRam(xf86Int10InfoPtr pInt); -static void UnmapVRam(xf86Int10InfoPtr pInt); - -#ifdef _PC -#define GET_HIGH_BASE(x) (((V_BIOS + (x) + getpagesize() - 1)/getpagesize()) \ - * getpagesize()) -#endif - -static void *sysMem = NULL; - -static Bool -readIntVec(struct pci_device *dev, unsigned char *buf, int len) -{ - void *map; - - if (pci_device_map_legacy(dev, 0, len, 0, &map)) - return FALSE; - - memcpy(buf, map, len); - pci_device_unmap_legacy(dev, map, len); - - return TRUE; -} - -xf86Int10InfoPtr -xf86ExtendedInitInt10(int entityIndex, int Flags) -{ - xf86Int10InfoPtr pInt; - void *base = 0; - void *vbiosMem = 0; - void *options = NULL; - legacyVGARec vga; - ScrnInfoPtr pScrn; - - pScrn = xf86FindScreenForEntity(entityIndex); - - options = xf86HandleInt10Options(pScrn, entityIndex); - - if (int10skip(options)) { - free(options); - return NULL; - } - - pInt = (xf86Int10InfoPtr) xnfcalloc(1, sizeof(xf86Int10InfoRec)); - pInt->entityIndex = entityIndex; - if (!xf86Int10ExecSetup(pInt)) - goto error0; - pInt->mem = &genericMem; - pInt->private = (void *) xnfcalloc(1, sizeof(genericInt10Priv)); - INTPriv(pInt)->alloc = (void *) xnfcalloc(1, ALLOC_ENTRIES(getpagesize())); - pInt->pScrn = pScrn; - base = INTPriv(pInt)->base = xnfalloc(SYS_BIOS); - - /* FIXME: Shouldn't this be a failure case? Leaving dev as NULL seems like - * FIXME: an error - */ - pInt->dev = xf86GetPciInfoForEntity(entityIndex); - - /* - * we need to map video RAM MMIO as some chipsets map mmio - * registers into this range. - */ - MapVRam(pInt); -#ifdef _PC - if (!sysMem) - pci_device_map_legacy(pInt->dev, V_BIOS, BIOS_SIZE + SYS_BIOS - V_BIOS, - PCI_DEV_MAP_FLAG_WRITABLE, &sysMem); - INTPriv(pInt)->sysMem = sysMem; - - if (!readIntVec(pInt->dev, base, LOW_PAGE_SIZE)) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Cannot read int vect\n"); - goto error1; - } - - /* - * Retrieve everything between V_BIOS and SYS_BIOS as some system BIOSes - * have executable code there. - */ - memset((char *) base + V_BIOS, 0, SYS_BIOS - V_BIOS); - INTPriv(pInt)->highMemory = V_BIOS; - - if (xf86IsEntityPrimary(entityIndex) && !(initPrimary(options))) { - if (!xf86int10GetBiosSegment(pInt, (unsigned char *) sysMem - V_BIOS)) - goto error1; - - set_return_trap(pInt); - - pInt->Flags = Flags & (SET_BIOS_SCRATCH | RESTORE_BIOS_SCRATCH); - if (!(pInt->Flags & SET_BIOS_SCRATCH)) - pInt->Flags &= ~RESTORE_BIOS_SCRATCH; - xf86Int10SaveRestoreBIOSVars(pInt, TRUE); - - } - else { - const BusType location_type = xf86int10GetBiosLocationType(pInt); - int bios_location = V_BIOS; - - reset_int_vect(pInt); - set_return_trap(pInt); - - switch (location_type) { - case BUS_PCI:{ - int err; - struct pci_device *rom_device = - xf86GetPciInfoForEntity(pInt->entityIndex); - - vbiosMem = (unsigned char *) base + bios_location; - err = pci_device_read_rom(rom_device, vbiosMem); - if (err) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Cannot read V_BIOS (3) %s\n", - strerror(err)); - goto error1; - } - INTPriv(pInt)->highMemory = GET_HIGH_BASE(rom_device->rom_size); - break; - } - default: - goto error1; - } - pInt->BIOSseg = V_BIOS >> 4; - pInt->num = 0xe6; - LockLegacyVGA(pInt, &vga); - xf86ExecX86int10(pInt); - UnlockLegacyVGA(pInt, &vga); - } -#else - if (!sysMem) { - sysMem = xnfalloc(BIOS_SIZE); - setup_system_bios(sysMem); - } - INTPriv(pInt)->sysMem = sysMem; - setup_int_vect(pInt); - set_return_trap(pInt); - - /* Retrieve the entire legacy video BIOS segment. This can be up to - * 128KiB. - */ - vbiosMem = (char *) base + V_BIOS; - memset(vbiosMem, 0, 2 * V_BIOS_SIZE); - if (pci_device_read_rom(pInt->dev, vbiosMem) != 0 - || pInt->dev->rom_size < V_BIOS_SIZE) { - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "Unable to retrieve all of segment 0x0C0000.\n"); - } - - /* - * If this adapter is the primary, use its post-init BIOS (if we can find - * it). - */ - { - int bios_location = V_BIOS; - Bool done = FALSE; - - vbiosMem = (unsigned char *) base + bios_location; - - if (xf86IsEntityPrimary(entityIndex)) { - if (int10_check_bios(pScrn->scrnIndex, bios_location >> 4, vbiosMem)) - done = TRUE; - else - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "No legacy BIOS found -- trying PCI\n"); - } - if (!done) { - int err; - struct pci_device *rom_device = - xf86GetPciInfoForEntity(pInt->entityIndex); - - err = pci_device_read_rom(rom_device, vbiosMem); - if (err) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Cannot read V_BIOS (5) %s\n", - strerror(err)); - goto error1; - } - } - } - - pInt->BIOSseg = V_BIOS >> 4; - pInt->num = 0xe6; - LockLegacyVGA(pInt, &vga); - xf86ExecX86int10(pInt); - UnlockLegacyVGA(pInt, &vga); -#endif - free(options); - return pInt; - - error1: - free(base); - UnmapVRam(pInt); - free(INTPriv(pInt)->alloc); - free(pInt->private); - error0: - free(pInt); - free(options); - - return NULL; -} - -static void -MapVRam(xf86Int10InfoPtr pInt) -{ - int pagesize = getpagesize(); - int size = ((VRAM_SIZE + pagesize - 1) / pagesize) * pagesize; - - pci_device_map_legacy(pInt->dev, V_RAM, size, PCI_DEV_MAP_FLAG_WRITABLE, - &(INTPriv(pInt)->vRam)); - pInt->io = pci_legacy_open_io(pInt->dev, 0, 64 * 1024); -} - -static void -UnmapVRam(xf86Int10InfoPtr pInt) -{ - int pagesize = getpagesize(); - int size = ((VRAM_SIZE + pagesize - 1) / pagesize) * pagesize; - - pci_device_unmap_legacy(pInt->dev, INTPriv(pInt)->vRam, size); - pci_device_close_io(pInt->dev, pInt->io); - pInt->io = NULL; -} - -Bool -MapCurrentInt10(xf86Int10InfoPtr pInt) -{ - /* nothing to do here */ - return TRUE; -} - -void -xf86FreeInt10(xf86Int10InfoPtr pInt) -{ - if (!pInt) - return; -#if defined (_PC) - xf86Int10SaveRestoreBIOSVars(pInt, FALSE); -#endif - if (Int10Current == pInt) - Int10Current = NULL; - free(INTPriv(pInt)->base); - UnmapVRam(pInt); - free(INTPriv(pInt)->alloc); - free(pInt->private); - free(pInt); -} - -void * -xf86Int10AllocPages(xf86Int10InfoPtr pInt, int num, int *off) -{ - int pagesize = getpagesize(); - int num_pages = ALLOC_ENTRIES(pagesize); - int i, j; - - for (i = 0; i < (num_pages - num); i++) { - if (INTPriv(pInt)->alloc[i] == 0) { - for (j = i; j < (num + i); j++) - if (INTPriv(pInt)->alloc[j] != 0) - break; - if (j == (num + i)) - break; - i += num; - } - } - if (i == (num_pages - num)) - return NULL; - - for (j = i; j < (i + num); j++) - INTPriv(pInt)->alloc[j] = 1; - - *off = (i + 1) * pagesize; - - return (char *) INTPriv(pInt)->base + *off; -} - -void -xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num) -{ - int pagesize = getpagesize(); - int first = - (((char *) pbase - (char *) INTPriv(pInt)->base) / pagesize) - 1; - int i; - - for (i = first; i < (first + num); i++) - INTPriv(pInt)->alloc[i] = 0; -} - -#define OFF(addr) ((addr) & 0xffff) -#if defined _PC -#define HIGH_OFFSET (INTPriv(pInt)->highMemory) -#define HIGH_BASE V_BIOS -#else -#define HIGH_OFFSET SYS_BIOS -#define HIGH_BASE SYS_BIOS -#endif -#define SYS(addr) ((addr) >= HIGH_OFFSET) -#define V_ADDR(addr) \ - (SYS(addr) ? ((char*)INTPriv(pInt)->sysMem) + (addr - HIGH_BASE) \ - : (((char*)(INTPriv(pInt)->base) + addr))) -#define VRAM_ADDR(addr) (addr - V_RAM) -#define VRAM_BASE (INTPriv(pInt)->vRam) - -#define VRAM(addr) ((addr >= V_RAM) && (addr < (V_RAM + VRAM_SIZE))) -#define V_ADDR_RB(addr) \ - ((VRAM(addr)) ? MMIO_IN8((uint8_t*)VRAM_BASE,VRAM_ADDR(addr)) \ - : *(uint8_t*) V_ADDR(addr)) -#define V_ADDR_RW(addr) \ - ((VRAM(addr)) ? MMIO_IN16((uint16_t*)VRAM_BASE,VRAM_ADDR(addr)) \ - : ldw_u((void *)V_ADDR(addr))) -#define V_ADDR_RL(addr) \ - ((VRAM(addr)) ? MMIO_IN32((uint32_t*)VRAM_BASE,VRAM_ADDR(addr)) \ - : ldl_u((void *)V_ADDR(addr))) - -#define V_ADDR_WB(addr,val) \ - if(VRAM(addr)) \ - MMIO_OUT8((uint8_t*)VRAM_BASE,VRAM_ADDR(addr),val); \ - else \ - *(uint8_t*) V_ADDR(addr) = val; -#define V_ADDR_WW(addr,val) \ - if(VRAM(addr)) \ - MMIO_OUT16((uint16_t*)VRAM_BASE,VRAM_ADDR(addr),val); \ - else \ - stw_u((val),(void *)(V_ADDR(addr))); - -#define V_ADDR_WL(addr,val) \ - if (VRAM(addr)) \ - MMIO_OUT32((uint32_t*)VRAM_BASE,VRAM_ADDR(addr),val); \ - else \ - stl_u(val,(void *)(V_ADDR(addr))); - -static uint8_t -read_b(xf86Int10InfoPtr pInt, int addr) -{ - return V_ADDR_RB(addr); -} - -static uint16_t -read_w(xf86Int10InfoPtr pInt, int addr) -{ -#if X_BYTE_ORDER == X_LITTLE_ENDIAN - if (OFF(addr + 1) > 0) - return V_ADDR_RW(addr); -#endif - return V_ADDR_RB(addr) | (V_ADDR_RB(addr + 1) << 8); -} - -static uint32_t -read_l(xf86Int10InfoPtr pInt, int addr) -{ -#if X_BYTE_ORDER == X_LITTLE_ENDIAN - if (OFF(addr + 3) > 2) - return V_ADDR_RL(addr); -#endif - return V_ADDR_RB(addr) | - (V_ADDR_RB(addr + 1) << 8) | - (V_ADDR_RB(addr + 2) << 16) | (V_ADDR_RB(addr + 3) << 24); -} - -static void -write_b(xf86Int10InfoPtr pInt, int addr, uint8_t val) -{ - V_ADDR_WB(addr, val); -} - -static void -write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val) -{ -#if X_BYTE_ORDER == X_LITTLE_ENDIAN - if (OFF(addr + 1) > 0) { - V_ADDR_WW(addr, val); - } -#endif - V_ADDR_WB(addr, val); - V_ADDR_WB(addr + 1, val >> 8); -} - -static void -write_l(xf86Int10InfoPtr pInt, int addr, uint32_t val) -{ -#if X_BYTE_ORDER == X_LITTLE_ENDIAN - if (OFF(addr + 3) > 2) { - V_ADDR_WL(addr, val); - } -#endif - V_ADDR_WB(addr, val); - V_ADDR_WB(addr + 1, val >> 8); - V_ADDR_WB(addr + 2, val >> 16); - V_ADDR_WB(addr + 3, val >> 24); -} - -void * -xf86int10Addr(xf86Int10InfoPtr pInt, uint32_t addr) -{ - return V_ADDR(addr); -} diff --git a/hw/xfree86/int10/helper_exec.c b/hw/xfree86/int10/helper_exec.c deleted file mode 100644 index 12000bf96..000000000 --- a/hw/xfree86/int10/helper_exec.c +++ /dev/null @@ -1,766 +0,0 @@ -/* - * XFree86 int10 module - * execute BIOS int 10h calls in x86 real mode environment - * Copyright 1999 Egbert Eich - * - * Part of this code was inspired by the VBIOS POSTing code in DOSEMU - * developed by the "DOSEMU-Development-Team" - */ - -/* - * To debug port accesses define PRINT_PORT to 1. - * Note! You also have to comment out ioperm() - * in xf86EnableIO(). Otherwise we won't trap - * on PIO. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#define PRINT_PORT 0 - -#include - -#include -#include "xf86.h" -#include "xf86_OSproc.h" -#include "compiler.h" -#define _INT10_PRIVATE -#include "int10Defines.h" -#include "xf86int10.h" -#include "Pci.h" -#ifdef _X86EMU -#include "x86emu/x86emui.h" -#else -#define DEBUG_IO_TRACE() 0 -#endif -#include - -static int pciCfg1in(uint16_t addr, uint32_t *val); -static int pciCfg1out(uint16_t addr, uint32_t val); -static int pciCfg1inw(uint16_t addr, uint16_t *val); -static int pciCfg1outw(uint16_t addr, uint16_t val); -static int pciCfg1inb(uint16_t addr, uint8_t *val); -static int pciCfg1outb(uint16_t addr, uint8_t val); - -#if defined (_PC) -static void SetResetBIOSVars(xf86Int10InfoPtr pInt, Bool set); -#endif - -#define REG pInt - -int -setup_int(xf86Int10InfoPtr pInt) -{ - if (pInt != Int10Current) { - if (!MapCurrentInt10(pInt)) - return -1; - Int10Current = pInt; - } - X86_EAX = (uint32_t) pInt->ax; - X86_EBX = (uint32_t) pInt->bx; - X86_ECX = (uint32_t) pInt->cx; - X86_EDX = (uint32_t) pInt->dx; - X86_ESI = (uint32_t) pInt->si; - X86_EDI = (uint32_t) pInt->di; - X86_EBP = (uint32_t) pInt->bp; - X86_ESP = 0x1000; - X86_SS = pInt->stackseg >> 4; - X86_EIP = 0x0600; - X86_CS = 0x0; /* address of 'hlt' */ - X86_DS = 0x40; /* standard pc ds */ - X86_ES = pInt->es; - X86_FS = 0; - X86_GS = 0; - X86_EFLAGS = X86_IF_MASK | X86_IOPL_MASK; -#if defined (_PC) - if (pInt->Flags & SET_BIOS_SCRATCH) - SetResetBIOSVars(pInt, TRUE); -#endif - OsBlockSignals(); - return 0; -} - -void -finish_int(xf86Int10InfoPtr pInt, int sig) -{ - OsReleaseSignals(); - pInt->ax = (uint32_t) X86_EAX; - pInt->bx = (uint32_t) X86_EBX; - pInt->cx = (uint32_t) X86_ECX; - pInt->dx = (uint32_t) X86_EDX; - pInt->si = (uint32_t) X86_ESI; - pInt->di = (uint32_t) X86_EDI; - pInt->es = (uint16_t) X86_ES; - pInt->bp = (uint32_t) X86_EBP; - pInt->flags = (uint32_t) X86_FLAGS; -#if defined (_PC) - if (pInt->Flags & RESTORE_BIOS_SCRATCH) - SetResetBIOSVars(pInt, FALSE); -#endif -} - -/* general software interrupt handler */ -uint32_t -getIntVect(xf86Int10InfoPtr pInt, int num) -{ - return MEM_RW(pInt, num << 2) + (MEM_RW(pInt, (num << 2) + 2) << 4); -} - -void -pushw(xf86Int10InfoPtr pInt, uint16_t val) -{ - X86_ESP -= 2; - MEM_WW(pInt, ((uint32_t) X86_SS << 4) + X86_SP, val); -} - -int -run_bios_int(int num, xf86Int10InfoPtr pInt) -{ - uint32_t eflags; - -#ifndef _PC - /* check if bios vector is initialized */ - if (MEM_RW(pInt, (num << 2) + 2) == (SYS_BIOS >> 4)) { /* SYS_BIOS_SEG ? */ - - if (num == 21 && X86_AH == 0x4e) { - xf86DrvMsg(pInt->pScrn->scrnIndex, X_NOTICE, - "Failing Find-Matching-File on non-PC" - " (int 21, func 4e)\n"); - X86_AX = 2; - SET_FLAG(F_CF); - return 1; - } - else { - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "Ignoring int 0x%02x call\n", num); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - return 1; - } - } -#endif -#ifdef PRINT_INT - ErrorF("calling card BIOS at: "); -#endif - eflags = X86_EFLAGS; -#if 0 - eflags = eflags | IF_MASK; - X86_EFLAGS = X86_EFLAGS & ~(VIF_MASK | TF_MASK | IF_MASK | NT_MASK); -#endif - pushw(pInt, eflags); - pushw(pInt, X86_CS); - pushw(pInt, X86_IP); - X86_CS = MEM_RW(pInt, (num << 2) + 2); - X86_IP = MEM_RW(pInt, num << 2); -#ifdef PRINT_INT - ErrorF("0x%x:%lx\n", X86_CS, X86_EIP); -#endif - return 1; -} - -/* Debugging stuff */ -void -dump_code(xf86Int10InfoPtr pInt) -{ - int i; - uint32_t lina = SEG_ADR((uint32_t), X86_CS, IP); - - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3, "code at 0x%8.8" PRIx32 ":\n", - (unsigned) lina); - for (i = 0; i < 0x10; i++) - xf86ErrorFVerb(3, " %2.2x", MEM_RB(pInt, lina + i)); - xf86ErrorFVerb(3, "\n"); - for (; i < 0x20; i++) - xf86ErrorFVerb(3, " %2.2x", MEM_RB(pInt, lina + i)); - xf86ErrorFVerb(3, "\n"); -} - -void -dump_registers(xf86Int10InfoPtr pInt) -{ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3, - "EAX=0x%8.8lx, EBX=0x%8.8lx, ECX=0x%8.8lx, EDX=0x%8.8lx\n", - (unsigned long) X86_EAX, (unsigned long) X86_EBX, - (unsigned long) X86_ECX, (unsigned long) X86_EDX); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3, - "ESP=0x%8.8lx, EBP=0x%8.8lx, ESI=0x%8.8lx, EDI=0x%8.8lx\n", - (unsigned long) X86_ESP, (unsigned long) X86_EBP, - (unsigned long) X86_ESI, (unsigned long) X86_EDI); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3, - "CS=0x%4.4x, SS=0x%4.4x," - " DS=0x%4.4x, ES=0x%4.4x, FS=0x%4.4x, GS=0x%4.4x\n", - X86_CS, X86_SS, X86_DS, X86_ES, X86_FS, X86_GS); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_INFO, 3, - "EIP=0x%8.8lx, EFLAGS=0x%8.8lx\n", - (unsigned long) X86_EIP, (unsigned long) X86_EFLAGS); -} - -void -stack_trace(xf86Int10InfoPtr pInt) -{ - int i = 0; - unsigned long stack = SEG_ADR((uint32_t), X86_SS, SP); - unsigned long tail = (uint32_t) ((X86_SS << 4) + 0x1000); - - if (stack >= tail) - return; - - xf86MsgVerb(X_INFO, 3, "stack at 0x%8.8lx:\n", stack); - for (; stack < tail; stack++) { - xf86ErrorFVerb(3, " %2.2x", MEM_RB(pInt, stack)); - i = (i + 1) % 0x10; - if (!i) - xf86ErrorFVerb(3, "\n"); - } - if (i) - xf86ErrorFVerb(3, "\n"); -} - -int -port_rep_inb(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count) -{ - register int inc = d_f ? -1 : 1; - uint32_t dst = base; - - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" rep_insb(%#x) %" PRIu32 " bytes at %8.8" PRIx32 " %s\n", - port, (unsigned) count, (unsigned) base, d_f ? "up" : "down"); - while (count--) { - MEM_WB(pInt, dst, x_inb(port)); - dst += inc; - } - return dst - base; -} - -int -port_rep_inw(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count) -{ - register int inc = d_f ? -2 : 2; - uint32_t dst = base; - - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" rep_insw(%#x) %" PRIu32 " bytes at %8.8" PRIx32 " %s\n", - port, (unsigned) count, (unsigned) base, d_f ? "up" : "down"); - while (count--) { - MEM_WW(pInt, dst, x_inw(port)); - dst += inc; - } - return dst - base; -} - -int -port_rep_inl(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count) -{ - register int inc = d_f ? -4 : 4; - uint32_t dst = base; - - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" rep_insl(%#x) %" PRIu32 " bytes at %8.8" PRIx32 " %s\n", - port, (unsigned) count, (unsigned) base, d_f ? "up" : "down"); - while (count--) { - MEM_WL(pInt, dst, x_inl(port)); - dst += inc; - } - return dst - base; -} - -int -port_rep_outb(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count) -{ - register int inc = d_f ? -1 : 1; - uint32_t dst = base; - - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" rep_outb(%#x) %" PRIu32 " bytes at %8.8" PRIx32 " %s\n", - port, (unsigned) count, (unsigned) base, d_f ? "up" : "down"); - while (count--) { - x_outb(port, MEM_RB(pInt, dst)); - dst += inc; - } - return dst - base; -} - -int -port_rep_outw(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count) -{ - register int inc = d_f ? -2 : 2; - uint32_t dst = base; - - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" rep_outw(%#x) %" PRIu32 " bytes at %8.8" PRIx32 " %s\n", - port, (unsigned) count, (unsigned) base, d_f ? "up" : "down"); - while (count--) { - x_outw(port, MEM_RW(pInt, dst)); - dst += inc; - } - return dst - base; -} - -int -port_rep_outl(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count) -{ - register int inc = d_f ? -4 : 4; - uint32_t dst = base; - - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" rep_outl(%#x) %" PRIu32 " bytes at %8.8" PRIx32 " %s\n", - port, (unsigned) count, (unsigned) base, d_f ? "up" : "down"); - while (count--) { - x_outl(port, MEM_RL(pInt, dst)); - dst += inc; - } - return dst - base; -} - -uint8_t -x_inb(uint16_t port) -{ - uint8_t val; - - if (port == 0x40) { - Int10Current->inb40time++; - val = (uint8_t) (Int10Current->inb40time >> - ((Int10Current->inb40time & 1) << 3)); - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" inb(%#x) = %2.2x\n", port, val); -#ifdef __NOT_YET__ - } - else if (port < 0x0100) { /* Don't interfere with mainboard */ - val = 0; - xf86DrvMsgVerb(Int10Current->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "inb 0x%4.4x\n", port); - if (xf86GetVerbosity() > 3) { - dump_registers(Int10Current); - stack_trace(Int10Current); - } -#endif /* __NOT_YET__ */ - } - else if (!pciCfg1inb(port, &val)) { - val = pci_io_read8(Int10Current->io, port); - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" inb(%#x) = %2.2x\n", port, val); - } - return val; -} - -uint16_t -x_inw(uint16_t port) -{ - uint16_t val; - - if (port == 0x5c) { - struct timeval tv; - - /* - * Emulate a PC's timer. Typical resolution is 3.26 usec. - * Approximate this by dividing by 3. - */ - X_GETTIMEOFDAY(&tv); - val = (uint16_t) (tv.tv_usec / 3); - } - else if (!pciCfg1inw(port, &val)) { - val = pci_io_read16(Int10Current->io, port); - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" inw(%#x) = %4.4x\n", port, val); - } - return val; -} - -void -x_outb(uint16_t port, uint8_t val) -{ - if ((port == 0x43) && (val == 0)) { - struct timeval tv; - - /* - * Emulate a PC's timer 0. Such timers typically have a resolution of - * some .838 usec per tick, but this can only provide 1 usec per tick. - * (Not that this matters much, given inherent emulation delays.) Use - * the bottom bit as a byte select. See inb(0x40) above. - */ - X_GETTIMEOFDAY(&tv); - Int10Current->inb40time = (uint16_t) (tv.tv_usec | 1); - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" outb(%#x, %2.2x)\n", port, val); -#ifdef __NOT_YET__ - } - else if (port < 0x0100) { /* Don't interfere with mainboard */ - xf86DrvMsgVerb(Int10Current->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "outb 0x%4.4x,0x%2.2x\n", port, val); - if (xf86GetVerbosity() > 3) { - dump_registers(Int10Current); - stack_trace(Int10Current); - } -#endif /* __NOT_YET__ */ - } - else if (!pciCfg1outb(port, val)) { - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" outb(%#x, %2.2x)\n", port, val); - pci_io_write8(Int10Current->io, port, val); - } -} - -void -x_outw(uint16_t port, uint16_t val) -{ - - if (!pciCfg1outw(port, val)) { - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" outw(%#x, %4.4x)\n", port, val); - pci_io_write16(Int10Current->io, port, val); - } -} - -uint32_t -x_inl(uint16_t port) -{ - uint32_t val; - - if (!pciCfg1in(port, &val)) { - val = pci_io_read32(Int10Current->io, port); - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" inl(%#x) = %8.8" PRIx32 "\n", port, (unsigned) val); - } - return val; -} - -void -x_outl(uint16_t port, uint32_t val) -{ - if (!pciCfg1out(port, val)) { - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" outl(%#x, %8.8" PRIx32 ")\n", port, (unsigned) val); - pci_io_write32(Int10Current->io, port, val); - } -} - -uint8_t -Mem_rb(uint32_t addr) -{ - return (*Int10Current->mem->rb) (Int10Current, addr); -} - -uint16_t -Mem_rw(uint32_t addr) -{ - return (*Int10Current->mem->rw) (Int10Current, addr); -} - -uint32_t -Mem_rl(uint32_t addr) -{ - return (*Int10Current->mem->rl) (Int10Current, addr); -} - -void -Mem_wb(uint32_t addr, uint8_t val) -{ - (*Int10Current->mem->wb) (Int10Current, addr, val); -} - -void -Mem_ww(uint32_t addr, uint16_t val) -{ - (*Int10Current->mem->ww) (Int10Current, addr, val); -} - -void -Mem_wl(uint32_t addr, uint32_t val) -{ - (*Int10Current->mem->wl) (Int10Current, addr, val); -} - -static uint32_t PciCfg1Addr = 0; - -#define PCI_DOM_FROM_TAG(tag) (((tag) >> 24) & (PCI_DOM_MASK)) -#define PCI_BUS_FROM_TAG(tag) (((tag) >> 16) & (PCI_DOMBUS_MASK)) -#define PCI_DEV_FROM_TAG(tag) (((tag) & 0x0000f800u) >> 11) -#define PCI_FUNC_FROM_TAG(tag) (((tag) & 0x00000700u) >> 8) - -#define PCI_OFFSET(x) ((x) & 0x000000ff) -#define PCI_TAG(x) ((x) & 0x7fffff00) - -static struct pci_device * -pci_device_for_cfg_address(uint32_t addr) -{ - struct pci_device *dev = NULL; - uint32_t tag = PCI_TAG(addr); - - struct pci_slot_match slot_match = { - .domain = PCI_DOM_FROM_TAG(tag), - .bus = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(tag)), - .dev = PCI_DEV_FROM_TAG(tag), - .func = PCI_FUNC_FROM_TAG(tag), - .match_data = 0 - }; - - struct pci_device_iterator *iter = - pci_slot_match_iterator_create(&slot_match); - - if (iter) - dev = pci_device_next(iter); - - pci_iterator_destroy(iter); - - return dev; -} - -static int -pciCfg1in(uint16_t addr, uint32_t *val) -{ - if (addr == 0xCF8) { - *val = PciCfg1Addr; - return 1; - } - if (addr == 0xCFC) { - pci_device_cfg_read_u32(pci_device_for_cfg_address(PciCfg1Addr), - (uint32_t *) val, PCI_OFFSET(PciCfg1Addr)); - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" cfg_inl(%#" PRIx32 ") = %8.8" PRIx32 "\n", (unsigned) PciCfg1Addr, - (unsigned) *val); - return 1; - } - return 0; -} - -static int -pciCfg1out(uint16_t addr, uint32_t val) -{ - if (addr == 0xCF8) { - PciCfg1Addr = val; - return 1; - } - if (addr == 0xCFC) { - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" cfg_outl(%#" PRIx32 ", %8.8" PRIx32 ")\n", (unsigned) PciCfg1Addr, - (unsigned) val); - pci_device_cfg_write_u32(pci_device_for_cfg_address(PciCfg1Addr), val, - PCI_OFFSET(PciCfg1Addr)); - return 1; - } - return 0; -} - -static int -pciCfg1inw(uint16_t addr, uint16_t *val) -{ - int shift; - - if ((addr >= 0xCF8) && (addr <= 0xCFB)) { - shift = (addr - 0xCF8) * 8; - *val = (PciCfg1Addr >> shift) & 0xffff; - return 1; - } - if ((addr >= 0xCFC) && (addr <= 0xCFF)) { - const unsigned offset = addr - 0xCFC; - - pci_device_cfg_read_u16(pci_device_for_cfg_address(PciCfg1Addr), - val, PCI_OFFSET(PciCfg1Addr) + offset); - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" cfg_inw(%#" PRIx32 ") = %4.4x\n", (unsigned) (PciCfg1Addr + offset), - (unsigned) *val); - return 1; - } - return 0; -} - -static int -pciCfg1outw(uint16_t addr, uint16_t val) -{ - int shift; - - if ((addr >= 0xCF8) && (addr <= 0xCFB)) { - shift = (addr - 0xCF8) * 8; - PciCfg1Addr &= ~(0xffff << shift); - PciCfg1Addr |= ((uint32_t) val) << shift; - return 1; - } - if ((addr >= 0xCFC) && (addr <= 0xCFF)) { - const unsigned offset = addr - 0xCFC; - - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" cfg_outw(%#" PRIx32 ", %4.4x)\n", (unsigned) (PciCfg1Addr + offset), - (unsigned) val); - pci_device_cfg_write_u16(pci_device_for_cfg_address(PciCfg1Addr), val, - PCI_OFFSET(PciCfg1Addr) + offset); - return 1; - } - return 0; -} - -static int -pciCfg1inb(uint16_t addr, uint8_t *val) -{ - int shift; - - if ((addr >= 0xCF8) && (addr <= 0xCFB)) { - shift = (addr - 0xCF8) * 8; - *val = (PciCfg1Addr >> shift) & 0xff; - return 1; - } - if ((addr >= 0xCFC) && (addr <= 0xCFF)) { - const unsigned offset = addr - 0xCFC; - - pci_device_cfg_read_u8(pci_device_for_cfg_address(PciCfg1Addr), - val, PCI_OFFSET(PciCfg1Addr) + offset); - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" cfg_inb(%#" PRIx32 ") = %2.2x\n", (unsigned) (PciCfg1Addr + offset), - (unsigned) *val); - return 1; - } - return 0; -} - -static int -pciCfg1outb(uint16_t addr, uint8_t val) -{ - int shift; - - if ((addr >= 0xCF8) && (addr <= 0xCFB)) { - shift = (addr - 0xCF8) * 8; - PciCfg1Addr &= ~(0xff << shift); - PciCfg1Addr |= ((uint32_t) val) << shift; - return 1; - } - if ((addr >= 0xCFC) && (addr <= 0xCFF)) { - const unsigned offset = addr - 0xCFC; - - if (PRINT_PORT && DEBUG_IO_TRACE()) - ErrorF(" cfg_outb(%#" PRIx32 ", %2.2x)\n", (unsigned) (PciCfg1Addr + offset), - (unsigned) val); - pci_device_cfg_write_u8(pci_device_for_cfg_address(PciCfg1Addr), val, - PCI_OFFSET(PciCfg1Addr) + offset); - return 1; - } - return 0; -} - -uint8_t -bios_checksum(const uint8_t *start, int size) -{ - uint8_t sum = 0; - - while (size-- > 0) - sum += *start++; - return sum; -} - -/* - * Lock/Unlock legacy VGA. Some Bioses try to be very clever and make - * an attempt to detect a legacy ISA card. If they find one they might - * act very strange: for example they might configure the card as a - * monochrome card. This might cause some drivers to choke. - * To avoid this we attempt legacy VGA by writing to all known VGA - * disable registers before we call the BIOS initialization and - * restore the original values afterwards. In between we hold our - * breath. To get to a (possibly existing) ISA card need to disable - * our current PCI card. - */ -/* - * This is just for booting: we just want to catch pure - * legacy vga therefore we don't worry about mmio etc. - * This stuff should really go into vgaHW.c. However then - * the driver would have to load the vga-module prior to - * doing int10. - */ -void -LockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga) -{ - vga->save_msr = pci_io_read8(pInt->io, 0x03CC); - vga->save_vse = pci_io_read8(pInt->io, 0x03C3); -#ifndef __ia64__ - vga->save_46e8 = pci_io_read8(pInt->io, 0x46E8); -#endif - vga->save_pos102 = pci_io_read8(pInt->io, 0x0102); - pci_io_write8(pInt->io, 0x03C2, ~(uint8_t) 0x03 & vga->save_msr); - pci_io_write8(pInt->io, 0x03C3, ~(uint8_t) 0x01 & vga->save_vse); -#ifndef __ia64__ - pci_io_write8(pInt->io, 0x46E8, ~(uint8_t) 0x08 & vga->save_46e8); -#endif - pci_io_write8(pInt->io, 0x0102, ~(uint8_t) 0x01 & vga->save_pos102); -} - -void -UnlockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga) -{ - pci_io_write8(pInt->io, 0x0102, vga->save_pos102); -#ifndef __ia64__ - pci_io_write8(pInt->io, 0x46E8, vga->save_46e8); -#endif - pci_io_write8(pInt->io, 0x03C3, vga->save_vse); - pci_io_write8(pInt->io, 0x03C2, vga->save_msr); -} - -#if defined (_PC) -static void -SetResetBIOSVars(xf86Int10InfoPtr pInt, Bool set) -{ - int pagesize = getpagesize(); - unsigned char *base; - int i; - - if (pci_device_map_legacy - (pInt->dev, 0, pagesize, PCI_DEV_MAP_FLAG_WRITABLE, (void **) &base)) - return; /* eek */ - - if (set) { - for (i = BIOS_SCRATCH_OFF; i < BIOS_SCRATCH_END; i++) - MEM_WW(pInt, i, *(base + i)); - } - else { - for (i = BIOS_SCRATCH_OFF; i < BIOS_SCRATCH_END; i++) - *(base + i) = MEM_RW(pInt, i); - } - - pci_device_unmap_legacy(pInt->dev, base, pagesize); -} - -void -xf86Int10SaveRestoreBIOSVars(xf86Int10InfoPtr pInt, Bool save) -{ - int pagesize = getpagesize(); - unsigned char *base; - int i; - - if (!xf86IsEntityPrimary(pInt->entityIndex) - || (!save && !pInt->BIOSScratch)) - return; - - if (pci_device_map_legacy - (pInt->dev, 0, pagesize, PCI_DEV_MAP_FLAG_WRITABLE, (void **) &base)) - return; /* eek */ - - base += BIOS_SCRATCH_OFF; - if (save) { - if ((pInt->BIOSScratch = xnfalloc(BIOS_SCRATCH_LEN))) - for (i = 0; i < BIOS_SCRATCH_LEN; i++) - *(((char *) pInt->BIOSScratch + i)) = *(base + i); - } - else { - if (pInt->BIOSScratch) { - for (i = 0; i < BIOS_SCRATCH_LEN; i++) - *(base + i) = *(pInt->BIOSScratch + i); - free(pInt->BIOSScratch); - pInt->BIOSScratch = NULL; - } - } - - pci_device_unmap_legacy(pInt->dev, base - BIOS_SCRATCH_OFF, pagesize); -} -#endif - -xf86Int10InfoPtr -xf86InitInt10(int entityIndex) -{ - return xf86ExtendedInitInt10(entityIndex, 0); -} diff --git a/hw/xfree86/int10/helper_mem.c b/hw/xfree86/int10/helper_mem.c deleted file mode 100644 index 1b5960e0c..000000000 --- a/hw/xfree86/int10/helper_mem.c +++ /dev/null @@ -1,324 +0,0 @@ -/* - * XFree86 int10 module - * execute BIOS int 10h calls in x86 real mode environment - * Copyright 1999 Egbert Eich - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#include "xf86.h" -#include "xf86_OSproc.h" -#include "compiler.h" -#include "xf86Pci.h" -#define _INT10_PRIVATE -#if 0 -#include "int10Defines.h" -#endif -#include "xf86int10.h" - -#define REG pInt - -typedef enum { - OPT_NOINT10, - OPT_INIT_PRIMARY, -} INT10Opts; - -static const OptionInfoRec INT10Options[] = { - {OPT_NOINT10, "NoINT10", OPTV_BOOLEAN, {0}, FALSE}, - {OPT_INIT_PRIMARY, "InitPrimary", OPTV_BOOLEAN, {0}, FALSE}, - {-1, NULL, OPTV_NONE, {0}, FALSE}, -}; - -#ifdef DEBUG -void -dprint(unsigned long start, unsigned long size) -{ - int i, j; - char *c = (char *) start; - - for (j = 0; j < (size >> 4); j++) { - char *d = c; - - ErrorF("\n0x%lx: ", (unsigned long) c); - for (i = 0; i < 16; i++) - ErrorF("%2.2x ", (unsigned char) (*(c++))); - c = d; - for (i = 0; i < 16; i++) { - ErrorF("%c", ((((CARD8) (*c)) > 32) && (((CARD8) (*c)) < 128)) ? - (unsigned char) (*(c)) : '.'); - c++; - } - } - ErrorF("\n"); -} -#endif - -#ifndef _PC -/* - * here we are really paranoid about faking a "real" - * BIOS. Most of this information was pulled from - * dosemu. - */ -void -setup_int_vect(xf86Int10InfoPtr pInt) -{ - int i; - - /* let the int vects point to the SYS_BIOS seg */ - for (i = 0; i < 0x80; i++) { - MEM_WW(pInt, i << 2, 0); - MEM_WW(pInt, (i << 2) + 2, SYS_BIOS >> 4); - } - - reset_int_vect(pInt); - /* font tables default location (int 1F) */ - MEM_WW(pInt, 0x1f << 2, 0xfa6e); - - /* int 11 default location (Get Equipment Configuration) */ - MEM_WW(pInt, 0x11 << 2, 0xf84d); - /* int 12 default location (Get Conventional Memory Size) */ - MEM_WW(pInt, 0x12 << 2, 0xf841); - /* int 15 default location (I/O System Extensions) */ - MEM_WW(pInt, 0x15 << 2, 0xf859); - /* int 1A default location (RTC, PCI and others) */ - MEM_WW(pInt, 0x1a << 2, 0xff6e); - /* int 05 default location (Bound Exceeded) */ - MEM_WW(pInt, 0x05 << 2, 0xff54); - /* int 08 default location (Double Fault) */ - MEM_WW(pInt, 0x08 << 2, 0xfea5); - /* int 13 default location (Disk) */ - MEM_WW(pInt, 0x13 << 2, 0xec59); - /* int 0E default location (Page Fault) */ - MEM_WW(pInt, 0x0e << 2, 0xef57); - /* int 17 default location (Parallel Port) */ - MEM_WW(pInt, 0x17 << 2, 0xefd2); - /* fdd table default location (int 1e) */ - MEM_WW(pInt, 0x1e << 2, 0xefc7); - - /* Set Equipment flag to VGA */ - i = MEM_RB(pInt, 0x0410) & 0xCF; - MEM_WB(pInt, 0x0410, i); - /* XXX Perhaps setup more of the BDA here. See also int42(0x00). */ -} -#endif - -int -setup_system_bios(void *base_addr) -{ - char *base = (char *) base_addr; - - /* - * we trap the "industry standard entry points" to the BIOS - * and all other locations by filling them with "hlt" - * TODO: implement hlt-handler for these - */ - memset(base, 0xf4, 0x10000); - - /* set bios date */ - strcpy(base + 0x0FFF5, "06/11/99"); - /* set up eisa ident string */ - strcpy(base + 0x0FFD9, "PCI_ISA"); - /* write system model id for IBM-AT */ - *((unsigned char *) (base + 0x0FFFE)) = 0xfc; - - return 1; -} - -void -reset_int_vect(xf86Int10InfoPtr pInt) -{ - /* - * This table is normally located at 0xF000:0xF0A4. However, int 0x42, - * function 0 (Mode Set) expects it (or a copy) somewhere in the bottom - * 64kB. Note that because this data doesn't survive POST, int 0x42 should - * only be used during EGA/VGA BIOS initialisation. - */ - static const CARD8 VideoParms[] = { - /* Timing for modes 0x00 & 0x01 */ - 0x38, 0x28, 0x2d, 0x0a, 0x1f, 0x06, 0x19, 0x1c, - 0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, - /* Timing for modes 0x02 & 0x03 */ - 0x71, 0x50, 0x5a, 0x0a, 0x1f, 0x06, 0x19, 0x1c, - 0x02, 0x07, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, - /* Timing for modes 0x04, 0x05 & 0x06 */ - 0x38, 0x28, 0x2d, 0x0a, 0x7f, 0x06, 0x64, 0x70, - 0x02, 0x01, 0x06, 0x07, 0x00, 0x00, 0x00, 0x00, - /* Timing for mode 0x07 */ - 0x61, 0x50, 0x52, 0x0f, 0x19, 0x06, 0x19, 0x19, - 0x02, 0x0d, 0x0b, 0x0c, 0x00, 0x00, 0x00, 0x00, - /* Display page lengths in little endian order */ - 0x00, 0x08, /* Modes 0x00 and 0x01 */ - 0x00, 0x10, /* Modes 0x02 and 0x03 */ - 0x00, 0x40, /* Modes 0x04 and 0x05 */ - 0x00, 0x40, /* Modes 0x06 and 0x07 */ - /* Number of columns for each mode */ - 40, 40, 80, 80, 40, 40, 80, 80, - /* CGA Mode register value for each mode */ - 0x2c, 0x28, 0x2d, 0x29, 0x2a, 0x2e, 0x1e, 0x29, - /* Padding */ - 0x00, 0x00, 0x00, 0x00 - }; - int i; - - for (i = 0; i < sizeof(VideoParms); i++) - MEM_WB(pInt, i + (0x1000 - sizeof(VideoParms)), VideoParms[i]); - MEM_WW(pInt, 0x1d << 2, 0x1000 - sizeof(VideoParms)); - MEM_WW(pInt, (0x1d << 2) + 2, 0); - - MEM_WW(pInt, 0x10 << 2, 0xf065); - MEM_WW(pInt, (0x10 << 2) + 2, SYS_BIOS >> 4); - MEM_WW(pInt, 0x42 << 2, 0xf065); - MEM_WW(pInt, (0x42 << 2) + 2, SYS_BIOS >> 4); - MEM_WW(pInt, 0x6D << 2, 0xf065); - MEM_WW(pInt, (0x6D << 2) + 2, SYS_BIOS >> 4); -} - -void -set_return_trap(xf86Int10InfoPtr pInt) -{ - /* - * Here we set the exit condition: We return when we encounter - * 'hlt' (=0xf4), which we locate at address 0x600 in x86 memory. - */ - MEM_WB(pInt, 0x0600, 0xf4); - - /* - * Allocate a segment for the stack - */ - xf86Int10AllocPages(pInt, 1, &pInt->stackseg); -} - -void * -xf86HandleInt10Options(ScrnInfoPtr pScrn, int entityIndex) -{ - EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex); - OptionInfoPtr options = NULL; - - if (pEnt->device) { - void *configOptions = NULL; - - /* Check if xf86CollectOptions() has already been called */ - if (((pEnt->index < 0) || - !pScrn || !(configOptions = pScrn->options)) && pEnt->device) - configOptions = pEnt->device->options; - - if (configOptions) { - if (!(options = (OptionInfoPtr) malloc(sizeof(INT10Options)))) - return NULL; - - (void) memcpy(options, INT10Options, sizeof(INT10Options)); - xf86ProcessOptions(pScrn->scrnIndex, configOptions, options); - } - } - free(pEnt); - - return options; -} - -Bool -int10skip(const void *options) -{ - Bool noint10 = FALSE; - - if (!options) - return FALSE; - - xf86GetOptValBool(options, OPT_NOINT10, &noint10); - return noint10; -} - -Bool -int10_check_bios(int scrnIndex, int codeSeg, const unsigned char *vbiosMem) -{ - int size; - - if ((codeSeg & 0x1f) || /* Not 512-byte aligned otherwise */ - ((codeSeg << 4) < V_BIOS) || ((codeSeg << 4) >= SYS_SIZE)) - return FALSE; - - if ((*vbiosMem != 0x55) || (*(vbiosMem + 1) != 0xAA) || !*(vbiosMem + 2)) - return FALSE; - - size = *(vbiosMem + 2) * 512; - - if ((size + (codeSeg << 4)) > SYS_SIZE) - return FALSE; - - if (bios_checksum(vbiosMem, size)) - xf86DrvMsg(scrnIndex, X_INFO, "Bad V_BIOS checksum\n"); - - return TRUE; -} - -Bool -initPrimary(const void *options) -{ - Bool initPrimary = FALSE; - - if (!options) - return FALSE; - - xf86GetOptValBool(options, OPT_INIT_PRIMARY, &initPrimary); - return initPrimary; -} - -BusType -xf86int10GetBiosLocationType(const xf86Int10InfoPtr pInt) -{ - BusType location_type; - - EntityInfoPtr pEnt = xf86GetEntityInfo(pInt->entityIndex); - - location_type = pEnt->location.type; - free(pEnt); - - return location_type; -} - -#define CHECK_V_SEGMENT_RANGE(x) \ - if (((x) << 4) < V_BIOS) { \ - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, \ - "V_BIOS address 0x%lx out of range\n", \ - (unsigned long)(x) << 4); \ - return FALSE; \ - } - -Bool -xf86int10GetBiosSegment(xf86Int10InfoPtr pInt, void *base) -{ - unsigned i; - int cs = ~0; - int segments[4]; - - segments[0] = MEM_RW(pInt, (0x10 << 2) + 2); - segments[1] = MEM_RW(pInt, (0x42 << 2) + 2); - segments[2] = V_BIOS >> 4; - segments[3] = ~0; - - for (i = 0; segments[i] != ~0; i++) { - unsigned char *vbiosMem; - - cs = segments[i]; - - CHECK_V_SEGMENT_RANGE(cs); - vbiosMem = (unsigned char *) base + (cs << 4); - if (int10_check_bios(pInt->pScrn->scrnIndex, cs, vbiosMem)) { - break; - } - } - - if (segments[i] == ~0) { - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "No V_BIOS found\n"); - return FALSE; - } - - xf86DrvMsg(pInt->pScrn->scrnIndex, X_INFO, "Primary V_BIOS segment is: 0x%lx\n", - (unsigned long) cs); - - pInt->BIOSseg = cs; - return TRUE; -} diff --git a/hw/xfree86/int10/meson.build b/hw/xfree86/int10/meson.build deleted file mode 100644 index a309e9b53..000000000 --- a/hw/xfree86/int10/meson.build +++ /dev/null @@ -1,64 +0,0 @@ -srcs_xorg_int10 = [ - 'vbe.c', - 'vbeModes.c', - 'helper_exec.c', - 'helper_mem.c', - 'xf86int10.c', - 'xf86int10module.c', -] - -int10_c_args = [xorg_c_args] -int10_link = [] - -if host_machine.cpu() == 'i386' or host_machine.cpu() == 'x86_64' - int10_c_args += '-D_PC' -endif - -if int10 == 'stub' - srcs_xorg_int10 += 'stub.c' - int10_c_args += '-D_VM86_LINUX' -endif - -if int10 == 'x86emu' - srcs_xorg_int10 += [ - 'generic.c', - 'xf86x86emu.c', - 'x86emu.c', - ] - int10_c_args += '-D_X86EMU' - int10_c_args += '-DNO_SYS_HEADERS' - - # Silence some useless warnings from x86emu - if cc.has_argument('-Wno-format-nonliteral') - int10_c_args += '-Wno-format-nonliteral' - endif - - int10_link += xorg_x86emu -endif - -if int10 == 'vm86' - srcs_xorg_int10 += [ - 'vm86/linux_vm86.c', - 'linux.c', - ] - int10_c_args += '-D_VM86_LINUX' -endif - -xorg_int10 = shared_module('int10', - srcs_xorg_int10, - include_directories: [ - inc, - xorg_inc, - include_directories('../x86emu') - ], - dependencies: common_dep, - link_with: int10_link, - c_args: int10_c_args, - - install: true, - install_dir: module_dir, -) - -install_data('xf86int10.h', install_dir: xorgsdkdir) -install_data('vbe.h', install_dir: xorgsdkdir) -install_data('vbeModes.h', install_dir: xorgsdkdir) diff --git a/hw/xfree86/int10/stub.c b/hw/xfree86/int10/stub.c deleted file mode 100644 index 4bbcddeda..000000000 --- a/hw/xfree86/int10/stub.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * XFree86 int10 module - * execute BIOS int 10h calls in x86 real mode environment - * Copyright 1999 Egbert Eich - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86str.h" -#include "xf86_OSproc.h" -#define _INT10_PRIVATE -#include "xf86int10.h" - -xf86Int10InfoPtr -xf86InitInt10(int entityIndex) -{ - return xf86ExtendedInitInt10(entityIndex, 0); -} - -xf86Int10InfoPtr -xf86ExtendedInitInt10(int entityIndex, int Flags) -{ - return NULL; -} - -Bool -MapCurrentInt10(xf86Int10InfoPtr pInt) -{ - return FALSE; -} - -void -xf86FreeInt10(xf86Int10InfoPtr pInt) -{ - return; -} - -void * -xf86Int10AllocPages(xf86Int10InfoPtr pInt, int num, int *off) -{ - *off = 0; - return NULL; -} - -void -xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num) -{ - return; -} - -Bool -xf86Int10ExecSetup(xf86Int10InfoPtr pInt) -{ - return FALSE; -} - -void -xf86ExecX86int10(xf86Int10InfoPtr pInt) -{ - return; -} - -void * -xf86int10Addr(xf86Int10InfoPtr pInt, uint32_t addr) -{ - return 0; -} diff --git a/hw/xfree86/int10/vbe.c b/hw/xfree86/int10/vbe.c deleted file mode 100644 index 26efdd76e..000000000 --- a/hw/xfree86/int10/vbe.c +++ /dev/null @@ -1,1096 +0,0 @@ - -/* - * XFree86 vbe module - * Copyright 2000 Egbert Eich - * - * The mode query/save/set/restore functions from the vesa driver - * have been moved here. - * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com) - * Authors: Paulo César Pereira de Andrade - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "xf86.h" -#include "xf86Modes.h" -#include "vbe.h" -#include - -#define VERSION(x) VBE_VERSION_MAJOR(x),VBE_VERSION_MINOR(x) - -#if X_BYTE_ORDER == X_LITTLE_ENDIAN -#define B_O16(x) (x) -#define B_O32(x) (x) -#else -#define B_O16(x) ((((x) & 0xff) << 8) | (((x) & 0xff) >> 8)) -#define B_O32(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) \ - | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24)) -#endif -#define L_ADD(x) (B_O32(x) & 0xffff) + ((B_O32(x) >> 12) & 0xffff00) - -#define FARP(p) (((unsigned)(p & 0xffff0000) >> 12) | (p & 0xffff)) -#define R16(v) ((v) & 0xffff) - -static unsigned char *vbeReadEDID(vbeInfoPtr pVbe); -static Bool vbeProbeDDC(vbeInfoPtr pVbe); - -static const char vbeVersionString[] = "VBE2"; - -vbeInfoPtr -VBEInit(xf86Int10InfoPtr pInt, int entityIndex) -{ - return VBEExtendedInit(pInt, entityIndex, 0); -} - -vbeInfoPtr -VBEExtendedInit(xf86Int10InfoPtr pInt, int entityIndex, int Flags) -{ - int RealOff; - void *page = NULL; - ScrnInfoPtr pScrn = xf86FindScreenForEntity(entityIndex); - vbeControllerInfoPtr vbe = NULL; - Bool init_int10 = FALSE; - vbeInfoPtr vip = NULL; - int screen; - - if (!pScrn) - return NULL; - screen = pScrn->scrnIndex; - - if (!pInt) { - if (!xf86LoadSubModule(pScrn, "int10")) - goto error; - - xf86DrvMsg(screen, X_INFO, "initializing int10\n"); - pInt = xf86ExtendedInitInt10(entityIndex, Flags); - if (!pInt) - goto error; - init_int10 = TRUE; - } - - page = xf86Int10AllocPages(pInt, 1, &RealOff); - if (!page) - goto error; - vbe = (vbeControllerInfoPtr) page; - memcpy(vbe->VbeSignature, vbeVersionString, 4); - - pInt->ax = 0x4F00; - pInt->es = SEG_ADDR(RealOff); - pInt->di = SEG_OFF(RealOff); - pInt->num = 0x10; - - xf86ExecX86int10(pInt); - - if ((pInt->ax & 0xff) != 0x4f) { - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA BIOS not detected\n"); - goto error; - } - - switch (pInt->ax & 0xff00) { - case 0: - xf86DrvMsg(screen, X_INFO, "VESA BIOS detected\n"); - break; - case 0x100: - xf86DrvMsg(screen, X_INFO, "VESA BIOS function failed\n"); - goto error; - case 0x200: - xf86DrvMsg(screen, X_INFO, "VESA BIOS not supported\n"); - goto error; - case 0x300: - xf86DrvMsg(screen, X_INFO, "VESA BIOS not supported in current mode\n"); - goto error; - default: - xf86DrvMsg(screen, X_INFO, "Invalid\n"); - goto error; - } - - xf86DrvMsgVerb(screen, X_INFO, 4, - "VbeVersion is %d, OemStringPtr is 0x%08lx,\n" - "\tOemVendorNamePtr is 0x%08lx, OemProductNamePtr is 0x%08lx,\n" - "\tOemProductRevPtr is 0x%08lx\n", - vbe->VbeVersion, (unsigned long) vbe->OemStringPtr, - (unsigned long) vbe->OemVendorNamePtr, - (unsigned long) vbe->OemProductNamePtr, - (unsigned long) vbe->OemProductRevPtr); - - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE Version %i.%i\n", - VERSION(vbe->VbeVersion)); - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE Total Mem: %i kB\n", - vbe->TotalMem * 64); - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE OEM: %s\n", - (CARD8 *) xf86int10Addr(pInt, L_ADD(vbe->OemStringPtr))); - - if (B_O16(vbe->VbeVersion) >= 0x200) { - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE OEM Software Rev: %i.%i\n", - VERSION(vbe->OemSoftwareRev)); - if (vbe->OemVendorNamePtr) - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE OEM Vendor: %s\n", - (CARD8 *) xf86int10Addr(pInt, - L_ADD(vbe-> - OemVendorNamePtr))); - if (vbe->OemProductNamePtr) - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE OEM Product: %s\n", - (CARD8 *) xf86int10Addr(pInt, - L_ADD(vbe-> - OemProductNamePtr))); - if (vbe->OemProductRevPtr) - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE OEM Product Rev: %s\n", - (CARD8 *) xf86int10Addr(pInt, - L_ADD(vbe-> - OemProductRevPtr))); - } - vip = (vbeInfoPtr) xnfalloc(sizeof(vbeInfoRec)); - vip->version = B_O16(vbe->VbeVersion); - vip->pInt10 = pInt; - vip->ddc = DDC_UNCHECKED; - vip->memory = page; - vip->real_mode_base = RealOff; - vip->num_pages = 1; - vip->init_int10 = init_int10; - - return vip; - - error: - if (page) - xf86Int10FreePages(pInt, page, 1); - if (init_int10) - xf86FreeInt10(pInt); - return NULL; -} - -void -vbeFree(vbeInfoPtr pVbe) -{ - if (!pVbe) - return; - - xf86Int10FreePages(pVbe->pInt10, pVbe->memory, pVbe->num_pages); - /* If we have initialized int10 we ought to free it, too */ - if (pVbe->init_int10) - xf86FreeInt10(pVbe->pInt10); - free(pVbe); - return; -} - -static Bool -vbeProbeDDC(vbeInfoPtr pVbe) -{ - const char *ddc_level; - int screen = pVbe->pInt10->pScrn->scrnIndex; - - if (pVbe->ddc == DDC_NONE) - return FALSE; - if (pVbe->ddc != DDC_UNCHECKED) - return TRUE; - - pVbe->pInt10->ax = 0x4F15; - pVbe->pInt10->bx = 0; - pVbe->pInt10->cx = 0; - pVbe->pInt10->es = 0; - pVbe->pInt10->di = 0; - pVbe->pInt10->num = 0x10; - - xf86ExecX86int10(pVbe->pInt10); - - if ((pVbe->pInt10->ax & 0xff) != 0x4f) { - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE DDC not supported\n"); - pVbe->ddc = DDC_NONE; - return FALSE; - } - - switch ((pVbe->pInt10->ax >> 8) & 0xff) { - case 0: - xf86DrvMsg(screen, X_INFO, "VESA VBE DDC supported\n"); - switch (pVbe->pInt10->bx & 0x3) { - case 0: - ddc_level = " none"; - pVbe->ddc = DDC_NONE; - break; - case 1: - ddc_level = " 1"; - pVbe->ddc = DDC_1; - break; - case 2: - ddc_level = " 2"; - pVbe->ddc = DDC_2; - break; - case 3: - ddc_level = " 1 + 2"; - pVbe->ddc = DDC_1_2; - break; - default: - ddc_level = ""; - pVbe->ddc = DDC_NONE; - break; - } - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE DDC Level%s\n", ddc_level); - if (pVbe->pInt10->bx & 0x4) { - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE DDC Screen blanked" - "for data transfer\n"); - pVbe->ddc_blank = TRUE; - } - else - pVbe->ddc_blank = FALSE; - - xf86DrvMsgVerb(screen, X_INFO, 3, - "VESA VBE DDC transfer in appr. %x sec.\n", - (pVbe->pInt10->bx >> 8) & 0xff); - } - - return TRUE; -} - -typedef enum { - VBEOPT_NOVBE, - VBEOPT_NODDC -} VBEOpts; - -static const OptionInfoRec VBEOptions[] = { - {VBEOPT_NOVBE, "NoVBE", OPTV_BOOLEAN, {0}, FALSE}, - {VBEOPT_NODDC, "NoDDC", OPTV_BOOLEAN, {0}, FALSE}, - {-1, NULL, OPTV_NONE, {0}, FALSE}, -}; - -static unsigned char * -vbeReadEDID(vbeInfoPtr pVbe) -{ - int RealOff = pVbe->real_mode_base; - void *page = pVbe->memory; - unsigned char *tmp = NULL; - Bool novbe = FALSE; - Bool noddc = FALSE; - ScrnInfoPtr pScrn = pVbe->pInt10->pScrn; - int screen = pScrn->scrnIndex; - OptionInfoPtr options; - - if (!page) - return NULL; - - options = xnfalloc(sizeof(VBEOptions)); - (void) memcpy(options, VBEOptions, sizeof(VBEOptions)); - xf86ProcessOptions(screen, pScrn->options, options); - xf86GetOptValBool(options, VBEOPT_NOVBE, &novbe); - xf86GetOptValBool(options, VBEOPT_NODDC, &noddc); - free(options); - if (novbe || noddc) - return NULL; - - if (!vbeProbeDDC(pVbe)) - goto error; - - memset(page, 0, sizeof(vbeInfoPtr)); - strcpy(page, vbeVersionString); - - pVbe->pInt10->ax = 0x4F15; - pVbe->pInt10->bx = 0x01; - pVbe->pInt10->cx = 0; - pVbe->pInt10->dx = 0; - pVbe->pInt10->es = SEG_ADDR(RealOff); - pVbe->pInt10->di = SEG_OFF(RealOff); - pVbe->pInt10->num = 0x10; - - xf86ExecX86int10(pVbe->pInt10); - - if ((pVbe->pInt10->ax & 0xff) != 0x4f) { - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE DDC invalid\n"); - goto error; - } - switch (pVbe->pInt10->ax & 0xff00) { - case 0x0: - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE DDC read successfully\n"); - tmp = (unsigned char *) xnfalloc(128); - memcpy(tmp, page, 128); - break; - case 0x100: - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE DDC read failed\n"); - break; - default: - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE DDC unknown failure %i\n", - pVbe->pInt10->ax & 0xff00); - break; - } - - error: - return tmp; -} - -xf86MonPtr -vbeDoEDID(vbeInfoPtr pVbe, void *unused) -{ - unsigned char *DDC_data = NULL; - - if (!pVbe) - return NULL; - if (pVbe->version < 0x102) - return NULL; - - DDC_data = vbeReadEDID(pVbe); - - if (!DDC_data) - return NULL; - - return xf86InterpretEDID(pVbe->pInt10->pScrn->scrnIndex, DDC_data); -} - -#define GET_UNALIGNED2(x) \ - ((*(CARD16*)(x)) | (*(((CARD16*)(x) + 1))) << 16) - -VbeInfoBlock * -VBEGetVBEInfo(vbeInfoPtr pVbe) -{ - VbeInfoBlock *block = NULL; - int i, pStr, pModes; - char *str; - CARD16 major, *modes; - - memset(pVbe->memory, 0, sizeof(VbeInfoBlock)); - - /* - Input: - AH := 4Fh Super VGA support - AL := 00h Return Super VGA information - ES:DI := Pointer to buffer - - Output: - AX := status - (All other registers are preserved) - */ - - ((char *) pVbe->memory)[0] = 'V'; - ((char *) pVbe->memory)[1] = 'B'; - ((char *) pVbe->memory)[2] = 'E'; - ((char *) pVbe->memory)[3] = '2'; - - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f00; - pVbe->pInt10->es = SEG_ADDR(pVbe->real_mode_base); - pVbe->pInt10->di = SEG_OFF(pVbe->real_mode_base); - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) != 0x4f) - return NULL; - - block = calloc(sizeof(VbeInfoBlock), 1); - block->VESASignature[0] = ((char *) pVbe->memory)[0]; - block->VESASignature[1] = ((char *) pVbe->memory)[1]; - block->VESASignature[2] = ((char *) pVbe->memory)[2]; - block->VESASignature[3] = ((char *) pVbe->memory)[3]; - - block->VESAVersion = *(CARD16 *) (((char *) pVbe->memory) + 4); - major = (unsigned) block->VESAVersion >> 8; - - pStr = GET_UNALIGNED2((((char *) pVbe->memory) + 6)); - str = xf86int10Addr(pVbe->pInt10, FARP(pStr)); - block->OEMStringPtr = strdup(str); - - block->Capabilities[0] = ((char *) pVbe->memory)[10]; - block->Capabilities[1] = ((char *) pVbe->memory)[11]; - block->Capabilities[2] = ((char *) pVbe->memory)[12]; - block->Capabilities[3] = ((char *) pVbe->memory)[13]; - - pModes = GET_UNALIGNED2((((char *) pVbe->memory) + 14)); - modes = xf86int10Addr(pVbe->pInt10, FARP(pModes)); - i = 0; - while (modes[i] != 0xffff) - i++; - block->VideoModePtr = xallocarray(i + 1, sizeof(CARD16)); - memcpy(block->VideoModePtr, modes, sizeof(CARD16) * i); - block->VideoModePtr[i] = 0xffff; - - block->TotalMemory = *(CARD16 *) (((char *) pVbe->memory) + 18); - - if (major < 2) - memcpy(&block->OemSoftwareRev, ((char *) pVbe->memory) + 20, 236); - else { - block->OemSoftwareRev = *(CARD16 *) (((char *) pVbe->memory) + 20); - pStr = GET_UNALIGNED2((((char *) pVbe->memory) + 22)); - str = xf86int10Addr(pVbe->pInt10, FARP(pStr)); - block->OemVendorNamePtr = strdup(str); - pStr = GET_UNALIGNED2((((char *) pVbe->memory) + 26)); - str = xf86int10Addr(pVbe->pInt10, FARP(pStr)); - block->OemProductNamePtr = strdup(str); - pStr = GET_UNALIGNED2((((char *) pVbe->memory) + 30)); - str = xf86int10Addr(pVbe->pInt10, FARP(pStr)); - block->OemProductRevPtr = strdup(str); - memcpy(&block->Reserved, ((char *) pVbe->memory) + 34, 222); - memcpy(&block->OemData, ((char *) pVbe->memory) + 256, 256); - } - - return block; -} - -void -VBEFreeVBEInfo(VbeInfoBlock * block) -{ - free(block->OEMStringPtr); - free(block->VideoModePtr); - if (((unsigned) block->VESAVersion >> 8) >= 2) { - free(block->OemVendorNamePtr); - free(block->OemProductNamePtr); - free(block->OemProductRevPtr); - } - free(block); -} - -Bool -VBESetVBEMode(vbeInfoPtr pVbe, int mode, VbeCRTCInfoBlock * block) -{ - /* - Input: - AH := 4Fh Super VGA support - AL := 02h Set Super VGA video mode - BX := Video mode - D0-D8 := Mode number - D9-D10 := Reserved (must be 0) - D11 := 0 Use current default refresh rate - := 1 Use user specified CRTC values for refresh rate - D12-13 Reserved for VBE/AF (must be 0) - D14 := 0 Use windowed frame buffer model - := 1 Use linear/flat frame buffer model - D15 := 0 Clear video memory - := 1 Don't clear video memory - ES:DI := Pointer to VbeCRTCInfoBlock structure - - Output: AX = Status - (All other registers are preserved) - */ - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f02; - pVbe->pInt10->bx = mode; - if (block) { - pVbe->pInt10->bx |= 1 << 11; - memcpy(pVbe->memory, block, sizeof(VbeCRTCInfoBlock)); - pVbe->pInt10->es = SEG_ADDR(pVbe->real_mode_base); - pVbe->pInt10->di = SEG_OFF(pVbe->real_mode_base); - } - else - pVbe->pInt10->bx &= ~(1 << 11); - - xf86ExecX86int10(pVbe->pInt10); - - return (R16(pVbe->pInt10->ax) == 0x4f); -} - -Bool -VBEGetVBEMode(vbeInfoPtr pVbe, int *mode) -{ - /* - Input: - AH := 4Fh Super VGA support - AL := 03h Return current video mode - - Output: - AX := Status - BX := Current video mode - (All other registers are preserved) - */ - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f03; - - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) == 0x4f) { - *mode = R16(pVbe->pInt10->bx); - - return TRUE; - } - - return FALSE; -} - -VbeModeInfoBlock * -VBEGetModeInfo(vbeInfoPtr pVbe, int mode) -{ - VbeModeInfoBlock *block = NULL; - - memset(pVbe->memory, 0, sizeof(VbeModeInfoBlock)); - - /* - Input: - AH := 4Fh Super VGA support - AL := 01h Return Super VGA mode information - CX := Super VGA video mode - (mode number must be one of those returned by Function 0) - ES:DI := Pointer to buffer - - Output: - AX := status - (All other registers are preserved) - */ - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f01; - pVbe->pInt10->cx = mode; - pVbe->pInt10->es = SEG_ADDR(pVbe->real_mode_base); - pVbe->pInt10->di = SEG_OFF(pVbe->real_mode_base); - xf86ExecX86int10(pVbe->pInt10); - if (R16(pVbe->pInt10->ax) != 0x4f) - return NULL; - - block = malloc(sizeof(VbeModeInfoBlock)); - if (block) - memcpy(block, pVbe->memory, sizeof(*block)); - - return block; -} - -void -VBEFreeModeInfo(VbeModeInfoBlock * block) -{ - free(block); -} - -Bool -VBESaveRestore(vbeInfoPtr pVbe, vbeSaveRestoreFunction function, - void **memory, int *size, int *real_mode_pages) -{ - /* - Input: - AH := 4Fh Super VGA support - AL := 04h Save/restore Super VGA video state - DL := 00h Return save/restore state buffer size - CX := Requested states - D0 = Save/restore video hardware state - D1 = Save/restore video BIOS data state - D2 = Save/restore video DAC state - D3 = Save/restore Super VGA state - - Output: - AX = Status - BX = Number of 64-byte blocks to hold the state buffer - (All other registers are preserved) - - Input: - AH := 4Fh Super VGA support - AL := 04h Save/restore Super VGA video state - DL := 01h Save Super VGA video state - CX := Requested states (see above) - ES:BX := Pointer to buffer - - Output: - AX := Status - (All other registers are preserved) - - Input: - AH := 4Fh Super VGA support - AL := 04h Save/restore Super VGA video state - DL := 02h Restore Super VGA video state - CX := Requested states (see above) - ES:BX := Pointer to buffer - - Output: - AX := Status - (All other registers are preserved) - */ - - if ((pVbe->version & 0xff00) > 0x100) { - int screen = pVbe->pInt10->pScrn->scrnIndex; - - if (function == MODE_QUERY || (function == MODE_SAVE && !*memory)) { - /* Query amount of memory to save state */ - - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f04; - pVbe->pInt10->dx = 0; - pVbe->pInt10->cx = 0x000f; - xf86ExecX86int10(pVbe->pInt10); - if (R16(pVbe->pInt10->ax) != 0x4f) - return FALSE; - - if (function == MODE_SAVE) { - int npages = (R16(pVbe->pInt10->bx) * 64) / 4096 + 1; - - if ((*memory = xf86Int10AllocPages(pVbe->pInt10, npages, - real_mode_pages)) == NULL) { - xf86DrvMsg(screen, X_ERROR, - "Cannot allocate memory to save SVGA state.\n"); - return FALSE; - } - } - *size = pVbe->pInt10->bx * 64; - } - - /* Save/Restore Super VGA state */ - if (function != MODE_QUERY) { - - if (!*memory) - return FALSE; - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f04; - switch (function) { - case MODE_SAVE: - pVbe->pInt10->dx = 1; - break; - case MODE_RESTORE: - pVbe->pInt10->dx = 2; - break; - case MODE_QUERY: - return FALSE; - } - pVbe->pInt10->cx = 0x000f; - - pVbe->pInt10->es = SEG_ADDR(*real_mode_pages); - pVbe->pInt10->bx = SEG_OFF(*real_mode_pages); - xf86ExecX86int10(pVbe->pInt10); - return (R16(pVbe->pInt10->ax) == 0x4f); - - } - } - return TRUE; -} - -Bool -VBEBankSwitch(vbeInfoPtr pVbe, unsigned int iBank, int window) -{ - /* - Input: - AH := 4Fh Super VGA support - AL := 05h - - Output: - */ - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f05; - pVbe->pInt10->bx = window; - pVbe->pInt10->dx = iBank; - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) != 0x4f) - return FALSE; - - return TRUE; -} - -Bool -VBESetGetLogicalScanlineLength(vbeInfoPtr pVbe, vbeScanwidthCommand command, - int width, int *pixels, int *bytes, int *max) -{ - if (command < SCANWID_SET || command > SCANWID_GET_MAX) - return FALSE; - - /* - Input: - AX := 4F06h VBE Set/Get Logical Scan Line Length - BL := 00h Set Scan Line Length in Pixels - := 01h Get Scan Line Length - := 02h Set Scan Line Length in Bytes - := 03h Get Maximum Scan Line Length - CX := If BL=00h Desired Width in Pixels - If BL=02h Desired Width in Bytes - (Ignored for Get Functions) - - Output: - AX := VBE Return Status - BX := Bytes Per Scan Line - CX := Actual Pixels Per Scan Line - (truncated to nearest complete pixel) - DX := Maximum Number of Scan Lines - */ - - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f06; - pVbe->pInt10->bx = command; - if (command == SCANWID_SET || command == SCANWID_SET_BYTES) - pVbe->pInt10->cx = width; - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) != 0x4f) - return FALSE; - - if (command == SCANWID_GET || command == SCANWID_GET_MAX) { - if (pixels) - *pixels = R16(pVbe->pInt10->cx); - if (bytes) - *bytes = R16(pVbe->pInt10->bx); - if (max) - *max = R16(pVbe->pInt10->dx); - } - - return TRUE; -} - -Bool -VBESetDisplayStart(vbeInfoPtr pVbe, int x, int y, Bool wait_retrace) -{ - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f07; - pVbe->pInt10->bx = wait_retrace ? 0x80 : 0x00; - pVbe->pInt10->cx = x; - pVbe->pInt10->dx = y; - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) != 0x4f) - return FALSE; - - return TRUE; -} - -Bool -VBEGetDisplayStart(vbeInfoPtr pVbe, int *x, int *y) -{ - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f07; - pVbe->pInt10->bx = 0x01; - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) != 0x4f) - return FALSE; - - *x = pVbe->pInt10->cx; - *y = pVbe->pInt10->dx; - - return TRUE; -} - -int -VBESetGetDACPaletteFormat(vbeInfoPtr pVbe, int bits) -{ - /* - Input: - AX := 4F08h VBE Set/Get Palette Format - BL := 00h Set DAC Palette Format - := 01h Get DAC Palette Format - BH := Desired bits of color per primary - (Set DAC Palette Format only) - - Output: - AX := VBE Return Status - BH := Current number of bits of color per primary - */ - - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f08; - if (!bits) - pVbe->pInt10->bx = 0x01; - else - pVbe->pInt10->bx = (bits & 0x00ff) << 8; - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) != 0x4f) - return 0; - - return (bits != 0 ? bits : (pVbe->pInt10->bx >> 8) & 0x00ff); -} - -CARD32 * -VBESetGetPaletteData(vbeInfoPtr pVbe, Bool set, int first, int num, - CARD32 *data, Bool secondary, Bool wait_retrace) -{ - /* - Input: - (16-bit) - AX := 4F09h VBE Load/Unload Palette Data - BL := 00h Set Palette Data - := 01h Get Palette Data - := 02h Set Secondary Palette Data - := 03h Get Secondary Palette Data - := 80h Set Palette Data during Vertical Retrace - CX := Number of palette registers to update (to a maximum of 256) - DX := First of the palette registers to update (start) - ES:DI := Table of palette values (see below for format) - - Output: - AX := VBE Return Status - - Input: - (32-bit) - BL := 00h Set Palette Data - := 80h Set Palette Data during Vertical Retrace - CX := Number of palette registers to update (to a maximum of 256) - DX := First of the palette registers to update (start) - ES:EDI := Table of palette values (see below for format) - DS := Selector for memory mapped registers - */ - - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f09; - if (!secondary) - pVbe->pInt10->bx = set && wait_retrace ? 0x80 : set ? 0 : 1; - else - pVbe->pInt10->bx = set ? 2 : 3; - pVbe->pInt10->cx = num; - pVbe->pInt10->dx = first; - pVbe->pInt10->es = SEG_ADDR(pVbe->real_mode_base); - pVbe->pInt10->di = SEG_OFF(pVbe->real_mode_base); - if (set) - memcpy(pVbe->memory, data, num * sizeof(CARD32)); - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) != 0x4f) - return NULL; - - if (set) - return data; - - data = xallocarray(num, sizeof(CARD32)); - memcpy(data, pVbe->memory, num * sizeof(CARD32)); - - return data; -} - -VBEpmi * -VBEGetVBEpmi(vbeInfoPtr pVbe) -{ - VBEpmi *pmi; - - /* - Input: - AH := 4Fh Super VGA support - AL := 0Ah Protected Mode Interface - BL := 00h Return Protected Mode Table - - Output: - AX := Status - ES := Real Mode Segment of Table - DI := Offset of Table - CX := Length of Table including protected mode code in bytes (for copying purposes) - (All other registers are preserved) - */ - - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f0a; - pVbe->pInt10->bx = 0; - pVbe->pInt10->di = 0; - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) != 0x4f) - return NULL; - - pmi = malloc(sizeof(VBEpmi)); - pmi->seg_tbl = R16(pVbe->pInt10->es); - pmi->tbl_off = R16(pVbe->pInt10->di); - pmi->tbl_len = R16(pVbe->pInt10->cx); - - return pmi; -} - -#if 0 -vbeModeInfoPtr -VBEBuildVbeModeList(vbeInfoPtr pVbe, VbeInfoBlock * vbe) -{ - vbeModeInfoPtr ModeList = NULL; - - int i = 0; - - while (vbe->VideoModePtr[i] != 0xffff) { - vbeModeInfoPtr m; - VbeModeInfoBlock *mode; - int id = vbe->VideoModePtr[i++]; - int bpp; - - if ((mode = VBEGetModeInfo(pVbe, id)) == NULL) - continue; - - bpp = mode->BitsPerPixel; - - m = xnfcalloc(sizeof(vbeModeInfoRec), 1); - m->width = mode->XResolution; - m->height = mode->YResolution; - m->bpp = bpp; - m->n = id; - m->next = ModeList; - - xf86DrvMsgVerb(pVbe->pInt10->pScrn->scrnIndex, X_PROBED, 3, - "BIOS reported VESA mode 0x%x: x:%i y:%i bpp:%i\n", - m->n, m->width, m->height, m->bpp); - - ModeList = m; - - VBEFreeModeInfo(mode); - } - return ModeList; -} - -unsigned short -VBECalcVbeModeIndex(vbeModeInfoPtr m, DisplayModePtr mode, int bpp) -{ - while (m) { - if (bpp == m->bpp - && mode->HDisplay == m->width && mode->VDisplay == m->height) - return m->n; - m = m->next; - } - return 0; -} -#endif - -void -VBEVesaSaveRestore(vbeInfoPtr pVbe, vbeSaveRestorePtr vbe_sr, - vbeSaveRestoreFunction function) -{ - Bool SaveSucc = FALSE; - - if (VBE_VERSION_MAJOR(pVbe->version) > 1 - && (function == MODE_SAVE || vbe_sr->pstate)) { - if (function == MODE_RESTORE) - memcpy(vbe_sr->state, vbe_sr->pstate, vbe_sr->stateSize); - ErrorF("VBESaveRestore\n"); - if ((VBESaveRestore(pVbe, function, - (void *) &vbe_sr->state, - &vbe_sr->stateSize, &vbe_sr->statePage))) { - if (function == MODE_SAVE) { - SaveSucc = TRUE; - vbe_sr->stateMode = -1; /* invalidate */ - /* don't rely on the memory not being touched */ - if (vbe_sr->pstate == NULL) - vbe_sr->pstate = malloc(vbe_sr->stateSize); - memcpy(vbe_sr->pstate, vbe_sr->state, vbe_sr->stateSize); - } - ErrorF("VBESaveRestore done with success\n"); - return; - } - ErrorF("VBESaveRestore done\n"); - } - - if (function == MODE_SAVE && !SaveSucc) - (void) VBEGetVBEMode(pVbe, &vbe_sr->stateMode); - - if (function == MODE_RESTORE && vbe_sr->stateMode != -1) - VBESetVBEMode(pVbe, vbe_sr->stateMode, NULL); - -} - -int -VBEGetPixelClock(vbeInfoPtr pVbe, int mode, int clock) -{ - /* - Input: - AX := 4F0Bh VBE Get Pixel Clock - BL := 00h Get Pixel Clock - ECX := pixel clock in units of Hz - DX := mode number - - Output: - AX := VBE Return Status - ECX := Closest pixel clock - */ - - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f0b; - pVbe->pInt10->bx = 0x00; - pVbe->pInt10->cx = clock; - pVbe->pInt10->dx = mode; - xf86ExecX86int10(pVbe->pInt10); - - if (R16(pVbe->pInt10->ax) != 0x4f) - return 0; - - return pVbe->pInt10->cx; -} - -Bool -VBEDPMSSet(vbeInfoPtr pVbe, int mode) -{ - /* - Input: - AX := 4F10h DPMS - BL := 01h Set Display Power State - BH := requested power state - - Output: - AX := VBE Return Status - */ - - pVbe->pInt10->num = 0x10; - pVbe->pInt10->ax = 0x4f10; - pVbe->pInt10->bx = 0x01; - switch (mode) { - case DPMSModeOn: - break; - case DPMSModeStandby: - pVbe->pInt10->bx |= 0x100; - break; - case DPMSModeSuspend: - pVbe->pInt10->bx |= 0x200; - break; - case DPMSModeOff: - pVbe->pInt10->bx |= 0x400; - break; - } - xf86ExecX86int10(pVbe->pInt10); - return (R16(pVbe->pInt10->ax) == 0x4f); -} - -void -VBEInterpretPanelID(ScrnInfoPtr pScrn, struct vbePanelID *data) -{ - DisplayModePtr mode; - const float PANEL_HZ = 60.0; - - if (!data) - return; - - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "PanelID returned panel resolution %dx%d\n", - data->hsize, data->vsize); - - if (pScrn->monitor->nHsync || pScrn->monitor->nVrefresh) - return; - - if (data->hsize < 320 || data->vsize < 240) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, "...which I refuse to believe\n"); - return; - } - - mode = xf86CVTMode(data->hsize, data->vsize, PANEL_HZ, 1, 0); - - pScrn->monitor->nHsync = 1; - pScrn->monitor->hsync[0].lo = 29.37; - pScrn->monitor->hsync[0].hi = (float) mode->Clock / (float) mode->HTotal; - pScrn->monitor->nVrefresh = 1; - pScrn->monitor->vrefresh[0].lo = 56.0; - pScrn->monitor->vrefresh[0].hi = - (float) mode->Clock * 1000.0 / (float) mode->HTotal / - (float) mode->VTotal; - - if (pScrn->monitor->vrefresh[0].hi < 59.47) - pScrn->monitor->vrefresh[0].hi = 59.47; - - free(mode); -} - -struct vbePanelID * -VBEReadPanelID(vbeInfoPtr pVbe) -{ - int RealOff = pVbe->real_mode_base; - void *page = pVbe->memory; - void *tmp = NULL; - int screen = pVbe->pInt10->pScrn->scrnIndex; - - pVbe->pInt10->ax = 0x4F11; - pVbe->pInt10->bx = 0x01; - pVbe->pInt10->cx = 0; - pVbe->pInt10->dx = 0; - pVbe->pInt10->es = SEG_ADDR(RealOff); - pVbe->pInt10->di = SEG_OFF(RealOff); - pVbe->pInt10->num = 0x10; - - xf86ExecX86int10(pVbe->pInt10); - - if ((pVbe->pInt10->ax & 0xff) != 0x4f) { - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE PanelID invalid\n"); - goto error; - } - - switch (pVbe->pInt10->ax & 0xff00) { - case 0x0: - xf86DrvMsgVerb(screen, X_INFO, 3, - "VESA VBE PanelID read successfully\n"); - tmp = xnfalloc(32); - memcpy(tmp, page, 32); - break; - case 0x100: - xf86DrvMsgVerb(screen, X_INFO, 3, "VESA VBE PanelID read failed\n"); - break; - default: - xf86DrvMsgVerb(screen, X_INFO, 3, - "VESA VBE PanelID unknown failure %i\n", - pVbe->pInt10->ax & 0xff00); - break; - } - - error: - return tmp; -} diff --git a/hw/xfree86/int10/vbe.h b/hw/xfree86/int10/vbe.h deleted file mode 100644 index 8024f5102..000000000 --- a/hw/xfree86/int10/vbe.h +++ /dev/null @@ -1,356 +0,0 @@ - -/* - * XFree86 vbe module - * Copyright 2000 Egbert Eich - * - * The mode query/save/set/restore functions from the vesa driver - * have been moved here. - * Copyright (c) 2000 by Conectiva S.A. (http://www.conectiva.com) - * Authors: Paulo César Pereira de Andrade - */ - -#ifndef _VBE_H -#define _VBE_H -#include "xf86int10.h" -#include "xf86DDC.h" - -typedef enum { - DDC_UNCHECKED, - DDC_NONE, - DDC_1, - DDC_2, - DDC_1_2 -} ddc_lvl; - -typedef struct { - xf86Int10InfoPtr pInt10; - int version; - void *memory; - int real_mode_base; - int num_pages; - Bool init_int10; - ddc_lvl ddc; - Bool ddc_blank; -} vbeInfoRec, *vbeInfoPtr; - -#define VBE_VERSION_MAJOR(x) *((CARD8*)(&x) + 1) -#define VBE_VERSION_MINOR(x) (CARD8)(x) - -extern _X_EXPORT vbeInfoPtr VBEInit(xf86Int10InfoPtr pInt, int entityIndex); -extern _X_EXPORT vbeInfoPtr VBEExtendedInit(xf86Int10InfoPtr pInt, - int entityIndex, int Flags); -extern _X_EXPORT void vbeFree(vbeInfoPtr pVbe); -extern _X_EXPORT xf86MonPtr vbeDoEDID(vbeInfoPtr pVbe, void *pDDCModule); - -#pragma pack(1) - -typedef struct vbeControllerInfoBlock { - CARD8 VbeSignature[4]; - CARD16 VbeVersion; - CARD32 OemStringPtr; - CARD8 Capabilities[4]; - CARD32 VideoModePtr; - CARD16 TotalMem; - CARD16 OemSoftwareRev; - CARD32 OemVendorNamePtr; - CARD32 OemProductNamePtr; - CARD32 OemProductRevPtr; - CARD8 Scratch[222]; - CARD8 OemData[256]; -} vbeControllerInfoRec, *vbeControllerInfoPtr; - -#if defined(__GNUC__) || defined(__USLC__) || defined(__SUNPRO_C) -#pragma pack() /* All GCC versions recognise this syntax */ -#else -#pragma pack(0) -#endif - -#if !( defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) ) -#define __attribute__(a) -#endif - -typedef struct _VbeInfoBlock VbeInfoBlock; -typedef struct _VbeModeInfoBlock VbeModeInfoBlock; -typedef struct _VbeCRTCInfoBlock VbeCRTCInfoBlock; - -/* - * INT 0 - */ - -struct _VbeInfoBlock { - /* VESA 1.2 fields */ - CARD8 VESASignature[4]; /* VESA */ - CARD16 VESAVersion; /* Higher byte major, lower byte minor */ - /*CARD32 */ char *OEMStringPtr; - /* Pointer to OEM string */ - CARD8 Capabilities[4]; /* Capabilities of the video environment */ - - /*CARD32 */ CARD16 *VideoModePtr; - /* pointer to supported Super VGA modes */ - - CARD16 TotalMemory; /* Number of 64kb memory blocks on board */ - /* if not VESA 2, 236 scratch bytes follow (256 bytes total size) */ - - /* VESA 2 fields */ - CARD16 OemSoftwareRev; /* VBE implementation Software revision */ - /*CARD32 */ char *OemVendorNamePtr; - /* Pointer to Vendor Name String */ - /*CARD32 */ char *OemProductNamePtr; - /* Pointer to Product Name String */ - /*CARD32 */ char *OemProductRevPtr; - /* Pointer to Product Revision String */ - CARD8 Reserved[222]; /* Reserved for VBE implementation */ - CARD8 OemData[256]; /* Data Area for OEM Strings */ -} __attribute__ ((packed)); - -/* Return Super VGA Information */ -extern _X_EXPORT VbeInfoBlock *VBEGetVBEInfo(vbeInfoPtr pVbe); -extern _X_EXPORT void VBEFreeVBEInfo(VbeInfoBlock * block); - -/* - * INT 1 - */ - -struct _VbeModeInfoBlock { - CARD16 ModeAttributes; /* mode attributes */ - CARD8 WinAAttributes; /* window A attributes */ - CARD8 WinBAttributes; /* window B attributes */ - CARD16 WinGranularity; /* window granularity */ - CARD16 WinSize; /* window size */ - CARD16 WinASegment; /* window A start segment */ - CARD16 WinBSegment; /* window B start segment */ - CARD32 WinFuncPtr; /* real mode pointer to window function */ - CARD16 BytesPerScanline; /* bytes per scanline */ - - /* Mandatory information for VBE 1.2 and above */ - CARD16 XResolution; /* horizontal resolution in pixels or characters */ - CARD16 YResolution; /* vertical resolution in pixels or characters */ - CARD8 XCharSize; /* character cell width in pixels */ - CARD8 YCharSize; /* character cell height in pixels */ - CARD8 NumberOfPlanes; /* number of memory planes */ - CARD8 BitsPerPixel; /* bits per pixel */ - CARD8 NumberOfBanks; /* number of banks */ - CARD8 MemoryModel; /* memory model type */ - CARD8 BankSize; /* bank size in KB */ - CARD8 NumberOfImages; /* number of images */ - CARD8 Reserved; /* 1 *//* reserved for page function */ - - /* Direct color fields (required for direct/6 and YUV/7 memory models) */ - CARD8 RedMaskSize; /* size of direct color red mask in bits */ - CARD8 RedFieldPosition; /* bit position of lsb of red mask */ - CARD8 GreenMaskSize; /* size of direct color green mask in bits */ - CARD8 GreenFieldPosition; /* bit position of lsb of green mask */ - CARD8 BlueMaskSize; /* size of direct color blue mask in bits */ - CARD8 BlueFieldPosition; /* bit position of lsb of blue mask */ - CARD8 RsvdMaskSize; /* size of direct color reserved mask in bits */ - CARD8 RsvdFieldPosition; /* bit position of lsb of reserved mask */ - CARD8 DirectColorModeInfo; /* direct color mode attributes */ - - /* Mandatory information for VBE 2.0 and above */ - CARD32 PhysBasePtr; /* physical address for flat memory frame buffer */ - CARD32 Reserved32; /* 0 *//* Reserved - always set to 0 */ - CARD16 Reserved16; /* 0 *//* Reserved - always set to 0 */ - - /* Mandatory information for VBE 3.0 and above */ - CARD16 LinBytesPerScanLine; /* bytes per scan line for linear modes */ - CARD8 BnkNumberOfImagePages; /* number of images for banked modes */ - CARD8 LinNumberOfImagePages; /* number of images for linear modes */ - CARD8 LinRedMaskSize; /* size of direct color red mask (linear modes) */ - CARD8 LinRedFieldPosition; /* bit position of lsb of red mask (linear modes) */ - CARD8 LinGreenMaskSize; /* size of direct color green mask (linear modes) */ - CARD8 LinGreenFieldPosition; /* bit position of lsb of green mask (linear modes) */ - CARD8 LinBlueMaskSize; /* size of direct color blue mask (linear modes) */ - CARD8 LinBlueFieldPosition; /* bit position of lsb of blue mask (linear modes) */ - CARD8 LinRsvdMaskSize; /* size of direct color reserved mask (linear modes) */ - CARD8 LinRsvdFieldPosition; /* bit position of lsb of reserved mask (linear modes) */ - CARD32 MaxPixelClock; /* maximum pixel clock (in Hz) for graphics mode */ - CARD8 Reserved2[189]; /* remainder of VbeModeInfoBlock */ -} __attribute__ ((packed)); - -/* Return VBE Mode Information */ -extern _X_EXPORT VbeModeInfoBlock *VBEGetModeInfo(vbeInfoPtr pVbe, int mode); -extern _X_EXPORT void VBEFreeModeInfo(VbeModeInfoBlock * block); - -/* - * INT2 - */ - -#define CRTC_DBLSCAN (1<<0) -#define CRTC_INTERLACE (1<<1) -#define CRTC_NHSYNC (1<<2) -#define CRTC_NVSYNC (1<<3) - -struct _VbeCRTCInfoBlock { - CARD16 HorizontalTotal; /* Horizontal total in pixels */ - CARD16 HorizontalSyncStart; /* Horizontal sync start in pixels */ - CARD16 HorizontalSyncEnd; /* Horizontal sync end in pixels */ - CARD16 VerticalTotal; /* Vertical total in lines */ - CARD16 VerticalSyncStart; /* Vertical sync start in lines */ - CARD16 VerticalSyncEnd; /* Vertical sync end in lines */ - CARD8 Flags; /* Flags (Interlaced, Double Scan etc) */ - CARD32 PixelClock; /* Pixel clock in units of Hz */ - CARD16 RefreshRate; /* Refresh rate in units of 0.01 Hz */ - CARD8 Reserved[40]; /* remainder of ModeInfoBlock */ -} __attribute__ ((packed)); - -/* VbeCRTCInfoBlock is in the VESA 3.0 specs */ - -extern _X_EXPORT Bool VBESetVBEMode(vbeInfoPtr pVbe, int mode, - VbeCRTCInfoBlock * crtc); - -/* - * INT 3 - */ - -extern _X_EXPORT Bool VBEGetVBEMode(vbeInfoPtr pVbe, int *mode); - -/* - * INT 4 - */ - -/* Save/Restore Super VGA video state */ -/* function values are (values stored in VESAPtr): - * 0 := query & allocate amount of memory to save state - * 1 := save state - * 2 := restore state - * - * function 0 called automatically if function 1 called without - * a previous call to function 0. - */ - -typedef enum { - MODE_QUERY, - MODE_SAVE, - MODE_RESTORE -} vbeSaveRestoreFunction; - -extern _X_EXPORT Bool -VBESaveRestore(vbeInfoPtr pVbe, vbeSaveRestoreFunction function, - void **memory, int *size, int *real_mode_pages); - -/* - * INT 5 - */ - -extern _X_EXPORT Bool - VBEBankSwitch(vbeInfoPtr pVbe, unsigned int iBank, int window); - -/* - * INT 6 - */ - -typedef enum { - SCANWID_SET, - SCANWID_GET, - SCANWID_SET_BYTES, - SCANWID_GET_MAX -} vbeScanwidthCommand; - -#define VBESetLogicalScanline(pVbe, width) \ - VBESetGetLogicalScanlineLength(pVbe, SCANWID_SET, width, \ - NULL, NULL, NULL) -#define VBESetLogicalScanlineBytes(pVbe, width) \ - VBESetGetLogicalScanlineLength(pVbe, SCANWID_SET_BYTES, width, \ - NULL, NULL, NULL) -#define VBEGetLogicalScanline(pVbe, pixels, bytes, max) \ - VBESetGetLogicalScanlineLength(pVbe, SCANWID_GET, 0, \ - pixels, bytes, max) -#define VBEGetMaxLogicalScanline(pVbe, pixels, bytes, max) \ - VBESetGetLogicalScanlineLength(pVbe, SCANWID_GET_MAX, 0, \ - pixels, bytes, max) -extern _X_EXPORT Bool VBESetGetLogicalScanlineLength(vbeInfoPtr pVbe, - vbeScanwidthCommand - command, int width, - int *pixels, int *bytes, - int *max); - -/* - * INT 7 - */ - -/* 16 bit code */ -extern _X_EXPORT Bool VBESetDisplayStart(vbeInfoPtr pVbe, int x, int y, - Bool wait_retrace); -extern _X_EXPORT Bool VBEGetDisplayStart(vbeInfoPtr pVbe, int *x, int *y); - -/* - * INT 8 - */ - -/* if bits is 0, then it is a GET */ -extern _X_EXPORT int VBESetGetDACPaletteFormat(vbeInfoPtr pVbe, int bits); - -/* - * INT 9 - */ - -/* - * If getting a palette, the data argument is not used. It will return - * the data. - * If setting a palette, it will return the pointer received on success, - * NULL on failure. - */ -extern _X_EXPORT CARD32 *VBESetGetPaletteData(vbeInfoPtr pVbe, Bool set, - int first, int num, CARD32 *data, - Bool secondary, - Bool wait_retrace); -#define VBEFreePaletteData(data) free(data) - -/* - * INT A - */ - -typedef struct _VBEpmi { - int seg_tbl; - int tbl_off; - int tbl_len; -} VBEpmi; - -extern _X_EXPORT VBEpmi *VBEGetVBEpmi(vbeInfoPtr pVbe); - -#define VESAFreeVBEpmi(pmi) free(pmi) - -/* high level helper functions */ - -typedef struct _vbeModeInfoRec { - int width; - int height; - int bpp; - int n; - struct _vbeModeInfoRec *next; -} vbeModeInfoRec, *vbeModeInfoPtr; - -typedef struct { - CARD8 *state; - CARD8 *pstate; - int statePage; - int stateSize; - int stateMode; -} vbeSaveRestoreRec, *vbeSaveRestorePtr; - -extern _X_EXPORT void - -VBEVesaSaveRestore(vbeInfoPtr pVbe, vbeSaveRestorePtr vbe_sr, - vbeSaveRestoreFunction function); - -extern _X_EXPORT int VBEGetPixelClock(vbeInfoPtr pVbe, int mode, int Clock); -extern _X_EXPORT Bool VBEDPMSSet(vbeInfoPtr pVbe, int mode); - -struct vbePanelID { - short hsize; - short vsize; - short fptype; - char redbpp; - char greenbpp; - char bluebpp; - char reservedbpp; - int reserved_offscreen_mem_size; - int reserved_offscreen_mem_pointer; - char reserved[14]; -}; - -extern _X_EXPORT void VBEInterpretPanelID(ScrnInfoPtr pScrn, - struct vbePanelID *data); -extern _X_EXPORT struct vbePanelID *VBEReadPanelID(vbeInfoPtr pVbe); - -#endif diff --git a/hw/xfree86/int10/vbeModes.c b/hw/xfree86/int10/vbeModes.c deleted file mode 100644 index 980e40b9c..000000000 --- a/hw/xfree86/int10/vbeModes.c +++ /dev/null @@ -1,453 +0,0 @@ -#define DEBUG_VERB 2 -/* - * Copyright © 2002 David Dawes - * - * 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 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 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 author(s). - * - * Authors: David Dawes - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#include "xf86.h" -#include "vbe.h" -#include "vbeModes.h" - -static int -GetDepthFlag(vbeInfoPtr pVbe, int id) -{ - VbeModeInfoBlock *mode; - int bpp; - - if ((mode = VBEGetModeInfo(pVbe, id)) == NULL) - return 0; - - if (VBE_MODE_USABLE(mode, 0)) { - int depth; - - if (VBE_MODE_COLOR(mode)) { - depth = mode->RedMaskSize + mode->GreenMaskSize + - mode->BlueMaskSize; - } - else { - depth = 1; - } - bpp = mode->BitsPerPixel; - VBEFreeModeInfo(mode); - mode = NULL; - switch (depth) { - case 1: - return V_DEPTH_1; - case 4: - return V_DEPTH_4; - case 8: - return V_DEPTH_8; - case 15: - return V_DEPTH_15; - case 16: - return V_DEPTH_16; - case 24: - switch (bpp) { - case 24: - return V_DEPTH_24_24; - case 32: - return V_DEPTH_24_32; - } - } - } - if (mode) - VBEFreeModeInfo(mode); - return 0; -} - -/* - * Find supported mode depths. - */ -int -VBEFindSupportedDepths(vbeInfoPtr pVbe, VbeInfoBlock * vbe, int *flags24, - int modeTypes) -{ - int i = 0; - int depths = 0; - - if (modeTypes & V_MODETYPE_VBE) { - while (vbe->VideoModePtr[i] != 0xffff) { - depths |= GetDepthFlag(pVbe, vbe->VideoModePtr[i++]); - } - } - - /* - * XXX This possibly only works with VBE 3.0 and later. - */ - if (modeTypes & V_MODETYPE_VGA) { - for (i = 0; i < 0x7F; i++) { - depths |= GetDepthFlag(pVbe, i); - } - } - - if (flags24) { - if (depths & V_DEPTH_24_24) - *flags24 |= Support24bppFb; - if (depths & V_DEPTH_24_32) - *flags24 |= Support32bppFb; - } - - return depths; -} - -static DisplayModePtr -CheckMode(ScrnInfoPtr pScrn, vbeInfoPtr pVbe, VbeInfoBlock * vbe, int id, - int flags) -{ - CARD16 major; - VbeModeInfoBlock *mode; - DisplayModePtr pMode; - VbeModeInfoData *data; - Bool modeOK = FALSE; - - major = (unsigned) (vbe->VESAVersion >> 8); - - if ((mode = VBEGetModeInfo(pVbe, id)) == NULL) - return NULL; - - /* Does the mode match the depth/bpp? */ - /* Some BIOS's set BitsPerPixel to 15 instead of 16 for 15/16 */ - if (VBE_MODE_USABLE(mode, flags) && - ((pScrn->bitsPerPixel == 1 && !VBE_MODE_COLOR(mode)) || - (mode->BitsPerPixel > 8 && - (mode->RedMaskSize + mode->GreenMaskSize + - mode->BlueMaskSize) == pScrn->depth && - mode->BitsPerPixel == pScrn->bitsPerPixel) || - (mode->BitsPerPixel == 15 && pScrn->depth == 15) || - (mode->BitsPerPixel <= 8 && - mode->BitsPerPixel == pScrn->bitsPerPixel))) { - modeOK = TRUE; - xf86ErrorFVerb(DEBUG_VERB, "*"); - } - - xf86ErrorFVerb(DEBUG_VERB, - "Mode: %x (%dx%d)\n", id, mode->XResolution, - mode->YResolution); - xf86ErrorFVerb(DEBUG_VERB, " ModeAttributes: 0x%x\n", - mode->ModeAttributes); - xf86ErrorFVerb(DEBUG_VERB, " WinAAttributes: 0x%x\n", - mode->WinAAttributes); - xf86ErrorFVerb(DEBUG_VERB, " WinBAttributes: 0x%x\n", - mode->WinBAttributes); - xf86ErrorFVerb(DEBUG_VERB, " WinGranularity: %d\n", - mode->WinGranularity); - xf86ErrorFVerb(DEBUG_VERB, " WinSize: %d\n", mode->WinSize); - xf86ErrorFVerb(DEBUG_VERB, - " WinASegment: 0x%x\n", mode->WinASegment); - xf86ErrorFVerb(DEBUG_VERB, - " WinBSegment: 0x%x\n", mode->WinBSegment); - xf86ErrorFVerb(DEBUG_VERB, - " WinFuncPtr: 0x%lx\n", (unsigned long) mode->WinFuncPtr); - xf86ErrorFVerb(DEBUG_VERB, - " BytesPerScanline: %d\n", mode->BytesPerScanline); - xf86ErrorFVerb(DEBUG_VERB, " XResolution: %d\n", mode->XResolution); - xf86ErrorFVerb(DEBUG_VERB, " YResolution: %d\n", mode->YResolution); - xf86ErrorFVerb(DEBUG_VERB, " XCharSize: %d\n", mode->XCharSize); - xf86ErrorFVerb(DEBUG_VERB, " YCharSize: %d\n", mode->YCharSize); - xf86ErrorFVerb(DEBUG_VERB, - " NumberOfPlanes: %d\n", mode->NumberOfPlanes); - xf86ErrorFVerb(DEBUG_VERB, - " BitsPerPixel: %d\n", mode->BitsPerPixel); - xf86ErrorFVerb(DEBUG_VERB, - " NumberOfBanks: %d\n", mode->NumberOfBanks); - xf86ErrorFVerb(DEBUG_VERB, " MemoryModel: %d\n", mode->MemoryModel); - xf86ErrorFVerb(DEBUG_VERB, " BankSize: %d\n", mode->BankSize); - xf86ErrorFVerb(DEBUG_VERB, - " NumberOfImages: %d\n", mode->NumberOfImages); - xf86ErrorFVerb(DEBUG_VERB, " RedMaskSize: %d\n", mode->RedMaskSize); - xf86ErrorFVerb(DEBUG_VERB, - " RedFieldPosition: %d\n", mode->RedFieldPosition); - xf86ErrorFVerb(DEBUG_VERB, - " GreenMaskSize: %d\n", mode->GreenMaskSize); - xf86ErrorFVerb(DEBUG_VERB, - " GreenFieldPosition: %d\n", mode->GreenFieldPosition); - xf86ErrorFVerb(DEBUG_VERB, - " BlueMaskSize: %d\n", mode->BlueMaskSize); - xf86ErrorFVerb(DEBUG_VERB, - " BlueFieldPosition: %d\n", mode->BlueFieldPosition); - xf86ErrorFVerb(DEBUG_VERB, - " RsvdMaskSize: %d\n", mode->RsvdMaskSize); - xf86ErrorFVerb(DEBUG_VERB, - " RsvdFieldPosition: %d\n", mode->RsvdFieldPosition); - xf86ErrorFVerb(DEBUG_VERB, - " DirectColorModeInfo: %d\n", mode->DirectColorModeInfo); - if (major >= 2) { - xf86ErrorFVerb(DEBUG_VERB, - " PhysBasePtr: 0x%lx\n", - (unsigned long) mode->PhysBasePtr); - if (major >= 3) { - xf86ErrorFVerb(DEBUG_VERB, - " LinBytesPerScanLine: %d\n", - mode->LinBytesPerScanLine); - xf86ErrorFVerb(DEBUG_VERB, " BnkNumberOfImagePages: %d\n", - mode->BnkNumberOfImagePages); - xf86ErrorFVerb(DEBUG_VERB, " LinNumberOfImagePages: %d\n", - mode->LinNumberOfImagePages); - xf86ErrorFVerb(DEBUG_VERB, " LinRedMaskSize: %d\n", - mode->LinRedMaskSize); - xf86ErrorFVerb(DEBUG_VERB, " LinRedFieldPosition: %d\n", - mode->LinRedFieldPosition); - xf86ErrorFVerb(DEBUG_VERB, " LinGreenMaskSize: %d\n", - mode->LinGreenMaskSize); - xf86ErrorFVerb(DEBUG_VERB, " LinGreenFieldPosition: %d\n", - mode->LinGreenFieldPosition); - xf86ErrorFVerb(DEBUG_VERB, " LinBlueMaskSize: %d\n", - mode->LinBlueMaskSize); - xf86ErrorFVerb(DEBUG_VERB, " LinBlueFieldPosition: %d\n", - mode->LinBlueFieldPosition); - xf86ErrorFVerb(DEBUG_VERB, " LinRsvdMaskSize: %d\n", - mode->LinRsvdMaskSize); - xf86ErrorFVerb(DEBUG_VERB, " LinRsvdFieldPosition: %d\n", - mode->LinRsvdFieldPosition); - xf86ErrorFVerb(DEBUG_VERB, " MaxPixelClock: %ld\n", - (unsigned long) mode->MaxPixelClock); - } - } - - if (!modeOK) { - VBEFreeModeInfo(mode); - return NULL; - } - pMode = xnfcalloc(sizeof(DisplayModeRec), 1); - - pMode->status = MODE_OK; - pMode->type = M_T_BUILTIN; - - /* for adjust frame */ - pMode->HDisplay = mode->XResolution; - pMode->VDisplay = mode->YResolution; - - data = xnfcalloc(sizeof(VbeModeInfoData), 1); - data->mode = id; - data->data = mode; - pMode->PrivSize = sizeof(VbeModeInfoData); - pMode->Private = (INT32 *) data; - pMode->next = NULL; - return pMode; -} - -/* - * Check the available BIOS modes, and extract those that match the - * requirements into the modePool. Note: modePool is a NULL-terminated - * list. - */ - -DisplayModePtr -VBEGetModePool(ScrnInfoPtr pScrn, vbeInfoPtr pVbe, VbeInfoBlock * vbe, - int modeTypes) -{ - DisplayModePtr pMode, p = NULL, modePool = NULL; - int i = 0; - - if (modeTypes & V_MODETYPE_VBE) { - while (vbe->VideoModePtr[i] != 0xffff) { - int id = vbe->VideoModePtr[i++]; - - if ((pMode = CheckMode(pScrn, pVbe, vbe, id, modeTypes)) != NULL) { - ModeStatus status = MODE_OK; - - /* Check the mode against a specified virtual size (if any) */ - if (pScrn->display->virtualX > 0 && - pMode->HDisplay > pScrn->display->virtualX) { - status = MODE_VIRTUAL_X; - } - if (pScrn->display->virtualY > 0 && - pMode->VDisplay > pScrn->display->virtualY) { - status = MODE_VIRTUAL_Y; - } - if (status != MODE_OK) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Not using mode \"%dx%d\" (%s)\n", - pMode->HDisplay, pMode->VDisplay, - xf86ModeStatusToString(status)); - } - else { - if (p == NULL) { - modePool = pMode; - } - else { - p->next = pMode; - } - pMode->prev = NULL; - p = pMode; - } - } - } - } - if (modeTypes & V_MODETYPE_VGA) { - for (i = 0; i < 0x7F; i++) { - if ((pMode = CheckMode(pScrn, pVbe, vbe, i, modeTypes)) != NULL) { - ModeStatus status = MODE_OK; - - /* Check the mode against a specified virtual size (if any) */ - if (pScrn->display->virtualX > 0 && - pMode->HDisplay > pScrn->display->virtualX) { - status = MODE_VIRTUAL_X; - } - if (pScrn->display->virtualY > 0 && - pMode->VDisplay > pScrn->display->virtualY) { - status = MODE_VIRTUAL_Y; - } - if (status != MODE_OK) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Not using mode \"%dx%d\" (%s)\n", - pMode->HDisplay, pMode->VDisplay, - xf86ModeStatusToString(status)); - } - else { - if (p == NULL) { - modePool = pMode; - } - else { - p->next = pMode; - } - pMode->prev = NULL; - p = pMode; - } - } - } - } - return modePool; -} - -void -VBESetModeNames(DisplayModePtr pMode) -{ - if (!pMode) - return; - - do { - if (!pMode->name) { - /* Catch "bad" modes. */ - if (pMode->HDisplay > 10000 || pMode->HDisplay < 0 || - pMode->VDisplay > 10000 || pMode->VDisplay < 0) { - pMode->name = strdup("BADMODE"); - } - else { - char *tmp; - XNFasprintf(&tmp, "%dx%d", - pMode->HDisplay, pMode->VDisplay); - pMode->name = tmp; - } - } - pMode = pMode->next; - } while (pMode); -} - -/* - * Go through the monitor modes and selecting the best set of - * parameters for each BIOS mode. Note: This is only supported in - * VBE version 3.0 or later. - */ -void -VBESetModeParameters(ScrnInfoPtr pScrn, vbeInfoPtr pVbe) -{ - DisplayModePtr pMode; - VbeModeInfoData *data; - - pMode = pScrn->modes; - do { - DisplayModePtr p, best = NULL; - ModeStatus status; - - for (p = pScrn->monitor->Modes; p != NULL; p = p->next) { - if ((p->HDisplay != pMode->HDisplay) || - (p->VDisplay != pMode->VDisplay) || - (p->Flags & (V_INTERLACE | V_DBLSCAN | V_CLKDIV2))) - continue; - /* XXX could support the various V_ flags */ - status = xf86CheckModeForMonitor(p, pScrn->monitor); - if (status != MODE_OK) - continue; - if (!best || (p->Clock > best->Clock)) - best = p; - } - - if (best) { - int clock; - - data = (VbeModeInfoData *) pMode->Private; - pMode->HSync = (float) best->Clock * 1000.0 / best->HTotal + 0.5; - pMode->VRefresh = pMode->HSync / best->VTotal + 0.5; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Attempting to use %dHz refresh for mode \"%s\" (%x)\n", - (int) pMode->VRefresh, pMode->name, data->mode); - data->block = calloc(sizeof(VbeCRTCInfoBlock), 1); - data->block->HorizontalTotal = best->HTotal; - data->block->HorizontalSyncStart = best->HSyncStart; - data->block->HorizontalSyncEnd = best->HSyncEnd; - data->block->VerticalTotal = best->VTotal; - data->block->VerticalSyncStart = best->VSyncStart; - data->block->VerticalSyncEnd = best->VSyncEnd; - data->block->Flags = ((best->Flags & V_NHSYNC) ? CRTC_NHSYNC : 0) | - ((best->Flags & V_NVSYNC) ? CRTC_NVSYNC : 0); - data->block->PixelClock = best->Clock * 1000; - /* XXX May not have this. */ - clock = VBEGetPixelClock(pVbe, data->mode, data->block->PixelClock); - DebugF("Setting clock %.2fMHz, closest is %.2fMHz\n", - (double) data->block->PixelClock / 1000000.0, - (double) clock / 1000000.0); - if (clock) - data->block->PixelClock = clock; - data->mode |= (1 << 11); - data->block->RefreshRate = ((double) (data->block->PixelClock) / - (double) (best->HTotal * - best->VTotal)) * 100; - } - pMode = pMode->next; - } while (pMode != pScrn->modes); -} - -/* - * These wrappers are to allow (temporary) functionality divergences. - */ -int -VBEValidateModes(ScrnInfoPtr scrp, DisplayModePtr availModes, - const char **modeNames, ClockRangePtr clockRanges, - int *linePitches, int minPitch, int maxPitch, int pitchInc, - int minHeight, int maxHeight, int virtualX, int virtualY, - int apertureSize, LookupModeFlags strategy) -{ - return xf86ValidateModes(scrp, availModes, modeNames, clockRanges, - linePitches, minPitch, maxPitch, pitchInc, - minHeight, maxHeight, virtualX, virtualY, - apertureSize, strategy); -} - -void -VBEPrintModes(ScrnInfoPtr scrp) -{ - xf86PrintModes(scrp); -} diff --git a/hw/xfree86/int10/vbeModes.h b/hw/xfree86/int10/vbeModes.h deleted file mode 100644 index ee0257c15..000000000 --- a/hw/xfree86/int10/vbeModes.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright © 2002 David Dawes - * - * 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 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 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 author(s). - * - * Authors: David Dawes - * - */ - -#ifndef _VBE_MODES_H - -/* - * This is intended to be stored in the DisplayModeRec's private area. - * It includes all the information necessary to VBE information. - */ -typedef struct _VbeModeInfoData { - int mode; - VbeModeInfoBlock *data; - VbeCRTCInfoBlock *block; -} VbeModeInfoData; - -#define V_DEPTH_1 0x001 -#define V_DEPTH_4 0x002 -#define V_DEPTH_8 0x004 -#define V_DEPTH_15 0x008 -#define V_DEPTH_16 0x010 -#define V_DEPTH_24_24 0x020 -#define V_DEPTH_24_32 0x040 -#define V_DEPTH_24 (V_DEPTH_24_24 | V_DEPTH_24_32) -#define V_DEPTH_30 0x080 -#define V_DEPTH_32 0x100 - -#define VBE_MODE_SUPPORTED(m) (((m)->ModeAttributes & 0x01) != 0) -#define VBE_MODE_COLOR(m) (((m)->ModeAttributes & 0x08) != 0) -#define VBE_MODE_GRAPHICS(m) (((m)->ModeAttributes & 0x10) != 0) -#define VBE_MODE_VGA(m) (((m)->ModeAttributes & 0x40) == 0) -#define VBE_MODE_LINEAR(m) (((m)->ModeAttributes & 0x80) != 0 && \ - ((m)->PhysBasePtr != 0)) - -#define VBE_MODE_USABLE(m, f) (VBE_MODE_SUPPORTED(m) || \ - (f & V_MODETYPE_BAD)) && \ - VBE_MODE_GRAPHICS(m) && \ - (VBE_MODE_VGA(m) || VBE_MODE_LINEAR(m)) - -#define V_MODETYPE_VBE 0x01 -#define V_MODETYPE_VGA 0x02 -#define V_MODETYPE_BAD 0x04 - -extern _X_EXPORT int VBEFindSupportedDepths(vbeInfoPtr pVbe, VbeInfoBlock * vbe, - int *flags24, int modeTypes); -extern _X_EXPORT DisplayModePtr VBEGetModePool(ScrnInfoPtr pScrn, - vbeInfoPtr pVbe, - VbeInfoBlock * vbe, - int modeTypes); -extern _X_EXPORT void VBESetModeNames(DisplayModePtr pMode); -extern _X_EXPORT void VBESetModeParameters(ScrnInfoPtr pScrn, vbeInfoPtr pVbe); - -/* - * Note: These are alternatives to the standard helpers. They should - * usually just wrap the standard helpers. - */ -extern _X_EXPORT int VBEValidateModes(ScrnInfoPtr scrp, - DisplayModePtr availModes, - const char **modeNames, - ClockRangePtr clockRanges, - int *linePitches, int minPitch, - int maxPitch, int pitchInc, int minHeight, - int maxHeight, int virtualX, int virtualY, - int apertureSize, - LookupModeFlags strategy); -extern _X_EXPORT void VBEPrintModes(ScrnInfoPtr scrp); - -#endif /* VBE_MODES_H */ diff --git a/hw/xfree86/int10/x86emu.c b/hw/xfree86/int10/x86emu.c deleted file mode 100644 index b3320e5b9..000000000 --- a/hw/xfree86/int10/x86emu.c +++ /dev/null @@ -1,12 +0,0 @@ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "debug.c" -#include "decode.c" -#include "fpu.c" -#include "ops.c" -#include "ops2.c" -#include "prim_ops.c" -#include "sys.c" diff --git a/hw/xfree86/int10/xf86int10.c b/hw/xfree86/int10/xf86int10.c deleted file mode 100644 index 578f461b7..000000000 --- a/hw/xfree86/int10/xf86int10.c +++ /dev/null @@ -1,884 +0,0 @@ -/* - * XFree86 int10 module - * execute BIOS int 10h calls in x86 real mode environment - * Copyright 1999 Egbert Eich - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "compiler.h" -#define _INT10_PRIVATE -#include "xf86int10.h" -#include "int10Defines.h" -#include "Pci.h" - -#define REG pInt - -xf86Int10InfoPtr Int10Current = NULL; - -static int int1A_handler(xf86Int10InfoPtr pInt); - -#ifndef _PC -static int int42_handler(xf86Int10InfoPtr pInt); -#endif -static int intE6_handler(xf86Int10InfoPtr pInt); -static struct pci_device *findPci(xf86Int10InfoPtr pInt, unsigned short bx); -static CARD32 pciSlotBX(const struct pci_device *pvp); - -int -int_handler(xf86Int10InfoPtr pInt) -{ - int num = pInt->num; - int ret = 0; - - switch (num) { -#ifndef _PC - case 0x10: - case 0x42: - case 0x6D: - if (getIntVect(pInt, num) == I_S_DEFAULT_INT_VECT) - ret = int42_handler(pInt); - break; -#endif - case 0x1A: - ret = int1A_handler(pInt); - break; - case 0xe6: - ret = intE6_handler(pInt); - break; - default: - break; - } - - if (!ret) - ret = run_bios_int(num, pInt); - - if (!ret) { - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "Halting on int 0x%2.2x!\n", num); - dump_registers(pInt); - stack_trace(pInt); - } - - return ret; -} - -#ifndef _PC -/* - * This is derived from a number of PC system BIOS'es. The intent here is to - * provide very primitive video support, before an EGA/VGA BIOS installs its - * own interrupt vector. Here, "Ignored" calls should remain so. "Not - * Implemented" denotes functionality that can be implemented should the need - * arise. What are "Not Implemented" throughout are video memory accesses. - * Also, very little input validity checking is done here. - */ -static int -int42_handler(xf86Int10InfoPtr pInt) -{ - switch (X86_AH) { - case 0x00: - /* Set Video Mode */ - /* Enter: AL = video mode number */ - /* Leave: Nothing */ - /* Implemented (except for clearing the screen) */ - { /* Localise */ - unsigned int ioport; - int i; - CARD16 int1d, regvals, tmp; - CARD8 mode, cgamode, cgacolour; - - /* - * Ignore all mode numbers but 0x00-0x13. Some systems also ignore - * 0x0B and 0x0C, but don't do that here. - */ - if (X86_AL > 0x13) - break; - - /* - * You didn't think that was really the mode set, did you? There - * are only so many slots in the video parameter table... - */ - mode = X86_AL; - ioport = 0x03D4; - switch (MEM_RB(pInt, 0x0410) & 0x30) { - case 0x30: /* MDA */ - mode = 0x07; /* Force mode to 0x07 */ - ioport = 0x03B4; - break; - case 0x10: /* CGA 40x25 */ - if (mode >= 0x07) - mode = 0x01; - break; - case 0x20: /* CGA 80x25 (MCGA?) */ - if (mode >= 0x07) - mode = 0x03; - break; - case 0x00: /* EGA/VGA */ - if (mode >= 0x07) /* Don't try MDA timings */ - mode = 0x01; /* !?!?! */ - break; - } - - /* Locate data in video parameter table */ - int1d = MEM_RW(pInt, 0x1d << 2); - regvals = ((mode >> 1) << 4) + int1d; - cgacolour = 0x30; - if (mode == 0x06) { - regvals -= 0x10; - cgacolour = 0x3F; - } - - /** Update BIOS Data Area **/ - - /* Video mode */ - MEM_WB(pInt, 0x0449, mode); - - /* Columns */ - tmp = MEM_RB(pInt, mode + int1d + 0x48); - MEM_WW(pInt, 0x044A, tmp); - - /* Page length */ - tmp = MEM_RW(pInt, (mode & 0x06) + int1d + 0x40); - MEM_WW(pInt, 0x044C, tmp); - - /* Start Address */ - MEM_WW(pInt, 0x044E, 0); - - /* Cursor positions, one for each display page */ - for (i = 0x0450; i < 0x0460; i += 2) - MEM_WW(pInt, i, 0); - - /* Cursor start & end scanlines */ - tmp = MEM_RB(pInt, regvals + 0x0B); - MEM_WB(pInt, 0x0460, tmp); - tmp = MEM_RB(pInt, regvals + 0x0A); - MEM_WB(pInt, 0x0461, tmp); - - /* Current display page number */ - MEM_WB(pInt, 0x0462, 0); - - /* CRTC I/O address */ - MEM_WW(pInt, 0x0463, ioport); - - /* CGA Mode register value */ - cgamode = MEM_RB(pInt, mode + int1d + 0x50); - MEM_WB(pInt, 0x0465, cgamode); - - /* CGA Colour register value */ - MEM_WB(pInt, 0x0466, cgacolour); - - /* Rows */ - MEM_WB(pInt, 0x0484, (25 - 1)); - - /* Program the mode */ - pci_io_write8(pInt->io, ioport + 4, cgamode & 0x37); /* Turn off screen */ - for (i = 0; i < 0x10; i++) { - tmp = MEM_RB(pInt, regvals + i); - pci_io_write8(pInt->io, ioport, i); - pci_io_write8(pInt->io, ioport + 1, tmp); - } - pci_io_write8(pInt->io, ioport + 5, cgacolour); /* Select colour mode */ - pci_io_write8(pInt->io, ioport + 4, cgamode); /* Turn on screen */ - } - break; - - case 0x01: - /* Set Cursor Type */ - /* Enter: CH = starting line for cursor */ - /* CL = ending line for cursor */ - /* Leave: Nothing */ - /* Implemented */ - { /* Localise */ - unsigned int ioport = MEM_RW(pInt, 0x0463); - - MEM_WB(pInt, 0x0460, X86_CL); - MEM_WB(pInt, 0x0461, X86_CH); - - pci_io_write8(pInt->io, ioport, 0x0A); - pci_io_write8(pInt->io, ioport + 1, X86_CH); - pci_io_write8(pInt->io, ioport, 0x0B); - pci_io_write8(pInt->io, ioport + 1, X86_CL); - } - break; - - case 0x02: - /* Set Cursor Position */ - /* Enter: BH = display page number */ - /* DH = row */ - /* DL = column */ - /* Leave: Nothing */ - /* Implemented */ - { /* Localise */ - unsigned int ioport; - CARD16 offset; - - MEM_WB(pInt, (X86_BH << 1) + 0x0450, X86_DL); - MEM_WB(pInt, (X86_BH << 1) + 0x0451, X86_DH); - - if (X86_BH != MEM_RB(pInt, 0x0462)) - break; - - offset = (X86_DH * MEM_RW(pInt, 0x044A)) + X86_DL; - offset += MEM_RW(pInt, 0x044E) << 1; - - ioport = MEM_RW(pInt, 0x0463); - pci_io_write8(pInt->io, ioport, 0x0E); - pci_io_write8(pInt->io, ioport + 1, offset >> 8); - pci_io_write8(pInt->io, ioport, 0x0F); - pci_io_write8(pInt->io, ioport + 1, offset & 0xFF); - } - break; - - case 0x03: - /* Get Cursor Position */ - /* Enter: BH = display page number */ - /* Leave: CH = starting line for cursor */ - /* CL = ending line for cursor */ - /* DH = row */ - /* DL = column */ - /* Implemented */ - { /* Localise */ - X86_CL = MEM_RB(pInt, 0x0460); - X86_CH = MEM_RB(pInt, 0x0461); - X86_DL = MEM_RB(pInt, (X86_BH << 1) + 0x0450); - X86_DH = MEM_RB(pInt, (X86_BH << 1) + 0x0451); - } - break; - - case 0x04: - /* Get Light Pen Position */ - /* Enter: Nothing */ - /* Leave: AH = 0x01 (down/triggered) or 0x00 (not) */ - /* BX = pixel column */ - /* CX = pixel row */ - /* DH = character row */ - /* DL = character column */ - /* Not Implemented */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x04) -- Get Light Pen Position\n", - pInt->num); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - X86_AH = X86_BX = X86_CX = X86_DX = 0; - } - break; - - case 0x05: - /* Set Display Page */ - /* Enter: AL = display page number */ - /* Leave: Nothing */ - /* Implemented */ - { /* Localise */ - unsigned int ioport = MEM_RW(pInt, 0x0463); - CARD16 start; - CARD8 x, y; - - /* Calculate new start address */ - MEM_WB(pInt, 0x0462, X86_AL); - start = X86_AL * MEM_RW(pInt, 0x044C); - MEM_WW(pInt, 0x044E, start); - start <<= 1; - - /* Update start address */ - pci_io_write8(pInt->io, ioport, 0x0C); - pci_io_write8(pInt->io, ioport + 1, start >> 8); - pci_io_write8(pInt->io, ioport, 0x0D); - pci_io_write8(pInt->io, ioport + 1, start & 0xFF); - - /* Switch cursor position */ - y = MEM_RB(pInt, (X86_AL << 1) + 0x0450); - x = MEM_RB(pInt, (X86_AL << 1) + 0x0451); - start += (y * MEM_RW(pInt, 0x044A)) + x; - - /* Update cursor position */ - pci_io_write8(pInt->io, ioport, 0x0E); - pci_io_write8(pInt->io, ioport + 1, start >> 8); - pci_io_write8(pInt->io, ioport, 0x0F); - pci_io_write8(pInt->io, ioport + 1, start & 0xFF); - } - break; - - case 0x06: - /* Initialise or Scroll Window Up */ - /* Enter: AL = lines to scroll up */ - /* BH = attribute for blank */ - /* CH = upper y of window */ - /* CL = left x of window */ - /* DH = lower y of window */ - /* DL = right x of window */ - /* Leave: Nothing */ - /* Not Implemented */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x06) -- Initialise or Scroll Window Up\n", - pInt->num); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3, - " AL=0x%2.2x, BH=0x%2.2x," - " CH=0x%2.2x, CL=0x%2.2x, DH=0x%2.2x, DL=0x%2.2x\n", - X86_AL, X86_BH, X86_CH, X86_CL, X86_DH, X86_DL); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - } - break; - - case 0x07: - /* Initialise or Scroll Window Down */ - /* Enter: AL = lines to scroll down */ - /* BH = attribute for blank */ - /* CH = upper y of window */ - /* CL = left x of window */ - /* DH = lower y of window */ - /* DL = right x of window */ - /* Leave: Nothing */ - /* Not Implemented */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x07) -- Initialise or Scroll Window Down\n", - pInt->num); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3, - " AL=0x%2.2x, BH=0x%2.2x," - " CH=0x%2.2x, CL=0x%2.2x, DH=0x%2.2x, DL=0x%2.2x\n", - X86_AL, X86_BH, X86_CH, X86_CL, X86_DH, X86_DL); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - } - break; - - case 0x08: - /* Read Character and Attribute at Cursor */ - /* Enter: BH = display page number */ - /* Leave: AH = attribute */ - /* AL = character */ - /* Not Implemented */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x08) -- Read Character and Attribute at" - " Cursor\n", pInt->num); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3, - "BH=0x%2.2x\n", X86_BH); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - X86_AX = 0; - } - break; - - case 0x09: - /* Write Character and Attribute at Cursor */ - /* Enter: AL = character */ - /* BH = display page number */ - /* BL = attribute (text) or colour (graphics) */ - /* CX = replication count */ - /* Leave: Nothing */ - /* Not Implemented */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x09) -- Write Character and Attribute at" - " Cursor\n", pInt->num); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3, - "AL=0x%2.2x, BH=0x%2.2x, BL=0x%2.2x, CX=0x%4.4x\n", - X86_AL, X86_BH, X86_BL, X86_CX); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - } - break; - - case 0x0a: - /* Write Character at Cursor */ - /* Enter: AL = character */ - /* BH = display page number */ - /* BL = colour */ - /* CX = replication count */ - /* Leave: Nothing */ - /* Not Implemented */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x0A) -- Write Character at Cursor\n", - pInt->num); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3, - "AL=0x%2.2x, BH=0x%2.2x, BL=0x%2.2x, CX=0x%4.4x\n", - X86_AL, X86_BH, X86_BL, X86_CX); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - } - break; - - case 0x0b: - /* Set Palette, Background or Border */ - /* Enter: BH = 0x00 or 0x01 */ - /* BL = colour or palette (respectively) */ - /* Leave: Nothing */ - /* Implemented */ - { /* Localise */ - unsigned int ioport = MEM_RW(pInt, 0x0463) + 5; - CARD8 cgacolour = MEM_RB(pInt, 0x0466); - - if (X86_BH) { - cgacolour &= 0xDF; - cgacolour |= (X86_BL & 0x01) << 5; - } - else { - cgacolour &= 0xE0; - cgacolour |= X86_BL & 0x1F; - } - - MEM_WB(pInt, 0x0466, cgacolour); - pci_io_write8(pInt->io, ioport, cgacolour); - } - break; - - case 0x0c: - /* Write Graphics Pixel */ - /* Enter: AL = pixel value */ - /* BH = display page number */ - /* CX = column */ - /* DX = row */ - /* Leave: Nothing */ - /* Not Implemented */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x0C) -- Write Graphics Pixel\n", - pInt->num); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3, - "AL=0x%2.2x, BH=0x%2.2x, CX=0x%4.4x, DX=0x%4.4x\n", - X86_AL, X86_BH, X86_CX, X86_DX); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - } - break; - - case 0x0d: - /* Read Graphics Pixel */ - /* Enter: BH = display page number */ - /* CX = column */ - /* DX = row */ - /* Leave: AL = pixel value */ - /* Not Implemented */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x0D) -- Read Graphics Pixel\n", - pInt->num); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3, - "BH=0x%2.2x, CX=0x%4.4x, DX=0x%4.4x\n", X86_BH, X86_CX, - X86_DX); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - X86_AL = 0; - } - break; - - case 0x0e: - /* Write Character in Teletype Mode */ - /* Enter: AL = character */ - /* BH = display page number */ - /* BL = foreground colour */ - /* Leave: Nothing */ - /* Not Implemented */ - /* WARNING: Emulation of BEL characters will require */ - /* emulation of RTC and PC speaker I/O. */ - /* Also, this recurses through int 0x10 */ - /* which might or might not have been */ - /* installed yet. */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x0E) -- Write Character in Teletype Mode\n", - pInt->num); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3, - "AL=0x%2.2x, BH=0x%2.2x, BL=0x%2.2x\n", - X86_AL, X86_BH, X86_BL); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - } - break; - - case 0x0f: - /* Get Video Mode */ - /* Enter: Nothing */ - /* Leave: AH = number of columns */ - /* AL = video mode number */ - /* BH = display page number */ - /* Implemented */ - { /* Localise */ - X86_AH = MEM_RW(pInt, 0x044A); - X86_AL = MEM_RB(pInt, 0x0449); - X86_BH = MEM_RB(pInt, 0x0462); - } - break; - - case 0x10: - /* Colour Control (subfunction in AL) */ - /* Enter: Various */ - /* Leave: Various */ - /* Ignored */ - break; - - case 0x11: - /* Font Control (subfunction in AL) */ - /* Enter: Various */ - /* Leave: Various */ - /* Ignored */ - break; - - case 0x12: - /* Miscellaneous (subfunction in BL) */ - /* Enter: Various */ - /* Leave: Various */ - /* Ignored. Previous code here optionally allowed */ - /* the enabling and disabling of VGA, but no system */ - /* BIOS I've come across actually implements it. */ - break; - - case 0x13: - /* Write String in Teletype Mode */ - /* Enter: AL = write mode */ - /* BL = attribute (if (AL & 0x02) == 0) */ - /* CX = string length */ - /* DH = row */ - /* DL = column */ - /* ES:BP = string segment:offset */ - /* Leave: Nothing */ - /* Not Implemented */ - /* WARNING: Emulation of BEL characters will require */ - /* emulation of RTC and PC speaker I/O. */ - /* Also, this recurses through int 0x10 */ - /* which might or might not have been */ - /* installed yet. */ - { /* Localise */ - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x%2.2x(AH=0x13) -- Write String in Teletype Mode\n", - pInt->num); - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 3, - "AL=0x%2.2x, BL=0x%2.2x, CX=0x%4.4x," - " DH=0x%2.2x, DL=0x%2.2x, ES:BP=0x%4.4x:0x%4.4x\n", - X86_AL, X86_BL, X86_CX, X86_DH, X86_DL, X86_ES, X86_BP); - if (xf86GetVerbosity() > 3) { - dump_registers(pInt); - stack_trace(pInt); - } - } - break; - - default: - /* Various extensions */ - /* Enter: Various */ - /* Leave: Various */ - /* Ignored */ - break; - } - - return 1; -} -#endif - -#define SUCCESSFUL 0x00 -#define DEVICE_NOT_FOUND 0x86 -#define BAD_REGISTER_NUMBER 0x87 - -#ifdef SHOW_ALL_DEVICES -/** - * These functions are meant to be used by the PCI BIOS emulation. Some - * BIOSes need to see if there are \b other chips of the same type around so - * by setting \c exclude one PCI device can be explicitly excluded, if - * required. - */ -static struct pci_device * -do_find(const struct pci_id_match *m, char n, const struct pci_device *exclude) -{ - struct pci_device *dev; - struct pci_device_iterator *iter; - - n++; - - iter = pci_id_match_iterator_create(m); - while ((dev = pci_device_next(iter)) != NULL) { - if ((dev != exclude) && !(--n)) { - break; - } - } - - pci_iterator_destroy(iter); - - return dev; -} - -static struct pci_device * -find_pci_device_vendor(CARD16 vendorID, CARD16 deviceID, - char n, const struct pci_device *exclude) -{ - struct pci_id_match m; - - m.vendor_id = vendorID; - m.device_id = deviceID; - m.subvendor_id = PCI_MATCH_ANY; - m.subdevice_id = PCI_MATCH_ANY; - m.device_class = 0; - m.device_class_mask = 0; - - return do_find(&m, n, exclude); -} - -static struct pci_device * -find_pci_class(CARD8 intf, CARD8 subClass, CARD16 _class, - char n, const struct pci_device *exclude) -{ - struct pci_id_match m; - - m.vendor_id = PCI_MATCH_ANY; - m.device_id = PCI_MATCH_ANY; - m.subvendor_id = PCI_MATCH_ANY; - m.subdevice_id = PCI_MATCH_ANY; - m.device_class = (((uint32_t) _class) << 16) - | (((uint32_t) subClass) << 8) | intf; - m.device_class_mask = 0x00ffffff; - - return do_find(&m, n, exclude); -} -#endif - -/* - * Return the last bus number in the same domain as dev. Only look at the - * one domain since this is going into %cl, and VGA I/O is per-domain anyway. - */ -static int -int1A_last_bus_number(struct pci_device *dev) -{ - struct pci_device *d; - - struct pci_slot_match m = { dev->domain, - PCI_MATCH_ANY, - PCI_MATCH_ANY, - PCI_MATCH_ANY - }; - struct pci_device_iterator *iter; - int i = 0; - - iter = pci_slot_match_iterator_create(&m); - - while ((d = pci_device_next(iter))) - if (d->bus > i) - i = d->bus; - - pci_iterator_destroy(iter); - - return i; -} - -static int -int1A_handler(xf86Int10InfoPtr pInt) -{ - struct pci_device *const pvp = xf86GetPciInfoForEntity(pInt->entityIndex); - struct pci_device *dev; - - if (pvp == NULL) - return 0; /* oops */ - -#ifdef PRINT_INT - ErrorF("int 0x1a: ax=0x%x bx=0x%x cx=0x%x dx=0x%x di=0x%x es=0x%x\n", - X86_EAX, X86_EBX, X86_ECX, X86_EDX, X86_EDI, X86_ESI); -#endif - switch (X86_AX) { - case 0xb101: - X86_EAX &= 0xFF00; /* no config space/special cycle support */ - X86_EDX = 0x20494350; /* " ICP" */ - X86_EBX = 0x0210; /* Version 2.10 */ - X86_ECX &= 0xFF00; - X86_ECX |= int1A_last_bus_number(pvp); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ -#ifdef PRINT_INT - ErrorF("ax=0x%x dx=0x%x bx=0x%x cx=0x%x flags=0x%x\n", - X86_EAX, X86_EDX, X86_EBX, X86_ECX, X86_EFLAGS); -#endif - return 1; - case 0xb102: - if ((X86_DX == pvp->vendor_id) - && (X86_CX == pvp->device_id) - && (X86_ESI == 0)) { - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - X86_EBX = pciSlotBX(pvp); - } -#ifdef SHOW_ALL_DEVICES - else if ((dev = find_pci_device_vendor(X86_EDX, X86_ECX, X86_ESI, pvp))) { - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - X86_EBX = pciSlotBX(dev); - } -#endif - else { - X86_EAX = X86_AL | (DEVICE_NOT_FOUND << 8); - X86_EFLAGS |= ((unsigned long) 0x01); /* set carry flag */ - } -#ifdef PRINT_INT - ErrorF("ax=0x%x bx=0x%x flags=0x%x\n", X86_EAX, X86_EBX, X86_EFLAGS); -#endif - return 1; - case 0xb103: - if ((X86_ECX & 0x00FFFFFF) == pvp->device_class) { - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EBX = pciSlotBX(pvp); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - } -#ifdef SHOW_ALL_DEVICES - else if ((dev = find_pci_class(X86_CL, X86_CH, - (X86_ECX & 0xffff0000) >> 16, - X86_ESI, pvp))) { - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - X86_EBX = pciSlotBX(dev); - } -#endif - else { - X86_EAX = X86_AL | (DEVICE_NOT_FOUND << 8); - X86_EFLAGS |= ((unsigned long) 0x01); /* set carry flag */ - } -#ifdef PRINT_INT - ErrorF("ax=0x%x flags=0x%x\n", X86_EAX, X86_EFLAGS); -#endif - return 1; - case 0xb108: - if ((dev = findPci(pInt, X86_EBX)) != NULL) { - pci_device_cfg_read_u8(dev, &X86_CL, X86_DI); - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - } - else { - X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8); - X86_EFLAGS |= ((unsigned long) 0x01); /* set carry flag */ - } -#ifdef PRINT_INT - ErrorF("ax=0x%x cx=0x%x flags=0x%x\n", X86_EAX, X86_ECX, X86_EFLAGS); -#endif - return 1; - case 0xb109: - if ((dev = findPci(pInt, X86_EBX)) != NULL) { - pci_device_cfg_read_u16(dev, &X86_CX, X86_DI); - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - } - else { - X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8); - X86_EFLAGS |= ((unsigned long) 0x01); /* set carry flag */ - } -#ifdef PRINT_INT - ErrorF("ax=0x%x cx=0x%x flags=0x%x\n", X86_EAX, X86_ECX, X86_EFLAGS); -#endif - return 1; - case 0xb10a: - if ((dev = findPci(pInt, X86_EBX)) != NULL) { - pci_device_cfg_read_u32(dev, &X86_ECX, X86_DI); - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - } - else { - X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8); - X86_EFLAGS |= ((unsigned long) 0x01); /* set carry flag */ - } -#ifdef PRINT_INT - ErrorF("ax=0x%x cx=0x%x flags=0x%x\n", X86_EAX, X86_ECX, X86_EFLAGS); -#endif - return 1; - case 0xb10b: - if ((dev = findPci(pInt, X86_EBX)) != NULL) { - pci_device_cfg_write_u8(dev, X86_CL, X86_DI); - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - } - else { - X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8); - X86_EFLAGS |= ((unsigned long) 0x01); /* set carry flag */ - } -#ifdef PRINT_INT - ErrorF("ax=0x%x flags=0x%x\n", X86_EAX, X86_EFLAGS); -#endif - return 1; - case 0xb10c: - if ((dev = findPci(pInt, X86_EBX)) != NULL) { - pci_device_cfg_write_u16(dev, X86_CX, X86_DI); - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - } - else { - X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8); - X86_EFLAGS |= ((unsigned long) 0x01); /* set carry flag */ - } -#ifdef PRINT_INT - ErrorF("ax=0x%x flags=0x%x\n", X86_EAX, X86_EFLAGS); -#endif - return 1; - case 0xb10d: - if ((dev = findPci(pInt, X86_EBX)) != NULL) { - pci_device_cfg_write_u32(dev, X86_ECX, X86_DI); - X86_EAX = X86_AL | (SUCCESSFUL << 8); - X86_EFLAGS &= ~((unsigned long) 0x01); /* clear carry flag */ - } - else { - X86_EAX = X86_AL | (BAD_REGISTER_NUMBER << 8); - X86_EFLAGS |= ((unsigned long) 0x01); /* set carry flag */ - } -#ifdef PRINT_INT - ErrorF("ax=0x%x flags=0x%x\n", X86_EAX, X86_EFLAGS); -#endif - return 1; - default: - xf86DrvMsgVerb(pInt->pScrn->scrnIndex, X_NOT_IMPLEMENTED, 2, - "int 0x1a subfunction\n"); - dump_registers(pInt); - if (xf86GetVerbosity() > 3) - stack_trace(pInt); - return 0; - } -} - -static struct pci_device * -findPci(xf86Int10InfoPtr pInt, unsigned short bx) -{ - const unsigned bus = (bx >> 8) & 0x00FF; - const unsigned dev = (bx >> 3) & 0x001F; - const unsigned func = (bx) & 0x0007; - - return pci_device_find_by_slot(pInt->dev->domain, bus, dev, func); -} - -static CARD32 -pciSlotBX(const struct pci_device *pvp) -{ - return ((pvp->bus << 8) & 0x00FF00) | (pvp->dev << 3) | (pvp->func); -} - -/* - * handle initialization - */ -static int -intE6_handler(xf86Int10InfoPtr pInt) -{ - struct pci_device *pvp; - - if ((pvp = xf86GetPciInfoForEntity(pInt->entityIndex))) - X86_AX = (pvp->bus << 8) | (pvp->dev << 3) | (pvp->func & 0x7); - pushw(pInt, X86_CS); - pushw(pInt, X86_IP); - X86_CS = pInt->BIOSseg; - X86_EIP = 0x0003; - X86_ES = 0; /* standard pc es */ - return 1; -} diff --git a/hw/xfree86/int10/xf86int10.h b/hw/xfree86/int10/xf86int10.h deleted file mode 100644 index 83bab7e61..000000000 --- a/hw/xfree86/int10/xf86int10.h +++ /dev/null @@ -1,191 +0,0 @@ - -/* - * XFree86 int10 module - * execute BIOS int 10h calls in x86 real mode environment - * Copyright 1999 Egbert Eich - */ - -#ifndef _XF86INT10_H -#define _XF86INT10_H - -#include -#include -#include "xf86Pci.h" - -#define SEG_ADDR(x) (((x) >> 4) & 0x00F000) -#define SEG_OFF(x) ((x) & 0x0FFFF) - -#define SET_BIOS_SCRATCH 0x1 -#define RESTORE_BIOS_SCRATCH 0x2 - -/* int10 info structure */ -typedef struct { - int entityIndex; - uint16_t BIOSseg; - uint16_t inb40time; - ScrnInfoPtr pScrn; - void *cpuRegs; - char *BIOSScratch; - int Flags; - void *private; - struct _int10Mem *mem; - int num; - int ax; - int bx; - int cx; - int dx; - int si; - int di; - int es; - int bp; - int flags; - int stackseg; - struct pci_device *dev; - struct pci_io_handle *io; -} xf86Int10InfoRec, *xf86Int10InfoPtr; - -typedef struct _int10Mem { - uint8_t (*rb) (xf86Int10InfoPtr, int); - uint16_t (*rw) (xf86Int10InfoPtr, int); - uint32_t (*rl) (xf86Int10InfoPtr, int); - void (*wb) (xf86Int10InfoPtr, int, uint8_t); - void (*ww) (xf86Int10InfoPtr, int, uint16_t); - void (*wl) (xf86Int10InfoPtr, int, uint32_t); -} int10MemRec, *int10MemPtr; - -typedef struct { - uint8_t save_msr; - uint8_t save_pos102; - uint8_t save_vse; - uint8_t save_46e8; -} legacyVGARec, *legacyVGAPtr; - -/* OS dependent functions */ -extern _X_EXPORT xf86Int10InfoPtr xf86InitInt10(int entityIndex); -extern _X_EXPORT xf86Int10InfoPtr xf86ExtendedInitInt10(int entityIndex, - int Flags); -extern _X_EXPORT void xf86FreeInt10(xf86Int10InfoPtr pInt); -extern _X_EXPORT void *xf86Int10AllocPages(xf86Int10InfoPtr pInt, int num, - int *off); -extern _X_EXPORT void xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, - int num); -extern _X_EXPORT void *xf86int10Addr(xf86Int10InfoPtr pInt, uint32_t addr); - -/* x86 executor related functions */ -extern _X_EXPORT void xf86ExecX86int10(xf86Int10InfoPtr pInt); - -#ifdef _INT10_PRIVATE - -#define I_S_DEFAULT_INT_VECT 0xFF065 -#define SYS_SIZE 0x100000 -#define SYS_BIOS 0xF0000 -#if 1 -#define BIOS_SIZE 0x10000 -#else /* a bug in DGUX requires this - let's try it */ -#define BIOS_SIZE (0x10000 - 1) -#endif -#define LOW_PAGE_SIZE 0x600 -#define V_RAM 0xA0000 -#define VRAM_SIZE 0x20000 -#define V_BIOS_SIZE 0x10000 -#define V_BIOS 0xC0000 -#define BIOS_SCRATCH_OFF 0x449 -#define BIOS_SCRATCH_END 0x466 -#define BIOS_SCRATCH_LEN (BIOS_SCRATCH_END - BIOS_SCRATCH_OFF + 1) -#define HIGH_MEM V_BIOS -#define HIGH_MEM_SIZE (SYS_BIOS - HIGH_MEM) -#define SEG_ADR(type, seg, reg) type((seg << 4) + (X86_##reg)) -#define SEG_EADR(type, seg, reg) type((seg << 4) + (X86_E##reg)) - -#define X86_TF_MASK 0x00000100 -#define X86_IF_MASK 0x00000200 -#define X86_IOPL_MASK 0x00003000 -#define X86_NT_MASK 0x00004000 -#define X86_VM_MASK 0x00020000 -#define X86_AC_MASK 0x00040000 -#define X86_VIF_MASK 0x00080000 /* virtual interrupt flag */ -#define X86_VIP_MASK 0x00100000 /* virtual interrupt pending */ -#define X86_ID_MASK 0x00200000 - -#define MEM_RB(name, addr) (*name->mem->rb)(name, addr) -#define MEM_RW(name, addr) (*name->mem->rw)(name, addr) -#define MEM_RL(name, addr) (*name->mem->rl)(name, addr) -#define MEM_WB(name, addr, val) (*name->mem->wb)(name, addr, val) -#define MEM_WW(name, addr, val) (*name->mem->ww)(name, addr, val) -#define MEM_WL(name, addr, val) (*name->mem->wl)(name, addr, val) - -/* OS dependent functions */ -extern _X_EXPORT Bool MapCurrentInt10(xf86Int10InfoPtr pInt); - -/* x86 executor related functions */ -extern _X_EXPORT Bool xf86Int10ExecSetup(xf86Int10InfoPtr pInt); - -/* int.c */ -extern _X_EXPORT xf86Int10InfoPtr Int10Current; -int int_handler(xf86Int10InfoPtr pInt); - -/* helper_exec.c */ -int setup_int(xf86Int10InfoPtr pInt); -void finish_int(xf86Int10InfoPtr, int sig); -uint32_t getIntVect(xf86Int10InfoPtr pInt, int num); -void pushw(xf86Int10InfoPtr pInt, uint16_t val); -int run_bios_int(int num, xf86Int10InfoPtr pInt); -void dump_code(xf86Int10InfoPtr pInt); -void dump_registers(xf86Int10InfoPtr pInt); -void stack_trace(xf86Int10InfoPtr pInt); -uint8_t bios_checksum(const uint8_t *start, int size); -void LockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga); -void UnlockLegacyVGA(xf86Int10InfoPtr pInt, legacyVGAPtr vga); - -#if defined (_PC) -extern _X_EXPORT void xf86Int10SaveRestoreBIOSVars(xf86Int10InfoPtr pInt, - Bool save); -#endif -int port_rep_inb(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count); -int port_rep_inw(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count); -int port_rep_inl(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count); -int port_rep_outb(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count); -int port_rep_outw(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count); -int port_rep_outl(xf86Int10InfoPtr pInt, - uint16_t port, uint32_t base, int d_f, uint32_t count); - -uint8_t x_inb(uint16_t port); -uint16_t x_inw(uint16_t port); -void x_outb(uint16_t port, uint8_t val); -void x_outw(uint16_t port, uint16_t val); -uint32_t x_inl(uint16_t port); -void x_outl(uint16_t port, uint32_t val); - -uint8_t Mem_rb(uint32_t addr); -uint16_t Mem_rw(uint32_t addr); -uint32_t Mem_rl(uint32_t addr); -void Mem_wb(uint32_t addr, uint8_t val); -void Mem_ww(uint32_t addr, uint16_t val); -void Mem_wl(uint32_t addr, uint32_t val); - -/* helper_mem.c */ -void setup_int_vect(xf86Int10InfoPtr pInt); -int setup_system_bios(void *base_addr); -void reset_int_vect(xf86Int10InfoPtr pInt); -void set_return_trap(xf86Int10InfoPtr pInt); -extern _X_EXPORT void *xf86HandleInt10Options(ScrnInfoPtr pScrn, - int entityIndex); -Bool int10skip(const void *options); -Bool int10_check_bios(int scrnIndex, int codeSeg, - const unsigned char *vbiosMem); -Bool initPrimary(const void *options); -extern _X_EXPORT BusType xf86int10GetBiosLocationType(const xf86Int10InfoPtr - pInt); -extern _X_EXPORT Bool xf86int10GetBiosSegment(xf86Int10InfoPtr pInt, - void *base); -#ifdef DEBUG -void dprint(unsigned long start, unsigned long size); -#endif - -#endif /* _INT10_PRIVATE */ -#endif /* _XF86INT10_H */ diff --git a/hw/xfree86/int10/xf86int10module.c b/hw/xfree86/int10/xf86int10module.c deleted file mode 100644 index 1eb5a0783..000000000 --- a/hw/xfree86/int10/xf86int10module.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * XFree86 int10 module - * execute BIOS int 10h calls in x86 real mode environment - * Copyright 1999 Egbert Eich - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86str.h" -#include "xf86Pci.h" -#include "xf86int10.h" - -#ifndef MOD_NAME -#define MOD_NAME int10 -#endif - -#define stringify(x) #x -#define STRING(x) stringify(x) -#define concat(x,y) x ## y -#define combine(a,b) concat(a,b) -#define NAME(x) combine(MOD_NAME,x) - -static XF86ModuleVersionInfo NAME(VersRec) = { - STRING(NAME()), MODULEVENDORSTRING, MODINFOSTRING1, MODINFOSTRING2, XORG_VERSION_CURRENT, 1, 0, 0, ABI_CLASS_VIDEODRV, /* needs the video driver ABI */ - ABI_VIDEODRV_VERSION, MOD_CLASS_NONE, { - 0, 0, 0, 0} -}; - -_X_EXPORT XF86ModuleData NAME(ModuleData) = { -&NAME(VersRec), NULL, NULL}; diff --git a/hw/xfree86/int10/xf86x86emu.c b/hw/xfree86/int10/xf86x86emu.c deleted file mode 100644 index 1dc695d2c..000000000 --- a/hw/xfree86/int10/xf86x86emu.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * XFree86 int10 module - * execute BIOS int 10h calls in x86 real mode environment - * Copyright 1999 Egbert Eich - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86_OSproc.h" -#include "xf86Pci.h" -#define _INT10_PRIVATE -#include "xf86int10.h" -#include "int10Defines.h" -#include - -#define M _X86EMU_env - -static void -x86emu_do_int(int num) -{ - Int10Current->num = num; - - if (!int_handler(Int10Current)) { - X86EMU_halt_sys(); - } -} - -void -xf86ExecX86int10(xf86Int10InfoPtr pInt) -{ - int sig = setup_int(pInt); - - if (sig < 0) - return; - - if (int_handler(pInt)) { - X86EMU_exec(); - } - - finish_int(pInt, sig); -} - -Bool -xf86Int10ExecSetup(xf86Int10InfoPtr pInt) -{ - int i; - X86EMU_intrFuncs intFuncs[256]; - - X86EMU_pioFuncs pioFuncs = { - .inb = x_inb, - .inw = x_inw, - .inl = x_inl, - .outb = x_outb, - .outw = x_outw, - .outl = x_outl - }; - - X86EMU_memFuncs memFuncs = { - (&Mem_rb), - (&Mem_rw), - (&Mem_rl), - (&Mem_wb), - (&Mem_ww), - (&Mem_wl) - }; - - X86EMU_setupMemFuncs(&memFuncs); - - pInt->cpuRegs = &M; - M.mem_base = 0; - M.mem_size = 1024 * 1024 + 1024; - X86EMU_setupPioFuncs(&pioFuncs); - - for (i = 0; i < 256; i++) - intFuncs[i] = x86emu_do_int; - X86EMU_setupIntrFuncs(intFuncs); - return TRUE; -} - -void -printk(const char *fmt, ...) -{ - va_list argptr; - - va_start(argptr, fmt); - VErrorF(fmt, argptr); - va_end(argptr); -} diff --git a/hw/xfree86/int10/xf86x86emu.h b/hw/xfree86/int10/xf86x86emu.h deleted file mode 100644 index 4af2dafb7..000000000 --- a/hw/xfree86/int10/xf86x86emu.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * XFree86 int10 module - * execute BIOS int 10h calls in x86 real mode environment - * Copyright 1999 Egbert Eich - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef XF86X86EMU_H_ -#define XF86X86EMU_H_ -#include - -#define M _X86EMU_env - -#define X86_EAX M.x86.R_EAX -#define X86_EBX M.x86.R_EBX -#define X86_ECX M.x86.R_ECX -#define X86_EDX M.x86.R_EDX -#define X86_ESI M.x86.R_ESI -#define X86_EDI M.x86.R_EDI -#define X86_EBP M.x86.R_EBP -#define X86_EIP M.x86.R_EIP -#define X86_ESP M.x86.R_ESP -#define X86_EFLAGS M.x86.R_EFLG - -#define X86_FLAGS M.x86.R_FLG -#define X86_AX M.x86.R_AX -#define X86_BX M.x86.R_BX -#define X86_CX M.x86.R_CX -#define X86_DX M.x86.R_DX -#define X86_SI M.x86.R_SI -#define X86_DI M.x86.R_DI -#define X86_BP M.x86.R_BP -#define X86_IP M.x86.R_IP -#define X86_SP M.x86.R_SP -#define X86_CS M.x86.R_CS -#define X86_DS M.x86.R_DS -#define X86_ES M.x86.R_ES -#define X86_SS M.x86.R_SS -#define X86_FS M.x86.R_FS -#define X86_GS M.x86.R_GS - -#define X86_AL M.x86.R_AL -#define X86_BL M.x86.R_BL -#define X86_CL M.x86.R_CL -#define X86_DL M.x86.R_DL - -#define X86_AH M.x86.R_AH -#define X86_BH M.x86.R_BH -#define X86_CH M.x86.R_CH -#define X86_DH M.x86.R_DH - -#endif diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c deleted file mode 100644 index 2580e93d9..000000000 --- a/hw/xfree86/loader/loader.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 1995-1998 by Metro Link, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Metro Link, Inc. not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Metro Link, Inc. makes no - * representations about the suitability of this software for any purpose. - * It is provided "as is" without express or implied warranty. - * - * METRO LINK, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL METRO LINK, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "loader.h" -#include "loaderProcs.h" - -#ifdef HAVE_DLFCN_H - -#include -#include - -#else -#error i have no dynamic linker and i must scream -#endif - -#ifndef XORG_NO_SDKSYMS -extern void *xorg_symbols[]; -#endif - -void -LoaderInit(void) -{ -#ifndef XORG_NO_SDKSYMS - LogMessageVerb(X_INFO, 2, "Loader magic: %p\n", (void *) xorg_symbols); -#endif - LogMessageVerb(X_INFO, 2, "Module ABI versions:\n"); - LogWrite(2, "\t%s: %d.%d\n", ABI_CLASS_ANSIC, - GET_ABI_MAJOR(LoaderVersionInfo.ansicVersion), - GET_ABI_MINOR(LoaderVersionInfo.ansicVersion)); - LogWrite(2, "\t%s: %d.%d\n", ABI_CLASS_VIDEODRV, - GET_ABI_MAJOR(LoaderVersionInfo.videodrvVersion), - GET_ABI_MINOR(LoaderVersionInfo.videodrvVersion)); - LogWrite(2, "\t%s : %d.%d\n", ABI_CLASS_XINPUT, - GET_ABI_MAJOR(LoaderVersionInfo.xinputVersion), - GET_ABI_MINOR(LoaderVersionInfo.xinputVersion)); - LogWrite(2, "\t%s : %d.%d\n", ABI_CLASS_EXTENSION, - GET_ABI_MAJOR(LoaderVersionInfo.extensionVersion), - GET_ABI_MINOR(LoaderVersionInfo.extensionVersion)); - -} - -/* Public Interface to the loader. */ - -void * -LoaderOpen(const char *module, int *errmaj) -{ - void *ret; - -#if defined(DEBUG) - ErrorF("LoaderOpen(%s)\n", module); -#endif - - LogMessage(X_INFO, "Loading %s\n", module); - - if (!(ret = dlopen(module, RTLD_LAZY | RTLD_GLOBAL))) { - LogMessage(X_ERROR, "Failed to load %s: %s\n", module, dlerror()); - if (errmaj) - *errmaj = LDR_NOLOAD; - return NULL; - } - - return ret; -} - -void * -LoaderSymbol(const char *name) -{ - static void *global_scope = NULL; - void *p; - - p = dlsym(RTLD_DEFAULT, name); - if (p != NULL) - return p; - - if (!global_scope) - global_scope = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); - - if (global_scope) - return dlsym(global_scope, name); - - return NULL; -} - -void * -LoaderSymbolFromModule(void *handle, const char *name) -{ - ModuleDescPtr mod = handle; - return dlsym(mod->handle, name); -} - -void -LoaderUnload(const char *name, void *handle) -{ - LogMessageVerbSigSafe(X_INFO, 1, "Unloading %s\n", name); - if (handle) - dlclose(handle); -} - -unsigned long LoaderOptions = 0; - -void -LoaderSetOptions(unsigned long opts) -{ - LoaderOptions |= opts; -} - -Bool -LoaderShouldIgnoreABI(void) -{ - return (LoaderOptions & LDR_OPT_ABI_MISMATCH_NONFATAL) != 0; -} - -int -LoaderGetABIVersion(const char *abiclass) -{ - struct { - const char *name; - int version; - } classes[] = { - {ABI_CLASS_ANSIC, LoaderVersionInfo.ansicVersion}, - {ABI_CLASS_VIDEODRV, LoaderVersionInfo.videodrvVersion}, - {ABI_CLASS_XINPUT, LoaderVersionInfo.xinputVersion}, - {ABI_CLASS_EXTENSION, LoaderVersionInfo.extensionVersion}, - {NULL, 0} - }; - int i; - - for (i = 0; classes[i].name; i++) { - if (!strcmp(classes[i].name, abiclass)) { - return classes[i].version; - } - } - - return 0; -} diff --git a/hw/xfree86/loader/loader.h b/hw/xfree86/loader/loader.h deleted file mode 100644 index 4e83730a2..000000000 --- a/hw/xfree86/loader/loader.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 1995-1998 by Metro Link, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Metro Link, Inc. not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Metro Link, Inc. makes no - * representations about the suitability of this software for any purpose. - * It is provided "as is" without express or implied warranty. - * - * METRO LINK, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL METRO LINK, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Copyright (c) 1997-2001 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _LOADER_H -#define _LOADER_H - -#include -#include -#include - -/* Compiled-in version information */ -typedef struct { - int xf86Version; - int ansicVersion; - int videodrvVersion; - int xinputVersion; - int extensionVersion; - int fontVersion; -} ModuleVersions; -extern const ModuleVersions LoaderVersionInfo; - -extern unsigned long LoaderOptions; - -/* Internal Functions */ -void *LoaderOpen(const char *, int *); - -#endif /* _LOADER_H */ diff --git a/hw/xfree86/loader/loaderProcs.h b/hw/xfree86/loader/loaderProcs.h deleted file mode 100644 index 8b16cb7ea..000000000 --- a/hw/xfree86/loader/loaderProcs.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 1995-1998 by Metro Link, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Metro Link, Inc. not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Metro Link, Inc. makes no - * representations about the suitability of this software for any purpose. - * It is provided "as is" without express or implied warranty. - * - * METRO LINK, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL METRO LINK, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Copyright (c) 1997-2002 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _LOADERPROCS_H -#define _LOADERPROCS_H - -#include "xf86Module.h" - -typedef struct module_desc { - struct module_desc *child; - struct module_desc *sib; - struct module_desc *parent; - void *handle; - ModuleSetupProc SetupProc; - ModuleTearDownProc TearDownProc; - void *TearDownData; /* returned from SetupProc */ - const XF86ModuleVersionInfo *VersionInfo; -} ModuleDesc, *ModuleDescPtr; - -/* External API for the loader */ - -void LoaderInit(void); - -ModuleDescPtr LoadModule(const char *, void *, const XF86ModReqInfo *, int *); -ModuleDescPtr DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent); -void UnloadDriver(ModuleDescPtr); -void LoaderSetPath(const char *path); - -void LoaderUnload(const char *, void *); -unsigned long LoaderGetModuleVersion(ModuleDescPtr mod); - -void LoaderResetOptions(void); -void LoaderSetOptions(unsigned long); - -const char **LoaderListDir(const char *, const char **); - -/* Options for LoaderSetOptions */ -#define LDR_OPT_ABI_MISMATCH_NONFATAL 0x0001 - -#endif /* _LOADERPROCS_H */ diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c deleted file mode 100644 index f8a44827f..000000000 --- a/hw/xfree86/loader/loadmod.c +++ /dev/null @@ -1,1009 +0,0 @@ -/* - * Copyright 1995-1998 by Metro Link, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Metro Link, Inc. not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Metro Link, Inc. makes no - * representations about the suitability of this software for any purpose. - * It is provided "as is" without express or implied warranty. - * - * METRO LINK, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL METRO LINK, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ -/* - * Copyright (c) 1997-2002 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "dix.h" -#include "os.h" -#include "loaderProcs.h" -#include "xf86Module.h" -#include "loader.h" - -#include -#include -#include -#include -#include - -typedef struct _pattern { - const char *pattern; - regex_t rex; -} PatternRec, *PatternPtr; - -/* Prototypes for static functions */ -static char *FindModule(const char *, const char *, PatternPtr); -static Bool CheckVersion(const char *, XF86ModuleVersionInfo *, - const XF86ModReqInfo *); -static char *LoaderGetCanonicalName(const char *, PatternPtr); -static void RemoveChild(ModuleDescPtr); - -const ModuleVersions LoaderVersionInfo = { - XORG_VERSION_CURRENT, - ABI_ANSIC_VERSION, - ABI_VIDEODRV_VERSION, - ABI_XINPUT_VERSION, - ABI_EXTENSION_VERSION, -}; - -static int ModuleDuplicated[] = { }; - -static void -FreeStringList(char **paths) -{ - char **p; - - if (!paths) - return; - - for (p = paths; *p; p++) - free(*p); - - free(paths); -} - -static char **defaultPathList = NULL; - -static Bool -PathIsAbsolute(const char *path) -{ - return *path == '/'; -} - -/* - * Convert a comma-separated path into a NULL-terminated array of path - * elements, rejecting any that are not full absolute paths, and appending - * a '/' when it isn't already present. - */ -static char ** -InitPathList(const char *path) -{ - char *fullpath = NULL; - char *elem = NULL; - char **list = NULL, **save = NULL; - int len; - int addslash; - int n = 0; - - fullpath = strdup(path); - if (!fullpath) - return NULL; - elem = strtok(fullpath, ","); - while (elem) { - if (PathIsAbsolute(elem)) { - len = strlen(elem); - addslash = (elem[len - 1] != '/'); - if (addslash) - len++; - save = list; - list = reallocarray(list, n + 2, sizeof(char *)); - if (!list) { - if (save) { - save[n] = NULL; - FreeStringList(save); - } - free(fullpath); - return NULL; - } - list[n] = malloc(len + 1); - if (!list[n]) { - FreeStringList(list); - free(fullpath); - return NULL; - } - strcpy(list[n], elem); - if (addslash) { - list[n][len - 1] = '/'; - list[n][len] = '\0'; - } - n++; - } - elem = strtok(NULL, ","); - } - if (list) - list[n] = NULL; - free(fullpath); - return list; -} - -void -LoaderSetPath(const char *path) -{ - if (!path) - return; - - FreeStringList(defaultPathList); - defaultPathList = InitPathList(path); -} - -/* Standard set of module subdirectories to search, in order of preference */ -static const char *stdSubdirs[] = { - "", - "input/", - "drivers/", - "extensions/", - NULL -}; - -/* - * Standard set of module name patterns to check, in order of preference - * These are regular expressions (suitable for use with POSIX regex(3)). - * - * This list assumes that you're an ELFish platform and therefore your - * shared libraries are named something.so. If we're ever nuts enough - * to port this DDX to, say, Darwin, we'll need to fix this. - */ -static PatternRec stdPatterns[] = { -#ifdef __CYGWIN__ - {"^cyg(.*)\\.dll$",}, - {"(.*)_drv\\.dll$",}, - {"(.*)\\.dll$",}, -#else - {"^lib(.*)\\.so$",}, - {"(.*)_drv\\.so$",}, - {"(.*)\\.so$",}, -#endif - {NULL,} -}; - -static PatternPtr -InitPatterns(const char **patternlist) -{ - char errmsg[80]; - int i, e; - PatternPtr patterns = NULL; - PatternPtr p = NULL; - static int firstTime = 1; - const char **s; - - if (firstTime) { - /* precompile stdPatterns */ - firstTime = 0; - for (p = stdPatterns; p->pattern; p++) - if ((e = regcomp(&p->rex, p->pattern, REG_EXTENDED)) != 0) { - regerror(e, &p->rex, errmsg, sizeof(errmsg)); - FatalError("InitPatterns: regcomp error for `%s': %s\n", - p->pattern, errmsg); - } - } - - if (patternlist) { - for (i = 0, s = patternlist; *s; i++, s++) - if (*s == DEFAULT_LIST) - i += ARRAY_SIZE(stdPatterns) - 1 - 1; - patterns = xallocarray(i + 1, sizeof(PatternRec)); - if (!patterns) { - return NULL; - } - for (i = 0, s = patternlist; *s; i++, s++) - if (*s != DEFAULT_LIST) { - p = patterns + i; - p->pattern = *s; - if ((e = regcomp(&p->rex, p->pattern, REG_EXTENDED)) != 0) { - regerror(e, &p->rex, errmsg, sizeof(errmsg)); - ErrorF("InitPatterns: regcomp error for `%s': %s\n", - p->pattern, errmsg); - i--; - } - } - else { - for (p = stdPatterns; p->pattern; p++, i++) - patterns[i] = *p; - if (p != stdPatterns) - i--; - } - patterns[i].pattern = NULL; - } - else - patterns = stdPatterns; - return patterns; -} - -static void -FreePatterns(PatternPtr patterns) -{ - if (patterns && patterns != stdPatterns) - free(patterns); -} - -static char * -FindModuleInSubdir(const char *dirpath, const char *module) -{ - struct dirent *direntry = NULL; - DIR *dir = NULL; - char *ret = NULL, tmpBuf[PATH_MAX]; - struct stat stat_buf; - - dir = opendir(dirpath); - if (!dir) - return NULL; - - while ((direntry = readdir(dir))) { - if (direntry->d_name[0] == '.') - continue; - snprintf(tmpBuf, PATH_MAX, "%s%s/", dirpath, direntry->d_name); - /* the stat with the appended / fails for normal files, - and works for sub dirs fine, looks a bit strange in strace - but does seem to work */ - if ((stat(tmpBuf, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode)) { - if ((ret = FindModuleInSubdir(tmpBuf, module))) - break; - continue; - } - -#ifdef __CYGWIN__ - snprintf(tmpBuf, PATH_MAX, "cyg%s.dll", module); -#else - snprintf(tmpBuf, PATH_MAX, "lib%s.so", module); -#endif - if (strcmp(direntry->d_name, tmpBuf) == 0) { - if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1) - ret = NULL; - break; - } - -#ifdef __CYGWIN__ - snprintf(tmpBuf, PATH_MAX, "%s_drv.dll", module); -#else - snprintf(tmpBuf, PATH_MAX, "%s_drv.so", module); -#endif - if (strcmp(direntry->d_name, tmpBuf) == 0) { - if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1) - ret = NULL; - break; - } - -#ifdef __CYGWIN__ - snprintf(tmpBuf, PATH_MAX, "%s.dll", module); -#else - snprintf(tmpBuf, PATH_MAX, "%s.so", module); -#endif - if (strcmp(direntry->d_name, tmpBuf) == 0) { - if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1) - ret = NULL; - break; - } - } - - closedir(dir); - return ret; -} - -static char * -FindModule(const char *module, const char *dirname, PatternPtr patterns) -{ - char buf[PATH_MAX + 1]; - char *name = NULL; - const char **s; - - if (strlen(dirname) > PATH_MAX) - return NULL; - - for (s = stdSubdirs; *s; s++) { - snprintf(buf, PATH_MAX, "%s%s", dirname, *s); - if ((name = FindModuleInSubdir(buf, module))) - break; - } - - return name; -} - -const char ** -LoaderListDir(const char *subdir, const char **patternlist) -{ - char buf[PATH_MAX + 1]; - char **pathlist; - char **elem; - PatternPtr patterns = NULL; - PatternPtr p; - DIR *d; - struct dirent *dp; - regmatch_t match[2]; - struct stat stat_buf; - int len, dirlen; - char *fp; - char **listing = NULL; - char **save; - char **ret = NULL; - int n = 0; - - if (!(pathlist = defaultPathList)) - return NULL; - if (!(patterns = InitPatterns(patternlist))) - goto bail; - - for (elem = pathlist; *elem; elem++) { - dirlen = snprintf(buf, PATH_MAX, "%s/%s", *elem, subdir); - fp = buf + dirlen; - if (stat(buf, &stat_buf) == 0 && S_ISDIR(stat_buf.st_mode) && - (d = opendir(buf))) { - if (buf[dirlen - 1] != '/') { - buf[dirlen++] = '/'; - fp++; - } - while ((dp = readdir(d))) { - if (dirlen + strlen(dp->d_name) > PATH_MAX) - continue; - strcpy(fp, dp->d_name); - if (!(stat(buf, &stat_buf) == 0 && S_ISREG(stat_buf.st_mode))) - continue; - for (p = patterns; p->pattern; p++) { - if (regexec(&p->rex, dp->d_name, 2, match, 0) == 0 && - match[1].rm_so != -1) { - len = match[1].rm_eo - match[1].rm_so; - save = listing; - listing = reallocarray(listing, n + 2, sizeof(char *)); - if (!listing) { - if (save) { - save[n] = NULL; - FreeStringList(save); - } - closedir(d); - goto bail; - } - listing[n] = malloc(len + 1); - if (!listing[n]) { - FreeStringList(listing); - closedir(d); - goto bail; - } - strncpy(listing[n], dp->d_name + match[1].rm_so, len); - listing[n][len] = '\0'; - n++; - break; - } - } - } - closedir(d); - } - } - if (listing) - listing[n] = NULL; - ret = listing; - - bail: - FreePatterns(patterns); - return (const char **) ret; -} - -static Bool -CheckVersion(const char *module, XF86ModuleVersionInfo * data, - const XF86ModReqInfo * req) -{ - int vercode[4]; - long ver = data->xf86version; - MessageType errtype; - - LogMessage(X_INFO, "Module %s: vendor=\"%s\"\n", - data->modname ? data->modname : "UNKNOWN!", - data->vendor ? data->vendor : "UNKNOWN!"); - - vercode[0] = ver / 10000000; - vercode[1] = (ver / 100000) % 100; - vercode[2] = (ver / 1000) % 100; - vercode[3] = ver % 1000; - LogWrite(1, "\tcompiled for %d.%d.%d", vercode[0], vercode[1], vercode[2]); - if (vercode[3] != 0) - LogWrite(1, ".%d", vercode[3]); - LogWrite(1, ", module version = %d.%d.%d\n", data->majorversion, - data->minorversion, data->patchlevel); - - if (data->moduleclass) - LogWrite(2, "\tModule class: %s\n", data->moduleclass); - - ver = -1; - if (data->abiclass) { - int abimaj, abimin; - int vermaj, vermin; - - if (!strcmp(data->abiclass, ABI_CLASS_ANSIC)) - ver = LoaderVersionInfo.ansicVersion; - else if (!strcmp(data->abiclass, ABI_CLASS_VIDEODRV)) - ver = LoaderVersionInfo.videodrvVersion; - else if (!strcmp(data->abiclass, ABI_CLASS_XINPUT)) - ver = LoaderVersionInfo.xinputVersion; - else if (!strcmp(data->abiclass, ABI_CLASS_EXTENSION)) - ver = LoaderVersionInfo.extensionVersion; - - abimaj = GET_ABI_MAJOR(data->abiversion); - abimin = GET_ABI_MINOR(data->abiversion); - LogWrite(2, "\tABI class: %s, version %d.%d\n", - data->abiclass, abimaj, abimin); - if (ver != -1) { - vermaj = GET_ABI_MAJOR(ver); - vermin = GET_ABI_MINOR(ver); - if (abimaj != vermaj) { - if (LoaderOptions & LDR_OPT_ABI_MISMATCH_NONFATAL) - errtype = X_WARNING; - else - errtype = X_ERROR; - LogMessageVerb(errtype, 0, "%s: module ABI major version (%d) " - "doesn't match the server's version (%d)\n", - module, abimaj, vermaj); - if (!(LoaderOptions & LDR_OPT_ABI_MISMATCH_NONFATAL)) - return FALSE; - } - else if (abimin > vermin) { - if (LoaderOptions & LDR_OPT_ABI_MISMATCH_NONFATAL) - errtype = X_WARNING; - else - errtype = X_ERROR; - LogMessageVerb(errtype, 0, "%s: module ABI minor version (%d) " - "is newer than the server's version (%d)\n", - module, abimin, vermin); - if (!(LoaderOptions & LDR_OPT_ABI_MISMATCH_NONFATAL)) - return FALSE; - } - } - } - - /* Check against requirements that the caller has specified */ - if (req) { - if (data->majorversion != req->majorversion) { - LogMessageVerb(X_WARNING, 2, "%s: module major version (%d) " - "doesn't match required major version (%d)\n", - module, data->majorversion, req->majorversion); - return FALSE; - } - else if (data->minorversion < req->minorversion) { - LogMessageVerb(X_WARNING, 2, "%s: module minor version (%d) is " - "less than the required minor version (%d)\n", - module, data->minorversion, req->minorversion); - return FALSE; - } - else if (data->minorversion == req->minorversion && - data->patchlevel < req->patchlevel) { - LogMessageVerb(X_WARNING, 2, "%s: module patch level (%d) " - "is less than the required patch level " - "(%d)\n", module, data->patchlevel, req->patchlevel); - return FALSE; - } - if (req->moduleclass) { - if (!data->moduleclass || - strcmp(req->moduleclass, data->moduleclass)) { - LogMessageVerb(X_WARNING, 2, "%s: Module class (%s) doesn't " - "match the required class (%s)\n", module, - data->moduleclass ? data->moduleclass : "", - req->moduleclass); - return FALSE; - } - } - else if (req->abiclass != ABI_CLASS_NONE) { - if (!data->abiclass || strcmp(req->abiclass, data->abiclass)) { - LogMessageVerb(X_WARNING, 2, "%s: ABI class (%s) doesn't match" - " the required ABI class (%s)\n", module, - data->abiclass ? data->abiclass : "", - req->abiclass); - return FALSE; - } - } - if (req->abiclass != ABI_CLASS_NONE) { - int reqmaj, reqmin, maj, min; - - reqmaj = GET_ABI_MAJOR(req->abiversion); - reqmin = GET_ABI_MINOR(req->abiversion); - maj = GET_ABI_MAJOR(data->abiversion); - min = GET_ABI_MINOR(data->abiversion); - if (maj != reqmaj) { - LogMessageVerb(X_WARNING, 2, "%s: ABI major version (%d) " - "doesn't match the required ABI major version " - "(%d)\n", module, maj, reqmaj); - return FALSE; - } - /* XXX Maybe this should be the other way around? */ - if (min > reqmin) { - LogMessageVerb(X_WARNING, 2, "%s: module ABI minor version " - "(%d) is newer than that available (%d)\n", - module, min, reqmin); - return FALSE; - } - } - } - return TRUE; -} - -static ModuleDescPtr -AddSibling(ModuleDescPtr head, ModuleDescPtr new) -{ - new->sib = head; - return new; -} - -void * -LoadSubModule(void *_parent, const char *module, - const char **subdirlist, const char **patternlist, - void *options, const XF86ModReqInfo * modreq, - int *errmaj, int *errmin) -{ - ModuleDescPtr submod; - ModuleDescPtr parent = (ModuleDescPtr) _parent; - - LogMessageVerb(X_INFO, 3, "Loading sub module \"%s\"\n", module); - - if (PathIsAbsolute(module)) { - LogMessage(X_ERROR, "LoadSubModule: " - "Absolute module path not permitted: \"%s\"\n", module); - if (errmaj) - *errmaj = LDR_BADUSAGE; - if (errmin) - *errmin = 0; - return NULL; - } - - submod = LoadModule(module, options, modreq, errmaj); - if (submod && submod != (ModuleDescPtr) 1) { - parent->child = AddSibling(parent->child, submod); - submod->parent = parent; - } - return submod; -} - -ModuleDescPtr -DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent) -{ - ModuleDescPtr ret; - - if (!mod) - return NULL; - - ret = calloc(1, sizeof(ModuleDesc)); - if (ret == NULL) - return NULL; - - ret->handle = mod->handle; - - ret->SetupProc = mod->SetupProc; - ret->TearDownProc = mod->TearDownProc; - ret->TearDownData = ModuleDuplicated; - ret->child = DuplicateModule(mod->child, ret); - ret->sib = DuplicateModule(mod->sib, parent); - ret->parent = parent; - ret->VersionInfo = mod->VersionInfo; - - return ret; -} - -static const char *compiled_in_modules[] = { - "ddc", - "fb", - "i2c", - "ramdac", - "dbe", - "record", - "extmod", - "dri", - "dri2", -#ifdef DRI3 - "dri3", -#endif -#ifdef PRESENT - "present", -#endif - NULL -}; - -/* - * LoadModule: load a module - * - * module The module name. Normally this is not a filename but the - * module's "canonical name. A full pathname is, however, - * also accepted. - * options A NULL terminated list of Options that are passed to the - * module's SetupProc function. - * modreq An optional XF86ModReqInfo* containing - * version/ABI/vendor-ABI requirements to check for when - * loading the module. The following fields of the - * XF86ModReqInfo struct are checked: - * majorversion - must match the module's majorversion exactly - * minorversion - the module's minorversion must be >= this - * patchlevel - the module's minorversion.patchlevel must be - * >= this. Patchlevel is ignored when - * minorversion is not set. - * abiclass - (string) must match the module's abiclass - * abiversion - must be consistent with the module's - * abiversion (major equal, minor no older) - * moduleclass - string must match the module's moduleclass - * string - * "don't care" values are ~0 for numbers, and NULL for strings - * errmaj Major error return. - * - */ -ModuleDescPtr -LoadModule(const char *module, void *options, const XF86ModReqInfo *modreq, - int *errmaj) -{ - XF86ModuleData *initdata = NULL; - char **pathlist = NULL; - char *found = NULL; - char *name = NULL; - char **path_elem = NULL; - char *p = NULL; - ModuleDescPtr ret = NULL; - PatternPtr patterns = NULL; - int noncanonical = 0; - char *m = NULL; - const char **cim; - - LogMessageVerb(X_INFO, 3, "LoadModule: \"%s\"", module); - - patterns = InitPatterns(NULL); - name = LoaderGetCanonicalName(module, patterns); - noncanonical = (name && strcmp(module, name) != 0); - if (noncanonical) { - LogWrite(3, " (%s)\n", name); - LogMessageVerb(X_WARNING, 1, - "LoadModule: given non-canonical module name \"%s\"\n", - module); - m = name; - } - else { - LogWrite(3, "\n"); - m = (char *) module; - } - - /* Backward compatibility, vbe and int10 are merged into int10 now */ - if (!strcmp(m, "vbe")) - m = name = strdup("int10"); - - for (cim = compiled_in_modules; *cim; cim++) - if (!strcmp(m, *cim)) { - LogMessageVerb(X_INFO, 3, "Module \"%s\" already built-in\n", m); - ret = (ModuleDescPtr) 1; - goto LoadModule_exit; - } - - if (!name) { - if (errmaj) - *errmaj = LDR_BADUSAGE; - goto LoadModule_fail; - } - ret = calloc(1, sizeof(ModuleDesc)); - if (!ret) { - if (errmaj) - *errmaj = LDR_NOMEM; - goto LoadModule_fail; - } - - pathlist = defaultPathList; - if (!pathlist) { - /* This could be a malloc failure too */ - if (errmaj) - *errmaj = LDR_BADUSAGE; - goto LoadModule_fail; - } - - /* - * if the module name is not a full pathname, we need to - * check the elements in the path - */ - if (PathIsAbsolute(module)) - found = xstrdup(module); - path_elem = pathlist; - while (!found && *path_elem != NULL) { - found = FindModule(m, *path_elem, patterns); - path_elem++; - /* - * When the module name isn't the canonical name, search for the - * former if no match was found for the latter. - */ - if (!*path_elem && m == name) { - path_elem = pathlist; - m = (char *) module; - } - } - - /* - * did we find the module? - */ - if (!found) { - LogMessage(X_WARNING, "Warning, couldn't open module %s\n", module); - if (errmaj) - *errmaj = LDR_NOENT; - goto LoadModule_fail; - } - ret->handle = LoaderOpen(found, errmaj); - if (ret->handle == NULL) - goto LoadModule_fail; - - /* drop any explicit suffix from the module name */ - p = strchr(name, '.'); - if (p) - *p = '\0'; - - /* - * now check if the special data object ModuleData is - * present. - */ - if (asprintf(&p, "%sModuleData", name) == -1) { - p = NULL; - if (errmaj) - *errmaj = LDR_NOMEM; - goto LoadModule_fail; - } - initdata = LoaderSymbolFromModule(ret, p); - if (initdata) { - ModuleSetupProc setup; - ModuleTearDownProc teardown; - XF86ModuleVersionInfo *vers; - - vers = initdata->vers; - setup = initdata->setup; - teardown = initdata->teardown; - - if (vers) { - if (!CheckVersion(module, vers, modreq)) { - if (errmaj) - *errmaj = LDR_MISMATCH; - goto LoadModule_fail; - } - } - else { - LogMessage(X_ERROR, "LoadModule: Module %s does not supply" - " version information\n", module); - if (errmaj) - *errmaj = LDR_INVALID; - goto LoadModule_fail; - } - if (setup) - ret->SetupProc = setup; - if (teardown) - ret->TearDownProc = teardown; - ret->VersionInfo = vers; - } - else { - /* no initdata, fail the load */ - LogMessage(X_ERROR, "LoadModule: Module %s does not have a %s " - "data object.\n", module, p); - if (errmaj) - *errmaj = LDR_INVALID; - goto LoadModule_fail; - } - if (ret->SetupProc) { - ret->TearDownData = ret->SetupProc(ret, options, errmaj, NULL); - if (!ret->TearDownData) { - goto LoadModule_fail; - } - } - else if (options) { - LogMessage(X_WARNING, "Module Options present, but no SetupProc " - "available for %s\n", module); - } - goto LoadModule_exit; - - LoadModule_fail: - UnloadModule(ret); - ret = NULL; - - LoadModule_exit: - FreePatterns(patterns); - free(found); - free(name); - free(p); - - return ret; -} - -void -UnloadModule(void *_mod) -{ - ModuleDescPtr mod = _mod; - - if (mod == (ModuleDescPtr) 1) - return; - - if (mod == NULL) - return; - - if (mod->VersionInfo) { - const char *name = mod->VersionInfo->modname; - - if (mod->parent) - LogMessageVerbSigSafe(X_INFO, 3, "UnloadSubModule: \"%s\"\n", name); - else - LogMessageVerbSigSafe(X_INFO, 3, "UnloadModule: \"%s\"\n", name); - - if (mod->TearDownData != ModuleDuplicated) { - if ((mod->TearDownProc) && (mod->TearDownData)) - mod->TearDownProc(mod->TearDownData); - LoaderUnload(name, mod->handle); - } - } - - if (mod->child) - UnloadModule(mod->child); - if (mod->sib) - UnloadModule(mod->sib); - free(mod); -} - -void -UnloadSubModule(void *_mod) -{ - ModuleDescPtr mod = (ModuleDescPtr) _mod; - - /* Some drivers are calling us on built-in submodules, ignore them */ - if (mod == (ModuleDescPtr) 1) - return; - RemoveChild(mod); - UnloadModule(mod); -} - -static void -RemoveChild(ModuleDescPtr child) -{ - ModuleDescPtr mdp; - ModuleDescPtr prevsib; - ModuleDescPtr parent; - - if (!child->parent) - return; - - parent = child->parent; - if (parent->child == child) { - parent->child = child->sib; - return; - } - - prevsib = parent->child; - mdp = prevsib->sib; - while (mdp && mdp != child) { - prevsib = mdp; - mdp = mdp->sib; - } - if (mdp == child) - prevsib->sib = child->sib; - child->sib = NULL; - return; -} - -void -LoaderErrorMsg(const char *name, const char *modname, int errmaj, int errmin) -{ - const char *msg; - MessageType type = X_ERROR; - - switch (errmaj) { - case LDR_NOERROR: - msg = "no error"; - break; - case LDR_NOMEM: - msg = "out of memory"; - break; - case LDR_NOENT: - msg = "module does not exist"; - break; - case LDR_NOLOAD: - msg = "loader failed"; - break; - case LDR_ONCEONLY: - msg = "already loaded"; - type = X_INFO; - break; - case LDR_MISMATCH: - msg = "module requirement mismatch"; - break; - case LDR_BADUSAGE: - msg = "invalid argument(s) to LoadModule()"; - break; - case LDR_INVALID: - msg = "invalid module"; - break; - case LDR_BADOS: - msg = "module doesn't support this OS"; - break; - case LDR_MODSPECIFIC: - msg = "module-specific error"; - break; - default: - msg = "unknown error"; - } - if (name) - LogMessage(type, "%s: Failed to load module \"%s\" (%s, %d)\n", - name, modname, msg, errmin); - else - LogMessage(type, "Failed to load module \"%s\" (%s, %d)\n", - modname, msg, errmin); -} - -/* Given a module path or file name, return the module's canonical name */ -static char * -LoaderGetCanonicalName(const char *modname, PatternPtr patterns) -{ - char *str; - const char *s; - int len; - PatternPtr p; - regmatch_t match[2]; - - /* Strip off any leading path */ - s = strrchr(modname, '/'); - if (s == NULL) - s = modname; - else - s++; - - /* Find the first regex that is matched */ - for (p = patterns; p->pattern; p++) - if (regexec(&p->rex, s, 2, match, 0) == 0 && match[1].rm_so != -1) { - len = match[1].rm_eo - match[1].rm_so; - str = malloc(len + 1); - if (!str) - return NULL; - strncpy(str, s + match[1].rm_so, len); - str[len] = '\0'; - return str; - } - - /* If there is no match, return the whole name minus the leading path */ - return strdup(s); -} - -/* - * Return the module version information. - */ -unsigned long -LoaderGetModuleVersion(ModuleDescPtr mod) -{ - if (!mod || mod == (ModuleDescPtr) 1 || !mod->VersionInfo) - return 0; - - return MODULE_VERSION_NUMERIC(mod->VersionInfo->majorversion, - mod->VersionInfo->minorversion, - mod->VersionInfo->patchlevel); -} diff --git a/hw/xfree86/loader/meson.build b/hw/xfree86/loader/meson.build deleted file mode 100644 index 533c4f15c..000000000 --- a/hw/xfree86/loader/meson.build +++ /dev/null @@ -1,16 +0,0 @@ -srcs_xorg_loader = [ - 'loader.c', - 'loadmod.c', -] - -xorg_loader = static_library('xorg_loader', - srcs_xorg_loader, - include_directories: [inc, xorg_inc], - dependencies: [common_dep, dl_dep], - c_args: xorg_c_args, -) - -xorg_symbol_test = executable('xorg_symbol_test', - 'symbol-test.c', - dependencies: dl_dep, -) diff --git a/hw/xfree86/loader/symbol-test.c b/hw/xfree86/loader/symbol-test.c deleted file mode 100644 index 1d7d84635..000000000 --- a/hw/xfree86/loader/symbol-test.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 2017 Broadcom - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -/* Small test program to see if we can successfully resolve all - * symbols of a set of X.Org modules when they're loaded in order. - */ - -#include -#include -#include - -int main (int argc, char**argv) -{ - void *ret; - - if (argc < 2) { - fprintf(stderr, - "Must pass path any modules to be loaded.\n"); - exit(1); - } - - for (int i = 1; i < argc; i++) { - fprintf(stderr, "opening %s\n", argv[i]); - ret = dlopen(argv[i], RTLD_GLOBAL | RTLD_NOW); - if (!ret) { - fprintf(stderr, "dlopen error: %s\n", dlerror()); - exit(1); - } - } - - return 0; -} diff --git a/hw/xfree86/man/Xorg.man b/hw/xfree86/man/Xorg.man deleted file mode 100644 index 3ec6e2c25..000000000 --- a/hw/xfree86/man/Xorg.man +++ /dev/null @@ -1,638 +0,0 @@ -.\" $XdotOrg: xserver/xorg/hw/xfree86/doc/man/Xorg.man.pre,v 1.3 2005/07/04 18:41:01 ajax Exp $ -.\" shorthand for double quote that works everywhere. -.ds q \N'34' -.TH Xorg @appmansuffix@ @vendorversion@ -.SH NAME -Xorg - X11R7 X server -.SH SYNOPSIS -.B Xorg -.RI [\fB:\fP display ] -.RI [ option -.IR ... ] -.SH DESCRIPTION -.B Xorg -is a full featured X server that was originally designed for UNIX and -UNIX-like operating systems running on Intel x86 hardware. It now runs -on a wider range of hardware and OS platforms. -.PP -This work was derived by the X.Org Foundation from the XFree86 Project's -.I "XFree86\ 4.4rc2" -release. -The XFree86 release was originally derived from -.I "X386\ 1.2" -by Thomas Roell which was contributed to X11R5 by Snitily Graphics -Consulting Service. -.SH PLATFORMS -.PP -.B Xorg -operates under a wide range of operating systems and hardware platforms. -The Intel x86 (IA32) architecture is the most widely supported hardware -platform. Other hardware platforms include Compaq Alpha, Intel IA64, AMD64, -SPARC and PowerPC. The most widely supported operating systems are the -free/OpenSource UNIX-like systems such as Linux, FreeBSD, NetBSD, -OpenBSD, and Solaris. Commercial UNIX operating systems such as -UnixWare are also supported. Other supported operating systems include -GNU Hurd. Mac OS X is supported with the -Xquartz(@appmansuffix@) X server. Win32/Cygwin is supported with the -XWin(@appmansuffix@) X server. -.PP -.SH "NETWORK CONNECTIONS" -.B Xorg -supports connections made using the following reliable -byte-streams: -.TP 4 -.I "Local" -On most platforms, the "Local" connection type is a UNIX-domain socket. -On some System V platforms, the "local" connection types also include -STREAMS pipes, named pipes, and some other mechanisms. See the -"LOCAL CONNECTIONS" section of X(@miscmansuffix@) for details. -.TP 4 -.I TCP/IP -.B Xorg -listens on port -.RI 6000+ n , -where -.I n -is the display number. This connection type is usually disabled by default, -but may be enabled with the -.B \-listen -option (see the Xserver(1) man page for details). -.SH OPTIONS -.B Xorg -supports several mechanisms for supplying/obtaining configuration and -run-time parameters: command line options, environment variables, the -xorg.conf(@filemansuffix@) configuration files, auto-detection, and -fallback defaults. When the same information is supplied in more than -one way, the highest precedence mechanism is used. The list of mechanisms -is ordered from highest precedence to lowest. Note that not all parameters -can be supplied via all methods. The available command line options -and environment variables (and some defaults) are described here and in -the Xserver(@appmansuffix@) manual page. Most configuration file -parameters, with their defaults, are described in the -xorg.conf(@filemansuffix@) manual page. Driver and module specific -configuration parameters are described in the relevant driver or module -manual page. -.PP -In addition to the normal server options described in the -Xserver(@appmansuffix@) manual page, -.B Xorg -accepts the following command line switches: -.TP 8 -.BI vt XX -.I XX -specifies the Virtual Terminal device number which -.B Xorg -will use. Without this option, -.B Xorg -will pick the first available Virtual Terminal that it can locate. This -option applies only to platforms that have virtual terminal support, such -as Linux, BSD, OpenSolaris, SVR3, and SVR4. -.TP -.B \-allowMouseOpenFail -Allow the server to start up even if the mouse device can't be opened -or initialised. This is equivalent to the -.B AllowMouseOpenFail -xorg.conf(@filemansuffix@) file option. -.TP 8 -.B \-allowNonLocalXvidtune -Make the VidMode extension available to remote clients. This allows -the xvidtune client to connect from another host. This is equivalent -to the -.B AllowNonLocalXvidtune -xorg.conf(@filemansuffix@) file option. By default non-local -connections are not allowed. -.TP 8 -.BI \-bgamma " value" -Set the blue gamma correction. -.I value -must be between 0.1 and 10. -The default is 1.0. Not all drivers support this. See also the -.BR \-gamma , -.BR \-rgamma , -and -.B \-ggamma -options. -.TP 8 -.BI \-bpp " n" -No longer supported. Use -.B \-depth -to set the color depth, and use -.B \-fbbpp -if you really need to force a non-default framebuffer (hardware) pixel -format. -.TP 8 -.BI \-config " file" -Read the server configuration from -.IR file . -This option will work for any file when the server is run as root (i.e, -with real-uid 0), or for files relative to a directory in the config -search path for all other users. -.TP 8 -.BI \-configdir " directory" -Read the server configuration files from -.IR directory . -This option will work for any directory when the server is run as root -(i.e, with real-uid 0), or for directories relative to a directory in the -config directory search path for all other users. -.TP 8 -.B \-configure -When this option is specified, the -.B Xorg -server loads all video driver modules, probes for available hardware, -and writes out an initial xorg.conf(@filemansuffix@) file based on -what was detected. This option currently has some problems on some -platforms, but in most cases it is a good way to bootstrap the -configuration process. This option is only available when the server -is run as root (i.e, with real-uid 0). -.TP 8 -.BI "\-crt /dev/tty" XX -SCO only. This is the same as the -.B vt -option, and is provided for compatibility with the native SCO X server. -.TP 8 -.BI \-depth " n" -Sets the default color depth. Legal values are 1, 4, 8, 15, 16, and -24. Not all drivers support all values. -.TP 8 -.B \-disableVidMode -Disable the parts of the VidMode extension (used by the xvidtune -client) that can be used to change the video modes. This is equivalent -to the -.B DisableVidModeExtension -xorg.conf(@filemansuffix@) file option. -.TP 8 -.B \-fbbpp \fIn\fP -Sets the number of framebuffer bits per pixel. You should only set this -if you're sure it's necessary; normally the server can deduce the correct -value from -.B \-depth -above. Useful if you want to run a depth 24 configuration with a 24 -bpp framebuffer rather than the (possibly default) 32 bpp framebuffer -(or vice versa). Legal values are 1, 8, 16, 24, 32. Not all drivers -support all values. -.TP 8 -.BI \-gamma " value" -Set the gamma correction. -.I value -must be between 0.1 and 10. The default is 1.0. This value is applied -equally to the R, G and B values. Those values can be set independently -with the -.BR \-rgamma , -.BR \-bgamma , -and -.B \-ggamma -options. Not all drivers support this. -.TP 8 -.BI \-ggamma " value" -Set the green gamma correction. -.I value -must be between 0.1 and 10. The default is 1.0. Not all drivers support -this. See also the -.BR \-gamma , -.BR \-rgamma , -and -.B \-bgamma -options. -.TP 8 -.B \-ignoreABI -The -.B Xorg -server checks the ABI revision levels of each module that it loads. It -will normally refuse to load modules with ABI revisions that are newer -than the server's. This is because such modules might use interfaces -that the server does not have. When this option is specified, mismatches -like this are downgraded from fatal errors to warnings. This option -should be used with care. -.TP 8 -.B \-isolateDevice \fIbus\-id\fP -Restrict device resets to the device at -.IR bus\-id . -The -.I bus\-id -string has the form -.IB bustype : bus : device : function -(e.g., \(oqPCI:1:0:0\(cq). -At present, only isolation of PCI devices is supported; i.e., this option -is ignored if -.I bustype -is anything other than \(oqPCI\(cq. -.TP 8 -.B \-keeptty -Prevent the server from detaching its initial controlling terminal. If you -want to use systemd-logind integration you must specify this option. -Not all platforms support (or can use) this option. -.TP 8 -.BI \-keyboard " keyboard-name" -Use the xorg.conf(@filemansuffix@) file -.B InputDevice -section called -.I keyboard-name -as the core keyboard. This option is ignored when the -.B Layout -section specifies a core keyboard. In the absence of both a Layout -section and this option, the first relevant -.B InputDevice -section is used for the core keyboard. -.TP 8 -.BI \-layout " layout-name" -Use the xorg.conf(@filemansuffix@) file -.B Layout -section called -.IR layout-name . -By default the first -.B Layout -section is used. -.TP 8 -.BI \-logfile " filename" -Use the file called -.I filename -as the -.B Xorg -server log file. The default log file when running as root is -.BI @logdir@/Xorg. n .log -and for non root it is -.BI $XDG_DATA_HOME/xorg/Xorg. n .log -where -.I n -is the display number of the -.B Xorg -server. The default may be in a different directory on some platforms. -This option is only available when the server is run as root (i.e, with -real-uid 0). -.TP 8 -.BR \-logverbose " [\fIn\fP]" -Sets the verbosity level for information printed to the -.B Xorg -server log file. If the -.I n -value isn't supplied, each occurrence of this option increments the log -file verbosity level. When the -.I n -value is supplied, the log file verbosity level is set to that value. -The default log file verbosity level is 3. -.TP 8 -.BI \-modulepath " searchpath" -Set the module search path to -.IR searchpath . -.I searchpath -is a comma separated list of directories to search for -.B Xorg -server modules. This option is only available when the server is run -as root (i.e, with real-uid 0). -.TP 8 -.B \-noautoBindGPU -Disable automatically setting secondary GPUs up as output sinks and offload -sources. This is equivalent to setting the -.B AutoBindGPU -xorg.conf(__filemansuffix__) file option. To -.B false. -.TP 8 -.B \-nosilk -Disable Silken Mouse support. -.TP 8 -.B \-novtswitch -Disable the automatic switching on X server reset and shutdown to the -VT that was active when the server started, if supported by the OS. -.TP 8 -.BI \-pointer " pointer-name" -Use the xorg.conf(@filemansuffix@) file -.B InputDevice -section called -.I pointer-name -as the core pointer. This option is ignored when the -.B Layout -section specifies a core pointer. In the absence of both a Layout -section and this option, the first relevant -.B InputDevice -section is used for the core pointer. -.TP 8 -.B \-quiet -Suppress most informational messages at startup. The verbosity level -is set to zero. -.TP 8 -.BI \-rgamma " value" -Set the red gamma correction. -.I value -must be between 0.1 and 10. The default is 1.0. Not all drivers support -this. See also the -.BR \-gamma , -.BR \-bgamma , -and -.B \-ggamma -options. -.TP 8 -.B \-sharevts -Share virtual terminals with another X server, if supported by the OS. -.TP 8 -.BI \-screen " screen-name" -Use the xorg.conf(@filemansuffix@) file -.B Screen -section called -.IR screen-name . -By default the screens referenced by the default -.B Layout -section are used, or the first -.B Screen -section when there are no -.B Layout -sections. -.TP 8 -.B \-showconfig -This is the same as the -.B \-version -option, and is included for compatibility reasons. It may be removed -in a future release, so the -.B \-version -option should be used instead. -.TP 8 -.B \-showDefaultModulePath -Print out the default module path the server was compiled with. -.TP 8 -.B \-showDefaultLibPath -Print out the path libraries should be installed to. -.TP 8 -.B \-showopts -For each driver module installed, print out the list of options and their -argument types. -.TP 8 -.BI \-weight " nnn" -Set RGB weighting at 16 bpp. The default is 565. This applies only to -those drivers which support 16 bpp. -.TP 8 -.BR \-verbose " [\fIn\fP]" -Sets the verbosity level for information printed on stderr. If the -.I n -value isn't supplied, each occurrence of this option increments the -verbosity level. When the -.I n -value is supplied, the verbosity level is set to that value. The default -verbosity level is 0. -.TP 8 -.B \-version -Print out the server version, patchlevel, release date, the operating -system/platform it was built on, and whether it includes module loader -support. -.SH "KEYBOARD" -.PP -The -.B Xorg -server is normally configured to recognize various special combinations -of key presses that instruct the server to perform some action, rather -than just sending the key press event to a client application. These actions -depend on the XKB keymap loaded by a particular keyboard device and may or -may not be available on a given configuration. -.PP -The following key combinations are commonly part of the default XKEYBOARD -keymap. -.TP 8 -.B Ctrl+Alt+Backspace -Immediately kills the server -- no questions asked. It can be disabled by -setting the -.B DontZap -xorg.conf(@filemansuffix@) file option to a TRUE value. -.PP -.RS 8 -It should be noted that zapping is triggered by the -.B Terminate_Server -action in the keyboard map. This action is not part of the default keymaps -but can be enabled with the XKB option -.B \*qterminate:ctrl_alt_bksp\*q. -.RE -.TP 8 -.B Ctrl+Alt+Keypad-Plus -Change video mode to next one specified in the configuration file. -This can be disabled with the -.B DontZoom -xorg.conf(@filemansuffix@) file option. -.TP 8 -.B Ctrl+Alt+Keypad-Minus -Change video mode to previous one specified in the configuration file. -This can be disabled with the -.B DontZoom -xorg.conf(@filemansuffix@) file option. -.TP 8 -.B Ctrl+Alt+F1...F12 -For systems with virtual terminal support, these keystroke -combinations are used to switch to virtual terminals 1 through 12, -respectively. This can be disabled with the -.B DontVTSwitch -xorg.conf(@filemansuffix@) file option. -.SH CONFIGURATION -.B Xorg -typically uses a configuration file called -.B xorg.conf -and configuration files with the suffix -.I .conf -in a directory called -.B @xconfigdir@ -for its initial setup. -Refer to the xorg.conf(@filemansuffix@) manual page for information -about the format of this file. -.PP -.B Xorg -has a mechanism for automatically generating a built-in configuration -at run-time when no -.B xorg.conf -file or -.B @xconfigdir@ -files are present. The current version of this automatic configuration -mechanism works in two ways. -.PP -The first is via enhancements that have made many components of the -.B xorg.conf -file optional. This means that information that can be probed or -reasonably deduced doesn't need to be specified explicitly, greatly -reducing the amount of built-in configuration information that needs to -be generated at run-time. -.PP -The second is to have "safe" fallbacks for most configuration information. -This maximises the likelihood that the -.B Xorg -server will start up in some usable configuration even when information -about the specific hardware is not available. -.PP -The automatic configuration support for Xorg is work in progress. -It is currently aimed at the most popular hardware and software platforms -supported by Xorg. Enhancements are planned for future releases. -.SH FILES -The -.B Xorg -server config files can be found in a range of locations. These are -documented fully in the xorg.conf(@filemansuffix@) manual page. The -most commonly used locations are shown here. -.TP 30 -.B /etc/X11/xorg.conf -Server configuration file. -.TP 30 -.B /etc/X11/xorg.conf-4 -Server configuration file. -.TP 30 -.B /etc/xorg.conf -Server configuration file. -.TP 30 -.B @projectroot@/etc/xorg.conf -Server configuration file. -.TP 30 -.B @projectroot@/lib/X11/xorg.conf -Server configuration file. -.TP 30 -.B /etc/X11/@xconfigdir@ -Server configuration directory. -.TP 30 -.B /etc/X11/@xconfigdir@-4 -Server configuration directory. -.TP 30 -.B /etc/@xconfigdir@ -Server configuration directory. -.TP 30 -.B @projectroot@/etc/@xconfigdir@ -Server configuration directory. -.TP 30 -.B @projectroot@/lib/X11/@xconfigdir@ -Server configuration directory. -.TP 30 -.BI @logdir@/Xorg. n .log -Server log file for display -.IR n . -.TP 30 -.B @projectroot@/bin/\(** -Client binaries. -.TP 30 -.B @projectroot@/include/\(** -Header files. -.TP 30 -.B @projectroot@/lib/\(** -Libraries. -.TP 30 -.B @datadir@/fonts/X11/\(** -Fonts. -.TP 30 -.B @projectroot@/share/X11/XErrorDB -Client error message database. -.TP 30 -.B @projectroot@/lib/X11/app-defaults/\(** -Client resource specifications. -.TP 30 -.B @mandir@/man?/\(** -Manual pages. -.TP 30 -.BI /etc/X n .hosts -Initial access control list for display -.IR n . -.SH "SEE ALSO" -X(@miscmansuffix@), Xserver(@appmansuffix@), xdm(@appmansuffix@), xinit(@appmansuffix@), -xorg.conf(@filemansuffix@), xvidtune(@appmansuffix@), -xkeyboard-config (@miscmansuffix@), -apm(@drivermansuffix@), -ati(@drivermansuffix@), -chips(@drivermansuffix@), -cirrus(@drivermansuffix@), -cyrix(@drivermansuffix@), -fbdev(@drivermansuffix@), -glide(@drivermansuffix@), -glint(@drivermansuffix@), -i128(@drivermansuffix@), -i740(@drivermansuffix@), -imstt(@drivermansuffix@), -intel(@drivermansuffix@), -mga(@drivermansuffix@), -neomagic(@drivermansuffix@), -nsc(@drivermansuffix@), -nv(@drivermansuffix@), -openchrome (@drivermansuffix@), -r128(@drivermansuffix@), -rendition(@drivermansuffix@), -s3virge(@drivermansuffix@), -siliconmotion(@drivermansuffix@), -sis(@drivermansuffix@), -sunbw2(@drivermansuffix@), -suncg14(@drivermansuffix@), -suncg3(@drivermansuffix@), -suncg6(@drivermansuffix@), -sunffb(@drivermansuffix@), -sunleo(@drivermansuffix@), -suntcx(@drivermansuffix@), -tdfx(@drivermansuffix@), -tga(@drivermansuffix@), -trident(@drivermansuffix@), -tseng(@drivermansuffix@), -v4l(@drivermansuffix@), -vesa(@drivermansuffix@), -vmware(@drivermansuffix@), -.br -Web site -.IR . - -.SH AUTHORS -Xorg has many contributors world wide. The names of most of them -can be found in the documentation, ChangeLog files in the source tree, -and in the actual source code. -.PP -Xorg was originally based on XFree86 4.4rc2. -That was originally based on \fIX386 1.2\fP by Thomas Roell, which -was contributed to the then X Consortium's X11R5 distribution by SGCS. -.PP -Xorg is released by the X.Org Foundation. -.PP -The project that became XFree86 was originally founded in 1992 by -David Dawes, Glenn Lai, Jim Tsillas and David Wexelblat. -.PP -XFree86 was later integrated in the then X Consortium's X11R6 release -by a group of dedicated XFree86 developers, including the following: -.PP -.RS 4 -.nf -Stuart Anderson \fIanderson@metrolink.com\fP -Doug Anson \fIdanson@lgc.com\fP -Gertjan Akkerman \fIakkerman@dutiba.twi.tudelft.nl\fP -Mike Bernson \fImike@mbsun.mlb.org\fP -Robin Cutshaw \fIrobin@XFree86.org\fP -David Dawes \fIdawes@XFree86.org\fP -Marc Evans \fImarc@XFree86.org\fP -Pascal Haible \fIhaible@izfm.uni-stuttgart.de\fP -Matthieu Herrb \fIMatthieu.Herrb@laas.fr\fP -Dirk Hohndel \fIhohndel@XFree86.org\fP -David Holland \fIdavidh@use.com\fP -Alan Hourihane \fIalanh@fairlite.demon.co.uk\fP -Jeffrey Hsu \fIhsu@soda.berkeley.edu\fP -Glenn Lai \fIglenn@cs.utexas.edu\fP -Ted Lemon \fImellon@ncd.com\fP -Rich Murphey \fIrich@XFree86.org\fP -Hans Nasten \fInasten@everyware.se\fP -Mark Snitily \fImark@sgcs.com\fP -Randy Terbush \fIrandyt@cse.unl.edu\fP -Jon Tombs \fItombs@XFree86.org\fP -Kees Verstoep \fIversto@cs.vu.nl\fP -Paul Vixie \fIpaul@vix.com\fP -Mark Weaver \fIMark_Weaver@brown.edu\fP -David Wexelblat \fIdwex@XFree86.org\fP -Philip Wheatley \fIPhilip.Wheatley@ColumbiaSC.NCR.COM\fP -Thomas Wolfram \fIwolf@prz.tu-berlin.de\fP -Orest Zborowski \fIorestz@eskimo.com\fP -.fi -.RE -.PP -Xorg source is available from the FTP server -\fI\fP, and from the X.Org -server \fI\fP. Documentation and other -information can be found from the X.Org web site -\fI\fP. - -.SH LEGAL -.PP -.B Xorg -is copyright software, provided under licenses that permit modification -and redistribution in source and binary form without fee. -.B Xorg is copyright by numerous authors and -contributors from around the world. Licensing information can be found -at -.IR . -Refer to the source code for specific copyright notices. -.PP -.B XFree86(TM) -is a trademark of The XFree86 Project, Inc. -.PP -.B X11(TM) -and -.B X Window System(TM) -are trademarks of The Open Group. diff --git a/hw/xfree86/man/Xorg.wrap.man b/hw/xfree86/man/Xorg.wrap.man deleted file mode 100644 index a8ee5eae8..000000000 --- a/hw/xfree86/man/Xorg.wrap.man +++ /dev/null @@ -1,67 +0,0 @@ -.\" Xwrapper.wrap.@appmansuffix@ -.\" -.\" Copyright 2014 Red Hat, Inc. -.\" -.\" Permission to use, copy, modify, distribute, and sell this software and its -.\" documentation for any purpose is hereby granted without fee, provided that -.\" the above copyright notice appear in all copies and that both that -.\" copyright notice and this permission notice appear in supporting -.\" documentation. -.\" -.\" 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 OPEN GROUP 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 Open Group 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 Open Group. -.\" -.\" shorthand for double quote that works everywhere. -.ds q \N'34' -.TH Xorg.wrap @appmansuffix@ @xorgversion@ -.SH NAME -Xorg.wrap \- Xorg X server binary wrapper -.SH DESCRIPTION -The Xorg X server may need root rights to function properly. To start the -Xorg X server with these rights your system is using a suid root wrapper -installed as @suid_wrapper_dir@/Xorg.wrap which will execute the real -X server which is installed as @suid_wrapper_dir@/Xorg. -.PP -By default Xorg.wrap will autodetect if root rights are necessary, and -if not it will drop its elevated rights before starting the real X server. -By default Xorg.wrap will only allow executing the real X server from login -sessions on a physical console. - -.SH CONFIG FILE -Xorg.wrap's default behavior can be overridden from the -\fI@sysconfdir@/X11/Xwrapper.config\fP config file. Lines starting with a -\fB#\fP in Xwrapper.config are considered comments and will be ignored. Any -other non empty lines must take the form of \fBkey\fP = \fIvalue\fP. -.TP 8 -\fBallowed_users\fP = \fIrootonly\fP|\fIconsole\fP|\fIanybody\fP -Specify which users may start the X server through the wrapper. Use -\fIrootonly\fP to only allow root, use \fIconsole\fP to only allow users -logged into a physical console, and use \fIanybody\fP to allow anybody. -The default is \fIconsole\fP. -.TP 8 -\fBneeds_root_rights\fP = \fIyes\fP|\fIno\fP|\fIauto\fP -Configure if the wrapper should drop its elevated (root) rights before starting -the X server. Use \fIyes\fP to force execution as root, \fIno\fP to force -execution with all suid rights dropped, and \fIauto\fP to let the wrapper -auto-detect. The default is \fIauto\fP. -.PP -When auto-detecting the wrapper will drop rights if kms graphics are available -and not drop them if no kms graphics are detected. If a system has multiple -graphics cards and some are not kms capable auto-detection may fail, -in this case manual configuration should be used. - -.SH "SEE ALSO" -Xorg X server information: \fIXorg\fP(1) diff --git a/hw/xfree86/man/Xwrapper.config.man b/hw/xfree86/man/Xwrapper.config.man deleted file mode 100644 index 46bc65e2c..000000000 --- a/hw/xfree86/man/Xwrapper.config.man +++ /dev/null @@ -1 +0,0 @@ -.so man@appmansuffix@/Xorg.wrap.@appmansuffix@ diff --git a/hw/xfree86/man/xorg.conf.d.man b/hw/xfree86/man/xorg.conf.d.man deleted file mode 100644 index 9ac2dbfbb..000000000 --- a/hw/xfree86/man/xorg.conf.d.man +++ /dev/null @@ -1 +0,0 @@ -.so man@filemansuffix@/xorg.conf.@filemansuffix@ diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man deleted file mode 100644 index ac88d7e7a..000000000 --- a/hw/xfree86/man/xorg.conf.man +++ /dev/null @@ -1,2603 +0,0 @@ -.\" shorthand for double quote that works everywhere. -.ds q \N'34' -.TH xorg.conf @filemansuffix@ @vendorversion@ -.SH NAME -xorg.conf, @xconfigdir@ \- configuration files for -Xorg X server -.SH INTRODUCTION -.B Xorg -supports several mechanisms for supplying/obtaining configuration and -run-time parameters: command line options, environment variables, the -xorg.conf and @xconfigdir@ configuration files, auto-detection, -and fallback defaults. When the same information is supplied in more -than one way, the highest precedence mechanism is used. The list of -mechanisms is ordered from highest precedence to lowest. Note that not -all parameters can be supplied via all methods. The available command -line options and environment variables (and some defaults) are -described in the Xserver(@appmansuffix@) and -Xorg(@appmansuffix@) manual pages. Most configuration file -parameters, with their defaults, are described below. Driver and module -specific configuration parameters are described in the relevant driver -or module manual page. -.SH DESCRIPTION -.B Xorg -uses a configuration file called -.I xorg.conf -and files ending in the suffix -.I .conf -from the directory -.I @xconfigdir@ -for its initial setup. -The -.I xorg.conf -configuration file is searched for in the following places when the -server is started as a normal user: -.PP -.RS 4 -.nf -.IR /etc/X11/ -.IR @projectroot@/etc/X11/ -.IB /etc/X11/ $XORGCONFIG -.IB @projectroot@/etc/X11/ $XORGCONFIG -.I /etc/X11/xorg.conf -.I /etc/xorg.conf -.IR @projectroot@/etc/X11/xorg.conf. -.I @projectroot@/etc/X11/xorg.conf -.IR @projectroot@/lib/X11/xorg.conf. -.I @projectroot@/lib/X11/xorg.conf -.fi -.RE -.PP -where -.I -is a relative path (with no \(lq..\(rq components) specified with the -.B \-config -command line option, -.B $XORGCONFIG -is the relative path (with no \(lq..\(rq components) specified by that -environment variable, and -.I -is the machine's hostname as reported by -.BR gethostname (@libmansuffix@). -.PP -When the Xorg server is started by the \(lqroot\(rq user, the config file -search locations are as follows: -.PP -.RS 4 -.nf - -.IR /etc/X11/ -.IR @projectroot@/etc/X11/ -.B $XORGCONFIG -.IB /etc/X11/ $XORGCONFIG -.IB @projectroot@/etc/X11/ $XORGCONFIG -.I /etc/X11/xorg.conf -.I /etc/xorg.conf -.IR @projectroot@/etc/X11/xorg.conf. -.I @projectroot@/etc/X11/xorg.conf -.IR @projectroot@/lib/X11/xorg.conf. -.I @projectroot@/lib/X11/xorg.conf -.fi -.RE -.PP -where -.I -is the path specified with the -.B \-config -command line option (which may be absolute or relative), -.B $XORGCONFIG -is the path specified by that -environment variable (absolute or relative), -.B $HOME -is the path specified by that environment variable (usually the home -directory), and -.I -is the machine's hostname as reported by -.BR gethostname (@libmansuffix@). -.PP -Additional configuration files are searched for in the following -directories when the server is started as a normal user: -.PP -.RS 4 -.nf -.IR /etc/X11/ -.IR @sysconfdir@/X11/ -.I /etc/X11/@xconfigdir@ -.I @sysconfdir@/X11/@xconfigdir@ -.fi -.RE -.PP -where -.I -is a relative path (with no \(lq..\(rq components) specified with the -.B \-configdir -command line option. -.PP -When the Xorg server is started by the \(lqroot\(rq user, the -config directory search locations are as follows: -.PP -.RS 4 -.nf - -.IR /etc/X11/ -.IR @sysconfdir@/X11/ -.I /etc/X11/@xconfigdir@ -.I @sysconfdir@/X11/@xconfigdir@ -.fi -.RE -.PP -where -.I -is the path specified with the -.B \-configdir -command line option (which may be absolute or relative). -.PP -Finally, configuration files will also be searched for in a directory reserved -for system use. -This is to separate configuration files from the vendor or 3rd party packages -from those of local administration. -These files are found in the following directory: -.PP -.RS 4 -.nf -.I @datadir@/X11/@xconfigdir@ -.fi -.RE -.PP -The -.I xorg.conf -and -.I @xconfigdir@ -files are composed of a number of sections which may be present in any order, -or omitted to use default configuration values. -Each section has the form: -.PP -.RS 4 -.nf -.BI "Section \*q" SectionName \*q -.RI " " SectionEntry - ... -.B EndSection -.fi -.RE -.PP -The section names are: -.PP -.RS 4 -.nf -.BR "Files " "File pathnames" -.BR "ServerFlags " "Server flags" -.BR "Module " "Dynamic module loading" -.BR "Extensions " "Extension enabling" -.BR "InputDevice " "Input device description" -.BR "InputClass " "Input class description" -.BR "OutputClass " "Output class description" -.BR "Device " "Graphics device description" -.BR "VideoAdaptor " "Xv video adaptor description" -.BR "Monitor " "Monitor description" -.BR "Modes " "Video modes descriptions" -.BR "Screen " "Screen configuration" -.BR "ServerLayout " "Overall layout" -.BR "DRI " "DRI\-specific configuration" -.BR "Vendor " "Vendor\-specific configuration" -.fi -.RE -.PP -The following obsolete section names are still recognised for compatibility -purposes. -In new config files, the -.B InputDevice -section should be used instead. -.PP -.RS 4 -.nf -.BR "Keyboard " "Keyboard configuration" -.BR "Pointer " "Pointer/mouse configuration" -.fi -.RE -.PP -The old -.B XInput -section is no longer recognised. -.PP -The -.B ServerLayout -sections are at the highest level. -They bind together the input and output devices that will be used in a session. -The input devices are described in the -.B InputDevice -sections. -Output devices usually consist of multiple independent components (e.g., -a graphics board and a monitor). -These multiple components are bound together in the -.B Screen -sections, and it is these that are referenced by the -.B ServerLayout -section. -Each -.B Screen -section binds together a graphics board and a monitor. -The graphics boards are described in the -.B Device -sections, and the monitors are described in the -.B Monitor -sections. -.PP -Config file keywords are case\-insensitive, and \(lq_\(rq characters are -ignored. -Most strings (including -.B Option -names) are also case-insensitive, and insensitive to white space and -\(lq_\(rq characters. -.PP -Each config file entry usually takes up a single line in the file. They -consist of a keyword, which is possibly followed by one or more arguments, -with the number and types of the arguments depending on the keyword. -The argument types are: -.PP -.RS 4 -.nf -.BR "Integer " "an integer number in decimal, hex or octal" -.BR "Real " "a floating point number" -.BR "String " "a string enclosed in double quote marks (\*q)" -.fi -.RE -.PP -Note: hex integer values must be prefixed with \(lq0x\(rq, and octal values -with \(lq0\(rq. -.PP -A special keyword called -.B Option -may be used to provide free\-form data to various components of the server. -The -.B Option -keyword takes either one or two string arguments. -The first is the option name, and the optional second argument is the -option value. -Some commonly used option value types include: -.PP -.RS 4 -.nf -.BR "Integer " "an integer number in decimal, hex or octal" -.BR "Real " "a floating point number" -.BR "String " "a sequence of characters" -.BR "Boolean " "a boolean value (see below)" -.BR "Frequency " "a frequency value (see below)" -.fi -.RE -.PP -Note that -.I all -.B Option -values, not just strings, must be enclosed in quotes. -.PP -Boolean options may optionally have a value specified. -When no value is specified, the option's value is -.BR TRUE . -The following boolean option values are recognised as -.BR TRUE : -.PP -.RS 4 -.BR 1 , -.BR on , -.BR true , -.B yes -.RE -.PP -and the following boolean option values are recognised as -.BR FALSE : -.PP -.RS 4 -.BR 0 , -.BR off , -.BR false , -.B no -.RE -.PP -If an option name is prefixed with -.RB \*q No \*q, -then the option value is negated. -.PP -Example: the following option entries are equivalent: -.PP -.RS 4 -.nf -.B "Option \*qAccel\*q \*qOff\*q" -.B "Option \*qNoAccel\*q" -.B "Option \*qNoAccel\*q \*qOn\*q" -.B "Option \*qAccel\*q \*qfalse\*q" -.B "Option \*qAccel\*q \*qno\*q" -.fi -.RE -.PP -Frequency option values consist of a real number that is optionally -followed by one of the following frequency units: -.PP -.RS 4 -.BR Hz , -.BR k , -.BR kHz , -.BR M , -.B MHz -.RE -.PP -When the unit name is omitted, the correct units will be determined from -the value and the expectations of the appropriate range of the value. -It is recommended that the units always be specified when using frequency -option values to avoid any errors in determining the value. -.SH "FILES SECTION" -The -.B Files -section is used to specify some path names required by the server. -Some of these paths can also be set from the command line (see -.BR Xserver (@appmansuffix@) -and -.BR Xorg (@appmansuffix@)). -The command line settings override the values specified in the config -file. -The -.B Files -section is optional, as are all of the entries that may appear in it. -.PP -The entries that can appear in this section are: -.TP 7 -.BI "FontPath \*q" path \*q -sets the search path for fonts. -This path is a comma separated list of font path elements which the Xorg -server searches for font databases. -Multiple -.B FontPath -entries may be specified, and they will be concatenated to build up the -fontpath used by the server. Font path elements can be absolute -directory paths, catalogue directories or a font server identifier. The -formats of the later two are explained below: -.PP -.RS 7 -Catalogue directories: -.PP -.RS 4 -Catalogue directories can be specified using the prefix \fBcatalogue:\fR -before the directory name. The directory can then be populated with -symlinks pointing to the real font directories, using the following -syntax in the symlink name: -.PP -.RS 4 -.IR : [attribute]: pri= -.RE -.PP -where -.I -is an alphanumeric identifier, -.I [attribute] -is an attribute which will be passed to the underlying FPE and -.I -is a number used to order the fontfile FPEs. Examples: -.PP -.RS 4 -.nf -.I 75dpi:unscaled:pri=20 -> /usr/share/X11/fonts/75dpi -.I gscript:pri=60 -> /usr/share/fonts/default/ghostscript -.I misc:unscaled:pri=10 \-> /usr/share/X11/fonts/misc -.fi -.PP -.RE -.RE -.RE -.PP -.RS 7 -Font server identifiers: -.PP -.RS 4 -Font server identifiers have the form: -.RS 4 -.PP -.IR / : -.RE -.PP -where -.I -is the transport type to use to connect to the font server (e.g., -.B unix -for UNIX\-domain sockets or -.B tcp -for a TCP/IP connection), -.I -is the hostname of the machine running the font server, and -.I -is the port number that the font server is listening on (usually 7100). -.RE -.PP -When this entry is not specified in the config file, the server falls back -to the compiled\-in default font path, which contains the following -font path elements (which can be set inside a catalogue directory): -.PP -.RS 4 -.nf -.I @datadir@/fonts/X11/misc/ -.I @datadir@/fonts/X11/TTF/ -.I @datadir@/fonts/X11/OTF/ -.I @datadir@/fonts/X11/Type1/ -.I @datadir@/fonts/X11/100dpi/ -.I @datadir@/fonts/X11/75dpi/ -.fi -.RE -.PP -Font path elements that are found to be invalid are removed from the -font path when the server starts up. -.RE -.TP 7 -.BI "ModulePath \*q" path \*q -sets the search path for loadable Xorg server modules. -This path is a comma separated list of directories which the Xorg server -searches for loadable modules loading in the order specified. -Multiple -.B ModulePath -entries may be specified, and they will be concatenated to build the -module search path used by the server. The default module path is -.PP -.RS 11 -@modulepath@ -.RE -.\" The LogFile keyword is not currently implemented -.ig -.TP 7 -.BI "LogFile \*q" path \*q -sets the name of the Xorg server log file. -The default log file name when running as root is -.PP -.RS 11 -.RI @logdir@/Xorg. .log -.RE -and for non root it is -.RS 11 -.RI $XDG_DATA_HOME/xorg/Xorg. .log -.RE -.PP -.RS 7 -where -.I -is the display number for the Xorg server. -.. -.TP 7 -.BI "XkbDir \*q" path \*q -sets the base directory for keyboard layout files. The -.B \-xkbdir -command line option can be used to override this. The default directory is -.PP -.RS 11 -@xkbdir@ -.RE -.SH "SERVERFLAGS SECTION" -In addition to options specific to this section (described below), the -.B ServerFlags -section is used to specify some global -Xorg server options. -All of the entries in this section are -.BR Options , -although for compatibility purposes some of the old style entries are -still recognised. -Those old style entries are not documented here, and using them is -discouraged. -The -.B ServerFlags -section is optional, as are the entries that may be specified in it. -.PP -.B Options -specified in this section (with the exception of the -.B \*qDefaultServerLayout\*q -.BR Option ) -may be overridden by -.B Options -specified in the active -.B ServerLayout -section. -Options with command line equivalents are overridden when their command -line equivalent is used. -The options recognised by this section are: -.TP 7 -.BI "Option \*qDebug\*q \*q" string \*q -This comma-separated list provides a way to control various debugging switches -from the config file. -At the moment the only defined value is -.B dmabuf_capable -which instructs glamor to enable some unstable buffer management code. -.TP 7 -.BI "Option \*qDefaultServerLayout\*q \*q" layout\-id \*q -This specifies the default -.B ServerLayout -section to use in the absence of the -.B \-layout -command line option. -.TP 7 -.BI "Option \*qDontVTSwitch\*q \*q" boolean \*q -This disallows the use of the -.BI Ctrl+Alt+F n -sequence (where -.RI F n -refers to one of the numbered function keys). -That sequence is normally used to switch to another \*qvirtual terminal\*q -on operating systems that have this feature. -When this option is enabled, that key sequence has no special meaning and -is passed to clients. -Default: off. -.TP 7 -.BI "Option \*qDontZap\*q \*q" boolean \*q -This disallows the use of the -.B Terminate_Server -XKB action (usually on Ctrl+Alt+Backspace, depending on XKB options). -This action is normally used to terminate the Xorg server. -When this option is enabled, the action has no effect. -Default: off. -.TP 7 -.BI "Option \*qDontZoom\*q \*q" boolean \*q -This disallows the use of the -.B Ctrl+Alt+Keypad\-Plus -and -.B Ctrl+Alt+Keypad\-Minus -sequences. -These sequences allows you to switch between video modes. -When this option is enabled, those key sequences have no special meaning -and are passed to clients. -Default: off. -.TP 7 -.BI "Option \*qDisableVidModeExtension\*q \*q" boolean \*q -This disables the parts of the VidMode extension used by the xvidtune client -that can be used to change the video modes. -Default: the VidMode extension is enabled. -.TP 7 -.BI "Option \*qAllowNonLocalXvidtune\*q \*q" boolean \*q -This allows the xvidtune client (and other clients that use the VidMode -extension) to connect from another host. -Default: off. -.TP 7 -.BI "Option \*qAllowMouseOpenFail\*q \*q" boolean \*q -This tells the mousedrv(@drivermansuffix@) and vmmouse(@drivermansuffix@) -drivers to not report failure if the mouse device can't be opened/initialised. -It has no effect on the evdev(@drivermansuffix@) or other drivers. -Default: false. -.TP 7 -.BI "Option \*qBlankTime\*q \*q" time \*q -sets the inactivity timeout for the -.B blank -phase of the screensaver. -.I time -is in minutes. -This is equivalent to the Xorg server's -.B \-s -flag, and the value can be changed at run\-time with -.BR xset(@appmansuffix@). -Default: 10 minutes. -.TP 7 -.BI "Option \*qStandbyTime\*q \*q" time \*q -sets the inactivity timeout for the -.B standby -phase of DPMS mode. -.I time -is in minutes, and the value can be changed at run\-time with -.BR xset(@appmansuffix@). -Default: 10 minutes. -This is only suitable for VESA DPMS compatible monitors, and may not be -supported by all video drivers. -It is only enabled for screens that have the -.B \*qDPMS\*q -option set (see the MONITOR section below). -.TP 7 -.BI "Option \*qSuspendTime\*q \*q" time \*q -sets the inactivity timeout for the -.B suspend -phase of DPMS mode. -.I time -is in minutes, and the value can be changed at run\-time with -.BR xset(@appmansuffix@). -Default: 10 minutes. -This is only suitable for VESA DPMS compatible monitors, and may not be -supported by all video drivers. -It is only enabled for screens that have the -.B \*qDPMS\*q -option set (see the MONITOR section below). -.TP 7 -.BI "Option \*qOffTime\*q \*q" time \*q -sets the inactivity timeout for the -.B off -phase of DPMS mode. -.I time -is in minutes, and the value can be changed at run\-time with -.BR xset(@appmansuffix@). -Default: 10 minutes. -This is only suitable for VESA DPMS compatible monitors, and may not be -supported by all video drivers. -It is only enabled for screens that have the -.B \*qDPMS\*q -option set (see the MONITOR section below). -.TP 7 -.BI "Option \*qMaxClients\*q \*q" integer \*q -Set the maximum number of clients allowed to connect to the X server. -Acceptable values are 64, 128, 256 or 512. -.TP 7 -.BI "Option \*qNoPM\*q \*q" boolean \*q -Disables something to do with power management events. -Default: PM enabled on platforms that support it. -.TP 7 -.BI "Option \*qXinerama\*q \*q" boolean \*q -enable or disable XINERAMA extension. -Default is disabled. -.TP 7 -.BI "Option \*qIndirectGLX\*q \*q" boolean \*q -enable or disable indirect GLX contexts. Indirect GLX contexts are disabled by -default. -.TP 7 -.BI "Option \*qDRI2\*q \*q" boolean \*q -enable or disable DRI2. DRI2 is disabled by default. -.TP 7 -.BI "Option \*qGlxVisuals\*q \*q" string \*q -This option controls how many GLX visuals the GLX modules sets up. -The default value is -.BR "typical" , -which will setup up a typical subset of -the GLXFBConfigs provided by the driver as GLX visuals. Other options are -.BR "minimal" , -which will set up the minimal set allowed by the GLX specification and -.BR "all" -which will setup GLX visuals for all GLXFBConfigs. -.TP 7 -.BI "Option \*qUseDefaultFontPath\*q \*q" boolean \*q -Include the default font path even if other paths are specified in -xorg.conf. If enabled, other font paths are included as well. Enabled by -default. -.TP 7 -.BI "Option \*qIgnoreABI\*q \*q" boolean \*q -Allow modules built for a different, potentially incompatible version of -the X server to load. Disabled by default. -.TP 7 -.BI "Option \*qAutoAddDevices\*q \*q" boolean \*q -If this option is disabled, then no devices will be added from the HAL or -udev backends. Enabled by default. -.TP 7 -.BI "Option \*qAutoEnableDevices\*q \*q" boolean \*q -If this option is disabled, then the devices will be added (and the -DevicePresenceNotify event sent), but not enabled, thus leaving policy up -to the client. -Enabled by default. -.TP 7 -.BI "Option \*qAutoAddGPU\*q \*q" boolean \*q -If this option is disabled, then no GPU devices will be added from the udev -backend. Enabled by default. (May need to be disabled to setup Xinerama). -.TP 7 -.BI "Option \*qAutoBindGPU\*q \*q" boolean \*q -If enabled then secondary GPUs will be automatically set up as output-sinks and -offload-sources. Making e.g. laptop outputs connected only to the secondary -GPU directly available for use without needing to run -"xrandr --setprovideroutputsource". Enabled by default. -.TP 7 -.BI "Option \*qLog\*q \*q" string \*q -This option controls whether the log is flushed and/or synced to disk after -each message. -Possible values are -.B flush -or -.BR sync . -Unset by default. -.SH "MODULE SECTION" -The -.B Module -section is used to specify which Xorg server modules should be loaded. -This section is ignored when the Xorg server is built in static form. -The type of modules normally loaded in this section are Xorg server -extension modules. -Most other module types are loaded automatically when they are needed via -other mechanisms. -The -.B Module -section is optional, as are all of the entries that may be specified in -it. -.PP -Entries in this section may be in two forms. -The first and most commonly used form is an entry that uses the -.B Load -keyword, as described here: -.TP 7 -.BI "Load \*q" modulename \*q -This instructs the server to load the module called -.IR modulename . -The module name given should be the module's standard name, not the -module file name. -The standard name is case\-sensitive, and does not include the \(lqlib\(rq -or \(lqcyg\(rq prefixes, or the \(lq.so\(rq or \(lq.dll\(rq suffixes. -.PP -.RS 7 -Example: the DRI extension module can be loaded with the following entry: -.PP -.RS 4 -.B "Load \*qdri\*q" -.RE -.RE -.TP 7 -.BI "Disable \*q" modulename \*q -This instructs the server to not load the module called -.IR modulename . -Some modules are loaded by default in the server, and this overrides that -default. If a -.B Load -instruction is given for the same module, it overrides the -.B Disable -instruction and the module is loaded. The module name given should be the -module's standard name, not the module file name. As with the -.B Load -instruction, the standard name is case-sensitive, and does not include the -"lib" prefix, or the ".a", ".o", or ".so" suffixes. -.PP -The second form of entry is a -.BR SubSection, -with the subsection name being the module name, and the contents of the -.B SubSection -being -.B Options -that are passed to the module when it is loaded. -.PP -Example: the extmod module (which contains a miscellaneous group of -server extensions) can be loaded, with the XFree86\-DGA extension -disabled by using the following entry: -.PP -.RS 4 -.nf -.B "SubSection \*qextmod\*q" -.B " Option \*qomit XFree86\-DGA\*q" -.B EndSubSection -.fi -.RE -.PP -Modules are searched for in each directory specified in the -.B ModulePath -search path, and in the drivers, extensions, input, internal, and -multimedia subdirectories of each of those directories. -In addition to this, operating system specific subdirectories of all -the above are searched first if they exist. -.PP -To see what extension modules are available, check the extensions -subdirectory under: -.PP -.RS 4 -.nf -@modulepath@ -.fi -.RE -.PP -The \(lqextmod\(rq, \(lqdbe\(rq, \(lqdri\(rq, \(lqdri2\(rq, \(lqglx\(rq, -and \(lqrecord\(rq extension modules are loaded automatically, if they -are present, unless disabled with \*qDisable\*q entries. -It is recommended -that at very least the \(lqextmod\(rq extension module be loaded. -If it isn't, some commonly used server extensions (like the SHAPE -extension) will not be available. -.SH "EXTENSIONS SECTION" -The -.B Extensions -section is used to specify which X11 protocol extensions should be enabled -or disabled. -The -.B Extensions -section is optional, as are all of the entries that may be specified in -it. -.PP -Entries in this section are listed as Option statements with the name of -the extension as the first argument, and a boolean value as the second. -The extension name is case\-sensitive, and matches the form shown in the output -of \*qXorg -extension ?\*q. -.PP -.RS 7 -Example: the MIT-SHM extension can be disabled with the following entry: -.PP -.RS 4 -.nf -.B "Section \*qExtensions\*q" -.B " Option \*qMIT-SHM\*q \*qDisable\*q" -.B "EndSection" -.fi -.RE -.RE -.SH "INPUTDEVICE SECTION" -The config file may have multiple -.B InputDevice -sections. -Recent X servers employ HAL or udev backends for input device enumeration -and input hotplugging. It is usually not -necessary to provide -.B InputDevice -sections in the xorg.conf if hotplugging is in use (i.e. AutoAddDevices is -enabled). If hotplugging is enabled, -.B InputDevice -sections using the -.B mouse, kbd -and -.B vmmouse -driver will be ignored. -.PP -If hotplugging is disabled, there will normally -be at least two: one for the core (primary) keyboard -and one for the core pointer. -If either of these two is missing, a default configuration for the missing -ones will be used. In the absence of an explicitly specified core input -device, the first -.B InputDevice -marked as -.B CorePointer -(or -.BR CoreKeyboard ) -is used. -If there is no match there, the first -.B InputDevice -that uses the \(lqmouse\(rq (or \(lqkbd\(rq) driver is used. -The final fallback is to use built\-in default configurations. -Currently the default configuration may not work as expected on all platforms. -.PP -.B InputDevice -sections have the following format: -.PP -.RS 4 -.nf -.B "Section \*qInputDevice\*q" -.BI " Identifier \*q" name \*q -.BI " Driver \*q" inputdriver \*q -.I " options" -.I " ..." -.B "EndSection" -.fi -.RE -.PP -The -.B Identifier -and -.B Driver -entries are required in all -.B InputDevice -sections. -All other entries are optional. -.PP -The -.B Identifier -entry specifies the unique name for this input device. -The -.B Driver -entry specifies the name of the driver to use for this input device. -When using the loadable server, the input driver module -.RI \*q inputdriver \*q -will be loaded for each active -.B InputDevice -section. -An -.B InputDevice -section is considered active if it is referenced by an active -.B ServerLayout -section, if it is referenced by the -.B \-keyboard -or -.B \-pointer -command line options, or if it is selected implicitly as the core pointer -or keyboard device in the absence of such explicit references. -The most commonly used input drivers are -.BR evdev (@drivermansuffix@) -on Linux systems, and -.BR kbd (@drivermansuffix@) -and -.BR mousedrv (@drivermansuffix@) -on other platforms. -.PP -.PP -.B InputDevice -sections recognise some driver\-independent -.BR Options , -which are described here. -See the individual input driver manual pages for a description of the -device\-specific options. -.TP 7 -.BI "Option \*qAutoServerLayout\*q \*q" boolean \*q -Always add the device to the ServerLayout section used by this instance of -the server. This affects implied layouts as well as explicit layouts -specified in the configuration and/or on the command line. -.TP 7 -.BI "Option \*qCorePointer\*q" -Deprecated, see -.B Floating -.TP 7 -.BI "Option \*qCoreKeyboard\*q" -Deprecated, see -.B Floating -.TP 7 -.BI "Option \*qAlwaysCore\*q \*q" boolean \*q -Deprecated, see -.B Floating -.TP 7 -.BI "Option \*qSendCoreEvents\*q \*q" boolean \*q -Deprecated, see -.B Floating - -.TP 7 -.BI "Option \*qFloating\*q \*q" boolean \*q -When enabled, the input device is set up floating and does not -report events through any master device or control a cursor. The device is -only available to clients using the X Input Extension API. This option is -disabled by default. -The options -.B CorePointer, -.B CoreKeyboard, -.B AlwaysCore, -and -.B SendCoreEvents, -are the inverse of option -.B Floating -(i.e. -.B SendCoreEvents \*qon\*q -is equivalent to -.B Floating \*qoff\*q -). - -This option controls the startup behavior only, a device -may be reattached or set floating at runtime. -.TP 7 -.BI "Option \*qTransformationMatrix\*q \*q" a " " b " " c " " d " " e " " f " " g " " h " " i \*q -Specifies the 3x3 transformation matrix for absolute input devices. The -input device will be bound to the area given in the matrix. In most -configurations, "a" and "e" specify the width and height of the area the -device is bound to, and "c" and "f" specify the x and y offset of the area. -The value range is 0 to 1, where 1 represents the width or height of all -root windows together, 0.5 represents half the area, etc. The values -represent a 3x3 matrix, with the first, second and third group of three -values representing the first, second and third row of the matrix, -respectively. The identity matrix is "1 0 0 0 1 0 0 0 1". -.SS POINTER ACCELERATION -For pointing devices, the following options control how the pointer -is accelerated or decelerated with respect to physical device motion. Most of -these can be adjusted at runtime, see the xinput(1) man page for details. Only -the most important acceleration options are discussed here. -.TP 7 -.BI "Option \*qAccelerationProfile\*q \*q" integer \*q -Select the profile. In layman's terms, the profile constitutes the "feeling" of -the acceleration. More formally, it defines how the transfer function (actual -acceleration as a function of current device velocity and acceleration controls) -is constructed. This is mainly a matter of personal preference. -.PP -.RS 6 -.nf -.B " 0 classic (mostly compatible)" -.B "-1 none (only constant deceleration is applied)" -.B " 1 device-dependent" -.B " 2 polynomial (polynomial function)" -.B " 3 smooth linear (soft knee, then linear)" -.B " 4 simple (normal when slow, otherwise accelerated)" -.B " 5 power (power function)" -.B " 6 linear (more speed, more acceleration)" -.B " 7 limited (like linear, but maxes out at threshold)" -.fi -.RE -.TP 7 -.BI "Option \*qConstantDeceleration\*q \*q" real \*q -Makes the pointer go -.B deceleration -times slower than normal. Most useful for high-resolution devices. A value -between 0 and 1 will speed up the pointer. -.TP 7 -.BI "Option \*qAdaptiveDeceleration\*q \*q" real \*q -Allows to actually decelerate the pointer when going slow. At most, it will be -.B adaptive deceleration -times slower. Enables precise pointer placement without sacrificing speed. -.TP 7 -.BI "Option \*qAccelerationScheme\*q \*q" string \*q -Selects the scheme, which is the underlying algorithm. -.PP -.RS 7 -.nf -.B "predictable default algorithm (behaving more predictable)" -.B "lightweight old acceleration code (as specified in the X protocol spec)" -.B "none no acceleration or deceleration" -.fi -.RE -.TP 7 -.BI "Option \*qAccelerationNumerator\*q \*q" integer \*q -.TP 7 -.BI "Option \*qAccelerationDenominator\*q \*q" integer \*q -Set numerator and denominator of the acceleration factor. The acceleration -factor is a rational which, together with threshold, can be used to tweak -profiles to suit the users needs. The -.B simple -and -.B limited -profiles use it directly (i.e. they accelerate by the factor), for other -profiles it should hold that a higher acceleration factor leads to a faster -pointer. Typically, 1 is unaccelerated and values up to 5 are sensible. -.TP 7 -.BI "Option \*qAccelerationThreshold\*q \*q" integer \*q -Set the threshold, which is roughly the velocity (usually device units per 10 -ms) required for acceleration to become effective. The precise effect varies -with the profile however. - -.SH "INPUTCLASS SECTION" -The config file may have multiple -.B InputClass -sections. -These sections are optional and are used to provide configuration for a -class of input devices as they are automatically added. An input device can -match more than one -.B InputClass -section. Each class can override settings from a previous class, so it is -best to arrange the sections with the most generic matches first. -.PP -.B InputClass -sections have the following format: -.PP -.RS 4 -.nf -.B "Section \*qInputClass\*q" -.BI " Identifier \*q" name \*q -.I " entries" -.I " ..." -.I " options" -.I " ..." -.B "EndSection" -.fi -.RE -.PP -The -.B Identifier -entry is required in all -.B InputClass -sections. -All other entries are optional. -.PP -The -.B Identifier -entry specifies the unique name for this input class. -The -.B Driver -entry specifies the name of the driver to use for this input device. -After all classes have been examined, the -.RI \*q inputdriver \*q -module from the first -.B Driver -entry will be enabled when using the loadable server. -.PP -When an input device is automatically added, its characteristics are -checked against all -.B InputClass -sections. Each section can contain optional entries to narrow the match -of the class. If none of the optional entries appear, the -.B InputClass -section is generic and will match any input device. If more than one of -these entries appear, they all must match for the configuration to apply. -.PP -There are two types of match entries used in -.B InputClass -sections. The first allows various tokens to be matched against attributes -of the device. An entry can be constructed to match attributes from different -devices by separating arguments with a '|' character. Multiple entries of the -same type may be supplied to add multiple matching conditions on the same -attribute. For example: -.PP -.RS 4 -.nf -.B "Section \*qInputClass\*q" -.B " Identifier \*qMy Class\*q" -.B " # product string must contain example and -.B " # either gizmo or gadget -.B " MatchProduct \*qexample\*q -.B " MatchProduct \*qgizmo|gadget\*q -.B " NoMatchDriver \*qdrivername\*q -.I " ..." -.B "EndSection" -.fi -.RE -.TP 7 -.BI "MatchProduct \*q" matchproduct \*q -This entry can be used to check if the substring -.RI \*q matchproduct \*q -occurs in the device's product name. -.TP 7 -.BI "MatchVendor \*q" matchvendor \*q -This entry can be used to check if the substring -.RI \*q matchvendor \*q -occurs in the device's vendor name. -.TP 7 -.BI "MatchDevicePath \*q" matchdevice \*q -This entry can be used to check if the device file matches the -.RI \*q matchdevice \*q -pathname pattern. -.TP 7 -.BI "MatchOS \*q" matchos \*q -This entry can be used to check if the operating system matches the -case-insensitive -.RI \*q matchos \*q -string. This entry is only supported on platforms providing the -.BR uname (2) -system call. -.TP 7 -.BI "MatchPnPID \*q" matchpnp \*q -The device's Plug and Play (PnP) ID can be checked against the -.RI \*q matchpnp \*q -shell wildcard pattern. -.TP 7 -.BI "MatchUSBID \*q" matchusb \*q -The device's USB ID can be checked against the -.RI \*q matchusb \*q -shell wildcard pattern. The ID is constructed as lowercase hexadecimal numbers -separated by a ':'. This is the same format as the -.BR lsusb (8) -program. -.TP 7 -.BI "MatchDriver \*q" matchdriver \*q -Check the case-sensitive string -.RI \*q matchdriver \*q -against the currently configured driver of the device. Ordering of sections -using this entry is important since it will not match unless the driver has -been set by the config backend or a previous -.B InputClass -section. -.TP 7 -.BI "MatchTag \*q" matchtag \*q -This entry can be used to check if tags assigned by the config backend -matches the -.RI \*q matchtag \*q -pattern. A match is found if at least one of the tags given in -.RI \*q matchtag \*q -matches at least one of the tags assigned by the backend. -.TP 7 -.BI "MatchLayout \*q" matchlayout \*q -Check the case-sensitive string -.RI \*q matchlayout \*q -against the currently active -.B ServerLayout -section. The empty string "" matches an implicit layout which appears -if no named -.B ServerLayout -sections have been found. -.PP -The above directives have equivalents for negative matching with the -.B NoMatchProduct, -.B NoMatchVendor, -.B NoMatchDevicePath, -.B NoMatchOS, -.B NoMatchPnPID, -.B NoMatchUSBID, -.B NoMatchDriver, -.B NoMatchTag, -and -.B NoMatchLayout -directives. These NoMatch directives match if the subsequent match is not -met by the device. -.PP -The second type of entry is used to match device types. These entries take a -boolean argument similar to -.B Option -entries. -.TP 7 -.BI "MatchIsKeyboard \*q" bool \*q -.TP 7 -.BI "MatchIsPointer \*q" bool \*q -.TP 7 -.BI "MatchIsJoystick \*q" bool \*q -.TP 7 -.BI "MatchIsTablet \*q" bool \*q -.TP 7 -.BI "MatchIsTabletPad \*q" bool \*q -.TP 7 -.BI "MatchIsTouchpad \*q" bool \*q -.TP 7 -.BI "MatchIsTouchscreen \*q" bool \*q -.PP -When an input device has been matched to the -.B InputClass -section, any -.B Option -entries are applied to the device. One -.B InputClass -specific -.B Option -is recognized. See the -.B InputDevice -section above for a description of the remaining -.B Option -entries. -.TP 7 -.BI "Option \*qIgnore\*q \*q" boolean \*q -This optional entry specifies that the device should be ignored entirely, -and not added to the server. This can be useful when the device is handled -by another program and no X events should be generated. -.SH "OUTPUTCLASS SECTION" -The config file may have multiple -.B OutputClass -sections. -These sections are optional and are used to provide configuration for a -class of output devices as they are automatically added. -An output device can match more than one -.B OutputClass -section. -Each class can override settings from a previous class, so it is best to -arrange the sections with the most generic matches first. -.PP -.B OutputClass -sections have the following format: -.PP -.RS 4 -.nf -.B "Section \*qOutputClass\*q" -.BI " Identifier \*q" name \*q -.I " entries" -.I " ..." -.B "EndSection" -.fi -.RE -.PP -The -.B Identifier -entry is required in all -.B OutputClass -sections. -All other entries are optional. -.PP -The -.B Identifier -entry specifies the unique name for this output class. -The -.B Driver -entry specifies the name of the driver to use for this output device. -After all classes have been examined, the -.RI \*q outputdriver \*q -module from the first -.B Driver -entry will be enabled when using the loadable server. -.PP -When an output device is automatically added, its characteristics are -checked against all -.B OutputClass -sections. -Each section can contain optional entries to narrow the match of the class. -If none of the optional entries appear, the -.B OutputClass -section is generic and will match any output device. -If more than one of these entries appear, they all must match for the -configuration to apply. -.PP -The following list of tokens can be matched against attributes of the device. -An entry can be constructed to match attributes from different devices by -separating arguments with a '|' character. -.PP -For example: -.PP -.RS 4 -.nf -.B "Section \*qOutputClass\*q" -.B " Identifier \*qMy Class\*q" -.B " # kernel driver must be either foo or bar -.B " MatchDriver \*qfoo|bar\*q -.I " ..." -.B "EndSection" -.fi -.RE -.TP 7 -.BI "MatchDriver \*q" matchdriver \*q -Check the case-sensitive string -.RI \*q matchdriver \*q -against the kernel driver of the device. -.PP -When an output device has been matched to the -.B OutputClass -section, any -.B Option -entries are applied to the device. One -.B OutputClass -specific -.B Option -is recognized. See the -.B Device -section below for a description of the remaining -.B Option -entries. -.TP 7 -.BI "Option \*qPrimaryGPU\*q \*q" boolean \*q -This option specifies that the matched device should be treated as the -primary GPU, replacing the selection of the GPU used as output by the -firmware. If multiple output devices match an OutputClass section with -the PrimaryGPU option set, the first one enumerated becomes the primary GPU. -.PP -A -.B OutputClass -Section may contain -.B ModulePath -entries. When an output device matches an -.B OutputClass -section, any -.B ModulePath -entries in that -.B OutputClass -are pre-pended to the search path for loadable Xorg server modules. See -.B ModulePath -in the -.B Files -section for more info. -.SH "DEVICE SECTION" -The config file may have multiple -.B Device -sections. -There must be at least one, for the video card being used. -.PP -.B Device -sections have the following format: -.PP -.RS 4 -.nf -.B "Section \*qDevice\*q" -.BI " Identifier \*q" name \*q -.BI " Driver \*q" driver \*q -.I " entries" -.I " ..." -.B "EndSection" -.fi -.RE -.PP -The -.B Identifier -and -.B Driver -entries are required in all -.B Device -sections. All other entries are optional. -.PP -The -.B Identifier -entry specifies the unique name for this graphics device. -The -.B Driver -entry specifies the name of the driver to use for this graphics device. -When using the loadable server, the driver module -.RI \*q driver \*q -will be loaded for each active -.B Device -section. -A -.B Device -section is considered active if it is referenced by an active -.B Screen -section. -.PP -.B Device -sections recognise some driver\-independent entries and -.BR Options , -which are described here. -Not all drivers make use of these -driver\-independent entries, and many of those that do don't require them -to be specified because the information is auto\-detected. -See the individual graphics driver manual pages for further information -about this, and for a description of the device\-specific options. -Note that most of the -.B Options -listed here (but not the other entries) may be specified in the -.B Screen -section instead of here in the -.B Device -section. -.TP 7 -.BI "BusID \*q" bus\-id \*q -This specifies the bus location of the graphics card. -For PCI/AGP cards, -the -.I bus\-id -string has the form -.BI PCI: bus @ domain : device : function -(e.g., \(lqPCI:1@0:0:0\(rq might be appropriate for an AGP card). The -"@domain" part can be left out for PCI domain 0. This field is usually -optional in single-head configurations when using the primary graphics card. -In multi-head configurations, or when using a secondary graphics card in a -single-head configuration, this entry is mandatory. -Its main purpose is to make an unambiguous connection between the device -section and the hardware it is representing. -This information can usually be found by running the pciaccess tool -scanpci. -.TP 7 -.BI "Screen " number -This option is mandatory for cards where a single PCI entity can drive more -than one display (i.e., multiple CRTCs sharing a single graphics accelerator -and video memory). -One -.B Device -section is required for each head, and this -parameter determines which head each of the -.B Device -sections applies to. -The legal values of -.I number -range from 0 to one less than the total number of heads per entity. -Most drivers require that the primary screen (0) be present. -.TP 7 -.BI "Chipset \*q" chipset \*q -This usually optional entry specifies the chipset used on the graphics -board. -In most cases this entry is not required because the drivers will probe the -hardware to determine the chipset type. -Don't specify it unless the driver-specific documentation recommends that you -do. -.TP 7 -.BI "Ramdac \*q" ramdac\-type \*q -This optional entry specifies the type of RAMDAC used on the graphics -board. -This is only used by a few of the drivers, and in most cases it is not -required because the drivers will probe the hardware to determine the -RAMDAC type where possible. -Don't specify it unless the driver-specific documentation recommends that you -do. -.TP 7 -.BI "DacSpeed " speed -.TP 7 -.BI "DacSpeed " "speed\-8 speed\-16 speed\-24 speed\-32" -This optional entry specifies the RAMDAC speed rating (which is usually -printed on the RAMDAC chip). -The speed is in MHz. -When one value is given, it applies to all framebuffer pixel sizes. -When multiple values are given, they apply to the framebuffer pixel sizes -8, 16, 24 and 32 respectively. -This is not used by many drivers, and only needs to be specified when the -speed rating of the RAMDAC is different from the defaults built in to -driver, or when the driver can't auto-detect the correct defaults. -Don't specify it unless the driver-specific documentation recommends that you -do. -.TP 7 -.BI "Clocks " "clock ..." -specifies the pixel that are on your graphics board. -The clocks are in MHz, and may be specified as a floating point number. -The value is stored internally to the nearest kHz. -The ordering of the clocks is important. -It must match the order in which they are selected on the graphics board. -Multiple -.B Clocks -lines may be specified, and each is concatenated to form the list. -Most drivers do not use this entry, and it is only required for some older -boards with non-programmable clocks. -Don't specify this entry unless the driver-specific documentation explicitly -recommends that you do. -.TP -.BI "ClockChip \*q" clockchip\-type \*q -This optional entry is used to specify the clock chip type on graphics -boards which have a programmable clock generator. -Only a few Xorg drivers support programmable clock chips. -For details, see the appropriate driver manual page. -.TP 7 -.BI "VideoRam " "mem" -This optional entry specifies the amount of video ram that is installed -on the graphics board. -This is measured in kBytes. -In most cases this is not required because the Xorg server probes -the graphics board to determine this quantity. -The driver-specific documentation should indicate when it might be needed. -.TP 7 -.BI "MemBase " "baseaddress" -This optional entry specifies the memory base address of a graphics -board's linear frame buffer. -This entry is not used by many drivers, and it should only be specified if -the driver-specific documentation recommends it. -.TP 7 -.BI "IOBase " "baseaddress" -This optional entry specifies the IO base address. -This entry is not used by many drivers, and it should only be specified if -the driver-specific documentation recommends it. -.TP 7 -.BI "ChipID " "id" -This optional entry specifies a numerical ID representing the chip type. -For PCI cards, it is usually the device ID. -This can be used to override the auto-detection, but that should only be done -when the driver-specific documentation recommends it. -.TP 7 -.BI "ChipRev " "rev" -This optional entry specifies the chip revision number. -This can be used to override the auto-detection, but that should only be done -when the driver-specific documentation recommends it. -.TP 7 -.BI "MatchSeat " "seat\-id" -Only apply this -.B Device -section if X server was started with -.B -seat -.I seat\-id -option. -.TP 7 -.BI "Option \*qModeDebug\*q \*q" boolean \*q -Enable printing of additional debugging information about modesetting to -the server log. -.TP 7 -.BI "Option \*qNoOutputInitialSize\*q \*q" width " " height \*q -Normally, the X server infers the initial screen size based on any -connected outputs. -However, if no outputs are connected, the X server picks a default screen size -of 1024 x 768. -This option overrides the default screen size to use when no outputs are -connected. -In contrast to the \*qVirtual\*q Display SubSection entry, which applies -unconditionally, \*qNoOutputInitialSize\*q is only used if no outputs are -detected when the X server starts. -.TP 7 -.BI "Option \*qPreferCloneMode\*q \*q" boolean \*q -If enabled, bring up monitors of a screen in clone mode instead of horizontal -extended layout by default. (Defaults to off; the video driver can change the -default value, but this option can always override it) -.ig -.TP 7 -This optional entry allows an IRQ number to be specified. -.. -.TP 7 -.B Options -Option flags may be specified in the -.B Device -sections. -These include driver\-specific options and driver\-independent options. -The former are described in the driver\-specific documentation. -Some of the latter are described below in the section about the -.B Screen -section, and they may also be included here. - -.SH "VIDEOADAPTOR SECTION" -Nobody wants to say how this works. -Maybe nobody knows ... - -.SH "MONITOR SECTION" -The config file may have multiple -.B Monitor -sections. -There should normally be at least one, for the monitor being used, -but a default configuration will be created when one isn't specified. -.PP -.B Monitor -sections have the following format: -.PP -.RS 4 -.nf -.B "Section \*qMonitor\*q" -.BI " Identifier \*q" name \*q -.I " entries" -.I " ..." -.B "EndSection" -.fi -.RE -.PP -The only mandatory entry in a -.B Monitor -section is the -.B Identifier -entry. -.PP -The -.B Identifier -entry specifies the unique name for this monitor. -The -.B Monitor -section may be used to provide information about the specifications of the -monitor, monitor-specific -.BR Options , -and information about the video modes to use with the monitor. -.PP -With RandR 1.2-enabled drivers, monitor sections may be tied to specific -outputs of the video card. Using the name of the output defined by the video -driver plus the identifier of a monitor section, one associates a monitor -section with an output by adding an option to the Device section in the -following format: - -.BI "Option \*qMonitor-" outputname "\*q \*q" monitorsection \*q - -(for example, -.B Option \*qMonitor-VGA\*q \*qVGA monitor\*q -for a VGA output) -.PP -In the absence of specific association of monitor sections to outputs, if a -monitor section is present the server will associate it with an output to -preserve compatibility for previous single-head configurations. -.PP -Specifying video modes is optional because the server will use the DDC or other -information provided by the monitor to automatically configure the list of -modes available. -When modes are specified explicitly in the -.B Monitor -section (with the -.BR Mode , -.BR ModeLine , -or -.B UseModes -keywords), built-in modes with the same names are not included. -Built-in modes with different names are, however, still implicitly included, -when they meet the requirements of the monitor. -.PP -The entries that may be used in -.B Monitor -sections are described below. -.TP 7 -.BI "VendorName \*q" vendor \*q -This optional entry specifies the monitor's manufacturer. -.TP 7 -.BI "ModelName \*q" model \*q -This optional entry specifies the monitor's model. -.TP 7 -.BI "HorizSync " "horizsync\-range" -gives the range(s) of horizontal sync frequencies supported by the -monitor. -.I horizsync\-range -may be a comma separated list of either discrete values or ranges of -values. -A range of values is two values separated by a dash. -By default the values are in units of kHz. -They may be specified in MHz or Hz -if -.B MHz -or -.B Hz -is added to the end of the line. -The data given here is used by the Xorg server to determine if video -modes are within the specifications of the monitor. -This information should be available in the monitor's handbook. -If this entry is omitted, a default range of 28\-33kHz is used. -.TP 7 -.BI "VertRefresh " "vertrefresh\-range" -gives the range(s) of vertical refresh frequencies supported by the -monitor. -.I vertrefresh\-range -may be a comma separated list of either discrete values or ranges of -values. -A range of values is two values separated by a dash. -By default the values are in units of Hz. -They may be specified in MHz or kHz -if -.B MHz -or -.B kHz -is added to the end of the line. -The data given here is used by the Xorg server to determine if video -modes are within the specifications of the monitor. -This information should be available in the monitor's handbook. -If this entry is omitted, a default range of 43\-72Hz is used. -.TP 7 -.BI "DisplaySize " "width height" -This optional entry gives the width and height, in millimetres, of the -picture area of the monitor. -If given this is used to calculate the horizontal and vertical pitch (DPI) of -the screen. -.TP 7 -.BI "Gamma " "gamma\-value" -.TP 7 -.BI "Gamma " "red\-gamma green\-gamma blue\-gamma" -This is an optional entry that can be used to specify the gamma correction -for the monitor. -It may be specified as either a single value or as three separate RGB values. -The values should be in the range 0.1 to 10.0, and the default is 1.0. -Not all drivers are capable of using this information. -.TP 7 -.BI "UseModes \*q" modesection\-id \*q -Include the set of modes listed in the -.B Modes -section called -.IR modesection\-id. -This makes all of the modes defined in that section available for use by -this monitor. -.TP 7 -.BI "Mode \*q" name \*q -This is an optional multi-line entry that can be used to provide -definitions for video modes for the monitor. -In most cases this isn't necessary because the built-in set of VESA standard -modes will be sufficient. -The -.B Mode -keyword indicates the start of a multi-line video mode description. -The mode description is terminated with the -.B EndMode -keyword. -The mode description consists of the following entries: -.RS 7 -.TP 4 -.BI "DotClock " clock -is the dot (pixel) clock rate to be used for the mode. -.TP 4 -.BI "HTimings " "hdisp hsyncstart hsyncend htotal" -specifies the horizontal timings for the mode. -.TP 4 -.BI "VTimings " "vdisp vsyncstart vsyncend vtotal" -specifies the vertical timings for the mode. -.TP 4 -.BI "Flags \*q" flag \*q " ..." -specifies an optional set of mode flags, each of which is a separate -string in double quotes. -.B \*qInterlace\*q -indicates that the mode is interlaced. -.B \*qDoubleScan\*q -indicates a mode where each scanline is doubled. -.B \*q+HSync\*q -and -.B \*q\-HSync\*q -can be used to select the polarity of the HSync signal. -.B \*q+VSync\*q -and -.B \*q\-VSync\*q -can be used to select the polarity of the VSync signal. -.B \*qComposite\*q -can be used to specify composite sync on hardware where this is supported. -Additionally, on some hardware, -.B \*q+CSync\*q -and -.B \*q\-CSync\*q -may be used to select the composite sync polarity. -.TP 4 -.BI "HSkew " hskew -specifies the number of pixels (towards the right edge of the screen) by -which the display enable signal is to be skewed. -Not all drivers use this information. -This option might become necessary to override the default value supplied -by the server (if any). -\(lqRoving\(rq horizontal lines indicate this value needs to be increased. -If the last few pixels on a scan line appear on the left of the screen, -this value should be decreased. -.TP 4 -.BI "VScan " vscan -specifies the number of times each scanline is painted on the screen. -Not all drivers use this information. -Values less than 1 are treated as 1, which is the default. -Generally, the -.B \*qDoubleScan\*q -.B Flag -mentioned above doubles this value. -.RE -.TP 7 -.BI "ModeLine \*q" name \*q " mode\-description" -This entry is a more compact version of the -.B Mode -entry, and it also can be used to specify video modes for the monitor. -This is a single line format for specifying video modes. -In most cases this isn't necessary because the built\-in set of VESA -standard modes will be sufficient. -.PP -.RS 7 -The -.I mode\-description -is in four sections, the first three of which are mandatory. -The first is the dot (pixel) clock. -This is a single number specifying the pixel clock rate for the mode in -MHz. -The second section is a list of four numbers specifying the horizontal -timings. -These numbers are the -.IR hdisp , -.IR hsyncstart , -.IR hsyncend , -and -.I htotal -values. -The third section is a list of four numbers specifying the vertical -timings. -These numbers are the -.IR vdisp , -.IR vsyncstart , -.IR vsyncend , -and -.I vtotal -values. -The final section is a list of flags specifying other characteristics of -the mode. -.B Interlace -indicates that the mode is interlaced. -.B DoubleScan -indicates a mode where each scanline is doubled. -.B +HSync -and -.B \-HSync -can be used to select the polarity of the HSync signal. -.B +VSync -and -.B \-VSync -can be used to select the polarity of the VSync signal. -.B Composite -can be used to specify composite sync on hardware where this is supported. -Additionally, on some hardware, -.B +CSync -and -.B \-CSync -may be used to select the composite sync polarity. -The -.B HSkew -and -.B VScan -options mentioned above in the -.B Mode -entry description can also be used here. -.RE -.TP 7 -.BI "Option \*qDPMS\*q \*q" bool \*q -This option controls whether the server should enable the DPMS extension -for power management for this screen. The default is to enable the -extension. -.TP 7 -.BI "Option \*qSyncOnGreen\*q \*q" bool \*q -This option controls whether the video card should drive the sync signal -on the green color pin. Not all cards support this option, and most -monitors do not require it. The default is off. -.TP 7 -.BI "Option \*qPrimary\*q \*q" bool \*q -This optional entry specifies that the monitor should be treated as the primary -monitor. (RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qPreferredMode\*q \*q" name \*q -This optional entry specifies a mode to be marked as the preferred initial mode -of the monitor. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qZoomModes\*q \*q" name " " name " " ... \*q -This optional entry specifies modes to be marked as zoom modes. -It is possible to switch to the next and previous mode via -.BR Ctrl+Alt+Keypad\-Plus " and " Ctrl+Alt+Keypad\-Minus . -All these keypad available modes are selected from the screen mode list. -This list is a copy of the compatibility output monitor mode list. -Since this output is the output connected to the lowest -dot-area monitor, as determined from its largest size mode, that -monitor defines the available zoom modes. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qPosition\*q \*q" x " " y \*q -This optional entry specifies the position of the monitor within the X -screen. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qLeftOf\*q \*q" output \*q -This optional entry specifies that the monitor should be positioned to the -left of the output (not monitor) of the given name. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qRightOf\*q \*q" output \*q -This optional entry specifies that the monitor should be positioned to the -right of the output (not monitor) of the given name. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qAbove\*q \*q" output \*q -This optional entry specifies that the monitor should be positioned above the -output (not monitor) of the given name. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qBelow\*q \*q" output \*q -This optional entry specifies that the monitor should be positioned below the -output (not monitor) of the given name. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qEnable\*q \*q" bool \*q -This optional entry specifies whether the monitor should be turned on -at startup. By default, the server will attempt to enable all connected -monitors. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qDefaultModes\*q \*q" bool \*q -This optional entry specifies whether the server should add supported default -modes to the list of modes offered on this monitor. By default, the server -will add default modes; you should only disable this if you can guarantee -that EDID will be available at all times, or if you have added custom modelines -which the server can use. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qMinClock\*q \*q" frequency \*q -This optional entry specifies the minimum dot clock, in kHz, that is supported -by the monitor. -.TP 7 -.BI "Option \*qMaxClock\*q \*q" frequency \*q -This optional entry specifies the maximum dot clock, in kHz, that is supported -by the monitor. -.TP 7 -.BI "Option \*qIgnore\*q \*q" bool \*q -This optional entry specifies that the monitor should be ignored entirely, -and not reported through RandR. This is useful if the hardware reports the -presence of outputs that don't exist. -(RandR 1.2-supporting drivers only) -.TP 7 -.BI "Option \*qRotate\*q \*q" rotation \*q -This optional entry specifies the initial rotation of the given monitor. -Valid values for rotation are \*qnormal\*q, \*qleft\*q, \*qright\*q, and -\*qinverted\*q. -(RandR 1.2-supporting drivers only) - -.SH "MODES SECTION" -The config file may have multiple -.B Modes -sections, or none. -These sections provide a way of defining sets of video modes independently -of the -.B Monitor -sections. -.B Monitor -sections may include the definitions provided in these sections by -using the -.B UseModes -keyword. -In most cases the -.B Modes -sections are not necessary because the built\-in set of VESA standard modes -will be sufficient. -.PP -.B Modes -sections have the following format: -.PP -.RS 4 -.nf -.B "Section \*qModes\*q" -.BI " Identifier \*q" name \*q -.I " entries" -.I " ..." -.B "EndSection" -.fi -.RE -.PP -The -.B Identifier -entry specifies the unique name for this set of mode descriptions. -The other entries permitted in -.B Modes -sections are the -.B Mode -and -.B ModeLine -entries that are described above in the -.B Monitor -section. -.SH "SCREEN SECTION" -The config file may have multiple -.B Screen -sections. -There must be at least one, for the \(lqscreen\(rq being used. -A \(lqscreen\(rq represents the binding of a graphics device -.RB ( Device -section) and a monitor -.RB ( Monitor -section). -A -.B Screen -section is considered \(lqactive\(rq if it is referenced by an active -.B ServerLayout -section or by the -.B \-screen -command line option. -If neither of those is present, the first -.B Screen -section found in the config file is considered the active one. -.PP -.B Screen -sections have the following format: -.PP -.RS 4 -.nf -.B "Section \*qScreen\*q" -.BI " Identifier \*q" name \*q -.BI " Device \*q" devid \*q -.BI " GPUDevice \*q" devid \*q -.BI " Monitor \*q" monid \*q -.I " entries" -.I " ..." -.BI " SubSection \*qDisplay\*q" -.I " entries" -.I " ... -.B " EndSubSection" -.I " ..." -.B "EndSection" -.fi -.RE -.PP -The -.B Identifier -entry is mandatory. -All others are optional. -.PP -The -.B Identifier -entry specifies the unique name for this screen. -The -.B Screen -section provides information specific to the whole screen, including -screen\-specific -.BR Options . -In multi\-head configurations, there will be multiple active -.B Screen -sections, one for each head. -The entries available -for this section are: -.TP 7 -.BI "Device \*q" device\-id \*q -This entry specifies the -.B Device -section to be used for this screen. When multiple graphics cards are -present, this is what ties a specific card to a screen. The -.I device\-id -must match the -.B Identifier -of a -.B Device -section in the config file. -.TP 7 -.BI "GPUDevice \*q" device\-id \*q -This entry specifies the -.B Device -section to be used as a secondary GPU device for this screen. When multiple graphics cards are -present, this is what ties a specific secondary card to a screen. The -.I device\-id -must match the -.B Identifier -of a -.B Device -section in the config file. This can be specified up to 4 times for a single screen. -.TP 7 -.BI "Monitor \*q" monitor\-id \*q -specifies which monitor description is to be used for this screen. -If a -.B Monitor -name is not specified, a default configuration is used. -Currently the default configuration may not function as expected on all -platforms. -.TP 7 -.BI "VideoAdaptor \*q" xv\-id \*q -specifies an optional Xv video adaptor description to be used with this -screen. -.TP 7 -.BI "DefaultDepth " depth -specifies which color depth the server should use by default. -The -.B \-depth -command line option can be used to override this. -If neither is specified, the default depth is driver\-specific, but in most -cases is 8. -.TP 7 -.BI "DefaultFbBpp " bpp -specifies which framebuffer layout to use by default. -The -.B \-fbbpp -command line option can be used to override this. -In most cases the driver will chose the best default value for this. -The only case where there is even a choice in this value is for depth 24, -where some hardware supports both a packed 24 bit framebuffer layout and a -sparse 32 bit framebuffer layout. -.TP 7 -.BI "MatchSeat " "seat\-id" -Only apply this -.B Screen -section if X server was started with -.B -seat -.I seat\-id -option. -.TP 7 -.B Options -Various -.B Option -flags may be specified in the -.B Screen -section. -Some are driver\-specific and are described in the driver documentation. -Others are driver\-independent, and will eventually be described here. -.\" XXX These should really be in an xaa man page. -.TP 7 -.BI "Option \*qAccel\*q" -Enables 2D hardware acceleration. -This option is on by default, but it may be necessary to turn it off if -there are bugs in the driver. -There are many options to disable specific accelerated operations, listed -below. -Note that disabling an operation will have no effect if the operation is -not accelerated (whether due to lack of support in the hardware or in the -driver). -.TP 7 -.BI "Option \*qGlxVendorLibrary\*q \*q" string \*q -This option specifies a space-separated list of OpenGL vendor libraries to -use for the screen. This may be used to select an alternate implementation -for development, debugging, or alternate feature sets. -Default: mesa. -.TP 7 -.BI "Option \*qInitPrimary\*q \*q" boolean \*q -Use the Int10 module to initialize the primary graphics card. -Normally, only secondary cards are soft-booted using the Int10 module, as the -primary card has already been initialized by the BIOS at boot time. -Default: false. -.TP 7 -.BI "Option \*qNoInt10\*q \*q" boolean \*q -Disables the Int10 module, a module that uses the int10 call to the BIOS -of the graphics card to initialize it. -Default: false. -.PP -Each -.B Screen -section may optionally contain one or more -.B Display -subsections. -Those subsections provide depth/fbbpp specific configuration information, -and the one chosen depends on the depth and/or fbbpp that is being used for -the screen. -The -.B Display -subsection format is described in the section below. - -.SH "DISPLAY SUBSECTION" -Each -.B Screen -section may have multiple -.B Display -subsections. -The \(lqactive\(rq -.B Display -subsection is the first that matches the depth and/or fbbpp values being -used, or failing that, the first that has neither a depth or fbbpp value -specified. -The -.B Display -subsections are optional. -When there isn't one that matches the depth and/or fbbpp values being used, -all the parameters that can be specified here fall back to their defaults. -.PP -.B Display -subsections have the following format: -.PP -.RS 4 -.nf -.B " SubSection \*qDisplay\*q" -.BI " Depth " depth -.I " entries" -.I " ..." -.B " EndSubSection" -.fi -.RE -.TP 7 -.BI "Depth " depth -This entry specifies what colour depth the -.B Display -subsection is to be used for. -This entry is usually specified, but it may be omitted to create a match\-all -.B Display -subsection or when wishing to match only against the -.B FbBpp -parameter. -The range of -.I depth -values that are allowed depends on the driver. -Most drivers support 8, 15, 16 and 24. -Some also support 1 and/or 4, and some may support other values (like 30). -Note: -.I depth -means the number of bits in a pixel that are actually used to determine -the pixel colour. -32 is not a valid -.I depth -value. -Most hardware that uses 32 bits per pixel only uses 24 of them to hold the -colour information, which means that the colour depth is 24, not 32. -.TP 7 -.BI "FbBpp " bpp -This entry specifies the framebuffer format this -.B Display -subsection is to be used for. -This entry is only needed when providing depth 24 configurations that allow -a choice between a 24 bpp packed framebuffer format and a 32bpp sparse -framebuffer format. -In most cases this entry should not be used. -.TP 7 -.BI "Weight " "red\-weight green\-weight blue\-weight" -This optional entry specifies the relative RGB weighting to be used -for a screen is being used at depth 16 for drivers that allow multiple -formats. -This may also be specified from the command line with the -.B \-weight -option (see -.BR Xorg(@appmansuffix@)). -.TP 7 -.BI "Virtual " "xdim ydim" -This optional entry specifies the virtual screen resolution to be used. -.I xdim -must be a multiple of either 8 or 16 for most drivers, and a multiple -of 32 when running in monochrome mode. -The given value will be rounded down if this is not the case. -Video modes which are too large for the specified virtual size will be -rejected. -If this entry is not present, the virtual screen resolution will be set to -accommodate all the valid video modes given in the -.B Modes -entry. -Some drivers/hardware combinations do not support virtual screens. -Refer to the appropriate driver\-specific documentation for details. -.TP 7 -.BI "ViewPort " "x0 y0" -This optional entry sets the upper left corner of the initial display. -This is only relevant when the virtual screen resolution is different -from the resolution of the initial video mode. -If this entry is not given, then the initial display will be centered in -the virtual display area. -.TP 7 -.BI "Modes \*q" mode\-name \*q " ..." -This optional entry specifies the list of video modes to use. -Each -.I mode\-name -specified must be in double quotes. -They must correspond to those specified or referenced in the appropriate -.B Monitor -section (including implicitly referenced built\-in VESA standard modes). -The server will delete modes from this list which don't satisfy various -requirements. -The first valid mode in this list will be the default display mode for -startup. -The list of valid modes is converted internally into a circular list. -It is possible to switch to the next mode with -.B Ctrl+Alt+Keypad\-Plus -and to the previous mode with -.BR Ctrl+Alt+Keypad\-Minus . -When this entry is omitted, the valid modes referenced by the appropriate -.B Monitor -section will be used. If the -.B Monitor -section contains no modes, then the selection will be taken from the -built-in VESA standard modes. -.TP 7 -.BI "Visual \*q" visual\-name \*q -This optional entry sets the default root visual type. -This may also be specified from the command line (see the -.BR Xserver(@appmansuffix@) -man page). -The visual types available for depth 8 are (default is -.BR PseudoColor ): -.PP -.RS 11 -.nf -.B StaticGray -.B GrayScale -.B StaticColor -.B PseudoColor -.B TrueColor -.B DirectColor -.fi -.RE -.PP -.RS 7 -The visual type available for the depths 15, 16 and 24 are (default is -.BR TrueColor ): -.PP -.RS 4 -.nf -.B TrueColor -.B DirectColor -.fi -.RE -.PP -Not all drivers support -.B DirectColor -at these depths. -.PP -The visual types available for the depth 4 are (default is -.BR StaticColor ): -.PP -.RS 4 -.nf -.B StaticGray -.B GrayScale -.B StaticColor -.B PseudoColor -.fi -.RE -.PP -The visual type available for the depth 1 (monochrome) is -.BR StaticGray . -.RE -.TP 7 -.BI "Black " "red green blue" -This optional entry allows the \(lqblack\(rq colour to be specified. -This is only supported at depth 1. -The default is black. -.TP 7 -.BI "White " "red green blue" -This optional entry allows the \(lqwhite\(rq colour to be specified. -This is only supported at depth 1. -The default is white. -.TP 7 -.B Options -Option flags may be specified in the -.B Display -subsections. -These may include driver\-specific options and driver\-independent options. -The former are described in the driver\-specific documentation. -Some of the latter are described above in the section about the -.B Screen -section, and they may also be included here. -.SH "SERVERLAYOUT SECTION" -The config file may have multiple -.B ServerLayout -sections. -A \(lqserver layout\(rq represents the binding of one or more screens -.RB ( Screen -sections) and one or more input devices -.RB ( InputDevice -sections) to form a complete configuration. -In multi\-head configurations, it also specifies the relative layout of the -heads. -A -.B ServerLayout -section is considered \(lqactive\(rq if it is referenced by the -.B \-layout -command line option or by an -.B "Option \*qDefaultServerLayout\*q" -entry in the -.B ServerFlags -section (the former takes precedence over the latter). -If those options are not used, the first -.B ServerLayout -section found in the config file is considered the active one. -If no -.B ServerLayout -sections are present, the single active screen and two active (core) -input devices are selected as described in the relevant sections above. -.PP -.B ServerLayout -sections have the following format: -.PP -.RS 4 -.nf -.B "Section \*qServerLayout\*q" -.BI " Identifier \*q" name \*q -.BI " Screen \*q" screen\-id \*q -.I " ..." -.BI " InputDevice \*q" idev\-id \*q -.I " ..." -.I " options" -.I " ..." -.B "EndSection" -.fi -.RE -.PP -Each -.B ServerLayout -section must have an -.B Identifier -entry and at least one -.B Screen -entry. -.PP -The -.B Identifier -entry specifies the unique name for this server layout. -The -.B ServerLayout -section provides information specific to the whole session, including -session\-specific -.BR Options . -The -.B ServerFlags -options (described above) may be specified here, and ones given here -override those given in the -.B ServerFlags -section. -.PP -The entries that may be used in this section are described here. -.TP 7 -.BI "Screen " "screen\-num" " \*qscreen\-id\*q " "position\-information" -One of these entries must be given for each screen being used in -a session. -The -.I screen\-id -field is mandatory, and specifies the -.B Screen -section being referenced. -The -.I screen\-num -field is optional, and may be used to specify the screen number -in multi\-head configurations. -When this field is omitted, the screens will be numbered in the order that -they are listed in. -The numbering starts from 0, and must be consecutive. -The -.I position\-information -field describes the way multiple screens are positioned. -There are a number of different ways that this information can be provided: -.RS 7 -.TP 4 -.I "x y" -.TP 4 -.BI "Absolute " "x y" -These both specify that the upper left corner's coordinates are -.RI ( x , y ). -The -.B Absolute -keyword is optional. -Some older versions of XFree86 (4.2 and earlier) don't recognise the -.B Absolute -keyword, so it's safest to just specify the coordinates without it. -.TP 4 -.BI "RightOf \*q" screen\-id \*q -.TP 4 -.BI "LeftOf \*q" screen\-id \*q -.TP 4 -.BI "Above \*q" screen\-id \*q -.TP 4 -.BI "Below \*q" screen\-id \*q -.TP 4 -.BI "Relative \*q" screen\-id \*q " x y" -These give the screen's location relative to another screen. -The first four position the screen immediately to the right, left, above or -below the other screen. -When positioning to the right or left, the top edges are aligned. -When positioning above or below, the left edges are aligned. -The -.B Relative -form specifies the offset of the screen's origin (upper left corner) -relative to the origin of another screen. -.RE -.TP 7 -.BI "InputDevice \*q" idev\-id "\*q \*q" option \*q " ..." -One of these entries should be given for each input device being used in -a session. -Normally at least two are required, one each for the core pointer and -keyboard devices. -If either of those is missing, suitable -.B InputDevice -entries are searched for using the method described above in the -.B INPUTDEVICE -section. The -.I idev\-id -field is mandatory, and specifies the name of the -.B InputDevice -section being referenced. -Multiple -.I option -fields may be specified, each in double quotes. -The options permitted here are any that may also be given in the -.B InputDevice -sections. -Normally only session\-specific input device options would be used here. -The most commonly used options are: -.PP -.RS 11 -.nf -.B \*qCorePointer\*q -.B \*qCoreKeyboard\*q -.B \*qSendCoreEvents\*q -.fi -.RE -.PP -.RS 7 -and the first two should normally be used to indicate the core pointer -and core keyboard devices respectively. -.RE -.TP 7 -.BI "MatchSeat " "seat\-id" -Only apply this -.B ServerLayout -section if X server was started with -.B -seat -.I seat\-id -option. -.TP 7 -.B Options -In addition to the following, any option permitted in the -.B ServerFlags -section may also be specified here. -When the same option appears in both places, the value given here overrides -the one given in the -.B ServerFlags -section. -.TP 7 -.BI "Option \*qIsolateDevice\*q \*q" bus\-id \*q -Restrict device resets to the specified -.IR bus\-id . -See the -.B BusID -option (described in -.BR "DEVICE SECTION" , -above) for the format of the -.I bus\-id -parameter. -This option overrides -.BR SingleCard , -if specified. -At present, only PCI devices can be isolated in this manner. -.TP 7 -.BI "Option \*qSingleCard\*q \*q" boolean \*q -As -.BR IsolateDevice , -except that the bus ID of the first device in the layout is used. -.PP -Here is an example of a -.B ServerLayout -section for a dual headed configuration with two mice: -.PP -.RS 4 -.nf -.B "Section \*qServerLayout\*q" -.B " Identifier \*qLayout 1\*q" -.B " Screen \*qMGA 1\*q" -.B " Screen \*qMGA 2\*q RightOf \*qMGA 1\*q" -.B " InputDevice \*qKeyboard 1\*q \*qCoreKeyboard\*q" -.B " InputDevice \*qMouse 1\*q \*qCorePointer\*q" -.B " InputDevice \*qMouse 2\*q \*qSendCoreEvents\*q" -.B " Option \*qBlankTime\*q \*q5\*q" -.B "EndSection" -.fi -.RE -.SH "DRI SECTION" -This optional section is used to provide some information for the -Direct Rendering Infrastructure. -Details about the format of this section can be found on-line at -.IR . -.SH "VENDOR SECTION" -The optional -.B Vendor -section may be used to provide vendor\-specific configuration information. -Multiple -.B Vendor -sections may be present, and they may contain an -.B Identifier -entry and multiple -.B Option -flags. -The data therein is not used in this release. -.PP -.SH "SEE ALSO" -General: -.BR X (@miscmansuffix@), -.BR Xserver (@appmansuffix@), -.BR Xorg (@appmansuffix@), -.BR cvt (@appmansuffix@), -.BR gtf (@appmansuffix@). -.PP -.B "Not all modules or interfaces are available on all platforms." -.PP -Display drivers: -.BR apm (@drivermansuffix@), -.BR ati (@drivermansuffix@), -.BR chips (@drivermansuffix@), -.BR cirrus (@drivermansuffix@), -.BR cyrix (@drivermansuffix@), -.BR fbdev (@drivermansuffix@), -.BR glide (@drivermansuffix@), -.BR glint (@drivermansuffix@), -.BR i128 (@drivermansuffix@), -.BR i740 (@drivermansuffix@), -.BR imstt (@drivermansuffix@), -.BR intel (@drivermansuffix@), -.BR mga (@drivermansuffix@), -.BR neomagic (@drivermansuffix@), -.BR nv (@drivermansuffix@), -.BR openchrome (@drivermansuffix@), -.BR r128 (@drivermansuffix@), -.BR radeon (@drivermansuffix@), -.BR rendition (@drivermansuffix@), -.BR savage (@drivermansuffix@), -.BR s3virge (@drivermansuffix@), -.BR siliconmotion (@drivermansuffix@), -.BR sis (@drivermansuffix@), -.BR sisusb (@drivermansuffix@), -.BR sunbw2 (@drivermansuffix@), -.BR suncg14 (@drivermansuffix@), -.BR suncg3 (@drivermansuffix@), -.BR suncg6 (@drivermansuffix@), -.BR sunffb (@drivermansuffix@), -.BR sunleo (@drivermansuffix@), -.BR suntcx (@drivermansuffix@), -.BR tdfx (@drivermansuffix@), -.\" .BR tga (@drivermansuffix@), -.BR trident (@drivermansuffix@), -.BR tseng (@drivermansuffix@), -.BR vesa (@drivermansuffix@), -.BR vmware (@drivermansuffix@), -.BR voodoo (@drivermansuffix@), -.BR wsfb (@drivermansuffix@), -.BR xgi (@drivermansuffix@), -.BR xgixp (@drivermansuffix@). -.PP -Input drivers: -.BR acecad (@drivermansuffix@), -.BR citron (@drivermansuffix@), -.BR elographics (@drivermansuffix@), -.BR evdev (@drivermansuffix@), -.BR fpit (@drivermansuffix@), -.BR joystick (@drivermansuffix@), -.BR kbd (@drivermansuffix@), -.BR libinput (@drivermansuffix@), -.BR mousedrv (@drivermansuffix@), -.BR mutouch (@drivermansuffix@), -.BR penmount (@drivermansuffix@), -.BR synaptics (@drivermansuffix@), -.BR vmmouse (@drivermansuffix@), -.BR void (@drivermansuffix@), -.BR wacom (@drivermansuffix@). -.PP -Other modules and interfaces: -.BR exa (@drivermansuffix@), -.BR fbdevhw (@drivermansuffix@), -.\" .BR shadowfb (@drivermansuffix@), -.BR v4l (@drivermansuffix@). -.br -.SH AUTHORS -This manual page was largely rewritten by David Dawes -.IR . diff --git a/hw/xfree86/meson.build b/hw/xfree86/meson.build deleted file mode 100644 index 29ea31568..000000000 --- a/hw/xfree86/meson.build +++ /dev/null @@ -1,234 +0,0 @@ -xorg_inc = include_directories( - 'common', - 'ddc', - 'dri2', - 'i2c', - 'int10', - 'loader', - 'modes', - 'os-support', - 'os-support/bus', - 'parser', - 'ramdac', - 'vgahw', -) - -xorg_c_args = [] -xorg_c_args += '-DHAVE_XORG_CONFIG_H' -xorg_c_args += '-DXORG_NO_SDKSYMS' - -pciaccess_dep = [] -if get_option('pciaccess') - pciaccess_dep = dependency('pciaccess', version: '>= 0.12.901') -endif - -# subdirs for convenience libraries statically linked into Xorg -subdir('common') -subdir('ddc') -if build_dri1 - subdir('dri') -endif -if build_dri2 - subdir('dri2') -endif -subdir('i2c') -subdir('loader') -subdir('modes') -subdir('os-support') -subdir('parser') -subdir('ramdac') -subdir('xkb') - -srcs_xorg = [ - '../../mi/miinitext.c', - '../../mi/miinitext.h', -] - -# Extract all the objects so that all symbols get brought into the -# server. This prevents us from needing a global table of all symbols -# that should be exported to Xorg modules, at the expense of all -# symbols being included and public - -xorg_link = [ - libxserver, - libglxvnd, - xorg_common, - xorg_loader, - xorg_ddc, - xorg_xkb, - xorg_i2c, - xorg_modes, - xorg_os_support, - xorg_parser, - xorg_ramdac, - libxserver_fb, - libxserver_xext_vidmode, - libxserver_main, - libxserver_config, -] -if build_dri1 - xorg_link += xorg_dri -endif -if build_dri2 - xorg_link += xorg_dri2 -endif - -if host_machine.system() == 'cygwin' or host_machine.system() == 'windows' - linker_export_flags = '-Wl,--export-all-symbols' -elif host_machine.system() == 'sunos' - linker_export_flags = [] -else - linker_export_flags = '-Wl,--export-dynamic' -endif - -xorg_deps = [ - pixman_dep, - m_dep, - dl_dep, - pciaccess_dep, - sha1_dep, - dependency('xau'), - xdmcp_dep, - xfont2_dep, - xshmfence_dep, - config_dep, - libdrm_dep, -] - -if get_option('suid_wrapper') - xorg_install_dir = get_option('libexecdir') -else - xorg_install_dir = get_option('bindir') -endif - -e = executable( - 'Xorg', - srcs_xorg, - include_directories: [inc, xorg_inc], - link_whole: xorg_link, - dependencies: xorg_deps, - link_args: linker_export_flags, - c_args: xorg_c_args, - install: true, - install_dir: xorg_install_dir, - implib: true, -) - -# subdirs for modules loadable by Xorg -subdir('dixmods') -subdir('exa') -subdir('fbdevhw') -if gbm_dep.found() - subdir('glamor_egl') -endif -if int10 != 'false' - if int10 == 'x86emu' - subdir('x86emu') - endif - subdir('int10') -endif -subdir('shadowfb') -if build_vgahw - subdir('vgahw') -endif -if build_modesetting - subdir('drivers/modesetting') -endif -if get_option('xf86-input-inputtest') - subdir('drivers/inputtest') -endif - -meson.add_install_script( - 'sh', '-c', - 'ln -fs Xorg @0@@1@'.format( - '${DESTDIR}', - join_paths(get_option('prefix'), get_option('bindir'), 'X'))) - -if get_option('suid_wrapper') - executable('Xorg.wrap', - 'xorg-wrapper.c', - include_directories: [inc, xorg_inc], - dependencies: xorg_deps, - c_args: xorg_c_args, - install: true, - install_dir: get_option('libexecdir'), - install_mode: ['r-sr-xr-x', 0, 0], - ) - - # meson gets confused when there are two targets of the same name - # within the same directory, so we use a different intermediate name. - xorg_sh = configure_file( - input: 'Xorg.sh.in', - output: 'Xorg.sh', - configuration: conf_data, - ) - - install_data( - xorg_sh, - install_mode: 'rwxr-xr-x', - install_dir: join_paths(get_option('prefix'), get_option('bindir')), - rename: ['Xorg'] - ) -endif - -executable('gtf', - 'utils/gtf/gtf.c', - include_directories: [inc, xorg_inc], - dependencies: xorg_deps, - c_args: xorg_c_args, - install: true, -) - -# For symbol presence testing only -xorgserver_lib = shared_library( - 'xorgserver', - srcs_xorg, - include_directories: [inc, xorg_inc], - link_whole: xorg_link, - dependencies: xorg_deps, - link_args: linker_export_flags, - c_args: xorg_c_args, - install: false, -) - -xorgserver_dep = declare_dependency(link_with: xorgserver_lib) - -install_man(configure_file( - input: 'man/Xorg.man', - output: 'Xorg.1', - configuration: manpage_config, -)) - -if get_option('suid_wrapper') - install_man(configure_file( - input: 'man/Xorg.wrap.man', - output: 'Xorg.wrap.1', - configuration: manpage_config, - )) - - install_man(configure_file( - input: 'man/Xwrapper.config.man', - output: 'Xwrapper.config.5', - configuration: manpage_config, - )) -endif - -install_man(configure_file( - input: 'man/xorg.conf.man', - output: 'xorg.conf.5', - configuration: manpage_config, -)) - -install_man(configure_file( - input: 'man/xorg.conf.d.man', - output: 'xorg.conf.d.5', - configuration: manpage_config, -)) - -install_man(configure_file( - input: 'utils/man/gtf.man', - output: 'gtf.1', - configuration: manpage_config, -)) - -subdir('doc') diff --git a/hw/xfree86/modes/meson.build b/hw/xfree86/modes/meson.build deleted file mode 100644 index 8a40018ca..000000000 --- a/hw/xfree86/modes/meson.build +++ /dev/null @@ -1,29 +0,0 @@ -srcs_xorg_modes = [ - 'xf86Crtc.c', - 'xf86Cursors.c', - 'xf86gtf.c', - 'xf86EdidModes.c', - 'xf86Modes.c', - 'xf86RandR12.c', - 'xf86Rotate.c', -] - -if build_dga - srcs_xorg_modes += 'xf86DiDGA.c' -endif - -xorg_modes = static_library('xorg_modes', - srcs_xorg_modes, - include_directories: [ inc, xorg_inc ], - dependencies: [ common_dep, libxcvt_dep ], - c_args: xorg_c_args, -) - -install_data( - [ - 'xf86Crtc.h', - 'xf86Modes.h', - 'xf86RandR12.h', - ], - install_dir: xorgsdkdir, -) diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c deleted file mode 100644 index c6e89e66f..000000000 --- a/hw/xfree86/modes/xf86Crtc.c +++ /dev/null @@ -1,3558 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * Copyright © 2008 Red Hat, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include - -#include "xf86.h" -#include "xf86DDC.h" -#include "xf86Crtc.h" -#include "xf86Modes.h" -#include "xf86Priv.h" -#include "xf86RandR12.h" -#include "X11/extensions/render.h" -#include "X11/extensions/dpmsconst.h" -#include "X11/Xatom.h" -#include "picturestr.h" - -#ifdef XV -#include "xf86xv.h" -#endif - -#define NO_OUTPUT_DEFAULT_WIDTH 1024 -#define NO_OUTPUT_DEFAULT_HEIGHT 768 -/* - * Initialize xf86CrtcConfig structure - */ - -int xf86CrtcConfigPrivateIndex = -1; - -void -xf86CrtcConfigInit(ScrnInfoPtr scrn, const xf86CrtcConfigFuncsRec * funcs) -{ - xf86CrtcConfigPtr config; - - if (xf86CrtcConfigPrivateIndex == -1) - xf86CrtcConfigPrivateIndex = xf86AllocateScrnInfoPrivateIndex(); - config = xnfcalloc(1, sizeof(xf86CrtcConfigRec)); - - config->funcs = funcs; - config->compat_output = -1; - - scrn->privates[xf86CrtcConfigPrivateIndex].ptr = config; -} - -void -xf86CrtcSetSizeRange(ScrnInfoPtr scrn, - int minWidth, int minHeight, int maxWidth, int maxHeight) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - - config->minWidth = minWidth; - config->minHeight = minHeight; - config->maxWidth = maxWidth; - config->maxHeight = maxHeight; -} - -/* - * Crtc functions - */ -xf86CrtcPtr -xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CrtcPtr crtc, *crtcs; - - crtc = calloc(sizeof(xf86CrtcRec), 1); - if (!crtc) - return NULL; - crtc->version = XF86_CRTC_VERSION; - crtc->scrn = scrn; - crtc->funcs = funcs; -#ifdef RANDR_12_INTERFACE - crtc->randr_crtc = NULL; -#endif - crtc->rotation = RR_Rotate_0; - crtc->desiredRotation = RR_Rotate_0; - pixman_transform_init_identity(&crtc->crtc_to_framebuffer); - pixman_f_transform_init_identity(&crtc->f_crtc_to_framebuffer); - pixman_f_transform_init_identity(&crtc->f_framebuffer_to_crtc); - crtc->filter = NULL; - crtc->params = NULL; - crtc->nparams = 0; - crtc->filter_width = 0; - crtc->filter_height = 0; - crtc->transform_in_use = FALSE; - crtc->transformPresent = FALSE; - crtc->desiredTransformPresent = FALSE; - memset(&crtc->bounds, '\0', sizeof(crtc->bounds)); - - /* Preallocate gamma at a sensible size. */ - crtc->gamma_size = 256; - crtc->gamma_red = xallocarray(crtc->gamma_size, 3 * sizeof(CARD16)); - if (!crtc->gamma_red) { - free(crtc); - return NULL; - } - crtc->gamma_green = crtc->gamma_red + crtc->gamma_size; - crtc->gamma_blue = crtc->gamma_green + crtc->gamma_size; - - if (xf86_config->crtc) - crtcs = reallocarray(xf86_config->crtc, - xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr)); - else - crtcs = xallocarray(xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr)); - if (!crtcs) { - free(crtc->gamma_red); - free(crtc); - return NULL; - } - xf86_config->crtc = crtcs; - xf86_config->crtc[xf86_config->num_crtc++] = crtc; - return crtc; -} - -void -xf86CrtcDestroy(xf86CrtcPtr crtc) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); - int c; - - (*crtc->funcs->destroy) (crtc); - for (c = 0; c < xf86_config->num_crtc; c++) - if (xf86_config->crtc[c] == crtc) { - memmove(&xf86_config->crtc[c], - &xf86_config->crtc[c + 1], - ((xf86_config->num_crtc - (c + 1)) * sizeof(void *))); - xf86_config->num_crtc--; - break; - } - free(crtc->params); - free(crtc->gamma_red); - free(crtc); -} - -/** - * Return whether any outputs are connected to the specified pipe - */ - -Bool -xf86CrtcInUse(xf86CrtcPtr crtc) -{ - ScrnInfoPtr pScrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int o; - - for (o = 0; o < xf86_config->num_output; o++) - if (xf86_config->output[o]->crtc == crtc) - return TRUE; - return FALSE; -} - -/** - * Return whether the crtc is leased by a client - */ - -static Bool -xf86CrtcIsLeased(xf86CrtcPtr crtc) -{ - /* If the DIX structure hasn't been created, it can't have been leased */ - if (!crtc->randr_crtc) - return FALSE; - return RRCrtcIsLeased(crtc->randr_crtc); -} - -/** - * Return whether the output is leased by a client - */ - -static Bool -xf86OutputIsLeased(xf86OutputPtr output) -{ - /* If the DIX structure hasn't been created, it can't have been leased */ - if (!output->randr_output) - return FALSE; - return RROutputIsLeased(output->randr_output); -} - -void -xf86CrtcSetScreenSubpixelOrder(ScreenPtr pScreen) -{ - int subpixel_order = SubPixelUnknown; - Bool has_none = FALSE; - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int icrtc, o; - - for (icrtc = 0; icrtc < xf86_config->num_crtc; icrtc++) { - xf86CrtcPtr crtc = xf86_config->crtc[icrtc]; - - for (o = 0; o < xf86_config->num_output; o++) { - xf86OutputPtr output = xf86_config->output[o]; - - if (output->crtc == crtc) { - switch (output->subpixel_order) { - case SubPixelNone: - has_none = TRUE; - break; - case SubPixelUnknown: - break; - default: - subpixel_order = output->subpixel_order; - break; - } - } - if (subpixel_order != SubPixelUnknown) - break; - } - if (subpixel_order != SubPixelUnknown) { - static const int circle[4] = { - SubPixelHorizontalRGB, - SubPixelVerticalRGB, - SubPixelHorizontalBGR, - SubPixelVerticalBGR, - }; - int rotate; - int sc; - - for (rotate = 0; rotate < 4; rotate++) - if (crtc->rotation & (1 << rotate)) - break; - for (sc = 0; sc < 4; sc++) - if (circle[sc] == subpixel_order) - break; - sc = (sc + rotate) & 0x3; - if ((crtc->rotation & RR_Reflect_X) && !(sc & 1)) - sc ^= 2; - if ((crtc->rotation & RR_Reflect_Y) && (sc & 1)) - sc ^= 2; - subpixel_order = circle[sc]; - break; - } - } - if (subpixel_order == SubPixelUnknown && has_none) - subpixel_order = SubPixelNone; - PictureSetSubpixelOrder(pScreen, subpixel_order); -} - -/** - * Sets the given video mode on the given crtc - */ -Bool -xf86CrtcSetModeTransform(xf86CrtcPtr crtc, DisplayModePtr mode, - Rotation rotation, RRTransformPtr transform, int x, - int y) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int i; - Bool ret = FALSE; - Bool didLock = FALSE; - DisplayModePtr adjusted_mode; - DisplayModeRec saved_mode; - int saved_x, saved_y; - Rotation saved_rotation; - RRTransformRec saved_transform; - Bool saved_transform_present; - - crtc->enabled = xf86CrtcInUse(crtc) && !xf86CrtcIsLeased(crtc); - - /* We only hit this if someone explicitly sends a "disabled" modeset. */ - if (!crtc->enabled) { - /* Check everything for stuff that should be off. */ - xf86DisableUnusedFunctions(scrn); - return TRUE; - } - - adjusted_mode = xf86DuplicateMode(mode); - - saved_mode = crtc->mode; - saved_x = crtc->x; - saved_y = crtc->y; - saved_rotation = crtc->rotation; - if (crtc->transformPresent) { - RRTransformInit(&saved_transform); - RRTransformCopy(&saved_transform, &crtc->transform); - } - saved_transform_present = crtc->transformPresent; - - /* Update crtc values up front so the driver can rely on them for mode - * setting. - */ - crtc->mode = *mode; - crtc->x = x; - crtc->y = y; - crtc->rotation = rotation; - if (transform) { - RRTransformCopy(&crtc->transform, transform); - crtc->transformPresent = TRUE; - } - else - crtc->transformPresent = FALSE; - - if (crtc->funcs->set_mode_major) { - ret = crtc->funcs->set_mode_major(crtc, mode, rotation, x, y); - goto done; - } - - didLock = crtc->funcs->lock(crtc); - /* Pass our mode to the outputs and the CRTC to give them a chance to - * adjust it according to limitations or output properties, and also - * a chance to reject the mode entirely. - */ - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - - if (output->crtc != crtc) - continue; - - if (!output->funcs->mode_fixup(output, mode, adjusted_mode)) { - goto done; - } - } - - if (!crtc->funcs->mode_fixup(crtc, mode, adjusted_mode)) { - goto done; - } - - if (!xf86CrtcRotate(crtc)) - goto done; - - /* Prepare the outputs and CRTCs before setting the mode. */ - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - - if (output->crtc != crtc) - continue; - - /* Disable the output as the first thing we do. */ - output->funcs->prepare(output); - } - - crtc->funcs->prepare(crtc); - - /* Set up the DPLL and any output state that needs to adjust or depend - * on the DPLL. - */ - crtc->funcs->mode_set(crtc, mode, adjusted_mode, crtc->x, crtc->y); - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - - if (output->crtc == crtc) - output->funcs->mode_set(output, mode, adjusted_mode); - } - - /* Only upload when needed, to avoid unneeded delays. */ - if (!crtc->active && crtc->funcs->gamma_set) - crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green, - crtc->gamma_blue, crtc->gamma_size); - - /* Now, enable the clocks, plane, pipe, and outputs that we set up. */ - crtc->funcs->commit(crtc); - for (i = 0; i < xf86_config->num_output; i++) { - xf86OutputPtr output = xf86_config->output[i]; - - if (output->crtc == crtc) - output->funcs->commit(output); - } - - ret = TRUE; - - done: - if (ret) { - crtc->active = TRUE; - if (scrn->pScreen) - xf86CrtcSetScreenSubpixelOrder(scrn->pScreen); - if (scrn->ModeSet) - scrn->ModeSet(scrn); - - /* Make sure the HW cursor is hidden if it's supposed to be, in case - * it was hidden while the CRTC was disabled - */ - if (!xf86_config->cursor_on) - xf86_hide_cursors(scrn); - } - else { - crtc->x = saved_x; - crtc->y = saved_y; - crtc->rotation = saved_rotation; - crtc->mode = saved_mode; - if (saved_transform_present) - RRTransformCopy(&crtc->transform, &saved_transform); - crtc->transformPresent = saved_transform_present; - } - - free((void *) adjusted_mode->name); - free(adjusted_mode); - - if (didLock) - crtc->funcs->unlock(crtc); - - return ret; -} - -/** - * Sets the given video mode on the given crtc, but without providing - * a transform - */ -Bool -xf86CrtcSetMode(xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, - int x, int y) -{ - return xf86CrtcSetModeTransform(crtc, mode, rotation, NULL, x, y); -} - -/** - * Pans the screen, does not change the mode - */ -void -xf86CrtcSetOrigin(xf86CrtcPtr crtc, int x, int y) -{ - ScrnInfoPtr scrn = crtc->scrn; - - crtc->x = x; - crtc->y = y; - - if (xf86CrtcIsLeased(crtc)) - return; - - if (crtc->funcs->set_origin) { - if (!xf86CrtcRotate(crtc)) - return; - crtc->funcs->set_origin(crtc, x, y); - if (scrn->ModeSet) - scrn->ModeSet(scrn); - } - else - xf86CrtcSetMode(crtc, &crtc->mode, crtc->rotation, x, y); -} - -/* - * Output functions - */ - -extern XF86ConfigPtr xf86configptr; - -typedef enum { - OPTION_PREFERRED_MODE, - OPTION_ZOOM_MODES, - OPTION_POSITION, - OPTION_BELOW, - OPTION_RIGHT_OF, - OPTION_ABOVE, - OPTION_LEFT_OF, - OPTION_ENABLE, - OPTION_DISABLE, - OPTION_MIN_CLOCK, - OPTION_MAX_CLOCK, - OPTION_IGNORE, - OPTION_ROTATE, - OPTION_PANNING, - OPTION_PRIMARY, - OPTION_DEFAULT_MODES, -} OutputOpts; - -static OptionInfoRec xf86OutputOptions[] = { - {OPTION_PREFERRED_MODE, "PreferredMode", OPTV_STRING, {0}, FALSE}, - {OPTION_ZOOM_MODES, "ZoomModes", OPTV_STRING, {0}, FALSE }, - {OPTION_POSITION, "Position", OPTV_STRING, {0}, FALSE}, - {OPTION_BELOW, "Below", OPTV_STRING, {0}, FALSE}, - {OPTION_RIGHT_OF, "RightOf", OPTV_STRING, {0}, FALSE}, - {OPTION_ABOVE, "Above", OPTV_STRING, {0}, FALSE}, - {OPTION_LEFT_OF, "LeftOf", OPTV_STRING, {0}, FALSE}, - {OPTION_ENABLE, "Enable", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_DISABLE, "Disable", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_MIN_CLOCK, "MinClock", OPTV_FREQ, {0}, FALSE}, - {OPTION_MAX_CLOCK, "MaxClock", OPTV_FREQ, {0}, FALSE}, - {OPTION_IGNORE, "Ignore", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_ROTATE, "Rotate", OPTV_STRING, {0}, FALSE}, - {OPTION_PANNING, "Panning", OPTV_STRING, {0}, FALSE}, - {OPTION_PRIMARY, "Primary", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_DEFAULT_MODES, "DefaultModes", OPTV_BOOLEAN, {0}, FALSE}, - {-1, NULL, OPTV_NONE, {0}, FALSE}, -}; - -enum { - OPTION_MODEDEBUG, - OPTION_PREFER_CLONEMODE, - OPTION_NO_OUTPUT_INITIAL_SIZE, -}; - -static OptionInfoRec xf86DeviceOptions[] = { - {OPTION_MODEDEBUG, "ModeDebug", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_PREFER_CLONEMODE, "PreferCloneMode", OPTV_BOOLEAN, {0}, FALSE}, - {OPTION_NO_OUTPUT_INITIAL_SIZE, "NoOutputInitialSize", OPTV_STRING, {0}, FALSE}, - {-1, NULL, OPTV_NONE, {0}, FALSE}, -}; - -static void -xf86OutputSetMonitor(xf86OutputPtr output) -{ - char *option_name; - const char *monitor; - - if (!output->name) - return; - - free(output->options); - - output->options = xnfalloc(sizeof(xf86OutputOptions)); - memcpy(output->options, xf86OutputOptions, sizeof(xf86OutputOptions)); - - XNFasprintf(&option_name, "monitor-%s", output->name); - monitor = xf86findOptionValue(output->scrn->options, option_name); - if (!monitor) - monitor = output->name; - else - xf86MarkOptionUsedByName(output->scrn->options, option_name); - free(option_name); - output->conf_monitor = xf86findMonitor(monitor, - xf86configptr->conf_monitor_lst); - /* - * Find the monitor section of the screen and use that - */ - if (!output->conf_monitor && output->use_screen_monitor) - output->conf_monitor = xf86findMonitor(output->scrn->monitor->id, - xf86configptr->conf_monitor_lst); - if (output->conf_monitor) { - xf86DrvMsg(output->scrn->scrnIndex, X_INFO, - "Output %s using monitor section %s\n", - output->name, output->conf_monitor->mon_identifier); - xf86ProcessOptions(output->scrn->scrnIndex, - output->conf_monitor->mon_option_lst, - output->options); - } - else - xf86DrvMsg(output->scrn->scrnIndex, X_INFO, - "Output %s has no monitor section\n", output->name); -} - -Bool -xf86OutputForceEnabled(xf86OutputPtr output) -{ - Bool enable; - - if (xf86GetOptValBool(output->options, OPTION_ENABLE, &enable) && enable) - return TRUE; - return FALSE; -} - -static Bool -xf86OutputEnabled(xf86OutputPtr output, Bool strict) -{ - Bool enable, disable; - - /* check to see if this output was enabled in the config file */ - if (xf86GetOptValBool(output->options, OPTION_ENABLE, &enable) && enable) { - xf86DrvMsg(output->scrn->scrnIndex, X_INFO, - "Output %s enabled by config file\n", output->name); - return TRUE; - } - /* or if this output was disabled in the config file */ - if (xf86GetOptValBool(output->options, OPTION_DISABLE, &disable) && disable) { - xf86DrvMsg(output->scrn->scrnIndex, X_INFO, - "Output %s disabled by config file\n", output->name); - return FALSE; - } - - /* If not, try to only light up the ones we know are connected which are supposed to be on the desktop */ - if (strict) { - enable = output->status == XF86OutputStatusConnected && !output->non_desktop; - } - /* But if that fails, try to light up even outputs we're unsure of */ - else { - enable = output->status != XF86OutputStatusDisconnected; - } - - xf86DrvMsg(output->scrn->scrnIndex, X_INFO, - "Output %s %sconnected\n", output->name, enable ? "" : "dis"); - return enable; -} - -static Bool -xf86OutputIgnored(xf86OutputPtr output) -{ - return xf86ReturnOptValBool(output->options, OPTION_IGNORE, FALSE); -} - -static const char *direction[4] = { - "normal", - "left", - "inverted", - "right" -}; - -static Rotation -xf86OutputInitialRotation(xf86OutputPtr output) -{ - const char *rotate_name = xf86GetOptValString(output->options, - OPTION_ROTATE); - int i; - - if (!rotate_name) { - if (output->initial_rotation) - return output->initial_rotation; - return RR_Rotate_0; - } - - for (i = 0; i < 4; i++) - if (xf86nameCompare(direction[i], rotate_name) == 0) - return 1 << i; - return RR_Rotate_0; -} - -xf86OutputPtr -xf86OutputCreate(ScrnInfoPtr scrn, - const xf86OutputFuncsRec * funcs, const char *name) -{ - xf86OutputPtr output, *outputs; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int len; - Bool primary; - - if (name) - len = strlen(name) + 1; - else - len = 0; - - output = calloc(sizeof(xf86OutputRec) + len, 1); - if (!output) - return NULL; - output->scrn = scrn; - output->funcs = funcs; - if (name) { - output->name = (char *) (output + 1); - strcpy(output->name, name); - } - output->subpixel_order = SubPixelUnknown; - /* - * Use the old per-screen monitor section for the first output - */ - output->use_screen_monitor = (xf86_config->num_output == 0); -#ifdef RANDR_12_INTERFACE - output->randr_output = NULL; -#endif - if (name) { - xf86OutputSetMonitor(output); - if (xf86OutputIgnored(output)) { - free(output); - return FALSE; - } - } - - if (xf86_config->output) - outputs = reallocarray(xf86_config->output, - xf86_config->num_output + 1, - sizeof(xf86OutputPtr)); - else - outputs = xallocarray(xf86_config->num_output + 1, - sizeof(xf86OutputPtr)); - if (!outputs) { - free(output); - return NULL; - } - - xf86_config->output = outputs; - - if (xf86GetOptValBool(output->options, OPTION_PRIMARY, &primary) && primary) { - memmove(xf86_config->output + 1, xf86_config->output, - xf86_config->num_output * sizeof(xf86OutputPtr)); - xf86_config->output[0] = output; - } - else { - xf86_config->output[xf86_config->num_output] = output; - } - - xf86_config->num_output++; - - return output; -} - -Bool -xf86OutputRename(xf86OutputPtr output, const char *name) -{ - char *newname = strdup(name); - - if (!newname) - return FALSE; /* so sorry... */ - - if (output->name && output->name != (char *) (output + 1)) - free(output->name); - output->name = newname; - xf86OutputSetMonitor(output); - if (xf86OutputIgnored(output)) - return FALSE; - return TRUE; -} - -void -xf86OutputUseScreenMonitor(xf86OutputPtr output, Bool use_screen_monitor) -{ - if (use_screen_monitor != output->use_screen_monitor) { - output->use_screen_monitor = use_screen_monitor; - xf86OutputSetMonitor(output); - } -} - -void -xf86OutputDestroy(xf86OutputPtr output) -{ - ScrnInfoPtr scrn = output->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int o; - - (*output->funcs->destroy) (output); - while (output->probed_modes) - xf86DeleteMode(&output->probed_modes, output->probed_modes); - for (o = 0; o < xf86_config->num_output; o++) - if (xf86_config->output[o] == output) { - memmove(&xf86_config->output[o], - &xf86_config->output[o + 1], - ((xf86_config->num_output - (o + 1)) * sizeof(void *))); - xf86_config->num_output--; - break; - } - if (output->name && output->name != (char *) (output + 1)) - free(output->name); - free(output); -} - -/* - * Called during CreateScreenResources to hook up RandR - */ -static Bool -xf86CrtcCreateScreenResources(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - - screen->CreateScreenResources = config->CreateScreenResources; - - if (!(*screen->CreateScreenResources) (screen)) - return FALSE; - - if (!xf86RandR12CreateScreenResources(screen)) - return FALSE; - - return TRUE; -} - -/* - * Clean up config on server reset - */ -static Bool -xf86CrtcCloseScreen(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int o, c; - - /* The randr_output and randr_crtc pointers are already invalid as - * the DIX resources were freed when the associated resources were - * freed. Clear them now; referencing through them during the rest - * of the CloseScreen sequence will not end well. - */ - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - output->randr_output = NULL; - } - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - crtc->randr_crtc = NULL; - } - - screen->CloseScreen = config->CloseScreen; - - xf86RotateCloseScreen(screen); - - xf86RandR12CloseScreen(screen); - - screen->CloseScreen(screen); - - /* detach any providers */ - if (config->randr_provider) { - RRProviderDestroy(config->randr_provider); - config->randr_provider = NULL; - } - return TRUE; -} - -/* - * Called at ScreenInit time to set up - */ -#ifdef RANDR_13_INTERFACE -int -#else -Bool -#endif -xf86CrtcScreenInit(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - /* Rotation */ - xf86RandR12Init(screen); - - /* support all rotations if every crtc has the shadow alloc funcs */ - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - if (!crtc->funcs->shadow_allocate || !crtc->funcs->shadow_create) - break; - } - if (c == config->num_crtc) { - xf86RandR12SetRotations(screen, RR_Rotate_0 | RR_Rotate_90 | - RR_Rotate_180 | RR_Rotate_270 | - RR_Reflect_X | RR_Reflect_Y); - xf86RandR12SetTransformSupport(screen, TRUE); - } - else { - xf86RandR12SetRotations(screen, RR_Rotate_0); - xf86RandR12SetTransformSupport(screen, FALSE); - } - - /* Wrap CreateScreenResources so we can initialize the RandR code */ - config->CreateScreenResources = screen->CreateScreenResources; - screen->CreateScreenResources = xf86CrtcCreateScreenResources; - - config->CloseScreen = screen->CloseScreen; - screen->CloseScreen = xf86CrtcCloseScreen; - - /* This might still be marked wrapped from a previous generation */ - config->BlockHandler = NULL; - -#ifdef XFreeXDGA - _xf86_di_dga_init_internal(screen); -#endif -#ifdef RANDR_13_INTERFACE - return RANDR_INTERFACE_VERSION; -#else - return TRUE; -#endif -} - -static DisplayModePtr -xf86DefaultMode(xf86OutputPtr output, int width, int height) -{ - DisplayModePtr target_mode = NULL; - DisplayModePtr mode; - int target_diff = 0; - int target_preferred = 0; - int mm_height; - - mm_height = output->mm_height; - if (!mm_height) - mm_height = (768 * 25.4) / DEFAULT_DPI; - /* - * Pick a mode closest to DEFAULT_DPI - */ - for (mode = output->probed_modes; mode; mode = mode->next) { - int dpi; - int preferred = (((mode->type & M_T_PREFERRED) != 0) + - ((mode->type & M_T_USERPREF) != 0)); - int diff; - - if (xf86ModeWidth(mode, output->initial_rotation) > width || - xf86ModeHeight(mode, output->initial_rotation) > height) - continue; - - /* yes, use VDisplay here, not xf86ModeHeight */ - dpi = (mode->VDisplay * 254) / (mm_height * 10); - diff = dpi - DEFAULT_DPI; - diff = diff < 0 ? -diff : diff; - if (target_mode == NULL || (preferred > target_preferred) || - (preferred == target_preferred && diff < target_diff)) { - target_mode = mode; - target_diff = diff; - target_preferred = preferred; - } - } - return target_mode; -} - -static DisplayModePtr -xf86ClosestMode(xf86OutputPtr output, - DisplayModePtr match, Rotation match_rotation, - int width, int height) -{ - DisplayModePtr target_mode = NULL; - DisplayModePtr mode; - int target_diff = 0; - - /* - * Pick a mode closest to the specified mode - */ - for (mode = output->probed_modes; mode; mode = mode->next) { - int dx, dy; - int diff; - - if (xf86ModeWidth(mode, output->initial_rotation) > width || - xf86ModeHeight(mode, output->initial_rotation) > height) - continue; - - /* exact matches are preferred */ - if (output->initial_rotation == match_rotation && - xf86ModesEqual(mode, match)) - return mode; - - dx = xf86ModeWidth(match, match_rotation) - xf86ModeWidth(mode, - output-> - initial_rotation); - dy = xf86ModeHeight(match, match_rotation) - xf86ModeHeight(mode, - output-> - initial_rotation); - diff = dx * dx + dy * dy; - if (target_mode == NULL || diff < target_diff) { - target_mode = mode; - target_diff = diff; - } - } - return target_mode; -} - -static DisplayModePtr -xf86OutputHasPreferredMode(xf86OutputPtr output, int width, int height) -{ - DisplayModePtr mode; - - for (mode = output->probed_modes; mode; mode = mode->next) { - if (xf86ModeWidth(mode, output->initial_rotation) > width || - xf86ModeHeight(mode, output->initial_rotation) > height) - continue; - - if (mode->type & M_T_PREFERRED) - return mode; - } - return NULL; -} - -static DisplayModePtr -xf86OutputHasUserPreferredMode(xf86OutputPtr output) -{ - DisplayModePtr mode, first = output->probed_modes; - - for (mode = first; mode && mode->next != first; mode = mode->next) - if (mode->type & M_T_USERPREF) - return mode; - - return NULL; -} - -static int -xf86PickCrtcs(ScrnInfoPtr scrn, - xf86CrtcPtr * best_crtcs, - DisplayModePtr * modes, int n, int width, int height) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int c, o; - xf86OutputPtr output; - xf86CrtcPtr crtc; - xf86CrtcPtr *crtcs; - int best_score; - int score; - int my_score; - - if (n == config->num_output) - return 0; - output = config->output[n]; - - /* - * Compute score with this output disabled - */ - best_crtcs[n] = NULL; - best_score = xf86PickCrtcs(scrn, best_crtcs, modes, n + 1, width, height); - if (modes[n] == NULL) - return best_score; - - crtcs = xallocarray(config->num_output, sizeof(xf86CrtcPtr)); - if (!crtcs) - return best_score; - - my_score = 1; - /* Score outputs that are known to be connected higher */ - if (output->status == XF86OutputStatusConnected) - my_score++; - /* Score outputs with preferred modes higher */ - if (xf86OutputHasPreferredMode(output, width, height)) - my_score++; - /* - * Select a crtc for this output and - * then attempt to configure the remaining - * outputs - */ - for (c = 0; c < config->num_crtc; c++) { - if ((output->possible_crtcs & (1 << c)) == 0) - continue; - - crtc = config->crtc[c]; - /* - * Check to see if some other output is - * using this crtc - */ - for (o = 0; o < n; o++) - if (best_crtcs[o] == crtc) - break; - if (o < n) { - /* - * If the two outputs desire the same mode, - * see if they can be cloned - */ - if (xf86ModesEqual(modes[o], modes[n]) && - config->output[o]->initial_rotation == - config->output[n]->initial_rotation && - config->output[o]->initial_x == config->output[n]->initial_x && - config->output[o]->initial_y == config->output[n]->initial_y) { - if ((output->possible_clones & (1 << o)) == 0) - continue; /* nope, try next CRTC */ - } - else - continue; /* different modes, can't clone */ - } - crtcs[n] = crtc; - memcpy(crtcs, best_crtcs, n * sizeof(xf86CrtcPtr)); - score = - my_score + xf86PickCrtcs(scrn, crtcs, modes, n + 1, width, height); - if (score > best_score) { - best_score = score; - memcpy(best_crtcs, crtcs, config->num_output * sizeof(xf86CrtcPtr)); - } - } - free(crtcs); - return best_score; -} - -/* - * Compute the virtual size necessary to place all of the available - * crtcs in the specified configuration. - * - * canGrow indicates that the driver can make the screen larger than its initial - * configuration. If FALSE, this function will enlarge the screen to include - * the largest available mode. - */ - -static void -xf86DefaultScreenLimits(ScrnInfoPtr scrn, int *widthp, int *heightp, - Bool canGrow) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int width = 0, height = 0; - int o; - int c; - int s; - - for (c = 0; c < config->num_crtc; c++) { - int crtc_width = 0, crtc_height = 0; - xf86CrtcPtr crtc = config->crtc[c]; - - if (crtc->enabled) { - crtc_width = - crtc->desiredX + xf86ModeWidth(&crtc->desiredMode, - crtc->desiredRotation); - crtc_height = - crtc->desiredY + xf86ModeHeight(&crtc->desiredMode, - crtc->desiredRotation); - } - if (!canGrow) { - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - for (s = 0; s < config->num_crtc; s++) - if (output->possible_crtcs & (1 << s)) { - DisplayModePtr mode; - - for (mode = output->probed_modes; mode; - mode = mode->next) { - if (mode->HDisplay > crtc_width) - crtc_width = mode->HDisplay; - if (mode->VDisplay > crtc_width) - crtc_width = mode->VDisplay; - if (mode->VDisplay > crtc_height) - crtc_height = mode->VDisplay; - if (mode->HDisplay > crtc_height) - crtc_height = mode->HDisplay; - } - } - } - } - if (crtc_width > width) - width = crtc_width; - if (crtc_height > height) - height = crtc_height; - } - if (config->maxWidth && width > config->maxWidth) - width = config->maxWidth; - if (config->maxHeight && height > config->maxHeight) - height = config->maxHeight; - if (config->minWidth && width < config->minWidth) - width = config->minWidth; - if (config->minHeight && height < config->minHeight) - height = config->minHeight; - *widthp = width; - *heightp = height; -} - -#define POSITION_UNSET -100000 - -/* - * check if the user configured any outputs at all - * with either a position or a relative setting or a mode. - */ -static Bool -xf86UserConfiguredOutputs(ScrnInfoPtr scrn, DisplayModePtr * modes) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int o; - Bool user_conf = FALSE; - - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - const char *position; - const char *relative_name; - OutputOpts relation; - int r; - - static const OutputOpts relations[] = { - OPTION_BELOW, OPTION_RIGHT_OF, OPTION_ABOVE, OPTION_LEFT_OF - }; - - position = xf86GetOptValString(output->options, OPTION_POSITION); - if (position) - user_conf = TRUE; - - relation = 0; - relative_name = NULL; - for (r = 0; r < 4; r++) { - relation = relations[r]; - relative_name = xf86GetOptValString(output->options, relation); - if (relative_name) - break; - } - if (relative_name) - user_conf = TRUE; - - modes[o] = xf86OutputHasUserPreferredMode(output); - if (modes[o]) - user_conf = TRUE; - } - - return user_conf; -} - -static Bool -xf86InitialOutputPositions(ScrnInfoPtr scrn, DisplayModePtr * modes) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int o; - int min_x, min_y; - - /* check for initial right-of heuristic */ - for (o = 0; o < config->num_output; o++) - { - xf86OutputPtr output = config->output[o]; - - if (output->initial_x || output->initial_y) - return TRUE; - } - - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - output->initial_x = output->initial_y = POSITION_UNSET; - } - - /* - * Loop until all outputs are set - */ - for (;;) { - Bool any_set = FALSE; - Bool keep_going = FALSE; - - for (o = 0; o < config->num_output; o++) { - static const OutputOpts relations[] = { - OPTION_BELOW, OPTION_RIGHT_OF, OPTION_ABOVE, OPTION_LEFT_OF - }; - xf86OutputPtr output = config->output[o]; - xf86OutputPtr relative; - const char *relative_name; - const char *position; - OutputOpts relation; - int r; - - if (output->initial_x != POSITION_UNSET) - continue; - position = xf86GetOptValString(output->options, OPTION_POSITION); - /* - * Absolute position wins - */ - if (position) { - int x, y; - - if (sscanf(position, "%d %d", &x, &y) == 2) { - output->initial_x = x; - output->initial_y = y; - } - else { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Output %s position not of form \"x y\"\n", - output->name); - output->initial_x = output->initial_y = 0; - } - any_set = TRUE; - continue; - } - /* - * Next comes relative positions - */ - relation = 0; - relative_name = NULL; - for (r = 0; r < 4; r++) { - relation = relations[r]; - relative_name = xf86GetOptValString(output->options, relation); - if (relative_name) - break; - } - if (relative_name) { - int or; - - relative = NULL; - for (or = 0; or < config->num_output; or++) { - xf86OutputPtr out_rel = config->output[or]; - XF86ConfMonitorPtr rel_mon = out_rel->conf_monitor; - - if (rel_mon) { - if (xf86nameCompare(rel_mon->mon_identifier, - relative_name) == 0) { - relative = config->output[or]; - break; - } - } - if (strcmp(out_rel->name, relative_name) == 0) { - relative = config->output[or]; - break; - } - } - if (!relative) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Cannot position output %s relative to unknown output %s\n", - output->name, relative_name); - output->initial_x = 0; - output->initial_y = 0; - any_set = TRUE; - continue; - } - if (!modes[or]) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Cannot position output %s relative to output %s without modes\n", - output->name, relative_name); - output->initial_x = 0; - output->initial_y = 0; - any_set = TRUE; - continue; - } - if (relative->initial_x == POSITION_UNSET) { - keep_going = TRUE; - continue; - } - output->initial_x = relative->initial_x; - output->initial_y = relative->initial_y; - switch (relation) { - case OPTION_BELOW: - output->initial_y += - xf86ModeHeight(modes[or], relative->initial_rotation); - break; - case OPTION_RIGHT_OF: - output->initial_x += - xf86ModeWidth(modes[or], relative->initial_rotation); - break; - case OPTION_ABOVE: - if (modes[o]) - output->initial_y -= - xf86ModeHeight(modes[o], output->initial_rotation); - break; - case OPTION_LEFT_OF: - if (modes[o]) - output->initial_x -= - xf86ModeWidth(modes[o], output->initial_rotation); - break; - default: - break; - } - any_set = TRUE; - continue; - } - - /* Nothing set, just stick them at 0,0 */ - output->initial_x = 0; - output->initial_y = 0; - any_set = TRUE; - } - if (!keep_going) - break; - if (!any_set) { - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - if (output->initial_x == POSITION_UNSET) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Output position loop. Moving %s to 0,0\n", - output->name); - output->initial_x = output->initial_y = 0; - break; - } - } - } - } - - /* - * normalize positions - */ - min_x = 1000000; - min_y = 1000000; - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - if (output->initial_x < min_x) - min_x = output->initial_x; - if (output->initial_y < min_y) - min_y = output->initial_y; - } - - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - output->initial_x -= min_x; - output->initial_y -= min_y; - } - return TRUE; -} - -static void -xf86InitialPanning(ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int o; - - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - const char *panning = xf86GetOptValString(output->options, OPTION_PANNING); - int width, height, left, top; - int track_width, track_height, track_left, track_top; - int brdr[4]; - - memset(&output->initialTotalArea, 0, sizeof(BoxRec)); - memset(&output->initialTrackingArea, 0, sizeof(BoxRec)); - memset(output->initialBorder, 0, 4 * sizeof(INT16)); - - if (!panning) - continue; - - switch (sscanf(panning, "%dx%d+%d+%d/%dx%d+%d+%d/%d/%d/%d/%d", - &width, &height, &left, &top, - &track_width, &track_height, &track_left, &track_top, - &brdr[0], &brdr[1], &brdr[2], &brdr[3])) { - case 12: - output->initialBorder[0] = brdr[0]; - output->initialBorder[1] = brdr[1]; - output->initialBorder[2] = brdr[2]; - output->initialBorder[3] = brdr[3]; - /* fall through */ - case 8: - output->initialTrackingArea.x1 = track_left; - output->initialTrackingArea.y1 = track_top; - output->initialTrackingArea.x2 = track_left + track_width; - output->initialTrackingArea.y2 = track_top + track_height; - /* fall through */ - case 4: - output->initialTotalArea.x1 = left; - output->initialTotalArea.y1 = top; - /* fall through */ - case 2: - output->initialTotalArea.x2 = output->initialTotalArea.x1 + width; - output->initialTotalArea.y2 = output->initialTotalArea.y1 + height; - break; - default: - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Broken panning specification '%s' for output %s in config file\n", - panning, output->name); - } - } -} - -/** Return - 0 + if a should be earlier, same or later than b in list - */ -static int -xf86ModeCompare(DisplayModePtr a, DisplayModePtr b) -{ - int diff; - - diff = ((b->type & M_T_PREFERRED) != 0) - ((a->type & M_T_PREFERRED) != 0); - if (diff) - return diff; - diff = b->HDisplay * b->VDisplay - a->HDisplay * a->VDisplay; - if (diff) - return diff; - diff = b->Clock - a->Clock; - return diff; -} - -/** - * Insertion sort input in-place and return the resulting head - */ -static DisplayModePtr -xf86SortModes(DisplayModePtr input) -{ - DisplayModePtr output = NULL, i, o, n, *op, prev; - - /* sort by preferred status and pixel area */ - while (input) { - i = input; - input = input->next; - for (op = &output; (o = *op); op = &o->next) - if (xf86ModeCompare(o, i) > 0) - break; - i->next = *op; - *op = i; - } - /* prune identical modes */ - for (o = output; o && (n = o->next); o = n) { - if (!strcmp(o->name, n->name) && xf86ModesEqual(o, n)) { - o->next = n->next; - free((void *) n->name); - free(n); - n = o; - } - } - /* hook up backward links */ - prev = NULL; - for (o = output; o; o = o->next) { - o->prev = prev; - prev = o; - } - return output; -} - -static const char * -preferredMode(ScrnInfoPtr pScrn, xf86OutputPtr output) -{ - const char *preferred_mode = NULL; - - /* Check for a configured preference for a particular mode */ - preferred_mode = xf86GetOptValString(output->options, - OPTION_PREFERRED_MODE); - if (preferred_mode) - return preferred_mode; - - if (pScrn->display->modes && *pScrn->display->modes) - preferred_mode = *pScrn->display->modes; - - return preferred_mode; -} - -/** identify a token - * args - * *src a string with zero or more tokens, e.g. "tok0 tok1", - * **token stores a pointer to the first token character, - * *len stores the token length. - * return - * a pointer into src[] at the token terminating character, or - * NULL if no token is found. - */ -static const char * -gettoken(const char *src, const char **token, int *len) -{ - const char *delim = " \t"; - int skip; - - if (!src) - return NULL; - - skip = strspn(src, delim); - *token = &src[skip]; - - *len = strcspn(*token, delim); - /* Support for backslash escaped delimiters could be implemented - * here. - */ - - /* (*token)[0] != '\0' <==> *len > 0 */ - if (*len > 0) - return &(*token)[*len]; - else - return NULL; -} - -/** Check for a user configured zoom mode list, Option "ZoomModes": - * - * Section "Monitor" - * Identifier "a21inch" - * Option "ZoomModes" "1600x1200 1280x1024 1280x1024 640x480" - * EndSection - * - * Each user mode name is searched for independently so the list - * specification order is free. An output mode is matched at most - * once, a mode with an already set M_T_USERDEF type bit is skipped. - * Thus a repeat mode name specification matches the next output mode - * with the same name. - * - * Ctrl+Alt+Keypad-{Plus,Minus} zooms {in,out} by selecting the - * {next,previous} M_T_USERDEF mode in the screen modes list, itself - * sorted toward lower dot area or lower dot clock frequency, see - * modes/xf86Crtc.c: xf86SortModes() xf86SetScrnInfoModes(), and - * common/xf86Cursor.c: xf86ZoomViewport(). - */ -static int -processZoomModes(xf86OutputPtr output) -{ - const char *zoom_modes; - int count = 0; - - zoom_modes = xf86GetOptValString(output->options, OPTION_ZOOM_MODES); - - if (zoom_modes) { - const char *token, *next; - int len; - - next = gettoken(zoom_modes, &token, &len); - while (next) { - DisplayModePtr mode; - - for (mode = output->probed_modes; mode; mode = mode->next) - if (!strncmp(token, mode->name, len) /* prefix match */ - && mode->name[len] == '\0' /* equal length */ - && !(mode->type & M_T_USERDEF)) { /* no rematch */ - mode->type |= M_T_USERDEF; - break; - } - - count++; - next = gettoken(next, &token, &len); - } - } - - return count; -} - -static void -GuessRangeFromModes(MonPtr mon, DisplayModePtr mode) -{ - if (!mon || !mode) - return; - - mon->nHsync = 1; - mon->hsync[0].lo = 1024.0; - mon->hsync[0].hi = 0.0; - - mon->nVrefresh = 1; - mon->vrefresh[0].lo = 1024.0; - mon->vrefresh[0].hi = 0.0; - - while (mode) { - if (!mode->HSync) - mode->HSync = ((float) mode->Clock) / ((float) mode->HTotal); - - if (!mode->VRefresh) - mode->VRefresh = (1000.0 * ((float) mode->Clock)) / - ((float) (mode->HTotal * mode->VTotal)); - - if (mode->HSync < mon->hsync[0].lo) - mon->hsync[0].lo = mode->HSync; - - if (mode->HSync > mon->hsync[0].hi) - mon->hsync[0].hi = mode->HSync; - - if (mode->VRefresh < mon->vrefresh[0].lo) - mon->vrefresh[0].lo = mode->VRefresh; - - if (mode->VRefresh > mon->vrefresh[0].hi) - mon->vrefresh[0].hi = mode->VRefresh; - - mode = mode->next; - } - - /* stretch out the bottom to fit 640x480@60 */ - if (mon->hsync[0].lo > 31.0) - mon->hsync[0].lo = 31.0; - if (mon->vrefresh[0].lo > 58.0) - mon->vrefresh[0].lo = 58.0; -} - -enum det_monrec_source { - sync_config, sync_edid, sync_default -}; - -struct det_monrec_parameter { - MonRec *mon_rec; - int *max_clock; - Bool set_hsync; - Bool set_vrefresh; - enum det_monrec_source *sync_source; -}; - -static void -handle_detailed_monrec(struct detailed_monitor_section *det_mon, void *data) -{ - struct det_monrec_parameter *p; - - p = (struct det_monrec_parameter *) data; - - if (det_mon->type == DS_RANGES) { - struct monitor_ranges *ranges = &det_mon->section.ranges; - - if (p->set_hsync && ranges->max_h) { - p->mon_rec->hsync[p->mon_rec->nHsync].lo = ranges->min_h; - p->mon_rec->hsync[p->mon_rec->nHsync].hi = ranges->max_h; - p->mon_rec->nHsync++; - if (*p->sync_source == sync_default) - *p->sync_source = sync_edid; - } - if (p->set_vrefresh && ranges->max_v) { - p->mon_rec->vrefresh[p->mon_rec->nVrefresh].lo = ranges->min_v; - p->mon_rec->vrefresh[p->mon_rec->nVrefresh].hi = ranges->max_v; - p->mon_rec->nVrefresh++; - if (*p->sync_source == sync_default) - *p->sync_source = sync_edid; - } - if (ranges->max_clock * 1000 > *p->max_clock) - *p->max_clock = ranges->max_clock * 1000; - } -} - -void -xf86ProbeOutputModes(ScrnInfoPtr scrn, int maxX, int maxY) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int o; - - /* When canGrow was TRUE in the initial configuration we have to - * compare against the maximum values so that we don't drop modes. - * When canGrow was FALSE, the maximum values would have been clamped - * anyway. - */ - if (maxX == 0 || maxY == 0) { - maxX = config->maxWidth; - maxY = config->maxHeight; - } - - /* Probe the list of modes for each output. */ - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - DisplayModePtr mode; - DisplayModePtr config_modes = NULL, output_modes, default_modes = NULL; - const char *preferred_mode; - xf86MonPtr edid_monitor; - XF86ConfMonitorPtr conf_monitor; - MonRec mon_rec; - int min_clock = 0; - int max_clock = 0; - double clock; - Bool add_default_modes; - Bool debug_modes = config->debug_modes || xf86Initialising; - enum det_monrec_source sync_source = sync_default; - - while (output->probed_modes != NULL) - xf86DeleteMode(&output->probed_modes, output->probed_modes); - - /* - * Check connection status - */ - output->status = (*output->funcs->detect) (output); - - if (output->status == XF86OutputStatusDisconnected && - !xf86ReturnOptValBool(output->options, OPTION_ENABLE, FALSE)) { - xf86OutputSetEDID(output, NULL); - continue; - } - - memset(&mon_rec, '\0', sizeof(mon_rec)); - - conf_monitor = output->conf_monitor; - - if (conf_monitor) { - int i; - - for (i = 0; i < conf_monitor->mon_n_hsync; i++) { - mon_rec.hsync[mon_rec.nHsync].lo = - conf_monitor->mon_hsync[i].lo; - mon_rec.hsync[mon_rec.nHsync].hi = - conf_monitor->mon_hsync[i].hi; - mon_rec.nHsync++; - sync_source = sync_config; - } - for (i = 0; i < conf_monitor->mon_n_vrefresh; i++) { - mon_rec.vrefresh[mon_rec.nVrefresh].lo = - conf_monitor->mon_vrefresh[i].lo; - mon_rec.vrefresh[mon_rec.nVrefresh].hi = - conf_monitor->mon_vrefresh[i].hi; - mon_rec.nVrefresh++; - sync_source = sync_config; - } - config_modes = xf86GetMonitorModes(scrn, conf_monitor); - } - - output_modes = (*output->funcs->get_modes) (output); - - /* - * If the user has a preference, respect it. - * Otherwise, don't second-guess the driver. - */ - if (!xf86GetOptValBool(output->options, OPTION_DEFAULT_MODES, - &add_default_modes)) - add_default_modes = (output_modes == NULL); - - edid_monitor = output->MonInfo; - - if (edid_monitor) { - struct det_monrec_parameter p; - struct cea_data_block *hdmi_db; - - /* if display is not continuous-frequency, don't add default modes */ - if (!gtf_supported(edid_monitor)) - add_default_modes = FALSE; - - p.mon_rec = &mon_rec; - p.max_clock = &max_clock; - p.set_hsync = mon_rec.nHsync == 0; - p.set_vrefresh = mon_rec.nVrefresh == 0; - p.sync_source = &sync_source; - - xf86ForEachDetailedBlock(edid_monitor, handle_detailed_monrec, &p); - - /* Look at the CEA HDMI vendor block for the max TMDS freq */ - hdmi_db = xf86MonitorFindHDMIBlock(edid_monitor); - if (hdmi_db && hdmi_db->len >= 7) { - int tmds_freq = hdmi_db->u.vendor.hdmi.max_tmds_clock * 5000; - xf86DrvMsg(scrn->scrnIndex, X_PROBED, - "HDMI max TMDS frequency %dKHz\n", tmds_freq); - if (tmds_freq > max_clock) - max_clock = tmds_freq; - } - } - - if (xf86GetOptValFreq(output->options, OPTION_MIN_CLOCK, - OPTUNITS_KHZ, &clock)) - min_clock = (int) clock; - if (xf86GetOptValFreq(output->options, OPTION_MAX_CLOCK, - OPTUNITS_KHZ, &clock)) - max_clock = (int) clock; - - /* If we still don't have a sync range, guess wildly */ - if (!mon_rec.nHsync || !mon_rec.nVrefresh) - GuessRangeFromModes(&mon_rec, output_modes); - - /* - * These limits will end up setting a 1024x768@60Hz mode by default, - * which seems like a fairly good mode to use when nothing else is - * specified - */ - if (mon_rec.nHsync == 0) { - mon_rec.hsync[0].lo = 31.0; - mon_rec.hsync[0].hi = 55.0; - mon_rec.nHsync = 1; - } - if (mon_rec.nVrefresh == 0) { - mon_rec.vrefresh[0].lo = 58.0; - mon_rec.vrefresh[0].hi = 62.0; - mon_rec.nVrefresh = 1; - } - - if (add_default_modes) - default_modes = xf86GetDefaultModes(); - - /* - * If this is not an RB monitor, remove RB modes from the default - * pool. RB modes from the config or the monitor itself are fine. - */ - if (!mon_rec.reducedblanking) - xf86ValidateModesReducedBlanking(scrn, default_modes); - - if (sync_source == sync_config) { - /* - * Check output and config modes against sync range from config file - */ - xf86ValidateModesSync(scrn, output_modes, &mon_rec); - xf86ValidateModesSync(scrn, config_modes, &mon_rec); - } - /* - * Check default modes against sync range - */ - xf86ValidateModesSync(scrn, default_modes, &mon_rec); - /* - * Check default modes against monitor max clock - */ - if (max_clock) { - xf86ValidateModesClocks(scrn, default_modes, - &min_clock, &max_clock, 1); - xf86ValidateModesClocks(scrn, output_modes, - &min_clock, &max_clock, 1); - } - - output->probed_modes = NULL; - output->probed_modes = xf86ModesAdd(output->probed_modes, config_modes); - output->probed_modes = xf86ModesAdd(output->probed_modes, output_modes); - output->probed_modes = - xf86ModesAdd(output->probed_modes, default_modes); - - /* - * Check all modes against max size, interlace, and doublescan - */ - if (maxX && maxY) - xf86ValidateModesSize(scrn, output->probed_modes, maxX, maxY, 0); - - { - int flags = (output->interlaceAllowed ? V_INTERLACE : 0) | - (output->doubleScanAllowed ? V_DBLSCAN : 0); - xf86ValidateModesFlags(scrn, output->probed_modes, flags); - } - - /* - * Check all modes against output - */ - for (mode = output->probed_modes; mode != NULL; mode = mode->next) - if (mode->status == MODE_OK) - mode->status = (*output->funcs->mode_valid) (output, mode); - - xf86PruneInvalidModes(scrn, &output->probed_modes, debug_modes); - - output->probed_modes = xf86SortModes(output->probed_modes); - - /* Check for a configured preference for a particular mode */ - preferred_mode = preferredMode(scrn, output); - - if (preferred_mode) { - for (mode = output->probed_modes; mode; mode = mode->next) { - if (!strcmp(preferred_mode, mode->name)) { - if (mode != output->probed_modes) { - if (mode->prev) - mode->prev->next = mode->next; - if (mode->next) - mode->next->prev = mode->prev; - mode->next = output->probed_modes; - output->probed_modes->prev = mode; - mode->prev = NULL; - output->probed_modes = mode; - } - mode->type |= (M_T_PREFERRED | M_T_USERPREF); - break; - } - } - } - - /* Ctrl+Alt+Keypad-{Plus,Minus} zoom mode: M_T_USERDEF mode type */ - processZoomModes(output); - - output->initial_rotation = xf86OutputInitialRotation(output); - - if (debug_modes) { - if (output->probed_modes != NULL) { - xf86DrvMsg(scrn->scrnIndex, X_INFO, - "Printing probed modes for output %s\n", - output->name); - } - else { - xf86DrvMsg(scrn->scrnIndex, X_INFO, - "No remaining probed modes for output %s\n", - output->name); - } - } - for (mode = output->probed_modes; mode != NULL; mode = mode->next) { - /* The code to choose the best mode per pipe later on will require - * VRefresh to be set. - */ - mode->VRefresh = xf86ModeVRefresh(mode); - xf86SetModeCrtc(mode, INTERLACE_HALVE_V); - - if (debug_modes) - xf86PrintModeline(scrn->scrnIndex, mode); - } - } -} - -/** - * Copy one of the output mode lists to the ScrnInfo record - */ - -static DisplayModePtr -biggestMode(DisplayModePtr a, DisplayModePtr b) -{ - int A, B; - - if (!a) - return b; - if (!b) - return a; - - A = a->HDisplay * a->VDisplay; - B = b->HDisplay * b->VDisplay; - - if (A > B) - return a; - - return b; -} - -static xf86OutputPtr -SetCompatOutput(xf86CrtcConfigPtr config) -{ - xf86OutputPtr output = NULL, test = NULL; - DisplayModePtr maxmode = NULL, testmode, mode; - int o, compat = -1, count, mincount = 0; - - if (config->num_output == 0) - return NULL; - - /* Look for one that's definitely connected */ - for (o = 0; o < config->num_output; o++) { - test = config->output[o]; - if (!test->crtc) - continue; - if (test->status != XF86OutputStatusConnected) - continue; - if (!test->probed_modes) - continue; - - testmode = mode = test->probed_modes; - for (count = 0; mode; mode = mode->next, count++) - testmode = biggestMode(testmode, mode); - - if (!output) { - output = test; - compat = o; - maxmode = testmode; - mincount = count; - } - else if (maxmode == biggestMode(maxmode, testmode)) { - output = test; - compat = o; - maxmode = testmode; - mincount = count; - } - else if ((maxmode->HDisplay == testmode->HDisplay) && - (maxmode->VDisplay == testmode->VDisplay) && - count <= mincount) { - output = test; - compat = o; - maxmode = testmode; - mincount = count; - } - } - - /* If we didn't find one, take anything we can get */ - if (!output) { - for (o = 0; o < config->num_output; o++) { - test = config->output[o]; - if (!test->crtc) - continue; - if (!test->probed_modes) - continue; - - if (!output) { - output = test; - compat = o; - } - else if (test->probed_modes->HDisplay < - output->probed_modes->HDisplay) { - output = test; - compat = o; - } - } - } - - if (compat >= 0) { - config->compat_output = compat; - } - else if (config->compat_output >= 0 && config->compat_output < config->num_output) { - /* Don't change the compat output when no valid outputs found */ - output = config->output[config->compat_output]; - } - - /* All outputs are disconnected, select one to fake */ - if (!output && config->num_output) { - config->compat_output = 0; - output = config->output[config->compat_output]; - } - - return output; -} - -void -xf86SetScrnInfoModes(ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - xf86OutputPtr output; - xf86CrtcPtr crtc; - DisplayModePtr last, mode = NULL; - - output = SetCompatOutput(config); - - if (!output) - return; /* punt */ - - crtc = output->crtc; - - /* Clear any existing modes from scrn->modes */ - while (scrn->modes != NULL) - xf86DeleteMode(&scrn->modes, scrn->modes); - - /* Set scrn->modes to the mode list for the 'compat' output */ - scrn->modes = xf86DuplicateModes(scrn, output->probed_modes); - - if (crtc) { - for (mode = scrn->modes; mode; mode = mode->next) - if (xf86ModesEqual(mode, &crtc->desiredMode)) - break; - } - - if (!scrn->modes) { - scrn->modes = xf86ModesAdd(scrn->modes, - xf86CVTMode(scrn->display->virtualX, - scrn->display->virtualY, - 60, 0, 0)); - } - - /* For some reason, scrn->modes is circular, unlike the other mode - * lists. How great is that? - */ - for (last = scrn->modes; last && last->next; last = last->next); - last->next = scrn->modes; - scrn->modes->prev = last; - if (mode) { - while (scrn->modes != mode) - scrn->modes = scrn->modes->next; - } - - scrn->currentMode = scrn->modes; -#ifdef XFreeXDGA - if (scrn->pScreen) - _xf86_di_dga_reinit_internal(scrn->pScreen); -#endif -} - -static Bool -xf86CollectEnabledOutputs(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, - Bool *enabled) -{ - Bool any_enabled = FALSE; - int o; - - /* - * Don't bother enabling outputs on GPU screens: a client needs to attach - * it to a source provider before setting a mode that scans out a shared - * pixmap. - */ - if (scrn->is_gpu) - return FALSE; - - for (o = 0; o < config->num_output; o++) - any_enabled |= enabled[o] = xf86OutputEnabled(config->output[o], TRUE); - - if (!any_enabled) { - xf86DrvMsg(scrn->scrnIndex, X_WARNING, - "No outputs definitely connected, trying again...\n"); - - for (o = 0; o < config->num_output; o++) - any_enabled |= enabled[o] = - xf86OutputEnabled(config->output[o], FALSE); - } - - return any_enabled; -} - -static Bool -nextEnabledOutput(xf86CrtcConfigPtr config, Bool *enabled, int *index) -{ - int o = *index; - - for (o++; o < config->num_output; o++) { - if (enabled[o]) { - *index = o; - return TRUE; - } - } - - return FALSE; -} - -static Bool -aspectMatch(float a, float b) -{ - return fabs(1 - (a / b)) < 0.05; -} - -static DisplayModePtr -nextAspectMode(xf86OutputPtr o, DisplayModePtr last, float aspect) -{ - DisplayModePtr m = NULL; - - if (!o) - return NULL; - - if (!last) - m = o->probed_modes; - else - m = last->next; - - for (; m; m = m->next) - if (aspectMatch(aspect, (float) m->HDisplay / (float) m->VDisplay)) - return m; - - return NULL; -} - -static DisplayModePtr -bestModeForAspect(xf86CrtcConfigPtr config, Bool *enabled, float aspect) -{ - int o = -1, p; - DisplayModePtr mode = NULL, test = NULL, match = NULL; - - if (!nextEnabledOutput(config, enabled, &o)) - return NULL; - while ((mode = nextAspectMode(config->output[o], mode, aspect))) { - test = mode; - for (p = o; nextEnabledOutput(config, enabled, &p);) { - test = xf86OutputFindClosestMode(config->output[p], mode); - if (!test) - break; - if (test->HDisplay != mode->HDisplay || - test->VDisplay != mode->VDisplay) { - test = NULL; - break; - } - } - - /* if we didn't match it on all outputs, try the next one */ - if (!test) - continue; - - /* if it's bigger than the last one, save it */ - if (!match || (test->HDisplay > match->HDisplay)) - match = test; - } - - /* return the biggest one found */ - return match; -} - -static int -numEnabledOutputs(xf86CrtcConfigPtr config, Bool *enabled) -{ - int i = 0, p; - - for (i = 0, p = -1; nextEnabledOutput(config, enabled, &p); i++) ; - - return i; -} - -static Bool -xf86TargetRightOf(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, - DisplayModePtr *modes, Bool *enabled, - int width, int height) -{ - int o; - int w = 0; - Bool has_tile = FALSE; - uint32_t configured_outputs; - - xf86GetOptValBool(config->options, OPTION_PREFER_CLONEMODE, - &scrn->preferClone); - if (scrn->preferClone) - return FALSE; - - if (numEnabledOutputs(config, enabled) < 2) - return FALSE; - - for (o = -1; nextEnabledOutput(config, enabled, &o); ) { - DisplayModePtr mode = - xf86OutputHasPreferredMode(config->output[o], width, height); - - if (!mode) - return FALSE; - - w += mode->HDisplay; - } - - if (w > width) - return FALSE; - - w = 0; - configured_outputs = 0; - - for (o = -1; nextEnabledOutput(config, enabled, &o); ) { - DisplayModePtr mode = - xf86OutputHasPreferredMode(config->output[o], width, height); - - if (configured_outputs & (1 << o)) - continue; - - if (config->output[o]->tile_info.group_id) { - has_tile = TRUE; - continue; - } - - config->output[o]->initial_x = w; - w += mode->HDisplay; - - configured_outputs |= (1 << o); - modes[o] = mode; - } - - if (has_tile) { - for (o = -1; nextEnabledOutput(config, enabled, &o); ) { - int ht, vt, ot; - int add_x, cur_x = w; - struct xf86CrtcTileInfo *tile_info = &config->output[o]->tile_info, *this_tile; - if (configured_outputs & (1 << o)) - continue; - if (!tile_info->group_id) - continue; - - if (tile_info->tile_h_loc != 0 && tile_info->tile_v_loc != 0) - continue; - - for (ht = 0; ht < tile_info->num_h_tile; ht++) { - int cur_y = 0; - add_x = 0; - for (vt = 0; vt < tile_info->num_v_tile; vt++) { - - for (ot = -1; nextEnabledOutput(config, enabled, &ot); ) { - - DisplayModePtr mode = - xf86OutputHasPreferredMode(config->output[ot], width, height); - if (!config->output[ot]->tile_info.group_id) - continue; - - this_tile = &config->output[ot]->tile_info; - if (this_tile->group_id != tile_info->group_id) - continue; - - if (this_tile->tile_h_loc != ht || - this_tile->tile_v_loc != vt) - continue; - - config->output[ot]->initial_x = cur_x; - config->output[ot]->initial_y = cur_y; - - if (vt == 0) - add_x = this_tile->tile_h_size; - cur_y += this_tile->tile_v_size; - configured_outputs |= (1 << ot); - modes[ot] = mode; - } - } - cur_x += add_x; - } - w = cur_x; - } - } - return TRUE; -} - -static Bool -xf86TargetPreferred(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, - DisplayModePtr * modes, Bool *enabled, - int width, int height) -{ - int o, p; - int max_pref_width = 0, max_pref_height = 0; - DisplayModePtr *preferred, *preferred_match; - Bool ret = FALSE; - - preferred = xnfcalloc(config->num_output, sizeof(DisplayModePtr)); - preferred_match = xnfcalloc(config->num_output, sizeof(DisplayModePtr)); - - /* Check if the preferred mode is available on all outputs */ - for (p = -1; nextEnabledOutput(config, enabled, &p);) { - Rotation r = config->output[p]->initial_rotation; - DisplayModePtr mode; - - if ((preferred[p] = xf86OutputHasPreferredMode(config->output[p], - width, height))) { - int pref_width = xf86ModeWidth(preferred[p], r); - int pref_height = xf86ModeHeight(preferred[p], r); - Bool all_match = TRUE; - - for (o = -1; nextEnabledOutput(config, enabled, &o);) { - Bool match = FALSE; - xf86OutputPtr output = config->output[o]; - - if (o == p) - continue; - - /* - * First see if the preferred mode matches on the next - * output as well. This catches the common case of identical - * monitors and makes sure they all have the same timings - * and refresh. If that fails, we fall back to trying to - * match just width & height. - */ - mode = xf86OutputHasPreferredMode(output, pref_width, - pref_height); - if (mode && xf86ModesEqual(mode, preferred[p])) { - preferred[o] = mode; - match = TRUE; - } - else { - for (mode = output->probed_modes; mode; mode = mode->next) { - Rotation ir = output->initial_rotation; - - if (xf86ModeWidth(mode, ir) == pref_width && - xf86ModeHeight(mode, ir) == pref_height) { - preferred[o] = mode; - match = TRUE; - } - } - } - - all_match &= match; - } - - if (all_match && - (pref_width * pref_height > max_pref_width * max_pref_height)) { - for (o = -1; nextEnabledOutput(config, enabled, &o);) - preferred_match[o] = preferred[o]; - max_pref_width = pref_width; - max_pref_height = pref_height; - ret = TRUE; - } - } - } - - /* - * If there's no preferred mode, but only one monitor, pick the - * biggest mode for its aspect ratio or 4:3, assuming one exists. - */ - if (!ret) - do { - float aspect = 0.0; - DisplayModePtr a = NULL, b = NULL; - - if (numEnabledOutputs(config, enabled) != 1) - break; - - p = -1; - nextEnabledOutput(config, enabled, &p); - if (config->output[p]->mm_height) - aspect = (float) config->output[p]->mm_width / - (float) config->output[p]->mm_height; - - a = bestModeForAspect(config, enabled, 4.0/3.0); - if (aspect) - b = bestModeForAspect(config, enabled, aspect); - - preferred_match[p] = biggestMode(a, b); - - if (preferred_match[p]) - ret = TRUE; - - } while (0); - - if (ret) { - /* oh good, there is a match. stash the selected modes and return. */ - memcpy(modes, preferred_match, - config->num_output * sizeof(DisplayModePtr)); - } - - free(preferred); - free(preferred_match); - return ret; -} - -static Bool -xf86TargetAspect(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, - DisplayModePtr * modes, Bool *enabled, int width, int height) -{ - int o; - float aspect = 0.0, *aspects; - xf86OutputPtr output; - Bool ret = FALSE; - DisplayModePtr guess = NULL, aspect_guess = NULL, base_guess = NULL; - - aspects = xnfcalloc(config->num_output, sizeof(float)); - - /* collect the aspect ratios */ - for (o = -1; nextEnabledOutput(config, enabled, &o);) { - output = config->output[o]; - if (output->mm_height) - aspects[o] = (float) output->mm_width / (float) output->mm_height; - else - aspects[o] = 4.0 / 3.0; - } - - /* check that they're all the same */ - for (o = -1; nextEnabledOutput(config, enabled, &o);) { - output = config->output[o]; - if (!aspect) { - aspect = aspects[o]; - } - else if (!aspectMatch(aspect, aspects[o])) { - goto no_aspect_match; - } - } - - /* if they're all 4:3, just skip ahead and save effort */ - if (!aspectMatch(aspect, 4.0 / 3.0)) - aspect_guess = bestModeForAspect(config, enabled, aspect); - - no_aspect_match: - base_guess = bestModeForAspect(config, enabled, 4.0 / 3.0); - - guess = biggestMode(base_guess, aspect_guess); - - if (!guess) - goto out; - - /* found a mode that works everywhere, now apply it */ - for (o = -1; nextEnabledOutput(config, enabled, &o);) { - modes[o] = xf86OutputFindClosestMode(config->output[o], guess); - } - ret = TRUE; - - out: - free(aspects); - return ret; -} - -static Bool -xf86TargetFallback(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, - DisplayModePtr * modes, Bool *enabled, int width, int height) -{ - DisplayModePtr target_mode = NULL; - Rotation target_rotation = RR_Rotate_0; - DisplayModePtr default_mode; - int default_preferred, target_preferred = 0, o; - - /* User preferred > preferred > other modes */ - for (o = -1; nextEnabledOutput(config, enabled, &o);) { - default_mode = xf86DefaultMode(config->output[o], width, height); - if (!default_mode) - continue; - - default_preferred = (((default_mode->type & M_T_PREFERRED) != 0) + - ((default_mode->type & M_T_USERPREF) != 0)); - - if (default_preferred > target_preferred || !target_mode) { - target_mode = default_mode; - target_preferred = default_preferred; - target_rotation = config->output[o]->initial_rotation; - config->compat_output = o; - } - } - - if (target_mode) - modes[config->compat_output] = target_mode; - - /* Fill in other output modes */ - for (o = -1; nextEnabledOutput(config, enabled, &o);) { - if (!modes[o]) - modes[o] = xf86ClosestMode(config->output[o], target_mode, - target_rotation, width, height); - } - - return target_mode != NULL; -} - -static Bool -xf86TargetUserpref(ScrnInfoPtr scrn, xf86CrtcConfigPtr config, - DisplayModePtr * modes, Bool *enabled, int width, int height) -{ - int o; - - if (xf86UserConfiguredOutputs(scrn, modes)) - return xf86TargetFallback(scrn, config, modes, enabled, width, height); - - for (o = -1; nextEnabledOutput(config, enabled, &o);) - if (xf86OutputHasUserPreferredMode(config->output[o])) - return - xf86TargetFallback(scrn, config, modes, enabled, width, height); - - return FALSE; -} - -void -xf86AssignNoOutputInitialSize(ScrnInfoPtr scrn, const OptionInfoRec *options, - int *no_output_width, int *no_output_height) -{ - int width = 0, height = 0; - const char *no_output_size = - xf86GetOptValString(options, OPTION_NO_OUTPUT_INITIAL_SIZE); - - *no_output_width = NO_OUTPUT_DEFAULT_WIDTH; - *no_output_height = NO_OUTPUT_DEFAULT_HEIGHT; - - if (no_output_size == NULL) { - return; - } - - if (sscanf(no_output_size, "%d %d", &width, &height) != 2) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "\"NoOutputInitialSize\" string \"%s\" not of form " - "\"width height\"\n", no_output_size); - return; - } - - *no_output_width = width; - *no_output_height = height; -} - -/** - * Construct default screen configuration - * - * Given auto-detected (and, eventually, configured) values, - * construct a usable configuration for the system - * - * canGrow indicates that the driver can resize the screen to larger than its - * initially configured size via the config->funcs->resize hook. If TRUE, this - * function will set virtualX and virtualY to match the initial configuration - * and leave config->max{Width,Height} alone. If FALSE, it will bloat - * virtual[XY] to include the largest modes and set config->max{Width,Height} - * accordingly. - */ - -Bool -xf86InitialConfiguration(ScrnInfoPtr scrn, Bool canGrow) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int o, c; - xf86CrtcPtr *crtcs; - DisplayModePtr *modes; - Bool *enabled; - int width, height; - int no_output_width, no_output_height; - int i = scrn->scrnIndex; - Bool have_outputs = TRUE; - Bool ret; - Bool success = FALSE; - - /* Set up the device options */ - config->options = xnfalloc(sizeof(xf86DeviceOptions)); - memcpy(config->options, xf86DeviceOptions, sizeof(xf86DeviceOptions)); - xf86ProcessOptions(scrn->scrnIndex, scrn->options, config->options); - config->debug_modes = xf86ReturnOptValBool(config->options, - OPTION_MODEDEBUG, FALSE); - - if (scrn->display->virtualX && !scrn->is_gpu) - width = scrn->display->virtualX; - else - width = config->maxWidth; - if (scrn->display->virtualY && !scrn->is_gpu) - height = scrn->display->virtualY; - else - height = config->maxHeight; - - xf86AssignNoOutputInitialSize(scrn, config->options, - &no_output_width, &no_output_height); - - xf86ProbeOutputModes(scrn, width, height); - - crtcs = xnfcalloc(config->num_output, sizeof(xf86CrtcPtr)); - modes = xnfcalloc(config->num_output, sizeof(DisplayModePtr)); - enabled = xnfcalloc(config->num_output, sizeof(Bool)); - - ret = xf86CollectEnabledOutputs(scrn, config, enabled); - if (ret == FALSE && canGrow) { - if (!scrn->is_gpu) - xf86DrvMsg(i, X_WARNING, - "Unable to find connected outputs - setting %dx%d " - "initial framebuffer\n", - no_output_width, no_output_height); - have_outputs = FALSE; - } - else { - if (xf86TargetUserpref(scrn, config, modes, enabled, width, height)) - xf86DrvMsg(i, X_INFO, "Using user preference for initial modes\n"); - else if (xf86TargetRightOf(scrn, config, modes, enabled, width, height)) - xf86DrvMsg(i, X_INFO, "Using spanning desktop for initial modes\n"); - else if (xf86TargetPreferred - (scrn, config, modes, enabled, width, height)) - xf86DrvMsg(i, X_INFO, "Using exact sizes for initial modes\n"); - else if (xf86TargetAspect(scrn, config, modes, enabled, width, height)) - xf86DrvMsg(i, X_INFO, - "Using fuzzy aspect match for initial modes\n"); - else if (xf86TargetFallback - (scrn, config, modes, enabled, width, height)) - xf86DrvMsg(i, X_INFO, "Using sloppy heuristic for initial modes\n"); - else - xf86DrvMsg(i, X_WARNING, "Unable to find initial modes\n"); - } - - for (o = -1; nextEnabledOutput(config, enabled, &o);) { - if (!modes[o]) - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Output %s enabled but has no modes\n", - config->output[o]->name); - else - xf86DrvMsg (scrn->scrnIndex, X_INFO, - "Output %s using initial mode %s +%d+%d\n", - config->output[o]->name, modes[o]->name, - config->output[o]->initial_x, - config->output[o]->initial_y); - } - - /* - * Set the position of each output - */ - if (!xf86InitialOutputPositions(scrn, modes)) - goto bailout; - - /* - * Set initial panning of each output - */ - xf86InitialPanning(scrn); - - /* - * Assign CRTCs to fit output configuration - */ - if (have_outputs && !xf86PickCrtcs(scrn, crtcs, modes, 0, width, height)) - goto bailout; - - /* XXX override xf86 common frame computation code */ - - if (!scrn->is_gpu) { - scrn->display->frameX0 = 0; - scrn->display->frameY0 = 0; - } - - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - crtc->enabled = FALSE; - memset(&crtc->desiredMode, '\0', sizeof(crtc->desiredMode)); - } - - /* - * Set initial configuration - */ - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - DisplayModePtr mode = modes[o]; - xf86CrtcPtr crtc = crtcs[o]; - - if (mode && crtc) { - xf86SaveModeContents(&crtc->desiredMode, mode); - crtc->desiredRotation = output->initial_rotation; - crtc->desiredX = output->initial_x; - crtc->desiredY = output->initial_y; - crtc->desiredTransformPresent = FALSE; - crtc->enabled = TRUE; - memcpy(&crtc->panningTotalArea, &output->initialTotalArea, - sizeof(BoxRec)); - memcpy(&crtc->panningTrackingArea, &output->initialTrackingArea, - sizeof(BoxRec)); - memcpy(crtc->panningBorder, output->initialBorder, - 4 * sizeof(INT16)); - output->crtc = crtc; - } - else { - output->crtc = NULL; - } - } - - if (scrn->display->virtualX == 0 || scrn->is_gpu) { - /* - * Expand virtual size to cover the current config and potential mode - * switches, if the driver can't enlarge the screen later. - */ - xf86DefaultScreenLimits(scrn, &width, &height, canGrow); - - if (have_outputs == FALSE) { - if (width < no_output_width && - height < no_output_height) { - width = no_output_width; - height = no_output_height; - } - } - - if (!scrn->is_gpu) { - scrn->display->virtualX = width; - scrn->display->virtualY = height; - } - } - - if (width > scrn->virtualX) - scrn->virtualX = width; - if (height > scrn->virtualY) - scrn->virtualY = height; - - /* - * Make sure the configuration isn't too small. - */ - if (width < config->minWidth || height < config->minHeight) - goto bailout; - - /* - * Limit the crtc config to virtual[XY] if the driver can't grow the - * desktop. - */ - if (!canGrow) { - xf86CrtcSetSizeRange(scrn, config->minWidth, config->minHeight, - width, height); - } - - xf86SetScrnInfoModes(scrn); - - success = TRUE; - bailout: - free(crtcs); - free(modes); - free(enabled); - return success; -} - -/* Turn a CRTC off, using the DPMS function and disabling the cursor */ -static void -xf86DisableCrtc(xf86CrtcPtr crtc) -{ - if (xf86CrtcIsLeased(crtc)) - return; - - crtc->funcs->dpms(crtc, DPMSModeOff); - xf86_crtc_hide_cursor(crtc); -} - -/* - * Check the CRTC we're going to map each output to vs. its current - * CRTC. If they don't match, we have to disable the output and the CRTC - * since the driver will have to re-route things. - */ -static void -xf86PrepareOutputs(ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int o; - - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - if (xf86OutputIsLeased(output)) - continue; - -#if RANDR_GET_CRTC_INTERFACE - /* Disable outputs that are unused or will be re-routed */ - if (!output->funcs->get_crtc || - output->crtc != (*output->funcs->get_crtc) (output) || - output->crtc == NULL) -#endif - (*output->funcs->dpms) (output, DPMSModeOff); - } -} - -static void -xf86PrepareCrtcs(ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; -#if RANDR_GET_CRTC_INTERFACE - xf86OutputPtr output = NULL; - uint32_t desired_outputs = 0, current_outputs = 0; - int o; - - if (xf86CrtcIsLeased(crtc)) - continue; - - for (o = 0; o < config->num_output; o++) { - output = config->output[o]; - if (output->crtc == crtc) - desired_outputs |= (1 << o); - /* If we can't tell where it's mapped, force it off */ - if (!output->funcs->get_crtc) { - desired_outputs = 0; - break; - } - if ((*output->funcs->get_crtc) (output) == crtc) - current_outputs |= (1 << o); - } - - /* - * If mappings are different or the CRTC is unused, - * we need to disable it - */ - if (desired_outputs != current_outputs || !desired_outputs) - xf86DisableCrtc(crtc); -#else - if (xf86CrtcIsLeased(crtc)) - continue; - - xf86DisableCrtc(crtc); -#endif - } -} - -/* - * Using the desired mode information in each crtc, set - * modes (used in EnterVT functions, or at server startup) - */ - -Bool -xf86SetDesiredModes(ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CrtcPtr crtc = config->crtc[0]; - int enabled = 0, failed = 0; - int c; - - /* A driver with this hook will take care of this */ - if (!crtc->funcs->set_mode_major) { - xf86PrepareOutputs(scrn); - xf86PrepareCrtcs(scrn); - } - - for (c = 0; c < config->num_crtc; c++) { - xf86OutputPtr output = NULL; - int o; - RRTransformPtr transform; - - crtc = config->crtc[c]; - - /* Skip disabled CRTCs */ - if (!crtc->enabled) - continue; - - if (xf86CompatOutput(scrn) && xf86CompatCrtc(scrn) == crtc) - output = xf86CompatOutput(scrn); - else { - for (o = 0; o < config->num_output; o++) - if (config->output[o]->crtc == crtc) { - output = config->output[o]; - break; - } - } - /* paranoia */ - if (!output) - continue; - - /* Mark that we'll need to re-set the mode for sure */ - memset(&crtc->mode, 0, sizeof(crtc->mode)); - if (!crtc->desiredMode.CrtcHDisplay) { - DisplayModePtr mode = - xf86OutputFindClosestMode(output, scrn->currentMode); - - if (!mode) - return FALSE; - xf86SaveModeContents(&crtc->desiredMode, mode); - crtc->desiredRotation = RR_Rotate_0; - crtc->desiredTransformPresent = FALSE; - crtc->desiredX = 0; - crtc->desiredY = 0; - } - - if (crtc->desiredTransformPresent) - transform = &crtc->desiredTransform; - else - transform = NULL; - if (xf86CrtcSetModeTransform - (crtc, &crtc->desiredMode, crtc->desiredRotation, transform, - crtc->desiredX, crtc->desiredY)) { - ++enabled; - } else { - for (o = 0; o < config->num_output; o++) - if (config->output[o]->crtc == crtc) - config->output[o]->crtc = NULL; - crtc->enabled = FALSE; - ++failed; - } - } - - xf86DisableUnusedFunctions(scrn); - return enabled != 0 || failed == 0; -} - -/** - * In the current world order, there are lists of modes per output, which may - * or may not include the mode that was asked to be set by XFree86's mode - * selection. Find the closest one, in the following preference order: - * - * - Equality - * - Closer in size to the requested mode, but no larger - * - Closer in refresh rate to the requested mode. - */ - -DisplayModePtr -xf86OutputFindClosestMode(xf86OutputPtr output, DisplayModePtr desired) -{ - DisplayModePtr best = NULL, scan = NULL; - - for (scan = output->probed_modes; scan != NULL; scan = scan->next) { - /* If there's an exact match, we're done. */ - if (xf86ModesEqual(scan, desired)) { - best = desired; - break; - } - - /* Reject if it's larger than the desired mode. */ - if (scan->HDisplay > desired->HDisplay || - scan->VDisplay > desired->VDisplay) { - continue; - } - - /* - * If we haven't picked a best mode yet, use the first - * one in the size range - */ - if (best == NULL) { - best = scan; - continue; - } - - /* Find if it's closer to the right size than the current best - * option. - */ - if ((scan->HDisplay > best->HDisplay && - scan->VDisplay >= best->VDisplay) || - (scan->HDisplay >= best->HDisplay && - scan->VDisplay > best->VDisplay)) { - best = scan; - continue; - } - - /* Find if it's still closer to the right refresh than the current - * best resolution. - */ - if (scan->HDisplay == best->HDisplay && - scan->VDisplay == best->VDisplay && - (fabs(scan->VRefresh - desired->VRefresh) < - fabs(best->VRefresh - desired->VRefresh))) { - best = scan; - } - } - return best; -} - -/** - * When setting a mode through XFree86-VidModeExtension or XFree86-DGA, - * take the specified mode and apply it to the crtc connected to the compat - * output. Then, find similar modes for the other outputs, as with the - * InitialConfiguration code above. The goal is to clone the desired - * mode across all outputs that are currently active. - */ - -Bool -xf86SetSingleMode(ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - Bool ok = TRUE; - xf86OutputPtr compat_output; - DisplayModePtr compat_mode = NULL; - int c; - - /* - * Let the compat output drive the final mode selection - */ - compat_output = xf86CompatOutput(pScrn); - if (compat_output) - compat_mode = xf86OutputFindClosestMode(compat_output, desired); - if (compat_mode) - desired = compat_mode; - - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - DisplayModePtr crtc_mode = NULL; - int o; - - if (!crtc->enabled) - continue; - - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - DisplayModePtr output_mode; - - /* skip outputs not on this crtc */ - if (output->crtc != crtc) - continue; - - if (crtc_mode) { - output_mode = xf86OutputFindClosestMode(output, crtc_mode); - if (output_mode != crtc_mode) - output->crtc = NULL; - } - else - crtc_mode = xf86OutputFindClosestMode(output, desired); - } - if (!crtc_mode) { - crtc->enabled = FALSE; - continue; - } - if (!xf86CrtcSetModeTransform(crtc, crtc_mode, rotation, NULL, 0, 0)) - ok = FALSE; - else { - xf86SaveModeContents(&crtc->desiredMode, crtc_mode); - crtc->desiredRotation = rotation; - crtc->desiredTransformPresent = FALSE; - crtc->desiredX = 0; - crtc->desiredY = 0; - } - } - xf86DisableUnusedFunctions(pScrn); -#ifdef RANDR_12_INTERFACE - xf86RandR12TellChanged(pScrn->pScreen); -#endif - return ok; -} - -/** - * Set the DPMS power mode of all outputs and CRTCs. - * - * If the new mode is off, it will turn off outputs and then CRTCs. - * Otherwise, it will affect CRTCs before outputs. - */ -void -xf86DPMSSet(ScrnInfoPtr scrn, int mode, int flags) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int i; - - if (!scrn->vtSema) - return; - - if (mode == DPMSModeOff) { - for (i = 0; i < config->num_output; i++) { - xf86OutputPtr output = config->output[i]; - - if (!xf86OutputIsLeased(output) && output->crtc != NULL) - (*output->funcs->dpms) (output, mode); - } - } - - for (i = 0; i < config->num_crtc; i++) { - xf86CrtcPtr crtc = config->crtc[i]; - - if (crtc->enabled) - (*crtc->funcs->dpms) (crtc, mode); - } - - if (mode != DPMSModeOff) { - for (i = 0; i < config->num_output; i++) { - xf86OutputPtr output = config->output[i]; - - if (!xf86OutputIsLeased(output) && output->crtc != NULL) - (*output->funcs->dpms) (output, mode); - } - } -} - -/** - * Implement the screensaver by just calling down into the driver DPMS hooks. - * - * Even for monitors with no DPMS support, by the definition of our DPMS hooks, - * the outputs will still get disabled (blanked). - */ -Bool -xf86SaveScreen(ScreenPtr pScreen, int mode) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - - if (xf86IsUnblank(mode)) - xf86DPMSSet(pScrn, DPMSModeOn, 0); - else - xf86DPMSSet(pScrn, DPMSModeOff, 0); - - return TRUE; -} - -/** - * Disable all inactive crtcs and outputs - */ -void -xf86DisableUnusedFunctions(ScrnInfoPtr pScrn) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int o, c; - - for (o = 0; o < xf86_config->num_output; o++) { - xf86OutputPtr output = xf86_config->output[o]; - - if (!output->crtc) - (*output->funcs->dpms) (output, DPMSModeOff); - } - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (!crtc->enabled) { - xf86DisableCrtc(crtc); - memset(&crtc->mode, 0, sizeof(crtc->mode)); - xf86RotateDestroy(crtc); - crtc->active = FALSE; - } - } - if (pScrn->pScreen) - xf86_crtc_notify(pScrn->pScreen); - if (pScrn->ModeSet) - pScrn->ModeSet(pScrn); - if (pScrn->pScreen) { - if (pScrn->pScreen->isGPU) - xf86CursorResetCursor(pScrn->pScreen->current_primary); - else - xf86CursorResetCursor(pScrn->pScreen); - } -} - -#ifdef RANDR_12_INTERFACE - -#define EDID_ATOM_NAME "EDID" - -/** - * Set the RandR EDID property - */ -static void -xf86OutputSetEDIDProperty(xf86OutputPtr output, void *data, int data_len) -{ - Atom edid_atom = MakeAtom(EDID_ATOM_NAME, sizeof(EDID_ATOM_NAME) - 1, TRUE); - - /* This may get called before the RandR resources have been created */ - if (output->randr_output == NULL) - return; - - if (data_len != 0) { - RRChangeOutputProperty(output->randr_output, edid_atom, XA_INTEGER, 8, - PropModeReplace, data_len, data, FALSE, TRUE); - } - else { - RRDeleteOutputProperty(output->randr_output, edid_atom); - } -} - -#define TILE_ATOM_NAME "TILE" -/* changing this in the future could be tricky as people may hardcode 8 */ -#define TILE_PROP_NUM_ITEMS 8 -static void -xf86OutputSetTileProperty(xf86OutputPtr output) -{ - Atom tile_atom = MakeAtom(TILE_ATOM_NAME, sizeof(TILE_ATOM_NAME) - 1, TRUE); - - /* This may get called before the RandR resources have been created */ - if (output->randr_output == NULL) - return; - - if (output->tile_info.group_id != 0) { - RRChangeOutputProperty(output->randr_output, tile_atom, XA_INTEGER, 32, - PropModeReplace, TILE_PROP_NUM_ITEMS, (uint32_t *)&output->tile_info, FALSE, TRUE); - } - else { - RRDeleteOutputProperty(output->randr_output, tile_atom); - } -} - -#endif - -/* Pull out a physical size from a detailed timing if available. */ -struct det_phySize_parameter { - xf86OutputPtr output; - ddc_quirk_t quirks; - Bool ret; -}; - -static void -handle_detailed_physical_size(struct detailed_monitor_section - *det_mon, void *data) -{ - struct det_phySize_parameter *p; - - p = (struct det_phySize_parameter *) data; - - if (p->ret == TRUE) - return; - - xf86DetTimingApplyQuirks(det_mon, p->quirks, - p->output->MonInfo->features.hsize, - p->output->MonInfo->features.vsize); - if (det_mon->type == DT && - det_mon->section.d_timings.h_size != 0 && - det_mon->section.d_timings.v_size != 0) { - /* some sanity checking for aspect ratio: - assume any h / v (or v / h) > 2.4 to be bogus. - This would even include cinemascope */ - if (((det_mon->section.d_timings.h_size * 5) < - (det_mon->section.d_timings.v_size * 12)) && - ((det_mon->section.d_timings.v_size * 5) < - (det_mon->section.d_timings.h_size * 12))) { - p->output->mm_width = det_mon->section.d_timings.h_size; - p->output->mm_height = det_mon->section.d_timings.v_size; - p->ret = TRUE; - } else - xf86DrvMsg(p->output->scrn->scrnIndex, X_WARNING, - "Output %s: Strange aspect ratio (%i/%i), " - "consider adding a quirk\n", p->output->name, - det_mon->section.d_timings.h_size, - det_mon->section.d_timings.v_size); - } -} - -Bool -xf86OutputParseKMSTile(const char *tile_data, int tile_length, - struct xf86CrtcTileInfo *tile_info) -{ - int ret; - - ret = sscanf(tile_data, "%d:%d:%d:%d:%d:%d:%d:%d", - &tile_info->group_id, - &tile_info->flags, - &tile_info->num_h_tile, - &tile_info->num_v_tile, - &tile_info->tile_h_loc, - &tile_info->tile_v_loc, - &tile_info->tile_h_size, - &tile_info->tile_v_size); - if (ret != 8) - return FALSE; - return TRUE; -} - -void -xf86OutputSetTile(xf86OutputPtr output, struct xf86CrtcTileInfo *tile_info) -{ - if (tile_info) - output->tile_info = *tile_info; - else - memset(&output->tile_info, 0, sizeof(output->tile_info)); -#ifdef RANDR_12_INTERFACE - xf86OutputSetTileProperty(output); -#endif -} - -/** - * Set the EDID information for the specified output - */ -void -xf86OutputSetEDID(xf86OutputPtr output, xf86MonPtr edid_mon) -{ - ScrnInfoPtr scrn = output->scrn; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - Bool debug_modes = config->debug_modes || xf86Initialising; - -#ifdef RANDR_12_INTERFACE - int size; -#endif - - free(output->MonInfo); - - output->MonInfo = edid_mon; - output->mm_width = 0; - output->mm_height = 0; - - if (debug_modes) { - xf86DrvMsg(scrn->scrnIndex, X_INFO, "EDID for output %s\n", - output->name); - xf86PrintEDID(edid_mon); - } - - /* Set the DDC properties for the 'compat' output */ - /* GPU screens don't have a root window */ - if (output == xf86CompatOutput(scrn) && !scrn->is_gpu) - xf86SetDDCproperties(scrn, edid_mon); - -#ifdef RANDR_12_INTERFACE - /* Set the RandR output properties */ - size = 0; - if (edid_mon) { - if (edid_mon->ver.version == 1) { - size = 128; - if (edid_mon->flags & EDID_COMPLETE_RAWDATA) - size += edid_mon->no_sections * 128; - } - else if (edid_mon->ver.version == 2) - size = 256; - } - xf86OutputSetEDIDProperty(output, edid_mon ? edid_mon->rawData : NULL, - size); -#endif - - if (edid_mon) { - - struct det_phySize_parameter p; - - p.output = output; - p.quirks = xf86DDCDetectQuirks(scrn->scrnIndex, edid_mon, FALSE); - p.ret = FALSE; - xf86ForEachDetailedBlock(edid_mon, handle_detailed_physical_size, &p); - - /* if no mm size is available from a detailed timing, check the max size field */ - if ((!output->mm_width || !output->mm_height) && - (edid_mon->features.hsize && edid_mon->features.vsize)) { - output->mm_width = edid_mon->features.hsize * 10; - output->mm_height = edid_mon->features.vsize * 10; - } - } -} - -/** - * Return the list of modes supported by the EDID information - * stored in 'output' - */ -DisplayModePtr -xf86OutputGetEDIDModes(xf86OutputPtr output) -{ - ScrnInfoPtr scrn = output->scrn; - xf86MonPtr edid_mon = output->MonInfo; - - if (!edid_mon) - return NULL; - return xf86DDCGetModes(scrn->scrnIndex, edid_mon); -} - -/* maybe we should care about DDC1? meh. */ -xf86MonPtr -xf86OutputGetEDID(xf86OutputPtr output, I2CBusPtr pDDCBus) -{ - ScrnInfoPtr scrn = output->scrn; - xf86MonPtr mon; - - mon = xf86DoEEDID(scrn, pDDCBus, TRUE); - if (mon) - xf86DDCApplyQuirks(scrn->scrnIndex, mon); - - return mon; -} - -static const char *_xf86ConnectorNames[] = { - "None", "VGA", "DVI-I", "DVI-D", - "DVI-A", "Composite", "S-Video", - "Component", "LFP", "Proprietary", - "HDMI", "DisplayPort", -}; - -const char * -xf86ConnectorGetName(xf86ConnectorType connector) -{ - return _xf86ConnectorNames[connector]; -} - -#ifdef XV -static void -x86_crtc_box_intersect(BoxPtr dest, BoxPtr a, BoxPtr b) -{ - dest->x1 = a->x1 > b->x1 ? a->x1 : b->x1; - dest->x2 = a->x2 < b->x2 ? a->x2 : b->x2; - dest->y1 = a->y1 > b->y1 ? a->y1 : b->y1; - dest->y2 = a->y2 < b->y2 ? a->y2 : b->y2; - - if (dest->x1 >= dest->x2 || dest->y1 >= dest->y2) - dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0; -} - -static void -x86_crtc_box(xf86CrtcPtr crtc, BoxPtr crtc_box) -{ - if (crtc->enabled) { - crtc_box->x1 = crtc->x; - crtc_box->x2 = crtc->x + xf86ModeWidth(&crtc->mode, crtc->rotation); - crtc_box->y1 = crtc->y; - crtc_box->y2 = crtc->y + xf86ModeHeight(&crtc->mode, crtc->rotation); - } - else - crtc_box->x1 = crtc_box->x2 = crtc_box->y1 = crtc_box->y2 = 0; -} - -static int -xf86_crtc_box_area(BoxPtr box) -{ - return (int) (box->x2 - box->x1) * (int) (box->y2 - box->y1); -} - -/* - * Return the crtc covering 'box'. If two crtcs cover a portion of - * 'box', then prefer 'desired'. If 'desired' is NULL, then prefer the crtc - * with greater coverage - */ - -static xf86CrtcPtr -xf86_covering_crtc(ScrnInfoPtr pScrn, - BoxPtr box, xf86CrtcPtr desired, BoxPtr crtc_box_ret) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - xf86CrtcPtr crtc, best_crtc; - int coverage, best_coverage; - int c; - BoxRec crtc_box, cover_box; - - best_crtc = NULL; - best_coverage = 0; - crtc_box_ret->x1 = 0; - crtc_box_ret->x2 = 0; - crtc_box_ret->y1 = 0; - crtc_box_ret->y2 = 0; - for (c = 0; c < xf86_config->num_crtc; c++) { - crtc = xf86_config->crtc[c]; - x86_crtc_box(crtc, &crtc_box); - x86_crtc_box_intersect(&cover_box, &crtc_box, box); - coverage = xf86_crtc_box_area(&cover_box); - if (coverage && crtc == desired) { - *crtc_box_ret = crtc_box; - return crtc; - } - else if (coverage > best_coverage) { - *crtc_box_ret = crtc_box; - best_crtc = crtc; - best_coverage = coverage; - } - } - return best_crtc; -} - -/* - * For overlay video, compute the relevant CRTC and - * clip video to that. - * - * returning FALSE means there was a memory failure of some kind, - * not that the video shouldn't be displayed - */ - -Bool -xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn, - xf86CrtcPtr * crtc_ret, - xf86CrtcPtr desired_crtc, - BoxPtr dst, - INT32 *xa, - INT32 *xb, - INT32 *ya, - INT32 *yb, RegionPtr reg, INT32 width, INT32 height) -{ - Bool ret; - RegionRec crtc_region_local; - RegionPtr crtc_region = reg; - - if (crtc_ret) { - BoxRec crtc_box; - xf86CrtcPtr crtc = xf86_covering_crtc(pScrn, dst, - desired_crtc, - &crtc_box); - - if (crtc) { - RegionInit(&crtc_region_local, &crtc_box, 1); - crtc_region = &crtc_region_local; - RegionIntersect(crtc_region, crtc_region, reg); - } - *crtc_ret = crtc; - } - - ret = xf86XVClipVideoHelper(dst, xa, xb, ya, yb, - crtc_region, width, height); - - if (crtc_region != reg) - RegionUninit(&crtc_region_local); - - return ret; -} -#endif - -xf86_crtc_notify_proc_ptr -xf86_wrap_crtc_notify(ScreenPtr screen, xf86_crtc_notify_proc_ptr new) -{ - if (xf86CrtcConfigPrivateIndex != -1) { - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - xf86_crtc_notify_proc_ptr old; - - old = config->xf86_crtc_notify; - config->xf86_crtc_notify = new; - return old; - } - return NULL; -} - -void -xf86_unwrap_crtc_notify(ScreenPtr screen, xf86_crtc_notify_proc_ptr old) -{ - if (xf86CrtcConfigPrivateIndex != -1) { - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - - config->xf86_crtc_notify = old; - } -} - -void -xf86_crtc_notify(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - - if (config->xf86_crtc_notify) - config->xf86_crtc_notify(screen); -} - -Bool -xf86_crtc_supports_gamma(ScrnInfoPtr pScrn) -{ - if (xf86CrtcConfigPrivateIndex != -1) { - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - xf86CrtcPtr crtc; - - /* for multiple drivers loaded we need this */ - if (!xf86_config) - return FALSE; - if (xf86_config->num_crtc == 0) - return FALSE; - crtc = xf86_config->crtc[0]; - - return crtc->funcs->gamma_set != NULL; - } - - return FALSE; -} - -void -xf86ProviderSetup(ScrnInfoPtr scrn, - const xf86ProviderFuncsRec *funcs, const char *name) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - - assert(!xf86_config->name); - assert(name); - - xf86_config->name = strdup(name); - xf86_config->provider_funcs = funcs; -#ifdef RANDR_12_INTERFACE - xf86_config->randr_provider = NULL; -#endif -} - -void -xf86DetachAllCrtc(ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int i; - - for (i = 0; i < xf86_config->num_crtc; i++) { - xf86CrtcPtr crtc = xf86_config->crtc[i]; - - if (crtc->randr_crtc) - RRCrtcDetachScanoutPixmap(crtc->randr_crtc); - - /* dpms off */ - xf86DisableCrtc(crtc); - /* force a reset the next time its used */ - crtc->randr_crtc->mode = NULL; - crtc->mode.HDisplay = 0; - crtc->x = crtc->y = 0; - } -} diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h deleted file mode 100644 index e36adbe00..000000000 --- a/hw/xfree86/modes/xf86Crtc.h +++ /dev/null @@ -1,1151 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * Copyright © 2011 Aaron Plattner - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ -#ifndef _XF86CRTC_H_ -#define _XF86CRTC_H_ - -#include -#include "randrstr.h" -#include "xf86Modes.h" -#include "xf86Cursor.h" -#include "xf86i2c.h" -#include "damage.h" -#include "picturestr.h" - -/* Compat definitions for older X Servers. */ -#ifndef M_T_PREFERRED -#define M_T_PREFERRED 0x08 -#endif -#ifndef M_T_DRIVER -#define M_T_DRIVER 0x40 -#endif -#ifndef M_T_USERPREF -#define M_T_USERPREF 0x80 -#endif -#ifndef HARDWARE_CURSOR_ARGB -#define HARDWARE_CURSOR_ARGB 0x00004000 -#endif - -typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr; -typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr; -typedef struct _xf86Lease xf86LeaseRec, *xf86LeasePtr; - -/* define a standard for connector types */ -typedef enum _xf86ConnectorType { - XF86ConnectorNone, - XF86ConnectorVGA, - XF86ConnectorDVI_I, - XF86ConnectorDVI_D, - XF86ConnectorDVI_A, - XF86ConnectorComposite, - XF86ConnectorSvideo, - XF86ConnectorComponent, - XF86ConnectorLFP, - XF86ConnectorProprietary, - XF86ConnectorHDMI, - XF86ConnectorDisplayPort, -} xf86ConnectorType; - -typedef enum _xf86OutputStatus { - XF86OutputStatusConnected, - XF86OutputStatusDisconnected, - XF86OutputStatusUnknown -} xf86OutputStatus; - -typedef enum _xf86DriverTransforms { - XF86DriverTransformNone = 0, - XF86DriverTransformOutput = 1 << 0, - XF86DriverTransformCursorImage = 1 << 1, - XF86DriverTransformCursorPosition = 1 << 2, -} xf86DriverTransforms; - - -struct xf86CrtcTileInfo { - uint32_t group_id; - uint32_t flags; - uint32_t num_h_tile; - uint32_t num_v_tile; - uint32_t tile_h_loc; - uint32_t tile_v_loc; - uint32_t tile_h_size; - uint32_t tile_v_size; -}; - -typedef struct _xf86CrtcFuncs { - /** - * Turns the crtc on/off, or sets intermediate power levels if available. - * - * Unsupported intermediate modes drop to the lower power setting. If the - * mode is DPMSModeOff, the crtc must be disabled sufficiently for it to - * be safe to call mode_set. - */ - void - (*dpms) (xf86CrtcPtr crtc, int mode); - - /** - * Saves the crtc's state for restoration on VT switch. - */ - void - (*save) (xf86CrtcPtr crtc); - - /** - * Restore's the crtc's state at VT switch. - */ - void - (*restore) (xf86CrtcPtr crtc); - - /** - * Lock CRTC prior to mode setting, mostly for DRI. - * Returns whether unlock is needed - */ - Bool - (*lock) (xf86CrtcPtr crtc); - - /** - * Unlock CRTC after mode setting, mostly for DRI - */ - void - (*unlock) (xf86CrtcPtr crtc); - - /** - * Callback to adjust the mode to be set in the CRTC. - * - * This allows a CRTC to adjust the clock or even the entire set of - * timings, which is used for panels with fixed timings or for - * buses with clock limitations. - */ - Bool - (*mode_fixup) (xf86CrtcPtr crtc, - DisplayModePtr mode, DisplayModePtr adjusted_mode); - - /** - * Prepare CRTC for an upcoming mode set. - */ - void - (*prepare) (xf86CrtcPtr crtc); - - /** - * Callback for setting up a video mode after fixups have been made. - */ - void - (*mode_set) (xf86CrtcPtr crtc, - DisplayModePtr mode, - DisplayModePtr adjusted_mode, int x, int y); - - /** - * Commit mode changes to a CRTC - */ - void - (*commit) (xf86CrtcPtr crtc); - - /* Set the color ramps for the CRTC to the given values. */ - void - (*gamma_set) (xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue, - int size); - - /** - * Allocate the shadow area, delay the pixmap creation until needed - */ - void *(*shadow_allocate) (xf86CrtcPtr crtc, int width, int height); - - /** - * Create shadow pixmap for rotation support - */ - PixmapPtr - (*shadow_create) (xf86CrtcPtr crtc, void *data, int width, int height); - - /** - * Destroy shadow pixmap - */ - void - (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data); - - /** - * Set cursor colors - */ - void - (*set_cursor_colors) (xf86CrtcPtr crtc, int bg, int fg); - - /** - * Set cursor position - */ - void - (*set_cursor_position) (xf86CrtcPtr crtc, int x, int y); - - /** - * Show cursor - */ - void - (*show_cursor) (xf86CrtcPtr crtc); - Bool - (*show_cursor_check) (xf86CrtcPtr crtc); - - /** - * Hide cursor - */ - void - (*hide_cursor) (xf86CrtcPtr crtc); - - /** - * Load monochrome image - */ - void - (*load_cursor_image) (xf86CrtcPtr crtc, CARD8 *image); - Bool - (*load_cursor_image_check) (xf86CrtcPtr crtc, CARD8 *image); - - /** - * Load ARGB image - */ - void - (*load_cursor_argb) (xf86CrtcPtr crtc, CARD32 *image); - Bool - (*load_cursor_argb_check) (xf86CrtcPtr crtc, CARD32 *image); - - /** - * Clean up driver-specific bits of the crtc - */ - void - (*destroy) (xf86CrtcPtr crtc); - - /** - * Less fine-grained mode setting entry point for kernel modesetting - */ - Bool - (*set_mode_major) (xf86CrtcPtr crtc, DisplayModePtr mode, - Rotation rotation, int x, int y); - - /** - * Callback for panning. Doesn't change the mode. - * Added in ABI version 2 - */ - void - (*set_origin) (xf86CrtcPtr crtc, int x, int y); - - /** - */ - Bool - (*set_scanout_pixmap)(xf86CrtcPtr crtc, PixmapPtr pixmap); - -} xf86CrtcFuncsRec, *xf86CrtcFuncsPtr; - -#define XF86_CRTC_VERSION 8 - -struct _xf86Crtc { - /** - * ABI versioning - */ - int version; - - /** - * Associated ScrnInfo - */ - ScrnInfoPtr scrn; - - /** - * Desired state of this CRTC - * - * Set when this CRTC should be driving one or more outputs - */ - Bool enabled; - - /** - * Active mode - * - * This reflects the mode as set in the CRTC currently - * It will be cleared when the VT is not active or - * during server startup - */ - DisplayModeRec mode; - Rotation rotation; - PixmapPtr rotatedPixmap; - void *rotatedData; - - /** - * Position on screen - * - * Locates this CRTC within the frame buffer - */ - int x, y; - - /** - * Desired mode - * - * This is set to the requested mode, independent of - * whether the VT is active. In particular, it receives - * the startup configured mode and saves the active mode - * on VT switch. - */ - DisplayModeRec desiredMode; - Rotation desiredRotation; - int desiredX, desiredY; - - /** crtc-specific functions */ - const xf86CrtcFuncsRec *funcs; - - /** - * Driver private - * - * Holds driver-private information - */ - void *driver_private; - -#ifdef RANDR_12_INTERFACE - /** - * RandR crtc - * - * When RandR 1.2 is available, this - * points at the associated crtc object - */ - RRCrtcPtr randr_crtc; -#else - void *randr_crtc; -#endif - - /** - * Current cursor is ARGB - */ - Bool cursor_argb; - /** - * Track whether cursor is within CRTC range - */ - Bool cursor_in_range; - /** - * Track state of cursor associated with this CRTC - */ - Bool cursor_shown; - - /** - * Current transformation matrix - */ - PictTransform crtc_to_framebuffer; - /* framebuffer_to_crtc was removed in ABI 2 */ - struct pict_f_transform f_crtc_to_framebuffer; /* ABI 2 */ - struct pict_f_transform f_framebuffer_to_crtc; /* ABI 2 */ - PictFilterPtr filter; /* ABI 2 */ - xFixed *params; /* ABI 2 */ - int nparams; /* ABI 2 */ - int filter_width; /* ABI 2 */ - int filter_height; /* ABI 2 */ - Bool transform_in_use; - RRTransformRec transform; /* ABI 2 */ - Bool transformPresent; /* ABI 2 */ - RRTransformRec desiredTransform; /* ABI 2 */ - Bool desiredTransformPresent; /* ABI 2 */ - /** - * Bounding box in screen space - */ - BoxRec bounds; - /** - * Panning: - * TotalArea: total panning area, larger than CRTC's size - * TrackingArea: Area of the pointer for which the CRTC is panned - * border: Borders of the displayed CRTC area which induces panning if the pointer reaches them - * Added in ABI version 2 - */ - BoxRec panningTotalArea; - BoxRec panningTrackingArea; - INT16 panningBorder[4]; - - /** - * Current gamma, especially useful after initial config. - * Added in ABI version 3 - */ - CARD16 *gamma_red; - CARD16 *gamma_green; - CARD16 *gamma_blue; - int gamma_size; - - /** - * Actual state of this CRTC - * - * Set to TRUE after modesetting, set to FALSE if no outputs are connected - * Added in ABI version 3 - */ - Bool active; - /** - * Clear the shadow - */ - Bool shadowClear; - - /** - * Indicates that the driver is handling some or all transforms: - * - * XF86DriverTransformOutput: The driver handles the output transform, so - * the shadow surface should be disabled. The driver writes this field - * before calling xf86CrtcRotate to indicate that it is handling the - * transform (including rotation and reflection). - * - * XF86DriverTransformCursorImage: Setting this flag causes the server to - * pass the untransformed cursor image to the driver hook. - * - * XF86DriverTransformCursorPosition: Setting this flag causes the server - * to pass the untransformed cursor position to the driver hook. - * - * Added in ABI version 4, changed to xf86DriverTransforms in ABI version 7 - */ - xf86DriverTransforms driverIsPerformingTransform; - - /* Added in ABI version 5 - */ - PixmapPtr current_scanout; - - /* Added in ABI version 6 - */ - PixmapPtr current_scanout_back; -}; - -typedef struct _xf86OutputFuncs { - /** - * Called to allow the output a chance to create properties after the - * RandR objects have been created. - */ - void - (*create_resources) (xf86OutputPtr output); - - /** - * Turns the output on/off, or sets intermediate power levels if available. - * - * Unsupported intermediate modes drop to the lower power setting. If the - * mode is DPMSModeOff, the output must be disabled, as the DPLL may be - * disabled afterwards. - */ - void - (*dpms) (xf86OutputPtr output, int mode); - - /** - * Saves the output's state for restoration on VT switch. - */ - void - (*save) (xf86OutputPtr output); - - /** - * Restore's the output's state at VT switch. - */ - void - (*restore) (xf86OutputPtr output); - - /** - * Callback for testing a video mode for a given output. - * - * This function should only check for cases where a mode can't be supported - * on the output specifically, and not represent generic CRTC limitations. - * - * \return MODE_OK if the mode is valid, or another MODE_* otherwise. - */ - int - (*mode_valid) (xf86OutputPtr output, DisplayModePtr pMode); - - /** - * Callback to adjust the mode to be set in the CRTC. - * - * This allows an output to adjust the clock or even the entire set of - * timings, which is used for panels with fixed timings or for - * buses with clock limitations. - */ - Bool - (*mode_fixup) (xf86OutputPtr output, - DisplayModePtr mode, DisplayModePtr adjusted_mode); - - /** - * Callback for preparing mode changes on an output - */ - void - (*prepare) (xf86OutputPtr output); - - /** - * Callback for committing mode changes on an output - */ - void - (*commit) (xf86OutputPtr output); - - /** - * Callback for setting up a video mode after fixups have been made. - * - * This is only called while the output is disabled. The dpms callback - * must be all that's necessary for the output, to turn the output on - * after this function is called. - */ - void - (*mode_set) (xf86OutputPtr output, - DisplayModePtr mode, DisplayModePtr adjusted_mode); - - /** - * Probe for a connected output, and return detect_status. - */ - xf86OutputStatus(*detect) (xf86OutputPtr output); - - /** - * Query the device for the modes it provides. - * - * This function may also update MonInfo, mm_width, and mm_height. - * - * \return singly-linked list of modes or NULL if no modes found. - */ - DisplayModePtr(*get_modes) (xf86OutputPtr output); - -#ifdef RANDR_12_INTERFACE - /** - * Callback when an output's property has changed. - */ - Bool - (*set_property) (xf86OutputPtr output, - Atom property, RRPropertyValuePtr value); -#endif -#ifdef RANDR_13_INTERFACE - /** - * Callback to get an updated property value - */ - Bool - (*get_property) (xf86OutputPtr output, Atom property); -#endif -#ifdef RANDR_GET_CRTC_INTERFACE - /** - * Callback to get current CRTC for a given output - */ - xf86CrtcPtr(*get_crtc) (xf86OutputPtr output); -#endif - /** - * Clean up driver-specific bits of the output - */ - void - (*destroy) (xf86OutputPtr output); -} xf86OutputFuncsRec, *xf86OutputFuncsPtr; - -#define XF86_OUTPUT_VERSION 3 - -struct _xf86Output { - /** - * ABI versioning - */ - int version; - - /** - * Associated ScrnInfo - */ - ScrnInfoPtr scrn; - - /** - * Currently connected crtc (if any) - * - * If this output is not in use, this field will be NULL. - */ - xf86CrtcPtr crtc; - - /** - * Possible CRTCs for this output as a mask of crtc indices - */ - CARD32 possible_crtcs; - - /** - * Possible outputs to share the same CRTC as a mask of output indices - */ - CARD32 possible_clones; - - /** - * Whether this output can support interlaced modes - */ - Bool interlaceAllowed; - - /** - * Whether this output can support double scan modes - */ - Bool doubleScanAllowed; - - /** - * List of available modes on this output. - * - * This should be the list from get_modes(), plus perhaps additional - * compatible modes added later. - */ - DisplayModePtr probed_modes; - - /** - * Options parsed from the related monitor section - */ - OptionInfoPtr options; - - /** - * Configured monitor section - */ - XF86ConfMonitorPtr conf_monitor; - - /** - * Desired initial position - */ - int initial_x, initial_y; - - /** - * Desired initial rotation - */ - Rotation initial_rotation; - - /** - * Current connection status - * - * This indicates whether a monitor is known to be connected - * to this output or not, or whether there is no way to tell - */ - xf86OutputStatus status; - - /** EDID monitor information */ - xf86MonPtr MonInfo; - - /** subpixel order */ - int subpixel_order; - - /** Physical size of the currently attached output device. */ - int mm_width, mm_height; - - /** Output name */ - char *name; - - /** output-specific functions */ - const xf86OutputFuncsRec *funcs; - - /** driver private information */ - void *driver_private; - - /** Whether to use the old per-screen Monitor config section */ - Bool use_screen_monitor; - - /** For pre-init, whether the output should be excluded from the - * desktop when there are other viable outputs to use - */ - Bool non_desktop; - -#ifdef RANDR_12_INTERFACE - /** - * RandR 1.2 output structure. - * - * When RandR 1.2 is available, this points at the associated - * RandR output structure and is created when this output is created - */ - RROutputPtr randr_output; -#else - void *randr_output; -#endif - /** - * Desired initial panning - * Added in ABI version 2 - */ - BoxRec initialTotalArea; - BoxRec initialTrackingArea; - INT16 initialBorder[4]; - - struct xf86CrtcTileInfo tile_info; -}; - -typedef struct _xf86ProviderFuncs { - /** - * Called to allow the provider a chance to create properties after the - * RandR objects have been created. - */ - void - (*create_resources) (ScrnInfoPtr scrn); - - /** - * Callback when an provider's property has changed. - */ - Bool - (*set_property) (ScrnInfoPtr scrn, - Atom property, RRPropertyValuePtr value); - - /** - * Callback to get an updated property value - */ - Bool - (*get_property) (ScrnInfoPtr provider, Atom property); - -} xf86ProviderFuncsRec, *xf86ProviderFuncsPtr; - -#define XF86_LEASE_VERSION 1 - -struct _xf86Lease { - /** - * ABI versioning - */ - int version; - - /** - * Associated ScrnInfo - */ - ScrnInfoPtr scrn; - - /** - * Driver private - */ - void *driver_private; - - /** - * RandR lease - */ - RRLeasePtr randr_lease; - - /* - * Contents of the lease - */ - - /** - * Number of leased CRTCs - */ - int num_crtc; - - /** - * Number of leased outputs - */ - int num_output; - - /** - * Array of pointers to leased CRTCs - */ - RRCrtcPtr *crtcs; - - /** - * Array of pointers to leased outputs - */ - RROutputPtr *outputs; -}; - -typedef struct _xf86CrtcConfigFuncs { - /** - * Requests that the driver resize the screen. - * - * The driver is responsible for updating scrn->virtualX and scrn->virtualY. - * If the requested size cannot be set, the driver should leave those values - * alone and return FALSE. - * - * A naive driver that cannot reallocate the screen may simply change - * virtual[XY]. A more advanced driver will want to also change the - * devPrivate.ptr and devKind of the screen pixmap, update any offscreen - * pixmaps it may have moved, and change pScrn->displayWidth. - */ - Bool - (*resize) (ScrnInfoPtr scrn, int width, int height); - - /** - * Requests that the driver create a lease - */ - int (*create_lease)(RRLeasePtr lease, int *fd); - - /** - * Ask the driver to terminate a lease, freeing all - * driver resources - */ - void (*terminate_lease)(RRLeasePtr lease); -} xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr; - -/* - * The driver calls this when it detects that a lease - * has been terminated - */ -extern _X_EXPORT void -xf86CrtcLeaseTerminated(RRLeasePtr lease); - -extern _X_EXPORT void -xf86CrtcLeaseStarted(RRLeasePtr lease); - -typedef void (*xf86_crtc_notify_proc_ptr) (ScreenPtr pScreen); - -typedef struct _xf86CrtcConfig { - int num_output; - xf86OutputPtr *output; - /** - * compat_output is used whenever we deal - * with legacy code that only understands a single - * output. pScrn->modes will be loaded from this output, - * adjust frame will whack this output, etc. - */ - int compat_output; - - int num_crtc; - xf86CrtcPtr *crtc; - - int minWidth, minHeight; - int maxWidth, maxHeight; - - /* For crtc-based rotation */ - DamagePtr rotation_damage; - Bool rotation_damage_registered; - - /* DGA */ - unsigned int dga_flags; - unsigned long dga_address; - DGAModePtr dga_modes; - int dga_nmode; - int dga_width, dga_height, dga_stride; - DisplayModePtr dga_save_mode; - - const xf86CrtcConfigFuncsRec *funcs; - - CreateScreenResourcesProcPtr CreateScreenResources; - - CloseScreenProcPtr CloseScreen; - - /* Cursor information */ - xf86CursorInfoPtr cursor_info; - CursorPtr cursor; - CARD8 *cursor_image; - Bool cursor_on; - CARD32 cursor_fg, cursor_bg; - - /** - * Options parsed from the related device section - */ - OptionInfoPtr options; - - Bool debug_modes; - - /* wrap screen BlockHandler for rotation */ - ScreenBlockHandlerProcPtr BlockHandler; - - /* callback when crtc configuration changes */ - xf86_crtc_notify_proc_ptr xf86_crtc_notify; - - char *name; - const xf86ProviderFuncsRec *provider_funcs; -#ifdef RANDR_12_INTERFACE - RRProviderPtr randr_provider; -#else - void *randr_provider; -#endif -} xf86CrtcConfigRec, *xf86CrtcConfigPtr; - -extern _X_EXPORT int xf86CrtcConfigPrivateIndex; - -#define XF86_CRTC_CONFIG_PTR(p) ((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr)) - -static _X_INLINE xf86OutputPtr -xf86CompatOutput(ScrnInfoPtr pScrn) -{ - xf86CrtcConfigPtr config; - - if (xf86CrtcConfigPrivateIndex == -1) - return NULL; - config = XF86_CRTC_CONFIG_PTR(pScrn); - if (config->compat_output < 0) - return NULL; - return config->output[config->compat_output]; -} - -static _X_INLINE xf86CrtcPtr -xf86CompatCrtc(ScrnInfoPtr pScrn) -{ - xf86OutputPtr compat_output = xf86CompatOutput(pScrn); - - if (!compat_output) - return NULL; - return compat_output->crtc; -} - -static _X_INLINE RRCrtcPtr -xf86CompatRRCrtc(ScrnInfoPtr pScrn) -{ - xf86CrtcPtr compat_crtc = xf86CompatCrtc(pScrn); - - if (!compat_crtc) - return NULL; - return compat_crtc->randr_crtc; -} - -/* - * Initialize xf86CrtcConfig structure - */ - -extern _X_EXPORT void - xf86CrtcConfigInit(ScrnInfoPtr scrn, const xf86CrtcConfigFuncsRec * funcs); - -extern _X_EXPORT void - -xf86CrtcSetSizeRange(ScrnInfoPtr scrn, - int minWidth, int minHeight, int maxWidth, int maxHeight); - -/* - * Crtc functions - */ -extern _X_EXPORT xf86CrtcPtr -xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs); - -extern _X_EXPORT void - xf86CrtcDestroy(xf86CrtcPtr crtc); - -/** - * Sets the given video mode on the given crtc - */ - -extern _X_EXPORT Bool - -xf86CrtcSetModeTransform(xf86CrtcPtr crtc, DisplayModePtr mode, - Rotation rotation, RRTransformPtr transform, int x, - int y); - -extern _X_EXPORT Bool - -xf86CrtcSetMode(xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, - int x, int y); - -extern _X_EXPORT void - xf86CrtcSetOrigin(xf86CrtcPtr crtc, int x, int y); - -/* - * Assign crtc rotation during mode set - */ -extern _X_EXPORT Bool - xf86CrtcRotate(xf86CrtcPtr crtc); - -/* - * Clean up any rotation data, used when a crtc is turned off - * as well as when rotation is disabled. - */ -extern _X_EXPORT void - xf86RotateDestroy(xf86CrtcPtr crtc); - -/* - * free shadow memory allocated for all crtcs - */ -extern _X_EXPORT void - xf86RotateFreeShadow(ScrnInfoPtr pScrn); - -/* - * Clean up rotation during CloseScreen - */ -extern _X_EXPORT void - xf86RotateCloseScreen(ScreenPtr pScreen); - -/** - * Return whether any output is assigned to the crtc - */ -extern _X_EXPORT Bool - xf86CrtcInUse(xf86CrtcPtr crtc); - -/* - * Output functions - */ -extern _X_EXPORT xf86OutputPtr -xf86OutputCreate(ScrnInfoPtr scrn, - const xf86OutputFuncsRec * funcs, const char *name); - -extern _X_EXPORT void - xf86OutputUseScreenMonitor(xf86OutputPtr output, Bool use_screen_monitor); - -extern _X_EXPORT Bool - xf86OutputRename(xf86OutputPtr output, const char *name); - -extern _X_EXPORT void - xf86OutputDestroy(xf86OutputPtr output); - -extern _X_EXPORT void - xf86ProbeOutputModes(ScrnInfoPtr pScrn, int maxX, int maxY); - -extern _X_EXPORT void - xf86SetScrnInfoModes(ScrnInfoPtr pScrn); - -#ifdef RANDR_13_INTERFACE -#define ScreenInitRetType int -#else -#define ScreenInitRetType Bool -#endif - -extern _X_EXPORT ScreenInitRetType xf86CrtcScreenInit(ScreenPtr pScreen); - -extern _X_EXPORT void -xf86AssignNoOutputInitialSize(ScrnInfoPtr scrn, const OptionInfoRec *options, - int *no_output_width, int *no_output_height); - -extern _X_EXPORT Bool - xf86InitialConfiguration(ScrnInfoPtr pScrn, Bool canGrow); - -extern _X_EXPORT void - xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags); - -extern _X_EXPORT Bool - xf86SaveScreen(ScreenPtr pScreen, int mode); - -extern _X_EXPORT void - xf86DisableUnusedFunctions(ScrnInfoPtr pScrn); - -extern _X_EXPORT DisplayModePtr -xf86OutputFindClosestMode(xf86OutputPtr output, DisplayModePtr desired); - -extern _X_EXPORT Bool - -xf86SetSingleMode(ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation); - -/** - * Set the EDID information for the specified output - */ -extern _X_EXPORT void - xf86OutputSetEDID(xf86OutputPtr output, xf86MonPtr edid_mon); - -/** - * Set the TILE information for the specified output - */ -extern _X_EXPORT void -xf86OutputSetTile(xf86OutputPtr output, struct xf86CrtcTileInfo *tile_info); - -extern _X_EXPORT Bool -xf86OutputParseKMSTile(const char *tile_data, int tile_length, struct xf86CrtcTileInfo *tile_info); - -/** - * Return the list of modes supported by the EDID information - * stored in 'output' - */ -extern _X_EXPORT DisplayModePtr xf86OutputGetEDIDModes(xf86OutputPtr output); - -extern _X_EXPORT xf86MonPtr -xf86OutputGetEDID(xf86OutputPtr output, I2CBusPtr pDDCBus); - -/** - * Initialize dga for this screen - */ - -#ifdef XFreeXDGA -extern _X_EXPORT Bool - xf86DiDGAInit(ScreenPtr pScreen, unsigned long dga_address); - -/* this is the real function, used only internally */ -_X_INTERNAL Bool - _xf86_di_dga_init_internal(ScreenPtr pScreen); - -/** - * Re-initialize dga for this screen (as when the set of modes changes) - */ - -extern _X_EXPORT Bool - xf86DiDGAReInit(ScreenPtr pScreen); -#endif - -/* This is the real function, used only internally */ -_X_INTERNAL Bool - _xf86_di_dga_reinit_internal(ScreenPtr pScreen); - -/* - * Set the subpixel order reported for the screen using - * the information from the outputs - */ - -extern _X_EXPORT void - xf86CrtcSetScreenSubpixelOrder(ScreenPtr pScreen); - -/* - * Get a standard string name for a connector type - */ -extern _X_EXPORT const char *xf86ConnectorGetName(xf86ConnectorType connector); - -/* - * Using the desired mode information in each crtc, set - * modes (used in EnterVT functions, or at server startup) - */ - -extern _X_EXPORT Bool - xf86SetDesiredModes(ScrnInfoPtr pScrn); - -/** - * Initialize the CRTC-based cursor code. CRTC function vectors must - * contain relevant cursor setting functions. - * - * Driver should call this from ScreenInit function - */ -extern _X_EXPORT Bool - xf86_cursors_init(ScreenPtr screen, int max_width, int max_height, int flags); - -/** - * Superseded by xf86CursorResetCursor, which is getting called - * automatically when necessary. - */ -static _X_INLINE _X_DEPRECATED void xf86_reload_cursors(ScreenPtr screen) {} - -/** - * Called from EnterVT to turn the cursors back on - */ -extern _X_EXPORT Bool - xf86_show_cursors(ScrnInfoPtr scrn); - -/** - * Called by the driver to turn a single crtc's cursor off - */ -extern _X_EXPORT void -xf86_crtc_hide_cursor(xf86CrtcPtr crtc); - -/** - * Called by the driver to turn a single crtc's cursor on - */ -extern _X_EXPORT Bool -xf86_crtc_show_cursor(xf86CrtcPtr crtc); - -/** - * Called by the driver to turn cursors off - */ -extern _X_EXPORT void - xf86_hide_cursors(ScrnInfoPtr scrn); - -/** - * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time. - */ -extern _X_EXPORT void - xf86_cursors_fini(ScreenPtr screen); - -#ifdef XV -/* - * For overlay video, compute the relevant CRTC and - * clip video to that. - * wraps xf86XVClipVideoHelper() - */ - -extern _X_EXPORT Bool - -xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn, - xf86CrtcPtr * crtc_ret, - xf86CrtcPtr desired_crtc, - BoxPtr dst, - INT32 *xa, - INT32 *xb, - INT32 *ya, - INT32 *yb, - RegionPtr reg, INT32 width, INT32 height); -#endif - -extern _X_EXPORT xf86_crtc_notify_proc_ptr -xf86_wrap_crtc_notify(ScreenPtr pScreen, xf86_crtc_notify_proc_ptr new); - -extern _X_EXPORT void - xf86_unwrap_crtc_notify(ScreenPtr pScreen, xf86_crtc_notify_proc_ptr old); - -extern _X_EXPORT void - xf86_crtc_notify(ScreenPtr pScreen); - -/** - * Gamma - */ - -extern _X_EXPORT Bool - xf86_crtc_supports_gamma(ScrnInfoPtr pScrn); - -extern _X_EXPORT void -xf86ProviderSetup(ScrnInfoPtr scrn, - const xf86ProviderFuncsRec * funcs, const char *name); - -extern _X_EXPORT void -xf86DetachAllCrtc(ScrnInfoPtr scrn); - -Bool xf86OutputForceEnabled(xf86OutputPtr output); -#endif /* _XF86CRTC_H_ */ diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c deleted file mode 100644 index dba5f8877..000000000 --- a/hw/xfree86/modes/xf86Cursors.c +++ /dev/null @@ -1,702 +0,0 @@ -/* - * Copyright © 2007 Keith Packard - * Copyright © 2010-2011 Aaron Plattner - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include - -#include -#include "xf86.h" -#include "xf86DDC.h" -#include "xf86Crtc.h" -#include "xf86Modes.h" -#include "xf86RandR12.h" -#include "xf86CursorPriv.h" -#include "X11/extensions/render.h" -#include "X11/extensions/dpmsconst.h" -#include "X11/Xatom.h" -#include "picturestr.h" -#include "cursorstr.h" -#include "inputstr.h" - -/* - * Returns the rotation being performed by the server. If the driver indicates - * that it's handling the screen transform, then this returns RR_Rotate_0. - */ -static Rotation -xf86_crtc_cursor_rotation(xf86CrtcPtr crtc) -{ - if (crtc->driverIsPerformingTransform & XF86DriverTransformCursorImage) - return RR_Rotate_0; - return crtc->rotation; -} - -/* - * Given a screen coordinate, rotate back to a cursor source coordinate - */ -static void -xf86_crtc_rotate_coord(Rotation rotation, - int width, - int height, int x_dst, int y_dst, int *x_src, int *y_src) -{ - int t; - - switch (rotation & 0xf) { - case RR_Rotate_0: - break; - case RR_Rotate_90: - t = x_dst; - x_dst = width - y_dst - 1; - y_dst = t; - break; - case RR_Rotate_180: - x_dst = width - x_dst - 1; - y_dst = height - y_dst - 1; - break; - case RR_Rotate_270: - t = x_dst; - x_dst = y_dst; - y_dst = height - t - 1; - break; - } - if (rotation & RR_Reflect_X) - x_dst = width - x_dst - 1; - if (rotation & RR_Reflect_Y) - y_dst = height - y_dst - 1; - *x_src = x_dst; - *y_src = y_dst; -} - -/* - * Given a cursor source coordinate, rotate to a screen coordinate - */ -static void -xf86_crtc_rotate_coord_back(Rotation rotation, - int width, - int height, - int x_dst, int y_dst, int *x_src, int *y_src) -{ - int t; - - if (rotation & RR_Reflect_X) - x_dst = width - x_dst - 1; - if (rotation & RR_Reflect_Y) - y_dst = height - y_dst - 1; - - switch (rotation & 0xf) { - case RR_Rotate_0: - break; - case RR_Rotate_90: - t = x_dst; - x_dst = y_dst; - y_dst = width - t - 1; - break; - case RR_Rotate_180: - x_dst = width - x_dst - 1; - y_dst = height - y_dst - 1; - break; - case RR_Rotate_270: - t = x_dst; - x_dst = height - y_dst - 1; - y_dst = t; - break; - } - *x_src = x_dst; - *y_src = y_dst; -} - -struct cursor_bit { - CARD8 *byte; - char bitpos; -}; - -/* - * Convert an x coordinate to a position within the cursor bitmap - */ -static struct cursor_bit -cursor_bitpos(CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y, - Bool mask) -{ - const int flags = cursor_info->Flags; - const Bool interleaved = - ! !(flags & (HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 | - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8 | - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16 | - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32 | - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64)); - const int width = cursor_info->MaxWidth; - const int height = cursor_info->MaxHeight; - const int stride = interleaved ? width / 4 : width / 8; - - struct cursor_bit ret; - - image += y * stride; - - if (flags & HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK) - mask = !mask; - if (flags & HARDWARE_CURSOR_NIBBLE_SWAPPED) - x = (x & ~3) | (3 - (x & 3)); - if (((flags & HARDWARE_CURSOR_BIT_ORDER_MSBFIRST) == 0) == - (X_BYTE_ORDER == X_BIG_ENDIAN)) - x = (x & ~7) | (7 - (x & 7)); - if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1) - x = (x << 1) + mask; - else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8) - x = ((x & ~7) << 1) | (mask << 3) | (x & 7); - else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16) - x = ((x & ~15) << 1) | (mask << 4) | (x & 15); - else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32) - x = ((x & ~31) << 1) | (mask << 5) | (x & 31); - else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64) - x = ((x & ~63) << 1) | (mask << 6) | (x & 63); - else if (mask) - image += stride * height; - - ret.byte = image + (x / 8); - ret.bitpos = x & 7; - - return ret; -} - -/* - * Fetch one bit from a cursor bitmap - */ -static CARD8 -get_bit(CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y, Bool mask) -{ - struct cursor_bit bit = cursor_bitpos(image, cursor_info, x, y, mask); - - return (*bit.byte >> bit.bitpos) & 1; -} - -/* - * Set one bit in a cursor bitmap - */ -static void -set_bit(CARD8 *image, xf86CursorInfoPtr cursor_info, int x, int y, Bool mask) -{ - struct cursor_bit bit = cursor_bitpos(image, cursor_info, x, y, mask); - - *bit.byte |= 1 << bit.bitpos; -} - -/* - * Wrappers to deal with API compatibility with drivers that don't expose - * *_cursor_*_check - */ -static inline Bool -xf86_driver_has_show_cursor(xf86CrtcPtr crtc) -{ - return crtc->funcs->show_cursor_check || crtc->funcs->show_cursor; -} - -static inline Bool -xf86_driver_has_load_cursor_image(xf86CrtcPtr crtc) -{ - return crtc->funcs->load_cursor_image_check || crtc->funcs->load_cursor_image; -} - -static inline Bool -xf86_driver_has_load_cursor_argb(xf86CrtcPtr crtc) -{ - return crtc->funcs->load_cursor_argb_check || crtc->funcs->load_cursor_argb; -} - -static inline Bool -xf86_driver_show_cursor(xf86CrtcPtr crtc) -{ - if (crtc->funcs->show_cursor_check) - return crtc->funcs->show_cursor_check(crtc); - crtc->funcs->show_cursor(crtc); - return TRUE; -} - -static inline Bool -xf86_driver_load_cursor_image(xf86CrtcPtr crtc, CARD8 *cursor_image) -{ - if (crtc->funcs->load_cursor_image_check) - return crtc->funcs->load_cursor_image_check(crtc, cursor_image); - crtc->funcs->load_cursor_image(crtc, cursor_image); - return TRUE; -} - -static inline Bool -xf86_driver_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *cursor_argb) -{ - if (crtc->funcs->load_cursor_argb_check) - return crtc->funcs->load_cursor_argb_check(crtc, cursor_argb); - crtc->funcs->load_cursor_argb(crtc, cursor_argb); - return TRUE; -} - -/* - * Load a two color cursor into a driver that supports only ARGB cursors - */ -static Bool -xf86_crtc_convert_cursor_to_argb(xf86CrtcPtr crtc, unsigned char *src) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - CARD32 *cursor_image = (CARD32 *) xf86_config->cursor_image; - int x, y; - int xin, yin; - int flags = cursor_info->Flags; - CARD32 bits; - const Rotation rotation = xf86_crtc_cursor_rotation(crtc); - - crtc->cursor_argb = FALSE; - - for (y = 0; y < cursor_info->MaxHeight; y++) - for (x = 0; x < cursor_info->MaxWidth; x++) { - xf86_crtc_rotate_coord(rotation, - cursor_info->MaxWidth, - cursor_info->MaxHeight, x, y, &xin, &yin); - if (get_bit(src, cursor_info, xin, yin, TRUE) == - ((flags & HARDWARE_CURSOR_INVERT_MASK) == 0)) { - if (get_bit(src, cursor_info, xin, yin, FALSE)) - bits = xf86_config->cursor_fg; - else - bits = xf86_config->cursor_bg; - } - else - bits = 0; - cursor_image[y * cursor_info->MaxWidth + x] = bits; - } - return xf86_driver_load_cursor_argb(crtc, cursor_image); -} - -/* - * Set the colors for a two-color cursor (ignore for ARGB cursors) - */ -static void -xf86_set_cursor_colors(ScrnInfoPtr scrn, int bg, int fg) -{ - ScreenPtr screen = scrn->pScreen; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - CursorPtr cursor = xf86CurrentCursor(screen); - int c; - CARD8 *bits = cursor ? - dixLookupScreenPrivate(&cursor->devPrivates, CursorScreenKey, screen) - : NULL; - - /* Save ARGB versions of these colors */ - xf86_config->cursor_fg = (CARD32) fg | 0xff000000; - xf86_config->cursor_bg = (CARD32) bg | 0xff000000; - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled && !crtc->cursor_argb) { - if (xf86_driver_has_load_cursor_image(crtc)) - crtc->funcs->set_cursor_colors(crtc, bg, fg); - else if (bits) - xf86_crtc_convert_cursor_to_argb(crtc, bits); - } - } -} - -void -xf86_crtc_hide_cursor(xf86CrtcPtr crtc) -{ - if (crtc->cursor_shown) { - crtc->funcs->hide_cursor(crtc); - crtc->cursor_shown = FALSE; - } -} - -void -xf86_hide_cursors(ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - xf86_config->cursor_on = FALSE; - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled) - xf86_crtc_hide_cursor(crtc); - } -} - -Bool -xf86_crtc_show_cursor(xf86CrtcPtr crtc) -{ - if (!crtc->cursor_in_range) { - crtc->funcs->hide_cursor(crtc); - return TRUE; - } - - if (!crtc->cursor_shown) - crtc->cursor_shown = xf86_driver_show_cursor(crtc); - - return crtc->cursor_shown; -} - -Bool -xf86_show_cursors(ScrnInfoPtr scrn) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - xf86_config->cursor_on = TRUE; - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled && !xf86_crtc_show_cursor(crtc)) - return FALSE; - } - - return TRUE; -} - -static void -xf86_crtc_transform_cursor_position(xf86CrtcPtr crtc, int *x, int *y) -{ - ScrnInfoPtr scrn = crtc->scrn; - ScreenPtr screen = scrn->pScreen; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&screen->devPrivates, - xf86CursorScreenKey); - int dx, dy, t; - Bool swap_reflection = FALSE; - - *x = *x - crtc->x + ScreenPriv->HotX; - *y = *y - crtc->y + ScreenPriv->HotY; - - switch (crtc->rotation & 0xf) { - case RR_Rotate_0: - break; - case RR_Rotate_90: - t = *x; - *x = *y; - *y = crtc->mode.VDisplay - t - 1; - swap_reflection = TRUE; - break; - case RR_Rotate_180: - *x = crtc->mode.HDisplay - *x - 1; - *y = crtc->mode.VDisplay - *y - 1; - break; - case RR_Rotate_270: - t = *x; - *x = crtc->mode.HDisplay - *y - 1; - *y = t; - swap_reflection = TRUE; - break; - } - - if (swap_reflection) { - if (crtc->rotation & RR_Reflect_Y) - *x = crtc->mode.HDisplay - *x - 1; - if (crtc->rotation & RR_Reflect_X) - *y = crtc->mode.VDisplay - *y - 1; - } else { - if (crtc->rotation & RR_Reflect_X) - *x = crtc->mode.HDisplay - *x - 1; - if (crtc->rotation & RR_Reflect_Y) - *y = crtc->mode.VDisplay - *y - 1; - } - - /* - * Transform position of cursor upper left corner - */ - xf86_crtc_rotate_coord_back(crtc->rotation, cursor_info->MaxWidth, - cursor_info->MaxHeight, ScreenPriv->HotX, - ScreenPriv->HotY, &dx, &dy); - *x -= dx; - *y -= dy; -} - -static void -xf86_crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - DisplayModePtr mode = &crtc->mode; - int crtc_x = x, crtc_y = y; - - /* - * Transform position of cursor on screen - */ - if (crtc->rotation != RR_Rotate_0) - xf86_crtc_transform_cursor_position(crtc, &crtc_x, &crtc_y); - else { - crtc_x -= crtc->x; - crtc_y -= crtc->y; - } - - /* - * Disable the cursor when it is outside the viewport - */ - if (crtc_x >= mode->HDisplay || crtc_y >= mode->VDisplay || - crtc_x <= -cursor_info->MaxWidth || crtc_y <= -cursor_info->MaxHeight) { - crtc->cursor_in_range = FALSE; - xf86_crtc_hide_cursor(crtc); - } else { - crtc->cursor_in_range = TRUE; - if (crtc->driverIsPerformingTransform & XF86DriverTransformCursorPosition) - crtc->funcs->set_cursor_position(crtc, x, y); - else - crtc->funcs->set_cursor_position(crtc, crtc_x, crtc_y); - xf86_crtc_show_cursor(crtc); - } -} - -static void -xf86_set_cursor_position(ScrnInfoPtr scrn, int x, int y) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - /* undo what xf86HWCurs did to the coordinates */ - x += scrn->frameX0; - y += scrn->frameY0; - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled) - xf86_crtc_set_cursor_position(crtc, x, y); - } -} - -/* - * Load a two-color cursor into a crtc, performing rotation as needed - */ -static Bool -xf86_crtc_load_cursor_image(xf86CrtcPtr crtc, CARD8 *src) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - CARD8 *cursor_image; - const Rotation rotation = xf86_crtc_cursor_rotation(crtc); - - crtc->cursor_argb = FALSE; - - if (rotation == RR_Rotate_0) - cursor_image = src; - else { - int x, y; - int xin, yin; - int stride = cursor_info->MaxWidth >> 2; - - cursor_image = xf86_config->cursor_image; - memset(cursor_image, 0, cursor_info->MaxHeight * stride); - - for (y = 0; y < cursor_info->MaxHeight; y++) - for (x = 0; x < cursor_info->MaxWidth; x++) { - xf86_crtc_rotate_coord(rotation, - cursor_info->MaxWidth, - cursor_info->MaxHeight, - x, y, &xin, &yin); - if (get_bit(src, cursor_info, xin, yin, FALSE)) - set_bit(cursor_image, cursor_info, x, y, FALSE); - if (get_bit(src, cursor_info, xin, yin, TRUE)) - set_bit(cursor_image, cursor_info, x, y, TRUE); - } - } - return xf86_driver_load_cursor_image(crtc, cursor_image); -} - -/* - * Load a cursor image into all active CRTCs - */ -static Bool -xf86_load_cursor_image(ScrnInfoPtr scrn, unsigned char *src) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - xf86_config->cursor = xf86CurrentCursor(scrn->pScreen); - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled) { - if (xf86_driver_has_load_cursor_image(crtc)) { - if (!xf86_crtc_load_cursor_image(crtc, src)) - return FALSE; - } else if (xf86_driver_has_load_cursor_argb(crtc)) { - if (!xf86_crtc_convert_cursor_to_argb(crtc, src)) - return FALSE; - } else - return FALSE; - } - } - return TRUE; -} - -static Bool -xf86_use_hw_cursor(ScreenPtr screen, CursorPtr cursor) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - int c; - - if (cursor->bits->width > cursor_info->MaxWidth || - cursor->bits->height > cursor_info->MaxHeight) - return FALSE; - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (!crtc->enabled) - continue; - - if (crtc->transformPresent) - return FALSE; - } - - return TRUE; -} - -static Bool -xf86_use_hw_cursor_argb(ScreenPtr screen, CursorPtr cursor) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - - if (!xf86_use_hw_cursor(screen, cursor)) - return FALSE; - - /* Make sure ARGB support is available */ - if ((cursor_info->Flags & HARDWARE_CURSOR_ARGB) == 0) - return FALSE; - - return TRUE; -} - -static Bool -xf86_crtc_load_cursor_argb(xf86CrtcPtr crtc, CursorPtr cursor) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; - CARD32 *cursor_image = (CARD32 *) xf86_config->cursor_image; - CARD32 *cursor_source = (CARD32 *) cursor->bits->argb; - int x, y; - int xin, yin; - CARD32 bits; - int source_width = cursor->bits->width; - int source_height = cursor->bits->height; - int image_width = cursor_info->MaxWidth; - int image_height = cursor_info->MaxHeight; - const Rotation rotation = xf86_crtc_cursor_rotation(crtc); - - for (y = 0; y < image_height; y++) - for (x = 0; x < image_width; x++) { - xf86_crtc_rotate_coord(rotation, image_width, image_height, x, y, - &xin, &yin); - if (xin < source_width && yin < source_height) - bits = cursor_source[yin * source_width + xin]; - else - bits = 0; - cursor_image[y * image_width + x] = bits; - } - - return xf86_driver_load_cursor_argb(crtc, cursor_image); -} - -static Bool -xf86_load_cursor_argb(ScrnInfoPtr scrn, CursorPtr cursor) -{ - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - xf86_config->cursor = cursor; - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->enabled) - if (!xf86_crtc_load_cursor_argb(crtc, cursor)) - return FALSE; - } - return TRUE; -} - -Bool -xf86_cursors_init(ScreenPtr screen, int max_width, int max_height, int flags) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - xf86CursorInfoPtr cursor_info; - - cursor_info = xf86CreateCursorInfoRec(); - if (!cursor_info) - return FALSE; - - xf86_config->cursor_image = malloc(max_width * max_height * 4); - - if (!xf86_config->cursor_image) { - xf86DestroyCursorInfoRec(cursor_info); - return FALSE; - } - - xf86_config->cursor_info = cursor_info; - - cursor_info->MaxWidth = max_width; - cursor_info->MaxHeight = max_height; - cursor_info->Flags = flags; - - cursor_info->SetCursorColors = xf86_set_cursor_colors; - cursor_info->SetCursorPosition = xf86_set_cursor_position; - cursor_info->LoadCursorImageCheck = xf86_load_cursor_image; - cursor_info->HideCursor = xf86_hide_cursors; - cursor_info->ShowCursorCheck = xf86_show_cursors; - cursor_info->UseHWCursor = xf86_use_hw_cursor; - if (flags & HARDWARE_CURSOR_ARGB) { - cursor_info->UseHWCursorARGB = xf86_use_hw_cursor_argb; - cursor_info->LoadCursorARGBCheck = xf86_load_cursor_argb; - } - - xf86_hide_cursors(scrn); - - return xf86InitCursor(screen, cursor_info); -} - -/** - * Clean up CRTC-based cursor code - */ -void -xf86_cursors_fini(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - - if (xf86_config->cursor_info) { - xf86DestroyCursorInfoRec(xf86_config->cursor_info); - xf86_config->cursor_info = NULL; - } - free(xf86_config->cursor_image); - xf86_config->cursor_image = NULL; - xf86_config->cursor = NULL; -} diff --git a/hw/xfree86/modes/xf86DiDGA.c b/hw/xfree86/modes/xf86DiDGA.c deleted file mode 100644 index 368649852..000000000 --- a/hw/xfree86/modes/xf86DiDGA.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86DDC.h" -#include "xf86_OSproc.h" -#include "dgaproc.h" -#include "xf86Crtc.h" -#include "xf86Modes.h" -#include "gcstruct.h" -#include "scrnintstr.h" -#include "windowstr.h" - -static Bool -xf86_dga_get_modes(ScreenPtr pScreen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - DGAModePtr modes, mode; - DisplayModePtr display_mode; - int bpp = scrn->bitsPerPixel >> 3; - int num; - - num = 0; - display_mode = scrn->modes; - while (display_mode) { - num++; - display_mode = display_mode->next; - if (display_mode == scrn->modes) - break; - } - - if (!num) - return FALSE; - - modes = xallocarray(num, sizeof(DGAModeRec)); - if (!modes) - return FALSE; - - num = 0; - display_mode = scrn->modes; - while (display_mode) { - mode = modes + num++; - - mode->mode = display_mode; - mode->flags = DGA_CONCURRENT_ACCESS; - if (display_mode->Flags & V_DBLSCAN) - mode->flags |= DGA_DOUBLESCAN; - if (display_mode->Flags & V_INTERLACE) - mode->flags |= DGA_INTERLACED; - mode->byteOrder = scrn->imageByteOrder; - mode->depth = scrn->depth; - mode->bitsPerPixel = scrn->bitsPerPixel; - mode->red_mask = scrn->mask.red; - mode->green_mask = scrn->mask.green; - mode->blue_mask = scrn->mask.blue; - mode->visualClass = (bpp == 1) ? PseudoColor : TrueColor; - mode->viewportWidth = display_mode->HDisplay; - mode->viewportHeight = display_mode->VDisplay; - mode->xViewportStep = (bpp == 3) ? 2 : 1; - mode->yViewportStep = 1; - mode->viewportFlags = DGA_FLIP_RETRACE; - mode->offset = 0; - mode->address = 0; - mode->imageWidth = mode->viewportWidth; - mode->imageHeight = mode->viewportHeight; - mode->bytesPerScanline = (mode->imageWidth * scrn->bitsPerPixel) >> 3; - mode->pixmapWidth = mode->imageWidth; - mode->pixmapHeight = mode->imageHeight; - mode->maxViewportX = 0; - mode->maxViewportY = 0; - - display_mode = display_mode->next; - if (display_mode == scrn->modes) - break; - } - free(xf86_config->dga_modes); - xf86_config->dga_nmode = num; - xf86_config->dga_modes = modes; - return TRUE; -} - -static Bool -xf86_dga_set_mode(ScrnInfoPtr scrn, DGAModePtr display_mode) -{ - ScreenPtr pScreen = scrn->pScreen; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - - if (!display_mode) { - if (xf86_config->dga_save_mode) { - xf86SwitchMode(pScreen, xf86_config->dga_save_mode); - xf86_config->dga_save_mode = NULL; - } - } - else { - if (!xf86_config->dga_save_mode) { - xf86_config->dga_save_mode = scrn->currentMode; - xf86SwitchMode(pScreen, display_mode->mode); - } - } - return TRUE; -} - -static int -xf86_dga_get_viewport(ScrnInfoPtr scrn) -{ - return 0; -} - -static void -xf86_dga_set_viewport(ScrnInfoPtr scrn, int x, int y, int flags) -{ - scrn->AdjustFrame(scrn, x, y); -} - -static Bool -xf86_dga_open_framebuffer(ScrnInfoPtr scrn, - char **name, - unsigned char **mem, int *size, int *offset, - int *flags) -{ - return FALSE; -} - -static void -xf86_dga_close_framebuffer(ScrnInfoPtr scrn) -{ -} - -static DGAFunctionRec xf86_dga_funcs = { - xf86_dga_open_framebuffer, - xf86_dga_close_framebuffer, - xf86_dga_set_mode, - xf86_dga_set_viewport, - xf86_dga_get_viewport, - NULL, - NULL, - NULL, - NULL -}; - -Bool -xf86DiDGAReInit(ScreenPtr pScreen) -{ - return TRUE; -} - -Bool -_xf86_di_dga_reinit_internal(ScreenPtr pScreen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - - if (!DGAScreenAvailable(pScreen)) - return TRUE; - - if (!xf86_dga_get_modes(pScreen)) - return FALSE; - - return DGAReInitModes(pScreen, xf86_config->dga_modes, - xf86_config->dga_nmode); -} - -Bool -xf86DiDGAInit(ScreenPtr pScreen, unsigned long dga_address) -{ - return TRUE; -} - -Bool -_xf86_di_dga_init_internal(ScreenPtr pScreen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - - xf86_config->dga_flags = 0; - xf86_config->dga_address = 0; - xf86_config->dga_width = 0; - xf86_config->dga_height = 0; - xf86_config->dga_stride = 0; - - if (!xf86_dga_get_modes(pScreen)) - return FALSE; - - return DGAInit(pScreen, &xf86_dga_funcs, xf86_config->dga_modes, - xf86_config->dga_nmode); -} diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c deleted file mode 100644 index 1ac573867..000000000 --- a/hw/xfree86/modes/xf86EdidModes.c +++ /dev/null @@ -1,1229 +0,0 @@ -/* - * Copyright 2006 Luc Verhaegen. - * Copyright 2008 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, 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 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -/** - * @file This file covers code to convert a xf86MonPtr containing EDID-probed - * information into a list of modes, including applying monitor-specific - * quirks to fix broken EDID data. - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#define _PARSE_EDID_ -#include "xf86.h" -#include "xf86DDC.h" -#include -#include "property.h" -#include "propertyst.h" -#include "xf86Crtc.h" -#include -#include - -static void -handle_detailed_rblank(struct detailed_monitor_section *det_mon, void *data) -{ - if (det_mon->type == DS_RANGES) - if (det_mon->section.ranges.supported_blanking & CVT_REDUCED) - *(Bool *) data = TRUE; -} - -static Bool -xf86MonitorSupportsReducedBlanking(xf86MonPtr DDC) -{ - /* EDID 1.4 explicitly defines RB support */ - if (DDC->ver.revision >= 4) { - Bool ret = FALSE; - - xf86ForEachDetailedBlock(DDC, handle_detailed_rblank, &ret); - return ret; - } - - /* For anything older, assume digital means RB support. Boo. */ - if (DDC->features.input_type) - return TRUE; - - return FALSE; -} - -static Bool -quirk_prefer_large_60(int scrnIndex, xf86MonPtr DDC) -{ - /* Belinea 10 15 55 */ - if (memcmp(DDC->vendor.name, "MAX", 4) == 0 && - ((DDC->vendor.prod_id == 1516) || (DDC->vendor.prod_id == 0x77e))) - return TRUE; - - /* Acer AL1706 */ - if (memcmp(DDC->vendor.name, "ACR", 4) == 0 && DDC->vendor.prod_id == 44358) - return TRUE; - - /* Bug #10814: Samsung SyncMaster 225BW */ - if (memcmp(DDC->vendor.name, "SAM", 4) == 0 && DDC->vendor.prod_id == 596) - return TRUE; - - /* Bug #10545: Samsung SyncMaster 226BW */ - if (memcmp(DDC->vendor.name, "SAM", 4) == 0 && DDC->vendor.prod_id == 638) - return TRUE; - - /* Acer F51 */ - if (memcmp(DDC->vendor.name, "API", 4) == 0 && - DDC->vendor.prod_id == 0x7602) - return TRUE; - - return FALSE; -} - -static Bool -quirk_prefer_large_75(int scrnIndex, xf86MonPtr DDC) -{ - /* Bug #11603: Funai Electronics PM36B */ - if (memcmp(DDC->vendor.name, "FCM", 4) == 0 && DDC->vendor.prod_id == 13600) - return TRUE; - - return FALSE; -} - -static Bool -quirk_detailed_h_in_cm(int scrnIndex, xf86MonPtr DDC) -{ - /* Bug #11603: Funai Electronics PM36B */ - if (memcmp(DDC->vendor.name, "FCM", 4) == 0 && DDC->vendor.prod_id == 13600) - return TRUE; - - return FALSE; -} - -static Bool -quirk_detailed_v_in_cm(int scrnIndex, xf86MonPtr DDC) -{ - /* Bug #11603: Funai Electronics PM36B */ - if (memcmp(DDC->vendor.name, "FCM", 4) == 0 && DDC->vendor.prod_id == 13600) - return TRUE; - - /* Bug #21000: LGPhilipsLCD LP154W01-TLAJ */ - if (memcmp(DDC->vendor.name, "LPL", 4) == 0 && DDC->vendor.prod_id == 47360) - return TRUE; - - /* Bug #10304: LGPhilipsLCD LP154W01-A5 */ - if (memcmp(DDC->vendor.name, "LPL", 4) == 0 && DDC->vendor.prod_id == 0) - return TRUE; - - /* Bug #24482: LGPhilipsLCD LP154W01-TLA1 */ - if (memcmp(DDC->vendor.name, "LPL", 4) == 0 && - DDC->vendor.prod_id == 0x2a00) - return TRUE; - - /* Bug #28414: HP Compaq NC8430 LP154W01-TLA8 */ - if (memcmp(DDC->vendor.name, "LPL", 4) == 0 && DDC->vendor.prod_id == 5750) - return TRUE; - - /* Bug #21750: Samsung Syncmaster 2333HD */ - if (memcmp(DDC->vendor.name, "SAM", 4) == 0 && DDC->vendor.prod_id == 1157) - return TRUE; - - return FALSE; -} - -static Bool -quirk_detailed_use_maximum_size(int scrnIndex, xf86MonPtr DDC) -{ - /* ADA 1024x600 7" display */ - if (memcmp(DDC->vendor.name, "ADA", 4) == 0 && - DDC->vendor.prod_id == 4) - return TRUE; - - /* Bug #21324: Iiyama Vision Master 450 */ - if (memcmp(DDC->vendor.name, "IVM", 4) == 0 && DDC->vendor.prod_id == 6400) - return TRUE; - - /* Bug #41141: Acer Aspire One */ - if (memcmp(DDC->vendor.name, "LGD", 4) == 0 && - DDC->vendor.prod_id == 0x7f01) - return TRUE; - - /* Sony Vaio Pro 13 */ - if (memcmp(DDC->vendor.name, "MEI", 4) == 0 && - DDC->vendor.prod_id == 0x96a2) - return TRUE; - - return FALSE; -} - -static Bool -quirk_135_clock_too_high(int scrnIndex, xf86MonPtr DDC) -{ - /* Envision Peripherals, Inc. EN-7100e. See bug #9550. */ - if (memcmp(DDC->vendor.name, "EPI", 4) == 0 && DDC->vendor.prod_id == 59264) - return TRUE; - - return FALSE; -} - -static Bool -quirk_first_detailed_preferred(int scrnIndex, xf86MonPtr DDC) -{ - /* Philips 107p5 CRT. Reported on xorg@ with pastebin. */ - if (memcmp(DDC->vendor.name, "PHL", 4) == 0 && DDC->vendor.prod_id == 57364) - return TRUE; - - /* Proview AY765C 17" LCD. See bug #15160 */ - if (memcmp(DDC->vendor.name, "PTS", 4) == 0 && DDC->vendor.prod_id == 765) - return TRUE; - - /* ACR of some sort RH #284231 */ - if (memcmp(DDC->vendor.name, "ACR", 4) == 0 && DDC->vendor.prod_id == 2423) - return TRUE; - - /* Peacock Ergovision 19. See rh#492359 */ - if (memcmp(DDC->vendor.name, "PEA", 4) == 0 && DDC->vendor.prod_id == 9003) - return TRUE; - - return FALSE; -} - -static Bool -quirk_detailed_sync_pp(int scrnIndex, xf86MonPtr DDC) -{ - /* Bug #12439: Samsung SyncMaster 205BW */ - if (memcmp(DDC->vendor.name, "SAM", 4) == 0 && DDC->vendor.prod_id == 541) - return TRUE; - return FALSE; -} - -/* This should probably be made more generic */ -static Bool -quirk_dvi_single_link(int scrnIndex, xf86MonPtr DDC) -{ - /* Red Hat bug #453106: Apple 23" Cinema Display */ - if (memcmp(DDC->vendor.name, "APL", 4) == 0 && - DDC->vendor.prod_id == 0x921c) - return TRUE; - return FALSE; -} - -typedef struct { - Bool (*detect) (int scrnIndex, xf86MonPtr DDC); - ddc_quirk_t quirk; - const char *description; -} ddc_quirk_map_t; - -static const ddc_quirk_map_t ddc_quirks[] = { - { - quirk_prefer_large_60, DDC_QUIRK_PREFER_LARGE_60, - "Detailed timing is not preferred, use largest mode at 60Hz"}, - { - quirk_135_clock_too_high, DDC_QUIRK_135_CLOCK_TOO_HIGH, - "Recommended 135MHz pixel clock is too high"}, - { - quirk_prefer_large_75, DDC_QUIRK_PREFER_LARGE_75, - "Detailed timing is not preferred, use largest mode at 75Hz"}, - { - quirk_detailed_h_in_cm, DDC_QUIRK_DETAILED_H_IN_CM, - "Detailed timings give horizontal size in cm."}, - { - quirk_detailed_v_in_cm, DDC_QUIRK_DETAILED_V_IN_CM, - "Detailed timings give vertical size in cm."}, - { - quirk_detailed_use_maximum_size, DDC_QUIRK_DETAILED_USE_MAXIMUM_SIZE, - "Use maximum size instead of detailed timing sizes."}, - { - quirk_first_detailed_preferred, DDC_QUIRK_FIRST_DETAILED_PREFERRED, - "First detailed timing was not marked as preferred."}, - { - quirk_detailed_sync_pp, DDC_QUIRK_DETAILED_SYNC_PP, - "Use +hsync +vsync for detailed timing."}, - { - quirk_dvi_single_link, DDC_QUIRK_DVI_SINGLE_LINK, - "Forcing maximum pixel clock to single DVI link."}, - { - NULL, DDC_QUIRK_NONE, - "No known quirks"}, -}; - -/* - * These more or less come from the DMT spec. The 720x400 modes are - * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75 - * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode - * should be 1152x870, again for the Mac, but instead we use the x864 DMT - * mode. - * - * The DMT modes have been fact-checked; the rest are mild guesses. - */ -#define MODEPREFIX NULL, NULL, NULL, 0, M_T_DRIVER -#define MODESUFFIX 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0 - -static const DisplayModeRec DDCEstablishedModes[17] = { - {MODEPREFIX, 40000, 800, 840, 968, 1056, 0, 600, 601, 605, 628, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 800x600@60Hz */ - {MODEPREFIX, 36000, 800, 824, 896, 1024, 0, 600, 601, 603, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 800x600@56Hz */ - {MODEPREFIX, 31500, 640, 656, 720, 840, 0, 480, 481, 484, 500, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 640x480@75Hz */ - {MODEPREFIX, 31500, 640, 664, 704, 832, 0, 480, 489, 492, 520, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 640x480@72Hz */ - {MODEPREFIX, 30240, 640, 704, 768, 864, 0, 480, 483, 486, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 640x480@67Hz */ - {MODEPREFIX, 25175, 640, 656, 752, 800, 0, 480, 490, 492, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 640x480@60Hz */ - {MODEPREFIX, 35500, 720, 738, 846, 900, 0, 400, 421, 423, 449, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 720x400@88Hz */ - {MODEPREFIX, 28320, 720, 738, 846, 900, 0, 400, 412, 414, 449, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 720x400@70Hz */ - {MODEPREFIX, 135000, 1280, 1296, 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x1024@75Hz */ - {MODEPREFIX, 78750, 1024, 1040, 1136, 1312, 0, 768, 769, 772, 800, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1024x768@75Hz */ - {MODEPREFIX, 75000, 1024, 1048, 1184, 1328, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 1024x768@70Hz */ - {MODEPREFIX, 65000, 1024, 1048, 1184, 1344, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 1024x768@60Hz */ - {MODEPREFIX, 44900, 1024, 1032, 1208, 1264, 0, 768, 768, 772, 817, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX}, /* 1024x768@43Hz */ - {MODEPREFIX, 57284, 832, 864, 928, 1152, 0, 624, 625, 628, 667, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 832x624@75Hz */ - {MODEPREFIX, 49500, 800, 816, 896, 1056, 0, 600, 601, 604, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 800x600@75Hz */ - {MODEPREFIX, 50000, 800, 856, 976, 1040, 0, 600, 637, 643, 666, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 800x600@72Hz */ - {MODEPREFIX, 108000, 1152, 1216, 1344, 1600, 0, 864, 865, 868, 900, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1152x864@75Hz */ -}; - -static DisplayModePtr -DDCModesFromEstablished(int scrnIndex, struct established_timings *timing, - ddc_quirk_t quirks) -{ - DisplayModePtr Modes = NULL, Mode = NULL; - CARD32 bits = (timing->t1) | (timing->t2 << 8) | - ((timing->t_manu & 0x80) << 9); - int i; - - for (i = 0; i < 17; i++) { - if (bits & (0x01 << i)) { - Mode = xf86DuplicateMode(&DDCEstablishedModes[i]); - Modes = xf86ModesAdd(Modes, Mode); - } - } - - return Modes; -} - -/* Autogenerated from the DMT spec */ -const DisplayModeRec DMTModes[] = { - {MODEPREFIX, 31500, 640, 672, 736, 832, 0, 350, 382, 385, 445, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 640x350@85Hz */ - {MODEPREFIX, 31500, 640, 672, 736, 832, 0, 400, 401, 404, 445, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 640x400@85Hz */ - {MODEPREFIX, 35500, 720, 756, 828, 936, 0, 400, 401, 404, 446, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 720x400@85Hz */ - {MODEPREFIX, 25175, 640, 656, 752, 800, 0, 480, 490, 492, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 640x480@60Hz */ - {MODEPREFIX, 31500, 640, 664, 704, 832, 0, 480, 489, 492, 520, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 640x480@72Hz */ - {MODEPREFIX, 31500, 640, 656, 720, 840, 0, 480, 481, 484, 500, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 640x480@75Hz */ - {MODEPREFIX, 36000, 640, 696, 752, 832, 0, 480, 481, 484, 509, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 640x480@85Hz */ - {MODEPREFIX, 36000, 800, 824, 896, 1024, 0, 600, 601, 603, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 800x600@56Hz */ - {MODEPREFIX, 40000, 800, 840, 968, 1056, 0, 600, 601, 605, 628, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 800x600@60Hz */ - {MODEPREFIX, 50000, 800, 856, 976, 1040, 0, 600, 637, 643, 666, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 800x600@72Hz */ - {MODEPREFIX, 49500, 800, 816, 896, 1056, 0, 600, 601, 604, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 800x600@75Hz */ - {MODEPREFIX, 56250, 800, 832, 896, 1048, 0, 600, 601, 604, 631, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 800x600@85Hz */ - {MODEPREFIX, 73250, 800, 848, 880, 960, 0, 600, 603, 607, 636, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 800x600@120Hz RB */ - {MODEPREFIX, 33750, 848, 864, 976, 1088, 0, 480, 486, 494, 517, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 848x480@60Hz */ - {MODEPREFIX, 44900, 1024, 1032, 1208, 1264, 0, 768, 768, 772, 817, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX}, /* 1024x768@43Hz (interlaced) */ - {MODEPREFIX, 65000, 1024, 1048, 1184, 1344, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 1024x768@60Hz */ - {MODEPREFIX, 75000, 1024, 1048, 1184, 1328, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* 1024x768@70Hz */ - {MODEPREFIX, 78750, 1024, 1040, 1136, 1312, 0, 768, 769, 772, 800, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1024x768@75Hz */ - {MODEPREFIX, 94500, 1024, 1072, 1168, 1376, 0, 768, 769, 772, 808, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1024x768@85Hz */ - {MODEPREFIX, 115500, 1024, 1072, 1104, 1184, 0, 768, 771, 775, 813, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1024x768@120Hz RB */ - {MODEPREFIX, 108000, 1152, 1216, 1344, 1600, 0, 864, 865, 868, 900, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1152x864@75Hz */ - {MODEPREFIX, 68250, 1280, 1328, 1360, 1440, 0, 768, 771, 778, 790, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1280x768@60Hz RB */ - {MODEPREFIX, 79500, 1280, 1344, 1472, 1664, 0, 768, 771, 778, 798, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x768@60Hz */ - {MODEPREFIX, 102250, 1280, 1360, 1488, 1696, 0, 768, 771, 778, 805, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x768@75Hz */ - {MODEPREFIX, 117500, 1280, 1360, 1496, 1712, 0, 768, 771, 778, 809, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x768@85Hz */ - {MODEPREFIX, 140250, 1280, 1328, 1360, 1440, 0, 768, 771, 778, 813, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1280x768@120Hz RB */ - {MODEPREFIX, 71000, 1280, 1328, 1360, 1440, 0, 800, 803, 809, 823, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1280x800@60Hz RB */ - {MODEPREFIX, 83500, 1280, 1352, 1480, 1680, 0, 800, 803, 809, 831, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x800@60Hz */ - {MODEPREFIX, 106500, 1280, 1360, 1488, 1696, 0, 800, 803, 809, 838, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x800@75Hz */ - {MODEPREFIX, 122500, 1280, 1360, 1496, 1712, 0, 800, 803, 809, 843, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x800@85Hz */ - {MODEPREFIX, 146250, 1280, 1328, 1360, 1440, 0, 800, 803, 809, 847, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1280x800@120Hz RB */ - {MODEPREFIX, 108000, 1280, 1376, 1488, 1800, 0, 960, 961, 964, 1000, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x960@60Hz */ - {MODEPREFIX, 148500, 1280, 1344, 1504, 1728, 0, 960, 961, 964, 1011, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x960@85Hz */ - {MODEPREFIX, 175500, 1280, 1328, 1360, 1440, 0, 960, 963, 967, 1017, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1280x960@120Hz RB */ - {MODEPREFIX, 108000, 1280, 1328, 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x1024@60Hz */ - {MODEPREFIX, 135000, 1280, 1296, 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x1024@75Hz */ - {MODEPREFIX, 157500, 1280, 1344, 1504, 1728, 0, 1024, 1025, 1028, 1072, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1280x1024@85Hz */ - {MODEPREFIX, 187250, 1280, 1328, 1360, 1440, 0, 1024, 1027, 1034, 1084, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1280x1024@120Hz RB */ - {MODEPREFIX, 85500, 1360, 1424, 1536, 1792, 0, 768, 771, 777, 795, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1360x768@60Hz */ - {MODEPREFIX, 148250, 1360, 1408, 1440, 1520, 0, 768, 771, 776, 813, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1360x768@120Hz RB */ - {MODEPREFIX, 101000, 1400, 1448, 1480, 1560, 0, 1050, 1053, 1057, 1080, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1400x1050@60Hz RB */ - {MODEPREFIX, 121750, 1400, 1488, 1632, 1864, 0, 1050, 1053, 1057, 1089, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1400x1050@60Hz */ - {MODEPREFIX, 156000, 1400, 1504, 1648, 1896, 0, 1050, 1053, 1057, 1099, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1400x1050@75Hz */ - {MODEPREFIX, 179500, 1400, 1504, 1656, 1912, 0, 1050, 1053, 1057, 1105, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1400x1050@85Hz */ - {MODEPREFIX, 208000, 1400, 1448, 1480, 1560, 0, 1050, 1053, 1057, 1112, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1400x1050@120Hz RB */ - {MODEPREFIX, 88750, 1440, 1488, 1520, 1600, 0, 900, 903, 909, 926, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1440x900@60Hz RB */ - {MODEPREFIX, 106500, 1440, 1520, 1672, 1904, 0, 900, 903, 909, 934, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1440x900@60Hz */ - {MODEPREFIX, 136750, 1440, 1536, 1688, 1936, 0, 900, 903, 909, 942, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1440x900@75Hz */ - {MODEPREFIX, 157000, 1440, 1544, 1696, 1952, 0, 900, 903, 909, 948, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1440x900@85Hz */ - {MODEPREFIX, 182750, 1440, 1488, 1520, 1600, 0, 900, 903, 909, 953, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1440x900@120Hz RB */ - {MODEPREFIX, 162000, 1600, 1664, 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1600x1200@60Hz */ - {MODEPREFIX, 175500, 1600, 1664, 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1600x1200@65Hz */ - {MODEPREFIX, 189000, 1600, 1664, 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1600x1200@70Hz */ - {MODEPREFIX, 202500, 1600, 1664, 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1600x1200@75Hz */ - {MODEPREFIX, 229500, 1600, 1664, 1856, 2160, 0, 1200, 1201, 1204, 1250, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* 1600x1200@85Hz */ - {MODEPREFIX, 268250, 1600, 1648, 1680, 1760, 0, 1200, 1203, 1207, 1271, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1600x1200@120Hz RB */ - {MODEPREFIX, 119000, 1680, 1728, 1760, 1840, 0, 1050, 1053, 1059, 1080, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1680x1050@60Hz RB */ - {MODEPREFIX, 146250, 1680, 1784, 1960, 2240, 0, 1050, 1053, 1059, 1089, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1680x1050@60Hz */ - {MODEPREFIX, 187000, 1680, 1800, 1976, 2272, 0, 1050, 1053, 1059, 1099, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1680x1050@75Hz */ - {MODEPREFIX, 214750, 1680, 1808, 1984, 2288, 0, 1050, 1053, 1059, 1105, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1680x1050@85Hz */ - {MODEPREFIX, 245500, 1680, 1728, 1760, 1840, 0, 1050, 1053, 1059, 1112, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1680x1050@120Hz RB */ - {MODEPREFIX, 204750, 1792, 1920, 2120, 2448, 0, 1344, 1345, 1348, 1394, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1792x1344@60Hz */ - {MODEPREFIX, 261000, 1792, 1888, 2104, 2456, 0, 1344, 1345, 1348, 1417, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1792x1344@75Hz */ - {MODEPREFIX, 333250, 1792, 1840, 1872, 1952, 0, 1344, 1347, 1351, 1423, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1792x1344@120Hz RB */ - {MODEPREFIX, 218250, 1856, 1952, 2176, 2528, 0, 1392, 1393, 1396, 1439, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1856x1392@60Hz */ - {MODEPREFIX, 288000, 1856, 1984, 2208, 2560, 0, 1392, 1393, 1396, 1500, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1856x1392@75Hz */ - {MODEPREFIX, 356500, 1856, 1904, 1936, 2016, 0, 1392, 1395, 1399, 1474, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1856x1392@120Hz RB */ - {MODEPREFIX, 154000, 1920, 1968, 2000, 2080, 0, 1200, 1203, 1209, 1235, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1920x1200@60Hz RB */ - {MODEPREFIX, 193250, 1920, 2056, 2256, 2592, 0, 1200, 1203, 1209, 1245, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1920x1200@60Hz */ - {MODEPREFIX, 245250, 1920, 2056, 2264, 2608, 0, 1200, 1203, 1209, 1255, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1920x1200@75Hz */ - {MODEPREFIX, 281250, 1920, 2064, 2272, 2624, 0, 1200, 1203, 1209, 1262, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1920x1200@85Hz */ - {MODEPREFIX, 317000, 1920, 1968, 2000, 2080, 0, 1200, 1203, 1209, 1271, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1920x1200@120Hz RB */ - {MODEPREFIX, 234000, 1920, 2048, 2256, 2600, 0, 1440, 1441, 1444, 1500, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1920x1440@60Hz */ - {MODEPREFIX, 297000, 1920, 2064, 2288, 2640, 0, 1440, 1441, 1444, 1500, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 1920x1440@75Hz */ - {MODEPREFIX, 380500, 1920, 1968, 2000, 2080, 0, 1440, 1443, 1447, 1525, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 1920x1440@120Hz RB */ - {MODEPREFIX, 268500, 2560, 2608, 2640, 2720, 0, 1600, 1603, 1609, 1646, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 2560x1600@60Hz RB */ - {MODEPREFIX, 348500, 2560, 2752, 3032, 3504, 0, 1600, 1603, 1609, 1658, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 2560x1600@60Hz */ - {MODEPREFIX, 443250, 2560, 2768, 3048, 3536, 0, 1600, 1603, 1609, 1672, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 2560x1600@75Hz */ - {MODEPREFIX, 505250, 2560, 2768, 3048, 3536, 0, 1600, 1603, 1609, 1682, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX}, /* 2560x1600@85Hz */ - {MODEPREFIX, 552750, 2560, 2608, 2640, 2720, 0, 1600, 1603, 1609, 1694, 0, V_PHSYNC | V_NVSYNC, MODESUFFIX}, /* 2560x1600@120Hz RB */ -}; - -#define LEVEL_DMT 0 -#define LEVEL_GTF 1 -#define LEVEL_CVT 2 - -static int -MonitorStandardTimingLevel(xf86MonPtr DDC) -{ - if (DDC->ver.revision >= 2) { - if (DDC->ver.revision >= 4 && CVT_SUPPORTED(DDC->features.msc)) { - return LEVEL_CVT; - } - return LEVEL_GTF; - } - return LEVEL_DMT; -} - -static int -ModeRefresh(const DisplayModeRec * mode) -{ - return (int) (xf86ModeVRefresh(mode) + 0.5); -} - -/* - * If rb is not set, then we'll not consider reduced-blanking modes as - * part of the DMT pool. For the 'standard' EDID mode descriptor there's - * no way to specify whether the mode should be RB or not. - */ -DisplayModePtr -FindDMTMode(int hsize, int vsize, int refresh, Bool rb) -{ - int i; - const DisplayModeRec *ret; - - for (i = 0; i < ARRAY_SIZE(DMTModes); i++) { - ret = &DMTModes[i]; - - if (!rb && xf86ModeIsReduced(ret)) - continue; - - if (ret->HDisplay == hsize && - ret->VDisplay == vsize && refresh == ModeRefresh(ret)) - return xf86DuplicateMode(ret); - } - - return NULL; -} - -/* - * Appendix B of the EDID 1.4 spec defines the right thing to do here. - * If the timing given here matches a mode defined in the VESA DMT standard, - * we _must_ use that. If the device supports CVT modes, then we should - * generate a CVT timing. If both of the above fail, use GTF. - * - * There are some wrinkles here. EDID 1.1 and 1.0 sinks can't really - * "support" GTF, since it wasn't a standard yet; so if they ask for a - * timing in this section that isn't defined in DMT, returning a GTF mode - * may not actually be valid. EDID 1.3 sinks often report support for - * some CVT modes, but they are not required to support CVT timings for - * modes in the standard timing descriptor, so we should _not_ treat them - * as CVT-compliant (unless specified in an extension block I suppose). - * - * EDID 1.4 requires that all sink devices support both GTF and CVT timings - * for modes in this section, but does say that CVT is preferred. - */ -static DisplayModePtr -DDCModesFromStandardTiming(DisplayModePtr pool, struct std_timings *timing, - ddc_quirk_t quirks, - int timing_level, Bool rb) -{ - DisplayModePtr Modes = NULL, Mode = NULL; - int i, hsize, vsize, refresh; - - for (i = 0; i < STD_TIMINGS; i++) { - DisplayModePtr p = NULL; - hsize = timing[i].hsize; - vsize = timing[i].vsize; - refresh = timing[i].refresh; - - /* HDTV hack, part one */ - if (refresh == 60 && - ((hsize == 1360 && vsize == 765) || - (hsize == 1368 && vsize == 769))) { - hsize = 1366; - vsize = 768; - } - - /* If we already have a detailed timing for this size, don't add more */ - for (p = pool; p; p = p->next) { - if (p->HDisplay == hsize && p->VDisplay == vsize && - refresh == round(xf86ModeVRefresh(p))) - break; - } - if (p) - continue; - - /* HDTV hack, because you can't say 1366 */ - if (refresh == 60 && hsize == 1366 && vsize == 768) { - Mode = xf86CVTMode(1366, 768, 60, FALSE, FALSE); - Mode->HDisplay = 1366; - Mode->HSyncStart--; - Mode->HSyncEnd--; - } - else if (hsize && vsize && refresh) { - Mode = FindDMTMode(hsize, vsize, refresh, rb); - - if (!Mode) { - if (timing_level == LEVEL_CVT) - /* pass rb here too? */ - Mode = xf86CVTMode(hsize, vsize, refresh, FALSE, FALSE); - else if (timing_level == LEVEL_GTF) - Mode = xf86GTFMode(hsize, vsize, refresh, FALSE, FALSE); - } - - } - - if (Mode) { - Mode->type = M_T_DRIVER; - Modes = xf86ModesAdd(Modes, Mode); - } - Mode = NULL; - } - - return Modes; -} - -static void -DDCModeDoInterlaceQuirks(DisplayModePtr mode) -{ - /* - * EDID is delightfully ambiguous about how interlaced modes are to be - * encoded. X's internal representation is of frame height, but some - * HDTV detailed timings are encoded as field height. - * - * The format list here is from CEA, in frame size. Technically we - * should be checking refresh rate too. Whatever. - */ - static const struct { - int w, h; - } cea_interlaced[] = { - {1920, 1080}, - {720, 480}, - {1440, 480}, - {2880, 480}, - {720, 576}, - {1440, 576}, - {2880, 576}, - }; - int i; - - for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) { - if ((mode->HDisplay == cea_interlaced[i].w) && - (mode->VDisplay == cea_interlaced[i].h / 2)) { - mode->VDisplay *= 2; - mode->VSyncStart *= 2; - mode->VSyncEnd *= 2; - mode->VTotal *= 2; - mode->VTotal |= 1; - } - } - - mode->Flags |= V_INTERLACE; -} - -/* - * - */ -static DisplayModePtr -DDCModeFromDetailedTiming(int scrnIndex, struct detailed_timings *timing, - Bool preferred, ddc_quirk_t quirks) -{ - DisplayModePtr Mode; - - /* - * Refuse to create modes that are insufficiently large. 64 is a random - * number, maybe the spec says something about what the minimum is. In - * particular I see this frequently with _old_ EDID, 1.0 or so, so maybe - * our parser is just being too aggressive there. - */ - if (timing->h_active < 64 || timing->v_active < 64) { - xf86DrvMsg(scrnIndex, X_INFO, - "%s: Ignoring tiny %dx%d mode\n", __func__, - timing->h_active, timing->v_active); - return NULL; - } - - /* We don't do stereo */ - if (timing->stereo) { - xf86DrvMsg(scrnIndex, X_INFO, - "%s: Ignoring: We don't handle stereo.\n", __func__); - return NULL; - } - - /* We only do separate sync currently */ - if (timing->sync != 0x03) { - xf86DrvMsg(scrnIndex, X_INFO, - "%s: %dx%d Warning: We only handle separate" - " sync.\n", __func__, timing->h_active, timing->v_active); - } - - Mode = xnfcalloc(1, sizeof(DisplayModeRec)); - - Mode->type = M_T_DRIVER; - if (preferred) - Mode->type |= M_T_PREFERRED; - - if ((quirks & DDC_QUIRK_135_CLOCK_TOO_HIGH) && timing->clock == 135000000) - Mode->Clock = 108880; - else - Mode->Clock = timing->clock / 1000.0; - - Mode->HDisplay = timing->h_active; - Mode->HSyncStart = timing->h_active + timing->h_sync_off; - Mode->HSyncEnd = Mode->HSyncStart + timing->h_sync_width; - Mode->HTotal = timing->h_active + timing->h_blanking; - - Mode->VDisplay = timing->v_active; - Mode->VSyncStart = timing->v_active + timing->v_sync_off; - Mode->VSyncEnd = Mode->VSyncStart + timing->v_sync_width; - Mode->VTotal = timing->v_active + timing->v_blanking; - - /* perform basic check on the detail timing */ - if (Mode->HSyncEnd > Mode->HTotal || Mode->VSyncEnd > Mode->VTotal) { - free(Mode); - return NULL; - } - - /* We ignore h/v_size and h/v_border for now. */ - - if (timing->interlaced) - DDCModeDoInterlaceQuirks(Mode); - - if (quirks & DDC_QUIRK_DETAILED_SYNC_PP) - Mode->Flags |= V_PVSYNC | V_PHSYNC; - else { - if (timing->misc & 0x02) - Mode->Flags |= V_PVSYNC; - else - Mode->Flags |= V_NVSYNC; - - if (timing->misc & 0x01) - Mode->Flags |= V_PHSYNC; - else - Mode->Flags |= V_NHSYNC; - } - - xf86SetModeDefaultName(Mode); - - return Mode; -} - -static DisplayModePtr -DDCModesFromCVT(int scrnIndex, struct cvt_timings *t) -{ - DisplayModePtr modes = NULL; - int i; - - for (i = 0; i < 4; i++) { - if (t[i].height) { - if (t[i].rates & 0x10) - modes = xf86ModesAdd(modes, - xf86CVTMode(t[i].width, t[i].height, 50, 0, - 0)); - if (t[i].rates & 0x08) - modes = xf86ModesAdd(modes, - xf86CVTMode(t[i].width, t[i].height, 60, 0, - 0)); - if (t[i].rates & 0x04) - modes = xf86ModesAdd(modes, - xf86CVTMode(t[i].width, t[i].height, 75, 0, - 0)); - if (t[i].rates & 0x02) - modes = xf86ModesAdd(modes, - xf86CVTMode(t[i].width, t[i].height, 85, 0, - 0)); - if (t[i].rates & 0x01) - modes = xf86ModesAdd(modes, - xf86CVTMode(t[i].width, t[i].height, 60, 1, - 0)); - } - else - break; - } - - return modes; -} - -static const struct { - short w; - short h; - short r; - short rb; -} EstIIIModes[] = { - /* byte 6 */ - {640, 350, 85, 0}, - {640, 400, 85, 0}, - {720, 400, 85, 0}, - {640, 480, 85, 0}, - {848, 480, 60, 0}, - {800, 600, 85, 0}, - {1024, 768, 85, 0}, - {1152, 864, 75, 0}, - /* byte 7 */ - {1280, 768, 60, 1}, - {1280, 768, 60, 0}, - {1280, 768, 75, 0}, - {1280, 768, 85, 0}, - {1280, 960, 60, 0}, - {1280, 960, 85, 0}, - {1280, 1024, 60, 0}, - {1280, 1024, 85, 0}, - /* byte 8 */ - {1360, 768, 60, 0}, - {1440, 900, 60, 1}, - {1440, 900, 60, 0}, - {1440, 900, 75, 0}, - {1440, 900, 85, 0}, - {1400, 1050, 60, 1}, - {1400, 1050, 60, 0}, - {1400, 1050, 75, 0}, - /* byte 9 */ - {1400, 1050, 85, 0}, - {1680, 1050, 60, 1}, - {1680, 1050, 60, 0}, - {1680, 1050, 75, 0}, - {1680, 1050, 85, 0}, - {1600, 1200, 60, 0}, - {1600, 1200, 65, 0}, - {1600, 1200, 70, 0}, - /* byte 10 */ - {1600, 1200, 75, 0}, - {1600, 1200, 85, 0}, - {1792, 1344, 60, 0}, - {1792, 1344, 75, 0}, - {1856, 1392, 60, 0}, - {1856, 1392, 75, 0}, - {1920, 1200, 60, 1}, - {1920, 1200, 60, 0}, - /* byte 11 */ - {1920, 1200, 75, 0}, - {1920, 1200, 85, 0}, - {1920, 1440, 60, 0}, - {1920, 1440, 75, 0}, - /* fill up last byte */ - {0,0,0,0}, - {0,0,0,0}, - {0,0,0,0}, - {0,0,0,0}, -}; - -static DisplayModePtr -DDCModesFromEstIII(unsigned char *est) -{ - DisplayModePtr modes = NULL; - int i, j, m; - - for (i = 0; i < 6; i++) { - for (j = 7; j >= 0; j--) { - if (est[i] & (1 << j)) { - m = (i * 8) + (7 - j); - if (EstIIIModes[m].w) - modes = xf86ModesAdd(modes, - FindDMTMode(EstIIIModes[m].w, - EstIIIModes[m].h, - EstIIIModes[m].r, - EstIIIModes[m].rb)); - } - } - } - - return modes; -} - -/* - * This is only valid when the sink claims to be continuous-frequency - * but does not supply a detailed range descriptor. Such sinks are - * arguably broken. Currently the mode validation code isn't aware of - * this; the non-RANDR code even punts the decision of optional sync - * range checking to the driver. Loss. - */ -static void -DDCGuessRangesFromModes(int scrnIndex, MonPtr Monitor, DisplayModePtr Modes) -{ - DisplayModePtr Mode = Modes; - - if (!Monitor || !Modes) - return; - - /* set up the ranges for scanning through the modes */ - Monitor->nHsync = 1; - Monitor->hsync[0].lo = 1024.0; - Monitor->hsync[0].hi = 0.0; - - Monitor->nVrefresh = 1; - Monitor->vrefresh[0].lo = 1024.0; - Monitor->vrefresh[0].hi = 0.0; - - while (Mode) { - if (!Mode->HSync) - Mode->HSync = ((float) Mode->Clock) / ((float) Mode->HTotal); - - if (!Mode->VRefresh) - Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) / - ((float) (Mode->HTotal * Mode->VTotal)); - - if (Mode->HSync < Monitor->hsync[0].lo) - Monitor->hsync[0].lo = Mode->HSync; - - if (Mode->HSync > Monitor->hsync[0].hi) - Monitor->hsync[0].hi = Mode->HSync; - - if (Mode->VRefresh < Monitor->vrefresh[0].lo) - Monitor->vrefresh[0].lo = Mode->VRefresh; - - if (Mode->VRefresh > Monitor->vrefresh[0].hi) - Monitor->vrefresh[0].hi = Mode->VRefresh; - - Mode = Mode->next; - } -} - -ddc_quirk_t -xf86DDCDetectQuirks(int scrnIndex, xf86MonPtr DDC, Bool verbose) -{ - ddc_quirk_t quirks; - int i; - - quirks = DDC_QUIRK_NONE; - for (i = 0; ddc_quirks[i].detect; i++) { - if (ddc_quirks[i].detect(scrnIndex, DDC)) { - if (verbose) { - xf86DrvMsg(scrnIndex, X_INFO, " EDID quirk: %s\n", - ddc_quirks[i].description); - } - quirks |= ddc_quirks[i].quirk; - } - } - - return quirks; -} - -void -xf86DetTimingApplyQuirks(struct detailed_monitor_section *det_mon, - ddc_quirk_t quirks, int hsize, int vsize) -{ - if (det_mon->type != DT) - return; - - if (quirks & DDC_QUIRK_DETAILED_H_IN_CM) - det_mon->section.d_timings.h_size *= 10; - - if (quirks & DDC_QUIRK_DETAILED_V_IN_CM) - det_mon->section.d_timings.v_size *= 10; - - if (quirks & DDC_QUIRK_DETAILED_USE_MAXIMUM_SIZE) { - det_mon->section.d_timings.h_size = 10 * hsize; - det_mon->section.d_timings.v_size = 10 * vsize; - } -} - -/** - * Applies monitor-specific quirks to the decoded EDID information. - * - * Note that some quirks applying to the mode list are still implemented in - * xf86DDCGetModes. - */ -void -xf86DDCApplyQuirks(int scrnIndex, xf86MonPtr DDC) -{ - ddc_quirk_t quirks = xf86DDCDetectQuirks(scrnIndex, DDC, FALSE); - int i; - - for (i = 0; i < DET_TIMINGS; i++) { - xf86DetTimingApplyQuirks(DDC->det_mon + i, quirks, - DDC->features.hsize, DDC->features.vsize); - } -} - -/** - * Walks the modes list, finding the mode with the largest area which is - * closest to the target refresh rate, and marks it as the only preferred mode. -*/ -static void -xf86DDCSetPreferredRefresh(int scrnIndex, DisplayModePtr modes, - float target_refresh) -{ - DisplayModePtr mode, best = modes; - - for (mode = modes; mode; mode = mode->next) { - mode->type &= ~M_T_PREFERRED; - - if (mode == best) - continue; - - if (mode->HDisplay * mode->VDisplay > best->HDisplay * best->VDisplay) { - best = mode; - continue; - } - if (mode->HDisplay * mode->VDisplay == best->HDisplay * best->VDisplay) { - double mode_refresh = xf86ModeVRefresh(mode); - double best_refresh = xf86ModeVRefresh(best); - double mode_dist = fabs(mode_refresh - target_refresh); - double best_dist = fabs(best_refresh - target_refresh); - - if (mode_dist < best_dist) { - best = mode; - continue; - } - } - } - if (best) - best->type |= M_T_PREFERRED; -} - -#define CEA_VIDEO_MODES_NUM 64 -static const DisplayModeRec CEAVideoModes[CEA_VIDEO_MODES_NUM] = { - {MODEPREFIX, 25175, 640, 656, 752, 800, 0, 480, 490, 492, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 1:640x480@60Hz */ - {MODEPREFIX, 27000, 720, 736, 798, 858, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 2:720x480@60Hz */ - {MODEPREFIX, 27000, 720, 736, 798, 858, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 3:720x480@60Hz */ - {MODEPREFIX, 74250, 1280, 1390, 1430, 1650, 0, 720, 725, 730, 750, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 4: 1280x720@60Hz */ - {MODEPREFIX, 74250, 1920, 2008, 2052, 2200, 0, 1080, 1084, 1094, 1125, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 5:1920x1080i@60Hz */ - {MODEPREFIX, 27000, 1440, 1478, 1602, 1716, 0, 480, 488, 494, 525, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 6:1440x480i@60Hz */ - {MODEPREFIX, 27000, 1440, 1478, 1602, 1716, 0, 480, 488, 494, 525, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 7:1440x480i@60Hz */ - {MODEPREFIX, 27000, 1440, 1478, 1602, 1716, 0, 240, 244, 247, 262, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 8:1440x240@60Hz */ - {MODEPREFIX, 27000, 1440, 1478, 1602, 1716, 0, 240, 244, 247, 262, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 9:1440x240@60Hz */ - {MODEPREFIX, 54000, 2880, 2956, 3204, 3432, 0, 480, 488, 494, 525, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 10:2880x480i@60Hz */ - {MODEPREFIX, 54000, 2880, 2956, 3204, 3432, 0, 480, 488, 494, 525, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 11:2880x480i@60Hz */ - {MODEPREFIX, 54000, 2880, 2956, 3204, 3432, 0, 240, 244, 247, 262, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 12:2880x240@60Hz */ - {MODEPREFIX, 54000, 2880, 2956, 3204, 3432, 0, 240, 244, 247, 262, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 13:2880x240@60Hz */ - {MODEPREFIX, 54000, 1440, 1472, 1596, 1716, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 14:1440x480@60Hz */ - {MODEPREFIX, 54000, 1440, 1472, 1596, 1716, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 15:1440x480@60Hz */ - {MODEPREFIX, 148500, 1920, 2008, 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 16:1920x1080@60Hz */ - {MODEPREFIX, 27000, 720, 732, 796, 864, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 17:720x576@50Hz */ - {MODEPREFIX, 27000, 720, 732, 796, 864, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 18:720x576@50Hz */ - {MODEPREFIX, 74250, 1280, 1720, 1760, 1980, 0, 720, 725, 730, 750, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 19: 1280x720@50Hz */ - {MODEPREFIX, 74250, 1920, 2448, 2492, 2640, 0, 1080, 1084, 1094, 1125, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 20:1920x1080i@50Hz */ - {MODEPREFIX, 27000, 1440, 1464, 1590, 1728, 0, 576, 580, 586, 625, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 21:1440x576i@50Hz */ - {MODEPREFIX, 27000, 1440, 1464, 1590, 1728, 0, 576, 580, 586, 625, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 22:1440x576i@50Hz */ - {MODEPREFIX, 27000, 1440, 1464, 1590, 1728, 0, 288, 290, 293, 312, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 23:1440x288@50Hz */ - {MODEPREFIX, 27000, 1440, 1464, 1590, 1728, 0, 288, 290, 293, 312, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 24:1440x288@50Hz */ - {MODEPREFIX, 54000, 2880, 2928, 3180, 3456, 0, 576, 580, 586, 625, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 25:2880x576i@50Hz */ - {MODEPREFIX, 54000, 2880, 2928, 3180, 3456, 0, 576, 580, 586, 625, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 26:2880x576i@50Hz */ - {MODEPREFIX, 54000, 2880, 2928, 3180, 3456, 0, 288, 290, 293, 312, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 27:2880x288@50Hz */ - {MODEPREFIX, 54000, 2880, 2928, 3180, 3456, 0, 288, 290, 293, 312, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 28:2880x288@50Hz */ - {MODEPREFIX, 54000, 1440, 1464, 1592, 1728, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 29:1440x576@50Hz */ - {MODEPREFIX, 54000, 1440, 1464, 1592, 1728, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 30:1440x576@50Hz */ - {MODEPREFIX, 148500, 1920, 2448, 2492, 2640, 0, 1080, 1084, 1089, 1125, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 31:1920x1080@50Hz */ - {MODEPREFIX, 74250, 1920, 2558, 2602, 2750, 0, 1080, 1084, 1089, 1125, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 32:1920x1080@24Hz */ - {MODEPREFIX, 74250, 1920, 2448, 2492, 2640, 0, 1080, 1084, 1089, 1125, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 33:1920x1080@25Hz */ - {MODEPREFIX, 74250, 1920, 2008, 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 34:1920x1080@30Hz */ - {MODEPREFIX, 108000, 2880, 2944, 3192, 3432, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 35:2880x480@60Hz */ - {MODEPREFIX, 108000, 2880, 2944, 3192, 3432, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 36:2880x480@60Hz */ - {MODEPREFIX, 108000, 2880, 2928, 3184, 3456, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 37:2880x576@50Hz */ - {MODEPREFIX, 108000, 2880, 2928, 3184, 3456, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 38:2880x576@50Hz */ - {MODEPREFIX, 72000, 1920, 1952, 2120, 2304, 0, 1080, 1126, 1136, 1250, 0, V_PHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 39:1920x1080i@50Hz */ - {MODEPREFIX, 148500, 1920, 2448, 2492, 2640, 0, 1080, 1084, 1094, 1125, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 40:1920x1080i@100Hz */ - {MODEPREFIX, 148500, 1280, 1720, 1760, 1980, 0, 720, 725, 730, 750, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 41:1280x720@100Hz */ - {MODEPREFIX, 54000, 720, 732, 796, 864, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 42:720x576@100Hz */ - {MODEPREFIX, 54000, 720, 732, 796, 864, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 43:720x576@100Hz */ - {MODEPREFIX, 54000, 1440, 1464, 1590, 1728, 0, 576, 580, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 44:1440x576i@100Hz */ - {MODEPREFIX, 54000, 1440, 1464, 1590, 1728, 0, 576, 580, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 45:1440x576i@100Hz */ - {MODEPREFIX, 148500, 1920, 2008, 2052, 2200, 0, 1080, 1084, 1094, 1125, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 46:1920x1080i@120Hz */ - {MODEPREFIX, 148500, 1280, 1390, 1430, 1650, 0, 720, 725, 730, 750, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 47:1280x720@120Hz */ - {MODEPREFIX, 54000, 720, 736, 798, 858, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 48:720x480@120Hz */ - {MODEPREFIX, 54000, 720, 736, 798, 858, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 49:720x480@120Hz */ - {MODEPREFIX, 54000, 1440, 1478, 1602, 1716, 0, 480, 488, 494, 525, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 50:1440x480i@120Hz */ - {MODEPREFIX, 54000, 1440, 1478, 1602, 1716, 0, 480, 488, 494, 525, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 51:1440x480i@120Hz */ - {MODEPREFIX, 108000, 720, 732, 796, 864, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 52:720x576@200Hz */ - {MODEPREFIX, 108000, 720, 732, 796, 864, 0, 576, 581, 586, 625, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 53:720x576@200Hz */ - {MODEPREFIX, 108000, 1440, 1464, 1590, 1728, 0, 576, 580, 586, 625, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 54:1440x576i@200Hz */ - {MODEPREFIX, 108000, 1440, 1464, 1590, 1728, 0, 576, 580, 586, 625, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 55:1440x576i@200Hz */ - {MODEPREFIX, 108000, 720, 736, 798, 858, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 56:720x480@240Hz */ - {MODEPREFIX, 108000, 720, 736, 798, 858, 0, 480, 489, 495, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX}, /* VIC 57:720x480@240Hz */ - {MODEPREFIX, 108000, 1440, 1478, 1602, 1716, 0, 480, 488, 494, 525, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 58:1440x480i@240 */ - {MODEPREFIX, 108000, 1440, 1478, 1602, 1716, 0, 480, 488, 494, 525, 0, V_NHSYNC | V_NVSYNC | V_INTERLACE, MODESUFFIX}, /* VIC 59:1440x480i@240 */ - {MODEPREFIX, 59400, 1280, 3040, 3080, 3300, 0, 720, 725, 730, 750, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 60: 1280x720@24Hz */ - {MODEPREFIX, 74250, 1280, 3700, 3740, 3960, 0, 720, 725, 730, 750, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 61: 1280x720@25Hz */ - {MODEPREFIX, 74250, 1280, 3040, 3080, 3300, 0, 720, 725, 730, 750, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 62: 1280x720@30Hz */ - {MODEPREFIX, 297000, 1920, 2008, 2052, 2200, 0, 1080, 1084, 1089, 1125, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 63: 1920x1080@120Hz */ - {MODEPREFIX, 297000, 1920, 2448, 2492, 2640, 0, 1080, 1084, 1094, 1125, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX}, /* VIC 64:1920x1080@100Hz */ -}; - -/* chose mode line by cea short video descriptor*/ -static void -handle_cea_svd(struct cea_video_block *video, void *data) -{ - DisplayModePtr Mode; - DisplayModePtr *Modes = (DisplayModePtr *) data; - int vid; - - vid = video->video_code & 0x7f; - if (vid >= 1 && vid <= CEA_VIDEO_MODES_NUM) { - Mode = xf86DuplicateMode(CEAVideoModes + (vid - 1)); - *Modes = xf86ModesAdd(*Modes, Mode); - } -} - -static DisplayModePtr -DDCModesFromCEAExtension(int scrnIndex, xf86MonPtr mon_ptr) -{ - DisplayModePtr Modes = NULL; - - xf86ForEachVideoBlock(mon_ptr, handle_cea_svd, &Modes); - - return Modes; -} - -struct det_modes_parameter { - xf86MonPtr DDC; - ddc_quirk_t quirks; - DisplayModePtr Modes; - Bool rb; - Bool preferred; - int timing_level; -}; - -static void -handle_detailed_modes(struct detailed_monitor_section *det_mon, void *data) -{ - DisplayModePtr Mode; - struct det_modes_parameter *p = (struct det_modes_parameter *) data; - - xf86DetTimingApplyQuirks(det_mon, p->quirks, - p->DDC->features.hsize, p->DDC->features.vsize); - - switch (det_mon->type) { - case DT: - Mode = DDCModeFromDetailedTiming(p->DDC->scrnIndex, - &det_mon->section.d_timings, - p->preferred, p->quirks); - p->preferred = FALSE; - p->Modes = xf86ModesAdd(p->Modes, Mode); - break; - case DS_STD_TIMINGS: - Mode = DDCModesFromStandardTiming(p->Modes, - det_mon->section.std_t, - p->quirks, p->timing_level, p->rb); - p->Modes = xf86ModesAdd(p->Modes, Mode); - break; - case DS_CVT: - Mode = DDCModesFromCVT(p->DDC->scrnIndex, det_mon->section.cvt); - p->Modes = xf86ModesAdd(p->Modes, Mode); - break; - case DS_EST_III: - Mode = DDCModesFromEstIII(det_mon->section.est_iii); - p->Modes = xf86ModesAdd(p->Modes, Mode); - break; - default: - break; - } -} - -DisplayModePtr -xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC) -{ - DisplayModePtr Modes = NULL, Mode; - ddc_quirk_t quirks; - Bool preferred, rb; - int timing_level; - struct det_modes_parameter p; - - xf86DrvMsg(scrnIndex, X_INFO, "EDID vendor \"%s\", prod id %d\n", - DDC->vendor.name, DDC->vendor.prod_id); - - quirks = xf86DDCDetectQuirks(scrnIndex, DDC, TRUE); - - preferred = PREFERRED_TIMING_MODE(DDC->features.msc); - if (DDC->ver.revision >= 4) - preferred = TRUE; - if (quirks & DDC_QUIRK_FIRST_DETAILED_PREFERRED) - preferred = TRUE; - if (quirks & (DDC_QUIRK_PREFER_LARGE_60 | DDC_QUIRK_PREFER_LARGE_75)) - preferred = FALSE; - - rb = xf86MonitorSupportsReducedBlanking(DDC); - - timing_level = MonitorStandardTimingLevel(DDC); - - p.quirks = quirks; - p.DDC = DDC; - p.Modes = Modes; - p.rb = rb; - p.preferred = preferred; - p.timing_level = timing_level; - xf86ForEachDetailedBlock(DDC, handle_detailed_modes, &p); - Modes = p.Modes; - - /* Add cea-extension mode timings */ - Mode = DDCModesFromCEAExtension(scrnIndex, DDC); - Modes = xf86ModesAdd(Modes, Mode); - - /* Add established timings */ - Mode = DDCModesFromEstablished(scrnIndex, &DDC->timings1, quirks); - Modes = xf86ModesAdd(Modes, Mode); - - /* Add standard timings */ - Mode = DDCModesFromStandardTiming(Modes, DDC->timings2, quirks, - timing_level, rb); - Modes = xf86ModesAdd(Modes, Mode); - - if (quirks & DDC_QUIRK_PREFER_LARGE_60) - xf86DDCSetPreferredRefresh(scrnIndex, Modes, 60); - - if (quirks & DDC_QUIRK_PREFER_LARGE_75) - xf86DDCSetPreferredRefresh(scrnIndex, Modes, 75); - - Modes = xf86PruneDuplicateModes(Modes); - - return Modes; -} - -struct det_mon_parameter { - MonPtr Monitor; - ddc_quirk_t quirks; - Bool have_hsync; - Bool have_vrefresh; - Bool have_maxpixclock; -}; - -static void -handle_detailed_monset(struct detailed_monitor_section *det_mon, void *data) -{ - int clock; - struct det_mon_parameter *p = (struct det_mon_parameter *) data; - int scrnIndex = ((xf86MonPtr) (p->Monitor->DDC))->scrnIndex; - - switch (det_mon->type) { - case DS_RANGES: - if (!p->have_hsync) { - if (!p->Monitor->nHsync) - xf86DrvMsg(scrnIndex, X_INFO, - "Using EDID range info for horizontal sync\n"); - p->Monitor->hsync[p->Monitor->nHsync].lo = - det_mon->section.ranges.min_h; - p->Monitor->hsync[p->Monitor->nHsync].hi = - det_mon->section.ranges.max_h; - p->Monitor->nHsync++; - } - else { - xf86DrvMsg(scrnIndex, X_INFO, - "Using hsync ranges from config file\n"); - } - - if (!p->have_vrefresh) { - if (!p->Monitor->nVrefresh) - xf86DrvMsg(scrnIndex, X_INFO, - "Using EDID range info for vertical refresh\n"); - p->Monitor->vrefresh[p->Monitor->nVrefresh].lo = - det_mon->section.ranges.min_v; - p->Monitor->vrefresh[p->Monitor->nVrefresh].hi = - det_mon->section.ranges.max_v; - p->Monitor->nVrefresh++; - } - else { - xf86DrvMsg(scrnIndex, X_INFO, - "Using vrefresh ranges from config file\n"); - } - - clock = det_mon->section.ranges.max_clock * 1000; - if (p->quirks & DDC_QUIRK_DVI_SINGLE_LINK) - clock = min(clock, 165000); - if (!p->have_maxpixclock && clock > p->Monitor->maxPixClock) - p->Monitor->maxPixClock = clock; - - break; - default: - break; - } -} - -/* - * Fill out MonPtr with xf86MonPtr information. - */ -void -xf86EdidMonitorSet(int scrnIndex, MonPtr Monitor, xf86MonPtr DDC) -{ - DisplayModePtr Modes = NULL, Mode; - struct det_mon_parameter p; - - if (!Monitor || !DDC) - return; - - Monitor->DDC = DDC; - - if (Monitor->widthmm <= 0 || Monitor->heightmm <= 0) { - Monitor->widthmm = 10 * DDC->features.hsize; - Monitor->heightmm = 10 * DDC->features.vsize; - } - - Monitor->reducedblanking = xf86MonitorSupportsReducedBlanking(DDC); - - Modes = xf86DDCGetModes(scrnIndex, DDC); - - /* Go through the detailed monitor sections */ - p.Monitor = Monitor; - p.quirks = xf86DDCDetectQuirks(scrnIndex, Monitor->DDC, FALSE); - p.have_hsync = (Monitor->nHsync != 0); - p.have_vrefresh = (Monitor->nVrefresh != 0); - p.have_maxpixclock = (Monitor->maxPixClock != 0); - xf86ForEachDetailedBlock(DDC, handle_detailed_monset, &p); - - if (Modes) { - /* Print Modes */ - xf86DrvMsg(scrnIndex, X_INFO, "Printing DDC gathered Modelines:\n"); - - Mode = Modes; - while (Mode) { - xf86PrintModeline(scrnIndex, Mode); - Mode = Mode->next; - } - - /* Do we still need ranges to be filled in? */ - if (!Monitor->nHsync || !Monitor->nVrefresh) - DDCGuessRangesFromModes(scrnIndex, Monitor, Modes); - - /* add to MonPtr */ - if (Monitor->Modes) { - Monitor->Last->next = Modes; - Modes->prev = Monitor->Last; - } - else { - Monitor->Modes = Modes; - } - - Monitor->Modes = xf86PruneDuplicateModes(Monitor->Modes); - - /* Update pointer to last mode */ - for (Mode = Monitor->Modes; Mode && Mode->next; Mode = Mode->next) {} - Monitor->Last = Mode; - } -} diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c deleted file mode 100644 index 00586c457..000000000 --- a/hw/xfree86/modes/xf86Modes.c +++ /dev/null @@ -1,829 +0,0 @@ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86Modes.h" -#include "xf86Priv.h" - -extern XF86ConfigPtr xf86configptr; - -/** - * Calculates the horizontal sync rate of a mode. - */ -double -xf86ModeHSync(const DisplayModeRec * mode) -{ - double hsync = 0.0; - - if (mode->HSync > 0.0) - hsync = mode->HSync; - else if (mode->HTotal > 0) - hsync = (float) mode->Clock / (float) mode->HTotal; - - return hsync; -} - -/** - * Calculates the vertical refresh rate of a mode. - */ -double -xf86ModeVRefresh(const DisplayModeRec * mode) -{ - double refresh = 0.0; - - if (mode->VRefresh > 0.0) - refresh = mode->VRefresh; - else if (mode->HTotal > 0 && mode->VTotal > 0) { - refresh = mode->Clock * 1000.0 / mode->HTotal / mode->VTotal; - if (mode->Flags & V_INTERLACE) - refresh *= 2.0; - if (mode->Flags & V_DBLSCAN) - refresh /= 2.0; - if (mode->VScan > 1) - refresh /= (float) (mode->VScan); - } - return refresh; -} - -int -xf86ModeWidth(const DisplayModeRec * mode, Rotation rotation) -{ - switch (rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_180: - return mode->HDisplay; - case RR_Rotate_90: - case RR_Rotate_270: - return mode->VDisplay; - default: - return 0; - } -} - -int -xf86ModeHeight(const DisplayModeRec * mode, Rotation rotation) -{ - switch (rotation & 0xf) { - case RR_Rotate_0: - case RR_Rotate_180: - return mode->VDisplay; - case RR_Rotate_90: - case RR_Rotate_270: - return mode->HDisplay; - default: - return 0; - } -} - -/** Calculates the memory bandwidth (in MiB/sec) of a mode. */ -unsigned int -xf86ModeBandwidth(DisplayModePtr mode, int depth) -{ - float a_active, a_total, active_percent, pixels_per_second; - int bytes_per_pixel = bits_to_bytes(depth); - - if (!mode->HTotal || !mode->VTotal || !mode->Clock) - return 0; - - a_active = mode->HDisplay * mode->VDisplay; - a_total = mode->HTotal * mode->VTotal; - active_percent = a_active / a_total; - pixels_per_second = active_percent * mode->Clock * 1000.0; - - return (unsigned int) (pixels_per_second * bytes_per_pixel / (1024 * 1024)); -} - -/** Sets a default mode name of x on a mode. */ -void -xf86SetModeDefaultName(DisplayModePtr mode) -{ - Bool interlaced = ! !(mode->Flags & V_INTERLACE); - char *tmp; - - free((void *) mode->name); - - XNFasprintf(&tmp, "%dx%d%s", mode->HDisplay, mode->VDisplay, - interlaced ? "i" : ""); - mode->name = tmp; -} - -/* - * xf86SetModeCrtc - * - * Initialises the Crtc parameters for a mode. The initialisation includes - * adjustments for interlaced and double scan modes. - */ -void -xf86SetModeCrtc(DisplayModePtr p, int adjustFlags) -{ - if ((p == NULL) || ((p->type & M_T_CRTC_C) == M_T_BUILTIN)) - return; - - p->CrtcHDisplay = p->HDisplay; - p->CrtcHSyncStart = p->HSyncStart; - p->CrtcHSyncEnd = p->HSyncEnd; - p->CrtcHTotal = p->HTotal; - p->CrtcHSkew = p->HSkew; - p->CrtcVDisplay = p->VDisplay; - p->CrtcVSyncStart = p->VSyncStart; - p->CrtcVSyncEnd = p->VSyncEnd; - p->CrtcVTotal = p->VTotal; - if (p->Flags & V_INTERLACE) { - if (adjustFlags & INTERLACE_HALVE_V) { - p->CrtcVDisplay /= 2; - p->CrtcVSyncStart /= 2; - p->CrtcVSyncEnd /= 2; - p->CrtcVTotal /= 2; - } - /* Force interlaced modes to have an odd VTotal */ - /* maybe we should only do this when INTERLACE_HALVE_V is set? */ - p->CrtcVTotal |= 1; - } - - if (p->Flags & V_DBLSCAN) { - p->CrtcVDisplay *= 2; - p->CrtcVSyncStart *= 2; - p->CrtcVSyncEnd *= 2; - p->CrtcVTotal *= 2; - } - if (p->VScan > 1) { - p->CrtcVDisplay *= p->VScan; - p->CrtcVSyncStart *= p->VScan; - p->CrtcVSyncEnd *= p->VScan; - p->CrtcVTotal *= p->VScan; - } - p->CrtcVBlankStart = min(p->CrtcVSyncStart, p->CrtcVDisplay); - p->CrtcVBlankEnd = max(p->CrtcVSyncEnd, p->CrtcVTotal); - p->CrtcHBlankStart = min(p->CrtcHSyncStart, p->CrtcHDisplay); - p->CrtcHBlankEnd = max(p->CrtcHSyncEnd, p->CrtcHTotal); - - p->CrtcHAdjusted = FALSE; - p->CrtcVAdjusted = FALSE; -} - -/** - * Fills in a copy of mode, removing all stale pointer references. - * xf86ModesEqual will return true when comparing with original mode. - */ -void -xf86SaveModeContents(DisplayModePtr intern, const DisplayModeRec *mode) -{ - *intern = *mode; - intern->prev = intern->next = NULL; - intern->name = NULL; - intern->PrivSize = 0; - intern->PrivFlags = 0; - intern->Private = NULL; -} - -/** - * Allocates and returns a copy of pMode, including pointers within pMode. - */ -DisplayModePtr -xf86DuplicateMode(const DisplayModeRec * pMode) -{ - DisplayModePtr pNew; - - pNew = xnfalloc(sizeof(DisplayModeRec)); - *pNew = *pMode; - pNew->next = NULL; - pNew->prev = NULL; - - if (pMode->name == NULL) - xf86SetModeDefaultName(pNew); - else - pNew->name = xnfstrdup(pMode->name); - - return pNew; -} - -/** - * Duplicates every mode in the given list and returns a pointer to the first - * mode. - * - * \param modeList doubly-linked mode list - */ -DisplayModePtr -xf86DuplicateModes(ScrnInfoPtr pScrn, DisplayModePtr modeList) -{ - DisplayModePtr first = NULL, last = NULL; - DisplayModePtr mode; - - for (mode = modeList; mode != NULL; mode = mode->next) { - DisplayModePtr new; - - new = xf86DuplicateMode(mode); - - /* Insert pNew into modeList */ - if (last) { - last->next = new; - new->prev = last; - } - else { - first = new; - new->prev = NULL; - } - new->next = NULL; - last = new; - } - - return first; -} - -/** - * Returns true if the given modes should program to the same timings. - * - * This doesn't use Crtc values, as it might be used on ModeRecs without the - * Crtc values set. So, it's assumed that the other numbers are enough. - */ -Bool -xf86ModesEqual(const DisplayModeRec * pMode1, const DisplayModeRec * pMode2) -{ - if (pMode1->Clock == pMode2->Clock && - pMode1->HDisplay == pMode2->HDisplay && - pMode1->HSyncStart == pMode2->HSyncStart && - pMode1->HSyncEnd == pMode2->HSyncEnd && - pMode1->HTotal == pMode2->HTotal && - pMode1->HSkew == pMode2->HSkew && - pMode1->VDisplay == pMode2->VDisplay && - pMode1->VSyncStart == pMode2->VSyncStart && - pMode1->VSyncEnd == pMode2->VSyncEnd && - pMode1->VTotal == pMode2->VTotal && - pMode1->VScan == pMode2->VScan && pMode1->Flags == pMode2->Flags) { - return TRUE; - } - else { - return FALSE; - } -} - -static void -add(char **p, const char *new) -{ - *p = xnfrealloc(*p, strlen(*p) + strlen(new) + 2); - strcat(*p, " "); - strcat(*p, new); -} - -/** - * Print out a modeline. - * - * The mode type bits are informational except for the capitalized U - * and P bits which give sort order priority. Letter map: - * - * USERPREF, U, user preferred is set from the xorg.conf Monitor - * Option "PreferredMode" or from the Screen Display Modes statement. - * This unique modeline is moved to the head of the list after sorting. - * - * DRIVER, e, is set by the video driver, EDID or flat panel native. - * - * USERDEF, z, a configured zoom mode Ctrl+Alt+Keypad-{Plus,Minus}. - * - * DEFAULT, d, a compiled-in default. - * - * PREFERRED, P, driver preferred is set by the video device driver, - * e.g. the EDID detailed timing modeline. This is a true sort - * priority and multiple P modes form a sorted sublist at the list - * head. - * - * BUILTIN, b, a hardware fixed CRTC mode. - * - * See modes/xf86Crtc.c: xf86ProbeOutputModes(). - */ -void -xf86PrintModeline(int scrnIndex, DisplayModePtr mode) -{ - char tmp[256]; - char *flags = xnfcalloc(1, 1); - -#define TBITS 6 - const char tchar[TBITS + 1] = "UezdPb"; - - int tbit[TBITS] = { - M_T_USERPREF, M_T_DRIVER, M_T_USERDEF, - M_T_DEFAULT, M_T_PREFERRED, M_T_BUILTIN - }; - char type[TBITS + 2]; /* +1 for leading space */ - -#undef TBITS - int tlen = 0; - - if (mode->type) { - int i; - - type[tlen++] = ' '; - for (i = 0; tchar[i]; i++) - if (mode->type & tbit[i]) - type[tlen++] = tchar[i]; - } - type[tlen] = '\0'; - - if (mode->HSkew) { - snprintf(tmp, 256, "hskew %i", mode->HSkew); - add(&flags, tmp); - } - if (mode->VScan) { - snprintf(tmp, 256, "vscan %i", mode->VScan); - add(&flags, tmp); - } - if (mode->Flags & V_INTERLACE) - add(&flags, "interlace"); - if (mode->Flags & V_CSYNC) - add(&flags, "composite"); - if (mode->Flags & V_DBLSCAN) - add(&flags, "doublescan"); - if (mode->Flags & V_BCAST) - add(&flags, "bcast"); - if (mode->Flags & V_PHSYNC) - add(&flags, "+hsync"); - if (mode->Flags & V_NHSYNC) - add(&flags, "-hsync"); - if (mode->Flags & V_PVSYNC) - add(&flags, "+vsync"); - if (mode->Flags & V_NVSYNC) - add(&flags, "-vsync"); - if (mode->Flags & V_PCSYNC) - add(&flags, "+csync"); - if (mode->Flags & V_NCSYNC) - add(&flags, "-csync"); -#if 0 - if (mode->Flags & V_CLKDIV2) - add(&flags, "vclk/2"); -#endif - xf86DrvMsg(scrnIndex, X_INFO, - "Modeline \"%s\"x%.01f %6.2f %i %i %i %i %i %i %i %i%s" - " (%.01f kHz%s)\n", - mode->name, mode->VRefresh, mode->Clock / 1000., - mode->HDisplay, mode->HSyncStart, mode->HSyncEnd, mode->HTotal, - mode->VDisplay, mode->VSyncStart, mode->VSyncEnd, mode->VTotal, - flags, xf86ModeHSync(mode), type); - free(flags); -} - -/** - * Marks as bad any modes with unsupported flags. - * - * \param modeList doubly-linked list of modes. - * \param flags flags supported by the driver. - * - * \bug only V_INTERLACE and V_DBLSCAN are supported. Is that enough? - */ -void -xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList, int flags) -{ - DisplayModePtr mode; - - if (flags == (V_INTERLACE | V_DBLSCAN)) - return; - - for (mode = modeList; mode != NULL; mode = mode->next) { - if (mode->Flags & V_INTERLACE && !(flags & V_INTERLACE)) - mode->status = MODE_NO_INTERLACE; - if (mode->Flags & V_DBLSCAN && !(flags & V_DBLSCAN)) - mode->status = MODE_NO_DBLESCAN; - } -} - -/** - * Marks as bad any modes extending beyond the given max X, Y, or pitch. - * - * \param modeList doubly-linked list of modes. - */ -void -xf86ValidateModesSize(ScrnInfoPtr pScrn, DisplayModePtr modeList, - int maxX, int maxY, int maxPitch) -{ - DisplayModePtr mode; - - if (maxPitch <= 0) - maxPitch = MAXINT; - if (maxX <= 0) - maxX = MAXINT; - if (maxY <= 0) - maxY = MAXINT; - - for (mode = modeList; mode != NULL; mode = mode->next) { - if ((xf86ModeWidth(mode, RR_Rotate_0) > maxPitch || - xf86ModeWidth(mode, RR_Rotate_0) > maxX || - xf86ModeHeight(mode, RR_Rotate_0) > maxY) && - (xf86ModeWidth(mode, RR_Rotate_90) > maxPitch || - xf86ModeWidth(mode, RR_Rotate_90) > maxX || - xf86ModeHeight(mode, RR_Rotate_90) > maxY)) { - if (xf86ModeWidth(mode, RR_Rotate_0) > maxPitch || - xf86ModeWidth(mode, RR_Rotate_90) > maxPitch) - mode->status = MODE_BAD_WIDTH; - - if (xf86ModeWidth(mode, RR_Rotate_0) > maxX || - xf86ModeWidth(mode, RR_Rotate_90) > maxX) - mode->status = MODE_VIRTUAL_X; - - if (xf86ModeHeight(mode, RR_Rotate_0) > maxY || - xf86ModeHeight(mode, RR_Rotate_90) > maxY) - mode->status = MODE_VIRTUAL_Y; - } - - if (mode->next == modeList) - break; - } -} - -/** - * Marks as bad any modes that aren't supported by the given monitor's - * hsync and vrefresh ranges. - * - * \param modeList doubly-linked list of modes. - */ -void -xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList, MonPtr mon) -{ - DisplayModePtr mode; - - for (mode = modeList; mode != NULL; mode = mode->next) { - Bool bad; - int i; - - bad = TRUE; - for (i = 0; i < mon->nHsync; i++) { - if (xf86ModeHSync(mode) >= mon->hsync[i].lo * (1 - SYNC_TOLERANCE) - && xf86ModeHSync(mode) <= - mon->hsync[i].hi * (1 + SYNC_TOLERANCE)) { - bad = FALSE; - } - } - if (bad) - mode->status = MODE_HSYNC; - - bad = TRUE; - for (i = 0; i < mon->nVrefresh; i++) { - if (xf86ModeVRefresh(mode) >= - mon->vrefresh[i].lo * (1 - SYNC_TOLERANCE) && - xf86ModeVRefresh(mode) <= - mon->vrefresh[i].hi * (1 + SYNC_TOLERANCE)) { - bad = FALSE; - } - } - if (bad) - mode->status = MODE_VSYNC; - - if (mode->next == modeList) - break; - } -} - -/** - * Marks as bad any modes extending beyond outside of the given clock ranges. - * - * \param modeList doubly-linked list of modes. - * \param min pointer to minimums of clock ranges - * \param max pointer to maximums of clock ranges - * \param n_ranges number of ranges. - */ -void -xf86ValidateModesClocks(ScrnInfoPtr pScrn, DisplayModePtr modeList, - int *min, int *max, int n_ranges) -{ - DisplayModePtr mode; - int i; - - for (mode = modeList; mode != NULL; mode = mode->next) { - Bool good = FALSE; - - for (i = 0; i < n_ranges; i++) { - if (mode->Clock >= min[i] * (1 - SYNC_TOLERANCE) && - mode->Clock <= max[i] * (1 + SYNC_TOLERANCE)) { - good = TRUE; - break; - } - } - if (!good) - mode->status = MODE_CLOCK_RANGE; - } -} - -/** - * If the user has specified a set of mode names to use, mark as bad any modes - * not listed. - * - * The user mode names specified are prefixes to names of modes, so "1024x768" - * will match modes named "1024x768", "1024x768x75", "1024x768-good", but - * "1024x768x75" would only match "1024x768x75" from that list. - * - * MODE_BAD is used as the rejection flag, for lack of a better flag. - * - * \param modeList doubly-linked list of modes. - */ -void -xf86ValidateModesUserConfig(ScrnInfoPtr pScrn, DisplayModePtr modeList) -{ - DisplayModePtr mode; - - if (pScrn->display->modes[0] == NULL) - return; - - for (mode = modeList; mode != NULL; mode = mode->next) { - int i; - Bool good = FALSE; - - for (i = 0; pScrn->display->modes[i] != NULL; i++) { - if (strncmp(pScrn->display->modes[i], mode->name, - strlen(pScrn->display->modes[i])) == 0) { - good = TRUE; - break; - } - } - if (!good) - mode->status = MODE_BAD; - } -} - -/** - * Marks as bad any modes exceeding the given bandwidth. - * - * \param modeList doubly-linked list of modes. - * \param bandwidth bandwidth in MHz. - * \param depth color depth. - */ -void -xf86ValidateModesBandwidth(ScrnInfoPtr pScrn, DisplayModePtr modeList, - unsigned int bandwidth, int depth) -{ - DisplayModePtr mode; - - for (mode = modeList; mode != NULL; mode = mode->next) { - if (xf86ModeBandwidth(mode, depth) > bandwidth) - mode->status = MODE_BANDWIDTH; - } -} - -Bool -xf86ModeIsReduced(const DisplayModeRec * mode) -{ - if ((((mode->HDisplay * 5 / 4) & ~0x07) > mode->HTotal) && - ((mode->HTotal - mode->HDisplay) == 160) && - ((mode->HSyncEnd - mode->HDisplay) == 80) && - ((mode->HSyncEnd - mode->HSyncStart) == 32) && - ((mode->VSyncStart - mode->VDisplay) == 3)) - return TRUE; - return FALSE; -} - -/** - * Marks as bad any reduced-blanking modes. - * - * \param modeList doubly-linked list of modes. - */ -void -xf86ValidateModesReducedBlanking(ScrnInfoPtr pScrn, DisplayModePtr modeList) -{ - for (; modeList != NULL; modeList = modeList->next) - if (xf86ModeIsReduced(modeList)) - modeList->status = MODE_NO_REDUCED; -} - -/** - * Frees any modes from the list with a status other than MODE_OK. - * - * \param modeList pointer to a doubly-linked or circular list of modes. - * \param verbose determines whether the reason for mode invalidation is - * printed. - */ -void -xf86PruneInvalidModes(ScrnInfoPtr pScrn, DisplayModePtr * modeList, - Bool verbose) -{ - DisplayModePtr mode; - - for (mode = *modeList; mode != NULL;) { - DisplayModePtr next = mode->next, first = *modeList; - - if (mode->status != MODE_OK) { - if (verbose) { - const char *type = ""; - - if (mode->type & M_T_BUILTIN) - type = "built-in "; - else if (mode->type & M_T_DEFAULT) - type = "default "; - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Not using %smode \"%s\" (%s)\n", type, mode->name, - xf86ModeStatusToString(mode->status)); - } - xf86DeleteMode(modeList, mode); - } - - if (next == first) - break; - mode = next; - } -} - -/** - * Adds the new mode into the mode list, and returns the new list - * - * \param modes doubly-linked mode list. - */ -DisplayModePtr -xf86ModesAdd(DisplayModePtr modes, DisplayModePtr new) -{ - if (modes == NULL) - return new; - - if (new) { - DisplayModePtr mode = modes; - - while (mode->next) - mode = mode->next; - - mode->next = new; - new->prev = mode; - } - - return modes; -} - -/** - * Build a mode list from a list of config file modes - */ -static DisplayModePtr -xf86GetConfigModes(XF86ConfModeLinePtr conf_mode) -{ - DisplayModePtr head = NULL, prev = NULL, mode; - - for (; conf_mode; conf_mode = (XF86ConfModeLinePtr) conf_mode->list.next) { - mode = calloc(1, sizeof(DisplayModeRec)); - if (!mode) - continue; - mode->name = xstrdup(conf_mode->ml_identifier); - if (!mode->name) { - free(mode); - continue; - } - mode->type = 0; - mode->Clock = conf_mode->ml_clock; - mode->HDisplay = conf_mode->ml_hdisplay; - mode->HSyncStart = conf_mode->ml_hsyncstart; - mode->HSyncEnd = conf_mode->ml_hsyncend; - mode->HTotal = conf_mode->ml_htotal; - mode->VDisplay = conf_mode->ml_vdisplay; - mode->VSyncStart = conf_mode->ml_vsyncstart; - mode->VSyncEnd = conf_mode->ml_vsyncend; - mode->VTotal = conf_mode->ml_vtotal; - mode->Flags = conf_mode->ml_flags; - mode->HSkew = conf_mode->ml_hskew; - mode->VScan = conf_mode->ml_vscan; - - mode->prev = prev; - mode->next = NULL; - if (prev) - prev->next = mode; - else - head = mode; - prev = mode; - } - return head; -} - -/** - * Build a mode list from a monitor configuration - */ -DisplayModePtr -xf86GetMonitorModes(ScrnInfoPtr pScrn, XF86ConfMonitorPtr conf_monitor) -{ - DisplayModePtr modes = NULL; - XF86ConfModesLinkPtr modes_link; - - if (!conf_monitor) - return NULL; - - /* - * first we collect the mode lines from the UseModes directive - */ - for (modes_link = conf_monitor->mon_modes_sect_lst; - modes_link; modes_link = modes_link->list.next) { - /* If this modes link hasn't been resolved, go look it up now */ - if (!modes_link->ml_modes) - modes_link->ml_modes = xf86findModes(modes_link->ml_modes_str, - xf86configptr->conf_modes_lst); - if (modes_link->ml_modes) - modes = xf86ModesAdd(modes, - xf86GetConfigModes(modes_link->ml_modes-> - mon_modeline_lst)); - } - - return xf86ModesAdd(modes, - xf86GetConfigModes(conf_monitor->mon_modeline_lst)); -} - -/** - * Build a mode list containing all of the default modes - */ -DisplayModePtr -xf86GetDefaultModes(void) -{ - DisplayModePtr head = NULL, mode; - int i; - - for (i = 0; i < xf86NumDefaultModes; i++) { - const DisplayModeRec *defMode = &xf86DefaultModes[i]; - - mode = xf86DuplicateMode(defMode); - head = xf86ModesAdd(head, mode); - } - return head; -} - -/* - * Walk a mode list and prune out duplicates. Will preserve the preferred - * mode of an otherwise-duplicate pair. - * - * Probably best to call this on lists that are all of a single class - * (driver, default, user, etc.), otherwise, which mode gets deleted is - * not especially well defined. - * - * Returns the new list. - */ - -DisplayModePtr -xf86PruneDuplicateModes(DisplayModePtr modes) -{ - DisplayModePtr m, n, o; - - top: - for (m = modes; m; m = m->next) { - for (n = m->next; n; n = o) { - o = n->next; - if (xf86ModesEqual(m, n)) { - if (n->type & M_T_PREFERRED) { - xf86DeleteMode(&modes, m); - goto top; - } - else - xf86DeleteMode(&modes, n); - } - } - } - - return modes; -} - -/* - * Generate a CVT standard mode from HDisplay, VDisplay and VRefresh. - */ -DisplayModePtr -xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced, - Bool Interlaced) -{ - struct libxcvt_mode_info *libxcvt_mode_info; - DisplayModeRec *Mode = xnfcalloc(1, sizeof(DisplayModeRec)); - char *tmp; - - libxcvt_mode_info = - libxcvt_gen_mode_info(HDisplay, VDisplay, VRefresh, Reduced, Interlaced); - - XNFasprintf(&tmp, "%dx%d", HDisplay, VDisplay); - Mode->name = tmp; - - Mode->VDisplay = libxcvt_mode_info->vdisplay; - Mode->HDisplay = libxcvt_mode_info->hdisplay; - Mode->Clock = libxcvt_mode_info->dot_clock; - Mode->HSyncStart = libxcvt_mode_info->hsync_start; - Mode->HSyncEnd = libxcvt_mode_info->hsync_end; - Mode->HTotal = libxcvt_mode_info->htotal; - Mode->VSyncStart = libxcvt_mode_info->vsync_start; - Mode->VSyncEnd = libxcvt_mode_info->vsync_end; - Mode->VTotal = libxcvt_mode_info->vtotal; - Mode->VRefresh = libxcvt_mode_info->vrefresh; - Mode->Flags = libxcvt_mode_info->mode_flags; - - free(libxcvt_mode_info); - - return Mode; -} diff --git a/hw/xfree86/modes/xf86Modes.h b/hw/xfree86/modes/xf86Modes.h deleted file mode 100644 index 545891884..000000000 --- a/hw/xfree86/modes/xf86Modes.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright © 2006 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Authors: - * Eric Anholt - * - */ - -#ifndef _XF86MODES_H_ -#define _XF86MODES_H_ - -#include -#include -#include - -#include "xf86.h" -#include "xorgVersion.h" -#include "edid.h" -#include "xf86Parser.h" - -extern _X_EXPORT double xf86ModeHSync(const DisplayModeRec * mode); -extern _X_EXPORT double xf86ModeVRefresh(const DisplayModeRec * mode); -extern _X_EXPORT unsigned int xf86ModeBandwidth(DisplayModePtr mode, int depth); - -extern _X_EXPORT int - xf86ModeWidth(const DisplayModeRec * mode, Rotation rotation); - -extern _X_EXPORT int - xf86ModeHeight(const DisplayModeRec * mode, Rotation rotation); - -extern _X_EXPORT DisplayModePtr xf86DuplicateMode(const DisplayModeRec * pMode); -extern _X_EXPORT DisplayModePtr xf86DuplicateModes(ScrnInfoPtr pScrn, - DisplayModePtr modeList); -extern _X_EXPORT void xf86SetModeDefaultName(DisplayModePtr mode); -extern _X_EXPORT void xf86SetModeCrtc(DisplayModePtr p, int adjustFlags); -extern _X_EXPORT Bool xf86ModesEqual(const DisplayModeRec * pMode1, - const DisplayModeRec * pMode2); -extern _X_EXPORT void xf86PrintModeline(int scrnIndex, DisplayModePtr mode); -extern _X_EXPORT DisplayModePtr xf86ModesAdd(DisplayModePtr modes, - DisplayModePtr new); - -extern _X_EXPORT DisplayModePtr xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC); -extern _X_EXPORT DisplayModePtr xf86CVTMode(int HDisplay, int VDisplay, - float VRefresh, Bool Reduced, - Bool Interlaced); -extern _X_EXPORT DisplayModePtr xf86GTFMode(int h_pixels, int v_lines, - float freq, int interlaced, - int margins); - -extern _X_EXPORT Bool - xf86ModeIsReduced(const DisplayModeRec * mode); - -extern _X_EXPORT void - xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList, int flags); - -extern _X_EXPORT void - -xf86ValidateModesClocks(ScrnInfoPtr pScrn, DisplayModePtr modeList, - int *min, int *max, int n_ranges); - -extern _X_EXPORT void - -xf86ValidateModesSize(ScrnInfoPtr pScrn, DisplayModePtr modeList, - int maxX, int maxY, int maxPitch); - -extern _X_EXPORT void - xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList, MonPtr mon); - -extern _X_EXPORT void - -xf86ValidateModesBandwidth(ScrnInfoPtr pScrn, DisplayModePtr modeList, - unsigned int bandwidth, int depth); - -extern _X_EXPORT void - xf86ValidateModesReducedBlanking(ScrnInfoPtr pScrn, DisplayModePtr modeList); - -extern _X_EXPORT void - -xf86PruneInvalidModes(ScrnInfoPtr pScrn, DisplayModePtr * modeList, - Bool verbose); - -extern _X_EXPORT DisplayModePtr xf86PruneDuplicateModes(DisplayModePtr modes); - -extern _X_EXPORT void - xf86ValidateModesUserConfig(ScrnInfoPtr pScrn, DisplayModePtr modeList); - -extern _X_EXPORT DisplayModePtr -xf86GetMonitorModes(ScrnInfoPtr pScrn, XF86ConfMonitorPtr conf_monitor); - -extern _X_EXPORT DisplayModePtr xf86GetDefaultModes(void); - -extern _X_EXPORT void -xf86SaveModeContents(DisplayModePtr intern, const DisplayModeRec *mode); - -extern _X_EXPORT void - xf86DDCApplyQuirks(int scrnIndex, xf86MonPtr DDC); - -#endif /* _XF86MODES_H_ */ diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c deleted file mode 100644 index 39a38c741..000000000 --- a/hw/xfree86/modes/xf86RandR12.c +++ /dev/null @@ -1,2410 +0,0 @@ -/* - * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "os.h" -#include "globals.h" -#include "xf86Modes.h" -#include "xf86Priv.h" -#include "xf86DDC.h" -#include "mipointer.h" -#include "windowstr.h" -#include "inputstr.h" -#include -#include - -#include "xf86cmap.h" -#include "xf86Crtc.h" -#include "xf86RandR12.h" - -typedef struct _xf86RandR12Info { - int virtualX; - int virtualY; - int mmWidth; - int mmHeight; - int maxX; - int maxY; - int pointerX; - int pointerY; - Rotation rotation; /* current mode */ - Rotation supported_rotations; /* driver supported */ - - /* Compatibility with colormaps and XF86VidMode's gamma */ - int palette_red_size; - int palette_green_size; - int palette_blue_size; - int palette_size; - LOCO *palette; - - /* Used to wrap EnterVT so we can re-probe the outputs when a laptop unsuspends - * (actually, any time that we switch back into our VT). - * - * See https://bugs.freedesktop.org/show_bug.cgi?id=21554 - */ - xf86EnterVTProc *orig_EnterVT; - - Bool panning; - ConstrainCursorHarderProcPtr orig_ConstrainCursorHarder; -} XF86RandRInfoRec, *XF86RandRInfoPtr; - -#ifdef RANDR_12_INTERFACE -static Bool xf86RandR12Init12(ScreenPtr pScreen); -static Bool xf86RandR12CreateScreenResources12(ScreenPtr pScreen); -#endif - -static int xf86RandR12Generation; - -static DevPrivateKeyRec xf86RandR12KeyRec; - -#define XF86RANDRINFO(p) ((XF86RandRInfoPtr) \ - dixLookupPrivate(&(p)->devPrivates, &xf86RandR12KeyRec)) - -static int -xf86RandR12ModeRefresh(DisplayModePtr mode) -{ - if (mode->VRefresh) - return (int) (mode->VRefresh + 0.5); - else - return (int) (mode->Clock * 1000.0 / mode->HTotal / mode->VTotal + 0.5); -} - -/* Adapt panning area; return TRUE if panning area was valid without adaption */ -static int -xf86RandR13VerifyPanningArea(xf86CrtcPtr crtc, int screenWidth, - int screenHeight) -{ - int ret = TRUE; - - if (crtc->version < 2) - return FALSE; - - if (crtc->panningTotalArea.x2 <= crtc->panningTotalArea.x1) { - /* Panning in X is disabled */ - if (crtc->panningTotalArea.x1 || crtc->panningTotalArea.x2) - /* Illegal configuration -> fail/disable */ - ret = FALSE; - crtc->panningTotalArea.x1 = crtc->panningTotalArea.x2 = 0; - crtc->panningTrackingArea.x1 = crtc->panningTrackingArea.x2 = 0; - crtc->panningBorder[0] = crtc->panningBorder[2] = 0; - } - else { - /* Panning in X is enabled */ - if (crtc->panningTotalArea.x1 < 0) { - /* Panning region outside screen -> move inside */ - crtc->panningTotalArea.x2 -= crtc->panningTotalArea.x1; - crtc->panningTotalArea.x1 = 0; - ret = FALSE; - } - if (crtc->panningTotalArea.x2 < - crtc->panningTotalArea.x1 + crtc->mode.HDisplay) { - /* Panning region smaller than displayed area -> crop to displayed area */ - crtc->panningTotalArea.x2 = - crtc->panningTotalArea.x1 + crtc->mode.HDisplay; - ret = FALSE; - } - if (crtc->panningTotalArea.x2 > screenWidth) { - /* Panning region larger than screen -> move inside, then crop to screen */ - crtc->panningTotalArea.x1 -= - crtc->panningTotalArea.x2 - screenWidth; - crtc->panningTotalArea.x2 = screenWidth; - ret = FALSE; - if (crtc->panningTotalArea.x1 < 0) - crtc->panningTotalArea.x1 = 0; - } - if (crtc->panningBorder[0] + crtc->panningBorder[2] > - crtc->mode.HDisplay) { - /* Borders too large -> set to 0 */ - crtc->panningBorder[0] = crtc->panningBorder[2] = 0; - ret = FALSE; - } - } - - if (crtc->panningTotalArea.y2 <= crtc->panningTotalArea.y1) { - /* Panning in Y is disabled */ - if (crtc->panningTotalArea.y1 || crtc->panningTotalArea.y2) - /* Illegal configuration -> fail/disable */ - ret = FALSE; - crtc->panningTotalArea.y1 = crtc->panningTotalArea.y2 = 0; - crtc->panningTrackingArea.y1 = crtc->panningTrackingArea.y2 = 0; - crtc->panningBorder[1] = crtc->panningBorder[3] = 0; - } - else { - /* Panning in Y is enabled */ - if (crtc->panningTotalArea.y1 < 0) { - /* Panning region outside screen -> move inside */ - crtc->panningTotalArea.y2 -= crtc->panningTotalArea.y1; - crtc->panningTotalArea.y1 = 0; - ret = FALSE; - } - if (crtc->panningTotalArea.y2 < - crtc->panningTotalArea.y1 + crtc->mode.VDisplay) { - /* Panning region smaller than displayed area -> crop to displayed area */ - crtc->panningTotalArea.y2 = - crtc->panningTotalArea.y1 + crtc->mode.VDisplay; - ret = FALSE; - } - if (crtc->panningTotalArea.y2 > screenHeight) { - /* Panning region larger than screen -> move inside, then crop to screen */ - crtc->panningTotalArea.y1 -= - crtc->panningTotalArea.y2 - screenHeight; - crtc->panningTotalArea.y2 = screenHeight; - ret = FALSE; - if (crtc->panningTotalArea.y1 < 0) - crtc->panningTotalArea.y1 = 0; - } - if (crtc->panningBorder[1] + crtc->panningBorder[3] > - crtc->mode.VDisplay) { - /* Borders too large -> set to 0 */ - crtc->panningBorder[1] = crtc->panningBorder[3] = 0; - ret = FALSE; - } - } - - return ret; -} - -/* - * The heart of the panning operation: - * - * Given a frame buffer position (fb_x, fb_y), - * and a crtc position (crtc_x, crtc_y), - * and a transform matrix which maps frame buffer to crtc, - * compute a panning position (pan_x, pan_y) that - * makes the resulting transform line those two up - */ - -static void -xf86ComputeCrtcPan(Bool transform_in_use, - struct pixman_f_transform *m, - double screen_x, double screen_y, - double crtc_x, double crtc_y, - int old_pan_x, int old_pan_y, int *new_pan_x, int *new_pan_y) -{ - if (transform_in_use) { - /* - * Given the current transform, M, the current position - * on the Screen, S, and the desired position on the CRTC, - * C, compute a translation, T, such that: - * - * M T S = C - * - * where T is of the form - * - * | 1 0 dx | - * | 0 1 dy | - * | 0 0 1 | - * - * M T S = - * | M00 Sx + M01 Sy + M00 dx + M01 dy + M02 | | Cx F | - * | M10 Sx + M11 Sy + M10 dx + M11 dy + M12 | = | Cy F | - * | M20 Sx + M21 Sy + M20 dx + M21 dy + M22 | | F | - * - * R = M S - * - * Cx F = M00 dx + M01 dy + R0 - * Cy F = M10 dx + M11 dy + R1 - * F = M20 dx + M21 dy + R2 - * - * Zero out dx, then dy - * - * F (Cx M10 - Cy M00) = - * (M10 M01 - M00 M11) dy + M10 R0 - M00 R1 - * F (M10 - Cy M20) = - * (M10 M21 - M20 M11) dy + M10 R2 - M20 R1 - * - * F (Cx M11 - Cy M01) = - * (M11 M00 - M01 M10) dx + M11 R0 - M01 R1 - * F (M11 - Cy M21) = - * (M11 M20 - M21 M10) dx + M11 R2 - M21 R1 - * - * Make some temporaries - * - * T = | Cx M10 - Cy M00 | - * | Cx M11 - Cy M01 | - * - * U = | M10 M01 - M00 M11 | - * | M11 M00 - M01 M10 | - * - * Q = | M10 R0 - M00 R1 | - * | M11 R0 - M01 R1 | - * - * P = | M10 - Cy M20 | - * | M11 - Cy M21 | - * - * W = | M10 M21 - M20 M11 | - * | M11 M20 - M21 M10 | - * - * V = | M10 R2 - M20 R1 | - * | M11 R2 - M21 R1 | - * - * Rewrite: - * - * F T0 = U0 dy + Q0 - * F P0 = W0 dy + V0 - * F T1 = U1 dx + Q1 - * F P1 = W1 dx + V1 - * - * Solve for F (two ways) - * - * F (W0 T0 - U0 P0) = W0 Q0 - U0 V0 - * - * W0 Q0 - U0 V0 - * F = ------------- - * W0 T0 - U0 P0 - * - * F (W1 T1 - U1 P1) = W1 Q1 - U1 V1 - * - * W1 Q1 - U1 V1 - * F = ------------- - * W1 T1 - U1 P1 - * - * We'll use which ever solution works (denominator != 0) - * - * Finally, solve for dx and dy: - * - * dx = (F T1 - Q1) / U1 - * dx = (F P1 - V1) / W1 - * - * dy = (F T0 - Q0) / U0 - * dy = (F P0 - V0) / W0 - */ - double r[3]; - double q[2], u[2], t[2], v[2], w[2], p[2]; - double f; - struct pict_f_vector d; - int i; - - /* Get the un-normalized crtc coordinates again */ - for (i = 0; i < 3; i++) - r[i] = m->m[i][0] * screen_x + m->m[i][1] * screen_y + m->m[i][2]; - - /* Combine values into temporaries */ - for (i = 0; i < 2; i++) { - q[i] = m->m[1][i] * r[0] - m->m[0][i] * r[1]; - u[i] = m->m[1][i] * m->m[0][1 - i] - m->m[0][i] * m->m[1][1 - i]; - t[i] = m->m[1][i] * crtc_x - m->m[0][i] * crtc_y; - - v[i] = m->m[1][i] * r[2] - m->m[2][i] * r[1]; - w[i] = m->m[1][i] * m->m[2][1 - i] - m->m[2][i] * m->m[1][1 - i]; - p[i] = m->m[1][i] - m->m[2][i] * crtc_y; - } - - /* Find a way to compute f */ - f = 0; - for (i = 0; i < 2; i++) { - double a = w[i] * q[i] - u[i] * v[i]; - double b = w[i] * t[i] - u[i] * p[i]; - - if (b != 0) { - f = a / b; - break; - } - } - - /* Solve for the resulting transform vector */ - for (i = 0; i < 2; i++) { - if (u[i]) - d.v[1 - i] = (t[i] * f - q[i]) / u[i]; - else if (w[1]) - d.v[1 - i] = (p[i] * f - v[i]) / w[i]; - else - d.v[1 - i] = 0; - } - *new_pan_x = old_pan_x - floor(d.v[0] + 0.5); - *new_pan_y = old_pan_y - floor(d.v[1] + 0.5); - } - else { - *new_pan_x = screen_x - crtc_x; - *new_pan_y = screen_y - crtc_y; - } -} - -static void -xf86RandR13Pan(xf86CrtcPtr crtc, int x, int y) -{ - int newX, newY; - int width, height; - Bool panned = FALSE; - - if (crtc->version < 2) - return; - - if (!crtc->enabled || - (crtc->panningTotalArea.x2 <= crtc->panningTotalArea.x1 && - crtc->panningTotalArea.y2 <= crtc->panningTotalArea.y1)) - return; - - newX = crtc->x; - newY = crtc->y; - width = crtc->mode.HDisplay; - height = crtc->mode.VDisplay; - - if ((crtc->panningTrackingArea.x2 <= crtc->panningTrackingArea.x1 || - (x >= crtc->panningTrackingArea.x1 && - x < crtc->panningTrackingArea.x2)) && - (crtc->panningTrackingArea.y2 <= crtc->panningTrackingArea.y1 || - (y >= crtc->panningTrackingArea.y1 && - y < crtc->panningTrackingArea.y2))) { - struct pict_f_vector c; - - /* - * Pre-clip the mouse position to the panning area so that we don't - * push the crtc outside. This doesn't deal with changes to the - * panning values, only mouse position changes. - */ - if (crtc->panningTotalArea.x2 > crtc->panningTotalArea.x1) { - if (x < crtc->panningTotalArea.x1) - x = crtc->panningTotalArea.x1; - if (x >= crtc->panningTotalArea.x2) - x = crtc->panningTotalArea.x2 - 1; - } - if (crtc->panningTotalArea.y2 > crtc->panningTotalArea.y1) { - if (y < crtc->panningTotalArea.y1) - y = crtc->panningTotalArea.y1; - if (y >= crtc->panningTotalArea.y2) - y = crtc->panningTotalArea.y2 - 1; - } - - c.v[0] = x; - c.v[1] = y; - c.v[2] = 1.0; - if (crtc->transform_in_use) { - pixman_f_transform_point(&crtc->f_framebuffer_to_crtc, &c); - } - else { - c.v[0] -= crtc->x; - c.v[1] -= crtc->y; - } - - if (crtc->panningTotalArea.x2 > crtc->panningTotalArea.x1) { - if (c.v[0] < crtc->panningBorder[0]) { - c.v[0] = crtc->panningBorder[0]; - panned = TRUE; - } - if (c.v[0] >= width - crtc->panningBorder[2]) { - c.v[0] = width - crtc->panningBorder[2] - 1; - panned = TRUE; - } - } - if (crtc->panningTotalArea.y2 > crtc->panningTotalArea.y1) { - if (c.v[1] < crtc->panningBorder[1]) { - c.v[1] = crtc->panningBorder[1]; - panned = TRUE; - } - if (c.v[1] >= height - crtc->panningBorder[3]) { - c.v[1] = height - crtc->panningBorder[3] - 1; - panned = TRUE; - } - } - if (panned) - xf86ComputeCrtcPan(crtc->transform_in_use, - &crtc->f_framebuffer_to_crtc, - x, y, c.v[0], c.v[1], newX, newY, &newX, &newY); - } - - /* - * Ensure that the crtc is within the panning region. - * - * XXX This computation only works when we do not have a transform - * in use. - */ - if (!crtc->transform_in_use) { - /* Validate against [xy]1 after [xy]2, to be sure that results are > 0 for [xy]1 > 0 */ - if (crtc->panningTotalArea.x2 > crtc->panningTotalArea.x1) { - if (newX > crtc->panningTotalArea.x2 - width) - newX = crtc->panningTotalArea.x2 - width; - if (newX < crtc->panningTotalArea.x1) - newX = crtc->panningTotalArea.x1; - } - if (crtc->panningTotalArea.y2 > crtc->panningTotalArea.y1) { - if (newY > crtc->panningTotalArea.y2 - height) - newY = crtc->panningTotalArea.y2 - height; - if (newY < crtc->panningTotalArea.y1) - newY = crtc->panningTotalArea.y1; - } - } - if (newX != crtc->x || newY != crtc->y) - xf86CrtcSetOrigin(crtc, newX, newY); -} - -static Bool -xf86RandR12GetInfo(ScreenPtr pScreen, Rotation * rotations) -{ - RRScreenSizePtr pSize; - ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - DisplayModePtr mode; - int maxX = 0, maxY = 0; - - *rotations = randrp->supported_rotations; - - if (randrp->virtualX == -1 || randrp->virtualY == -1) { - randrp->virtualX = scrp->virtualX; - randrp->virtualY = scrp->virtualY; - } - - /* Re-probe the outputs for new monitors or modes */ - if (scrp->vtSema) { - xf86ProbeOutputModes(scrp, 0, 0); - xf86SetScrnInfoModes(scrp); - } - - for (mode = scrp->modes;; mode = mode->next) { - int refresh = xf86RandR12ModeRefresh(mode); - - if (randrp->maxX == 0 || randrp->maxY == 0) { - if (maxX < mode->HDisplay) - maxX = mode->HDisplay; - if (maxY < mode->VDisplay) - maxY = mode->VDisplay; - } - pSize = RRRegisterSize(pScreen, - mode->HDisplay, mode->VDisplay, - randrp->mmWidth, randrp->mmHeight); - if (!pSize) - return FALSE; - RRRegisterRate(pScreen, pSize, refresh); - - if (xf86ModesEqual(mode, scrp->currentMode)) { - RRSetCurrentConfig(pScreen, randrp->rotation, refresh, pSize); - } - if (mode->next == scrp->modes) - break; - } - - if (randrp->maxX == 0 || randrp->maxY == 0) { - randrp->maxX = maxX; - randrp->maxY = maxY; - } - - return TRUE; -} - -static Bool -xf86RandR12SetMode(ScreenPtr pScreen, - DisplayModePtr mode, - Bool useVirtual, int mmWidth, int mmHeight) -{ - ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - int oldWidth = pScreen->width; - int oldHeight = pScreen->height; - int oldmmWidth = pScreen->mmWidth; - int oldmmHeight = pScreen->mmHeight; - WindowPtr pRoot = pScreen->root; - DisplayModePtr currentMode = NULL; - Bool ret = TRUE; - - if (pRoot) - (*scrp->EnableDisableFBAccess) (scrp, FALSE); - if (useVirtual) { - scrp->virtualX = randrp->virtualX; - scrp->virtualY = randrp->virtualY; - } - else { - scrp->virtualX = mode->HDisplay; - scrp->virtualY = mode->VDisplay; - } - - if (randrp->rotation & (RR_Rotate_90 | RR_Rotate_270)) { - /* If the screen is rotated 90 or 270 degrees, swap the sizes. */ - pScreen->width = scrp->virtualY; - pScreen->height = scrp->virtualX; - pScreen->mmWidth = mmHeight; - pScreen->mmHeight = mmWidth; - } - else { - pScreen->width = scrp->virtualX; - pScreen->height = scrp->virtualY; - pScreen->mmWidth = mmWidth; - pScreen->mmHeight = mmHeight; - } - if (scrp->currentMode == mode) { - /* Save current mode */ - currentMode = scrp->currentMode; - /* Reset, just so we ensure the drivers SwitchMode is called */ - scrp->currentMode = NULL; - } - /* - * We know that if the driver failed to SwitchMode to the rotated - * version, then it should revert back to its prior mode. - */ - if (!xf86SwitchMode(pScreen, mode)) { - ret = FALSE; - scrp->virtualX = pScreen->width = oldWidth; - scrp->virtualY = pScreen->height = oldHeight; - pScreen->mmWidth = oldmmWidth; - pScreen->mmHeight = oldmmHeight; - scrp->currentMode = currentMode; - } - - /* - * Make sure the layout is correct - */ - xf86ReconfigureLayout(); - - /* - * Make sure the whole screen is visible - */ - xf86SetViewport(pScreen, pScreen->width, pScreen->height); - xf86SetViewport(pScreen, 0, 0); - if (pRoot) - (*scrp->EnableDisableFBAccess) (scrp, TRUE); - return ret; -} - -Bool -xf86RandR12SetConfig(ScreenPtr pScreen, - Rotation rotation, int rate, RRScreenSizePtr pSize) -{ - ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - DisplayModePtr mode; - int pos[MAXDEVICES][2]; - Bool useVirtual = FALSE; - int maxX = 0, maxY = 0; - Rotation oldRotation = randrp->rotation; - DeviceIntPtr dev; - Bool view_adjusted = FALSE; - - randrp->rotation = rotation; - - if (randrp->virtualX == -1 || randrp->virtualY == -1) { - randrp->virtualX = scrp->virtualX; - randrp->virtualY = scrp->virtualY; - } - - for (dev = inputInfo.devices; dev; dev = dev->next) { - if (!IsMaster(dev) && !IsFloating(dev)) - continue; - - miPointerGetPosition(dev, &pos[dev->id][0], &pos[dev->id][1]); - } - - for (mode = scrp->modes;; mode = mode->next) { - if (randrp->maxX == 0 || randrp->maxY == 0) { - if (maxX < mode->HDisplay) - maxX = mode->HDisplay; - if (maxY < mode->VDisplay) - maxY = mode->VDisplay; - } - if (mode->HDisplay == pSize->width && - mode->VDisplay == pSize->height && - (rate == 0 || xf86RandR12ModeRefresh(mode) == rate)) - break; - if (mode->next == scrp->modes) { - if (pSize->width == randrp->virtualX && - pSize->height == randrp->virtualY) { - mode = scrp->modes; - useVirtual = TRUE; - break; - } - if (randrp->maxX == 0 || randrp->maxY == 0) { - randrp->maxX = maxX; - randrp->maxY = maxY; - } - return FALSE; - } - } - - if (randrp->maxX == 0 || randrp->maxY == 0) { - randrp->maxX = maxX; - randrp->maxY = maxY; - } - - if (!xf86RandR12SetMode(pScreen, mode, useVirtual, pSize->mmWidth, - pSize->mmHeight)) { - randrp->rotation = oldRotation; - return FALSE; - } - - /* - * Move the cursor back where it belongs; SwitchMode repositions it - * FIXME: duplicated code, see modes/xf86RandR12.c - */ - for (dev = inputInfo.devices; dev; dev = dev->next) { - if (!IsMaster(dev) && !IsFloating(dev)) - continue; - - if (pScreen == miPointerGetScreen(dev)) { - int px = pos[dev->id][0]; - int py = pos[dev->id][1]; - - px = (px >= pScreen->width ? (pScreen->width - 1) : px); - py = (py >= pScreen->height ? (pScreen->height - 1) : py); - - /* Setting the viewpoint makes only sense on one device */ - if (!view_adjusted && IsMaster(dev)) { - xf86SetViewport(pScreen, px, py); - view_adjusted = TRUE; - } - - (*pScreen->SetCursorPosition) (dev, pScreen, px, py, FALSE); - } - } - - return TRUE; -} - -#define PANNING_ENABLED(crtc) \ - ((crtc)->panningTotalArea.x2 > (crtc)->panningTotalArea.x1 || \ - (crtc)->panningTotalArea.y2 > (crtc)->panningTotalArea.y1) - -static Bool -xf86RandR12ScreenSetSize(ScreenPtr pScreen, - CARD16 width, - CARD16 height, CARD32 mmWidth, CARD32 mmHeight) -{ - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - WindowPtr pRoot = pScreen->root; - PixmapPtr pScrnPix; - Bool ret = FALSE; - int c; - - if (randrp->virtualX == -1 || randrp->virtualY == -1) { - randrp->virtualX = pScrn->virtualX; - randrp->virtualY = pScrn->virtualY; - } - if (pRoot && pScrn->vtSema) - (*pScrn->EnableDisableFBAccess) (pScrn, FALSE); - - /* Let the driver update virtualX and virtualY */ - if (!(*config->funcs->resize) (pScrn, width, height)) - goto finish; - - ret = TRUE; - /* Update panning information */ - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - if (PANNING_ENABLED (crtc)) { - if (crtc->panningTotalArea.x2 > crtc->panningTrackingArea.x1) - crtc->panningTotalArea.x2 += width - pScreen->width; - if (crtc->panningTotalArea.y2 > crtc->panningTrackingArea.y1) - crtc->panningTotalArea.y2 += height - pScreen->height; - if (crtc->panningTrackingArea.x2 > crtc->panningTrackingArea.x1) - crtc->panningTrackingArea.x2 += width - pScreen->width; - if (crtc->panningTrackingArea.y2 > crtc->panningTrackingArea.y1) - crtc->panningTrackingArea.y2 += height - pScreen->height; - xf86RandR13VerifyPanningArea(crtc, width, height); - xf86RandR13Pan(crtc, randrp->pointerX, randrp->pointerY); - } - } - - pScrnPix = (*pScreen->GetScreenPixmap) (pScreen); - pScreen->width = pScrnPix->drawable.width = width; - pScreen->height = pScrnPix->drawable.height = height; - randrp->mmWidth = pScreen->mmWidth = mmWidth; - randrp->mmHeight = pScreen->mmHeight = mmHeight; - - xf86SetViewport(pScreen, pScreen->width - 1, pScreen->height - 1); - xf86SetViewport(pScreen, 0, 0); - - finish: - update_desktop_dimensions(); - - if (pRoot && pScrn->vtSema) - (*pScrn->EnableDisableFBAccess) (pScrn, TRUE); -#if RANDR_12_INTERFACE - if (pScreen->root && ret) - RRScreenSizeNotify(pScreen); -#endif - return ret; -} - -Rotation -xf86RandR12GetRotation(ScreenPtr pScreen) -{ - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - - return randrp->rotation; -} - -Bool -xf86RandR12CreateScreenResources(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config; - XF86RandRInfoPtr randrp; - int c; - int width, height; - int mmWidth, mmHeight; - -#ifdef PANORAMIX - /* XXX disable RandR when using Xinerama */ - if (!noPanoramiXExtension) - return TRUE; -#endif - - config = XF86_CRTC_CONFIG_PTR(pScrn); - randrp = XF86RANDRINFO(pScreen); - /* - * Compute size of screen - */ - width = 0; - height = 0; - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - int crtc_width = crtc->x + xf86ModeWidth(&crtc->mode, crtc->rotation); - int crtc_height = crtc->y + xf86ModeHeight(&crtc->mode, crtc->rotation); - - if (crtc->enabled) { - if (crtc_width > width) - width = crtc_width; - if (crtc_height > height) - height = crtc_height; - if (crtc->panningTotalArea.x2 > width) - width = crtc->panningTotalArea.x2; - if (crtc->panningTotalArea.y2 > height) - height = crtc->panningTotalArea.y2; - } - } - - if (width && height) { - /* - * Compute physical size of screen - */ - if (monitorResolution) { - mmWidth = width * 25.4 / monitorResolution; - mmHeight = height * 25.4 / monitorResolution; - } - else { - xf86OutputPtr output = xf86CompatOutput(pScrn); - - if (output && - output->conf_monitor && - (output->conf_monitor->mon_width > 0 && - output->conf_monitor->mon_height > 0)) { - /* - * Prefer user configured DisplaySize - */ - mmWidth = output->conf_monitor->mon_width; - mmHeight = output->conf_monitor->mon_height; - } - else { - /* - * Otherwise, just set the screen to DEFAULT_DPI - */ - mmWidth = width * 25.4 / DEFAULT_DPI; - mmHeight = height * 25.4 / DEFAULT_DPI; - } - } - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - "Setting screen physical size to %d x %d\n", - mmWidth, mmHeight); - /* - * This is the initial setting of the screen size. - * We have to pre-set it here, otherwise panning would be adapted - * to the new screen size. - */ - pScreen->width = width; - pScreen->height = height; - xf86RandR12ScreenSetSize(pScreen, width, height, mmWidth, mmHeight); - } - - if (randrp->virtualX == -1 || randrp->virtualY == -1) { - randrp->virtualX = pScrn->virtualX; - randrp->virtualY = pScrn->virtualY; - } - xf86CrtcSetScreenSubpixelOrder(pScreen); -#if RANDR_12_INTERFACE - if (xf86RandR12CreateScreenResources12(pScreen)) - return TRUE; -#endif - return TRUE; -} - -Bool -xf86RandR12Init(ScreenPtr pScreen) -{ - rrScrPrivPtr rp; - XF86RandRInfoPtr randrp; - -#ifdef PANORAMIX - /* XXX disable RandR when using Xinerama */ - if (!noPanoramiXExtension) { - if (xf86NumScreens == 1) - noPanoramiXExtension = TRUE; - else - return TRUE; - } -#endif - - if (xf86RandR12Generation != serverGeneration) - xf86RandR12Generation = serverGeneration; - - if (!dixRegisterPrivateKey(&xf86RandR12KeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - randrp = malloc(sizeof(XF86RandRInfoRec)); - if (!randrp) - return FALSE; - - if (!RRScreenInit(pScreen)) { - free(randrp); - return FALSE; - } - rp = rrGetScrPriv(pScreen); - rp->rrGetInfo = xf86RandR12GetInfo; - rp->rrSetConfig = xf86RandR12SetConfig; - - randrp->virtualX = -1; - randrp->virtualY = -1; - randrp->mmWidth = pScreen->mmWidth; - randrp->mmHeight = pScreen->mmHeight; - - randrp->rotation = RR_Rotate_0; /* initial rotated mode */ - - randrp->supported_rotations = RR_Rotate_0; - - randrp->maxX = randrp->maxY = 0; - - randrp->palette_size = 0; - randrp->palette = NULL; - - dixSetPrivate(&pScreen->devPrivates, &xf86RandR12KeyRec, randrp); - -#if RANDR_12_INTERFACE - if (!xf86RandR12Init12(pScreen)) - return FALSE; -#endif - return TRUE; -} - -void -xf86RandR12CloseScreen(ScreenPtr pScreen) -{ - XF86RandRInfoPtr randrp; - - if (!dixPrivateKeyRegistered(&xf86RandR12KeyRec)) - return; - - randrp = XF86RANDRINFO(pScreen); -#if RANDR_12_INTERFACE - xf86ScreenToScrn(pScreen)->EnterVT = randrp->orig_EnterVT; - pScreen->ConstrainCursorHarder = randrp->orig_ConstrainCursorHarder; -#endif - - free(randrp->palette); - free(randrp); -} - -void -xf86RandR12SetRotations(ScreenPtr pScreen, Rotation rotations) -{ - XF86RandRInfoPtr randrp; - -#if RANDR_12_INTERFACE - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - int c; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); -#endif - - if (!dixPrivateKeyRegistered(&xf86RandR12KeyRec)) - return; - - randrp = XF86RANDRINFO(pScreen); -#if RANDR_12_INTERFACE - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - RRCrtcSetRotations(crtc->randr_crtc, rotations); - } -#endif - randrp->supported_rotations = rotations; -} - -void -xf86RandR12SetTransformSupport(ScreenPtr pScreen, Bool transforms) -{ -#if RANDR_13_INTERFACE - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - int c; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - - if (!dixPrivateKeyRegistered(&xf86RandR12KeyRec)) - return; - - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - RRCrtcSetTransformSupport(crtc->randr_crtc, transforms); - } -#endif -} - -void -xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr pScrn, int *x, int *y) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - - if (xf86RandR12Generation != serverGeneration || - XF86RANDRINFO(pScreen)->virtualX == -1) { - *x = pScrn->virtualX; - *y = pScrn->virtualY; - } - else { - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - - *x = randrp->virtualX; - *y = randrp->virtualY; - } -} - -#if RANDR_12_INTERFACE - -#define FLAG_BITS (RR_HSyncPositive | \ - RR_HSyncNegative | \ - RR_VSyncPositive | \ - RR_VSyncNegative | \ - RR_Interlace | \ - RR_DoubleScan | \ - RR_CSync | \ - RR_CSyncPositive | \ - RR_CSyncNegative | \ - RR_HSkewPresent | \ - RR_BCast | \ - RR_PixelMultiplex | \ - RR_DoubleClock | \ - RR_ClockDivideBy2) - -static Bool -xf86RandRModeMatches(RRModePtr randr_mode, DisplayModePtr mode) -{ -#if 0 - if (match_name) { - /* check for same name */ - int len = strlen(mode->name); - - if (randr_mode->mode.nameLength != len) - return FALSE; - if (memcmp(randr_mode->name, mode->name, len) != 0) - return FALSE; - } -#endif - - /* check for same timings */ - if (randr_mode->mode.dotClock / 1000 != mode->Clock) - return FALSE; - if (randr_mode->mode.width != mode->HDisplay) - return FALSE; - if (randr_mode->mode.hSyncStart != mode->HSyncStart) - return FALSE; - if (randr_mode->mode.hSyncEnd != mode->HSyncEnd) - return FALSE; - if (randr_mode->mode.hTotal != mode->HTotal) - return FALSE; - if (randr_mode->mode.hSkew != mode->HSkew) - return FALSE; - if (randr_mode->mode.height != mode->VDisplay) - return FALSE; - if (randr_mode->mode.vSyncStart != mode->VSyncStart) - return FALSE; - if (randr_mode->mode.vSyncEnd != mode->VSyncEnd) - return FALSE; - if (randr_mode->mode.vTotal != mode->VTotal) - return FALSE; - - /* check for same flags (using only the XF86 valid flag bits) */ - if ((randr_mode->mode.modeFlags & FLAG_BITS) != (mode->Flags & FLAG_BITS)) - return FALSE; - - /* everything matches */ - return TRUE; -} - -static Bool -xf86RandR12CrtcNotify(RRCrtcPtr randr_crtc) -{ - ScreenPtr pScreen = randr_crtc->pScreen; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - RRModePtr randr_mode = NULL; - int x; - int y; - Rotation rotation; - int numOutputs; - RROutputPtr *randr_outputs; - RROutputPtr randr_output; - xf86CrtcPtr crtc = randr_crtc->devPrivate; - xf86OutputPtr output; - int i, j; - DisplayModePtr mode = &crtc->mode; - Bool ret; - - randr_outputs = xallocarray(config->num_output, sizeof(RROutputPtr)); - if (!randr_outputs) - return FALSE; - x = crtc->x; - y = crtc->y; - rotation = crtc->rotation; - numOutputs = 0; - randr_mode = NULL; - for (i = 0; i < config->num_output; i++) { - output = config->output[i]; - if (output->crtc == crtc) { - randr_output = output->randr_output; - randr_outputs[numOutputs++] = randr_output; - /* - * We make copies of modes, so pointer equality - * isn't sufficient - */ - for (j = 0; j < randr_output->numModes + randr_output->numUserModes; - j++) { - RRModePtr m = - (j < - randr_output->numModes ? randr_output-> - modes[j] : randr_output->userModes[j - - randr_output-> - numModes]); - - if (xf86RandRModeMatches(m, mode)) { - randr_mode = m; - break; - } - } - } - } - ret = RRCrtcNotify(randr_crtc, randr_mode, x, y, - rotation, - crtc->transformPresent ? &crtc->transform : NULL, - numOutputs, randr_outputs); - free(randr_outputs); - return ret; -} - -/* - * Convert a RandR mode to a DisplayMode - */ -static void -xf86RandRModeConvert(ScrnInfoPtr scrn, - RRModePtr randr_mode, DisplayModePtr mode) -{ - memset(mode, 0, sizeof(DisplayModeRec)); - mode->status = MODE_OK; - - mode->Clock = randr_mode->mode.dotClock / 1000; - - mode->HDisplay = randr_mode->mode.width; - mode->HSyncStart = randr_mode->mode.hSyncStart; - mode->HSyncEnd = randr_mode->mode.hSyncEnd; - mode->HTotal = randr_mode->mode.hTotal; - mode->HSkew = randr_mode->mode.hSkew; - - mode->VDisplay = randr_mode->mode.height; - mode->VSyncStart = randr_mode->mode.vSyncStart; - mode->VSyncEnd = randr_mode->mode.vSyncEnd; - mode->VTotal = randr_mode->mode.vTotal; - mode->VScan = 0; - - mode->Flags = randr_mode->mode.modeFlags & FLAG_BITS; - - xf86SetModeCrtc(mode, scrn->adjustFlags); -} - -static Bool -xf86RandR12CrtcSet(ScreenPtr pScreen, - RRCrtcPtr randr_crtc, - RRModePtr randr_mode, - int x, - int y, - Rotation rotation, - int num_randr_outputs, RROutputPtr * randr_outputs) -{ - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - xf86CrtcPtr crtc = randr_crtc->devPrivate; - RRTransformPtr transform; - Bool changed = FALSE; - int o, ro; - xf86CrtcPtr *save_crtcs; - Bool save_enabled = crtc->enabled; - - if (!crtc->scrn->vtSema) - return FALSE; - - save_crtcs = xallocarray(config->num_output, sizeof(xf86CrtcPtr)); - if ((randr_mode != NULL) != crtc->enabled) - changed = TRUE; - else if (randr_mode && !xf86RandRModeMatches(randr_mode, &crtc->mode)) - changed = TRUE; - - if (rotation != crtc->rotation) - changed = TRUE; - - if (crtc->current_scanout != randr_crtc->scanout_pixmap || - crtc->current_scanout_back != randr_crtc->scanout_pixmap_back) - changed = TRUE; - - transform = RRCrtcGetTransform(randr_crtc); - if ((transform != NULL) != crtc->transformPresent) - changed = TRUE; - else if (transform && - !RRTransformEqual(transform, &crtc->transform)) - changed = TRUE; - - if (x != crtc->x || y != crtc->y) - changed = TRUE; - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - xf86CrtcPtr new_crtc; - - save_crtcs[o] = output->crtc; - - if (output->crtc == crtc) - new_crtc = NULL; - else - new_crtc = output->crtc; - for (ro = 0; ro < num_randr_outputs; ro++) - if (output->randr_output == randr_outputs[ro]) { - new_crtc = crtc; - break; - } - if (new_crtc != output->crtc) { - changed = TRUE; - output->crtc = new_crtc; - } - } - for (ro = 0; ro < num_randr_outputs; ro++) - if (randr_outputs[ro]->pendingProperties) - changed = TRUE; - - /* XXX need device-independent mode setting code through an API */ - if (changed) { - crtc->enabled = randr_mode != NULL; - - if (randr_mode) { - DisplayModeRec mode; - - xf86RandRModeConvert(pScrn, randr_mode, &mode); - if (!xf86CrtcSetModeTransform - (crtc, &mode, rotation, transform, x, y)) { - crtc->enabled = save_enabled; - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - output->crtc = save_crtcs[o]; - } - free(save_crtcs); - return FALSE; - } - xf86RandR13VerifyPanningArea(crtc, pScreen->width, pScreen->height); - xf86RandR13Pan(crtc, randrp->pointerX, randrp->pointerY); - randrp->panning = PANNING_ENABLED (crtc); - /* - * Save the last successful setting for EnterVT - */ - xf86SaveModeContents(&crtc->desiredMode, &mode); - crtc->desiredRotation = rotation; - crtc->current_scanout = randr_crtc->scanout_pixmap; - crtc->current_scanout_back = randr_crtc->scanout_pixmap_back; - if (transform) { - crtc->desiredTransform = *transform; - crtc->desiredTransformPresent = TRUE; - } - else - crtc->desiredTransformPresent = FALSE; - - crtc->desiredX = x; - crtc->desiredY = y; - } - xf86DisableUnusedFunctions(pScrn); - } - free(save_crtcs); - return xf86RandR12CrtcNotify(randr_crtc); -} - -static void -xf86RandR12CrtcComputeGamma(xf86CrtcPtr crtc, LOCO *palette, - int palette_red_size, int palette_green_size, - int palette_blue_size, CARD16 *gamma_red, - CARD16 *gamma_green, CARD16 *gamma_blue, - int gamma_size) -{ - int gamma_slots; - unsigned shift; - int i, j; - CARD32 value = 0; - - for (shift = 0; (gamma_size << shift) < (1 << 16); shift++); - - if (crtc->gamma_size >= palette_red_size) { - /* Upsampling of smaller palette to larger hw lut size */ - gamma_slots = crtc->gamma_size / palette_red_size; - for (i = 0; i < palette_red_size; i++) { - value = palette[i].red; - if (gamma_red) - value = gamma_red[value]; - else - value <<= shift; - - for (j = 0; j < gamma_slots; j++) - crtc->gamma_red[i * gamma_slots + j] = value; - } - - /* Replicate last value until end of crtc for gamma_size not a power of 2 */ - for (j = i * gamma_slots; j < crtc->gamma_size; j++) - crtc->gamma_red[j] = value; - } else { - /* Downsampling of larger palette to smaller hw lut size */ - for (i = 0; i < crtc->gamma_size; i++) { - value = palette[i * (palette_red_size - 1) / (crtc->gamma_size - 1)].red; - if (gamma_red) - value = gamma_red[value]; - else - value <<= shift; - - crtc->gamma_red[i] = value; - } - } - - if (crtc->gamma_size >= palette_green_size) { - /* Upsampling of smaller palette to larger hw lut size */ - gamma_slots = crtc->gamma_size / palette_green_size; - for (i = 0; i < palette_green_size; i++) { - value = palette[i].green; - if (gamma_green) - value = gamma_green[value]; - else - value <<= shift; - - for (j = 0; j < gamma_slots; j++) - crtc->gamma_green[i * gamma_slots + j] = value; - } - - /* Replicate last value until end of crtc for gamma_size not a power of 2 */ - for (j = i * gamma_slots; j < crtc->gamma_size; j++) - crtc->gamma_green[j] = value; - } else { - /* Downsampling of larger palette to smaller hw lut size */ - for (i = 0; i < crtc->gamma_size; i++) { - value = palette[i * (palette_green_size - 1) / (crtc->gamma_size - 1)].green; - if (gamma_green) - value = gamma_green[value]; - else - value <<= shift; - - crtc->gamma_green[i] = value; - } - } - - if (crtc->gamma_size >= palette_blue_size) { - /* Upsampling of smaller palette to larger hw lut size */ - gamma_slots = crtc->gamma_size / palette_blue_size; - for (i = 0; i < palette_blue_size; i++) { - value = palette[i].blue; - if (gamma_blue) - value = gamma_blue[value]; - else - value <<= shift; - - for (j = 0; j < gamma_slots; j++) - crtc->gamma_blue[i * gamma_slots + j] = value; - } - - /* Replicate last value until end of crtc for gamma_size not a power of 2 */ - for (j = i * gamma_slots; j < crtc->gamma_size; j++) - crtc->gamma_blue[j] = value; - } else { - /* Downsampling of larger palette to smaller hw lut size */ - for (i = 0; i < crtc->gamma_size; i++) { - value = palette[i * (palette_blue_size - 1) / (crtc->gamma_size - 1)].blue; - if (gamma_blue) - value = gamma_blue[value]; - else - value <<= shift; - - crtc->gamma_blue[i] = value; - } - } -} - -static void -xf86RandR12CrtcReloadGamma(xf86CrtcPtr crtc) -{ - if (!crtc->scrn->vtSema || !crtc->funcs->gamma_set) - return; - - /* Only set it when the crtc is actually running. - * Otherwise it will be set when it's activated. - */ - if (crtc->active) - crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green, - crtc->gamma_blue, crtc->gamma_size); -} - -static Bool -xf86RandR12CrtcSetGamma(ScreenPtr pScreen, RRCrtcPtr randr_crtc) -{ - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - xf86CrtcPtr crtc = randr_crtc->devPrivate; - int max_size = crtc->gamma_size; - - if (crtc->funcs->gamma_set == NULL) - return FALSE; - - if (randrp->palette_size) { - xf86RandR12CrtcComputeGamma(crtc, randrp->palette, - randrp->palette_red_size, - randrp->palette_green_size, - randrp->palette_blue_size, - randr_crtc->gammaRed, - randr_crtc->gammaGreen, - randr_crtc->gammaBlue, - randr_crtc->gammaSize); - } else { - if (max_size > randr_crtc->gammaSize) - max_size = randr_crtc->gammaSize; - - memcpy(crtc->gamma_red, randr_crtc->gammaRed, - max_size * sizeof(crtc->gamma_red[0])); - memcpy(crtc->gamma_green, randr_crtc->gammaGreen, - max_size * sizeof(crtc->gamma_green[0])); - memcpy(crtc->gamma_blue, randr_crtc->gammaBlue, - max_size * sizeof(crtc->gamma_blue[0])); - } - - xf86RandR12CrtcReloadGamma(crtc); - - return TRUE; -} - -static void -init_one_component(CARD16 *comp, unsigned size, float gamma) -{ - int i; - unsigned shift; - - for (shift = 0; (size << shift) < (1 << 16); shift++); - - if (gamma == 1.0) { - for (i = 0; i < size; i++) - comp[i] = i << shift; - } else { - for (i = 0; i < size; i++) - comp[i] = (CARD16) (pow((double) i / (double) (size - 1), - 1. / (double) gamma) * - (double) (size - 1) * (1 << shift)); - } -} - -static Bool -xf86RandR12CrtcInitGamma(xf86CrtcPtr crtc, float gamma_red, float gamma_green, - float gamma_blue) -{ - unsigned size = crtc->randr_crtc->gammaSize; - CARD16 *red, *green, *blue; - - if (!crtc->funcs->gamma_set && - (gamma_red != 1.0f || gamma_green != 1.0f || gamma_blue != 1.0f)) - return FALSE; - - red = xallocarray(size, 3 * sizeof(CARD16)); - if (!red) - return FALSE; - - green = red + size; - blue = green + size; - - init_one_component(red, size, gamma_red); - init_one_component(green, size, gamma_green); - init_one_component(blue, size, gamma_blue); - - RRCrtcGammaSet(crtc->randr_crtc, red, green, blue); - free(red); - - return TRUE; -} - -static Bool -xf86RandR12OutputInitGamma(xf86OutputPtr output) -{ - XF86ConfMonitorPtr mon = output->conf_monitor; - float gamma_red = 1.0, gamma_green = 1.0, gamma_blue = 1.0; - - if (!mon) - return TRUE; - - /* Get configured values, where they exist. */ - if (mon->mon_gamma_red >= GAMMA_MIN && mon->mon_gamma_red <= GAMMA_MAX) - gamma_red = mon->mon_gamma_red; - - if (mon->mon_gamma_green >= GAMMA_MIN && mon->mon_gamma_green <= GAMMA_MAX) - gamma_green = mon->mon_gamma_green; - - if (mon->mon_gamma_blue >= GAMMA_MIN && mon->mon_gamma_blue <= GAMMA_MAX) - gamma_blue = mon->mon_gamma_blue; - - /* Don't set gamma 1.0 if another cloned output on this CRTC already set a - * different gamma - */ - if (gamma_red != 1.0 || gamma_green != 1.0 || gamma_blue != 1.0) { - if (!output->crtc->randr_crtc) { - xf86DrvMsg(output->scrn->scrnIndex, X_WARNING, - "Gamma correction for output %s not possible because " - "RandR is disabled\n", output->name); - return TRUE; - } - - xf86DrvMsg(output->scrn->scrnIndex, X_INFO, - "Output %s wants gamma correction (%.1f, %.1f, %.1f)\n", - output->name, gamma_red, gamma_green, gamma_blue); - return xf86RandR12CrtcInitGamma(output->crtc, gamma_red, gamma_green, - gamma_blue); - } - - return TRUE; -} - -Bool -xf86RandR12InitGamma(ScrnInfoPtr pScrn, unsigned gammaSize) { - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int o, c; - - /* Set default gamma for all CRTCs - * This is done to avoid problems later on with cloned outputs - */ - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - if (!crtc->randr_crtc) - continue; - - if (!RRCrtcGammaSetSize(crtc->randr_crtc, gammaSize) || - !xf86RandR12CrtcInitGamma(crtc, 1.0f, 1.0f, 1.0f)) - return FALSE; - } - - /* Set initial gamma per monitor configuration - */ - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - if (output->crtc && - !xf86RandR12OutputInitGamma(output)) - xf86DrvMsg(pScrn->scrnIndex, X_WARNING, - "Initial gamma correction for output %s: failed.\n", - output->name); - } - - return TRUE; -} - -static Bool -xf86RandR12OutputSetProperty(ScreenPtr pScreen, - RROutputPtr randr_output, - Atom property, RRPropertyValuePtr value) -{ - xf86OutputPtr output = randr_output->devPrivate; - - /* If we don't have any property handler, then we don't care what the - * user is setting properties to. - */ - if (output->funcs->set_property == NULL) - return TRUE; - - /* - * This function gets called even when vtSema is FALSE, as - * drivers will need to remember the correct value to apply - * when the VT switch occurs - */ - return output->funcs->set_property(output, property, value); -} - -static Bool -xf86RandR13OutputGetProperty(ScreenPtr pScreen, - RROutputPtr randr_output, Atom property) -{ - xf86OutputPtr output = randr_output->devPrivate; - - if (output->funcs->get_property == NULL) - return TRUE; - - /* Should be safe even w/o vtSema */ - return output->funcs->get_property(output, property); -} - -static Bool -xf86RandR12OutputValidateMode(ScreenPtr pScreen, - RROutputPtr randr_output, RRModePtr randr_mode) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86OutputPtr output = randr_output->devPrivate; - DisplayModeRec mode; - - xf86RandRModeConvert(pScrn, randr_mode, &mode); - /* - * This function may be called when vtSema is FALSE, so - * the underlying function must either avoid touching the hardware - * or return FALSE when vtSema is FALSE - */ - if (output->funcs->mode_valid(output, &mode) != MODE_OK) - return FALSE; - return TRUE; -} - -static void -xf86RandR12ModeDestroy(ScreenPtr pScreen, RRModePtr randr_mode) -{ -} - -/** - * Given a list of xf86 modes and a RandR Output object, construct - * RandR modes and assign them to the output - */ -static Bool -xf86RROutputSetModes(RROutputPtr randr_output, DisplayModePtr modes) -{ - DisplayModePtr mode; - RRModePtr *rrmodes = NULL; - int nmode = 0; - int npreferred = 0; - Bool ret = TRUE; - int pref; - - for (mode = modes; mode; mode = mode->next) - nmode++; - - if (nmode) { - rrmodes = xallocarray(nmode, sizeof(RRModePtr)); - - if (!rrmodes) - return FALSE; - nmode = 0; - - for (pref = 1; pref >= 0; pref--) { - for (mode = modes; mode; mode = mode->next) { - if ((pref != 0) == ((mode->type & M_T_PREFERRED) != 0)) { - xRRModeInfo modeInfo; - RRModePtr rrmode; - - modeInfo.nameLength = strlen(mode->name); - modeInfo.width = mode->HDisplay; - modeInfo.dotClock = mode->Clock * 1000; - modeInfo.hSyncStart = mode->HSyncStart; - modeInfo.hSyncEnd = mode->HSyncEnd; - modeInfo.hTotal = mode->HTotal; - modeInfo.hSkew = mode->HSkew; - - modeInfo.height = mode->VDisplay; - modeInfo.vSyncStart = mode->VSyncStart; - modeInfo.vSyncEnd = mode->VSyncEnd; - modeInfo.vTotal = mode->VTotal; - modeInfo.modeFlags = mode->Flags; - - rrmode = RRModeGet(&modeInfo, mode->name); - if (rrmode) { - rrmodes[nmode++] = rrmode; - npreferred += pref; - } - } - } - } - } - - ret = RROutputSetModes(randr_output, rrmodes, nmode, npreferred); - free(rrmodes); - return ret; -} - -/* - * Mirror the current mode configuration to RandR - */ -static Bool -xf86RandR12SetInfo12(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - RROutputPtr *clones; - RRCrtcPtr *crtcs; - int ncrtc; - int o, c, l; - int nclone; - - clones = xallocarray(config->num_output, sizeof(RROutputPtr)); - crtcs = xallocarray(config->num_crtc, sizeof(RRCrtcPtr)); - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - ncrtc = 0; - for (c = 0; c < config->num_crtc; c++) - if (output->possible_crtcs & (1 << c)) - crtcs[ncrtc++] = config->crtc[c]->randr_crtc; - - if (!RROutputSetCrtcs(output->randr_output, crtcs, ncrtc)) { - free(crtcs); - free(clones); - return FALSE; - } - - RROutputSetPhysicalSize(output->randr_output, - output->mm_width, output->mm_height); - xf86RROutputSetModes(output->randr_output, output->probed_modes); - - switch (output->status) { - case XF86OutputStatusConnected: - RROutputSetConnection(output->randr_output, RR_Connected); - break; - case XF86OutputStatusDisconnected: - if (xf86OutputForceEnabled(output)) - RROutputSetConnection(output->randr_output, RR_Connected); - else - RROutputSetConnection(output->randr_output, RR_Disconnected); - break; - case XF86OutputStatusUnknown: - RROutputSetConnection(output->randr_output, RR_UnknownConnection); - break; - } - - RROutputSetSubpixelOrder(output->randr_output, output->subpixel_order); - - /* - * Valid clones - */ - nclone = 0; - for (l = 0; l < config->num_output; l++) { - xf86OutputPtr clone = config->output[l]; - - if (l != o && (output->possible_clones & (1 << l))) - clones[nclone++] = clone->randr_output; - } - if (!RROutputSetClones(output->randr_output, clones, nclone)) { - free(crtcs); - free(clones); - return FALSE; - } - } - free(crtcs); - free(clones); - return TRUE; -} - -/* - * Query the hardware for the current state, then mirror - * that to RandR - */ -static Bool -xf86RandR12GetInfo12(ScreenPtr pScreen, Rotation * rotations) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - - if (!pScrn->vtSema) - return TRUE; - xf86ProbeOutputModes(pScrn, 0, 0); - xf86SetScrnInfoModes(pScrn); - return xf86RandR12SetInfo12(pScreen); -} - -static Bool -xf86RandR12CreateObjects12(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int c; - int o; - - if (!RRInit()) - return FALSE; - - /* - * Configure crtcs - */ - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - crtc->randr_crtc = RRCrtcCreate(pScreen, crtc); - } - /* - * Configure outputs - */ - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - - output->randr_output = RROutputCreate(pScreen, output->name, - strlen(output->name), output); - - if (output->funcs->create_resources != NULL) - output->funcs->create_resources(output); - RRPostPendingProperties(output->randr_output); - } - - if (config->name) { - config->randr_provider = RRProviderCreate(pScreen, config->name, - strlen(config->name)); - - RRProviderSetCapabilities(config->randr_provider, pScrn->capabilities); - } - - return TRUE; -} - -static void -xf86RandR12CreateMonitors(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int o, ot; - int ht, vt; - int ret; - char buf[25]; - - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr output = config->output[o]; - struct xf86CrtcTileInfo *tile_info = &output->tile_info, *this_tile; - RRMonitorPtr monitor; - int output_num, num_outputs; - if (!tile_info->group_id) - continue; - - if (tile_info->tile_h_loc || - tile_info->tile_v_loc) - continue; - - num_outputs = tile_info->num_h_tile * tile_info->num_v_tile; - - monitor = RRMonitorAlloc(num_outputs); - if (!monitor) - return; - monitor->pScreen = pScreen; - snprintf(buf, 25, "Auto-Monitor-%d", tile_info->group_id); - monitor->name = MakeAtom(buf, strlen(buf), TRUE); - monitor->primary = 0; - monitor->automatic = TRUE; - memset(&monitor->geometry.box, 0, sizeof(monitor->geometry.box)); - - output_num = 0; - for (ht = 0; ht < tile_info->num_h_tile; ht++) { - for (vt = 0; vt < tile_info->num_v_tile; vt++) { - - for (ot = 0; ot < config->num_output; ot++) { - this_tile = &config->output[ot]->tile_info; - - if (this_tile->group_id != tile_info->group_id) - continue; - - if (this_tile->tile_h_loc != ht || - this_tile->tile_v_loc != vt) - continue; - - monitor->outputs[output_num] = config->output[ot]->randr_output->id; - output_num++; - - } - - } - } - - ret = RRMonitorAdd(serverClient, pScreen, monitor); - if (ret) { - RRMonitorFree(monitor); - return; - } - } -} - -static Bool -xf86RandR12CreateScreenResources12(ScreenPtr pScreen) -{ - int c; - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - rrScrPrivPtr rp = rrGetScrPriv(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - - for (c = 0; c < config->num_crtc; c++) - xf86RandR12CrtcNotify(config->crtc[c]->randr_crtc); - - RRScreenSetSizeRange(pScreen, config->minWidth, config->minHeight, - config->maxWidth, config->maxHeight); - - xf86RandR12CreateMonitors(pScreen); - - if (!pScreen->isGPU) { - rp->primaryOutput = config->output[0]->randr_output; - RROutputChanged(rp->primaryOutput, FALSE); - rp->layoutChanged = TRUE; - } - - return TRUE; -} - -/* - * Something happened within the screen configuration due - * to DGA, VidMode or hot key. Tell RandR - */ - -void -xf86RandR12TellChanged(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int c; - - xf86RandR12SetInfo12(pScreen); - for (c = 0; c < config->num_crtc; c++) - xf86RandR12CrtcNotify(config->crtc[c]->randr_crtc); - - RRTellChanged(pScreen); -} - -static void -xf86RandR12PointerMoved(ScrnInfoPtr pScrn, int x, int y) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - int c; - - randrp->pointerX = x; - randrp->pointerY = y; - for (c = 0; c < config->num_crtc; c++) - xf86RandR13Pan(config->crtc[c], x, y); -} - -static Bool -xf86RandR13GetPanning(ScreenPtr pScreen, - RRCrtcPtr randr_crtc, - BoxPtr totalArea, BoxPtr trackingArea, INT16 *border) -{ - xf86CrtcPtr crtc = randr_crtc->devPrivate; - - if (crtc->version < 2) - return FALSE; - if (totalArea) - memcpy(totalArea, &crtc->panningTotalArea, sizeof(BoxRec)); - if (trackingArea) - memcpy(trackingArea, &crtc->panningTrackingArea, sizeof(BoxRec)); - if (border) - memcpy(border, crtc->panningBorder, 4 * sizeof(INT16)); - - return TRUE; -} - -static Bool -xf86RandR13SetPanning(ScreenPtr pScreen, - RRCrtcPtr randr_crtc, - BoxPtr totalArea, BoxPtr trackingArea, INT16 *border) -{ - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - xf86CrtcPtr crtc = randr_crtc->devPrivate; - BoxRec oldTotalArea; - BoxRec oldTrackingArea; - INT16 oldBorder[4]; - Bool oldPanning = randrp->panning; - - if (crtc->version < 2) - return FALSE; - - memcpy(&oldTotalArea, &crtc->panningTotalArea, sizeof(BoxRec)); - memcpy(&oldTrackingArea, &crtc->panningTrackingArea, sizeof(BoxRec)); - memcpy(oldBorder, crtc->panningBorder, 4 * sizeof(INT16)); - - if (totalArea) - memcpy(&crtc->panningTotalArea, totalArea, sizeof(BoxRec)); - if (trackingArea) - memcpy(&crtc->panningTrackingArea, trackingArea, sizeof(BoxRec)); - if (border) - memcpy(crtc->panningBorder, border, 4 * sizeof(INT16)); - - if (xf86RandR13VerifyPanningArea(crtc, pScreen->width, pScreen->height)) { - xf86RandR13Pan(crtc, randrp->pointerX, randrp->pointerY); - randrp->panning = PANNING_ENABLED (crtc); - return TRUE; - } - else { - /* Restore old settings */ - memcpy(&crtc->panningTotalArea, &oldTotalArea, sizeof(BoxRec)); - memcpy(&crtc->panningTrackingArea, &oldTrackingArea, sizeof(BoxRec)); - memcpy(crtc->panningBorder, oldBorder, 4 * sizeof(INT16)); - randrp->panning = oldPanning; - return FALSE; - } -} - -/* - * Compatibility with colormaps and XF86VidMode's gamma - */ -void -xf86RandR12LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, - LOCO *colors, VisualPtr pVisual) -{ - ScreenPtr pScreen = pScrn->pScreen; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int reds, greens, blues, index, palette_size; - int c, i; - - if (pVisual->class == TrueColor || pVisual->class == DirectColor) { - reds = (pVisual->redMask >> pVisual->offsetRed) + 1; - greens = (pVisual->greenMask >> pVisual->offsetGreen) + 1; - blues = (pVisual->blueMask >> pVisual->offsetBlue) + 1; - } else { - reds = greens = blues = pVisual->ColormapEntries; - } - - palette_size = max(reds, max(greens, blues)); - - if (dixPrivateKeyRegistered(rrPrivKey)) { - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - - if (randrp->palette_size != palette_size) { - randrp->palette = reallocarray(randrp->palette, palette_size, - sizeof(colors[0])); - if (!randrp->palette) { - randrp->palette_size = 0; - return; - } - - randrp->palette_size = palette_size; - } - randrp->palette_red_size = reds; - randrp->palette_green_size = greens; - randrp->palette_blue_size = blues; - - for (i = 0; i < numColors; i++) { - index = indices[i]; - - if (index < reds) - randrp->palette[index].red = colors[index].red; - if (index < greens) - randrp->palette[index].green = colors[index].green; - if (index < blues) - randrp->palette[index].blue = colors[index].blue; - } - } - - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - RRCrtcPtr randr_crtc = crtc->randr_crtc; - - if (randr_crtc) { - xf86RandR12CrtcComputeGamma(crtc, colors, reds, greens, blues, - randr_crtc->gammaRed, - randr_crtc->gammaGreen, - randr_crtc->gammaBlue, - randr_crtc->gammaSize); - } else { - xf86RandR12CrtcComputeGamma(crtc, colors, reds, greens, blues, - NULL, NULL, NULL, - xf86GetGammaRampSize(pScreen)); - } - xf86RandR12CrtcReloadGamma(crtc); - } -} - -/* - * Compatibility pScrn->ChangeGamma provider for ddx drivers which do not call - * xf86HandleColormaps(). Note such drivers really should be fixed to call - * xf86HandleColormaps() as this clobbers the per-CRTC gamma ramp of the CRTC - * assigned to the RandR compatibility output. - */ -static int -xf86RandR12ChangeGamma(ScrnInfoPtr pScrn, Gamma gamma) -{ - RRCrtcPtr randr_crtc = xf86CompatRRCrtc(pScrn); - int size; - - if (!randr_crtc || pScrn->LoadPalette == xf86RandR12LoadPalette) - return Success; - - size = max(0, randr_crtc->gammaSize); - if (!size) - return Success; - - init_one_component(randr_crtc->gammaRed, size, gamma.red); - init_one_component(randr_crtc->gammaGreen, size, gamma.green); - init_one_component(randr_crtc->gammaBlue, size, gamma.blue); - xf86RandR12CrtcSetGamma(xf86ScrnToScreen(pScrn), randr_crtc); - - pScrn->gamma = gamma; - - return Success; -} - -static Bool -xf86RandR12EnterVT(ScrnInfoPtr pScrn) -{ - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - rrScrPrivPtr rp = rrGetScrPriv(pScreen); - Bool ret; - int i; - - if (randrp->orig_EnterVT) { - pScrn->EnterVT = randrp->orig_EnterVT; - ret = pScrn->EnterVT(pScrn); - randrp->orig_EnterVT = pScrn->EnterVT; - pScrn->EnterVT = xf86RandR12EnterVT; - if (!ret) - return FALSE; - } - - /* reload gamma */ - for (i = 0; i < rp->numCrtcs; i++) - xf86RandR12CrtcReloadGamma(rp->crtcs[i]->devPrivate); - - return RRGetInfo(pScreen, TRUE); /* force a re-probe of outputs and notify clients about changes */ -} - -static void -xf86DetachOutputGPU(ScreenPtr pScreen) -{ - rrScrPrivPtr rp = rrGetScrPriv(pScreen); - int i; - - /* make sure there are no attached shared scanout pixmaps first */ - for (i = 0; i < rp->numCrtcs; i++) - RRCrtcDetachScanoutPixmap(rp->crtcs[i]); - - DetachOutputGPU(pScreen); -} - -static Bool -xf86RandR14ProviderSetOutputSource(ScreenPtr pScreen, - RRProviderPtr provider, - RRProviderPtr source_provider) -{ - if (!source_provider) { - if (provider->output_source) { - xf86DetachOutputGPU(pScreen); - } - provider->output_source = NULL; - return TRUE; - } - - if (provider->output_source == source_provider) - return TRUE; - - SetRootClip(source_provider->pScreen, ROOT_CLIP_NONE); - - AttachOutputGPU(source_provider->pScreen, pScreen); - - provider->output_source = source_provider; - SetRootClip(source_provider->pScreen, ROOT_CLIP_FULL); - return TRUE; -} - -static Bool -xf86RandR14ProviderSetOffloadSink(ScreenPtr pScreen, - RRProviderPtr provider, - RRProviderPtr sink_provider) -{ - if (!sink_provider) { - if (provider->offload_sink) { - xf86DetachOutputGPU(pScreen); - } - - provider->offload_sink = NULL; - return TRUE; - } - - if (provider->offload_sink == sink_provider) - return TRUE; - - AttachOffloadGPU(sink_provider->pScreen, pScreen); - - provider->offload_sink = sink_provider; - return TRUE; -} - -static Bool -xf86RandR14ProviderSetProperty(ScreenPtr pScreen, - RRProviderPtr randr_provider, - Atom property, RRPropertyValuePtr value) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - - /* If we don't have any property handler, then we don't care what the - * user is setting properties to. - */ - if (config->provider_funcs->set_property == NULL) - return TRUE; - - /* - * This function gets called even when vtSema is FALSE, as - * drivers will need to remember the correct value to apply - * when the VT switch occurs - */ - return config->provider_funcs->set_property(pScrn, property, value); -} - -static Bool -xf86RandR14ProviderGetProperty(ScreenPtr pScreen, - RRProviderPtr randr_provider, Atom property) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - - if (config->provider_funcs->get_property == NULL) - return TRUE; - - /* Should be safe even w/o vtSema */ - return config->provider_funcs->get_property(pScrn, property); -} - -static Bool -xf86CrtcSetScanoutPixmap(RRCrtcPtr randr_crtc, PixmapPtr pixmap) -{ - xf86CrtcPtr crtc = randr_crtc->devPrivate; - if (!crtc->funcs->set_scanout_pixmap) - return FALSE; - return crtc->funcs->set_scanout_pixmap(crtc, pixmap); -} - -static void -xf86RandR13ConstrainCursorHarder(DeviceIntPtr dev, ScreenPtr screen, int mode, int *x, int *y) -{ - XF86RandRInfoPtr randrp = XF86RANDRINFO(screen); - - if (randrp->panning) - return; - - if (randrp->orig_ConstrainCursorHarder) { - screen->ConstrainCursorHarder = randrp->orig_ConstrainCursorHarder; - screen->ConstrainCursorHarder(dev, screen, mode, x, y); - screen->ConstrainCursorHarder = xf86RandR13ConstrainCursorHarder; - } -} - -static void -xf86RandR14ProviderDestroy(ScreenPtr screen, RRProviderPtr provider) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - - if (config->randr_provider == provider) { - if (config->randr_provider->offload_sink) { - DetachOffloadGPU(screen); - config->randr_provider->offload_sink = NULL; - RRSetChanged(screen); - } - if (config->randr_provider->output_source) { - xf86DetachOutputGPU(screen); - config->randr_provider->output_source = NULL; - RRSetChanged(screen); - } - if (screen->current_primary) - DetachUnboundGPU(screen); - } - config->randr_provider = NULL; -} - -static void -xf86CrtcCheckReset(xf86CrtcPtr crtc) { - if (xf86CrtcInUse(crtc)) { - RRTransformPtr transform; - - if (crtc->desiredTransformPresent) - transform = &crtc->desiredTransform; - else - transform = NULL; - xf86CrtcSetModeTransform(crtc, &crtc->desiredMode, - crtc->desiredRotation, transform, - crtc->desiredX, crtc->desiredY); - xf86_crtc_show_cursor(crtc); - } -} - -void -xf86CrtcLeaseTerminated(RRLeasePtr lease) -{ - int c; - int o; - ScrnInfoPtr scrn = xf86ScreenToScrn(lease->screen); - - RRLeaseTerminated(lease); - /* - * Force a full mode set on any crtc in the expiring lease which - * was running before the lease started - */ - for (c = 0; c < lease->numCrtcs; c++) { - RRCrtcPtr randr_crtc = lease->crtcs[c]; - xf86CrtcPtr crtc = randr_crtc->devPrivate; - - xf86CrtcCheckReset(crtc); - } - - /* Check to see if any leased output is using a crtc which - * was not reset in the above loop - */ - for (o = 0; o < lease->numOutputs; o++) { - RROutputPtr randr_output = lease->outputs[o]; - xf86OutputPtr output = randr_output->devPrivate; - xf86CrtcPtr crtc = output->crtc; - - if (crtc) { - for (c = 0; c < lease->numCrtcs; c++) - if (lease->crtcs[c] == crtc->randr_crtc) - break; - if (c != lease->numCrtcs) - continue; - xf86CrtcCheckReset(crtc); - } - } - - /* Power off if necessary */ - xf86DisableUnusedFunctions(scrn); - - RRLeaseFree(lease); -} - -static Bool -xf86CrtcSoleOutput(xf86CrtcPtr crtc, xf86OutputPtr output) -{ - ScrnInfoPtr scrn = crtc->scrn; - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - int o; - - for (o = 0; o < config->num_output; o++) { - xf86OutputPtr other = config->output[o]; - - if (other != output && other->crtc == crtc) - return FALSE; - } - return TRUE; -} - -void -xf86CrtcLeaseStarted(RRLeasePtr lease) -{ - int c; - int o; - - for (c = 0; c < lease->numCrtcs; c++) { - RRCrtcPtr randr_crtc = lease->crtcs[c]; - xf86CrtcPtr crtc = randr_crtc->devPrivate; - - if (crtc->enabled) { - /* - * Leave the primary plane enabled so we can - * flip without blanking the screen. Hide - * the cursor so it doesn't remain on the screen - * while the lease is active - */ - xf86_crtc_hide_cursor(crtc); - crtc->enabled = FALSE; - } - } - for (o = 0; o < lease->numOutputs; o++) { - RROutputPtr randr_output = lease->outputs[o]; - xf86OutputPtr output = randr_output->devPrivate; - xf86CrtcPtr crtc = output->crtc; - - if (crtc) - if (xf86CrtcSoleOutput(crtc, output)) - crtc->enabled = FALSE; - } -} - -static int -xf86RandR16CreateLease(ScreenPtr screen, RRLeasePtr randr_lease, int *fd) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - - if (config->funcs->create_lease) - return config->funcs->create_lease(randr_lease, fd); - else - return BadMatch; -} - - -static void -xf86RandR16TerminateLease(ScreenPtr screen, RRLeasePtr randr_lease) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); - - if (config->funcs->terminate_lease) - config->funcs->terminate_lease(randr_lease); -} - -static Bool -xf86RandR12Init12(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - rrScrPrivPtr rp = rrGetScrPriv(pScreen); - XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); - - rp->rrGetInfo = xf86RandR12GetInfo12; - rp->rrScreenSetSize = xf86RandR12ScreenSetSize; - rp->rrCrtcSet = xf86RandR12CrtcSet; - rp->rrCrtcSetGamma = xf86RandR12CrtcSetGamma; - rp->rrOutputSetProperty = xf86RandR12OutputSetProperty; - rp->rrOutputValidateMode = xf86RandR12OutputValidateMode; -#if RANDR_13_INTERFACE - rp->rrOutputGetProperty = xf86RandR13OutputGetProperty; - rp->rrGetPanning = xf86RandR13GetPanning; - rp->rrSetPanning = xf86RandR13SetPanning; -#endif - rp->rrModeDestroy = xf86RandR12ModeDestroy; - rp->rrSetConfig = NULL; - - rp->rrProviderSetOutputSource = xf86RandR14ProviderSetOutputSource; - rp->rrProviderSetOffloadSink = xf86RandR14ProviderSetOffloadSink; - - rp->rrProviderSetProperty = xf86RandR14ProviderSetProperty; - rp->rrProviderGetProperty = xf86RandR14ProviderGetProperty; - rp->rrCrtcSetScanoutPixmap = xf86CrtcSetScanoutPixmap; - rp->rrProviderDestroy = xf86RandR14ProviderDestroy; - - rp->rrCreateLease = xf86RandR16CreateLease; - rp->rrTerminateLease = xf86RandR16TerminateLease; - - pScrn->PointerMoved = xf86RandR12PointerMoved; - pScrn->ChangeGamma = xf86RandR12ChangeGamma; - - randrp->orig_EnterVT = pScrn->EnterVT; - pScrn->EnterVT = xf86RandR12EnterVT; - - randrp->panning = FALSE; - randrp->orig_ConstrainCursorHarder = pScreen->ConstrainCursorHarder; - pScreen->ConstrainCursorHarder = xf86RandR13ConstrainCursorHarder; - - if (!xf86RandR12CreateObjects12(pScreen)) - return FALSE; - - /* - * Configure output modes - */ - if (!xf86RandR12SetInfo12(pScreen)) - return FALSE; - - if (!xf86RandR12InitGamma(pScrn, 256)) - return FALSE; - - return TRUE; -} - -#endif - -Bool -xf86RandR12PreInit(ScrnInfoPtr pScrn) -{ - return TRUE; -} diff --git a/hw/xfree86/modes/xf86RandR12.h b/hw/xfree86/modes/xf86RandR12.h deleted file mode 100644 index 31aaaaf28..000000000 --- a/hw/xfree86/modes/xf86RandR12.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifndef _XF86_RANDR_H_ -#define _XF86_RANDR_H_ -#include -#include - -extern _X_EXPORT Bool xf86RandR12CreateScreenResources(ScreenPtr pScreen); -extern _X_EXPORT Bool xf86RandR12Init(ScreenPtr pScreen); -extern _X_EXPORT void xf86RandR12CloseScreen(ScreenPtr pScreen); -extern _X_EXPORT void xf86RandR12SetRotations(ScreenPtr pScreen, - Rotation rotation); -extern _X_EXPORT void xf86RandR12SetTransformSupport(ScreenPtr pScreen, - Bool transforms); -extern _X_EXPORT Bool xf86RandR12SetConfig(ScreenPtr pScreen, Rotation rotation, - int rate, RRScreenSizePtr pSize); -extern _X_EXPORT Rotation xf86RandR12GetRotation(ScreenPtr pScreen); -extern _X_EXPORT void xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr pScrn, - int *x, int *y); -extern _X_EXPORT Bool xf86RandR12PreInit(ScrnInfoPtr pScrn); -extern _X_EXPORT void xf86RandR12TellChanged(ScreenPtr pScreen); - -extern void xf86RandR12LoadPalette(ScrnInfoPtr pScrn, int numColors, - int *indices, LOCO *colors, - VisualPtr pVisual); -extern Bool xf86RandR12InitGamma(ScrnInfoPtr pScrn, unsigned gammaSize); - -#endif /* _XF86_RANDR_H_ */ diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c deleted file mode 100644 index ea9c43c0f..000000000 --- a/hw/xfree86/modes/xf86Rotate.c +++ /dev/null @@ -1,494 +0,0 @@ -/* - * Copyright © 2006 Keith Packard - * Copyright © 2011 Aaron Plattner - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the name of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include "mi.h" -#include "xf86.h" -#include "xf86DDC.h" -#include "windowstr.h" -#include "xf86Crtc.h" -#include "xf86Modes.h" -#include "xf86RandR12.h" -#include "X11/extensions/render.h" -#include "X11/extensions/dpmsconst.h" -#include "X11/Xatom.h" - -static void -xf86RotateCrtcRedisplay(xf86CrtcPtr crtc, RegionPtr region) -{ - ScrnInfoPtr scrn = crtc->scrn; - ScreenPtr screen = scrn->pScreen; - WindowPtr root = screen->root; - PixmapPtr dst_pixmap = crtc->rotatedPixmap; - PictFormatPtr format = PictureWindowFormat(screen->root); - int error; - PicturePtr src, dst; - int n = RegionNumRects(region); - BoxPtr b = RegionRects(region); - XID include_inferiors = IncludeInferiors; - - if (crtc->driverIsPerformingTransform & XF86DriverTransformOutput) - return; - - src = CreatePicture(None, - &root->drawable, - format, - CPSubwindowMode, - &include_inferiors, serverClient, &error); - if (!src) - return; - - dst = CreatePicture(None, - &dst_pixmap->drawable, - format, 0L, NULL, serverClient, &error); - if (!dst) - return; - - error = SetPictureTransform(src, &crtc->crtc_to_framebuffer); - if (error) - return; - if (crtc->transform_in_use && crtc->filter) - SetPicturePictFilter(src, crtc->filter, crtc->params, crtc->nparams); - - if (crtc->shadowClear) { - CompositePicture(PictOpSrc, - src, NULL, dst, - 0, 0, 0, 0, 0, 0, - crtc->mode.HDisplay, crtc->mode.VDisplay); - crtc->shadowClear = FALSE; - } - else { - while (n--) { - BoxRec dst_box; - - dst_box = *b; - dst_box.x1 -= crtc->filter_width >> 1; - dst_box.x2 += crtc->filter_width >> 1; - dst_box.y1 -= crtc->filter_height >> 1; - dst_box.y2 += crtc->filter_height >> 1; - pixman_f_transform_bounds(&crtc->f_framebuffer_to_crtc, &dst_box); - CompositePicture(PictOpSrc, - src, NULL, dst, - dst_box.x1, dst_box.y1, 0, 0, dst_box.x1, - dst_box.y1, dst_box.x2 - dst_box.x1, - dst_box.y2 - dst_box.y1); - b++; - } - } - FreePicture(src, None); - FreePicture(dst, None); -} - -static void -xf86CrtcDamageShadow(xf86CrtcPtr crtc) -{ - ScrnInfoPtr pScrn = crtc->scrn; - BoxRec damage_box; - RegionRec damage_region; - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - - damage_box.x1 = 0; - damage_box.x2 = crtc->mode.HDisplay; - damage_box.y1 = 0; - damage_box.y2 = crtc->mode.VDisplay; - if (!pixman_transform_bounds(&crtc->crtc_to_framebuffer, &damage_box)) { - damage_box.x1 = 0; - damage_box.y1 = 0; - damage_box.x2 = pScreen->width; - damage_box.y2 = pScreen->height; - } - if (damage_box.x1 < 0) - damage_box.x1 = 0; - if (damage_box.y1 < 0) - damage_box.y1 = 0; - if (damage_box.x2 > pScreen->width) - damage_box.x2 = pScreen->width; - if (damage_box.y2 > pScreen->height) - damage_box.y2 = pScreen->height; - RegionInit(&damage_region, &damage_box, 1); - DamageDamageRegion(&(*pScreen->GetScreenPixmap) (pScreen)->drawable, - &damage_region); - RegionUninit(&damage_region); - crtc->shadowClear = TRUE; -} - -static void -xf86RotatePrepare(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int c; - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->rotatedData && !crtc->rotatedPixmap) { - crtc->rotatedPixmap = crtc->funcs->shadow_create(crtc, - crtc->rotatedData, - crtc->mode. - HDisplay, - crtc->mode. - VDisplay); - if (!xf86_config->rotation_damage_registered) { - /* Hook damage to screen pixmap */ - DamageRegister(&pScreen->root->drawable, - xf86_config->rotation_damage); - xf86_config->rotation_damage_registered = TRUE; - EnableLimitedSchedulingLatency(); - } - - xf86CrtcDamageShadow(crtc); - } - } -} - -static Bool -xf86RotateRedisplay(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - DamagePtr damage = xf86_config->rotation_damage; - RegionPtr region; - - if (!damage || !pScreen->root) - return FALSE; - xf86RotatePrepare(pScreen); - region = DamageRegion(damage); - if (RegionNotEmpty(region)) { - int c; - SourceValidateProcPtr SourceValidate; - - /* - * SourceValidate is used by the software cursor code - * to pull the cursor off of the screen when reading - * bits from the frame buffer. Bypassing this function - * leaves the software cursor in place - */ - SourceValidate = pScreen->SourceValidate; - pScreen->SourceValidate = miSourceValidate; - - for (c = 0; c < xf86_config->num_crtc; c++) { - xf86CrtcPtr crtc = xf86_config->crtc[c]; - - if (crtc->transform_in_use && crtc->enabled) { - RegionRec crtc_damage; - - /* compute portion of damage that overlaps crtc */ - RegionInit(&crtc_damage, &crtc->bounds, 1); - RegionIntersect(&crtc_damage, &crtc_damage, region); - - /* update damaged region */ - if (RegionNotEmpty(&crtc_damage)) - xf86RotateCrtcRedisplay(crtc, &crtc_damage); - - RegionUninit(&crtc_damage); - } - } - pScreen->SourceValidate = SourceValidate; - DamageEmpty(damage); - } - return TRUE; -} - -static void -xf86RotateBlockHandler(ScreenPtr pScreen, void *pTimeout) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - - /* Unwrap before redisplay in case the software - * cursor layer wants to add its block handler to the - * chain - */ - pScreen->BlockHandler = xf86_config->BlockHandler; - - xf86RotateRedisplay(pScreen); - - (*pScreen->BlockHandler) (pScreen, pTimeout); - - /* Re-wrap if we still need this hook */ - if (xf86_config->rotation_damage != NULL) { - xf86_config->BlockHandler = pScreen->BlockHandler; - pScreen->BlockHandler = xf86RotateBlockHandler; - } else - xf86_config->BlockHandler = NULL; -} - -void -xf86RotateDestroy(xf86CrtcPtr crtc) -{ - ScrnInfoPtr pScrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - int c; - - /* Free memory from rotation */ - if (crtc->rotatedPixmap || crtc->rotatedData) { - crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, - crtc->rotatedData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - - for (c = 0; c < xf86_config->num_crtc; c++) - if (xf86_config->crtc[c]->rotatedData) - return; - - /* - * Clean up damage structures when no crtcs are rotated - */ - if (xf86_config->rotation_damage) { - /* Free damage structure */ - if (xf86_config->rotation_damage_registered) { - xf86_config->rotation_damage_registered = FALSE; - DisableLimitedSchedulingLatency(); - } - DamageDestroy(xf86_config->rotation_damage); - xf86_config->rotation_damage = NULL; - } -} - -void -xf86RotateFreeShadow(ScrnInfoPtr pScrn) -{ - xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); - int c; - - for (c = 0; c < config->num_crtc; c++) { - xf86CrtcPtr crtc = config->crtc[c]; - - if (crtc->rotatedPixmap || crtc->rotatedData) { - crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap, - crtc->rotatedData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - } -} - -void -xf86RotateCloseScreen(ScreenPtr screen) -{ - ScrnInfoPtr scrn = xf86ScreenToScrn(screen); - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); - int c; - - /* This has already been destroyed when the root window was destroyed */ - xf86_config->rotation_damage = NULL; - for (c = 0; c < xf86_config->num_crtc; c++) - xf86RotateDestroy(xf86_config->crtc[c]); -} - -static Bool -xf86CrtcFitsScreen(xf86CrtcPtr crtc, struct pict_f_transform *crtc_to_fb) -{ - ScrnInfoPtr pScrn = crtc->scrn; - BoxRec b; - - /* When called before PreInit, the driver is - * presumably doing load detect - */ - if (pScrn->is_gpu) { - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - if (pScreen->current_primary) - pScrn = xf86ScreenToScrn(pScreen->current_primary); - } - - if (pScrn->virtualX == 0 || pScrn->virtualY == 0) - return TRUE; - - b.x1 = 0; - b.y1 = 0; - b.x2 = crtc->mode.HDisplay; - b.y2 = crtc->mode.VDisplay; - if (crtc_to_fb) - pixman_f_transform_bounds(crtc_to_fb, &b); - else { - b.x1 += crtc->x; - b.y1 += crtc->y; - b.x2 += crtc->x; - b.y2 += crtc->y; - } - - return (0 <= b.x1 && b.x2 <= pScrn->virtualX && - 0 <= b.y1 && b.y2 <= pScrn->virtualY); -} - -Bool -xf86CrtcRotate(xf86CrtcPtr crtc) -{ - ScrnInfoPtr pScrn = crtc->scrn; - xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - PictTransform crtc_to_fb; - struct pict_f_transform f_crtc_to_fb, f_fb_to_crtc; - xFixed *new_params = NULL; - int new_nparams = 0; - PictFilterPtr new_filter = NULL; - int new_width = 0; - int new_height = 0; - RRTransformPtr transform = NULL; - Bool damage = FALSE; - - if (pScreen->isGPU) - return TRUE; - if (crtc->transformPresent) - transform = &crtc->transform; - - if (!RRTransformCompute(crtc->x, crtc->y, - crtc->mode.HDisplay, crtc->mode.VDisplay, - crtc->rotation, - transform, - &crtc_to_fb, - &f_crtc_to_fb, - &f_fb_to_crtc) && - xf86CrtcFitsScreen(crtc, &f_crtc_to_fb)) { - /* - * If the untranslated transformation is the identity, - * disable the shadow buffer - */ - xf86RotateDestroy(crtc); - crtc->transform_in_use = FALSE; - free(new_params); - new_params = NULL; - new_nparams = 0; - new_filter = NULL; - new_width = 0; - new_height = 0; - } - else { - if (crtc->driverIsPerformingTransform & XF86DriverTransformOutput) { - xf86RotateDestroy(crtc); - } - else { - /* - * these are the size of the shadow pixmap, which - * matches the mode, not the pre-rotated copy in the - * frame buffer - */ - int width = crtc->mode.HDisplay; - int height = crtc->mode.VDisplay; - void *shadowData = crtc->rotatedData; - PixmapPtr shadow = crtc->rotatedPixmap; - int old_width = shadow ? shadow->drawable.width : 0; - int old_height = shadow ? shadow->drawable.height : 0; - - /* Allocate memory for rotation */ - if (old_width != width || old_height != height) { - if (shadow || shadowData) { - crtc->funcs->shadow_destroy(crtc, shadow, shadowData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - shadowData = crtc->funcs->shadow_allocate(crtc, width, height); - if (!shadowData) - goto bail1; - crtc->rotatedData = shadowData; - /* shadow will be damaged in xf86RotatePrepare */ - } - else { - /* mark shadowed area as damaged so it will be repainted */ - damage = TRUE; - } - - if (!xf86_config->rotation_damage) { - /* Create damage structure */ - xf86_config->rotation_damage = DamageCreate(NULL, NULL, - DamageReportNone, - TRUE, pScreen, - pScreen); - if (!xf86_config->rotation_damage) - goto bail2; - - /* Wrap block handler */ - if (!xf86_config->BlockHandler) { - xf86_config->BlockHandler = pScreen->BlockHandler; - pScreen->BlockHandler = xf86RotateBlockHandler; - } - } - - if (0) { - bail2: - if (shadow || shadowData) { - crtc->funcs->shadow_destroy(crtc, shadow, shadowData); - crtc->rotatedPixmap = NULL; - crtc->rotatedData = NULL; - } - bail1: - if (old_width && old_height) - crtc->rotatedPixmap = - crtc->funcs->shadow_create(crtc, NULL, old_width, - old_height); - return FALSE; - } - } -#ifdef RANDR_12_INTERFACE - if (transform) { - if (transform->nparams) { - new_params = malloc(transform->nparams * sizeof(xFixed)); - if (new_params) { - memcpy(new_params, transform->params, - transform->nparams * sizeof(xFixed)); - new_nparams = transform->nparams; - new_filter = transform->filter; - } - } - else - new_filter = transform->filter; - if (new_filter) { - new_width = new_filter->width; - new_height = new_filter->height; - } - } -#endif - crtc->transform_in_use = TRUE; - } - crtc->crtc_to_framebuffer = crtc_to_fb; - crtc->f_crtc_to_framebuffer = f_crtc_to_fb; - crtc->f_framebuffer_to_crtc = f_fb_to_crtc; - free(crtc->params); - crtc->params = new_params; - crtc->nparams = new_nparams; - crtc->filter = new_filter; - crtc->filter_width = new_width; - crtc->filter_height = new_height; - crtc->bounds.x1 = 0; - crtc->bounds.x2 = crtc->mode.HDisplay; - crtc->bounds.y1 = 0; - crtc->bounds.y2 = crtc->mode.VDisplay; - pixman_f_transform_bounds(&f_crtc_to_fb, &crtc->bounds); - - if (damage) - xf86CrtcDamageShadow(crtc); - else if (crtc->rotatedData && !crtc->rotatedPixmap) - /* Make sure the new rotate buffer has valid transformed contents */ - xf86RotateRedisplay(pScreen); - - /* All done */ - return TRUE; -} diff --git a/hw/xfree86/modes/xf86gtf.c b/hw/xfree86/modes/xf86gtf.c deleted file mode 100644 index c6a738422..000000000 --- a/hw/xfree86/modes/xf86gtf.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - * gtf.c Generate mode timings using the GTF Timing Standard - * - * gcc gtf.c -o gtf -lm -Wall - * - * Copyright (c) 2001, Andy Ritger aritger@nvidia.com - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * o Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * o Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * o Neither the name of NVIDIA nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * This program is based on the Generalized Timing Formula(GTF TM) - * Standard Version: 1.0, Revision: 1.0 - * - * The GTF Document contains the following Copyright information: - * - * Copyright (c) 1994, 1995, 1996 - Video Electronics Standards - * Association. Duplication of this document within VESA member - * companies for review purposes is permitted. All other rights - * reserved. - * - * While every precaution has been taken in the preparation - * of this standard, the Video Electronics Standards Association and - * its contributors assume no responsibility for errors or omissions, - * and make no warranties, expressed or implied, of functionality - * of suitability for any purpose. The sample code contained within - * this standard may be used without restriction. - * - * - * - * The GTF EXCEL(TM) SPREADSHEET, a sample (and the definitive) - * implementation of the GTF Timing Standard, is available at: - * - * ftp://ftp.vesa.org/pub/GTF/GTF_V1R1.xls - */ - -/* Ruthlessly converted to server code by Adam Jackson */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86Modes.h" -#include - -#define MARGIN_PERCENT 1.8 /* % of active vertical image */ -#define CELL_GRAN 8.0 /* assumed character cell granularity */ -#define MIN_PORCH 1 /* minimum front porch */ -#define V_SYNC_RQD 3 /* width of vsync in lines */ -#define H_SYNC_PERCENT 8.0 /* width of hsync as % of total line */ -#define MIN_VSYNC_PLUS_BP 550.0 /* min time of vsync + back porch (microsec) */ -#define M 600.0 /* blanking formula gradient */ -#define C 40.0 /* blanking formula offset */ -#define K 128.0 /* blanking formula scaling factor */ -#define J 20.0 /* blanking formula scaling factor */ - -/* C' and M' are part of the Blanking Duty Cycle computation */ - -#define C_PRIME (((C - J) * K/256.0) + J) -#define M_PRIME (K/256.0 * M) - -/* - * xf86GTFMode() - as defined by the GTF Timing Standard, compute the - * Stage 1 Parameters using the vertical refresh frequency. In other - * words: input a desired resolution and desired refresh rate, and - * output the GTF mode timings. - * - * XXX All the code is in place to compute interlaced modes, but I don't - * feel like testing it right now. - * - * XXX margin computations are implemented but not tested (nor used by - * XServer of fbset mode descriptions, from what I can tell). - */ - -DisplayModePtr -xf86GTFMode(int h_pixels, int v_lines, float freq, int interlaced, int margins) -{ - DisplayModeRec *mode = xnfcalloc(1, sizeof(DisplayModeRec)); - - float h_pixels_rnd; - float v_lines_rnd; - float v_field_rate_rqd; - float top_margin; - float bottom_margin; - float interlace; - float h_period_est; - float vsync_plus_bp; - float v_back_porch; - float total_v_lines; - float v_field_rate_est; - float h_period; - float v_field_rate; - float v_frame_rate; - float left_margin; - float right_margin; - float total_active_pixels; - float ideal_duty_cycle; - float h_blank; - float total_pixels; - float pixel_freq; - float h_freq; - - float h_sync; - float h_front_porch; - float v_odd_front_porch_lines; - - /* 1. In order to give correct results, the number of horizontal - * pixels requested is first processed to ensure that it is divisible - * by the character size, by rounding it to the nearest character - * cell boundary: - * - * [H PIXELS RND] = ((ROUND([H PIXELS]/[CELL GRAN RND],0))*[CELLGRAN RND]) - */ - - h_pixels_rnd = rint((float) h_pixels / CELL_GRAN) * CELL_GRAN; - - /* 2. If interlace is requested, the number of vertical lines assumed - * by the calculation must be halved, as the computation calculates - * the number of vertical lines per field. In either case, the - * number of lines is rounded to the nearest integer. - * - * [V LINES RND] = IF([INT RQD?]="y", ROUND([V LINES]/2,0), - * ROUND([V LINES],0)) - */ - - v_lines_rnd = interlaced ? - rint((float) v_lines) / 2.0 : rint((float) v_lines); - - /* 3. Find the frame rate required: - * - * [V FIELD RATE RQD] = IF([INT RQD?]="y", [I/P FREQ RQD]*2, - * [I/P FREQ RQD]) - */ - - v_field_rate_rqd = interlaced ? (freq * 2.0) : (freq); - - /* 4. Find number of lines in Top margin: - * - * [TOP MARGIN (LINES)] = IF([MARGINS RQD?]="Y", - * ROUND(([MARGIN%]/100*[V LINES RND]),0), - * 0) - */ - - top_margin = margins ? rint(MARGIN_PERCENT / 100.0 * v_lines_rnd) : (0.0); - - /* 5. Find number of lines in Bottom margin: - * - * [BOT MARGIN (LINES)] = IF([MARGINS RQD?]="Y", - * ROUND(([MARGIN%]/100*[V LINES RND]),0), - * 0) - */ - - bottom_margin = - margins ? rint(MARGIN_PERCENT / 100.0 * v_lines_rnd) : (0.0); - - /* 6. If interlace is required, then set variable [INTERLACE]=0.5: - * - * [INTERLACE]=(IF([INT RQD?]="y",0.5,0)) - */ - - interlace = interlaced ? 0.5 : 0.0; - - /* 7. Estimate the Horizontal period - * - * [H PERIOD EST] = ((1/[V FIELD RATE RQD]) - [MIN VSYNC+BP]/1000000) / - * ([V LINES RND] + (2*[TOP MARGIN (LINES)]) + - * [MIN PORCH RND]+[INTERLACE]) * 1000000 - */ - - h_period_est = (((1.0 / v_field_rate_rqd) - (MIN_VSYNC_PLUS_BP / 1000000.0)) - / (v_lines_rnd + (2 * top_margin) + MIN_PORCH + interlace) - * 1000000.0); - - /* 8. Find the number of lines in V sync + back porch: - * - * [V SYNC+BP] = ROUND(([MIN VSYNC+BP]/[H PERIOD EST]),0) - */ - - vsync_plus_bp = rint(MIN_VSYNC_PLUS_BP / h_period_est); - - /* 9. Find the number of lines in V back porch alone: - * - * [V BACK PORCH] = [V SYNC+BP] - [V SYNC RND] - * - * XXX is "[V SYNC RND]" a typo? should be [V SYNC RQD]? - */ - - v_back_porch = vsync_plus_bp - V_SYNC_RQD; - (void) v_back_porch; - - /* 10. Find the total number of lines in Vertical field period: - * - * [TOTAL V LINES] = [V LINES RND] + [TOP MARGIN (LINES)] + - * [BOT MARGIN (LINES)] + [V SYNC+BP] + [INTERLACE] + - * [MIN PORCH RND] - */ - - total_v_lines = v_lines_rnd + top_margin + bottom_margin + vsync_plus_bp + - interlace + MIN_PORCH; - - /* 11. Estimate the Vertical field frequency: - * - * [V FIELD RATE EST] = 1 / [H PERIOD EST] / [TOTAL V LINES] * 1000000 - */ - - v_field_rate_est = 1.0 / h_period_est / total_v_lines * 1000000.0; - - /* 12. Find the actual horizontal period: - * - * [H PERIOD] = [H PERIOD EST] / ([V FIELD RATE RQD] / [V FIELD RATE EST]) - */ - - h_period = h_period_est / (v_field_rate_rqd / v_field_rate_est); - - /* 13. Find the actual Vertical field frequency: - * - * [V FIELD RATE] = 1 / [H PERIOD] / [TOTAL V LINES] * 1000000 - */ - - v_field_rate = 1.0 / h_period / total_v_lines * 1000000.0; - - /* 14. Find the Vertical frame frequency: - * - * [V FRAME RATE] = (IF([INT RQD?]="y", [V FIELD RATE]/2, [V FIELD RATE])) - */ - - v_frame_rate = interlaced ? v_field_rate / 2.0 : v_field_rate; - (void) v_frame_rate; - - /* 15. Find number of pixels in left margin: - * - * [LEFT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y", - * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 / - * [CELL GRAN RND]),0)) * [CELL GRAN RND], - * 0)) - */ - - left_margin = margins ? - rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN : - 0.0; - - /* 16. Find number of pixels in right margin: - * - * [RIGHT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y", - * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 / - * [CELL GRAN RND]),0)) * [CELL GRAN RND], - * 0)) - */ - - right_margin = margins ? - rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN : - 0.0; - - /* 17. Find total number of active pixels in image and left and right - * margins: - * - * [TOTAL ACTIVE PIXELS] = [H PIXELS RND] + [LEFT MARGIN (PIXELS)] + - * [RIGHT MARGIN (PIXELS)] - */ - - total_active_pixels = h_pixels_rnd + left_margin + right_margin; - - /* 18. Find the ideal blanking duty cycle from the blanking duty cycle - * equation: - * - * [IDEAL DUTY CYCLE] = [C'] - ([M']*[H PERIOD]/1000) - */ - - ideal_duty_cycle = C_PRIME - (M_PRIME * h_period / 1000.0); - - /* 19. Find the number of pixels in the blanking time to the nearest - * double character cell: - * - * [H BLANK (PIXELS)] = (ROUND(([TOTAL ACTIVE PIXELS] * - * [IDEAL DUTY CYCLE] / - * (100-[IDEAL DUTY CYCLE]) / - * (2*[CELL GRAN RND])), 0)) - * * (2*[CELL GRAN RND]) - */ - - h_blank = rint(total_active_pixels * - ideal_duty_cycle / - (100.0 - ideal_duty_cycle) / - (2.0 * CELL_GRAN)) * (2.0 * CELL_GRAN); - - /* 20. Find total number of pixels: - * - * [TOTAL PIXELS] = [TOTAL ACTIVE PIXELS] + [H BLANK (PIXELS)] - */ - - total_pixels = total_active_pixels + h_blank; - - /* 21. Find pixel clock frequency: - * - * [PIXEL FREQ] = [TOTAL PIXELS] / [H PERIOD] - */ - - pixel_freq = total_pixels / h_period; - - /* 22. Find horizontal frequency: - * - * [H FREQ] = 1000 / [H PERIOD] - */ - - h_freq = 1000.0 / h_period; - - /* Stage 1 computations are now complete; I should really pass - the results to another function and do the Stage 2 - computations, but I only need a few more values so I'll just - append the computations here for now */ - - /* 17. Find the number of pixels in the horizontal sync period: - * - * [H SYNC (PIXELS)] =(ROUND(([H SYNC%] / 100 * [TOTAL PIXELS] / - * [CELL GRAN RND]),0))*[CELL GRAN RND] - */ - - h_sync = - rint(H_SYNC_PERCENT / 100.0 * total_pixels / CELL_GRAN) * CELL_GRAN; - - /* 18. Find the number of pixels in the horizontal front porch period: - * - * [H FRONT PORCH (PIXELS)] = ([H BLANK (PIXELS)]/2)-[H SYNC (PIXELS)] - */ - - h_front_porch = (h_blank / 2.0) - h_sync; - - /* 36. Find the number of lines in the odd front porch period: - * - * [V ODD FRONT PORCH(LINES)]=([MIN PORCH RND]+[INTERLACE]) - */ - - v_odd_front_porch_lines = MIN_PORCH + interlace; - - /* finally, pack the results in the mode struct */ - - mode->HDisplay = (int) (h_pixels_rnd); - mode->HSyncStart = (int) (h_pixels_rnd + h_front_porch); - mode->HSyncEnd = (int) (h_pixels_rnd + h_front_porch + h_sync); - mode->HTotal = (int) (total_pixels); - mode->VDisplay = (int) (v_lines_rnd); - mode->VSyncStart = (int) (v_lines_rnd + v_odd_front_porch_lines); - mode->VSyncEnd = (int) (v_lines_rnd + v_odd_front_porch_lines + V_SYNC_RQD); - mode->VTotal = (int) (total_v_lines); - - mode->Clock = (int) (pixel_freq * 1000.0); - mode->HSync = h_freq; - mode->VRefresh = freq; - - xf86SetModeDefaultName(mode); - - mode->Flags = V_NHSYNC | V_PVSYNC; - if (interlaced) { - mode->VTotal *= 2; - mode->Flags |= V_INTERLACE; - } - - return mode; -} diff --git a/hw/xfree86/os-support/bsd/alpha_video.c b/hw/xfree86/os-support/bsd/alpha_video.c deleted file mode 100644 index b4038bd2b..000000000 --- a/hw/xfree86/os-support/bsd/alpha_video.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright 1992 by Rich Murphey - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR - * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" - -#include -#ifndef __NetBSD__ -#include -#endif - -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -#if defined(__NetBSD__) && !defined(MAP_FILE) -#define MAP_FLAGS MAP_SHARED -#else -#define MAP_FLAGS (MAP_FILE | MAP_SHARED) -#endif - -#ifndef __NetBSD__ -extern unsigned long dense_base(void); -#else /* __NetBSD__ */ -static struct alpha_bus_window *abw; -static int abw_count = -1; - -static void -init_abw(void) -{ - if (abw_count < 0) { - abw_count = alpha_bus_getwindows(ALPHA_BUS_TYPE_PCI_MEM, &abw); - if (abw_count <= 0) - FatalError("init_abw: alpha_bus_getwindows failed\n"); - } -} - -static unsigned long -dense_base(void) -{ - if (abw_count < 0) - init_abw(); - - /* XXX check abst_flags for ABST_DENSE just to be safe? */ - xf86Msg(X_INFO, "dense base = %#lx\n", abw[0].abw_abst.abst_sys_start); /* XXXX */ - return abw[0].abw_abst.abst_sys_start; -} - -#endif /* __NetBSD__ */ - -#define BUS_BASE dense_base() - -/***************************************************************************/ -/* Video Memory Mapping section */ -/***************************************************************************/ - -#ifdef __OpenBSD__ -#define SYSCTL_MSG "\tCheck that you have set 'machdep.allowaperture=1'\n"\ - "\tin /etc/sysctl.conf and reboot your machine\n" \ - "\trefer to xf86(4) for details" -#endif - -static int devMemFd = -1; - -#ifdef HAS_APERTURE_DRV -#define DEV_APERTURE "/dev/xf86" -#endif - -/* - * Check if /dev/mem can be mmap'd. If it can't print a warning when - * "warn" is TRUE. - */ -static void -checkDevMem(Bool warn) -{ - static Bool devMemChecked = FALSE; - int fd; - void *base; - - if (devMemChecked) - return; - devMemChecked = TRUE; - -#ifdef HAS_APERTURE_DRV - /* Try the aperture driver first */ - if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); - - if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); - devMemFd = fd; - xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n", - DEV_APERTURE); - return; - } - else { - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_APERTURE, strerror(errno)); - } - } - } -#endif - if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); - - if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); - devMemFd = fd; - return; - } - else { - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_MEM, strerror(errno)); - } - } - } - if (warn) { -#ifndef HAS_APERTURE_DRV - xf86Msg(X_WARNING, "checkDevMem: failed to open/mmap %s (%s)\n", - DEV_MEM, strerror(errno)); -#else -#ifndef __OpenBSD__ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n", DEV_APERTURE, DEV_MEM, strerror(errno)); -#else /* __OpenBSD__ */ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n%s", DEV_APERTURE, DEV_MEM, strerror(errno), - SYSCTL_MSG); -#endif /* __OpenBSD__ */ -#endif - xf86ErrorF("\tlinear framebuffer access unavailable\n"); - } - return; -} - -void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - checkDevMem(TRUE); - - pVidMem->initialised = TRUE; -} - -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) - -extern int ioperm(unsigned long from, unsigned long num, int on); - -Bool -xf86EnableIO() -{ - if (!ioperm(0, 65536, TRUE)) - return TRUE; - return FALSE; -} - -void -xf86DisableIO() -{ - return; -} - -#endif /* __FreeBSD_kernel__ || __OpenBSD__ */ - -#ifdef USE_ALPHA_PIO - -Bool -xf86EnableIO() -{ - alpha_pci_io_enable(1); - return TRUE; -} - -void -xf86DisableIO() -{ - alpha_pci_io_enable(0); -} - -#endif /* USE_ALPHA_PIO */ - -extern int readDense8(void *Base, register unsigned long Offset); -extern int readDense16(void *Base, register unsigned long Offset); -extern int readDense32(void *Base, register unsigned long Offset); -extern void - writeDense8(int Value, void *Base, register unsigned long Offset); -extern void - writeDense16(int Value, void *Base, register unsigned long Offset); -extern void - writeDense32(int Value, void *Base, register unsigned long Offset); - -void (*xf86WriteMmio8) (int Value, void *Base, unsigned long Offset) - = writeDense8; -void (*xf86WriteMmio16) (int Value, void *Base, unsigned long Offset) - = writeDense16; -void (*xf86WriteMmio32) (int Value, void *Base, unsigned long Offset) - = writeDense32; -int (*xf86ReadMmio8) (void *Base, unsigned long Offset) - = readDense8; -int (*xf86ReadMmio16) (void *Base, unsigned long Offset) - = readDense16; -int (*xf86ReadMmio32) (void *Base, unsigned long Offset) - = readDense32; diff --git a/hw/xfree86/os-support/bsd/arm_video.c b/hw/xfree86/os-support/bsd/arm_video.c deleted file mode 100644 index 180d70543..000000000 --- a/hw/xfree86/os-support/bsd/arm_video.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright 1992 by Rich Murphey - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR - * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -/* - * The ARM32 code here carries the following copyright: - * - * Copyright 1997 - * Digital Equipment Corporation. All rights reserved. - * This software is furnished under license and may be used and copied only in - * accordance with the following terms and conditions. Subject to these - * conditions, you may download, copy, install, use, modify and distribute - * this software in source and/or binary form. No title or ownership is - * transferred hereby. - * - * 1) Any source code used, modified or distributed must reproduce and retain - * this copyright notice and list of conditions as they appear in the - * source file. - * - * 2) No right is granted to use any trade name, trademark, or logo of Digital - * Equipment Corporation. Neither the "Digital Equipment Corporation" - * name nor any trademark or logo of Digital Equipment Corporation may be - * used to endorse or promote products derived from this software without - * the prior written permission of Digital Equipment Corporation. - * - * 3) This software is provided "AS-IS" and any express or implied warranties, - * including but not limited to, any implied warranties of merchantability, - * fitness for a particular purpose, or non-infringement are disclaimed. - * In no event shall DIGITAL be liable for any damages whatsoever, and in - * particular, DIGITAL shall not be liable for special, indirect, - * consequential, or incidental damages or damages for lost profits, loss - * of revenue or loss of use, whether such damages arise in contract, - * negligence, tort, under statute, in equity, at law or otherwise, even - * if advised of the possibility of such damage. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" -#include "compiler.h" - -#if defined(__NetBSD__) && !defined(MAP_FILE) -#define MAP_FLAGS MAP_SHARED -#else -#define MAP_FLAGS (MAP_FILE | MAP_SHARED) -#endif - -#define BUS_BASE 0L -#define BUS_BASE_BWX 0L - -/***************************************************************************/ -/* Video Memory Mapping section */ -/***************************************************************************/ - -static int devMemFd = -1; - -/* - * Check if /dev/mem can be mmap'd. If it can't print a warning when - * "warn" is TRUE. - */ -static void -checkDevMem(Bool warn) -{ - static Bool devMemChecked = FALSE; - int fd; - void *base; - - if (devMemChecked) - return; - devMemChecked = TRUE; - - if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000 + BUS_BASE); - - if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); - devMemFd = fd; - return; - } - else { - /* This should not happen */ - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_MEM, strerror(errno)); - } - return; - } - } - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - } - return; -} - -void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - checkDevMem(TRUE); - - pVidMem->initialised = TRUE; -} - -#ifdef USE_DEV_IO -static int IoFd = -1; - -Bool -xf86EnableIO() -{ - if (IoFd >= 0) - return TRUE; - - if ((IoFd = open("/dev/io", O_RDWR)) == -1) { - xf86Msg(X_WARNING, "xf86EnableIO: " - "Failed to open /dev/io for extended I/O\n"); - return FALSE; - } - return TRUE; -} - -void -xf86DisableIO() -{ - if (IoFd < 0) - return; - - close(IoFd); - IoFd = -1; - return; -} - -#endif - -#if defined(USE_ARC_MMAP) || defined(__arm32__) - -unsigned int IOPortBase; - -Bool -xf86EnableIO() -{ - int fd; - void *base; - - if (ExtendedEnabled) - return TRUE; - - if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) { - /* Try to map a page at the pccons I/O space */ - base = (void *) mmap((caddr_t) 0, 65536, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0x0000); - - if (base != (void *) -1) { - IOPortBase = base; - } - else { - xf86Msg(X_WARNING, "EnableIO: failed to mmap %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - return FALSE; - } - } - else { - xf86Msg("EnableIO: failed to open %s (%s)\n", - "/dev/ttyC0", strerror(errno)); - return FALSE; - } - - ExtendedEnabled = TRUE; - - return TRUE; -} - -void -xf86DisableIO() -{ - return; -} - -#endif /* USE_ARC_MMAP */ diff --git a/hw/xfree86/os-support/bsd/bsd_VTsw.c b/hw/xfree86/os-support/bsd/bsd_VTsw.c deleted file mode 100644 index 0ee51de2f..000000000 --- a/hw/xfree86/os-support/bsd/bsd_VTsw.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Derived from VTsw_usl.c which is - * Copyright 1993 by David Wexelblat - * by S_ren Schmidt (sos@login.dkuug.dk) - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of David Wexelblat not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. David Wexelblat makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -/* - * Handle the VT-switching interface for OSs that use USL-style ioctl()s - * (the bsd, sysv, sco, and linux subdirs). - */ - -/* - * This function is the signal handler for the VT-switching signal. It - * is only referenced inside the OS-support layer. - */ -void -xf86VTRequest(int sig) -{ -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) { - xf86Info.vtRequestsPending = TRUE; - } -#endif - return; -} - -Bool -xf86VTSwitchPending() -{ -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) { - return xf86Info.vtRequestsPending ? TRUE : FALSE; - } -#endif - return FALSE; -} - -Bool -xf86VTSwitchAway() -{ -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) { - xf86Info.vtRequestsPending = FALSE; - if (ioctl(xf86Info.consoleFd, VT_RELDISP, 1) < 0) - return FALSE; - else - return TRUE; - } -#endif - return FALSE; -} - -Bool -xf86VTSwitchTo() -{ -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - if (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT) { - xf86Info.vtRequestsPending = FALSE; - if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) - return FALSE; - else - return TRUE; - } -#endif - return TRUE; -} - -Bool -xf86VTActivate(int vtno) -{ - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vtno) < 0) { - return FALSE; - } - return TRUE; -} diff --git a/hw/xfree86/os-support/bsd/bsd_bell.c b/hw/xfree86/os-support/bsd/bsd_bell.c deleted file mode 100644 index 19d1f4882..000000000 --- a/hw/xfree86/os-support/bsd/bsd_bell.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 1992 by Rich Murphey - * Copyright 1993 by David Dawes - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Rich Murphey and David Dawes - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Rich Murphey and - * David Dawes make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * RICH MURPHEY AND DAVID DAWES DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID DAWES BE LIABLE FOR - * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#if defined (SYSCONS_SUPPORT) -#include -#endif - -#include - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -void -xf86OSRingBell(int loudness, int pitch, int duration) -{ -#ifdef WSCONS_SUPPORT - struct wskbd_bell_data wsb; -#endif - - if (loudness && pitch) { -#ifdef PCCONS_SUPPORT - int data[2]; -#endif - - switch (xf86Info.consType) { - -#ifdef PCCONS_SUPPORT - case PCCONS: - data[0] = pitch; - data[1] = (duration * loudness) / 50; - ioctl(xf86Info.consoleFd, CONSOLE_X_BELL, data); - break; -#endif -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - case SYSCONS: - case PCVT: - ioctl(xf86Info.consoleFd, KDMKTONE, - ((1193190 / pitch) & 0xffff) | - (((unsigned long) duration * loudness / 50) << 16)); - break; -#endif -#if defined (WSCONS_SUPPORT) - case WSCONS: - wsb.which = WSKBD_BELL_DOALL; - wsb.pitch = pitch; - wsb.period = duration; - wsb.volume = loudness; - ioctl(xf86Info.consoleFd, WSKBDIO_COMPLEXBELL, &wsb); - break; -#endif - } - } -} diff --git a/hw/xfree86/os-support/bsd/bsd_ev56.c b/hw/xfree86/os-support/bsd/bsd_ev56.c deleted file mode 100644 index 95883491b..000000000 --- a/hw/xfree86/os-support/bsd/bsd_ev56.c +++ /dev/null @@ -1,75 +0,0 @@ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "input.h" -#include "scrnintstr.h" -#include "compiler.h" - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -#include - -/* - * The following functions are used only on EV56 and greater CPUs, - * and the assembler requires going to EV56 mode in order to emit - * these instructions. - */ -__asm(".arch ev56"); - -int readDense8(void *Base, register unsigned long Offset); -int readDense16(void *Base, register unsigned long Offset); -int readDense32(void *Base, register unsigned long Offset); -void - writeDense8(int Value, void *Base, register unsigned long Offset); -void - writeDense16(int Value, void *Base, register unsigned long Offset); -void - writeDense32(int Value, void *Base, register unsigned long Offset); - -int -readDense8(void *Base, register unsigned long Offset) -{ - mem_barrier(); - return (alpha_ldbu((void *) ((unsigned long) Base + (Offset)))); -} - -int -readDense16(void *Base, register unsigned long Offset) -{ - mem_barrier(); - return (alpha_ldwu((void *) ((unsigned long) Base + (Offset)))); -} - -int -readDense32(void *Base, register unsigned long Offset) -{ - mem_barrier(); - return *(volatile CARD32 *) ((unsigned long) Base + (Offset)); -} - -void -writeDense8(int Value, void *Base, register unsigned long Offset) -{ - write_mem_barrier(); - alpha_stb((void *) ((unsigned long) Base + (Offset)), Value); -} - -void -writeDense16(int Value, void *Base, register unsigned long Offset) -{ - write_mem_barrier(); - alpha_stw((void *) ((unsigned long) Base + (Offset)), Value); -} - -void -writeDense32(int Value, void *Base, register unsigned long Offset) -{ - write_mem_barrier(); - *(volatile CARD32 *) ((unsigned long) Base + (Offset)) = Value; -} diff --git a/hw/xfree86/os-support/bsd/bsd_init.c b/hw/xfree86/os-support/bsd/bsd_init.c deleted file mode 100644 index 46536f81d..000000000 --- a/hw/xfree86/os-support/bsd/bsd_init.c +++ /dev/null @@ -1,669 +0,0 @@ -/* - * Copyright 1992 by Rich Murphey - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR - * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "compiler.h" - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -#include -#include -#include -#include - -static Bool KeepTty = FALSE; - -#ifdef PCCONS_SUPPORT -static int devConsoleFd = -1; -#endif -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) -static int VTnum = -1; -static int initialVT = -1; -#endif - -#ifdef PCCONS_SUPPORT -/* Stock 0.1 386bsd pccons console driver interface */ -#define PCCONS_CONSOLE_DEV1 "/dev/ttyv0" -#define PCCONS_CONSOLE_DEV2 "/dev/vga" -#define PCCONS_CONSOLE_MODE O_RDWR|O_NDELAY -#endif - -#ifdef SYSCONS_SUPPORT -/* The FreeBSD 1.1 version syscons driver uses /dev/ttyv0 */ -#define SYSCONS_CONSOLE_DEV1 "/dev/ttyv0" -#define SYSCONS_CONSOLE_DEV2 "/dev/vga" -#define SYSCONS_CONSOLE_MODE O_RDWR|O_NDELAY -#endif - -#ifdef PCVT_SUPPORT -/* Hellmuth Michaelis' pcvt driver */ -#ifndef __OpenBSD__ -#define PCVT_CONSOLE_DEV "/dev/ttyv0" -#else -#define PCVT_CONSOLE_DEV "/dev/ttyC0" -#endif -#define PCVT_CONSOLE_MODE O_RDWR|O_NDELAY -#endif - -#if defined(WSCONS_SUPPORT) && defined(__NetBSD__) -/* NetBSD's new console driver */ -#define WSCONS_PCVT_COMPAT_CONSOLE_DEV "/dev/ttyE0" -#endif - -#ifdef __GLIBC__ -#define setpgrp setpgid -#endif - -#define CHECK_DRIVER_MSG \ - "Check your kernel's console driver configuration and /dev entries" - -static char *supported_drivers[] = { -#ifdef PCCONS_SUPPORT - "pccons (with X support)", -#endif -#ifdef SYSCONS_SUPPORT - "syscons", -#endif -#ifdef PCVT_SUPPORT - "pcvt", -#endif -#ifdef WSCONS_SUPPORT - "wscons", -#endif -}; - -/* - * Functions to probe for the existence of a supported console driver. - * Any function returns either a valid file descriptor (driver probed - * successfully), -1 (driver not found), or uses FatalError() if the - * driver was found but proved to not support the required mode to run - * an X server. - */ - -typedef int (*xf86ConsOpen_t) (void); - -#ifdef PCCONS_SUPPORT -static int xf86OpenPccons(void); -#endif /* PCCONS_SUPPORT */ - -#ifdef SYSCONS_SUPPORT -static int xf86OpenSyscons(void); -#endif /* SYSCONS_SUPPORT */ - -#ifdef PCVT_SUPPORT -static int xf86OpenPcvt(void); -#endif /* PCVT_SUPPORT */ - -#ifdef WSCONS_SUPPORT -static int xf86OpenWScons(void); -#endif - -/* - * The sequence of the driver probes is important; start with the - * driver that is best distinguishable, and end with the most generic - * driver. (Otherwise, pcvt would also probe as syscons, and either - * pcvt or syscons might successfully probe as pccons.) - */ -static xf86ConsOpen_t xf86ConsTab[] = { -#ifdef PCVT_SUPPORT - xf86OpenPcvt, -#endif -#ifdef SYSCONS_SUPPORT - xf86OpenSyscons, -#endif -#ifdef PCCONS_SUPPORT - xf86OpenPccons, -#endif -#ifdef WSCONS_SUPPORT - xf86OpenWScons, -#endif - (xf86ConsOpen_t) NULL -}; - -void -xf86OpenConsole() -{ - int i, fd = -1; - xf86ConsOpen_t *driver; - -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - int result; - -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - struct utsname uts; -#endif - vtmode_t vtmode; -#endif - - if (serverGeneration == 1) { - /* check if we are run with euid==0 */ - if (geteuid() != 0) { - FatalError("xf86OpenConsole: Server must be suid root"); - } - - if (!KeepTty) { - /* - * detaching the controlling tty solves problems of kbd character - * loss. This is not interesting for CO driver, because it is - * exclusive. - */ - setpgrp(0, getpid()); - if ((i = open("/dev/tty", O_RDWR)) >= 0) { - ioctl(i, TIOCNOTTY, (char *) 0); - close(i); - } - } - - /* detect which driver we are running on */ - for (driver = xf86ConsTab; *driver; driver++) { - if ((fd = (*driver) ()) >= 0) - break; - } - - /* Check that a supported console driver was found */ - if (fd < 0) { - char cons_drivers[80] = { 0, }; - for (i = 0; i < ARRAY_SIZE(supported_drivers); i++) { - if (i) { - strcat(cons_drivers, ", "); - } - strcat(cons_drivers, supported_drivers[i]); - } - FatalError - ("%s: No console driver found\n\tSupported drivers: %s\n\t%s", - "xf86OpenConsole", cons_drivers, CHECK_DRIVER_MSG); - } - xf86Info.consoleFd = fd; - - switch (xf86Info.consType) { -#ifdef PCCONS_SUPPORT - case PCCONS: - if (ioctl(xf86Info.consoleFd, CONSOLE_X_MODE_ON, 0) < 0) { - FatalError("%s: CONSOLE_X_MODE_ON failed (%s)\n%s", - "xf86OpenConsole", strerror(errno), - CHECK_DRIVER_MSG); - } - /* - * Hack to prevent keyboard hanging when syslogd closes - * /dev/console - */ - if ((devConsoleFd = open("/dev/console", O_WRONLY, 0)) < 0) { - xf86Msg(X_WARNING, - "xf86OpenConsole: couldn't open /dev/console (%s)\n", - strerror(errno)); - } - break; -#endif -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - case SYSCONS: - /* as of FreeBSD 2.2.8, syscons driver does not need the #1 vt - * switching anymore. Here we check for FreeBSD 3.1 and up. - * Add cases for other *BSD that behave the same. - */ -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - uname(&uts); - i = atof(uts.release) * 100; - if (i >= 310) - goto acquire_vt; -#endif - /* otherwise fall through */ - case PCVT: -#if !(defined(__NetBSD__) && (__NetBSD_Version__ >= 200000000)) - /* - * First activate the #1 VT. This is a hack to allow a server - * to be started while another one is active. There should be - * a better way. - */ - if (initialVT != 1) { - - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, 1) != 0) { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); - } - sleep(1); - } -#endif - acquire_vt: - if (!xf86Info.ShareVTs) { - /* - * now get the VT - */ - SYSCALL(result = - ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno)); - if (result != 0) { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); - } - SYSCALL(result = - ioctl(xf86Info.consoleFd, VT_WAITACTIVE, - xf86Info.vtno)); - if (result != 0) { - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_WAITACTIVE failed\n"); - } - - OsSignal(SIGUSR1, xf86VTRequest); - - vtmode.mode = VT_PROCESS; - vtmode.relsig = SIGUSR1; - vtmode.acqsig = SIGUSR1; - vtmode.frsig = SIGUSR1; - if (ioctl(xf86Info.consoleFd, VT_SETMODE, &vtmode) < 0) { - FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed"); - } -#if !defined(__OpenBSD__) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) - if (ioctl(xf86Info.consoleFd, KDENABIO, 0) < 0) { - FatalError("xf86OpenConsole: KDENABIO failed (%s)", - strerror(errno)); - } -#endif - if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) { - FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed"); - } - } - else { /* xf86Info.ShareVTs */ - close(xf86Info.consoleFd); - } - break; -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ -#ifdef WSCONS_SUPPORT - case WSCONS: - /* Nothing to do */ - break; -#endif - } - } - else { - /* serverGeneration != 1 */ -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - if (!xf86Info.ShareVTs && - (xf86Info.consType == SYSCONS || xf86Info.consType == PCVT)) { - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, xf86Info.vtno) != 0) { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_ACTIVATE failed\n"); - } - } -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ - } - return; -} - -#ifdef PCCONS_SUPPORT - -static int -xf86OpenPccons() -{ - int fd = -1; - - if ((fd = open(PCCONS_CONSOLE_DEV1, PCCONS_CONSOLE_MODE, 0)) - >= 0 || (fd = open(PCCONS_CONSOLE_DEV2, PCCONS_CONSOLE_MODE, 0)) - >= 0) { - if (ioctl(fd, CONSOLE_X_MODE_OFF, 0) < 0) { - FatalError("%s: CONSOLE_X_MODE_OFF failed (%s)\n%s\n%s", - "xf86OpenPccons", - strerror(errno), - "Was expecting pccons driver with X support", - CHECK_DRIVER_MSG); - } - xf86Info.consType = PCCONS; - xf86Msg(X_PROBED, "Using pccons driver with X support\n"); - } - return fd; -} - -#endif /* PCCONS_SUPPORT */ - -#ifdef SYSCONS_SUPPORT - -static int -xf86OpenSyscons() -{ - int fd = -1; - vtmode_t vtmode; - char vtname[12]; - long syscons_version; - MessageType from; - - /* Check for syscons */ - if ((fd = open(SYSCONS_CONSOLE_DEV1, SYSCONS_CONSOLE_MODE, 0)) >= 0 - || (fd = open(SYSCONS_CONSOLE_DEV2, SYSCONS_CONSOLE_MODE, 0)) >= 0) { - if (ioctl(fd, VT_GETMODE, &vtmode) >= 0) { - /* Get syscons version */ - if (ioctl(fd, CONS_GETVERS, &syscons_version) < 0) { - syscons_version = 0; - } - - xf86Info.vtno = VTnum; - from = X_CMDLINE; - -#ifdef VT_GETACTIVE - if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0) - initialVT = -1; -#endif - if (xf86Info.ShareVTs) - xf86Info.vtno = initialVT; - - if (xf86Info.vtno == -1) { - /* - * For old syscons versions (<0x100), VT_OPENQRY returns - * the current VT rather than the next free VT. In this - * case, the server gets started on the current VT instead - * of the next free VT. - */ - -#if 0 - /* check for the fixed VT_OPENQRY */ - if (syscons_version >= 0x100) { -#endif - if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) { - /* No free VTs */ - xf86Info.vtno = -1; - } -#if 0 - } -#endif - - if (xf86Info.vtno == -1) { - /* - * All VTs are in use. If initialVT was found, use it. - */ - if (initialVT != -1) { - xf86Info.vtno = initialVT; - } - else { - if (syscons_version >= 0x100) { - FatalError("%s: Cannot find a free VT", - "xf86OpenSyscons"); - } - /* Should no longer reach here */ - FatalError("%s: %s %s\n\t%s %s", - "xf86OpenSyscons", - "syscons versions prior to 1.0 require", - "either the", - "server's stdin be a VT", - "or the use of the vtxx server option"); - } - } - from = X_PROBED; - } - - close(fd); - snprintf(vtname, sizeof(vtname), "/dev/ttyv%01x", - xf86Info.vtno - 1); - if ((fd = open(vtname, SYSCONS_CONSOLE_MODE, 0)) < 0) { - FatalError("xf86OpenSyscons: Cannot open %s (%s)", - vtname, strerror(errno)); - } - if (ioctl(fd, VT_GETMODE, &vtmode) < 0) { - FatalError("xf86OpenSyscons: VT_GETMODE failed"); - } - xf86Info.consType = SYSCONS; - xf86Msg(X_PROBED, "Using syscons driver with X support"); - if (syscons_version >= 0x100) { - xf86ErrorF(" (version %ld.%ld)\n", syscons_version >> 8, - syscons_version & 0xFF); - } - else { - xf86ErrorF(" (version 0.x)\n"); - } - xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); - } - else { - /* VT_GETMODE failed, probably not syscons */ - close(fd); - fd = -1; - } - } - return fd; -} - -#endif /* SYSCONS_SUPPORT */ - -#ifdef PCVT_SUPPORT - -static int -xf86OpenPcvt() -{ - /* This looks much like syscons, since pcvt is API compatible */ - int fd = -1; - vtmode_t vtmode; - char vtname[12], *vtprefix; - struct pcvtid pcvt_version; - -#ifndef __OpenBSD__ - vtprefix = "/dev/ttyv"; -#else - vtprefix = "/dev/ttyC"; -#endif - - fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); -#ifdef WSCONS_PCVT_COMPAT_CONSOLE_DEV - if (fd < 0) { - fd = open(WSCONS_PCVT_COMPAT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0); - vtprefix = "/dev/ttyE"; - } -#endif - if (fd >= 0) { - if (ioctl(fd, VGAPCVTID, &pcvt_version) >= 0) { - if (ioctl(fd, VT_GETMODE, &vtmode) < 0) { - FatalError("%s: VT_GETMODE failed\n%s%s\n%s", - "xf86OpenPcvt", - "Found pcvt driver but X11 seems to be", - " not supported.", CHECK_DRIVER_MSG); - } - - xf86Info.vtno = VTnum; - - if (ioctl(fd, VT_GETACTIVE, &initialVT) < 0) - initialVT = -1; - - if (xf86Info.vtno == -1) { - if (ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) { - /* No free VTs */ - xf86Info.vtno = -1; - } - - if (xf86Info.vtno == -1) { - /* - * All VTs are in use. If initialVT was found, use it. - */ - if (initialVT != -1) { - xf86Info.vtno = initialVT; - } - else { - FatalError("%s: Cannot find a free VT", "xf86OpenPcvt"); - } - } - } - - close(fd); - snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, - xf86Info.vtno - 1); - if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { - ErrorF("xf86OpenPcvt: Cannot open %s (%s)", - vtname, strerror(errno)); - xf86Info.vtno = initialVT; - snprintf(vtname, sizeof(vtname), "%s%01x", vtprefix, - xf86Info.vtno - 1); - if ((fd = open(vtname, PCVT_CONSOLE_MODE, 0)) < 0) { - FatalError("xf86OpenPcvt: Cannot open %s (%s)", - vtname, strerror(errno)); - } - } - if (ioctl(fd, VT_GETMODE, &vtmode) < 0) { - FatalError("xf86OpenPcvt: VT_GETMODE failed"); - } - xf86Info.consType = PCVT; -#ifdef WSCONS_SUPPORT - xf86Msg(X_PROBED, - "Using wscons driver on %s in pcvt compatibility mode " - "(version %d.%d)\n", vtname, - pcvt_version.rmajor, pcvt_version.rminor); -#else - xf86Msg(X_PROBED, "Using pcvt driver (version %d.%d)\n", - pcvt_version.rmajor, pcvt_version.rminor); -#endif - } - else { - /* Not pcvt */ - close(fd); - fd = -1; - } - } - return fd; -} - -#endif /* PCVT_SUPPORT */ - -#ifdef WSCONS_SUPPORT - -static int -xf86OpenWScons() -{ - int fd = -1; - int mode = WSDISPLAYIO_MODE_MAPPED; - int i; - char ttyname[16]; - - /* XXX Is this ok? */ - for (i = 0; i < 8; i++) { -#if defined(__NetBSD__) - snprintf(ttyname, sizeof(ttyname), "/dev/ttyE%d", i); -#elif defined(__OpenBSD__) - snprintf(ttyname, sizeof(ttyname), "/dev/ttyC%x", i); -#endif - if ((fd = open(ttyname, 2)) != -1) - break; - } - if (fd != -1) { - if (ioctl(fd, WSDISPLAYIO_SMODE, &mode) < 0) { - FatalError("%s: WSDISPLAYIO_MODE_MAPPED failed (%s)\n%s", - "xf86OpenConsole", strerror(errno), CHECK_DRIVER_MSG); - } - xf86Info.consType = WSCONS; - xf86Msg(X_PROBED, "Using wscons driver\n"); - } - return fd; -} - -#endif /* WSCONS_SUPPORT */ - -void -xf86CloseConsole() -{ -#if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) - struct vt_mode VT; -#endif - - if (xf86Info.ShareVTs) - return; - - switch (xf86Info.consType) { -#ifdef PCCONS_SUPPORT - case PCCONS: - ioctl(xf86Info.consoleFd, CONSOLE_X_MODE_OFF, 0); - break; -#endif /* PCCONS_SUPPORT */ -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - case SYSCONS: - case PCVT: - ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT); /* Back to text mode */ - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) { - VT.mode = VT_AUTO; - ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* dflt vt handling */ - } -#if !defined(__OpenBSD__) && !defined(USE_DEV_IO) && !defined(USE_I386_IOPL) - if (ioctl(xf86Info.consoleFd, KDDISABIO, 0) < 0) { - xf86FatalError("xf86CloseConsole: KDDISABIO failed (%s)", - strerror(errno)); - } -#endif - if (initialVT != -1) - ioctl(xf86Info.consoleFd, VT_ACTIVATE, initialVT); - break; -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ -#ifdef WSCONS_SUPPORT - case WSCONS: - { - int mode = WSDISPLAYIO_MODE_EMUL; - - ioctl(xf86Info.consoleFd, WSDISPLAYIO_SMODE, &mode); - break; - } -#endif - } - - close(xf86Info.consoleFd); -#ifdef PCCONS_SUPPORT - if (devConsoleFd >= 0) - close(devConsoleFd); -#endif - return; -} - -int -xf86ProcessArgument(int argc, char *argv[], int i) -{ - /* - * Keep server from detaching from controlling tty. This is useful - * when debugging (so the server can receive keyboard signals. - */ - if (!strcmp(argv[i], "-keeptty")) { - KeepTty = TRUE; - return 1; - } -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { - if (sscanf(argv[i], "vt%2d", &VTnum) == 0 || VTnum < 1 || VTnum > 12) { - UseMsg(); - VTnum = -1; - return 0; - } - return 1; - } -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ - return 0; -} - -void -xf86UseMsg() -{ -#if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT) - ErrorF("vtXX use the specified VT number (1-12)\n"); -#endif /* SYSCONS_SUPPORT || PCVT_SUPPORT */ - ErrorF("-keeptty "); - ErrorF("don't detach controlling tty (for debugging only)\n"); - return; -} - -void -xf86OSInputThreadInit(void) -{ - return; -} diff --git a/hw/xfree86/os-support/bsd/bsd_kmod.c b/hw/xfree86/os-support/bsd/bsd_kmod.c deleted file mode 100644 index 150bb0db4..000000000 --- a/hw/xfree86/os-support/bsd/bsd_kmod.c +++ /dev/null @@ -1,29 +0,0 @@ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "xf86_OSproc.h" - -/* - * Load a FreeBSD kernel module. - * This is used by the DRI/DRM to load a DRM kernel module when - * the X server starts. It could be used for other purposes in the future. - * Input: - * modName - name of the kernel module (Ex: "tdfx") - * Return: - * 0 for failure, 1 for success - */ -int -xf86LoadKernelModule(const char *modName) -{ - if (kldload(modName) != -1) - return 1; - else - return 0; -} diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c deleted file mode 100644 index a38a7de27..000000000 --- a/hw/xfree86/os-support/bsd/i386_video.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright 1992 by Rich Murphey - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR - * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" - -#include -#include - -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -#if defined(__NetBSD__) && !defined(MAP_FILE) -#define MAP_FLAGS MAP_SHARED -#else -#define MAP_FLAGS (MAP_FILE | MAP_SHARED) -#endif - -#ifdef __OpenBSD__ -#define SYSCTL_MSG "\tCheck that you have set 'machdep.allowaperture=1'\n"\ - "\tin /etc/sysctl.conf and reboot your machine\n" \ - "\trefer to xf86(4) for details" -#define SYSCTL_MSG2 \ - "Check that you have set 'machdep.allowaperture=2'\n" \ - "\tin /etc/sysctl.conf and reboot your machine\n" \ - "\trefer to xf86(4) for details" -#endif - -/***************************************************************************/ -/* Video Memory Mapping section */ -/***************************************************************************/ - -static Bool useDevMem = FALSE; -static int devMemFd = -1; - -#ifdef HAS_APERTURE_DRV -#define DEV_APERTURE "/dev/xf86" -#endif - -/* - * Check if /dev/mem can be mmap'd. If it can't print a warning when - * "warn" is TRUE. - */ -static void -checkDevMem(Bool warn) -{ - static Bool devMemChecked = FALSE; - int fd; - void *base; - - if (devMemChecked) - return; - devMemChecked = TRUE; - - if ((fd = open(DEV_MEM, O_RDWR)) >= 0) { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000); - - if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); - devMemFd = fd; - useDevMem = TRUE; - return; - } - else { - /* This should not happen */ - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_MEM, strerror(errno)); - } - useDevMem = FALSE; - return; - } - } -#ifndef HAS_APERTURE_DRV - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n", - DEV_MEM, strerror(errno)); - } - useDevMem = FALSE; - return; -#else - /* Failed to open /dev/mem, try the aperture driver */ - if ((fd = open(DEV_APERTURE, O_RDWR)) >= 0) { - /* Try to map a page at the VGA address */ - base = mmap((caddr_t) 0, 4096, PROT_READ | PROT_WRITE, - MAP_FLAGS, fd, (off_t) 0xA0000); - - if (base != MAP_FAILED) { - munmap((caddr_t) base, 4096); - devMemFd = fd; - useDevMem = TRUE; - xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n", - DEV_APERTURE); - return; - } - else { - - if (warn) { - xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n", - DEV_APERTURE, strerror(errno)); - } - } - } - else { - if (warn) { -#ifndef __OpenBSD__ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n", DEV_MEM, DEV_APERTURE, strerror(errno)); -#else /* __OpenBSD__ */ - xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n" - "\t(%s)\n%s", DEV_MEM, DEV_APERTURE, strerror(errno), - SYSCTL_MSG); -#endif /* __OpenBSD__ */ - } - } - - useDevMem = FALSE; - return; - -#endif -} - -void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - checkDevMem(TRUE); - - pci_system_init_dev_mem(devMemFd); - - pVidMem->initialised = TRUE; -} - -#ifdef USE_I386_IOPL -/***************************************************************************/ -/* I/O Permissions section */ -/***************************************************************************/ - -static Bool ExtendedEnabled = FALSE; - -Bool -xf86EnableIO() -{ - if (ExtendedEnabled) - return TRUE; - - if (i386_iopl(TRUE) < 0) { -#ifndef __OpenBSD__ - xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O", - "xf86EnableIO"); -#else - xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O\n%s", - "xf86EnableIO", SYSCTL_MSG); -#endif - return FALSE; - } - ExtendedEnabled = TRUE; - - return TRUE; -} - -void -xf86DisableIO() -{ - if (!ExtendedEnabled) - return; - - i386_iopl(FALSE); - ExtendedEnabled = FALSE; - - return; -} - -#endif /* USE_I386_IOPL */ - -#ifdef USE_AMD64_IOPL -/***************************************************************************/ -/* I/O Permissions section */ -/***************************************************************************/ - -static Bool ExtendedEnabled = FALSE; - -Bool -xf86EnableIO() -{ - if (ExtendedEnabled) - return TRUE; - - if (amd64_iopl(TRUE) < 0) { -#ifndef __OpenBSD__ - xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O", - "xf86EnableIO"); -#else - xf86Msg(X_WARNING, "%s: Failed to set IOPL for extended I/O\n%s", - "xf86EnableIO", SYSCTL_MSG); -#endif - return FALSE; - } - ExtendedEnabled = TRUE; - - return TRUE; -} - -void -xf86DisableIO() -{ - if (!ExtendedEnabled) - return; - - if (amd64_iopl(FALSE) == 0) { - ExtendedEnabled = FALSE; - } - /* Otherwise, the X server has revoqued its root uid, - and thus cannot give up IO privileges any more */ - - return; -} - -#endif /* USE_AMD64_IOPL */ - -#ifdef USE_DEV_IO -static int IoFd = -1; - -Bool -xf86EnableIO() -{ - if (IoFd >= 0) - return TRUE; - - if ((IoFd = open("/dev/io", O_RDWR)) == -1) { - xf86Msg(X_WARNING, "xf86EnableIO: " - "Failed to open /dev/io for extended I/O"); - return FALSE; - } - return TRUE; -} - -void -xf86DisableIO() -{ - if (IoFd < 0) - return; - - close(IoFd); - IoFd = -1; - return; -} - -#endif - -#ifdef __NetBSD__ -/***************************************************************************/ -/* Set TV output mode */ -/***************************************************************************/ -void -xf86SetTVOut(int mode) -{ - switch (xf86Info.consType) { -#ifdef PCCONS_SUPPORT - case PCCONS:{ - - if (ioctl(xf86Info.consoleFd, CONSOLE_X_TV_ON, &mode) < 0) { - xf86Msg(X_WARNING, - "xf86SetTVOut: Could not set console to TV output, %s\n", - strerror(errno)); - } - } - break; -#endif /* PCCONS_SUPPORT */ - - default: - FatalError("Xf86SetTVOut: Unsupported console"); - break; - } - return; -} - -void -xf86SetRGBOut() -{ - switch (xf86Info.consType) { -#ifdef PCCONS_SUPPORT - case PCCONS:{ - - if (ioctl(xf86Info.consoleFd, CONSOLE_X_TV_OFF, 0) < 0) { - xf86Msg(X_WARNING, - "xf86SetTVOut: Could not set console to RGB output, %s\n", - strerror(errno)); - } - } - break; -#endif /* PCCONS_SUPPORT */ - - default: - FatalError("Xf86SetTVOut: Unsupported console"); - break; - } - return; -} -#endif diff --git a/hw/xfree86/os-support/bsd/memrange.h b/hw/xfree86/os-support/bsd/memrange.h deleted file mode 100644 index 49d5627f1..000000000 --- a/hw/xfree86/os-support/bsd/memrange.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Memory range attribute operations, performed on /dev/mem - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _MEMRANGE_H -#define _MEMRANGE_H - -/* Memory range attributes */ -#define MDF_UNCACHEABLE (1<<0) /* region not cached */ -#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine" - * action */ -#define MDF_WRITETHROUGH (1<<2) /* write-through cached */ -#define MDF_WRITEBACK (1<<3) /* write-back cached */ -#define MDF_WRITEPROTECT (1<<4) /* read-only region */ -#define MDF_ATTRMASK (0x00ffffff) - -#define MDF_FIXBASE (1<<24) /* fixed base */ -#define MDF_FIXLEN (1<<25) /* fixed length */ -#define MDF_FIRMWARE (1<<26) /* set by firmware (XXX not useful?) */ -#define MDF_ACTIVE (1<<27) /* currently active */ -#define MDF_BOGUS (1<<28) /* we don't like it */ -#define MDF_FIXACTIVE (1<<29) /* can't be turned off */ -#define MDF_BUSY (1<<30) /* range is in use */ - -struct mem_range_desc { - u_int64_t mr_base; - u_int64_t mr_len; - int mr_flags; - char mr_owner[8]; -}; - -struct mem_range_op { - struct mem_range_desc *mo_desc; - int mo_arg[2]; -#define MEMRANGE_SET_UPDATE 0 -#define MEMRANGE_SET_REMOVE 1 - /* XXX want a flag that says "set and undo when I exit" */ -}; - -#define MEMRANGE_GET _IOWR('m', 50, struct mem_range_op) -#define MEMRANGE_SET _IOW('m', 51, struct mem_range_op) - -#ifdef _KERNEL - -struct mem_range_softc; -struct mem_range_ops { - void (*init) __P((struct mem_range_softc * sc)); - int (*set) - __P((struct mem_range_softc * sc, struct mem_range_desc * mrd, - int *arg)); - void (*initAP) __P((struct mem_range_softc * sc)); -}; - -struct mem_range_softc { - struct mem_range_ops *mr_op; - int mr_cap; - int mr_ndesc; - struct mem_range_desc *mr_desc; -}; - -extern struct mem_range_softc mem_range_softc; - -extern int mem_range_attr_get __P((struct mem_range_desc * mrd, int *arg)); -extern int mem_range_attr_set __P((struct mem_range_desc * mrd, int *arg)); -extern void mem_range_AP_init __P((void)); -#endif - -#endif diff --git a/hw/xfree86/os-support/bsd/ppc_video.c b/hw/xfree86/os-support/bsd/ppc_video.c deleted file mode 100644 index 5a58da19d..000000000 --- a/hw/xfree86/os-support/bsd/ppc_video.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 1992 by Rich Murphey - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR - * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" - -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -#include "bus/Pci.h" - -/***************************************************************************/ -/* Video Memory Mapping section */ -/***************************************************************************/ - -#ifdef __OpenBSD__ -#define DEV_MEM "/dev/xf86" -#endif - -Bool xf86EnableIO(void); -void xf86DisableIO(void); - -void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - pVidMem->initialised = TRUE; - xf86EnableIO(); -} - -volatile unsigned char *ioBase = MAP_FAILED; - -Bool -xf86EnableIO() -{ - int fd = xf86Info.consoleFd; - - xf86MsgVerb(X_WARNING, 3, "xf86EnableIO %d\n", fd); - if (ioBase == MAP_FAILED) { - ioBase = mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, - 0xf2000000); - xf86MsgVerb(X_INFO, 3, "xf86EnableIO: %08x\n", ioBase); - if (ioBase == MAP_FAILED) { - xf86MsgVerb(X_WARNING, 3, "Can't map IO space!\n"); - return FALSE; - } - } - return TRUE; -} - -void -xf86DisableIO() -{ - - if (ioBase != MAP_FAILED) { - munmap(__UNVOLATILE(ioBase), 0x10000); - ioBase = MAP_FAILED; - } -} diff --git a/hw/xfree86/os-support/bsd/sparc64_video.c b/hw/xfree86/os-support/bsd/sparc64_video.c deleted file mode 100644 index 3f8cccd19..000000000 --- a/hw/xfree86/os-support/bsd/sparc64_video.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 1992 by Rich Murphey - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Rich Murphey and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Rich Murphey and - * David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO - * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR - * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" - -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -/***************************************************************************/ -/* Video Memory Mapping section */ -/***************************************************************************/ - -void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - pVidMem->initialised = TRUE; -} diff --git a/hw/xfree86/os-support/bus/Pci.c b/hw/xfree86/os-support/bus/Pci.c deleted file mode 100644 index 52d142fbf..000000000 --- a/hw/xfree86/os-support/bus/Pci.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 1998 by Concurrent Computer Corporation - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of Concurrent Computer - * Corporation not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. Concurrent Computer Corporation makes no representations - * about the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. - * - * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - * Copyright 1998 by Metro Link Incorporated - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of Metro Link - * Incorporated not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. Metro Link Incorporated makes no representations - * about the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. - * - * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - * This software is derived from the original XFree86 PCI code - * which includes the following copyright notices as well: - * - * Copyright 1995 by Robin Cutshaw - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of the above listed copyright holder(s) - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. The above listed - * copyright holder(s) make(s) no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * This code is also based heavily on the code in FreeBSD-current, which was - * written by Wolfgang Stanglmeier, and contains the following copyright: - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -/* - * Copyright (c) 1999-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "Pci.h" - -Bool -xf86scanpci(void) -{ - Bool success = FALSE; - - success = (pci_system_init() == 0); - - /* choose correct platform/OS specific PCI init routine */ - osPciInit(); - - return success; -} diff --git a/hw/xfree86/os-support/bus/Pci.h b/hw/xfree86/os-support/bus/Pci.h deleted file mode 100644 index 1921e0282..000000000 --- a/hw/xfree86/os-support/bus/Pci.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 1998 by Concurrent Computer Corporation - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of Concurrent Computer - * Corporation not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. Concurrent Computer Corporation makes no representations - * about the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. - * - * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - * Copyright 1998 by Metro Link Incorporated - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of Metro Link - * Incorporated not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. Metro Link Incorporated makes no representations - * about the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. - * - * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - * This file is derived in part from the original xf86_PCI.h that included - * following copyright message: - * - * Copyright 1995 by Robin Cutshaw - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of the above listed copyright holder(s) - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. The above listed - * copyright holder(s) make(s) no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * Copyright (c) 1999-2003 by The XFree86 Project, 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). - */ - -/* - * This file has the private Pci definitions. The public ones are imported - * from xf86Pci.h. Drivers should not use this file. - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _PCI_H -#define _PCI_H 1 - -#include "xf86Pci.h" - -/* - * Global Definitions - */ -#if (defined(__alpha__) || defined(__ia64__)) && defined (__linux__) -#define PCI_DOM_MASK 0x01fful -#else -#define PCI_DOM_MASK 0x0ffu -#endif - -#ifndef PCI_DOM_MASK -#define PCI_DOM_MASK 0x0ffu -#endif -#define PCI_DOMBUS_MASK (((PCI_DOM_MASK) << 8) | 0x0ffu) - -/* - * "b" contains an optional domain number. - */ -#define PCI_MAKE_TAG(b,d,f) ((((b) & (PCI_DOMBUS_MASK)) << 16) | \ - (((d) & 0x00001fu) << 11) | \ - (((f) & 0x000007u) << 8)) - -#define PCI_MAKE_BUS(d,b) ((((d) & (PCI_DOM_MASK)) << 8) | ((b) & 0xffu)) - -#define PCI_DOM_FROM_BUS(bus) (((bus) >> 8) & (PCI_DOM_MASK)) -#define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu) -#define PCI_TAG_NO_DOMAIN(tag) ((tag) & 0x00ffff00u) - -#if defined(__linux__) -#define osPciInit(x) do {} while (0) -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ - defined(__OpenBSD__) || defined(__NetBSD__) || \ - defined(__DragonFly__) || defined(__sun) || defined(__GNU__) -extern void osPciInit(void); -#else -#error No PCI support available for this architecture/OS combination -#endif - -#endif /* _PCI_H */ diff --git a/hw/xfree86/os-support/bus/Sbus.c b/hw/xfree86/os-support/bus/Sbus.c deleted file mode 100644 index cb14368f8..000000000 --- a/hw/xfree86/os-support/bus/Sbus.c +++ /dev/null @@ -1,723 +0,0 @@ -/* - * SBUS and OpenPROM access functions. - * - * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * JAKUB JELINEK 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. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#ifdef __sun -#include -#endif -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -#include "xf86sbusBus.h" -#include "xf86Sbus.h" - -int promRootNode; - -static int promFd = -1; -static int promCurrentNode; -static int promOpenCount = 0; -static int promP1275 = -1; - -#define MAX_PROP 128 -#define MAX_VAL (4096-128-4) -static struct openpromio *promOpio; - -sbusDevicePtr *xf86SbusInfo = NULL; - -struct sbus_devtable sbusDeviceTable[] = { - {SBUS_DEVICE_BW2, FBTYPE_SUN2BW, "bwtwo", "sunbw2", - "Sun Monochrome (bwtwo)"}, - {SBUS_DEVICE_CG2, FBTYPE_SUN2COLOR, "cgtwo", NULL, "Sun Color2 (cgtwo)"}, - {SBUS_DEVICE_CG3, FBTYPE_SUN3COLOR, "cgthree", "suncg3", - "Sun Color3 (cgthree)"}, - {SBUS_DEVICE_CG4, FBTYPE_SUN4COLOR, "cgfour", NULL, "Sun Color4 (cgfour)"}, - {SBUS_DEVICE_CG6, FBTYPE_SUNFAST_COLOR, "cgsix", "suncg6", "Sun GX"}, - {SBUS_DEVICE_CG8, FBTYPE_MEMCOLOR, "cgeight", NULL, "Sun CG8/RasterOps"}, - {SBUS_DEVICE_CG12, FBTYPE_SUNGP3, "cgtwelve", NULL, "Sun GS (cgtwelve)"}, - {SBUS_DEVICE_CG14, FBTYPE_MDICOLOR, "cgfourteen", "suncg14", "Sun SX"}, - {SBUS_DEVICE_GT, FBTYPE_SUNGT, "gt", NULL, "Sun Graphics Tower"}, - {SBUS_DEVICE_MGX, -1, "mgx", NULL, "Quantum 3D MGXplus"}, - {SBUS_DEVICE_LEO, FBTYPE_SUNLEO, "leo", "sunleo", "Sun ZX or Turbo ZX"}, - {SBUS_DEVICE_TCX, FBTYPE_TCXCOLOR, "tcx", "suntcx", "Sun TCX"}, - {SBUS_DEVICE_FFB, FBTYPE_CREATOR, "ffb", "sunffb", "Sun FFB"}, - {SBUS_DEVICE_FFB, FBTYPE_CREATOR, "afb", "sunffb", "Sun Elite3D"}, - {0, 0, NULL} -}; - -int -promGetSibling(int node) -{ - promOpio->oprom_size = sizeof(int); - - if (node == -1) - return 0; - *(int *) promOpio->oprom_array = node; - if (ioctl(promFd, OPROMNEXT, promOpio) < 0) - return 0; - promCurrentNode = *(int *) promOpio->oprom_array; - return *(int *) promOpio->oprom_array; -} - -int -promGetChild(int node) -{ - promOpio->oprom_size = sizeof(int); - - if (!node || node == -1) - return 0; - *(int *) promOpio->oprom_array = node; - if (ioctl(promFd, OPROMCHILD, promOpio) < 0) - return 0; - promCurrentNode = *(int *) promOpio->oprom_array; - return *(int *) promOpio->oprom_array; -} - -char * -promGetProperty(const char *prop, int *lenp) -{ - promOpio->oprom_size = MAX_VAL; - - strcpy(promOpio->oprom_array, prop); - if (ioctl(promFd, OPROMGETPROP, promOpio) < 0) - return 0; - if (lenp) - *lenp = promOpio->oprom_size; - return promOpio->oprom_array; -} - -int -promGetBool(const char *prop) -{ - promOpio->oprom_size = 0; - - *(int *) promOpio->oprom_array = 0; - for (;;) { - promOpio->oprom_size = MAX_PROP; - if (ioctl(promFd, OPROMNXTPROP, promOpio) < 0) - return 0; - if (!promOpio->oprom_size) - return 0; - if (!strcmp(promOpio->oprom_array, prop)) - return 1; - } -} - -#define PROM_NODE_SIBLING 0x01 -#define PROM_NODE_PREF 0x02 -#define PROM_NODE_SBUS 0x04 -#define PROM_NODE_EBUS 0x08 -#define PROM_NODE_PCI 0x10 - -static int -promSetNode(sbusPromNodePtr pnode) -{ - int node; - - if (!pnode->node || pnode->node == -1) - return -1; - if (pnode->cookie[0] & PROM_NODE_SIBLING) - node = promGetSibling(pnode->cookie[1]); - else - node = promGetChild(pnode->cookie[1]); - if (pnode->node != node) - return -1; - return 0; -} - -static void -promIsP1275(void) -{ -#ifdef __linux__ - FILE *f; - char buffer[1024]; - - if (promP1275 != -1) - return; - promP1275 = 0; - f = fopen("/proc/cpuinfo", "r"); - if (!f) - return; - while (fgets(buffer, 1024, f) != NULL) - if (!strncmp(buffer, "type", 4) && strstr(buffer, "sun4u")) { - promP1275 = 1; - break; - } - fclose(f); -#elif defined(__sun) - struct utsname buffer; - - if ((uname(&buffer) >= 0) && !strcmp(buffer.machine, "sun4u")) - promP1275 = TRUE; - else - promP1275 = FALSE; -#elif defined(__FreeBSD__) - promP1275 = TRUE; -#else -#error Missing promIsP1275() function for this OS -#endif -} - -void -sparcPromClose(void) -{ - if (promOpenCount > 1) { - promOpenCount--; - return; - } - if (promFd != -1) { - close(promFd); - promFd = -1; - } - free(promOpio); - promOpio = NULL; - promOpenCount = 0; -} - -int -sparcPromInit(void) -{ - if (promOpenCount) { - promOpenCount++; - return 0; - } - promFd = open("/dev/openprom", O_RDONLY, 0); - if (promFd == -1) - return -1; - promOpio = (struct openpromio *) malloc(4096); - if (!promOpio) { - sparcPromClose(); - return -1; - } - promRootNode = promGetSibling(0); - if (!promRootNode) { - sparcPromClose(); - return -1; - } - promIsP1275(); - promOpenCount++; - - return 0; -} - -char * -sparcPromGetProperty(sbusPromNodePtr pnode, const char *prop, int *lenp) -{ - if (promSetNode(pnode)) - return NULL; - return promGetProperty(prop, lenp); -} - -int -sparcPromGetBool(sbusPromNodePtr pnode, const char *prop) -{ - if (promSetNode(pnode)) - return 0; - return promGetBool(prop); -} - -static char * -promWalkGetDriverName(int node, int oldnode) -{ - int nextnode; - int len; - char *prop; - int devId, i; - - prop = promGetProperty("device_type", &len); - if (prop && (len > 0)) - do { - if (!strcmp(prop, "display")) { - prop = promGetProperty("name", &len); - if (!prop || len <= 0) - break; - while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',') - prop++; - for (i = 0; sbusDeviceTable[i].devId; i++) - if (!strcmp(prop, sbusDeviceTable[i].promName)) - break; - devId = sbusDeviceTable[i].devId; - if (!devId) - break; - if (sbusDeviceTable[i].driverName) - return sbusDeviceTable[i].driverName; - } - } while (0); - - nextnode = promGetChild(node); - if (nextnode) { - char *name; - - name = promWalkGetDriverName(nextnode, node); - if (name) - return name; - } - - nextnode = promGetSibling(node); - if (nextnode) - return promWalkGetDriverName(nextnode, node); - return NULL; -} - -char * -sparcDriverName(void) -{ - char *name; - - if (sparcPromInit() < 0) - return NULL; - promGetSibling(0); - name = promWalkGetDriverName(promRootNode, 0); - sparcPromClose(); - return name; -} - -static void -promWalkAssignNodes(int node, int oldnode, int flags, - sbusDevicePtr * devicePtrs) -{ - int nextnode; - int len, sbus = flags & PROM_NODE_SBUS; - char *prop; - int devId, i, j; - sbusPromNode pNode, pNode2; - - prop = promGetProperty("device_type", &len); - if (prop && (len > 0)) - do { - if (!strcmp(prop, "display")) { - prop = promGetProperty("name", &len); - if (!prop || len <= 0) - break; - while ((*prop >= 'A' && *prop <= 'Z') || *prop == ',') - prop++; - for (i = 0; sbusDeviceTable[i].devId; i++) - if (!strcmp(prop, sbusDeviceTable[i].promName)) - break; - devId = sbusDeviceTable[i].devId; - if (!devId) - break; - if (!sbus) { - if (devId == SBUS_DEVICE_FFB) { - /* - * All /SUNW,ffb outside of SBUS tree come before all - * /SUNW,afb outside of SBUS tree in Linux. - */ - if (!strcmp(prop, "afb")) - flags |= PROM_NODE_PREF; - } - else if (devId != SBUS_DEVICE_CG14) - break; - } - for (i = 0; i < 32; i++) { - if (!devicePtrs[i] || devicePtrs[i]->devId != devId) - continue; - if (devicePtrs[i]->node.node) { - if ((devicePtrs[i]->node. - cookie[0] & ~PROM_NODE_SIBLING) <= - (flags & ~PROM_NODE_SIBLING)) - continue; - for (j = i + 1, pNode = devicePtrs[i]->node; j < 32; - j++) { - if (!devicePtrs[j] || devicePtrs[j]->devId != devId) - continue; - pNode2 = devicePtrs[j]->node; - devicePtrs[j]->node = pNode; - pNode = pNode2; - } - } - devicePtrs[i]->node.node = node; - devicePtrs[i]->node.cookie[0] = flags; - devicePtrs[i]->node.cookie[1] = oldnode; - break; - } - break; - } - } while (0); - - prop = promGetProperty("name", &len); - if (prop && len > 0) { - if (!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) - sbus = PROM_NODE_SBUS; - } - - nextnode = promGetChild(node); - if (nextnode) - promWalkAssignNodes(nextnode, node, sbus, devicePtrs); - - nextnode = promGetSibling(node); - if (nextnode) - promWalkAssignNodes(nextnode, node, PROM_NODE_SIBLING | sbus, - devicePtrs); -} - -void -sparcPromAssignNodes(void) -{ - sbusDevicePtr psdp, *psdpp; - int n, holes = 0, i, j; - FILE *f; - sbusDevicePtr devicePtrs[32]; - - memset(devicePtrs, 0, sizeof(devicePtrs)); - for (psdpp = xf86SbusInfo, n = 0; (psdp = *psdpp); psdpp++, n++) { - if (psdp->fbNum != n) - holes = 1; - devicePtrs[psdp->fbNum] = psdp; - } - if (holes && (f = fopen("/proc/fb", "r")) != NULL) { - /* We could not open one of fb devices, check /proc/fb to see what - * were the types of the cards missed. */ - char buffer[64]; - int fbNum, devId; - static struct { - int devId; - char *prefix; - } procFbPrefixes[] = { - {SBUS_DEVICE_BW2, "BWtwo"}, - {SBUS_DEVICE_CG14, "CGfourteen"}, - {SBUS_DEVICE_CG6, "CGsix"}, - {SBUS_DEVICE_CG3, "CGthree"}, - {SBUS_DEVICE_FFB, "Creator"}, - {SBUS_DEVICE_FFB, "Elite 3D"}, - {SBUS_DEVICE_LEO, "Leo"}, - {SBUS_DEVICE_TCX, "TCX"}, - {0, NULL}, - }; - - while (fscanf(f, "%d %63s\n", &fbNum, buffer) == 2) { - for (i = 0; procFbPrefixes[i].devId; i++) - if (!strncmp(procFbPrefixes[i].prefix, buffer, - strlen(procFbPrefixes[i].prefix))) - break; - devId = procFbPrefixes[i].devId; - if (!devId) - continue; - if (devicePtrs[fbNum]) { - if (devicePtrs[fbNum]->devId != devId) - xf86ErrorF("Inconsistent /proc/fb with FBIOGATTR\n"); - } - else if (!devicePtrs[fbNum]) { - devicePtrs[fbNum] = psdp = xnfcalloc(sizeof(sbusDevice), 1); - psdp->devId = devId; - psdp->fbNum = fbNum; - psdp->fd = -2; - } - } - fclose(f); - } - promGetSibling(0); - promWalkAssignNodes(promRootNode, 0, PROM_NODE_PREF, devicePtrs); - for (i = 0, j = 0; i < 32; i++) - if (devicePtrs[i] && devicePtrs[i]->fbNum == -1) - j++; - xf86SbusInfo = xnfreallocarray(xf86SbusInfo, n + j + 1, sizeof(psdp)); - for (i = 0, psdpp = xf86SbusInfo; i < 32; i++) - if (devicePtrs[i]) { - if (devicePtrs[i]->fbNum == -1) { - memmove(psdpp + 1, psdpp, sizeof(psdpp) * (n + 1)); - *psdpp = devicePtrs[i]; - } - else - n--; - } -} - -static char * -promGetReg(int type) -{ - char *prop; - int len; - static char regstr[40]; - - regstr[0] = 0; - prop = promGetProperty("reg", &len); - if (prop && len >= 4) { - unsigned int *reg = (unsigned int *) prop; - - if (!promP1275 || (type == PROM_NODE_SBUS) || (type == PROM_NODE_EBUS)) - snprintf(regstr, sizeof(regstr), "@%x,%x", reg[0], reg[1]); - else if (type == PROM_NODE_PCI) { - if ((reg[0] >> 8) & 7) - snprintf(regstr, sizeof(regstr), "@%x,%x", - (reg[0] >> 11) & 0x1f, (reg[0] >> 8) & 7); - else - snprintf(regstr, sizeof(regstr), "@%x", (reg[0] >> 11) & 0x1f); - } - else if (len == 4) - snprintf(regstr, sizeof(regstr), "@%x", reg[0]); - else { - unsigned int regs[2]; - - /* Things get more complicated on UPA. If upa-portid exists, - then address is @upa-portid,second-int-in-reg, otherwise - it is @first-int-in-reg/16,second-int-in-reg (well, probably - upa-portid always exists, but just to be safe). */ - memcpy(regs, reg, sizeof(regs)); - prop = promGetProperty("upa-portid", &len); - if (prop && len == 4) { - reg = (unsigned int *) prop; - snprintf(regstr, sizeof(regstr), "@%x,%x", reg[0], regs[1]); - } - else - snprintf(regstr, sizeof(regstr), "@%x,%x", regs[0] >> 4, - regs[1]); - } - } - return regstr; -} - -static int -promWalkNode2Pathname(char *path, int parent, int node, int searchNode, - int type) -{ - int nextnode; - int len, ntype = type; - char *prop, *p; - - prop = promGetProperty("name", &len); - *path = '/'; - if (!prop || len <= 0) - return 0; - if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type) - ntype = PROM_NODE_SBUS; - else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI) - ntype = PROM_NODE_EBUS; - else if (!strcmp(prop, "pci") && !type) - ntype = PROM_NODE_PCI; - strcpy(path + 1, prop); - p = promGetReg(type); - if (*p) - strcat(path, p); - if (node == searchNode) - return 1; - nextnode = promGetChild(node); - if (nextnode && - promWalkNode2Pathname(strchr(path, 0), node, nextnode, searchNode, - ntype)) - return 1; - nextnode = promGetSibling(node); - if (nextnode && - promWalkNode2Pathname(path, parent, nextnode, searchNode, type)) - return 1; - return 0; -} - -char * -sparcPromNode2Pathname(sbusPromNodePtr pnode) -{ - char *ret; - - if (!pnode->node) - return NULL; - ret = malloc(4096); - if (!ret) - return NULL; - if (promWalkNode2Pathname - (ret, promRootNode, promGetChild(promRootNode), pnode->node, 0)) - return ret; - free(ret); - return NULL; -} - -static int -promWalkPathname2Node(char *name, char *regstr, int parent, int type) -{ - int len, node, ret; - char *prop, *p; - - for (;;) { - prop = promGetProperty("name", &len); - if (!prop || len <= 0) - return 0; - if ((!strcmp(prop, "sbus") || !strcmp(prop, "sbi")) && !type) - type = PROM_NODE_SBUS; - else if (!strcmp(prop, "ebus") && type == PROM_NODE_PCI) - type = PROM_NODE_EBUS; - else if (!strcmp(prop, "pci") && !type) - type = PROM_NODE_PCI; - for (node = promGetChild(parent); node; node = promGetSibling(node)) { - prop = promGetProperty("name", &len); - if (!prop || len <= 0) - continue; - if (*name && strcmp(name, prop)) - continue; - if (*regstr) { - p = promGetReg(type); - if (!*p || strcmp(p + 1, regstr)) - continue; - } - break; - } - if (!node) { - for (node = promGetChild(parent); node; node = promGetSibling(node)) { - ret = promWalkPathname2Node(name, regstr, node, type); - if (ret) - return ret; - } - return 0; - } - name = strchr(regstr, 0) + 1; - if (!*name) - return node; - p = strchr(name, '/'); - if (p) - *p = 0; - else - p = strchr(name, 0); - regstr = strchr(name, '@'); - if (regstr) - *regstr++ = 0; - else - regstr = p; - if (name == regstr) - return 0; - parent = node; - } -} - -int -sparcPromPathname2Node(const char *pathName) -{ - int i; - char *name, *regstr, *p; - - i = strlen(pathName); - name = malloc(i + 2); - if (!name) - return 0; - strcpy(name, pathName); - name[i + 1] = 0; - if (name[0] != '/') { - free(name); - return 0; - } - p = strchr(name + 1, '/'); - if (p) - *p = 0; - else - p = strchr(name, 0); - regstr = strchr(name, '@'); - if (regstr) - *regstr++ = 0; - else - regstr = p; - if (name + 1 == regstr) { - free(name); - return 0; - } - promGetSibling(0); - i = promWalkPathname2Node(name + 1, regstr, promRootNode, 0); - free(name); - return i; -} - -void * -xf86MapSbusMem(sbusDevicePtr psdp, unsigned long offset, unsigned long size) -{ - void *ret; - unsigned long pagemask = getpagesize() - 1; - unsigned long off = offset & ~pagemask; - unsigned long len = ((offset + size + pagemask) & ~pagemask) - off; - - if (psdp->fd == -1) { - psdp->fd = open(psdp->device, O_RDWR); - if (psdp->fd == -1) - return NULL; - } - else if (psdp->fd < 0) - return NULL; - - ret = (void *) mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, - psdp->fd, off); - if (ret == (void *) -1) { - ret = (void *) mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, - psdp->fd, off); - } - if (ret == (void *) -1) - return NULL; - - return (char *) ret + (offset - off); -} - -void -xf86UnmapSbusMem(sbusDevicePtr psdp, void *addr, unsigned long size) -{ - unsigned long mask = getpagesize() - 1; - unsigned long base = (unsigned long) addr & ~mask; - unsigned long len = (((unsigned long) addr + size + mask) & ~mask) - base; - - munmap((void *) base, len); -} - -/* Tell OS that we are driving the HW cursor ourselves. */ -void -xf86SbusHideOsHwCursor(sbusDevicePtr psdp) -{ - struct fbcursor fbcursor; - unsigned char zeros[8]; - - memset(&fbcursor, 0, sizeof(fbcursor)); - memset(&zeros, 0, sizeof(zeros)); - fbcursor.cmap.count = 2; - fbcursor.cmap.red = zeros; - fbcursor.cmap.green = zeros; - fbcursor.cmap.blue = zeros; - fbcursor.image = (char *) zeros; - fbcursor.mask = (char *) zeros; - fbcursor.size.x = 32; - fbcursor.size.y = 1; - fbcursor.set = FB_CUR_SETALL; - ioctl(psdp->fd, FBIOSCURSOR, &fbcursor); -} - -/* Set HW cursor colormap. */ -void -xf86SbusSetOsHwCursorCmap(sbusDevicePtr psdp, int bg, int fg) -{ - struct fbcursor fbcursor; - unsigned char red[2], green[2], blue[2]; - - memset(&fbcursor, 0, sizeof(fbcursor)); - red[0] = bg >> 16; - green[0] = bg >> 8; - blue[0] = bg; - red[1] = fg >> 16; - green[1] = fg >> 8; - blue[1] = fg; - fbcursor.cmap.count = 2; - fbcursor.cmap.red = red; - fbcursor.cmap.green = green; - fbcursor.cmap.blue = blue; - fbcursor.set = FB_CUR_SETCMAP; - ioctl(psdp->fd, FBIOSCURSOR, &fbcursor); -} diff --git a/hw/xfree86/os-support/bus/bsd_pci.c b/hw/xfree86/os-support/bus/bsd_pci.c deleted file mode 100644 index 7a5dbbb01..000000000 --- a/hw/xfree86/os-support/bus/bsd_pci.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright © 2007 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - * - * Authors: - * Eric Anholt - * - */ - -/** - * @file bsd_pci.c - * - * This is a trivial implementation of the remaining PCI support hooks in the - * X Server that is unaware of domains. - * - * Most of even this should go away once drivers are converted and the - * old interfaces are confirmed to all be obsolete. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "compiler.h" -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "Pci.h" - -#include "pciaccess.h" - -void -osPciInit(void) -{ - xf86InitVidMem(); -} diff --git a/hw/xfree86/os-support/bus/nobus.c b/hw/xfree86/os-support/bus/nobus.c deleted file mode 100644 index 4872c5be8..000000000 --- a/hw/xfree86/os-support/bus/nobus.c +++ /dev/null @@ -1,8 +0,0 @@ -void -__noop_to_appease_ar__(void); - -void -__noop_to_appease_ar__(void) -{ - return; -} diff --git a/hw/xfree86/os-support/bus/xf86Pci.h b/hw/xfree86/os-support/bus/xf86Pci.h deleted file mode 100644 index 4dbe08bd7..000000000 --- a/hw/xfree86/os-support/bus/xf86Pci.h +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright 1998 by Concurrent Computer Corporation - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of Concurrent Computer - * Corporation not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. Concurrent Computer Corporation makes no representations - * about the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. - * - * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - * Copyright 1998 by Metro Link Incorporated - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of Metro Link - * Incorporated not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. Metro Link Incorporated makes no representations - * about the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. - * - * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, - * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, - * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - * This file is derived in part from the original xf86_PCI.h that included - * following copyright message: - * - * Copyright 1995 by Robin Cutshaw - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of the above listed copyright holder(s) - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. The above listed - * copyright holder(s) make(s) no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* - * Copyright (c) 1999-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains just the public interface to the PCI code. - * Drivers should use this file rather than Pci.h. - */ - -#ifndef _XF86PCI_H -#define _XF86PCI_H 1 -#include -#include -#include "misc.h" -#include - -/* - * PCI cfg space definitions (e.g. stuff right out of the PCI spec) - */ - -/* Device identification register */ -#define PCI_ID_REG 0x00 - -/* Command and status register */ -#define PCI_CMD_STAT_REG 0x04 -#define PCI_CMD_BASE_REG 0x10 -#define PCI_CMD_BIOS_REG 0x30 -#define PCI_CMD_MASK 0xffff -#define PCI_CMD_IO_ENABLE 0x01 -#define PCI_CMD_MEM_ENABLE 0x02 -#define PCI_CMD_MASTER_ENABLE 0x04 -#define PCI_CMD_SPECIAL_ENABLE 0x08 -#define PCI_CMD_INVALIDATE_ENABLE 0x10 -#define PCI_CMD_PALETTE_ENABLE 0x20 -#define PCI_CMD_PARITY_ENABLE 0x40 -#define PCI_CMD_STEPPING_ENABLE 0x80 -#define PCI_CMD_SERR_ENABLE 0x100 -#define PCI_CMD_BACKTOBACK_ENABLE 0x200 -#define PCI_CMD_BIOS_ENABLE 0x01 - -/* base class */ -#define PCI_CLASS_REG 0x08 -#define PCI_CLASS_MASK 0xff000000 -#define PCI_CLASS_SHIFT 24 -#define PCI_CLASS_EXTRACT(x) \ - (((x) & PCI_CLASS_MASK) >> PCI_CLASS_SHIFT) - -/* base class values */ -#define PCI_CLASS_PREHISTORIC 0x00 -#define PCI_CLASS_MASS_STORAGE 0x01 -#define PCI_CLASS_NETWORK 0x02 -#define PCI_CLASS_DISPLAY 0x03 -#define PCI_CLASS_MULTIMEDIA 0x04 -#define PCI_CLASS_MEMORY 0x05 -#define PCI_CLASS_BRIDGE 0x06 -#define PCI_CLASS_COMMUNICATIONS 0x07 -#define PCI_CLASS_SYSPERIPH 0x08 -#define PCI_CLASS_INPUT 0x09 -#define PCI_CLASS_DOCKING 0x0a -#define PCI_CLASS_PROCESSOR 0x0b -#define PCI_CLASS_SERIALBUS 0x0c -#define PCI_CLASS_WIRELESS 0x0d -#define PCI_CLASS_I2O 0x0e -#define PCI_CLASS_SATELLITE 0x0f -#define PCI_CLASS_CRYPT 0x10 -#define PCI_CLASS_DATA_ACQUISTION 0x11 -#define PCI_CLASS_UNDEFINED 0xff - -/* sub class */ -#define PCI_SUBCLASS_MASK 0x00ff0000 -#define PCI_SUBCLASS_SHIFT 16 -#define PCI_SUBCLASS_EXTRACT(x) \ - (((x) & PCI_SUBCLASS_MASK) >> PCI_SUBCLASS_SHIFT) - -/* Sub class values */ -/* 0x00 prehistoric subclasses */ -#define PCI_SUBCLASS_PREHISTORIC_MISC 0x00 -#define PCI_SUBCLASS_PREHISTORIC_VGA 0x01 - -/* 0x03 display subclasses */ -#define PCI_SUBCLASS_DISPLAY_VGA 0x00 -#define PCI_SUBCLASS_DISPLAY_XGA 0x01 -#define PCI_SUBCLASS_DISPLAY_MISC 0x80 - -/* 0x04 multimedia subclasses */ -#define PCI_SUBCLASS_MULTIMEDIA_VIDEO 0x00 -#define PCI_SUBCLASS_MULTIMEDIA_AUDIO 0x01 -#define PCI_SUBCLASS_MULTIMEDIA_MISC 0x80 - -/* 0x06 bridge subclasses */ -#define PCI_SUBCLASS_BRIDGE_HOST 0x00 -#define PCI_SUBCLASS_BRIDGE_ISA 0x01 -#define PCI_SUBCLASS_BRIDGE_EISA 0x02 -#define PCI_SUBCLASS_BRIDGE_MC 0x03 -#define PCI_SUBCLASS_BRIDGE_PCI 0x04 -#define PCI_SUBCLASS_BRIDGE_PCMCIA 0x05 -#define PCI_SUBCLASS_BRIDGE_NUBUS 0x06 -#define PCI_SUBCLASS_BRIDGE_CARDBUS 0x07 -#define PCI_SUBCLASS_BRIDGE_RACEWAY 0x08 -#define PCI_SUBCLASS_BRIDGE_MISC 0x80 -#define PCI_IF_BRIDGE_PCI_SUBTRACTIVE 0x01 - -/* 0x0b processor subclasses */ -#define PCI_SUBCLASS_PROCESSOR_386 0x00 -#define PCI_SUBCLASS_PROCESSOR_486 0x01 -#define PCI_SUBCLASS_PROCESSOR_PENTIUM 0x02 -#define PCI_SUBCLASS_PROCESSOR_ALPHA 0x10 -#define PCI_SUBCLASS_PROCESSOR_POWERPC 0x20 -#define PCI_SUBCLASS_PROCESSOR_MIPS 0x30 -#define PCI_SUBCLASS_PROCESSOR_COPROC 0x40 - -/* PCI-PCI bridge mapping registers */ -#define PCI_PCI_BRIDGE_BUS_REG 0x18 -#define PCI_SUBORDINATE_BUS_MASK 0x00ff0000 -#define PCI_SECONDARY_BUS_MASK 0x0000ff00 -#define PCI_PRIMARY_BUS_MASK 0x000000ff - -#define PCI_PCI_BRIDGE_IO_REG 0x1c -#define PCI_PCI_BRIDGE_MEM_REG 0x20 -#define PCI_PCI_BRIDGE_PMEM_REG 0x24 - -#define PCI_PCI_BRIDGE_CONTROL_REG 0x3E -#define PCI_PCI_BRIDGE_PARITY_EN 0x01 -#define PCI_PCI_BRIDGE_SERR_EN 0x02 -#define PCI_PCI_BRIDGE_ISA_EN 0x04 -#define PCI_PCI_BRIDGE_VGA_EN 0x08 -#define PCI_PCI_BRIDGE_MASTER_ABORT_EN 0x20 -#define PCI_PCI_BRIDGE_SECONDARY_RESET 0x40 -#define PCI_PCI_BRIDGE_FAST_B2B_EN 0x80 - -/* Subsystem identification register */ -#define PCI_SUBSYSTEM_ID_REG 0x2c - -/* User defined cfg space regs */ -#define PCI_REG_USERCONFIG 0x40 -#define PCI_OPTION_REG 0x40 - -/* - * Typedefs, etc... - */ - -/* Public PCI access functions */ -extern _X_EXPORT Bool xf86scanpci(void); -extern _X_EXPORT char *DRICreatePCIBusID(const struct pci_device *dev); - -#endif /* _XF86PCI_H */ diff --git a/hw/xfree86/os-support/bus/xf86Sbus.h b/hw/xfree86/os-support/bus/xf86Sbus.h deleted file mode 100644 index d702e4e6c..000000000 --- a/hw/xfree86/os-support/bus/xf86Sbus.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Platform specific SBUS and OpenPROM access declarations. - * - * Copyright (C) 2000 Jakub Jelinek (jakub@redhat.com) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * JAKUB JELINEK 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. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _XF86_SBUS_H -#define _XF86_SBUS_H - -#if defined(__linux__) -#include -#include -#include -#include -#elif defined(SVR4) -#include -#include -#elif defined(__OpenBSD__) && defined(__sparc64__) -/* XXX */ -#elif defined(CSRG_BASED) -#if defined(__FreeBSD__) -#include -#include -#include -#else -#include -#endif -#else -#include -#endif - -#ifndef FBTYPE_SUNGP3 -#define FBTYPE_SUNGP3 -1 -#endif -#ifndef FBTYPE_MDICOLOR -#define FBTYPE_MDICOLOR -1 -#endif -#ifndef FBTYPE_SUNLEO -#define FBTYPE_SUNLEO -1 -#endif -#ifndef FBTYPE_TCXCOLOR -#define FBTYPE_TCXCOLOR -1 -#endif -#ifndef FBTYPE_CREATOR -#define FBTYPE_CREATOR -1 -#endif - -#endif /* _XF86_SBUS_H */ diff --git a/hw/xfree86/os-support/hurd/hurd_bell.c b/hw/xfree86/os-support/hurd/hurd_bell.c deleted file mode 100644 index 33965a44c..000000000 --- a/hw/xfree86/os-support/hurd/hurd_bell.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2006 Daniel Stone - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Daniel Stone - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86Priv.h" - -void -xf86OSRingBell(int loudness, int pitch, int duration) -{ - return; -} diff --git a/hw/xfree86/os-support/hurd/hurd_init.c b/hw/xfree86/os-support/hurd/hurd_init.c deleted file mode 100644 index c1b632f19..000000000 --- a/hw/xfree86/os-support/hurd/hurd_init.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 1997,1998 by UCHIYAMA Yasushi - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of UCHIYAMA Yasushi not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. UCHIYAMA Yasushi makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "input.h" -#include "scrnintstr.h" - -#include "compiler.h" - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -#include -#include -#include -#include -#include -#include -#include - -int -xf86ProcessArgument(int argc, char **argv, int i) -{ - return 0; -} - -void -xf86UseMsg() -{ - return; -} - -void -xf86OpenConsole() -{ - if (serverGeneration == 1) { - kern_return_t err; - mach_port_t device; - int fd; - - err = get_privileged_ports(NULL, &device); - if (err) { - errno = err; - FatalError("xf86KbdInit can't get_privileged_ports. (%s)\n", - strerror(errno)); - } - mach_port_deallocate(mach_task_self(), device); - - if ((fd = open("/dev/kbd", O_RDONLY | O_NONBLOCK)) < 0) { - fprintf(stderr, "Cannot open keyboard (%s)\n", strerror(errno)); - exit(1); - } - xf86Info.consoleFd = fd; - } - return; -} - -void -xf86CloseConsole() -{ - close(xf86Info.consoleFd); - return; -} - -void -xf86OSInputThreadInit(void) -{ - return; -} diff --git a/hw/xfree86/os-support/hurd/hurd_video.c b/hw/xfree86/os-support/hurd/hurd_video.c deleted file mode 100644 index ac24f1950..000000000 --- a/hw/xfree86/os-support/hurd/hurd_video.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 1997, 1998 by UCHIYAMA Yasushi - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of UCHIYAMA Yasushi not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. UCHIYAMA Yasushi makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL UCHIYAMA YASUSHI BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include -#include "input.h" -#include "scrnintstr.h" - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -/************************************************************************** - * Video Memory Mapping section - ***************************************************************************/ - -/************************************************************************** - * I/O Permissions section - ***************************************************************************/ - -/* - * Due to conflicts with "compiler.h", don't rely on to declare - * this. - */ -extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on); - -Bool -xf86EnableIO() -{ - if (ioperm(0, 0x10000, 1)) { - FatalError("xf86EnableIO: ioperm() failed (%s)\n", strerror(errno)); - return FALSE; - } -#if 0 - /* - * Trapping disabled for now, as some VBIOSes (mga-g450 notably) use these - * ports, and the int10 wrapper is not emulating them. (Note that it's - * effectively what happens in the Linux variant too, as iopl() is used - * there, making the ioperm() meaningless.) - * - * Reenable this when int10 gets fixed. */ - ioperm(0x40, 4, 0); /* trap access to the timer chip */ - ioperm(0x60, 4, 0); /* trap access to the keyboard controller */ -#endif - return TRUE; -} - -void -xf86DisableIO() -{ - ioperm(0, 0x10000, 0); - return; -} - -void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - pVidMem->initialised = TRUE; -} diff --git a/hw/xfree86/os-support/int10Defines.h b/hw/xfree86/os-support/int10Defines.h deleted file mode 100644 index d942fbdad..000000000 --- a/hw/xfree86/os-support/int10Defines.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2000-2001 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _INT10DEFINES_H_ -#define _INT10DEFINES_H_ 1 - -#ifdef _VM86_LINUX - -#include - -#define CPU_R(type,name,num) \ - (((type *)&(((struct vm86_struct *)REG->cpuRegs)->regs.name))[num]) -#define CPU_RD(name,num) CPU_R(CARD32,name,num) -#define CPU_RW(name,num) CPU_R(CARD16,name,num) -#define CPU_RB(name,num) CPU_R(CARD8,name,num) - -#define X86_EAX CPU_RD(eax,0) -#define X86_EBX CPU_RD(ebx,0) -#define X86_ECX CPU_RD(ecx,0) -#define X86_EDX CPU_RD(edx,0) -#define X86_ESI CPU_RD(esi,0) -#define X86_EDI CPU_RD(edi,0) -#define X86_EBP CPU_RD(ebp,0) -#define X86_EIP CPU_RD(eip,0) -#define X86_ESP CPU_RD(esp,0) -#define X86_EFLAGS CPU_RD(eflags,0) - -#define X86_FLAGS CPU_RW(eflags,0) -#define X86_AX CPU_RW(eax,0) -#define X86_BX CPU_RW(ebx,0) -#define X86_CX CPU_RW(ecx,0) -#define X86_DX CPU_RW(edx,0) -#define X86_SI CPU_RW(esi,0) -#define X86_DI CPU_RW(edi,0) -#define X86_BP CPU_RW(ebp,0) -#define X86_IP CPU_RW(eip,0) -#define X86_SP CPU_RW(esp,0) -#define X86_CS CPU_RW(cs,0) -#define X86_DS CPU_RW(ds,0) -#define X86_ES CPU_RW(es,0) -#define X86_SS CPU_RW(ss,0) -#define X86_FS CPU_RW(fs,0) -#define X86_GS CPU_RW(gs,0) - -#define X86_AL CPU_RB(eax,0) -#define X86_BL CPU_RB(ebx,0) -#define X86_CL CPU_RB(ecx,0) -#define X86_DL CPU_RB(edx,0) - -#define X86_AH CPU_RB(eax,1) -#define X86_BH CPU_RB(ebx,1) -#define X86_CH CPU_RB(ecx,1) -#define X86_DH CPU_RB(edx,1) - -#elif defined(_X86EMU) - -#include "xf86x86emu.h" - -#endif - -#endif diff --git a/hw/xfree86/os-support/linux/int10/linux.c b/hw/xfree86/os-support/linux/int10/linux.c deleted file mode 100644 index 6ca118f25..000000000 --- a/hw/xfree86/os-support/linux/int10/linux.c +++ /dev/null @@ -1,561 +0,0 @@ -/* - * linux specific part of the int10 module - * Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2008 Egbert Eich - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86_OSproc.h" -#include "xf86Pci.h" -#include "compiler.h" -#define _INT10_PRIVATE -#include "xf86int10.h" -#ifdef __sparc__ -#define DEV_MEM "/dev/fb" -#else -#define DEV_MEM "/dev/mem" -#endif -#define ALLOC_ENTRIES(x) ((V_RAM / x) - 1) -#define SHMERRORPTR (void *)(-1) - -#include -#include -#include -#include -#include -#include -#include - -static int counter = 0; -static unsigned long int10Generation = 0; - -static CARD8 read_b(xf86Int10InfoPtr pInt, int addr); -static CARD16 read_w(xf86Int10InfoPtr pInt, int addr); -static CARD32 read_l(xf86Int10InfoPtr pInt, int addr); -static void write_b(xf86Int10InfoPtr pInt, int addr, CARD8 val); -static void write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val); -static void write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val); - -int10MemRec linuxMem = { - read_b, - read_w, - read_l, - write_b, - write_w, - write_l -}; - -typedef struct { - int lowMem; - int highMem; - char *base; - char *base_high; - char *alloc; -} linuxInt10Priv; - -#if defined DoSubModules - -typedef enum { - INT10_NOT_LOADED, - INT10_LOADED_VM86, - INT10_LOADED_X86EMU, - INT10_LOAD_FAILED -} Int10LinuxSubModuleState; - -static Int10LinuxSubModuleState loadedSubModule = INT10_NOT_LOADED; - -static Int10LinuxSubModuleState int10LinuxLoadSubModule(ScrnInfoPtr pScrn); - -#endif /* DoSubModules */ - -static Bool -readLegacy(struct pci_device *dev, unsigned char *buf, int base, int len) -{ - void *map; - - if (pci_device_map_legacy(dev, base, len, 0, &map)) - return FALSE; - - memcpy(buf, map, len); - pci_device_unmap_legacy(dev, man, len); - - return TRUE; -} - -xf86Int10InfoPtr -xf86ExtendedInitInt10(int entityIndex, int Flags) -{ - xf86Int10InfoPtr pInt = NULL; - int screen; - int fd; - static void *vidMem = NULL; - static void *sysMem = NULL; - void *vMem = NULL; - void *options = NULL; - int low_mem; - int high_mem = -1; - char *base = SHMERRORPTR; - char *base_high = SHMERRORPTR; - int pagesize; - memType cs; - legacyVGARec vga; - Bool videoBiosMapped = FALSE; - ScrnInfoPtr pScrn; - if (int10Generation != serverGeneration) { - counter = 0; - int10Generation = serverGeneration; - } - - pScrn = xf86FindScreenForEntity(entityIndex); - screen = pScrn->scrnIndex; - - options = xf86HandleInt10Options(pScrn, entityIndex); - - if (int10skip(options)) { - free(options); - return NULL; - } - -#if defined DoSubModules - if (loadedSubModule == INT10_NOT_LOADED) - loadedSubModule = int10LinuxLoadSubModule(pScrn); - - if (loadedSubModule == INT10_LOAD_FAILED) - return NULL; -#endif - - if ((!vidMem) || (!sysMem)) { - if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { - if (!sysMem) { - DebugF("Mapping sys bios area\n"); - if ((sysMem = mmap((void *) (SYS_BIOS), BIOS_SIZE, - PROT_READ | PROT_EXEC, - MAP_SHARED | MAP_FIXED, fd, SYS_BIOS)) - == MAP_FAILED) { - xf86DrvMsg(screen, X_ERROR, "Cannot map SYS BIOS\n"); - close(fd); - goto error0; - } - } - if (!vidMem) { - DebugF("Mapping VRAM area\n"); - if ((vidMem = mmap((void *) (V_RAM), VRAM_SIZE, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_SHARED | MAP_FIXED, fd, V_RAM)) - == MAP_FAILED) { - xf86DrvMsg(screen, X_ERROR, "Cannot map V_RAM\n"); - close(fd); - goto error0; - } - } - close(fd); - } - else { - xf86DrvMsg(screen, X_ERROR, "Cannot open %s\n", DEV_MEM); - goto error0; - } - } - - pInt = (xf86Int10InfoPtr) xnfcalloc(1, sizeof(xf86Int10InfoRec)); - pInt->pScrn = pScrn; - pInt->entityIndex = entityIndex; - pInt->dev = xf86GetPciInfoForEntity(entityIndex); - - if (!xf86Int10ExecSetup(pInt)) - goto error0; - pInt->mem = &linuxMem; - pagesize = getpagesize(); - pInt->private = (void *) xnfcalloc(1, sizeof(linuxInt10Priv)); - ((linuxInt10Priv *) pInt->private)->alloc = - (void *) xnfcalloc(1, ALLOC_ENTRIES(pagesize)); - - if (!xf86IsEntityPrimary(entityIndex)) { - DebugF("Mapping high memory area\n"); - if ((high_mem = shmget(counter++, HIGH_MEM_SIZE, - IPC_CREAT | SHM_R | SHM_W)) == -1) { - if (errno == ENOSYS) - xf86DrvMsg(screen, X_ERROR, "shmget error\n Please reconfigure" - " your kernel to include System V IPC support\n"); - else - xf86DrvMsg(screen, X_ERROR, - "shmget(highmem) error: %s\n", strerror(errno)); - goto error1; - } - } - else { - DebugF("Mapping Video BIOS\n"); - videoBiosMapped = TRUE; - if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { - if ((vMem = mmap((void *) (V_BIOS), SYS_BIOS - V_BIOS, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_SHARED | MAP_FIXED, fd, V_BIOS)) - == MAP_FAILED) { - xf86DrvMsg(screen, X_ERROR, "Cannot map V_BIOS\n"); - close(fd); - goto error1; - } - close(fd); - } - else - goto error1; - } - ((linuxInt10Priv *) pInt->private)->highMem = high_mem; - - DebugF("Mapping 640kB area\n"); - if ((low_mem = shmget(counter++, V_RAM, IPC_CREAT | SHM_R | SHM_W)) == -1) { - xf86DrvMsg(screen, X_ERROR, - "shmget(lowmem) error: %s\n", strerror(errno)); - goto error2; - } - - ((linuxInt10Priv *) pInt->private)->lowMem = low_mem; - base = shmat(low_mem, 0, 0); - if (base == SHMERRORPTR) { - xf86DrvMsg(screen, X_ERROR, - "shmat(low_mem) error: %s\n", strerror(errno)); - goto error3; - } - ((linuxInt10Priv *) pInt->private)->base = base; - if (high_mem > -1) { - base_high = shmat(high_mem, 0, 0); - if (base_high == SHMERRORPTR) { - xf86DrvMsg(screen, X_ERROR, - "shmat(high_mem) error: %s\n", strerror(errno)); - goto error3; - } - ((linuxInt10Priv *) pInt->private)->base_high = base_high; - } - else - ((linuxInt10Priv *) pInt->private)->base_high = NULL; - - if (!MapCurrentInt10(pInt)) - goto error3; - - Int10Current = pInt; - - DebugF("Mapping int area\n"); - /* note: yes, we really are writing the 0 page here */ - if (!readLegacy(pInt->dev, (unsigned char *) 0, 0, LOW_PAGE_SIZE)) { - xf86DrvMsg(screen, X_ERROR, "Cannot read int vect\n"); - goto error3; - } - DebugF("done\n"); - /* - * Read in everything between V_BIOS and SYS_BIOS as some system BIOSes - * have executable code there. Note that xf86ReadBIOS() can only bring in - * 64K bytes at a time. - */ - if (!videoBiosMapped) { - memset((void *) V_BIOS, 0, SYS_BIOS - V_BIOS); - DebugF("Reading BIOS\n"); - for (cs = V_BIOS; cs < SYS_BIOS; cs += V_BIOS_SIZE) - if (!readLegacy(pInt->dev, (void *)cs, cs, V_BIOS_SIZE)) - xf86DrvMsg(screen, X_WARNING, - "Unable to retrieve all of segment 0x%06lX.\n", - (long) cs); - DebugF("done\n"); - } - - if (xf86IsEntityPrimary(entityIndex) && !(initPrimary(options))) { - if (!xf86int10GetBiosSegment(pInt, NULL)) - goto error3; - - set_return_trap(pInt); -#ifdef _PC - pInt->Flags = Flags & (SET_BIOS_SCRATCH | RESTORE_BIOS_SCRATCH); - if (!(pInt->Flags & SET_BIOS_SCRATCH)) - pInt->Flags &= ~RESTORE_BIOS_SCRATCH; - xf86Int10SaveRestoreBIOSVars(pInt, TRUE); -#endif - } - else { - const BusType location_type = xf86int10GetBiosLocationType(pInt); - - switch (location_type) { - case BUS_PCI:{ - int err; - struct pci_device *rom_device = - xf86GetPciInfoForEntity(pInt->entityIndex); - - pci_device_enable(rom_device); - err = pci_device_read_rom(rom_device, (unsigned char *) (V_BIOS)); - if (err) { - xf86DrvMsg(screen, X_ERROR, "Cannot read V_BIOS (%s)\n", - strerror(err)); - goto error3; - } - - pInt->BIOSseg = V_BIOS >> 4; - break; - } - default: - goto error3; - } - - pInt->num = 0xe6; - reset_int_vect(pInt); - set_return_trap(pInt); - LockLegacyVGA(pInt, &vga); - xf86ExecX86int10(pInt); - UnlockLegacyVGA(pInt, &vga); - } -#ifdef DEBUG - dprint(0xc0000, 0x20); -#endif - - free(options); - return pInt; - - error3: - if (base_high) - shmdt(base_high); - shmdt(base); - shmdt(0); - if (base_high) - shmdt((char *) HIGH_MEM); - shmctl(low_mem, IPC_RMID, NULL); - Int10Current = NULL; - error2: - if (high_mem > -1) - shmctl(high_mem, IPC_RMID, NULL); - error1: - if (vMem) - munmap(vMem, SYS_BIOS - V_BIOS); - free(((linuxInt10Priv *) pInt->private)->alloc); - free(pInt->private); - error0: - free(options); - free(pInt); - return NULL; -} - -Bool -MapCurrentInt10(xf86Int10InfoPtr pInt) -{ - void *addr; - int fd = -1; - - if (Int10Current) { - shmdt(0); - if (((linuxInt10Priv *) Int10Current->private)->highMem >= 0) - shmdt((char *) HIGH_MEM); - else - munmap((void *) V_BIOS, (SYS_BIOS - V_BIOS)); - } - addr = - shmat(((linuxInt10Priv *) pInt->private)->lowMem, (char *) 1, SHM_RND); - if (addr == SHMERRORPTR) { - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "Cannot shmat() low memory\n"); - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, - "shmat(low_mem) error: %s\n", strerror(errno)); - return FALSE; - } - if (mprotect((void *) 0, V_RAM, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, - "Cannot set EXEC bit on low memory: %s\n", strerror(errno)); - - if (((linuxInt10Priv *) pInt->private)->highMem >= 0) { - addr = shmat(((linuxInt10Priv *) pInt->private)->highMem, - (char *) HIGH_MEM, 0); - if (addr == SHMERRORPTR) { - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, - "Cannot shmat() high memory\n"); - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, - "shmget error: %s\n", strerror(errno)); - return FALSE; - } - if (mprotect((void *) HIGH_MEM, HIGH_MEM_SIZE, - PROT_READ | PROT_WRITE | PROT_EXEC) != 0) - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, - "Cannot set EXEC bit on high memory: %s\n", - strerror(errno)); - } - else { - if ((fd = open(DEV_MEM, O_RDWR, 0)) >= 0) { - if (mmap((void *) (V_BIOS), SYS_BIOS - V_BIOS, - PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_SHARED | MAP_FIXED, fd, V_BIOS) - == MAP_FAILED) { - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "Cannot map V_BIOS\n"); - close(fd); - return FALSE; - } - } - else { - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "Cannot open %s\n", DEV_MEM); - return FALSE; - } - close(fd); - } - - return TRUE; -} - -void -xf86FreeInt10(xf86Int10InfoPtr pInt) -{ - if (!pInt) - return; - -#ifdef _PC - xf86Int10SaveRestoreBIOSVars(pInt, FALSE); -#endif - if (Int10Current == pInt) { - shmdt(0); - if (((linuxInt10Priv *) pInt->private)->highMem >= 0) - shmdt((char *) HIGH_MEM); - else - munmap((void *) V_BIOS, (SYS_BIOS - V_BIOS)); - Int10Current = NULL; - } - - if (((linuxInt10Priv *) pInt->private)->base_high) - shmdt(((linuxInt10Priv *) pInt->private)->base_high); - shmdt(((linuxInt10Priv *) pInt->private)->base); - shmctl(((linuxInt10Priv *) pInt->private)->lowMem, IPC_RMID, NULL); - if (((linuxInt10Priv *) pInt->private)->highMem >= 0) - shmctl(((linuxInt10Priv *) pInt->private)->highMem, IPC_RMID, NULL); - free(((linuxInt10Priv *) pInt->private)->alloc); - free(pInt->private); - free(pInt); -} - -void * -xf86Int10AllocPages(xf86Int10InfoPtr pInt, int num, int *off) -{ - int pagesize = getpagesize(); - int num_pages = ALLOC_ENTRIES(pagesize); - int i, j; - - for (i = 0; i < (num_pages - num); i++) { - if (((linuxInt10Priv *) pInt->private)->alloc[i] == 0) { - for (j = i; j < (num + i); j++) - if ((((linuxInt10Priv *) pInt->private)->alloc[j] != 0)) - break; - if (j == (num + i)) - break; - else - i = i + num; - } - } - if (i == (num_pages - num)) - return NULL; - - for (j = i; j < (i + num); j++) - ((linuxInt10Priv *) pInt->private)->alloc[j] = 1; - - *off = (i + 1) * pagesize; - - return ((linuxInt10Priv *) pInt->private)->base + ((i + 1) * pagesize); -} - -void -xf86Int10FreePages(xf86Int10InfoPtr pInt, void *pbase, int num) -{ - int pagesize = getpagesize(); - int first = (((unsigned long) pbase - - (unsigned long) ((linuxInt10Priv *) pInt->private)->base) - / pagesize) - 1; - int i; - - for (i = first; i < (first + num); i++) - ((linuxInt10Priv *) pInt->private)->alloc[i] = 0; -} - -static CARD8 -read_b(xf86Int10InfoPtr pInt, int addr) -{ - return *((CARD8 *) (memType) addr); -} - -static CARD16 -read_w(xf86Int10InfoPtr pInt, int addr) -{ - return *((CARD16 *) (memType) addr); -} - -static CARD32 -read_l(xf86Int10InfoPtr pInt, int addr) -{ - return *((CARD32 *) (memType) addr); -} - -static void -write_b(xf86Int10InfoPtr pInt, int addr, CARD8 val) -{ - *((CARD8 *) (memType) addr) = val; -} - -static void -write_w(xf86Int10InfoPtr pInt, int addr, CARD16 val) -{ - *((CARD16 *) (memType) addr) = val; -} - -static - void -write_l(xf86Int10InfoPtr pInt, int addr, CARD32 val) -{ - *((CARD32 *) (memType) addr) = val; -} - -void * -xf86int10Addr(xf86Int10InfoPtr pInt, CARD32 addr) -{ - if (addr < V_RAM) - return ((linuxInt10Priv *) pInt->private)->base + addr; - else if (addr < V_BIOS) - return (void *) (memType) addr; - else if (addr < SYS_BIOS) { - if (((linuxInt10Priv *) pInt->private)->base_high) - return (void *) (((linuxInt10Priv *) pInt->private)->base_high - - V_BIOS + addr); - else - return (void *) (memType) addr; - } - else - return (void *) (memType) addr; -} - -#if defined DoSubModules - -static Bool -vm86_tst(void) -{ - int __res; - -#ifdef __PIC__ - /* When compiling with -fPIC, we can't use asm constraint "b" because - %ebx is already taken by gcc. */ - __asm__ __volatile__("pushl %%ebx\n\t" - "movl %2,%%ebx\n\t" - "movl %1,%%eax\n\t" - "int $0x80\n\t" "popl %%ebx":"=a"(__res) - :"n"((int) 113), "r"(NULL)); -#else - __asm__ __volatile__("int $0x80\n\t":"=a"(__res):"a"((int) 113), - "b"((struct vm86_struct *) NULL)); -#endif - - if (__res < 0 && __res == -ENOSYS) - return FALSE; - - return TRUE; -} - -static Int10LinuxSubModuleState -int10LinuxLoadSubModule(ScrnInfoPtr pScrn) -{ - if (vm86_tst()) { - if (xf86LoadSubModule(pScrn, "vm86")) - return INT10_LOADED_VM86; - } - if (xf86LoadSubModule(pScrn, "x86emu")) - return INT10_LOADED_X86EMU; - - return INT10_LOAD_FAILED; -} - -#endif /* DoSubModules */ diff --git a/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c b/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c deleted file mode 100644 index 134809814..000000000 --- a/hw/xfree86/os-support/linux/int10/vm86/linux_vm86.c +++ /dev/null @@ -1,323 +0,0 @@ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#include "xf86.h" -#include "xf86_OSproc.h" -#include "xf86Pci.h" -#include "compiler.h" -#define _INT10_PRIVATE -#include "xf86int10.h" - -#define REG pInt - -#ifdef _VM86_LINUX -#include "int10Defines.h" - -static int vm86_rep(struct vm86_struct *ptr); -static struct vm86_struct vm86_s; - -Bool -xf86Int10ExecSetup(xf86Int10InfoPtr pInt) -{ -#define VM86S ((struct vm86_struct *)pInt->cpuRegs) - - pInt->cpuRegs = &vm86_s; - VM86S->flags = 0; - VM86S->screen_bitmap = 0; - VM86S->cpu_type = CPU_586; - memset(&VM86S->int_revectored, 0xff, sizeof(VM86S->int_revectored)); - memset(&VM86S->int21_revectored, 0xff, sizeof(VM86S->int21_revectored)); - return TRUE; -} - -/* get the linear address */ -#define LIN_PREF_SI ((pref_seg << 4) + X86_SI) -#define LWECX ((prefix66 ^ prefix67) ? X86_ECX : X86_CX) -#define LWECX_ZERO {if (prefix66 ^ prefix67) X86_ECX = 0; else X86_CX = 0;} -#define DF (1 << 10) - -/* vm86 fault handling */ -static Bool -vm86_GP_fault(xf86Int10InfoPtr pInt) -{ - unsigned char *csp, *lina; - CARD32 org_eip; - int pref_seg; - int done, is_rep, prefix66, prefix67; - - csp = lina = SEG_ADR((unsigned char *), X86_CS, IP); - - is_rep = 0; - prefix66 = prefix67 = 0; - pref_seg = -1; - - /* eat up prefixes */ - done = 0; - do { - switch (MEM_RB(pInt, (int) csp++)) { - case 0x66: /* operand prefix */ - prefix66 = 1; - break; - case 0x67: /* address prefix */ - prefix67 = 1; - break; - case 0x2e: /* CS */ - pref_seg = X86_CS; - break; - case 0x3e: /* DS */ - pref_seg = X86_DS; - break; - case 0x26: /* ES */ - pref_seg = X86_ES; - break; - case 0x36: /* SS */ - pref_seg = X86_SS; - break; - case 0x65: /* GS */ - pref_seg = X86_GS; - break; - case 0x64: /* FS */ - pref_seg = X86_FS; - break; - case 0xf0: /* lock */ - break; - case 0xf2: /* repnz */ - case 0xf3: /* rep */ - is_rep = 1; - break; - default: - done = 1; - } - } while (!done); - csp--; /* oops one too many */ - org_eip = X86_EIP; - X86_IP += (csp - lina); - - switch (MEM_RB(pInt, (int) csp)) { - case 0x6c: /* insb */ - /* NOTE: ES can't be overwritten; prefixes 66,67 should use esi,edi,ecx - * but is anyone using extended regs in real mode? */ - /* WARNING: no test for DI wrapping! */ - X86_EDI += port_rep_inb(pInt, X86_DX, SEG_EADR((CARD32), X86_ES, DI), - X86_FLAGS & DF, is_rep ? LWECX : 1); - if (is_rep) - LWECX_ZERO; - X86_IP++; - break; - - case 0x6d: /* (rep) insw / insd */ - /* NOTE: ES can't be overwritten */ - /* WARNING: no test for _DI wrapping! */ - if (prefix66) { - X86_DI += port_rep_inl(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI), - X86_EFLAGS & DF, is_rep ? LWECX : 1); - } - else { - X86_DI += port_rep_inw(pInt, X86_DX, SEG_ADR((CARD32), X86_ES, DI), - X86_FLAGS & DF, is_rep ? LWECX : 1); - } - if (is_rep) - LWECX_ZERO; - X86_IP++; - break; - - case 0x6e: /* (rep) outsb */ - if (pref_seg < 0) - pref_seg = X86_DS; - /* WARNING: no test for _SI wrapping! */ - X86_SI += port_rep_outb(pInt, X86_DX, (CARD32) LIN_PREF_SI, - X86_FLAGS & DF, is_rep ? LWECX : 1); - if (is_rep) - LWECX_ZERO; - X86_IP++; - break; - - case 0x6f: /* (rep) outsw / outsd */ - if (pref_seg < 0) - pref_seg = X86_DS; - /* WARNING: no test for _SI wrapping! */ - if (prefix66) { - X86_SI += port_rep_outl(pInt, X86_DX, (CARD32) LIN_PREF_SI, - X86_EFLAGS & DF, is_rep ? LWECX : 1); - } - else { - X86_SI += port_rep_outw(pInt, X86_DX, (CARD32) LIN_PREF_SI, - X86_FLAGS & DF, is_rep ? LWECX : 1); - } - if (is_rep) - LWECX_ZERO; - X86_IP++; - break; - - case 0xe5: /* inw xx, inl xx */ - if (prefix66) - X86_EAX = x_inl(csp[1]); - else - X86_AX = x_inw(csp[1]); - X86_IP += 2; - break; - - case 0xe4: /* inb xx */ - X86_AL = x_inb(csp[1]); - X86_IP += 2; - break; - - case 0xed: /* inw dx, inl dx */ - if (prefix66) - X86_EAX = x_inl(X86_DX); - else - X86_AX = x_inw(X86_DX); - X86_IP += 1; - break; - - case 0xec: /* inb dx */ - X86_AL = x_inb(X86_DX); - X86_IP += 1; - break; - - case 0xe7: /* outw xx */ - if (prefix66) - x_outl(csp[1], X86_EAX); - else - x_outw(csp[1], X86_AX); - X86_IP += 2; - break; - - case 0xe6: /* outb xx */ - x_outb(csp[1], X86_AL); - X86_IP += 2; - break; - - case 0xef: /* outw dx */ - if (prefix66) - x_outl(X86_DX, X86_EAX); - else - x_outw(X86_DX, X86_AX); - X86_IP += 1; - break; - - case 0xee: /* outb dx */ - x_outb(X86_DX, X86_AL); - X86_IP += 1; - break; - - case 0xf4: - DebugF("hlt at %p\n", lina); - return FALSE; - - case 0x0f: - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, - "CPU 0x0f Trap at CS:EIP=0x%4.4x:0x%8.8lx\n", X86_CS, - X86_EIP); - goto op0ferr; - - default: - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "unknown reason for exception\n"); - - op0ferr: - dump_registers(pInt); - stack_trace(pInt); - dump_code(pInt); - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "cannot continue\n"); - return FALSE; - } /* end of switch() */ - return TRUE; -} - -static int -do_vm86(xf86Int10InfoPtr pInt) -{ - int retval; - - retval = vm86_rep(VM86S); - - switch (VM86_TYPE(retval)) { - case VM86_UNKNOWN: - if (!vm86_GP_fault(pInt)) - return 0; - break; - case VM86_STI: - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "vm86_sti :-((\n"); - dump_registers(pInt); - dump_code(pInt); - stack_trace(pInt); - return 0; - case VM86_INTx: - pInt->num = VM86_ARG(retval); - if (!int_handler(pInt)) { - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, - "Unknown vm86_int: 0x%X\n\n", VM86_ARG(retval)); - dump_registers(pInt); - dump_code(pInt); - stack_trace(pInt); - return 0; - } - /* I'm not sure yet what to do if we can handle ints */ - break; - case VM86_SIGNAL: - return 1; - /* - * we used to warn here and bail out - but now the sigio stuff - * always fires signals at us. So we just ignore them for now. - */ - xf86DrvMsg(pInt->pScrn->scrnIndex, X_WARNING, "received signal\n"); - return 0; - default: - xf86DrvMsg(pInt->pScrn->scrnIndex, X_ERROR, "unknown type(0x%x)=0x%x\n", - VM86_ARG(retval), VM86_TYPE(retval)); - dump_registers(pInt); - dump_code(pInt); - stack_trace(pInt); - return 0; - } - - return 1; -} - -void -xf86ExecX86int10(xf86Int10InfoPtr pInt) -{ - int sig = setup_int(pInt); - - if (int_handler(pInt)) - while (do_vm86(pInt)) { - }; - - finish_int(pInt, sig); -} - -static int -vm86_rep(struct vm86_struct *ptr) -{ - int __res; - -#ifdef __PIC__ - /* When compiling with -fPIC, we can't use asm constraint "b" because - %ebx is already taken by gcc. */ - __asm__ __volatile__("pushl %%ebx\n\t" - "push %%gs\n\t" - "movl %2,%%ebx\n\t" - "movl %1,%%eax\n\t" - "int $0x80\n\t" "pop %%gs\n\t" "popl %%ebx":"=a"(__res) - :"n"((int) 113), "r"((struct vm86_struct *) ptr)); -#else - __asm__ __volatile__("push %%gs\n\t" - "int $0x80\n\t" - "pop %%gs":"=a"(__res):"a"((int) 113), - "b"((struct vm86_struct *) ptr)); -#endif - - if (__res < 0) { - errno = -__res; - __res = -1; - } - else - errno = 0; - return __res; -} - -#endif diff --git a/hw/xfree86/os-support/linux/linux.h b/hw/xfree86/os-support/linux/linux.h deleted file mode 100644 index 83506fd38..000000000 --- a/hw/xfree86/os-support/linux/linux.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright © 2015 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Hans de Goede - */ - -#ifndef XF86_LINUX_H -#define XF86_LINUX_H - -int linux_parse_vt_settings(int may_fail); -int linux_get_keeptty(void); - -#endif diff --git a/hw/xfree86/os-support/linux/lnx_acpi.c b/hw/xfree86/os-support/linux/lnx_acpi.c deleted file mode 100644 index dbd5afe90..000000000 --- a/hw/xfree86/os-support/linux/lnx_acpi.c +++ /dev/null @@ -1,181 +0,0 @@ -#ifdef HAVE_XORG_CONFIG_H -#include "xorg-config.h" -#endif - -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" -#include -#include -#include -#include -#include -#include -#include - -#define ACPI_SOCKET "/var/run/acpid.socket" - -#define ACPI_VIDEO_NOTIFY_SWITCH 0x80 -#define ACPI_VIDEO_NOTIFY_PROBE 0x81 -#define ACPI_VIDEO_NOTIFY_CYCLE 0x82 -#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83 -#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84 - -#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85 -#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86 -#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87 -#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88 -#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89 - -#define ACPI_VIDEO_HEAD_INVALID (~0u - 1) -#define ACPI_VIDEO_HEAD_END (~0u) - -static void lnxCloseACPI(void); -static void *ACPIihPtr = NULL; -PMClose lnxACPIOpen(void); - -/* in milliseconds */ -#define ACPI_REOPEN_DELAY 1000 - -static CARD32 -lnxACPIReopen(OsTimerPtr timer, CARD32 time, void *arg) -{ - if (lnxACPIOpen()) { - TimerFree(timer); - return 0; - } - - return ACPI_REOPEN_DELAY; -} - -#define LINE_LENGTH 80 - -static int -lnxACPIGetEventFromOs(int fd, pmEvent * events, int num) -{ - char ev[LINE_LENGTH]; - int n; - - memset(ev, 0, LINE_LENGTH); - - do { - n = read(fd, ev, LINE_LENGTH); - } while ((n == -1) && (errno == EAGAIN || errno == EINTR)); - - if (n <= 0) { - lnxCloseACPI(); - TimerSet(NULL, 0, ACPI_REOPEN_DELAY, lnxACPIReopen, NULL); - return 0; - } - /* FIXME: this only processes the first read ACPI event & might break - * with interrupted reads. */ - - /* Check that we have a video event */ - if (!strncmp(ev, "video", 5)) { - char *GFX = NULL; - char *notify = NULL; - char *data = NULL; /* doesn't appear to be used in the kernel */ - unsigned long int notify_l; - - strtok(ev, " "); - - if (!(GFX = strtok(NULL, " "))) - return 0; -#if 0 - ErrorF("GFX: %s\n", GFX); -#endif - - if (!(notify = strtok(NULL, " "))) - return 0; - notify_l = strtoul(notify, NULL, 16); -#if 0 - ErrorF("notify: 0x%lx\n", notify_l); -#endif - - if (!(data = strtok(NULL, " "))) - return 0; -#if 0 - data_l = strtoul(data, NULL, 16); - ErrorF("data: 0x%lx\n", data_l); -#endif - - /* Differentiate between events */ - switch (notify_l) { - case ACPI_VIDEO_NOTIFY_SWITCH: - case ACPI_VIDEO_NOTIFY_CYCLE: - case ACPI_VIDEO_NOTIFY_NEXT_OUTPUT: - case ACPI_VIDEO_NOTIFY_PREV_OUTPUT: - events[0] = XF86_APM_CAPABILITY_CHANGED; - return 1; - case ACPI_VIDEO_NOTIFY_PROBE: - return 0; - default: - return 0; - } - } - - return 0; -} - -static pmWait -lnxACPIConfirmEventToOs(int fd, pmEvent event) -{ - /* No ability to send back to the kernel in ACPI */ - switch (event) { - default: - return PM_NONE; - } -} - -PMClose -lnxACPIOpen(void) -{ - int fd; - struct sockaddr_un addr; - int r = -1; - static int warned = 0; - - DebugF("ACPI: OSPMOpen called\n"); - if (ACPIihPtr || !xf86Info.pmFlag) - return NULL; - - DebugF("ACPI: Opening device\n"); - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) > -1) { - memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - strcpy(addr.sun_path, ACPI_SOCKET); - if ((r = connect(fd, (struct sockaddr *) &addr, sizeof(addr))) == -1) { - if (!warned) - xf86MsgVerb(X_WARNING, 3, "Open ACPI failed (%s) (%s)\n", - ACPI_SOCKET, strerror(errno)); - warned = 1; - shutdown(fd, 2); - close(fd); - return NULL; - } - } - - xf86PMGetEventFromOs = lnxACPIGetEventFromOs; - xf86PMConfirmEventToOs = lnxACPIConfirmEventToOs; - ACPIihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL); - xf86MsgVerb(X_INFO, 3, "Open ACPI successful (%s)\n", ACPI_SOCKET); - warned = 0; - - return lnxCloseACPI; -} - -static void -lnxCloseACPI(void) -{ - int fd; - - DebugF("ACPI: Closing device\n"); - if (ACPIihPtr) { - fd = xf86RemoveGeneralHandler(ACPIihPtr); - shutdown(fd, 2); - close(fd); - ACPIihPtr = NULL; - } -} diff --git a/hw/xfree86/os-support/linux/lnx_agp.c b/hw/xfree86/os-support/linux/lnx_agp.c deleted file mode 100644 index 3aec5397c..000000000 --- a/hw/xfree86/os-support/linux/lnx_agp.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - * Abstraction of the AGP GART interface. - * - * This version is for Linux and Free/Open/NetBSD. - * - * Copyright © 2000 VA Linux Systems, Inc. - * Copyright © 2001 The XFree86 Project, Inc. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -#if defined(__linux__) -#include -#include -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) -#include -#include -#endif - -#ifndef AGP_DEVICE -#define AGP_DEVICE "/dev/agpgart" -#endif -/* AGP page size is independent of the host page size. */ -#ifndef AGP_PAGE_SIZE -#define AGP_PAGE_SIZE 4096 -#endif -#define AGPGART_MAJOR_VERSION 0 -#define AGPGART_MINOR_VERSION 99 - -static int gartFd = -1; -static int acquiredScreen = -1; -static Bool initDone = FALSE; - -/* - * Close /dev/agpgart. This frees all associated memory allocated during - * this server generation. - */ -Bool -xf86GARTCloseScreen(int screenNum) -{ - if (gartFd != -1) { - close(gartFd); - acquiredScreen = -1; - gartFd = -1; - initDone = FALSE; - } - return TRUE; -} - -/* - * Open /dev/agpgart. Keep it open until xf86GARTCloseScreen is called. - */ -static Bool -GARTInit(int screenNum) -{ - struct _agp_info agpinf; - - if (initDone) - return gartFd != -1; - - initDone = TRUE; - - if (gartFd == -1) - gartFd = open(AGP_DEVICE, O_RDWR, 0); - else - return FALSE; - - if (gartFd == -1) { - xf86DrvMsg(screenNum, X_ERROR, - "GARTInit: Unable to open " AGP_DEVICE " (%s)\n", - strerror(errno)); - return FALSE; - } - - xf86AcquireGART(-1); - /* Check the kernel driver version. */ - if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { - xf86DrvMsg(screenNum, X_ERROR, - "GARTInit: AGPIOC_INFO failed (%s)\n", strerror(errno)); - close(gartFd); - gartFd = -1; - return FALSE; - } - xf86ReleaseGART(-1); - -#if defined(__linux__) - /* Per Dave Jones, every effort will be made to keep the - * agpgart interface backwards compatible, so allow all - * future versions. - */ - if ( -#if (AGPGART_MAJOR_VERSION > 0) /* quiet compiler */ - agpinf.version.major < AGPGART_MAJOR_VERSION || -#endif - (agpinf.version.major == AGPGART_MAJOR_VERSION && - agpinf.version.minor < AGPGART_MINOR_VERSION)) { - xf86DrvMsg(screenNum, X_ERROR, - "GARTInit: Kernel agpgart driver version is not current" - " (%d.%d vs %d.%d)\n", - agpinf.version.major, agpinf.version.minor, - AGPGART_MAJOR_VERSION, AGPGART_MINOR_VERSION); - close(gartFd); - gartFd = -1; - return FALSE; - } -#endif - - return TRUE; -} - -Bool -xf86AgpGARTSupported(void) -{ - return GARTInit(-1); -} - -AgpInfoPtr -xf86GetAGPInfo(int screenNum) -{ - struct _agp_info agpinf; - AgpInfoPtr info; - - if (!GARTInit(screenNum)) - return NULL; - - if ((info = calloc(sizeof(AgpInfo), 1)) == NULL) { - xf86DrvMsg(screenNum, X_ERROR, - "xf86GetAGPInfo: Failed to allocate AgpInfo\n"); - return NULL; - } - - memset((char *) &agpinf, 0, sizeof(agpinf)); - - if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { - xf86DrvMsg(screenNum, X_ERROR, - "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n", - strerror(errno)); - free(info); - return NULL; - } - - info->bridgeId = agpinf.bridge_id; - info->agpMode = agpinf.agp_mode; - info->base = agpinf.aper_base; - info->size = agpinf.aper_size; - info->totalPages = agpinf.pg_total; - info->systemPages = agpinf.pg_system; - info->usedPages = agpinf.pg_used; - - xf86DrvMsg(screenNum, X_INFO, "Kernel reported %zu total, %zu used\n", - agpinf.pg_total, agpinf.pg_used); - - return info; -} - -/* - * XXX If multiple screens can acquire the GART, should we have a reference - * count instead of using acquiredScreen? - */ - -Bool -xf86AcquireGART(int screenNum) -{ - if (screenNum != -1 && !GARTInit(screenNum)) - return FALSE; - - if (screenNum == -1 || acquiredScreen != screenNum) { - if (ioctl(gartFd, AGPIOC_ACQUIRE, 0) != 0) { - xf86DrvMsg(screenNum, X_WARNING, - "xf86AcquireGART: AGPIOC_ACQUIRE failed (%s)\n", - strerror(errno)); - return FALSE; - } - acquiredScreen = screenNum; - } - return TRUE; -} - -Bool -xf86ReleaseGART(int screenNum) -{ - if (screenNum != -1 && !GARTInit(screenNum)) - return FALSE; - - if (acquiredScreen == screenNum) { - /* - * The FreeBSD agp driver removes allocations on release. - * The Linux driver doesn't. xf86ReleaseGART() is expected - * to give up access to the GART, but not to remove any - * allocations. - */ -#if !defined(__linux__) - if (screenNum == -1) -#endif - { - if (ioctl(gartFd, AGPIOC_RELEASE, 0) != 0) { - xf86DrvMsg(screenNum, X_WARNING, - "xf86ReleaseGART: AGPIOC_RELEASE failed (%s)\n", - strerror(errno)); - return FALSE; - } - acquiredScreen = -1; - } - return TRUE; - } - return FALSE; -} - -int -xf86AllocateGARTMemory(int screenNum, unsigned long size, int type, - unsigned long *physical) -{ - struct _agp_allocate alloc; - int pages; - - /* - * Allocates "size" bytes of GART memory (rounds up to the next - * page multiple) or type "type". A handle (key) for the allocated - * memory is returned. On error, the return value is -1. - */ - - if (!GARTInit(screenNum) || acquiredScreen != screenNum) - return -1; - - pages = (size / AGP_PAGE_SIZE); - if (size % AGP_PAGE_SIZE != 0) - pages++; - - /* XXX check for pages == 0? */ - - alloc.pg_count = pages; - alloc.type = type; - - if (ioctl(gartFd, AGPIOC_ALLOCATE, &alloc) != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86AllocateGARTMemory: " - "allocation of %d pages failed\n\t(%s)\n", pages, - strerror(errno)); - return -1; - } - - if (physical) - *physical = alloc.physical; - - return alloc.key; -} - -Bool -xf86DeallocateGARTMemory(int screenNum, int key) -{ - if (!GARTInit(screenNum) || acquiredScreen != screenNum) - return FALSE; - - if (acquiredScreen != screenNum) { - xf86DrvMsg(screenNum, X_ERROR, - "xf86UnbindGARTMemory: AGP not acquired by this screen\n"); - return FALSE; - } - -#ifdef __linux__ - if (ioctl(gartFd, AGPIOC_DEALLOCATE, (int *) (uintptr_t) key) != 0) { -#else - if (ioctl(gartFd, AGPIOC_DEALLOCATE, &key) != 0) { -#endif - xf86DrvMsg(screenNum, X_WARNING, "xf86DeAllocateGARTMemory: " - "deallocation gart memory with key %d failed\n\t(%s)\n", - key, strerror(errno)); - return FALSE; - } - - return TRUE; -} - -/* Bind GART memory with "key" at "offset" */ -Bool -xf86BindGARTMemory(int screenNum, int key, unsigned long offset) -{ - struct _agp_bind bind; - int pageOffset; - - if (!GARTInit(screenNum) || acquiredScreen != screenNum) - return FALSE; - - if (acquiredScreen != screenNum) { - xf86DrvMsg(screenNum, X_ERROR, - "xf86BindGARTMemory: AGP not acquired by this screen\n"); - return FALSE; - } - - if (offset % AGP_PAGE_SIZE != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: " - "offset (0x%lx) is not page-aligned (%d)\n", - offset, AGP_PAGE_SIZE); - return FALSE; - } - pageOffset = offset / AGP_PAGE_SIZE; - - xf86DrvMsgVerb(screenNum, X_INFO, 3, - "xf86BindGARTMemory: bind key %d at 0x%08lx " - "(pgoffset %d)\n", key, offset, pageOffset); - - bind.pg_start = pageOffset; - bind.key = key; - - if (ioctl(gartFd, AGPIOC_BIND, &bind) != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: " - "binding of gart memory with key %d\n" - "\tat offset 0x%lx failed (%s)\n", - key, offset, strerror(errno)); - return FALSE; - } - - return TRUE; -} - -/* Unbind GART memory with "key" */ -Bool -xf86UnbindGARTMemory(int screenNum, int key) -{ - struct _agp_unbind unbind; - - if (!GARTInit(screenNum) || acquiredScreen != screenNum) - return FALSE; - - if (acquiredScreen != screenNum) { - xf86DrvMsg(screenNum, X_ERROR, - "xf86UnbindGARTMemory: AGP not acquired by this screen\n"); - return FALSE; - } - - unbind.priority = 0; - unbind.key = key; - - if (ioctl(gartFd, AGPIOC_UNBIND, &unbind) != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86UnbindGARTMemory: " - "unbinding of gart memory with key %d " - "failed (%s)\n", key, strerror(errno)); - return FALSE; - } - - xf86DrvMsgVerb(screenNum, X_INFO, 3, - "xf86UnbindGARTMemory: unbind key %d\n", key); - - return TRUE; -} - -/* XXX Interface may change. */ -Bool -xf86EnableAGP(int screenNum, CARD32 mode) -{ - agp_setup setup; - - if (!GARTInit(screenNum) || acquiredScreen != screenNum) - return FALSE; - - setup.agp_mode = mode; - if (ioctl(gartFd, AGPIOC_SETUP, &setup) != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86EnableAGP: " - "AGPIOC_SETUP with mode %ld failed (%s)\n", - (unsigned long) mode, strerror(errno)); - return FALSE; - } - - return TRUE; -} diff --git a/hw/xfree86/os-support/linux/lnx_apm.c b/hw/xfree86/os-support/linux/lnx_apm.c deleted file mode 100644 index b928febf6..000000000 --- a/hw/xfree86/os-support/linux/lnx_apm.c +++ /dev/null @@ -1,197 +0,0 @@ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" - -#ifdef HAVE_ACPI -extern PMClose lnxACPIOpen(void); -#endif - -#ifdef HAVE_APM - -#include -#include -#include -#include -#include -#include -#include - -#define APM_PROC "/proc/apm" -#define APM_DEVICE "/dev/apm_bios" - -#ifndef APM_STANDBY_FAILED -#define APM_STANDBY_FAILED 0xf000 -#endif -#ifndef APM_SUSPEND_FAILED -#define APM_SUSPEND_FAILED 0xf001 -#endif - -static PMClose lnxAPMOpen(void); -static void lnxCloseAPM(void); -static void *APMihPtr = NULL; - -static struct { - apm_event_t apmLinux; - pmEvent xf86; -} LinuxToXF86[] = { - {APM_SYS_STANDBY, XF86_APM_SYS_STANDBY}, - {APM_SYS_SUSPEND, XF86_APM_SYS_SUSPEND}, - {APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME}, - {APM_CRITICAL_RESUME, XF86_APM_CRITICAL_RESUME}, - {APM_LOW_BATTERY, XF86_APM_LOW_BATTERY}, - {APM_POWER_STATUS_CHANGE, XF86_APM_POWER_STATUS_CHANGE}, - {APM_UPDATE_TIME, XF86_APM_UPDATE_TIME}, - {APM_CRITICAL_SUSPEND, XF86_APM_CRITICAL_SUSPEND}, - {APM_USER_STANDBY, XF86_APM_USER_STANDBY}, - {APM_USER_SUSPEND, XF86_APM_USER_SUSPEND}, - {APM_STANDBY_RESUME, XF86_APM_STANDBY_RESUME}, -#if defined(APM_CAPABILITY_CHANGED) - {APM_CAPABILITY_CHANGED, XF86_CAPABILITY_CHANGED}, -#endif -#if 0 - {APM_STANDBY_FAILED, XF86_APM_STANDBY_FAILED}, - {APM_SUSPEND_FAILED, XF86_APM_SUSPEND_FAILED} -#endif -}; - -/* - * APM is still under construction. - * I'm not sure if the places where I initialize/deinitialize - * apm is correct. Also I don't know what to do in SETUP state. - * This depends if wakeup gets called in this situation, too. - * Also we need to check if the action that is taken on an - * event is reasonable. - */ -static int -lnxPMGetEventFromOs(int fd, pmEvent * events, int num) -{ - int i, j, n; - apm_event_t linuxEvents[8]; - - if ((n = read(fd, linuxEvents, num * sizeof(apm_event_t))) == -1) - return 0; - n /= sizeof(apm_event_t); - if (n > num) - n = num; - for (i = 0; i < n; i++) { - for (j = 0; j < ARRAY_SIZE(LinuxToXF86); j++) - if (LinuxToXF86[j].apmLinux == linuxEvents[i]) { - events[i] = LinuxToXF86[j].xf86; - break; - } - if (j == ARRAY_SIZE(LinuxToXF86)) - events[i] = XF86_APM_UNKNOWN; - } - return n; -} - -static pmWait -lnxPMConfirmEventToOs(int fd, pmEvent event) -{ - switch (event) { - case XF86_APM_SYS_STANDBY: - case XF86_APM_USER_STANDBY: - if (ioctl(fd, APM_IOC_STANDBY, NULL)) - return PM_FAILED; - return PM_CONTINUE; - case XF86_APM_SYS_SUSPEND: - case XF86_APM_CRITICAL_SUSPEND: - case XF86_APM_USER_SUSPEND: - if (ioctl(fd, APM_IOC_SUSPEND, NULL)) { - /* I believe this is wrong (EE) - EBUSY is sent when a device refuses to be suspended. - In this case we still need to undo everything we have - done to suspend ourselves or we will stay in suspended - state forever. */ - if (errno == EBUSY) - return PM_CONTINUE; - else - return PM_FAILED; - } - return PM_CONTINUE; - case XF86_APM_STANDBY_RESUME: - case XF86_APM_NORMAL_RESUME: - case XF86_APM_CRITICAL_RESUME: - case XF86_APM_STANDBY_FAILED: - case XF86_APM_SUSPEND_FAILED: - return PM_CONTINUE; - default: - return PM_NONE; - } -} - -#endif // HAVE_APM - -PMClose -xf86OSPMOpen(void) -{ - PMClose ret = NULL; - -#ifdef HAVE_ACPI - /* Favour ACPI over APM, but only when enabled */ - - if (!xf86acpiDisableFlag) { - ret = lnxACPIOpen(); - if (ret) - return ret; - } -#endif -#ifdef HAVE_APM - ret = lnxAPMOpen(); -#endif - - return ret; -} - -#ifdef HAVE_APM - -static PMClose -lnxAPMOpen(void) -{ - int fd, pfd; - - DebugF("APM: OSPMOpen called\n"); - if (APMihPtr || !xf86Info.pmFlag) - return NULL; - - DebugF("APM: Opening device\n"); - if ((fd = open(APM_DEVICE, O_RDWR)) > -1) { - if (access(APM_PROC, R_OK) || ((pfd = open(APM_PROC, O_RDONLY)) == -1)) { - xf86MsgVerb(X_WARNING, 3, "Cannot open APM (%s) (%s)\n", - APM_PROC, strerror(errno)); - close(fd); - return NULL; - } - else - close(pfd); - xf86PMGetEventFromOs = lnxPMGetEventFromOs; - xf86PMConfirmEventToOs = lnxPMConfirmEventToOs; - APMihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL); - xf86MsgVerb(X_INFO, 3, "Open APM successful\n"); - return lnxCloseAPM; - } - return NULL; -} - -static void -lnxCloseAPM(void) -{ - int fd; - - DebugF("APM: Closing device\n"); - if (APMihPtr) { - fd = xf86RemoveGeneralHandler(APMihPtr); - close(fd); - APMihPtr = NULL; - } -} - -#endif // HAVE_APM diff --git a/hw/xfree86/os-support/linux/lnx_bell.c b/hw/xfree86/os-support/linux/lnx_bell.c deleted file mode 100644 index e1d3cbf17..000000000 --- a/hw/xfree86/os-support/linux/lnx_bell.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright © 2006 Daniel Stone - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Daniel Stone - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSproc.h" - -void -xf86OSRingBell(int loudness, int pitch, int duration) -{ - if (xf86Info.consoleFd == -1 || !pitch || !loudness) - return; - - ioctl(xf86Info.consoleFd, KDMKTONE, - ((1193190 / pitch) & 0xffff) | - (((unsigned long) duration * loudness / 50) << 16)); -} diff --git a/hw/xfree86/os-support/linux/lnx_ev56.c b/hw/xfree86/os-support/linux/lnx_ev56.c deleted file mode 100644 index 4e886b6ce..000000000 --- a/hw/xfree86/os-support/linux/lnx_ev56.c +++ /dev/null @@ -1,59 +0,0 @@ -/* This file has to be built with -mcpu=ev56 */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "compiler.h" - -int readDense8(void *Base, register unsigned long Offset); -int readDense16(void *Base, register unsigned long Offset); -int readDense32(void *Base, register unsigned long Offset); -void - writeDense8(int Value, void *Base, register unsigned long Offset); -void - writeDense16(int Value, void *Base, register unsigned long Offset); -void - writeDense32(int Value, void *Base, register unsigned long Offset); - -int -readDense8(void *Base, register unsigned long Offset) -{ - mem_barrier(); - return *(volatile CARD8 *) ((unsigned long) Base + (Offset)); -} - -int -readDense16(void *Base, register unsigned long Offset) -{ - mem_barrier(); - return *(volatile CARD16 *) ((unsigned long) Base + (Offset)); -} - -int -readDense32(void *Base, register unsigned long Offset) -{ - mem_barrier(); - return *(volatile CARD32 *) ((unsigned long) Base + (Offset)); -} - -void -writeDense8(int Value, void *Base, register unsigned long Offset) -{ - write_mem_barrier(); - *(volatile CARD8 *) ((unsigned long) Base + (Offset)) = Value; -} - -void -writeDense16(int Value, void *Base, register unsigned long Offset) -{ - write_mem_barrier(); - *(volatile CARD16 *) ((unsigned long) Base + (Offset)) = Value; -} - -void -writeDense32(int Value, void *Base, register unsigned long Offset) -{ - write_mem_barrier(); - *(volatile CARD32 *) ((unsigned long) Base + (Offset)) = Value; -} diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c deleted file mode 100644 index 111b3b4e4..000000000 --- a/hw/xfree86/os-support/linux/lnx_init.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright 1992 by Orest Zborowski - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Orest Zborowski and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Orest Zborowski - * and David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#include "compiler.h" -#include "linux.h" - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -#include -#ifdef HAVE_SYS_SYSMACROS_H -#include -#endif - -#ifndef K_OFF -#define K_OFF 0x4 -#endif - -static Bool KeepTty = FALSE; -static int activeVT = -1; - -static char vtname[11]; -static struct termios tty_attr; /* tty state to restore */ -static int tty_mode; /* kbd mode to restore */ - -static void -drain_console(int fd, void *closure) -{ - errno = 0; - if (tcflush(fd, TCIOFLUSH) == -1 && errno == EIO) { - xf86SetConsoleHandler(NULL, NULL); - } -} - -static int -switch_to(int vt, const char *from) -{ - int ret; - - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt)); - if (ret < 0) { - xf86Msg(X_WARNING, "%s: VT_ACTIVATE failed: %s\n", from, strerror(errno)); - return 0; - } - - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt)); - if (ret < 0) { - xf86Msg(X_WARNING, "%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno)); - return 0; - } - - return 1; -} - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" - -int -linux_parse_vt_settings(int may_fail) -{ - int i, fd = -1, ret, current_vt = -1; - struct vt_stat vts; - struct stat st; - MessageType from = X_PROBED; - - /* Only do this once */ - static int vt_settings_parsed = 0; - - if (vt_settings_parsed) - return 1; - - /* - * setup the virtual terminal manager - */ - if (xf86Info.vtno != -1) { - from = X_CMDLINE; - } - else { - fd = open("/dev/tty0", O_WRONLY, 0); - if (fd < 0) { - if (may_fail) - return 0; - FatalError("parse_vt_settings: Cannot open /dev/tty0 (%s)\n", - strerror(errno)); - } - - if (xf86Info.ShareVTs) { - SYSCALL(ret = ioctl(fd, VT_GETSTATE, &vts)); - if (ret < 0) { - if (may_fail) - return 0; - FatalError("parse_vt_settings: Cannot find the current" - " VT (%s)\n", strerror(errno)); - } - xf86Info.vtno = vts.v_active; - } - else { - SYSCALL(ret = ioctl(fd, VT_OPENQRY, &xf86Info.vtno)); - if (ret < 0) { - if (may_fail) - return 0; - FatalError("parse_vt_settings: Cannot find a free VT: " - "%s\n", strerror(errno)); - } - if (xf86Info.vtno == -1) { - if (may_fail) - return 0; - FatalError("parse_vt_settings: Cannot find a free VT\n"); - } - } - close(fd); - } - - xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); - - /* Some of stdin / stdout / stderr maybe redirected to a file */ - for (i = STDIN_FILENO; i <= STDERR_FILENO; i++) { - ret = fstat(i, &st); - if (ret == 0 && S_ISCHR(st.st_mode) && major(st.st_rdev) == 4) { - current_vt = minor(st.st_rdev); - break; - } - } - - if (!KeepTty && current_vt == xf86Info.vtno) { - xf86Msg(X_PROBED, - "controlling tty is VT number %d, auto-enabling KeepTty\n", - current_vt); - KeepTty = TRUE; - } - - vt_settings_parsed = 1; - return 1; -} - -int -linux_get_keeptty(void) -{ - return KeepTty; -} - -void -xf86OpenConsole(void) -{ - int i, ret; - struct vt_stat vts; - struct vt_mode VT; - const char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL }; - - if (serverGeneration == 1) { - linux_parse_vt_settings(FALSE); - - if (!KeepTty) { - pid_t ppid = getppid(); - pid_t ppgid; - - ppgid = getpgid(ppid); - - /* - * change to parent process group that pgid != pid so - * that setsid() doesn't fail and we become process - * group leader - */ - if (setpgid(0, ppgid) < 0) - xf86Msg(X_WARNING, "xf86OpenConsole: setpgid failed: %s\n", - strerror(errno)); - - /* become process group leader */ - if ((setsid() < 0)) - xf86Msg(X_WARNING, "xf86OpenConsole: setsid failed: %s\n", - strerror(errno)); - } - - i = 0; - while (vcs[i] != NULL) { - snprintf(vtname, sizeof(vtname), vcs[i], xf86Info.vtno); /* /dev/tty1-64 */ - if ((xf86Info.consoleFd = open(vtname, O_RDWR | O_NDELAY, 0)) >= 0) - break; - i++; - } - - if (xf86Info.consoleFd < 0) - FatalError("xf86OpenConsole: Cannot open virtual console" - " %d (%s)\n", xf86Info.vtno, strerror(errno)); - - /* - * Linux doesn't switch to an active vt after the last close of a vt, - * so we do this ourselves by remembering which is active now. - */ - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts)); - if (ret < 0) - xf86Msg(X_WARNING, "xf86OpenConsole: VT_GETSTATE failed: %s\n", - strerror(errno)); - else - activeVT = vts.v_active; - - if (!xf86Info.ShareVTs) { - struct termios nTty; - - /* - * now get the VT. This _must_ succeed, or else fail completely. - */ - if (!switch_to(xf86Info.vtno, "xf86OpenConsole")) - FatalError("xf86OpenConsole: Switching VT failed\n"); - - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT)); - if (ret < 0) - FatalError("xf86OpenConsole: VT_GETMODE failed %s\n", - strerror(errno)); - - OsSignal(SIGUSR1, xf86VTRequest); - - VT.mode = VT_PROCESS; - VT.relsig = SIGUSR1; - VT.acqsig = SIGUSR1; - - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT)); - if (ret < 0) - FatalError - ("xf86OpenConsole: VT_SETMODE VT_PROCESS failed: %s\n", - strerror(errno)); - - SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); - if (ret < 0) - FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed %s\n", - strerror(errno)); - - tcgetattr(xf86Info.consoleFd, &tty_attr); - SYSCALL(ioctl(xf86Info.consoleFd, KDGKBMODE, &tty_mode)); - - /* disable kernel special keys and buffering */ - SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_OFF)); - if (ret < 0) - { - /* fine, just disable special keys */ - SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW)); - if (ret < 0) - FatalError("xf86OpenConsole: KDSKBMODE K_RAW failed %s\n", - strerror(errno)); - - /* ... and drain events, else the kernel gets angry */ - xf86SetConsoleHandler(drain_console, NULL); - } - - nTty = tty_attr; - nTty.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); - nTty.c_oflag = 0; - nTty.c_cflag = CREAD | CS8; - nTty.c_lflag = 0; - nTty.c_cc[VTIME] = 0; - nTty.c_cc[VMIN] = 1; - cfsetispeed(&nTty, 9600); - cfsetospeed(&nTty, 9600); - tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty); - } - } - else { /* serverGeneration != 1 */ - if (!xf86Info.ShareVTs && xf86Info.autoVTSwitch) { - /* now get the VT */ - if (!switch_to(xf86Info.vtno, "xf86OpenConsole")) - FatalError("xf86OpenConsole: Switching VT failed\n"); - } - } -} - -#pragma GCC diagnostic pop - -void -xf86CloseConsole(void) -{ - struct vt_mode VT; - struct vt_stat vts; - int ret; - - if (xf86Info.ShareVTs) { - close(xf86Info.consoleFd); - return; - } - - /* - * unregister the drain_console handler - * - what to do if someone else changed it in the meantime? - */ - xf86SetConsoleHandler(NULL, NULL); - - /* Back to text mode ... */ - SYSCALL(ret = ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT)); - if (ret < 0) - xf86Msg(X_WARNING, "xf86CloseConsole: KDSETMODE failed: %s\n", - strerror(errno)); - - SYSCALL(ioctl(xf86Info.consoleFd, KDSKBMODE, tty_mode)); - tcsetattr(xf86Info.consoleFd, TCSANOW, &tty_attr); - - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETMODE, &VT)); - if (ret < 0) - xf86Msg(X_WARNING, "xf86CloseConsole: VT_GETMODE failed: %s\n", - strerror(errno)); - else { - /* set dflt vt handling */ - VT.mode = VT_AUTO; - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_SETMODE, &VT)); - if (ret < 0) - xf86Msg(X_WARNING, "xf86CloseConsole: VT_SETMODE failed: %s\n", - strerror(errno)); - } - - if (xf86Info.autoVTSwitch) { - /* - * Perform a switch back to the active VT when we were started if our - * vt is active now. - */ - if (activeVT >= 0) { - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_GETSTATE, &vts)); - if (ret < 0) { - xf86Msg(X_WARNING, "xf86OpenConsole: VT_GETSTATE failed: %s\n", - strerror(errno)); - } else { - if (vts.v_active == xf86Info.vtno) { - switch_to(activeVT, "xf86CloseConsole"); - } - } - activeVT = -1; - } - } - close(xf86Info.consoleFd); /* make the vt-manager happy */ -} - -#define CHECK_FOR_REQUIRED_ARGUMENT() \ - if (((i + 1) >= argc) || (!argv[i + 1])) { \ - ErrorF("Required argument to %s not specified\n", argv[i]); \ - UseMsg(); \ - FatalError("Required argument to %s not specified\n", argv[i]); \ - } - -int -xf86ProcessArgument(int argc, char *argv[], int i) -{ - /* - * Keep server from detaching from controlling tty. This is useful - * when debugging (so the server can receive keyboard signals. - */ - if (!strcmp(argv[i], "-keeptty")) { - KeepTty = TRUE; - return 1; - } - - if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { - if (sscanf(argv[i], "vt%2d", &xf86Info.vtno) == 0) { - UseMsg(); - xf86Info.vtno = -1; - return 0; - } - return 1; - } - - if (!strcmp(argv[i], "-masterfd")) { - CHECK_FOR_REQUIRED_ARGUMENT(); - if (xf86PrivsElevated()) - FatalError("\nCannot specify -masterfd when server is setuid/setgid\n"); - if (sscanf(argv[++i], "%d", &xf86DRMMasterFd) != 1) { - UseMsg(); - xf86DRMMasterFd = -1; - return 0; - } - return 2; - } - - return 0; -} - -void -xf86UseMsg(void) -{ - ErrorF("vtXX use the specified VT number\n"); - ErrorF("-keeptty "); - ErrorF("don't detach controlling tty (for debugging only)\n"); - ErrorF("-masterfd use the specified fd as the DRM master fd (not if setuid/gid)\n"); -} - -void -xf86OSInputThreadInit(void) -{ - return; -} diff --git a/hw/xfree86/os-support/linux/lnx_kmod.c b/hw/xfree86/os-support/linux/lnx_kmod.c deleted file mode 100644 index 6d1222655..000000000 --- a/hw/xfree86/os-support/linux/lnx_kmod.c +++ /dev/null @@ -1,111 +0,0 @@ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include "xf86_OSlib.h" -#include "xf86.h" - -#define MODPROBE_PATH_FILE "/proc/sys/kernel/modprobe" -#define MAX_PATH 1024 - -#if 0 -/* XFree86 #defines execl to be the xf86execl() function which does - * a fork AND exec. We don't want that. We want the regular, - * standard execl(). - */ -#ifdef execl -#undef execl -#endif -#endif - -/* - * Load a Linux kernel module. - * This is used by the DRI/DRM to load a DRM kernel module when - * the X server starts. It could be used for other purposes in the future. - * Input: - * modName - name of the kernel module (Ex: "tdfx") - * Return: - * 0 for failure, 1 for success - */ -int -xf86LoadKernelModule(const char *modName) -{ - char mpPath[MAX_PATH] = ""; - int fd = -1, status; - pid_t pid; - - /* get the path to the modprobe program */ - fd = open(MODPROBE_PATH_FILE, O_RDONLY); - if (fd >= 0) { - int count = read(fd, mpPath, MAX_PATH - 1); - - if (count <= 0) { - mpPath[0] = 0; - } - else if (mpPath[count - 1] == '\n') { - mpPath[count - 1] = 0; /* replaces \n with \0 */ - } - close(fd); - /* if this worked, mpPath will be "/sbin/modprobe" or similar. */ - } - - if (mpPath[0] == 0) { - /* we failed to get the path from the system, use a default */ - strcpy(mpPath, "/sbin/modprobe"); - } - - /* now fork/exec the modprobe command */ - /* - * It would be good to capture stdout/stderr so that it can be directed - * to the log file. modprobe errors currently are missing from the log - * file. - */ - switch (pid = fork()) { - case 0: /* child */ - /* change real/effective user ID to 0/0 as we need to - * preinstall agpgart module for some DRM modules - */ - if (setreuid(0, 0)) { - xf86Msg(X_WARNING, "LoadKernelModule: " - "Setting of real/effective user Id to 0/0 failed"); - } - setenv("PATH", "/sbin", 1); - execl(mpPath, "modprobe", modName, NULL); - xf86Msg(X_WARNING, "LoadKernelModule %s\n", strerror(errno)); - exit(EXIT_FAILURE); /* if we get here the child's exec failed */ - break; - case -1: /* fork failed */ - return 0; - default: /* fork worked */ - { - /* XXX we loop over waitpid() because it sometimes fails on - * the first attempt. Don't know why! - */ - int count = 0, p; - - do { - p = waitpid(pid, &status, 0); - } while (p == -1 && count++ < 4); - - if (p == -1) { - return 0; - } - - if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { - return 1; /* success! */ - } - else { - return 0; - } - } - } - - /* never get here */ - return 0; -} diff --git a/hw/xfree86/os-support/linux/lnx_platform.c b/hw/xfree86/os-support/linux/lnx_platform.c deleted file mode 100644 index 8a6be97aa..000000000 --- a/hw/xfree86/os-support/linux/lnx_platform.c +++ /dev/null @@ -1,219 +0,0 @@ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifdef XSERVER_PLATFORM_BUS - -#include -#include -#include -#include -#include - -/* Linux platform device support */ -#include "xf86_OSproc.h" - -#include "xf86.h" -#include "xf86platformBus.h" -#include "xf86Bus.h" - -#include "hotplug.h" -#include "systemd-logind.h" - -static Bool -get_drm_info(struct OdevAttributes *attribs, char *path, int delayed_index) -{ - drmVersionPtr v; - int fd; - int err = 0; - Bool paused, server_fd = FALSE; - - LogMessage(X_INFO, "Platform probe for %s\n", attribs->syspath); - - fd = systemd_logind_take_fd(attribs->major, attribs->minor, path, &paused); - if (fd != -1) { - if (paused) { - LogMessage(X_ERROR, - "Error systemd-logind returned paused fd for drm node\n"); - systemd_logind_release_fd(attribs->major, attribs->minor, -1); - return FALSE; - } - attribs->fd = fd; - server_fd = TRUE; - } - - if (fd == -1) - fd = open(path, O_RDWR | O_CLOEXEC, 0); - - if (fd == -1) - return FALSE; - - /* for a delayed probe we've already added the device */ - if (delayed_index == -1) { - xf86_add_platform_device(attribs, FALSE); - delayed_index = xf86_num_platform_devices - 1; - } - - if (server_fd) - xf86_platform_devices[delayed_index].flags |= XF86_PDEV_SERVER_FD; - - v = drmGetVersion(fd); - if (!v) { - xf86Msg(X_ERROR, "%s: failed to query DRM version\n", path); - goto out; - } - - xf86_platform_odev_attributes(delayed_index)->driver = XNFstrdup(v->name); - drmFreeVersion(v); - -out: - if (!server_fd) - close(fd); - return (err == 0); -} - -Bool -xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid) -{ - const char *syspath = device->attribs->syspath; - BusType bustype; - const char *id; - - if (!syspath) - return FALSE; - - bustype = StringToBusType(busid, &id); - if (bustype == BUS_PCI) { - struct pci_device *pPci = device->pdev; - if (!pPci) - return FALSE; - - if (xf86ComparePciBusString(busid, - ((pPci->domain << 8) - | pPci->bus), - pPci->dev, pPci->func)) { - return TRUE; - } - } - else if (bustype == BUS_PLATFORM) { - /* match on the minimum string */ - int len = strlen(id); - - if (strlen(syspath) < strlen(id)) - len = strlen(syspath); - - if (strncmp(id, syspath, len)) - return FALSE; - return TRUE; - } - else if (bustype == BUS_USB) { - if (strcasecmp(busid, device->attribs->busid)) - return FALSE; - return TRUE; - } - return FALSE; -} - -void -xf86PlatformReprobeDevice(int index, struct OdevAttributes *attribs) -{ - Bool ret; - char *dpath = attribs->path; - - ret = get_drm_info(attribs, dpath, index); - if (ret == FALSE) { - xf86_remove_platform_device(index); - return; - } - ret = xf86platformAddDevice(index); - if (ret == -1) - xf86_remove_platform_device(index); -} - -void -xf86PlatformDeviceProbe(struct OdevAttributes *attribs) -{ - int i; - char *path = attribs->path; - Bool ret; - - if (!path) - goto out_free; - - for (i = 0; i < xf86_num_platform_devices; i++) { - char *dpath = xf86_platform_odev_attributes(i)->path; - - if (dpath && !strcmp(path, dpath)) - break; - } - - if (i != xf86_num_platform_devices) - goto out_free; - - LogMessage(X_INFO, "xfree86: Adding drm device (%s)\n", path); - - if (!xf86VTOwner()) { - /* if we don't currently own the VT then don't probe the device, - just mark it as unowned for later use */ - xf86_add_platform_device(attribs, TRUE); - return; - } - - ret = get_drm_info(attribs, path, -1); - if (ret == FALSE) - goto out_free; - - return; - -out_free: - config_odev_free_attributes(attribs); -} - -void NewGPUDeviceRequest(struct OdevAttributes *attribs) -{ - int old_num = xf86_num_platform_devices; - int ret; - xf86PlatformDeviceProbe(attribs); - - if (old_num == xf86_num_platform_devices) - return; - - if (xf86_get_platform_device_unowned(xf86_num_platform_devices - 1) == TRUE) - return; - - ret = xf86platformAddDevice(xf86_num_platform_devices-1); - if (ret == -1) - xf86_remove_platform_device(xf86_num_platform_devices-1); - - ErrorF("xf86: found device %d\n", xf86_num_platform_devices); - return; -} - -void DeleteGPUDeviceRequest(struct OdevAttributes *attribs) -{ - int index; - char *syspath = attribs->syspath; - - if (!syspath) - goto out; - - for (index = 0; index < xf86_num_platform_devices; index++) { - char *dspath = xf86_platform_odev_attributes(index)->syspath; - if (dspath && !strcmp(syspath, dspath)) - break; - } - - if (index == xf86_num_platform_devices) - goto out; - - ErrorF("xf86: remove device %d %s\n", index, syspath); - - if (xf86_get_platform_device_unowned(index) == TRUE) - xf86_remove_platform_device(index); - else - xf86platformRemoveDevice(index); -out: - config_odev_free_attributes(attribs); -} - -#endif diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c deleted file mode 100644 index fd83022f6..000000000 --- a/hw/xfree86/os-support/linux/lnx_video.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 1992 by Orest Zborowski - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of Orest Zborowski and David Wexelblat - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. Orest Zborowski - * and David Wexelblat make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE - * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include - -#include -#include "input.h" -#include "scrnintstr.h" - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -static Bool ExtendedEnabled = FALSE; - -#ifdef __ia64__ - -#include "compiler.h" -#include - -#elif !defined(__powerpc__) && \ - !defined(__mc68000__) && \ - !defined(__sparc__) && \ - !defined(__mips__) && \ - !defined(__nds32__) && \ - !defined(__arm__) && \ - !defined(__aarch64__) && \ - !defined(__arc__) && \ - !defined(__xtensa__) - -/* - * Due to conflicts with "compiler.h", don't rely on to declare - * these. - */ -extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on); -extern int iopl(int __level); - -#endif - -/***************************************************************************/ -/* Video Memory Mapping section */ -/***************************************************************************/ - -void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - pVidMem->initialised = TRUE; -} - -/***************************************************************************/ -/* I/O Permissions section */ -/***************************************************************************/ - -#if defined(__powerpc__) -volatile unsigned char *ioBase = NULL; - -#ifndef __NR_pciconfig_iobase -#define __NR_pciconfig_iobase 200 -#endif - -static Bool -hwEnableIO(void) -{ - int fd; - unsigned int ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0); - - fd = open("/dev/mem", O_RDWR); - if (ioBase == NULL) { - ioBase = (volatile unsigned char *) mmap(0, 0x20000, - PROT_READ | PROT_WRITE, - MAP_SHARED, fd, ioBase_phys); - } - close(fd); - - return ioBase != MAP_FAILED; -} - -static void -hwDisableIO(void) -{ - munmap(ioBase, 0x20000); - ioBase = NULL; -} - -#elif defined(__i386__) || defined(__x86_64__) || defined(__ia64__) || \ - defined(__alpha__) - -static Bool -hwEnableIO(void) -{ - short i; - size_t n=0; - int begin, end; - char *buf=NULL, target[5]; - FILE *fp; - - if (ioperm(0, 1024, 1)) { - ErrorF("xf86EnableIO: failed to enable I/O ports 0000-03ff (%s)\n", - strerror(errno)); - return FALSE; - } - -#if !defined(__alpha__) - target[4] = '\0'; - - /* trap access to the keyboard controller(s) and timer chip(s) */ - fp = fopen("/proc/ioports", "r"); - while (getline(&buf, &n, fp) != -1) { - if ((strstr(buf, "keyboard") != NULL) || (strstr(buf, "timer") != NULL)) { - for (i=0; i<4; i++) - target[i] = buf[i+2]; - begin = atoi(target); - - for (i=0; i<4; i++) - target[i] = buf[i+7]; - end = atoi(target); - - ioperm(begin, end-begin+1, 0); - } - } - free(buf); - fclose(fp); -#endif - - return TRUE; -} - -static void -hwDisableIO(void) -{ - iopl(0); - ioperm(0, 1024, 0); -} - -#else /* non-IO architectures */ - -#define hwEnableIO() TRUE -#define hwDisableIO() do {} while (0) - -#endif - -Bool -xf86EnableIO(void) -{ - if (ExtendedEnabled) - return TRUE; - - ExtendedEnabled = hwEnableIO(); - - return ExtendedEnabled; -} - -void -xf86DisableIO(void) -{ - if (!ExtendedEnabled) - return; - - hwDisableIO(); - - ExtendedEnabled = FALSE; -} diff --git a/hw/xfree86/os-support/linux/systemd-logind.c b/hw/xfree86/os-support/linux/systemd-logind.c deleted file mode 100644 index dbb00cd85..000000000 --- a/hw/xfree86/os-support/linux/systemd-logind.c +++ /dev/null @@ -1,635 +0,0 @@ -/* - * Copyright © 2013 Red Hat Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Hans de Goede - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include "os.h" -#include "dbus-core.h" -#include "linux.h" -#include "xf86.h" -#include "xf86platformBus.h" -#include "xf86Xinput.h" -#include "xf86Priv.h" -#include "globals.h" - -#include "systemd-logind.h" - -struct systemd_logind_info { - DBusConnection *conn; - char *session; - Bool active; - Bool vt_active; -}; - -static struct systemd_logind_info logind_info; - -static InputInfoPtr -systemd_logind_find_info_ptr_by_devnum(InputInfoPtr start, - int major, int minor) -{ - InputInfoPtr pInfo; - - for (pInfo = start; pInfo; pInfo = pInfo->next) - if (pInfo->major == major && pInfo->minor == minor && - (pInfo->flags & XI86_SERVER_FD)) - return pInfo; - - return NULL; -} - -static void -systemd_logind_set_input_fd_for_all_devs(int major, int minor, int fd, - Bool enable) -{ - InputInfoPtr pInfo; - - pInfo = systemd_logind_find_info_ptr_by_devnum(xf86InputDevs, major, minor); - while (pInfo) { - pInfo->fd = fd; - pInfo->options = xf86ReplaceIntOption(pInfo->options, "fd", fd); - if (enable) - xf86EnableInputDeviceForVTSwitch(pInfo); - - pInfo = systemd_logind_find_info_ptr_by_devnum(pInfo->next, major, minor); - } -} - -int -systemd_logind_take_fd(int _major, int _minor, const char *path, - Bool *paused_ret) -{ - struct systemd_logind_info *info = &logind_info; - InputInfoPtr pInfo; - DBusError error; - DBusMessage *msg = NULL; - DBusMessage *reply = NULL; - dbus_int32_t major = _major; - dbus_int32_t minor = _minor; - dbus_bool_t paused; - int fd = -1; - - if (!info->session || major == 0) - return -1; - - /* logind does not support mouse devs (with evdev we don't need them) */ - if (strstr(path, "mouse")) - return -1; - - /* Check if we already have an InputInfo entry with this major, minor - * (shared device-nodes happen ie with Wacom tablets). */ - pInfo = systemd_logind_find_info_ptr_by_devnum(xf86InputDevs, major, minor); - if (pInfo) { - LogMessage(X_INFO, "systemd-logind: returning pre-existing fd for %s %u:%u\n", - path, major, minor); - *paused_ret = FALSE; - return pInfo->fd; - } - - dbus_error_init(&error); - - msg = dbus_message_new_method_call("org.freedesktop.login1", info->session, - "org.freedesktop.login1.Session", "TakeDevice"); - if (!msg) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major, - DBUS_TYPE_UINT32, &minor, - DBUS_TYPE_INVALID)) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - reply = dbus_connection_send_with_reply_and_block(info->conn, msg, - DBUS_TIMEOUT_USE_DEFAULT, &error); - if (!reply) { - LogMessage(X_ERROR, "systemd-logind: failed to take device %s: %s\n", - path, error.message); - goto cleanup; - } - - if (!dbus_message_get_args(reply, &error, - DBUS_TYPE_UNIX_FD, &fd, - DBUS_TYPE_BOOLEAN, &paused, - DBUS_TYPE_INVALID)) { - LogMessage(X_ERROR, "systemd-logind: TakeDevice %s: %s\n", - path, error.message); - goto cleanup; - } - - *paused_ret = paused; - - LogMessage(X_INFO, "systemd-logind: got fd for %s %u:%u fd %d paused %d\n", - path, major, minor, fd, paused); - -cleanup: - if (msg) - dbus_message_unref(msg); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); - - return fd; -} - -void -systemd_logind_release_fd(int _major, int _minor, int fd) -{ - struct systemd_logind_info *info = &logind_info; - InputInfoPtr pInfo; - DBusError error; - DBusMessage *msg = NULL; - DBusMessage *reply = NULL; - dbus_int32_t major = _major; - dbus_int32_t minor = _minor; - int matches = 0; - - if (!info->session || major == 0) - goto close; - - /* Only release the fd if there is only 1 InputInfo left for this major - * and minor, otherwise other InputInfo's are still referencing the fd. */ - pInfo = systemd_logind_find_info_ptr_by_devnum(xf86InputDevs, major, minor); - while (pInfo) { - matches++; - pInfo = systemd_logind_find_info_ptr_by_devnum(pInfo->next, major, minor); - } - if (matches > 1) { - LogMessage(X_INFO, "systemd-logind: not releasing fd for %u:%u, still in use\n", major, minor); - return; - } - - LogMessage(X_INFO, "systemd-logind: releasing fd for %u:%u\n", major, minor); - - dbus_error_init(&error); - - msg = dbus_message_new_method_call("org.freedesktop.login1", info->session, - "org.freedesktop.login1.Session", "ReleaseDevice"); - if (!msg) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major, - DBUS_TYPE_UINT32, &minor, - DBUS_TYPE_INVALID)) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - reply = dbus_connection_send_with_reply_and_block(info->conn, msg, - DBUS_TIMEOUT_USE_DEFAULT, &error); - if (!reply) - LogMessage(X_ERROR, "systemd-logind: failed to release device: %s\n", - error.message); - -cleanup: - if (msg) - dbus_message_unref(msg); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); -close: - if (fd != -1) - close(fd); -} - -int -systemd_logind_controls_session(void) -{ - return logind_info.session ? 1 : 0; -} - -void -systemd_logind_vtenter(void) -{ - struct systemd_logind_info *info = &logind_info; - InputInfoPtr pInfo; - int i; - - if (!info->session) - return; /* Not using systemd-logind */ - - if (!info->active) - return; /* Session not active */ - - if (info->vt_active) - return; /* Already did vtenter */ - - for (i = 0; i < xf86_num_platform_devices; i++) { - if (xf86_platform_devices[i].flags & XF86_PDEV_PAUSED) - break; - } - if (i != xf86_num_platform_devices) - return; /* Some drm nodes are still paused wait for resume */ - - xf86VTEnter(); - info->vt_active = TRUE; - - /* Activate any input devices which were resumed before the drm nodes */ - for (pInfo = xf86InputDevs; pInfo; pInfo = pInfo->next) - if ((pInfo->flags & XI86_SERVER_FD) && pInfo->fd != -1) - xf86EnableInputDeviceForVTSwitch(pInfo); - - /* Do delayed input probing, this must be done after the above enabling */ - xf86InputEnableVTProbe(); -} - -static void -systemd_logind_ack_pause(struct systemd_logind_info *info, - dbus_int32_t minor, dbus_int32_t major) -{ - DBusError error; - DBusMessage *msg = NULL; - DBusMessage *reply = NULL; - - dbus_error_init(&error); - - msg = dbus_message_new_method_call("org.freedesktop.login1", info->session, - "org.freedesktop.login1.Session", "PauseDeviceComplete"); - if (!msg) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major, - DBUS_TYPE_UINT32, &minor, - DBUS_TYPE_INVALID)) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - reply = dbus_connection_send_with_reply_and_block(info->conn, msg, - DBUS_TIMEOUT_USE_DEFAULT, &error); - if (!reply) - LogMessage(X_ERROR, "systemd-logind: failed to ack pause: %s\n", - error.message); - -cleanup: - if (msg) - dbus_message_unref(msg); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); -} - -/* - * Send a message to logind, to pause the drm device - * and ensure the drm_drop_master is done before - * VT_RELDISP when switching VT - */ -void systemd_logind_drop_master(void) -{ - int i; - for (i = 0; i < xf86_num_platform_devices; i++) { - if (xf86_platform_devices[i].flags & XF86_PDEV_SERVER_FD) { - dbus_int32_t major, minor; - struct systemd_logind_info *info = &logind_info; - - xf86_platform_devices[i].flags |= XF86_PDEV_PAUSED; - major = xf86_platform_odev_attributes(i)->major; - minor = xf86_platform_odev_attributes(i)->minor; - systemd_logind_ack_pause(info, minor, major); - } - } -} - -static Bool are_platform_devices_resumed(void) { - int i; - for (i = 0; i < xf86_num_platform_devices; i++) { - if (xf86_platform_devices[i].flags & XF86_PDEV_PAUSED) { - return FALSE; - } - } - return TRUE; -} - -static DBusHandlerResult -message_filter(DBusConnection * connection, DBusMessage * message, void *data) -{ - struct systemd_logind_info *info = data; - struct xf86_platform_device *pdev = NULL; - InputInfoPtr pInfo = NULL; - int ack = 0, pause = 0, fd = -1; - DBusError error; - dbus_int32_t major, minor; - char *pause_str; - - if (strcmp(dbus_message_get_path(message), info->session) != 0) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - dbus_error_init(&error); - - if (dbus_message_is_signal(message, "org.freedesktop.login1.Session", - "PauseDevice")) { - if (!dbus_message_get_args(message, &error, - DBUS_TYPE_UINT32, &major, - DBUS_TYPE_UINT32, &minor, - DBUS_TYPE_STRING, &pause_str, - DBUS_TYPE_INVALID)) { - LogMessage(X_ERROR, "systemd-logind: PauseDevice: %s\n", - error.message); - dbus_error_free(&error); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - if (strcmp(pause_str, "pause") == 0) { - pause = 1; - ack = 1; - } - else if (strcmp(pause_str, "force") == 0) { - pause = 1; - } - else if (strcmp(pause_str, "gone") == 0) { - /* Device removal is handled through udev */ - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - else { - LogMessage(X_WARNING, "systemd-logind: unknown pause type: %s\n", - pause_str); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - } - else if (dbus_message_is_signal(message, "org.freedesktop.login1.Session", - "ResumeDevice")) { - if (!dbus_message_get_args(message, &error, - DBUS_TYPE_UINT32, &major, - DBUS_TYPE_UINT32, &minor, - DBUS_TYPE_UNIX_FD, &fd, - DBUS_TYPE_INVALID)) { - LogMessage(X_ERROR, "systemd-logind: ResumeDevice: %s\n", - error.message); - dbus_error_free(&error); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - } else - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - LogMessage(X_INFO, "systemd-logind: got %s for %u:%u\n", - pause ? "pause" : "resume", major, minor); - - pdev = xf86_find_platform_device_by_devnum(major, minor); - if (!pdev) - pInfo = systemd_logind_find_info_ptr_by_devnum(xf86InputDevs, - major, minor); - if (!pdev && !pInfo) { - LogMessage(X_WARNING, "systemd-logind: could not find dev %u:%u\n", - major, minor); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - if (pause) { - /* Our VT_PROCESS usage guarantees we've already given up the vt */ - info->active = info->vt_active = FALSE; - /* Note the actual vtleave has already been handled by xf86Events.c */ - if (pdev) - pdev->flags |= XF86_PDEV_PAUSED; - else { - close(pInfo->fd); - systemd_logind_set_input_fd_for_all_devs(major, minor, -1, FALSE); - } - if (ack) - systemd_logind_ack_pause(info, major, minor); - } - else { - /* info->vt_active gets set by systemd_logind_vtenter() */ - info->active = TRUE; - - if (pdev) { - pdev->flags &= ~XF86_PDEV_PAUSED; - } else - systemd_logind_set_input_fd_for_all_devs(major, minor, fd, - info->vt_active); - /* Call vtenter if all platform devices are resumed, or if there are no platform device */ - if (are_platform_devices_resumed()) - systemd_logind_vtenter(); - } - return DBUS_HANDLER_RESULT_HANDLED; -} - -static void -connect_hook(DBusConnection *connection, void *data) -{ - struct systemd_logind_info *info = data; - DBusError error; - DBusMessage *msg = NULL; - DBusMessage *reply = NULL; - dbus_int32_t arg; - char *session = NULL; - - dbus_error_init(&error); - - msg = dbus_message_new_method_call("org.freedesktop.login1", - "/org/freedesktop/login1", "org.freedesktop.login1.Manager", - "GetSessionByPID"); - if (!msg) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - arg = getpid(); - if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &arg, - DBUS_TYPE_INVALID)) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - reply = dbus_connection_send_with_reply_and_block(connection, msg, - DBUS_TIMEOUT_USE_DEFAULT, &error); - if (!reply) { - LogMessage(X_ERROR, "systemd-logind: failed to get session: %s\n", - error.message); - goto cleanup; - } - dbus_message_unref(msg); - - if (!dbus_message_get_args(reply, &error, DBUS_TYPE_OBJECT_PATH, &session, - DBUS_TYPE_INVALID)) { - LogMessage(X_ERROR, "systemd-logind: GetSessionByPID: %s\n", - error.message); - goto cleanup; - } - session = XNFstrdup(session); - - dbus_message_unref(reply); - reply = NULL; - - - msg = dbus_message_new_method_call("org.freedesktop.login1", - session, "org.freedesktop.login1.Session", "TakeControl"); - if (!msg) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - arg = FALSE; /* Don't forcibly take over over the session */ - if (!dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &arg, - DBUS_TYPE_INVALID)) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - reply = dbus_connection_send_with_reply_and_block(connection, msg, - DBUS_TIMEOUT_USE_DEFAULT, &error); - if (!reply) { - LogMessage(X_ERROR, "systemd-logind: TakeControl failed: %s\n", - error.message); - goto cleanup; - } - - dbus_bus_add_match(connection, - "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='PauseDevice'", - &error); - if (dbus_error_is_set(&error)) { - LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n", - error.message); - goto cleanup; - } - - dbus_bus_add_match(connection, - "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='ResumeDevice'", - &error); - if (dbus_error_is_set(&error)) { - LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n", - error.message); - goto cleanup; - } - - /* - * HdG: This is not useful with systemd <= 208 since the signal only - * contains invalidated property names there, rather than property, val - * pairs as it should. Instead we just use the first resume / pause now. - */ -#if 0 - snprintf(match, sizeof(match), - "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',path='%s'", - session); - dbus_bus_add_match(connection, match, &error); - if (dbus_error_is_set(&error)) { - LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n", - error.message); - goto cleanup; - } -#endif - - if (!dbus_connection_add_filter(connection, message_filter, info, NULL)) { - LogMessage(X_ERROR, "systemd-logind: could not add filter: %s\n", - error.message); - goto cleanup; - } - - LogMessage(X_INFO, "systemd-logind: took control of session %s\n", - session); - info->conn = connection; - info->session = session; - info->vt_active = info->active = TRUE; /* The server owns the vt during init */ - session = NULL; - -cleanup: - free(session); - if (msg) - dbus_message_unref(msg); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); -} - -static void -systemd_logind_release_control(struct systemd_logind_info *info) -{ - DBusError error; - DBusMessage *msg = NULL; - DBusMessage *reply = NULL; - - dbus_error_init(&error); - - msg = dbus_message_new_method_call("org.freedesktop.login1", - info->session, "org.freedesktop.login1.Session", "ReleaseControl"); - if (!msg) { - LogMessage(X_ERROR, "systemd-logind: out of memory\n"); - goto cleanup; - } - - reply = dbus_connection_send_with_reply_and_block(info->conn, msg, - DBUS_TIMEOUT_USE_DEFAULT, &error); - if (!reply) { - LogMessage(X_ERROR, "systemd-logind: ReleaseControl failed: %s\n", - error.message); - goto cleanup; - } - -cleanup: - if (msg) - dbus_message_unref(msg); - if (reply) - dbus_message_unref(reply); - dbus_error_free(&error); -} - -static void -disconnect_hook(void *data) -{ - struct systemd_logind_info *info = data; - - free(info->session); - info->session = NULL; - info->conn = NULL; -} - -static struct dbus_core_hook core_hook = { - .connect = connect_hook, - .disconnect = disconnect_hook, - .data = &logind_info, -}; - -int -systemd_logind_init(void) -{ - if (!ServerIsNotSeat0() && xf86HasTTYs() && linux_parse_vt_settings(TRUE) && !linux_get_keeptty()) { - LogMessage(X_INFO, - "systemd-logind: logind integration requires -keeptty and " - "-keeptty was not provided, disabling logind integration\n"); - return 1; - } - - return dbus_core_add_hook(&core_hook); -} - -void -systemd_logind_fini(void) -{ - if (logind_info.session) - systemd_logind_release_control(&logind_info); - - dbus_core_remove_hook(&core_hook); -} diff --git a/hw/xfree86/os-support/meson.build b/hw/xfree86/os-support/meson.build deleted file mode 100644 index b6069ee85..000000000 --- a/hw/xfree86/os-support/meson.build +++ /dev/null @@ -1,170 +0,0 @@ -srcs_xorg_os_support = [ - 'bus/nobus.c', - 'shared/posix_tty.c', - 'shared/sigio.c', - 'shared/vidmem.c', -] - -hdrs_xorg_os_support = [ - 'bus/xf86Pci.h', - 'xf86_OSlib.h', - 'xf86_OSproc.h' -] - -os_dep = [] -os_c_args = [] - -if get_option('pciaccess') - srcs_xorg_os_support += 'bus/Pci.c' - if host_machine.system() != 'linux' - srcs_xorg_os_support += 'bus/bsd_pci.c' - endif - if host_machine.cpu() == 'sparc' or host_machine.cpu() == 'sparc64' - srcs_xorg_os_support += 'bus/Sbus.c' - install_data('bus/xf86Sbus.h', install_dir: xorgsdkdir) - endif -endif - -if get_option('agp') == 'auto' - build_agp = cc.has_header('sys/agpio.h') or cc.has_header('sys/agpgart.h') or cc.has_header('linux/agpgart.h') -else - build_agp = get_option('agp') == 'true' -endif - -if host_machine.system() == 'linux' - srcs_xorg_os_support += [ - 'linux/lnx_bell.c', - 'linux/lnx_init.c', - 'linux/lnx_kmod.c', - 'linux/lnx_platform.c', - 'linux/lnx_video.c', - 'misc/SlowBcopy.c', - 'shared/VTsw_usl.c', - ] - if build_agp - srcs_xorg_os_support += 'linux/lnx_agp.c' - else - srcs_xorg_os_support += 'shared/agp_noop.c' - endif - if build_systemd_logind - srcs_xorg_os_support += 'linux/systemd-logind.c' - endif - - # this is ugly because the code is also - if build_apm or build_acpi - srcs_xorg_os_support += 'linux/lnx_apm.c' - if build_acpi - srcs_xorg_os_support += 'linux/lnx_acpi.c' - endif - else - srcs_xorg_os_support += 'shared/pm_noop.c' - endif - -elif host_machine.system() == 'sunos' - srcs_xorg_os_support += [ - 'solaris/sun_apm.c', - 'solaris/sun_bell.c', - 'solaris/sun_init.c', - 'solaris/sun_vid.c', - 'shared/kmod_noop.c', - ] - - if cc.has_header('sys/vt.h') - srcs_xorg_os_support += 'solaris/sun_VTsw.c' - else - srcs_xorg_os_support += 'shared/VTsw_noop.c' - endif - - if build_agp - srcs_xorg_os_support += 'solaris/sun_agp.c' - else - srcs_xorg_os_support += 'shared/agp_noop.c' - endif - - if host_machine.cpu_family() == 'sparc' - srcs_xorg_os_support += 'solaris/solaris-sparcv8plus.S' - elif host_machine.cpu_family() == 'x86_64' - srcs_xorg_os_support += 'solaris/solaris-amd64.S' - elif host_machine.cpu_family() == 'x86' - srcs_xorg_os_support += 'solaris/solaris-ia32.S' - else - error('Unknown CPU family for Solaris build') - endif - -elif host_machine.system().endswith('bsd') - srcs_xorg_os_support += [ - 'bsd/bsd_VTsw.c', - 'bsd/bsd_bell.c', - 'bsd/bsd_init.c', - 'shared/pm_noop.c' - ] - - if host_machine.cpu_family() == 'x86_64' - srcs_xorg_os_support += 'bsd/i386_video.c' - if host_machine.system() == 'netbsd' - os_dep += cc.find_library('x86_64') - elif host_machine.system() == 'openbsd' - os_dep += cc.find_library('amd64') - endif - elif host_machine.cpu_family() == 'x86' - srcs_xorg_os_support += 'bsd/i386_video.c' - if host_machine.system() == 'netbsd' or host_machine.system() == 'openbsd' - os_dep += cc.find_library('i386') - endif - elif host_machine.cpu_family() == 'arm' - srcs_xorg_os_support += 'bsd/arm_video.c' - elif host_machine.cpu_family() == 'powerpc' - srcs_xorg_os_support += 'bsd/ppc_video.c' - elif host_machine.cpu_family() == 'sparc64' - srcs_xorg_os_support += 'bsd/sparc64_video.c' - srcs_xorg_os_support += 'shared/ioperm_noop.c' - elif host_machine.cpu_family() == 'alpha' - srcs_xorg_os_support += 'bsd/alpha_video.c' - if host_machine.system() == 'freebsd' - os_dep += cc.find_library('io') - elif host_machine.system() == 'netbsd' - os_c_args += '-DUSE_ALPHA_PIO' - endif - endif - - if host_machine.system() == 'freebsd' - srcs_xorg_os_support += 'bsd/bsd_kmod.c' - else - srcs_xorg_os_support += 'shared/kmod_noop.c' - endif - - if build_agp - srcs_xorg_os_support += 'linux/lnx_agp.c' - else - srcs_xorg_os_support += 'shared/agp_noop.c' - endif -else - # stub ossupport - srcs_xorg_os_support += [ - 'shared/VTsw_noop.c', - 'shared/agp_noop.c', - 'shared/ioperm_noop.c', - 'shared/kmod_noop.c', - 'shared/pm_noop.c', - 'shared/vidmem.c', - 'shared/posix_tty.c', - 'shared/sigio.c', - 'stub/stub_bell.c', - 'stub/stub_init.c', - 'stub/stub_video.c', - ] -endif - -xorg_os_support = static_library('xorg_os_support', - srcs_xorg_os_support, - include_directories: [inc, xorg_inc], - dependencies: [ - common_dep, - dbus_dep, - libdrm_dep, - os_dep, - ], - c_args: xorg_c_args + os_c_args, -) - -install_data(hdrs_xorg_os_support, install_dir: xorgsdkdir) diff --git a/hw/xfree86/os-support/misc/SlowBcopy.c b/hw/xfree86/os-support/misc/SlowBcopy.c deleted file mode 100644 index 9d82c71bf..000000000 --- a/hw/xfree86/os-support/misc/SlowBcopy.c +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - for Alpha Linux -*******************************************************************************/ - -/* - * Create a dependency that should be immune from the effect of register - * renaming as is commonly seen in superscalar processors. This should - * insert a minimum of 100-ns delays between reads/writes at clock rates - * up to 100 MHz---GGL - * - * Slowbcopy(char *src, char *dst, int count) - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "compiler.h" - -static int really_slow_bcopy; - -void -xf86SetReallySlowBcopy(void) -{ - really_slow_bcopy = 1; -} - -#if defined(__i386__) || defined(__amd64__) -static void -xf86_really_slow_bcopy(unsigned char *src, unsigned char *dst, int len) -{ - while (len--) { - *dst++ = *src++; - outb(0x80, 0x00); - } -} -#endif - -/* The outb() isn't needed on my machine, but who knows ... -- ost */ -void -xf86SlowBcopy(unsigned char *src, unsigned char *dst, int len) -{ -#if defined(__i386__) || defined(__amd64__) - if (really_slow_bcopy) { - xf86_really_slow_bcopy(src, dst, len); - return; - } -#endif - while (len--) - *dst++ = *src++; -} - -#ifdef __alpha__ - -#ifdef __linux__ - -unsigned long _bus_base(void); - -#define useSparse() (!_bus_base()) - -#define SPARSE (7) - -#else - -#define useSparse() 0 - -#define SPARSE 0 - -#endif - -void -xf86SlowBCopyFromBus(unsigned char *src, unsigned char *dst, int count) -{ - if (useSparse()) { - unsigned long addr; - long result; - - addr = (unsigned long) src; - while (count) { - result = *(volatile int *) addr; - result >>= ((addr >> SPARSE) & 3) * 8; - *dst++ = (unsigned char) (0xffUL & result); - addr += 1 << SPARSE; - count--; - outb(0x80, 0x00); - } - } - else - xf86SlowBcopy(src, dst, count); -} - -void -xf86SlowBCopyToBus(unsigned char *src, unsigned char *dst, int count) -{ - if (useSparse()) { - unsigned long addr; - - addr = (unsigned long) dst; - while (count) { - *(volatile unsigned int *) addr = - (unsigned short) (*src) * 0x01010101; - src++; - addr += 1 << SPARSE; - count--; - outb(0x80, 0x00); - } - } - else - xf86SlowBcopy(src, dst, count); -} -#endif diff --git a/hw/xfree86/os-support/shared/VTsw_noop.c b/hw/xfree86/os-support/shared/VTsw_noop.c deleted file mode 100644 index a75d134b4..000000000 --- a/hw/xfree86/os-support/shared/VTsw_noop.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of David Wexelblat not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. David Wexelblat makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -/* - * No-op functions for OSs without VTs - */ - -Bool -xf86VTSwitchPending(void) -{ - return FALSE; -} - -Bool -xf86VTSwitchAway(void) -{ - return FALSE; -} - -Bool -xf86VTSwitchTo(void) -{ - return TRUE; -} - -Bool -xf86VTActivate(int vtno) -{ - return TRUE; -} diff --git a/hw/xfree86/os-support/shared/VTsw_usl.c b/hw/xfree86/os-support/shared/VTsw_usl.c deleted file mode 100644 index 64402616e..000000000 --- a/hw/xfree86/os-support/shared/VTsw_usl.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of David Wexelblat not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. David Wexelblat makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -/* - * Handle the VT-switching interface for OSs that use USL-style ioctl()s - * (the sysv, sco, and linux subdirs). - */ - -/* - * This function is the signal handler for the VT-switching signal. It - * is only referenced inside the OS-support layer. - */ -void -xf86VTRequest(int sig) -{ - OsSignal(sig, (void (*)(int)) xf86VTRequest); - xf86Info.vtRequestsPending = TRUE; - return; -} - -Bool -xf86VTSwitchPending(void) -{ - return xf86Info.vtRequestsPending ? TRUE : FALSE; -} - -Bool -xf86VTSwitchAway(void) -{ - xf86Info.vtRequestsPending = FALSE; - if (ioctl(xf86Info.consoleFd, VT_RELDISP, 1) < 0) - return FALSE; - else - return TRUE; -} - -Bool -xf86VTSwitchTo(void) -{ - xf86Info.vtRequestsPending = FALSE; - if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) - return FALSE; - else - return TRUE; -} - -Bool -xf86VTActivate(int vtno) -{ -#ifdef VT_ACTIVATE - if (ioctl(xf86Info.consoleFd, VT_ACTIVATE, vtno) < 0) { - return FALSE; - } -#endif - return TRUE; -} diff --git a/hw/xfree86/os-support/shared/agp_noop.c b/hw/xfree86/os-support/shared/agp_noop.c deleted file mode 100644 index da486c051..000000000 --- a/hw/xfree86/os-support/shared/agp_noop.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2000-2003 by The XFree86 Project, 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). - */ - -/* - * Abstraction of the AGP GART interface. Stubs for platforms without - * AGP GART support. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -Bool -xf86GARTCloseScreen(int screenNum) -{ - return FALSE; -} - -Bool -xf86AgpGARTSupported(void) -{ - return FALSE; -} - -AgpInfoPtr -xf86GetAGPInfo(int screenNum) -{ - return NULL; -} - -Bool -xf86AcquireGART(int screenNum) -{ - return FALSE; -} - -Bool -xf86ReleaseGART(int screenNum) -{ - return FALSE; -} - -int -xf86AllocateGARTMemory(int screenNum, unsigned long size, int type, - unsigned long *physical) -{ - return -1; -} - -Bool -xf86DeallocateGARTMemory(int screenNum, int key) -{ - return FALSE; -} - -Bool -xf86BindGARTMemory(int screenNum, int key, unsigned long offset) -{ - return FALSE; -} - -Bool -xf86UnbindGARTMemory(int screenNum, int key) -{ - return FALSE; -} - -Bool -xf86EnableAGP(int screenNum, CARD32 mode) -{ - return FALSE; -} diff --git a/hw/xfree86/os-support/shared/ioperm_noop.c b/hw/xfree86/os-support/shared/ioperm_noop.c deleted file mode 100644 index de5fb9ba4..000000000 --- a/hw/xfree86/os-support/shared/ioperm_noop.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 1993 by David Wexelblat - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of David Wexelblat not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. David Wexelblat makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL DAVID WEXELBLAT BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - */ - -/* - * Some platforms don't bother with I/O permissions, - * or the permissions are implicit with opening/enabling the console. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -Bool -xf86EnableIO(void) -{ - return TRUE; -} - -void -xf86DisableIO(void) -{ - return; -} diff --git a/hw/xfree86/os-support/shared/kmod_noop.c b/hw/xfree86/os-support/shared/kmod_noop.c deleted file mode 100644 index 0437bc564..000000000 --- a/hw/xfree86/os-support/shared/kmod_noop.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2000 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86_OSproc.h" - -int -xf86LoadKernelModule(const char *pathname) -{ - (void) pathname; - return 0; /* failure */ -} diff --git a/hw/xfree86/os-support/shared/platform_noop.c b/hw/xfree86/os-support/shared/platform_noop.c deleted file mode 100644 index 199ae5e8e..000000000 --- a/hw/xfree86/os-support/shared/platform_noop.c +++ /dev/null @@ -1,23 +0,0 @@ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifdef XSERVER_PLATFORM_BUS -/* noop platform device support */ -#include "xf86_OSproc.h" - -#include "xf86.h" -#include "xf86platformBus.h" - -Bool -xf86PlatformDeviceCheckBusID(struct xf86_platform_device *device, const char *busid) -{ - return FALSE; -} - -void xf86PlatformDeviceProbe(struct OdevAttributes *attribs) -{ - -} -#endif diff --git a/hw/xfree86/os-support/shared/pm_noop.c b/hw/xfree86/os-support/shared/pm_noop.c deleted file mode 100644 index 1d6f0789d..000000000 --- a/hw/xfree86/os-support/shared/pm_noop.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2000 by The XFree86 Project, 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). - */ - -/* Stubs for the OS-support layer power-management functions. */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" - -PMClose -xf86OSPMOpen(void) -{ - return NULL; -} diff --git a/hw/xfree86/os-support/shared/posix_tty.c b/hw/xfree86/os-support/shared/posix_tty.c deleted file mode 100644 index 0cb9788cc..000000000 --- a/hw/xfree86/os-support/shared/posix_tty.c +++ /dev/null @@ -1,629 +0,0 @@ -/* - * Copyright 1993-2003 by The XFree86 Project, 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 XFREE86 PROJECT 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 XFree86 Project 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 - * XFree86 Project. - */ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -static int -GetBaud(int baudrate) -{ -#ifdef B300 - if (baudrate == 300) - return B300; -#endif -#ifdef B1200 - if (baudrate == 1200) - return B1200; -#endif -#ifdef B2400 - if (baudrate == 2400) - return B2400; -#endif -#ifdef B4800 - if (baudrate == 4800) - return B4800; -#endif -#ifdef B9600 - if (baudrate == 9600) - return B9600; -#endif -#ifdef B19200 - if (baudrate == 19200) - return B19200; -#endif -#ifdef B38400 - if (baudrate == 38400) - return B38400; -#endif -#ifdef B57600 - if (baudrate == 57600) - return B57600; -#endif -#ifdef B115200 - if (baudrate == 115200) - return B115200; -#endif -#ifdef B230400 - if (baudrate == 230400) - return B230400; -#endif -#ifdef B460800 - if (baudrate == 460800) - return B460800; -#endif - return 0; -} - -int -xf86OpenSerial(XF86OptionPtr options) -{ - struct termios t; - int fd, i; - char *dev; - - dev = xf86SetStrOption(options, "Device", NULL); - if (!dev) { - xf86Msg(X_ERROR, "xf86OpenSerial: No Device specified.\n"); - return -1; - } - - fd = xf86CheckIntOption(options, "fd", -1); - - if (fd == -1) - SYSCALL(fd = open(dev, O_RDWR | O_NONBLOCK)); - - if (fd == -1) { - xf86Msg(X_ERROR, - "xf86OpenSerial: Cannot open device %s\n\t%s.\n", - dev, strerror(errno)); - free(dev); - return -1; - } - - if (!isatty(fd)) { - /* Allow non-tty devices to be opened. */ - free(dev); - return fd; - } - - /* set up default port parameters */ - SYSCALL(tcgetattr(fd, &t)); - t.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR - | IGNCR | ICRNL | IXON); - t.c_oflag &= ~OPOST; - t.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); - t.c_cflag &= ~(CSIZE | PARENB); - t.c_cflag |= CS8 | CLOCAL; - - cfsetispeed(&t, B9600); - cfsetospeed(&t, B9600); - t.c_cc[VMIN] = 1; - t.c_cc[VTIME] = 0; - - SYSCALL(tcsetattr(fd, TCSANOW, &t)); - - if (xf86SetSerial(fd, options) == -1) { - SYSCALL(close(fd)); - free(dev); - return -1; - } - - SYSCALL(i = fcntl(fd, F_GETFL, 0)); - if (i == -1) { - SYSCALL(close(fd)); - free(dev); - return -1; - } - i &= ~O_NONBLOCK; - SYSCALL(i = fcntl(fd, F_SETFL, i)); - if (i == -1) { - SYSCALL(close(fd)); - free(dev); - return -1; - } - free(dev); - return fd; -} - -int -xf86SetSerial(int fd, XF86OptionPtr options) -{ - struct termios t; - int val; - char *s; - int baud, r; - - if (fd < 0) - return -1; - - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; - - SYSCALL(tcgetattr(fd, &t)); - - if ((val = xf86SetIntOption(options, "BaudRate", 0))) { - if ((baud = GetBaud(val))) { - cfsetispeed(&t, baud); - cfsetospeed(&t, baud); - } - else { - xf86Msg(X_ERROR, "Invalid Option BaudRate value: %d\n", val); - return -1; - } - } - - if ((val = xf86SetIntOption(options, "StopBits", 0))) { - switch (val) { - case 1: - t.c_cflag &= ~(CSTOPB); - break; - case 2: - t.c_cflag |= CSTOPB; - break; - default: - xf86Msg(X_ERROR, "Invalid Option StopBits value: %d\n", val); - return -1; - break; - } - } - - if ((val = xf86SetIntOption(options, "DataBits", 0))) { - switch (val) { - case 5: - t.c_cflag &= ~(CSIZE); - t.c_cflag |= CS5; - break; - case 6: - t.c_cflag &= ~(CSIZE); - t.c_cflag |= CS6; - break; - case 7: - t.c_cflag &= ~(CSIZE); - t.c_cflag |= CS7; - break; - case 8: - t.c_cflag &= ~(CSIZE); - t.c_cflag |= CS8; - break; - default: - xf86Msg(X_ERROR, "Invalid Option DataBits value: %d\n", val); - return -1; - break; - } - } - - if ((s = xf86SetStrOption(options, "Parity", NULL))) { - if (xf86NameCmp(s, "Odd") == 0) { - t.c_cflag |= PARENB | PARODD; - } - else if (xf86NameCmp(s, "Even") == 0) { - t.c_cflag |= PARENB; - t.c_cflag &= ~(PARODD); - } - else if (xf86NameCmp(s, "None") == 0) { - t.c_cflag &= ~(PARENB); - } - else { - xf86Msg(X_ERROR, "Invalid Option Parity value: %s\n", s); - free(s); - return -1; - } - free(s); - } - - if ((val = xf86SetIntOption(options, "Vmin", -1)) != -1) { - t.c_cc[VMIN] = val; - } - if ((val = xf86SetIntOption(options, "Vtime", -1)) != -1) { - t.c_cc[VTIME] = val; - } - - if ((s = xf86SetStrOption(options, "FlowControl", NULL))) { - xf86MarkOptionUsedByName(options, "FlowControl"); - if (xf86NameCmp(s, "Xoff") == 0) { - t.c_iflag |= IXOFF; - } - else if (xf86NameCmp(s, "Xon") == 0) { - t.c_iflag |= IXON; - } - else if (xf86NameCmp(s, "XonXoff") == 0) { - t.c_iflag |= IXON | IXOFF; - } - else if (xf86NameCmp(s, "None") == 0) { - t.c_iflag &= ~(IXON | IXOFF); - } - else { - xf86Msg(X_ERROR, "Invalid Option FlowControl value: %s\n", s); - free(s); - return -1; - } - free(s); - } - - if ((xf86SetBoolOption(options, "ClearDTR", FALSE))) { -#ifdef CLEARDTR_SUPPORT -#if defined(TIOCMBIC) - val = TIOCM_DTR; - SYSCALL(ioctl(fd, TIOCMBIC, &val)); -#else - SYSCALL(ioctl(fd, TIOCCDTR, NULL)); -#endif -#else - xf86Msg(X_WARNING, "Option ClearDTR not supported on this OS\n"); - return -1; -#endif - xf86MarkOptionUsedByName(options, "ClearDTR"); - } - - if ((xf86SetBoolOption(options, "ClearRTS", FALSE))) { - xf86Msg(X_WARNING, "Option ClearRTS not supported on this OS\n"); - return -1; - xf86MarkOptionUsedByName(options, "ClearRTS"); - } - - SYSCALL(r = tcsetattr(fd, TCSANOW, &t)); - return r; -} - -int -xf86SetSerialSpeed(int fd, int speed) -{ - struct termios t; - int baud, r; - - if (fd < 0) - return -1; - - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; - - SYSCALL(tcgetattr(fd, &t)); - - if ((baud = GetBaud(speed))) { - cfsetispeed(&t, baud); - cfsetospeed(&t, baud); - } - else { - xf86Msg(X_ERROR, "Invalid Option BaudRate value: %d\n", speed); - return -1; - } - - SYSCALL(r = tcsetattr(fd, TCSANOW, &t)); - return r; -} - -int -xf86ReadSerial(int fd, void *buf, int count) -{ - int r; - int i; - - SYSCALL(r = read(fd, buf, count)); - DebugF("ReadingSerial: 0x%x", (unsigned char) *(((unsigned char *) buf))); - for (i = 1; i < r; i++) - DebugF(", 0x%x", (unsigned char) *(((unsigned char *) buf) + i)); - DebugF("\n"); - return r; -} - -int -xf86WriteSerial(int fd, const void *buf, int count) -{ - int r; - int i; - - DebugF("WritingSerial: 0x%x", (unsigned char) *(((unsigned char *) buf))); - for (i = 1; i < count; i++) - DebugF(", 0x%x", (unsigned char) *(((unsigned char *) buf) + i)); - DebugF("\n"); - SYSCALL(r = write(fd, buf, count)); - return r; -} - -int -xf86CloseSerial(int fd) -{ - int r; - - SYSCALL(r = close(fd)); - return r; -} - -int -xf86WaitForInput(int fd, int timeout) -{ - int r; - struct pollfd poll_fd; - - poll_fd.fd = fd; - poll_fd.events = POLLIN; - - /* convert microseconds to milliseconds */ - timeout = (timeout + 999) / 1000; - - if (fd >= 0) { - SYSCALL(r = xserver_poll(&poll_fd, 1, timeout)); - } - else { - SYSCALL(r = xserver_poll(&poll_fd, 0, timeout)); - } - xf86ErrorFVerb(9, "poll returned %d\n", r); - return r; -} - -int -xf86SerialSendBreak(int fd, int duration) -{ - int r; - - SYSCALL(r = tcsendbreak(fd, duration)); - return r; - -} - -int -xf86FlushInput(int fd) -{ - struct pollfd poll_fd; - /* this needs to be big enough to flush an evdev event. */ - char c[256]; - - DebugF("FlushingSerial\n"); - if (tcflush(fd, TCIFLUSH) == 0) - return 0; - - poll_fd.fd = fd; - poll_fd.events = POLLIN; - while (xserver_poll(&poll_fd, 1, 0) > 0) { - if (read(fd, &c, sizeof(c)) < 1) - return 0; - } - return 0; -} - -static struct states { - int xf; - int os; -} modemStates[] = { -#ifdef TIOCM_LE - { - XF86_M_LE, TIOCM_LE}, -#endif -#ifdef TIOCM_DTR - { - XF86_M_DTR, TIOCM_DTR}, -#endif -#ifdef TIOCM_RTS - { - XF86_M_RTS, TIOCM_RTS}, -#endif -#ifdef TIOCM_ST - { - XF86_M_ST, TIOCM_ST}, -#endif -#ifdef TIOCM_SR - { - XF86_M_SR, TIOCM_SR}, -#endif -#ifdef TIOCM_CTS - { - XF86_M_CTS, TIOCM_CTS}, -#endif -#ifdef TIOCM_CAR - { - XF86_M_CAR, TIOCM_CAR}, -#elif defined(TIOCM_CD) - { - XF86_M_CAR, TIOCM_CD}, -#endif -#ifdef TIOCM_RNG - { - XF86_M_RNG, TIOCM_RNG}, -#elif defined(TIOCM_RI) - { - XF86_M_CAR, TIOCM_RI}, -#endif -#ifdef TIOCM_DSR - { - XF86_M_DSR, TIOCM_DSR}, -#endif -}; - -static int numStates = ARRAY_SIZE(modemStates); - -static int -xf2osState(int state) -{ - int i; - int ret = 0; - - for (i = 0; i < numStates; i++) - if (state & modemStates[i].xf) - ret |= modemStates[i].os; - return ret; -} - -static int -os2xfState(int state) -{ - int i; - int ret = 0; - - for (i = 0; i < numStates; i++) - if (state & modemStates[i].os) - ret |= modemStates[i].xf; - return ret; -} - -static int -getOsStateMask(void) -{ - int i; - int ret = 0; - - for (i = 0; i < numStates; i++) - ret |= modemStates[i].os; - return ret; -} - -static int osStateMask = 0; - -int -xf86SetSerialModemState(int fd, int state) -{ - int ret; - int s; - - if (fd < 0) - return -1; - - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; - -#ifndef TIOCMGET - return -1; -#else - if (!osStateMask) - osStateMask = getOsStateMask(); - - state = xf2osState(state); - SYSCALL((ret = ioctl(fd, TIOCMGET, &s))); - if (ret < 0) - return -1; - s &= ~osStateMask; - s |= state; - SYSCALL((ret = ioctl(fd, TIOCMSET, &s))); - if (ret < 0) - return -1; - else - return 0; -#endif -} - -int -xf86GetSerialModemState(int fd) -{ - int ret; - int s; - - if (fd < 0) - return -1; - - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; - -#ifndef TIOCMGET - return -1; -#else - SYSCALL((ret = ioctl(fd, TIOCMGET, &s))); - if (ret < 0) - return -1; - return os2xfState(s); -#endif -} - -int -xf86SerialModemSetBits(int fd, int bits) -{ - int ret; - int s; - - if (fd < 0) - return -1; - - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; - -#ifndef TIOCMGET - return -1; -#else - s = xf2osState(bits); - SYSCALL((ret = ioctl(fd, TIOCMBIS, &s))); - return ret; -#endif -} - -int -xf86SerialModemClearBits(int fd, int bits) -{ - int ret; - int s; - - if (fd < 0) - return -1; - - /* Don't try to set parameters for non-tty devices. */ - if (!isatty(fd)) - return 0; - -#ifndef TIOCMGET - return -1; -#else - s = xf2osState(bits); - SYSCALL((ret = ioctl(fd, TIOCMBIC, &s))); - return ret; -#endif -} diff --git a/hw/xfree86/os-support/shared/sigio.c b/hw/xfree86/os-support/shared/sigio.c deleted file mode 100644 index ad8af6093..000000000 --- a/hw/xfree86/os-support/shared/sigio.c +++ /dev/null @@ -1,295 +0,0 @@ -/* sigio.c -- Support for SIGIO handler installation and removal - * Created: Thu Jun 3 15:39:18 1999 by faith@precisioninsight.com - * - * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Authors: Rickard E. (Rik) Faith - */ -/* - * Copyright (c) 2002 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "inputstr.h" - -#ifdef HAVE_STROPTS_H -#include -#endif - -#ifdef MAXDEVICES -/* MAXDEVICES represents the maximum number of input devices usable - * at the same time plus one entry for DRM support. - */ -#define MAX_FUNCS (MAXDEVICES + 1) -#else -#define MAX_FUNCS 16 -#endif - -typedef struct _xf86SigIOFunc { - void (*f) (int, void *); - int fd; - void *closure; -} Xf86SigIOFunc; - -static Xf86SigIOFunc xf86SigIOFuncs[MAX_FUNCS]; -static int xf86SigIOMax; -static struct pollfd *xf86SigIOFds; -static int xf86SigIONum; - -static Bool -xf86SigIOAdd(int fd) -{ - struct pollfd *n; - - n = realloc(xf86SigIOFds, (xf86SigIONum + 1) * sizeof (struct pollfd)); - if (!n) - return FALSE; - - n[xf86SigIONum].fd = fd; - n[xf86SigIONum].events = POLLIN; - xf86SigIONum++; - xf86SigIOFds = n; - return TRUE; -} - -static void -xf86SigIORemove(int fd) -{ - int i; - for (i = 0; i < xf86SigIONum; i++) - if (xf86SigIOFds[i].fd == fd) { - memmove(&xf86SigIOFds[i], &xf86SigIOFds[i+1], (xf86SigIONum - i - 1) * sizeof (struct pollfd)); - xf86SigIONum--; - break; - } -} - -/* - * SIGIO gives no way of discovering which fd signalled, select - * to discover - */ -static void -xf86SIGIO(int sig) -{ - int i, f; - int save_errno = errno; /* do not clobber the global errno */ - int r; - - inSignalContext = TRUE; - - SYSCALL(r = xserver_poll(xf86SigIOFds, xf86SigIONum, 0)); - for (f = 0; r > 0 && f < xf86SigIONum; f++) { - if (xf86SigIOFds[f].revents & POLLIN) { - for (i = 0; i < xf86SigIOMax; i++) - if (xf86SigIOFuncs[i].f && xf86SigIOFuncs[i].fd == xf86SigIOFds[f].fd) - (*xf86SigIOFuncs[i].f) (xf86SigIOFuncs[i].fd, - xf86SigIOFuncs[i].closure); - r--; - } - } - if (r > 0) { - xf86Msg(X_ERROR, "SIGIO %d descriptors not handled\n", r); - } - /* restore global errno */ - errno = save_errno; - - inSignalContext = FALSE; -} - -static int -xf86IsPipe(int fd) -{ - struct stat buf; - - if (fstat(fd, &buf) < 0) - return 0; - return S_ISFIFO(buf.st_mode); -} - -static void -block_sigio(void) -{ - sigset_t set; - - sigemptyset(&set); - sigaddset(&set, SIGIO); - xthread_sigmask(SIG_BLOCK, &set, NULL); -} - -static void -release_sigio(void) -{ - sigset_t set; - - sigemptyset(&set); - sigaddset(&set, SIGIO); - xthread_sigmask(SIG_UNBLOCK, &set, NULL); -} - -int -xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), void *closure) -{ - struct sigaction sa; - struct sigaction osa; - int i; - int installed = FALSE; - - for (i = 0; i < MAX_FUNCS; i++) { - if (!xf86SigIOFuncs[i].f) { - if (xf86IsPipe(fd)) - return 0; - block_sigio(); -#ifdef O_ASYNC - if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC) == -1) { - xf86Msg(X_WARNING, "fcntl(%d, O_ASYNC): %s\n", - fd, strerror(errno)); - } - else { - if (fcntl(fd, F_SETOWN, getpid()) == -1) { - xf86Msg(X_WARNING, "fcntl(%d, F_SETOWN): %s\n", - fd, strerror(errno)); - } - else { - installed = TRUE; - } - } -#endif -#if defined(I_SETSIG) && defined(HAVE_ISASTREAM) - /* System V Streams - used on Solaris for input devices */ - if (!installed && isastream(fd)) { - if (ioctl(fd, I_SETSIG, S_INPUT | S_ERROR | S_HANGUP) == -1) { - xf86Msg(X_WARNING, "fcntl(%d, I_SETSIG): %s\n", - fd, strerror(errno)); - } - else { - installed = TRUE; - } - } -#endif - if (!installed) { - release_sigio(); - return 0; - } - sigemptyset(&sa.sa_mask); - sigaddset(&sa.sa_mask, SIGIO); - sa.sa_flags = SA_RESTART; - sa.sa_handler = xf86SIGIO; - sigaction(SIGIO, &sa, &osa); - xf86SigIOFuncs[i].fd = fd; - xf86SigIOFuncs[i].closure = closure; - xf86SigIOFuncs[i].f = f; - if (i >= xf86SigIOMax) - xf86SigIOMax = i + 1; - xf86SigIOAdd(fd); - release_sigio(); - return 1; - } - /* Allow overwriting of the closure and callback */ - else if (xf86SigIOFuncs[i].fd == fd) { - xf86SigIOFuncs[i].closure = closure; - xf86SigIOFuncs[i].f = f; - return 1; - } - } - return 0; -} - -int -xf86RemoveSIGIOHandler(int fd) -{ - struct sigaction sa; - struct sigaction osa; - int i; - int max; - int ret; - - max = 0; - ret = 0; - for (i = 0; i < MAX_FUNCS; i++) { - if (xf86SigIOFuncs[i].f) { - if (xf86SigIOFuncs[i].fd == fd) { - xf86SigIOFuncs[i].f = 0; - xf86SigIOFuncs[i].fd = 0; - xf86SigIOFuncs[i].closure = 0; - xf86SigIORemove(fd); - ret = 1; - } - else { - max = i + 1; - } - } - } - if (ret) { -#ifdef O_ASYNC - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_ASYNC); -#endif -#if defined(I_SETSIG) && defined(HAVE_ISASTREAM) - if (isastream(fd)) { - if (ioctl(fd, I_SETSIG, 0) == -1) { - xf86Msg(X_WARNING, "fcntl(%d, I_SETSIG, 0): %s\n", - fd, strerror(errno)); - } - } -#endif - xf86SigIOMax = max; - if (!max) { - sigemptyset(&sa.sa_mask); - sigaddset(&sa.sa_mask, SIGIO); - sa.sa_flags = 0; - sa.sa_handler = SIG_IGN; - sigaction(SIGIO, &sa, &osa); - } - } - return ret; -} diff --git a/hw/xfree86/os-support/shared/sigiostubs.c b/hw/xfree86/os-support/shared/sigiostubs.c deleted file mode 100644 index d1792e8ac..000000000 --- a/hw/xfree86/os-support/shared/sigiostubs.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 1999-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -int -xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), void *closure) -{ - return 0; -} - -int -xf86RemoveSIGIOHandler(int fd) -{ - return 0; -} diff --git a/hw/xfree86/os-support/shared/vidmem.c b/hw/xfree86/os-support/shared/vidmem.c deleted file mode 100644 index a6bf677f5..000000000 --- a/hw/xfree86/os-support/shared/vidmem.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 1993-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "input.h" -#include "scrnintstr.h" - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -/* - * This file contains the common part of the video memory mapping functions - */ - -static VidMemInfo vidMemInfo = { FALSE, }; - -void -xf86InitVidMem(void) -{ - if (!vidMemInfo.initialised) { - memset(&vidMemInfo, 0, sizeof(VidMemInfo)); - xf86OSInitVidMem(&vidMemInfo); - } -} diff --git a/hw/xfree86/os-support/solaris/solaris-amd64.S b/hw/xfree86/os-support/solaris/solaris-amd64.S deleted file mode 100644 index 4cc0642dd..000000000 --- a/hw/xfree86/os-support/solaris/solaris-amd64.S +++ /dev/null @@ -1,67 +0,0 @@ -/ Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. -/ -/ Permission is hereby granted, free of charge, to any person obtaining a -/ copy of this software and associated documentation files (the "Software"), -/ to deal in the Software without restriction, including without limitation -/ the rights to use, copy, modify, merge, publish, distribute, sublicense, -/ and/or sell copies of the Software, and to permit persons to whom the -/ Software is furnished to do so, subject to the following conditions: -/ -/ The above copyright notice and this permission notice (including the next -/ paragraph) shall be included in all copies or substantial portions of the -/ Software. -/ -/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -/ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -/ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -/ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -/ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -/ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -/ DEALINGS IN THE SOFTWARE. - -#ifdef INLINE_ASM -#define FUNCTION_START(f,n) .inline f,n -#define FUNCTION_END(f) .end -#else -#define _ASM -#include -#define FUNCTION_START(f,n) ENTRY(f) -#define FUNCTION_END(f) ret; SET_SIZE(f) -#endif - - FUNCTION_START(inb,4) - movq %rdi, %rdx - xorq %rax, %rax - inb (%dx) - FUNCTION_END(inb) - - FUNCTION_START(inw,4) - movq %rdi, %rdx - xorq %rax, %rax - inw (%dx) - FUNCTION_END(inw) - - FUNCTION_START(inl,4) - movq %rdi, %rdx - xorq %rax, %rax - inl (%dx) - FUNCTION_END(inl) - - FUNCTION_START(outb,8) - movq %rdi, %rdx - movq %rsi, %rax - outb (%dx) - FUNCTION_END(outb) - - FUNCTION_START(outw,8) - movq %rdi, %rdx - movq %rsi, %rax - outw (%dx) - FUNCTION_END(outw) - - FUNCTION_START(outl,8) - movq %rdi, %rdx - movq %rsi, %rax - outl (%dx) - FUNCTION_END(outl) - diff --git a/hw/xfree86/os-support/solaris/solaris-ia32.S b/hw/xfree86/os-support/solaris/solaris-ia32.S deleted file mode 100644 index 74d787d31..000000000 --- a/hw/xfree86/os-support/solaris/solaris-ia32.S +++ /dev/null @@ -1,67 +0,0 @@ -/ Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. -/ -/ Permission is hereby granted, free of charge, to any person obtaining a -/ copy of this software and associated documentation files (the "Software"), -/ to deal in the Software without restriction, including without limitation -/ the rights to use, copy, modify, merge, publish, distribute, sublicense, -/ and/or sell copies of the Software, and to permit persons to whom the -/ Software is furnished to do so, subject to the following conditions: -/ -/ The above copyright notice and this permission notice (including the next -/ paragraph) shall be included in all copies or substantial portions of the -/ Software. -/ -/ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -/ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -/ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -/ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -/ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -/ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -/ DEALINGS IN THE SOFTWARE. - -#ifdef INLINE_ASM -#define FUNCTION_START(f,n) .inline f,n -#define FUNCTION_END(f) .end -#else -#define _ASM -#include -#define FUNCTION_START(f,n) ENTRY(f) -#define FUNCTION_END(f) ret; SET_SIZE(f) -#endif - - FUNCTION_START(inb,4) - movl (%esp), %edx - xorl %eax, %eax - inb (%dx) - FUNCTION_END(inb) - - FUNCTION_START(inw,4) - movl (%esp), %edx - xorl %eax, %eax - inw (%dx) - FUNCTION_END(inw) - - FUNCTION_START(inl,4) - movl (%esp), %edx - xorl %eax, %eax - inl (%dx) - FUNCTION_END(inl) - - FUNCTION_START(outb,8) - movl (%esp), %edx - movl 4(%esp), %eax - outb (%dx) - FUNCTION_END(outb) - - FUNCTION_START(outw,8) - movl (%esp), %edx - movl 4(%esp), %eax - outw (%dx) - FUNCTION_END(outw) - - FUNCTION_START(outl,8) - movl (%esp), %edx - movl 4(%esp), %eax - outl (%dx) - FUNCTION_END(outl) - diff --git a/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S b/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S deleted file mode 100644 index 0ecafb352..000000000 --- a/hw/xfree86/os-support/solaris/solaris-sparcv8plus.S +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef INLINE_ASM -#define FUNCTION_START(f,n) .inline f,n -#define FUNCTION_END(f) .end -#else -#define _ASM -#include -#define FUNCTION_START(f,n) ENTRY(f) -#define FUNCTION_END(f) retl; nop; SET_SIZE(f) -#endif - -/* Converted from common/compiler.h gcc inline format to Sun cc inline - * format by Kenjiro Tsuji - * - * The value 0x88 means ASI_PRIMARY_LITTLE. - * The store or load to/from the address space will be done - * as little-endian. In the original xrog code, the value - * is defined as the macro ASI_PL. - * - * In the original xorg code, "membar #StoreStore|#StoreLoad" - * is directly implemented as an instruction "0x8143e00a". - * - */ - - FUNCTION_START(outb, 0) - stba %o1, [%o0] 0x88 - membar #StoreStore|#StoreLoad - FUNCTION_END(outb) - - FUNCTION_START(outw, 0) - stha %o1, [%o0] 0x88 - membar #StoreStore|#StoreLoad - FUNCTION_END(outw) - - FUNCTION_START(outl, 0) - sta %o1, [%o0] 0x88 - membar #StoreStore|#StoreLoad - FUNCTION_END(outl) - - FUNCTION_START(inb, 0) - lduba [%o0] 0x88, %o0 - FUNCTION_END(inb) - - FUNCTION_START(inw, 0) - lduha [%o0] 0x88, %o0 - FUNCTION_END(inw) - - FUNCTION_START(inl, 0) - lda [%o0] 0x88, %o0 - FUNCTION_END(inl) - - FUNCTION_START(xf86ReadMmio8, 0) - lduba [%o0 + %o1] 0x88, %o0 - FUNCTION_END(xf86ReadMmio8) - - FUNCTION_START(xf86ReadMmio16Be, 0) - lduh [%o0 + %o1], %o0 - FUNCTION_END(xf86ReadMmio16Be) - - FUNCTION_START(xf86ReadMmio16Le, 0) - lduha [%o0 + %o1] 0x88, %o0 - FUNCTION_END(xf86ReadMmio16Le) - - FUNCTION_START(xf86ReadMmio32Be, 0) - ld [%o0 + %o1], %o0 - FUNCTION_END(xf86ReadMmio32Be) - - FUNCTION_START(xf86ReadMmio32Le, 0) - lda [%o0 + %o1] 0x88, %o0 - FUNCTION_END(xf86ReadMmio32Le) - - FUNCTION_START(xf86WriteMmio8, 0) - stba %o2, [%o0 + %o1] 0x88 - membar #StoreStore|#StoreLoad - FUNCTION_END(xf86WriteMmio8) - - FUNCTION_START(xf86WriteMmio16Be, 0) - sth %o2, [%o0 + %o1] - membar #StoreStore|#StoreLoad - FUNCTION_END(xf86WriteMmio16Be) - - FUNCTION_START(xf86WriteMmio16Le, 0) - stha %o2, [%o0 + %o1] 0x88 - membar #StoreStore|#StoreLoad - FUNCTION_END(xf86WriteMmio16Le) - - FUNCTION_START(xf86WriteMmio32Be, 0) - st %o2, [%o0 + %o1] - membar #StoreStore|#StoreLoad - FUNCTION_END(xf86WriteMmio32Be) - - FUNCTION_START(xf86WriteMmio32Le, 0) - sta %o2, [%o0 + %o1] 0x88 - membar #StoreStore|#StoreLoad - FUNCTION_END(xf86WriteMmio32Le) - - FUNCTION_START(xf86WriteMmio8NB, 0) - add %o0, %o1, %o0 - stba %o2, [%o0] 0x88 - FUNCTION_END(xf86WriteMmio8NB) - - FUNCTION_START(xf86WriteMmio16BeNB, 0) - sth %o2, [%o0 + %o1] - FUNCTION_END(xf86WriteMmio16BeNB) - - FUNCTION_START(xf86WriteMmio16LeNB, 0) - stha %o2, [%o0 + %o1] 0x88 - FUNCTION_END(xf86WriteMmio16LeNB) - - FUNCTION_START(xf86WriteMmio32BeNB, 0) - st %o2, [%o0 + %o1] - FUNCTION_END(xf86WriteMmio32BeNB) - - FUNCTION_START(xf86WriteMmio32LeNB, 0) - sta %o2, [%o0 + %o1] 0x88 - FUNCTION_END(xf86WriteMmio32LeNB) - diff --git a/hw/xfree86/os-support/solaris/sun_VTsw.c b/hw/xfree86/os-support/solaris/sun_VTsw.c deleted file mode 100644 index 573358b43..000000000 --- a/hw/xfree86/os-support/solaris/sun_VTsw.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -#include -#include - -/* - * Handle the VT-switching interface for Solaris/OpenSolaris - */ - -static int xf86VTPruneDoor = 0; - -void -xf86VTRelease(int sig) -{ - if (xf86Info.vtPendingNum == -1) { - xf86VTPruneDoor = 1; - xf86Info.vtRequestsPending = TRUE; - return; - } - - ioctl(xf86Info.consoleFd, VT_RELDISP, 1); - xf86Info.vtPendingNum = -1; - - return; -} - -void -xf86VTAcquire(int sig) -{ - xf86Info.vtRequestsPending = TRUE; - return; -} - -Bool -xf86VTSwitchPending(void) -{ - return xf86Info.vtRequestsPending ? TRUE : FALSE; -} - -Bool -xf86VTSwitchAway(void) -{ - int door_fd; - vt_cmd_arg_t vt_door_arg; - door_arg_t door_arg; - - xf86Info.vtRequestsPending = FALSE; - - if (xf86VTPruneDoor) { - xf86VTPruneDoor = 0; - ioctl(xf86Info.consoleFd, VT_RELDISP, 1); - return TRUE; - } - - vt_door_arg.vt_ev = VT_EV_HOTKEYS; - vt_door_arg.vt_num = xf86Info.vtPendingNum; - door_arg.data_ptr = (char *) &vt_door_arg; - door_arg.data_size = sizeof(vt_cmd_arg_t); - door_arg.rbuf = NULL; - door_arg.rsize = 0; - door_arg.desc_ptr = NULL; - door_arg.desc_num = 0; - - if ((door_fd = open(VT_DAEMON_DOOR_FILE, O_RDONLY)) < 0) - return FALSE; - - if (door_call(door_fd, &door_arg) != 0) { - close(door_fd); - return FALSE; - } - - close(door_fd); - return TRUE; -} - -Bool -xf86VTSwitchTo(void) -{ - xf86Info.vtRequestsPending = FALSE; - if (ioctl(xf86Info.consoleFd, VT_RELDISP, VT_ACKACQ) < 0) { - return FALSE; - } - else { - return TRUE; - } -} - -Bool -xf86VTActivate(int vtno) -{ - struct vt_stat state; - - if (ioctl(xf86Info.consoleFd, VT_GETSTATE, &state) < 0) - return FALSE; - - if ((state.v_state & (1 << vtno)) == 0) - return FALSE; - - xf86Info.vtRequestsPending = TRUE; - xf86Info.vtPendingNum = vtno; - - return TRUE; -} diff --git a/hw/xfree86/os-support/solaris/sun_agp.c b/hw/xfree86/os-support/solaris/sun_agp.c deleted file mode 100644 index fb58eca81..000000000 --- a/hw/xfree86/os-support/solaris/sun_agp.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Abstraction of the AGP GART interface. - * - * This version is for Solaris. - * - * Copyright © 2000 VA Linux Systems, Inc. - * Copyright © 2001 The XFree86 Project, Inc. - */ -/* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86_OSproc.h" -#include -#include -#include -#include -#include - -/* AGP page size is independent of the host page size. */ -#ifndef AGP_PAGE_SIZE -#define AGP_PAGE_SIZE 4096 -#endif - -static int gartFd = -1; -static int acquiredScreen = -1; -static Bool initDone = FALSE; - -/* - * Close /dev/agpgart. This frees all associated memory allocated during - * this server generation. - */ -Bool -xf86GARTCloseScreen(int screenNum) -{ - if (gartFd != -1) { - close(gartFd); - acquiredScreen = -1; - gartFd = -1; - initDone = FALSE; - - xf86DrvMsg(screenNum, X_INFO, - "xf86GARTCloseScreen: device closed successfully\n"); - - } - return TRUE; -} - -/* - * Open /dev/agpgart. Keep it open until xf86GARTCloseScreen is called. - */ -static Bool -GARTInit(int screenNum) -{ - if (initDone) - return gartFd != -1; - - if (gartFd == -1) - gartFd = open(AGP_DEVICE, O_RDWR); - else - return FALSE; - - if (gartFd == -1) { - xf86DrvMsg(screenNum, X_ERROR, - "GARTInit: Unable to open " AGP_DEVICE " (%s)\n", - strerror(errno)); - return FALSE; - } - - initDone = TRUE; - xf86DrvMsg(screenNum, X_INFO, - "GARTInit: " AGP_DEVICE " opened successfully\n"); - - return TRUE; -} - -Bool -xf86AgpGARTSupported(void) -{ - return (GARTInit(-1)); - -} - -AgpInfoPtr -xf86GetAGPInfo(int screenNum) -{ - agp_info_t agpinf; - AgpInfoPtr info; - - if (!GARTInit(screenNum)) - return NULL; - - if (ioctl(gartFd, AGPIOC_INFO, &agpinf) != 0) { - xf86DrvMsg(screenNum, X_ERROR, - "xf86GetAGPInfo: AGPIOC_INFO failed (%s)\n", - strerror(errno)); - return NULL; - } - - if ((info = calloc(sizeof(AgpInfo), 1)) == NULL) { - xf86DrvMsg(screenNum, X_ERROR, - "xf86GetAGPInfo: Failed to allocate AgpInfo\n"); - return NULL; - } - - info->bridgeId = agpinf.agpi_devid; - info->agpMode = agpinf.agpi_mode; - info->base = agpinf.agpi_aperbase; - info->size = agpinf.agpi_apersize; - info->totalPages = (unsigned long) agpinf.agpi_pgtotal; - info->systemPages = (unsigned long) agpinf.agpi_pgsystem; - info->usedPages = (unsigned long) agpinf.agpi_pgused; - - return info; -} - -Bool -xf86AcquireGART(int screenNum) -{ - - if (!GARTInit(screenNum)) - return FALSE; - - if (acquiredScreen != screenNum) { - if (ioctl(gartFd, AGPIOC_ACQUIRE, 0) != 0) { - xf86DrvMsg(screenNum, X_WARNING, - "xf86AcquireGART: AGPIOC_ACQUIRE failed (%s)\n", - strerror(errno)); - return FALSE; - } - acquiredScreen = screenNum; - xf86DrvMsg(screenNum, X_INFO, - "xf86AcquireGART: AGPIOC_ACQUIRE succeeded\n"); - } - return TRUE; -} - -Bool -xf86ReleaseGART(int screenNum) -{ - - if (!GARTInit(screenNum)) - return FALSE; - - if (acquiredScreen == screenNum) { - /* - * The FreeBSD agp driver removes allocations on release. - * The Solaris driver doesn't. xf86ReleaseGART() is expected - * to give up access to the GART, but not to remove any - * allocations. - */ - - if (ioctl(gartFd, AGPIOC_RELEASE, 0) != 0) { - xf86DrvMsg(screenNum, X_WARNING, - "xf86ReleaseGART: AGPIOC_RELEASE failed (%s)\n", - strerror(errno)); - return FALSE; - } - acquiredScreen = -1; - xf86DrvMsg(screenNum, X_INFO, - "xf86ReleaseGART: AGPIOC_RELEASE succeeded\n"); - return TRUE; - } - return FALSE; -} - -int -xf86AllocateGARTMemory(int screenNum, unsigned long size, int type, - unsigned long *physical) -{ - agp_allocate_t alloc; - int pages; - - /* - * Allocates "size" bytes of GART memory (rounds up to the next - * page multiple) or type "type". A handle (key) for the allocated - * memory is returned. On error, the return value is -1. - * "size" should be larger than 0, or AGPIOC_ALLOCATE ioctl will - * return error. - */ - - if (!GARTInit(screenNum) || (acquiredScreen != screenNum)) - return -1; - - pages = (size / AGP_PAGE_SIZE); - if (size % AGP_PAGE_SIZE != 0) - pages++; - - alloc.agpa_pgcount = pages; - alloc.agpa_type = type; - - if (ioctl(gartFd, AGPIOC_ALLOCATE, &alloc) != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86AllocateGARTMemory: " - "allocation of %d pages failed\n\t(%s)\n", pages, - strerror(errno)); - return -1; - } - - if (physical) - *physical = (unsigned long) alloc.agpa_physical; - - return alloc.agpa_key; -} - -Bool -xf86DeallocateGARTMemory(int screenNum, int key) -{ - if (!GARTInit(screenNum) || (acquiredScreen != screenNum)) - return FALSE; - - if (ioctl(gartFd, AGPIOC_DEALLOCATE, (int *) (uintptr_t) key) != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86DeAllocateGARTMemory: " - "deallocation of gart memory with key %d failed\n" - "\t(%s)\n", key, strerror(errno)); - return FALSE; - } - - return TRUE; -} - -/* Bind GART memory with "key" at "offset" */ -Bool -xf86BindGARTMemory(int screenNum, int key, unsigned long offset) -{ - agp_bind_t bind; - int pageOffset; - - if (!GARTInit(screenNum) || (acquiredScreen != screenNum)) - return FALSE; - - if (offset % AGP_PAGE_SIZE != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: " - "offset (0x%lx) is not page-aligned (%d)\n", - offset, AGP_PAGE_SIZE); - return FALSE; - } - pageOffset = offset / AGP_PAGE_SIZE; - - xf86DrvMsgVerb(screenNum, X_INFO, 3, - "xf86BindGARTMemory: bind key %d at 0x%08lx " - "(pgoffset %d)\n", key, offset, pageOffset); - - bind.agpb_pgstart = pageOffset; - bind.agpb_key = key; - - if (ioctl(gartFd, AGPIOC_BIND, &bind) != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86BindGARTMemory: " - "binding of gart memory with key %d\n" - "\tat offset 0x%lx failed (%s)\n", - key, offset, strerror(errno)); - return FALSE; - } - - return TRUE; -} - -/* Unbind GART memory with "key" */ -Bool -xf86UnbindGARTMemory(int screenNum, int key) -{ - agp_unbind_t unbind; - - if (!GARTInit(screenNum) || (acquiredScreen != screenNum)) - return FALSE; - - unbind.agpu_pri = 0; - unbind.agpu_key = key; - - if (ioctl(gartFd, AGPIOC_UNBIND, &unbind) != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86UnbindGARTMemory: " - "unbinding of gart memory with key %d " - "failed (%s)\n", key, strerror(errno)); - return FALSE; - } - - xf86DrvMsgVerb(screenNum, X_INFO, 3, - "xf86UnbindGARTMemory: unbind key %d\n", key); - - return TRUE; -} - -/* XXX Interface may change. */ -Bool -xf86EnableAGP(int screenNum, CARD32 mode) -{ - agp_setup_t setup; - - if (!GARTInit(screenNum) || (acquiredScreen != screenNum)) - return FALSE; - - setup.agps_mode = mode; - if (ioctl(gartFd, AGPIOC_SETUP, &setup) != 0) { - xf86DrvMsg(screenNum, X_WARNING, "xf86EnableAGP: " - "AGPIOC_SETUP with mode %x failed (%s)\n", - (unsigned int) mode, strerror(errno)); - return FALSE; - } - - return TRUE; -} diff --git a/hw/xfree86/os-support/solaris/sun_apm.c b/hw/xfree86/os-support/solaris/sun_apm.c deleted file mode 100644 index 368f21eef..000000000 --- a/hw/xfree86/os-support/solaris/sun_apm.c +++ /dev/null @@ -1,223 +0,0 @@ -/* Based on hw/xfree86/os-support/bsd/bsd_apm.c which bore no explicit - * copyright notice, so is covered by the following notice: - * - * Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved. - * - * 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 XFREE86 PROJECT 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 XFree86 Project 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 - * XFree86 Project. - */ - -/* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "xf86.h" -#include "xf86Priv.h" -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" -#include "xf86_OSlib.h" - -#ifndef PLEASE_FIX_THIS -#define APM_STANDBY_REQ 0xa01 -#define APM_SUSPEND_REQ 0xa02 -#define APM_NORMAL_RESUME 0xa03 -#define APM_CRIT_RESUME 0xa04 -#define APM_BATTERY_LOW 0xa05 -#define APM_POWER_CHANGE 0xa06 -#define APM_UPDATE_TIME 0xa07 -#define APM_CRIT_SUSPEND_REQ 0xa08 -#define APM_USER_STANDBY_REQ 0xa09 -#define APM_USER_SUSPEND_REQ 0xa0a -#define APM_SYS_STANDBY_RESUME 0xa0b -#define APM_IOC_NEXTEVENT 0xa0c -#define APM_IOC_RESUME 0xa0d -#define APM_IOC_SUSPEND 0xa0e -#define APM_IOC_STANDBY 0xa0f -#endif - -typedef struct apm_event_info { - int type; -} apm_event_info; - -/* - This may be replaced with a better device name - very soon... -*/ -#define APM_DEVICE "/dev/srn" -#define APM_DEVICE1 "/dev/apm" - -static void *APMihPtr = NULL; -static void sunCloseAPM(void); - -static struct { - u_int apmBsd; - pmEvent xf86; -} sunToXF86Array[] = { - {APM_STANDBY_REQ, XF86_APM_SYS_STANDBY}, - {APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND}, - {APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME}, - {APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME}, - {APM_BATTERY_LOW, XF86_APM_LOW_BATTERY}, - {APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE}, - {APM_UPDATE_TIME, XF86_APM_UPDATE_TIME}, - {APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND}, - {APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY}, - {APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND}, - {APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME}, -#ifdef APM_CAPABILITY_CHANGE - {APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED}, -#endif -}; - -static pmEvent -sunToXF86(int type) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(sunToXF86Array); i++) { - if (type == sunToXF86Array[i].apmBsd) { - return sunToXF86Array[i].xf86; - } - } - return XF86_APM_UNKNOWN; -} - -/* - * APM events can be requested directly from /dev/apm - */ -static int -sunPMGetEventFromOS(int fd, pmEvent * events, int num) -{ - struct apm_event_info sunEvent; - int i; - - for (i = 0; i < num; i++) { - - if (ioctl(fd, APM_IOC_NEXTEVENT, &sunEvent) < 0) { - if (errno != EAGAIN) { - xf86Msg(X_WARNING, "sunPMGetEventFromOS: APM_IOC_NEXTEVENT" - " %s\n", strerror(errno)); - } - break; - } - events[i] = sunToXF86(sunEvent.type); - } - xf86Msg(X_WARNING, "Got some events\n"); - return i; -} - -static pmWait -sunPMConfirmEventToOs(int fd, pmEvent event) -{ - switch (event) { -/* XXX: NOT CURRENTLY RETURNED FROM OS */ - case XF86_APM_SYS_STANDBY: - case XF86_APM_USER_STANDBY: - if (ioctl(fd, APM_IOC_STANDBY, NULL) == 0) - return PM_WAIT; /* should we stop the Xserver in standby, too? */ - else - return PM_NONE; - case XF86_APM_SYS_SUSPEND: - case XF86_APM_CRITICAL_SUSPEND: - case XF86_APM_USER_SUSPEND: - xf86Msg(X_WARNING, "Got SUSPENDED\n"); - if (ioctl(fd, APM_IOC_SUSPEND, NULL) == 0) - return PM_CONTINUE; - else { - xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_SUSPEND" - " %s\n", strerror(errno)); - return PM_FAILED; - } - case XF86_APM_STANDBY_RESUME: - case XF86_APM_NORMAL_RESUME: - case XF86_APM_CRITICAL_RESUME: - case XF86_APM_STANDBY_FAILED: - case XF86_APM_SUSPEND_FAILED: - xf86Msg(X_WARNING, "Got RESUME\n"); - if (ioctl(fd, APM_IOC_RESUME, NULL) == 0) - return PM_CONTINUE; - else { - xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_RESUME" - " %s\n", strerror(errno)); - return PM_FAILED; - } - default: - return PM_NONE; - } -} - -PMClose -xf86OSPMOpen(void) -{ - int fd; - - if (APMihPtr || !xf86Info.pmFlag) { - return NULL; - } - - if ((fd = open(APM_DEVICE, O_RDWR)) == -1) { - if ((fd = open(APM_DEVICE1, O_RDWR)) == -1) { - return NULL; - } - } - xf86PMGetEventFromOs = sunPMGetEventFromOS; - xf86PMConfirmEventToOs = sunPMConfirmEventToOs; - APMihPtr = xf86AddGeneralHandler(fd, xf86HandlePMEvents, NULL); - return sunCloseAPM; -} - -static void -sunCloseAPM(void) -{ - int fd; - - if (APMihPtr) { - fd = xf86RemoveGeneralHandler(APMihPtr); - close(fd); - APMihPtr = NULL; - } -} diff --git a/hw/xfree86/os-support/solaris/sun_bell.c b/hw/xfree86/os-support/solaris/sun_bell.c deleted file mode 100644 index 883728e51..000000000 --- a/hw/xfree86/os-support/solaris/sun_bell.c +++ /dev/null @@ -1,183 +0,0 @@ -/* Copyright (c) 2004-2005, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" - -#define BELL_RATE 48000 /* Samples per second */ -#define BELL_HZ 50 /* Fraction of a second i.e. 1/x */ -#define BELL_MS (1000/BELL_HZ) /* MS */ -#define BELL_SAMPLES (BELL_RATE / BELL_HZ) -#define BELL_MIN 3 /* Min # of repeats */ - -#define AUDIO_DEVICE "/dev/audio" - -void -xf86OSRingBell(int loudness, int pitch, int duration) -{ - static short samples[BELL_SAMPLES]; - static short silence[BELL_SAMPLES]; /* "The Sound of Silence" */ - static int lastFreq; - int cnt; - int i; - int written; - int repeats; - int freq; - audio_info_t audioInfo; - struct iovec iov[IOV_MAX]; - int iovcnt; - double ampl, cyclen, phase; - int audioFD; - - if ((loudness <= 0) || (pitch <= 0) || (duration <= 0)) { - return; - } - - lastFreq = 0; - memset(silence, 0, sizeof(silence)); - - audioFD = open(AUDIO_DEVICE, O_WRONLY | O_NONBLOCK); - if (audioFD == -1) { - xf86Msg(X_ERROR, "Bell: cannot open audio device \"%s\": %s\n", - AUDIO_DEVICE, strerror(errno)); - return; - } - - freq = pitch; - freq = min(freq, (BELL_RATE / 2) - 1); - freq = max(freq, 2 * BELL_HZ); - - /* - * Ensure full waves per buffer - */ - freq -= freq % BELL_HZ; - - if (freq != lastFreq) { - lastFreq = freq; - ampl = 16384.0; - - cyclen = (double) freq / (double) BELL_RATE; - phase = 0.0; - - for (i = 0; i < BELL_SAMPLES; i++) { - samples[i] = (short) (ampl * sin(2.0 * M_PI * phase)); - phase += cyclen; - if (phase >= 1.0) - phase -= 1.0; - } - } - - repeats = (duration + (BELL_MS / 2)) / BELL_MS; - repeats = max(repeats, BELL_MIN); - - loudness = max(0, loudness); - loudness = min(loudness, 100); - -#ifdef DEBUG - ErrorF("BELL : freq %d volume %d duration %d repeats %d\n", - freq, loudness, duration, repeats); -#endif - - AUDIO_INITINFO(&audioInfo); - audioInfo.play.encoding = AUDIO_ENCODING_LINEAR; - audioInfo.play.sample_rate = BELL_RATE; - audioInfo.play.channels = 2; - audioInfo.play.precision = 16; - audioInfo.play.gain = min(AUDIO_MAX_GAIN, AUDIO_MAX_GAIN * loudness / 100); - - if (ioctl(audioFD, AUDIO_SETINFO, &audioInfo) < 0) { - xf86Msg(X_ERROR, - "Bell: AUDIO_SETINFO failed on audio device \"%s\": %s\n", - AUDIO_DEVICE, strerror(errno)); - close(audioFD); - return; - } - - iovcnt = 0; - - for (cnt = 0; cnt <= repeats; cnt++) { - if (cnt == repeats) { - /* Insert a bit of silence so that multiple beeps are distinct and - * not compressed into a single tone. - */ - iov[iovcnt].iov_base = (char *) silence; - iov[iovcnt++].iov_len = sizeof(silence); - } - else { - iov[iovcnt].iov_base = (char *) samples; - iov[iovcnt++].iov_len = sizeof(samples); - } - if ((iovcnt >= IOV_MAX) || (cnt == repeats)) { - written = writev(audioFD, iov, iovcnt); - - if ((written < ((int) (sizeof(samples) * iovcnt)))) { - /* audio buffer was full! */ - - int naptime; - - if (written == -1) { - if (errno != EAGAIN) { - xf86Msg(X_ERROR, - "Bell: writev failed on audio device \"%s\": %s\n", - AUDIO_DEVICE, strerror(errno)); - close(audioFD); - return; - } - i = iovcnt; - } - else { - i = ((sizeof(samples) * iovcnt) - written) - / sizeof(samples); - } - cnt -= i; - - /* sleep a little to allow audio buffer to drain */ - naptime = BELL_MS * i; - xserver_poll(NULL, 0, naptime); - - i = ((sizeof(samples) * iovcnt) - written) % sizeof(samples); - iovcnt = 0; - if ((written != -1) && (i > 0)) { - iov[iovcnt].iov_base = ((char *) samples) + i; - iov[iovcnt++].iov_len = sizeof(samples) - i; - } - } - else { - iovcnt = 0; - } - } - } - - close(audioFD); - return; -} diff --git a/hw/xfree86/os-support/solaris/sun_init.c b/hw/xfree86/os-support/solaris/sun_init.c deleted file mode 100644 index cc50f36c4..000000000 --- a/hw/xfree86/os-support/solaris/sun_init.c +++ /dev/null @@ -1,391 +0,0 @@ -/* - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany - * Copyright 1993 by David Wexelblat - * Copyright 1999 by David Holland - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the names of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND IN NO - * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#ifdef HAVE_SYS_KD_H -#include -#endif - -/* - * Applications see VT number as consecutive integers starting from 1. - * VT number VT device - * ------------------------------------------------------- - * 1 : /dev/vt/0 (Alt + Ctrl + F1) - * 2 : /dev/vt/2 (Alt + Ctrl + F2) - * 3 : /dev/vt/3 (Alt + Ctrl + F3) - * ... ... - */ -#define CONSOLE_VTNO 1 -#define SOL_CONSOLE_DEV "/dev/console" - -static Bool KeepTty = FALSE; -static Bool UseConsole = FALSE; - -#ifdef HAS_USL_VTS -static int VTnum = -1; -static int xf86StartVT = -1; -static int vtEnabled = 0; -#endif - -/* Device to open as xf86Info.consoleFd */ -static char consoleDev[PATH_MAX] = "/dev/fb"; - -/* Set by -dev argument on CLI - Used by hw/xfree86/common/xf86AutoConfig.c for VIS_GETIDENTIFIER */ -_X_HIDDEN char xf86SolarisFbDev[PATH_MAX] = "/dev/fb"; - -static void -switch_to(int vt, const char *from) -{ - int ret; - - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_ACTIVATE, vt)); - if (ret != 0) - xf86Msg(X_WARNING, "%s: VT_ACTIVATE failed: %s\n", - from, strerror(errno)); - - SYSCALL(ret = ioctl(xf86Info.consoleFd, VT_WAITACTIVE, vt)); - if (ret != 0) - xf86Msg(X_WARNING, "%s: VT_WAITACTIVE failed: %s\n", - from, strerror(errno)); -} - -void -xf86OpenConsole(void) -{ - int i; - -#ifdef HAS_USL_VTS - int fd; - struct vt_mode VT; - struct vt_stat vtinfo; - MessageType from = X_PROBED; -#endif - - if (serverGeneration == 1) { - /* Check if we're run with euid==0 */ - if (geteuid() != 0) - FatalError("xf86OpenConsole: Server must be suid root\n"); - -#ifdef HAS_USL_VTS - - /* - * Setup the virtual terminal manager - */ - if ((fd = open("/dev/vt/0", O_RDWR, 0)) == -1) { - xf86ErrorF("xf86OpenConsole: Cannot open /dev/vt/0 (%s)\n", - strerror(errno)); - vtEnabled = 0; - } - else { - if (ioctl(fd, VT_ENABLED, &vtEnabled) < 0) { - xf86ErrorF("xf86OpenConsole: VT_ENABLED failed (%s)\n", - strerror(errno)); - vtEnabled = 0; - } - } -#endif /* HAS_USL_VTS */ - - if (UseConsole) { - strlcpy(consoleDev, SOL_CONSOLE_DEV, sizeof(consoleDev)); - -#ifdef HAS_USL_VTS - xf86Info.vtno = CONSOLE_VTNO; - - if (vtEnabled == 0) { - xf86StartVT = 0; - } - else { - if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) - FatalError - ("xf86OpenConsole: Cannot determine current VT\n"); - xf86StartVT = vtinfo.v_active; - } -#endif /* HAS_USL_VTS */ - goto OPENCONSOLE; - } - -#ifdef HAS_USL_VTS - if (vtEnabled == 0) { - /* VT not enabled - kernel too old or Sparc platforms - without visual_io support */ - xf86Msg(from, "VT infrastructure is not available\n"); - - xf86StartVT = 0; - xf86Info.vtno = 0; - strlcpy(consoleDev, xf86SolarisFbDev, sizeof(consoleDev)); - goto OPENCONSOLE; - } - - if (ioctl(fd, VT_GETSTATE, &vtinfo) < 0) - FatalError("xf86OpenConsole: Cannot determine current VT\n"); - - xf86StartVT = vtinfo.v_active; - - if (VTnum != -1) { - xf86Info.vtno = VTnum; - from = X_CMDLINE; - } - else if (xf86Info.ShareVTs) { - xf86Info.vtno = vtinfo.v_active; - from = X_CMDLINE; - } - else { - if ((ioctl(fd, VT_OPENQRY, &xf86Info.vtno) < 0) || - (xf86Info.vtno == -1)) { - FatalError("xf86OpenConsole: Cannot find a free VT\n"); - } - } - - xf86Msg(from, "using VT number %d\n\n", xf86Info.vtno); - snprintf(consoleDev, PATH_MAX, "/dev/vt/%d", xf86Info.vtno); - - if (fd != -1) { - close(fd); - } - -#endif /* HAS_USL_VTS */ - - OPENCONSOLE: - if (!KeepTty) - setpgrp(); - - if (((xf86Info.consoleFd = open(consoleDev, O_RDWR | O_NDELAY, 0)) < 0)) - FatalError("xf86OpenConsole: Cannot open %s (%s)\n", - consoleDev, strerror(errno)); - - /* Change ownership of the vt or console */ - chown(consoleDev, getuid(), getgid()); - -#ifdef HAS_USL_VTS - if (xf86Info.ShareVTs) - return; - - if (vtEnabled) { - /* - * Now get the VT - */ - switch_to(xf86Info.vtno, "xf86OpenConsole"); - -#ifdef VT_SET_CONSUSER /* added in snv_139 */ - if (strcmp(display, "0") == 0) - if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_SET_CONSUSER failed\n"); -#endif - - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) < 0) - FatalError("xf86OpenConsole: VT_GETMODE failed\n"); - - OsSignal(SIGUSR1, xf86VTAcquire); - OsSignal(SIGUSR2, xf86VTRelease); - - VT.mode = VT_PROCESS; - VT.acqsig = SIGUSR1; - VT.relsig = SIGUSR2; - - if (ioctl(xf86Info.consoleFd, VT_SETMODE, &VT) < 0) - FatalError("xf86OpenConsole: VT_SETMODE VT_PROCESS failed\n"); - - if (ioctl(xf86Info.consoleFd, VT_SETDISPINFO, atoi(display)) < 0) - xf86Msg(X_WARNING, "xf86OpenConsole: VT_SETDISPINFO failed\n"); - } -#endif - -#ifdef KDSETMODE - SYSCALL(i = ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS)); - if (i < 0) { - xf86Msg(X_WARNING, - "xf86OpenConsole: KDSETMODE KD_GRAPHICS failed on %s (%s)\n", - consoleDev, strerror(errno)); - } -#endif - } - else { /* serverGeneration != 1 */ - -#ifdef HAS_USL_VTS - if (vtEnabled && !xf86Info.ShareVTs) { - /* - * Now re-get the VT - */ - if (xf86Info.autoVTSwitch) - switch_to(xf86Info.vtno, "xf86OpenConsole"); - -#ifdef VT_SET_CONSUSER /* added in snv_139 */ - if (strcmp(display, "0") == 0) - if (ioctl(xf86Info.consoleFd, VT_SET_CONSUSER) != 0) - xf86Msg(X_WARNING, - "xf86OpenConsole: VT_SET_CONSUSER failed\n"); -#endif - - /* - * If the server doesn't have the VT when the reset occurs, - * this is to make sure we don't continue until the activate - * signal is received. - */ - if (!xf86VTOwner()) - sleep(5); - } -#endif /* HAS_USL_VTS */ - - } -} - -void -xf86CloseConsole(void) -{ -#ifdef HAS_USL_VTS - struct vt_mode VT; -#endif - -#if !defined(__i386__) && !defined(__i386) && !defined(__x86) - - if (!xf86DoConfigure) { - int fd; - - /* - * Wipe out framebuffer just like the non-SI Xsun server does. This - * could be improved by saving framebuffer contents in - * xf86OpenConsole() above and restoring them here. Also, it's unclear - * at this point whether this should be done for all framebuffers in - * the system, rather than only the console. - */ - if ((fd = open(xf86SolarisFbDev, O_RDWR, 0)) < 0) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to open framebuffer (%s)\n", - strerror(errno)); - } - else { - struct fbgattr fbattr; - - if ((ioctl(fd, FBIOGATTR, &fbattr) < 0) && - (ioctl(fd, FBIOGTYPE, &fbattr.fbtype) < 0)) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to retrieve framebuffer" - " attributes (%s)\n", strerror(errno)); - } - else { - void *fbdata; - - fbdata = mmap(NULL, fbattr.fbtype.fb_size, - PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (fbdata == MAP_FAILED) { - xf86Msg(X_WARNING, - "xf86CloseConsole(): unable to mmap framebuffer" - " (%s)\n", strerror(errno)); - } - else { - memset(fbdata, 0, fbattr.fbtype.fb_size); - munmap(fbdata, fbattr.fbtype.fb_size); - } - } - - close(fd); - } - } - -#endif - -#ifdef KDSETMODE - /* Reset the display back to text mode */ - SYSCALL(ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT)); -#endif - -#ifdef HAS_USL_VTS - if (vtEnabled) { - if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) { - VT.mode = VT_AUTO; /* Set default vt handling */ - ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); - } - - /* Activate the VT that X was started on */ - if (xf86Info.autoVTSwitch) - switch_to(xf86StartVT, "xf86CloseConsole"); - } -#endif /* HAS_USL_VTS */ - - close(xf86Info.consoleFd); -} - -int -xf86ProcessArgument(int argc, char **argv, int i) -{ - /* - * Keep server from detaching from controlling tty. This is useful when - * debugging, so the server can receive keyboard signals. - */ - if (!strcmp(argv[i], "-keeptty")) { - KeepTty = TRUE; - return 1; - } - - /* - * Use /dev/console as the console device. - */ - if (!strcmp(argv[i], "-C")) { - UseConsole = TRUE; - return 1; - } - -#ifdef HAS_USL_VTS - - if ((argv[i][0] == 'v') && (argv[i][1] == 't')) { - if (sscanf(argv[i], "vt%d", &VTnum) == 0) { - UseMsg(); - VTnum = -1; - return 0; - } - - return 1; - } - -#endif /* HAS_USL_VTS */ - - if ((i + 1) < argc) { - if (!strcmp(argv[i], "-dev")) { - strlcpy(xf86SolarisFbDev, argv[i + 1], sizeof(xf86SolarisFbDev)); - return 2; - } - } - - return 0; -} - -void -xf86UseMsg(void) -{ -#ifdef HAS_USL_VTS - ErrorF("vtX Use the specified VT number\n"); -#endif - ErrorF("-dev Framebuffer device\n"); - ErrorF("-keeptty Don't detach controlling tty\n"); - ErrorF(" (for debugging only)\n"); - ErrorF("-C Use /dev/console as the console device\n"); -} diff --git a/hw/xfree86/os-support/solaris/sun_inout.s b/hw/xfree86/os-support/solaris/sun_inout.s deleted file mode 100644 index e8f03d0e8..000000000 --- a/hw/xfree86/os-support/solaris/sun_inout.s +++ /dev/null @@ -1,124 +0,0 @@ -/ $XFree86: xc/programs/Xserver/hw/xfree86/os-support/sunos/sun_inout.s,v 1.1 2001/05/28 02:42:31 tsi Exp $ -/ -/ Copyright 1994-2001 The XFree86 Project, Inc. All Rights Reserved. -/ -/ 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 -/ XFREE86 PROJECT 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 XFree86 Project 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 -/ XFree86 Project. -/ -/ -/ File: sun_inout.s -/ -/ Purpose: Provide inb(), inw(), inl(), outb(), outw(), outl() functions -/ for Solaris x86 using the ProWorks compiler by SunPro -/ -/ Author: Installed into XFree86 SuperProbe by Doug Anson (danson@lgc.com) -/ Portions donated to XFree86 by Steve Dever (Steve.Dever@Eng.Sun.Com) -/ -/ Synopsis: (c callable external declarations) -/ extern unsigned char inb(int port); -/ extern unsigned short inw(int port); -/ extern unsigned long inl(int port); -/ extern void outb(int port, unsigned char value); -/ extern void outw(int port, unsigned short value); -/ extern void outl(int port, unsigned long value); -/ - -.file "sunos_inout.s" -.text - -.globl inb -.globl inw -.globl inl -.globl outb -.globl outw -.globl outl - -/ -/ unsigned char inb(int port); -/ -.align 4 -inb: - movl 4(%esp),%edx - subl %eax,%eax - inb (%dx) - ret -.type inb,@function -.size inb,.-inb - -/ -/ unsigned short inw(int port); -/ -.align 4 -inw: - movl 4(%esp),%edx - subl %eax,%eax - inw (%dx) - ret -.type inw,@function -.size inw,.-inw - -/ -/ unsigned long inl(int port); -/ -.align 4 -inl: - movl 4(%esp),%edx - inl (%dx) - ret -.type inl,@function -.size inl,.-inl - -/ -/ void outb(int port, unsigned char value); -/ -.align 4 -outb: - movl 4(%esp),%edx - movl 8(%esp),%eax - outb (%dx) - ret -.type outb,@function -.size outb,.-outb - -/ -/ void outw(int port, unsigned short value); -/ -.align 4 -outw: - movl 4(%esp),%edx - movl 8(%esp),%eax - outw (%dx) - ret -.type outw,@function -.size outw,.-outw - -/ -/ void outl(int port, unsigned long value); -/ -.align 4 -outl: - movl 4(%esp),%edx - movl 8(%esp),%eax - outl (%dx) - ret -.type outl,@function -.size outl,.-outl diff --git a/hw/xfree86/os-support/solaris/sun_vid.c b/hw/xfree86/os-support/solaris/sun_vid.c deleted file mode 100644 index 8e94fcced..000000000 --- a/hw/xfree86/os-support/solaris/sun_vid.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany - * Copyright 1993 by David Wexelblat - * Copyright 1999 by David Holland - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that copyright - * notice and this permission notice appear in supporting documentation, and - * that the names of the copyright holders not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. The copyright holders make no representations - * about the suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT - * SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - * OF THIS SOFTWARE. - * - */ -/* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include /* get __x86 definition if not set by compiler */ - -#if defined(__i386__) || defined(__i386) || defined(__x86) -#define _NEED_SYSI86 -#endif -#include "xf86.h" -#include "xf86Priv.h" -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" -#include - -/***************************************************************************/ -/* Video Memory Mapping section */ -/***************************************************************************/ - -_X_HIDDEN void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - pVidMem->initialised = TRUE; -} - -/***************************************************************************/ -/* I/O Permissions section */ -/***************************************************************************/ - -void -xf86OSInputThreadInit(void) -{ - /* - * Need to enable in input thread as well, as Solaris kernel tracks - * IOPL per-thread and doesn't inherit when creating a new thread. - */ - xf86EnableIO(); -} - -Bool -xf86EnableIO(void) -{ -#if defined(__i386__) || defined(__i386) || defined(__x86) - if (sysi86(SI86V86, V86SC_IOPL, PS_IOPL) < 0) { - xf86Msg(X_WARNING, "xf86EnableIO: Failed to set IOPL for I/O\n"); - return FALSE; - } -#endif /* i386 */ - return TRUE; -} - -void -xf86DisableIO(void) -{ -#if defined(__i386__) || defined(__i386) || defined(__x86) - sysi86(SI86V86, V86SC_IOPL, 0); -#endif /* i386 */ -} diff --git a/hw/xfree86/os-support/stub/stub_bell.c b/hw/xfree86/os-support/stub/stub_bell.c deleted file mode 100644 index 48625928f..000000000 --- a/hw/xfree86/os-support/stub/stub_bell.c +++ /dev/null @@ -1,10 +0,0 @@ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86_OSlib.h" - -void -xf86OSRingBell(int loudness, int pitch, int duration) -{ -} diff --git a/hw/xfree86/os-support/stub/stub_init.c b/hw/xfree86/os-support/stub/stub_init.c deleted file mode 100644 index f0d9039b9..000000000 --- a/hw/xfree86/os-support/stub/stub_init.c +++ /dev/null @@ -1,32 +0,0 @@ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86_OSlib.h" - -void -xf86OpenConsole(void) -{ -} - -void -xf86CloseConsole(void) -{ -} - -int -xf86ProcessArgument(int argc, char *argv[], int i) -{ - return 0; -} - -void -xf86UseMsg(void) -{ -} - -void -xf86OSInputThreadInit(void) -{ - return; -} diff --git a/hw/xfree86/os-support/stub/stub_video.c b/hw/xfree86/os-support/stub/stub_video.c deleted file mode 100644 index 9771fcf6e..000000000 --- a/hw/xfree86/os-support/stub/stub_video.c +++ /dev/null @@ -1,13 +0,0 @@ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86_OSlib.h" -#include "xf86OSpriv.h" - -void -xf86OSInitVidMem(VidMemInfoPtr pVidMem) -{ - pVidMem->initialised = TRUE; - return; -} diff --git a/hw/xfree86/os-support/xf86OSpriv.h b/hw/xfree86/os-support/xf86OSpriv.h deleted file mode 100644 index ce1ec33a1..000000000 --- a/hw/xfree86/os-support/xf86OSpriv.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 1999-2000 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _XF86OSPRIV_H -#define _XF86OSPRIV_H - -typedef struct { - Bool initialised; -} VidMemInfo, *VidMemInfoPtr; - -void xf86OSInitVidMem(VidMemInfoPtr); - -#endif /* _XF86OSPRIV_H */ diff --git a/hw/xfree86/os-support/xf86_OSlib.h b/hw/xfree86/os-support/xf86_OSlib.h deleted file mode 100644 index 159c8064c..000000000 --- a/hw/xfree86/os-support/xf86_OSlib.h +++ /dev/null @@ -1,355 +0,0 @@ -/* - * Copyright 1990, 1991 by Thomas Roell, Dinkelscherben, Germany - * Copyright 1992 by David Dawes - * Copyright 1992 by Jim Tsillas - * Copyright 1992 by Rich Murphey - * Copyright 1992 by Robert Baron - * Copyright 1992 by Orest Zborowski - * Copyright 1993 by Vrije Universiteit, The Netherlands - * Copyright 1993 by David Wexelblat - * Copyright 1994, 1996 by Holger Veit - * Copyright 1997 by Takis Psarogiannakopoulos - * Copyright 1994-2003 by The XFree86 Project, Inc - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of the above listed copyright holders - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. The above listed - * copyright holders make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * THE ABOVE LISTED COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDERS BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -/* - * The ARM32 code here carries the following copyright: - * - * Copyright 1997 - * Digital Equipment Corporation. All rights reserved. - * This software is furnished under license and may be used and copied only in - * accordance with the following terms and conditions. Subject to these - * conditions, you may download, copy, install, use, modify and distribute - * this software in source and/or binary form. No title or ownership is - * transferred hereby. - * - * 1) Any source code used, modified or distributed must reproduce and retain - * this copyright notice and list of conditions as they appear in the - * source file. - * - * 2) No right is granted to use any trade name, trademark, or logo of Digital - * Equipment Corporation. Neither the "Digital Equipment Corporation" - * name nor any trademark or logo of Digital Equipment Corporation may be - * used to endorse or promote products derived from this software without - * the prior written permission of Digital Equipment Corporation. - * - * 3) This software is provided "AS-IS" and any express or implied warranties, - * including but not limited to, any implied warranties of merchantability, - * fitness for a particular purpose, or non-infringement are disclaimed. - * In no event shall DIGITAL be liable for any damages whatsoever, and in - * particular, DIGITAL shall not be liable for special, indirect, - * consequential, or incidental damages or damages for lost profits, loss - * of revenue or loss of use, whether such damages arise in contract, - * negligence, tort, under statute, in equity, at law or otherwise, even - * if advised of the possibility of such damage. - * - */ - -/* - * This is private, and should not be included by any drivers. Drivers - * may include xf86_OSproc.h to get prototypes for public interfaces. - */ - -#ifndef _XF86_OSLIB_H -#define _XF86_OSLIB_H - -#include -#include - -#include -#include -#include - -/**************************************************************************/ -/* SYSV386 (SVR3, SVR4), including Solaris */ -/**************************************************************************/ -#if (defined(SYSV) || defined(SVR4)) && \ - (defined(__sun) || defined(__i386__)) -#include -#include -#include -#include -#include - -#include - -#if defined(_NEED_SYSI86) -#if !(defined (__sun) && defined (SVR4)) -#include -#include -#include -#endif -#include -#include -#if defined(SVR4) && !defined(__sun) -#include -#endif /* SVR4 && !__sun */ -/* V86SC_IOPL was moved to on Solaris 7 and later */ -#if !defined(V86SC_IOPL) /* Solaris 7 or later? */ -#include /* Nope */ -#endif -#if defined(__sun) && (defined (__i386__) || defined(__i386) || defined(__x86)) && defined (SVR4) -#include -#endif -#endif /* _NEED_SYSI86 */ - -#if defined(HAS_SVR3_MMAPDRV) -#include -#if !defined(_NEED_SYSI86) -#include -#include -#endif -#include /* MMAP driver header */ -#endif - -#if !defined(__sun) || defined(HAVE_SYS_VT_H) -#define HAS_USL_VTS -#endif -#if !defined(__sun) -#include -#endif -#if defined(HAS_USL_VTS) -#if !defined(__sun) -#include -#endif -#include -#include - -extern _X_HIDDEN void xf86VTAcquire(int); -extern _X_HIDDEN void xf86VTRelease(int); -#endif - -#if defined(__sun) -#include -extern _X_HIDDEN char xf86SolarisFbDev[PATH_MAX]; - -#include -#include - -/* undefine symbols from we don't need that conflict with enum - definitions in parser/xf86tokens.h */ -#undef STRING -#undef LEFTALT -#undef RIGHTALT - -#define LED_CAP LED_CAPS_LOCK -#define LED_NUM LED_NUM_LOCK -#define LED_SCR LED_SCROLL_LOCK -#define LED_COMP LED_COMPOSE -#endif /* __sun */ - -#if !defined(VT_ACKACQ) -#define VT_ACKACQ 2 -#endif /* !VT_ACKACQ */ - -#if defined(SVR4) -#include -#if !(defined(__sun) && defined (SVR4)) -#define DEV_MEM "/dev/pmem" -#endif -#define CLEARDTR_SUPPORT -#define POSIX_TTY -#endif /* SVR4 */ - -#endif /* (SYSV || SVR4) */ - -/**************************************************************************/ -/* Linux or Glibc-based system */ -/**************************************************************************/ -#if defined(__linux__) || defined(__GLIBC__) || defined(__CYGWIN__) -#include -#include -#include -#include -#include - -#include -#ifdef __sparc__ -#include -#endif - -#include - -#include - -#include -#ifdef __linux__ -#define HAS_USL_VTS -#include -#include -#define LDGMAP GIO_SCRNMAP -#define LDSMAP PIO_SCRNMAP -#define LDNMAP LDSMAP -#define CLEARDTR_SUPPORT -#endif - -#define POSIX_TTY - -#endif /* __linux__ || __GLIBC__ */ - -/**************************************************************************/ -/* System is BSD-like */ -/**************************************************************************/ - -#ifdef CSRG_BASED -#include -#include - -#include -#define termio termios -#define POSIX_TTY - -#include - -#include -#include -#include - -#endif /* CSRG_BASED */ - -/**************************************************************************/ -/* Kernel of *BSD */ -/**************************************************************************/ -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ - defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) - -#include -#if defined(__FreeBSD_version) && !defined(__FreeBSD_kernel_version) -#define __FreeBSD_kernel_version __FreeBSD_version -#endif - -#ifdef SYSCONS_SUPPORT -#define COMPAT_SYSCONS -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) -#if defined(__DragonFly__) || (__FreeBSD_kernel_version >= 410000) -#include -#include -#else -#include -#endif /* FreeBSD 4.1 RELEASE or lator */ -#else -#include -#endif -#endif /* SYSCONS_SUPPORT */ -#if defined(PCVT_SUPPORT) && !defined(__NetBSD__) && !defined(__OpenBSD__) -#if !defined(SYSCONS_SUPPORT) - /* no syscons, so include pcvt specific header file */ -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -#include -#else -#include -#endif /* __FreeBSD_kernel__ */ -#else /* pcvt and syscons: hard-code the ID magic */ -#define VGAPCVTID _IOWR('V',113, struct pcvtid) -struct pcvtid { - char name[16]; - int rmajor, rminor; -}; -#endif /* PCVT_SUPPORT && SYSCONS_SUPPORT */ -#endif /* PCVT_SUPPORT */ -#ifdef WSCONS_SUPPORT -#include -#include -#endif /* WSCONS_SUPPORT */ -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) -#include -#endif - /* Include these definitions in case ioctl_pc.h didn't get included */ -#ifndef CONSOLE_X_MODE_ON -#define CONSOLE_X_MODE_ON _IO('t',121) -#endif -#ifndef CONSOLE_X_MODE_OFF -#define CONSOLE_X_MODE_OFF _IO('t',122) -#endif -#ifndef CONSOLE_X_BELL -#define CONSOLE_X_BELL _IOW('t',123,int[2]) -#endif -#ifndef CONSOLE_X_TV_ON -#define CONSOLE_X_TV_ON _IOW('t',155,int) -#define XMODE_RGB 0 -#define XMODE_NTSC 1 -#define XMODE_PAL 2 -#define XMODE_SECAM 3 -#endif -#ifndef CONSOLE_X_TV_OFF -#define CONSOLE_X_TV_OFF _IO('t',156) -#endif -#ifndef CONSOLE_GET_LINEAR_INFO -#define CONSOLE_GET_LINEAR_INFO _IOR('t',157,struct map_info) -#endif -#ifndef CONSOLE_GET_IO_INFO -#define CONSOLE_GET_IO_INFO _IOR('t',158,struct map_info) -#endif -#ifndef CONSOLE_GET_MEM_INFO -#define CONSOLE_GET_MEM_INFO _IOR('t',159,struct map_info) -#endif - -#if defined(USE_I386_IOPL) || defined(USE_AMD64_IOPL) -#include -#endif - -#define CLEARDTR_SUPPORT - -#endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __DragonFly__ */ - -/**************************************************************************/ -/* IRIX */ -/**************************************************************************/ - -/**************************************************************************/ -/* Generic */ -/**************************************************************************/ - -#include /* May need to adjust this for other OSs */ - -/* For PATH_MAX */ -#include "misc.h" - -/* - * Hack originally for ISC 2.2 POSIX headers, but may apply elsewhere, - * and it's safe, so just do it. - */ -#if !defined(O_NDELAY) && defined(O_NONBLOCK) -#define O_NDELAY O_NONBLOCK -#endif /* !O_NDELAY && O_NONBLOCK */ - -#if !defined(MAXHOSTNAMELEN) -#define MAXHOSTNAMELEN 32 -#endif /* !MAXHOSTNAMELEN */ - -#include - -#ifndef DEV_MEM -#define DEV_MEM "/dev/mem" -#endif - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *)-1) -#endif - -#define SYSCALL(call) while(((call) == -1) && (errno == EINTR)) - -#define XF86_OS_PRIVS -#include "xf86_OSproc.h" - -#endif /* _XF86_OSLIB_H */ diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h deleted file mode 100644 index 05a7cd820..000000000 --- a/hw/xfree86/os-support/xf86_OSproc.h +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright 1990, 1991 by Thomas Roell, Dinkelscherben, Germany - * Copyright 1992 by David Dawes - * Copyright 1992 by Jim Tsillas - * Copyright 1992 by Rich Murphey - * Copyright 1992 by Robert Baron - * Copyright 1992 by Orest Zborowski - * Copyright 1993 by Vrije Universiteit, The Netherlands - * Copyright 1993 by David Wexelblat - * Copyright 1994, 1996 by Holger Veit - * Copyright 1994-2003 by The XFree86 Project, Inc - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the names of the above listed copyright holders - * not be used in advertising or publicity pertaining to distribution of - * the software without specific, written prior permission. The above listed - * copyright holders make no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * THE ABOVE LISTED COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD - * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDERS BE - * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY - * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER - * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING - * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -/* - * The ARM32 code here carries the following copyright: - * - * Copyright 1997 - * Digital Equipment Corporation. All rights reserved. - * This software is furnished under license and may be used and copied only in - * accordance with the following terms and conditions. Subject to these - * conditions, you may download, copy, install, use, modify and distribute - * this software in source and/or binary form. No title or ownership is - * transferred hereby. - * - * 1) Any source code used, modified or distributed must reproduce and retain - * this copyright notice and list of conditions as they appear in the - * source file. - * - * 2) No right is granted to use any trade name, trademark, or logo of Digital - * Equipment Corporation. Neither the "Digital Equipment Corporation" - * name nor any trademark or logo of Digital Equipment Corporation may be - * used to endorse or promote products derived from this software without - * the prior written permission of Digital Equipment Corporation. - * - * 3) This software is provided "AS-IS" and any express or implied warranties, - * including but not limited to, any implied warranties of merchantability, - * fitness for a particular purpose, or non-infringement are disclaimed. - * In no event shall DIGITAL be liable for any damages whatsoever, and in - * particular, DIGITAL shall not be liable for special, indirect, - * consequential, or incidental damages or damages for lost profits, loss - * of revenue or loss of use, whether such damages arise in contract, - * negligence, tort, under statute, in equity, at law or otherwise, even - * if advised of the possibility of such damage. - * - */ - -#ifndef _XF86_OSPROC_H -#define _XF86_OSPROC_H - -/* - * The actual prototypes have been pulled into this separate file so - * that they can can be used without pulling in all of the OS specific - * stuff like sys/stat.h, etc. that causes problems for loadable modules. - */ - -/* - * OS-independent modem state flags for xf86SetSerialModemState() and - * xf86GetSerialModemState(). - */ -#define XF86_M_LE 0x001 /* line enable */ -#define XF86_M_DTR 0x002 /* data terminal ready */ -#define XF86_M_RTS 0x004 /* request to send */ -#define XF86_M_ST 0x008 /* secondary transmit */ -#define XF86_M_SR 0x010 /* secondary receive */ -#define XF86_M_CTS 0x020 /* clear to send */ -#define XF86_M_CAR 0x040 /* carrier detect */ -#define XF86_M_RNG 0x080 /* ring */ -#define XF86_M_DSR 0x100 /* data set ready */ - -#ifndef NO_OSLIB_PROTOTYPES -/* - * This is to prevent re-entrancy to FatalError() when aborting. - * Anything that can be called as a result of ddxGiveUp() should use this - * instead of FatalError(). - */ - -#define xf86FatalError(a, b) \ - if (dispatchException & DE_TERMINATE) { \ - ErrorF(a, b); \ - ErrorF("\n"); \ - return; \ - } else FatalError(a, b) - -/***************************************************************************/ -/* Prototypes */ -/***************************************************************************/ - -#include -#include "opaque.h" -#include "xf86Optionstr.h" - -_XFUNCPROTOBEGIN - -/* public functions */ -extern _X_EXPORT Bool xf86EnableIO(void); -extern _X_EXPORT void xf86DisableIO(void); - -#ifdef __NetBSD__ -extern _X_EXPORT void xf86SetTVOut(int); -extern _X_EXPORT void xf86SetRGBOut(void); -#endif -extern _X_EXPORT void xf86OSRingBell(int, int, int); -extern _X_EXPORT void xf86SetReallySlowBcopy(void); -extern _X_EXPORT void xf86SlowBcopy(unsigned char *, unsigned char *, int); -extern _X_EXPORT int xf86OpenSerial(XF86OptionPtr options); -extern _X_EXPORT int xf86SetSerial(int fd, XF86OptionPtr options); -extern _X_EXPORT int xf86SetSerialSpeed(int fd, int speed); -extern _X_EXPORT int xf86ReadSerial(int fd, void *buf, int count); -extern _X_EXPORT int xf86WriteSerial(int fd, const void *buf, int count); -extern _X_EXPORT int xf86CloseSerial(int fd); -extern _X_EXPORT int xf86FlushInput(int fd); -extern _X_EXPORT int xf86WaitForInput(int fd, int timeout); -extern _X_EXPORT int xf86SerialSendBreak(int fd, int duration); -extern _X_EXPORT int xf86SetSerialModemState(int fd, int state); -extern _X_EXPORT int xf86GetSerialModemState(int fd); -extern _X_EXPORT int xf86SerialModemSetBits(int fd, int bits); -extern _X_EXPORT int xf86SerialModemClearBits(int fd, int bits); -extern _X_EXPORT int xf86LoadKernelModule(const char *pathname); -extern _X_EXPORT void xf86OSInputThreadInit(void); - -/* AGP GART interface */ - -typedef struct _AgpInfo { - CARD32 bridgeId; - CARD32 agpMode; - unsigned long base; - unsigned long size; - unsigned long totalPages; - unsigned long systemPages; - unsigned long usedPages; -} AgpInfo, *AgpInfoPtr; - -extern _X_EXPORT Bool xf86AgpGARTSupported(void); -extern _X_EXPORT AgpInfoPtr xf86GetAGPInfo(int screenNum); -extern _X_EXPORT Bool xf86AcquireGART(int screenNum); -extern _X_EXPORT Bool xf86ReleaseGART(int screenNum); -extern _X_EXPORT int xf86AllocateGARTMemory(int screenNum, unsigned long size, - int type, unsigned long *physical); -extern _X_EXPORT Bool xf86DeallocateGARTMemory(int screenNum, int key); -extern _X_EXPORT Bool xf86BindGARTMemory(int screenNum, int key, - unsigned long offset); -extern _X_EXPORT Bool xf86UnbindGARTMemory(int screenNum, int key); -extern _X_EXPORT Bool xf86EnableAGP(int screenNum, CARD32 mode); -extern _X_EXPORT Bool xf86GARTCloseScreen(int screenNum); - -/* These routines are in shared/sigio.c and are not loaded as part of the - module. These routines are small, and the code if very POSIX-signal (or - OS-signal) specific, so it seemed better to provide more complex - wrappers than to wrap each individual function called. */ -extern _X_EXPORT int xf86InstallSIGIOHandler(int fd, void (*f) (int, void *), - void *); -extern _X_EXPORT int xf86RemoveSIGIOHandler(int fd); - -#ifdef XF86_OS_PRIVS -typedef void (*PMClose) (void); -extern _X_EXPORT void xf86OpenConsole(void); -extern _X_EXPORT void xf86CloseConsole(void); -extern _X_HIDDEN Bool xf86VTActivate(int vtno); -extern _X_EXPORT Bool xf86VTSwitchPending(void); -extern _X_EXPORT Bool xf86VTSwitchAway(void); -extern _X_EXPORT Bool xf86VTSwitchTo(void); -extern _X_EXPORT void xf86VTRequest(int sig); -extern _X_EXPORT int xf86ProcessArgument(int, char **, int); -extern _X_EXPORT void xf86UseMsg(void); -extern _X_EXPORT PMClose xf86OSPMOpen(void); - -extern _X_EXPORT void xf86InitVidMem(void); - -#endif /* XF86_OS_PRIVS */ - -#ifdef XSERVER_PLATFORM_BUS -#include "hotplug.h" -void -xf86PlatformDeviceProbe(struct OdevAttributes *attribs); - -void -xf86PlatformReprobeDevice(int index, struct OdevAttributes *attribs); -#endif - -_XFUNCPROTOEND -#endif /* NO_OSLIB_PROTOTYPES */ -#endif /* _XF86_OSPROC_H */ diff --git a/hw/xfree86/parser/Configint.h b/hw/xfree86/parser/Configint.h deleted file mode 100644 index 0a8e4feee..000000000 --- a/hw/xfree86/parser/Configint.h +++ /dev/null @@ -1,214 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2002 by The XFree86 Project, 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). - */ - -/* - * These definitions are used through out the configuration file parser, but - * they should not be visible outside of the parser. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _Configint_h_ -#define _Configint_h_ - -#include -#include -#include -#include -#include "xf86Parser.h" - -typedef enum { PARSE_DECIMAL, PARSE_OCTAL, PARSE_HEX } ParserNumType; - -typedef struct { - int num; /* returned number */ - char *str; /* private copy of the return-string */ - double realnum; /* returned number as a real */ - ParserNumType numType; /* used to enforce correct number formatting */ -} LexRec, *LexPtr; - -extern LexRec xf86_lex_val; - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - -#include "configProcs.h" -#include - -#define TestFree(a) if (a) { free ((void *) a); a = NULL; } - -#define parsePrologue(typeptr,typerec) typeptr ptr; \ -if( (ptr=calloc(1,sizeof(typerec))) == NULL ) { return NULL; } - -#define HANDLE_RETURN(f,func)\ -if ((ptr->f=func) == NULL)\ -{\ - CLEANUP (ptr);\ - return NULL;\ -} - -#define HANDLE_LIST(field,func,type)\ -{\ -type p = func ();\ -if (p == NULL)\ -{\ - CLEANUP (ptr);\ - return NULL;\ -}\ -else\ -{\ - ptr->field = (type) xf86addListItem ((glp) ptr->field, (glp) p);\ -}\ -} - -#define Error(...) do { \ - xf86parseError (__VA_ARGS__); CLEANUP (ptr); return NULL; \ - } while (0) - -/* - * These are defines for error messages to promote consistency. - * Error messages are preceded by the line number, section and file name, - * so these messages should be about the specific keyword and syntax in error. - * To help limit namespace pollution, end each with _MSG. - * Limit messages to 70 characters if possible. - */ - -#define BAD_OPTION_MSG \ -"The Option keyword requires 1 or 2 quoted strings to follow it." -#define INVALID_KEYWORD_MSG \ -"\"%s\" is not a valid keyword in this section." -#define INVALID_SECTION_MSG \ -"\"%s\" is not a valid section name." -#define UNEXPECTED_EOF_MSG \ -"Unexpected EOF. Missing EndSection keyword?" -#define QUOTE_MSG \ -"The %s keyword requires a quoted string to follow it." -#define NUMBER_MSG \ -"The %s keyword requires a number to follow it." -#define POSITIVE_INT_MSG \ -"The %s keyword requires a positive integer to follow it." -#define BOOL_MSG \ -"The %s keyword requires a boolean to follow it." -#define ZAXISMAPPING_MSG \ -"The ZAxisMapping keyword requires 2 positive numbers or X or Y to follow it." -#define DACSPEED_MSG \ -"The DacSpeed keyword must be followed by a list of up to %d numbers." -#define DISPLAYSIZE_MSG \ -"The DisplaySize keyword must be followed by the width and height in mm." -#define HORIZSYNC_MSG \ -"The HorizSync keyword must be followed by a list of numbers or ranges." -#define VERTREFRESH_MSG \ -"The VertRefresh keyword must be followed by a list of numbers or ranges." -#define VIEWPORT_MSG \ -"The Viewport keyword must be followed by an X and Y value." -#define VIRTUAL_MSG \ -"The Virtual keyword must be followed by a width and height value." -#define WEIGHT_MSG \ -"The Weight keyword must be followed by red, green and blue values." -#define BLACK_MSG \ -"The Black keyword must be followed by red, green and blue values." -#define WHITE_MSG \ -"The White keyword must be followed by red, green and blue values." -#define SCREEN_MSG \ -"The Screen keyword must be followed by an optional number, a screen name\n" \ -"\tin quotes, and optional position/layout information." -#define INVALID_SCR_MSG \ -"Invalid Screen line." -#define INPUTDEV_MSG \ -"The InputDevice keyword must be followed by an input device name in quotes." -#define INACTIVE_MSG \ -"The Inactive keyword must be followed by a Device name in quotes." -#define UNDEFINED_SCREEN_MSG \ -"Undefined Screen \"%s\" referenced by ServerLayout \"%s\"." -#define UNDEFINED_MODES_MSG \ -"Undefined Modes Section \"%s\" referenced by Monitor \"%s\"." -#define UNDEFINED_DEVICE_MSG \ -"Undefined Device \"%s\" referenced by Screen \"%s\"." -#define UNDEFINED_ADAPTOR_MSG \ -"Undefined VideoAdaptor \"%s\" referenced by Screen \"%s\"." -#define ADAPTOR_REF_TWICE_MSG \ -"VideoAdaptor \"%s\" already referenced by Screen \"%s\"." -#define UNDEFINED_DEVICE_LAY_MSG \ -"Undefined Device \"%s\" referenced by ServerLayout \"%s\"." -#define UNDEFINED_INPUT_MSG \ -"Undefined InputDevice \"%s\" referenced by ServerLayout \"%s\"." -#define NO_IDENT_MSG \ -"This section must have an Identifier line." -#define ONLY_ONE_MSG \ -"This section must have only one of either %s line." -#define UNDEFINED_INPUTDRIVER_MSG \ -"InputDevice section \"%s\" must have a Driver line." -#define INVALID_GAMMA_MSG \ -"gamma correction value(s) expected\n either one value or three r/g/b values." -#define GROUP_MSG \ -"The Group keyword must be followed by either a group name in quotes or\n" \ -"\ta numerical group id." -#define MULTIPLE_MSG \ -"Multiple \"%s\" lines." -#define MUST_BE_OCTAL_MSG \ -"The number \"%d\" given in this section must be in octal (0xxx) format." -#define GPU_DEVICE_TOO_MANY \ -"More than %d GPU devices defined." - -/* Warning messages */ -#define OBSOLETE_MSG \ -"Ignoring obsolete keyword \"%s\"." - -#endif /* _Configint_h_ */ diff --git a/hw/xfree86/parser/DRI.c b/hw/xfree86/parser/DRI.c deleted file mode 100644 index 31f447d05..000000000 --- a/hw/xfree86/parser/DRI.c +++ /dev/null @@ -1,122 +0,0 @@ -/* DRI.c -- DRI Section in XF86Config file - * Created: Fri Mar 19 08:40:22 1999 by faith@precisioninsight.com - * Revised: Thu Jun 17 16:08:05 1999 by faith@precisioninsight.com - * - * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "os.h" -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec DRITab[] = { - {ENDSECTION, "endsection"}, - {GROUP, "group"}, - {MODE, "mode"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeDRI - -XF86ConfDRIPtr -xf86parseDRISection(void) -{ - int token; - - parsePrologue(XF86ConfDRIPtr, XF86ConfDRIRec); - - /* Zero is a valid value for this. */ - ptr->dri_group = -1; - while ((token = xf86getToken(DRITab)) != ENDSECTION) { - switch (token) { - case GROUP: - if ((token = xf86getSubToken(&(ptr->dri_comment))) == STRING) - ptr->dri_group_name = xf86_lex_val.str; - else if (token == NUMBER) - ptr->dri_group = xf86_lex_val.num; - else - Error(GROUP_MSG); - break; - case MODE: - if (xf86getSubToken(&(ptr->dri_comment)) != NUMBER) - Error(NUMBER_MSG, "Mode"); - if (xf86_lex_val.numType != PARSE_OCTAL) - Error(MUST_BE_OCTAL_MSG, xf86_lex_val.num); - ptr->dri_mode = xf86_lex_val.num; - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - case COMMENT: - ptr->dri_comment = xf86addComment(ptr->dri_comment, xf86_lex_val.str); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - -#ifdef DEBUG - ErrorF("DRI section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -void -xf86printDRISection(FILE * cf, XF86ConfDRIPtr ptr) -{ - if (ptr == NULL) - return; - - fprintf(cf, "Section \"DRI\"\n"); - if (ptr->dri_comment) - fprintf(cf, "%s", ptr->dri_comment); - if (ptr->dri_group_name) - fprintf(cf, "\tGroup \"%s\"\n", ptr->dri_group_name); - else if (ptr->dri_group >= 0) - fprintf(cf, "\tGroup %d\n", ptr->dri_group); - if (ptr->dri_mode) - fprintf(cf, "\tMode 0%o\n", ptr->dri_mode); - fprintf(cf, "EndSection\n\n"); -} - -void -xf86freeDRI(XF86ConfDRIPtr ptr) -{ - if (ptr == NULL) - return; - - TestFree(ptr->dri_comment); - free(ptr); -} diff --git a/hw/xfree86/parser/Device.c b/hw/xfree86/parser/Device.c deleted file mode 100644 index 34b7f6557..000000000 --- a/hw/xfree86/parser/Device.c +++ /dev/null @@ -1,350 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec DeviceTab[] = { - {ENDSECTION, "endsection"}, - {IDENTIFIER, "identifier"}, - {VENDOR, "vendorname"}, - {BOARD, "boardname"}, - {CHIPSET, "chipset"}, - {RAMDAC, "ramdac"}, - {DACSPEED, "dacspeed"}, - {CLOCKS, "clocks"}, - {MATCHSEAT, "matchseat"}, - {OPTION, "option"}, - {VIDEORAM, "videoram"}, - {BIOSBASE, "biosbase"}, - {MEMBASE, "membase"}, - {IOBASE, "iobase"}, - {CLOCKCHIP, "clockchip"}, - {CHIPID, "chipid"}, - {CHIPREV, "chiprev"}, - {CARD, "card"}, - {DRIVER, "driver"}, - {BUSID, "busid"}, - {IRQ, "irq"}, - {SCREEN, "screen"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeDeviceList - -XF86ConfDevicePtr -xf86parseDeviceSection(void) -{ - int i; - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfDevicePtr, XF86ConfDeviceRec) - - /* Zero is a valid value for these */ - ptr->dev_chipid = -1; - ptr->dev_chiprev = -1; - ptr->dev_irq = -1; - while ((token = xf86getToken(DeviceTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->dev_comment = xf86addComment(ptr->dev_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->dev_identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case VENDOR: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "Vendor"); - ptr->dev_vendor = xf86_lex_val.str; - break; - case BOARD: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "Board"); - ptr->dev_board = xf86_lex_val.str; - break; - case CHIPSET: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "Chipset"); - ptr->dev_chipset = xf86_lex_val.str; - break; - case CARD: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "Card"); - ptr->dev_card = xf86_lex_val.str; - break; - case DRIVER: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "Driver"); - ptr->dev_driver = xf86_lex_val.str; - break; - case RAMDAC: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "Ramdac"); - ptr->dev_ramdac = xf86_lex_val.str; - break; - case DACSPEED: - for (i = 0; i < CONF_MAXDACSPEEDS; i++) - ptr->dev_dacSpeeds[i] = 0; - if (xf86getSubToken(&(ptr->dev_comment)) != NUMBER) { - Error(DACSPEED_MSG, CONF_MAXDACSPEEDS); - } - else { - ptr->dev_dacSpeeds[0] = (int) (xf86_lex_val.realnum * 1000.0 + 0.5); - for (i = 1; i < CONF_MAXDACSPEEDS; i++) { - if (xf86getSubToken(&(ptr->dev_comment)) == NUMBER) - ptr->dev_dacSpeeds[i] = (int) - (xf86_lex_val.realnum * 1000.0 + 0.5); - else { - xf86unGetToken(token); - break; - } - } - } - break; - case VIDEORAM: - if (xf86getSubToken(&(ptr->dev_comment)) != NUMBER) - Error(NUMBER_MSG, "VideoRam"); - ptr->dev_videoram = xf86_lex_val.num; - break; - case BIOSBASE: - if (xf86getSubToken(&(ptr->dev_comment)) != NUMBER) - Error(NUMBER_MSG, "BIOSBase"); - /* ignored */ - break; - case MEMBASE: - if (xf86getSubToken(&(ptr->dev_comment)) != NUMBER) - Error(NUMBER_MSG, "MemBase"); - ptr->dev_mem_base = xf86_lex_val.num; - break; - case IOBASE: - if (xf86getSubToken(&(ptr->dev_comment)) != NUMBER) - Error(NUMBER_MSG, "IOBase"); - ptr->dev_io_base = xf86_lex_val.num; - break; - case CLOCKCHIP: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "ClockChip"); - ptr->dev_clockchip = xf86_lex_val.str; - break; - case CHIPID: - if (xf86getSubToken(&(ptr->dev_comment)) != NUMBER) - Error(NUMBER_MSG, "ChipID"); - ptr->dev_chipid = xf86_lex_val.num; - break; - case CHIPREV: - if (xf86getSubToken(&(ptr->dev_comment)) != NUMBER) - Error(NUMBER_MSG, "ChipRev"); - ptr->dev_chiprev = xf86_lex_val.num; - break; - - case CLOCKS: - token = xf86getSubToken(&(ptr->dev_comment)); - for (i = ptr->dev_clocks; - token == NUMBER && i < CONF_MAXCLOCKS; i++) { - ptr->dev_clock[i] = (int) (xf86_lex_val.realnum * 1000.0 + 0.5); - token = xf86getSubToken(&(ptr->dev_comment)); - } - ptr->dev_clocks = i; - xf86unGetToken(token); - break; - case MATCHSEAT: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "MatchSeat"); - ptr->match_seat = xf86_lex_val.str; - break; - case OPTION: - ptr->dev_option_lst = xf86parseOption(ptr->dev_option_lst); - break; - case BUSID: - if (xf86getSubToken(&(ptr->dev_comment)) != STRING) - Error(QUOTE_MSG, "BusID"); - ptr->dev_busid = xf86_lex_val.str; - break; - case IRQ: - if (xf86getSubToken(&(ptr->dev_comment)) != NUMBER) - Error(QUOTE_MSG, "IRQ"); - ptr->dev_irq = xf86_lex_val.num; - break; - case SCREEN: - if (xf86getSubToken(&(ptr->dev_comment)) != NUMBER) - Error(NUMBER_MSG, "Screen"); - ptr->dev_screen = xf86_lex_val.num; - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - - if (!has_ident) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("Device section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -void -xf86printDeviceSection(FILE * cf, XF86ConfDevicePtr ptr) -{ - int i; - - while (ptr) { - fprintf(cf, "Section \"Device\"\n"); - if (ptr->dev_comment) - fprintf(cf, "%s", ptr->dev_comment); - if (ptr->dev_identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->dev_identifier); - if (ptr->dev_driver) - fprintf(cf, "\tDriver \"%s\"\n", ptr->dev_driver); - if (ptr->dev_vendor) - fprintf(cf, "\tVendorName \"%s\"\n", ptr->dev_vendor); - if (ptr->dev_board) - fprintf(cf, "\tBoardName \"%s\"\n", ptr->dev_board); - if (ptr->dev_chipset) - fprintf(cf, "\tChipSet \"%s\"\n", ptr->dev_chipset); - if (ptr->dev_card) - fprintf(cf, "\tCard \"%s\"\n", ptr->dev_card); - if (ptr->dev_ramdac) - fprintf(cf, "\tRamDac \"%s\"\n", ptr->dev_ramdac); - if (ptr->dev_dacSpeeds[0] > 0) { - fprintf(cf, "\tDacSpeed "); - for (i = 0; i < CONF_MAXDACSPEEDS && ptr->dev_dacSpeeds[i] > 0; i++) - fprintf(cf, "%g ", (double) (ptr->dev_dacSpeeds[i]) / 1000.0); - fprintf(cf, "\n"); - } - if (ptr->dev_videoram) - fprintf(cf, "\tVideoRam %d\n", ptr->dev_videoram); - if (ptr->dev_mem_base) - fprintf(cf, "\tMemBase 0x%lx\n", ptr->dev_mem_base); - if (ptr->dev_io_base) - fprintf(cf, "\tIOBase 0x%lx\n", ptr->dev_io_base); - if (ptr->dev_clockchip) - fprintf(cf, "\tClockChip \"%s\"\n", ptr->dev_clockchip); - if (ptr->dev_chipid != -1) - fprintf(cf, "\tChipId 0x%x\n", ptr->dev_chipid); - if (ptr->dev_chiprev != -1) - fprintf(cf, "\tChipRev 0x%x\n", ptr->dev_chiprev); - - xf86printOptionList(cf, ptr->dev_option_lst, 1); - if (ptr->dev_clocks > 0) { - fprintf(cf, "\tClocks "); - for (i = 0; i < ptr->dev_clocks; i++) - fprintf(cf, "%.1f ", (double) ptr->dev_clock[i] / 1000.0); - fprintf(cf, "\n"); - } - if (ptr->dev_busid) - fprintf(cf, "\tBusID \"%s\"\n", ptr->dev_busid); - if (ptr->dev_screen > 0) - fprintf(cf, "\tScreen %d\n", ptr->dev_screen); - if (ptr->dev_irq >= 0) - fprintf(cf, "\tIRQ %d\n", ptr->dev_irq); - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } -} - -void -xf86freeDeviceList(XF86ConfDevicePtr ptr) -{ - XF86ConfDevicePtr prev; - - while (ptr) { - TestFree(ptr->dev_identifier); - TestFree(ptr->dev_vendor); - TestFree(ptr->dev_board); - TestFree(ptr->dev_chipset); - TestFree(ptr->dev_card); - TestFree(ptr->dev_driver); - TestFree(ptr->dev_ramdac); - TestFree(ptr->dev_clockchip); - TestFree(ptr->dev_comment); - xf86optionListFree(ptr->dev_option_lst); - - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -XF86ConfDevicePtr -xf86findDevice(const char *ident, XF86ConfDevicePtr p) -{ - while (p) { - if (xf86nameCompare(ident, p->dev_identifier) == 0) - return p; - - p = p->list.next; - } - return NULL; -} diff --git a/hw/xfree86/parser/Extensions.c b/hw/xfree86/parser/Extensions.c deleted file mode 100644 index 3a2195901..000000000 --- a/hw/xfree86/parser/Extensions.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2004 Red Hat Inc., Raleigh, North Carolina. - * - * All Rights Reserved. - * - * 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, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/* - * Authors: - * Kevin E. Martin - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "os.h" -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec ExtensionsTab[] = { - {ENDSECTION, "endsection"}, - {OPTION, "option"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeExtensions - -XF86ConfExtensionsPtr -xf86parseExtensionsSection(void) -{ - int token; - - parsePrologue(XF86ConfExtensionsPtr, XF86ConfExtensionsRec); - - while ((token = xf86getToken(ExtensionsTab)) != ENDSECTION) { - switch (token) { - case OPTION: - ptr->ext_option_lst = xf86parseOption(ptr->ext_option_lst); - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - case COMMENT: - ptr->extensions_comment = - xf86addComment(ptr->extensions_comment, xf86_lex_val.str); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - -#ifdef DEBUG - ErrorF("Extensions section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -void -xf86printExtensionsSection(FILE * cf, XF86ConfExtensionsPtr ptr) -{ - XF86OptionPtr p; - - if (ptr == NULL || ptr->ext_option_lst == NULL) - return; - - p = ptr->ext_option_lst; - fprintf(cf, "Section \"Extensions\"\n"); - if (ptr->extensions_comment) - fprintf(cf, "%s", ptr->extensions_comment); - xf86printOptionList(cf, p, 1); - fprintf(cf, "EndSection\n\n"); -} - -void -xf86freeExtensions(XF86ConfExtensionsPtr ptr) -{ - if (ptr == NULL) - return; - - xf86optionListFree(ptr->ext_option_lst); - TestFree(ptr->extensions_comment); - free(ptr); -} diff --git a/hw/xfree86/parser/Files.c b/hw/xfree86/parser/Files.c deleted file mode 100644 index c86ac7af2..000000000 --- a/hw/xfree86/parser/Files.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec FilesTab[] = { - {ENDSECTION, "endsection"}, - {FONTPATH, "fontpath"}, - {MODULEPATH, "modulepath"}, - {LOGFILEPATH, "logfile"}, - {XKBDIR, "xkbdir"}, - /* Obsolete keywords that aren't used but shouldn't cause errors: */ - {OBSOLETE_TOKEN, "rgbpath"}, - {OBSOLETE_TOKEN, "inputdevices"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeFiles - -XF86ConfFilesPtr -xf86parseFilesSection(void) -{ - int i, j; - int k, l; - char *str; - int token; - - parsePrologue(XF86ConfFilesPtr, XF86ConfFilesRec) - - while ((token = xf86getToken(FilesTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->file_comment = xf86addComment(ptr->file_comment, xf86_lex_val.str); - break; - case FONTPATH: - if (xf86getSubToken(&(ptr->file_comment)) != STRING) - Error(QUOTE_MSG, "FontPath"); - j = FALSE; - str = xf86_lex_val.str; - if (ptr->file_fontpath == NULL) { - ptr->file_fontpath = calloc(1, 1); - i = strlen(str) + 1; - } - else { - i = strlen(ptr->file_fontpath) + strlen(str) + 1; - if (ptr->file_fontpath[strlen(ptr->file_fontpath) - 1] != ',') { - i++; - j = TRUE; - } - } - ptr->file_fontpath = realloc(ptr->file_fontpath, i); - if (j) - strcat(ptr->file_fontpath, ","); - - strcat(ptr->file_fontpath, str); - free(xf86_lex_val.str); - break; - case MODULEPATH: - if (xf86getSubToken(&(ptr->file_comment)) != STRING) - Error(QUOTE_MSG, "ModulePath"); - l = FALSE; - str = xf86_lex_val.str; - if (ptr->file_modulepath == NULL) { - ptr->file_modulepath = malloc(1); - ptr->file_modulepath[0] = '\0'; - k = strlen(str) + 1; - } - else { - k = strlen(ptr->file_modulepath) + strlen(str) + 1; - if (ptr->file_modulepath[strlen(ptr->file_modulepath) - 1] != - ',') { - k++; - l = TRUE; - } - } - ptr->file_modulepath = realloc(ptr->file_modulepath, k); - if (l) - strcat(ptr->file_modulepath, ","); - - strcat(ptr->file_modulepath, str); - free(xf86_lex_val.str); - break; - case LOGFILEPATH: - if (xf86getSubToken(&(ptr->file_comment)) != STRING) - Error(QUOTE_MSG, "LogFile"); - ptr->file_logfile = xf86_lex_val.str; - break; - case XKBDIR: - if (xf86getSubToken(&(ptr->file_xkbdir)) != STRING) - Error(QUOTE_MSG, "XkbDir"); - ptr->file_xkbdir = xf86_lex_val.str; - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - case OBSOLETE_TOKEN: - xf86parseError(OBSOLETE_MSG, xf86tokenString()); - xf86getSubToken(&(ptr->file_comment)); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - -#ifdef DEBUG - printf("File section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -void -xf86printFileSection(FILE * cf, XF86ConfFilesPtr ptr) -{ - char *p, *s; - - if (ptr == NULL) - return; - - if (ptr->file_comment) - fprintf(cf, "%s", ptr->file_comment); - if (ptr->file_logfile) - fprintf(cf, "\tLogFile \"%s\"\n", ptr->file_logfile); - if (ptr->file_modulepath) { - s = ptr->file_modulepath; - p = index(s, ','); - while (p) { - *p = '\000'; - fprintf(cf, "\tModulePath \"%s\"\n", s); - *p = ','; - s = p; - s++; - p = index(s, ','); - } - fprintf(cf, "\tModulePath \"%s\"\n", s); - } - if (ptr->file_fontpath) { - s = ptr->file_fontpath; - p = index(s, ','); - while (p) { - *p = '\000'; - fprintf(cf, "\tFontPath \"%s\"\n", s); - *p = ','; - s = p; - s++; - p = index(s, ','); - } - fprintf(cf, "\tFontPath \"%s\"\n", s); - } - if (ptr->file_xkbdir) - fprintf(cf, "\tXkbDir \"%s\"\n", ptr->file_xkbdir); -} - -void -xf86freeFiles(XF86ConfFilesPtr p) -{ - if (p == NULL) - return; - - TestFree(p->file_logfile); - TestFree(p->file_modulepath); - TestFree(p->file_fontpath); - TestFree(p->file_comment); - TestFree(p->file_xkbdir); - - free(p); -} diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c deleted file mode 100644 index d677cf1db..000000000 --- a/hw/xfree86/parser/Flags.c +++ /dev/null @@ -1,493 +0,0 @@ -/* - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" -#include -#include "Xprintf.h" -#include "optionstr.h" - - -static const xf86ConfigSymTabRec ServerFlagsTab[] = { - {ENDSECTION, "endsection"}, - {DONTZAP, "dontzap"}, - {DONTZOOM, "dontzoom"}, - {DISABLEVIDMODE, "disablevidmodeextension"}, - {ALLOWNONLOCAL, "allownonlocalxvidtune"}, - {DISABLEMODINDEV, "disablemodindev"}, - {MODINDEVALLOWNONLOCAL, "allownonlocalmodindev"}, - {ALLOWMOUSEOPENFAIL, "allowmouseopenfail"}, - {OPTION, "option"}, - {BLANKTIME, "blanktime"}, - {STANDBYTIME, "standbytime"}, - {SUSPENDTIME, "suspendtime"}, - {OFFTIME, "offtime"}, - {DEFAULTLAYOUT, "defaultserverlayout"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeFlags - -XF86ConfFlagsPtr -xf86parseFlagsSection(void) -{ - int token; - - parsePrologue(XF86ConfFlagsPtr, XF86ConfFlagsRec) - - while ((token = xf86getToken(ServerFlagsTab)) != ENDSECTION) { - int hasvalue = FALSE; - int strvalue = FALSE; - int tokentype; - - switch (token) { - case COMMENT: - ptr->flg_comment = xf86addComment(ptr->flg_comment, xf86_lex_val.str); - break; - /* - * these old keywords are turned into standard generic options. - * we fall through here on purpose - */ - case DEFAULTLAYOUT: - strvalue = TRUE; - case BLANKTIME: - case STANDBYTIME: - case SUSPENDTIME: - case OFFTIME: - hasvalue = TRUE; - case DONTZAP: - case DONTZOOM: - case DISABLEVIDMODE: - case ALLOWNONLOCAL: - case DISABLEMODINDEV: - case MODINDEVALLOWNONLOCAL: - case ALLOWMOUSEOPENFAIL: - { - int i = 0; - - while (ServerFlagsTab[i].token != -1) { - char *tmp; - - if (ServerFlagsTab[i].token == token) { - char *valstr = NULL; - - tmp = strdup(ServerFlagsTab[i].name); - if (hasvalue) { - tokentype = xf86getSubToken(&(ptr->flg_comment)); - if (strvalue) { - if (tokentype != STRING) - Error(QUOTE_MSG, tmp); - valstr = xf86_lex_val.str; - } - else { - if (tokentype != NUMBER) - Error(NUMBER_MSG, tmp); - if (asprintf(&valstr, "%d", xf86_lex_val.num) == -1) - valstr = NULL; - } - } - ptr->flg_option_lst = xf86addNewOption - (ptr->flg_option_lst, tmp, valstr); - } - i++; - } - } - break; - case OPTION: - ptr->flg_option_lst = xf86parseOption(ptr->flg_option_lst); - break; - - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - -#ifdef DEBUG - printf("Flags section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -void -xf86printServerFlagsSection(FILE * f, XF86ConfFlagsPtr flags) -{ - XF86OptionPtr p; - - if ((!flags) || (!flags->flg_option_lst)) - return; - p = flags->flg_option_lst; - fprintf(f, "Section \"ServerFlags\"\n"); - if (flags->flg_comment) - fprintf(f, "%s", flags->flg_comment); - xf86printOptionList(f, p, 1); - fprintf(f, "EndSection\n\n"); -} - -static XF86OptionPtr -addNewOption2(XF86OptionPtr head, char *name, char *_val, int used) -{ - XF86OptionPtr new, old = NULL; - - /* Don't allow duplicates, free old strings */ - if (head != NULL && (old = xf86findOption(head, name)) != NULL) { - new = old; - free(new->opt_name); - free(new->opt_val); - } - else - new = calloc(1, sizeof(*new)); - new->opt_name = name; - new->opt_val = _val; - new->opt_used = used; - - if (old) - return head; - return ((XF86OptionPtr) xf86addListItem((glp) head, (glp) new)); -} - -XF86OptionPtr -xf86addNewOption(XF86OptionPtr head, char *name, char *_val) -{ - return addNewOption2(head, name, _val, 0); -} - -void -xf86freeFlags(XF86ConfFlagsPtr flags) -{ - if (flags == NULL) - return; - xf86optionListFree(flags->flg_option_lst); - TestFree(flags->flg_comment); - free(flags); -} - -XF86OptionPtr -xf86optionListDup(XF86OptionPtr opt) -{ - XF86OptionPtr newopt = NULL; - char *_val; - - while (opt) { - _val = opt->opt_val ? strdup(opt->opt_val) : NULL; - newopt = xf86addNewOption(newopt, strdup(opt->opt_name), _val); - newopt->opt_used = opt->opt_used; - if (opt->opt_comment) - newopt->opt_comment = strdup(opt->opt_comment); - opt = opt->list.next; - } - return newopt; -} - -void -xf86optionListFree(XF86OptionPtr opt) -{ - XF86OptionPtr prev; - - while (opt) { - TestFree(opt->opt_name); - TestFree(opt->opt_val); - TestFree(opt->opt_comment); - prev = opt; - opt = opt->list.next; - free(prev); - } -} - -char * -xf86optionName(XF86OptionPtr opt) -{ - if (opt) - return opt->opt_name; - return 0; -} - -char * -xf86optionValue(XF86OptionPtr opt) -{ - if (opt) - return opt->opt_val; - return 0; -} - -XF86OptionPtr -xf86newOption(char *name, char *value) -{ - XF86OptionPtr opt; - - opt = calloc(1, sizeof(*opt)); - if (!opt) - return NULL; - - opt->opt_used = 0; - opt->list.next = 0; - opt->opt_name = name; - opt->opt_val = value; - - return opt; -} - -XF86OptionPtr -xf86nextOption(XF86OptionPtr list) -{ - if (!list) - return NULL; - return list->list.next; -} - -/* - * this function searches the given option list for the named option and - * returns a pointer to the option rec if found. If not found, it returns - * NULL - */ - -XF86OptionPtr -xf86findOption(XF86OptionPtr list, const char *name) -{ - while (list) { - if (xf86nameCompare(list->opt_name, name) == 0) - return list; - list = list->list.next; - } - return NULL; -} - -/* - * this function searches the given option list for the named option. If - * found and the option has a parameter, a pointer to the parameter is - * returned. If the option does not have a parameter an empty string is - * returned. If the option is not found, a NULL is returned. - */ - -const char * -xf86findOptionValue(XF86OptionPtr list, const char *name) -{ - XF86OptionPtr p = xf86findOption(list, name); - - if (p) { - if (p->opt_val) - return p->opt_val; - else - return ""; - } - return NULL; -} - -XF86OptionPtr -xf86optionListCreate(const char **options, int count, int used) -{ - XF86OptionPtr p = NULL; - char *t1, *t2; - int i; - - if (count == -1) { - for (count = 0; options[count]; count++); - } - if ((count % 2) != 0) { - fprintf(stderr, - "xf86optionListCreate: count must be an even number.\n"); - return NULL; - } - for (i = 0; i < count; i += 2) { - t1 = strdup(options[i]); - t2 = strdup(options[i + 1]); - p = addNewOption2(p, t1, t2, used); - } - - return p; -} - -/* the 2 given lists are merged. If an option with the same name is present in - * both, the option from the user list - specified in the second argument - - * is used. The end result is a single valid list of options. Duplicates - * are freed, and the original lists are no longer guaranteed to be complete. - */ -XF86OptionPtr -xf86optionListMerge(XF86OptionPtr head, XF86OptionPtr tail) -{ - XF86OptionPtr a, b, ap = NULL, bp = NULL; - - a = tail; - b = head; - while (tail && b) { - if (xf86nameCompare(a->opt_name, b->opt_name) == 0) { - if (b == head) - head = a; - else - bp->list.next = a; - if (a == tail) - tail = a->list.next; - else - ap->list.next = a->list.next; - a->list.next = b->list.next; - b->list.next = NULL; - xf86optionListFree(b); - b = a->list.next; - bp = a; - a = tail; - ap = NULL; - } - else { - ap = a; - if (!(a = a->list.next)) { - a = tail; - bp = b; - b = b->list.next; - ap = NULL; - } - } - } - - if (head) { - for (a = head; a->list.next; a = a->list.next); - a->list.next = tail; - } - else - head = tail; - - return head; -} - -char * -xf86uLongToString(unsigned long i) -{ - char *s; - - if (asprintf(&s, "%lu", i) == -1) - return NULL; - return s; -} - -XF86OptionPtr -xf86parseOption(XF86OptionPtr head) -{ - XF86OptionPtr option, cnew, old; - char *name, *comment = NULL; - int token; - - if ((token = xf86getSubToken(&comment)) != STRING) { - xf86parseError(BAD_OPTION_MSG); - free(comment); - return head; - } - - name = xf86_lex_val.str; - if ((token = xf86getSubToken(&comment)) == STRING) { - option = xf86newOption(name, xf86_lex_val.str); - option->opt_comment = comment; - if ((token = xf86getToken(NULL)) == COMMENT) - option->opt_comment = xf86addComment(option->opt_comment, xf86_lex_val.str); - else - xf86unGetToken(token); - } - else { - option = xf86newOption(name, NULL); - option->opt_comment = comment; - if (token == COMMENT) - option->opt_comment = xf86addComment(option->opt_comment, xf86_lex_val.str); - else - xf86unGetToken(token); - } - - old = NULL; - - /* Don't allow duplicates */ - if (head != NULL && (old = xf86findOption(head, name)) != NULL) { - cnew = old; - free(option->opt_name); - TestFree(option->opt_val); - TestFree(option->opt_comment); - free(option); - } - else - cnew = option; - - if (old == NULL) - return ((XF86OptionPtr) xf86addListItem((glp) head, (glp) cnew)); - - return head; -} - -void -xf86printOptionList(FILE * fp, XF86OptionPtr list, int tabs) -{ - int i; - - if (!list) - return; - while (list) { - for (i = 0; i < tabs; i++) - fputc('\t', fp); - if (list->opt_val) - fprintf(fp, "Option \"%s\" \"%s\"", list->opt_name, - list->opt_val); - else - fprintf(fp, "Option \"%s\"", list->opt_name); - if (list->opt_comment) - fprintf(fp, "%s", list->opt_comment); - else - fputc('\n', fp); - list = list->list.next; - } -} diff --git a/hw/xfree86/parser/Input.c b/hw/xfree86/parser/Input.c deleted file mode 100644 index 88d19b6b5..000000000 --- a/hw/xfree86/parser/Input.c +++ /dev/null @@ -1,202 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "os.h" -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec InputTab[] = { - {ENDSECTION, "endsection"}, - {IDENTIFIER, "identifier"}, - {OPTION, "option"}, - {DRIVER, "driver"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeInputList - -XF86ConfInputPtr -xf86parseInputSection(void) -{ - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfInputPtr, XF86ConfInputRec) - - while ((token = xf86getToken(InputTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->inp_comment = xf86addComment(ptr->inp_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->inp_comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->inp_identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case DRIVER: - if (xf86getSubToken(&(ptr->inp_comment)) != STRING) - Error(QUOTE_MSG, "Driver"); - if (strcmp(xf86_lex_val.str, "keyboard") == 0) { - ptr->inp_driver = strdup("kbd"); - free(xf86_lex_val.str); - } - else - ptr->inp_driver = xf86_lex_val.str; - break; - case OPTION: - ptr->inp_option_lst = xf86parseOption(ptr->inp_option_lst); - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - - if (!has_ident) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("InputDevice section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -void -xf86printInputSection(FILE * cf, XF86ConfInputPtr ptr) -{ - while (ptr) { - fprintf(cf, "Section \"InputDevice\"\n"); - if (ptr->inp_comment) - fprintf(cf, "%s", ptr->inp_comment); - if (ptr->inp_identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->inp_identifier); - if (ptr->inp_driver) - fprintf(cf, "\tDriver \"%s\"\n", ptr->inp_driver); - xf86printOptionList(cf, ptr->inp_option_lst, 1); - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } -} - -void -xf86freeInputList(XF86ConfInputPtr ptr) -{ - XF86ConfInputPtr prev; - - while (ptr) { - TestFree(ptr->inp_identifier); - TestFree(ptr->inp_driver); - TestFree(ptr->inp_comment); - xf86optionListFree(ptr->inp_option_lst); - - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -int -xf86validateInput(XF86ConfigPtr p) -{ - XF86ConfInputPtr input = p->conf_input_lst; - - while (input) { - if (!input->inp_driver) { - xf86validationError(UNDEFINED_INPUTDRIVER_MSG, - input->inp_identifier); - return FALSE; - } - input = input->list.next; - } - return TRUE; -} - -XF86ConfInputPtr -xf86findInput(const char *ident, XF86ConfInputPtr p) -{ - while (p) { - if (xf86nameCompare(ident, p->inp_identifier) == 0) - return p; - - p = p->list.next; - } - return NULL; -} - -XF86ConfInputPtr -xf86findInputByDriver(const char *driver, XF86ConfInputPtr p) -{ - while (p) { - if (xf86nameCompare(driver, p->inp_driver) == 0) - return p; - - p = p->list.next; - } - return NULL; -} diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c deleted file mode 100644 index 7281659e0..000000000 --- a/hw/xfree86/parser/InputClass.c +++ /dev/null @@ -1,499 +0,0 @@ -/* - * Copyright (c) 2009 Dan Nicholson - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include "os.h" -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec InputClassTab[] = { - {ENDSECTION, "endsection"}, - {IDENTIFIER, "identifier"}, - {OPTION, "option"}, - {DRIVER, "driver"}, - {MATCH_PRODUCT, "matchproduct"}, - {MATCH_VENDOR, "matchvendor"}, - {MATCH_DEVICE_PATH, "matchdevicepath"}, - {MATCH_OS, "matchos"}, - {MATCH_PNPID, "matchpnpid"}, - {MATCH_USBID, "matchusbid"}, - {MATCH_DRIVER, "matchdriver"}, - {MATCH_TAG, "matchtag"}, - {MATCH_LAYOUT, "matchlayout"}, - {MATCH_IS_KEYBOARD, "matchiskeyboard"}, - {MATCH_IS_POINTER, "matchispointer"}, - {MATCH_IS_JOYSTICK, "matchisjoystick"}, - {MATCH_IS_TABLET, "matchistablet"}, - {MATCH_IS_TABLET_PAD, "matchistabletpad"}, - {MATCH_IS_TOUCHPAD, "matchistouchpad"}, - {MATCH_IS_TOUCHSCREEN, "matchistouchscreen"}, - {NOMATCH_PRODUCT, "nomatchproduct"}, - {NOMATCH_VENDOR, "nomatchvendor"}, - {NOMATCH_DEVICE_PATH, "nomatchdevicepath"}, - {NOMATCH_OS, "nomatchos"}, - {NOMATCH_PNPID, "nomatchpnpid"}, - {NOMATCH_USBID, "nomatchusbid"}, - {NOMATCH_DRIVER, "nomatchdriver"}, - {NOMATCH_TAG, "nomatchtag"}, - {NOMATCH_LAYOUT, "nomatchlayout"}, - {-1, ""}, -}; - -static void -xf86freeInputClassList(XF86ConfInputClassPtr ptr) -{ - XF86ConfInputClassPtr prev; - - while (ptr) { - xf86MatchGroup *group, *next; - char **list; - - TestFree(ptr->identifier); - TestFree(ptr->driver); - - xorg_list_for_each_entry_safe(group, next, &ptr->match_product, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - xorg_list_for_each_entry_safe(group, next, &ptr->match_vendor, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - xorg_list_for_each_entry_safe(group, next, &ptr->match_device, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - xorg_list_for_each_entry_safe(group, next, &ptr->match_os, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - xorg_list_for_each_entry_safe(group, next, &ptr->match_pnpid, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - xorg_list_for_each_entry_safe(group, next, &ptr->match_usbid, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - xorg_list_for_each_entry_safe(group, next, &ptr->match_driver, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - xorg_list_for_each_entry_safe(group, next, &ptr->match_tag, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - xorg_list_for_each_entry_safe(group, next, &ptr->match_layout, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - - TestFree(ptr->comment); - xf86optionListFree(ptr->option_lst); - - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -#define CLEANUP xf86freeInputClassList - -#define TOKEN_SEP "|" - -enum MatchType { - MATCH_NORMAL, - MATCH_NEGATED, -}; - -static void -add_group_entry(struct xorg_list *head, char **values, enum MatchType type) -{ - xf86MatchGroup *group; - - group = malloc(sizeof(*group)); - if (group) { - group->is_negated = (type == MATCH_NEGATED); - group->values = values; - xorg_list_add(&group->entry, head); - } -} - -XF86ConfInputClassPtr -xf86parseInputClassSection(void) -{ - int has_ident = FALSE; - int token; - enum MatchType matchtype; - - parsePrologue(XF86ConfInputClassPtr, XF86ConfInputClassRec) - - /* Initialize MatchGroup lists */ - xorg_list_init(&ptr->match_product); - xorg_list_init(&ptr->match_vendor); - xorg_list_init(&ptr->match_device); - xorg_list_init(&ptr->match_os); - xorg_list_init(&ptr->match_pnpid); - xorg_list_init(&ptr->match_usbid); - xorg_list_init(&ptr->match_driver); - xorg_list_init(&ptr->match_tag); - xorg_list_init(&ptr->match_layout); - - while ((token = xf86getToken(InputClassTab)) != ENDSECTION) { - matchtype = MATCH_NORMAL; - - switch (token) { - case COMMENT: - ptr->comment = xf86addComment(ptr->comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case DRIVER: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "Driver"); - if (strcmp(xf86_lex_val.str, "keyboard") == 0) { - ptr->driver = strdup("kbd"); - free(xf86_lex_val.str); - } - else - ptr->driver = xf86_lex_val.str; - break; - case OPTION: - ptr->option_lst = xf86parseOption(ptr->option_lst); - break; - case NOMATCH_PRODUCT: - matchtype = MATCH_NEGATED; - /* fallthrough */ - case MATCH_PRODUCT: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchProduct"); - add_group_entry(&ptr->match_product, - xstrtokenize(xf86_lex_val.str, TOKEN_SEP), - matchtype); - free(xf86_lex_val.str); - break; - case NOMATCH_VENDOR: - matchtype = MATCH_NEGATED; - /* fallthrough */ - case MATCH_VENDOR: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchVendor"); - add_group_entry(&ptr->match_vendor, - xstrtokenize(xf86_lex_val.str, TOKEN_SEP), - matchtype); - free(xf86_lex_val.str); - break; - case NOMATCH_DEVICE_PATH: - matchtype = MATCH_NEGATED; - /* fallthrough */ - case MATCH_DEVICE_PATH: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchDevicePath"); - add_group_entry(&ptr->match_device, - xstrtokenize(xf86_lex_val.str, TOKEN_SEP), - matchtype); - free(xf86_lex_val.str); - break; - case NOMATCH_OS: - matchtype = MATCH_NEGATED; - /* fallthrough */ - case MATCH_OS: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchOS"); - add_group_entry(&ptr->match_os, xstrtokenize(xf86_lex_val.str, - TOKEN_SEP), - matchtype); - free(xf86_lex_val.str); - break; - case NOMATCH_PNPID: - matchtype = MATCH_NEGATED; - /* fallthrough */ - case MATCH_PNPID: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchPnPID"); - add_group_entry(&ptr->match_pnpid, - xstrtokenize(xf86_lex_val.str, TOKEN_SEP), - matchtype); - free(xf86_lex_val.str); - break; - case NOMATCH_USBID: - matchtype = MATCH_NEGATED; - /* fallthrough */ - case MATCH_USBID: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchUSBID"); - add_group_entry(&ptr->match_usbid, - xstrtokenize(xf86_lex_val.str, TOKEN_SEP), - matchtype); - free(xf86_lex_val.str); - break; - case NOMATCH_DRIVER: - matchtype = MATCH_NEGATED; - /* fallthrough */ - case MATCH_DRIVER: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchDriver"); - add_group_entry(&ptr->match_driver, - xstrtokenize(xf86_lex_val.str, TOKEN_SEP), - matchtype); - free(xf86_lex_val.str); - break; - case NOMATCH_TAG: - matchtype = MATCH_NEGATED; - /* fallthrough */ - case MATCH_TAG: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchTag"); - add_group_entry(&ptr->match_tag, xstrtokenize(xf86_lex_val.str, - TOKEN_SEP), - matchtype); - free(xf86_lex_val.str); - break; - case NOMATCH_LAYOUT: - matchtype = MATCH_NEGATED; - /* fallthrough */ - case MATCH_LAYOUT: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchLayout"); - add_group_entry(&ptr->match_layout, - xstrtokenize(xf86_lex_val.str, TOKEN_SEP), - matchtype); - free(xf86_lex_val.str); - break; - case MATCH_IS_KEYBOARD: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchIsKeyboard"); - ptr->is_keyboard.set = xf86getBoolValue(&ptr->is_keyboard.val, - xf86_lex_val.str); - free(xf86_lex_val.str); - if (!ptr->is_keyboard.set) - Error(BOOL_MSG, "MatchIsKeyboard"); - break; - case MATCH_IS_POINTER: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchIsPointer"); - ptr->is_pointer.set = xf86getBoolValue(&ptr->is_pointer.val, - xf86_lex_val.str); - free(xf86_lex_val.str); - if (!ptr->is_pointer.set) - Error(BOOL_MSG, "MatchIsPointer"); - break; - case MATCH_IS_JOYSTICK: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchIsJoystick"); - ptr->is_joystick.set = xf86getBoolValue(&ptr->is_joystick.val, - xf86_lex_val.str); - free(xf86_lex_val.str); - if (!ptr->is_joystick.set) - Error(BOOL_MSG, "MatchIsJoystick"); - break; - case MATCH_IS_TABLET: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchIsTablet"); - ptr->is_tablet.set = xf86getBoolValue(&ptr->is_tablet.val, xf86_lex_val.str); - free(xf86_lex_val.str); - if (!ptr->is_tablet.set) - Error(BOOL_MSG, "MatchIsTablet"); - break; - case MATCH_IS_TABLET_PAD: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchIsTabletPad"); - ptr->is_tablet_pad.set = xf86getBoolValue(&ptr->is_tablet_pad.val, xf86_lex_val.str); - free(xf86_lex_val.str); - if (!ptr->is_tablet_pad.set) - Error(BOOL_MSG, "MatchIsTabletPad"); - break; - case MATCH_IS_TOUCHPAD: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchIsTouchpad"); - ptr->is_touchpad.set = xf86getBoolValue(&ptr->is_touchpad.val, - xf86_lex_val.str); - free(xf86_lex_val.str); - if (!ptr->is_touchpad.set) - Error(BOOL_MSG, "MatchIsTouchpad"); - break; - case MATCH_IS_TOUCHSCREEN: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchIsTouchscreen"); - ptr->is_touchscreen.set = xf86getBoolValue(&ptr->is_touchscreen.val, - xf86_lex_val.str); - free(xf86_lex_val.str); - if (!ptr->is_touchscreen.set) - Error(BOOL_MSG, "MatchIsTouchscreen"); - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - - if (!has_ident) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("InputClass section parsed\n"); -#endif - - return ptr; -} - -void -xf86printInputClassSection(FILE * cf, XF86ConfInputClassPtr ptr) -{ - const xf86MatchGroup *group; - char *const *cur; - - while (ptr) { - fprintf(cf, "Section \"InputClass\"\n"); - if (ptr->comment) - fprintf(cf, "%s", ptr->comment); - if (ptr->identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->identifier); - if (ptr->driver) - fprintf(cf, "\tDriver \"%s\"\n", ptr->driver); - - xorg_list_for_each_entry(group, &ptr->match_product, entry) { - fprintf(cf, "\tMatchProduct \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - xorg_list_for_each_entry(group, &ptr->match_vendor, entry) { - fprintf(cf, "\tMatchVendor \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - xorg_list_for_each_entry(group, &ptr->match_device, entry) { - fprintf(cf, "\tMatchDevicePath \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - xorg_list_for_each_entry(group, &ptr->match_os, entry) { - fprintf(cf, "\tMatchOS \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - xorg_list_for_each_entry(group, &ptr->match_pnpid, entry) { - fprintf(cf, "\tMatchPnPID \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - xorg_list_for_each_entry(group, &ptr->match_usbid, entry) { - fprintf(cf, "\tMatchUSBID \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - xorg_list_for_each_entry(group, &ptr->match_driver, entry) { - fprintf(cf, "\tMatchDriver \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - xorg_list_for_each_entry(group, &ptr->match_tag, entry) { - fprintf(cf, "\tMatchTag \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - xorg_list_for_each_entry(group, &ptr->match_layout, entry) { - fprintf(cf, "\tMatchLayout \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - - if (ptr->is_keyboard.set) - fprintf(cf, "\tIsKeyboard \"%s\"\n", - ptr->is_keyboard.val ? "yes" : "no"); - if (ptr->is_pointer.set) - fprintf(cf, "\tIsPointer \"%s\"\n", - ptr->is_pointer.val ? "yes" : "no"); - if (ptr->is_joystick.set) - fprintf(cf, "\tIsJoystick \"%s\"\n", - ptr->is_joystick.val ? "yes" : "no"); - if (ptr->is_tablet.set) - fprintf(cf, "\tIsTablet \"%s\"\n", - ptr->is_tablet.val ? "yes" : "no"); - if (ptr->is_tablet_pad.set) - fprintf(cf, "\tIsTabletPad \"%s\"\n", - ptr->is_tablet_pad.val ? "yes" : "no"); - if (ptr->is_touchpad.set) - fprintf(cf, "\tIsTouchpad \"%s\"\n", - ptr->is_touchpad.val ? "yes" : "no"); - if (ptr->is_touchscreen.set) - fprintf(cf, "\tIsTouchscreen \"%s\"\n", - ptr->is_touchscreen.val ? "yes" : "no"); - xf86printOptionList(cf, ptr->option_lst, 1); - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } -} diff --git a/hw/xfree86/parser/Layout.c b/hw/xfree86/parser/Layout.c deleted file mode 100644 index 2c829f4ee..000000000 --- a/hw/xfree86/parser/Layout.c +++ /dev/null @@ -1,537 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" -#include -#include "optionstr.h" - -/* Needed for auto server layout */ -extern int xf86CheckBoolOption(void *optlist, const char *name, int deflt); - - -static const xf86ConfigSymTabRec LayoutTab[] = { - {ENDSECTION, "endsection"}, - {SCREEN, "screen"}, - {IDENTIFIER, "identifier"}, - {MATCHSEAT, "matchseat"}, - {INACTIVE, "inactive"}, - {INPUTDEVICE, "inputdevice"}, - {OPTION, "option"}, - {-1, ""}, -}; - -static const xf86ConfigSymTabRec AdjTab[] = { - {RIGHTOF, "rightof"}, - {LEFTOF, "leftof"}, - {ABOVE, "above"}, - {BELOW, "below"}, - {RELATIVE, "relative"}, - {ABSOLUTE, "absolute"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeLayoutList - -XF86ConfLayoutPtr -xf86parseLayoutSection(void) -{ - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfLayoutPtr, XF86ConfLayoutRec) - - while ((token = xf86getToken(LayoutTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->lay_comment = xf86addComment(ptr->lay_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->lay_comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->lay_identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case MATCHSEAT: - if (xf86getSubToken(&(ptr->lay_comment)) != STRING) - Error(QUOTE_MSG, "MatchSeat"); - ptr->match_seat = xf86_lex_val.str; - break; - case INACTIVE: - { - XF86ConfInactivePtr iptr; - - iptr = calloc(1, sizeof(XF86ConfInactiveRec)); - iptr->list.next = NULL; - if (xf86getSubToken(&(ptr->lay_comment)) != STRING) { - free(iptr); - Error(INACTIVE_MSG); - } - iptr->inactive_device_str = xf86_lex_val.str; - ptr->lay_inactive_lst = (XF86ConfInactivePtr) - xf86addListItem((glp) ptr->lay_inactive_lst, (glp) iptr); - } - break; - case SCREEN: - { - XF86ConfAdjacencyPtr aptr; - int absKeyword = 0; - - aptr = calloc(1, sizeof(XF86ConfAdjacencyRec)); - aptr->list.next = NULL; - aptr->adj_scrnum = -1; - aptr->adj_where = CONF_ADJ_OBSOLETE; - aptr->adj_x = 0; - aptr->adj_y = 0; - aptr->adj_refscreen = NULL; - if ((token = xf86getSubToken(&(ptr->lay_comment))) == NUMBER) - aptr->adj_scrnum = xf86_lex_val.num; - else - xf86unGetToken(token); - token = xf86getSubToken(&(ptr->lay_comment)); - if (token != STRING) { - free(aptr); - Error(SCREEN_MSG); - } - aptr->adj_screen_str = xf86_lex_val.str; - - token = xf86getSubTokenWithTab(&(ptr->lay_comment), AdjTab); - switch (token) { - case RIGHTOF: - aptr->adj_where = CONF_ADJ_RIGHTOF; - break; - case LEFTOF: - aptr->adj_where = CONF_ADJ_LEFTOF; - break; - case ABOVE: - aptr->adj_where = CONF_ADJ_ABOVE; - break; - case BELOW: - aptr->adj_where = CONF_ADJ_BELOW; - break; - case RELATIVE: - aptr->adj_where = CONF_ADJ_RELATIVE; - break; - case ABSOLUTE: - aptr->adj_where = CONF_ADJ_ABSOLUTE; - absKeyword = 1; - break; - case EOF_TOKEN: - free(aptr); - Error(UNEXPECTED_EOF_MSG); - break; - default: - xf86unGetToken(token); - token = xf86getSubToken(&(ptr->lay_comment)); - if (token == STRING) - aptr->adj_where = CONF_ADJ_OBSOLETE; - else - aptr->adj_where = CONF_ADJ_ABSOLUTE; - } - switch (aptr->adj_where) { - case CONF_ADJ_ABSOLUTE: - if (absKeyword) - token = xf86getSubToken(&(ptr->lay_comment)); - if (token == NUMBER) { - aptr->adj_x = xf86_lex_val.num; - token = xf86getSubToken(&(ptr->lay_comment)); - if (token != NUMBER) { - free(aptr); - Error(INVALID_SCR_MSG); - } - aptr->adj_y = xf86_lex_val.num; - } - else { - if (absKeyword) { - free(aptr); - Error(INVALID_SCR_MSG); - } - else - xf86unGetToken(token); - } - break; - case CONF_ADJ_RIGHTOF: - case CONF_ADJ_LEFTOF: - case CONF_ADJ_ABOVE: - case CONF_ADJ_BELOW: - case CONF_ADJ_RELATIVE: - token = xf86getSubToken(&(ptr->lay_comment)); - if (token != STRING) { - free(aptr); - Error(INVALID_SCR_MSG); - } - aptr->adj_refscreen = xf86_lex_val.str; - if (aptr->adj_where == CONF_ADJ_RELATIVE) { - token = xf86getSubToken(&(ptr->lay_comment)); - if (token != NUMBER) { - free(aptr); - Error(INVALID_SCR_MSG); - } - aptr->adj_x = xf86_lex_val.num; - token = xf86getSubToken(&(ptr->lay_comment)); - if (token != NUMBER) { - free(aptr); - Error(INVALID_SCR_MSG); - } - aptr->adj_y = xf86_lex_val.num; - } - break; - case CONF_ADJ_OBSOLETE: - /* top */ - aptr->adj_top_str = xf86_lex_val.str; - - /* bottom */ - if (xf86getSubToken(&(ptr->lay_comment)) != STRING) { - free(aptr); - Error(SCREEN_MSG); - } - aptr->adj_bottom_str = xf86_lex_val.str; - - /* left */ - if (xf86getSubToken(&(ptr->lay_comment)) != STRING) { - free(aptr); - Error(SCREEN_MSG); - } - aptr->adj_left_str = xf86_lex_val.str; - - /* right */ - if (xf86getSubToken(&(ptr->lay_comment)) != STRING) { - free(aptr); - Error(SCREEN_MSG); - } - aptr->adj_right_str = xf86_lex_val.str; - - } - ptr->lay_adjacency_lst = (XF86ConfAdjacencyPtr) - xf86addListItem((glp) ptr->lay_adjacency_lst, (glp) aptr); - } - break; - case INPUTDEVICE: - { - XF86ConfInputrefPtr iptr; - - iptr = calloc(1, sizeof(XF86ConfInputrefRec)); - iptr->list.next = NULL; - iptr->iref_option_lst = NULL; - if (xf86getSubToken(&(ptr->lay_comment)) != STRING) { - free(iptr); - Error(INPUTDEV_MSG); - } - iptr->iref_inputdev_str = xf86_lex_val.str; - while ((token = xf86getSubToken(&(ptr->lay_comment))) == STRING) { - iptr->iref_option_lst = - xf86addNewOption(iptr->iref_option_lst, xf86_lex_val.str, NULL); - } - xf86unGetToken(token); - ptr->lay_input_lst = (XF86ConfInputrefPtr) - xf86addListItem((glp) ptr->lay_input_lst, (glp) iptr); - } - break; - case OPTION: - ptr->lay_option_lst = xf86parseOption(ptr->lay_option_lst); - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - - if (!has_ident) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("Layout section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -void -xf86printLayoutSection(FILE * cf, XF86ConfLayoutPtr ptr) -{ - XF86ConfAdjacencyPtr aptr; - XF86ConfInactivePtr iptr; - XF86ConfInputrefPtr inptr; - XF86OptionPtr optr; - - while (ptr) { - fprintf(cf, "Section \"ServerLayout\"\n"); - if (ptr->lay_comment) - fprintf(cf, "%s", ptr->lay_comment); - if (ptr->lay_identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->lay_identifier); - - for (aptr = ptr->lay_adjacency_lst; aptr; aptr = aptr->list.next) { - fprintf(cf, "\tScreen "); - if (aptr->adj_scrnum >= 0) - fprintf(cf, "%2d", aptr->adj_scrnum); - else - fprintf(cf, " "); - fprintf(cf, " \"%s\"", aptr->adj_screen_str); - switch (aptr->adj_where) { - case CONF_ADJ_OBSOLETE: - fprintf(cf, " \"%s\"", aptr->adj_top_str); - fprintf(cf, " \"%s\"", aptr->adj_bottom_str); - fprintf(cf, " \"%s\"", aptr->adj_right_str); - fprintf(cf, " \"%s\"\n", aptr->adj_left_str); - break; - case CONF_ADJ_ABSOLUTE: - if (aptr->adj_x != -1) - fprintf(cf, " %d %d\n", aptr->adj_x, aptr->adj_y); - else - fprintf(cf, "\n"); - break; - case CONF_ADJ_RIGHTOF: - fprintf(cf, " RightOf \"%s\"\n", aptr->adj_refscreen); - break; - case CONF_ADJ_LEFTOF: - fprintf(cf, " LeftOf \"%s\"\n", aptr->adj_refscreen); - break; - case CONF_ADJ_ABOVE: - fprintf(cf, " Above \"%s\"\n", aptr->adj_refscreen); - break; - case CONF_ADJ_BELOW: - fprintf(cf, " Below \"%s\"\n", aptr->adj_refscreen); - break; - case CONF_ADJ_RELATIVE: - fprintf(cf, " Relative \"%s\" %d %d\n", aptr->adj_refscreen, - aptr->adj_x, aptr->adj_y); - break; - } - } - for (iptr = ptr->lay_inactive_lst; iptr; iptr = iptr->list.next) - fprintf(cf, "\tInactive \"%s\"\n", iptr->inactive_device_str); - for (inptr = ptr->lay_input_lst; inptr; inptr = inptr->list.next) { - fprintf(cf, "\tInputDevice \"%s\"", inptr->iref_inputdev_str); - for (optr = inptr->iref_option_lst; optr; optr = optr->list.next) { - fprintf(cf, " \"%s\"", optr->opt_name); - } - fprintf(cf, "\n"); - } - xf86printOptionList(cf, ptr->lay_option_lst, 1); - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } -} - -static void -xf86freeAdjacencyList(XF86ConfAdjacencyPtr ptr) -{ - XF86ConfAdjacencyPtr prev; - - while (ptr) { - TestFree(ptr->adj_screen_str); - TestFree(ptr->adj_top_str); - TestFree(ptr->adj_bottom_str); - TestFree(ptr->adj_left_str); - TestFree(ptr->adj_right_str); - - prev = ptr; - ptr = ptr->list.next; - free(prev); - } - -} - -static void -xf86freeInputrefList(XF86ConfInputrefPtr ptr) -{ - XF86ConfInputrefPtr prev; - - while (ptr) { - TestFree(ptr->iref_inputdev_str); - xf86optionListFree(ptr->iref_option_lst); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } - -} - -void -xf86freeLayoutList(XF86ConfLayoutPtr ptr) -{ - XF86ConfLayoutPtr prev; - - while (ptr) { - TestFree(ptr->lay_identifier); - TestFree(ptr->lay_comment); - xf86freeAdjacencyList(ptr->lay_adjacency_lst); - xf86freeInputrefList(ptr->lay_input_lst); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -int -xf86layoutAddInputDevices(XF86ConfigPtr config, XF86ConfLayoutPtr layout) -{ - int count = 0; - XF86ConfInputPtr input = config->conf_input_lst; - XF86ConfInputrefPtr inptr; - - /* add all AutoServerLayout devices to the server layout */ - while (input) { - if (xf86CheckBoolOption - (input->inp_option_lst, "AutoServerLayout", FALSE)) { - XF86ConfInputrefPtr iref = layout->lay_input_lst; - - /* avoid duplicates if referenced but lists AutoServerLayout too */ - while (iref) { - if (strcmp(iref->iref_inputdev_str, input->inp_identifier) == 0) - break; - iref = iref->list.next; - } - - if (!iref) { - XF86ConfInputrefPtr iptr; - - iptr = calloc(1, sizeof(XF86ConfInputrefRec)); - iptr->iref_inputdev_str = input->inp_identifier; - layout->lay_input_lst = (XF86ConfInputrefPtr) - xf86addListItem((glp) layout->lay_input_lst, (glp) iptr); - count++; - } - } - input = input->list.next; - } - - inptr = layout->lay_input_lst; - while (inptr) { - input = xf86findInput(inptr->iref_inputdev_str, config->conf_input_lst); - if (!input) { - xf86validationError(UNDEFINED_INPUT_MSG, - inptr->iref_inputdev_str, - layout->lay_identifier); - return -1; - } - else - inptr->iref_inputdev = input; - inptr = inptr->list.next; - } - - return count; -} - -int -xf86validateLayout(XF86ConfigPtr p) -{ - XF86ConfLayoutPtr layout = p->conf_layout_lst; - XF86ConfAdjacencyPtr adj; - XF86ConfInactivePtr iptr; - XF86ConfScreenPtr screen; - XF86ConfDevicePtr device; - - while (layout) { - adj = layout->lay_adjacency_lst; - while (adj) { - /* the first one can't be "" but all others can */ - screen = xf86findScreen(adj->adj_screen_str, p->conf_screen_lst); - if (!screen) { - xf86validationError(UNDEFINED_SCREEN_MSG, - adj->adj_screen_str, - layout->lay_identifier); - return FALSE; - } - else - adj->adj_screen = screen; - - adj = adj->list.next; - } - iptr = layout->lay_inactive_lst; - while (iptr) { - device = xf86findDevice(iptr->inactive_device_str, - p->conf_device_lst); - if (!device) { - xf86validationError(UNDEFINED_DEVICE_LAY_MSG, - iptr->inactive_device_str, - layout->lay_identifier); - return FALSE; - } - else - iptr->inactive_device = device; - iptr = iptr->list.next; - } - - if (xf86layoutAddInputDevices(p, layout) == -1) - return FALSE; - - layout = layout->list.next; - } - return TRUE; -} - -XF86ConfLayoutPtr -xf86findLayout(const char *name, XF86ConfLayoutPtr list) -{ - while (list) { - if (xf86nameCompare(list->lay_identifier, name) == 0) - return list; - list = list->list.next; - } - return NULL; -} diff --git a/hw/xfree86/parser/Module.c b/hw/xfree86/parser/Module.c deleted file mode 100644 index 38bf777ed..000000000 --- a/hw/xfree86/parser/Module.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec SubModuleTab[] = { - {ENDSUBSECTION, "endsubsection"}, - {OPTION, "option"}, - {-1, ""}, -}; - -static const xf86ConfigSymTabRec ModuleTab[] = { - {ENDSECTION, "endsection"}, - {LOAD, "load"}, - {DISABLE, "disable"}, - {LOAD_DRIVER, "loaddriver"}, - {SUBSECTION, "subsection"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeModules - -static XF86LoadPtr -xf86parseModuleSubSection(XF86LoadPtr head, char *name) -{ - int token; - - parsePrologue(XF86LoadPtr, XF86LoadRec) - - ptr->load_name = name; - ptr->load_type = XF86_LOAD_MODULE; - ptr->ignore = 0; - ptr->load_opt = NULL; - ptr->list.next = NULL; - - while ((token = xf86getToken(SubModuleTab)) != ENDSUBSECTION) { - switch (token) { - case COMMENT: - ptr->load_comment = xf86addComment(ptr->load_comment, xf86_lex_val.str); - break; - case OPTION: - ptr->load_opt = xf86parseOption(ptr->load_opt); - break; - case EOF_TOKEN: - xf86parseError(UNEXPECTED_EOF_MSG); - free(ptr); - return NULL; - default: - xf86parseError(INVALID_KEYWORD_MSG, xf86tokenString()); - free(ptr); - return NULL; - break; - } - - } - - return ((XF86LoadPtr) xf86addListItem((glp) head, (glp) ptr)); -} - -XF86ConfModulePtr -xf86parseModuleSection(void) -{ - int token; - - parsePrologue(XF86ConfModulePtr, XF86ConfModuleRec) - - while ((token = xf86getToken(ModuleTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->mod_comment = xf86addComment(ptr->mod_comment, xf86_lex_val.str); - break; - case LOAD: - if (xf86getSubToken(&(ptr->mod_comment)) != STRING) - Error(QUOTE_MSG, "Load"); - ptr->mod_load_lst = - xf86addNewLoadDirective(ptr->mod_load_lst, xf86_lex_val.str, - XF86_LOAD_MODULE, NULL); - break; - case DISABLE: - if (xf86getSubToken(&(ptr->mod_comment)) != STRING) - Error(QUOTE_MSG, "Disable"); - ptr->mod_disable_lst = - xf86addNewLoadDirective(ptr->mod_disable_lst, xf86_lex_val.str, - XF86_DISABLE_MODULE, NULL); - break; - case LOAD_DRIVER: - if (xf86getSubToken(&(ptr->mod_comment)) != STRING) - Error(QUOTE_MSG, "LoadDriver"); - ptr->mod_load_lst = - xf86addNewLoadDirective(ptr->mod_load_lst, xf86_lex_val.str, - XF86_LOAD_DRIVER, NULL); - break; - case SUBSECTION: - if (xf86getSubToken(&(ptr->mod_comment)) != STRING) - Error(QUOTE_MSG, "SubSection"); - ptr->mod_load_lst = - xf86parseModuleSubSection(ptr->mod_load_lst, xf86_lex_val.str); - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - -#ifdef DEBUG - printf("Module section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -void -xf86printModuleSection(FILE * cf, XF86ConfModulePtr ptr) -{ - XF86LoadPtr lptr; - - if (ptr == NULL) - return; - - if (ptr->mod_comment) - fprintf(cf, "%s", ptr->mod_comment); - for (lptr = ptr->mod_load_lst; lptr; lptr = lptr->list.next) { - switch (lptr->load_type) { - case XF86_LOAD_MODULE: - if (lptr->load_opt == NULL) { - fprintf(cf, "\tLoad \"%s\"", lptr->load_name); - if (lptr->load_comment) - fprintf(cf, "%s", lptr->load_comment); - else - fputc('\n', cf); - } - else { - fprintf(cf, "\tSubSection \"%s\"\n", lptr->load_name); - if (lptr->load_comment) - fprintf(cf, "%s", lptr->load_comment); - xf86printOptionList(cf, lptr->load_opt, 2); - fprintf(cf, "\tEndSubSection\n"); - } - break; - case XF86_LOAD_DRIVER: - fprintf(cf, "\tLoadDriver \"%s\"", lptr->load_name); - if (lptr->load_comment) - fprintf(cf, "%s", lptr->load_comment); - else - fputc('\n', cf); - break; -#if 0 - default: - fprintf(cf, "#\tUnknown type \"%s\"\n", lptr->load_name); - break; -#endif - } - } -} - -XF86LoadPtr -xf86addNewLoadDirective(XF86LoadPtr head, const char *name, int type, - XF86OptionPtr opts) -{ - XF86LoadPtr new; - int token; - - new = calloc(1, sizeof(XF86LoadRec)); - new->load_name = name; - new->load_type = type; - new->load_opt = opts; - new->ignore = 0; - new->list.next = NULL; - - if ((token = xf86getToken(NULL)) == COMMENT) - new->load_comment = xf86addComment(new->load_comment, xf86_lex_val.str); - else - xf86unGetToken(token); - - return ((XF86LoadPtr) xf86addListItem((glp) head, (glp) new)); -} - -void -xf86freeModules(XF86ConfModulePtr ptr) -{ - XF86LoadPtr lptr; - XF86LoadPtr prev; - - if (ptr == NULL) - return; - lptr = ptr->mod_load_lst; - while (lptr) { - TestFree(lptr->load_name); - TestFree(lptr->load_comment); - prev = lptr; - lptr = lptr->list.next; - free(prev); - } - lptr = ptr->mod_disable_lst; - while (lptr) { - TestFree(lptr->load_name); - TestFree(lptr->load_comment); - prev = lptr; - lptr = lptr->list.next; - free(prev); - } - TestFree(ptr->mod_comment); - free(ptr); -} diff --git a/hw/xfree86/parser/Monitor.c b/hw/xfree86/parser/Monitor.c deleted file mode 100644 index 1d63a441c..000000000 --- a/hw/xfree86/parser/Monitor.c +++ /dev/null @@ -1,861 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec MonitorTab[] = { - {ENDSECTION, "endsection"}, - {IDENTIFIER, "identifier"}, - {VENDOR, "vendorname"}, - {MODEL, "modelname"}, - {USEMODES, "usemodes"}, - {MODELINE, "modeline"}, - {DISPLAYSIZE, "displaysize"}, - {HORIZSYNC, "horizsync"}, - {VERTREFRESH, "vertrefresh"}, - {MODE, "mode"}, - {GAMMA, "gamma"}, - {OPTION, "option"}, - {-1, ""}, -}; - -static const xf86ConfigSymTabRec ModesTab[] = { - {ENDSECTION, "endsection"}, - {IDENTIFIER, "identifier"}, - {MODELINE, "modeline"}, - {MODE, "mode"}, - {-1, ""}, -}; - -static const xf86ConfigSymTabRec TimingTab[] = { - {TT_INTERLACE, "interlace"}, - {TT_PHSYNC, "+hsync"}, - {TT_NHSYNC, "-hsync"}, - {TT_PVSYNC, "+vsync"}, - {TT_NVSYNC, "-vsync"}, - {TT_CSYNC, "composite"}, - {TT_PCSYNC, "+csync"}, - {TT_NCSYNC, "-csync"}, - {TT_DBLSCAN, "doublescan"}, - {TT_HSKEW, "hskew"}, - {TT_BCAST, "bcast"}, - {TT_VSCAN, "vscan"}, - {-1, ""}, -}; - -static const xf86ConfigSymTabRec ModeTab[] = { - {DOTCLOCK, "dotclock"}, - {HTIMINGS, "htimings"}, - {VTIMINGS, "vtimings"}, - {FLAGS, "flags"}, - {HSKEW, "hskew"}, - {BCAST, "bcast"}, - {VSCAN, "vscan"}, - {ENDMODE, "endmode"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeModeLineList - -static void -xf86freeModeLineList(XF86ConfModeLinePtr ptr) -{ - XF86ConfModeLinePtr prev; - - while (ptr) { - TestFree(ptr->ml_identifier); - TestFree(ptr->ml_comment); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -static XF86ConfModeLinePtr -xf86parseModeLine(void) -{ - int token; - - parsePrologue(XF86ConfModeLinePtr, XF86ConfModeLineRec) - - /* Identifier */ - if (xf86getSubToken(&(ptr->ml_comment)) != STRING) - Error("ModeLine identifier expected"); - ptr->ml_identifier = xf86_lex_val.str; - - /* DotClock */ - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("ModeLine dotclock expected"); - ptr->ml_clock = (int) (xf86_lex_val.realnum * 1000.0 + 0.5); - - /* HDisplay */ - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("ModeLine Hdisplay expected"); - ptr->ml_hdisplay = xf86_lex_val.num; - - /* HSyncStart */ - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("ModeLine HSyncStart expected"); - ptr->ml_hsyncstart = xf86_lex_val.num; - - /* HSyncEnd */ - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("ModeLine HSyncEnd expected"); - ptr->ml_hsyncend = xf86_lex_val.num; - - /* HTotal */ - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("ModeLine HTotal expected"); - ptr->ml_htotal = xf86_lex_val.num; - - /* VDisplay */ - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("ModeLine Vdisplay expected"); - ptr->ml_vdisplay = xf86_lex_val.num; - - /* VSyncStart */ - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("ModeLine VSyncStart expected"); - ptr->ml_vsyncstart = xf86_lex_val.num; - - /* VSyncEnd */ - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("ModeLine VSyncEnd expected"); - ptr->ml_vsyncend = xf86_lex_val.num; - - /* VTotal */ - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("ModeLine VTotal expected"); - ptr->ml_vtotal = xf86_lex_val.num; - - token = xf86getSubTokenWithTab(&(ptr->ml_comment), TimingTab); - while ((token == TT_INTERLACE) || (token == TT_PHSYNC) || - (token == TT_NHSYNC) || (token == TT_PVSYNC) || - (token == TT_NVSYNC) || (token == TT_CSYNC) || - (token == TT_PCSYNC) || (token == TT_NCSYNC) || - (token == TT_DBLSCAN) || (token == TT_HSKEW) || - (token == TT_VSCAN) || (token == TT_BCAST)) { - switch (token) { - - case TT_INTERLACE: - ptr->ml_flags |= XF86CONF_INTERLACE; - break; - case TT_PHSYNC: - ptr->ml_flags |= XF86CONF_PHSYNC; - break; - case TT_NHSYNC: - ptr->ml_flags |= XF86CONF_NHSYNC; - break; - case TT_PVSYNC: - ptr->ml_flags |= XF86CONF_PVSYNC; - break; - case TT_NVSYNC: - ptr->ml_flags |= XF86CONF_NVSYNC; - break; - case TT_CSYNC: - ptr->ml_flags |= XF86CONF_CSYNC; - break; - case TT_PCSYNC: - ptr->ml_flags |= XF86CONF_PCSYNC; - break; - case TT_NCSYNC: - ptr->ml_flags |= XF86CONF_NCSYNC; - break; - case TT_DBLSCAN: - ptr->ml_flags |= XF86CONF_DBLSCAN; - break; - case TT_HSKEW: - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error(NUMBER_MSG, "Hskew"); - ptr->ml_hskew = xf86_lex_val.num; - ptr->ml_flags |= XF86CONF_HSKEW; - break; - case TT_BCAST: - ptr->ml_flags |= XF86CONF_BCAST; - break; - case TT_VSCAN: - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error(NUMBER_MSG, "Vscan"); - ptr->ml_vscan = xf86_lex_val.num; - ptr->ml_flags |= XF86CONF_VSCAN; - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - token = xf86getSubTokenWithTab(&(ptr->ml_comment), TimingTab); - } - xf86unGetToken(token); - -#ifdef DEBUG - printf("ModeLine parsed\n"); -#endif - return ptr; -} - -static XF86ConfModeLinePtr -xf86parseVerboseMode(void) -{ - int token, token2; - int had_dotclock = 0, had_htimings = 0, had_vtimings = 0; - - parsePrologue(XF86ConfModeLinePtr, XF86ConfModeLineRec) - - if (xf86getSubToken(&(ptr->ml_comment)) != STRING) - Error("Mode name expected"); - ptr->ml_identifier = xf86_lex_val.str; - while ((token = xf86getToken(ModeTab)) != ENDMODE) { - switch (token) { - case COMMENT: - ptr->ml_comment = xf86addComment(ptr->ml_comment, xf86_lex_val.str); - break; - case DOTCLOCK: - if ((token = xf86getSubToken(&(ptr->ml_comment))) != NUMBER) - Error(NUMBER_MSG, "DotClock"); - ptr->ml_clock = (int) (xf86_lex_val.realnum * 1000.0 + 0.5); - had_dotclock = 1; - break; - case HTIMINGS: - if (xf86getSubToken(&(ptr->ml_comment)) == NUMBER) - ptr->ml_hdisplay = xf86_lex_val.num; - else - Error("Horizontal display expected"); - - if (xf86getSubToken(&(ptr->ml_comment)) == NUMBER) - ptr->ml_hsyncstart = xf86_lex_val.num; - else - Error("Horizontal sync start expected"); - - if (xf86getSubToken(&(ptr->ml_comment)) == NUMBER) - ptr->ml_hsyncend = xf86_lex_val.num; - else - Error("Horizontal sync end expected"); - - if (xf86getSubToken(&(ptr->ml_comment)) == NUMBER) - ptr->ml_htotal = xf86_lex_val.num; - else - Error("Horizontal total expected"); - had_htimings = 1; - break; - case VTIMINGS: - if (xf86getSubToken(&(ptr->ml_comment)) == NUMBER) - ptr->ml_vdisplay = xf86_lex_val.num; - else - Error("Vertical display expected"); - - if (xf86getSubToken(&(ptr->ml_comment)) == NUMBER) - ptr->ml_vsyncstart = xf86_lex_val.num; - else - Error("Vertical sync start expected"); - - if (xf86getSubToken(&(ptr->ml_comment)) == NUMBER) - ptr->ml_vsyncend = xf86_lex_val.num; - else - Error("Vertical sync end expected"); - - if (xf86getSubToken(&(ptr->ml_comment)) == NUMBER) - ptr->ml_vtotal = xf86_lex_val.num; - else - Error("Vertical total expected"); - had_vtimings = 1; - break; - case FLAGS: - token = xf86getSubToken(&(ptr->ml_comment)); - if (token != STRING) - Error(QUOTE_MSG, "Flags"); - while (token == STRING) { - token2 = xf86getStringToken(TimingTab); - switch (token2) { - case TT_INTERLACE: - ptr->ml_flags |= XF86CONF_INTERLACE; - break; - case TT_PHSYNC: - ptr->ml_flags |= XF86CONF_PHSYNC; - break; - case TT_NHSYNC: - ptr->ml_flags |= XF86CONF_NHSYNC; - break; - case TT_PVSYNC: - ptr->ml_flags |= XF86CONF_PVSYNC; - break; - case TT_NVSYNC: - ptr->ml_flags |= XF86CONF_NVSYNC; - break; - case TT_CSYNC: - ptr->ml_flags |= XF86CONF_CSYNC; - break; - case TT_PCSYNC: - ptr->ml_flags |= XF86CONF_PCSYNC; - break; - case TT_NCSYNC: - ptr->ml_flags |= XF86CONF_NCSYNC; - break; - case TT_DBLSCAN: - ptr->ml_flags |= XF86CONF_DBLSCAN; - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error("Unknown flag string"); - break; - } - token = xf86getSubToken(&(ptr->ml_comment)); - } - xf86unGetToken(token); - break; - case HSKEW: - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("Horizontal skew expected"); - ptr->ml_flags |= XF86CONF_HSKEW; - ptr->ml_hskew = xf86_lex_val.num; - break; - case VSCAN: - if (xf86getSubToken(&(ptr->ml_comment)) != NUMBER) - Error("Vertical scan count expected"); - ptr->ml_flags |= XF86CONF_VSCAN; - ptr->ml_vscan = xf86_lex_val.num; - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error("Unexpected token in verbose \"Mode\" entry\n"); - } - } - if (!had_dotclock) - Error("the dotclock is missing"); - if (!had_htimings) - Error("the horizontal timings are missing"); - if (!had_vtimings) - Error("the vertical timings are missing"); - -#ifdef DEBUG - printf("Verbose Mode parsed\n"); -#endif - return ptr; -} - -#undef CLEANUP - -#define CLEANUP xf86freeMonitorList - -XF86ConfMonitorPtr -xf86parseMonitorSection(void) -{ - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfMonitorPtr, XF86ConfMonitorRec) - - while ((token = xf86getToken(MonitorTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->mon_comment = xf86addComment(ptr->mon_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->mon_comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->mon_identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case VENDOR: - if (xf86getSubToken(&(ptr->mon_comment)) != STRING) - Error(QUOTE_MSG, "Vendor"); - ptr->mon_vendor = xf86_lex_val.str; - break; - case MODEL: - if (xf86getSubToken(&(ptr->mon_comment)) != STRING) - Error(QUOTE_MSG, "ModelName"); - ptr->mon_modelname = xf86_lex_val.str; - break; - case MODE: - HANDLE_LIST(mon_modeline_lst, xf86parseVerboseMode, - XF86ConfModeLinePtr); - break; - case MODELINE: - HANDLE_LIST(mon_modeline_lst, xf86parseModeLine, - XF86ConfModeLinePtr); - break; - case DISPLAYSIZE: - if (xf86getSubToken(&(ptr->mon_comment)) != NUMBER) - Error(DISPLAYSIZE_MSG); - ptr->mon_width = xf86_lex_val.realnum; - if (xf86getSubToken(&(ptr->mon_comment)) != NUMBER) - Error(DISPLAYSIZE_MSG); - ptr->mon_height = xf86_lex_val.realnum; - break; - - case HORIZSYNC: - if (xf86getSubToken(&(ptr->mon_comment)) != NUMBER) - Error(HORIZSYNC_MSG); - do { - if (ptr->mon_n_hsync >= CONF_MAX_HSYNC) - Error("Sorry. Too many horizontal sync intervals."); - ptr->mon_hsync[ptr->mon_n_hsync].lo = xf86_lex_val.realnum; - switch (token = xf86getSubToken(&(ptr->mon_comment))) { - case COMMA: - ptr->mon_hsync[ptr->mon_n_hsync].hi = - ptr->mon_hsync[ptr->mon_n_hsync].lo; - break; - case DASH: - if (xf86getSubToken(&(ptr->mon_comment)) != NUMBER || - (float) xf86_lex_val.realnum < - ptr->mon_hsync[ptr->mon_n_hsync].lo) - Error(HORIZSYNC_MSG); - ptr->mon_hsync[ptr->mon_n_hsync].hi = xf86_lex_val.realnum; - if ((token = xf86getSubToken(&(ptr->mon_comment))) == COMMA) - break; - ptr->mon_n_hsync++; - goto HorizDone; - default: - /* We cannot currently know if a '\n' was found, - * or this is a real error - */ - ptr->mon_hsync[ptr->mon_n_hsync].hi = - ptr->mon_hsync[ptr->mon_n_hsync].lo; - ptr->mon_n_hsync++; - goto HorizDone; - } - ptr->mon_n_hsync++; - } while ((token = xf86getSubToken(&(ptr->mon_comment))) == NUMBER); - HorizDone: - xf86unGetToken(token); - break; - - case VERTREFRESH: - if (xf86getSubToken(&(ptr->mon_comment)) != NUMBER) - Error(VERTREFRESH_MSG); - do { - ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo = xf86_lex_val.realnum; - switch (token = xf86getSubToken(&(ptr->mon_comment))) { - case COMMA: - ptr->mon_vrefresh[ptr->mon_n_vrefresh].hi = - ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo; - break; - case DASH: - if (xf86getSubToken(&(ptr->mon_comment)) != NUMBER || - (float) xf86_lex_val.realnum < - ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo) - Error(VERTREFRESH_MSG); - ptr->mon_vrefresh[ptr->mon_n_vrefresh].hi = xf86_lex_val.realnum; - if ((token = xf86getSubToken(&(ptr->mon_comment))) == COMMA) - break; - ptr->mon_n_vrefresh++; - goto VertDone; - default: - /* We cannot currently know if a '\n' was found, - * or this is a real error - */ - ptr->mon_vrefresh[ptr->mon_n_vrefresh].hi = - ptr->mon_vrefresh[ptr->mon_n_vrefresh].lo; - ptr->mon_n_vrefresh++; - goto VertDone; - } - if (ptr->mon_n_vrefresh >= CONF_MAX_VREFRESH) - Error("Sorry. Too many vertical refresh intervals."); - ptr->mon_n_vrefresh++; - } while ((token = xf86getSubToken(&(ptr->mon_comment))) == NUMBER); - VertDone: - xf86unGetToken(token); - break; - - case GAMMA: - if (xf86getSubToken(&(ptr->mon_comment)) != NUMBER) { - Error(INVALID_GAMMA_MSG); - } - else { - ptr->mon_gamma_red = ptr->mon_gamma_green = - ptr->mon_gamma_blue = xf86_lex_val.realnum; - if (xf86getSubToken(&(ptr->mon_comment)) == NUMBER) { - ptr->mon_gamma_green = xf86_lex_val.realnum; - if (xf86getSubToken(&(ptr->mon_comment)) == NUMBER) { - ptr->mon_gamma_blue = xf86_lex_val.realnum; - } - else { - Error(INVALID_GAMMA_MSG); - } - } - else - xf86unGetToken(token); - } - break; - case OPTION: - ptr->mon_option_lst = xf86parseOption(ptr->mon_option_lst); - break; - case USEMODES: - { - XF86ConfModesLinkPtr mptr; - - if ((token = xf86getSubToken(&(ptr->mon_comment))) != STRING) - Error(QUOTE_MSG, "UseModes"); - - /* add to the end of the list of modes sections - referenced here */ - mptr = calloc(1, sizeof(XF86ConfModesLinkRec)); - mptr->list.next = NULL; - mptr->ml_modes_str = xf86_lex_val.str; - mptr->ml_modes = NULL; - ptr->mon_modes_sect_lst = (XF86ConfModesLinkPtr) - xf86addListItem((GenericListPtr) ptr->mon_modes_sect_lst, - (GenericListPtr) mptr); - } - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - xf86parseError(INVALID_KEYWORD_MSG, xf86tokenString()); - CLEANUP(ptr); - return NULL; - break; - } - } - - if (!has_ident) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("Monitor section parsed\n"); -#endif - return ptr; -} - -#undef CLEANUP -#define CLEANUP xf86freeModesList - -XF86ConfModesPtr -xf86parseModesSection(void) -{ - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfModesPtr, XF86ConfModesRec) - - while ((token = xf86getToken(ModesTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->modes_comment = xf86addComment(ptr->modes_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->modes_comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->modes_identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case MODE: - HANDLE_LIST(mon_modeline_lst, xf86parseVerboseMode, - XF86ConfModeLinePtr); - break; - case MODELINE: - HANDLE_LIST(mon_modeline_lst, xf86parseModeLine, - XF86ConfModeLinePtr); - break; - default: - xf86parseError(INVALID_KEYWORD_MSG, xf86tokenString()); - CLEANUP(ptr); - return NULL; - break; - } - } - - if (!has_ident) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("Modes section parsed\n"); -#endif - return ptr; -} - -#undef CLEANUP - -void -xf86printMonitorSection(FILE * cf, XF86ConfMonitorPtr ptr) -{ - int i; - XF86ConfModeLinePtr mlptr; - XF86ConfModesLinkPtr mptr; - - while (ptr) { - mptr = ptr->mon_modes_sect_lst; - fprintf(cf, "Section \"Monitor\"\n"); - if (ptr->mon_comment) - fprintf(cf, "%s", ptr->mon_comment); - if (ptr->mon_identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->mon_identifier); - if (ptr->mon_vendor) - fprintf(cf, "\tVendorName \"%s\"\n", ptr->mon_vendor); - if (ptr->mon_modelname) - fprintf(cf, "\tModelName \"%s\"\n", ptr->mon_modelname); - while (mptr) { - fprintf(cf, "\tUseModes \"%s\"\n", mptr->ml_modes_str); - mptr = mptr->list.next; - } - if (ptr->mon_width) - fprintf(cf, "\tDisplaySize %d\t%d\n", - ptr->mon_width, ptr->mon_height); - for (i = 0; i < ptr->mon_n_hsync; i++) { - fprintf(cf, "\tHorizSync %2.1f - %2.1f\n", - ptr->mon_hsync[i].lo, ptr->mon_hsync[i].hi); - } - for (i = 0; i < ptr->mon_n_vrefresh; i++) { - fprintf(cf, "\tVertRefresh %2.1f - %2.1f\n", - ptr->mon_vrefresh[i].lo, ptr->mon_vrefresh[i].hi); - } - if (ptr->mon_gamma_red) { - if (ptr->mon_gamma_red == ptr->mon_gamma_green - && ptr->mon_gamma_red == ptr->mon_gamma_blue) { - fprintf(cf, "\tGamma %.4g\n", ptr->mon_gamma_red); - } - else { - fprintf(cf, "\tGamma %.4g %.4g %.4g\n", - ptr->mon_gamma_red, - ptr->mon_gamma_green, ptr->mon_gamma_blue); - } - } - for (mlptr = ptr->mon_modeline_lst; mlptr; mlptr = mlptr->list.next) { - fprintf(cf, "\tModeLine \"%s\" %2.1f ", - mlptr->ml_identifier, mlptr->ml_clock / 1000.0); - fprintf(cf, "%d %d %d %d %d %d %d %d", - mlptr->ml_hdisplay, mlptr->ml_hsyncstart, - mlptr->ml_hsyncend, mlptr->ml_htotal, - mlptr->ml_vdisplay, mlptr->ml_vsyncstart, - mlptr->ml_vsyncend, mlptr->ml_vtotal); - if (mlptr->ml_flags & XF86CONF_PHSYNC) - fprintf(cf, " +hsync"); - if (mlptr->ml_flags & XF86CONF_NHSYNC) - fprintf(cf, " -hsync"); - if (mlptr->ml_flags & XF86CONF_PVSYNC) - fprintf(cf, " +vsync"); - if (mlptr->ml_flags & XF86CONF_NVSYNC) - fprintf(cf, " -vsync"); - if (mlptr->ml_flags & XF86CONF_INTERLACE) - fprintf(cf, " interlace"); - if (mlptr->ml_flags & XF86CONF_CSYNC) - fprintf(cf, " composite"); - if (mlptr->ml_flags & XF86CONF_PCSYNC) - fprintf(cf, " +csync"); - if (mlptr->ml_flags & XF86CONF_NCSYNC) - fprintf(cf, " -csync"); - if (mlptr->ml_flags & XF86CONF_DBLSCAN) - fprintf(cf, " doublescan"); - if (mlptr->ml_flags & XF86CONF_HSKEW) - fprintf(cf, " hskew %d", mlptr->ml_hskew); - if (mlptr->ml_flags & XF86CONF_BCAST) - fprintf(cf, " bcast"); - fprintf(cf, "\n"); - } - xf86printOptionList(cf, ptr->mon_option_lst, 1); - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } -} - -void -xf86printModesSection(FILE * cf, XF86ConfModesPtr ptr) -{ - XF86ConfModeLinePtr mlptr; - - while (ptr) { - fprintf(cf, "Section \"Modes\"\n"); - if (ptr->modes_comment) - fprintf(cf, "%s", ptr->modes_comment); - if (ptr->modes_identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->modes_identifier); - for (mlptr = ptr->mon_modeline_lst; mlptr; mlptr = mlptr->list.next) { - fprintf(cf, "\tModeLine \"%s\" %2.1f ", - mlptr->ml_identifier, mlptr->ml_clock / 1000.0); - fprintf(cf, "%d %d %d %d %d %d %d %d", - mlptr->ml_hdisplay, mlptr->ml_hsyncstart, - mlptr->ml_hsyncend, mlptr->ml_htotal, - mlptr->ml_vdisplay, mlptr->ml_vsyncstart, - mlptr->ml_vsyncend, mlptr->ml_vtotal); - if (mlptr->ml_flags & XF86CONF_PHSYNC) - fprintf(cf, " +hsync"); - if (mlptr->ml_flags & XF86CONF_NHSYNC) - fprintf(cf, " -hsync"); - if (mlptr->ml_flags & XF86CONF_PVSYNC) - fprintf(cf, " +vsync"); - if (mlptr->ml_flags & XF86CONF_NVSYNC) - fprintf(cf, " -vsync"); - if (mlptr->ml_flags & XF86CONF_INTERLACE) - fprintf(cf, " interlace"); - if (mlptr->ml_flags & XF86CONF_CSYNC) - fprintf(cf, " composite"); - if (mlptr->ml_flags & XF86CONF_PCSYNC) - fprintf(cf, " +csync"); - if (mlptr->ml_flags & XF86CONF_NCSYNC) - fprintf(cf, " -csync"); - if (mlptr->ml_flags & XF86CONF_DBLSCAN) - fprintf(cf, " doublescan"); - if (mlptr->ml_flags & XF86CONF_HSKEW) - fprintf(cf, " hskew %d", mlptr->ml_hskew); - if (mlptr->ml_flags & XF86CONF_VSCAN) - fprintf(cf, " vscan %d", mlptr->ml_vscan); - if (mlptr->ml_flags & XF86CONF_BCAST) - fprintf(cf, " bcast"); - if (mlptr->ml_comment) - fprintf(cf, "%s", mlptr->ml_comment); - else - fprintf(cf, "\n"); - } - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } -} - -void -xf86freeMonitorList(XF86ConfMonitorPtr ptr) -{ - XF86ConfMonitorPtr prev; - - while (ptr) { - TestFree(ptr->mon_identifier); - TestFree(ptr->mon_vendor); - TestFree(ptr->mon_modelname); - TestFree(ptr->mon_comment); - xf86optionListFree(ptr->mon_option_lst); - xf86freeModeLineList(ptr->mon_modeline_lst); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -void -xf86freeModesList(XF86ConfModesPtr ptr) -{ - XF86ConfModesPtr prev; - - while (ptr) { - TestFree(ptr->modes_identifier); - TestFree(ptr->modes_comment); - xf86freeModeLineList(ptr->mon_modeline_lst); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -XF86ConfMonitorPtr -xf86findMonitor(const char *ident, XF86ConfMonitorPtr p) -{ - while (p) { - if (xf86nameCompare(ident, p->mon_identifier) == 0) - return p; - - p = p->list.next; - } - return NULL; -} - -XF86ConfModesPtr -xf86findModes(const char *ident, XF86ConfModesPtr p) -{ - while (p) { - if (xf86nameCompare(ident, p->modes_identifier) == 0) - return p; - - p = p->list.next; - } - return NULL; -} - -XF86ConfModeLinePtr -xf86findModeLine(const char *ident, XF86ConfModeLinePtr p) -{ - while (p) { - if (xf86nameCompare(ident, p->ml_identifier) == 0) - return p; - - p = p->list.next; - } - return NULL; -} - -int -xf86validateMonitor(XF86ConfigPtr p, XF86ConfScreenPtr screen) -{ - XF86ConfMonitorPtr monitor = screen->scrn_monitor; - XF86ConfModesLinkPtr modeslnk = monitor->mon_modes_sect_lst; - XF86ConfModesPtr modes; - - while (modeslnk) { - modes = xf86findModes(modeslnk->ml_modes_str, p->conf_modes_lst); - if (!modes) { - xf86validationError(UNDEFINED_MODES_MSG, - modeslnk->ml_modes_str, - screen->scrn_identifier); - return FALSE; - } - modeslnk->ml_modes = modes; - modeslnk = modeslnk->list.next; - } - return TRUE; -} diff --git a/hw/xfree86/parser/OutputClass.c b/hw/xfree86/parser/OutputClass.c deleted file mode 100644 index 01b348fdd..000000000 --- a/hw/xfree86/parser/OutputClass.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2014 NVIDIA Corporation. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "os.h" -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - -static const xf86ConfigSymTabRec OutputClassTab[] = { - {ENDSECTION, "endsection"}, - {IDENTIFIER, "identifier"}, - {DRIVER, "driver"}, - {MODULEPATH, "modulepath"}, - {OPTION, "option"}, - {MATCH_DRIVER, "matchdriver"}, - {-1, ""}, -}; - -static void -xf86freeOutputClassList(XF86ConfOutputClassPtr ptr) -{ - XF86ConfOutputClassPtr prev; - - while (ptr) { - xf86MatchGroup *group, *next; - char **list; - - TestFree(ptr->identifier); - TestFree(ptr->comment); - TestFree(ptr->driver); - TestFree(ptr->modulepath); - - xorg_list_for_each_entry_safe(group, next, &ptr->match_driver, entry) { - xorg_list_del(&group->entry); - for (list = group->values; *list; list++) - free(*list); - free(group); - } - - xf86optionListFree(ptr->option_lst); - - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -#define CLEANUP xf86freeOutputClassList - -#define TOKEN_SEP "|" - -static void -add_group_entry(struct xorg_list *head, char **values) -{ - xf86MatchGroup *group; - - group = malloc(sizeof(*group)); - if (group) { - group->values = values; - xorg_list_add(&group->entry, head); - } -} - -XF86ConfOutputClassPtr -xf86parseOutputClassSection(void) -{ - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfOutputClassPtr, XF86ConfOutputClassRec) - - /* Initialize MatchGroup lists */ - xorg_list_init(&ptr->match_driver); - - while ((token = xf86getToken(OutputClassTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->comment = xf86addComment(ptr->comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case DRIVER: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "Driver"); - else - ptr->driver = xf86_lex_val.str; - break; - case MODULEPATH: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "ModulePath"); - if (ptr->modulepath) { - char *path; - XNFasprintf(&path, "%s,%s", ptr->modulepath, xf86_lex_val.str); - free(xf86_lex_val.str); - free(ptr->modulepath); - ptr->modulepath = path; - } else { - ptr->modulepath = xf86_lex_val.str; - } - break; - case OPTION: - ptr->option_lst = xf86parseOption(ptr->option_lst); - break; - case MATCH_DRIVER: - if (xf86getSubToken(&(ptr->comment)) != STRING) - Error(QUOTE_MSG, "MatchDriver"); - add_group_entry(&ptr->match_driver, - xstrtokenize(xf86_lex_val.str, TOKEN_SEP)); - free(xf86_lex_val.str); - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - - if (!has_ident) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("OutputClass section parsed\n"); -#endif - - return ptr; -} -void -xf86printOutputClassSection(FILE * cf, XF86ConfOutputClassPtr ptr) -{ - const xf86MatchGroup *group; - char *const *cur; - - while (ptr) { - fprintf(cf, "Section \"OutputClass\"\n"); - if (ptr->comment) - fprintf(cf, "%s", ptr->comment); - if (ptr->identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->identifier); - if (ptr->driver) - fprintf(cf, "\tDriver \"%s\"\n", ptr->driver); - - xorg_list_for_each_entry(group, &ptr->match_driver, entry) { - fprintf(cf, "\tMatchDriver \""); - for (cur = group->values; *cur; cur++) - fprintf(cf, "%s%s", cur == group->values ? "" : TOKEN_SEP, - *cur); - fprintf(cf, "\"\n"); - } - - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } -} diff --git a/hw/xfree86/parser/Pointer.c b/hw/xfree86/parser/Pointer.c deleted file mode 100644 index ff63deb31..000000000 --- a/hw/xfree86/parser/Pointer.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" -#include "Xprintf.h" - - -static const xf86ConfigSymTabRec PointerTab[] = { - {PROTOCOL, "protocol"}, - {EMULATE3, "emulate3buttons"}, - {EM3TIMEOUT, "emulate3timeout"}, - {ENDSUBSECTION, "endsubsection"}, - {ENDSECTION, "endsection"}, - {PDEVICE, "device"}, - {PDEVICE, "port"}, - {BAUDRATE, "baudrate"}, - {SAMPLERATE, "samplerate"}, - {CLEARDTR, "cleardtr"}, - {CLEARRTS, "clearrts"}, - {CHORDMIDDLE, "chordmiddle"}, - {PRESOLUTION, "resolution"}, - {DEVICE_NAME, "devicename"}, - {ALWAYSCORE, "alwayscore"}, - {PBUTTONS, "buttons"}, - {ZAXISMAPPING, "zaxismapping"}, - {-1, ""}, -}; - -static const xf86ConfigSymTabRec ZMapTab[] = { - {XAXIS, "x"}, - {YAXIS, "y"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeInputList - -XF86ConfInputPtr -xf86parsePointerSection(void) -{ - char *s; - unsigned long val1; - int token; - - parsePrologue(XF86ConfInputPtr, XF86ConfInputRec) - - while ((token = xf86getToken(PointerTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->inp_comment = xf86addComment(ptr->inp_comment, xf86_lex_val.str); - break; - case PROTOCOL: - if (xf86getSubToken(&(ptr->inp_comment)) != STRING) - Error(QUOTE_MSG, "Protocol"); - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("Protocol"), xf86_lex_val.str); - break; - case PDEVICE: - if (xf86getSubToken(&(ptr->inp_comment)) != STRING) - Error(QUOTE_MSG, "Device"); - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("Device"), xf86_lex_val.str); - break; - case EMULATE3: - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("Emulate3Buttons"), - NULL); - break; - case EM3TIMEOUT: - if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0) - Error(POSITIVE_INT_MSG, "Emulate3Timeout"); - s = xf86uLongToString(xf86_lex_val.num); - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("Emulate3Timeout"), - s); - break; - case CHORDMIDDLE: - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("ChordMiddle"), NULL); - break; - case PBUTTONS: - if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0) - Error(POSITIVE_INT_MSG, "Buttons"); - s = xf86uLongToString(xf86_lex_val.num); - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("Buttons"), s); - break; - case BAUDRATE: - if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0) - Error(POSITIVE_INT_MSG, "BaudRate"); - s = xf86uLongToString(xf86_lex_val.num); - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("BaudRate"), s); - break; - case SAMPLERATE: - if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0) - Error(POSITIVE_INT_MSG, "SampleRate"); - s = xf86uLongToString(xf86_lex_val.num); - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("SampleRate"), s); - break; - case PRESOLUTION: - if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || xf86_lex_val.num < 0) - Error(POSITIVE_INT_MSG, "Resolution"); - s = xf86uLongToString(xf86_lex_val.num); - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("Resolution"), s); - break; - case CLEARDTR: - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("ClearDTR"), NULL); - break; - case CLEARRTS: - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("ClearRTS"), NULL); - break; - case ZAXISMAPPING: - switch (xf86getToken(ZMapTab)) { - case NUMBER: - if (xf86_lex_val.num < 0) - Error(ZAXISMAPPING_MSG); - val1 = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->inp_comment)) != NUMBER || - xf86_lex_val.num < 0) { - Error(ZAXISMAPPING_MSG); - } - if (asprintf(&s, "%lu %u", val1, xf86_lex_val.num) == -1) - s = NULL; - break; - case XAXIS: - s = strdup("x"); - break; - case YAXIS: - s = strdup("y"); - break; - default: - Error(ZAXISMAPPING_MSG); - break; - } - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("ZAxisMapping"), s); - break; - case ALWAYSCORE: - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - - ptr->inp_identifier = strdup(CONF_IMPLICIT_POINTER); - ptr->inp_driver = strdup("mouse"); - ptr->inp_option_lst = xf86addNewOption(ptr->inp_option_lst, - strdup("CorePointer"), NULL); - -#ifdef DEBUG - printf("Pointer section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP diff --git a/hw/xfree86/parser/Screen.c b/hw/xfree86/parser/Screen.c deleted file mode 100644 index a831c30cd..000000000 --- a/hw/xfree86/parser/Screen.c +++ /dev/null @@ -1,564 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec DisplayTab[] = { - {ENDSUBSECTION, "endsubsection"}, - {MODES, "modes"}, - {VIEWPORT, "viewport"}, - {VIRTUAL, "virtual"}, - {VISUAL, "visual"}, - {BLACK_TOK, "black"}, - {WHITE_TOK, "white"}, - {DEPTH, "depth"}, - {BPP, "fbbpp"}, - {WEIGHT, "weight"}, - {OPTION, "option"}, - {-1, ""}, -}; - -static void -xf86freeModeList(XF86ModePtr ptr) -{ - XF86ModePtr prev; - - while (ptr) { - TestFree(ptr->mode_name); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -static void -xf86freeDisplayList(XF86ConfDisplayPtr ptr) -{ - XF86ConfDisplayPtr prev; - - while (ptr) { - xf86freeModeList(ptr->disp_mode_lst); - xf86optionListFree(ptr->disp_option_lst); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -#define CLEANUP xf86freeDisplayList - -static XF86ConfDisplayPtr -xf86parseDisplaySubSection(void) -{ - int token; - - parsePrologue(XF86ConfDisplayPtr, XF86ConfDisplayRec) - - ptr->disp_black.red = ptr->disp_black.green = ptr->disp_black.blue = -1; - ptr->disp_white.red = ptr->disp_white.green = ptr->disp_white.blue = -1; - ptr->disp_frameX0 = ptr->disp_frameY0 = -1; - while ((token = xf86getToken(DisplayTab)) != ENDSUBSECTION) { - switch (token) { - case COMMENT: - ptr->disp_comment = xf86addComment(ptr->disp_comment, xf86_lex_val.str); - break; - case VIEWPORT: - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(VIEWPORT_MSG); - ptr->disp_frameX0 = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(VIEWPORT_MSG); - ptr->disp_frameY0 = xf86_lex_val.num; - break; - case VIRTUAL: - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(VIRTUAL_MSG); - ptr->disp_virtualX = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(VIRTUAL_MSG); - ptr->disp_virtualY = xf86_lex_val.num; - break; - case DEPTH: - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(NUMBER_MSG, "Display"); - ptr->disp_depth = xf86_lex_val.num; - break; - case BPP: - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(NUMBER_MSG, "Display"); - ptr->disp_bpp = xf86_lex_val.num; - break; - case VISUAL: - if (xf86getSubToken(&(ptr->disp_comment)) != STRING) - Error(QUOTE_MSG, "Display"); - ptr->disp_visual = xf86_lex_val.str; - break; - case WEIGHT: - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(WEIGHT_MSG); - ptr->disp_weight.red = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(WEIGHT_MSG); - ptr->disp_weight.green = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(WEIGHT_MSG); - ptr->disp_weight.blue = xf86_lex_val.num; - break; - case BLACK_TOK: - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(BLACK_MSG); - ptr->disp_black.red = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(BLACK_MSG); - ptr->disp_black.green = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(BLACK_MSG); - ptr->disp_black.blue = xf86_lex_val.num; - break; - case WHITE_TOK: - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(WHITE_MSG); - ptr->disp_white.red = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(WHITE_MSG); - ptr->disp_white.green = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->disp_comment)) != NUMBER) - Error(WHITE_MSG); - ptr->disp_white.blue = xf86_lex_val.num; - break; - case MODES: - { - XF86ModePtr mptr; - - while ((token = - xf86getSubTokenWithTab(&(ptr->disp_comment), - DisplayTab)) == STRING) { - mptr = calloc(1, sizeof(XF86ModeRec)); - mptr->mode_name = xf86_lex_val.str; - mptr->list.next = NULL; - ptr->disp_mode_lst = (XF86ModePtr) - xf86addListItem((glp) ptr->disp_mode_lst, (glp) mptr); - } - xf86unGetToken(token); - } - break; - case OPTION: - ptr->disp_option_lst = xf86parseOption(ptr->disp_option_lst); - break; - - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - -#ifdef DEBUG - printf("Display subsection parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -static const xf86ConfigSymTabRec ScreenTab[] = { - {ENDSECTION, "endsection"}, - {IDENTIFIER, "identifier"}, - {MATCHSEAT, "matchseat"}, - {OBSDRIVER, "driver"}, - {MDEVICE, "device"}, - {MONITOR, "monitor"}, - {VIDEOADAPTOR, "videoadaptor"}, - {SCREENNO, "screenno"}, - {SUBSECTION, "subsection"}, - {DEFAULTDEPTH, "defaultcolordepth"}, - {DEFAULTDEPTH, "defaultdepth"}, - {DEFAULTBPP, "defaultbpp"}, - {DEFAULTFBBPP, "defaultfbbpp"}, - {VIRTUAL, "virtual"}, - {OPTION, "option"}, - {GDEVICE, "gpudevice"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeScreenList -XF86ConfScreenPtr -xf86parseScreenSection(void) -{ - int has_ident = FALSE; - int has_driver = FALSE; - int token; - - parsePrologue(XF86ConfScreenPtr, XF86ConfScreenRec) - - while ((token = xf86getToken(ScreenTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->scrn_comment = xf86addComment(ptr->scrn_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->scrn_comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - ptr->scrn_identifier = xf86_lex_val.str; - if (has_ident || has_driver) - Error(ONLY_ONE_MSG, "Identifier or Driver"); - has_ident = TRUE; - break; - case MATCHSEAT: - if (xf86getSubToken(&(ptr->scrn_comment)) != STRING) - Error(QUOTE_MSG, "MatchSeat"); - ptr->match_seat = xf86_lex_val.str; - break; - case OBSDRIVER: - if (xf86getSubToken(&(ptr->scrn_comment)) != STRING) - Error(QUOTE_MSG, "Driver"); - ptr->scrn_obso_driver = xf86_lex_val.str; - if (has_ident || has_driver) - Error(ONLY_ONE_MSG, "Identifier or Driver"); - has_driver = TRUE; - break; - case DEFAULTDEPTH: - if (xf86getSubToken(&(ptr->scrn_comment)) != NUMBER) - Error(NUMBER_MSG, "DefaultDepth"); - ptr->scrn_defaultdepth = xf86_lex_val.num; - break; - case DEFAULTBPP: - if (xf86getSubToken(&(ptr->scrn_comment)) != NUMBER) - Error(NUMBER_MSG, "DefaultBPP"); - ptr->scrn_defaultbpp = xf86_lex_val.num; - break; - case DEFAULTFBBPP: - if (xf86getSubToken(&(ptr->scrn_comment)) != NUMBER) - Error(NUMBER_MSG, "DefaultFbBPP"); - ptr->scrn_defaultfbbpp = xf86_lex_val.num; - break; - case MDEVICE: - if (xf86getSubToken(&(ptr->scrn_comment)) != STRING) - Error(QUOTE_MSG, "Device"); - ptr->scrn_device_str = xf86_lex_val.str; - break; - case GDEVICE: - if (xf86getSubToken(&(ptr->scrn_comment)) != STRING) - Error(QUOTE_MSG, "GPUDevice"); - if (ptr->num_gpu_devices == CONF_MAXGPUDEVICES) - Error(GPU_DEVICE_TOO_MANY, CONF_MAXGPUDEVICES); - ptr->scrn_gpu_device_str[ptr->num_gpu_devices++] = xf86_lex_val.str; - break; - case MONITOR: - if (xf86getSubToken(&(ptr->scrn_comment)) != STRING) - Error(QUOTE_MSG, "Monitor"); - ptr->scrn_monitor_str = xf86_lex_val.str; - break; - case VIDEOADAPTOR: - { - XF86ConfAdaptorLinkPtr aptr; - - if (xf86getSubToken(&(ptr->scrn_comment)) != STRING) - Error(QUOTE_MSG, "VideoAdaptor"); - - /* Don't allow duplicates */ - for (aptr = ptr->scrn_adaptor_lst; aptr; - aptr = (XF86ConfAdaptorLinkPtr) aptr->list.next) - if (xf86nameCompare(xf86_lex_val.str, aptr->al_adaptor_str) == 0) - break; - - if (aptr == NULL) { - aptr = calloc(1, sizeof(XF86ConfAdaptorLinkRec)); - aptr->list.next = NULL; - aptr->al_adaptor_str = xf86_lex_val.str; - ptr->scrn_adaptor_lst = (XF86ConfAdaptorLinkPtr) - xf86addListItem((glp) ptr->scrn_adaptor_lst, (glp) aptr); - } - } - break; - case VIRTUAL: - if (xf86getSubToken(&(ptr->scrn_comment)) != NUMBER) - Error(VIRTUAL_MSG); - ptr->scrn_virtualX = xf86_lex_val.num; - if (xf86getSubToken(&(ptr->scrn_comment)) != NUMBER) - Error(VIRTUAL_MSG); - ptr->scrn_virtualY = xf86_lex_val.num; - break; - case OPTION: - ptr->scrn_option_lst = xf86parseOption(ptr->scrn_option_lst); - break; - case SUBSECTION: - if (xf86getSubToken(&(ptr->scrn_comment)) != STRING) - Error(QUOTE_MSG, "SubSection"); - { - free(xf86_lex_val.str); - HANDLE_LIST(scrn_display_lst, xf86parseDisplaySubSection, - XF86ConfDisplayPtr); - } - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - - if (!has_ident && !has_driver) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("Screen section parsed\n"); -#endif - - return ptr; -} - -void -xf86printScreenSection(FILE * cf, XF86ConfScreenPtr ptr) -{ - XF86ConfAdaptorLinkPtr aptr; - XF86ConfDisplayPtr dptr; - XF86ModePtr mptr; - int i; - while (ptr) { - fprintf(cf, "Section \"Screen\"\n"); - if (ptr->scrn_comment) - fprintf(cf, "%s", ptr->scrn_comment); - if (ptr->scrn_identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->scrn_identifier); - if (ptr->scrn_obso_driver) - fprintf(cf, "\tDriver \"%s\"\n", ptr->scrn_obso_driver); - if (ptr->scrn_device_str) - fprintf(cf, "\tDevice \"%s\"\n", ptr->scrn_device_str); - for (i = 0; i < ptr->num_gpu_devices; i++) - if (ptr->scrn_gpu_device_str[i]) - fprintf(cf, "\tGPUDevice \"%s\"\n", ptr->scrn_gpu_device_str[i]); - if (ptr->scrn_monitor_str) - fprintf(cf, "\tMonitor \"%s\"\n", ptr->scrn_monitor_str); - if (ptr->scrn_defaultdepth) - fprintf(cf, "\tDefaultDepth %d\n", ptr->scrn_defaultdepth); - if (ptr->scrn_defaultbpp) - fprintf(cf, "\tDefaultBPP %d\n", ptr->scrn_defaultbpp); - if (ptr->scrn_defaultfbbpp) - fprintf(cf, "\tDefaultFbBPP %d\n", ptr->scrn_defaultfbbpp); - xf86printOptionList(cf, ptr->scrn_option_lst, 1); - for (aptr = ptr->scrn_adaptor_lst; aptr; aptr = aptr->list.next) { - fprintf(cf, "\tVideoAdaptor \"%s\"\n", aptr->al_adaptor_str); - } - if (ptr->scrn_virtualX && ptr->scrn_virtualY) - fprintf(cf, "\tVirtual %d %d\n", - ptr->scrn_virtualX, ptr->scrn_virtualY); - for (dptr = ptr->scrn_display_lst; dptr; dptr = dptr->list.next) { - fprintf(cf, "\tSubSection \"Display\"\n"); - if (dptr->disp_comment) - fprintf(cf, "%s", dptr->disp_comment); - if (dptr->disp_frameX0 >= 0 || dptr->disp_frameY0 >= 0) { - fprintf(cf, "\t\tViewport %d %d\n", - dptr->disp_frameX0, dptr->disp_frameY0); - } - if (dptr->disp_virtualX != 0 || dptr->disp_virtualY != 0) { - fprintf(cf, "\t\tVirtual %d %d\n", - dptr->disp_virtualX, dptr->disp_virtualY); - } - if (dptr->disp_depth) { - fprintf(cf, "\t\tDepth %d\n", dptr->disp_depth); - } - if (dptr->disp_bpp) { - fprintf(cf, "\t\tFbBPP %d\n", dptr->disp_bpp); - } - if (dptr->disp_visual) { - fprintf(cf, "\t\tVisual \"%s\"\n", dptr->disp_visual); - } - if (dptr->disp_weight.red != 0) { - fprintf(cf, "\t\tWeight %d %d %d\n", - dptr->disp_weight.red, dptr->disp_weight.green, - dptr->disp_weight.blue); - } - if (dptr->disp_black.red != -1) { - fprintf(cf, "\t\tBlack 0x%04x 0x%04x 0x%04x\n", - dptr->disp_black.red, dptr->disp_black.green, - dptr->disp_black.blue); - } - if (dptr->disp_white.red != -1) { - fprintf(cf, "\t\tWhite 0x%04x 0x%04x 0x%04x\n", - dptr->disp_white.red, dptr->disp_white.green, - dptr->disp_white.blue); - } - if (dptr->disp_mode_lst) { - fprintf(cf, "\t\tModes "); - } - for (mptr = dptr->disp_mode_lst; mptr; mptr = mptr->list.next) { - fprintf(cf, " \"%s\"", mptr->mode_name); - } - if (dptr->disp_mode_lst) { - fprintf(cf, "\n"); - } - xf86printOptionList(cf, dptr->disp_option_lst, 2); - fprintf(cf, "\tEndSubSection\n"); - } - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } - -} - -static void -xf86freeAdaptorLinkList(XF86ConfAdaptorLinkPtr ptr) -{ - XF86ConfAdaptorLinkPtr prev; - - while (ptr) { - TestFree(ptr->al_adaptor_str); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -void -xf86freeScreenList(XF86ConfScreenPtr ptr) -{ - XF86ConfScreenPtr prev; - int i; - while (ptr) { - TestFree(ptr->scrn_identifier); - TestFree(ptr->scrn_monitor_str); - TestFree(ptr->scrn_device_str); - for (i = 0; i < ptr->num_gpu_devices; i++) - TestFree(ptr->scrn_gpu_device_str[i]); - TestFree(ptr->scrn_comment); - xf86optionListFree(ptr->scrn_option_lst); - xf86freeAdaptorLinkList(ptr->scrn_adaptor_lst); - xf86freeDisplayList(ptr->scrn_display_lst); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -int -xf86validateScreen(XF86ConfigPtr p) -{ - XF86ConfScreenPtr screen = p->conf_screen_lst; - XF86ConfMonitorPtr monitor; - XF86ConfAdaptorLinkPtr adaptor; - int i; - - while (screen) { - if (screen->scrn_obso_driver && !screen->scrn_identifier) - screen->scrn_identifier = screen->scrn_obso_driver; - - monitor = - xf86findMonitor(screen->scrn_monitor_str, p->conf_monitor_lst); - if (screen->scrn_monitor_str) { - if (monitor) { - screen->scrn_monitor = monitor; - if (!xf86validateMonitor(p, screen)) - return FALSE; - } - } - - screen->scrn_device = - xf86findDevice(screen->scrn_device_str, p->conf_device_lst); - - for (i = 0; i < screen->num_gpu_devices; i++) { - screen->scrn_gpu_devices[i] = - xf86findDevice(screen->scrn_gpu_device_str[i], p->conf_device_lst); - } - adaptor = screen->scrn_adaptor_lst; - while (adaptor) { - adaptor->al_adaptor = - xf86findVideoAdaptor(adaptor->al_adaptor_str, - p->conf_videoadaptor_lst); - if (!adaptor->al_adaptor) { - xf86validationError(UNDEFINED_ADAPTOR_MSG, - adaptor->al_adaptor_str, - screen->scrn_identifier); - return FALSE; - } - else if (adaptor->al_adaptor->va_fwdref) { - xf86validationError(ADAPTOR_REF_TWICE_MSG, - adaptor->al_adaptor_str, - adaptor->al_adaptor->va_fwdref); - return FALSE; - } - - adaptor->al_adaptor->va_fwdref = strdup(screen->scrn_identifier); - adaptor = adaptor->list.next; - } - - screen = screen->list.next; - } - - return TRUE; -} - -XF86ConfScreenPtr -xf86findScreen(const char *ident, XF86ConfScreenPtr p) -{ - while (p) { - if (xf86nameCompare(ident, p->scrn_identifier) == 0) - return p; - - p = p->list.next; - } - return NULL; -} diff --git a/hw/xfree86/parser/Vendor.c b/hw/xfree86/parser/Vendor.c deleted file mode 100644 index 50ea68956..000000000 --- a/hw/xfree86/parser/Vendor.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec VendorSubTab[] = { - {ENDSUBSECTION, "endsubsection"}, - {IDENTIFIER, "identifier"}, - {OPTION, "option"}, - {-1, ""}, -}; - -static void -xf86freeVendorSubList(XF86ConfVendSubPtr ptr) -{ - XF86ConfVendSubPtr prev; - - while (ptr) { - TestFree(ptr->vs_identifier); - TestFree(ptr->vs_name); - TestFree(ptr->vs_comment); - xf86optionListFree(ptr->vs_option_lst); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -#define CLEANUP xf86freeVendorSubList - -static XF86ConfVendSubPtr -xf86parseVendorSubSection(void) -{ - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfVendSubPtr, XF86ConfVendSubRec) - - while ((token = xf86getToken(VendorSubTab)) != ENDSUBSECTION) { - switch (token) { - case COMMENT: - ptr->vs_comment = xf86addComment(ptr->vs_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->vs_comment))) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->vs_identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case OPTION: - ptr->vs_option_lst = xf86parseOption(ptr->vs_option_lst); - break; - - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - -#ifdef DEBUG - printf("Vendor subsection parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -static const xf86ConfigSymTabRec VendorTab[] = { - {ENDSECTION, "endsection"}, - {IDENTIFIER, "identifier"}, - {OPTION, "option"}, - {SUBSECTION, "subsection"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeVendorList - -XF86ConfVendorPtr -xf86parseVendorSection(void) -{ - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfVendorPtr, XF86ConfVendorRec) - - while ((token = xf86getToken(VendorTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->vnd_comment = xf86addComment(ptr->vnd_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->vnd_comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->vnd_identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case OPTION: - ptr->vnd_option_lst = xf86parseOption(ptr->vnd_option_lst); - break; - case SUBSECTION: - if (xf86getSubToken(&(ptr->vnd_comment)) != STRING) - Error(QUOTE_MSG, "SubSection"); - { - HANDLE_LIST(vnd_sub_lst, xf86parseVendorSubSection, - XF86ConfVendSubPtr); - } - break; - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - - } - - if (!has_ident) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("Vendor section parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -void -xf86printVendorSection(FILE * cf, XF86ConfVendorPtr ptr) -{ - XF86ConfVendSubPtr pptr; - - while (ptr) { - fprintf(cf, "Section \"Vendor\"\n"); - if (ptr->vnd_comment) - fprintf(cf, "%s", ptr->vnd_comment); - if (ptr->vnd_identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->vnd_identifier); - - xf86printOptionList(cf, ptr->vnd_option_lst, 1); - for (pptr = ptr->vnd_sub_lst; pptr; pptr = pptr->list.next) { - fprintf(cf, "\tSubSection \"Vendor\"\n"); - if (pptr->vs_comment) - fprintf(cf, "%s", pptr->vs_comment); - if (pptr->vs_identifier) - fprintf(cf, "\t\tIdentifier \"%s\"\n", pptr->vs_identifier); - xf86printOptionList(cf, pptr->vs_option_lst, 2); - fprintf(cf, "\tEndSubSection\n"); - } - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } -} - -void -xf86freeVendorList(XF86ConfVendorPtr p) -{ - if (p == NULL) - return; - xf86freeVendorSubList(p->vnd_sub_lst); - TestFree(p->vnd_identifier); - TestFree(p->vnd_comment); - xf86optionListFree(p->vnd_option_lst); - free(p); -} diff --git a/hw/xfree86/parser/Video.c b/hw/xfree86/parser/Video.c deleted file mode 100644 index 4e8526f3f..000000000 --- a/hw/xfree86/parser/Video.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec VideoPortTab[] = { - {ENDSUBSECTION, "endsubsection"}, - {IDENTIFIER, "identifier"}, - {OPTION, "option"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeVideoPortList - -static void -xf86freeVideoPortList(XF86ConfVideoPortPtr ptr) -{ - XF86ConfVideoPortPtr prev; - - while (ptr) { - TestFree(ptr->vp_identifier); - TestFree(ptr->vp_comment); - xf86optionListFree(ptr->vp_option_lst); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -static XF86ConfVideoPortPtr -xf86parseVideoPortSubSection(void) -{ - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfVideoPortPtr, XF86ConfVideoPortRec) - - while ((token = xf86getToken(VideoPortTab)) != ENDSUBSECTION) { - switch (token) { - case COMMENT: - ptr->vp_comment = xf86addComment(ptr->vp_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->vp_comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - ptr->vp_identifier = xf86_lex_val.str; - has_ident = TRUE; - break; - case OPTION: - ptr->vp_option_lst = xf86parseOption(ptr->vp_option_lst); - break; - - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - -#ifdef DEBUG - printf("VideoPort subsection parsed\n"); -#endif - - return ptr; -} - -#undef CLEANUP - -static const xf86ConfigSymTabRec VideoAdaptorTab[] = { - {ENDSECTION, "endsection"}, - {IDENTIFIER, "identifier"}, - {VENDOR, "vendorname"}, - {BOARD, "boardname"}, - {BUSID, "busid"}, - {DRIVER, "driver"}, - {OPTION, "option"}, - {SUBSECTION, "subsection"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeVideoAdaptorList - -XF86ConfVideoAdaptorPtr -xf86parseVideoAdaptorSection(void) -{ - int has_ident = FALSE; - int token; - - parsePrologue(XF86ConfVideoAdaptorPtr, XF86ConfVideoAdaptorRec) - - while ((token = xf86getToken(VideoAdaptorTab)) != ENDSECTION) { - switch (token) { - case COMMENT: - ptr->va_comment = xf86addComment(ptr->va_comment, xf86_lex_val.str); - break; - case IDENTIFIER: - if (xf86getSubToken(&(ptr->va_comment)) != STRING) - Error(QUOTE_MSG, "Identifier"); - ptr->va_identifier = xf86_lex_val.str; - if (has_ident == TRUE) - Error(MULTIPLE_MSG, "Identifier"); - has_ident = TRUE; - break; - case VENDOR: - if (xf86getSubToken(&(ptr->va_comment)) != STRING) - Error(QUOTE_MSG, "Vendor"); - ptr->va_vendor = xf86_lex_val.str; - break; - case BOARD: - if (xf86getSubToken(&(ptr->va_comment)) != STRING) - Error(QUOTE_MSG, "Board"); - ptr->va_board = xf86_lex_val.str; - break; - case BUSID: - if (xf86getSubToken(&(ptr->va_comment)) != STRING) - Error(QUOTE_MSG, "BusID"); - ptr->va_busid = xf86_lex_val.str; - break; - case DRIVER: - if (xf86getSubToken(&(ptr->va_comment)) != STRING) - Error(QUOTE_MSG, "Driver"); - ptr->va_driver = xf86_lex_val.str; - break; - case OPTION: - ptr->va_option_lst = xf86parseOption(ptr->va_option_lst); - break; - case SUBSECTION: - if (xf86getSubToken(&(ptr->va_comment)) != STRING) - Error(QUOTE_MSG, "SubSection"); - { - HANDLE_LIST(va_port_lst, xf86parseVideoPortSubSection, - XF86ConfVideoPortPtr); - } - break; - - case EOF_TOKEN: - Error(UNEXPECTED_EOF_MSG); - break; - default: - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - break; - } - } - - if (!has_ident) - Error(NO_IDENT_MSG); - -#ifdef DEBUG - printf("VideoAdaptor section parsed\n"); -#endif - - return ptr; -} - -void -xf86printVideoAdaptorSection(FILE * cf, XF86ConfVideoAdaptorPtr ptr) -{ - XF86ConfVideoPortPtr pptr; - - while (ptr) { - fprintf(cf, "Section \"VideoAdaptor\"\n"); - if (ptr->va_comment) - fprintf(cf, "%s", ptr->va_comment); - if (ptr->va_identifier) - fprintf(cf, "\tIdentifier \"%s\"\n", ptr->va_identifier); - if (ptr->va_vendor) - fprintf(cf, "\tVendorName \"%s\"\n", ptr->va_vendor); - if (ptr->va_board) - fprintf(cf, "\tBoardName \"%s\"\n", ptr->va_board); - if (ptr->va_busid) - fprintf(cf, "\tBusID \"%s\"\n", ptr->va_busid); - if (ptr->va_driver) - fprintf(cf, "\tDriver \"%s\"\n", ptr->va_driver); - xf86printOptionList(cf, ptr->va_option_lst, 1); - for (pptr = ptr->va_port_lst; pptr; pptr = pptr->list.next) { - fprintf(cf, "\tSubSection \"VideoPort\"\n"); - if (pptr->vp_comment) - fprintf(cf, "%s", pptr->vp_comment); - if (pptr->vp_identifier) - fprintf(cf, "\t\tIdentifier \"%s\"\n", pptr->vp_identifier); - xf86printOptionList(cf, pptr->vp_option_lst, 2); - fprintf(cf, "\tEndSubSection\n"); - } - fprintf(cf, "EndSection\n\n"); - ptr = ptr->list.next; - } - -} - -void -xf86freeVideoAdaptorList(XF86ConfVideoAdaptorPtr ptr) -{ - XF86ConfVideoAdaptorPtr prev; - - while (ptr) { - TestFree(ptr->va_identifier); - TestFree(ptr->va_vendor); - TestFree(ptr->va_board); - TestFree(ptr->va_busid); - TestFree(ptr->va_driver); - TestFree(ptr->va_fwdref); - TestFree(ptr->va_comment); - xf86freeVideoPortList(ptr->va_port_lst); - xf86optionListFree(ptr->va_option_lst); - prev = ptr; - ptr = ptr->list.next; - free(prev); - } -} - -XF86ConfVideoAdaptorPtr -xf86findVideoAdaptor(const char *ident, XF86ConfVideoAdaptorPtr p) -{ - while (p) { - if (xf86nameCompare(ident, p->va_identifier) == 0) - return p; - - p = p->list.next; - } - return NULL; -} diff --git a/hw/xfree86/parser/configProcs.h b/hw/xfree86/parser/configProcs.h deleted file mode 100644 index 7a46e0160..000000000 --- a/hw/xfree86/parser/configProcs.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 1997-2001 by The XFree86 Project, 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). - */ - -/* Private procs. Public procs are in xf86Parser.h and xf86Optrec.h */ - -/* exported functions are/were used by the X Server */ - -/* Device.c */ -XF86ConfDevicePtr xf86parseDeviceSection(void); -void xf86printDeviceSection(FILE * cf, XF86ConfDevicePtr ptr); -void xf86freeDeviceList(XF86ConfDevicePtr ptr); -int xf86validateDevice(XF86ConfigPtr p); - -/* Files.c */ -XF86ConfFilesPtr xf86parseFilesSection(void); -void xf86printFileSection(FILE * cf, XF86ConfFilesPtr ptr); -void xf86freeFiles(XF86ConfFilesPtr p); - -/* Flags.c */ -XF86ConfFlagsPtr xf86parseFlagsSection(void); -void xf86printServerFlagsSection(FILE * f, XF86ConfFlagsPtr flags); -void xf86freeFlags(XF86ConfFlagsPtr flags); - -/* Input.c */ -XF86ConfInputPtr xf86parseInputSection(void); -void xf86printInputSection(FILE * f, XF86ConfInputPtr ptr); -void xf86freeInputList(XF86ConfInputPtr ptr); -int xf86validateInput(XF86ConfigPtr p); - -/* InputClass.c */ -XF86ConfInputClassPtr xf86parseInputClassSection(void); -void xf86printInputClassSection(FILE * f, XF86ConfInputClassPtr ptr); - -/* OutputClass.c */ -XF86ConfOutputClassPtr xf86parseOutputClassSection(void); -void xf86printOutputClassSection(FILE * f, XF86ConfOutputClassPtr ptr); - -/* Layout.c */ -XF86ConfLayoutPtr xf86parseLayoutSection(void); -void xf86printLayoutSection(FILE * cf, XF86ConfLayoutPtr ptr); -void xf86freeLayoutList(XF86ConfLayoutPtr ptr); -int xf86validateLayout(XF86ConfigPtr p); - -/* Module.c */ -XF86ConfModulePtr xf86parseModuleSection(void); -void xf86printModuleSection(FILE * cf, XF86ConfModulePtr ptr); -extern _X_EXPORT XF86LoadPtr xf86addNewLoadDirective(XF86LoadPtr head, - const char *name, int type, - XF86OptionPtr opts); -void xf86freeModules(XF86ConfModulePtr ptr); - -/* Monitor.c */ -XF86ConfMonitorPtr xf86parseMonitorSection(void); -XF86ConfModesPtr xf86parseModesSection(void); -void xf86printMonitorSection(FILE * cf, XF86ConfMonitorPtr ptr); -void xf86printModesSection(FILE * cf, XF86ConfModesPtr ptr); -extern _X_EXPORT void xf86freeMonitorList(XF86ConfMonitorPtr ptr); -void xf86freeModesList(XF86ConfModesPtr ptr); -int xf86validateMonitor(XF86ConfigPtr p, XF86ConfScreenPtr screen); - -/* Pointer.c */ -XF86ConfInputPtr xf86parsePointerSection(void); - -/* Screen.c */ -XF86ConfScreenPtr xf86parseScreenSection(void); -void xf86printScreenSection(FILE * cf, XF86ConfScreenPtr ptr); -extern _X_EXPORT void xf86freeScreenList(XF86ConfScreenPtr ptr); -int xf86validateScreen(XF86ConfigPtr p); - -/* Vendor.c */ -XF86ConfVendorPtr xf86parseVendorSection(void); -void xf86freeVendorList(XF86ConfVendorPtr p); -void xf86printVendorSection(FILE * cf, XF86ConfVendorPtr ptr); - -/* Video.c */ -XF86ConfVideoAdaptorPtr xf86parseVideoAdaptorSection(void); -void xf86printVideoAdaptorSection(FILE * cf, XF86ConfVideoAdaptorPtr ptr); -void xf86freeVideoAdaptorList(XF86ConfVideoAdaptorPtr ptr); - -/* scan.c */ -int xf86getToken(const xf86ConfigSymTabRec * tab); -int xf86getSubToken(char **comment); -int xf86getSubTokenWithTab(char **comment, const xf86ConfigSymTabRec * tab); -void xf86unGetToken(int token); -char *xf86tokenString(void); -void -xf86parseError(const char *format, ...) -_X_ATTRIBUTE_PRINTF(1, 2); -void -xf86validationError(const char *format, ...) -_X_ATTRIBUTE_PRINTF(1, 2); -void -xf86setSection(const char *section); -int -xf86getStringToken(const xf86ConfigSymTabRec * tab); - -/* write.c */ -/* DRI.c */ -XF86ConfDRIPtr -xf86parseDRISection(void); -void -xf86printDRISection(FILE * cf, XF86ConfDRIPtr ptr); -void -xf86freeDRI(XF86ConfDRIPtr ptr); - -/* Extensions.c */ -XF86ConfExtensionsPtr -xf86parseExtensionsSection(void); -void -xf86printExtensionsSection(FILE * cf, XF86ConfExtensionsPtr ptr); -void -xf86freeExtensions(XF86ConfExtensionsPtr ptr); - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef HAVE_XORG_CONFIG_H -/* Externally provided functions */ -void -ErrorF(const char *f, ...); -void -VErrorF(const char *f, va_list args); -#endif diff --git a/hw/xfree86/parser/meson.build b/hw/xfree86/parser/meson.build deleted file mode 100644 index 031dc2bec..000000000 --- a/hw/xfree86/parser/meson.build +++ /dev/null @@ -1,32 +0,0 @@ -srcs_xorg_parser = [ - 'Device.c', - 'Files.c', - 'Flags.c', - 'Input.c', - 'InputClass.c', - 'OutputClass.c', - 'Layout.c', - 'Module.c', - 'Video.c', - 'Monitor.c', - 'Pointer.c', - 'Screen.c', - 'Vendor.c', - 'read.c', - 'scan.c', - 'write.c', - 'DRI.c', - 'Extensions.c', -] - -xorg_parser = static_library('xorg_parser', - srcs_xorg_parser, - include_directories: [inc, xorg_inc], - dependencies: common_dep, - c_args: [ - xorg_c_args, - '-DDATADIR="' + join_paths(get_option('prefix'), get_option('datadir')) + '"', - ], -) - -install_data(['xf86Parser.h', 'xf86Optrec.h'], install_dir: xorgsdkdir) diff --git a/hw/xfree86/parser/read.c b/hw/xfree86/parser/read.c deleted file mode 100644 index d7e731217..000000000 --- a/hw/xfree86/parser/read.c +++ /dev/null @@ -1,309 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Config.h" -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - - -static const xf86ConfigSymTabRec TopLevelTab[] = { - {SECTION, "section"}, - {-1, ""}, -}; - -#define CLEANUP xf86freeConfig - -/* - * This function resolves name references and reports errors if the named - * objects cannot be found. - */ -static int -xf86validateConfig(XF86ConfigPtr p) -{ - if (!xf86validateScreen(p)) - return FALSE; - if (!xf86validateInput(p)) - return FALSE; - if (!xf86validateLayout(p)) - return FALSE; - - return TRUE; -} - -XF86ConfigPtr -xf86readConfigFile(void) -{ - int token; - XF86ConfigPtr ptr = NULL; - - if ((ptr = xf86allocateConfig()) == NULL) { - return NULL; - } - - while ((token = xf86getToken(TopLevelTab)) != EOF_TOKEN) { - switch (token) { - case COMMENT: - ptr->conf_comment = xf86addComment(ptr->conf_comment, xf86_lex_val.str); - break; - case SECTION: - if (xf86getSubToken(&(ptr->conf_comment)) != STRING) { - xf86parseError(QUOTE_MSG, "Section"); - CLEANUP(ptr); - return NULL; - } - xf86setSection(xf86_lex_val.str); - if (xf86nameCompare(xf86_lex_val.str, "files") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_RETURN(conf_files, xf86parseFilesSection()); - } - else if (xf86nameCompare(xf86_lex_val.str, "serverflags") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_RETURN(conf_flags, xf86parseFlagsSection()); - } - else if (xf86nameCompare(xf86_lex_val.str, "pointer") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_input_lst, xf86parsePointerSection, - XF86ConfInputPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "videoadaptor") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_videoadaptor_lst, xf86parseVideoAdaptorSection, - XF86ConfVideoAdaptorPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "device") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_device_lst, xf86parseDeviceSection, - XF86ConfDevicePtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "monitor") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_monitor_lst, xf86parseMonitorSection, - XF86ConfMonitorPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "modes") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_modes_lst, xf86parseModesSection, - XF86ConfModesPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "screen") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_screen_lst, xf86parseScreenSection, - XF86ConfScreenPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "inputdevice") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_input_lst, xf86parseInputSection, - XF86ConfInputPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "inputclass") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_inputclass_lst, - xf86parseInputClassSection, XF86ConfInputClassPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "outputclass") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_outputclass_lst, xf86parseOutputClassSection, - XF86ConfOutputClassPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "module") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_RETURN(conf_modules, xf86parseModuleSection()); - } - else if (xf86nameCompare(xf86_lex_val.str, "serverlayout") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_layout_lst, xf86parseLayoutSection, - XF86ConfLayoutPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "vendor") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_LIST(conf_vendor_lst, xf86parseVendorSection, - XF86ConfVendorPtr); - } - else if (xf86nameCompare(xf86_lex_val.str, "dri") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_RETURN(conf_dri, xf86parseDRISection()); - } - else if (xf86nameCompare(xf86_lex_val.str, "extensions") == 0) { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - HANDLE_RETURN(conf_extensions, xf86parseExtensionsSection()); - } - else { - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - Error(INVALID_SECTION_MSG, xf86tokenString()); - } - break; - default: - free(xf86_lex_val.str); - xf86_lex_val.str = NULL; - Error(INVALID_KEYWORD_MSG, xf86tokenString()); - } - } - - if (xf86validateConfig(ptr)) - return ptr; - else { - CLEANUP(ptr); - return NULL; - } -} - -#undef CLEANUP - -/* - * adds an item to the end of the linked list. Any record whose first field - * is a GenericListRec can be cast to this type and used with this function. - * A pointer to the head of the list is returned to handle the addition of - * the first item. - */ -GenericListPtr -xf86addListItem(GenericListPtr head, GenericListPtr new) -{ - GenericListPtr p = head; - GenericListPtr last = NULL; - - while (p) { - last = p; - p = p->next; - } - - if (last) { - last->next = new; - return head; - } - else - return new; -} - -/* - * Test if one chained list contains the other. - * In this case both list have the same endpoint (provided they don't loop) - */ -int -xf86itemNotSublist(GenericListPtr list_1, GenericListPtr list_2) -{ - GenericListPtr p = list_1; - GenericListPtr last_1 = NULL, last_2 = NULL; - - while (p) { - last_1 = p; - p = p->next; - } - - p = list_2; - while (p) { - last_2 = p; - p = p->next; - } - - return (!(last_1 == last_2)); -} - -/* - * Conditionally allocate config struct, but only allocate it - * if it's not already there. In either event, return the pointer - * to the global config struct. - */ -XF86ConfigPtr xf86allocateConfig(void) -{ - if (!xf86configptr) { - xf86configptr = calloc(1, sizeof(XF86ConfigRec)); - } - return xf86configptr; -} - -void -xf86freeConfig(XF86ConfigPtr p) -{ - if (p == NULL) - return; - - xf86freeFiles(p->conf_files); - xf86freeModules(p->conf_modules); - xf86freeFlags(p->conf_flags); - xf86freeMonitorList(p->conf_monitor_lst); - xf86freeModesList(p->conf_modes_lst); - xf86freeVideoAdaptorList(p->conf_videoadaptor_lst); - xf86freeDeviceList(p->conf_device_lst); - xf86freeScreenList(p->conf_screen_lst); - xf86freeLayoutList(p->conf_layout_lst); - xf86freeInputList(p->conf_input_lst); - xf86freeVendorList(p->conf_vendor_lst); - xf86freeDRI(p->conf_dri); - xf86freeExtensions(p->conf_extensions); - TestFree(p->conf_comment); - - free(p); -} diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c deleted file mode 100644 index 1eb35ed73..000000000 --- a/hw/xfree86/parser/scan.c +++ /dev/null @@ -1,1134 +0,0 @@ -/* - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if !defined(MAXHOSTNAMELEN) -#define MAXHOSTNAMELEN 32 -#endif /* !MAXHOSTNAMELEN */ - -/* For PATH_MAX */ -#include "misc.h" - -#include "Configint.h" -#include "xf86tokens.h" - -#define CONFIG_BUF_LEN 1024 -#define CONFIG_MAX_FILES 64 - -static struct { - FILE *file; - char *path; -} configFiles[CONFIG_MAX_FILES]; -static const char **builtinConfig = NULL; -static int builtinIndex = 0; -static int configPos = 0; /* current readers position */ -static int configLineNo = 0; /* linenumber */ -static char *configBuf, *configRBuf; /* buffer for lines */ -static char *configSection = NULL; /* name of current section being parsed */ -static int numFiles = 0; /* number of config files */ -static int curFileIndex = 0; /* index of current config file */ -static int pushToken = LOCK_TOKEN; -static int eol_seen = 0; /* private state to handle comments */ -LexRec xf86_lex_val; - -/* - * xf86getNextLine -- - * - * read from the configFiles FILE stream until we encounter a new - * line; this is effectively just a big wrapper for fgets(3). - * - * xf86getToken() assumes that we will read up to the next - * newline; we need to grow configBuf and configRBuf as needed to - * support that. - */ - -static char * -xf86getNextLine(void) -{ - static int configBufLen = CONFIG_BUF_LEN; - char *tmpConfigBuf, *tmpConfigRBuf; - int c, i, pos = 0, eolFound = 0; - char *ret = NULL; - - /* - * reallocate the string if it was grown last time (i.e., is no - * longer CONFIG_BUF_LEN); we malloc the new strings first, so - * that if either of the mallocs fail, we can fall back on the - * existing buffer allocations - */ - - if (configBufLen != CONFIG_BUF_LEN) { - - tmpConfigBuf = malloc(CONFIG_BUF_LEN); - tmpConfigRBuf = malloc(CONFIG_BUF_LEN); - - if (!tmpConfigBuf || !tmpConfigRBuf) { - - /* - * at least one of the mallocs failed; keep the old buffers - * and free any partial allocations - */ - - free(tmpConfigBuf); - free(tmpConfigRBuf); - - } - else { - - /* - * malloc succeeded; free the old buffers and use the new - * buffers - */ - - configBufLen = CONFIG_BUF_LEN; - - free(configBuf); - free(configRBuf); - - configBuf = tmpConfigBuf; - configRBuf = tmpConfigRBuf; - } - } - - /* read in another block of chars */ - - do { - ret = fgets(configBuf + pos, configBufLen - pos - 1, - configFiles[curFileIndex].file); - - if (!ret) { - /* - * if the file doesn't end in a newline, add one - * and trigger another read - */ - if (pos != 0) { - strcpy(&configBuf[pos], "\n"); - ret = configBuf; - } - else - break; - } - - /* search for EOL in the new block of chars */ - - for (i = pos; i < (configBufLen - 1); i++) { - c = configBuf[i]; - - if (c == '\0') - break; - - if ((c == '\n') || (c == '\r')) { - eolFound = 1; - break; - } - } - - /* - * if we didn't find EOL, then grow the string and - * read in more - */ - - if (!eolFound) { - - tmpConfigBuf = realloc(configBuf, configBufLen + CONFIG_BUF_LEN); - tmpConfigRBuf = realloc(configRBuf, configBufLen + CONFIG_BUF_LEN); - - if (!tmpConfigBuf || !tmpConfigRBuf) { - - /* - * at least one of the reallocations failed; use the - * new allocation that succeeded, but we have to - * fallback to the previous configBufLen size and use - * the string we have, even though we don't have an - * EOL - */ - - if (tmpConfigBuf) - configBuf = tmpConfigBuf; - if (tmpConfigRBuf) - configRBuf = tmpConfigRBuf; - - break; - - } - else { - - /* reallocation succeeded */ - - configBuf = tmpConfigBuf; - configRBuf = tmpConfigRBuf; - pos = i; - configBufLen += CONFIG_BUF_LEN; - } - } - - } while (!eolFound); - - return ret; -} - -static int -StringToToken(const char *str, const xf86ConfigSymTabRec * tab) -{ - int i; - - for (i = 0; tab[i].token != -1; i++) { - if (!xf86nameCompare(tab[i].name, str)) - return tab[i].token; - } - return ERROR_TOKEN; -} - -/* - * xf86getToken -- - * Read next Token from the config file. Handle the global variable - * pushToken. - */ -int -xf86getToken(const xf86ConfigSymTabRec * tab) -{ - int c, i; - - /* - * First check whether pushToken has a different value than LOCK_TOKEN. - * In this case rBuf[] contains a valid STRING/TOKEN/NUMBER. But in the - * oth * case the next token must be read from the input. - */ - if (pushToken == EOF_TOKEN) - return EOF_TOKEN; - else if (pushToken == LOCK_TOKEN) { - /* - * eol_seen is only set for the first token after a newline. - */ - eol_seen = 0; - - c = configBuf[configPos]; - - /* - * Get start of next Token. EOF is handled, - * whitespaces are skipped. - */ - - again: - if (!c) { - char *ret; - - if (numFiles > 0) - ret = xf86getNextLine(); - else { - if (builtinConfig[builtinIndex] == NULL) - ret = NULL; - else { - strlcpy(configBuf, - builtinConfig[builtinIndex], CONFIG_BUF_LEN); - ret = configBuf; - builtinIndex++; - } - } - if (ret == NULL) { - /* - * if necessary, move to the next file and - * read the first line - */ - if (curFileIndex + 1 < numFiles) { - curFileIndex++; - configLineNo = 0; - goto again; - } - else - return pushToken = EOF_TOKEN; - } - configLineNo++; - configPos = 0; - eol_seen = 1; - } - - i = 0; - for (;;) { - c = configBuf[configPos++]; - configRBuf[i++] = c; - switch (c) { - case ' ': - case '\t': - case '\r': - continue; - case '\n': - i = 0; - continue; - } - break; - } - if (c == '\0') - goto again; - - if (c == '#') { - do { - configRBuf[i++] = (c = configBuf[configPos++]); - } - while ((c != '\n') && (c != '\r') && (c != '\0')); - configRBuf[i] = '\0'; - /* XXX no private copy. - * Use xf86addComment when setting a comment. - */ - xf86_lex_val.str = configRBuf; - return COMMENT; - } - - /* GJA -- handle '-' and ',' * Be careful: "-hsync" is a keyword. */ - else if ((c == ',') && !isalpha(configBuf[configPos])) { - return COMMA; - } - else if ((c == '-') && !isalpha(configBuf[configPos])) { - return DASH; - } - - /* - * Numbers are returned immediately ... - */ - if (isdigit(c)) { - int base; - - if (c == '0') - if ((configBuf[configPos] == 'x') || - (configBuf[configPos] == 'X')) { - base = 16; - xf86_lex_val.numType = PARSE_HEX; - } - else { - base = 8; - xf86_lex_val.numType = PARSE_OCTAL; - } - else { - base = 10; - xf86_lex_val.numType = PARSE_DECIMAL; - } - - configRBuf[0] = c; - i = 1; - while (isdigit(c = configBuf[configPos++]) || - (c == '.') || (c == 'x') || (c == 'X') || - ((base == 16) && (((c >= 'a') && (c <= 'f')) || - ((c >= 'A') && (c <= 'F'))))) - configRBuf[i++] = c; - configPos--; /* GJA -- one too far */ - configRBuf[i] = '\0'; - xf86_lex_val.num = strtoul(configRBuf, NULL, 0); - xf86_lex_val.realnum = atof(configRBuf); - return NUMBER; - } - - /* - * All Strings START with a \" ... - */ - else if (c == '\"') { - i = -1; - do { - configRBuf[++i] = (c = configBuf[configPos++]); - } - while ((c != '\"') && (c != '\n') && (c != '\r') && (c != '\0')); - configRBuf[i] = '\0'; - xf86_lex_val.str = malloc(strlen(configRBuf) + 1); - strcpy(xf86_lex_val.str, configRBuf); /* private copy ! */ - return STRING; - } - - /* - * ... and now we MUST have a valid token. The search is - * handled later along with the pushed tokens. - */ - else { - configRBuf[0] = c; - i = 0; - do { - configRBuf[++i] = (c = configBuf[configPos++]); - } - while ((c != ' ') && (c != '\t') && (c != '\n') && (c != '\r') && - (c != '\0') && (c != '#')); - --configPos; - configRBuf[i] = '\0'; - i = 0; - } - - } - else { - - /* - * Here we deal with pushed tokens. Reinitialize pushToken again. If - * the pushed token was NUMBER || STRING return them again ... - */ - int temp = pushToken; - - pushToken = LOCK_TOKEN; - - if (temp == COMMA || temp == DASH) - return temp; - if (temp == NUMBER || temp == STRING) - return temp; - } - - /* - * Joop, at last we have to lookup the token ... - */ - if (tab) - return StringToToken(configRBuf, tab); - - return ERROR_TOKEN; /* Error catcher */ -} - -int -xf86getSubToken(char **comment) -{ - int token; - - for (;;) { - token = xf86getToken(NULL); - if (token == COMMENT) { - if (comment) - *comment = xf86addComment(*comment, xf86_lex_val.str); - } - else - return token; - } - /*NOTREACHED*/} - -int -xf86getSubTokenWithTab(char **comment, const xf86ConfigSymTabRec * tab) -{ - int token; - - for (;;) { - token = xf86getToken(tab); - if (token == COMMENT) { - if (comment) - *comment = xf86addComment(*comment, xf86_lex_val.str); - } - else - return token; - } - /*NOTREACHED*/} - -void -xf86unGetToken(int token) -{ - pushToken = token; -} - -char * -xf86tokenString(void) -{ - return configRBuf; -} - -int -xf86pathIsAbsolute(const char *path) -{ - if (path && path[0] == '/') - return 1; - return 0; -} - -/* A path is "safe" if it is relative and if it contains no ".." elements. */ -int -xf86pathIsSafe(const char *path) -{ - if (xf86pathIsAbsolute(path)) - return 0; - - /* Compare with ".." */ - if (!strcmp(path, "..")) - return 0; - - /* Look for leading "../" */ - if (!strncmp(path, "../", 3)) - return 0; - - /* Look for trailing "/.." */ - if ((strlen(path) > 3) && !strcmp(path + strlen(path) - 3, "/..")) - return 0; - - /* Look for "/../" */ - if (strstr(path, "/../")) - return 0; - - return 1; -} - -/* - * This function substitutes the following escape sequences: - * - * %A cmdline argument as an absolute path (must be absolute to match) - * %R cmdline argument as a relative path - * %S cmdline argument as a "safe" path (relative, and no ".." elements) - * %X default config file name ("xorg.conf") - * %H hostname - * %E config file environment ($XORGCONFIG) as an absolute path - * %F config file environment ($XORGCONFIG) as a relative path - * %G config file environment ($XORGCONFIG) as a safe path - * %P projroot - * %C sysconfdir - * %D datadir - * %% % - */ - -#define XCONFIGSUFFIX ".conf" -#define XCONFENV "XORGCONFIG" - -#define BAIL_OUT do { \ - free(result); \ - return NULL; \ - } while (0) - -#define CHECK_LENGTH do { \ - if (l > PATH_MAX) { \ - BAIL_OUT; \ - } \ - } while (0) - -#define APPEND_STR(s) do { \ - if (strlen(s) + l > PATH_MAX) { \ - BAIL_OUT; \ - } else { \ - strcpy(result + l, s); \ - l += strlen(s); \ - } \ - } while (0) - -static char * -DoSubstitution(const char *template, const char *cmdline, const char *projroot, - int *cmdlineUsed, int *envUsed, const char *XConfigFile) -{ - char *result; - int i, l; - static const char *env = NULL; - static char *hostname = NULL; - - if (!template) - return NULL; - - if (cmdlineUsed) - *cmdlineUsed = 0; - if (envUsed) - *envUsed = 0; - - result = malloc(PATH_MAX + 1); - l = 0; - for (i = 0; template[i]; i++) { - if (template[i] != '%') { - result[l++] = template[i]; - CHECK_LENGTH; - } - else { - switch (template[++i]) { - case 'A': - if (cmdline && xf86pathIsAbsolute(cmdline)) { - APPEND_STR(cmdline); - if (cmdlineUsed) - *cmdlineUsed = 1; - } - else - BAIL_OUT; - break; - case 'R': - if (cmdline && !xf86pathIsAbsolute(cmdline)) { - APPEND_STR(cmdline); - if (cmdlineUsed) - *cmdlineUsed = 1; - } - else - BAIL_OUT; - break; - case 'S': - if (cmdline && xf86pathIsSafe(cmdline)) { - APPEND_STR(cmdline); - if (cmdlineUsed) - *cmdlineUsed = 1; - } - else - BAIL_OUT; - break; - case 'X': - APPEND_STR(XConfigFile); - break; - case 'H': - if (!hostname) { - if ((hostname = malloc(MAXHOSTNAMELEN + 1))) { - if (gethostname(hostname, MAXHOSTNAMELEN) == 0) { - hostname[MAXHOSTNAMELEN] = '\0'; - } - else { - free(hostname); - hostname = NULL; - } - } - } - if (hostname) - APPEND_STR(hostname); - break; - case 'E': - if (!env) - env = getenv(XCONFENV); - if (env && xf86pathIsAbsolute(env)) { - APPEND_STR(env); - if (envUsed) - *envUsed = 1; - } - else - BAIL_OUT; - break; - case 'F': - if (!env) - env = getenv(XCONFENV); - if (env && !xf86pathIsAbsolute(env)) { - APPEND_STR(env); - if (envUsed) - *envUsed = 1; - } - else - BAIL_OUT; - break; - case 'G': - if (!env) - env = getenv(XCONFENV); - if (env && xf86pathIsSafe(env)) { - APPEND_STR(env); - if (envUsed) - *envUsed = 1; - } - else - BAIL_OUT; - break; - case 'P': - if (projroot && xf86pathIsAbsolute(projroot)) - APPEND_STR(projroot); - else - BAIL_OUT; - break; - case 'C': - APPEND_STR(SYSCONFDIR); - break; - case 'D': - APPEND_STR(DATADIR); - break; - case '%': - result[l++] = '%'; - CHECK_LENGTH; - break; - default: - fprintf(stderr, "invalid escape %%%c found in path template\n", - template[i]); - BAIL_OUT; - break; - } - } - } -#ifdef DEBUG - fprintf(stderr, "Converted `%s' to `%s'\n", template, result); -#endif - return result; -} - -/* - * Given some searching parameters, locate and open the xorg config file. - */ -static char * -OpenConfigFile(const char *path, const char *cmdline, const char *projroot, - const char *confname) -{ - char *filepath = NULL; - char *pathcopy; - const char *template; - int cmdlineUsed = 0; - FILE *file = NULL; - - pathcopy = strdup(path); - for (template = strtok(pathcopy, ","); template && !file; - template = strtok(NULL, ",")) { - filepath = DoSubstitution(template, cmdline, projroot, - &cmdlineUsed, NULL, confname); - if (!filepath) - continue; - if (cmdline && !cmdlineUsed) { - free(filepath); - filepath = NULL; - continue; - } - file = fopen(filepath, "r"); - if (!file) { - free(filepath); - filepath = NULL; - } - } - - free(pathcopy); - if (file) { - configFiles[numFiles].file = file; - configFiles[numFiles].path = strdup(filepath); - numFiles++; - } - return filepath; -} - -/* - * Match non-hidden files in the xorg config directory with a .conf - * suffix. This filter is passed to scandir(3). - */ -static int -ConfigFilter(const struct dirent *de) -{ - const char *name = de->d_name; - size_t len; - size_t suflen = strlen(XCONFIGSUFFIX); - - if (!name || name[0] == '.') - return 0; - len = strlen(name); - if (len <= suflen) - return 0; - if (strcmp(&name[len - suflen], XCONFIGSUFFIX) != 0) - return 0; - return 1; -} - -static Bool -AddConfigDirFiles(const char *dirpath, struct dirent **list, int num) -{ - int i; - Bool openedFile = FALSE; - Bool warnOnce = FALSE; - - for (i = 0; i < num; i++) { - char *path; - FILE *file; - - if (numFiles >= CONFIG_MAX_FILES) { - if (!warnOnce) { - ErrorF("Maximum number of configuration " "files opened\n"); - warnOnce = TRUE; - } - continue; - } - - path = malloc(PATH_MAX + 1); - snprintf(path, PATH_MAX + 1, "%s/%s", dirpath, list[i]->d_name); - file = fopen(path, "r"); - if (!file) { - free(path); - continue; - } - openedFile = TRUE; - - configFiles[numFiles].file = file; - configFiles[numFiles].path = path; - numFiles++; - } - - return openedFile; -} - -/* - * Given some searching parameters, locate and open the xorg config - * directory. The directory does not need to contain config files. - */ -static char * -OpenConfigDir(const char *path, const char *cmdline, const char *projroot, - const char *confname) -{ - char *dirpath = NULL, *pathcopy; - const char *template; - Bool found = FALSE; - int cmdlineUsed = 0; - - pathcopy = strdup(path); - for (template = strtok(pathcopy, ","); template && !found; - template = strtok(NULL, ",")) { - struct dirent **list = NULL; - int num; - - dirpath = DoSubstitution(template, cmdline, projroot, - &cmdlineUsed, NULL, confname); - if (!dirpath) - continue; - if (cmdline && !cmdlineUsed) { - free(dirpath); - dirpath = NULL; - continue; - } - - /* match files named *.conf */ - num = scandir(dirpath, &list, ConfigFilter, alphasort); - if (num < 0) { - list = NULL; - num = 0; - } - found = AddConfigDirFiles(dirpath, list, num); - if (!found) { - free(dirpath); - dirpath = NULL; - } - while (num--) - free(list[num]); - free(list); - } - - free(pathcopy); - return dirpath; -} - -/* - * xf86initConfigFiles -- Setup global variables and buffers. - */ -void -xf86initConfigFiles(void) -{ - curFileIndex = 0; - configPos = 0; - configLineNo = 0; - pushToken = LOCK_TOKEN; - - configBuf = malloc(CONFIG_BUF_LEN); - configRBuf = malloc(CONFIG_BUF_LEN); - configBuf[0] = '\0'; /* sanity ... */ -} - -/* - * xf86openConfigFile -- - * - * This function take a config file search path (optional), a command-line - * specified file name (optional) and the ProjectRoot path (optional) and - * locates and opens a config file based on that information. If a - * command-line file name is specified, then this function fails if none - * of the located files. - * - * The return value is a pointer to the actual name of the file that was - * opened. When no file is found, the return value is NULL. The caller should - * free() the returned value. - * - * The escape sequences allowed in the search path are defined above. - * - */ - -#ifndef DEFAULT_CONF_PATH -#define DEFAULT_CONF_PATH "/etc/X11/%S," \ - "%P/etc/X11/%S," \ - "/etc/X11/%G," \ - "%P/etc/X11/%G," \ - "/etc/X11/%X-%M," \ - "/etc/X11/%X," \ - "/etc/%X," \ - "%P/etc/X11/%X.%H," \ - "%P/etc/X11/%X-%M," \ - "%P/etc/X11/%X," \ - "%P/lib/X11/%X.%H," \ - "%P/lib/X11/%X-%M," \ - "%P/lib/X11/%X" -#endif - -char * -xf86openConfigFile(const char *path, const char *cmdline, const char *projroot) -{ - if (!path || !path[0]) - path = DEFAULT_CONF_PATH; - if (!projroot || !projroot[0]) - projroot = PROJECTROOT; - - /* Search for a config file */ - return OpenConfigFile(path, cmdline, projroot, XCONFIGFILE); -} - -/* - * xf86openConfigDirFiles -- - * - * This function take a config directory search path (optional), a - * command-line specified directory name (optional) and the ProjectRoot path - * (optional) and locates and opens a config directory based on that - * information. If a command-line name is specified, then this function - * fails if it is not found. - * - * The return value is a pointer to the actual name of the directory that was - * opened. When no directory is found, the return value is NULL. The caller - * should free() the returned value. - * - * The escape sequences allowed in the search path are defined above. - * - */ -char * -xf86openConfigDirFiles(const char *path, const char *cmdline, - const char *projroot) -{ - if (!path || !path[0]) - path = DEFAULT_CONF_PATH; - if (!projroot || !projroot[0]) - projroot = PROJECTROOT; - - /* Search for the multiconf directory */ - return OpenConfigDir(path, cmdline, projroot, XCONFIGDIR); -} - -void -xf86closeConfigFile(void) -{ - int i; - - free(configRBuf); - configRBuf = NULL; - free(configBuf); - configBuf = NULL; - - if (numFiles == 0) { - builtinConfig = NULL; - builtinIndex = 0; - } - for (i = 0; i < numFiles; i++) { - fclose(configFiles[i].file); - configFiles[i].file = NULL; - free(configFiles[i].path); - configFiles[i].path = NULL; - } - numFiles = 0; -} - -void -xf86setBuiltinConfig(const char *config[]) -{ - builtinConfig = config; -} - -void -xf86parseError(const char *format, ...) -{ - va_list ap; - const char *filename = numFiles ? configFiles[curFileIndex].path - : ""; - - ErrorF("Parse error on line %d of section %s in file %s\n\t", - configLineNo, configSection, filename); - va_start(ap, format); - VErrorF(format, ap); - va_end(ap); - - ErrorF("\n"); -} - -void -xf86validationError(const char *format, ...) -{ - va_list ap; - const char *filename = numFiles ? configFiles[curFileIndex].path - : ""; - - ErrorF("Data incomplete in file %s\n\t", filename); - va_start(ap, format); - VErrorF(format, ap); - va_end(ap); - - ErrorF("\n"); -} - -void -xf86setSection(const char *section) -{ - free(configSection); - configSection = strdup(section); -} - -/* - * xf86getToken -- - * Lookup a string if it is actually a token in disguise. - */ -int -xf86getStringToken(const xf86ConfigSymTabRec * tab) -{ - return StringToToken(xf86_lex_val.str, tab); -} - -/* - * Compare two names. The characters '_', ' ', and '\t' are ignored - * in the comparison. - */ -int -xf86nameCompare(const char *s1, const char *s2) -{ - char c1, c2; - - if (!s1 || *s1 == 0) { - if (!s2 || *s2 == 0) - return 0; - else - return 1; - } else if (!s2 || *s2 == 0) { - return -1; - } - - while (*s1 == '_' || *s1 == ' ' || *s1 == '\t') - s1++; - while (*s2 == '_' || *s2 == ' ' || *s2 == '\t') - s2++; - c1 = (isupper(*s1) ? tolower(*s1) : *s1); - c2 = (isupper(*s2) ? tolower(*s2) : *s2); - while (c1 == c2) { - if (c1 == '\0') - return 0; - s1++; - s2++; - while (*s1 == '_' || *s1 == ' ' || *s1 == '\t') - s1++; - while (*s2 == '_' || *s2 == ' ' || *s2 == '\t') - s2++; - c1 = (isupper(*s1) ? tolower(*s1) : *s1); - c2 = (isupper(*s2) ? tolower(*s2) : *s2); - } - return c1 - c2; -} - -char * -xf86addComment(char *cur, const char *add) -{ - char *str; - const char *cstr; - int len, curlen, iscomment, hasnewline = 0, insnewline, endnewline; - - if (add == NULL || add[0] == '\0') - return cur; - - if (cur) { - curlen = strlen(cur); - if (curlen) - hasnewline = cur[curlen - 1] == '\n'; - eol_seen = 0; - } - else - curlen = 0; - - cstr = add; - iscomment = 0; - while (*cstr) { - if (*cstr != ' ' && *cstr != '\t') - break; - ++cstr; - } - iscomment = (*cstr == '#'); - - len = strlen(add); - endnewline = add[len - 1] == '\n'; - - insnewline = eol_seen || (curlen && !hasnewline); - if (insnewline) - len++; - if (!iscomment) - len++; - if (!endnewline) - len++; - - /* Allocate + 1 char for '\0' terminator. */ - str = realloc(cur, curlen + len + 1); - if (!str) - return cur; - - cur = str; - - if (insnewline) - cur[curlen++] = '\n'; - if (!iscomment) - cur[curlen++] = '#'; - strcpy(cur + curlen, add); - if (!endnewline) - strcat(cur, "\n"); - - return cur; -} - -Bool -xf86getBoolValue(Bool *val, const char *str) -{ - if (!val || !str) - return FALSE; - if (*str == '\0') { - *val = TRUE; - } - else { - if (xf86nameCompare(str, "1") == 0) - *val = TRUE; - else if (xf86nameCompare(str, "on") == 0) - *val = TRUE; - else if (xf86nameCompare(str, "true") == 0) - *val = TRUE; - else if (xf86nameCompare(str, "yes") == 0) - *val = TRUE; - else if (xf86nameCompare(str, "0") == 0) - *val = FALSE; - else if (xf86nameCompare(str, "off") == 0) - *val = FALSE; - else if (xf86nameCompare(str, "false") == 0) - *val = FALSE; - else if (xf86nameCompare(str, "no") == 0) - *val = FALSE; - else - return FALSE; - } - return TRUE; -} diff --git a/hw/xfree86/parser/write.c b/hw/xfree86/parser/write.c deleted file mode 100644 index 6e96ba053..000000000 --- a/hw/xfree86/parser/write.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "os.h" -#include "xf86Parser.h" -#include "xf86tokens.h" -#include "Configint.h" - -#include -#include -#include -#include - -#if defined(HAVE_SETEUID) && defined(_POSIX_SAVED_IDS) && _POSIX_SAVED_IDS > 0 -#define HAS_SAVED_IDS_AND_SETEUID -#endif -#if defined(WIN32) -#define HAS_NO_UIDS -#endif - -static int -doWriteConfigFile(const char *filename, XF86ConfigPtr cptr) -{ - FILE *cf; - - if ((cf = fopen(filename, "w")) == NULL) { - return 0; - } - - if (cptr->conf_comment) - fprintf(cf, "%s\n", cptr->conf_comment); - - xf86printLayoutSection(cf, cptr->conf_layout_lst); - - if (cptr->conf_files != NULL) { - fprintf(cf, "Section \"Files\"\n"); - xf86printFileSection(cf, cptr->conf_files); - fprintf(cf, "EndSection\n\n"); - } - - if (cptr->conf_modules != NULL) { - fprintf(cf, "Section \"Module\"\n"); - xf86printModuleSection(cf, cptr->conf_modules); - fprintf(cf, "EndSection\n\n"); - } - - xf86printVendorSection(cf, cptr->conf_vendor_lst); - - xf86printServerFlagsSection(cf, cptr->conf_flags); - - xf86printInputSection(cf, cptr->conf_input_lst); - - xf86printInputClassSection(cf, cptr->conf_inputclass_lst); - - xf86printOutputClassSection(cf, cptr->conf_outputclass_lst); - - xf86printVideoAdaptorSection(cf, cptr->conf_videoadaptor_lst); - - xf86printModesSection(cf, cptr->conf_modes_lst); - - xf86printMonitorSection(cf, cptr->conf_monitor_lst); - - xf86printDeviceSection(cf, cptr->conf_device_lst); - - xf86printScreenSection(cf, cptr->conf_screen_lst); - - xf86printDRISection(cf, cptr->conf_dri); - - xf86printExtensionsSection(cf, cptr->conf_extensions); - - fclose(cf); - return 1; -} - -int -xf86writeConfigFile(const char *filename, XF86ConfigPtr cptr) -{ -#ifndef HAS_NO_UIDS - int ret; - - if (getuid() != geteuid()) { - -#if !defined(HAS_SAVED_IDS_AND_SETEUID) - int pid, p; - int status; - void (*csig) (int); - - /* Need to fork to change ruid without losing euid */ - csig = OsSignal(SIGCHLD, SIG_DFL); - switch ((pid = fork())) { - case -1: - ErrorF("xf86writeConfigFile(): fork failed (%s)\n", - strerror(errno)); - return 0; - case 0: /* child */ - if (setuid(getuid()) == -1) - FatalError("xf86writeConfigFile(): " - "setuid failed(%s)\n", strerror(errno)); - ret = doWriteConfigFile(filename, cptr); - exit(ret); - break; - default: /* parent */ - do { - p = waitpid(pid, &status, 0); - } while (p == -1 && errno == EINTR); - } - OsSignal(SIGCHLD, csig); - if (p != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0) - return 1; /* success */ - else - return 0; - -#else /* HAS_SAVED_IDS_AND_SETEUID */ - int ruid, euid; - - ruid = getuid(); - euid = geteuid(); - - if (seteuid(ruid) == -1) { - ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n", - ruid, strerror(errno)); - return 0; - } - ret = doWriteConfigFile(filename, cptr); - - if (seteuid(euid) == -1) { - ErrorF("xf86writeConfigFile(): seteuid(%d) failed (%s)\n", - euid, strerror(errno)); - } - return ret; - -#endif /* HAS_SAVED_IDS_AND_SETEUID */ - - } - else -#endif /* !HAS_NO_UIDS */ - return doWriteConfigFile(filename, cptr); -} diff --git a/hw/xfree86/parser/xf86Optrec.h b/hw/xfree86/parser/xf86Optrec.h deleted file mode 100644 index dfa907989..000000000 --- a/hw/xfree86/parser/xf86Optrec.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2001 by The XFree86 Project, 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). - */ - -/* - * This file contains the Option Record that is passed between the Parser, - * and Module setup procs. - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _xf86Optrec_h_ -#define _xf86Optrec_h_ -#include -#include -#include "xf86Optionstr.h" - -#include - -extern _X_EXPORT XF86OptionPtr xf86addNewOption(XF86OptionPtr head, char *name, - char *val); -extern _X_EXPORT XF86OptionPtr xf86optionListDup(XF86OptionPtr opt); -extern _X_EXPORT void xf86optionListFree(XF86OptionPtr opt); -extern _X_EXPORT char *xf86optionName(XF86OptionPtr opt); -extern _X_EXPORT char *xf86optionValue(XF86OptionPtr opt); -extern _X_EXPORT XF86OptionPtr xf86newOption(char *name, char *value); -extern _X_EXPORT XF86OptionPtr xf86nextOption(XF86OptionPtr list); -extern _X_EXPORT XF86OptionPtr xf86findOption(XF86OptionPtr list, - const char *name); -extern _X_EXPORT const char *xf86findOptionValue(XF86OptionPtr list, - const char *name); -extern _X_EXPORT XF86OptionPtr xf86optionListCreate(const char **options, - int count, int used); -extern _X_EXPORT XF86OptionPtr xf86optionListMerge(XF86OptionPtr head, - XF86OptionPtr tail); -extern _X_EXPORT int xf86nameCompare(const char *s1, const char *s2); -extern _X_EXPORT char *xf86uLongToString(unsigned long i); -extern _X_EXPORT XF86OptionPtr xf86parseOption(XF86OptionPtr head); -extern _X_EXPORT void xf86printOptionList(FILE * fp, XF86OptionPtr list, - int tabs); - -#endif /* _xf86Optrec_h_ */ diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h deleted file mode 100644 index 6762edbe1..000000000 --- a/hw/xfree86/parser/xf86Parser.h +++ /dev/null @@ -1,488 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -/* - * This file contains the external interfaces for the XFree86 configuration - * file parser. - */ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _xf86Parser_h_ -#define _xf86Parser_h_ - -#include -#include "xf86Optrec.h" -#include "list.h" - -#define HAVE_PARSER_DECLS - -typedef struct { - char *file_logfile; - char *file_modulepath; - char *file_fontpath; - char *file_comment; - char *file_xkbdir; -} XF86ConfFilesRec, *XF86ConfFilesPtr; - -/* Values for load_type */ -#define XF86_LOAD_MODULE 0 -#define XF86_LOAD_DRIVER 1 -#define XF86_DISABLE_MODULE 2 - -typedef struct { - GenericListRec list; - int load_type; - const char *load_name; - XF86OptionPtr load_opt; - char *load_comment; - int ignore; -} XF86LoadRec, *XF86LoadPtr; - -typedef struct { - XF86LoadPtr mod_load_lst; - XF86LoadPtr mod_disable_lst; - char *mod_comment; -} XF86ConfModuleRec, *XF86ConfModulePtr; - -#define CONF_IMPLICIT_KEYBOARD "Implicit Core Keyboard" - -#define CONF_IMPLICIT_POINTER "Implicit Core Pointer" - -#define XF86CONF_PHSYNC 0x0001 -#define XF86CONF_NHSYNC 0x0002 -#define XF86CONF_PVSYNC 0x0004 -#define XF86CONF_NVSYNC 0x0008 -#define XF86CONF_INTERLACE 0x0010 -#define XF86CONF_DBLSCAN 0x0020 -#define XF86CONF_CSYNC 0x0040 -#define XF86CONF_PCSYNC 0x0080 -#define XF86CONF_NCSYNC 0x0100 -#define XF86CONF_HSKEW 0x0200 /* hskew provided */ -#define XF86CONF_BCAST 0x0400 -#define XF86CONF_VSCAN 0x1000 - -typedef struct { - GenericListRec list; - const char *ml_identifier; - int ml_clock; - int ml_hdisplay; - int ml_hsyncstart; - int ml_hsyncend; - int ml_htotal; - int ml_vdisplay; - int ml_vsyncstart; - int ml_vsyncend; - int ml_vtotal; - int ml_vscan; - int ml_flags; - int ml_hskew; - char *ml_comment; -} XF86ConfModeLineRec, *XF86ConfModeLinePtr; - -typedef struct { - GenericListRec list; - const char *vp_identifier; - XF86OptionPtr vp_option_lst; - char *vp_comment; -} XF86ConfVideoPortRec, *XF86ConfVideoPortPtr; - -typedef struct { - GenericListRec list; - const char *va_identifier; - const char *va_vendor; - const char *va_board; - const char *va_busid; - const char *va_driver; - XF86OptionPtr va_option_lst; - XF86ConfVideoPortPtr va_port_lst; - const char *va_fwdref; - char *va_comment; -} XF86ConfVideoAdaptorRec, *XF86ConfVideoAdaptorPtr; - -#define CONF_MAX_HSYNC 8 -#define CONF_MAX_VREFRESH 8 - -typedef struct { - float hi, lo; -} parser_range; - -typedef struct { - int red, green, blue; -} parser_rgb; - -typedef struct { - GenericListRec list; - const char *modes_identifier; - XF86ConfModeLinePtr mon_modeline_lst; - char *modes_comment; -} XF86ConfModesRec, *XF86ConfModesPtr; - -typedef struct { - GenericListRec list; - const char *ml_modes_str; - XF86ConfModesPtr ml_modes; -} XF86ConfModesLinkRec, *XF86ConfModesLinkPtr; - -typedef struct { - GenericListRec list; - const char *mon_identifier; - const char *mon_vendor; - char *mon_modelname; - int mon_width; /* in mm */ - int mon_height; /* in mm */ - XF86ConfModeLinePtr mon_modeline_lst; - int mon_n_hsync; - parser_range mon_hsync[CONF_MAX_HSYNC]; - int mon_n_vrefresh; - parser_range mon_vrefresh[CONF_MAX_VREFRESH]; - float mon_gamma_red; - float mon_gamma_green; - float mon_gamma_blue; - XF86OptionPtr mon_option_lst; - XF86ConfModesLinkPtr mon_modes_sect_lst; - char *mon_comment; -} XF86ConfMonitorRec, *XF86ConfMonitorPtr; - -#define CONF_MAXDACSPEEDS 4 -#define CONF_MAXCLOCKS 128 - -typedef struct { - GenericListRec list; - const char *dev_identifier; - const char *dev_vendor; - const char *dev_board; - const char *dev_chipset; - const char *dev_busid; - const char *dev_card; - const char *dev_driver; - const char *dev_ramdac; - int dev_dacSpeeds[CONF_MAXDACSPEEDS]; - int dev_videoram; - unsigned long dev_mem_base; - unsigned long dev_io_base; - const char *dev_clockchip; - int dev_clocks; - int dev_clock[CONF_MAXCLOCKS]; - int dev_chipid; - int dev_chiprev; - int dev_irq; - int dev_screen; - XF86OptionPtr dev_option_lst; - char *dev_comment; - char *match_seat; -} XF86ConfDeviceRec, *XF86ConfDevicePtr; - -typedef struct { - GenericListRec list; - const char *mode_name; -} XF86ModeRec, *XF86ModePtr; - -typedef struct { - GenericListRec list; - int disp_frameX0; - int disp_frameY0; - int disp_virtualX; - int disp_virtualY; - int disp_depth; - int disp_bpp; - const char *disp_visual; - parser_rgb disp_weight; - parser_rgb disp_black; - parser_rgb disp_white; - XF86ModePtr disp_mode_lst; - XF86OptionPtr disp_option_lst; - char *disp_comment; -} XF86ConfDisplayRec, *XF86ConfDisplayPtr; - -typedef struct { - XF86OptionPtr flg_option_lst; - char *flg_comment; -} XF86ConfFlagsRec, *XF86ConfFlagsPtr; - -typedef struct { - GenericListRec list; - const char *al_adaptor_str; - XF86ConfVideoAdaptorPtr al_adaptor; -} XF86ConfAdaptorLinkRec, *XF86ConfAdaptorLinkPtr; - -#define CONF_MAXGPUDEVICES 4 -typedef struct { - GenericListRec list; - const char *scrn_identifier; - const char *scrn_obso_driver; - int scrn_defaultdepth; - int scrn_defaultbpp; - int scrn_defaultfbbpp; - const char *scrn_monitor_str; - XF86ConfMonitorPtr scrn_monitor; - const char *scrn_device_str; - XF86ConfDevicePtr scrn_device; - XF86ConfAdaptorLinkPtr scrn_adaptor_lst; - XF86ConfDisplayPtr scrn_display_lst; - XF86OptionPtr scrn_option_lst; - char *scrn_comment; - int scrn_virtualX, scrn_virtualY; - char *match_seat; - - int num_gpu_devices; - const char *scrn_gpu_device_str[CONF_MAXGPUDEVICES]; - XF86ConfDevicePtr scrn_gpu_devices[CONF_MAXGPUDEVICES]; -} XF86ConfScreenRec, *XF86ConfScreenPtr; - -typedef struct { - GenericListRec list; - char *inp_identifier; - char *inp_driver; - XF86OptionPtr inp_option_lst; - char *inp_comment; -} XF86ConfInputRec, *XF86ConfInputPtr; - -typedef struct { - GenericListRec list; - XF86ConfInputPtr iref_inputdev; - char *iref_inputdev_str; - XF86OptionPtr iref_option_lst; -} XF86ConfInputrefRec, *XF86ConfInputrefPtr; - -typedef struct { - Bool set; - Bool val; -} xf86TriState; - -typedef struct { - struct xorg_list entry; - char **values; - Bool is_negated; -} xf86MatchGroup; - -typedef struct { - GenericListRec list; - char *identifier; - char *driver; - struct xorg_list match_product; - struct xorg_list match_vendor; - struct xorg_list match_device; - struct xorg_list match_os; - struct xorg_list match_pnpid; - struct xorg_list match_usbid; - struct xorg_list match_driver; - struct xorg_list match_tag; - struct xorg_list match_layout; - xf86TriState is_keyboard; - xf86TriState is_pointer; - xf86TriState is_joystick; - xf86TriState is_tablet; - xf86TriState is_tablet_pad; - xf86TriState is_touchpad; - xf86TriState is_touchscreen; - XF86OptionPtr option_lst; - char *comment; -} XF86ConfInputClassRec, *XF86ConfInputClassPtr; - -typedef struct { - GenericListRec list; - char *identifier; - char *driver; - char *modulepath; - struct xorg_list match_driver; - XF86OptionPtr option_lst; - char *comment; -} XF86ConfOutputClassRec, *XF86ConfOutputClassPtr; - -/* Values for adj_where */ -#define CONF_ADJ_OBSOLETE -1 -#define CONF_ADJ_ABSOLUTE 0 -#define CONF_ADJ_RIGHTOF 1 -#define CONF_ADJ_LEFTOF 2 -#define CONF_ADJ_ABOVE 3 -#define CONF_ADJ_BELOW 4 -#define CONF_ADJ_RELATIVE 5 - -typedef struct { - GenericListRec list; - int adj_scrnum; - XF86ConfScreenPtr adj_screen; - const char *adj_screen_str; - XF86ConfScreenPtr adj_top; - const char *adj_top_str; - XF86ConfScreenPtr adj_bottom; - const char *adj_bottom_str; - XF86ConfScreenPtr adj_left; - const char *adj_left_str; - XF86ConfScreenPtr adj_right; - const char *adj_right_str; - int adj_where; - int adj_x; - int adj_y; - const char *adj_refscreen; -} XF86ConfAdjacencyRec, *XF86ConfAdjacencyPtr; - -typedef struct { - GenericListRec list; - const char *inactive_device_str; - XF86ConfDevicePtr inactive_device; -} XF86ConfInactiveRec, *XF86ConfInactivePtr; - -typedef struct { - GenericListRec list; - const char *lay_identifier; - XF86ConfAdjacencyPtr lay_adjacency_lst; - XF86ConfInactivePtr lay_inactive_lst; - XF86ConfInputrefPtr lay_input_lst; - XF86OptionPtr lay_option_lst; - char *match_seat; - char *lay_comment; -} XF86ConfLayoutRec, *XF86ConfLayoutPtr; - -typedef struct { - GenericListRec list; - const char *vs_name; - const char *vs_identifier; - XF86OptionPtr vs_option_lst; - char *vs_comment; -} XF86ConfVendSubRec, *XF86ConfVendSubPtr; - -typedef struct { - GenericListRec list; - const char *vnd_identifier; - XF86OptionPtr vnd_option_lst; - XF86ConfVendSubPtr vnd_sub_lst; - char *vnd_comment; -} XF86ConfVendorRec, *XF86ConfVendorPtr; - -typedef struct { - const char *dri_group_name; - int dri_group; - int dri_mode; - char *dri_comment; -} XF86ConfDRIRec, *XF86ConfDRIPtr; - -typedef struct { - XF86OptionPtr ext_option_lst; - char *extensions_comment; -} XF86ConfExtensionsRec, *XF86ConfExtensionsPtr; - -typedef struct { - XF86ConfFilesPtr conf_files; - XF86ConfModulePtr conf_modules; - XF86ConfFlagsPtr conf_flags; - XF86ConfVideoAdaptorPtr conf_videoadaptor_lst; - XF86ConfModesPtr conf_modes_lst; - XF86ConfMonitorPtr conf_monitor_lst; - XF86ConfDevicePtr conf_device_lst; - XF86ConfScreenPtr conf_screen_lst; - XF86ConfInputPtr conf_input_lst; - XF86ConfInputClassPtr conf_inputclass_lst; - XF86ConfOutputClassPtr conf_outputclass_lst; - XF86ConfLayoutPtr conf_layout_lst; - XF86ConfVendorPtr conf_vendor_lst; - XF86ConfDRIPtr conf_dri; - XF86ConfExtensionsPtr conf_extensions; - char *conf_comment; -} XF86ConfigRec, *XF86ConfigPtr; - -typedef struct { - int token; /* id of the token */ - const char *name; /* pointer to the LOWERCASED name */ -} xf86ConfigSymTabRec, *xf86ConfigSymTabPtr; - -/* - * prototypes for public functions - */ -extern void xf86initConfigFiles(void); -extern char *xf86openConfigFile(const char *path, const char *cmdline, - const char *projroot); -extern char *xf86openConfigDirFiles(const char *path, const char *cmdline, - const char *projroot); -extern void xf86setBuiltinConfig(const char *config[]); -extern XF86ConfigPtr xf86readConfigFile(void); -extern void xf86closeConfigFile(void); -extern XF86ConfigPtr xf86allocateConfig(void); -extern void xf86freeConfig(XF86ConfigPtr p); -extern int xf86writeConfigFile(const char *, XF86ConfigPtr); -extern _X_EXPORT XF86ConfDevicePtr xf86findDevice(const char *ident, - XF86ConfDevicePtr p); -extern _X_EXPORT XF86ConfLayoutPtr xf86findLayout(const char *name, - XF86ConfLayoutPtr list); -extern _X_EXPORT XF86ConfMonitorPtr xf86findMonitor(const char *ident, - XF86ConfMonitorPtr p); -extern _X_EXPORT XF86ConfModesPtr xf86findModes(const char *ident, - XF86ConfModesPtr p); -extern _X_EXPORT XF86ConfModeLinePtr xf86findModeLine(const char *ident, - XF86ConfModeLinePtr p); -extern _X_EXPORT XF86ConfScreenPtr xf86findScreen(const char *ident, - XF86ConfScreenPtr p); -extern _X_EXPORT XF86ConfInputPtr xf86findInput(const char *ident, - XF86ConfInputPtr p); -extern _X_EXPORT XF86ConfInputPtr xf86findInputByDriver(const char *driver, - XF86ConfInputPtr p); -extern _X_EXPORT XF86ConfVideoAdaptorPtr xf86findVideoAdaptor(const char *ident, - XF86ConfVideoAdaptorPtr - p); -extern int xf86layoutAddInputDevices(XF86ConfigPtr config, - XF86ConfLayoutPtr layout); - -extern _X_EXPORT GenericListPtr xf86addListItem(GenericListPtr head, - GenericListPtr c_new); -extern _X_EXPORT int xf86itemNotSublist(GenericListPtr list_1, - GenericListPtr list_2); - -extern _X_EXPORT int xf86pathIsAbsolute(const char *path); -extern _X_EXPORT int xf86pathIsSafe(const char *path); -extern _X_EXPORT char *xf86addComment(char *cur, const char *add); -extern _X_EXPORT Bool xf86getBoolValue(Bool *val, const char *str); - -#endif /* _xf86Parser_h_ */ diff --git a/hw/xfree86/parser/xf86tokens.h b/hw/xfree86/parser/xf86tokens.h deleted file mode 100644 index 4abff0d79..000000000 --- a/hw/xfree86/parser/xf86tokens.h +++ /dev/null @@ -1,302 +0,0 @@ -/* - * - * Copyright (c) 1997 Metro Link Incorporated - * - * 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 X CONSORTIUM 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 Metro Link shall not be - * used in advertising or otherwise to promote the sale, use or other dealings - * in this Software without prior written authorization from Metro Link. - * - */ -/* - * Copyright (c) 1997-2003 by The XFree86 Project, 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). - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _xf86_tokens_h -#define _xf86_tokens_h - -/* Undefine symbols that some OSs might define */ -#undef IOBASE - -/* - * Each token should have a unique value regardless of the section - * it is used in. - */ - -typedef enum { - /* errno-style tokens */ - OBSOLETE_TOKEN = -5, - EOF_TOKEN = -4, - LOCK_TOKEN = -3, - ERROR_TOKEN = -2, - - /* value type tokens */ - NUMBER = 1, - STRING, - - /* Tokens that can appear in many sections */ - SECTION, - SUBSECTION, - ENDSECTION, - ENDSUBSECTION, - IDENTIFIER, - VENDOR, - DASH, - COMMA, - MATCHSEAT, - OPTION, - COMMENT, - - /* Frequency units */ - HRZ, - KHZ, - MHZ, - - /* File tokens */ - FONTPATH, - MODULEPATH, - LOGFILEPATH, - XKBDIR, - - /* Server Flag tokens. These are deprecated in favour of generic Options */ - DONTZAP, - DONTZOOM, - DISABLEVIDMODE, - ALLOWNONLOCAL, - DISABLEMODINDEV, - MODINDEVALLOWNONLOCAL, - ALLOWMOUSEOPENFAIL, - BLANKTIME, - STANDBYTIME, - SUSPENDTIME, - OFFTIME, - DEFAULTLAYOUT, - - /* Monitor tokens */ - MODEL, - MODELINE, - DISPLAYSIZE, - HORIZSYNC, - VERTREFRESH, - MODE, - GAMMA, - USEMODES, - - /* Modes tokens */ - /* no new ones */ - - /* Mode tokens */ - DOTCLOCK, - HTIMINGS, - VTIMINGS, - FLAGS, - HSKEW, - BCAST, - VSCAN, - ENDMODE, - - /* Screen tokens */ - OBSDRIVER, - MDEVICE, - GDEVICE, - MONITOR, - SCREENNO, - DEFAULTDEPTH, - DEFAULTBPP, - DEFAULTFBBPP, - - /* VideoAdaptor tokens */ - VIDEOADAPTOR, - - /* Mode timing tokens */ - TT_INTERLACE, - TT_PHSYNC, - TT_NHSYNC, - TT_PVSYNC, - TT_NVSYNC, - TT_CSYNC, - TT_PCSYNC, - TT_NCSYNC, - TT_DBLSCAN, - TT_HSKEW, - TT_BCAST, - TT_VSCAN, - - /* Module tokens */ - LOAD, - LOAD_DRIVER, - DISABLE, - - /* Device tokens */ - DRIVER, - CHIPSET, - CLOCKS, - VIDEORAM, - BOARD, - IOBASE, - RAMDAC, - DACSPEED, - BIOSBASE, - MEMBASE, - CLOCKCHIP, - CHIPID, - CHIPREV, - CARD, - BUSID, - IRQ, - - /* Keyboard tokens */ - AUTOREPEAT, - XLEDS, - KPROTOCOL, - XKBKEYMAP, - XKBCOMPAT, - XKBTYPES, - XKBKEYCODES, - XKBGEOMETRY, - XKBSYMBOLS, - XKBDISABLE, - PANIX106, - XKBRULES, - XKBMODEL, - XKBLAYOUT, - XKBVARIANT, - XKBOPTIONS, - /* Obsolete keyboard tokens */ - SERVERNUM, - LEFTALT, - RIGHTALT, - SCROLLLOCK_TOK, - RIGHTCTL, - /* arguments for the above obsolete tokens */ - CONF_KM_META, - CONF_KM_COMPOSE, - CONF_KM_MODESHIFT, - CONF_KM_MODELOCK, - CONF_KM_SCROLLLOCK, - CONF_KM_CONTROL, - - /* Pointer tokens */ - EMULATE3, - BAUDRATE, - SAMPLERATE, - PRESOLUTION, - CLEARDTR, - CLEARRTS, - CHORDMIDDLE, - PROTOCOL, - PDEVICE, - EM3TIMEOUT, - DEVICE_NAME, - ALWAYSCORE, - PBUTTONS, - ZAXISMAPPING, - - /* Pointer Z axis mapping tokens */ - XAXIS, - YAXIS, - - /* Display tokens */ - MODES, - VIEWPORT, - VIRTUAL, - VISUAL, - BLACK_TOK, - WHITE_TOK, - DEPTH, - BPP, - WEIGHT, - - /* Layout Tokens */ - SCREEN, - INACTIVE, - INPUTDEVICE, - - /* Adjaceny Tokens */ - RIGHTOF, - LEFTOF, - ABOVE, - BELOW, - RELATIVE, - ABSOLUTE, - - /* Vendor Tokens */ - VENDORNAME, - - /* DRI Tokens */ - GROUP, - - /* InputClass Tokens */ - MATCH_PRODUCT, - MATCH_VENDOR, - MATCH_DEVICE_PATH, - MATCH_OS, - MATCH_PNPID, - MATCH_USBID, - MATCH_DRIVER, - MATCH_TAG, - MATCH_LAYOUT, - MATCH_IS_KEYBOARD, - MATCH_IS_POINTER, - MATCH_IS_JOYSTICK, - MATCH_IS_TABLET, - MATCH_IS_TABLET_PAD, - MATCH_IS_TOUCHPAD, - MATCH_IS_TOUCHSCREEN, - - NOMATCH_PRODUCT, - NOMATCH_VENDOR, - NOMATCH_DEVICE_PATH, - NOMATCH_OS, - NOMATCH_PNPID, - NOMATCH_USBID, - NOMATCH_DRIVER, - NOMATCH_TAG, - NOMATCH_LAYOUT, -} ParserTokens; - -#endif /* _xf86_tokens_h */ diff --git a/hw/xfree86/ramdac/CURSOR.NOTES b/hw/xfree86/ramdac/CURSOR.NOTES deleted file mode 100644 index 3be79a1e2..000000000 --- a/hw/xfree86/ramdac/CURSOR.NOTES +++ /dev/null @@ -1,191 +0,0 @@ - CURSOR.NOTES - - This file describes how to add hardware cursor support to a chipset -driver. Though the cursor support itself is in the ramdac module, -cursor management is separate from the rest of the module. - - -1) CURSOR INITIALIZATION AND SHUTDOWN - - All relevant prototypes and defines are in xf86Cursor.h. - - To initialize the cursor, the driver should allocate an -xf86CursorInfoRec via xf86CreateCursorInfoRec(), fill it out as described -later in this document and pass it to xf86InitCursor(). xf86InitCursor() -must be called _after_ the software cursor initialization (usually -miDCInitialize). - - When shutting down, the driver should free the xf86CursorInfoRec -structure in its CloseScreen function via xf86DestroyCursorInfoRec(). - - -2) FILLING OUT THE xf86CursorInfoRec - - The driver informs the ramdac module of its hardware cursor capabilities by -filling out an xf86CursorInfoRec structure and passing it to xf86InitCursor(). -The xf86CursorInfoRec contains the following function pointers: - - -/**** These functions are required ****/ - -void ShowCursor(ScrnInfoPtr pScrn) - - ShowCursor should display the current cursor. - -void HideCursor(ScrnInfoPtr pScrn) - - HideCursor should hide the current cursor. - -void SetCursorPosition(ScrnInfoPtr pScrn, int x, int y) - - Set the cursor position to (x,y). X and/or y may be negative - indicating that the cursor image is partially offscreen on - the left and/or top edges of the screen. It is up to the - driver to trap for this and deal with that situation. - -void SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) - - Set the cursor foreground and background colors. In 8bpp, fg and - bg are indices into the current colormap unless the - HARDWARE_CURSOR_TRUECOLOR_AT_8BPP flag is set. In that case - and in all other bpps the fg and bg are in 8-8-8 RGB format. - -void LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *bits) - - LoadCursorImage is how the hardware cursor bits computed by the - RealizeCursor function will be passed to the driver when the cursor - shape needs to be changed. - - -/**** These functions are optional ****/ - - -unsigned char* RealizeCursor(xf86CursorInfoPtr infoPtr, CursorPtr pCurs) - - If RealizeCursor is not provided by the driver, one will be provided - for you based on the Flags field described below. The driver must - provide this function if the hardware cursor format is not one of - the common ones supported by this module. - - -Bool UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs) - - If the driver is unable to use a hardware cursor for reasons - other than the cursor being larger than the maximum specified - in the MaxWidth or MaxHeight field below, it can supply the - UseHWCursor function. If UseHWCursor is provided by the driver, - it will be called whenever the cursor shape changes or the video - mode changes. This is useful for when the hardware cursor cannot - be used in interlaced or doublescan modes. - - -/**** The following fields are required ****/ - -MaxWidth -MaxHeight - - These indicate the largest sized cursor that can be a hardware - cursor. It will fall back to a software cursor when a cursor - exceeding this size needs to be used. - - -Flags - - /* Color related flags */ - - HARDWARE_CURSOR_TRUECOLOR_AT_8BPP - - This indicates that the colors passed to the SetCursorColors - function should not be in 8-8-8 RGB format in 8bpp but rather, - they should be the pixel values from the current colormap. - - - /* Cursor data loading flags */ - - HARDWARE_CURSOR_SHOW_TRANSPARENT - - The HideCursor entry will normally be called instead of displaying a - completely transparent cursor, or when a switch to a software cursor - needs to occur. This flag prevents this behaviour, thus causing the - LoadCursorImage entry to be called with transparent cursor data. - NOTE: If you use this flag and provide your own RealizeCursor() entry, - ensure this entry returns transparent cursor data when called - with a NULL pCurs parameter. - - HARDWARE_CURSOR_UPDATE_UNHIDDEN - - This flag prevents the HideCursor call that would normally occur just before - the LoadCursorImage entry is to be called to load a new hardware cursor - image. - - - /* Cursor data packing flags */ - - Hardware cursor data consists of two pieces, a source and a mask. - The mask is a bitmap indicating which parts of the cursor are - transparent and which parts are drawn. The source is a bitmap - indicating which parts of the non-transparent portion of the the - cursor should be painted in the foreground color and which should - be painted in the background color. - - HARDWARE_CURSOR_INVERT_MASK - - By default, set bits indicate the opaque part of the mask bitmap - and clear bits indicate the transparent part. If your hardware - wants this the opposite way, this flag will invert the mask. - - HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK - - By default, RealizeCursor will store the source first and then - the mask. If the hardware needs this order reversed then this - flag should be set. - - HARDWARE_CURSOR_AND_SOURCE_WITH_MASK - - This flag will have the module logical AND the source with the mask to make - sure there are no source bits set if the corresponding mask bits - aren't set. Some hardware will not care if source bits are set where - there are supposed to be transparent areas, but some hardware will - interpret this as a third cursor color or similar. That type of - hardware will need this flag set. - - HARDWARE_CURSOR_BIT_ORDER_MSBFIRST - - By default, it is assumed that the least significant bit in each byte - corresponds to the leftmost pixel on the screen. If your hardware - has this reversed you should set this flag. - - HARDWARE_CURSOR_NIBBLE_SWAPPED - - If your hardware requires byte swapping of the hardware cursor, enable - this option. - - - /* Source-Mask interleaving flags */ - - By default the source and mask data are inlined (source first unless - the HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK flag is set). Some hardware - will require the source and mask to be interleaved, that is, X number - of source bits should packed and then X number of mask bits repeating - until the entire pattern is stored. The following flags describe the - bit interleave. - - HARDWARE_CURSOR_SOURCE_MASK_NOT_INTERLEAVED - - This one is the default. - - The following are for interleaved cursors. - - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8 - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16 - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32 - HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 - - And once again, if your hardware requires something different than - these packing styles, your driver can supply its own RealizeCursor - function. - - - -$XFree86: xc/programs/Xserver/hw/xfree86/ramdac/CURSOR.NOTES,v 1.4tsi Exp $ diff --git a/hw/xfree86/ramdac/meson.build b/hw/xfree86/ramdac/meson.build deleted file mode 100644 index 0a2bb4b79..000000000 --- a/hw/xfree86/ramdac/meson.build +++ /dev/null @@ -1,18 +0,0 @@ -srcs_xorg_ramdac = [ - 'xf86CursorRD.c', - 'xf86HWCurs.c', -] - -xorg_ramdac = static_library('xorg_ramdac', - srcs_xorg_ramdac, - include_directories: [inc, xorg_inc], - dependencies: common_dep, - c_args: xorg_c_args, -) - -install_data( - [ - 'xf86Cursor.h', - ], - install_dir: xorgsdkdir, -) diff --git a/hw/xfree86/ramdac/xf86Cursor.h b/hw/xfree86/ramdac/xf86Cursor.h deleted file mode 100644 index 11a03b67b..000000000 --- a/hw/xfree86/ramdac/xf86Cursor.h +++ /dev/null @@ -1,98 +0,0 @@ - -#ifndef _XF86CURSOR_H -#define _XF86CURSOR_H - -#include "xf86str.h" -#include "mipointer.h" - -typedef struct _xf86CursorInfoRec { - ScrnInfoPtr pScrn; - int Flags; - int MaxWidth; - int MaxHeight; - void (*SetCursorColors) (ScrnInfoPtr pScrn, int bg, int fg); - void (*SetCursorPosition) (ScrnInfoPtr pScrn, int x, int y); - void (*LoadCursorImage) (ScrnInfoPtr pScrn, unsigned char *bits); - Bool (*LoadCursorImageCheck) (ScrnInfoPtr pScrn, unsigned char *bits); - void (*HideCursor) (ScrnInfoPtr pScrn); - void (*ShowCursor) (ScrnInfoPtr pScrn); - Bool (*ShowCursorCheck) (ScrnInfoPtr pScrn); - unsigned char *(*RealizeCursor) (struct _xf86CursorInfoRec *, CursorPtr); - Bool (*UseHWCursor) (ScreenPtr, CursorPtr); - - Bool (*UseHWCursorARGB) (ScreenPtr, CursorPtr); - void (*LoadCursorARGB) (ScrnInfoPtr, CursorPtr); - Bool (*LoadCursorARGBCheck) (ScrnInfoPtr, CursorPtr); - -} xf86CursorInfoRec, *xf86CursorInfoPtr; - -static inline Bool -xf86DriverHasLoadCursorImage(xf86CursorInfoPtr infoPtr) -{ - return infoPtr->LoadCursorImageCheck || infoPtr->LoadCursorImage; -} - -static inline Bool -xf86DriverLoadCursorImage(xf86CursorInfoPtr infoPtr, unsigned char *bits) -{ - if(infoPtr->LoadCursorImageCheck) - return infoPtr->LoadCursorImageCheck(infoPtr->pScrn, bits); - infoPtr->LoadCursorImage(infoPtr->pScrn, bits); - return TRUE; -} - -static inline Bool -xf86DriverHasShowCursor(xf86CursorInfoPtr infoPtr) -{ - return infoPtr->ShowCursorCheck || infoPtr->ShowCursor; -} - -static inline Bool -xf86DriverShowCursor(xf86CursorInfoPtr infoPtr) -{ - if(infoPtr->ShowCursorCheck) - return infoPtr->ShowCursorCheck(infoPtr->pScrn); - infoPtr->ShowCursor(infoPtr->pScrn); - return TRUE; -} - -static inline Bool -xf86DriverHasLoadCursorARGB(xf86CursorInfoPtr infoPtr) -{ - return infoPtr->LoadCursorARGBCheck || infoPtr->LoadCursorARGB; -} - -static inline Bool -xf86DriverLoadCursorARGB(xf86CursorInfoPtr infoPtr, CursorPtr pCursor) -{ - if(infoPtr->LoadCursorARGBCheck) - return infoPtr->LoadCursorARGBCheck(infoPtr->pScrn, pCursor); - infoPtr->LoadCursorARGB(infoPtr->pScrn, pCursor); - return TRUE; -} - -extern _X_EXPORT Bool xf86InitCursor(ScreenPtr pScreen, - xf86CursorInfoPtr infoPtr); -extern _X_EXPORT xf86CursorInfoPtr xf86CreateCursorInfoRec(void); -extern _X_EXPORT void xf86DestroyCursorInfoRec(xf86CursorInfoPtr); -extern _X_EXPORT void xf86CursorResetCursor(ScreenPtr pScreen); -extern _X_EXPORT void xf86ForceHWCursor(ScreenPtr pScreen, Bool on); -extern _X_EXPORT CursorPtr xf86CurrentCursor(ScreenPtr pScreen); - -#define HARDWARE_CURSOR_INVERT_MASK 0x00000001 -#define HARDWARE_CURSOR_AND_SOURCE_WITH_MASK 0x00000002 -#define HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK 0x00000004 -#define HARDWARE_CURSOR_SOURCE_MASK_NOT_INTERLEAVED 0x00000008 -#define HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 0x00000010 -#define HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8 0x00000020 -#define HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16 0x00000040 -#define HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32 0x00000080 -#define HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 0x00000100 -#define HARDWARE_CURSOR_TRUECOLOR_AT_8BPP 0x00000200 -#define HARDWARE_CURSOR_BIT_ORDER_MSBFIRST 0x00000400 -#define HARDWARE_CURSOR_NIBBLE_SWAPPED 0x00000800 -#define HARDWARE_CURSOR_SHOW_TRANSPARENT 0x00001000 -#define HARDWARE_CURSOR_UPDATE_UNHIDDEN 0x00002000 -#define HARDWARE_CURSOR_ARGB 0x00004000 - -#endif /* _XF86CURSOR_H */ diff --git a/hw/xfree86/ramdac/xf86CursorPriv.h b/hw/xfree86/ramdac/xf86CursorPriv.h deleted file mode 100644 index 397d2a14b..000000000 --- a/hw/xfree86/ramdac/xf86CursorPriv.h +++ /dev/null @@ -1,51 +0,0 @@ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#ifndef _XF86CURSORPRIV_H -#define _XF86CURSORPRIV_H - -#include "xf86Cursor.h" -#include "mipointrst.h" - -typedef struct { - Bool SWCursor; - Bool isUp; - Bool showTransparent; - short HotX; - short HotY; - short x; - short y; - CursorPtr CurrentCursor, CursorToRestore; - xf86CursorInfoPtr CursorInfoPtr; - CloseScreenProcPtr CloseScreen; - RecolorCursorProcPtr RecolorCursor; - InstallColormapProcPtr InstallColormap; - QueryBestSizeProcPtr QueryBestSize; - miPointerSpriteFuncPtr spriteFuncs; - Bool PalettedCursor; - ColormapPtr pInstalledMap; - Bool (*SwitchMode) (ScrnInfoPtr, DisplayModePtr); - xf86EnableDisableFBAccessProc *EnableDisableFBAccess; - CursorPtr SavedCursor; - - /* Number of requests to force HW cursor */ - int ForceHWCursorCount; - Bool HWCursorForced; - - void *transparentData; -} xf86CursorScreenRec, *xf86CursorScreenPtr; - -Bool xf86SetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y); -void xf86SetTransparentCursor(ScreenPtr pScreen); -void xf86MoveCursor(ScreenPtr pScreen, int x, int y); -void xf86RecolorCursor(ScreenPtr pScreen, CursorPtr pCurs, Bool displayed); -Bool xf86InitHardwareCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr); - -Bool xf86CheckHWCursor(ScreenPtr pScreen, CursorPtr cursor, xf86CursorInfoPtr infoPtr); -extern _X_EXPORT DevPrivateKeyRec xf86CursorScreenKeyRec; - -#define xf86CursorScreenKey (&xf86CursorScreenKeyRec) - -#endif /* _XF86CURSORPRIV_H */ diff --git a/hw/xfree86/ramdac/xf86CursorRD.c b/hw/xfree86/ramdac/xf86CursorRD.c deleted file mode 100644 index c8362d169..000000000 --- a/hw/xfree86/ramdac/xf86CursorRD.c +++ /dev/null @@ -1,515 +0,0 @@ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86.h" -#include "xf86CursorPriv.h" -#include "colormapst.h" -#include "cursorstr.h" - -/* FIXME: This was added with the ABI change of the miPointerSpriteFuncs for - * MPX. - * inputInfo is needed to pass the core pointer as the default argument into - * the cursor functions. - * - * Externing inputInfo is not the nice way to do it but it works. - */ -#include "inputstr.h" - -DevPrivateKeyRec xf86CursorScreenKeyRec; - -/* sprite functions */ - -static Bool xf86CursorRealizeCursor(DeviceIntPtr, ScreenPtr, CursorPtr); -static Bool xf86CursorUnrealizeCursor(DeviceIntPtr, ScreenPtr, CursorPtr); -static void xf86CursorSetCursor(DeviceIntPtr, ScreenPtr, CursorPtr, int, int); -static void xf86CursorMoveCursor(DeviceIntPtr, ScreenPtr, int, int); -static Bool xf86DeviceCursorInitialize(DeviceIntPtr, ScreenPtr); -static void xf86DeviceCursorCleanup(DeviceIntPtr, ScreenPtr); - -static miPointerSpriteFuncRec xf86CursorSpriteFuncs = { - xf86CursorRealizeCursor, - xf86CursorUnrealizeCursor, - xf86CursorSetCursor, - xf86CursorMoveCursor, - xf86DeviceCursorInitialize, - xf86DeviceCursorCleanup -}; - -/* Screen functions */ - -static void xf86CursorInstallColormap(ColormapPtr); -static void xf86CursorRecolorCursor(DeviceIntPtr pDev, ScreenPtr, CursorPtr, - Bool); -static Bool xf86CursorCloseScreen(ScreenPtr); -static void xf86CursorQueryBestSize(int, unsigned short *, unsigned short *, - ScreenPtr); - -/* ScrnInfoRec functions */ - -static void xf86CursorEnableDisableFBAccess(ScrnInfoPtr, Bool); -static Bool xf86CursorSwitchMode(ScrnInfoPtr, DisplayModePtr); - -Bool -xf86InitCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - xf86CursorScreenPtr ScreenPriv; - miPointerScreenPtr PointPriv; - - if (!xf86InitHardwareCursor(pScreen, infoPtr)) - return FALSE; - - if (!dixRegisterPrivateKey(&xf86CursorScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - ScreenPriv = calloc(1, sizeof(xf86CursorScreenRec)); - if (!ScreenPriv) - return FALSE; - - dixSetPrivate(&pScreen->devPrivates, xf86CursorScreenKey, ScreenPriv); - - ScreenPriv->SWCursor = TRUE; - ScreenPriv->isUp = FALSE; - ScreenPriv->CurrentCursor = NULL; - ScreenPriv->CursorInfoPtr = infoPtr; - ScreenPriv->PalettedCursor = FALSE; - ScreenPriv->pInstalledMap = NULL; - - ScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = xf86CursorCloseScreen; - ScreenPriv->QueryBestSize = pScreen->QueryBestSize; - pScreen->QueryBestSize = xf86CursorQueryBestSize; - ScreenPriv->RecolorCursor = pScreen->RecolorCursor; - pScreen->RecolorCursor = xf86CursorRecolorCursor; - - if ((infoPtr->pScrn->bitsPerPixel == 8) && - !(infoPtr->Flags & HARDWARE_CURSOR_TRUECOLOR_AT_8BPP)) { - ScreenPriv->InstallColormap = pScreen->InstallColormap; - pScreen->InstallColormap = xf86CursorInstallColormap; - ScreenPriv->PalettedCursor = TRUE; - } - - PointPriv = dixLookupPrivate(&pScreen->devPrivates, miPointerScreenKey); - - ScreenPriv->showTransparent = PointPriv->showTransparent; - if (infoPtr->Flags & HARDWARE_CURSOR_SHOW_TRANSPARENT) - PointPriv->showTransparent = TRUE; - else - PointPriv->showTransparent = FALSE; - ScreenPriv->spriteFuncs = PointPriv->spriteFuncs; - PointPriv->spriteFuncs = &xf86CursorSpriteFuncs; - - ScreenPriv->EnableDisableFBAccess = pScrn->EnableDisableFBAccess; - ScreenPriv->SwitchMode = pScrn->SwitchMode; - - ScreenPriv->ForceHWCursorCount = 0; - ScreenPriv->HWCursorForced = FALSE; - - pScrn->EnableDisableFBAccess = xf86CursorEnableDisableFBAccess; - if (pScrn->SwitchMode) - pScrn->SwitchMode = xf86CursorSwitchMode; - - return TRUE; -} - -/***** Screen functions *****/ - -static Bool -xf86CursorCloseScreen(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - miPointerScreenPtr PointPriv = - (miPointerScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - miPointerScreenKey); - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - if (ScreenPriv->isUp && pScrn->vtSema) - xf86SetCursor(pScreen, NullCursor, ScreenPriv->x, ScreenPriv->y); - - if (ScreenPriv->CurrentCursor) - FreeCursor(ScreenPriv->CurrentCursor, None); - - pScreen->CloseScreen = ScreenPriv->CloseScreen; - pScreen->QueryBestSize = ScreenPriv->QueryBestSize; - pScreen->RecolorCursor = ScreenPriv->RecolorCursor; - if (ScreenPriv->InstallColormap) - pScreen->InstallColormap = ScreenPriv->InstallColormap; - - PointPriv->spriteFuncs = ScreenPriv->spriteFuncs; - PointPriv->showTransparent = ScreenPriv->showTransparent; - - pScrn->EnableDisableFBAccess = ScreenPriv->EnableDisableFBAccess; - pScrn->SwitchMode = ScreenPriv->SwitchMode; - - free(ScreenPriv->transparentData); - free(ScreenPriv); - - return (*pScreen->CloseScreen) (pScreen); -} - -static void -xf86CursorQueryBestSize(int class, - unsigned short *width, - unsigned short *height, ScreenPtr pScreen) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - if (class == CursorShape) { - if (*width > ScreenPriv->CursorInfoPtr->MaxWidth) - *width = ScreenPriv->CursorInfoPtr->MaxWidth; - if (*height > ScreenPriv->CursorInfoPtr->MaxHeight) - *height = ScreenPriv->CursorInfoPtr->MaxHeight; - } - else - (*ScreenPriv->QueryBestSize) (class, width, height, pScreen); -} - -static void -xf86CursorInstallColormap(ColormapPtr pMap) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pMap->pScreen->devPrivates, - xf86CursorScreenKey); - - ScreenPriv->pInstalledMap = pMap; - - (*ScreenPriv->InstallColormap) (pMap); -} - -static void -xf86CursorRecolorCursor(DeviceIntPtr pDev, - ScreenPtr pScreen, CursorPtr pCurs, Bool displayed) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - if (!displayed) - return; - - if (ScreenPriv->SWCursor) - (*ScreenPriv->RecolorCursor) (pDev, pScreen, pCurs, displayed); - else - xf86RecolorCursor(pScreen, pCurs, displayed); -} - -/***** ScrnInfoRec functions *********/ - -static void -xf86CursorEnableDisableFBAccess(ScrnInfoPtr pScrn, Bool enable) -{ - DeviceIntPtr pDev = inputInfo.pointer; - - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - if (!enable && ScreenPriv->CurrentCursor != NullCursor) { - CursorPtr currentCursor = RefCursor(ScreenPriv->CurrentCursor); - - xf86CursorSetCursor(pDev, pScreen, NullCursor, ScreenPriv->x, - ScreenPriv->y); - ScreenPriv->isUp = FALSE; - ScreenPriv->SWCursor = TRUE; - ScreenPriv->SavedCursor = currentCursor; - } - - if (ScreenPriv->EnableDisableFBAccess) - (*ScreenPriv->EnableDisableFBAccess) (pScrn, enable); - - if (enable && ScreenPriv->SavedCursor) { - /* - * Re-set current cursor so drivers can react to FB access having been - * temporarily disabled. - */ - xf86CursorSetCursor(pDev, pScreen, ScreenPriv->SavedCursor, - ScreenPriv->x, ScreenPriv->y); - UnrefCursor(ScreenPriv->SavedCursor); - ScreenPriv->SavedCursor = NULL; - } -} - -static Bool -xf86CursorSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode) -{ - Bool ret; - ScreenPtr pScreen = xf86ScrnToScreen(pScrn); - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - if (ScreenPriv->isUp) { - xf86SetCursor(pScreen, NullCursor, ScreenPriv->x, ScreenPriv->y); - ScreenPriv->isUp = FALSE; - } - - ret = (*ScreenPriv->SwitchMode) (pScrn, mode); - - /* - * Cannot restore cursor here because the new frame[XY][01] haven't been - * calculated yet. However, because the hardware cursor was removed above, - * ensure the cursor is repainted by miPointerWarpCursor(). - */ - ScreenPriv->CursorToRestore = ScreenPriv->CurrentCursor; - miPointerSetWaitForUpdate(pScreen, FALSE); /* Force cursor repaint */ - - return ret; -} - -/****** miPointerSpriteFunctions *******/ - -static Bool -xf86CursorRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCurs) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - if (CursorRefCount(pCurs) <= 1) - dixSetScreenPrivate(&pCurs->devPrivates, CursorScreenKey, pScreen, - NULL); - - return (*ScreenPriv->spriteFuncs->RealizeCursor) (pDev, pScreen, pCurs); -} - -static Bool -xf86CursorUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCurs) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - if (CursorRefCount(pCurs) <= 1) { - free(dixLookupScreenPrivate - (&pCurs->devPrivates, CursorScreenKey, pScreen)); - dixSetScreenPrivate(&pCurs->devPrivates, CursorScreenKey, pScreen, - NULL); - } - - return (*ScreenPriv->spriteFuncs->UnrealizeCursor) (pDev, pScreen, pCurs); -} - -static void -xf86CursorSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCurs, - int x, int y) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr; - - if (pCurs == NullCursor) { /* means we're supposed to remove the cursor */ - if (ScreenPriv->SWCursor || - !(GetMaster(pDev, MASTER_POINTER) == inputInfo.pointer)) - (*ScreenPriv->spriteFuncs->SetCursor) (pDev, pScreen, NullCursor, x, - y); - else if (ScreenPriv->isUp) { - xf86SetCursor(pScreen, NullCursor, x, y); - ScreenPriv->isUp = FALSE; - } - if (ScreenPriv->CurrentCursor) - FreeCursor(ScreenPriv->CurrentCursor, None); - ScreenPriv->CurrentCursor = NullCursor; - return; - } - - /* only update for VCP, otherwise we get cursor jumps when removing a - sprite. The second cursor is never HW rendered anyway. */ - if (GetMaster(pDev, MASTER_POINTER) == inputInfo.pointer) { - CursorPtr cursor = RefCursor(pCurs); - if (ScreenPriv->CurrentCursor) - FreeCursor(ScreenPriv->CurrentCursor, None); - ScreenPriv->CurrentCursor = cursor; - ScreenPriv->x = x; - ScreenPriv->y = y; - ScreenPriv->CursorToRestore = NULL; - ScreenPriv->HotX = cursor->bits->xhot; - ScreenPriv->HotY = cursor->bits->yhot; - - if (!infoPtr->pScrn->vtSema) { - cursor = RefCursor(cursor); - if (ScreenPriv->SavedCursor) - FreeCursor(ScreenPriv->SavedCursor, None); - ScreenPriv->SavedCursor = cursor; - return; - } - - if (infoPtr->pScrn->vtSema && - (ScreenPriv->ForceHWCursorCount || - xf86CheckHWCursor(pScreen, cursor, infoPtr))) { - - if (ScreenPriv->SWCursor) /* remove the SW cursor */ - (*ScreenPriv->spriteFuncs->SetCursor) (pDev, pScreen, - NullCursor, x, y); - - if (xf86SetCursor(pScreen, cursor, x, y)) { - ScreenPriv->SWCursor = FALSE; - ScreenPriv->isUp = TRUE; - - miPointerSetWaitForUpdate(pScreen, !infoPtr->pScrn->silkenMouse); - return; - } - } - - miPointerSetWaitForUpdate(pScreen, TRUE); - - if (ScreenPriv->isUp) { - /* Remove the HW cursor, or make it transparent */ - if (infoPtr->Flags & HARDWARE_CURSOR_SHOW_TRANSPARENT) { - xf86SetTransparentCursor(pScreen); - } - else { - xf86SetCursor(pScreen, NullCursor, x, y); - ScreenPriv->isUp = FALSE; - } - } - - if (!ScreenPriv->SWCursor) - ScreenPriv->SWCursor = TRUE; - - } - - if (pCurs->bits->emptyMask && !ScreenPriv->showTransparent) - pCurs = NullCursor; - - (*ScreenPriv->spriteFuncs->SetCursor) (pDev, pScreen, pCurs, x, y); -} - -/* Re-set the current cursor. This will switch between hardware and software - * cursor depending on whether hardware cursor is currently supported - * according to the driver. - */ -void -xf86CursorResetCursor(ScreenPtr pScreen) -{ - xf86CursorScreenPtr ScreenPriv; - - if (!inputInfo.pointer) - return; - - if (!dixPrivateKeyRegistered(xf86CursorScreenKey)) - return; - - ScreenPriv = (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - if (!ScreenPriv) - return; - - xf86CursorSetCursor(inputInfo.pointer, pScreen, ScreenPriv->CurrentCursor, - ScreenPriv->x, ScreenPriv->y); -} - -static void -xf86CursorMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - /* only update coordinate state for first sprite, otherwise we get jumps - when removing a sprite. The second sprite is never HW rendered anyway */ - if (GetMaster(pDev, MASTER_POINTER) == inputInfo.pointer) { - ScreenPriv->x = x; - ScreenPriv->y = y; - - if (ScreenPriv->CursorToRestore) - xf86CursorSetCursor(pDev, pScreen, ScreenPriv->CursorToRestore, x, - y); - else if (ScreenPriv->SWCursor) - (*ScreenPriv->spriteFuncs->MoveCursor) (pDev, pScreen, x, y); - else if (ScreenPriv->isUp) - xf86MoveCursor(pScreen, x, y); - } - else - (*ScreenPriv->spriteFuncs->MoveCursor) (pDev, pScreen, x, y); -} - -void -xf86ForceHWCursor(ScreenPtr pScreen, Bool on) -{ - DeviceIntPtr pDev = inputInfo.pointer; - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - if (on) { - if (ScreenPriv->ForceHWCursorCount++ == 0) { - if (ScreenPriv->SWCursor && ScreenPriv->CurrentCursor) { - ScreenPriv->HWCursorForced = TRUE; - xf86CursorSetCursor(pDev, pScreen, ScreenPriv->CurrentCursor, - ScreenPriv->x, ScreenPriv->y); - } - else - ScreenPriv->HWCursorForced = FALSE; - } - } - else { - if (--ScreenPriv->ForceHWCursorCount == 0) { - if (ScreenPriv->HWCursorForced && ScreenPriv->CurrentCursor) - xf86CursorSetCursor(pDev, pScreen, ScreenPriv->CurrentCursor, - ScreenPriv->x, ScreenPriv->y); - } - } -} - -CursorPtr -xf86CurrentCursor(ScreenPtr pScreen) -{ - xf86CursorScreenPtr ScreenPriv; - - if (pScreen->is_output_secondary) - pScreen = pScreen->current_primary; - - ScreenPriv = dixLookupPrivate(&pScreen->devPrivates, xf86CursorScreenKey); - return ScreenPriv->CurrentCursor; -} - -xf86CursorInfoPtr -xf86CreateCursorInfoRec(void) -{ - return calloc(1, sizeof(xf86CursorInfoRec)); -} - -void -xf86DestroyCursorInfoRec(xf86CursorInfoPtr infoPtr) -{ - free(infoPtr); -} - -/** - * New cursor has been created. Do your initalizations here. - */ -static Bool -xf86DeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen) -{ - int ret; - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - /* Init SW cursor */ - ret = (*ScreenPriv->spriteFuncs->DeviceCursorInitialize) (pDev, pScreen); - - return ret; -} - -/** - * Cursor has been removed. Clean up after yourself. - */ -static void -xf86DeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - /* Clean up SW cursor */ - (*ScreenPriv->spriteFuncs->DeviceCursorCleanup) (pDev, pScreen); -} diff --git a/hw/xfree86/ramdac/xf86HWCurs.c b/hw/xfree86/ramdac/xf86HWCurs.c deleted file mode 100644 index ddba5e6c6..000000000 --- a/hw/xfree86/ramdac/xf86HWCurs.c +++ /dev/null @@ -1,695 +0,0 @@ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include - -#include "misc.h" -#include "xf86.h" -#include "xf86_OSproc.h" - -#include -#include "scrnintstr.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "xf86str.h" -#include "cursorstr.h" -#include "mi.h" -#include "mipointer.h" -#include "randrstr.h" -#include "xf86CursorPriv.h" - -#include "servermd.h" - -static void -xf86RecolorCursor_locked(xf86CursorScreenPtr ScreenPriv, CursorPtr pCurs); - -static CARD32 -xf86ReverseBitOrder(CARD32 v) -{ - return (((0x01010101 & v) << 7) | ((0x02020202 & v) << 5) | - ((0x04040404 & v) << 3) | ((0x08080808 & v) << 1) | - ((0x10101010 & v) >> 1) | ((0x20202020 & v) >> 3) | - ((0x40404040 & v) >> 5) | ((0x80808080 & v) >> 7)); -} - -#if BITMAP_SCANLINE_PAD == 64 - -#if 1 -/* Cursors might be only 32 wide. Give'em a chance */ -#define SCANLINE CARD32 -#define CUR_BITMAP_SCANLINE_PAD 32 -#define CUR_LOG2_BITMAP_PAD 5 -#define REVERSE_BIT_ORDER(w) xf86ReverseBitOrder(w) -#else -#define SCANLINE CARD64 -#define CUR_BITMAP_SCANLINE_PAD BITMAP_SCANLINE_PAD -#define CUR_LOG2_BITMAP_PAD LOG2_BITMAP_PAD -#define REVERSE_BIT_ORDER(w) xf86CARD64ReverseBits(w) -static CARD64 xf86CARD64ReverseBits(CARD64 w); - -static CARD64 -xf86CARD64ReverseBits(CARD64 w) -{ - unsigned char *p = (unsigned char *) &w; - - p[0] = byte_reversed[p[0]]; - p[1] = byte_reversed[p[1]]; - p[2] = byte_reversed[p[2]]; - p[3] = byte_reversed[p[3]]; - p[4] = byte_reversed[p[4]]; - p[5] = byte_reversed[p[5]]; - p[6] = byte_reversed[p[6]]; - p[7] = byte_reversed[p[7]]; - - return w; -} -#endif - -#else - -#define SCANLINE CARD32 -#define CUR_BITMAP_SCANLINE_PAD BITMAP_SCANLINE_PAD -#define CUR_LOG2_BITMAP_PAD LOG2_BITMAP_PAD -#define REVERSE_BIT_ORDER(w) xf86ReverseBitOrder(w) - -#endif /* BITMAP_SCANLINE_PAD == 64 */ - -static unsigned char *RealizeCursorInterleave0(xf86CursorInfoPtr, CursorPtr); -static unsigned char *RealizeCursorInterleave1(xf86CursorInfoPtr, CursorPtr); -static unsigned char *RealizeCursorInterleave8(xf86CursorInfoPtr, CursorPtr); -static unsigned char *RealizeCursorInterleave16(xf86CursorInfoPtr, CursorPtr); -static unsigned char *RealizeCursorInterleave32(xf86CursorInfoPtr, CursorPtr); -static unsigned char *RealizeCursorInterleave64(xf86CursorInfoPtr, CursorPtr); - -Bool -xf86InitHardwareCursor(ScreenPtr pScreen, xf86CursorInfoPtr infoPtr) -{ - if ((infoPtr->MaxWidth <= 0) || (infoPtr->MaxHeight <= 0)) - return FALSE; - - /* These are required for now */ - if (!infoPtr->SetCursorPosition || - !xf86DriverHasLoadCursorImage(infoPtr) || - !infoPtr->HideCursor || - !xf86DriverHasShowCursor(infoPtr) || - !infoPtr->SetCursorColors) - return FALSE; - - if (infoPtr->RealizeCursor) { - /* Don't overwrite a driver provided Realize Cursor function */ - } - else if (HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1 & infoPtr->Flags) { - infoPtr->RealizeCursor = RealizeCursorInterleave1; - } - else if (HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8 & infoPtr->Flags) { - infoPtr->RealizeCursor = RealizeCursorInterleave8; - } - else if (HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16 & infoPtr->Flags) { - infoPtr->RealizeCursor = RealizeCursorInterleave16; - } - else if (HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32 & infoPtr->Flags) { - infoPtr->RealizeCursor = RealizeCursorInterleave32; - } - else if (HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 & infoPtr->Flags) { - infoPtr->RealizeCursor = RealizeCursorInterleave64; - } - else { /* not interleaved */ - infoPtr->RealizeCursor = RealizeCursorInterleave0; - } - - infoPtr->pScrn = xf86ScreenToScrn(pScreen); - - return TRUE; -} - -static Bool -xf86ScreenCheckHWCursor(ScreenPtr pScreen, CursorPtr cursor, xf86CursorInfoPtr infoPtr) -{ - return - (cursor->bits->argb && infoPtr->UseHWCursorARGB && - infoPtr->UseHWCursorARGB(pScreen, cursor)) || - (cursor->bits->argb == 0 && - cursor->bits->height <= infoPtr->MaxHeight && - cursor->bits->width <= infoPtr->MaxWidth && - (!infoPtr->UseHWCursor || infoPtr->UseHWCursor(pScreen, cursor))); -} - -Bool -xf86CheckHWCursor(ScreenPtr pScreen, CursorPtr cursor, xf86CursorInfoPtr infoPtr) -{ - ScreenPtr pSlave; - Bool use_hw_cursor = TRUE; - - input_lock(); - - if (!xf86ScreenCheckHWCursor(pScreen, cursor, infoPtr)) { - use_hw_cursor = FALSE; - goto unlock; - } - - /* ask each driver consuming a pixmap if it can support HW cursor */ - xorg_list_for_each_entry(pSlave, &pScreen->secondary_list, secondary_head) { - xf86CursorScreenPtr sPriv; - - if (!RRHasScanoutPixmap(pSlave)) - continue; - - sPriv = dixLookupPrivate(&pSlave->devPrivates, xf86CursorScreenKey); - if (!sPriv) { /* NULL if Option "SWCursor", possibly other conditions */ - use_hw_cursor = FALSE; - break; - } - - /* FALSE if HWCursor not supported by secondary */ - if (!xf86ScreenCheckHWCursor(pSlave, cursor, sPriv->CursorInfoPtr)) { - use_hw_cursor = FALSE; - break; - } - } - -unlock: - input_unlock(); - - return use_hw_cursor; -} - -static Bool -xf86ScreenSetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - xf86CursorInfoPtr infoPtr; - unsigned char *bits; - - if (!ScreenPriv) { /* NULL if Option "SWCursor" */ - return (pCurs == NullCursor); - } - - infoPtr = ScreenPriv->CursorInfoPtr; - - if (pCurs == NullCursor) { - (*infoPtr->HideCursor) (infoPtr->pScrn); - return TRUE; - } - - /* - * Hot plugged GPU's do not have a CursorScreenKey, force sw cursor. - * This check can be removed once dix/privates.c gets relocation code for - * PRIVATE_CURSOR. Also see the related comment in AddGPUScreen(). - */ - if (!_dixGetScreenPrivateKey(CursorScreenKey, pScreen)) - return FALSE; - - bits = - dixLookupScreenPrivate(&pCurs->devPrivates, CursorScreenKey, pScreen); - - x -= infoPtr->pScrn->frameX0; - y -= infoPtr->pScrn->frameY0; - - if (!pCurs->bits->argb || !xf86DriverHasLoadCursorARGB(infoPtr)) - if (!bits) { - bits = (*infoPtr->RealizeCursor) (infoPtr, pCurs); - dixSetScreenPrivate(&pCurs->devPrivates, CursorScreenKey, pScreen, - bits); - } - - if (!(infoPtr->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN)) - (*infoPtr->HideCursor) (infoPtr->pScrn); - - if (pCurs->bits->argb && xf86DriverHasLoadCursorARGB(infoPtr)) { - if (!xf86DriverLoadCursorARGB (infoPtr, pCurs)) - return FALSE; - } else - if (bits) - if (!xf86DriverLoadCursorImage (infoPtr, bits)) - return FALSE; - - xf86RecolorCursor_locked (ScreenPriv, pCurs); - - (*infoPtr->SetCursorPosition) (infoPtr->pScrn, x, y); - - return xf86DriverShowCursor(infoPtr); -} - -Bool -xf86SetCursor(ScreenPtr pScreen, CursorPtr pCurs, int x, int y) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - ScreenPtr pSlave; - Bool ret = FALSE; - - input_lock(); - - x -= ScreenPriv->HotX; - y -= ScreenPriv->HotY; - - if (!xf86ScreenSetCursor(pScreen, pCurs, x, y)) - goto out; - - /* ask each secondary driver to set the cursor. */ - xorg_list_for_each_entry(pSlave, &pScreen->secondary_list, secondary_head) { - if (!RRHasScanoutPixmap(pSlave)) - continue; - - if (!xf86ScreenSetCursor(pSlave, pCurs, x, y)) { - /* - * hide the primary (and successfully set secondary) cursors, - * otherwise both the hw and sw cursor will show. - */ - xf86SetCursor(pScreen, NullCursor, x, y); - goto out; - } - } - ret = TRUE; - - out: - input_unlock(); - return ret; -} - -void -xf86SetTransparentCursor(ScreenPtr pScreen) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr; - - input_lock(); - - if (!ScreenPriv->transparentData) - ScreenPriv->transparentData = - (*infoPtr->RealizeCursor) (infoPtr, NullCursor); - - if (!(infoPtr->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN)) - (*infoPtr->HideCursor) (infoPtr->pScrn); - - if (ScreenPriv->transparentData) - xf86DriverLoadCursorImage (infoPtr, - ScreenPriv->transparentData); - - xf86DriverShowCursor(infoPtr); - - input_unlock(); -} - -static void -xf86ScreenMoveCursor(ScreenPtr pScreen, int x, int y) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr; - - x -= infoPtr->pScrn->frameX0; - y -= infoPtr->pScrn->frameY0; - - (*infoPtr->SetCursorPosition) (infoPtr->pScrn, x, y); -} - -void -xf86MoveCursor(ScreenPtr pScreen, int x, int y) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - ScreenPtr pSlave; - - input_lock(); - - x -= ScreenPriv->HotX; - y -= ScreenPriv->HotY; - - xf86ScreenMoveCursor(pScreen, x, y); - - /* ask each secondary driver to move the cursor */ - xorg_list_for_each_entry(pSlave, &pScreen->secondary_list, secondary_head) { - if (!RRHasScanoutPixmap(pSlave)) - continue; - - xf86ScreenMoveCursor(pSlave, x, y); - } - - input_unlock(); -} - -static void -xf86RecolorCursor_locked(xf86CursorScreenPtr ScreenPriv, CursorPtr pCurs) -{ - xf86CursorInfoPtr infoPtr = ScreenPriv->CursorInfoPtr; - - /* recoloring isn't applicable to ARGB cursors and drivers - shouldn't have to ignore SetCursorColors requests */ - if (pCurs->bits->argb) - return; - - if (ScreenPriv->PalettedCursor) { - xColorItem sourceColor, maskColor; - ColormapPtr pmap = ScreenPriv->pInstalledMap; - - if (!pmap) - return; - - sourceColor.red = pCurs->foreRed; - sourceColor.green = pCurs->foreGreen; - sourceColor.blue = pCurs->foreBlue; - FakeAllocColor(pmap, &sourceColor); - maskColor.red = pCurs->backRed; - maskColor.green = pCurs->backGreen; - maskColor.blue = pCurs->backBlue; - FakeAllocColor(pmap, &maskColor); - FakeFreeColor(pmap, sourceColor.pixel); - FakeFreeColor(pmap, maskColor.pixel); - (*infoPtr->SetCursorColors) (infoPtr->pScrn, - maskColor.pixel, sourceColor.pixel); - } - else { /* Pass colors in 8-8-8 RGB format */ - (*infoPtr->SetCursorColors) (infoPtr->pScrn, - (pCurs->backBlue >> 8) | - ((pCurs->backGreen >> 8) << 8) | - ((pCurs->backRed >> 8) << 16), - (pCurs->foreBlue >> 8) | - ((pCurs->foreGreen >> 8) << 8) | - ((pCurs->foreRed >> 8) << 16) - ); - } -} - -void -xf86RecolorCursor(ScreenPtr pScreen, CursorPtr pCurs, Bool displayed) -{ - xf86CursorScreenPtr ScreenPriv = - (xf86CursorScreenPtr) dixLookupPrivate(&pScreen->devPrivates, - xf86CursorScreenKey); - - input_lock(); - xf86RecolorCursor_locked (ScreenPriv, pCurs); - input_unlock(); -} - -/* These functions assume that MaxWidth is a multiple of 32 */ -static unsigned char * -RealizeCursorInterleave0(xf86CursorInfoPtr infoPtr, CursorPtr pCurs) -{ - - SCANLINE *SrcS, *SrcM, *DstS, *DstM; - SCANLINE *pSrc, *pMsk; - unsigned char *mem; - int size = (infoPtr->MaxWidth * infoPtr->MaxHeight) >> 2; - int SrcPitch, DstPitch, Pitch, y, x; - - /* how many words are in the source or mask */ - int words = size / (CUR_BITMAP_SCANLINE_PAD / 4); - - if (!(mem = calloc(1, size))) - return NULL; - - if (pCurs == NullCursor) { - if (infoPtr->Flags & HARDWARE_CURSOR_INVERT_MASK) { - DstM = (SCANLINE *) mem; - if (!(infoPtr->Flags & HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK)) - DstM += words; - memset(DstM, -1, words * sizeof(SCANLINE)); - } - return mem; - } - - /* SrcPitch == the number of scanlines wide the cursor image is */ - SrcPitch = (pCurs->bits->width + (BITMAP_SCANLINE_PAD - 1)) >> - CUR_LOG2_BITMAP_PAD; - - /* DstPitch is the width of the hw cursor in scanlines */ - DstPitch = infoPtr->MaxWidth >> CUR_LOG2_BITMAP_PAD; - Pitch = SrcPitch < DstPitch ? SrcPitch : DstPitch; - - SrcS = (SCANLINE *) pCurs->bits->source; - SrcM = (SCANLINE *) pCurs->bits->mask; - DstS = (SCANLINE *) mem; - DstM = DstS + words; - - if (infoPtr->Flags & HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK) { - SCANLINE *tmp; - - tmp = DstS; - DstS = DstM; - DstM = tmp; - } - - if (infoPtr->Flags & HARDWARE_CURSOR_AND_SOURCE_WITH_MASK) { - for (y = pCurs->bits->height, pSrc = DstS, pMsk = DstM; - y--; - pSrc += DstPitch, pMsk += DstPitch, SrcS += SrcPitch, SrcM += - SrcPitch) { - for (x = 0; x < Pitch; x++) { - pSrc[x] = SrcS[x] & SrcM[x]; - pMsk[x] = SrcM[x]; - } - } - } - else { - for (y = pCurs->bits->height, pSrc = DstS, pMsk = DstM; - y--; - pSrc += DstPitch, pMsk += DstPitch, SrcS += SrcPitch, SrcM += - SrcPitch) { - for (x = 0; x < Pitch; x++) { - pSrc[x] = SrcS[x]; - pMsk[x] = SrcM[x]; - } - } - } - - if (infoPtr->Flags & HARDWARE_CURSOR_NIBBLE_SWAPPED) { - int count = size; - unsigned char *pntr1 = (unsigned char *) DstS; - unsigned char *pntr2 = (unsigned char *) DstM; - unsigned char a, b; - - while (count) { - - a = *pntr1; - b = *pntr2; - *pntr1 = ((a & 0xF0) >> 4) | ((a & 0x0F) << 4); - *pntr2 = ((b & 0xF0) >> 4) | ((b & 0x0F) << 4); - pntr1++; - pntr2++; - count -= 2; - } - } - - /* - * Must be _after_ HARDWARE_CURSOR_AND_SOURCE_WITH_MASK to avoid wiping - * out entire source mask. - */ - if (infoPtr->Flags & HARDWARE_CURSOR_INVERT_MASK) { - int count = words; - SCANLINE *pntr = DstM; - - while (count--) { - *pntr = ~(*pntr); - pntr++; - } - } - - if (infoPtr->Flags & HARDWARE_CURSOR_BIT_ORDER_MSBFIRST) { - for (y = pCurs->bits->height, pSrc = DstS, pMsk = DstM; - y--; pSrc += DstPitch, pMsk += DstPitch) { - for (x = 0; x < Pitch; x++) { - pSrc[x] = REVERSE_BIT_ORDER(pSrc[x]); - pMsk[x] = REVERSE_BIT_ORDER(pMsk[x]); - } - } - } - - return mem; -} - -static unsigned char * -RealizeCursorInterleave1(xf86CursorInfoPtr infoPtr, CursorPtr pCurs) -{ - unsigned char *DstS, *DstM; - unsigned char *pntr; - unsigned char *mem, *mem2; - int count; - int size = (infoPtr->MaxWidth * infoPtr->MaxHeight) >> 2; - - /* Realize the cursor without interleaving */ - if (!(mem2 = RealizeCursorInterleave0(infoPtr, pCurs))) - return NULL; - - if (!(mem = calloc(1, size))) { - free(mem2); - return NULL; - } - - /* 1 bit interleave */ - DstS = mem2; - DstM = DstS + (size >> 1); - pntr = mem; - count = size; - while (count) { - *pntr++ = ((*DstS & 0x01)) | ((*DstM & 0x01) << 1) | - ((*DstS & 0x02) << 1) | ((*DstM & 0x02) << 2) | - ((*DstS & 0x04) << 2) | ((*DstM & 0x04) << 3) | - ((*DstS & 0x08) << 3) | ((*DstM & 0x08) << 4); - *pntr++ = ((*DstS & 0x10) >> 4) | ((*DstM & 0x10) >> 3) | - ((*DstS & 0x20) >> 3) | ((*DstM & 0x20) >> 2) | - ((*DstS & 0x40) >> 2) | ((*DstM & 0x40) >> 1) | - ((*DstS & 0x80) >> 1) | ((*DstM & 0x80)); - DstS++; - DstM++; - count -= 2; - } - - /* Free the uninterleaved cursor */ - free(mem2); - - return mem; -} - -static unsigned char * -RealizeCursorInterleave8(xf86CursorInfoPtr infoPtr, CursorPtr pCurs) -{ - unsigned char *DstS, *DstM; - unsigned char *pntr; - unsigned char *mem, *mem2; - int count; - int size = (infoPtr->MaxWidth * infoPtr->MaxHeight) >> 2; - - /* Realize the cursor without interleaving */ - if (!(mem2 = RealizeCursorInterleave0(infoPtr, pCurs))) - return NULL; - - if (!(mem = calloc(1, size))) { - free(mem2); - return NULL; - } - - /* 8 bit interleave */ - DstS = mem2; - DstM = DstS + (size >> 1); - pntr = mem; - count = size; - while (count) { - *pntr++ = *DstS++; - *pntr++ = *DstM++; - count -= 2; - } - - /* Free the uninterleaved cursor */ - free(mem2); - - return mem; -} - -static unsigned char * -RealizeCursorInterleave16(xf86CursorInfoPtr infoPtr, CursorPtr pCurs) -{ - unsigned short *DstS, *DstM; - unsigned short *pntr; - unsigned char *mem, *mem2; - int count; - int size = (infoPtr->MaxWidth * infoPtr->MaxHeight) >> 2; - - /* Realize the cursor without interleaving */ - if (!(mem2 = RealizeCursorInterleave0(infoPtr, pCurs))) - return NULL; - - if (!(mem = calloc(1, size))) { - free(mem2); - return NULL; - } - - /* 16 bit interleave */ - DstS = (void *) mem2; - DstM = DstS + (size >> 2); - pntr = (void *) mem; - count = (size >> 1); - while (count) { - *pntr++ = *DstS++; - *pntr++ = *DstM++; - count -= 2; - } - - /* Free the uninterleaved cursor */ - free(mem2); - - return mem; -} - -static unsigned char * -RealizeCursorInterleave32(xf86CursorInfoPtr infoPtr, CursorPtr pCurs) -{ - CARD32 *DstS, *DstM; - CARD32 *pntr; - unsigned char *mem, *mem2; - int count; - int size = (infoPtr->MaxWidth * infoPtr->MaxHeight) >> 2; - - /* Realize the cursor without interleaving */ - if (!(mem2 = RealizeCursorInterleave0(infoPtr, pCurs))) - return NULL; - - if (!(mem = calloc(1, size))) { - free(mem2); - return NULL; - } - - /* 32 bit interleave */ - DstS = (void *) mem2; - DstM = DstS + (size >> 3); - pntr = (void *) mem; - count = (size >> 2); - while (count) { - *pntr++ = *DstS++; - *pntr++ = *DstM++; - count -= 2; - } - - /* Free the uninterleaved cursor */ - free(mem2); - - return mem; -} - -static unsigned char * -RealizeCursorInterleave64(xf86CursorInfoPtr infoPtr, CursorPtr pCurs) -{ - CARD32 *DstS, *DstM; - CARD32 *pntr; - unsigned char *mem, *mem2; - int count; - int size = (infoPtr->MaxWidth * infoPtr->MaxHeight) >> 2; - - /* Realize the cursor without interleaving */ - if (!(mem2 = RealizeCursorInterleave0(infoPtr, pCurs))) - return NULL; - - if (!(mem = calloc(1, size))) { - free(mem2); - return NULL; - } - - /* 64 bit interleave */ - DstS = (void *) mem2; - DstM = DstS + (size >> 3); - pntr = (void *) mem; - count = (size >> 2); - while (count) { - *pntr++ = *DstS++; - *pntr++ = *DstS++; - *pntr++ = *DstM++; - *pntr++ = *DstM++; - count -= 4; - } - - /* Free the uninterleaved cursor */ - free(mem2); - - return mem; -} diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh deleted file mode 100755 index 5fd5b5c2f..000000000 --- a/hw/xfree86/sdksyms.sh +++ /dev/null @@ -1,444 +0,0 @@ -#!/bin/sh - -cat > sdksyms.c << EOF -/* This file is automatically generated by sdksyms.sh. */ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - - -/* These must be included first */ -#include "misc.h" -#include "miscstruct.h" - - -/* render/Makefile.am */ -#include "picture.h" -#include "mipict.h" -#include "glyphstr.h" -#include "picturestr.h" - - -/* fb/Makefile.am */ -#include "fb.h" -#include "fbrop.h" -#include "fboverlay.h" -#include "fbpict.h" -/* wfb is still a module -#include "wfbrename.h" - */ - - -/* miext/shadow/Makefile.am -- module */ -/* -#include "shadow.h" - */ - - -/* miext/damage/Makefile.am */ -#include "damage.h" -#include "damagestr.h" - -/* miext/sync/Makefile.am */ -#include "misync.h" -#include "misyncstr.h" -#if HAVE_XSHMFENCE -#include "misyncshm.h" -#endif - -/* Xext/Makefile.am -- half is module, half is builtin */ -#ifdef XV -#include "xvdix.h" -#include "xvmcext.h" -#endif -#include "geext.h" -#ifdef MITSHM -#include "shmint.h" -#endif -#include "syncsdk.h" -#ifdef XINERAMA -# include "panoramiXsrv.h" -# include "panoramiX.h" -#endif - -/* glx/Makefile.am */ -#ifdef GLX -#include "vndserver.h" -#endif - -/* hw/xfree86/int10/Makefile.am -- module */ -/* -#include "xf86int10.h" -#include "vbe.h" -#include "vbeModes.h" - */ - - -/* hw/xfree86/i2c/Makefile.am -- "mostly" modules */ -#include "xf86i2c.h" -/* -#include "bt829.h" -#include "fi1236.h" -#include "msp3430.h" -#include "tda8425.h" -#include "tda9850.h" -#include "tda9885.h" -#include "uda1380.h" -#include "i2c_def.h" - */ - - -/* hw/xfree86/modes/Makefile.am */ -#include "xf86Crtc.h" -#include "xf86Modes.h" -#include "xf86RandR12.h" -/* #include "xf86Rename.h" */ - - -/* hw/xfree86/ddc/Makefile.am */ -#include "edid.h" -#include "xf86DDC.h" - - -/* hw/xfree86/dri2/Makefile.am -- module */ -#ifdef DRI2 -# include "dri2.h" -#endif - -# include "dri3.h" - -/* hw/xfree86/vgahw/Makefile.am -- module */ -/* -#include "vgaHW.h" - */ - - -/* hw/xfree86/fbdevhw/Makefile.am -- module */ -/* -#include "fbdevhw.h" - */ - - -/* hw/xfree86/common/Makefile.am */ -#include "compiler.h" -#include "xf86.h" -#include "xf86Module.h" -#include "xf86Opt.h" -#ifdef XSERVER_LIBPCIACCESS - #include "xf86VGAarbiter.h" -#endif -#include "xf86Priv.h" -#include "xf86Privstr.h" -#include "xf86cmap.h" -#include "xf86fbman.h" -#include "xf86str.h" -#include "xf86Xinput.h" -#include "xisb.h" -#ifdef XV -# include "xf86xv.h" -# include "xf86xvmc.h" -# include "xf86xvpriv.h" -#endif -#include "xorgVersion.h" -#if defined(__sparc__) || defined(__sparc) -# include "xf86sbusBus.h" -#endif - - -/* hw/xfree86/ramdac/Makefile.am */ -#include "xf86Cursor.h" - - -/* hw/xfree86/shadowfb/Makefile.am -- module */ -/* -#include "shadowfb.h" - */ - - -/* hw/xfree86/os-support/solaris/Makefile.am */ -#if defined(sun386) -# include "agpgart.h" -#endif - - -/* hw/xfree86/os-support/Makefile.am */ -#include "xf86_OSproc.h" -#include "xf86_OSlib.h" - - -/* hw/xfree86/os-support/bus/Makefile.am */ -#ifdef XSERVER_LIBPCIACCESS -# include "xf86Pci.h" -#endif -#if defined(__sparc__) || defined(__sparc) -# include "xf86Sbus.h" -#endif - - -/* hw/xfree86/parser/Makefile.am */ -#include "xf86Parser.h" -#include "xf86Optrec.h" - - -/* hw/xfree86/dri/Makefile.am -- module */ -#ifdef XF86DRI -# include "dri.h" -# include "sarea.h" -# include "dristruct.h" -#endif - - -/* mi/Makefile.am */ -#include "micmap.h" -#include "miline.h" -#include "mipointer.h" -#include "mi.h" -#include "migc.h" -#include "mipointrst.h" -#include "mizerarc.h" -#include "micoord.h" -#include "mifillarc.h" -#include "mistruct.h" -#include "mioverlay.h" - - -/* randr/Makefile.am */ -#include "randrstr.h" -#include "rrtransform.h" - - -/* dbe/Makefile.am -- module */ -#ifdef DBE -#include "dbestruct.h" -#endif - - -/* exa/Makefile.am -- module */ -/* -#include "exa.h" - */ - -#ifdef COMPOSITE -#include "compositeext.h" -#endif - -/* xfixes/Makefile.am */ -#include "xfixes.h" - - -/* include/Makefile.am */ -#include "XIstubs.h" -#include "Xprintf.h" -#include "closestr.h" -#include "closure.h" -#include "colormap.h" -#include "colormapst.h" -#include "hotplug.h" -#include "client.h" -#include "cursor.h" -#include "cursorstr.h" -#include "dix.h" -#include "dixaccess.h" -#include "dixevents.h" -#define _FONTPROTO_H -#include "dixfont.h" -#include "dixfontstr.h" -#include "dixgrabs.h" -#include "dixstruct.h" -#include "exevents.h" -#include "extension.h" -#include "extnsionst.h" -#include "fourcc.h" -#include "gc.h" -#include "gcstruct.h" -#include "globals.h" -#include "input.h" -#include "inputstr.h" -/* already included */ -/* -#include "misc.h" -#include "miscstruct.h" - */ -#include "opaque.h" -#include "os.h" -#include "pixmap.h" -#include "pixmapstr.h" -#include "privates.h" -#include "property.h" -#include "propertyst.h" -#include "ptrveloc.h" -#include "region.h" -#include "regionstr.h" -#include "registry.h" -#include "resource.h" -#include "rgb.h" -#include "screenint.h" -#include "scrnintstr.h" -#include "selection.h" -#include "servermd.h" -#include "validate.h" -#include "window.h" -#include "windowstr.h" -#include "xace.h" -#include "xkbfile.h" -#include "xkbsrv.h" -#include "xkbstr.h" -#include "xkbrules.h" -#include "xserver-properties.h" - -EOF - -topdir=$(readlink -f $1) -shift -LC_ALL=C -export LC_ALL -${CPP:-cpp} "$@" sdksyms.c > /dev/null || exit $? -${CPP:-cpp} "$@" sdksyms.c | ${AWK:-awk} -v topdir=$topdir ' -function basename(file) { - sub(".*/", "", file) - return file -} -BEGIN { - sdk = 0; - print("/*"); - print(" * These symbols are referenced to ensure they"); - print(" * will be available in the X Server binary."); - print(" */"); - print("_X_HIDDEN void *xorg_symbols[] = {"); - - printf("sdksyms.c:") > "sdksyms.dep"; -} -/^# [0-9]+ "/ { - # Match preprocessor linemarkers which have the form: - # # linenum "filename" flags - # - # Only process text for sdk exports where the linemarker filename has a - # relative path, or an absolute path matching $top_srcdir. - # - - # canonicalize filename - if ($3 in canonicalized) { - c = canonicalized[$3] - } else { - cmd = "readlink -f " $3 - cmd | getline c - close(cmd) - canonicalized[$3] = c - } - # note that index() starts at 1; 0 means no match. - sdk = $3 !~ /^"\// || index(c, topdir) == 1; - - if (sdk && $3 ~ /\.h"$/) { - # remove quotes - gsub(/"/, "", $3); - line = $2; - header = basename($3); - if (! headers[$3]) { - printf(" \\\n %s", $3) >> "sdksyms.dep"; - headers[$3] = 1; - } - } - next; -} - -/^extern[ ]/ { - if (sdk) { - n = 3; - - # skip line numbers GCC 5 adds before __attribute__ - while ($n == "" || $0 ~ /^# [0-9]+ "/) { - getline; - n = 1; - } - - # skip attribute, if any - while ($n ~ /^(__attribute__|__global)/ || - # skip modifiers, if any - $n ~ /^\*?(unsigned|const|volatile|struct|_X_EXPORT)$/ || - # skip pointer - $n ~ /^[a-zA-Z0-9_]*\*$/) { - n++; - # skip line numbers GCC 5 adds after __attribute__ - while ($n == "" || $0 ~ /^# [0-9]+ "/) { - getline; - n = 1; - } - } - # hack: pid_t becomes __pid_t on NetBSD, same for uint32_t -> __uint32_t. - # GCC 5 inserts additional lines around this. - if (($1 == "__pid_t" || $1 == "__uint32_t") && NF == 1) { - getline; - n++; - # skip line numbers GCC 5 adds (after typedef return type?) - while ($n == "" || $0 ~ /^# [0-9]+ "/) { - getline; - n = 1; - } - } - - # type specifier may not be set, as in - # extern _X_EXPORT unsigned name(...) - if ($n !~ /[^a-zA-Z0-9_]/) - n++; - - # go back if we are at the parameter list already - if ($n ~ /^[(]([^*].*)?$/) - n--; - - # match - # extern _X_EXPORT type (* name[])(...) - if ($n ~ /^[^a-zA-Z0-9_]+$/) - n++; - - # match - # extern _X_EXPORT const name *const ... - if ($n ~ /^([^a-zA-Z0-9_]+)?const$/) - n++; - - # actual name may be in the next line, as in - # extern _X_EXPORT type - # possibly ending with a * - # name(...) - if ($n == "" || $n ~ /^\*+$/) { - getline; - n = 1; - # indent may have inserted a blank link - if ($0 == "") - getline; - } - - # dont modify $0 or $n - symbol = $n; - - # remove starting non word chars - sub(/^[^a-zA-Z0-9_]+/, "",symbol); - - # remove from first non word to end of line - sub(/[^a-zA-Z0-9_].*/, "", symbol); - - #print; - if (symbol != "") - printf(" (void *) &%-50s /* %s:%s */\n", symbol ",", header, line); - } -} - -{ - line++; -} - -END { - print("};"); - - print("") >> "sdksyms.dep"; -}' > _sdksyms.c - -STATUS=$? - -cat _sdksyms.c >> sdksyms.c -rm _sdksyms.c - -[ $? != 0 ] && exit $? - -exit $STATUS diff --git a/hw/xfree86/shadowfb/meson.build b/hw/xfree86/shadowfb/meson.build deleted file mode 100644 index 7ecc9bc30..000000000 --- a/hw/xfree86/shadowfb/meson.build +++ /dev/null @@ -1,11 +0,0 @@ -shared_module('shadowfb', - [ 'shadowfb.c', 'sfbmodule.c'], - include_directories: [ inc, xorg_inc ], - dependencies: common_dep, - c_args: xorg_c_args, - install: true, - install_dir: module_dir, - link_with: e, -) - -install_data('shadowfb.h', install_dir: xorgsdkdir) diff --git a/hw/xfree86/shadowfb/sfbmodule.c b/hw/xfree86/shadowfb/sfbmodule.c deleted file mode 100644 index c20efc071..000000000 --- a/hw/xfree86/shadowfb/sfbmodule.c +++ /dev/null @@ -1,20 +0,0 @@ -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Module.h" - -static XF86ModuleVersionInfo VersRec = { - "shadowfb", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 1, 0, 0, - ABI_CLASS_ANSIC, /* Only need the ansic layer */ - ABI_ANSIC_VERSION, - MOD_CLASS_NONE, - {0, 0, 0, 0} /* signature, to be patched into the file by a tool */ -}; - -_X_EXPORT XF86ModuleData shadowfbModuleData = { &VersRec, NULL, NULL }; diff --git a/hw/xfree86/shadowfb/shadowfb.c b/hw/xfree86/shadowfb/shadowfb.c deleted file mode 100644 index d2481ed8a..000000000 --- a/hw/xfree86/shadowfb/shadowfb.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - Copyright (C) 1999. The XFree86 Project Inc. - Copyright 2014 Red Hat, Inc. - - Written by Mark Vojkovich (mvojkovi@ucsd.edu) - Pre-fb-write callbacks and RENDER support - Nolan Leake (nolan@vmware.com) -*/ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include "misc.h" -#include "pixmapstr.h" -#include "input.h" -#include -#include "mi.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include "gcstruct.h" -#include "dixfontstr.h" -#include -#include "xf86.h" -#include "xf86str.h" -#include "shadowfb.h" - -#include "picturestr.h" - -static Bool ShadowCloseScreen(ScreenPtr pScreen); -static Bool ShadowCreateRootWindow(WindowPtr pWin); - -typedef struct { - ScrnInfoPtr pScrn; - RefreshAreaFuncPtr preRefresh; - RefreshAreaFuncPtr postRefresh; - CloseScreenProcPtr CloseScreen; - CreateWindowProcPtr CreateWindow; -} ShadowScreenRec, *ShadowScreenPtr; - -static DevPrivateKeyRec ShadowScreenKeyRec; - -static ShadowScreenPtr -shadowfbGetScreenPrivate(ScreenPtr pScreen) -{ - return dixLookupPrivate(&(pScreen)->devPrivates, &ShadowScreenKeyRec); -} - -Bool -ShadowFBInit2(ScreenPtr pScreen, - RefreshAreaFuncPtr preRefreshArea, - RefreshAreaFuncPtr postRefreshArea) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - ShadowScreenPtr pPriv; - - if (!preRefreshArea && !postRefreshArea) - return FALSE; - - if (!dixRegisterPrivateKey(&ShadowScreenKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - if (!(pPriv = (ShadowScreenPtr) malloc(sizeof(ShadowScreenRec)))) - return FALSE; - - dixSetPrivate(&pScreen->devPrivates, &ShadowScreenKeyRec, pPriv); - - pPriv->pScrn = pScrn; - pPriv->preRefresh = preRefreshArea; - pPriv->postRefresh = postRefreshArea; - - pPriv->CloseScreen = pScreen->CloseScreen; - pPriv->CreateWindow = pScreen->CreateWindow; - - pScreen->CloseScreen = ShadowCloseScreen; - pScreen->CreateWindow = ShadowCreateRootWindow; - - return TRUE; -} - -Bool -ShadowFBInit(ScreenPtr pScreen, RefreshAreaFuncPtr refreshArea) -{ - return ShadowFBInit2(pScreen, NULL, refreshArea); -} - -/* - * Note that we don't do DamageEmpty, or indeed look at the region inside the - * DamagePtr at all. This is an optimization, believe it or not. The - * incoming RegionPtr is the new damage, and if we were to empty the region - * miext/damage would just have to waste time reallocating and re-unioning - * it every time, whereas if we leave it around the union gets fast-pathed - * away. - */ - -static void -shadowfbReportPre(DamagePtr damage, RegionPtr reg, void *closure) -{ - ShadowScreenPtr pPriv = closure; - - if (!pPriv->pScrn->vtSema) - return; - - pPriv->preRefresh(pPriv->pScrn, RegionNumRects(reg), RegionRects(reg)); -} - -static void -shadowfbReportPost(DamagePtr damage, RegionPtr reg, void *closure) -{ - ShadowScreenPtr pPriv = closure; - - if (!pPriv->pScrn->vtSema) - return; - - pPriv->postRefresh(pPriv->pScrn, RegionNumRects(reg), RegionRects(reg)); -} - -static Bool -ShadowCreateRootWindow(WindowPtr pWin) -{ - Bool ret; - ScreenPtr pScreen = pWin->drawable.pScreen; - ShadowScreenPtr pPriv = shadowfbGetScreenPrivate(pScreen); - - /* paranoia */ - if (pWin != pScreen->root) - ErrorF("ShadowCreateRootWindow called unexpectedly\n"); - - /* call down, but don't hook ourselves back in; we know the first time - * we're called it's for the root window. - */ - pScreen->CreateWindow = pPriv->CreateWindow; - ret = pScreen->CreateWindow(pWin); - - /* this might look like it leaks, but the damage code reaps listeners - * when their drawable disappears. - */ - if (ret) { - DamagePtr damage; - - if (pPriv->preRefresh) { - damage = DamageCreate(shadowfbReportPre, NULL, - DamageReportRawRegion, - TRUE, pScreen, pPriv); - DamageRegister(&pWin->drawable, damage); - } - - if (pPriv->postRefresh) { - damage = DamageCreate(shadowfbReportPost, NULL, - DamageReportRawRegion, - TRUE, pScreen, pPriv); - DamageSetReportAfterOp(damage, TRUE); - DamageRegister(&pWin->drawable, damage); - } - } - - return ret; -} - -static Bool -ShadowCloseScreen(ScreenPtr pScreen) -{ - ShadowScreenPtr pPriv = shadowfbGetScreenPrivate(pScreen); - - pScreen->CloseScreen = pPriv->CloseScreen; - - free(pPriv); - - return (*pScreen->CloseScreen) (pScreen); -} diff --git a/hw/xfree86/shadowfb/shadowfb.h b/hw/xfree86/shadowfb/shadowfb.h deleted file mode 100644 index b3dd44872..000000000 --- a/hw/xfree86/shadowfb/shadowfb.h +++ /dev/null @@ -1,39 +0,0 @@ - -#ifndef _SHADOWFB_H -#define _SHADOWFB_H - -#include "xf86str.h" - -/* - * User defined callback function. Passed a pointer to the ScrnInfo struct, - * the number of dirty rectangles, and a pointer to the first dirty rectangle - * in the array. - */ -typedef void (*RefreshAreaFuncPtr) (ScrnInfoPtr, int, BoxPtr); - -/* - * ShadowFBInit initializes the shadowfb subsystem. refreshArea is a pointer - * to a user supplied callback function. This function will be called after - * any operation that modifies the framebuffer. The newly dirtied rectangles - * are passed to the callback. - * - * Returns FALSE in the event of an error. - */ -extern _X_EXPORT Bool - ShadowFBInit(ScreenPtr pScreen, RefreshAreaFuncPtr refreshArea); - -/* - * ShadowFBInit2 is a more featureful refinement of the original shadowfb. - * ShadowFBInit2 allows you to specify two callbacks, one to be called - * immediately before an operation that modifies the framebuffer, and another - * to be called immediately after. - * - * Returns FALSE in the event of an error - */ -extern _X_EXPORT Bool - -ShadowFBInit2(ScreenPtr pScreen, - RefreshAreaFuncPtr preRefreshArea, - RefreshAreaFuncPtr postRefreshArea); - -#endif /* _SHADOWFB_H */ diff --git a/hw/xfree86/utils/gtf/.gitignore b/hw/xfree86/utils/gtf/.gitignore deleted file mode 100644 index 919c993fb..000000000 --- a/hw/xfree86/utils/gtf/.gitignore +++ /dev/null @@ -1 +0,0 @@ -gtf diff --git a/hw/xfree86/utils/gtf/gtf.c b/hw/xfree86/utils/gtf/gtf.c deleted file mode 100644 index 818ee0fd7..000000000 --- a/hw/xfree86/utils/gtf/gtf.c +++ /dev/null @@ -1,699 +0,0 @@ -/* gtf.c Generate mode timings using the GTF Timing Standard - * - * gcc gtf.c -o gtf -lm -Wall - * - * Copyright (c) 2001, Andy Ritger aritger@nvidia.com - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * o Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * o Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * o Neither the name of NVIDIA nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * - * - * This program is based on the Generalized Timing Formula(GTF TM) - * Standard Version: 1.0, Revision: 1.0 - * - * The GTF Document contains the following Copyright information: - * - * Copyright (c) 1994, 1995, 1996 - Video Electronics Standards - * Association. Duplication of this document within VESA member - * companies for review purposes is permitted. All other rights - * reserved. - * - * While every precaution has been taken in the preparation - * of this standard, the Video Electronics Standards Association and - * its contributors assume no responsibility for errors or omissions, - * and make no warranties, expressed or implied, of functionality - * of suitability for any purpose. The sample code contained within - * this standard may be used without restriction. - * - * - * - * The GTF EXCEL(TM) SPREADSHEET, a sample (and the definitive) - * implementation of the GTF Timing Standard, is available at: - * - * ftp://ftp.vesa.org/pub/GTF/GTF_V1R1.xls - * - * - * - * This program takes a desired resolution and vertical refresh rate, - * and computes mode timings according to the GTF Timing Standard. - * These mode timings can then be formatted as an XServer modeline - * or a mode description for use by fbset(8). - * - * - * - * NOTES: - * - * The GTF allows for computation of "margins" (the visible border - * surrounding the addressable video); on most non-overscan type - * systems, the margin period is zero. I've implemented the margin - * computations but not enabled it because 1) I don't really have - * any experience with this, and 2) neither XServer modelines nor - * fbset fb.modes provide an obvious way for margin timings to be - * included in their mode descriptions (needs more investigation). - * - * The GTF provides for computation of interlaced mode timings; - * I've implemented the computations but not enabled them, yet. - * I should probably enable and test this at some point. - * - * - * - * TODO: - * - * o Add support for interlaced modes. - * - * o Implement the other portions of the GTF: compute mode timings - * given either the desired pixel clock or the desired horizontal - * frequency. - * - * o It would be nice if this were more general purpose to do things - * outside the scope of the GTF: like generate double scan mode - * timings, for example. - * - * o Printing digits to the right of the decimal point when the - * digits are 0 annoys me. - * - * o Error checking. - * - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#define MARGIN_PERCENT 1.8 /* % of active vertical image */ -#define CELL_GRAN 8.0 /* assumed character cell granularity */ -#define MIN_PORCH 1 /* minimum front porch */ -#define V_SYNC_RQD 3 /* width of vsync in lines */ -#define H_SYNC_PERCENT 8.0 /* width of hsync as % of total line */ -#define MIN_VSYNC_PLUS_BP 550.0 /* min time of vsync + back porch (microsec) */ -#define M 600.0 /* blanking formula gradient */ -#define C 40.0 /* blanking formula offset */ -#define K 128.0 /* blanking formula scaling factor */ -#define J 20.0 /* blanking formula scaling factor */ - -/* C' and M' are part of the Blanking Duty Cycle computation */ - -#define C_PRIME (((C - J) * K/256.0) + J) -#define M_PRIME (K/256.0 * M) - -/* struct definitions */ - -typedef struct __mode { - int hr, hss, hse, hfl; - int vr, vss, vse, vfl; - float pclk, h_freq, v_freq; -} mode; - -typedef struct __options { - int x, y; - int xorgmode, fbmode; - float v_freq; -} options; - -/* prototypes */ - -void print_value(int n, const char *name, float val); -void print_xf86_mode(mode * m); -void print_fb_mode(mode * m); -mode *vert_refresh(int h_pixels, int v_lines, float freq, - int interlaced, int margins); -options *parse_command_line(int argc, char *argv[]); - -/* - * print_value() - print the result of the named computation; this is - * useful when comparing against the GTF EXCEL spreadsheet. - */ - -int global_verbose = 0; - -void -print_value(int n, const char *name, float val) -{ - if (global_verbose) { - printf("%2d: %-27s: %15f\n", n, name, val); - } -} - -/* print_xf86_mode() - print the XServer modeline, given mode timings. */ - -void -print_xf86_mode(mode * m) -{ - printf("\n"); - printf(" # %dx%d @ %.2f Hz (GTF) hsync: %.2f kHz; pclk: %.2f MHz\n", - m->hr, m->vr, m->v_freq, m->h_freq, m->pclk); - - printf(" Modeline \"%dx%d_%.2f\" %.2f" - " %d %d %d %d" - " %d %d %d %d" - " -HSync +Vsync\n\n", - m->hr, m->vr, m->v_freq, m->pclk, - m->hr, m->hss, m->hse, m->hfl, m->vr, m->vss, m->vse, m->vfl); - -} - -/* - * print_fb_mode() - print a mode description in fbset(8) format; - * see the fb.modes(8) manpage. The timing description used in - * this is rather odd; they use "left and right margin" to refer - * to the portion of the hblank before and after the sync pulse - * by conceptually wrapping the portion of the blank after the pulse - * to infront of the visible region; ie: - * - * - * Timing description I'm accustomed to: - * - * - * - * <--------1--------> <--2--> <--3--> <--4--> - * _________ - * |-------------------|_______| |_______ - * - * R SS SE FL - * - * 1: visible image - * 2: blank before sync (aka front porch) - * 3: sync pulse - * 4: blank after sync (aka back porch) - * R: Resolution - * SS: Sync Start - * SE: Sync End - * FL: Frame Length - * - * - * But the fb.modes format is: - * - * - * <--4--> <--------1--------> <--2--> <--3--> - * _________ - * _______|-------------------|_______| | - * - * The fb.modes(8) manpage refers to <4> and <2> as the left and - * right "margin" (as well as upper and lower margin in the vertical - * direction) -- note that this has nothing to do with the term - * "margin" used in the GTF Timing Standard. - * - * XXX always prints the 32 bit mode -- should I provide a command - * line option to specify the bpp? It's simple enough for a user - * to edit the mode description after it's generated. - */ - -void -print_fb_mode(mode * m) -{ - printf("\n"); - printf("mode \"%dx%d %.2fHz 32bit (GTF)\"\n", m->hr, m->vr, m->v_freq); - printf(" # PCLK: %.2f MHz, H: %.2f kHz, V: %.2f Hz\n", - m->pclk, m->h_freq, m->v_freq); - printf(" geometry %d %d %d %d 32\n", m->hr, m->vr, m->hr, m->vr); - printf(" timings %d %d %d %d %d %d %d\n", (int)lrint(1000000.0 / m->pclk), /* pixclock in picoseconds */ - m->hfl - m->hse, /* left margin (in pixels) */ - m->hss - m->hr, /* right margin (in pixels) */ - m->vfl - m->vse, /* upper margin (in pixel lines) */ - m->vss - m->vr, /* lower margin (in pixel lines) */ - m->hse - m->hss, /* horizontal sync length (pixels) */ - m->vse - m->vss); /* vert sync length (pixel lines) */ - printf(" hsync low\n"); - printf(" vsync high\n"); - printf("endmode\n\n"); - -} - -/* - * vert_refresh() - as defined by the GTF Timing Standard, compute the - * Stage 1 Parameters using the vertical refresh frequency. In other - * words: input a desired resolution and desired refresh rate, and - * output the GTF mode timings. - * - * XXX All the code is in place to compute interlaced modes, but I don't - * feel like testing it right now. - * - * XXX margin computations are implemented but not tested (nor used by - * XServer of fbset mode descriptions, from what I can tell). - */ - -mode * -vert_refresh(int h_pixels, int v_lines, float freq, int interlaced, int margins) -{ - float h_pixels_rnd; - float v_lines_rnd; - float v_field_rate_rqd; - float top_margin; - float bottom_margin; - float interlace; - float h_period_est; - float vsync_plus_bp; - float v_back_porch; - float total_v_lines; - float v_field_rate_est; - float h_period; - float v_field_rate; - float v_frame_rate; - float left_margin; - float right_margin; - float total_active_pixels; - float ideal_duty_cycle; - float h_blank; - float total_pixels; - float pixel_freq; - float h_freq; - - float h_sync; - float h_front_porch; - float v_odd_front_porch_lines; - - mode *m = (mode *) malloc(sizeof(mode)); - - /* 1. In order to give correct results, the number of horizontal - * pixels requested is first processed to ensure that it is divisible - * by the character size, by rounding it to the nearest character - * cell boundary: - * - * [H PIXELS RND] = ((ROUND([H PIXELS]/[CELL GRAN RND],0))*[CELLGRAN RND]) - */ - - h_pixels_rnd = rint((float) h_pixels / CELL_GRAN) * CELL_GRAN; - - print_value(1, "[H PIXELS RND]", h_pixels_rnd); - - /* 2. If interlace is requested, the number of vertical lines assumed - * by the calculation must be halved, as the computation calculates - * the number of vertical lines per field. In either case, the - * number of lines is rounded to the nearest integer. - * - * [V LINES RND] = IF([INT RQD?]="y", ROUND([V LINES]/2,0), - * ROUND([V LINES],0)) - */ - - v_lines_rnd = interlaced ? - rint((float) v_lines) / 2.0 : rint((float) v_lines); - - print_value(2, "[V LINES RND]", v_lines_rnd); - - /* 3. Find the frame rate required: - * - * [V FIELD RATE RQD] = IF([INT RQD?]="y", [I/P FREQ RQD]*2, - * [I/P FREQ RQD]) - */ - - v_field_rate_rqd = interlaced ? (freq * 2.0) : (freq); - - print_value(3, "[V FIELD RATE RQD]", v_field_rate_rqd); - - /* 4. Find number of lines in Top margin: - * - * [TOP MARGIN (LINES)] = IF([MARGINS RQD?]="Y", - * ROUND(([MARGIN%]/100*[V LINES RND]),0), - * 0) - */ - - top_margin = margins ? rint(MARGIN_PERCENT / 100.0 * v_lines_rnd) : (0.0); - - print_value(4, "[TOP MARGIN (LINES)]", top_margin); - - /* 5. Find number of lines in Bottom margin: - * - * [BOT MARGIN (LINES)] = IF([MARGINS RQD?]="Y", - * ROUND(([MARGIN%]/100*[V LINES RND]),0), - * 0) - */ - - bottom_margin = - margins ? rint(MARGIN_PERCENT / 100.0 * v_lines_rnd) : (0.0); - - print_value(5, "[BOT MARGIN (LINES)]", bottom_margin); - - /* 6. If interlace is required, then set variable [INTERLACE]=0.5: - * - * [INTERLACE]=(IF([INT RQD?]="y",0.5,0)) - */ - - interlace = interlaced ? 0.5 : 0.0; - - print_value(6, "[INTERLACE]", interlace); - - /* 7. Estimate the Horizontal period - * - * [H PERIOD EST] = ((1/[V FIELD RATE RQD]) - [MIN VSYNC+BP]/1000000) / - * ([V LINES RND] + (2*[TOP MARGIN (LINES)]) + - * [MIN PORCH RND]+[INTERLACE]) * 1000000 - */ - - h_period_est = (((1.0 / v_field_rate_rqd) - (MIN_VSYNC_PLUS_BP / 1000000.0)) - / (v_lines_rnd + (2 * top_margin) + MIN_PORCH + interlace) - * 1000000.0); - - print_value(7, "[H PERIOD EST]", h_period_est); - - /* 8. Find the number of lines in V sync + back porch: - * - * [V SYNC+BP] = ROUND(([MIN VSYNC+BP]/[H PERIOD EST]),0) - */ - - vsync_plus_bp = rint(MIN_VSYNC_PLUS_BP / h_period_est); - - print_value(8, "[V SYNC+BP]", vsync_plus_bp); - - /* 9. Find the number of lines in V back porch alone: - * - * [V BACK PORCH] = [V SYNC+BP] - [V SYNC RND] - * - * XXX is "[V SYNC RND]" a typo? should be [V SYNC RQD]? - */ - - v_back_porch = vsync_plus_bp - V_SYNC_RQD; - - print_value(9, "[V BACK PORCH]", v_back_porch); - - /* 10. Find the total number of lines in Vertical field period: - * - * [TOTAL V LINES] = [V LINES RND] + [TOP MARGIN (LINES)] + - * [BOT MARGIN (LINES)] + [V SYNC+BP] + [INTERLACE] + - * [MIN PORCH RND] - */ - - total_v_lines = v_lines_rnd + top_margin + bottom_margin + vsync_plus_bp + - interlace + MIN_PORCH; - - print_value(10, "[TOTAL V LINES]", total_v_lines); - - /* 11. Estimate the Vertical field frequency: - * - * [V FIELD RATE EST] = 1 / [H PERIOD EST] / [TOTAL V LINES] * 1000000 - */ - - v_field_rate_est = 1.0 / h_period_est / total_v_lines * 1000000.0; - - print_value(11, "[V FIELD RATE EST]", v_field_rate_est); - - /* 12. Find the actual horizontal period: - * - * [H PERIOD] = [H PERIOD EST] / ([V FIELD RATE RQD] / [V FIELD RATE EST]) - */ - - h_period = h_period_est / (v_field_rate_rqd / v_field_rate_est); - - print_value(12, "[H PERIOD]", h_period); - - /* 13. Find the actual Vertical field frequency: - * - * [V FIELD RATE] = 1 / [H PERIOD] / [TOTAL V LINES] * 1000000 - */ - - v_field_rate = 1.0 / h_period / total_v_lines * 1000000.0; - - print_value(13, "[V FIELD RATE]", v_field_rate); - - /* 14. Find the Vertical frame frequency: - * - * [V FRAME RATE] = (IF([INT RQD?]="y", [V FIELD RATE]/2, [V FIELD RATE])) - */ - - v_frame_rate = interlaced ? v_field_rate / 2.0 : v_field_rate; - - print_value(14, "[V FRAME RATE]", v_frame_rate); - - /* 15. Find number of pixels in left margin: - * - * [LEFT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y", - * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 / - * [CELL GRAN RND]),0)) * [CELL GRAN RND], - * 0)) - */ - - left_margin = margins ? - rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN : - 0.0; - - print_value(15, "[LEFT MARGIN (PIXELS)]", left_margin); - - /* 16. Find number of pixels in right margin: - * - * [RIGHT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y", - * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 / - * [CELL GRAN RND]),0)) * [CELL GRAN RND], - * 0)) - */ - - right_margin = margins ? - rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN : - 0.0; - - print_value(16, "[RIGHT MARGIN (PIXELS)]", right_margin); - - /* 17. Find total number of active pixels in image and left and right - * margins: - * - * [TOTAL ACTIVE PIXELS] = [H PIXELS RND] + [LEFT MARGIN (PIXELS)] + - * [RIGHT MARGIN (PIXELS)] - */ - - total_active_pixels = h_pixels_rnd + left_margin + right_margin; - - print_value(17, "[TOTAL ACTIVE PIXELS]", total_active_pixels); - - /* 18. Find the ideal blanking duty cycle from the blanking duty cycle - * equation: - * - * [IDEAL DUTY CYCLE] = [C'] - ([M']*[H PERIOD]/1000) - */ - - ideal_duty_cycle = C_PRIME - (M_PRIME * h_period / 1000.0); - - print_value(18, "[IDEAL DUTY CYCLE]", ideal_duty_cycle); - - /* 19. Find the number of pixels in the blanking time to the nearest - * double character cell: - * - * [H BLANK (PIXELS)] = (ROUND(([TOTAL ACTIVE PIXELS] * - * [IDEAL DUTY CYCLE] / - * (100-[IDEAL DUTY CYCLE]) / - * (2*[CELL GRAN RND])), 0)) - * * (2*[CELL GRAN RND]) - */ - - h_blank = rint(total_active_pixels * - ideal_duty_cycle / - (100.0 - ideal_duty_cycle) / - (2.0 * CELL_GRAN)) * (2.0 * CELL_GRAN); - - print_value(19, "[H BLANK (PIXELS)]", h_blank); - - /* 20. Find total number of pixels: - * - * [TOTAL PIXELS] = [TOTAL ACTIVE PIXELS] + [H BLANK (PIXELS)] - */ - - total_pixels = total_active_pixels + h_blank; - - print_value(20, "[TOTAL PIXELS]", total_pixels); - - /* 21. Find pixel clock frequency: - * - * [PIXEL FREQ] = [TOTAL PIXELS] / [H PERIOD] - */ - - pixel_freq = total_pixels / h_period; - - print_value(21, "[PIXEL FREQ]", pixel_freq); - - /* 22. Find horizontal frequency: - * - * [H FREQ] = 1000 / [H PERIOD] - */ - - h_freq = 1000.0 / h_period; - - print_value(22, "[H FREQ]", h_freq); - - /* Stage 1 computations are now complete; I should really pass - the results to another function and do the Stage 2 - computations, but I only need a few more values so I'll just - append the computations here for now */ - - /* 17. Find the number of pixels in the horizontal sync period: - * - * [H SYNC (PIXELS)] =(ROUND(([H SYNC%] / 100 * [TOTAL PIXELS] / - * [CELL GRAN RND]),0))*[CELL GRAN RND] - */ - - h_sync = - rint(H_SYNC_PERCENT / 100.0 * total_pixels / CELL_GRAN) * CELL_GRAN; - - print_value(17, "[H SYNC (PIXELS)]", h_sync); - - /* 18. Find the number of pixels in the horizontal front porch period: - * - * [H FRONT PORCH (PIXELS)] = ([H BLANK (PIXELS)]/2)-[H SYNC (PIXELS)] - */ - - h_front_porch = (h_blank / 2.0) - h_sync; - - print_value(18, "[H FRONT PORCH (PIXELS)]", h_front_porch); - - /* 36. Find the number of lines in the odd front porch period: - * - * [V ODD FRONT PORCH(LINES)]=([MIN PORCH RND]+[INTERLACE]) - */ - - v_odd_front_porch_lines = MIN_PORCH + interlace; - - print_value(36, "[V ODD FRONT PORCH(LINES)]", v_odd_front_porch_lines); - - /* finally, pack the results in the mode struct */ - - m->hr = (int) (h_pixels_rnd); - m->hss = (int) (h_pixels_rnd + h_front_porch); - m->hse = (int) (h_pixels_rnd + h_front_porch + h_sync); - m->hfl = (int) (total_pixels); - - m->vr = (int) (v_lines_rnd); - m->vss = (int) (v_lines_rnd + v_odd_front_porch_lines); - m->vse = (int) (int) (v_lines_rnd + v_odd_front_porch_lines + V_SYNC_RQD); - m->vfl = (int) (total_v_lines); - - m->pclk = pixel_freq; - m->h_freq = h_freq; - m->v_freq = freq; - - return m; - -} - -/* - * parse_command_line() - parse the command line and return an - * alloced structure containing the results. On error print usage - * and return NULL. - */ - -options * -parse_command_line(int argc, char *argv[]) -{ - int n; - - options *o = (options *) calloc(1, sizeof(options)); - - if (argc < 4) - goto bad_option; - - o->x = atoi(argv[1]); - o->y = atoi(argv[2]); - o->v_freq = atof(argv[3]); - - /* XXX should check for errors in the above */ - - n = 4; - - while (n < argc) { - if ((strcmp(argv[n], "-v") == 0) || (strcmp(argv[n], "--verbose") == 0)) { - global_verbose = 1; - } - else if ((strcmp(argv[n], "-f") == 0) || - (strcmp(argv[n], "--fbmode") == 0)) { - o->fbmode = 1; - } - else if ((strcmp(argv[n], "-x") == 0) || - (strcmp(argv[n], "--xorgmode") == 0) || - (strcmp(argv[n], "--xf86mode") == 0)) { - o->xorgmode = 1; - } - else { - goto bad_option; - } - - n++; - } - - /* if neither xorgmode nor fbmode were requested, default to - xorgmode */ - - if (!o->fbmode && !o->xorgmode) - o->xorgmode = 1; - - return o; - - bad_option: - - fprintf(stderr, "\n"); - fprintf(stderr, "usage: %s x y refresh [-v|--verbose] " - "[-f|--fbmode] [-x|--xorgmode]\n", argv[0]); - - fprintf(stderr, "\n"); - - fprintf(stderr, " x : the desired horizontal " - "resolution (required)\n"); - fprintf(stderr, " y : the desired vertical " - "resolution (required)\n"); - fprintf(stderr, " refresh : the desired refresh " "rate (required)\n"); - fprintf(stderr, " -v|--verbose : enable verbose printouts " - "(traces each step of the computation)\n"); - fprintf(stderr, " -f|--fbmode : output an fbset(8)-style mode " - "description\n"); - fprintf(stderr, " -x|--xorgmode : output an " __XSERVERNAME__ "-style mode " - "description (this is the default\n" - " if no mode description is requested)\n"); - - fprintf(stderr, "\n"); - - free(o); - return NULL; - -} - -int -main(int argc, char *argv[]) -{ - mode *m; - options *o; - - o = parse_command_line(argc, argv); - if (!o) - exit(1); - - m = vert_refresh(o->x, o->y, o->v_freq, 0, 0); - if (!m) - exit(1); - - if (o->xorgmode) - print_xf86_mode(m); - - if (o->fbmode) - print_fb_mode(m); - - free(m); - - return 0; - -} diff --git a/hw/xfree86/utils/man/gtf.man b/hw/xfree86/utils/man/gtf.man deleted file mode 100644 index 95bddbbcf..000000000 --- a/hw/xfree86/utils/man/gtf.man +++ /dev/null @@ -1,44 +0,0 @@ -.TH GTF 1 @vendorversion@ -.SH NAME -gtf - calculate VESA GTF mode lines -.SH SYNOPSIS -.B gtf -.I h-resolution -.I v-resolution -.I refresh -.RB [ \-v | \-\-verbose ] -.RB [ \-f | \-\-fbmode ] -.RB [ \-x | \-\-xorgmode ] -.SH DESCRIPTION -.I Gtf -is a utility for calculating VESA GTF modes. Given the desired -horizontal and vertical resolutions and refresh rate (in Hz), the parameters -for a matching VESA GTF mode are printed out. Two output formats are -supported: mode lines suitable for the Xorg -.B xorg.conf(@filemansuffix@) -file, and mode parameters suitable for the Linux -.B fbset(8) -utility. - -.SH OPTIONS -.TP 8 -.BR \-v | \-\-verbose -Enable verbose printouts This shows a trace for each step of the -computation. -.TP 8 -.BR \-x | \-\-xorgmode -Print the mode parameters as Xorg-style mode lines. This is the -default format. -.TP 8 -.BR \-f | \-\-fbset -Print the mode parameters in a format suitable for -.BR fbset(8) . -.SH "SEE ALSO" -xorg.conf(@filemansuffix@), cvt(@appmansuffix@) -.SH AUTHOR -Andy Ritger. -.PP -This program is based on the Generalized Timing Formula (GTF(TM)) Standard -Version: 1.0, Revision: 1.0. The GTF Excel(TM) spreadsheet, a sample -(and the definitive) implementation of the GTF Timing Standard is -available at . diff --git a/hw/xfree86/vgahw/meson.build b/hw/xfree86/vgahw/meson.build deleted file mode 100644 index 762a90f06..000000000 --- a/hw/xfree86/vgahw/meson.build +++ /dev/null @@ -1,10 +0,0 @@ -shared_module('vgahw', - [ 'vgaHW.c', 'vgaHWmodule.c'], - include_directories: [ inc, xorg_inc ], - dependencies: common_dep, - c_args: xorg_c_args, - install: true, - install_dir: module_dir, -) - -install_data('vgaHW.h', install_dir: xorgsdkdir) diff --git a/hw/xfree86/vgahw/vgaHW.c b/hw/xfree86/vgahw/vgaHW.c deleted file mode 100644 index f6888009c..000000000 --- a/hw/xfree86/vgahw/vgaHW.c +++ /dev/null @@ -1,2075 +0,0 @@ - -/* - * - * Copyright 1991-1999 by The XFree86 Project, Inc. - * - * Loosely based on code bearing the following copyright: - * - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. - * - */ - -#define _NEED_SYSI86 - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include - -#include -#include "misc.h" - -#include "xf86.h" -#include "xf86_OSproc.h" -#include "vgaHW.h" - -#include "compiler.h" - -#include "xf86cmap.h" - -#include "Pci.h" - -#ifndef SAVE_FONT1 -#define SAVE_FONT1 1 -#endif - -/* - * These used to be OS-specific, which made this module have an undesirable - * OS dependency. Define them by default for all platforms. - */ -#ifndef NEED_SAVED_CMAP -#define NEED_SAVED_CMAP -#endif -#ifndef SAVE_TEXT -#define SAVE_TEXT 1 -#endif -#ifndef SAVE_FONT2 -#define SAVE_FONT2 1 -#endif - -/* bytes per plane to save for text */ -#define TEXT_AMOUNT 16384 - -/* bytes per plane to save for font data */ -#define FONT_AMOUNT (8*8192) - -#if 0 -/* Override all of these for now */ -#undef SAVE_FONT1 -#define SAVE_FONT1 1 -#undef SAVE_FONT2 -#define SAVE_FONT2 1 -#undef SAVE_TEST -#define SAVE_TEST 1 -#undef FONT_AMOUNT -#define FONT_AMOUNT 65536 -#undef TEXT_AMOUNT -#define TEXT_AMOUNT 65536 -#endif - -/* DAC indices for white and black */ -#define WHITE_VALUE 0x3F -#define BLACK_VALUE 0x00 -#define OVERSCAN_VALUE 0x01 - -/* Use a private definition of this here */ -#undef VGAHWPTR -#define VGAHWPTRLVAL(p) (p)->privates[vgaHWPrivateIndex].ptr -#define VGAHWPTR(p) ((vgaHWPtr)(VGAHWPTRLVAL(p))) - -static int vgaHWPrivateIndex = -1; - -#define DAC_TEST_MASK 0x3F - -#ifdef NEED_SAVED_CMAP -/* This default colourmap is used only when it can't be read from the VGA */ - -static CARD8 defaultDAC[768] = { - 0, 0, 0, 0, 0, 42, 0, 42, 0, 0, 42, 42, - 42, 0, 0, 42, 0, 42, 42, 21, 0, 42, 42, 42, - 21, 21, 21, 21, 21, 63, 21, 63, 21, 21, 63, 63, - 63, 21, 21, 63, 21, 63, 63, 63, 21, 63, 63, 63, - 0, 0, 0, 5, 5, 5, 8, 8, 8, 11, 11, 11, - 14, 14, 14, 17, 17, 17, 20, 20, 20, 24, 24, 24, - 28, 28, 28, 32, 32, 32, 36, 36, 36, 40, 40, 40, - 45, 45, 45, 50, 50, 50, 56, 56, 56, 63, 63, 63, - 0, 0, 63, 16, 0, 63, 31, 0, 63, 47, 0, 63, - 63, 0, 63, 63, 0, 47, 63, 0, 31, 63, 0, 16, - 63, 0, 0, 63, 16, 0, 63, 31, 0, 63, 47, 0, - 63, 63, 0, 47, 63, 0, 31, 63, 0, 16, 63, 0, - 0, 63, 0, 0, 63, 16, 0, 63, 31, 0, 63, 47, - 0, 63, 63, 0, 47, 63, 0, 31, 63, 0, 16, 63, - 31, 31, 63, 39, 31, 63, 47, 31, 63, 55, 31, 63, - 63, 31, 63, 63, 31, 55, 63, 31, 47, 63, 31, 39, - 63, 31, 31, 63, 39, 31, 63, 47, 31, 63, 55, 31, - 63, 63, 31, 55, 63, 31, 47, 63, 31, 39, 63, 31, - 31, 63, 31, 31, 63, 39, 31, 63, 47, 31, 63, 55, - 31, 63, 63, 31, 55, 63, 31, 47, 63, 31, 39, 63, - 45, 45, 63, 49, 45, 63, 54, 45, 63, 58, 45, 63, - 63, 45, 63, 63, 45, 58, 63, 45, 54, 63, 45, 49, - 63, 45, 45, 63, 49, 45, 63, 54, 45, 63, 58, 45, - 63, 63, 45, 58, 63, 45, 54, 63, 45, 49, 63, 45, - 45, 63, 45, 45, 63, 49, 45, 63, 54, 45, 63, 58, - 45, 63, 63, 45, 58, 63, 45, 54, 63, 45, 49, 63, - 0, 0, 28, 7, 0, 28, 14, 0, 28, 21, 0, 28, - 28, 0, 28, 28, 0, 21, 28, 0, 14, 28, 0, 7, - 28, 0, 0, 28, 7, 0, 28, 14, 0, 28, 21, 0, - 28, 28, 0, 21, 28, 0, 14, 28, 0, 7, 28, 0, - 0, 28, 0, 0, 28, 7, 0, 28, 14, 0, 28, 21, - 0, 28, 28, 0, 21, 28, 0, 14, 28, 0, 7, 28, - 14, 14, 28, 17, 14, 28, 21, 14, 28, 24, 14, 28, - 28, 14, 28, 28, 14, 24, 28, 14, 21, 28, 14, 17, - 28, 14, 14, 28, 17, 14, 28, 21, 14, 28, 24, 14, - 28, 28, 14, 24, 28, 14, 21, 28, 14, 17, 28, 14, - 14, 28, 14, 14, 28, 17, 14, 28, 21, 14, 28, 24, - 14, 28, 28, 14, 24, 28, 14, 21, 28, 14, 17, 28, - 20, 20, 28, 22, 20, 28, 24, 20, 28, 26, 20, 28, - 28, 20, 28, 28, 20, 26, 28, 20, 24, 28, 20, 22, - 28, 20, 20, 28, 22, 20, 28, 24, 20, 28, 26, 20, - 28, 28, 20, 26, 28, 20, 24, 28, 20, 22, 28, 20, - 20, 28, 20, 20, 28, 22, 20, 28, 24, 20, 28, 26, - 20, 28, 28, 20, 26, 28, 20, 24, 28, 20, 22, 28, - 0, 0, 16, 4, 0, 16, 8, 0, 16, 12, 0, 16, - 16, 0, 16, 16, 0, 12, 16, 0, 8, 16, 0, 4, - 16, 0, 0, 16, 4, 0, 16, 8, 0, 16, 12, 0, - 16, 16, 0, 12, 16, 0, 8, 16, 0, 4, 16, 0, - 0, 16, 0, 0, 16, 4, 0, 16, 8, 0, 16, 12, - 0, 16, 16, 0, 12, 16, 0, 8, 16, 0, 4, 16, - 8, 8, 16, 10, 8, 16, 12, 8, 16, 14, 8, 16, - 16, 8, 16, 16, 8, 14, 16, 8, 12, 16, 8, 10, - 16, 8, 8, 16, 10, 8, 16, 12, 8, 16, 14, 8, - 16, 16, 8, 14, 16, 8, 12, 16, 8, 10, 16, 8, - 8, 16, 8, 8, 16, 10, 8, 16, 12, 8, 16, 14, - 8, 16, 16, 8, 14, 16, 8, 12, 16, 8, 10, 16, - 11, 11, 16, 12, 11, 16, 13, 11, 16, 15, 11, 16, - 16, 11, 16, 16, 11, 15, 16, 11, 13, 16, 11, 12, - 16, 11, 11, 16, 12, 11, 16, 13, 11, 16, 15, 11, - 16, 16, 11, 15, 16, 11, 13, 16, 11, 12, 16, 11, - 11, 16, 11, 11, 16, 12, 11, 16, 13, 11, 16, 15, - 11, 16, 16, 11, 15, 16, 11, 13, 16, 11, 12, 16, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -}; -#endif /* NEED_SAVED_CMAP */ - -/* - * Standard VGA versions of the register access functions. - */ -static void -stdWriteCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value) -{ - pci_io_write8(hwp->io, hwp->IOBase + VGA_CRTC_INDEX_OFFSET, index); - pci_io_write8(hwp->io, hwp->IOBase + VGA_CRTC_DATA_OFFSET, value); -} - -static CARD8 -stdReadCrtc(vgaHWPtr hwp, CARD8 index) -{ - pci_io_write8(hwp->io, hwp->IOBase + VGA_CRTC_INDEX_OFFSET, index); - return pci_io_read8(hwp->io, hwp->IOBase + VGA_CRTC_DATA_OFFSET); -} - -static void -stdWriteGr(vgaHWPtr hwp, CARD8 index, CARD8 value) -{ - pci_io_write8(hwp->io, VGA_GRAPH_INDEX, index); - pci_io_write8(hwp->io, VGA_GRAPH_DATA, value); -} - -static CARD8 -stdReadGr(vgaHWPtr hwp, CARD8 index) -{ - pci_io_write8(hwp->io, VGA_GRAPH_INDEX, index); - return pci_io_read8(hwp->io, VGA_GRAPH_DATA); -} - -static void -stdWriteSeq(vgaHWPtr hwp, CARD8 index, CARD8 value) -{ - pci_io_write8(hwp->io, VGA_SEQ_INDEX, index); - pci_io_write8(hwp->io, VGA_SEQ_DATA, value); -} - -static CARD8 -stdReadSeq(vgaHWPtr hwp, CARD8 index) -{ - pci_io_write8(hwp->io, VGA_SEQ_INDEX, index); - return pci_io_read8(hwp->io, VGA_SEQ_DATA); -} - -static CARD8 -stdReadST00(vgaHWPtr hwp) -{ - return pci_io_read8(hwp->io, VGA_IN_STAT_0); -} - -static CARD8 -stdReadST01(vgaHWPtr hwp) -{ - return pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET); -} - -static CARD8 -stdReadFCR(vgaHWPtr hwp) -{ - return pci_io_read8(hwp->io, VGA_FEATURE_R); -} - -static void -stdWriteFCR(vgaHWPtr hwp, CARD8 value) -{ - pci_io_write8(hwp->io, hwp->IOBase + VGA_FEATURE_W_OFFSET, value); -} - -static void -stdWriteAttr(vgaHWPtr hwp, CARD8 index, CARD8 value) -{ - if (hwp->paletteEnabled) - index &= ~0x20; - else - index |= 0x20; - - (void) pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET); - pci_io_write8(hwp->io, VGA_ATTR_INDEX, index); - pci_io_write8(hwp->io, VGA_ATTR_DATA_W, value); -} - -static CARD8 -stdReadAttr(vgaHWPtr hwp, CARD8 index) -{ - if (hwp->paletteEnabled) - index &= ~0x20; - else - index |= 0x20; - - (void) pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET); - pci_io_write8(hwp->io, VGA_ATTR_INDEX, index); - return pci_io_read8(hwp->io, VGA_ATTR_DATA_R); -} - -static void -stdWriteMiscOut(vgaHWPtr hwp, CARD8 value) -{ - pci_io_write8(hwp->io, VGA_MISC_OUT_W, value); -} - -static CARD8 -stdReadMiscOut(vgaHWPtr hwp) -{ - return pci_io_read8(hwp->io, VGA_MISC_OUT_R); -} - -static void -stdEnablePalette(vgaHWPtr hwp) -{ - (void) pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET); - pci_io_write8(hwp->io, VGA_ATTR_INDEX, 0x00); - hwp->paletteEnabled = TRUE; -} - -static void -stdDisablePalette(vgaHWPtr hwp) -{ - (void) pci_io_read8(hwp->io, hwp->IOBase + VGA_IN_STAT_1_OFFSET); - pci_io_write8(hwp->io, VGA_ATTR_INDEX, 0x20); - hwp->paletteEnabled = FALSE; -} - -static void -stdWriteDacMask(vgaHWPtr hwp, CARD8 value) -{ - pci_io_write8(hwp->io, VGA_DAC_MASK, value); -} - -static CARD8 -stdReadDacMask(vgaHWPtr hwp) -{ - return pci_io_read8(hwp->io, VGA_DAC_MASK); -} - -static void -stdWriteDacReadAddr(vgaHWPtr hwp, CARD8 value) -{ - pci_io_write8(hwp->io, VGA_DAC_READ_ADDR, value); -} - -static void -stdWriteDacWriteAddr(vgaHWPtr hwp, CARD8 value) -{ - pci_io_write8(hwp->io, VGA_DAC_WRITE_ADDR, value); -} - -static void -stdWriteDacData(vgaHWPtr hwp, CARD8 value) -{ - pci_io_write8(hwp->io, VGA_DAC_DATA, value); -} - -static CARD8 -stdReadDacData(vgaHWPtr hwp) -{ - return pci_io_read8(hwp->io, VGA_DAC_DATA); -} - -static CARD8 -stdReadEnable(vgaHWPtr hwp) -{ - return pci_io_read8(hwp->io, VGA_ENABLE); -} - -static void -stdWriteEnable(vgaHWPtr hwp, CARD8 value) -{ - pci_io_write8(hwp->io, VGA_ENABLE, value); -} - -void -vgaHWSetStdFuncs(vgaHWPtr hwp) -{ - hwp->writeCrtc = stdWriteCrtc; - hwp->readCrtc = stdReadCrtc; - hwp->writeGr = stdWriteGr; - hwp->readGr = stdReadGr; - hwp->readST00 = stdReadST00; - hwp->readST01 = stdReadST01; - hwp->readFCR = stdReadFCR; - hwp->writeFCR = stdWriteFCR; - hwp->writeAttr = stdWriteAttr; - hwp->readAttr = stdReadAttr; - hwp->writeSeq = stdWriteSeq; - hwp->readSeq = stdReadSeq; - hwp->writeMiscOut = stdWriteMiscOut; - hwp->readMiscOut = stdReadMiscOut; - hwp->enablePalette = stdEnablePalette; - hwp->disablePalette = stdDisablePalette; - hwp->writeDacMask = stdWriteDacMask; - hwp->readDacMask = stdReadDacMask; - hwp->writeDacWriteAddr = stdWriteDacWriteAddr; - hwp->writeDacReadAddr = stdWriteDacReadAddr; - hwp->writeDacData = stdWriteDacData; - hwp->readDacData = stdReadDacData; - hwp->readEnable = stdReadEnable; - hwp->writeEnable = stdWriteEnable; - - hwp->io = pci_legacy_open_io(hwp->dev, 0, 64 * 1024); -} - -/* - * MMIO versions of the register access functions. These require - * hwp->MemBase to be set in such a way that when the standard VGA port - * adderss is added the correct memory address results. - */ - -#define minb(p) MMIO_IN8(hwp->MMIOBase, (hwp->MMIOOffset + (p))) -#define moutb(p,v) MMIO_OUT8(hwp->MMIOBase, (hwp->MMIOOffset + (p)),(v)) - -static void -mmioWriteCrtc(vgaHWPtr hwp, CARD8 index, CARD8 value) -{ - moutb(hwp->IOBase + VGA_CRTC_INDEX_OFFSET, index); - moutb(hwp->IOBase + VGA_CRTC_DATA_OFFSET, value); -} - -static CARD8 -mmioReadCrtc(vgaHWPtr hwp, CARD8 index) -{ - moutb(hwp->IOBase + VGA_CRTC_INDEX_OFFSET, index); - return minb(hwp->IOBase + VGA_CRTC_DATA_OFFSET); -} - -static void -mmioWriteGr(vgaHWPtr hwp, CARD8 index, CARD8 value) -{ - moutb(VGA_GRAPH_INDEX, index); - moutb(VGA_GRAPH_DATA, value); -} - -static CARD8 -mmioReadGr(vgaHWPtr hwp, CARD8 index) -{ - moutb(VGA_GRAPH_INDEX, index); - return minb(VGA_GRAPH_DATA); -} - -static void -mmioWriteSeq(vgaHWPtr hwp, CARD8 index, CARD8 value) -{ - moutb(VGA_SEQ_INDEX, index); - moutb(VGA_SEQ_DATA, value); -} - -static CARD8 -mmioReadSeq(vgaHWPtr hwp, CARD8 index) -{ - moutb(VGA_SEQ_INDEX, index); - return minb(VGA_SEQ_DATA); -} - -static CARD8 -mmioReadST00(vgaHWPtr hwp) -{ - return minb(VGA_IN_STAT_0); -} - -static CARD8 -mmioReadST01(vgaHWPtr hwp) -{ - return minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET); -} - -static CARD8 -mmioReadFCR(vgaHWPtr hwp) -{ - return minb(VGA_FEATURE_R); -} - -static void -mmioWriteFCR(vgaHWPtr hwp, CARD8 value) -{ - moutb(hwp->IOBase + VGA_FEATURE_W_OFFSET, value); -} - -static void -mmioWriteAttr(vgaHWPtr hwp, CARD8 index, CARD8 value) -{ - if (hwp->paletteEnabled) - index &= ~0x20; - else - index |= 0x20; - - (void) minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET); - moutb(VGA_ATTR_INDEX, index); - moutb(VGA_ATTR_DATA_W, value); -} - -static CARD8 -mmioReadAttr(vgaHWPtr hwp, CARD8 index) -{ - if (hwp->paletteEnabled) - index &= ~0x20; - else - index |= 0x20; - - (void) minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET); - moutb(VGA_ATTR_INDEX, index); - return minb(VGA_ATTR_DATA_R); -} - -static void -mmioWriteMiscOut(vgaHWPtr hwp, CARD8 value) -{ - moutb(VGA_MISC_OUT_W, value); -} - -static CARD8 -mmioReadMiscOut(vgaHWPtr hwp) -{ - return minb(VGA_MISC_OUT_R); -} - -static void -mmioEnablePalette(vgaHWPtr hwp) -{ - (void) minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET); - moutb(VGA_ATTR_INDEX, 0x00); - hwp->paletteEnabled = TRUE; -} - -static void -mmioDisablePalette(vgaHWPtr hwp) -{ - (void) minb(hwp->IOBase + VGA_IN_STAT_1_OFFSET); - moutb(VGA_ATTR_INDEX, 0x20); - hwp->paletteEnabled = FALSE; -} - -static void -mmioWriteDacMask(vgaHWPtr hwp, CARD8 value) -{ - moutb(VGA_DAC_MASK, value); -} - -static CARD8 -mmioReadDacMask(vgaHWPtr hwp) -{ - return minb(VGA_DAC_MASK); -} - -static void -mmioWriteDacReadAddr(vgaHWPtr hwp, CARD8 value) -{ - moutb(VGA_DAC_READ_ADDR, value); -} - -static void -mmioWriteDacWriteAddr(vgaHWPtr hwp, CARD8 value) -{ - moutb(VGA_DAC_WRITE_ADDR, value); -} - -static void -mmioWriteDacData(vgaHWPtr hwp, CARD8 value) -{ - moutb(VGA_DAC_DATA, value); -} - -static CARD8 -mmioReadDacData(vgaHWPtr hwp) -{ - return minb(VGA_DAC_DATA); -} - -static CARD8 -mmioReadEnable(vgaHWPtr hwp) -{ - return minb(VGA_ENABLE); -} - -static void -mmioWriteEnable(vgaHWPtr hwp, CARD8 value) -{ - moutb(VGA_ENABLE, value); -} - -void -vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset) -{ - hwp->writeCrtc = mmioWriteCrtc; - hwp->readCrtc = mmioReadCrtc; - hwp->writeGr = mmioWriteGr; - hwp->readGr = mmioReadGr; - hwp->readST00 = mmioReadST00; - hwp->readST01 = mmioReadST01; - hwp->readFCR = mmioReadFCR; - hwp->writeFCR = mmioWriteFCR; - hwp->writeAttr = mmioWriteAttr; - hwp->readAttr = mmioReadAttr; - hwp->writeSeq = mmioWriteSeq; - hwp->readSeq = mmioReadSeq; - hwp->writeMiscOut = mmioWriteMiscOut; - hwp->readMiscOut = mmioReadMiscOut; - hwp->enablePalette = mmioEnablePalette; - hwp->disablePalette = mmioDisablePalette; - hwp->writeDacMask = mmioWriteDacMask; - hwp->readDacMask = mmioReadDacMask; - hwp->writeDacWriteAddr = mmioWriteDacWriteAddr; - hwp->writeDacReadAddr = mmioWriteDacReadAddr; - hwp->writeDacData = mmioWriteDacData; - hwp->readDacData = mmioReadDacData; - hwp->MMIOBase = base; - hwp->MMIOOffset = offset; - hwp->readEnable = mmioReadEnable; - hwp->writeEnable = mmioWriteEnable; -} - -/* - * vgaHWProtect -- - * Protect VGA registers and memory from corruption during loads. - */ - -void -vgaHWProtect(ScrnInfoPtr pScrn, Bool on) -{ - vgaHWPtr hwp = VGAHWPTR(pScrn); - - unsigned char tmp; - - if (pScrn->vtSema) { - if (on) { - /* - * Turn off screen and disable sequencer. - */ - tmp = hwp->readSeq(hwp, 0x01); - - vgaHWSeqReset(hwp, TRUE); /* start synchronous reset */ - hwp->writeSeq(hwp, 0x01, tmp | 0x20); /* disable the display */ - - hwp->enablePalette(hwp); - } - else { - /* - * Re-enable sequencer, then turn on screen. - */ - - tmp = hwp->readSeq(hwp, 0x01); - - hwp->writeSeq(hwp, 0x01, tmp & ~0x20); /* re-enable display */ - vgaHWSeqReset(hwp, FALSE); /* clear synchronousreset */ - - hwp->disablePalette(hwp); - } - } -} - -vgaHWProtectProc * -vgaHWProtectWeak(void) -{ - return vgaHWProtect; -} - -/* - * vgaHWBlankScreen -- blank the screen. - */ - -void -vgaHWBlankScreen(ScrnInfoPtr pScrn, Bool on) -{ - vgaHWPtr hwp = VGAHWPTR(pScrn); - unsigned char scrn; - - scrn = hwp->readSeq(hwp, 0x01); - - if (on) { - scrn &= ~0x20; /* enable screen */ - } - else { - scrn |= 0x20; /* blank screen */ - } - - vgaHWSeqReset(hwp, TRUE); - hwp->writeSeq(hwp, 0x01, scrn); /* change mode */ - vgaHWSeqReset(hwp, FALSE); -} - -vgaHWBlankScreenProc * -vgaHWBlankScreenWeak(void) -{ - return vgaHWBlankScreen; -} - -/* - * vgaHWSaveScreen -- blank the screen. - */ - -Bool -vgaHWSaveScreen(ScreenPtr pScreen, int mode) -{ - ScrnInfoPtr pScrn = NULL; - Bool on; - - if (pScreen != NULL) - pScrn = xf86ScreenToScrn(pScreen); - - on = xf86IsUnblank(mode); - -#if 0 - if (on) - SetTimeSinceLastInputEvent(); -#endif - - if ((pScrn != NULL) && pScrn->vtSema) { - vgaHWBlankScreen(pScrn, on); - } - return TRUE; -} - -/* - * vgaHWDPMSSet -- Sets VESA Display Power Management Signaling (DPMS) Mode - * - * This generic VGA function can only set the Off and On modes. If the - * Standby and Suspend modes are to be supported, a chip specific replacement - * for this function must be written. - */ - -void -vgaHWDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags) -{ - unsigned char seq1 = 0, crtc17 = 0; - vgaHWPtr hwp = VGAHWPTR(pScrn); - - if (!pScrn->vtSema) - return; - - switch (PowerManagementMode) { - case DPMSModeOn: - /* Screen: On; HSync: On, VSync: On */ - seq1 = 0x00; - crtc17 = 0x80; - break; - case DPMSModeStandby: - /* Screen: Off; HSync: Off, VSync: On -- Not Supported */ - seq1 = 0x20; - crtc17 = 0x80; - break; - case DPMSModeSuspend: - /* Screen: Off; HSync: On, VSync: Off -- Not Supported */ - seq1 = 0x20; - crtc17 = 0x80; - break; - case DPMSModeOff: - /* Screen: Off; HSync: Off, VSync: Off */ - seq1 = 0x20; - crtc17 = 0x00; - break; - } - hwp->writeSeq(hwp, 0x00, 0x01); /* Synchronous Reset */ - seq1 |= hwp->readSeq(hwp, 0x01) & ~0x20; - hwp->writeSeq(hwp, 0x01, seq1); - crtc17 |= hwp->readCrtc(hwp, 0x17) & ~0x80; - usleep(10000); - hwp->writeCrtc(hwp, 0x17, crtc17); - hwp->writeSeq(hwp, 0x00, 0x03); /* End Reset */ -} - -/* - * vgaHWSeqReset - * perform a sequencer reset. - */ - -void -vgaHWSeqReset(vgaHWPtr hwp, Bool start) -{ - if (start) - hwp->writeSeq(hwp, 0x00, 0x01); /* Synchronous Reset */ - else - hwp->writeSeq(hwp, 0x00, 0x03); /* End Reset */ -} - -void -vgaHWRestoreFonts(ScrnInfoPtr scrninfp, vgaRegPtr restore) -{ -#if SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 - vgaHWPtr hwp = VGAHWPTR(scrninfp); - int savedIOBase; - unsigned char miscOut, attr10, gr1, gr3, gr4, gr5, gr6, gr8, seq2, seq4; - Bool doMap = FALSE; - - /* If nothing to do, return now */ - if (!hwp->FontInfo1 && !hwp->FontInfo2 && !hwp->TextInfo) - return; - - if (hwp->Base == NULL) { - doMap = TRUE; - if (!vgaHWMapMem(scrninfp)) { - xf86DrvMsg(scrninfp->scrnIndex, X_ERROR, - "vgaHWRestoreFonts: vgaHWMapMem() failed\n"); - return; - } - } - - /* save the registers that are needed here */ - miscOut = hwp->readMiscOut(hwp); - attr10 = hwp->readAttr(hwp, 0x10); - gr1 = hwp->readGr(hwp, 0x01); - gr3 = hwp->readGr(hwp, 0x03); - gr4 = hwp->readGr(hwp, 0x04); - gr5 = hwp->readGr(hwp, 0x05); - gr6 = hwp->readGr(hwp, 0x06); - gr8 = hwp->readGr(hwp, 0x08); - seq2 = hwp->readSeq(hwp, 0x02); - seq4 = hwp->readSeq(hwp, 0x04); - - /* save hwp->IOBase and temporarily set it for colour mode */ - savedIOBase = hwp->IOBase; - hwp->IOBase = VGA_IOBASE_COLOR; - - /* Force into colour mode */ - hwp->writeMiscOut(hwp, miscOut | 0x01); - - vgaHWBlankScreen(scrninfp, FALSE); - - /* - * here we temporarily switch to 16 colour planar mode, to simply - * copy the font-info and saved text. - * - * BUG ALERT: The (S)VGA's segment-select register MUST be set correctly! - */ -#if 0 - hwp->writeAttr(hwp, 0x10, 0x01); /* graphics mode */ -#endif - - hwp->writeSeq(hwp, 0x04, 0x06); /* enable plane graphics */ - hwp->writeGr(hwp, 0x05, 0x00); /* write mode 0, read mode 0 */ - hwp->writeGr(hwp, 0x06, 0x05); /* set graphics */ - - if (scrninfp->depth == 4) { - /* GJA */ - hwp->writeGr(hwp, 0x03, 0x00); /* don't rotate, write unmodified */ - hwp->writeGr(hwp, 0x08, 0xFF); /* write all bits in a byte */ - hwp->writeGr(hwp, 0x01, 0x00); /* all planes come from CPU */ - } - -#if SAVE_FONT1 - if (hwp->FontInfo1) { - hwp->writeSeq(hwp, 0x02, 0x04); /* write to plane 2 */ - hwp->writeGr(hwp, 0x04, 0x02); /* read plane 2 */ - slowbcopy_tobus(hwp->FontInfo1, hwp->Base, FONT_AMOUNT); - } -#endif - -#if SAVE_FONT2 - if (hwp->FontInfo2) { - hwp->writeSeq(hwp, 0x02, 0x08); /* write to plane 3 */ - hwp->writeGr(hwp, 0x04, 0x03); /* read plane 3 */ - slowbcopy_tobus(hwp->FontInfo2, hwp->Base, FONT_AMOUNT); - } -#endif - -#if SAVE_TEXT - if (hwp->TextInfo) { - hwp->writeSeq(hwp, 0x02, 0x01); /* write to plane 0 */ - hwp->writeGr(hwp, 0x04, 0x00); /* read plane 0 */ - slowbcopy_tobus(hwp->TextInfo, hwp->Base, TEXT_AMOUNT); - hwp->writeSeq(hwp, 0x02, 0x02); /* write to plane 1 */ - hwp->writeGr(hwp, 0x04, 0x01); /* read plane 1 */ - slowbcopy_tobus((unsigned char *) hwp->TextInfo + TEXT_AMOUNT, - hwp->Base, TEXT_AMOUNT); - } -#endif - - vgaHWBlankScreen(scrninfp, TRUE); - - /* restore the registers that were changed */ - hwp->writeMiscOut(hwp, miscOut); - hwp->writeAttr(hwp, 0x10, attr10); - hwp->writeGr(hwp, 0x01, gr1); - hwp->writeGr(hwp, 0x03, gr3); - hwp->writeGr(hwp, 0x04, gr4); - hwp->writeGr(hwp, 0x05, gr5); - hwp->writeGr(hwp, 0x06, gr6); - hwp->writeGr(hwp, 0x08, gr8); - hwp->writeSeq(hwp, 0x02, seq2); - hwp->writeSeq(hwp, 0x04, seq4); - hwp->IOBase = savedIOBase; - - if (doMap) - vgaHWUnmapMem(scrninfp); - -#endif /* SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 */ -} - -void -vgaHWRestoreMode(ScrnInfoPtr scrninfp, vgaRegPtr restore) -{ - vgaHWPtr hwp = VGAHWPTR(scrninfp); - int i; - - if (restore->MiscOutReg & 0x01) - hwp->IOBase = VGA_IOBASE_COLOR; - else - hwp->IOBase = VGA_IOBASE_MONO; - - hwp->writeMiscOut(hwp, restore->MiscOutReg); - - for (i = 1; i < restore->numSequencer; i++) - hwp->writeSeq(hwp, i, restore->Sequencer[i]); - - /* Ensure CRTC registers 0-7 are unlocked by clearing bit 7 of CRTC[17] */ - hwp->writeCrtc(hwp, 17, restore->CRTC[17] & ~0x80); - - for (i = 0; i < restore->numCRTC; i++) - hwp->writeCrtc(hwp, i, restore->CRTC[i]); - - for (i = 0; i < restore->numGraphics; i++) - hwp->writeGr(hwp, i, restore->Graphics[i]); - - hwp->enablePalette(hwp); - for (i = 0; i < restore->numAttribute; i++) - hwp->writeAttr(hwp, i, restore->Attribute[i]); - hwp->disablePalette(hwp); -} - -void -vgaHWRestoreColormap(ScrnInfoPtr scrninfp, vgaRegPtr restore) -{ - vgaHWPtr hwp = VGAHWPTR(scrninfp); - int i; - -#if 0 - hwp->enablePalette(hwp); -#endif - - hwp->writeDacMask(hwp, 0xFF); - hwp->writeDacWriteAddr(hwp, 0x00); - for (i = 0; i < 768; i++) { - hwp->writeDacData(hwp, restore->DAC[i]); - DACDelay(hwp); - } - - hwp->disablePalette(hwp); -} - -/* - * vgaHWRestore -- - * restore the VGA state - */ - -void -vgaHWRestore(ScrnInfoPtr scrninfp, vgaRegPtr restore, int flags) -{ - if (flags & VGA_SR_MODE) - vgaHWRestoreMode(scrninfp, restore); - - if (flags & VGA_SR_FONTS) - vgaHWRestoreFonts(scrninfp, restore); - - if (flags & VGA_SR_CMAP) - vgaHWRestoreColormap(scrninfp, restore); -} - -void -vgaHWSaveFonts(ScrnInfoPtr scrninfp, vgaRegPtr save) -{ -#if SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 - vgaHWPtr hwp = VGAHWPTR(scrninfp); - int savedIOBase; - unsigned char miscOut, attr10, gr4, gr5, gr6, seq2, seq4; - Bool doMap = FALSE; - - if (hwp->Base == NULL) { - doMap = TRUE; - if (!vgaHWMapMem(scrninfp)) { - xf86DrvMsg(scrninfp->scrnIndex, X_ERROR, - "vgaHWSaveFonts: vgaHWMapMem() failed\n"); - return; - } - } - - /* If in graphics mode, don't save anything */ - attr10 = hwp->readAttr(hwp, 0x10); - if (attr10 & 0x01) - return; - - /* save the registers that are needed here */ - miscOut = hwp->readMiscOut(hwp); - gr4 = hwp->readGr(hwp, 0x04); - gr5 = hwp->readGr(hwp, 0x05); - gr6 = hwp->readGr(hwp, 0x06); - seq2 = hwp->readSeq(hwp, 0x02); - seq4 = hwp->readSeq(hwp, 0x04); - - /* save hwp->IOBase and temporarily set it for colour mode */ - savedIOBase = hwp->IOBase; - hwp->IOBase = VGA_IOBASE_COLOR; - - /* Force into colour mode */ - hwp->writeMiscOut(hwp, miscOut | 0x01); - - vgaHWBlankScreen(scrninfp, FALSE); - - /* - * get the character sets, and text screen if required - */ - /* - * Here we temporarily switch to 16 colour planar mode, to simply - * copy the font-info - * - * BUG ALERT: The (S)VGA's segment-select register MUST be set correctly! - */ -#if 0 - hwp->writeAttr(hwp, 0x10, 0x01); /* graphics mode */ -#endif - - hwp->writeSeq(hwp, 0x04, 0x06); /* enable plane graphics */ - hwp->writeGr(hwp, 0x05, 0x00); /* write mode 0, read mode 0 */ - hwp->writeGr(hwp, 0x06, 0x05); /* set graphics */ - -#if SAVE_FONT1 - if (hwp->FontInfo1 || (hwp->FontInfo1 = malloc(FONT_AMOUNT))) { - hwp->writeSeq(hwp, 0x02, 0x04); /* write to plane 2 */ - hwp->writeGr(hwp, 0x04, 0x02); /* read plane 2 */ - slowbcopy_frombus(hwp->Base, hwp->FontInfo1, FONT_AMOUNT); - } -#endif /* SAVE_FONT1 */ -#if SAVE_FONT2 - if (hwp->FontInfo2 || (hwp->FontInfo2 = malloc(FONT_AMOUNT))) { - hwp->writeSeq(hwp, 0x02, 0x08); /* write to plane 3 */ - hwp->writeGr(hwp, 0x04, 0x03); /* read plane 3 */ - slowbcopy_frombus(hwp->Base, hwp->FontInfo2, FONT_AMOUNT); - } -#endif /* SAVE_FONT2 */ -#if SAVE_TEXT - if (hwp->TextInfo || (hwp->TextInfo = malloc(2 * TEXT_AMOUNT))) { - hwp->writeSeq(hwp, 0x02, 0x01); /* write to plane 0 */ - hwp->writeGr(hwp, 0x04, 0x00); /* read plane 0 */ - slowbcopy_frombus(hwp->Base, hwp->TextInfo, TEXT_AMOUNT); - hwp->writeSeq(hwp, 0x02, 0x02); /* write to plane 1 */ - hwp->writeGr(hwp, 0x04, 0x01); /* read plane 1 */ - slowbcopy_frombus(hwp->Base, - (unsigned char *) hwp->TextInfo + TEXT_AMOUNT, - TEXT_AMOUNT); - } -#endif /* SAVE_TEXT */ - - /* Restore clobbered registers */ - hwp->writeAttr(hwp, 0x10, attr10); - hwp->writeSeq(hwp, 0x02, seq2); - hwp->writeSeq(hwp, 0x04, seq4); - hwp->writeGr(hwp, 0x04, gr4); - hwp->writeGr(hwp, 0x05, gr5); - hwp->writeGr(hwp, 0x06, gr6); - hwp->writeMiscOut(hwp, miscOut); - hwp->IOBase = savedIOBase; - - vgaHWBlankScreen(scrninfp, TRUE); - - if (doMap) - vgaHWUnmapMem(scrninfp); - -#endif /* SAVE_TEXT || SAVE_FONT1 || SAVE_FONT2 */ -} - -void -vgaHWSaveMode(ScrnInfoPtr scrninfp, vgaRegPtr save) -{ - vgaHWPtr hwp = VGAHWPTR(scrninfp); - int i; - - save->MiscOutReg = hwp->readMiscOut(hwp); - if (save->MiscOutReg & 0x01) - hwp->IOBase = VGA_IOBASE_COLOR; - else - hwp->IOBase = VGA_IOBASE_MONO; - - for (i = 0; i < save->numCRTC; i++) { - save->CRTC[i] = hwp->readCrtc(hwp, i); - DebugF("CRTC[0x%02x] = 0x%02x\n", i, save->CRTC[i]); - } - - hwp->enablePalette(hwp); - for (i = 0; i < save->numAttribute; i++) { - save->Attribute[i] = hwp->readAttr(hwp, i); - DebugF("Attribute[0x%02x] = 0x%02x\n", i, save->Attribute[i]); - } - hwp->disablePalette(hwp); - - for (i = 0; i < save->numGraphics; i++) { - save->Graphics[i] = hwp->readGr(hwp, i); - DebugF("Graphics[0x%02x] = 0x%02x\n", i, save->Graphics[i]); - } - - for (i = 1; i < save->numSequencer; i++) { - save->Sequencer[i] = hwp->readSeq(hwp, i); - DebugF("Sequencer[0x%02x] = 0x%02x\n", i, save->Sequencer[i]); - } -} - -void -vgaHWSaveColormap(ScrnInfoPtr scrninfp, vgaRegPtr save) -{ - vgaHWPtr hwp = VGAHWPTR(scrninfp); - Bool readError = FALSE; - int i; - -#ifdef NEED_SAVED_CMAP - /* - * Some ET4000 chips from 1991 have a HW bug that prevents the reading - * of the color lookup table. Mask rev 9042EAI is known to have this bug. - * - * If the colourmap is not readable, we set the saved map to a default - * map (taken from Ferraro's "Programmer's Guide to the EGA and VGA - * Cards" 2nd ed). - */ - - /* Only save it once */ - if (hwp->cmapSaved) - return; - -#if 0 - hwp->enablePalette(hwp); -#endif - - hwp->writeDacMask(hwp, 0xFF); - - /* - * check if we can read the lookup table - */ - hwp->writeDacReadAddr(hwp, 0x00); - for (i = 0; i < 6; i++) { - save->DAC[i] = hwp->readDacData(hwp); - switch (i % 3) { - case 0: - DebugF("DAC[0x%02x] = 0x%02x, ", i / 3, save->DAC[i]); - break; - case 1: - DebugF("0x%02x, ", save->DAC[i]); - break; - case 2: - DebugF("0x%02x\n", save->DAC[i]); - } - } - - /* - * Check if we can read the palette - - * use foreground color to prevent flashing. - */ - hwp->writeDacWriteAddr(hwp, 0x01); - for (i = 3; i < 6; i++) - hwp->writeDacData(hwp, ~save->DAC[i] & DAC_TEST_MASK); - hwp->writeDacReadAddr(hwp, 0x01); - for (i = 3; i < 6; i++) { - if (hwp->readDacData(hwp) != (~save->DAC[i] & DAC_TEST_MASK)) - readError = TRUE; - } - hwp->writeDacWriteAddr(hwp, 0x01); - for (i = 3; i < 6; i++) - hwp->writeDacData(hwp, save->DAC[i]); - - if (readError) { - /* - * save the default lookup table - */ - memmove(save->DAC, defaultDAC, 768); - xf86DrvMsg(scrninfp->scrnIndex, X_WARNING, - "Cannot read colourmap from VGA. Will restore with default\n"); - } - else { - /* save the colourmap */ - hwp->writeDacReadAddr(hwp, 0x02); - for (i = 6; i < 768; i++) { - save->DAC[i] = hwp->readDacData(hwp); - DACDelay(hwp); - switch (i % 3) { - case 0: - DebugF("DAC[0x%02x] = 0x%02x, ", i / 3, save->DAC[i]); - break; - case 1: - DebugF("0x%02x, ", save->DAC[i]); - break; - case 2: - DebugF("0x%02x\n", save->DAC[i]); - } - } - } - - hwp->disablePalette(hwp); - hwp->cmapSaved = TRUE; -#endif -} - -/* - * vgaHWSave -- - * save the current VGA state - */ - -void -vgaHWSave(ScrnInfoPtr scrninfp, vgaRegPtr save, int flags) -{ - if (save == NULL) - return; - - if (flags & VGA_SR_CMAP) - vgaHWSaveColormap(scrninfp, save); - - if (flags & VGA_SR_MODE) - vgaHWSaveMode(scrninfp, save); - - if (flags & VGA_SR_FONTS) - vgaHWSaveFonts(scrninfp, save); -} - -/* - * vgaHWInit -- - * Handle the initialization, etc. of a screen. - * Return FALSE on failure. - */ - -Bool -vgaHWInit(ScrnInfoPtr scrninfp, DisplayModePtr mode) -{ - unsigned int i; - vgaHWPtr hwp; - vgaRegPtr regp; - int depth = scrninfp->depth; - - /* - * make sure the vgaHWRec is allocated - */ - if (!vgaHWGetHWRec(scrninfp)) - return FALSE; - hwp = VGAHWPTR(scrninfp); - regp = &hwp->ModeReg; - - /* - * compute correct Hsync & Vsync polarity - */ - if ((mode->Flags & (V_PHSYNC | V_NHSYNC)) - && (mode->Flags & (V_PVSYNC | V_NVSYNC))) { - regp->MiscOutReg = 0x23; - if (mode->Flags & V_NHSYNC) - regp->MiscOutReg |= 0x40; - if (mode->Flags & V_NVSYNC) - regp->MiscOutReg |= 0x80; - } - else { - int VDisplay = mode->VDisplay; - - if (mode->Flags & V_DBLSCAN) - VDisplay *= 2; - if (mode->VScan > 1) - VDisplay *= mode->VScan; - if (VDisplay < 400) - regp->MiscOutReg = 0xA3; /* +hsync -vsync */ - else if (VDisplay < 480) - regp->MiscOutReg = 0x63; /* -hsync +vsync */ - else if (VDisplay < 768) - regp->MiscOutReg = 0xE3; /* -hsync -vsync */ - else - regp->MiscOutReg = 0x23; /* +hsync +vsync */ - } - - regp->MiscOutReg |= (mode->ClockIndex & 0x03) << 2; - - /* - * Time Sequencer - */ - if (depth == 4) - regp->Sequencer[0] = 0x02; - else - regp->Sequencer[0] = 0x00; - if (mode->Flags & V_CLKDIV2) - regp->Sequencer[1] = 0x09; - else - regp->Sequencer[1] = 0x01; - if (depth == 1) - regp->Sequencer[2] = 1 << BIT_PLANE; - else - regp->Sequencer[2] = 0x0F; - regp->Sequencer[3] = 0x00; /* Font select */ - if (depth < 8) - regp->Sequencer[4] = 0x06; /* Misc */ - else - regp->Sequencer[4] = 0x0E; /* Misc */ - - /* - * CRTC Controller - */ - regp->CRTC[0] = (mode->CrtcHTotal >> 3) - 5; - regp->CRTC[1] = (mode->CrtcHDisplay >> 3) - 1; - regp->CRTC[2] = (mode->CrtcHBlankStart >> 3) - 1; - regp->CRTC[3] = (((mode->CrtcHBlankEnd >> 3) - 1) & 0x1F) | 0x80; - i = (((mode->CrtcHSkew << 2) + 0x10) & ~0x1F); - if (i < 0x80) - regp->CRTC[3] |= i; - regp->CRTC[4] = (mode->CrtcHSyncStart >> 3); - regp->CRTC[5] = ((((mode->CrtcHBlankEnd >> 3) - 1) & 0x20) << 2) - | (((mode->CrtcHSyncEnd >> 3)) & 0x1F); - regp->CRTC[6] = (mode->CrtcVTotal - 2) & 0xFF; - regp->CRTC[7] = (((mode->CrtcVTotal - 2) & 0x100) >> 8) - | (((mode->CrtcVDisplay - 1) & 0x100) >> 7) - | ((mode->CrtcVSyncStart & 0x100) >> 6) - | (((mode->CrtcVBlankStart - 1) & 0x100) >> 5) - | 0x10 | (((mode->CrtcVTotal - 2) & 0x200) >> 4) - | (((mode->CrtcVDisplay - 1) & 0x200) >> 3) - | ((mode->CrtcVSyncStart & 0x200) >> 2); - regp->CRTC[8] = 0x00; - regp->CRTC[9] = (((mode->CrtcVBlankStart - 1) & 0x200) >> 4) | 0x40; - if (mode->Flags & V_DBLSCAN) - regp->CRTC[9] |= 0x80; - if (mode->VScan >= 32) - regp->CRTC[9] |= 0x1F; - else if (mode->VScan > 1) - regp->CRTC[9] |= mode->VScan - 1; - regp->CRTC[10] = 0x00; - regp->CRTC[11] = 0x00; - regp->CRTC[12] = 0x00; - regp->CRTC[13] = 0x00; - regp->CRTC[14] = 0x00; - regp->CRTC[15] = 0x00; - regp->CRTC[16] = mode->CrtcVSyncStart & 0xFF; - regp->CRTC[17] = (mode->CrtcVSyncEnd & 0x0F) | 0x20; - regp->CRTC[18] = (mode->CrtcVDisplay - 1) & 0xFF; - regp->CRTC[19] = scrninfp->displayWidth >> 4; /* just a guess */ - regp->CRTC[20] = 0x00; - regp->CRTC[21] = (mode->CrtcVBlankStart - 1) & 0xFF; - regp->CRTC[22] = (mode->CrtcVBlankEnd - 1) & 0xFF; - if (depth < 8) - regp->CRTC[23] = 0xE3; - else - regp->CRTC[23] = 0xC3; - regp->CRTC[24] = 0xFF; - - vgaHWHBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO); - vgaHWVBlankKGA(mode, regp, 0, KGA_FIX_OVERSCAN | KGA_ENABLE_ON_ZERO); - - /* - * Theory resumes here.... - */ - - /* - * Graphics Display Controller - */ - regp->Graphics[0] = 0x00; - regp->Graphics[1] = 0x00; - regp->Graphics[2] = 0x00; - regp->Graphics[3] = 0x00; - if (depth == 1) { - regp->Graphics[4] = BIT_PLANE; - regp->Graphics[5] = 0x00; - } - else { - regp->Graphics[4] = 0x00; - if (depth == 4) - regp->Graphics[5] = 0x02; - else - regp->Graphics[5] = 0x40; - } - regp->Graphics[6] = 0x05; /* only map 64k VGA memory !!!! */ - regp->Graphics[7] = 0x0F; - regp->Graphics[8] = 0xFF; - - if (depth == 1) { - /* Initialise the Mono map according to which bit-plane gets used */ - - for (i = 0; i < 16; i++) - if ((i & (1 << BIT_PLANE)) != 0) - regp->Attribute[i] = WHITE_VALUE; - else - regp->Attribute[i] = BLACK_VALUE; - - regp->Attribute[16] = 0x01; /* -VGA2- *//* wrong for the ET4000 */ - if (!hwp->ShowOverscan) - regp->Attribute[OVERSCAN] = OVERSCAN_VALUE; /* -VGA2- */ - } - else { - regp->Attribute[0] = 0x00; /* standard colormap translation */ - regp->Attribute[1] = 0x01; - regp->Attribute[2] = 0x02; - regp->Attribute[3] = 0x03; - regp->Attribute[4] = 0x04; - regp->Attribute[5] = 0x05; - regp->Attribute[6] = 0x06; - regp->Attribute[7] = 0x07; - regp->Attribute[8] = 0x08; - regp->Attribute[9] = 0x09; - regp->Attribute[10] = 0x0A; - regp->Attribute[11] = 0x0B; - regp->Attribute[12] = 0x0C; - regp->Attribute[13] = 0x0D; - regp->Attribute[14] = 0x0E; - regp->Attribute[15] = 0x0F; - if (depth == 4) - regp->Attribute[16] = 0x81; /* wrong for the ET4000 */ - else - regp->Attribute[16] = 0x41; /* wrong for the ET4000 */ - /* Attribute[17] (overscan) initialised in vgaHWGetHWRec() */ - } - regp->Attribute[18] = 0x0F; - regp->Attribute[19] = 0x00; - regp->Attribute[20] = 0x00; - - return TRUE; -} - - /* - * OK, so much for theory. Now, let's deal with the >real< world... - * - * The above CRTC settings are precise in theory, except that many, if not - * most, VGA clones fail to reset the blanking signal when the character or - * line counter reaches [HV]Total. In this case, the signal is only - * unblanked when the counter reaches [HV]BlankEnd (mod 64, 128 or 256 as - * the case may be) at the start of the >next< scanline or frame, which - * means only part of the screen shows. This affects how null overscans - * are to be implemented on such adapters. - * - * Henceforth, VGA cores that implement this broken, but unfortunately - * common, behaviour are to be designated as KGA's, in honour of Koen - * Gadeyne, whose zeal to eliminate overscans (read: fury) set in motion - * a series of events that led to the discovery of this problem. - * - * Some VGA's are KGA's only in the horizontal, or only in the vertical, - * some in both, others in neither. Don't let anyone tell you there is - * such a thing as a VGA "standard"... And, thank the Creator for the fact - * that Hilbert spaces are not yet implemented in this industry. - * - * The following implements a trick suggested by David Dawes. This sets - * [HV]BlankEnd to zero if the blanking interval does not already contain a - * 0-point, and decrements it by one otherwise. In the latter case, this - * will produce a left and/or top overscan which the colourmap code will - * (still) need to ensure is as close to black as possible. This will make - * the behaviour consistent across all chipsets, while allowing all - * chipsets to display the entire screen. Non-KGA drivers can ignore the - * following in their own copy of this code. - * - * -- TSI @ UQV, 1998.08.21 - */ - -CARD32 -vgaHWHBlankKGA(DisplayModePtr mode, vgaRegPtr regp, int nBits, - unsigned int Flags) -{ - int nExtBits = (nBits < 6) ? 0 : nBits - 6; - CARD32 ExtBits; - CARD32 ExtBitMask = ((1 << nExtBits) - 1) << 6; - - regp->CRTC[3] = (regp->CRTC[3] & ~0x1F) - | (((mode->CrtcHBlankEnd >> 3) - 1) & 0x1F); - regp->CRTC[5] = (regp->CRTC[5] & ~0x80) - | ((((mode->CrtcHBlankEnd >> 3) - 1) & 0x20) << 2); - ExtBits = ((mode->CrtcHBlankEnd >> 3) - 1) & ExtBitMask; - - /* First the horizontal case */ - if ((Flags & KGA_FIX_OVERSCAN) - && ((mode->CrtcHBlankEnd >> 3) == (mode->CrtcHTotal >> 3))) { - int i = (regp->CRTC[3] & 0x1F) - | ((regp->CRTC[5] & 0x80) >> 2) - | ExtBits; - - if (Flags & KGA_ENABLE_ON_ZERO) { - if ((i-- > (((mode->CrtcHBlankStart >> 3) - 1) - & (0x3F | ExtBitMask))) - && (mode->CrtcHBlankEnd == mode->CrtcHTotal)) - i = 0; - } - else if (Flags & KGA_BE_TOT_DEC) - i--; - regp->CRTC[3] = (regp->CRTC[3] & ~0x1F) | (i & 0x1F); - regp->CRTC[5] = (regp->CRTC[5] & ~0x80) | ((i << 2) & 0x80); - ExtBits = i & ExtBitMask; - } - return ExtBits >> 6; -} - - /* - * The vertical case is a little trickier. Some VGA's ignore bit 0x80 of - * CRTC[22]. Also, in some cases, a zero CRTC[22] will still blank the - * very first scanline in a double- or multi-scanned mode. This last case - * needs further investigation. - */ -CARD32 -vgaHWVBlankKGA(DisplayModePtr mode, vgaRegPtr regp, int nBits, - unsigned int Flags) -{ - CARD32 ExtBits; - CARD32 nExtBits = (nBits < 8) ? 0 : (nBits - 8); - CARD32 ExtBitMask = ((1 << nExtBits) - 1) << 8; - - /* If width is not known nBits should be 0. In this - * case BitMask is set to 0 so we can check for it. */ - CARD32 BitMask = (nBits < 7) ? 0 : ((1 << nExtBits) - 1); - int VBlankStart = (mode->CrtcVBlankStart - 1) & 0xFF; - - regp->CRTC[22] = (mode->CrtcVBlankEnd - 1) & 0xFF; - ExtBits = (mode->CrtcVBlankEnd - 1) & ExtBitMask; - - if ((Flags & KGA_FIX_OVERSCAN) - && (mode->CrtcVBlankEnd == mode->CrtcVTotal)) - /* Null top overscan */ - { - int i = regp->CRTC[22] | ExtBits; - - if (Flags & KGA_ENABLE_ON_ZERO) { - if (((BitMask && ((i & BitMask) > (VBlankStart & BitMask))) - || ((i > VBlankStart) && /* 8-bit case */ - ((i & 0x7F) > (VBlankStart & 0x7F)))) && /* 7-bit case */ - !(regp->CRTC[9] & 0x9F)) /* 1 scanline/row */ - i = 0; - else - i = (i - 1); - } - else if (Flags & KGA_BE_TOT_DEC) - i = (i - 1); - - regp->CRTC[22] = i & 0xFF; - ExtBits = i & 0xFF00; - } - return ExtBits >> 8; -} - -/* - * these are some more hardware specific helpers, formerly in vga.c - */ -static void -vgaHWGetHWRecPrivate(void) -{ - if (vgaHWPrivateIndex < 0) - vgaHWPrivateIndex = xf86AllocateScrnInfoPrivateIndex(); - return; -} - -static void -vgaHWFreeRegs(vgaRegPtr regp) -{ - free(regp->CRTC); - - regp->CRTC = regp->Sequencer = regp->Graphics = regp->Attribute = NULL; - - regp->numCRTC = - regp->numSequencer = regp->numGraphics = regp->numAttribute = 0; -} - -static Bool -vgaHWAllocRegs(vgaRegPtr regp) -{ - unsigned char *buf; - - if ((regp->numCRTC + regp->numSequencer + regp->numGraphics + - regp->numAttribute) == 0) - return FALSE; - - buf = calloc(regp->numCRTC + - regp->numSequencer + - regp->numGraphics + regp->numAttribute, 1); - if (!buf) - return FALSE; - - regp->CRTC = buf; - regp->Sequencer = regp->CRTC + regp->numCRTC; - regp->Graphics = regp->Sequencer + regp->numSequencer; - regp->Attribute = regp->Graphics + regp->numGraphics; - - return TRUE; -} - -Bool -vgaHWAllocDefaultRegs(vgaRegPtr regp) -{ - regp->numCRTC = VGA_NUM_CRTC; - regp->numSequencer = VGA_NUM_SEQ; - regp->numGraphics = VGA_NUM_GFX; - regp->numAttribute = VGA_NUM_ATTR; - - return vgaHWAllocRegs(regp); -} - -Bool -vgaHWSetRegCounts(ScrnInfoPtr scrp, int numCRTC, int numSequencer, - int numGraphics, int numAttribute) -{ -#define VGAHWMINNUM(regtype) \ - ((newMode.num##regtype < regp->num##regtype) ? \ - (newMode.num##regtype) : (regp->num##regtype)) -#define VGAHWCOPYREGSET(regtype) \ - memcpy (newMode.regtype, regp->regtype, VGAHWMINNUM(regtype)) - - vgaRegRec newMode, newSaved; - vgaRegPtr regp; - - regp = &VGAHWPTR(scrp)->ModeReg; - memcpy(&newMode, regp, sizeof(vgaRegRec)); - - /* allocate space for new registers */ - - regp = &newMode; - regp->numCRTC = numCRTC; - regp->numSequencer = numSequencer; - regp->numGraphics = numGraphics; - regp->numAttribute = numAttribute; - if (!vgaHWAllocRegs(regp)) - return FALSE; - - regp = &VGAHWPTR(scrp)->SavedReg; - memcpy(&newSaved, regp, sizeof(vgaRegRec)); - - regp = &newSaved; - regp->numCRTC = numCRTC; - regp->numSequencer = numSequencer; - regp->numGraphics = numGraphics; - regp->numAttribute = numAttribute; - if (!vgaHWAllocRegs(regp)) { - vgaHWFreeRegs(&newMode); - return FALSE; - } - - /* allocations succeeded, copy register data into new space */ - - regp = &VGAHWPTR(scrp)->ModeReg; - VGAHWCOPYREGSET(CRTC); - VGAHWCOPYREGSET(Sequencer); - VGAHWCOPYREGSET(Graphics); - VGAHWCOPYREGSET(Attribute); - - regp = &VGAHWPTR(scrp)->SavedReg; - VGAHWCOPYREGSET(CRTC); - VGAHWCOPYREGSET(Sequencer); - VGAHWCOPYREGSET(Graphics); - VGAHWCOPYREGSET(Attribute); - - /* free old register arrays */ - - regp = &VGAHWPTR(scrp)->ModeReg; - vgaHWFreeRegs(regp); - memcpy(regp, &newMode, sizeof(vgaRegRec)); - - regp = &VGAHWPTR(scrp)->SavedReg; - vgaHWFreeRegs(regp); - memcpy(regp, &newSaved, sizeof(vgaRegRec)); - - return TRUE; - -#undef VGAHWMINNUM -#undef VGAHWCOPYREGSET -} - -Bool -vgaHWCopyReg(vgaRegPtr dst, vgaRegPtr src) -{ - vgaHWFreeRegs(dst); - - memcpy(dst, src, sizeof(vgaRegRec)); - - if (!vgaHWAllocRegs(dst)) - return FALSE; - - memcpy(dst->CRTC, src->CRTC, src->numCRTC); - memcpy(dst->Sequencer, src->Sequencer, src->numSequencer); - memcpy(dst->Graphics, src->Graphics, src->numGraphics); - memcpy(dst->Attribute, src->Attribute, src->numAttribute); - - return TRUE; -} - -Bool -vgaHWGetHWRec(ScrnInfoPtr scrp) -{ - vgaRegPtr regp; - vgaHWPtr hwp; - int i; - - /* - * Let's make sure that the private exists and allocate one. - */ - vgaHWGetHWRecPrivate(); - /* - * New privates are always set to NULL, so we can check if the allocation - * has already been done. - */ - if (VGAHWPTR(scrp)) - return TRUE; - hwp = VGAHWPTRLVAL(scrp) = xnfcalloc(sizeof(vgaHWRec), 1); - regp = &VGAHWPTR(scrp)->ModeReg; - - if ((!vgaHWAllocDefaultRegs(&VGAHWPTR(scrp)->SavedReg)) || - (!vgaHWAllocDefaultRegs(&VGAHWPTR(scrp)->ModeReg))) { - free(hwp); - return FALSE; - } - - if (scrp->bitsPerPixel == 1) { - rgb blackColour = scrp->display->blackColour, - whiteColour = scrp->display->whiteColour; - - if (blackColour.red > 0x3F) - blackColour.red = 0x3F; - if (blackColour.green > 0x3F) - blackColour.green = 0x3F; - if (blackColour.blue > 0x3F) - blackColour.blue = 0x3F; - - if (whiteColour.red > 0x3F) - whiteColour.red = 0x3F; - if (whiteColour.green > 0x3F) - whiteColour.green = 0x3F; - if (whiteColour.blue > 0x3F) - whiteColour.blue = 0x3F; - - if ((blackColour.red == whiteColour.red) && - (blackColour.green == whiteColour.green) && - (blackColour.blue == whiteColour.blue)) { - blackColour.red ^= 0x3F; - blackColour.green ^= 0x3F; - blackColour.blue ^= 0x3F; - } - - /* - * initialize default colormap for monochrome - */ - for (i = 0; i < 3; i++) - regp->DAC[i] = 0x00; - for (i = 3; i < 768; i++) - regp->DAC[i] = 0x3F; - i = BLACK_VALUE * 3; - regp->DAC[i++] = blackColour.red; - regp->DAC[i++] = blackColour.green; - regp->DAC[i] = blackColour.blue; - i = WHITE_VALUE * 3; - regp->DAC[i++] = whiteColour.red; - regp->DAC[i++] = whiteColour.green; - regp->DAC[i] = whiteColour.blue; - i = OVERSCAN_VALUE * 3; - regp->DAC[i++] = 0x00; - regp->DAC[i++] = 0x00; - regp->DAC[i] = 0x00; - } - else { - /* Set all colours to black */ - for (i = 0; i < 768; i++) - regp->DAC[i] = 0x00; - /* ... and the overscan */ - if (scrp->depth >= 4) - regp->Attribute[OVERSCAN] = 0xFF; - } - if (xf86FindOption(scrp->confScreen->options, "ShowOverscan")) { - xf86MarkOptionUsedByName(scrp->confScreen->options, "ShowOverscan"); - xf86DrvMsg(scrp->scrnIndex, X_CONFIG, "Showing overscan area\n"); - regp->DAC[765] = 0x3F; - regp->DAC[766] = 0x00; - regp->DAC[767] = 0x3F; - regp->Attribute[OVERSCAN] = 0xFF; - hwp->ShowOverscan = TRUE; - } - else - hwp->ShowOverscan = FALSE; - - hwp->paletteEnabled = FALSE; - hwp->cmapSaved = FALSE; - hwp->MapSize = 0; - hwp->pScrn = scrp; - - hwp->dev = xf86GetPciInfoForEntity(scrp->entityList[0]); - - return TRUE; -} - -void -vgaHWFreeHWRec(ScrnInfoPtr scrp) -{ - if (vgaHWPrivateIndex >= 0) { - vgaHWPtr hwp = VGAHWPTR(scrp); - - if (!hwp) - return; - - pci_device_close_io(hwp->dev, hwp->io); - - free(hwp->FontInfo1); - free(hwp->FontInfo2); - free(hwp->TextInfo); - - vgaHWFreeRegs(&hwp->ModeReg); - vgaHWFreeRegs(&hwp->SavedReg); - - free(hwp); - VGAHWPTRLVAL(scrp) = NULL; - } -} - -Bool -vgaHWMapMem(ScrnInfoPtr scrp) -{ - vgaHWPtr hwp = VGAHWPTR(scrp); - - if (hwp->Base) - return TRUE; - - /* If not set, initialise with the defaults */ - if (hwp->MapSize == 0) - hwp->MapSize = VGA_DEFAULT_MEM_SIZE; - if (hwp->MapPhys == 0) - hwp->MapPhys = VGA_DEFAULT_PHYS_ADDR; - - /* - * Map as VIDMEM_MMIO_32BIT because WC - * is bad when there is page flipping. - * XXX This is not correct but we do it - * for now. - */ - DebugF("Mapping VGAMem\n"); - pci_device_map_legacy(hwp->dev, hwp->MapPhys, hwp->MapSize, - PCI_DEV_MAP_FLAG_WRITABLE, &hwp->Base); - return hwp->Base != NULL; -} - -void -vgaHWUnmapMem(ScrnInfoPtr scrp) -{ - vgaHWPtr hwp = VGAHWPTR(scrp); - - if (hwp->Base == NULL) - return; - - DebugF("Unmapping VGAMem\n"); - pci_device_unmap_legacy(hwp->dev, hwp->Base, hwp->MapSize); - hwp->Base = NULL; -} - -int -vgaHWGetIndex(void) -{ - return vgaHWPrivateIndex; -} - -void -vgaHWGetIOBase(vgaHWPtr hwp) -{ - hwp->IOBase = (hwp->readMiscOut(hwp) & 0x01) ? - VGA_IOBASE_COLOR : VGA_IOBASE_MONO; - xf86DrvMsgVerb(hwp->pScrn->scrnIndex, X_INFO, 3, - "vgaHWGetIOBase: hwp->IOBase is 0x%04x\n", hwp->IOBase); -} - -void -vgaHWLock(vgaHWPtr hwp) -{ - /* Protect CRTC[0-7] */ - hwp->writeCrtc(hwp, 0x11, hwp->readCrtc(hwp, 0x11) | 0x80); -} - -void -vgaHWUnlock(vgaHWPtr hwp) -{ - /* Unprotect CRTC[0-7] */ - hwp->writeCrtc(hwp, 0x11, hwp->readCrtc(hwp, 0x11) & ~0x80); -} - -void -vgaHWEnable(vgaHWPtr hwp) -{ - hwp->writeEnable(hwp, hwp->readEnable(hwp) | 0x01); -} - -void -vgaHWDisable(vgaHWPtr hwp) -{ - hwp->writeEnable(hwp, hwp->readEnable(hwp) & ~0x01); -} - -static void -vgaHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, LOCO * colors, - VisualPtr pVisual) -{ - vgaHWPtr hwp = VGAHWPTR(pScrn); - int i, index; - - for (i = 0; i < numColors; i++) { - index = indices[i]; - hwp->writeDacWriteAddr(hwp, index); - DACDelay(hwp); - hwp->writeDacData(hwp, colors[index].red); - DACDelay(hwp); - hwp->writeDacData(hwp, colors[index].green); - DACDelay(hwp); - hwp->writeDacData(hwp, colors[index].blue); - DACDelay(hwp); - } - - /* This shouldn't be necessary, but we'll play safe. */ - hwp->disablePalette(hwp); -} - -static void -vgaHWSetOverscan(ScrnInfoPtr pScrn, int overscan) -{ - vgaHWPtr hwp = VGAHWPTR(pScrn); - - if (overscan < 0 || overscan > 255) - return; - - hwp->enablePalette(hwp); - hwp->writeAttr(hwp, OVERSCAN, overscan); - -#ifdef DEBUGOVERSCAN - { - int ov = hwp->readAttr(hwp, OVERSCAN); - int red, green, blue; - - hwp->writeDacReadAddr(hwp, ov); - red = hwp->readDacData(hwp); - green = hwp->readDacData(hwp); - blue = hwp->readDacData(hwp); - ErrorF("Overscan index is 0x%02x, colours are #%02x%02x%02x\n", - ov, red, green, blue); - } -#endif - - hwp->disablePalette(hwp); -} - -Bool -vgaHWHandleColormaps(ScreenPtr pScreen) -{ - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); - - if (pScrn->depth > 1 && pScrn->depth <= 8) { - return xf86HandleColormaps(pScreen, 1 << pScrn->depth, - pScrn->rgbBits, vgaHWLoadPalette, - pScrn->depth > 4 ? vgaHWSetOverscan : NULL, - CMAP_RELOAD_ON_MODE_SWITCH); - } - return TRUE; -} - -/* ----------------------- DDC support ------------------------*/ -/* - * Adjust v_active, v_blank, v_sync, v_sync_end, v_blank_end, v_total - * to read out EDID at a faster rate. Allowed maximum is 25kHz with - * 20 usec v_sync active. Set positive v_sync polarity, turn off lightpen - * readback, enable access to cr00-cr07. - */ - -/* vertical timings */ -#define DISPLAY_END 0x04 -#define BLANK_START DISPLAY_END -#define SYNC_START BLANK_START -#define SYNC_END 0x09 -#define BLANK_END SYNC_END -#define V_TOTAL BLANK_END -/* this function doesn't have to be reentrant for our purposes */ -struct _vgaDdcSave { - unsigned char cr03; - unsigned char cr06; - unsigned char cr07; - unsigned char cr09; - unsigned char cr10; - unsigned char cr11; - unsigned char cr12; - unsigned char cr15; - unsigned char cr16; - unsigned char msr; -}; - -void -vgaHWddc1SetSpeed(ScrnInfoPtr pScrn, xf86ddcSpeed speed) -{ - vgaHWPtr hwp = VGAHWPTR(pScrn); - unsigned char tmp; - struct _vgaDdcSave *save; - - switch (speed) { - case DDC_FAST: - - if (hwp->ddc != NULL) - break; - hwp->ddc = xnfcalloc(sizeof(struct _vgaDdcSave), 1); - save = (struct _vgaDdcSave *) hwp->ddc; - /* Lightpen register disable - allow access to cr10 & 11; just in case */ - save->cr03 = hwp->readCrtc(hwp, 0x03); - hwp->writeCrtc(hwp, 0x03, (save->cr03 | 0x80)); - save->cr12 = hwp->readCrtc(hwp, 0x12); - hwp->writeCrtc(hwp, 0x12, DISPLAY_END); - save->cr15 = hwp->readCrtc(hwp, 0x15); - hwp->writeCrtc(hwp, 0x15, BLANK_START); - save->cr10 = hwp->readCrtc(hwp, 0x10); - hwp->writeCrtc(hwp, 0x10, SYNC_START); - save->cr11 = hwp->readCrtc(hwp, 0x11); - /* unprotect group 1 registers; just in case ... */ - hwp->writeCrtc(hwp, 0x11, ((save->cr11 & 0x70) | SYNC_END)); - save->cr16 = hwp->readCrtc(hwp, 0x16); - hwp->writeCrtc(hwp, 0x16, BLANK_END); - save->cr06 = hwp->readCrtc(hwp, 0x06); - hwp->writeCrtc(hwp, 0x06, V_TOTAL); - /* all values have less than 8 bit - mask out 9th and 10th bits */ - save->cr09 = hwp->readCrtc(hwp, 0x09); - hwp->writeCrtc(hwp, 0x09, (save->cr09 & 0xDF)); - save->cr07 = hwp->readCrtc(hwp, 0x07); - hwp->writeCrtc(hwp, 0x07, (save->cr07 & 0x10)); - /* vsync polarity negative & ensure a 25MHz clock */ - save->msr = hwp->readMiscOut(hwp); - hwp->writeMiscOut(hwp, ((save->msr & 0xF3) | 0x80)); - break; - case DDC_SLOW: - if (hwp->ddc == NULL) - break; - save = (struct _vgaDdcSave *) hwp->ddc; - hwp->writeMiscOut(hwp, save->msr); - hwp->writeCrtc(hwp, 0x07, save->cr07); - tmp = hwp->readCrtc(hwp, 0x09); - hwp->writeCrtc(hwp, 0x09, ((save->cr09 & 0x20) | (tmp & 0xDF))); - hwp->writeCrtc(hwp, 0x06, save->cr06); - hwp->writeCrtc(hwp, 0x16, save->cr16); - hwp->writeCrtc(hwp, 0x11, save->cr11); - hwp->writeCrtc(hwp, 0x10, save->cr10); - hwp->writeCrtc(hwp, 0x15, save->cr15); - hwp->writeCrtc(hwp, 0x12, save->cr12); - hwp->writeCrtc(hwp, 0x03, save->cr03); - free(save); - hwp->ddc = NULL; - break; - default: - break; - } -} - -DDC1SetSpeedProc -vgaHWddc1SetSpeedWeak(void) -{ - return vgaHWddc1SetSpeed; -} - -SaveScreenProcPtr -vgaHWSaveScreenWeak(void) -{ - return vgaHWSaveScreen; -} - -/* - * xf86GetClocks -- get the dot-clocks via a BIG BAD hack ... - */ -void -xf86GetClocks(ScrnInfoPtr pScrn, int num, Bool (*ClockFunc) (ScrnInfoPtr, int), - void (*ProtectRegs) (ScrnInfoPtr, Bool), - void (*BlankScreen) (ScrnInfoPtr, Bool), - unsigned long vertsyncreg, int maskval, int knownclkindex, - int knownclkvalue) -{ - register int status = vertsyncreg; - unsigned long i, cnt, rcnt, sync; - vgaHWPtr hwp = VGAHWPTR(pScrn); - - /* First save registers that get written on */ - (*ClockFunc) (pScrn, CLK_REG_SAVE); - - if (num > MAXCLOCKS) - num = MAXCLOCKS; - - for (i = 0; i < num; i++) { - if (ProtectRegs) - (*ProtectRegs) (pScrn, TRUE); - if (!(*ClockFunc) (pScrn, i)) { - pScrn->clock[i] = -1; - continue; - } - if (ProtectRegs) - (*ProtectRegs) (pScrn, FALSE); - if (BlankScreen) - (*BlankScreen) (pScrn, FALSE); - - usleep(50000); /* let VCO stabilise */ - - cnt = 0; - sync = 200000; - - while ((pci_io_read8(hwp->io, status) & maskval) == 0x00) - if (sync-- == 0) - goto finish; - /* Something appears to be happening, so reset sync count */ - sync = 200000; - while ((pci_io_read8(hwp->io, status) & maskval) == maskval) - if (sync-- == 0) - goto finish; - /* Something appears to be happening, so reset sync count */ - sync = 200000; - while ((pci_io_read8(hwp->io, status) & maskval) == 0x00) - if (sync-- == 0) - goto finish; - - for (rcnt = 0; rcnt < 5; rcnt++) { - while (!(pci_io_read8(hwp->io, status) & maskval)) - cnt++; - while ((pci_io_read8(hwp->io, status) & maskval)) - cnt++; - } - - finish: - pScrn->clock[i] = cnt ? cnt : -1; - if (BlankScreen) - (*BlankScreen) (pScrn, TRUE); - } - - for (i = 0; i < num; i++) { - if (i != knownclkindex) { - if (pScrn->clock[i] == -1) { - pScrn->clock[i] = 0; - } - else { - pScrn->clock[i] = (int) (0.5 + - (((float) knownclkvalue) * - pScrn->clock[knownclkindex]) / - (pScrn->clock[i])); - /* Round to nearest 10KHz */ - pScrn->clock[i] += 5; - pScrn->clock[i] /= 10; - pScrn->clock[i] *= 10; - } - } - } - - pScrn->clock[knownclkindex] = knownclkvalue; - pScrn->numClocks = num; - - /* Restore registers that were written on */ - (*ClockFunc) (pScrn, CLK_REG_RESTORE); -} diff --git a/hw/xfree86/vgahw/vgaHW.h b/hw/xfree86/vgahw/vgaHW.h deleted file mode 100644 index 0fa80da45..000000000 --- a/hw/xfree86/vgahw/vgaHW.h +++ /dev/null @@ -1,237 +0,0 @@ - -/* - * Copyright (c) 1997,1998 The XFree86 Project, Inc. - * - * Loosely based on code bearing the following copyright: - * - * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany. - * - * Author: Dirk Hohndel - */ - -#ifndef _VGAHW_H -#define _VGAHW_H - -#include -#include "misc.h" -#include "input.h" -#include "scrnintstr.h" -#include "colormapst.h" - -#include "xf86str.h" -#include "xf86Pci.h" - -#include "xf86DDC.h" - -#include "globals.h" -#include - -extern _X_EXPORT int vgaHWGetIndex(void); - -/* - * access macro - */ -#define VGAHWPTR(p) ((vgaHWPtr)((p)->privates[vgaHWGetIndex()].ptr)) - -/* Standard VGA registers */ -#define VGA_ATTR_INDEX 0x3C0 -#define VGA_ATTR_DATA_W 0x3C0 -#define VGA_ATTR_DATA_R 0x3C1 -#define VGA_IN_STAT_0 0x3C2 /* read */ -#define VGA_MISC_OUT_W 0x3C2 /* write */ -#define VGA_ENABLE 0x3C3 -#define VGA_SEQ_INDEX 0x3C4 -#define VGA_SEQ_DATA 0x3C5 -#define VGA_DAC_MASK 0x3C6 -#define VGA_DAC_READ_ADDR 0x3C7 -#define VGA_DAC_WRITE_ADDR 0x3C8 -#define VGA_DAC_DATA 0x3C9 -#define VGA_FEATURE_R 0x3CA /* read */ -#define VGA_MISC_OUT_R 0x3CC /* read */ -#define VGA_GRAPH_INDEX 0x3CE -#define VGA_GRAPH_DATA 0x3CF - -#define VGA_IOBASE_MONO 0x3B0 -#define VGA_IOBASE_COLOR 0x3D0 - -#define VGA_CRTC_INDEX_OFFSET 0x04 -#define VGA_CRTC_DATA_OFFSET 0x05 -#define VGA_IN_STAT_1_OFFSET 0x0A /* read */ -#define VGA_FEATURE_W_OFFSET 0x0A /* write */ - -/* default number of VGA registers stored internally */ -#define VGA_NUM_CRTC 25 -#define VGA_NUM_SEQ 5 -#define VGA_NUM_GFX 9 -#define VGA_NUM_ATTR 21 - -/* Flags for vgaHWSave() and vgaHWRestore() */ -#define VGA_SR_MODE 0x01 -#define VGA_SR_FONTS 0x02 -#define VGA_SR_CMAP 0x04 -#define VGA_SR_ALL (VGA_SR_MODE | VGA_SR_FONTS | VGA_SR_CMAP) - -/* Defaults for the VGA memory window */ -#define VGA_DEFAULT_PHYS_ADDR 0xA0000 -#define VGA_DEFAULT_MEM_SIZE (64 * 1024) - -/* - * vgaRegRec contains settings of standard VGA registers. - */ -typedef struct { - unsigned char MiscOutReg; /* */ - unsigned char *CRTC; /* Crtc Controller */ - unsigned char *Sequencer; /* Video Sequencer */ - unsigned char *Graphics; /* Video Graphics */ - unsigned char *Attribute; /* Video Attribute */ - unsigned char DAC[768]; /* Internal Colorlookuptable */ - unsigned char numCRTC; /* number of CRTC registers, def=VGA_NUM_CRTC */ - unsigned char numSequencer; /* number of seq registers, def=VGA_NUM_SEQ */ - unsigned char numGraphics; /* number of gfx registers, def=VGA_NUM_GFX */ - unsigned char numAttribute; /* number of attr registers, def=VGA_NUM_ATTR */ -} vgaRegRec, *vgaRegPtr; - -typedef struct _vgaHWRec *vgaHWPtr; - -typedef void (*vgaHWWriteIndexProcPtr) (vgaHWPtr hwp, CARD8 indx, CARD8 value); -typedef CARD8 (*vgaHWReadIndexProcPtr) (vgaHWPtr hwp, CARD8 indx); -typedef void (*vgaHWWriteProcPtr) (vgaHWPtr hwp, CARD8 value); -typedef CARD8 (*vgaHWReadProcPtr) (vgaHWPtr hwp); -typedef void (*vgaHWMiscProcPtr) (vgaHWPtr hwp); - -/* - * vgaHWRec contains per-screen information required by the vgahw module. - * - * Note, the palette referred to by the paletteEnabled, enablePalette and - * disablePalette is the 16-entry (+overscan) EGA-compatible palette accessed - * via the first 17 attribute registers and not the main 8-bit palette. - */ -typedef struct _vgaHWRec { - void *Base; /* Address of "VGA" memory */ - int MapSize; /* Size of "VGA" memory */ - unsigned long MapPhys; /* phys location of VGA mem */ - int IOBase; /* I/O Base address */ - CARD8 *MMIOBase; /* Pointer to MMIO start */ - int MMIOOffset; /* base + offset + vgareg - = mmioreg */ - void *FontInfo1; /* save area for fonts in - plane 2 */ - void *FontInfo2; /* save area for fonts in - plane 3 */ - void *TextInfo; /* save area for text */ - vgaRegRec SavedReg; /* saved registers */ - vgaRegRec ModeReg; /* register settings for - current mode */ - Bool ShowOverscan; - Bool paletteEnabled; - Bool cmapSaved; - ScrnInfoPtr pScrn; - vgaHWWriteIndexProcPtr writeCrtc; - vgaHWReadIndexProcPtr readCrtc; - vgaHWWriteIndexProcPtr writeGr; - vgaHWReadIndexProcPtr readGr; - vgaHWReadProcPtr readST00; - vgaHWReadProcPtr readST01; - vgaHWReadProcPtr readFCR; - vgaHWWriteProcPtr writeFCR; - vgaHWWriteIndexProcPtr writeAttr; - vgaHWReadIndexProcPtr readAttr; - vgaHWWriteIndexProcPtr writeSeq; - vgaHWReadIndexProcPtr readSeq; - vgaHWWriteProcPtr writeMiscOut; - vgaHWReadProcPtr readMiscOut; - vgaHWMiscProcPtr enablePalette; - vgaHWMiscProcPtr disablePalette; - vgaHWWriteProcPtr writeDacMask; - vgaHWReadProcPtr readDacMask; - vgaHWWriteProcPtr writeDacWriteAddr; - vgaHWWriteProcPtr writeDacReadAddr; - vgaHWWriteProcPtr writeDacData; - vgaHWReadProcPtr readDacData; - void *ddc; - struct pci_io_handle *io; - vgaHWReadProcPtr readEnable; - vgaHWWriteProcPtr writeEnable; - struct pci_device *dev; -} vgaHWRec; - -/* Some macros that VGA drivers can use in their ChipProbe() function */ -#define OVERSCAN 0x11 /* Index of OverScan register */ - -/* Flags that define how overscan correction should take place */ -#define KGA_FIX_OVERSCAN 1 /* overcan correction required */ -#define KGA_ENABLE_ON_ZERO 2 /* if possible enable display at beginning */ - /* of next scanline/frame */ -#define KGA_BE_TOT_DEC 4 /* always fix problem by setting blank end */ - /* to total - 1 */ -#define BIT_PLANE 3 /* Which plane we write to in mono mode */ -#define BITS_PER_GUN 6 -#define COLORMAP_SIZE 256 - -#define DACDelay(hw) \ - do { \ - (hw)->readST01((hw)); \ - (hw)->readST01((hw)); \ - } while (0) - -/* Function Prototypes */ - -/* vgaHW.c */ - -typedef void vgaHWProtectProc(ScrnInfoPtr, Bool); -typedef void vgaHWBlankScreenProc(ScrnInfoPtr, Bool); - -extern _X_EXPORT void vgaHWSetStdFuncs(vgaHWPtr hwp); -extern _X_EXPORT void vgaHWSetMmioFuncs(vgaHWPtr hwp, CARD8 *base, int offset); -extern _X_EXPORT void vgaHWProtect(ScrnInfoPtr pScrn, Bool on); -extern _X_EXPORT vgaHWProtectProc *vgaHWProtectWeak(void); -extern _X_EXPORT Bool vgaHWSaveScreen(ScreenPtr pScreen, int mode); -extern _X_EXPORT void vgaHWBlankScreen(ScrnInfoPtr pScrn, Bool on); -extern _X_EXPORT vgaHWBlankScreenProc *vgaHWBlankScreenWeak(void); -extern _X_EXPORT void vgaHWSeqReset(vgaHWPtr hwp, Bool start); -extern _X_EXPORT void vgaHWRestoreFonts(ScrnInfoPtr scrninfp, - vgaRegPtr restore); -extern _X_EXPORT void vgaHWRestoreMode(ScrnInfoPtr scrninfp, vgaRegPtr restore); -extern _X_EXPORT void vgaHWRestoreColormap(ScrnInfoPtr scrninfp, - vgaRegPtr restore); -extern _X_EXPORT void vgaHWRestore(ScrnInfoPtr scrninfp, vgaRegPtr restore, - int flags); -extern _X_EXPORT void vgaHWSaveFonts(ScrnInfoPtr scrninfp, vgaRegPtr save); -extern _X_EXPORT void vgaHWSaveMode(ScrnInfoPtr scrninfp, vgaRegPtr save); -extern _X_EXPORT void vgaHWSaveColormap(ScrnInfoPtr scrninfp, vgaRegPtr save); -extern _X_EXPORT void vgaHWSave(ScrnInfoPtr scrninfp, vgaRegPtr save, - int flags); -extern _X_EXPORT Bool vgaHWInit(ScrnInfoPtr scrnp, DisplayModePtr mode); -extern _X_EXPORT Bool vgaHWSetRegCounts(ScrnInfoPtr scrp, int numCRTC, - int numSequencer, int numGraphics, - int numAttribute); -extern _X_EXPORT Bool vgaHWCopyReg(vgaRegPtr dst, vgaRegPtr src); -extern _X_EXPORT Bool vgaHWGetHWRec(ScrnInfoPtr scrp); -extern _X_EXPORT void vgaHWFreeHWRec(ScrnInfoPtr scrp); -extern _X_EXPORT Bool vgaHWMapMem(ScrnInfoPtr scrp); -extern _X_EXPORT void vgaHWUnmapMem(ScrnInfoPtr scrp); -extern _X_EXPORT void vgaHWGetIOBase(vgaHWPtr hwp); -extern _X_EXPORT void vgaHWLock(vgaHWPtr hwp); -extern _X_EXPORT void vgaHWUnlock(vgaHWPtr hwp); -extern _X_EXPORT void vgaHWEnable(vgaHWPtr hwp); -extern _X_EXPORT void vgaHWDisable(vgaHWPtr hwp); -extern _X_EXPORT void vgaHWDPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, - int flags); -extern _X_EXPORT Bool vgaHWHandleColormaps(ScreenPtr pScreen); -extern _X_EXPORT void vgaHWddc1SetSpeed(ScrnInfoPtr pScrn, xf86ddcSpeed speed); -extern _X_EXPORT CARD32 vgaHWHBlankKGA(DisplayModePtr mode, vgaRegPtr regp, - int nBits, unsigned int Flags); -extern _X_EXPORT CARD32 vgaHWVBlankKGA(DisplayModePtr mode, vgaRegPtr regp, - int nBits, unsigned int Flags); -extern _X_EXPORT Bool vgaHWAllocDefaultRegs(vgaRegPtr regp); - -extern _X_EXPORT DDC1SetSpeedProc vgaHWddc1SetSpeedWeak(void); -extern _X_EXPORT SaveScreenProcPtr vgaHWSaveScreenWeak(void); -extern _X_EXPORT void xf86GetClocks(ScrnInfoPtr pScrn, int num, - Bool (*ClockFunc) (ScrnInfoPtr, int), - void (*ProtectRegs) (ScrnInfoPtr, Bool), - void (*BlankScreen) (ScrnInfoPtr, Bool), - unsigned long vertsyncreg, int maskval, - int knownclkindex, int knownclkvalue); - -#endif /* _VGAHW_H */ diff --git a/hw/xfree86/vgahw/vgaHWmodule.c b/hw/xfree86/vgahw/vgaHWmodule.c deleted file mode 100644 index 0c5a43aa6..000000000 --- a/hw/xfree86/vgahw/vgaHWmodule.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 1998 by The XFree86 Project, Inc - */ - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include "xf86Module.h" - -static XF86ModuleVersionInfo VersRec = { - "vgahw", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_NONE, - {0, 0, 0, 0} -}; - -_X_EXPORT XF86ModuleData vgahwModuleData = { &VersRec, NULL, NULL }; diff --git a/hw/xfree86/x86emu/debug.c b/hw/xfree86/x86emu/debug.c deleted file mode 100644 index 576ace55e..000000000 --- a/hw/xfree86/x86emu/debug.c +++ /dev/null @@ -1,487 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: This file contains the code to handle debugging of the -* emulator. -* -****************************************************************************/ - -#include "x86emu/x86emui.h" -#include -#include -#include -#ifndef NO_SYS_HEADERS -#include -#endif - -/*----------------------------- Implementation ----------------------------*/ - -#ifdef DEBUG - -static void print_encoded_bytes(u16 s, u16 o); -static void print_decoded_instruction(void); -static int parse_line(char *s, int *ps, int *n); - -/* should look something like debug's output. */ -void -X86EMU_trace_regs(void) -{ - if (DEBUG_TRACE()) { - x86emu_dump_regs(); - } - if (DEBUG_DECODE() && !DEBUG_DECODE_NOPRINT()) { - printk("%04x:%04x ", M.x86.saved_cs, M.x86.saved_ip); - print_encoded_bytes(M.x86.saved_cs, M.x86.saved_ip); - print_decoded_instruction(); - } -} - -void -X86EMU_trace_xregs(void) -{ - if (DEBUG_TRACE()) { - x86emu_dump_xregs(); - } -} - -void -x86emu_just_disassemble(void) -{ - /* - * This routine called if the flag DEBUG_DISASSEMBLE is set kind - * of a hack! - */ - printk("%04x:%04x ", M.x86.saved_cs, M.x86.saved_ip); - print_encoded_bytes(M.x86.saved_cs, M.x86.saved_ip); - print_decoded_instruction(); -} - -static void -disassemble_forward(u16 seg, u16 off, int n) -{ - X86EMU_sysEnv tregs; - int i; - u8 op1; - - /* - * hack, hack, hack. What we do is use the exact machinery set up - * for execution, except that now there is an additional state - * flag associated with the "execution", and we are using a copy - * of the register struct. All the major opcodes, once fully - * decoded, have the following two steps: TRACE_REGS(r,m); - * SINGLE_STEP(r,m); which disappear if DEBUG is not defined to - * the preprocessor. The TRACE_REGS macro expands to: - * - * if (debug&DEBUG_DISASSEMBLE) - * {just_disassemble(); goto EndOfInstruction;} - * if (debug&DEBUG_TRACE) trace_regs(r,m); - * - * ...... and at the last line of the routine. - * - * EndOfInstruction: end_instr(); - * - * Up to the point where TRACE_REG is expanded, NO modifications - * are done to any register EXCEPT the IP register, for fetch and - * decoding purposes. - * - * This was done for an entirely different reason, but makes a - * nice way to get the system to help debug codes. - */ - tregs = M; - tregs.x86.R_IP = off; - tregs.x86.R_CS = seg; - - /* reset the decoding buffers */ - tregs.x86.enc_str_pos = 0; - tregs.x86.enc_pos = 0; - - /* turn on the "disassemble only, no execute" flag */ - tregs.x86.debug |= DEBUG_DISASSEMBLE_F; - - /* DUMP NEXT n instructions to screen in straight_line fashion */ - /* - * This looks like the regular instruction fetch stream, except - * that when this occurs, each fetched opcode, upon seeing the - * DEBUG_DISASSEMBLE flag set, exits immediately after decoding - * the instruction. XXX --- CHECK THAT MEM IS NOT AFFECTED!!! - * Note the use of a copy of the register structure... - */ - for (i = 0; i < n; i++) { - op1 = (*sys_rdb) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP++)); - (x86emu_optab[op1]) (op1); - } - /* end major hack mode. */ -} - -void -x86emu_check_ip_access(void) -{ - /* NULL as of now */ -} - -void -x86emu_check_sp_access(void) -{ -} - -void -x86emu_check_mem_access(u32 dummy) -{ - /* check bounds, etc */ -} - -void -x86emu_check_data_access(uint dummy1, uint dummy2) -{ - /* check bounds, etc */ -} - -void -x86emu_inc_decoded_inst_len(int x) -{ - M.x86.enc_pos += x; -} - -void -x86emu_decode_printf(const char *x, ...) -{ - va_list ap; - char temp[100]; - - va_start(ap, x); - vsnprintf(temp, sizeof(temp), x, ap); - va_end(ap); - sprintf(M.x86.decoded_buf + M.x86.enc_str_pos, "%s", temp); - M.x86.enc_str_pos += strlen(temp); -} - -void -x86emu_end_instr(void) -{ - M.x86.enc_str_pos = 0; - M.x86.enc_pos = 0; -} - -static void -print_encoded_bytes(u16 s, u16 o) -{ - int i; - char buf1[64]; - - for (i = 0; i < M.x86.enc_pos; i++) { - sprintf(buf1 + 2 * i, "%02x", fetch_data_byte_abs(s, o + i)); - } - printk("%-20s", buf1); -} - -static void -print_decoded_instruction(void) -{ - printk("%s", M.x86.decoded_buf); -} - -void -x86emu_print_int_vect(u16 iv) -{ - u16 seg, off; - - if (iv > 256) - return; - seg = fetch_data_word_abs(0, iv * 4); - off = fetch_data_word_abs(0, iv * 4 + 2); - printk("%04x:%04x ", seg, off); -} - -void -X86EMU_dump_memory(u16 seg, u16 off, u32 amt) -{ - u32 start = off & 0xfffffff0; - u32 end = (off + 16) & 0xfffffff0; - u32 i; - - while (end <= off + amt) { - printk("%04x:%04x ", seg, start); - for (i = start; i < off; i++) - printk(" "); - for (; i < end; i++) - printk("%02x ", fetch_data_byte_abs(seg, i)); - printk("\n"); - start = end; - end = start + 16; - } -} - -void -x86emu_single_step(void) -{ - char s[1024]; - int ps[10]; - int ntok; - int cmd; - int done; - int segment; - int offset; - static int breakpoint; - static int noDecode = 1; - - if (DEBUG_BREAK()) { - if (M.x86.saved_ip != breakpoint) { - return; - } - else { - M.x86.debug &= ~DEBUG_DECODE_NOPRINT_F; - M.x86.debug |= DEBUG_TRACE_F; - M.x86.debug &= ~DEBUG_BREAK_F; - print_decoded_instruction(); - X86EMU_trace_regs(); - } - } - done = 0; - offset = M.x86.saved_ip; - while (!done) { - printk("-"); - (void)fgets(s, 1023, stdin); - cmd = parse_line(s, ps, &ntok); - switch (cmd) { - case 'u': - disassemble_forward(M.x86.saved_cs, (u16) offset, 10); - break; - case 'd': - if (ntok == 2) { - segment = M.x86.saved_cs; - offset = ps[1]; - X86EMU_dump_memory(segment, (u16) offset, 16); - offset += 16; - } - else if (ntok == 3) { - segment = ps[1]; - offset = ps[2]; - X86EMU_dump_memory(segment, (u16) offset, 16); - offset += 16; - } - else { - segment = M.x86.saved_cs; - X86EMU_dump_memory(segment, (u16) offset, 16); - offset += 16; - } - break; - case 'c': - M.x86.debug ^= DEBUG_TRACECALL_F; - break; - case 's': - M.x86.debug ^= DEBUG_SVC_F | DEBUG_SYS_F | DEBUG_SYSINT_F; - break; - case 'r': - X86EMU_trace_regs(); - break; - case 'x': - X86EMU_trace_xregs(); - break; - case 'g': - if (ntok == 2) { - breakpoint = ps[1]; - if (noDecode) { - M.x86.debug |= DEBUG_DECODE_NOPRINT_F; - } - else { - M.x86.debug &= ~DEBUG_DECODE_NOPRINT_F; - } - M.x86.debug &= ~DEBUG_TRACE_F; - M.x86.debug |= DEBUG_BREAK_F; - done = 1; - } - break; - case 'q': - M.x86.debug |= DEBUG_EXIT; - return; - case 'P': - noDecode = (noDecode) ? 0 : 1; - printk("Toggled decoding to %s\n", (noDecode) ? "FALSE" : "TRUE"); - break; - case 't': - case 0: - done = 1; - break; - } - } -} - -int -X86EMU_trace_on(void) -{ - return M.x86.debug |= DEBUG_STEP_F | DEBUG_DECODE_F | DEBUG_TRACE_F; -} - -int -X86EMU_trace_off(void) -{ - return M.x86.debug &= ~(DEBUG_STEP_F | DEBUG_DECODE_F | DEBUG_TRACE_F); -} - -static int -parse_line(char *s, int *ps, int *n) -{ - int cmd; - - *n = 0; - while (*s == ' ' || *s == '\t') - s++; - ps[*n] = *s; - switch (*s) { - case '\n': - *n += 1; - return 0; - default: - cmd = *s; - *n += 1; - } - - while (1) { - while (*s != ' ' && *s != '\t' && *s != '\n') - s++; - - if (*s == '\n') - return cmd; - - while (*s == ' ' || *s == '\t') - s++; - - sscanf(s, "%x", &ps[*n]); - *n += 1; - } -} - -#endif /* DEBUG */ - -void -x86emu_dump_regs(void) -{ - printk("\tAX=%04x ", M.x86.R_AX); - printk("BX=%04x ", M.x86.R_BX); - printk("CX=%04x ", M.x86.R_CX); - printk("DX=%04x ", M.x86.R_DX); - printk("SP=%04x ", M.x86.R_SP); - printk("BP=%04x ", M.x86.R_BP); - printk("SI=%04x ", M.x86.R_SI); - printk("DI=%04x\n", M.x86.R_DI); - printk("\tDS=%04x ", M.x86.R_DS); - printk("ES=%04x ", M.x86.R_ES); - printk("SS=%04x ", M.x86.R_SS); - printk("CS=%04x ", M.x86.R_CS); - printk("IP=%04x ", M.x86.R_IP); - if (ACCESS_FLAG(F_OF)) - printk("OV "); /* CHECKED... */ - else - printk("NV "); - if (ACCESS_FLAG(F_DF)) - printk("DN "); - else - printk("UP "); - if (ACCESS_FLAG(F_IF)) - printk("EI "); - else - printk("DI "); - if (ACCESS_FLAG(F_SF)) - printk("NG "); - else - printk("PL "); - if (ACCESS_FLAG(F_ZF)) - printk("ZR "); - else - printk("NZ "); - if (ACCESS_FLAG(F_AF)) - printk("AC "); - else - printk("NA "); - if (ACCESS_FLAG(F_PF)) - printk("PE "); - else - printk("PO "); - if (ACCESS_FLAG(F_CF)) - printk("CY "); - else - printk("NC "); - printk("\n"); -} - -void -x86emu_dump_xregs(void) -{ - printk("\tEAX=%08x ", M.x86.R_EAX); - printk("EBX=%08x ", M.x86.R_EBX); - printk("ECX=%08x ", M.x86.R_ECX); - printk("EDX=%08x \n", M.x86.R_EDX); - printk("\tESP=%08x ", M.x86.R_ESP); - printk("EBP=%08x ", M.x86.R_EBP); - printk("ESI=%08x ", M.x86.R_ESI); - printk("EDI=%08x\n", M.x86.R_EDI); - printk("\tDS=%04x ", M.x86.R_DS); - printk("ES=%04x ", M.x86.R_ES); - printk("SS=%04x ", M.x86.R_SS); - printk("CS=%04x ", M.x86.R_CS); - printk("EIP=%08x\n\t", M.x86.R_EIP); - if (ACCESS_FLAG(F_OF)) - printk("OV "); /* CHECKED... */ - else - printk("NV "); - if (ACCESS_FLAG(F_DF)) - printk("DN "); - else - printk("UP "); - if (ACCESS_FLAG(F_IF)) - printk("EI "); - else - printk("DI "); - if (ACCESS_FLAG(F_SF)) - printk("NG "); - else - printk("PL "); - if (ACCESS_FLAG(F_ZF)) - printk("ZR "); - else - printk("NZ "); - if (ACCESS_FLAG(F_AF)) - printk("AC "); - else - printk("NA "); - if (ACCESS_FLAG(F_PF)) - printk("PE "); - else - printk("PO "); - if (ACCESS_FLAG(F_CF)) - printk("CY "); - else - printk("NC "); - printk("\n"); -} diff --git a/hw/xfree86/x86emu/decode.c b/hw/xfree86/x86emu/decode.c deleted file mode 100644 index 261d67b21..000000000 --- a/hw/xfree86/x86emu/decode.c +++ /dev/null @@ -1,1102 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: This file includes subroutines which are related to -* instruction decoding and accessess of immediate data via IP. etc. -* -****************************************************************************/ - -#include - -#if defined(__sun) && defined(CS) /* avoid conflicts with Solaris sys/regset.h */ -# undef CS -# undef DS -# undef SS -# undef ES -# undef FS -# undef GS -#endif - -#include "x86emu/x86emui.h" - -/*----------------------------- Implementation ----------------------------*/ - -/**************************************************************************** -REMARKS: -Handles any pending asychronous interrupts. -****************************************************************************/ -static void -x86emu_intr_handle(void) -{ - u8 intno; - - if (M.x86.intr & INTR_SYNCH) { - intno = M.x86.intno; - if (_X86EMU_intrTab[intno]) { - (*_X86EMU_intrTab[intno]) (intno); - } - else { - push_word((u16) M.x86.R_FLG); - CLEAR_FLAG(F_IF); - CLEAR_FLAG(F_TF); - push_word(M.x86.R_CS); - M.x86.R_CS = mem_access_word(intno * 4 + 2); - push_word(M.x86.R_IP); - M.x86.R_IP = mem_access_word(intno * 4); - M.x86.intr = 0; - } - } -} - -/**************************************************************************** -PARAMETERS: -intrnum - Interrupt number to raise - -REMARKS: -Raise the specified interrupt to be handled before the execution of the -next instruction. -****************************************************************************/ -void -x86emu_intr_raise(u8 intrnum) -{ - M.x86.intno = intrnum; - M.x86.intr |= INTR_SYNCH; -} - -/**************************************************************************** -REMARKS: -Main execution loop for the emulator. We return from here when the system -halts, which is normally caused by a stack fault when we return from the -original real mode call. -****************************************************************************/ -void -X86EMU_exec(void) -{ - u8 op1; - - M.x86.intr = 0; - DB(x86emu_end_instr(); - ) - - for (;;) { - DB(if (CHECK_IP_FETCH()) - x86emu_check_ip_access();) - /* If debugging, save the IP and CS values. */ - SAVE_IP_CS(M.x86.R_CS, M.x86.R_IP); - INC_DECODED_INST_LEN(1); - if (M.x86.intr) { - if (M.x86.intr & INTR_HALTED) { - DB(if (M.x86.R_SP != 0) { - printk("halted\n"); X86EMU_trace_regs();} - else { - if (M.x86.debug) - printk("Service completed successfully\n");} - ) - return; - } - if (((M.x86.intr & INTR_SYNCH) && - (M.x86.intno == 0 || M.x86.intno == 2)) || - !ACCESS_FLAG(F_IF)) { - x86emu_intr_handle(); - } - } - op1 = (*sys_rdb) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP++)); - (*x86emu_optab[op1]) (op1); - if (M.x86.debug & DEBUG_EXIT) { - M.x86.debug &= ~DEBUG_EXIT; - return; - } - } -} - -/**************************************************************************** -REMARKS: -Halts the system by setting the halted system flag. -****************************************************************************/ -void -X86EMU_halt_sys(void) -{ - M.x86.intr |= INTR_HALTED; -} - -/**************************************************************************** -PARAMETERS: -mod - Mod value from decoded byte -regh - Reg h value from decoded byte -regl - Reg l value from decoded byte - -REMARKS: -Raise the specified interrupt to be handled before the execution of the -next instruction. - -NOTE: Do not inline this function, as (*sys_rdb) is already inline! -****************************************************************************/ -void -fetch_decode_modrm(int *mod, int *regh, int *regl) -{ - int fetched; - - DB(if (CHECK_IP_FETCH()) - x86emu_check_ip_access();) - fetched = (*sys_rdb) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP++)); - INC_DECODED_INST_LEN(1); - *mod = (fetched >> 6) & 0x03; - *regh = (fetched >> 3) & 0x07; - *regl = (fetched >> 0) & 0x07; -} - -/**************************************************************************** -RETURNS: -Immediate byte value read from instruction queue - -REMARKS: -This function returns the immediate byte from the instruction queue, and -moves the instruction pointer to the next value. - -NOTE: Do not inline this function, as (*sys_rdb) is already inline! -****************************************************************************/ -u8 -fetch_byte_imm(void) -{ - u8 fetched; - - DB(if (CHECK_IP_FETCH()) - x86emu_check_ip_access();) - fetched = (*sys_rdb) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP++)); - INC_DECODED_INST_LEN(1); - return fetched; -} - -/**************************************************************************** -RETURNS: -Immediate word value read from instruction queue - -REMARKS: -This function returns the immediate byte from the instruction queue, and -moves the instruction pointer to the next value. - -NOTE: Do not inline this function, as (*sys_rdw) is already inline! -****************************************************************************/ -u16 -fetch_word_imm(void) -{ - u16 fetched; - - DB(if (CHECK_IP_FETCH()) - x86emu_check_ip_access();) - fetched = (*sys_rdw) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP)); - M.x86.R_IP += 2; - INC_DECODED_INST_LEN(2); - return fetched; -} - -/**************************************************************************** -RETURNS: -Immediate lone value read from instruction queue - -REMARKS: -This function returns the immediate byte from the instruction queue, and -moves the instruction pointer to the next value. - -NOTE: Do not inline this function, as (*sys_rdw) is already inline! -****************************************************************************/ -u32 -fetch_long_imm(void) -{ - u32 fetched; - - DB(if (CHECK_IP_FETCH()) - x86emu_check_ip_access();) - fetched = (*sys_rdl) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP)); - M.x86.R_IP += 4; - INC_DECODED_INST_LEN(4); - return fetched; -} - -/**************************************************************************** -RETURNS: -Value of the default data segment - -REMARKS: -Inline function that returns the default data segment for the current -instruction. - -On the x86 processor, the default segment is not always DS if there is -no segment override. Address modes such as -3[BP] or 10[BP+SI] all refer to -addresses relative to SS (ie: on the stack). So, at the minimum, all -decodings of addressing modes would have to set/clear a bit describing -whether the access is relative to DS or SS. That is the function of the -cpu-state-varible M.x86.mode. There are several potential states: - - repe prefix seen (handled elsewhere) - repne prefix seen (ditto) - - cs segment override - ds segment override - es segment override - fs segment override - gs segment override - ss segment override - - ds/ss select (in absence of override) - -Each of the above 7 items are handled with a bit in the mode field. -****************************************************************************/ -_INLINE u32 -get_data_segment(void) -{ -#define GET_SEGMENT(segment) - switch (M.x86.mode & SYSMODE_SEGMASK) { - case 0: /* default case: use ds register */ - case SYSMODE_SEGOVR_DS: - case SYSMODE_SEGOVR_DS | SYSMODE_SEG_DS_SS: - return M.x86.R_DS; - case SYSMODE_SEG_DS_SS: /* non-overridden, use ss register */ - return M.x86.R_SS; - case SYSMODE_SEGOVR_CS: - case SYSMODE_SEGOVR_CS | SYSMODE_SEG_DS_SS: - return M.x86.R_CS; - case SYSMODE_SEGOVR_ES: - case SYSMODE_SEGOVR_ES | SYSMODE_SEG_DS_SS: - return M.x86.R_ES; - case SYSMODE_SEGOVR_FS: - case SYSMODE_SEGOVR_FS | SYSMODE_SEG_DS_SS: - return M.x86.R_FS; - case SYSMODE_SEGOVR_GS: - case SYSMODE_SEGOVR_GS | SYSMODE_SEG_DS_SS: - return M.x86.R_GS; - case SYSMODE_SEGOVR_SS: - case SYSMODE_SEGOVR_SS | SYSMODE_SEG_DS_SS: - return M.x86.R_SS; - default: -#ifdef DEBUG - printk("error: should not happen: multiple overrides.\n"); -#endif - HALT_SYS(); - return 0; - } -} - -/**************************************************************************** -PARAMETERS: -offset - Offset to load data from - -RETURNS: -Byte value read from the absolute memory location. - -NOTE: Do not inline this function as (*sys_rdX) is already inline! -****************************************************************************/ -u8 -fetch_data_byte(uint offset) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access((u16) get_data_segment(), offset); -#endif - return (*sys_rdb) ((get_data_segment() << 4) + offset); -} - -/**************************************************************************** -PARAMETERS: -offset - Offset to load data from - -RETURNS: -Word value read from the absolute memory location. - -NOTE: Do not inline this function as (*sys_rdX) is already inline! -****************************************************************************/ -u16 -fetch_data_word(uint offset) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access((u16) get_data_segment(), offset); -#endif - return (*sys_rdw) ((get_data_segment() << 4) + offset); -} - -/**************************************************************************** -PARAMETERS: -offset - Offset to load data from - -RETURNS: -Long value read from the absolute memory location. - -NOTE: Do not inline this function as (*sys_rdX) is already inline! -****************************************************************************/ -u32 -fetch_data_long(uint offset) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access((u16) get_data_segment(), offset); -#endif - return (*sys_rdl) ((get_data_segment() << 4) + offset); -} - -/**************************************************************************** -PARAMETERS: -segment - Segment to load data from -offset - Offset to load data from - -RETURNS: -Byte value read from the absolute memory location. - -NOTE: Do not inline this function as (*sys_rdX) is already inline! -****************************************************************************/ -u8 -fetch_data_byte_abs(uint segment, uint offset) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access(segment, offset); -#endif - return (*sys_rdb) (((u32) segment << 4) + offset); -} - -/**************************************************************************** -PARAMETERS: -segment - Segment to load data from -offset - Offset to load data from - -RETURNS: -Word value read from the absolute memory location. - -NOTE: Do not inline this function as (*sys_rdX) is already inline! -****************************************************************************/ -u16 -fetch_data_word_abs(uint segment, uint offset) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access(segment, offset); -#endif - return (*sys_rdw) (((u32) segment << 4) + offset); -} - -/**************************************************************************** -PARAMETERS: -segment - Segment to load data from -offset - Offset to load data from - -RETURNS: -Long value read from the absolute memory location. - -NOTE: Do not inline this function as (*sys_rdX) is already inline! -****************************************************************************/ -u32 -fetch_data_long_abs(uint segment, uint offset) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access(segment, offset); -#endif - return (*sys_rdl) (((u32) segment << 4) + offset); -} - -/**************************************************************************** -PARAMETERS: -offset - Offset to store data at -val - Value to store - -REMARKS: -Writes a word value to an segmented memory location. The segment used is -the current 'default' segment, which may have been overridden. - -NOTE: Do not inline this function as (*sys_wrX) is already inline! -****************************************************************************/ -void -store_data_byte(uint offset, u8 val) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access((u16) get_data_segment(), offset); -#endif - (*sys_wrb) ((get_data_segment() << 4) + offset, val); -} - -/**************************************************************************** -PARAMETERS: -offset - Offset to store data at -val - Value to store - -REMARKS: -Writes a word value to an segmented memory location. The segment used is -the current 'default' segment, which may have been overridden. - -NOTE: Do not inline this function as (*sys_wrX) is already inline! -****************************************************************************/ -void -store_data_word(uint offset, u16 val) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access((u16) get_data_segment(), offset); -#endif - (*sys_wrw) ((get_data_segment() << 4) + offset, val); -} - -/**************************************************************************** -PARAMETERS: -offset - Offset to store data at -val - Value to store - -REMARKS: -Writes a long value to an segmented memory location. The segment used is -the current 'default' segment, which may have been overridden. - -NOTE: Do not inline this function as (*sys_wrX) is already inline! -****************************************************************************/ -void -store_data_long(uint offset, u32 val) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access((u16) get_data_segment(), offset); -#endif - (*sys_wrl) ((get_data_segment() << 4) + offset, val); -} - -/**************************************************************************** -PARAMETERS: -segment - Segment to store data at -offset - Offset to store data at -val - Value to store - -REMARKS: -Writes a byte value to an absolute memory location. - -NOTE: Do not inline this function as (*sys_wrX) is already inline! -****************************************************************************/ -void -store_data_byte_abs(uint segment, uint offset, u8 val) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access(segment, offset); -#endif - (*sys_wrb) (((u32) segment << 4) + offset, val); -} - -/**************************************************************************** -PARAMETERS: -segment - Segment to store data at -offset - Offset to store data at -val - Value to store - -REMARKS: -Writes a word value to an absolute memory location. - -NOTE: Do not inline this function as (*sys_wrX) is already inline! -****************************************************************************/ -void -store_data_word_abs(uint segment, uint offset, u16 val) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access(segment, offset); -#endif - (*sys_wrw) (((u32) segment << 4) + offset, val); -} - -/**************************************************************************** -PARAMETERS: -segment - Segment to store data at -offset - Offset to store data at -val - Value to store - -REMARKS: -Writes a long value to an absolute memory location. - -NOTE: Do not inline this function as (*sys_wrX) is already inline! -****************************************************************************/ -void -store_data_long_abs(uint segment, uint offset, u32 val) -{ -#ifdef DEBUG - if (CHECK_DATA_ACCESS()) - x86emu_check_data_access(segment, offset); -#endif - (*sys_wrl) (((u32) segment << 4) + offset, val); -} - -/**************************************************************************** -PARAMETERS: -reg - Register to decode - -RETURNS: -Pointer to the appropriate register - -REMARKS: -Return a pointer to the register given by the R/RM field of the -modrm byte, for byte operands. Also enables the decoding of instructions. -****************************************************************************/ -u8 * -decode_rm_byte_register(int reg) -{ - switch (reg) { - case 0: - DECODE_PRINTF("AL"); - return &M.x86.R_AL; - case 1: - DECODE_PRINTF("CL"); - return &M.x86.R_CL; - case 2: - DECODE_PRINTF("DL"); - return &M.x86.R_DL; - case 3: - DECODE_PRINTF("BL"); - return &M.x86.R_BL; - case 4: - DECODE_PRINTF("AH"); - return &M.x86.R_AH; - case 5: - DECODE_PRINTF("CH"); - return &M.x86.R_CH; - case 6: - DECODE_PRINTF("DH"); - return &M.x86.R_DH; - case 7: - DECODE_PRINTF("BH"); - return &M.x86.R_BH; - } - HALT_SYS(); - return NULL; /* NOT REACHED OR REACHED ON ERROR */ -} - -/**************************************************************************** -PARAMETERS: -reg - Register to decode - -RETURNS: -Pointer to the appropriate register - -REMARKS: -Return a pointer to the register given by the R/RM field of the -modrm byte, for word operands. Also enables the decoding of instructions. -****************************************************************************/ -u16 * -decode_rm_word_register(int reg) -{ - switch (reg) { - case 0: - DECODE_PRINTF("AX"); - return &M.x86.R_AX; - case 1: - DECODE_PRINTF("CX"); - return &M.x86.R_CX; - case 2: - DECODE_PRINTF("DX"); - return &M.x86.R_DX; - case 3: - DECODE_PRINTF("BX"); - return &M.x86.R_BX; - case 4: - DECODE_PRINTF("SP"); - return &M.x86.R_SP; - case 5: - DECODE_PRINTF("BP"); - return &M.x86.R_BP; - case 6: - DECODE_PRINTF("SI"); - return &M.x86.R_SI; - case 7: - DECODE_PRINTF("DI"); - return &M.x86.R_DI; - } - HALT_SYS(); - return NULL; /* NOTREACHED OR REACHED ON ERROR */ -} - -/**************************************************************************** -PARAMETERS: -reg - Register to decode - -RETURNS: -Pointer to the appropriate register - -REMARKS: -Return a pointer to the register given by the R/RM field of the -modrm byte, for dword operands. Also enables the decoding of instructions. -****************************************************************************/ -u32 * -decode_rm_long_register(int reg) -{ - switch (reg) { - case 0: - DECODE_PRINTF("EAX"); - return &M.x86.R_EAX; - case 1: - DECODE_PRINTF("ECX"); - return &M.x86.R_ECX; - case 2: - DECODE_PRINTF("EDX"); - return &M.x86.R_EDX; - case 3: - DECODE_PRINTF("EBX"); - return &M.x86.R_EBX; - case 4: - DECODE_PRINTF("ESP"); - return &M.x86.R_ESP; - case 5: - DECODE_PRINTF("EBP"); - return &M.x86.R_EBP; - case 6: - DECODE_PRINTF("ESI"); - return &M.x86.R_ESI; - case 7: - DECODE_PRINTF("EDI"); - return &M.x86.R_EDI; - } - HALT_SYS(); - return NULL; /* NOTREACHED OR REACHED ON ERROR */ -} - -/**************************************************************************** -PARAMETERS: -reg - Register to decode - -RETURNS: -Pointer to the appropriate register - -REMARKS: -Return a pointer to the register given by the R/RM field of the -modrm byte, for word operands, modified from above for the weirdo -special case of segreg operands. Also enables the decoding of instructions. -****************************************************************************/ -u16 * -decode_rm_seg_register(int reg) -{ - switch (reg) { - case 0: - DECODE_PRINTF("ES"); - return &M.x86.R_ES; - case 1: - DECODE_PRINTF("CS"); - return &M.x86.R_CS; - case 2: - DECODE_PRINTF("SS"); - return &M.x86.R_SS; - case 3: - DECODE_PRINTF("DS"); - return &M.x86.R_DS; - case 4: - DECODE_PRINTF("FS"); - return &M.x86.R_FS; - case 5: - DECODE_PRINTF("GS"); - return &M.x86.R_GS; - case 6: - case 7: - DECODE_PRINTF("ILLEGAL SEGREG"); - break; - } - HALT_SYS(); - return NULL; /* NOT REACHED OR REACHED ON ERROR */ -} - -/* - * - * return offset from the SIB Byte - */ -u32 -decode_sib_address(int sib, int mod) -{ - u32 base = 0, i = 0, scale = 1; - - switch (sib & 0x07) { - case 0: - DECODE_PRINTF("[EAX]"); - base = M.x86.R_EAX; - break; - case 1: - DECODE_PRINTF("[ECX]"); - base = M.x86.R_ECX; - break; - case 2: - DECODE_PRINTF("[EDX]"); - base = M.x86.R_EDX; - break; - case 3: - DECODE_PRINTF("[EBX]"); - base = M.x86.R_EBX; - break; - case 4: - DECODE_PRINTF("[ESP]"); - base = M.x86.R_ESP; - M.x86.mode |= SYSMODE_SEG_DS_SS; - break; - case 5: - if (mod == 0) { - base = fetch_long_imm(); - DECODE_PRINTF2("%08x", base); - } - else { - DECODE_PRINTF("[EBP]"); - base = M.x86.R_ESP; - M.x86.mode |= SYSMODE_SEG_DS_SS; - } - break; - case 6: - DECODE_PRINTF("[ESI]"); - base = M.x86.R_ESI; - break; - case 7: - DECODE_PRINTF("[EDI]"); - base = M.x86.R_EDI; - break; - } - switch ((sib >> 3) & 0x07) { - case 0: - DECODE_PRINTF("[EAX"); - i = M.x86.R_EAX; - break; - case 1: - DECODE_PRINTF("[ECX"); - i = M.x86.R_ECX; - break; - case 2: - DECODE_PRINTF("[EDX"); - i = M.x86.R_EDX; - break; - case 3: - DECODE_PRINTF("[EBX"); - i = M.x86.R_EBX; - break; - case 4: - i = 0; - break; - case 5: - DECODE_PRINTF("[EBP"); - i = M.x86.R_EBP; - break; - case 6: - DECODE_PRINTF("[ESI"); - i = M.x86.R_ESI; - break; - case 7: - DECODE_PRINTF("[EDI"); - i = M.x86.R_EDI; - break; - } - scale = 1 << ((sib >> 6) & 0x03); - if (((sib >> 3) & 0x07) != 4) { - if (scale == 1) { - DECODE_PRINTF("]"); - } - else { - DECODE_PRINTF2("*%d]", scale); - } - } - return base + (i * scale); -} - -/**************************************************************************** -PARAMETERS: -rm - RM value to decode - -RETURNS: -Offset in memory for the address decoding - -REMARKS: -Return the offset given by mod=00 addressing. Also enables the -decoding of instructions. - -NOTE: The code which specifies the corresponding segment (ds vs ss) - below in the case of [BP+..]. The assumption here is that at the - point that this subroutine is called, the bit corresponding to - SYSMODE_SEG_DS_SS will be zero. After every instruction - except the segment override instructions, this bit (as well - as any bits indicating segment overrides) will be clear. So - if a SS access is needed, set this bit. Otherwise, DS access - occurs (unless any of the segment override bits are set). -****************************************************************************/ -u32 -decode_rm00_address(int rm) -{ - u32 offset; - int sib; - - if (M.x86.mode & SYSMODE_PREFIX_ADDR) { - /* 32-bit addressing */ - switch (rm) { - case 0: - DECODE_PRINTF("[EAX]"); - return M.x86.R_EAX; - case 1: - DECODE_PRINTF("[ECX]"); - return M.x86.R_ECX; - case 2: - DECODE_PRINTF("[EDX]"); - return M.x86.R_EDX; - case 3: - DECODE_PRINTF("[EBX]"); - return M.x86.R_EBX; - case 4: - sib = fetch_byte_imm(); - return decode_sib_address(sib, 0); - case 5: - offset = fetch_long_imm(); - DECODE_PRINTF2("[%08x]", offset); - return offset; - case 6: - DECODE_PRINTF("[ESI]"); - return M.x86.R_ESI; - case 7: - DECODE_PRINTF("[EDI]"); - return M.x86.R_EDI; - } - HALT_SYS(); - } - else { - /* 16-bit addressing */ - switch (rm) { - case 0: - DECODE_PRINTF("[BX+SI]"); - return (M.x86.R_BX + M.x86.R_SI) & 0xffff; - case 1: - DECODE_PRINTF("[BX+DI]"); - return (M.x86.R_BX + M.x86.R_DI) & 0xffff; - case 2: - DECODE_PRINTF("[BP+SI]"); - M.x86.mode |= SYSMODE_SEG_DS_SS; - return (M.x86.R_BP + M.x86.R_SI) & 0xffff; - case 3: - DECODE_PRINTF("[BP+DI]"); - M.x86.mode |= SYSMODE_SEG_DS_SS; - return (M.x86.R_BP + M.x86.R_DI) & 0xffff; - case 4: - DECODE_PRINTF("[SI]"); - return M.x86.R_SI; - case 5: - DECODE_PRINTF("[DI]"); - return M.x86.R_DI; - case 6: - offset = fetch_word_imm(); - DECODE_PRINTF2("[%04x]", offset); - return offset; - case 7: - DECODE_PRINTF("[BX]"); - return M.x86.R_BX; - } - HALT_SYS(); - } - return 0; -} - -/**************************************************************************** -PARAMETERS: -rm - RM value to decode - -RETURNS: -Offset in memory for the address decoding - -REMARKS: -Return the offset given by mod=01 addressing. Also enables the -decoding of instructions. -****************************************************************************/ -u32 -decode_rm01_address(int rm) -{ - int displacement = 0; - int sib; - - /* Fetch disp8 if no SIB byte */ - if (!((M.x86.mode & SYSMODE_PREFIX_ADDR) && (rm == 4))) - displacement = (s8) fetch_byte_imm(); - - if (M.x86.mode & SYSMODE_PREFIX_ADDR) { - /* 32-bit addressing */ - switch (rm) { - case 0: - DECODE_PRINTF2("%d[EAX]", displacement); - return M.x86.R_EAX + displacement; - case 1: - DECODE_PRINTF2("%d[ECX]", displacement); - return M.x86.R_ECX + displacement; - case 2: - DECODE_PRINTF2("%d[EDX]", displacement); - return M.x86.R_EDX + displacement; - case 3: - DECODE_PRINTF2("%d[EBX]", displacement); - return M.x86.R_EBX + displacement; - case 4: - sib = fetch_byte_imm(); - displacement = (s8) fetch_byte_imm(); - DECODE_PRINTF2("%d", displacement); - return decode_sib_address(sib, 1) + displacement; - case 5: - DECODE_PRINTF2("%d[EBP]", displacement); - return M.x86.R_EBP + displacement; - case 6: - DECODE_PRINTF2("%d[ESI]", displacement); - return M.x86.R_ESI + displacement; - case 7: - DECODE_PRINTF2("%d[EDI]", displacement); - return M.x86.R_EDI + displacement; - } - HALT_SYS(); - } - else { - /* 16-bit addressing */ - switch (rm) { - case 0: - DECODE_PRINTF2("%d[BX+SI]", displacement); - return (M.x86.R_BX + M.x86.R_SI + displacement) & 0xffff; - case 1: - DECODE_PRINTF2("%d[BX+DI]", displacement); - return (M.x86.R_BX + M.x86.R_DI + displacement) & 0xffff; - case 2: - DECODE_PRINTF2("%d[BP+SI]", displacement); - M.x86.mode |= SYSMODE_SEG_DS_SS; - return (M.x86.R_BP + M.x86.R_SI + displacement) & 0xffff; - case 3: - DECODE_PRINTF2("%d[BP+DI]", displacement); - M.x86.mode |= SYSMODE_SEG_DS_SS; - return (M.x86.R_BP + M.x86.R_DI + displacement) & 0xffff; - case 4: - DECODE_PRINTF2("%d[SI]", displacement); - return (M.x86.R_SI + displacement) & 0xffff; - case 5: - DECODE_PRINTF2("%d[DI]", displacement); - return (M.x86.R_DI + displacement) & 0xffff; - case 6: - DECODE_PRINTF2("%d[BP]", displacement); - M.x86.mode |= SYSMODE_SEG_DS_SS; - return (M.x86.R_BP + displacement) & 0xffff; - case 7: - DECODE_PRINTF2("%d[BX]", displacement); - return (M.x86.R_BX + displacement) & 0xffff; - } - HALT_SYS(); - } - return 0; /* SHOULD NOT HAPPEN */ -} - -/**************************************************************************** -PARAMETERS: -rm - RM value to decode - -RETURNS: -Offset in memory for the address decoding - -REMARKS: -Return the offset given by mod=10 addressing. Also enables the -decoding of instructions. -****************************************************************************/ -u32 -decode_rm10_address(int rm) -{ - u32 displacement = 0; - int sib; - - /* Fetch disp16 if 16-bit addr mode */ - if (!(M.x86.mode & SYSMODE_PREFIX_ADDR)) - displacement = (u16) fetch_word_imm(); - else { - /* Fetch disp32 if no SIB byte */ - if (rm != 4) - displacement = (u32) fetch_long_imm(); - } - - if (M.x86.mode & SYSMODE_PREFIX_ADDR) { - /* 32-bit addressing */ - switch (rm) { - case 0: - DECODE_PRINTF2("%08x[EAX]", displacement); - return M.x86.R_EAX + displacement; - case 1: - DECODE_PRINTF2("%08x[ECX]", displacement); - return M.x86.R_ECX + displacement; - case 2: - DECODE_PRINTF2("%08x[EDX]", displacement); - M.x86.mode |= SYSMODE_SEG_DS_SS; - return M.x86.R_EDX + displacement; - case 3: - DECODE_PRINTF2("%08x[EBX]", displacement); - return M.x86.R_EBX + displacement; - case 4: - sib = fetch_byte_imm(); - displacement = (u32) fetch_long_imm(); - DECODE_PRINTF2("%08x", displacement); - return decode_sib_address(sib, 2) + displacement; - break; - case 5: - DECODE_PRINTF2("%08x[EBP]", displacement); - return M.x86.R_EBP + displacement; - case 6: - DECODE_PRINTF2("%08x[ESI]", displacement); - return M.x86.R_ESI + displacement; - case 7: - DECODE_PRINTF2("%08x[EDI]", displacement); - return M.x86.R_EDI + displacement; - } - HALT_SYS(); - } - else { - /* 16-bit addressing */ - switch (rm) { - case 0: - DECODE_PRINTF2("%04x[BX+SI]", displacement); - return (M.x86.R_BX + M.x86.R_SI + displacement) & 0xffff; - case 1: - DECODE_PRINTF2("%04x[BX+DI]", displacement); - return (M.x86.R_BX + M.x86.R_DI + displacement) & 0xffff; - case 2: - DECODE_PRINTF2("%04x[BP+SI]", displacement); - M.x86.mode |= SYSMODE_SEG_DS_SS; - return (M.x86.R_BP + M.x86.R_SI + displacement) & 0xffff; - case 3: - DECODE_PRINTF2("%04x[BP+DI]", displacement); - M.x86.mode |= SYSMODE_SEG_DS_SS; - return (M.x86.R_BP + M.x86.R_DI + displacement) & 0xffff; - case 4: - DECODE_PRINTF2("%04x[SI]", displacement); - return (M.x86.R_SI + displacement) & 0xffff; - case 5: - DECODE_PRINTF2("%04x[DI]", displacement); - return (M.x86.R_DI + displacement) & 0xffff; - case 6: - DECODE_PRINTF2("%04x[BP]", displacement); - M.x86.mode |= SYSMODE_SEG_DS_SS; - return (M.x86.R_BP + displacement) & 0xffff; - case 7: - DECODE_PRINTF2("%04x[BX]", displacement); - return (M.x86.R_BX + displacement) & 0xffff; - } - HALT_SYS(); - } - return 0; - /*NOTREACHED */ -} diff --git a/hw/xfree86/x86emu/fpu.c b/hw/xfree86/x86emu/fpu.c deleted file mode 100644 index 0dab05ce3..000000000 --- a/hw/xfree86/x86emu/fpu.c +++ /dev/null @@ -1,976 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: This file contains the code to implement the decoding and -* emulation of the FPU instructions. -* -****************************************************************************/ - -#include "x86emu/x86emui.h" - -/*----------------------------- Implementation ----------------------------*/ - -/* opcode=0xd8 */ -void -x86emuOp_esc_coprocess_d8(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("ESC D8\n"); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR_NO_TRACE(); -} - -#ifdef DEBUG - -static const char *x86emu_fpu_op_d9_tab[] = { - "FLD\tDWORD PTR ", "ESC_D9\t", "FST\tDWORD PTR ", "FSTP\tDWORD PTR ", - "FLDENV\t", "FLDCW\t", "FSTENV\t", "FSTCW\t", - - "FLD\tDWORD PTR ", "ESC_D9\t", "FST\tDWORD PTR ", "FSTP\tDWORD PTR ", - "FLDENV\t", "FLDCW\t", "FSTENV\t", "FSTCW\t", - - "FLD\tDWORD PTR ", "ESC_D9\t", "FST\tDWORD PTR ", "FSTP\tDWORD PTR ", - "FLDENV\t", "FLDCW\t", "FSTENV\t", "FSTCW\t", -}; - -static const char *x86emu_fpu_op_d9_tab1[] = { - "FLD\t", "FLD\t", "FLD\t", "FLD\t", - "FLD\t", "FLD\t", "FLD\t", "FLD\t", - - "FXCH\t", "FXCH\t", "FXCH\t", "FXCH\t", - "FXCH\t", "FXCH\t", "FXCH\t", "FXCH\t", - - "FNOP", "ESC_D9", "ESC_D9", "ESC_D9", - "ESC_D9", "ESC_D9", "ESC_D9", "ESC_D9", - - "FSTP\t", "FSTP\t", "FSTP\t", "FSTP\t", - "FSTP\t", "FSTP\t", "FSTP\t", "FSTP\t", - - "FCHS", "FABS", "ESC_D9", "ESC_D9", - "FTST", "FXAM", "ESC_D9", "ESC_D9", - - "FLD1", "FLDL2T", "FLDL2E", "FLDPI", - "FLDLG2", "FLDLN2", "FLDZ", "ESC_D9", - - "F2XM1", "FYL2X", "FPTAN", "FPATAN", - "FXTRACT", "ESC_D9", "FDECSTP", "FINCSTP", - - "FPREM", "FYL2XP1", "FSQRT", "ESC_D9", - "FRNDINT", "FSCALE", "ESC_D9", "ESC_D9", -}; - -#endif /* DEBUG */ - -/* opcode=0xd9 */ -void -x86emuOp_esc_coprocess_d9(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset = 0; - u8 stkelem = 0; - - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (mod != 3) { - DECODE_PRINTINSTR32(x86emu_fpu_op_d9_tab, mod, rh, rl); - } - else { - DECODE_PRINTF(x86emu_fpu_op_d9_tab1[(rh << 3) + rl]); - } -#endif - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - break; - case 3: /* register to register */ - stkelem = (u8) rl; - if (rh < 4) { - DECODE_PRINTF2("ST(%d)\n", stkelem); - } - else { - DECODE_PRINTF("\n"); - } - break; - } -#ifdef X86EMU_FPU_PRESENT - /* execute */ - switch (mod) { - case 3: - switch (rh) { - case 0: - x86emu_fpu_R_fld(X86EMU_FPU_STKTOP, stkelem); - break; - case 1: - x86emu_fpu_R_fxch(X86EMU_FPU_STKTOP, stkelem); - break; - case 2: - switch (rl) { - case 0: - x86emu_fpu_R_nop(); - break; - default: - x86emu_fpu_illegal(); - break; - } - case 3: - x86emu_fpu_R_fstp(X86EMU_FPU_STKTOP, stkelem); - break; - case 4: - switch (rl) { - case 0: - x86emu_fpu_R_fchs(X86EMU_FPU_STKTOP); - break; - case 1: - x86emu_fpu_R_fabs(X86EMU_FPU_STKTOP); - break; - case 4: - x86emu_fpu_R_ftst(X86EMU_FPU_STKTOP); - break; - case 5: - x86emu_fpu_R_fxam(X86EMU_FPU_STKTOP); - break; - default: - /* 2,3,6,7 */ - x86emu_fpu_illegal(); - break; - } - break; - - case 5: - switch (rl) { - case 0: - x86emu_fpu_R_fld1(X86EMU_FPU_STKTOP); - break; - case 1: - x86emu_fpu_R_fldl2t(X86EMU_FPU_STKTOP); - break; - case 2: - x86emu_fpu_R_fldl2e(X86EMU_FPU_STKTOP); - break; - case 3: - x86emu_fpu_R_fldpi(X86EMU_FPU_STKTOP); - break; - case 4: - x86emu_fpu_R_fldlg2(X86EMU_FPU_STKTOP); - break; - case 5: - x86emu_fpu_R_fldln2(X86EMU_FPU_STKTOP); - break; - case 6: - x86emu_fpu_R_fldz(X86EMU_FPU_STKTOP); - break; - default: - /* 7 */ - x86emu_fpu_illegal(); - break; - } - break; - - case 6: - switch (rl) { - case 0: - x86emu_fpu_R_f2xm1(X86EMU_FPU_STKTOP); - break; - case 1: - x86emu_fpu_R_fyl2x(X86EMU_FPU_STKTOP); - break; - case 2: - x86emu_fpu_R_fptan(X86EMU_FPU_STKTOP); - break; - case 3: - x86emu_fpu_R_fpatan(X86EMU_FPU_STKTOP); - break; - case 4: - x86emu_fpu_R_fxtract(X86EMU_FPU_STKTOP); - break; - case 5: - x86emu_fpu_illegal(); - break; - case 6: - x86emu_fpu_R_decstp(); - break; - case 7: - x86emu_fpu_R_incstp(); - break; - } - break; - - case 7: - switch (rl) { - case 0: - x86emu_fpu_R_fprem(X86EMU_FPU_STKTOP); - break; - case 1: - x86emu_fpu_R_fyl2xp1(X86EMU_FPU_STKTOP); - break; - case 2: - x86emu_fpu_R_fsqrt(X86EMU_FPU_STKTOP); - break; - case 3: - x86emu_fpu_illegal(); - break; - case 4: - x86emu_fpu_R_frndint(X86EMU_FPU_STKTOP); - break; - case 5: - x86emu_fpu_R_fscale(X86EMU_FPU_STKTOP); - break; - case 6: - case 7: - default: - x86emu_fpu_illegal(); - break; - } - break; - - default: - switch (rh) { - case 0: - x86emu_fpu_M_fld(X86EMU_FPU_FLOAT, destoffset); - break; - case 1: - x86emu_fpu_illegal(); - break; - case 2: - x86emu_fpu_M_fst(X86EMU_FPU_FLOAT, destoffset); - break; - case 3: - x86emu_fpu_M_fstp(X86EMU_FPU_FLOAT, destoffset); - break; - case 4: - x86emu_fpu_M_fldenv(X86EMU_FPU_WORD, destoffset); - break; - case 5: - x86emu_fpu_M_fldcw(X86EMU_FPU_WORD, destoffset); - break; - case 6: - x86emu_fpu_M_fstenv(X86EMU_FPU_WORD, destoffset); - break; - case 7: - x86emu_fpu_M_fstcw(X86EMU_FPU_WORD, destoffset); - break; - } - } - } -#else - (void) destoffset; - (void) stkelem; -#endif /* X86EMU_FPU_PRESENT */ - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR_NO_TRACE(); -} - -#ifdef DEBUG - -static const char *x86emu_fpu_op_da_tab[] = { - "FIADD\tDWORD PTR ", "FIMUL\tDWORD PTR ", "FICOM\tDWORD PTR ", - "FICOMP\tDWORD PTR ", - "FISUB\tDWORD PTR ", "FISUBR\tDWORD PTR ", "FIDIV\tDWORD PTR ", - "FIDIVR\tDWORD PTR ", - - "FIADD\tDWORD PTR ", "FIMUL\tDWORD PTR ", "FICOM\tDWORD PTR ", - "FICOMP\tDWORD PTR ", - "FISUB\tDWORD PTR ", "FISUBR\tDWORD PTR ", "FIDIV\tDWORD PTR ", - "FIDIVR\tDWORD PTR ", - - "FIADD\tDWORD PTR ", "FIMUL\tDWORD PTR ", "FICOM\tDWORD PTR ", - "FICOMP\tDWORD PTR ", - "FISUB\tDWORD PTR ", "FISUBR\tDWORD PTR ", "FIDIV\tDWORD PTR ", - "FIDIVR\tDWORD PTR ", - - "ESC_DA ", "ESC_DA ", "ESC_DA ", "ESC_DA ", - "ESC_DA ", "ESC_DA ", "ESC_DA ", "ESC_DA ", -}; - -#endif /* DEBUG */ - -/* opcode=0xda */ -void -x86emuOp_esc_coprocess_da(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset = 0; - u8 stkelem = 0; - - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); - DECODE_PRINTINSTR32(x86emu_fpu_op_da_tab, mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - break; - case 3: /* register to register */ - stkelem = (u8) rl; - DECODE_PRINTF2("\tST(%d),ST\n", stkelem); - break; - } -#ifdef X86EMU_FPU_PRESENT - switch (mod) { - case 3: - x86emu_fpu_illegal(); - break; - default: - switch (rh) { - case 0: - x86emu_fpu_M_iadd(X86EMU_FPU_SHORT, destoffset); - break; - case 1: - x86emu_fpu_M_imul(X86EMU_FPU_SHORT, destoffset); - break; - case 2: - x86emu_fpu_M_icom(X86EMU_FPU_SHORT, destoffset); - break; - case 3: - x86emu_fpu_M_icomp(X86EMU_FPU_SHORT, destoffset); - break; - case 4: - x86emu_fpu_M_isub(X86EMU_FPU_SHORT, destoffset); - break; - case 5: - x86emu_fpu_M_isubr(X86EMU_FPU_SHORT, destoffset); - break; - case 6: - x86emu_fpu_M_idiv(X86EMU_FPU_SHORT, destoffset); - break; - case 7: - x86emu_fpu_M_idivr(X86EMU_FPU_SHORT, destoffset); - break; - } - } -#else - (void) destoffset; - (void) stkelem; -#endif - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR_NO_TRACE(); -} - -#ifdef DEBUG - -static const char *x86emu_fpu_op_db_tab[] = { - "FILD\tDWORD PTR ", "ESC_DB\t19", "FIST\tDWORD PTR ", "FISTP\tDWORD PTR ", - "ESC_DB\t1C", "FLD\tTBYTE PTR ", "ESC_DB\t1E", "FSTP\tTBYTE PTR ", - - "FILD\tDWORD PTR ", "ESC_DB\t19", "FIST\tDWORD PTR ", "FISTP\tDWORD PTR ", - "ESC_DB\t1C", "FLD\tTBYTE PTR ", "ESC_DB\t1E", "FSTP\tTBYTE PTR ", - - "FILD\tDWORD PTR ", "ESC_DB\t19", "FIST\tDWORD PTR ", "FISTP\tDWORD PTR ", - "ESC_DB\t1C", "FLD\tTBYTE PTR ", "ESC_DB\t1E", "FSTP\tTBYTE PTR ", -}; - -#endif /* DEBUG */ - -/* opcode=0xdb */ -void -x86emuOp_esc_coprocess_db(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset = 0; - - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (mod != 3) { - DECODE_PRINTINSTR32(x86emu_fpu_op_db_tab, mod, rh, rl); - } - else if (rh == 4) { /* === 11 10 0 nnn */ - switch (rl) { - case 0: - DECODE_PRINTF("FENI\n"); - break; - case 1: - DECODE_PRINTF("FDISI\n"); - break; - case 2: - DECODE_PRINTF("FCLEX\n"); - break; - case 3: - DECODE_PRINTF("FINIT\n"); - break; - } - } - else { - DECODE_PRINTF2("ESC_DB %0x\n", (mod << 6) + (rh << 3) + (rl)); - } -#endif /* DEBUG */ - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - break; - case 1: - destoffset = decode_rm01_address(rl); - break; - case 2: - destoffset = decode_rm10_address(rl); - break; - case 3: /* register to register */ - break; - } -#ifdef X86EMU_FPU_PRESENT - /* execute */ - switch (mod) { - case 3: - switch (rh) { - case 4: - switch (rl) { - case 0: - x86emu_fpu_R_feni(); - break; - case 1: - x86emu_fpu_R_fdisi(); - break; - case 2: - x86emu_fpu_R_fclex(); - break; - case 3: - x86emu_fpu_R_finit(); - break; - default: - x86emu_fpu_illegal(); - break; - } - break; - default: - x86emu_fpu_illegal(); - break; - } - break; - default: - switch (rh) { - case 0: - x86emu_fpu_M_fild(X86EMU_FPU_SHORT, destoffset); - break; - case 1: - x86emu_fpu_illegal(); - break; - case 2: - x86emu_fpu_M_fist(X86EMU_FPU_SHORT, destoffset); - break; - case 3: - x86emu_fpu_M_fistp(X86EMU_FPU_SHORT, destoffset); - break; - case 4: - x86emu_fpu_illegal(); - break; - case 5: - x86emu_fpu_M_fld(X86EMU_FPU_LDBL, destoffset); - break; - case 6: - x86emu_fpu_illegal(); - break; - case 7: - x86emu_fpu_M_fstp(X86EMU_FPU_LDBL, destoffset); - break; - } - } -#else - (void) destoffset; -#endif - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR_NO_TRACE(); -} - -#ifdef DEBUG -static const char *x86emu_fpu_op_dc_tab[] = { - "FADD\tQWORD PTR ", "FMUL\tQWORD PTR ", "FCOM\tQWORD PTR ", - "FCOMP\tQWORD PTR ", - "FSUB\tQWORD PTR ", "FSUBR\tQWORD PTR ", "FDIV\tQWORD PTR ", - "FDIVR\tQWORD PTR ", - - "FADD\tQWORD PTR ", "FMUL\tQWORD PTR ", "FCOM\tQWORD PTR ", - "FCOMP\tQWORD PTR ", - "FSUB\tQWORD PTR ", "FSUBR\tQWORD PTR ", "FDIV\tQWORD PTR ", - "FDIVR\tQWORD PTR ", - - "FADD\tQWORD PTR ", "FMUL\tQWORD PTR ", "FCOM\tQWORD PTR ", - "FCOMP\tQWORD PTR ", - "FSUB\tQWORD PTR ", "FSUBR\tQWORD PTR ", "FDIV\tQWORD PTR ", - "FDIVR\tQWORD PTR ", - - "FADD\t", "FMUL\t", "FCOM\t", "FCOMP\t", - "FSUBR\t", "FSUB\t", "FDIVR\t", "FDIV\t", -}; -#endif /* DEBUG */ - -/* opcode=0xdc */ -void -x86emuOp_esc_coprocess_dc(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset = 0; - u8 stkelem = 0; - - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); - DECODE_PRINTINSTR32(x86emu_fpu_op_dc_tab, mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - break; - case 3: /* register to register */ - stkelem = (u8) rl; - DECODE_PRINTF2("\tST(%d),ST\n", stkelem); - break; - } -#ifdef X86EMU_FPU_PRESENT - /* execute */ - switch (mod) { - case 3: - switch (rh) { - case 0: - x86emu_fpu_R_fadd(stkelem, X86EMU_FPU_STKTOP); - break; - case 1: - x86emu_fpu_R_fmul(stkelem, X86EMU_FPU_STKTOP); - break; - case 2: - x86emu_fpu_R_fcom(stkelem, X86EMU_FPU_STKTOP); - break; - case 3: - x86emu_fpu_R_fcomp(stkelem, X86EMU_FPU_STKTOP); - break; - case 4: - x86emu_fpu_R_fsubr(stkelem, X86EMU_FPU_STKTOP); - break; - case 5: - x86emu_fpu_R_fsub(stkelem, X86EMU_FPU_STKTOP); - break; - case 6: - x86emu_fpu_R_fdivr(stkelem, X86EMU_FPU_STKTOP); - break; - case 7: - x86emu_fpu_R_fdiv(stkelem, X86EMU_FPU_STKTOP); - break; - } - break; - default: - switch (rh) { - case 0: - x86emu_fpu_M_fadd(X86EMU_FPU_DOUBLE, destoffset); - break; - case 1: - x86emu_fpu_M_fmul(X86EMU_FPU_DOUBLE, destoffset); - break; - case 2: - x86emu_fpu_M_fcom(X86EMU_FPU_DOUBLE, destoffset); - break; - case 3: - x86emu_fpu_M_fcomp(X86EMU_FPU_DOUBLE, destoffset); - break; - case 4: - x86emu_fpu_M_fsub(X86EMU_FPU_DOUBLE, destoffset); - break; - case 5: - x86emu_fpu_M_fsubr(X86EMU_FPU_DOUBLE, destoffset); - break; - case 6: - x86emu_fpu_M_fdiv(X86EMU_FPU_DOUBLE, destoffset); - break; - case 7: - x86emu_fpu_M_fdivr(X86EMU_FPU_DOUBLE, destoffset); - break; - } - } -#else - (void) destoffset; - (void) stkelem; -#endif - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR_NO_TRACE(); -} - -#ifdef DEBUG - -static const char *x86emu_fpu_op_dd_tab[] = { - "FLD\tQWORD PTR ", "ESC_DD\t29,", "FST\tQWORD PTR ", "FSTP\tQWORD PTR ", - "FRSTOR\t", "ESC_DD\t2D,", "FSAVE\t", "FSTSW\t", - - "FLD\tQWORD PTR ", "ESC_DD\t29,", "FST\tQWORD PTR ", "FSTP\tQWORD PTR ", - "FRSTOR\t", "ESC_DD\t2D,", "FSAVE\t", "FSTSW\t", - - "FLD\tQWORD PTR ", "ESC_DD\t29,", "FST\tQWORD PTR ", "FSTP\tQWORD PTR ", - "FRSTOR\t", "ESC_DD\t2D,", "FSAVE\t", "FSTSW\t", - - "FFREE\t", "FXCH\t", "FST\t", "FSTP\t", - "ESC_DD\t2C,", "ESC_DD\t2D,", "ESC_DD\t2E,", "ESC_DD\t2F,", -}; - -#endif /* DEBUG */ - -/* opcode=0xdd */ -void -x86emuOp_esc_coprocess_dd(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset = 0; - u8 stkelem = 0; - - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); - DECODE_PRINTINSTR32(x86emu_fpu_op_dd_tab, mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - break; - case 3: /* register to register */ - stkelem = (u8) rl; - DECODE_PRINTF2("\tST(%d),ST\n", stkelem); - break; - } -#ifdef X86EMU_FPU_PRESENT - switch (mod) { - case 3: - switch (rh) { - case 0: - x86emu_fpu_R_ffree(stkelem); - break; - case 1: - x86emu_fpu_R_fxch(stkelem); - break; - case 2: - x86emu_fpu_R_fst(stkelem); /* register version */ - break; - case 3: - x86emu_fpu_R_fstp(stkelem); /* register version */ - break; - default: - x86emu_fpu_illegal(); - break; - } - break; - default: - switch (rh) { - case 0: - x86emu_fpu_M_fld(X86EMU_FPU_DOUBLE, destoffset); - break; - case 1: - x86emu_fpu_illegal(); - break; - case 2: - x86emu_fpu_M_fst(X86EMU_FPU_DOUBLE, destoffset); - break; - case 3: - x86emu_fpu_M_fstp(X86EMU_FPU_DOUBLE, destoffset); - break; - case 4: - x86emu_fpu_M_frstor(X86EMU_FPU_WORD, destoffset); - break; - case 5: - x86emu_fpu_illegal(); - break; - case 6: - x86emu_fpu_M_fsave(X86EMU_FPU_WORD, destoffset); - break; - case 7: - x86emu_fpu_M_fstsw(X86EMU_FPU_WORD, destoffset); - break; - } - } -#else - (void) destoffset; - (void) stkelem; -#endif - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR_NO_TRACE(); -} - -#ifdef DEBUG - -static const char *x86emu_fpu_op_de_tab[] = { - "FIADD\tWORD PTR ", "FIMUL\tWORD PTR ", "FICOM\tWORD PTR ", - "FICOMP\tWORD PTR ", - "FISUB\tWORD PTR ", "FISUBR\tWORD PTR ", "FIDIV\tWORD PTR ", - "FIDIVR\tWORD PTR ", - - "FIADD\tWORD PTR ", "FIMUL\tWORD PTR ", "FICOM\tWORD PTR ", - "FICOMP\tWORD PTR ", - "FISUB\tWORD PTR ", "FISUBR\tWORD PTR ", "FIDIV\tWORD PTR ", - "FIDIVR\tWORD PTR ", - - "FIADD\tWORD PTR ", "FIMUL\tWORD PTR ", "FICOM\tWORD PTR ", - "FICOMP\tWORD PTR ", - "FISUB\tWORD PTR ", "FISUBR\tWORD PTR ", "FIDIV\tWORD PTR ", - "FIDIVR\tWORD PTR ", - - "FADDP\t", "FMULP\t", "FCOMP\t", "FCOMPP\t", - "FSUBRP\t", "FSUBP\t", "FDIVRP\t", "FDIVP\t", -}; - -#endif /* DEBUG */ - -/* opcode=0xde */ -void -x86emuOp_esc_coprocess_de(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset = 0; - u8 stkelem = 0; - - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); - DECODE_PRINTINSTR32(x86emu_fpu_op_de_tab, mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - break; - case 3: /* register to register */ - stkelem = (u8) rl; - DECODE_PRINTF2("\tST(%d),ST\n", stkelem); - break; - } -#ifdef X86EMU_FPU_PRESENT - switch (mod) { - case 3: - switch (rh) { - case 0: - x86emu_fpu_R_faddp(stkelem, X86EMU_FPU_STKTOP); - break; - case 1: - x86emu_fpu_R_fmulp(stkelem, X86EMU_FPU_STKTOP); - break; - case 2: - x86emu_fpu_R_fcomp(stkelem, X86EMU_FPU_STKTOP); - break; - case 3: - if (stkelem == 1) - x86emu_fpu_R_fcompp(stkelem, X86EMU_FPU_STKTOP); - else - x86emu_fpu_illegal(); - break; - case 4: - x86emu_fpu_R_fsubrp(stkelem, X86EMU_FPU_STKTOP); - break; - case 5: - x86emu_fpu_R_fsubp(stkelem, X86EMU_FPU_STKTOP); - break; - case 6: - x86emu_fpu_R_fdivrp(stkelem, X86EMU_FPU_STKTOP); - break; - case 7: - x86emu_fpu_R_fdivp(stkelem, X86EMU_FPU_STKTOP); - break; - } - break; - default: - switch (rh) { - case 0: - x86emu_fpu_M_fiadd(X86EMU_FPU_WORD, destoffset); - break; - case 1: - x86emu_fpu_M_fimul(X86EMU_FPU_WORD, destoffset); - break; - case 2: - x86emu_fpu_M_ficom(X86EMU_FPU_WORD, destoffset); - break; - case 3: - x86emu_fpu_M_ficomp(X86EMU_FPU_WORD, destoffset); - break; - case 4: - x86emu_fpu_M_fisub(X86EMU_FPU_WORD, destoffset); - break; - case 5: - x86emu_fpu_M_fisubr(X86EMU_FPU_WORD, destoffset); - break; - case 6: - x86emu_fpu_M_fidiv(X86EMU_FPU_WORD, destoffset); - break; - case 7: - x86emu_fpu_M_fidivr(X86EMU_FPU_WORD, destoffset); - break; - } - } -#else - (void) destoffset; - (void) stkelem; -#endif - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR_NO_TRACE(); -} - -#ifdef DEBUG - -static const char *x86emu_fpu_op_df_tab[] = { - /* mod == 00 */ - "FILD\tWORD PTR ", "ESC_DF\t39\n", "FIST\tWORD PTR ", "FISTP\tWORD PTR ", - "FBLD\tTBYTE PTR ", "FILD\tQWORD PTR ", "FBSTP\tTBYTE PTR ", - "FISTP\tQWORD PTR ", - - /* mod == 01 */ - "FILD\tWORD PTR ", "ESC_DF\t39 ", "FIST\tWORD PTR ", "FISTP\tWORD PTR ", - "FBLD\tTBYTE PTR ", "FILD\tQWORD PTR ", "FBSTP\tTBYTE PTR ", - "FISTP\tQWORD PTR ", - - /* mod == 10 */ - "FILD\tWORD PTR ", "ESC_DF\t39 ", "FIST\tWORD PTR ", "FISTP\tWORD PTR ", - "FBLD\tTBYTE PTR ", "FILD\tQWORD PTR ", "FBSTP\tTBYTE PTR ", - "FISTP\tQWORD PTR ", - - /* mod == 11 */ - "FFREE\t", "FXCH\t", "FST\t", "FSTP\t", - "ESC_DF\t3C,", "ESC_DF\t3D,", "ESC_DF\t3E,", "ESC_DF\t3F," -}; - -#endif /* DEBUG */ - -/* opcode=0xdf */ -void -x86emuOp_esc_coprocess_df(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset = 0; - u8 stkelem = 0; - - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); - DECODE_PRINTINSTR32(x86emu_fpu_op_df_tab, mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - break; - case 3: /* register to register */ - stkelem = (u8) rl; - DECODE_PRINTF2("\tST(%d)\n", stkelem); - break; - } -#ifdef X86EMU_FPU_PRESENT - switch (mod) { - case 3: - switch (rh) { - case 0: - x86emu_fpu_R_ffree(stkelem); - break; - case 1: - x86emu_fpu_R_fxch(stkelem); - break; - case 2: - x86emu_fpu_R_fst(stkelem); /* register version */ - break; - case 3: - x86emu_fpu_R_fstp(stkelem); /* register version */ - break; - default: - x86emu_fpu_illegal(); - break; - } - break; - default: - switch (rh) { - case 0: - x86emu_fpu_M_fild(X86EMU_FPU_WORD, destoffset); - break; - case 1: - x86emu_fpu_illegal(); - break; - case 2: - x86emu_fpu_M_fist(X86EMU_FPU_WORD, destoffset); - break; - case 3: - x86emu_fpu_M_fistp(X86EMU_FPU_WORD, destoffset); - break; - case 4: - x86emu_fpu_M_fbld(X86EMU_FPU_BSD, destoffset); - break; - case 5: - x86emu_fpu_M_fild(X86EMU_FPU_LONG, destoffset); - break; - case 6: - x86emu_fpu_M_fbstp(X86EMU_FPU_BSD, destoffset); - break; - case 7: - x86emu_fpu_M_fistp(X86EMU_FPU_LONG, destoffset); - break; - } - } -#else - (void) destoffset; - (void) stkelem; -#endif - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR_NO_TRACE(); -} diff --git a/hw/xfree86/x86emu/meson.build b/hw/xfree86/x86emu/meson.build deleted file mode 100644 index 4846da99d..000000000 --- a/hw/xfree86/x86emu/meson.build +++ /dev/null @@ -1,15 +0,0 @@ -srcs_xorg_x86emu = [ - 'debug.c', - 'decode.c', - 'fpu.c', - 'ops2.c', - 'ops.c', - 'prim_ops.c', - 'sys.c', -] - -xorg_x86emu = static_library('x86emu', - srcs_xorg_x86emu, - include_directories: [inc, xorg_inc], - dependencies: common_dep, -) diff --git a/hw/xfree86/x86emu/ops.c b/hw/xfree86/x86emu/ops.c deleted file mode 100644 index 8846db0ca..000000000 --- a/hw/xfree86/x86emu/ops.c +++ /dev/null @@ -1,12399 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: This file includes subroutines to implement the decoding -* and emulation of all the x86 processor instructions. -* -* There are approximately 250 subroutines in here, which correspond -* to the 256 byte-"opcodes" found on the 8086. The table which -* dispatches this is found in the files optab.[ch]. -* -* Each opcode proc has a comment preceding it which gives its table -* address. Several opcodes are missing (undefined) in the table. -* -* Each proc includes information for decoding (DECODE_PRINTF and -* DECODE_PRINTF2), debugging (TRACE_REGS, SINGLE_STEP), and misc -* functions (START_OF_INSTR, END_OF_INSTR). -* -* Many of the procedures are *VERY* similar in coding. This has -* allowed for a very large amount of code to be generated in a fairly -* short amount of time (i.e. cut, paste, and modify). The result is -* that much of the code below could have been folded into subroutines -* for a large reduction in size of this file. The downside would be -* that there would be a penalty in execution speed. The file could -* also have been *MUCH* larger by inlining certain functions which -* were called. This could have resulted even faster execution. The -* prime directive I used to decide whether to inline the code or to -* modularize it, was basically: 1) no unnecessary subroutine calls, -* 2) no routines more than about 200 lines in size, and 3) modularize -* any code that I might not get right the first time. The fetch_* -* subroutines fall into the latter category. The The decode_* fall -* into the second category. The coding of the "switch(mod){ .... }" -* in many of the subroutines below falls into the first category. -* Especially, the coding of {add,and,or,sub,...}_{byte,word} -* subroutines are an especially glaring case of the third guideline. -* Since so much of the code is cloned from other modules (compare -* opcode #00 to opcode #01), making the basic operations subroutine -* calls is especially important; otherwise mistakes in coding an -* "add" would represent a nightmare in maintenance. -* -****************************************************************************/ - -#include "x86emu/x86emui.h" - -/*----------------------------- Implementation ----------------------------*/ - -/**************************************************************************** -PARAMETERS: -op1 - Instruction op code - -REMARKS: -Handles illegal opcodes. -****************************************************************************/ -static void -x86emuOp_illegal_op(u8 op1) -{ - START_OF_INSTR(); - if (M.x86.R_SP != 0) { - DECODE_PRINTF("ILLEGAL X86 OPCODE\n"); - TRACE_REGS(); - DB(printk("%04x:%04x: %02X ILLEGAL X86 OPCODE!\n", - M.x86.R_CS, M.x86.R_IP - 1, op1)); - HALT_SYS(); - } - else { - /* If we get here, it means the stack pointer is back to zero - * so we are just returning from an emulator service call - * so therte is no need to display an error message. We trap - * the emulator with an 0xF1 opcode to finish the service - * call. - */ - X86EMU_halt_sys(); - } - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x00 -****************************************************************************/ -static void -x86emuOp_add_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - u8 *destreg, *srcreg; - u8 destval; - - START_OF_INSTR(); - DECODE_PRINTF("ADD\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = add_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = add_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = add_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x01 -****************************************************************************/ -static void -x86emuOp_add_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("ADD\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = add_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = add_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = add_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = add_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = add_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = add_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x02 -****************************************************************************/ -static void -x86emuOp_add_byte_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint srcoffset; - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("ADD\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_byte(*destreg, srcval); - break; - case 1: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_byte(*destreg, srcval); - break; - case 2: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_byte(*destreg, srcval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x03 -****************************************************************************/ -static void -x86emuOp_add_word_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("ADD\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_word(*destreg, srcval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_word(*destreg, srcval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_word(*destreg, srcval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = add_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x04 -****************************************************************************/ -static void -x86emuOp_add_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("ADD\tAL,"); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - M.x86.R_AL = add_byte(M.x86.R_AL, srcval); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x05 -****************************************************************************/ -static void -x86emuOp_add_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("ADD\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("ADD\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = add_long(M.x86.R_EAX, srcval); - } - else { - M.x86.R_AX = add_word(M.x86.R_AX, (u16) srcval); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x06 -****************************************************************************/ -static void -x86emuOp_push_ES(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("PUSH\tES\n"); - TRACE_AND_STEP(); - push_word(M.x86.R_ES); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x07 -****************************************************************************/ -static void -x86emuOp_pop_ES(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("POP\tES\n"); - TRACE_AND_STEP(); - M.x86.R_ES = pop_word(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x08 -****************************************************************************/ -static void -x86emuOp_or_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint destoffset; - u8 destval; - - START_OF_INSTR(); - DECODE_PRINTF("OR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = or_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = or_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = or_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x09 -****************************************************************************/ -static void -x86emuOp_or_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("OR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = or_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = or_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = or_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = or_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = or_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = or_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0a -****************************************************************************/ -static void -x86emuOp_or_byte_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint srcoffset; - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("OR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_byte(*destreg, srcval); - break; - case 1: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_byte(*destreg, srcval); - break; - case 2: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_byte(*destreg, srcval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0b -****************************************************************************/ -static void -x86emuOp_or_word_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("OR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_word(*destreg, srcval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_word(*destreg, srcval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_word(*destreg, srcval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = or_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0c -****************************************************************************/ -static void -x86emuOp_or_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("OR\tAL,"); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - M.x86.R_AL = or_byte(M.x86.R_AL, srcval); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0d -****************************************************************************/ -static void -x86emuOp_or_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("OR\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("OR\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = or_long(M.x86.R_EAX, srcval); - } - else { - M.x86.R_AX = or_word(M.x86.R_AX, (u16) srcval); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0e -****************************************************************************/ -static void -x86emuOp_push_CS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("PUSH\tCS\n"); - TRACE_AND_STEP(); - push_word(M.x86.R_CS); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f. Escape for two-byte opcode (286 or better) -****************************************************************************/ -static void -x86emuOp_two_byte(u8 X86EMU_UNUSED(op1)) -{ - u8 op2 = (*sys_rdb) (((u32) M.x86.R_CS << 4) + (M.x86.R_IP++)); - - INC_DECODED_INST_LEN(1); - (*x86emu_optab2[op2]) (op2); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x10 -****************************************************************************/ -static void -x86emuOp_adc_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint destoffset; - u8 destval; - - START_OF_INSTR(); - DECODE_PRINTF("ADC\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = adc_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = adc_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = adc_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x11 -****************************************************************************/ -static void -x86emuOp_adc_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("ADC\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = adc_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = adc_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = adc_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = adc_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = adc_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = adc_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x12 -****************************************************************************/ -static void -x86emuOp_adc_byte_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint srcoffset; - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("ADC\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_byte(*destreg, srcval); - break; - case 1: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_byte(*destreg, srcval); - break; - case 2: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_byte(*destreg, srcval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x13 -****************************************************************************/ -static void -x86emuOp_adc_word_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("ADC\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_word(*destreg, srcval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_word(*destreg, srcval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_word(*destreg, srcval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = adc_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x14 -****************************************************************************/ -static void -x86emuOp_adc_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("ADC\tAL,"); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - M.x86.R_AL = adc_byte(M.x86.R_AL, srcval); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x15 -****************************************************************************/ -static void -x86emuOp_adc_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("ADC\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("ADC\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = adc_long(M.x86.R_EAX, srcval); - } - else { - M.x86.R_AX = adc_word(M.x86.R_AX, (u16) srcval); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x16 -****************************************************************************/ -static void -x86emuOp_push_SS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("PUSH\tSS\n"); - TRACE_AND_STEP(); - push_word(M.x86.R_SS); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x17 -****************************************************************************/ -static void -x86emuOp_pop_SS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("POP\tSS\n"); - TRACE_AND_STEP(); - M.x86.R_SS = pop_word(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x18 -****************************************************************************/ -static void -x86emuOp_sbb_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint destoffset; - u8 destval; - - START_OF_INSTR(); - DECODE_PRINTF("SBB\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sbb_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sbb_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sbb_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x19 -****************************************************************************/ -static void -x86emuOp_sbb_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("SBB\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sbb_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sbb_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sbb_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sbb_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sbb_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sbb_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x1a -****************************************************************************/ -static void -x86emuOp_sbb_byte_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint srcoffset; - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("SBB\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_byte(*destreg, srcval); - break; - case 1: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_byte(*destreg, srcval); - break; - case 2: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_byte(*destreg, srcval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x1b -****************************************************************************/ -static void -x86emuOp_sbb_word_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("SBB\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_word(*destreg, srcval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_word(*destreg, srcval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_word(*destreg, srcval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sbb_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x1c -****************************************************************************/ -static void -x86emuOp_sbb_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("SBB\tAL,"); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - M.x86.R_AL = sbb_byte(M.x86.R_AL, srcval); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x1d -****************************************************************************/ -static void -x86emuOp_sbb_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("SBB\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("SBB\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = sbb_long(M.x86.R_EAX, srcval); - } - else { - M.x86.R_AX = sbb_word(M.x86.R_AX, (u16) srcval); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x1e -****************************************************************************/ -static void -x86emuOp_push_DS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("PUSH\tDS\n"); - TRACE_AND_STEP(); - push_word(M.x86.R_DS); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x1f -****************************************************************************/ -static void -x86emuOp_pop_DS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("POP\tDS\n"); - TRACE_AND_STEP(); - M.x86.R_DS = pop_word(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x20 -****************************************************************************/ -static void -x86emuOp_and_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint destoffset; - u8 destval; - - START_OF_INSTR(); - DECODE_PRINTF("AND\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = and_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = and_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = and_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x21 -****************************************************************************/ -static void -x86emuOp_and_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("AND\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = and_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = and_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = and_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = and_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = and_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = and_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x22 -****************************************************************************/ -static void -x86emuOp_and_byte_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint srcoffset; - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("AND\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_byte(*destreg, srcval); - break; - case 1: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_byte(*destreg, srcval); - break; - case 2: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_byte(*destreg, srcval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x23 -****************************************************************************/ -static void -x86emuOp_and_word_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("AND\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_word(*destreg, srcval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_long(*destreg, srcval); - break; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_word(*destreg, srcval); - break; - } - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_word(*destreg, srcval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = and_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x24 -****************************************************************************/ -static void -x86emuOp_and_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("AND\tAL,"); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - M.x86.R_AL = and_byte(M.x86.R_AL, srcval); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x25 -****************************************************************************/ -static void -x86emuOp_and_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("AND\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("AND\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = and_long(M.x86.R_EAX, srcval); - } - else { - M.x86.R_AX = and_word(M.x86.R_AX, (u16) srcval); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x26 -****************************************************************************/ -static void -x86emuOp_segovr_ES(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("ES:\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_SEGOVR_ES; - /* - * note the lack of DECODE_CLEAR_SEGOVR(r) since, here is one of 4 - * opcode subroutines we do not want to do this. - */ - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x27 -****************************************************************************/ -static void -x86emuOp_daa(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("DAA\n"); - TRACE_AND_STEP(); - M.x86.R_AL = daa_byte(M.x86.R_AL); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x28 -****************************************************************************/ -static void -x86emuOp_sub_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint destoffset; - u8 destval; - - START_OF_INSTR(); - DECODE_PRINTF("SUB\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sub_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sub_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sub_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x29 -****************************************************************************/ -static void -x86emuOp_sub_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("SUB\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sub_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sub_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sub_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sub_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sub_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = sub_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x2a -****************************************************************************/ -static void -x86emuOp_sub_byte_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint srcoffset; - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("SUB\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_byte(*destreg, srcval); - break; - case 1: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_byte(*destreg, srcval); - break; - case 2: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_byte(*destreg, srcval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x2b -****************************************************************************/ -static void -x86emuOp_sub_word_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("SUB\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_word(*destreg, srcval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_word(*destreg, srcval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_word(*destreg, srcval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = sub_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x2c -****************************************************************************/ -static void -x86emuOp_sub_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("SUB\tAL,"); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - M.x86.R_AL = sub_byte(M.x86.R_AL, srcval); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x2d -****************************************************************************/ -static void -x86emuOp_sub_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("SUB\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("SUB\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = sub_long(M.x86.R_EAX, srcval); - } - else { - M.x86.R_AX = sub_word(M.x86.R_AX, (u16) srcval); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x2e -****************************************************************************/ -static void -x86emuOp_segovr_CS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("CS:\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_SEGOVR_CS; - /* note no DECODE_CLEAR_SEGOVR here. */ - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x2f -****************************************************************************/ -static void -x86emuOp_das(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("DAS\n"); - TRACE_AND_STEP(); - M.x86.R_AL = das_byte(M.x86.R_AL); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x30 -****************************************************************************/ -static void -x86emuOp_xor_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint destoffset; - u8 destval; - - START_OF_INSTR(); - DECODE_PRINTF("XOR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = xor_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = xor_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = xor_byte(destval, *srcreg); - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x31 -****************************************************************************/ -static void -x86emuOp_xor_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("XOR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = xor_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = xor_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = xor_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = xor_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = xor_long(destval, *srcreg); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = xor_word(destval, *srcreg); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x32 -****************************************************************************/ -static void -x86emuOp_xor_byte_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint srcoffset; - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("XOR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_byte(*destreg, srcval); - break; - case 1: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_byte(*destreg, srcval); - break; - case 2: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_byte(*destreg, srcval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x33 -****************************************************************************/ -static void -x86emuOp_xor_word_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("XOR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_word(*destreg, srcval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_word(*destreg, srcval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_word(*destreg, srcval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = xor_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x34 -****************************************************************************/ -static void -x86emuOp_xor_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("XOR\tAL,"); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - M.x86.R_AL = xor_byte(M.x86.R_AL, srcval); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x35 -****************************************************************************/ -static void -x86emuOp_xor_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("XOR\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("XOR\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = xor_long(M.x86.R_EAX, srcval); - } - else { - M.x86.R_AX = xor_word(M.x86.R_AX, (u16) srcval); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x36 -****************************************************************************/ -static void -x86emuOp_segovr_SS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("SS:\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_SEGOVR_SS; - /* no DECODE_CLEAR_SEGOVR ! */ - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x37 -****************************************************************************/ -static void -x86emuOp_aaa(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("AAA\n"); - TRACE_AND_STEP(); - M.x86.R_AX = aaa_word(M.x86.R_AX); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x38 -****************************************************************************/ -static void -x86emuOp_cmp_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - u8 *destreg, *srcreg; - u8 destval; - - START_OF_INSTR(); - DECODE_PRINTF("CMP\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_byte(destval, *srcreg); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_byte(destval, *srcreg); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_byte(destval, *srcreg); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x39 -****************************************************************************/ -static void -x86emuOp_cmp_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("CMP\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_long(destval, *srcreg); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_word(destval, *srcreg); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_long(destval, *srcreg); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_word(destval, *srcreg); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_long(destval, *srcreg); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_word(destval, *srcreg); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x3a -****************************************************************************/ -static void -x86emuOp_cmp_byte_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint srcoffset; - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("CMP\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_byte(*destreg, srcval); - break; - case 1: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_byte(*destreg, srcval); - break; - case 2: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_byte(*destreg, srcval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x3b -****************************************************************************/ -static void -x86emuOp_cmp_word_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("CMP\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_word(*destreg, srcval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_word(*destreg, srcval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_word(*destreg, srcval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - cmp_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x3c -****************************************************************************/ -static void -x86emuOp_cmp_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("CMP\tAL,"); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - cmp_byte(M.x86.R_AL, srcval); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x3d -****************************************************************************/ -static void -x86emuOp_cmp_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("CMP\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("CMP\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - cmp_long(M.x86.R_EAX, srcval); - } - else { - cmp_word(M.x86.R_AX, (u16) srcval); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x3e -****************************************************************************/ -static void -x86emuOp_segovr_DS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("DS:\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_SEGOVR_DS; - /* NO DECODE_CLEAR_SEGOVR! */ - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x3f -****************************************************************************/ -static void -x86emuOp_aas(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("AAS\n"); - TRACE_AND_STEP(); - M.x86.R_AX = aas_word(M.x86.R_AX); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x40 -****************************************************************************/ -static void -x86emuOp_inc_AX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INC\tEAX\n"); - } - else { - DECODE_PRINTF("INC\tAX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = inc_long(M.x86.R_EAX); - } - else { - M.x86.R_AX = inc_word(M.x86.R_AX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x41 -****************************************************************************/ -static void -x86emuOp_inc_CX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INC\tECX\n"); - } - else { - DECODE_PRINTF("INC\tCX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ECX = inc_long(M.x86.R_ECX); - } - else { - M.x86.R_CX = inc_word(M.x86.R_CX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x42 -****************************************************************************/ -static void -x86emuOp_inc_DX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INC\tEDX\n"); - } - else { - DECODE_PRINTF("INC\tDX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EDX = inc_long(M.x86.R_EDX); - } - else { - M.x86.R_DX = inc_word(M.x86.R_DX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x43 -****************************************************************************/ -static void -x86emuOp_inc_BX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INC\tEBX\n"); - } - else { - DECODE_PRINTF("INC\tBX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EBX = inc_long(M.x86.R_EBX); - } - else { - M.x86.R_BX = inc_word(M.x86.R_BX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x44 -****************************************************************************/ -static void -x86emuOp_inc_SP(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INC\tESP\n"); - } - else { - DECODE_PRINTF("INC\tSP\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ESP = inc_long(M.x86.R_ESP); - } - else { - M.x86.R_SP = inc_word(M.x86.R_SP); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x45 -****************************************************************************/ -static void -x86emuOp_inc_BP(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INC\tEBP\n"); - } - else { - DECODE_PRINTF("INC\tBP\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EBP = inc_long(M.x86.R_EBP); - } - else { - M.x86.R_BP = inc_word(M.x86.R_BP); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x46 -****************************************************************************/ -static void -x86emuOp_inc_SI(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INC\tESI\n"); - } - else { - DECODE_PRINTF("INC\tSI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ESI = inc_long(M.x86.R_ESI); - } - else { - M.x86.R_SI = inc_word(M.x86.R_SI); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x47 -****************************************************************************/ -static void -x86emuOp_inc_DI(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INC\tEDI\n"); - } - else { - DECODE_PRINTF("INC\tDI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EDI = inc_long(M.x86.R_EDI); - } - else { - M.x86.R_DI = inc_word(M.x86.R_DI); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x48 -****************************************************************************/ -static void -x86emuOp_dec_AX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("DEC\tEAX\n"); - } - else { - DECODE_PRINTF("DEC\tAX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = dec_long(M.x86.R_EAX); - } - else { - M.x86.R_AX = dec_word(M.x86.R_AX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x49 -****************************************************************************/ -static void -x86emuOp_dec_CX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("DEC\tECX\n"); - } - else { - DECODE_PRINTF("DEC\tCX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ECX = dec_long(M.x86.R_ECX); - } - else { - M.x86.R_CX = dec_word(M.x86.R_CX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x4a -****************************************************************************/ -static void -x86emuOp_dec_DX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("DEC\tEDX\n"); - } - else { - DECODE_PRINTF("DEC\tDX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EDX = dec_long(M.x86.R_EDX); - } - else { - M.x86.R_DX = dec_word(M.x86.R_DX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x4b -****************************************************************************/ -static void -x86emuOp_dec_BX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("DEC\tEBX\n"); - } - else { - DECODE_PRINTF("DEC\tBX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EBX = dec_long(M.x86.R_EBX); - } - else { - M.x86.R_BX = dec_word(M.x86.R_BX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x4c -****************************************************************************/ -static void -x86emuOp_dec_SP(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("DEC\tESP\n"); - } - else { - DECODE_PRINTF("DEC\tSP\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ESP = dec_long(M.x86.R_ESP); - } - else { - M.x86.R_SP = dec_word(M.x86.R_SP); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x4d -****************************************************************************/ -static void -x86emuOp_dec_BP(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("DEC\tEBP\n"); - } - else { - DECODE_PRINTF("DEC\tBP\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EBP = dec_long(M.x86.R_EBP); - } - else { - M.x86.R_BP = dec_word(M.x86.R_BP); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x4e -****************************************************************************/ -static void -x86emuOp_dec_SI(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("DEC\tESI\n"); - } - else { - DECODE_PRINTF("DEC\tSI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ESI = dec_long(M.x86.R_ESI); - } - else { - M.x86.R_SI = dec_word(M.x86.R_SI); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x4f -****************************************************************************/ -static void -x86emuOp_dec_DI(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("DEC\tEDI\n"); - } - else { - DECODE_PRINTF("DEC\tDI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EDI = dec_long(M.x86.R_EDI); - } - else { - M.x86.R_DI = dec_word(M.x86.R_DI); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x50 -****************************************************************************/ -static void -x86emuOp_push_AX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSH\tEAX\n"); - } - else { - DECODE_PRINTF("PUSH\tAX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_EAX); - } - else { - push_word(M.x86.R_AX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x51 -****************************************************************************/ -static void -x86emuOp_push_CX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSH\tECX\n"); - } - else { - DECODE_PRINTF("PUSH\tCX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_ECX); - } - else { - push_word(M.x86.R_CX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x52 -****************************************************************************/ -static void -x86emuOp_push_DX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSH\tEDX\n"); - } - else { - DECODE_PRINTF("PUSH\tDX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_EDX); - } - else { - push_word(M.x86.R_DX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x53 -****************************************************************************/ -static void -x86emuOp_push_BX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSH\tEBX\n"); - } - else { - DECODE_PRINTF("PUSH\tBX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_EBX); - } - else { - push_word(M.x86.R_BX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x54 -****************************************************************************/ -static void -x86emuOp_push_SP(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSH\tESP\n"); - } - else { - DECODE_PRINTF("PUSH\tSP\n"); - } - TRACE_AND_STEP(); - /* Always push (E)SP, since we are emulating an i386 and above - * processor. This is necessary as some BIOS'es use this to check - * what type of processor is in the system. - */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_ESP); - } - else { - push_word((u16) (M.x86.R_SP)); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x55 -****************************************************************************/ -static void -x86emuOp_push_BP(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSH\tEBP\n"); - } - else { - DECODE_PRINTF("PUSH\tBP\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_EBP); - } - else { - push_word(M.x86.R_BP); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x56 -****************************************************************************/ -static void -x86emuOp_push_SI(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSH\tESI\n"); - } - else { - DECODE_PRINTF("PUSH\tSI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_ESI); - } - else { - push_word(M.x86.R_SI); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x57 -****************************************************************************/ -static void -x86emuOp_push_DI(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSH\tEDI\n"); - } - else { - DECODE_PRINTF("PUSH\tDI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_EDI); - } - else { - push_word(M.x86.R_DI); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x58 -****************************************************************************/ -static void -x86emuOp_pop_AX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POP\tEAX\n"); - } - else { - DECODE_PRINTF("POP\tAX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = pop_long(); - } - else { - M.x86.R_AX = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x59 -****************************************************************************/ -static void -x86emuOp_pop_CX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POP\tECX\n"); - } - else { - DECODE_PRINTF("POP\tCX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ECX = pop_long(); - } - else { - M.x86.R_CX = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x5a -****************************************************************************/ -static void -x86emuOp_pop_DX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POP\tEDX\n"); - } - else { - DECODE_PRINTF("POP\tDX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EDX = pop_long(); - } - else { - M.x86.R_DX = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x5b -****************************************************************************/ -static void -x86emuOp_pop_BX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POP\tEBX\n"); - } - else { - DECODE_PRINTF("POP\tBX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EBX = pop_long(); - } - else { - M.x86.R_BX = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x5c -****************************************************************************/ -static void -x86emuOp_pop_SP(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POP\tESP\n"); - } - else { - DECODE_PRINTF("POP\tSP\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ESP = pop_long(); - } - else { - M.x86.R_SP = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x5d -****************************************************************************/ -static void -x86emuOp_pop_BP(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POP\tEBP\n"); - } - else { - DECODE_PRINTF("POP\tBP\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EBP = pop_long(); - } - else { - M.x86.R_BP = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x5e -****************************************************************************/ -static void -x86emuOp_pop_SI(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POP\tESI\n"); - } - else { - DECODE_PRINTF("POP\tSI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ESI = pop_long(); - } - else { - M.x86.R_SI = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x5f -****************************************************************************/ -static void -x86emuOp_pop_DI(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POP\tEDI\n"); - } - else { - DECODE_PRINTF("POP\tDI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EDI = pop_long(); - } - else { - M.x86.R_DI = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x60 -****************************************************************************/ -static void -x86emuOp_push_all(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSHAD\n"); - } - else { - DECODE_PRINTF("PUSHA\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 old_sp = M.x86.R_ESP; - - push_long(M.x86.R_EAX); - push_long(M.x86.R_ECX); - push_long(M.x86.R_EDX); - push_long(M.x86.R_EBX); - push_long(old_sp); - push_long(M.x86.R_EBP); - push_long(M.x86.R_ESI); - push_long(M.x86.R_EDI); - } - else { - u16 old_sp = M.x86.R_SP; - - push_word(M.x86.R_AX); - push_word(M.x86.R_CX); - push_word(M.x86.R_DX); - push_word(M.x86.R_BX); - push_word(old_sp); - push_word(M.x86.R_BP); - push_word(M.x86.R_SI); - push_word(M.x86.R_DI); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x61 -****************************************************************************/ -static void -x86emuOp_pop_all(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POPAD\n"); - } - else { - DECODE_PRINTF("POPA\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EDI = pop_long(); - M.x86.R_ESI = pop_long(); - M.x86.R_EBP = pop_long(); - M.x86.R_ESP += 4; /* skip ESP */ - M.x86.R_EBX = pop_long(); - M.x86.R_EDX = pop_long(); - M.x86.R_ECX = pop_long(); - M.x86.R_EAX = pop_long(); - } - else { - M.x86.R_DI = pop_word(); - M.x86.R_SI = pop_word(); - M.x86.R_BP = pop_word(); - M.x86.R_SP += 2; /* skip SP */ - M.x86.R_BX = pop_word(); - M.x86.R_DX = pop_word(); - M.x86.R_CX = pop_word(); - M.x86.R_AX = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/*opcode 0x62 ILLEGAL OP, calls x86emuOp_illegal_op() */ -/*opcode 0x63 ILLEGAL OP, calls x86emuOp_illegal_op() */ - -/**************************************************************************** -REMARKS: -Handles opcode 0x64 -****************************************************************************/ -static void -x86emuOp_segovr_FS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("FS:\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_SEGOVR_FS; - /* - * note the lack of DECODE_CLEAR_SEGOVR(r) since, here is one of 4 - * opcode subroutines we do not want to do this. - */ - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x65 -****************************************************************************/ -static void -x86emuOp_segovr_GS(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("GS:\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_SEGOVR_GS; - /* - * note the lack of DECODE_CLEAR_SEGOVR(r) since, here is one of 4 - * opcode subroutines we do not want to do this. - */ - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x66 - prefix for 32-bit register -****************************************************************************/ -static void -x86emuOp_prefix_data(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("DATA:\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_PREFIX_DATA; - /* note no DECODE_CLEAR_SEGOVR here. */ - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x67 - prefix for 32-bit address -****************************************************************************/ -static void -x86emuOp_prefix_addr(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("ADDR:\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_PREFIX_ADDR; - /* note no DECODE_CLEAR_SEGOVR here. */ - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x68 -****************************************************************************/ -static void -x86emuOp_push_word_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 imm; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - imm = fetch_long_imm(); - } - else { - imm = fetch_word_imm(); - } - DECODE_PRINTF2("PUSH\t%x\n", imm); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(imm); - } - else { - push_word((u16) imm); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x69 -****************************************************************************/ -static void -x86emuOp_imul_word_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("IMUL\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - u32 res_lo, res_hi; - s32 imm; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - imm = fetch_long_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) srcval, (s32) imm); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg; - u16 srcval; - u32 res; - s16 imm; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - imm = fetch_word_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - res = (s16) srcval *(s16) imm; - - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - u32 res_lo, res_hi; - s32 imm; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - imm = fetch_long_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) srcval, (s32) imm); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg; - u16 srcval; - u32 res; - s16 imm; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - imm = fetch_word_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - res = (s16) srcval *(s16) imm; - - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - u32 res_lo, res_hi; - s32 imm; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - imm = fetch_long_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) srcval, (s32) imm); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg; - u16 srcval; - u32 res; - s16 imm; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - imm = fetch_word_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - res = (s16) srcval *(s16) imm; - - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - u32 res_lo, res_hi; - s32 imm; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - imm = fetch_long_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) * srcreg, (s32) imm); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg, *srcreg; - u32 res; - s16 imm; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - imm = fetch_word_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - res = (s16) * srcreg * (s16) imm; - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x6a -****************************************************************************/ -static void -x86emuOp_push_byte_IMM(u8 X86EMU_UNUSED(op1)) -{ - s16 imm; - - START_OF_INSTR(); - imm = (s8) fetch_byte_imm(); - DECODE_PRINTF2("PUSH\t%d\n", imm); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long((s32) imm); - } - else { - push_word(imm); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x6b -****************************************************************************/ -static void -x86emuOp_imul_byte_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - s8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("IMUL\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - u32 res_lo, res_hi; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) srcval, (s32) imm); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg; - u16 srcval; - u32 res; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - res = (s16) srcval *(s16) imm; - - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - u32 res_lo, res_hi; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) srcval, (s32) imm); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg; - u16 srcval; - u32 res; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - res = (s16) srcval *(s16) imm; - - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - u32 res_lo, res_hi; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) srcval, (s32) imm); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg; - u16 srcval; - u32 res; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - res = (s16) srcval *(s16) imm; - - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - u32 res_lo, res_hi; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) * srcreg, (s32) imm); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg, *srcreg; - u32 res; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%d\n", (s32) imm); - res = (s16) * srcreg * (s16) imm; - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x6c -****************************************************************************/ -static void -x86emuOp_ins_byte(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("INSB\n"); - ins(1); - TRACE_AND_STEP(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x6d -****************************************************************************/ -static void -x86emuOp_ins_word(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INSD\n"); - ins(4); - } - else { - DECODE_PRINTF("INSW\n"); - ins(2); - } - TRACE_AND_STEP(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x6e -****************************************************************************/ -static void -x86emuOp_outs_byte(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("OUTSB\n"); - outs(1); - TRACE_AND_STEP(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x6f -****************************************************************************/ -static void -x86emuOp_outs_word(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("OUTSD\n"); - outs(4); - } - else { - DECODE_PRINTF("OUTSW\n"); - outs(2); - } - TRACE_AND_STEP(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x70 -****************************************************************************/ -static void -x86emuOp_jump_near_O(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if overflow flag is set */ - START_OF_INSTR(); - DECODE_PRINTF("JO\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_OF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x71 -****************************************************************************/ -static void -x86emuOp_jump_near_NO(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if overflow is not set */ - START_OF_INSTR(); - DECODE_PRINTF("JNO\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (!ACCESS_FLAG(F_OF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x72 -****************************************************************************/ -static void -x86emuOp_jump_near_B(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if carry flag is set. */ - START_OF_INSTR(); - DECODE_PRINTF("JB\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_CF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x73 -****************************************************************************/ -static void -x86emuOp_jump_near_NB(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if carry flag is clear. */ - START_OF_INSTR(); - DECODE_PRINTF("JNB\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (!ACCESS_FLAG(F_CF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x74 -****************************************************************************/ -static void -x86emuOp_jump_near_Z(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if zero flag is set. */ - START_OF_INSTR(); - DECODE_PRINTF("JZ\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_ZF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x75 -****************************************************************************/ -static void -x86emuOp_jump_near_NZ(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if zero flag is clear. */ - START_OF_INSTR(); - DECODE_PRINTF("JNZ\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (!ACCESS_FLAG(F_ZF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x76 -****************************************************************************/ -static void -x86emuOp_jump_near_BE(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if carry flag is set or if the zero - flag is set. */ - START_OF_INSTR(); - DECODE_PRINTF("JBE\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x77 -****************************************************************************/ -static void -x86emuOp_jump_near_NBE(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if carry flag is clear and if the zero - flag is clear */ - START_OF_INSTR(); - DECODE_PRINTF("JNBE\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (!(ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF))) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x78 -****************************************************************************/ -static void -x86emuOp_jump_near_S(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if sign flag is set */ - START_OF_INSTR(); - DECODE_PRINTF("JS\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_SF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x79 -****************************************************************************/ -static void -x86emuOp_jump_near_NS(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if sign flag is clear */ - START_OF_INSTR(); - DECODE_PRINTF("JNS\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (!ACCESS_FLAG(F_SF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x7a -****************************************************************************/ -static void -x86emuOp_jump_near_P(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if parity flag is set (even parity) */ - START_OF_INSTR(); - DECODE_PRINTF("JP\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_PF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x7b -****************************************************************************/ -static void -x86emuOp_jump_near_NP(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - - /* jump to byte offset if parity flag is clear (odd parity) */ - START_OF_INSTR(); - DECODE_PRINTF("JNP\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (!ACCESS_FLAG(F_PF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x7c -****************************************************************************/ -static void -x86emuOp_jump_near_L(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - int sf, of; - - /* jump to byte offset if sign flag not equal to overflow flag. */ - START_OF_INSTR(); - DECODE_PRINTF("JL\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - sf = ACCESS_FLAG(F_SF) != 0; - of = ACCESS_FLAG(F_OF) != 0; - if (sf ^ of) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x7d -****************************************************************************/ -static void -x86emuOp_jump_near_NL(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - int sf, of; - - /* jump to byte offset if sign flag not equal to overflow flag. */ - START_OF_INSTR(); - DECODE_PRINTF("JNL\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - sf = ACCESS_FLAG(F_SF) != 0; - of = ACCESS_FLAG(F_OF) != 0; - /* note: inverse of above, but using == instead of xor. */ - if (sf == of) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x7e -****************************************************************************/ -static void -x86emuOp_jump_near_LE(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - int sf, of; - - /* jump to byte offset if sign flag not equal to overflow flag - or the zero flag is set */ - START_OF_INSTR(); - DECODE_PRINTF("JLE\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - sf = ACCESS_FLAG(F_SF) != 0; - of = ACCESS_FLAG(F_OF) != 0; - if ((sf ^ of) || ACCESS_FLAG(F_ZF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x7f -****************************************************************************/ -static void -x86emuOp_jump_near_NLE(u8 X86EMU_UNUSED(op1)) -{ - s8 offset; - u16 target; - int sf, of; - - /* jump to byte offset if sign flag equal to overflow flag. - and the zero flag is clear */ - START_OF_INSTR(); - DECODE_PRINTF("JNLE\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + (s16) offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - sf = ACCESS_FLAG(F_SF) != 0; - of = ACCESS_FLAG(F_OF) != 0; - if ((sf == of) && !ACCESS_FLAG(F_ZF)) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -static u8(*opc80_byte_operation[]) (u8 d, u8 s) = { - add_byte, /* 00 */ - or_byte, /* 01 */ - adc_byte, /* 02 */ - sbb_byte, /* 03 */ - and_byte, /* 04 */ - sub_byte, /* 05 */ - xor_byte, /* 06 */ - cmp_byte, /* 07 */ -}; - -/**************************************************************************** -REMARKS: -Handles opcode 0x80 -****************************************************************************/ -static void -x86emuOp_opc80_byte_RM_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg; - uint destoffset; - u8 imm; - u8 destval; - - /* - * Weirdo special case instruction format. Part of the opcode - * held below in "RH". Doubly nested case would result, except - * that the decoded instruction - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - - switch (rh) { - case 0: - DECODE_PRINTF("ADD\t"); - break; - case 1: - DECODE_PRINTF("OR\t"); - break; - case 2: - DECODE_PRINTF("ADC\t"); - break; - case 3: - DECODE_PRINTF("SBB\t"); - break; - case 4: - DECODE_PRINTF("AND\t"); - break; - case 5: - DECODE_PRINTF("SUB\t"); - break; - case 6: - DECODE_PRINTF("XOR\t"); - break; - case 7: - DECODE_PRINTF("CMP\t"); - break; - } - } -#endif - /* know operation, decode the mod byte to find the addressing - mode. */ - switch (mod) { - case 0: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc80_byte_operation[rh]) (destval, imm); - if (rh != 7) - store_data_byte(destoffset, destval); - break; - case 1: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc80_byte_operation[rh]) (destval, imm); - if (rh != 7) - store_data_byte(destoffset, destval); - break; - case 2: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc80_byte_operation[rh]) (destval, imm); - if (rh != 7) - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc80_byte_operation[rh]) (*destreg, imm); - if (rh != 7) - *destreg = destval; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -static u16(*opc81_word_operation[]) (u16 d, u16 s) = { - add_word, /*00 */ - or_word, /*01 */ - adc_word, /*02 */ - sbb_word, /*03 */ - and_word, /*04 */ - sub_word, /*05 */ - xor_word, /*06 */ - cmp_word, /*07 */ -}; - -static u32(*opc81_long_operation[]) (u32 d, u32 s) = { - add_long, /*00 */ - or_long, /*01 */ - adc_long, /*02 */ - sbb_long, /*03 */ - and_long, /*04 */ - sub_long, /*05 */ - xor_long, /*06 */ - cmp_long, /*07 */ -}; - -/**************************************************************************** -REMARKS: -Handles opcode 0x81 -****************************************************************************/ -static void -x86emuOp_opc81_word_RM_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - /* - * Weirdo special case instruction format. Part of the opcode - * held below in "RH". Doubly nested case would result, except - * that the decoded instruction - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - - switch (rh) { - case 0: - DECODE_PRINTF("ADD\t"); - break; - case 1: - DECODE_PRINTF("OR\t"); - break; - case 2: - DECODE_PRINTF("ADC\t"); - break; - case 3: - DECODE_PRINTF("SBB\t"); - break; - case 4: - DECODE_PRINTF("AND\t"); - break; - case 5: - DECODE_PRINTF("SUB\t"); - break; - case 6: - DECODE_PRINTF("XOR\t"); - break; - case 7: - DECODE_PRINTF("CMP\t"); - break; - } - } -#endif - /* - * Know operation, decode the mod byte to find the addressing - * mode. - */ - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval, imm; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - imm = fetch_long_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc81_long_operation[rh]) (destval, imm); - if (rh != 7) - store_data_long(destoffset, destval); - } - else { - u16 destval, imm; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - imm = fetch_word_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc81_word_operation[rh]) (destval, imm); - if (rh != 7) - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval, imm; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - imm = fetch_long_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc81_long_operation[rh]) (destval, imm); - if (rh != 7) - store_data_long(destoffset, destval); - } - else { - u16 destval, imm; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - imm = fetch_word_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc81_word_operation[rh]) (destval, imm); - if (rh != 7) - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval, imm; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - imm = fetch_long_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc81_long_operation[rh]) (destval, imm); - if (rh != 7) - store_data_long(destoffset, destval); - } - else { - u16 destval, imm; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - imm = fetch_word_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc81_word_operation[rh]) (destval, imm); - if (rh != 7) - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 destval, imm; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - imm = fetch_long_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc81_long_operation[rh]) (*destreg, imm); - if (rh != 7) - *destreg = destval; - } - else { - u16 *destreg; - u16 destval, imm; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - imm = fetch_word_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc81_word_operation[rh]) (*destreg, imm); - if (rh != 7) - *destreg = destval; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -static u8(*opc82_byte_operation[]) (u8 s, u8 d) = { - add_byte, /*00 */ - or_byte, /*01 *//*YYY UNUSED ???? */ - adc_byte, /*02 */ - sbb_byte, /*03 */ - and_byte, /*04 *//*YYY UNUSED ???? */ - sub_byte, /*05 */ - xor_byte, /*06 *//*YYY UNUSED ???? */ - cmp_byte, /*07 */ -}; - -/**************************************************************************** -REMARKS: -Handles opcode 0x82 -****************************************************************************/ -static void -x86emuOp_opc82_byte_RM_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg; - uint destoffset; - u8 imm; - u8 destval; - - /* - * Weirdo special case instruction format. Part of the opcode - * held below in "RH". Doubly nested case would result, except - * that the decoded instruction Similar to opcode 81, except that - * the immediate byte is sign extended to a word length. - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - switch (rh) { - case 0: - DECODE_PRINTF("ADD\t"); - break; - case 1: - DECODE_PRINTF("OR\t"); - break; - case 2: - DECODE_PRINTF("ADC\t"); - break; - case 3: - DECODE_PRINTF("SBB\t"); - break; - case 4: - DECODE_PRINTF("AND\t"); - break; - case 5: - DECODE_PRINTF("SUB\t"); - break; - case 6: - DECODE_PRINTF("XOR\t"); - break; - case 7: - DECODE_PRINTF("CMP\t"); - break; - } - } -#endif - /* know operation, decode the mod byte to find the addressing - mode. */ - switch (mod) { - case 0: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm00_address(rl); - destval = fetch_data_byte(destoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc82_byte_operation[rh]) (destval, imm); - if (rh != 7) - store_data_byte(destoffset, destval); - break; - case 1: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm01_address(rl); - destval = fetch_data_byte(destoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc82_byte_operation[rh]) (destval, imm); - if (rh != 7) - store_data_byte(destoffset, destval); - break; - case 2: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm10_address(rl); - destval = fetch_data_byte(destoffset); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc82_byte_operation[rh]) (destval, imm); - if (rh != 7) - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc82_byte_operation[rh]) (*destreg, imm); - if (rh != 7) - *destreg = destval; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -static u16(*opc83_word_operation[]) (u16 s, u16 d) = { - add_word, /*00 */ - or_word, /*01 *//*YYY UNUSED ???? */ - adc_word, /*02 */ - sbb_word, /*03 */ - and_word, /*04 *//*YYY UNUSED ???? */ - sub_word, /*05 */ - xor_word, /*06 *//*YYY UNUSED ???? */ - cmp_word, /*07 */ -}; - -static u32(*opc83_long_operation[]) (u32 s, u32 d) = { - add_long, /*00 */ - or_long, /*01 *//*YYY UNUSED ???? */ - adc_long, /*02 */ - sbb_long, /*03 */ - and_long, /*04 *//*YYY UNUSED ???? */ - sub_long, /*05 */ - xor_long, /*06 *//*YYY UNUSED ???? */ - cmp_long, /*07 */ -}; - -/**************************************************************************** -REMARKS: -Handles opcode 0x83 -****************************************************************************/ -static void -x86emuOp_opc83_word_RM_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - /* - * Weirdo special case instruction format. Part of the opcode - * held below in "RH". Doubly nested case would result, except - * that the decoded instruction Similar to opcode 81, except that - * the immediate byte is sign extended to a word length. - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - switch (rh) { - case 0: - DECODE_PRINTF("ADD\t"); - break; - case 1: - DECODE_PRINTF("OR\t"); - break; - case 2: - DECODE_PRINTF("ADC\t"); - break; - case 3: - DECODE_PRINTF("SBB\t"); - break; - case 4: - DECODE_PRINTF("AND\t"); - break; - case 5: - DECODE_PRINTF("SUB\t"); - break; - case 6: - DECODE_PRINTF("XOR\t"); - break; - case 7: - DECODE_PRINTF("CMP\t"); - break; - } - } -#endif - /* know operation, decode the mod byte to find the addressing - mode. */ - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval, imm; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm00_address(rl); - destval = fetch_data_long(destoffset); - imm = (s8) fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc83_long_operation[rh]) (destval, imm); - if (rh != 7) - store_data_long(destoffset, destval); - } - else { - u16 destval, imm; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm00_address(rl); - destval = fetch_data_word(destoffset); - imm = (s8) fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc83_word_operation[rh]) (destval, imm); - if (rh != 7) - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval, imm; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm01_address(rl); - destval = fetch_data_long(destoffset); - imm = (s8) fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc83_long_operation[rh]) (destval, imm); - if (rh != 7) - store_data_long(destoffset, destval); - } - else { - u16 destval, imm; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm01_address(rl); - destval = fetch_data_word(destoffset); - imm = (s8) fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc83_word_operation[rh]) (destval, imm); - if (rh != 7) - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval, imm; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm10_address(rl); - destval = fetch_data_long(destoffset); - imm = (s8) fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc83_long_operation[rh]) (destval, imm); - if (rh != 7) - store_data_long(destoffset, destval); - } - else { - u16 destval, imm; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm10_address(rl); - destval = fetch_data_word(destoffset); - imm = (s8) fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc83_word_operation[rh]) (destval, imm); - if (rh != 7) - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 destval, imm; - - destreg = DECODE_RM_LONG_REGISTER(rl); - imm = (s8) fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc83_long_operation[rh]) (*destreg, imm); - if (rh != 7) - *destreg = destval; - } - else { - u16 *destreg; - u16 destval, imm; - - destreg = DECODE_RM_WORD_REGISTER(rl); - imm = (s8) fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - destval = (*opc83_word_operation[rh]) (*destreg, imm); - if (rh != 7) - *destreg = destval; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x84 -****************************************************************************/ -static void -x86emuOp_test_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint destoffset; - u8 destval; - - START_OF_INSTR(); - DECODE_PRINTF("TEST\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_byte(destval, *srcreg); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_byte(destval, *srcreg); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_byte(destval, *srcreg); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_byte(*destreg, *srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x85 -****************************************************************************/ -static void -x86emuOp_test_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("TEST\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_long(destval, *srcreg); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_word(destval, *srcreg); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_long(destval, *srcreg); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_word(destval, *srcreg); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_long(destval, *srcreg); - } - else { - u16 destval; - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_word(destval, *srcreg); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_long(*destreg, *srcreg); - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - test_word(*destreg, *srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x86 -****************************************************************************/ -static void -x86emuOp_xchg_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint destoffset; - u8 destval; - u8 tmp; - - START_OF_INSTR(); - DECODE_PRINTF("XCHG\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = destval; - destval = tmp; - store_data_byte(destoffset, destval); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = destval; - destval = tmp; - store_data_byte(destoffset, destval); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_byte(destoffset); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = destval; - destval = tmp; - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = *destreg; - *destreg = tmp; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x87 -****************************************************************************/ -static void -x86emuOp_xchg_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("XCHG\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg; - u32 destval, tmp; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = destval; - destval = tmp; - store_data_long(destoffset, destval); - } - else { - u16 *srcreg; - u16 destval, tmp; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = destval; - destval = tmp; - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg; - u32 destval, tmp; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = destval; - destval = tmp; - store_data_long(destoffset, destval); - } - else { - u16 *srcreg; - u16 destval, tmp; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = destval; - destval = tmp; - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg; - u32 destval, tmp; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_long(destoffset); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = destval; - destval = tmp; - store_data_long(destoffset, destval); - } - else { - u16 *srcreg; - u16 destval, tmp; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - destval = fetch_data_word(destoffset); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = destval; - destval = tmp; - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - u32 tmp; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = *destreg; - *destreg = tmp; - } - else { - u16 *destreg, *srcreg; - u16 tmp; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - tmp = *srcreg; - *srcreg = *destreg; - *destreg = tmp; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x88 -****************************************************************************/ -static void -x86emuOp_mov_byte_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - store_data_byte(destoffset, *srcreg); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - store_data_byte(destoffset, *srcreg); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - store_data_byte(destoffset, *srcreg); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x89 -****************************************************************************/ -static void -x86emuOp_mov_word_RM_R(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u32 destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - store_data_long(destoffset, *srcreg); - } - else { - u16 *srcreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - store_data_word(destoffset, *srcreg); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - store_data_long(destoffset, *srcreg); - } - else { - u16 *srcreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - store_data_word(destoffset, *srcreg); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - store_data_long(destoffset, *srcreg); - } - else { - u16 *srcreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - store_data_word(destoffset, *srcreg); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x8a -****************************************************************************/ -static void -x86emuOp_mov_byte_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg, *srcreg; - uint srcoffset; - u8 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 1: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 2: - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x8b -****************************************************************************/ -static void -x86emuOp_mov_word_R_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - } - else { - u16 *destreg, *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x8c -****************************************************************************/ -static void -x86emuOp_mov_word_RM_SR(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u16 *destreg, *srcreg; - uint destoffset; - u16 destval; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - srcreg = decode_rm_seg_register(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = *srcreg; - store_data_word(destoffset, destval); - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - srcreg = decode_rm_seg_register(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = *srcreg; - store_data_word(destoffset, destval); - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - srcreg = decode_rm_seg_register(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = *srcreg; - store_data_word(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcreg = decode_rm_seg_register(rh); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x8d -****************************************************************************/ -static void -x86emuOp_lea_word_R_M(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("LEA\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_ADDR) { - u32 *srcreg = DECODE_RM_LONG_REGISTER(rh); - - DECODE_PRINTF(","); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *srcreg = (u32) destoffset; - } - else { - u16 *srcreg = DECODE_RM_WORD_REGISTER(rh); - - DECODE_PRINTF(","); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *srcreg = (u16) destoffset; - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_ADDR) { - u32 *srcreg = DECODE_RM_LONG_REGISTER(rh); - - DECODE_PRINTF(","); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *srcreg = (u32) destoffset; - } - else { - u16 *srcreg = DECODE_RM_WORD_REGISTER(rh); - - DECODE_PRINTF(","); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *srcreg = (u16) destoffset; - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_ADDR) { - u32 *srcreg = DECODE_RM_LONG_REGISTER(rh); - - DECODE_PRINTF(","); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *srcreg = (u32) destoffset; - } - else { - u16 *srcreg = DECODE_RM_WORD_REGISTER(rh); - - DECODE_PRINTF(","); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *srcreg = (u16) destoffset; - } - break; - case 3: /* register to register */ - /* undefined. Do nothing. */ - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x8e -****************************************************************************/ -static void -x86emuOp_mov_word_SR_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u16 *destreg, *srcreg; - uint srcoffset; - u16 srcval; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = decode_rm_seg_register(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 1: - destreg = decode_rm_seg_register(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 2: - destreg = decode_rm_seg_register(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 3: /* register to register */ - destreg = decode_rm_seg_register(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - break; - } - /* - * Clean up, and reset all the R_xSP pointers to the correct - * locations. This is about 3x too much overhead (doing all the - * segreg ptrs when only one is needed, but this instruction - * *cannot* be that common, and this isn't too much work anyway. - */ - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x8f -****************************************************************************/ -static void -x86emuOp_pop_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("POP\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - if (rh != 0) { - DECODE_PRINTF("ILLEGAL DECODE OF OPCODE 8F\n"); - HALT_SYS(); - } - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = pop_long(); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = pop_word(); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = pop_long(); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = pop_word(); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = pop_long(); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - destval = pop_word(); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = pop_long(); - } - else { - u16 *destreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = pop_word(); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x90 -****************************************************************************/ -static void -x86emuOp_nop(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("NOP\n"); - TRACE_AND_STEP(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x91 -****************************************************************************/ -static void -x86emuOp_xchg_word_AX_CX(u8 X86EMU_UNUSED(op1)) -{ - u32 tmp; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("XCHG\tEAX,ECX\n"); - } - else { - DECODE_PRINTF("XCHG\tAX,CX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - tmp = M.x86.R_EAX; - M.x86.R_EAX = M.x86.R_ECX; - M.x86.R_ECX = tmp; - } - else { - tmp = M.x86.R_AX; - M.x86.R_AX = M.x86.R_CX; - M.x86.R_CX = (u16) tmp; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x92 -****************************************************************************/ -static void -x86emuOp_xchg_word_AX_DX(u8 X86EMU_UNUSED(op1)) -{ - u32 tmp; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("XCHG\tEAX,EDX\n"); - } - else { - DECODE_PRINTF("XCHG\tAX,DX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - tmp = M.x86.R_EAX; - M.x86.R_EAX = M.x86.R_EDX; - M.x86.R_EDX = tmp; - } - else { - tmp = M.x86.R_AX; - M.x86.R_AX = M.x86.R_DX; - M.x86.R_DX = (u16) tmp; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x93 -****************************************************************************/ -static void -x86emuOp_xchg_word_AX_BX(u8 X86EMU_UNUSED(op1)) -{ - u32 tmp; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("XCHG\tEAX,EBX\n"); - } - else { - DECODE_PRINTF("XCHG\tAX,BX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - tmp = M.x86.R_EAX; - M.x86.R_EAX = M.x86.R_EBX; - M.x86.R_EBX = tmp; - } - else { - tmp = M.x86.R_AX; - M.x86.R_AX = M.x86.R_BX; - M.x86.R_BX = (u16) tmp; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x94 -****************************************************************************/ -static void -x86emuOp_xchg_word_AX_SP(u8 X86EMU_UNUSED(op1)) -{ - u32 tmp; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("XCHG\tEAX,ESP\n"); - } - else { - DECODE_PRINTF("XCHG\tAX,SP\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - tmp = M.x86.R_EAX; - M.x86.R_EAX = M.x86.R_ESP; - M.x86.R_ESP = tmp; - } - else { - tmp = M.x86.R_AX; - M.x86.R_AX = M.x86.R_SP; - M.x86.R_SP = (u16) tmp; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x95 -****************************************************************************/ -static void -x86emuOp_xchg_word_AX_BP(u8 X86EMU_UNUSED(op1)) -{ - u32 tmp; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("XCHG\tEAX,EBP\n"); - } - else { - DECODE_PRINTF("XCHG\tAX,BP\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - tmp = M.x86.R_EAX; - M.x86.R_EAX = M.x86.R_EBP; - M.x86.R_EBP = tmp; - } - else { - tmp = M.x86.R_AX; - M.x86.R_AX = M.x86.R_BP; - M.x86.R_BP = (u16) tmp; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x96 -****************************************************************************/ -static void -x86emuOp_xchg_word_AX_SI(u8 X86EMU_UNUSED(op1)) -{ - u32 tmp; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("XCHG\tEAX,ESI\n"); - } - else { - DECODE_PRINTF("XCHG\tAX,SI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - tmp = M.x86.R_EAX; - M.x86.R_EAX = M.x86.R_ESI; - M.x86.R_ESI = tmp; - } - else { - tmp = M.x86.R_AX; - M.x86.R_AX = M.x86.R_SI; - M.x86.R_SI = (u16) tmp; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x97 -****************************************************************************/ -static void -x86emuOp_xchg_word_AX_DI(u8 X86EMU_UNUSED(op1)) -{ - u32 tmp; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("XCHG\tEAX,EDI\n"); - } - else { - DECODE_PRINTF("XCHG\tAX,DI\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - tmp = M.x86.R_EAX; - M.x86.R_EAX = M.x86.R_EDI; - M.x86.R_EDI = tmp; - } - else { - tmp = M.x86.R_AX; - M.x86.R_AX = M.x86.R_DI; - M.x86.R_DI = (u16) tmp; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x98 -****************************************************************************/ -static void -x86emuOp_cbw(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("CWDE\n"); - } - else { - DECODE_PRINTF("CBW\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - if (M.x86.R_AX & 0x8000) { - M.x86.R_EAX |= 0xffff0000; - } - else { - M.x86.R_EAX &= 0x0000ffff; - } - } - else { - if (M.x86.R_AL & 0x80) { - M.x86.R_AH = 0xff; - } - else { - M.x86.R_AH = 0x0; - } - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x99 -****************************************************************************/ -static void -x86emuOp_cwd(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("CDQ\n"); - } - else { - DECODE_PRINTF("CWD\n"); - } - DECODE_PRINTF("CWD\n"); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - if (M.x86.R_EAX & 0x80000000) { - M.x86.R_EDX = 0xffffffff; - } - else { - M.x86.R_EDX = 0x0; - } - } - else { - if (M.x86.R_AX & 0x8000) { - M.x86.R_DX = 0xffff; - } - else { - M.x86.R_DX = 0x0; - } - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x9a -****************************************************************************/ -static void -x86emuOp_call_far_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 farseg, faroff; - - START_OF_INSTR(); - DECODE_PRINTF("CALL\t"); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - faroff = fetch_long_imm(); - farseg = fetch_word_imm(); - } - else { - faroff = fetch_word_imm(); - farseg = fetch_word_imm(); - } - DECODE_PRINTF2("%04x:", farseg); - DECODE_PRINTF2("%04x\n", faroff); - CALL_TRACE(M.x86.saved_cs, M.x86.saved_ip, farseg, faroff, "FAR "); - - /* XXX - * - * Hooked interrupt vectors calling into our "BIOS" will cause - * problems unless all intersegment stuff is checked for BIOS - * access. Check needed here. For moment, let it alone. - */ - TRACE_AND_STEP(); - push_word(M.x86.R_CS); - M.x86.R_CS = farseg; - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_EIP); - } - else { - push_word(M.x86.R_IP); - } - M.x86.R_EIP = faroff & 0xffff; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x9b -****************************************************************************/ -static void -x86emuOp_wait(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("WAIT"); - TRACE_AND_STEP(); - /* NADA. */ - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x9c -****************************************************************************/ -static void -x86emuOp_pushf_word(u8 X86EMU_UNUSED(op1)) -{ - u32 flags; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("PUSHFD\n"); - } - else { - DECODE_PRINTF("PUSHF\n"); - } - TRACE_AND_STEP(); - - /* clear out *all* bits not representing flags, and turn on real bits */ - flags = (M.x86.R_EFLG & F_MSK) | F_ALWAYS_ON; - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(flags); - } - else { - push_word((u16) flags); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x9d -****************************************************************************/ -static void -x86emuOp_popf_word(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("POPFD\n"); - } - else { - DECODE_PRINTF("POPF\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EFLG = pop_long(); - } - else { - M.x86.R_FLG = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x9e -****************************************************************************/ -static void -x86emuOp_sahf(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("SAHF\n"); - TRACE_AND_STEP(); - /* clear the lower bits of the flag register */ - M.x86.R_FLG &= 0xffffff00; - /* or in the AH register into the flags register */ - M.x86.R_FLG |= M.x86.R_AH; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x9f -****************************************************************************/ -static void -x86emuOp_lahf(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("LAHF\n"); - TRACE_AND_STEP(); - M.x86.R_AH = (u8) (M.x86.R_FLG & 0xff); - /* Undocumented TC++ behavior??? Nope. It's documented, but - you have to look real hard to notice it. */ - M.x86.R_AH |= 0x2; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa0 -****************************************************************************/ -static void -x86emuOp_mov_AL_M_IMM(u8 X86EMU_UNUSED(op1)) -{ - u16 offset; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\tAL,"); - offset = fetch_word_imm(); - DECODE_PRINTF2("[%04x]\n", offset); - TRACE_AND_STEP(); - M.x86.R_AL = fetch_data_byte(offset); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa1 -****************************************************************************/ -static void -x86emuOp_mov_AX_M_IMM(u8 X86EMU_UNUSED(op1)) -{ - u16 offset; - - START_OF_INSTR(); - offset = fetch_word_imm(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF2("MOV\tEAX,[%04x]\n", offset); - } - else { - DECODE_PRINTF2("MOV\tAX,[%04x]\n", offset); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = fetch_data_long(offset); - } - else { - M.x86.R_AX = fetch_data_word(offset); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa2 -****************************************************************************/ -static void -x86emuOp_mov_M_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u16 offset; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\t"); - offset = fetch_word_imm(); - DECODE_PRINTF2("[%04x],AL\n", offset); - TRACE_AND_STEP(); - store_data_byte(offset, M.x86.R_AL); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa3 -****************************************************************************/ -static void -x86emuOp_mov_M_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u16 offset; - - START_OF_INSTR(); - offset = fetch_word_imm(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF2("MOV\t[%04x],EAX\n", offset); - } - else { - DECODE_PRINTF2("MOV\t[%04x],AX\n", offset); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - store_data_long(offset, M.x86.R_EAX); - } - else { - store_data_word(offset, M.x86.R_AX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa4 -****************************************************************************/ -static void -x86emuOp_movs_byte(u8 X86EMU_UNUSED(op1)) -{ - u8 val; - u32 count; - int inc; - - START_OF_INSTR(); - DECODE_PRINTF("MOVS\tBYTE\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -1; - else - inc = 1; - TRACE_AND_STEP(); - count = 1; - if (M.x86.mode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE)) { - /* don't care whether REPE or REPNE */ - /* move them until CX is ZERO. */ - count = M.x86.R_CX; - M.x86.R_CX = 0; - M.x86.mode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE); - } - while (count--) { - val = fetch_data_byte(M.x86.R_SI); - store_data_byte_abs(M.x86.R_ES, M.x86.R_DI, val); - M.x86.R_SI += inc; - M.x86.R_DI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa5 -****************************************************************************/ -static void -x86emuOp_movs_word(u8 X86EMU_UNUSED(op1)) -{ - u32 val; - int inc; - u32 count; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("MOVS\tDWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -4; - else - inc = 4; - } - else { - DECODE_PRINTF("MOVS\tWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -2; - else - inc = 2; - } - TRACE_AND_STEP(); - count = 1; - if (M.x86.mode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE)) { - /* don't care whether REPE or REPNE */ - /* move them until CX is ZERO. */ - count = M.x86.R_CX; - M.x86.R_CX = 0; - M.x86.mode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE); - } - while (count--) { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - val = fetch_data_long(M.x86.R_SI); - store_data_long_abs(M.x86.R_ES, M.x86.R_DI, val); - } - else { - val = fetch_data_word(M.x86.R_SI); - store_data_word_abs(M.x86.R_ES, M.x86.R_DI, (u16) val); - } - M.x86.R_SI += inc; - M.x86.R_DI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa6 -****************************************************************************/ -static void -x86emuOp_cmps_byte(u8 X86EMU_UNUSED(op1)) -{ - s8 val1, val2; - int inc; - - START_OF_INSTR(); - DECODE_PRINTF("CMPS\tBYTE\n"); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -1; - else - inc = 1; - - if (M.x86.mode & SYSMODE_PREFIX_REPE) { - /* REPE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - val1 = fetch_data_byte(M.x86.R_SI); - val2 = fetch_data_byte_abs(M.x86.R_ES, M.x86.R_DI); - cmp_byte(val1, val2); - M.x86.R_CX -= 1; - M.x86.R_SI += inc; - M.x86.R_DI += inc; - if (ACCESS_FLAG(F_ZF) == 0) - break; - } - M.x86.mode &= ~SYSMODE_PREFIX_REPE; - } - else if (M.x86.mode & SYSMODE_PREFIX_REPNE) { - /* REPNE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - val1 = fetch_data_byte(M.x86.R_SI); - val2 = fetch_data_byte_abs(M.x86.R_ES, M.x86.R_DI); - cmp_byte(val1, val2); - M.x86.R_CX -= 1; - M.x86.R_SI += inc; - M.x86.R_DI += inc; - if (ACCESS_FLAG(F_ZF)) - break; /* zero flag set means equal */ - } - M.x86.mode &= ~SYSMODE_PREFIX_REPNE; - } - else { - val1 = fetch_data_byte(M.x86.R_SI); - val2 = fetch_data_byte_abs(M.x86.R_ES, M.x86.R_DI); - cmp_byte(val1, val2); - M.x86.R_SI += inc; - M.x86.R_DI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa7 -****************************************************************************/ -static void -x86emuOp_cmps_word(u8 X86EMU_UNUSED(op1)) -{ - u32 val1, val2; - int inc; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("CMPS\tDWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -4; - else - inc = 4; - } - else { - DECODE_PRINTF("CMPS\tWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -2; - else - inc = 2; - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_REPE) { - /* REPE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - val1 = fetch_data_long(M.x86.R_SI); - val2 = fetch_data_long_abs(M.x86.R_ES, M.x86.R_DI); - cmp_long(val1, val2); - } - else { - val1 = fetch_data_word(M.x86.R_SI); - val2 = fetch_data_word_abs(M.x86.R_ES, M.x86.R_DI); - cmp_word((u16) val1, (u16) val2); - } - M.x86.R_CX -= 1; - M.x86.R_SI += inc; - M.x86.R_DI += inc; - if (ACCESS_FLAG(F_ZF) == 0) - break; - } - M.x86.mode &= ~SYSMODE_PREFIX_REPE; - } - else if (M.x86.mode & SYSMODE_PREFIX_REPNE) { - /* REPNE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - val1 = fetch_data_long(M.x86.R_SI); - val2 = fetch_data_long_abs(M.x86.R_ES, M.x86.R_DI); - cmp_long(val1, val2); - } - else { - val1 = fetch_data_word(M.x86.R_SI); - val2 = fetch_data_word_abs(M.x86.R_ES, M.x86.R_DI); - cmp_word((u16) val1, (u16) val2); - } - M.x86.R_CX -= 1; - M.x86.R_SI += inc; - M.x86.R_DI += inc; - if (ACCESS_FLAG(F_ZF)) - break; /* zero flag set means equal */ - } - M.x86.mode &= ~SYSMODE_PREFIX_REPNE; - } - else { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - val1 = fetch_data_long(M.x86.R_SI); - val2 = fetch_data_long_abs(M.x86.R_ES, M.x86.R_DI); - cmp_long(val1, val2); - } - else { - val1 = fetch_data_word(M.x86.R_SI); - val2 = fetch_data_word_abs(M.x86.R_ES, M.x86.R_DI); - cmp_word((u16) val1, (u16) val2); - } - M.x86.R_SI += inc; - M.x86.R_DI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa8 -****************************************************************************/ -static void -x86emuOp_test_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - int imm; - - START_OF_INSTR(); - DECODE_PRINTF("TEST\tAL,"); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%04x\n", imm); - TRACE_AND_STEP(); - test_byte(M.x86.R_AL, (u8) imm); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xa9 -****************************************************************************/ -static void -x86emuOp_test_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("TEST\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("TEST\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - test_long(M.x86.R_EAX, srcval); - } - else { - test_word(M.x86.R_AX, (u16) srcval); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xaa -****************************************************************************/ -static void -x86emuOp_stos_byte(u8 X86EMU_UNUSED(op1)) -{ - int inc; - - START_OF_INSTR(); - DECODE_PRINTF("STOS\tBYTE\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -1; - else - inc = 1; - TRACE_AND_STEP(); - if (M.x86.mode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE)) { - /* don't care whether REPE or REPNE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - store_data_byte_abs(M.x86.R_ES, M.x86.R_DI, M.x86.R_AL); - M.x86.R_CX -= 1; - M.x86.R_DI += inc; - } - M.x86.mode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE); - } - else { - store_data_byte_abs(M.x86.R_ES, M.x86.R_DI, M.x86.R_AL); - M.x86.R_DI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xab -****************************************************************************/ -static void -x86emuOp_stos_word(u8 X86EMU_UNUSED(op1)) -{ - int inc; - u32 count; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("STOS\tDWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -4; - else - inc = 4; - } - else { - DECODE_PRINTF("STOS\tWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -2; - else - inc = 2; - } - TRACE_AND_STEP(); - count = 1; - if (M.x86.mode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE)) { - /* don't care whether REPE or REPNE */ - /* move them until CX is ZERO. */ - count = M.x86.R_CX; - M.x86.R_CX = 0; - M.x86.mode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE); - } - while (count--) { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - store_data_long_abs(M.x86.R_ES, M.x86.R_DI, M.x86.R_EAX); - } - else { - store_data_word_abs(M.x86.R_ES, M.x86.R_DI, M.x86.R_AX); - } - M.x86.R_DI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xac -****************************************************************************/ -static void -x86emuOp_lods_byte(u8 X86EMU_UNUSED(op1)) -{ - int inc; - - START_OF_INSTR(); - DECODE_PRINTF("LODS\tBYTE\n"); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -1; - else - inc = 1; - if (M.x86.mode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE)) { - /* don't care whether REPE or REPNE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - M.x86.R_AL = fetch_data_byte(M.x86.R_SI); - M.x86.R_CX -= 1; - M.x86.R_SI += inc; - } - M.x86.mode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE); - } - else { - M.x86.R_AL = fetch_data_byte(M.x86.R_SI); - M.x86.R_SI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xad -****************************************************************************/ -static void -x86emuOp_lods_word(u8 X86EMU_UNUSED(op1)) -{ - int inc; - u32 count; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("LODS\tDWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -4; - else - inc = 4; - } - else { - DECODE_PRINTF("LODS\tWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -2; - else - inc = 2; - } - TRACE_AND_STEP(); - count = 1; - if (M.x86.mode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE)) { - /* don't care whether REPE or REPNE */ - /* move them until CX is ZERO. */ - count = M.x86.R_CX; - M.x86.R_CX = 0; - M.x86.mode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE); - } - while (count--) { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = fetch_data_long(M.x86.R_SI); - } - else { - M.x86.R_AX = fetch_data_word(M.x86.R_SI); - } - M.x86.R_SI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xae -****************************************************************************/ -static void -x86emuOp_scas_byte(u8 X86EMU_UNUSED(op1)) -{ - s8 val2; - int inc; - - START_OF_INSTR(); - DECODE_PRINTF("SCAS\tBYTE\n"); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -1; - else - inc = 1; - if (M.x86.mode & SYSMODE_PREFIX_REPE) { - /* REPE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - val2 = fetch_data_byte_abs(M.x86.R_ES, M.x86.R_DI); - cmp_byte(M.x86.R_AL, val2); - M.x86.R_CX -= 1; - M.x86.R_DI += inc; - if (ACCESS_FLAG(F_ZF) == 0) - break; - } - M.x86.mode &= ~SYSMODE_PREFIX_REPE; - } - else if (M.x86.mode & SYSMODE_PREFIX_REPNE) { - /* REPNE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - val2 = fetch_data_byte_abs(M.x86.R_ES, M.x86.R_DI); - cmp_byte(M.x86.R_AL, val2); - M.x86.R_CX -= 1; - M.x86.R_DI += inc; - if (ACCESS_FLAG(F_ZF)) - break; /* zero flag set means equal */ - } - M.x86.mode &= ~SYSMODE_PREFIX_REPNE; - } - else { - val2 = fetch_data_byte_abs(M.x86.R_ES, M.x86.R_DI); - cmp_byte(M.x86.R_AL, val2); - M.x86.R_DI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xaf -****************************************************************************/ -static void -x86emuOp_scas_word(u8 X86EMU_UNUSED(op1)) -{ - int inc; - u32 val; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("SCAS\tDWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -4; - else - inc = 4; - } - else { - DECODE_PRINTF("SCAS\tWORD\n"); - if (ACCESS_FLAG(F_DF)) /* down */ - inc = -2; - else - inc = 2; - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_REPE) { - /* REPE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - val = fetch_data_long_abs(M.x86.R_ES, M.x86.R_DI); - cmp_long(M.x86.R_EAX, val); - } - else { - val = fetch_data_word_abs(M.x86.R_ES, M.x86.R_DI); - cmp_word(M.x86.R_AX, (u16) val); - } - M.x86.R_CX -= 1; - M.x86.R_DI += inc; - if (ACCESS_FLAG(F_ZF) == 0) - break; - } - M.x86.mode &= ~SYSMODE_PREFIX_REPE; - } - else if (M.x86.mode & SYSMODE_PREFIX_REPNE) { - /* REPNE */ - /* move them until CX is ZERO. */ - while (M.x86.R_CX != 0) { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - val = fetch_data_long_abs(M.x86.R_ES, M.x86.R_DI); - cmp_long(M.x86.R_EAX, val); - } - else { - val = fetch_data_word_abs(M.x86.R_ES, M.x86.R_DI); - cmp_word(M.x86.R_AX, (u16) val); - } - M.x86.R_CX -= 1; - M.x86.R_DI += inc; - if (ACCESS_FLAG(F_ZF)) - break; /* zero flag set means equal */ - } - M.x86.mode &= ~SYSMODE_PREFIX_REPNE; - } - else { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - val = fetch_data_long_abs(M.x86.R_ES, M.x86.R_DI); - cmp_long(M.x86.R_EAX, val); - } - else { - val = fetch_data_word_abs(M.x86.R_ES, M.x86.R_DI); - cmp_word(M.x86.R_AX, (u16) val); - } - M.x86.R_DI += inc; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb0 -****************************************************************************/ -static void -x86emuOp_mov_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\tAL,"); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - M.x86.R_AL = imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb1 -****************************************************************************/ -static void -x86emuOp_mov_byte_CL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\tCL,"); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - M.x86.R_CL = imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb2 -****************************************************************************/ -static void -x86emuOp_mov_byte_DL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\tDL,"); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - M.x86.R_DL = imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb3 -****************************************************************************/ -static void -x86emuOp_mov_byte_BL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\tBL,"); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - M.x86.R_BL = imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb4 -****************************************************************************/ -static void -x86emuOp_mov_byte_AH_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\tAH,"); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - M.x86.R_AH = imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb5 -****************************************************************************/ -static void -x86emuOp_mov_byte_CH_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\tCH,"); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - M.x86.R_CH = imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb6 -****************************************************************************/ -static void -x86emuOp_mov_byte_DH_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\tDH,"); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - M.x86.R_DH = imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb7 -****************************************************************************/ -static void -x86emuOp_mov_byte_BH_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\tBH,"); - imm = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", imm); - TRACE_AND_STEP(); - M.x86.R_BH = imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb8 -****************************************************************************/ -static void -x86emuOp_mov_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("MOV\tEAX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("MOV\tAX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = srcval; - } - else { - M.x86.R_AX = (u16) srcval; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xb9 -****************************************************************************/ -static void -x86emuOp_mov_word_CX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("MOV\tECX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("MOV\tCX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ECX = srcval; - } - else { - M.x86.R_CX = (u16) srcval; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xba -****************************************************************************/ -static void -x86emuOp_mov_word_DX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("MOV\tEDX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("MOV\tDX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EDX = srcval; - } - else { - M.x86.R_DX = (u16) srcval; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xbb -****************************************************************************/ -static void -x86emuOp_mov_word_BX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("MOV\tEBX,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("MOV\tBX,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EBX = srcval; - } - else { - M.x86.R_BX = (u16) srcval; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xbc -****************************************************************************/ -static void -x86emuOp_mov_word_SP_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("MOV\tESP,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("MOV\tSP,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ESP = srcval; - } - else { - M.x86.R_SP = (u16) srcval; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xbd -****************************************************************************/ -static void -x86emuOp_mov_word_BP_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("MOV\tEBP,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("MOV\tBP,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EBP = srcval; - } - else { - M.x86.R_BP = (u16) srcval; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xbe -****************************************************************************/ -static void -x86emuOp_mov_word_SI_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("MOV\tESI,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("MOV\tSI,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ESI = srcval; - } - else { - M.x86.R_SI = (u16) srcval; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xbf -****************************************************************************/ -static void -x86emuOp_mov_word_DI_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 srcval; - - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("MOV\tEDI,"); - srcval = fetch_long_imm(); - } - else { - DECODE_PRINTF("MOV\tDI,"); - srcval = fetch_word_imm(); - } - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EDI = srcval; - } - else { - M.x86.R_DI = (u16) srcval; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/* used by opcodes c0, d0, and d2. */ -static u8(*opcD0_byte_operation[]) (u8 d, u8 s) = { - rol_byte, ror_byte, rcl_byte, rcr_byte, shl_byte, shr_byte, shl_byte, /* sal_byte === shl_byte by definition */ -sar_byte,}; - -/**************************************************************************** -REMARKS: -Handles opcode 0xc0 -****************************************************************************/ -static void -x86emuOp_opcC0_byte_RM_MEM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg; - uint destoffset; - u8 destval; - u8 amt; - - /* - * Yet another weirdo special case instruction format. Part of - * the opcode held below in "RH". Doubly nested case would - * result, except that the decoded instruction - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - - switch (rh) { - case 0: - DECODE_PRINTF("ROL\t"); - break; - case 1: - DECODE_PRINTF("ROR\t"); - break; - case 2: - DECODE_PRINTF("RCL\t"); - break; - case 3: - DECODE_PRINTF("RCR\t"); - break; - case 4: - DECODE_PRINTF("SHL\t"); - break; - case 5: - DECODE_PRINTF("SHR\t"); - break; - case 6: - DECODE_PRINTF("SAL\t"); - break; - case 7: - DECODE_PRINTF("SAR\t"); - break; - } - } -#endif - /* know operation, decode the mod byte to find the addressing - mode. */ - switch (mod) { - case 0: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm00_address(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (destval, amt); - store_data_byte(destoffset, destval); - break; - case 1: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm01_address(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (destval, amt); - store_data_byte(destoffset, destval); - break; - case 2: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm10_address(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (destval, amt); - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (*destreg, amt); - *destreg = destval; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/* used by opcodes c1, d1, and d3. */ -static u16(*opcD1_word_operation[]) (u16 s, u8 d) = { - rol_word, ror_word, rcl_word, rcr_word, shl_word, shr_word, shl_word, /* sal_byte === shl_byte by definition */ -sar_word,}; - -/* used by opcodes c1, d1, and d3. */ -static u32(*opcD1_long_operation[]) (u32 s, u8 d) = { - rol_long, ror_long, rcl_long, rcr_long, shl_long, shr_long, shl_long, /* sal_byte === shl_byte by definition */ -sar_long,}; - -/**************************************************************************** -REMARKS: -Handles opcode 0xc1 -****************************************************************************/ -static void -x86emuOp_opcC1_word_RM_MEM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - u8 amt; - - /* - * Yet another weirdo special case instruction format. Part of - * the opcode held below in "RH". Doubly nested case would - * result, except that the decoded instruction - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - - switch (rh) { - case 0: - DECODE_PRINTF("ROL\t"); - break; - case 1: - DECODE_PRINTF("ROR\t"); - break; - case 2: - DECODE_PRINTF("RCL\t"); - break; - case 3: - DECODE_PRINTF("RCR\t"); - break; - case 4: - DECODE_PRINTF("SHL\t"); - break; - case 5: - DECODE_PRINTF("SHR\t"); - break; - case 6: - DECODE_PRINTF("SAL\t"); - break; - case 7: - DECODE_PRINTF("SAR\t"); - break; - } - } -#endif - /* know operation, decode the mod byte to find the addressing - mode. */ - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm00_address(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (destval, amt); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm00_address(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (destval, amt); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm01_address(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (destval, amt); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm01_address(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (destval, amt); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm10_address(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (destval, amt); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm10_address(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (destval, amt); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - TRACE_AND_STEP(); - *destreg = (*opcD1_long_operation[rh]) (*destreg, amt); - } - else { - u16 *destreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - amt = fetch_byte_imm(); - DECODE_PRINTF2(",%x\n", amt); - TRACE_AND_STEP(); - *destreg = (*opcD1_word_operation[rh]) (*destreg, amt); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xc2 -****************************************************************************/ -static void -x86emuOp_ret_near_IMM(u8 X86EMU_UNUSED(op1)) -{ - u16 imm; - - START_OF_INSTR(); - DECODE_PRINTF("RET\t"); - imm = fetch_word_imm(); - DECODE_PRINTF2("%x\n", imm); - RETURN_TRACE("RET", M.x86.saved_cs, M.x86.saved_ip); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EIP = pop_long(); - } else { - M.x86.R_IP = pop_word(); - } - M.x86.R_SP += imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xc3 -****************************************************************************/ -static void -x86emuOp_ret_near(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("RET\n"); - RETURN_TRACE("RET", M.x86.saved_cs, M.x86.saved_ip); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EIP = pop_long(); - } else { - M.x86.R_IP = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xc4 -****************************************************************************/ -static void -x86emuOp_les_R_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rh, rl; - u16 *dstreg; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("LES\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_ES = fetch_data_word(srcoffset + 2); - break; - case 1: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_ES = fetch_data_word(srcoffset + 2); - break; - case 2: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_ES = fetch_data_word(srcoffset + 2); - break; - case 3: /* register to register */ - /* UNDEFINED! */ - TRACE_AND_STEP(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xc5 -****************************************************************************/ -static void -x86emuOp_lds_R_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rh, rl; - u16 *dstreg; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("LDS\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_DS = fetch_data_word(srcoffset + 2); - break; - case 1: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_DS = fetch_data_word(srcoffset + 2); - break; - case 2: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_DS = fetch_data_word(srcoffset + 2); - break; - case 3: /* register to register */ - /* UNDEFINED! */ - TRACE_AND_STEP(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xc6 -****************************************************************************/ -static void -x86emuOp_mov_byte_RM_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg; - uint destoffset; - u8 imm; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - if (rh != 0) { - DECODE_PRINTF("ILLEGAL DECODE OF OPCODE c6\n"); - HALT_SYS(); - } - switch (mod) { - case 0: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm00_address(rl); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%2x\n", imm); - TRACE_AND_STEP(); - store_data_byte(destoffset, imm); - break; - case 1: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm01_address(rl); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%2x\n", imm); - TRACE_AND_STEP(); - store_data_byte(destoffset, imm); - break; - case 2: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm10_address(rl); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%2x\n", imm); - TRACE_AND_STEP(); - store_data_byte(destoffset, imm); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - imm = fetch_byte_imm(); - DECODE_PRINTF2(",%2x\n", imm); - TRACE_AND_STEP(); - *destreg = imm; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xc7 -****************************************************************************/ -static void -x86emuOp_mov_word_RM_IMM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("MOV\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - if (rh != 0) { - DECODE_PRINTF("ILLEGAL DECODE OF OPCODE 8F\n"); - HALT_SYS(); - } - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 imm; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm00_address(rl); - imm = fetch_long_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - store_data_long(destoffset, imm); - } - else { - u16 imm; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm00_address(rl); - imm = fetch_word_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - store_data_word(destoffset, imm); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 imm; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm01_address(rl); - imm = fetch_long_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - store_data_long(destoffset, imm); - } - else { - u16 imm; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm01_address(rl); - imm = fetch_word_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - store_data_word(destoffset, imm); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 imm; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm10_address(rl); - imm = fetch_long_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - store_data_long(destoffset, imm); - } - else { - u16 imm; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm10_address(rl); - imm = fetch_word_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - store_data_word(destoffset, imm); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 imm; - - destreg = DECODE_RM_LONG_REGISTER(rl); - imm = fetch_long_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - *destreg = imm; - } - else { - u16 *destreg; - u16 imm; - - destreg = DECODE_RM_WORD_REGISTER(rl); - imm = fetch_word_imm(); - DECODE_PRINTF2(",%x\n", imm); - TRACE_AND_STEP(); - *destreg = imm; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xc8 -****************************************************************************/ -static void -x86emuOp_enter(u8 X86EMU_UNUSED(op1)) -{ - u16 local, frame_pointer; - u8 nesting; - int i; - - START_OF_INSTR(); - local = fetch_word_imm(); - nesting = fetch_byte_imm(); - DECODE_PRINTF2("ENTER %x\n", local); - DECODE_PRINTF2(",%x\n", nesting); - TRACE_AND_STEP(); - push_word(M.x86.R_BP); - frame_pointer = M.x86.R_SP; - if (nesting > 0) { - for (i = 1; i < nesting; i++) { - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_BP -= 4; - push_long(fetch_data_long_abs(M.x86.R_SS, M.x86.R_BP)); - } else { - M.x86.R_BP -= 2; - push_word(fetch_data_word_abs(M.x86.R_SS, M.x86.R_BP)); - } - } - push_word(frame_pointer); - } - M.x86.R_BP = frame_pointer; - M.x86.R_SP = (u16) (M.x86.R_SP - local); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xc9 -****************************************************************************/ -static void -x86emuOp_leave(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("LEAVE\n"); - TRACE_AND_STEP(); - M.x86.R_SP = M.x86.R_BP; - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EBP = pop_long(); - } else { - M.x86.R_BP = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xca -****************************************************************************/ -static void -x86emuOp_ret_far_IMM(u8 X86EMU_UNUSED(op1)) -{ - u16 imm; - - START_OF_INSTR(); - DECODE_PRINTF("RETF\t"); - imm = fetch_word_imm(); - DECODE_PRINTF2("%x\n", imm); - RETURN_TRACE("RETF", M.x86.saved_cs, M.x86.saved_ip); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EIP = pop_long(); - M.x86.R_CS = pop_long() & 0xffff; - } else { - M.x86.R_IP = pop_word(); - M.x86.R_CS = pop_word(); - } - M.x86.R_SP += imm; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xcb -****************************************************************************/ -static void -x86emuOp_ret_far(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("RETF\n"); - RETURN_TRACE("RETF", M.x86.saved_cs, M.x86.saved_ip); - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EIP = pop_long(); - M.x86.R_CS = pop_long() & 0xffff; - } else { - M.x86.R_IP = pop_word(); - M.x86.R_CS = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xcc -****************************************************************************/ -static void -x86emuOp_int3(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("INT 3\n"); - TRACE_AND_STEP(); - if (_X86EMU_intrTab[3]) { - (*_X86EMU_intrTab[3]) (3); - } - else { - push_word((u16) M.x86.R_FLG); - CLEAR_FLAG(F_IF); - CLEAR_FLAG(F_TF); - push_word(M.x86.R_CS); - M.x86.R_CS = mem_access_word(3 * 4 + 2); - push_word(M.x86.R_IP); - M.x86.R_IP = mem_access_word(3 * 4); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xcd -****************************************************************************/ -static void -x86emuOp_int_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 intnum; - - START_OF_INSTR(); - DECODE_PRINTF("INT\t"); - intnum = fetch_byte_imm(); - DECODE_PRINTF2("%x\n", intnum); - TRACE_AND_STEP(); - if (_X86EMU_intrTab[intnum]) { - (*_X86EMU_intrTab[intnum]) (intnum); - } - else { - push_word((u16) M.x86.R_FLG); - CLEAR_FLAG(F_IF); - CLEAR_FLAG(F_TF); - push_word(M.x86.R_CS); - M.x86.R_CS = mem_access_word(intnum * 4 + 2); - push_word(M.x86.R_IP); - M.x86.R_IP = mem_access_word(intnum * 4); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xce -****************************************************************************/ -static void -x86emuOp_into(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("INTO\n"); - TRACE_AND_STEP(); - if (ACCESS_FLAG(F_OF)) { - if (_X86EMU_intrTab[4]) { - (*_X86EMU_intrTab[4]) (4); - } - else { - push_word((u16) M.x86.R_FLG); - CLEAR_FLAG(F_IF); - CLEAR_FLAG(F_TF); - push_word(M.x86.R_CS); - M.x86.R_CS = mem_access_word(4 * 4 + 2); - push_word(M.x86.R_IP); - M.x86.R_IP = mem_access_word(4 * 4); - } - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xcf -****************************************************************************/ -static void -x86emuOp_iret(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("IRET\n"); - - TRACE_AND_STEP(); - - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EIP = pop_long(); - M.x86.R_CS = pop_long() & 0xffff; - M.x86.R_EFLG = (pop_long() & 0x257FD5) | (M.x86.R_EFLG & 0x1A0000); - } else { - M.x86.R_IP = pop_word(); - M.x86.R_CS = pop_word(); - M.x86.R_FLG = pop_word(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xd0 -****************************************************************************/ -static void -x86emuOp_opcD0_byte_RM_1(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg; - uint destoffset; - u8 destval; - - /* - * Yet another weirdo special case instruction format. Part of - * the opcode held below in "RH". Doubly nested case would - * result, except that the decoded instruction - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - switch (rh) { - case 0: - DECODE_PRINTF("ROL\t"); - break; - case 1: - DECODE_PRINTF("ROR\t"); - break; - case 2: - DECODE_PRINTF("RCL\t"); - break; - case 3: - DECODE_PRINTF("RCR\t"); - break; - case 4: - DECODE_PRINTF("SHL\t"); - break; - case 5: - DECODE_PRINTF("SHR\t"); - break; - case 6: - DECODE_PRINTF("SAL\t"); - break; - case 7: - DECODE_PRINTF("SAR\t"); - break; - } - } -#endif - /* know operation, decode the mod byte to find the addressing - mode. */ - switch (mod) { - case 0: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(",1\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (destval, 1); - store_data_byte(destoffset, destval); - break; - case 1: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(",1\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (destval, 1); - store_data_byte(destoffset, destval); - break; - case 2: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(",1\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (destval, 1); - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(",1\n"); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (*destreg, 1); - *destreg = destval; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xd1 -****************************************************************************/ -static void -x86emuOp_opcD1_word_RM_1(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - /* - * Yet another weirdo special case instruction format. Part of - * the opcode held below in "RH". Doubly nested case would - * result, except that the decoded instruction - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - switch (rh) { - case 0: - DECODE_PRINTF("ROL\t"); - break; - case 1: - DECODE_PRINTF("ROR\t"); - break; - case 2: - DECODE_PRINTF("RCL\t"); - break; - case 3: - DECODE_PRINTF("RCR\t"); - break; - case 4: - DECODE_PRINTF("SHL\t"); - break; - case 5: - DECODE_PRINTF("SHR\t"); - break; - case 6: - DECODE_PRINTF("SAL\t"); - break; - case 7: - DECODE_PRINTF("SAR\t"); - break; - } - } -#endif - /* know operation, decode the mod byte to find the addressing - mode. */ - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(",1\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (destval, 1); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(",1\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (destval, 1); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(",1\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (destval, 1); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(",1\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (destval, 1); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(",1\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (destval, 1); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(",1\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (destval, 1); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *destreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(",1\n"); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (*destreg, 1); - *destreg = destval; - } - else { - u16 destval; - u16 *destreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(",1\n"); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (*destreg, 1); - *destreg = destval; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xd2 -****************************************************************************/ -static void -x86emuOp_opcD2_byte_RM_CL(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg; - uint destoffset; - u8 destval; - u8 amt; - - /* - * Yet another weirdo special case instruction format. Part of - * the opcode held below in "RH". Doubly nested case would - * result, except that the decoded instruction - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - switch (rh) { - case 0: - DECODE_PRINTF("ROL\t"); - break; - case 1: - DECODE_PRINTF("ROR\t"); - break; - case 2: - DECODE_PRINTF("RCL\t"); - break; - case 3: - DECODE_PRINTF("RCR\t"); - break; - case 4: - DECODE_PRINTF("SHL\t"); - break; - case 5: - DECODE_PRINTF("SHR\t"); - break; - case 6: - DECODE_PRINTF("SAL\t"); - break; - case 7: - DECODE_PRINTF("SAR\t"); - break; - } - } -#endif - /* know operation, decode the mod byte to find the addressing - mode. */ - amt = M.x86.R_CL; - switch (mod) { - case 0: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(",CL\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (destval, amt); - store_data_byte(destoffset, destval); - break; - case 1: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(",CL\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (destval, amt); - store_data_byte(destoffset, destval); - break; - case 2: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(",CL\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (destval, amt); - store_data_byte(destoffset, destval); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = (*opcD0_byte_operation[rh]) (*destreg, amt); - *destreg = destval; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xd3 -****************************************************************************/ -static void -x86emuOp_opcD3_word_RM_CL(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - u8 amt; - - /* - * Yet another weirdo special case instruction format. Part of - * the opcode held below in "RH". Doubly nested case would - * result, except that the decoded instruction - */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - switch (rh) { - case 0: - DECODE_PRINTF("ROL\t"); - break; - case 1: - DECODE_PRINTF("ROR\t"); - break; - case 2: - DECODE_PRINTF("RCL\t"); - break; - case 3: - DECODE_PRINTF("RCR\t"); - break; - case 4: - DECODE_PRINTF("SHL\t"); - break; - case 5: - DECODE_PRINTF("SHR\t"); - break; - case 6: - DECODE_PRINTF("SAL\t"); - break; - case 7: - DECODE_PRINTF("SAR\t"); - break; - } - } -#endif - /* know operation, decode the mod byte to find the addressing - mode. */ - amt = M.x86.R_CL; - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(",CL\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (destval, amt); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(",CL\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (destval, amt); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(",CL\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (destval, amt); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(",CL\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (destval, amt); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(",CL\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_long_operation[rh]) (destval, amt); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("WORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(",CL\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = (*opcD1_word_operation[rh]) (destval, amt); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - *destreg = (*opcD1_long_operation[rh]) (*destreg, amt); - } - else { - u16 *destreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - *destreg = (*opcD1_word_operation[rh]) (*destreg, amt); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xd4 -****************************************************************************/ -static void -x86emuOp_aam(u8 X86EMU_UNUSED(op1)) -{ - u8 a; - - START_OF_INSTR(); - DECODE_PRINTF("AAM\n"); - a = fetch_byte_imm(); /* this is a stupid encoding. */ - if (a != 10) { - /* fix: add base decoding - aam_word(u8 val, int base a) */ - DECODE_PRINTF("ERROR DECODING AAM\n"); - TRACE_REGS(); - HALT_SYS(); - } - TRACE_AND_STEP(); - /* note the type change here --- returning AL and AH in AX. */ - M.x86.R_AX = aam_word(M.x86.R_AL); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xd5 -****************************************************************************/ -static void -x86emuOp_aad(u8 X86EMU_UNUSED(op1)) -{ - u8 a; - - START_OF_INSTR(); - DECODE_PRINTF("AAD\n"); - a = fetch_byte_imm(); - if (a != 10) { - /* fix: add base decoding - aad_word(u16 val, int base a) */ - DECODE_PRINTF("ERROR DECODING AAM\n"); - TRACE_REGS(); - HALT_SYS(); - } - TRACE_AND_STEP(); - M.x86.R_AX = aad_word(M.x86.R_AX); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/* opcode 0xd6 ILLEGAL OPCODE */ - -/**************************************************************************** -REMARKS: -Handles opcode 0xd7 -****************************************************************************/ -static void -x86emuOp_xlat(u8 X86EMU_UNUSED(op1)) -{ - u16 addr; - - START_OF_INSTR(); - DECODE_PRINTF("XLAT\n"); - TRACE_AND_STEP(); - addr = (u16) (M.x86.R_BX + (u8) M.x86.R_AL); - M.x86.R_AL = fetch_data_byte(addr); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/* instuctions D8 .. DF are in i87_ops.c */ - -/**************************************************************************** -REMARKS: -Handles opcode 0xe0 -****************************************************************************/ -static void -x86emuOp_loopne(u8 X86EMU_UNUSED(op1)) -{ - s16 ip; - - START_OF_INSTR(); - DECODE_PRINTF("LOOPNE\t"); - ip = (s8) fetch_byte_imm(); - ip += (s16) M.x86.R_IP; - DECODE_PRINTF2("%04x\n", ip); - TRACE_AND_STEP(); - M.x86.R_CX -= 1; - if (M.x86.R_CX != 0 && !ACCESS_FLAG(F_ZF)) /* CX != 0 and !ZF */ - M.x86.R_IP = ip; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xe1 -****************************************************************************/ -static void -x86emuOp_loope(u8 X86EMU_UNUSED(op1)) -{ - s16 ip; - - START_OF_INSTR(); - DECODE_PRINTF("LOOPE\t"); - ip = (s8) fetch_byte_imm(); - ip += (s16) M.x86.R_IP; - DECODE_PRINTF2("%04x\n", ip); - TRACE_AND_STEP(); - M.x86.R_CX -= 1; - if (M.x86.R_CX != 0 && ACCESS_FLAG(F_ZF)) /* CX != 0 and ZF */ - M.x86.R_IP = ip; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xe2 -****************************************************************************/ -static void -x86emuOp_loop(u8 X86EMU_UNUSED(op1)) -{ - s16 ip; - - START_OF_INSTR(); - DECODE_PRINTF("LOOP\t"); - ip = (s8) fetch_byte_imm(); - ip += (s16) M.x86.R_IP; - DECODE_PRINTF2("%04x\n", ip); - TRACE_AND_STEP(); - M.x86.R_CX -= 1; - if (M.x86.R_CX != 0) - M.x86.R_IP = ip; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xe3 -****************************************************************************/ -static void -x86emuOp_jcxz(u8 X86EMU_UNUSED(op1)) -{ - u16 target; - s8 offset; - - /* jump to byte offset if overflow flag is set */ - START_OF_INSTR(); - DECODE_PRINTF("JCXZ\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - if (M.x86.R_CX == 0) - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xe4 -****************************************************************************/ -static void -x86emuOp_in_byte_AL_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 port; - - START_OF_INSTR(); - DECODE_PRINTF("IN\t"); - port = (u8) fetch_byte_imm(); - DECODE_PRINTF2("%x,AL\n", port); - TRACE_AND_STEP(); - M.x86.R_AL = (*sys_inb) (port); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xe5 -****************************************************************************/ -static void -x86emuOp_in_word_AX_IMM(u8 X86EMU_UNUSED(op1)) -{ - u8 port; - - START_OF_INSTR(); - DECODE_PRINTF("IN\t"); - port = (u8) fetch_byte_imm(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF2("EAX,%x\n", port); - } - else { - DECODE_PRINTF2("AX,%x\n", port); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = (*sys_inl) (port); - } - else { - M.x86.R_AX = (*sys_inw) (port); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xe6 -****************************************************************************/ -static void -x86emuOp_out_byte_IMM_AL(u8 X86EMU_UNUSED(op1)) -{ - u8 port; - - START_OF_INSTR(); - DECODE_PRINTF("OUT\t"); - port = (u8) fetch_byte_imm(); - DECODE_PRINTF2("%x,AL\n", port); - TRACE_AND_STEP(); - (*sys_outb) (port, M.x86.R_AL); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xe7 -****************************************************************************/ -static void -x86emuOp_out_word_IMM_AX(u8 X86EMU_UNUSED(op1)) -{ - u8 port; - - START_OF_INSTR(); - DECODE_PRINTF("OUT\t"); - port = (u8) fetch_byte_imm(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF2("%x,EAX\n", port); - } - else { - DECODE_PRINTF2("%x,AX\n", port); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - (*sys_outl) (port, M.x86.R_EAX); - } - else { - (*sys_outw) (port, M.x86.R_AX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xe8 -****************************************************************************/ -static void -x86emuOp_call_near_IMM(u8 X86EMU_UNUSED(op1)) -{ - s16 ip16 = 0; - s32 ip32 = 0; - - START_OF_INSTR(); - DECODE_PRINTF("CALL\t"); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - ip32 = (s32) fetch_long_imm(); - ip32 += (s16) M.x86.R_IP; /* CHECK SIGN */ - DECODE_PRINTF2("%04x\n", (u16) ip32); - CALL_TRACE(M.x86.saved_cs, M.x86.saved_ip, M.x86.R_CS, ip32, ""); - } - else { - ip16 = (s16) fetch_word_imm(); - ip16 += (s16) M.x86.R_IP; /* CHECK SIGN */ - DECODE_PRINTF2("%04x\n", (u16) ip16); - CALL_TRACE(M.x86.saved_cs, M.x86.saved_ip, M.x86.R_CS, ip16, ""); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - push_long(M.x86.R_EIP); - M.x86.R_EIP = ip32 & 0xffff; - } - else { - push_word(M.x86.R_IP); - M.x86.R_EIP = ip16; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xe9 -****************************************************************************/ -static void -x86emuOp_jump_near_IMM(u8 X86EMU_UNUSED(op1)) -{ - u32 ip; - - START_OF_INSTR(); - DECODE_PRINTF("JMP\t"); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - ip = (u32) fetch_long_imm(); - ip += (u32) M.x86.R_EIP; - DECODE_PRINTF2("%08x\n", (u32) ip); - TRACE_AND_STEP(); - M.x86.R_EIP = (u32) ip; - } - else { - ip = (s16) fetch_word_imm(); - ip += (s16) M.x86.R_IP; - DECODE_PRINTF2("%04x\n", (u16) ip); - TRACE_AND_STEP(); - M.x86.R_IP = (u16) ip; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xea -****************************************************************************/ -static void -x86emuOp_jump_far_IMM(u8 X86EMU_UNUSED(op1)) -{ - u16 cs; - u32 ip; - - START_OF_INSTR(); - DECODE_PRINTF("JMP\tFAR "); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - ip = fetch_long_imm(); - } - else { - ip = fetch_word_imm(); - } - cs = fetch_word_imm(); - DECODE_PRINTF2("%04x:", cs); - DECODE_PRINTF2("%04x\n", ip); - TRACE_AND_STEP(); - M.x86.R_EIP = ip & 0xffff; - M.x86.R_CS = cs; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xeb -****************************************************************************/ -static void -x86emuOp_jump_byte_IMM(u8 X86EMU_UNUSED(op1)) -{ - u16 target; - s8 offset; - - START_OF_INSTR(); - DECODE_PRINTF("JMP\t"); - offset = (s8) fetch_byte_imm(); - target = (u16) (M.x86.R_IP + offset); - DECODE_PRINTF2("%x\n", target); - TRACE_AND_STEP(); - M.x86.R_IP = target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xec -****************************************************************************/ -static void -x86emuOp_in_byte_AL_DX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("IN\tAL,DX\n"); - TRACE_AND_STEP(); - M.x86.R_AL = (*sys_inb) (M.x86.R_DX); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xed -****************************************************************************/ -static void -x86emuOp_in_word_AX_DX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("IN\tEAX,DX\n"); - } - else { - DECODE_PRINTF("IN\tAX,DX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_EAX = (*sys_inl) (M.x86.R_DX); - } - else { - M.x86.R_AX = (*sys_inw) (M.x86.R_DX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xee -****************************************************************************/ -static void -x86emuOp_out_byte_DX_AL(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("OUT\tDX,AL\n"); - TRACE_AND_STEP(); - (*sys_outb) (M.x86.R_DX, M.x86.R_AL); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xef -****************************************************************************/ -static void -x86emuOp_out_word_DX_AX(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("OUT\tDX,EAX\n"); - } - else { - DECODE_PRINTF("OUT\tDX,AX\n"); - } - TRACE_AND_STEP(); - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - (*sys_outl) (M.x86.R_DX, M.x86.R_EAX); - } - else { - (*sys_outw) (M.x86.R_DX, M.x86.R_AX); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xf0 -****************************************************************************/ -static void -x86emuOp_lock(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("LOCK:\n"); - TRACE_AND_STEP(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/*opcode 0xf1 ILLEGAL OPERATION */ - -/**************************************************************************** -REMARKS: -Handles opcode 0xf2 -****************************************************************************/ -static void -x86emuOp_repne(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("REPNE\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_PREFIX_REPNE; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xf3 -****************************************************************************/ -static void -x86emuOp_repe(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("REPE\n"); - TRACE_AND_STEP(); - M.x86.mode |= SYSMODE_PREFIX_REPE; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xf4 -****************************************************************************/ -static void -x86emuOp_halt(u8 X86EMU_UNUSED(op1)) -{ - START_OF_INSTR(); - DECODE_PRINTF("HALT\n"); - TRACE_AND_STEP(); - HALT_SYS(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xf5 -****************************************************************************/ -static void -x86emuOp_cmc(u8 X86EMU_UNUSED(op1)) -{ - /* complement the carry flag. */ - START_OF_INSTR(); - DECODE_PRINTF("CMC\n"); - TRACE_AND_STEP(); - TOGGLE_FLAG(F_CF); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xf6 -****************************************************************************/ -static void -x86emuOp_opcF6_byte_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - u8 *destreg; - uint destoffset; - u8 destval, srcval; - - /* long, drawn out code follows. Double switch for a total - of 32 cases. */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: /* mod=00 */ - switch (rh) { - case 0: /* test byte imm */ - DECODE_PRINTF("TEST\tBYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%02x\n", srcval); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - test_byte(destval, srcval); - break; - case 1: - DECODE_PRINTF("ILLEGAL OP MOD=00 RH=01 OP=F6\n"); - HALT_SYS(); - break; - case 2: - DECODE_PRINTF("NOT\tBYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = not_byte(destval); - store_data_byte(destoffset, destval); - break; - case 3: - DECODE_PRINTF("NEG\tBYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = neg_byte(destval); - store_data_byte(destoffset, destval); - break; - case 4: - DECODE_PRINTF("MUL\tBYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - mul_byte(destval); - break; - case 5: - DECODE_PRINTF("IMUL\tBYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - imul_byte(destval); - break; - case 6: - DECODE_PRINTF("DIV\tBYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - div_byte(destval); - break; - case 7: - DECODE_PRINTF("IDIV\tBYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - idiv_byte(destval); - break; - } - break; /* end mod==00 */ - case 1: /* mod=01 */ - switch (rh) { - case 0: /* test byte imm */ - DECODE_PRINTF("TEST\tBYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%02x\n", srcval); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - test_byte(destval, srcval); - break; - case 1: - DECODE_PRINTF("ILLEGAL OP MOD=01 RH=01 OP=F6\n"); - HALT_SYS(); - break; - case 2: - DECODE_PRINTF("NOT\tBYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = not_byte(destval); - store_data_byte(destoffset, destval); - break; - case 3: - DECODE_PRINTF("NEG\tBYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = neg_byte(destval); - store_data_byte(destoffset, destval); - break; - case 4: - DECODE_PRINTF("MUL\tBYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - mul_byte(destval); - break; - case 5: - DECODE_PRINTF("IMUL\tBYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - imul_byte(destval); - break; - case 6: - DECODE_PRINTF("DIV\tBYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - div_byte(destval); - break; - case 7: - DECODE_PRINTF("IDIV\tBYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - idiv_byte(destval); - break; - } - break; /* end mod==01 */ - case 2: /* mod=10 */ - switch (rh) { - case 0: /* test byte imm */ - DECODE_PRINTF("TEST\tBYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%02x\n", srcval); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - test_byte(destval, srcval); - break; - case 1: - DECODE_PRINTF("ILLEGAL OP MOD=10 RH=01 OP=F6\n"); - HALT_SYS(); - break; - case 2: - DECODE_PRINTF("NOT\tBYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = not_byte(destval); - store_data_byte(destoffset, destval); - break; - case 3: - DECODE_PRINTF("NEG\tBYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = neg_byte(destval); - store_data_byte(destoffset, destval); - break; - case 4: - DECODE_PRINTF("MUL\tBYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - mul_byte(destval); - break; - case 5: - DECODE_PRINTF("IMUL\tBYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - imul_byte(destval); - break; - case 6: - DECODE_PRINTF("DIV\tBYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - div_byte(destval); - break; - case 7: - DECODE_PRINTF("IDIV\tBYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - idiv_byte(destval); - break; - } - break; /* end mod==10 */ - case 3: /* mod=11 */ - switch (rh) { - case 0: /* test byte imm */ - DECODE_PRINTF("TEST\t"); - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF(","); - srcval = fetch_byte_imm(); - DECODE_PRINTF2("%02x\n", srcval); - TRACE_AND_STEP(); - test_byte(*destreg, srcval); - break; - case 1: - DECODE_PRINTF("ILLEGAL OP MOD=00 RH=01 OP=F6\n"); - HALT_SYS(); - break; - case 2: - DECODE_PRINTF("NOT\t"); - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = not_byte(*destreg); - break; - case 3: - DECODE_PRINTF("NEG\t"); - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = neg_byte(*destreg); - break; - case 4: - DECODE_PRINTF("MUL\t"); - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - mul_byte(*destreg); /*!!! */ - break; - case 5: - DECODE_PRINTF("IMUL\t"); - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - imul_byte(*destreg); - break; - case 6: - DECODE_PRINTF("DIV\t"); - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - div_byte(*destreg); - break; - case 7: - DECODE_PRINTF("IDIV\t"); - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - idiv_byte(*destreg); - break; - } - break; /* end mod==11 */ - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xf7 -****************************************************************************/ -static void -x86emuOp_opcF7_word_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rl, rh; - uint destoffset; - - /* long, drawn out code follows. Double switch for a total - of 32 cases. */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: /* mod=00 */ - switch (rh) { - case 0: /* test word imm */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval, srcval; - - DECODE_PRINTF("TEST\tDWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - srcval = fetch_long_imm(); - DECODE_PRINTF2("%x\n", srcval); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - test_long(destval, srcval); - } - else { - u16 destval, srcval; - - DECODE_PRINTF("TEST\tWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - srcval = fetch_word_imm(); - DECODE_PRINTF2("%x\n", srcval); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - test_word(destval, srcval); - } - break; - case 1: - DECODE_PRINTF("ILLEGAL OP MOD=00 RH=01 OP=F7\n"); - HALT_SYS(); - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("NOT\tDWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = not_long(destval); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("NOT\tWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = not_word(destval); - store_data_word(destoffset, destval); - } - break; - case 3: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("NEG\tDWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = neg_long(destval); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("NEG\tWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = neg_word(destval); - store_data_word(destoffset, destval); - } - break; - case 4: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("MUL\tDWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - mul_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("MUL\tWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - mul_word(destval); - } - break; - case 5: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("IMUL\tDWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - imul_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("IMUL\tWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - imul_word(destval); - } - break; - case 6: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DIV\tDWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - div_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("DIV\tWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - div_word(destval); - } - break; - case 7: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("IDIV\tDWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - idiv_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("IDIV\tWORD PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - idiv_word(destval); - } - break; - } - break; /* end mod==00 */ - case 1: /* mod=01 */ - switch (rh) { - case 0: /* test word imm */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval, srcval; - - DECODE_PRINTF("TEST\tDWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - srcval = fetch_long_imm(); - DECODE_PRINTF2("%x\n", srcval); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - test_long(destval, srcval); - } - else { - u16 destval, srcval; - - DECODE_PRINTF("TEST\tWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - srcval = fetch_word_imm(); - DECODE_PRINTF2("%x\n", srcval); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - test_word(destval, srcval); - } - break; - case 1: - DECODE_PRINTF("ILLEGAL OP MOD=01 RH=01 OP=F6\n"); - HALT_SYS(); - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("NOT\tDWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = not_long(destval); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("NOT\tWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = not_word(destval); - store_data_word(destoffset, destval); - } - break; - case 3: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("NEG\tDWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = neg_long(destval); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("NEG\tWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = neg_word(destval); - store_data_word(destoffset, destval); - } - break; - case 4: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("MUL\tDWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - mul_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("MUL\tWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - mul_word(destval); - } - break; - case 5: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("IMUL\tDWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - imul_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("IMUL\tWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - imul_word(destval); - } - break; - case 6: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DIV\tDWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - div_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("DIV\tWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - div_word(destval); - } - break; - case 7: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("IDIV\tDWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - idiv_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("IDIV\tWORD PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - idiv_word(destval); - } - break; - } - break; /* end mod==01 */ - case 2: /* mod=10 */ - switch (rh) { - case 0: /* test word imm */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval, srcval; - - DECODE_PRINTF("TEST\tDWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - srcval = fetch_long_imm(); - DECODE_PRINTF2("%x\n", srcval); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - test_long(destval, srcval); - } - else { - u16 destval, srcval; - - DECODE_PRINTF("TEST\tWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - srcval = fetch_word_imm(); - DECODE_PRINTF2("%x\n", srcval); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - test_word(destval, srcval); - } - break; - case 1: - DECODE_PRINTF("ILLEGAL OP MOD=10 RH=01 OP=F6\n"); - HALT_SYS(); - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("NOT\tDWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = not_long(destval); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("NOT\tWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = not_word(destval); - store_data_word(destoffset, destval); - } - break; - case 3: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("NEG\tDWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval = neg_long(destval); - store_data_long(destoffset, destval); - } - else { - u16 destval; - - DECODE_PRINTF("NEG\tWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval = neg_word(destval); - store_data_word(destoffset, destval); - } - break; - case 4: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("MUL\tDWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - mul_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("MUL\tWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - mul_word(destval); - } - break; - case 5: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("IMUL\tDWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - imul_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("IMUL\tWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - imul_word(destval); - } - break; - case 6: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("DIV\tDWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - div_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("DIV\tWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - div_word(destval); - } - break; - case 7: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - - DECODE_PRINTF("IDIV\tDWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - idiv_long(destval); - } - else { - u16 destval; - - DECODE_PRINTF("IDIV\tWORD PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - idiv_word(destval); - } - break; - } - break; /* end mod==10 */ - case 3: /* mod=11 */ - switch (rh) { - case 0: /* test word imm */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - DECODE_PRINTF("TEST\t"); - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - srcval = fetch_long_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - test_long(*destreg, srcval); - } - else { - u16 *destreg; - u16 srcval; - - DECODE_PRINTF("TEST\t"); - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - srcval = fetch_word_imm(); - DECODE_PRINTF2("%x\n", srcval); - TRACE_AND_STEP(); - test_word(*destreg, srcval); - } - break; - case 1: - DECODE_PRINTF("ILLEGAL OP MOD=00 RH=01 OP=F6\n"); - HALT_SYS(); - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - - DECODE_PRINTF("NOT\t"); - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = not_long(*destreg); - } - else { - u16 *destreg; - - DECODE_PRINTF("NOT\t"); - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = not_word(*destreg); - } - break; - case 3: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - - DECODE_PRINTF("NEG\t"); - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = neg_long(*destreg); - } - else { - u16 *destreg; - - DECODE_PRINTF("NEG\t"); - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = neg_word(*destreg); - } - break; - case 4: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - - DECODE_PRINTF("MUL\t"); - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - mul_long(*destreg); /*!!! */ - } - else { - u16 *destreg; - - DECODE_PRINTF("MUL\t"); - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - mul_word(*destreg); /*!!! */ - } - break; - case 5: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - - DECODE_PRINTF("IMUL\t"); - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - imul_long(*destreg); - } - else { - u16 *destreg; - - DECODE_PRINTF("IMUL\t"); - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - imul_word(*destreg); - } - break; - case 6: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - - DECODE_PRINTF("DIV\t"); - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - div_long(*destreg); - } - else { - u16 *destreg; - - DECODE_PRINTF("DIV\t"); - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - div_word(*destreg); - } - break; - case 7: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - - DECODE_PRINTF("IDIV\t"); - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - idiv_long(*destreg); - } - else { - u16 *destreg; - - DECODE_PRINTF("IDIV\t"); - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - idiv_word(*destreg); - } - break; - } - break; /* end mod==11 */ - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xf8 -****************************************************************************/ -static void -x86emuOp_clc(u8 X86EMU_UNUSED(op1)) -{ - /* clear the carry flag. */ - START_OF_INSTR(); - DECODE_PRINTF("CLC\n"); - TRACE_AND_STEP(); - CLEAR_FLAG(F_CF); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xf9 -****************************************************************************/ -static void -x86emuOp_stc(u8 X86EMU_UNUSED(op1)) -{ - /* set the carry flag. */ - START_OF_INSTR(); - DECODE_PRINTF("STC\n"); - TRACE_AND_STEP(); - SET_FLAG(F_CF); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xfa -****************************************************************************/ -static void -x86emuOp_cli(u8 X86EMU_UNUSED(op1)) -{ - /* clear interrupts. */ - START_OF_INSTR(); - DECODE_PRINTF("CLI\n"); - TRACE_AND_STEP(); - CLEAR_FLAG(F_IF); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xfb -****************************************************************************/ -static void -x86emuOp_sti(u8 X86EMU_UNUSED(op1)) -{ - /* enable interrupts. */ - START_OF_INSTR(); - DECODE_PRINTF("STI\n"); - TRACE_AND_STEP(); - SET_FLAG(F_IF); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xfc -****************************************************************************/ -static void -x86emuOp_cld(u8 X86EMU_UNUSED(op1)) -{ - /* clear interrupts. */ - START_OF_INSTR(); - DECODE_PRINTF("CLD\n"); - TRACE_AND_STEP(); - CLEAR_FLAG(F_DF); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xfd -****************************************************************************/ -static void -x86emuOp_std(u8 X86EMU_UNUSED(op1)) -{ - /* clear interrupts. */ - START_OF_INSTR(); - DECODE_PRINTF("STD\n"); - TRACE_AND_STEP(); - SET_FLAG(F_DF); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xfe -****************************************************************************/ -static void -x86emuOp_opcFE_byte_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rh, rl; - u8 destval; - uint destoffset; - u8 *destreg; - - /* Yet another special case instruction. */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - - switch (rh) { - case 0: - DECODE_PRINTF("INC\t"); - break; - case 1: - DECODE_PRINTF("DEC\t"); - break; - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - DECODE_PRINTF2("ILLEGAL OP MAJOR OP 0xFE MINOR OP %x \n", mod); - HALT_SYS(); - break; - } - } -#endif - switch (mod) { - case 0: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - switch (rh) { - case 0: /* inc word ptr ... */ - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = inc_byte(destval); - store_data_byte(destoffset, destval); - break; - case 1: /* dec word ptr ... */ - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = dec_byte(destval); - store_data_byte(destoffset, destval); - break; - } - break; - case 1: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - switch (rh) { - case 0: - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = inc_byte(destval); - store_data_byte(destoffset, destval); - break; - case 1: - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = dec_byte(destval); - store_data_byte(destoffset, destval); - break; - } - break; - case 2: - DECODE_PRINTF("BYTE PTR "); - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - switch (rh) { - case 0: - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = inc_byte(destval); - store_data_byte(destoffset, destval); - break; - case 1: - destval = fetch_data_byte(destoffset); - TRACE_AND_STEP(); - destval = dec_byte(destval); - store_data_byte(destoffset, destval); - break; - } - break; - case 3: - destreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - switch (rh) { - case 0: - TRACE_AND_STEP(); - *destreg = inc_byte(*destreg); - break; - case 1: - TRACE_AND_STEP(); - *destreg = dec_byte(*destreg); - break; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0xff -****************************************************************************/ -static void -x86emuOp_opcFF_word_RM(u8 X86EMU_UNUSED(op1)) -{ - int mod, rh, rl; - uint destoffset = 0; - u16 *destreg; - u16 destval, destval2; - - /* Yet another special case instruction. */ - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); -#ifdef DEBUG - if (DEBUG_DECODE()) { - /* XXX DECODE_PRINTF may be changed to something more - general, so that it is important to leave the strings - in the same format, even though the result is that the - above test is done twice. */ - - switch (rh) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("INC\tDWORD PTR "); - } - else { - DECODE_PRINTF("INC\tWORD PTR "); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - DECODE_PRINTF("DEC\tDWORD PTR "); - } - else { - DECODE_PRINTF("DEC\tWORD PTR "); - } - break; - case 2: - DECODE_PRINTF("CALL\t"); - break; - case 3: - DECODE_PRINTF("CALL\tFAR "); - break; - case 4: - DECODE_PRINTF("JMP\t"); - break; - case 5: - DECODE_PRINTF("JMP\tFAR "); - break; - case 6: - DECODE_PRINTF("PUSH\t"); - break; - case 7: - DECODE_PRINTF("ILLEGAL DECODING OF OPCODE FF\t"); - HALT_SYS(); - break; - } - } -#endif - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - switch (rh) { - case 0: /* inc word ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval32; - - destval32 = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval32 = inc_long(destval32); - store_data_long(destoffset, destval32); - } - else { - u16 destval16; - - destval16 = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval16 = inc_word(destval16); - store_data_word(destoffset, destval16); - } - break; - case 1: /* dec word ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval32; - - destval32 = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval32 = dec_long(destval32); - store_data_long(destoffset, destval32); - } - else { - u16 destval16; - - destval16 = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval16 = dec_word(destval16); - store_data_word(destoffset, destval16); - } - break; - case 2: /* call word ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - push_long(M.x86.R_EIP); - M.x86.R_EIP = destval; - } else { - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - push_word(M.x86.R_IP); - M.x86.R_IP = destval; - } - break; - case 3: /* call far ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - destval = fetch_data_long(destoffset); - destval2 = fetch_data_word(destoffset + 4); - TRACE_AND_STEP(); - push_long(M.x86.R_CS); - M.x86.R_CS = destval2; - push_long(M.x86.R_EIP); - M.x86.R_EIP = destval; - } else { - destval = fetch_data_word(destoffset); - destval2 = fetch_data_word(destoffset + 2); - TRACE_AND_STEP(); - push_word(M.x86.R_CS); - M.x86.R_CS = destval2; - push_word(M.x86.R_IP); - M.x86.R_IP = destval; - } - break; - case 4: /* jmp word ptr ... */ - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - M.x86.R_IP = destval; - break; - case 5: /* jmp far ptr ... */ - destval = fetch_data_word(destoffset); - destval2 = fetch_data_word(destoffset + 2); - TRACE_AND_STEP(); - M.x86.R_IP = destval; - M.x86.R_CS = destval2; - break; - case 6: /* push word ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval32; - - destval32 = fetch_data_long(destoffset); - TRACE_AND_STEP(); - push_long(destval32); - } - else { - u16 destval16; - - destval16 = fetch_data_word(destoffset); - TRACE_AND_STEP(); - push_word(destval16); - } - break; - } - break; - case 1: - destoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - switch (rh) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval32; - - destval32 = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval32 = inc_long(destval32); - store_data_long(destoffset, destval32); - } - else { - u16 destval16; - - destval16 = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval16 = inc_word(destval16); - store_data_word(destoffset, destval16); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval32; - - destval32 = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval32 = dec_long(destval32); - store_data_long(destoffset, destval32); - } - else { - u16 destval16; - - destval16 = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval16 = dec_word(destval16); - store_data_word(destoffset, destval16); - } - break; - case 2: /* call word ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - push_long(M.x86.R_EIP); - M.x86.R_EIP = destval; - } else { - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - push_word(M.x86.R_IP); - M.x86.R_IP = destval; - } - break; - case 3: /* call far ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - destval = fetch_data_long(destoffset); - destval2 = fetch_data_word(destoffset + 4); - TRACE_AND_STEP(); - push_long(M.x86.R_CS); - M.x86.R_CS = destval2; - push_long(M.x86.R_EIP); - M.x86.R_EIP = destval; - } else { - destval = fetch_data_word(destoffset); - destval2 = fetch_data_word(destoffset + 2); - TRACE_AND_STEP(); - push_word(M.x86.R_CS); - M.x86.R_CS = destval2; - push_word(M.x86.R_IP); - M.x86.R_IP = destval; - } - break; - case 4: /* jmp word ptr ... */ - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - M.x86.R_IP = destval; - break; - case 5: /* jmp far ptr ... */ - destval = fetch_data_word(destoffset); - destval2 = fetch_data_word(destoffset + 2); - TRACE_AND_STEP(); - M.x86.R_IP = destval; - M.x86.R_CS = destval2; - break; - case 6: /* push word ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval32; - - destval32 = fetch_data_long(destoffset); - TRACE_AND_STEP(); - push_long(destval32); - } - else { - u16 destval16; - - destval16 = fetch_data_word(destoffset); - TRACE_AND_STEP(); - push_word(destval16); - } - break; - } - break; - case 2: - destoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - switch (rh) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval32; - - destval32 = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval32 = inc_long(destval32); - store_data_long(destoffset, destval32); - } - else { - u16 destval16; - - destval16 = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval16 = inc_word(destval16); - store_data_word(destoffset, destval16); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval32; - - destval32 = fetch_data_long(destoffset); - TRACE_AND_STEP(); - destval32 = dec_long(destval32); - store_data_long(destoffset, destval32); - } - else { - u16 destval16; - - destval16 = fetch_data_word(destoffset); - TRACE_AND_STEP(); - destval16 = dec_word(destval16); - store_data_word(destoffset, destval16); - } - break; - case 2: /* call word ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - destval = fetch_data_long(destoffset); - TRACE_AND_STEP(); - push_long(M.x86.R_EIP); - M.x86.R_EIP = destval; - } else { - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - push_word(M.x86.R_IP); - M.x86.R_IP = destval; - } - break; - case 3: /* call far ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - destval = fetch_data_long(destoffset); - destval2 = fetch_data_word(destoffset + 4); - TRACE_AND_STEP(); - push_long(M.x86.R_CS); - M.x86.R_CS = destval2; - push_long(M.x86.R_EIP); - M.x86.R_EIP = destval; - } else { - destval = fetch_data_word(destoffset); - destval2 = fetch_data_word(destoffset + 2); - TRACE_AND_STEP(); - push_word(M.x86.R_CS); - M.x86.R_CS = destval2; - push_word(M.x86.R_IP); - M.x86.R_IP = destval; - } - break; - case 4: /* jmp word ptr ... */ - destval = fetch_data_word(destoffset); - TRACE_AND_STEP(); - M.x86.R_IP = destval; - break; - case 5: /* jmp far ptr ... */ - destval = fetch_data_word(destoffset); - destval2 = fetch_data_word(destoffset + 2); - TRACE_AND_STEP(); - M.x86.R_IP = destval; - M.x86.R_CS = destval2; - break; - case 6: /* push word ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval32; - - destval32 = fetch_data_long(destoffset); - TRACE_AND_STEP(); - push_long(destval32); - } - else { - u16 destval16; - - destval16 = fetch_data_word(destoffset); - TRACE_AND_STEP(); - push_word(destval16); - } - break; - } - break; - case 3: - switch (rh) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg32; - - destreg32 = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg32 = inc_long(*destreg32); - } - else { - u16 *destreg16; - - destreg16 = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg16 = inc_word(*destreg16); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg32; - - destreg32 = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg32 = dec_long(*destreg32); - } - else { - u16 *destreg16; - - destreg16 = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg16 = dec_word(*destreg16); - } - break; - case 2: /* call word ptr ... */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - destreg = (u16 *)DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - push_long(M.x86.R_EIP); - M.x86.R_EIP = *destreg; - } else { - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - push_word(M.x86.R_IP); - M.x86.R_IP = *destreg; - } - break; - case 3: /* jmp far ptr ... */ - DECODE_PRINTF("OPERATION UNDEFINED 0XFF \n"); - TRACE_AND_STEP(); - HALT_SYS(); - break; - - case 4: /* jmp ... */ - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - M.x86.R_IP = (u16) (*destreg); - break; - case 5: /* jmp far ptr ... */ - DECODE_PRINTF("OPERATION UNDEFINED 0XFF \n"); - TRACE_AND_STEP(); - HALT_SYS(); - break; - case 6: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg32; - - destreg32 = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - push_long(*destreg32); - } - else { - u16 *destreg16; - - destreg16 = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - push_word(*destreg16); - } - break; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/*************************************************************************** - * Single byte operation code table: - **************************************************************************/ -void (*x86emu_optab[256]) (u8) = { -/* 0x00 */ x86emuOp_add_byte_RM_R, -/* 0x01 */ x86emuOp_add_word_RM_R, -/* 0x02 */ x86emuOp_add_byte_R_RM, -/* 0x03 */ x86emuOp_add_word_R_RM, -/* 0x04 */ x86emuOp_add_byte_AL_IMM, -/* 0x05 */ x86emuOp_add_word_AX_IMM, -/* 0x06 */ x86emuOp_push_ES, -/* 0x07 */ x86emuOp_pop_ES, -/* 0x08 */ x86emuOp_or_byte_RM_R, -/* 0x09 */ x86emuOp_or_word_RM_R, -/* 0x0a */ x86emuOp_or_byte_R_RM, -/* 0x0b */ x86emuOp_or_word_R_RM, -/* 0x0c */ x86emuOp_or_byte_AL_IMM, -/* 0x0d */ x86emuOp_or_word_AX_IMM, -/* 0x0e */ x86emuOp_push_CS, -/* 0x0f */ x86emuOp_two_byte, -/* 0x10 */ x86emuOp_adc_byte_RM_R, -/* 0x11 */ x86emuOp_adc_word_RM_R, -/* 0x12 */ x86emuOp_adc_byte_R_RM, -/* 0x13 */ x86emuOp_adc_word_R_RM, -/* 0x14 */ x86emuOp_adc_byte_AL_IMM, -/* 0x15 */ x86emuOp_adc_word_AX_IMM, -/* 0x16 */ x86emuOp_push_SS, -/* 0x17 */ x86emuOp_pop_SS, -/* 0x18 */ x86emuOp_sbb_byte_RM_R, -/* 0x19 */ x86emuOp_sbb_word_RM_R, -/* 0x1a */ x86emuOp_sbb_byte_R_RM, -/* 0x1b */ x86emuOp_sbb_word_R_RM, -/* 0x1c */ x86emuOp_sbb_byte_AL_IMM, -/* 0x1d */ x86emuOp_sbb_word_AX_IMM, -/* 0x1e */ x86emuOp_push_DS, -/* 0x1f */ x86emuOp_pop_DS, -/* 0x20 */ x86emuOp_and_byte_RM_R, -/* 0x21 */ x86emuOp_and_word_RM_R, -/* 0x22 */ x86emuOp_and_byte_R_RM, -/* 0x23 */ x86emuOp_and_word_R_RM, -/* 0x24 */ x86emuOp_and_byte_AL_IMM, -/* 0x25 */ x86emuOp_and_word_AX_IMM, -/* 0x26 */ x86emuOp_segovr_ES, -/* 0x27 */ x86emuOp_daa, -/* 0x28 */ x86emuOp_sub_byte_RM_R, -/* 0x29 */ x86emuOp_sub_word_RM_R, -/* 0x2a */ x86emuOp_sub_byte_R_RM, -/* 0x2b */ x86emuOp_sub_word_R_RM, -/* 0x2c */ x86emuOp_sub_byte_AL_IMM, -/* 0x2d */ x86emuOp_sub_word_AX_IMM, -/* 0x2e */ x86emuOp_segovr_CS, -/* 0x2f */ x86emuOp_das, -/* 0x30 */ x86emuOp_xor_byte_RM_R, -/* 0x31 */ x86emuOp_xor_word_RM_R, -/* 0x32 */ x86emuOp_xor_byte_R_RM, -/* 0x33 */ x86emuOp_xor_word_R_RM, -/* 0x34 */ x86emuOp_xor_byte_AL_IMM, -/* 0x35 */ x86emuOp_xor_word_AX_IMM, -/* 0x36 */ x86emuOp_segovr_SS, -/* 0x37 */ x86emuOp_aaa, -/* 0x38 */ x86emuOp_cmp_byte_RM_R, -/* 0x39 */ x86emuOp_cmp_word_RM_R, -/* 0x3a */ x86emuOp_cmp_byte_R_RM, -/* 0x3b */ x86emuOp_cmp_word_R_RM, -/* 0x3c */ x86emuOp_cmp_byte_AL_IMM, -/* 0x3d */ x86emuOp_cmp_word_AX_IMM, -/* 0x3e */ x86emuOp_segovr_DS, -/* 0x3f */ x86emuOp_aas, -/* 0x40 */ x86emuOp_inc_AX, -/* 0x41 */ x86emuOp_inc_CX, -/* 0x42 */ x86emuOp_inc_DX, -/* 0x43 */ x86emuOp_inc_BX, -/* 0x44 */ x86emuOp_inc_SP, -/* 0x45 */ x86emuOp_inc_BP, -/* 0x46 */ x86emuOp_inc_SI, -/* 0x47 */ x86emuOp_inc_DI, -/* 0x48 */ x86emuOp_dec_AX, -/* 0x49 */ x86emuOp_dec_CX, -/* 0x4a */ x86emuOp_dec_DX, -/* 0x4b */ x86emuOp_dec_BX, -/* 0x4c */ x86emuOp_dec_SP, -/* 0x4d */ x86emuOp_dec_BP, -/* 0x4e */ x86emuOp_dec_SI, -/* 0x4f */ x86emuOp_dec_DI, -/* 0x50 */ x86emuOp_push_AX, -/* 0x51 */ x86emuOp_push_CX, -/* 0x52 */ x86emuOp_push_DX, -/* 0x53 */ x86emuOp_push_BX, -/* 0x54 */ x86emuOp_push_SP, -/* 0x55 */ x86emuOp_push_BP, -/* 0x56 */ x86emuOp_push_SI, -/* 0x57 */ x86emuOp_push_DI, -/* 0x58 */ x86emuOp_pop_AX, -/* 0x59 */ x86emuOp_pop_CX, -/* 0x5a */ x86emuOp_pop_DX, -/* 0x5b */ x86emuOp_pop_BX, -/* 0x5c */ x86emuOp_pop_SP, -/* 0x5d */ x86emuOp_pop_BP, -/* 0x5e */ x86emuOp_pop_SI, -/* 0x5f */ x86emuOp_pop_DI, -/* 0x60 */ x86emuOp_push_all, -/* 0x61 */ x86emuOp_pop_all, - /* 0x62 */ x86emuOp_illegal_op, - /* bound */ - /* 0x63 */ x86emuOp_illegal_op, - /* arpl */ -/* 0x64 */ x86emuOp_segovr_FS, -/* 0x65 */ x86emuOp_segovr_GS, -/* 0x66 */ x86emuOp_prefix_data, -/* 0x67 */ x86emuOp_prefix_addr, -/* 0x68 */ x86emuOp_push_word_IMM, -/* 0x69 */ x86emuOp_imul_word_IMM, -/* 0x6a */ x86emuOp_push_byte_IMM, -/* 0x6b */ x86emuOp_imul_byte_IMM, -/* 0x6c */ x86emuOp_ins_byte, -/* 0x6d */ x86emuOp_ins_word, -/* 0x6e */ x86emuOp_outs_byte, -/* 0x6f */ x86emuOp_outs_word, -/* 0x70 */ x86emuOp_jump_near_O, -/* 0x71 */ x86emuOp_jump_near_NO, -/* 0x72 */ x86emuOp_jump_near_B, -/* 0x73 */ x86emuOp_jump_near_NB, -/* 0x74 */ x86emuOp_jump_near_Z, -/* 0x75 */ x86emuOp_jump_near_NZ, -/* 0x76 */ x86emuOp_jump_near_BE, -/* 0x77 */ x86emuOp_jump_near_NBE, -/* 0x78 */ x86emuOp_jump_near_S, -/* 0x79 */ x86emuOp_jump_near_NS, -/* 0x7a */ x86emuOp_jump_near_P, -/* 0x7b */ x86emuOp_jump_near_NP, -/* 0x7c */ x86emuOp_jump_near_L, -/* 0x7d */ x86emuOp_jump_near_NL, -/* 0x7e */ x86emuOp_jump_near_LE, -/* 0x7f */ x86emuOp_jump_near_NLE, -/* 0x80 */ x86emuOp_opc80_byte_RM_IMM, -/* 0x81 */ x86emuOp_opc81_word_RM_IMM, -/* 0x82 */ x86emuOp_opc82_byte_RM_IMM, -/* 0x83 */ x86emuOp_opc83_word_RM_IMM, -/* 0x84 */ x86emuOp_test_byte_RM_R, -/* 0x85 */ x86emuOp_test_word_RM_R, -/* 0x86 */ x86emuOp_xchg_byte_RM_R, -/* 0x87 */ x86emuOp_xchg_word_RM_R, -/* 0x88 */ x86emuOp_mov_byte_RM_R, -/* 0x89 */ x86emuOp_mov_word_RM_R, -/* 0x8a */ x86emuOp_mov_byte_R_RM, -/* 0x8b */ x86emuOp_mov_word_R_RM, -/* 0x8c */ x86emuOp_mov_word_RM_SR, -/* 0x8d */ x86emuOp_lea_word_R_M, -/* 0x8e */ x86emuOp_mov_word_SR_RM, -/* 0x8f */ x86emuOp_pop_RM, -/* 0x90 */ x86emuOp_nop, -/* 0x91 */ x86emuOp_xchg_word_AX_CX, -/* 0x92 */ x86emuOp_xchg_word_AX_DX, -/* 0x93 */ x86emuOp_xchg_word_AX_BX, -/* 0x94 */ x86emuOp_xchg_word_AX_SP, -/* 0x95 */ x86emuOp_xchg_word_AX_BP, -/* 0x96 */ x86emuOp_xchg_word_AX_SI, -/* 0x97 */ x86emuOp_xchg_word_AX_DI, -/* 0x98 */ x86emuOp_cbw, -/* 0x99 */ x86emuOp_cwd, -/* 0x9a */ x86emuOp_call_far_IMM, -/* 0x9b */ x86emuOp_wait, -/* 0x9c */ x86emuOp_pushf_word, -/* 0x9d */ x86emuOp_popf_word, -/* 0x9e */ x86emuOp_sahf, -/* 0x9f */ x86emuOp_lahf, -/* 0xa0 */ x86emuOp_mov_AL_M_IMM, -/* 0xa1 */ x86emuOp_mov_AX_M_IMM, -/* 0xa2 */ x86emuOp_mov_M_AL_IMM, -/* 0xa3 */ x86emuOp_mov_M_AX_IMM, -/* 0xa4 */ x86emuOp_movs_byte, -/* 0xa5 */ x86emuOp_movs_word, -/* 0xa6 */ x86emuOp_cmps_byte, -/* 0xa7 */ x86emuOp_cmps_word, -/* 0xa8 */ x86emuOp_test_AL_IMM, -/* 0xa9 */ x86emuOp_test_AX_IMM, -/* 0xaa */ x86emuOp_stos_byte, -/* 0xab */ x86emuOp_stos_word, -/* 0xac */ x86emuOp_lods_byte, -/* 0xad */ x86emuOp_lods_word, -/* 0xac */ x86emuOp_scas_byte, -/* 0xad */ x86emuOp_scas_word, -/* 0xb0 */ x86emuOp_mov_byte_AL_IMM, -/* 0xb1 */ x86emuOp_mov_byte_CL_IMM, -/* 0xb2 */ x86emuOp_mov_byte_DL_IMM, -/* 0xb3 */ x86emuOp_mov_byte_BL_IMM, -/* 0xb4 */ x86emuOp_mov_byte_AH_IMM, -/* 0xb5 */ x86emuOp_mov_byte_CH_IMM, -/* 0xb6 */ x86emuOp_mov_byte_DH_IMM, -/* 0xb7 */ x86emuOp_mov_byte_BH_IMM, -/* 0xb8 */ x86emuOp_mov_word_AX_IMM, -/* 0xb9 */ x86emuOp_mov_word_CX_IMM, -/* 0xba */ x86emuOp_mov_word_DX_IMM, -/* 0xbb */ x86emuOp_mov_word_BX_IMM, -/* 0xbc */ x86emuOp_mov_word_SP_IMM, -/* 0xbd */ x86emuOp_mov_word_BP_IMM, -/* 0xbe */ x86emuOp_mov_word_SI_IMM, -/* 0xbf */ x86emuOp_mov_word_DI_IMM, -/* 0xc0 */ x86emuOp_opcC0_byte_RM_MEM, -/* 0xc1 */ x86emuOp_opcC1_word_RM_MEM, -/* 0xc2 */ x86emuOp_ret_near_IMM, -/* 0xc3 */ x86emuOp_ret_near, -/* 0xc4 */ x86emuOp_les_R_IMM, -/* 0xc5 */ x86emuOp_lds_R_IMM, -/* 0xc6 */ x86emuOp_mov_byte_RM_IMM, -/* 0xc7 */ x86emuOp_mov_word_RM_IMM, -/* 0xc8 */ x86emuOp_enter, -/* 0xc9 */ x86emuOp_leave, -/* 0xca */ x86emuOp_ret_far_IMM, -/* 0xcb */ x86emuOp_ret_far, -/* 0xcc */ x86emuOp_int3, -/* 0xcd */ x86emuOp_int_IMM, -/* 0xce */ x86emuOp_into, -/* 0xcf */ x86emuOp_iret, -/* 0xd0 */ x86emuOp_opcD0_byte_RM_1, -/* 0xd1 */ x86emuOp_opcD1_word_RM_1, -/* 0xd2 */ x86emuOp_opcD2_byte_RM_CL, -/* 0xd3 */ x86emuOp_opcD3_word_RM_CL, -/* 0xd4 */ x86emuOp_aam, -/* 0xd5 */ x86emuOp_aad, - /* 0xd6 */ x86emuOp_illegal_op, - /* Undocumented SETALC instruction */ -/* 0xd7 */ x86emuOp_xlat, -/* 0xd8 */ x86emuOp_esc_coprocess_d8, -/* 0xd9 */ x86emuOp_esc_coprocess_d9, -/* 0xda */ x86emuOp_esc_coprocess_da, -/* 0xdb */ x86emuOp_esc_coprocess_db, -/* 0xdc */ x86emuOp_esc_coprocess_dc, -/* 0xdd */ x86emuOp_esc_coprocess_dd, -/* 0xde */ x86emuOp_esc_coprocess_de, -/* 0xdf */ x86emuOp_esc_coprocess_df, -/* 0xe0 */ x86emuOp_loopne, -/* 0xe1 */ x86emuOp_loope, -/* 0xe2 */ x86emuOp_loop, -/* 0xe3 */ x86emuOp_jcxz, -/* 0xe4 */ x86emuOp_in_byte_AL_IMM, -/* 0xe5 */ x86emuOp_in_word_AX_IMM, -/* 0xe6 */ x86emuOp_out_byte_IMM_AL, -/* 0xe7 */ x86emuOp_out_word_IMM_AX, -/* 0xe8 */ x86emuOp_call_near_IMM, -/* 0xe9 */ x86emuOp_jump_near_IMM, -/* 0xea */ x86emuOp_jump_far_IMM, -/* 0xeb */ x86emuOp_jump_byte_IMM, -/* 0xec */ x86emuOp_in_byte_AL_DX, -/* 0xed */ x86emuOp_in_word_AX_DX, -/* 0xee */ x86emuOp_out_byte_DX_AL, -/* 0xef */ x86emuOp_out_word_DX_AX, -/* 0xf0 */ x86emuOp_lock, -/* 0xf1 */ x86emuOp_illegal_op, -/* 0xf2 */ x86emuOp_repne, -/* 0xf3 */ x86emuOp_repe, -/* 0xf4 */ x86emuOp_halt, -/* 0xf5 */ x86emuOp_cmc, -/* 0xf6 */ x86emuOp_opcF6_byte_RM, -/* 0xf7 */ x86emuOp_opcF7_word_RM, -/* 0xf8 */ x86emuOp_clc, -/* 0xf9 */ x86emuOp_stc, -/* 0xfa */ x86emuOp_cli, -/* 0xfb */ x86emuOp_sti, -/* 0xfc */ x86emuOp_cld, -/* 0xfd */ x86emuOp_std, -/* 0xfe */ x86emuOp_opcFE_byte_RM, -/* 0xff */ x86emuOp_opcFF_word_RM, -}; diff --git a/hw/xfree86/x86emu/ops2.c b/hw/xfree86/x86emu/ops2.c deleted file mode 100644 index 5ed2bf68d..000000000 --- a/hw/xfree86/x86emu/ops2.c +++ /dev/null @@ -1,3008 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: This file includes subroutines to implement the decoding -* and emulation of all the x86 extended two-byte processor -* instructions. -* -****************************************************************************/ - -#include "x86emu/x86emui.h" - -#undef bswap_32 -#define bswap_32(x) (((x & 0xff000000) >> 24) | \ - ((x & 0x00ff0000) >> 8) | \ - ((x & 0x0000ff00) << 8) | \ - ((x & 0x000000ff) << 24)) - -/*----------------------------- Implementation ----------------------------*/ - -/**************************************************************************** -PARAMETERS: -op1 - Instruction op code - -REMARKS: -Handles illegal opcodes. -****************************************************************************/ -static void -x86emuOp2_illegal_op(u8 op2) -{ - START_OF_INSTR(); - DECODE_PRINTF("ILLEGAL EXTENDED X86 OPCODE\n"); - TRACE_REGS(); - printk("%04x:%04x: %02X ILLEGAL EXTENDED X86 OPCODE!\n", - M.x86.R_CS, M.x86.R_IP - 2, op2); - HALT_SYS(); - END_OF_INSTR(); -} - -#define xorl(a,b) ((a) && !(b)) || (!(a) && (b)) - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0x31 -****************************************************************************/ -static void -x86emuOp2_rdtsc(u8 X86EMU_UNUSED(op2)) -{ -#ifdef __HAS_LONG_LONG__ - static u64 counter = 0; -#else - static u32 counter = 0; -#endif - - counter += 0x10000; - - /* read timestamp counter */ - /* - * Note that instead of actually trying to accurately measure this, we just - * increase the counter by a fixed amount every time we hit one of these - * instructions. Feel free to come up with a better method. - */ - START_OF_INSTR(); - DECODE_PRINTF("RDTSC\n"); - TRACE_AND_STEP(); -#ifdef __HAS_LONG_LONG__ - M.x86.R_EAX = counter & 0xffffffff; - M.x86.R_EDX = counter >> 32; -#else - M.x86.R_EAX = counter; - M.x86.R_EDX = 0; -#endif - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0x80-0x8F -****************************************************************************/ -static void -x86emuOp2_long_jump(u8 op2) -{ - s32 target; - const char *name = NULL; - int cond = 0; - - /* conditional jump to word offset. */ - START_OF_INSTR(); - switch (op2) { - case 0x80: - name = "JO\t"; - cond = ACCESS_FLAG(F_OF); - break; - case 0x81: - name = "JNO\t"; - cond = !ACCESS_FLAG(F_OF); - break; - case 0x82: - name = "JB\t"; - cond = ACCESS_FLAG(F_CF); - break; - case 0x83: - name = "JNB\t"; - cond = !ACCESS_FLAG(F_CF); - break; - case 0x84: - name = "JZ\t"; - cond = ACCESS_FLAG(F_ZF); - break; - case 0x85: - name = "JNZ\t"; - cond = !ACCESS_FLAG(F_ZF); - break; - case 0x86: - name = "JBE\t"; - cond = ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF); - break; - case 0x87: - name = "JNBE\t"; - cond = !(ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF)); - break; - case 0x88: - name = "JS\t"; - cond = ACCESS_FLAG(F_SF); - break; - case 0x89: - name = "JNS\t"; - cond = !ACCESS_FLAG(F_SF); - break; - case 0x8a: - name = "JP\t"; - cond = ACCESS_FLAG(F_PF); - break; - case 0x8b: - name = "JNP\t"; - cond = !ACCESS_FLAG(F_PF); - break; - case 0x8c: - name = "JL\t"; - cond = xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)); - break; - case 0x8d: - name = "JNL\t"; - cond = !(xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF))); - break; - case 0x8e: - name = "JLE\t"; - cond = (xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)) || - ACCESS_FLAG(F_ZF)); - break; - case 0x8f: - name = "JNLE\t"; - cond = !(xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)) || - ACCESS_FLAG(F_ZF)); - break; - } - DECODE_PRINTF(name); - (void) name; - target = (s16) fetch_word_imm(); - target += (s16) M.x86.R_IP; - DECODE_PRINTF2("%04x\n", target); - TRACE_AND_STEP(); - if (cond) - M.x86.R_IP = (u16) target; - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0x90-0x9F -****************************************************************************/ -static void -x86emuOp2_set_byte(u8 op2) -{ - int mod, rl, rh; - uint destoffset; - u8 *destreg; - const char *name = NULL; - int cond = 0; - - START_OF_INSTR(); - switch (op2) { - case 0x90: - name = "SETO\t"; - cond = ACCESS_FLAG(F_OF); - break; - case 0x91: - name = "SETNO\t"; - cond = !ACCESS_FLAG(F_OF); - break; - case 0x92: - name = "SETB\t"; - cond = ACCESS_FLAG(F_CF); - break; - case 0x93: - name = "SETNB\t"; - cond = !ACCESS_FLAG(F_CF); - break; - case 0x94: - name = "SETZ\t"; - cond = ACCESS_FLAG(F_ZF); - break; - case 0x95: - name = "SETNZ\t"; - cond = !ACCESS_FLAG(F_ZF); - break; - case 0x96: - name = "SETBE\t"; - cond = ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF); - break; - case 0x97: - name = "SETNBE\t"; - cond = !(ACCESS_FLAG(F_CF) || ACCESS_FLAG(F_ZF)); - break; - case 0x98: - name = "SETS\t"; - cond = ACCESS_FLAG(F_SF); - break; - case 0x99: - name = "SETNS\t"; - cond = !ACCESS_FLAG(F_SF); - break; - case 0x9a: - name = "SETP\t"; - cond = ACCESS_FLAG(F_PF); - break; - case 0x9b: - name = "SETNP\t"; - cond = !ACCESS_FLAG(F_PF); - break; - case 0x9c: - name = "SETL\t"; - cond = xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)); - break; - case 0x9d: - name = "SETNL\t"; - cond = xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)); - break; - case 0x9e: - name = "SETLE\t"; - cond = (xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)) || - ACCESS_FLAG(F_ZF)); - break; - case 0x9f: - name = "SETNLE\t"; - cond = !(xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)) || - ACCESS_FLAG(F_ZF)); - break; - } - DECODE_PRINTF(name); - (void) name; - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destoffset = decode_rm00_address(rl); - TRACE_AND_STEP(); - store_data_byte(destoffset, cond ? 0x01 : 0x00); - break; - case 1: - destoffset = decode_rm01_address(rl); - TRACE_AND_STEP(); - store_data_byte(destoffset, cond ? 0x01 : 0x00); - break; - case 2: - destoffset = decode_rm10_address(rl); - TRACE_AND_STEP(); - store_data_byte(destoffset, cond ? 0x01 : 0x00); - break; - case 3: /* register to register */ - destreg = DECODE_RM_BYTE_REGISTER(rl); - TRACE_AND_STEP(); - *destreg = cond ? 0x01 : 0x00; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xa0 -****************************************************************************/ -static void -x86emuOp2_push_FS(u8 X86EMU_UNUSED(op2)) -{ - START_OF_INSTR(); - DECODE_PRINTF("PUSH\tFS\n"); - TRACE_AND_STEP(); - push_word(M.x86.R_FS); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xa1 -****************************************************************************/ -static void -x86emuOp2_pop_FS(u8 X86EMU_UNUSED(op2)) -{ - START_OF_INSTR(); - DECODE_PRINTF("POP\tFS\n"); - TRACE_AND_STEP(); - M.x86.R_FS = pop_word(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: CPUID takes EAX/ECX as inputs, writes EAX/EBX/ECX/EDX as output -Handles opcode 0x0f,0xa2 -****************************************************************************/ -static void -x86emuOp2_cpuid(u8 X86EMU_UNUSED(op2)) -{ - START_OF_INSTR(); - DECODE_PRINTF("CPUID\n"); - TRACE_AND_STEP(); - cpuid(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xa3 -****************************************************************************/ -static void -x86emuOp2_bt_R(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - int bit, disp; - - START_OF_INSTR(); - DECODE_PRINTF("BT\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval; - u32 *shiftreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF); - } - else { - u16 srcval; - u16 *shiftreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval; - u32 *shiftreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF); - } - else { - u16 srcval; - u16 *shiftreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval; - u32 *shiftreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF); - } - else { - u16 srcval; - u16 *shiftreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - CONDITIONAL_SET_FLAG(srcval & (0x1 << bit), F_CF); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg, *shiftreg; - - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - CONDITIONAL_SET_FLAG(*srcreg & (0x1 << bit), F_CF); - } - else { - u16 *srcreg, *shiftreg; - - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - CONDITIONAL_SET_FLAG(*srcreg & (0x1 << bit), F_CF); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xa4 -****************************************************************************/ -static void -x86emuOp2_shld_IMM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint destoffset; - u8 shift; - - START_OF_INSTR(); - DECODE_PRINTF("SHLD\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shld_long(destval, *shiftreg, shift); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shld_word(destval, *shiftreg, shift); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shld_long(destval, *shiftreg, shift); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shld_word(destval, *shiftreg, shift); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shld_long(destval, *shiftreg, shift); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shld_word(destval, *shiftreg, shift); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *shiftreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - *destreg = shld_long(*destreg, *shiftreg, shift); - } - else { - u16 *destreg, *shiftreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - *destreg = shld_word(*destreg, *shiftreg, shift); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xa5 -****************************************************************************/ -static void -x86emuOp2_shld_CL(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("SHLD\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shld_long(destval, *shiftreg, M.x86.R_CL); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shld_word(destval, *shiftreg, M.x86.R_CL); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shld_long(destval, *shiftreg, M.x86.R_CL); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shld_word(destval, *shiftreg, M.x86.R_CL); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shld_long(destval, *shiftreg, M.x86.R_CL); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shld_word(destval, *shiftreg, M.x86.R_CL); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *shiftreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - *destreg = shld_long(*destreg, *shiftreg, M.x86.R_CL); - } - else { - u16 *destreg, *shiftreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - *destreg = shld_word(*destreg, *shiftreg, M.x86.R_CL); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xa8 -****************************************************************************/ -static void -x86emuOp2_push_GS(u8 X86EMU_UNUSED(op2)) -{ - START_OF_INSTR(); - DECODE_PRINTF("PUSH\tGS\n"); - TRACE_AND_STEP(); - push_word(M.x86.R_GS); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xa9 -****************************************************************************/ -static void -x86emuOp2_pop_GS(u8 X86EMU_UNUSED(op2)) -{ - START_OF_INSTR(); - DECODE_PRINTF("POP\tGS\n"); - TRACE_AND_STEP(); - M.x86.R_GS = pop_word(); - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xab -****************************************************************************/ -static void -x86emuOp2_bts_R(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - int bit, disp; - - START_OF_INSTR(); - DECODE_PRINTF("BTS\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u32 *shiftreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_long(srcoffset + disp, srcval | mask); - } - else { - u16 srcval, mask; - u16 *shiftreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_word(srcoffset + disp, srcval | mask); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u32 *shiftreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_long(srcoffset + disp, srcval | mask); - } - else { - u16 srcval, mask; - u16 *shiftreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_word(srcoffset + disp, srcval | mask); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u32 *shiftreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_long(srcoffset + disp, srcval | mask); - } - else { - u16 srcval, mask; - u16 *shiftreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_word(srcoffset + disp, srcval | mask); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg, *shiftreg; - u32 mask; - - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF); - *srcreg |= mask; - } - else { - u16 *srcreg, *shiftreg; - u16 mask; - - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF); - *srcreg |= mask; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xac -****************************************************************************/ -static void -x86emuOp2_shrd_IMM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint destoffset; - u8 shift; - - START_OF_INSTR(); - DECODE_PRINTF("SHLD\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shrd_long(destval, *shiftreg, shift); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shrd_word(destval, *shiftreg, shift); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shrd_long(destval, *shiftreg, shift); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shrd_word(destval, *shiftreg, shift); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shrd_long(destval, *shiftreg, shift); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shrd_word(destval, *shiftreg, shift); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *shiftreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - *destreg = shrd_long(*destreg, *shiftreg, shift); - } - else { - u16 *destreg, *shiftreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - DECODE_PRINTF2("%d\n", shift); - TRACE_AND_STEP(); - *destreg = shrd_word(*destreg, *shiftreg, shift); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xad -****************************************************************************/ -static void -x86emuOp2_shrd_CL(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint destoffset; - - START_OF_INSTR(); - DECODE_PRINTF("SHLD\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shrd_long(destval, *shiftreg, M.x86.R_CL); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shrd_word(destval, *shiftreg, M.x86.R_CL); - store_data_word(destoffset, destval); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shrd_long(destval, *shiftreg, M.x86.R_CL); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shrd_word(destval, *shiftreg, M.x86.R_CL); - store_data_word(destoffset, destval); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 destval; - u32 *shiftreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_long(destoffset); - destval = shrd_long(destval, *shiftreg, M.x86.R_CL); - store_data_long(destoffset, destval); - } - else { - u16 destval; - u16 *shiftreg; - - destoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - destval = fetch_data_word(destoffset); - destval = shrd_word(destval, *shiftreg, M.x86.R_CL); - store_data_word(destoffset, destval); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *shiftreg; - - destreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - *destreg = shrd_long(*destreg, *shiftreg, M.x86.R_CL); - } - else { - u16 *destreg, *shiftreg; - - destreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(",CL\n"); - TRACE_AND_STEP(); - *destreg = shrd_word(*destreg, *shiftreg, M.x86.R_CL); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xaf -****************************************************************************/ -static void -x86emuOp2_imul_R_RM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("IMUL\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - u32 res_lo, res_hi; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_long(srcoffset); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) * destreg, (s32) srcval); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg; - u16 srcval; - u32 res; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - TRACE_AND_STEP(); - res = (s16) * destreg * (s16) srcval; - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - u32 res_lo, res_hi; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_long(srcoffset); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) * destreg, (s32) srcval); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg; - u16 srcval; - u32 res; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - TRACE_AND_STEP(); - res = (s16) * destreg * (s16) srcval; - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - u32 res_lo, res_hi; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_long(srcoffset); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) * destreg, (s32) srcval); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg; - u16 srcval; - u32 res; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - TRACE_AND_STEP(); - res = (s16) * destreg * (s16) srcval; - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg, *srcreg; - u32 res_lo, res_hi; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_LONG_REGISTER(rl); - TRACE_AND_STEP(); - imul_long_direct(&res_lo, &res_hi, (s32) * destreg, (s32) * srcreg); - if (res_hi != 0) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u32) res_lo; - } - else { - u16 *destreg, *srcreg; - u32 res; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - res = (s16) * destreg * (s16) * srcreg; - if (res > 0xFFFF) { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - *destreg = (u16) res; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xb2 -****************************************************************************/ -static void -x86emuOp2_lss_R_IMM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rh, rl; - u16 *dstreg; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("LSS\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_SS = fetch_data_word(srcoffset + 2); - break; - case 1: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_SS = fetch_data_word(srcoffset + 2); - break; - case 2: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_SS = fetch_data_word(srcoffset + 2); - break; - case 3: /* register to register */ - /* UNDEFINED! */ - TRACE_AND_STEP(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xb3 -****************************************************************************/ -static void -x86emuOp2_btr_R(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - int bit, disp; - - START_OF_INSTR(); - DECODE_PRINTF("BTR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u32 *shiftreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_long(srcoffset + disp, srcval & ~mask); - } - else { - u16 srcval, mask; - u16 *shiftreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_word(srcoffset + disp, (u16) (srcval & ~mask)); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u32 *shiftreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_long(srcoffset + disp, srcval & ~mask); - } - else { - u16 srcval, mask; - u16 *shiftreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_word(srcoffset + disp, (u16) (srcval & ~mask)); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u32 *shiftreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_long(srcoffset + disp, srcval & ~mask); - } - else { - u16 srcval, mask; - u16 *shiftreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_word(srcoffset + disp, (u16) (srcval & ~mask)); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg, *shiftreg; - u32 mask; - - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF); - *srcreg &= ~mask; - } - else { - u16 *srcreg, *shiftreg; - u16 mask; - - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF); - *srcreg &= ~mask; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xb4 -****************************************************************************/ -static void -x86emuOp2_lfs_R_IMM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rh, rl; - u16 *dstreg; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("LFS\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_FS = fetch_data_word(srcoffset + 2); - break; - case 1: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_FS = fetch_data_word(srcoffset + 2); - break; - case 2: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_FS = fetch_data_word(srcoffset + 2); - break; - case 3: /* register to register */ - /* UNDEFINED! */ - TRACE_AND_STEP(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xb5 -****************************************************************************/ -static void -x86emuOp2_lgs_R_IMM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rh, rl; - u16 *dstreg; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("LGS\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_GS = fetch_data_word(srcoffset + 2); - break; - case 1: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_GS = fetch_data_word(srcoffset + 2); - break; - case 2: - dstreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *dstreg = fetch_data_word(srcoffset); - M.x86.R_GS = fetch_data_word(srcoffset + 2); - break; - case 3: /* register to register */ - /* UNDEFINED! */ - TRACE_AND_STEP(); - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xb6 -****************************************************************************/ -static void -x86emuOp2_movzx_byte_R_RM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("MOVZX\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_byte(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u8 *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - } - else { - u16 *destreg; - u8 *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xb7 -****************************************************************************/ -static void -x86emuOp2_movzx_word_R_RM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - u32 *destreg; - u32 srcval; - u16 *srcreg; - - START_OF_INSTR(); - DECODE_PRINTF("MOVZX\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 1: - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 2: - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = fetch_data_word(srcoffset); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 3: /* register to register */ - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = *srcreg; - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xba -****************************************************************************/ -static void -x86emuOp2_btX_I(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - int bit; - - START_OF_INSTR(); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (rh) { - case 4: - DECODE_PRINTF("BT\t"); - break; - case 5: - DECODE_PRINTF("BTS\t"); - break; - case 6: - DECODE_PRINTF("BTR\t"); - break; - case 7: - DECODE_PRINTF("BTC\t"); - break; - default: - DECODE_PRINTF("ILLEGAL EXTENDED X86 OPCODE\n"); - TRACE_REGS(); - printk("%04x:%04x: %02X%02X ILLEGAL EXTENDED X86 OPCODE EXTENSION!\n", - M.x86.R_CS, M.x86.R_IP - 3, op2, (mod << 6) | (rh << 3) | rl); - HALT_SYS(); - } - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u8 shift; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - TRACE_AND_STEP(); - bit = shift & 0x1F; - srcval = fetch_data_long(srcoffset); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - switch (rh) { - case 5: - store_data_long(srcoffset, srcval | mask); - break; - case 6: - store_data_long(srcoffset, srcval & ~mask); - break; - case 7: - store_data_long(srcoffset, srcval ^ mask); - break; - default: - break; - } - } - else { - u16 srcval, mask; - u8 shift; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - TRACE_AND_STEP(); - bit = shift & 0xF; - srcval = fetch_data_word(srcoffset); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - switch (rh) { - case 5: - store_data_word(srcoffset, srcval | mask); - break; - case 6: - store_data_word(srcoffset, srcval & ~mask); - break; - case 7: - store_data_word(srcoffset, srcval ^ mask); - break; - default: - break; - } - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u8 shift; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - TRACE_AND_STEP(); - bit = shift & 0x1F; - srcval = fetch_data_long(srcoffset); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - switch (rh) { - case 5: - store_data_long(srcoffset, srcval | mask); - break; - case 6: - store_data_long(srcoffset, srcval & ~mask); - break; - case 7: - store_data_long(srcoffset, srcval ^ mask); - break; - default: - break; - } - } - else { - u16 srcval, mask; - u8 shift; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - TRACE_AND_STEP(); - bit = shift & 0xF; - srcval = fetch_data_word(srcoffset); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - switch (rh) { - case 5: - store_data_word(srcoffset, srcval | mask); - break; - case 6: - store_data_word(srcoffset, srcval & ~mask); - break; - case 7: - store_data_word(srcoffset, srcval ^ mask); - break; - default: - break; - } - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u8 shift; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - TRACE_AND_STEP(); - bit = shift & 0x1F; - srcval = fetch_data_long(srcoffset); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - switch (rh) { - case 5: - store_data_long(srcoffset, srcval | mask); - break; - case 6: - store_data_long(srcoffset, srcval & ~mask); - break; - case 7: - store_data_long(srcoffset, srcval ^ mask); - break; - default: - break; - } - } - else { - u16 srcval, mask; - u8 shift; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - TRACE_AND_STEP(); - bit = shift & 0xF; - srcval = fetch_data_word(srcoffset); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - switch (rh) { - case 5: - store_data_word(srcoffset, srcval | mask); - break; - case 6: - store_data_word(srcoffset, srcval & ~mask); - break; - case 7: - store_data_word(srcoffset, srcval ^ mask); - break; - default: - break; - } - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg; - u32 mask; - u8 shift; - - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - TRACE_AND_STEP(); - bit = shift & 0x1F; - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF); - switch (rh) { - case 5: - *srcreg |= mask; - break; - case 6: - *srcreg &= ~mask; - break; - case 7: - *srcreg ^= mask; - break; - default: - break; - } - } - else { - u16 *srcreg; - u16 mask; - u8 shift; - - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - shift = fetch_byte_imm(); - TRACE_AND_STEP(); - bit = shift & 0xF; - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF); - switch (rh) { - case 5: - *srcreg |= mask; - break; - case 6: - *srcreg &= ~mask; - break; - case 7: - *srcreg ^= mask; - break; - default: - break; - } - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xbb -****************************************************************************/ -static void -x86emuOp2_btc_R(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - int bit, disp; - - START_OF_INSTR(); - DECODE_PRINTF("BTC\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u32 *shiftreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_long(srcoffset + disp, srcval ^ mask); - } - else { - u16 srcval, mask; - u16 *shiftreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_word(srcoffset + disp, (u16) (srcval ^ mask)); - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u32 *shiftreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_long(srcoffset + disp, srcval ^ mask); - } - else { - u16 srcval, mask; - u16 *shiftreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_word(srcoffset + disp, (u16) (srcval ^ mask)); - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, mask; - u32 *shiftreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - disp = (s16) * shiftreg >> 5; - srcval = fetch_data_long(srcoffset + disp); - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_long(srcoffset + disp, srcval ^ mask); - } - else { - u16 srcval, mask; - u16 *shiftreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - disp = (s16) * shiftreg >> 4; - srcval = fetch_data_word(srcoffset + disp); - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(srcval & mask, F_CF); - store_data_word(srcoffset + disp, (u16) (srcval ^ mask)); - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *srcreg, *shiftreg; - u32 mask; - - srcreg = DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0x1F; - mask = (0x1 << bit); - CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF); - *srcreg ^= mask; - } - else { - u16 *srcreg, *shiftreg; - u16 mask; - - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - shiftreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - bit = *shiftreg & 0xF; - mask = (u16) (0x1 << bit); - CONDITIONAL_SET_FLAG(*srcreg & mask, F_CF); - *srcreg ^= mask; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xbc -****************************************************************************/ -static void -x86emuOp2_bsf(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("BSF\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, *dstreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_long(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 0; *dstreg < 32; (*dstreg)++) - if ((srcval >> *dstreg) & 1) - break; - } - else { - u16 srcval, *dstreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_word(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 0; *dstreg < 16; (*dstreg)++) - if ((srcval >> *dstreg) & 1) - break; - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, *dstreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_long(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 0; *dstreg < 32; (*dstreg)++) - if ((srcval >> *dstreg) & 1) - break; - } - else { - u16 srcval, *dstreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_word(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 0; *dstreg < 16; (*dstreg)++) - if ((srcval >> *dstreg) & 1) - break; - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, *dstreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_long(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 0; *dstreg < 32; (*dstreg)++) - if ((srcval >> *dstreg) & 1) - break; - } - else { - u16 srcval, *dstreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_word(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 0; *dstreg < 16; (*dstreg)++) - if ((srcval >> *dstreg) & 1) - break; - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, *dstreg; - - srcval = *DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 0; *dstreg < 32; (*dstreg)++) - if ((srcval >> *dstreg) & 1) - break; - } - else { - u16 srcval, *dstreg; - - srcval = *DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 0; *dstreg < 16; (*dstreg)++) - if ((srcval >> *dstreg) & 1) - break; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xbd -****************************************************************************/ -static void -x86emuOp2_bsr(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("BSR\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, *dstreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_long(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 31; *dstreg > 0; (*dstreg)--) - if ((srcval >> *dstreg) & 1) - break; - } - else { - u16 srcval, *dstreg; - - srcoffset = decode_rm00_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_word(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 15; *dstreg > 0; (*dstreg)--) - if ((srcval >> *dstreg) & 1) - break; - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, *dstreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_long(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 31; *dstreg > 0; (*dstreg)--) - if ((srcval >> *dstreg) & 1) - break; - } - else { - u16 srcval, *dstreg; - - srcoffset = decode_rm01_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_word(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 15; *dstreg > 0; (*dstreg)--) - if ((srcval >> *dstreg) & 1) - break; - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, *dstreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_long(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 31; *dstreg > 0; (*dstreg)--) - if ((srcval >> *dstreg) & 1) - break; - } - else { - u16 srcval, *dstreg; - - srcoffset = decode_rm10_address(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - srcval = fetch_data_word(srcoffset); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 15; *dstreg > 0; (*dstreg)--) - if ((srcval >> *dstreg) & 1) - break; - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 srcval, *dstreg; - - srcval = *DECODE_RM_LONG_REGISTER(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_LONG_REGISTER(rh); - TRACE_AND_STEP(); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 31; *dstreg > 0; (*dstreg)--) - if ((srcval >> *dstreg) & 1) - break; - } - else { - u16 srcval, *dstreg; - - srcval = *DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF(","); - dstreg = DECODE_RM_WORD_REGISTER(rh); - TRACE_AND_STEP(); - CONDITIONAL_SET_FLAG(srcval == 0, F_ZF); - for (*dstreg = 15; *dstreg > 0; (*dstreg)--) - if ((srcval >> *dstreg) & 1) - break; - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xbe -****************************************************************************/ -static void -x86emuOp2_movsx_byte_R_RM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - - START_OF_INSTR(); - DECODE_PRINTF("MOVSX\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = (s32) ((s8) fetch_data_byte(srcoffset)); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = (s16) ((s8) fetch_data_byte(srcoffset)); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - break; - case 1: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = (s32) ((s8) fetch_data_byte(srcoffset)); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = (s16) ((s8) fetch_data_byte(srcoffset)); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - break; - case 2: - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u32 srcval; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = (s32) ((s8) fetch_data_byte(srcoffset)); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - else { - u16 *destreg; - u16 srcval; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = (s16) ((s8) fetch_data_byte(srcoffset)); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - } - break; - case 3: /* register to register */ - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - u32 *destreg; - u8 *srcreg; - - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = (s32) ((s8) * srcreg); - } - else { - u16 *destreg; - u8 *srcreg; - - destreg = DECODE_RM_WORD_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_BYTE_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = (s16) ((s8) * srcreg); - } - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/**************************************************************************** -REMARKS: -Handles opcode 0x0f,0xbf -****************************************************************************/ -static void -x86emuOp2_movsx_word_R_RM(u8 X86EMU_UNUSED(op2)) -{ - int mod, rl, rh; - uint srcoffset; - u32 *destreg; - u32 srcval; - u16 *srcreg; - - START_OF_INSTR(); - DECODE_PRINTF("MOVSX\t"); - FETCH_DECODE_MODRM(mod, rh, rl); - switch (mod) { - case 0: - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm00_address(rl); - srcval = (s32) ((s16) fetch_data_word(srcoffset)); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 1: - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm01_address(rl); - srcval = (s32) ((s16) fetch_data_word(srcoffset)); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 2: - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcoffset = decode_rm10_address(rl); - srcval = (s32) ((s16) fetch_data_word(srcoffset)); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = srcval; - break; - case 3: /* register to register */ - destreg = DECODE_RM_LONG_REGISTER(rh); - DECODE_PRINTF(","); - srcreg = DECODE_RM_WORD_REGISTER(rl); - DECODE_PRINTF("\n"); - TRACE_AND_STEP(); - *destreg = (s32) ((s16) * srcreg); - break; - } - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/* Handles opcodes 0xc8-0xcf */ -static void -x86emuOp2_bswap(u8 X86EMU_UNUSED(op2)) -{ - START_OF_INSTR(); - DECODE_PRINTF("BSWAP\n"); - TRACE_AND_STEP(); - - switch (op2) { - case 0xc8: - M.x86.R_EAX = bswap_32(M.x86.R_EAX); - break; - case 0xc9: - M.x86.R_ECX = bswap_32(M.x86.R_ECX); - break; - case 0xca: - M.x86.R_EDX = bswap_32(M.x86.R_EDX); - break; - case 0xcb: - M.x86.R_EBX = bswap_32(M.x86.R_EBX); - break; - case 0xcc: - M.x86.R_ESP = bswap_32(M.x86.R_ESP); - break; - case 0xcd: - M.x86.R_EBP = bswap_32(M.x86.R_EBP); - break; - case 0xce: - M.x86.R_ESI = bswap_32(M.x86.R_ESI); - break; - case 0xcf: - M.x86.R_EDI = bswap_32(M.x86.R_EDI); - break; - default: - /* can't happen */ - break; - } - - DECODE_CLEAR_SEGOVR(); - END_OF_INSTR(); -} - -/*************************************************************************** - * Double byte operation code table: - **************************************************************************/ -void (*x86emu_optab2[256]) (u8) = { - /* 0x00 */ x86emuOp2_illegal_op, - /* Group F (ring 0 PM) */ - /* 0x01 */ x86emuOp2_illegal_op, - /* Group G (ring 0 PM) */ - /* 0x02 */ x86emuOp2_illegal_op, - /* lar (ring 0 PM) */ - /* 0x03 */ x86emuOp2_illegal_op, - /* lsl (ring 0 PM) */ -/* 0x04 */ x86emuOp2_illegal_op, - /* 0x05 */ x86emuOp2_illegal_op, - /* loadall (undocumented) */ - /* 0x06 */ x86emuOp2_illegal_op, - /* clts (ring 0 PM) */ - /* 0x07 */ x86emuOp2_illegal_op, - /* loadall (undocumented) */ - /* 0x08 */ x86emuOp2_illegal_op, - /* invd (ring 0 PM) */ - /* 0x09 */ x86emuOp2_illegal_op, - /* wbinvd (ring 0 PM) */ -/* 0x0a */ x86emuOp2_illegal_op, -/* 0x0b */ x86emuOp2_illegal_op, -/* 0x0c */ x86emuOp2_illegal_op, -/* 0x0d */ x86emuOp2_illegal_op, -/* 0x0e */ x86emuOp2_illegal_op, -/* 0x0f */ x86emuOp2_illegal_op, -/* 0x10 */ x86emuOp2_illegal_op, -/* 0x11 */ x86emuOp2_illegal_op, -/* 0x12 */ x86emuOp2_illegal_op, -/* 0x13 */ x86emuOp2_illegal_op, -/* 0x14 */ x86emuOp2_illegal_op, -/* 0x15 */ x86emuOp2_illegal_op, -/* 0x16 */ x86emuOp2_illegal_op, -/* 0x17 */ x86emuOp2_illegal_op, -/* 0x18 */ x86emuOp2_illegal_op, -/* 0x19 */ x86emuOp2_illegal_op, -/* 0x1a */ x86emuOp2_illegal_op, -/* 0x1b */ x86emuOp2_illegal_op, -/* 0x1c */ x86emuOp2_illegal_op, -/* 0x1d */ x86emuOp2_illegal_op, -/* 0x1e */ x86emuOp2_illegal_op, -/* 0x1f */ x86emuOp2_illegal_op, - /* 0x20 */ x86emuOp2_illegal_op, - /* mov reg32,creg (ring 0 PM) */ - /* 0x21 */ x86emuOp2_illegal_op, - /* mov reg32,dreg (ring 0 PM) */ - /* 0x22 */ x86emuOp2_illegal_op, - /* mov creg,reg32 (ring 0 PM) */ - /* 0x23 */ x86emuOp2_illegal_op, - /* mov dreg,reg32 (ring 0 PM) */ - /* 0x24 */ x86emuOp2_illegal_op, - /* mov reg32,treg (ring 0 PM) */ -/* 0x25 */ x86emuOp2_illegal_op, - /* 0x26 */ x86emuOp2_illegal_op, - /* mov treg,reg32 (ring 0 PM) */ -/* 0x27 */ x86emuOp2_illegal_op, -/* 0x28 */ x86emuOp2_illegal_op, -/* 0x29 */ x86emuOp2_illegal_op, -/* 0x2a */ x86emuOp2_illegal_op, -/* 0x2b */ x86emuOp2_illegal_op, -/* 0x2c */ x86emuOp2_illegal_op, -/* 0x2d */ x86emuOp2_illegal_op, -/* 0x2e */ x86emuOp2_illegal_op, -/* 0x2f */ x86emuOp2_illegal_op, -/* 0x30 */ x86emuOp2_illegal_op, -/* 0x31 */ x86emuOp2_rdtsc, -/* 0x32 */ x86emuOp2_illegal_op, -/* 0x33 */ x86emuOp2_illegal_op, -/* 0x34 */ x86emuOp2_illegal_op, -/* 0x35 */ x86emuOp2_illegal_op, -/* 0x36 */ x86emuOp2_illegal_op, -/* 0x37 */ x86emuOp2_illegal_op, -/* 0x38 */ x86emuOp2_illegal_op, -/* 0x39 */ x86emuOp2_illegal_op, -/* 0x3a */ x86emuOp2_illegal_op, -/* 0x3b */ x86emuOp2_illegal_op, -/* 0x3c */ x86emuOp2_illegal_op, -/* 0x3d */ x86emuOp2_illegal_op, -/* 0x3e */ x86emuOp2_illegal_op, -/* 0x3f */ x86emuOp2_illegal_op, -/* 0x40 */ x86emuOp2_illegal_op, -/* 0x41 */ x86emuOp2_illegal_op, -/* 0x42 */ x86emuOp2_illegal_op, -/* 0x43 */ x86emuOp2_illegal_op, -/* 0x44 */ x86emuOp2_illegal_op, -/* 0x45 */ x86emuOp2_illegal_op, -/* 0x46 */ x86emuOp2_illegal_op, -/* 0x47 */ x86emuOp2_illegal_op, -/* 0x48 */ x86emuOp2_illegal_op, -/* 0x49 */ x86emuOp2_illegal_op, -/* 0x4a */ x86emuOp2_illegal_op, -/* 0x4b */ x86emuOp2_illegal_op, -/* 0x4c */ x86emuOp2_illegal_op, -/* 0x4d */ x86emuOp2_illegal_op, -/* 0x4e */ x86emuOp2_illegal_op, -/* 0x4f */ x86emuOp2_illegal_op, -/* 0x50 */ x86emuOp2_illegal_op, -/* 0x51 */ x86emuOp2_illegal_op, -/* 0x52 */ x86emuOp2_illegal_op, -/* 0x53 */ x86emuOp2_illegal_op, -/* 0x54 */ x86emuOp2_illegal_op, -/* 0x55 */ x86emuOp2_illegal_op, -/* 0x56 */ x86emuOp2_illegal_op, -/* 0x57 */ x86emuOp2_illegal_op, -/* 0x58 */ x86emuOp2_illegal_op, -/* 0x59 */ x86emuOp2_illegal_op, -/* 0x5a */ x86emuOp2_illegal_op, -/* 0x5b */ x86emuOp2_illegal_op, -/* 0x5c */ x86emuOp2_illegal_op, -/* 0x5d */ x86emuOp2_illegal_op, -/* 0x5e */ x86emuOp2_illegal_op, -/* 0x5f */ x86emuOp2_illegal_op, -/* 0x60 */ x86emuOp2_illegal_op, -/* 0x61 */ x86emuOp2_illegal_op, -/* 0x62 */ x86emuOp2_illegal_op, -/* 0x63 */ x86emuOp2_illegal_op, -/* 0x64 */ x86emuOp2_illegal_op, -/* 0x65 */ x86emuOp2_illegal_op, -/* 0x66 */ x86emuOp2_illegal_op, -/* 0x67 */ x86emuOp2_illegal_op, -/* 0x68 */ x86emuOp2_illegal_op, -/* 0x69 */ x86emuOp2_illegal_op, -/* 0x6a */ x86emuOp2_illegal_op, -/* 0x6b */ x86emuOp2_illegal_op, -/* 0x6c */ x86emuOp2_illegal_op, -/* 0x6d */ x86emuOp2_illegal_op, -/* 0x6e */ x86emuOp2_illegal_op, -/* 0x6f */ x86emuOp2_illegal_op, -/* 0x70 */ x86emuOp2_illegal_op, -/* 0x71 */ x86emuOp2_illegal_op, -/* 0x72 */ x86emuOp2_illegal_op, -/* 0x73 */ x86emuOp2_illegal_op, -/* 0x74 */ x86emuOp2_illegal_op, -/* 0x75 */ x86emuOp2_illegal_op, -/* 0x76 */ x86emuOp2_illegal_op, -/* 0x77 */ x86emuOp2_illegal_op, -/* 0x78 */ x86emuOp2_illegal_op, -/* 0x79 */ x86emuOp2_illegal_op, -/* 0x7a */ x86emuOp2_illegal_op, -/* 0x7b */ x86emuOp2_illegal_op, -/* 0x7c */ x86emuOp2_illegal_op, -/* 0x7d */ x86emuOp2_illegal_op, -/* 0x7e */ x86emuOp2_illegal_op, -/* 0x7f */ x86emuOp2_illegal_op, -/* 0x80 */ x86emuOp2_long_jump, -/* 0x81 */ x86emuOp2_long_jump, -/* 0x82 */ x86emuOp2_long_jump, -/* 0x83 */ x86emuOp2_long_jump, -/* 0x84 */ x86emuOp2_long_jump, -/* 0x85 */ x86emuOp2_long_jump, -/* 0x86 */ x86emuOp2_long_jump, -/* 0x87 */ x86emuOp2_long_jump, -/* 0x88 */ x86emuOp2_long_jump, -/* 0x89 */ x86emuOp2_long_jump, -/* 0x8a */ x86emuOp2_long_jump, -/* 0x8b */ x86emuOp2_long_jump, -/* 0x8c */ x86emuOp2_long_jump, -/* 0x8d */ x86emuOp2_long_jump, -/* 0x8e */ x86emuOp2_long_jump, -/* 0x8f */ x86emuOp2_long_jump, -/* 0x90 */ x86emuOp2_set_byte, -/* 0x91 */ x86emuOp2_set_byte, -/* 0x92 */ x86emuOp2_set_byte, -/* 0x93 */ x86emuOp2_set_byte, -/* 0x94 */ x86emuOp2_set_byte, -/* 0x95 */ x86emuOp2_set_byte, -/* 0x96 */ x86emuOp2_set_byte, -/* 0x97 */ x86emuOp2_set_byte, -/* 0x98 */ x86emuOp2_set_byte, -/* 0x99 */ x86emuOp2_set_byte, -/* 0x9a */ x86emuOp2_set_byte, -/* 0x9b */ x86emuOp2_set_byte, -/* 0x9c */ x86emuOp2_set_byte, -/* 0x9d */ x86emuOp2_set_byte, -/* 0x9e */ x86emuOp2_set_byte, -/* 0x9f */ x86emuOp2_set_byte, -/* 0xa0 */ x86emuOp2_push_FS, -/* 0xa1 */ x86emuOp2_pop_FS, -/* 0xa2 */ x86emuOp2_cpuid, -/* 0xa3 */ x86emuOp2_bt_R, -/* 0xa4 */ x86emuOp2_shld_IMM, -/* 0xa5 */ x86emuOp2_shld_CL, -/* 0xa6 */ x86emuOp2_illegal_op, -/* 0xa7 */ x86emuOp2_illegal_op, -/* 0xa8 */ x86emuOp2_push_GS, -/* 0xa9 */ x86emuOp2_pop_GS, -/* 0xaa */ x86emuOp2_illegal_op, -/* 0xab */ x86emuOp2_bts_R, -/* 0xac */ x86emuOp2_shrd_IMM, -/* 0xad */ x86emuOp2_shrd_CL, -/* 0xae */ x86emuOp2_illegal_op, -/* 0xaf */ x86emuOp2_imul_R_RM, - /* 0xb0 */ x86emuOp2_illegal_op, - /* TODO: cmpxchg */ - /* 0xb1 */ x86emuOp2_illegal_op, - /* TODO: cmpxchg */ -/* 0xb2 */ x86emuOp2_lss_R_IMM, -/* 0xb3 */ x86emuOp2_btr_R, -/* 0xb4 */ x86emuOp2_lfs_R_IMM, -/* 0xb5 */ x86emuOp2_lgs_R_IMM, -/* 0xb6 */ x86emuOp2_movzx_byte_R_RM, -/* 0xb7 */ x86emuOp2_movzx_word_R_RM, -/* 0xb8 */ x86emuOp2_illegal_op, -/* 0xb9 */ x86emuOp2_illegal_op, -/* 0xba */ x86emuOp2_btX_I, -/* 0xbb */ x86emuOp2_btc_R, -/* 0xbc */ x86emuOp2_bsf, -/* 0xbd */ x86emuOp2_bsr, -/* 0xbe */ x86emuOp2_movsx_byte_R_RM, -/* 0xbf */ x86emuOp2_movsx_word_R_RM, - /* 0xc0 */ x86emuOp2_illegal_op, - /* TODO: xadd */ - /* 0xc1 */ x86emuOp2_illegal_op, - /* TODO: xadd */ -/* 0xc2 */ x86emuOp2_illegal_op, -/* 0xc3 */ x86emuOp2_illegal_op, -/* 0xc4 */ x86emuOp2_illegal_op, -/* 0xc5 */ x86emuOp2_illegal_op, -/* 0xc6 */ x86emuOp2_illegal_op, -/* 0xc7 */ x86emuOp2_illegal_op, -/* 0xc8 */ x86emuOp2_bswap, -/* 0xc9 */ x86emuOp2_bswap, -/* 0xca */ x86emuOp2_bswap, -/* 0xcb */ x86emuOp2_bswap, -/* 0xcc */ x86emuOp2_bswap, -/* 0xcd */ x86emuOp2_bswap, -/* 0xce */ x86emuOp2_bswap, -/* 0xcf */ x86emuOp2_bswap, -/* 0xd0 */ x86emuOp2_illegal_op, -/* 0xd1 */ x86emuOp2_illegal_op, -/* 0xd2 */ x86emuOp2_illegal_op, -/* 0xd3 */ x86emuOp2_illegal_op, -/* 0xd4 */ x86emuOp2_illegal_op, -/* 0xd5 */ x86emuOp2_illegal_op, -/* 0xd6 */ x86emuOp2_illegal_op, -/* 0xd7 */ x86emuOp2_illegal_op, -/* 0xd8 */ x86emuOp2_illegal_op, -/* 0xd9 */ x86emuOp2_illegal_op, -/* 0xda */ x86emuOp2_illegal_op, -/* 0xdb */ x86emuOp2_illegal_op, -/* 0xdc */ x86emuOp2_illegal_op, -/* 0xdd */ x86emuOp2_illegal_op, -/* 0xde */ x86emuOp2_illegal_op, -/* 0xdf */ x86emuOp2_illegal_op, -/* 0xe0 */ x86emuOp2_illegal_op, -/* 0xe1 */ x86emuOp2_illegal_op, -/* 0xe2 */ x86emuOp2_illegal_op, -/* 0xe3 */ x86emuOp2_illegal_op, -/* 0xe4 */ x86emuOp2_illegal_op, -/* 0xe5 */ x86emuOp2_illegal_op, -/* 0xe6 */ x86emuOp2_illegal_op, -/* 0xe7 */ x86emuOp2_illegal_op, -/* 0xe8 */ x86emuOp2_illegal_op, -/* 0xe9 */ x86emuOp2_illegal_op, -/* 0xea */ x86emuOp2_illegal_op, -/* 0xeb */ x86emuOp2_illegal_op, -/* 0xec */ x86emuOp2_illegal_op, -/* 0xed */ x86emuOp2_illegal_op, -/* 0xee */ x86emuOp2_illegal_op, -/* 0xef */ x86emuOp2_illegal_op, -/* 0xf0 */ x86emuOp2_illegal_op, -/* 0xf1 */ x86emuOp2_illegal_op, -/* 0xf2 */ x86emuOp2_illegal_op, -/* 0xf3 */ x86emuOp2_illegal_op, -/* 0xf4 */ x86emuOp2_illegal_op, -/* 0xf5 */ x86emuOp2_illegal_op, -/* 0xf6 */ x86emuOp2_illegal_op, -/* 0xf7 */ x86emuOp2_illegal_op, -/* 0xf8 */ x86emuOp2_illegal_op, -/* 0xf9 */ x86emuOp2_illegal_op, -/* 0xfa */ x86emuOp2_illegal_op, -/* 0xfb */ x86emuOp2_illegal_op, -/* 0xfc */ x86emuOp2_illegal_op, -/* 0xfd */ x86emuOp2_illegal_op, -/* 0xfe */ x86emuOp2_illegal_op, -/* 0xff */ x86emuOp2_illegal_op, -}; diff --git a/hw/xfree86/x86emu/prim_ops.c b/hw/xfree86/x86emu/prim_ops.c deleted file mode 100644 index 35ef94710..000000000 --- a/hw/xfree86/x86emu/prim_ops.c +++ /dev/null @@ -1,2859 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: This file contains the code to implement the primitive -* machine operations used by the emulation code in ops.c -* -* Carry Chain Calculation -* -* This represents a somewhat expensive calculation which is -* apparently required to emulate the setting of the OF and AF flag. -* The latter is not so important, but the former is. The overflow -* flag is the XOR of the top two bits of the carry chain for an -* addition (similar for subtraction). Since we do not want to -* simulate the addition in a bitwise manner, we try to calculate the -* carry chain given the two operands and the result. -* -* So, given the following table, which represents the addition of two -* bits, we can derive a formula for the carry chain. -* -* a b cin r cout -* 0 0 0 0 0 -* 0 0 1 1 0 -* 0 1 0 1 0 -* 0 1 1 0 1 -* 1 0 0 1 0 -* 1 0 1 0 1 -* 1 1 0 0 1 -* 1 1 1 1 1 -* -* Construction of table for cout: -* -* ab -* r \ 00 01 11 10 -* |------------------ -* 0 | 0 1 1 1 -* 1 | 0 0 1 0 -* -* By inspection, one gets: cc = ab + r'(a + b) -* -* That represents a lot of operations, but NO CHOICE.... -* -* Borrow Chain Calculation. -* -* The following table represents the subtraction of two bits, from -* which we can derive a formula for the borrow chain. -* -* a b bin r bout -* 0 0 0 0 0 -* 0 0 1 1 1 -* 0 1 0 1 1 -* 0 1 1 0 1 -* 1 0 0 1 0 -* 1 0 1 0 0 -* 1 1 0 0 0 -* 1 1 1 1 1 -* -* Construction of table for cout: -* -* ab -* r \ 00 01 11 10 -* |------------------ -* 0 | 0 1 0 0 -* 1 | 1 1 1 0 -* -* By inspection, one gets: bc = a'b + r(a' + b) -* -****************************************************************************/ - -#include - -#define PRIM_OPS_NO_REDEFINE_ASM -#include "x86emu/x86emui.h" - -#if defined(__GNUC__) -#if defined (__i386__) || defined(__i386) || defined(__AMD64__) || defined(__amd64__) -#include "x86emu/prim_x86_gcc.h" -#endif -#endif - -/*------------------------- Global Variables ------------------------------*/ - -static u32 x86emu_parity_tab[8] = { - 0x96696996, - 0x69969669, - 0x69969669, - 0x96696996, - 0x69969669, - 0x96696996, - 0x96696996, - 0x69969669, -}; - -#define PARITY(x) (((x86emu_parity_tab[(x) / 32] >> ((x) % 32)) & 1) == 0) -#define XOR2(x) (((x) ^ ((x)>>1)) & 0x1) - -/*----------------------------- Implementation ----------------------------*/ - -/**************************************************************************** -REMARKS: -Implements the AAA instruction and side effects. -****************************************************************************/ -u16 -aaa_word(u16 d) -{ - u16 res; - - if ((d & 0xf) > 0x9 || ACCESS_FLAG(F_AF)) { - d += 0x6; - d += 0x100; - SET_FLAG(F_AF); - SET_FLAG(F_CF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - } - res = (u16) (d & 0xFF0F); - CLEAR_FLAG(F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the AAA instruction and side effects. -****************************************************************************/ -u16 -aas_word(u16 d) -{ - u16 res; - - if ((d & 0xf) > 0x9 || ACCESS_FLAG(F_AF)) { - d -= 0x6; - d -= 0x100; - SET_FLAG(F_AF); - SET_FLAG(F_CF); - } - else { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - } - res = (u16) (d & 0xFF0F); - CLEAR_FLAG(F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the AAD instruction and side effects. -****************************************************************************/ -u16 -aad_word(u16 d) -{ - u16 l; - u8 hb, lb; - - hb = (u8) ((d >> 8) & 0xff); - lb = (u8) ((d & 0xff)); - l = (u16) ((lb + 10 * hb) & 0xFF); - - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(l & 0x80, F_SF); - CONDITIONAL_SET_FLAG(l == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(l & 0xff), F_PF); - return l; -} - -/**************************************************************************** -REMARKS: -Implements the AAM instruction and side effects. -****************************************************************************/ -u16 -aam_word(u8 d) -{ - u16 h, l; - - h = (u16) (d / 10); - l = (u16) (d % 10); - l |= (u16) (h << 8); - - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(l & 0x80, F_SF); - CONDITIONAL_SET_FLAG(l == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(l & 0xff), F_PF); - return l; -} - -/**************************************************************************** -REMARKS: -Implements the ADC instruction and side effects. -****************************************************************************/ -u8 -adc_byte(u8 d, u8 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 cc; - - if (ACCESS_FLAG(F_CF)) - res = 1 + d + s; - else - res = d + s; - - CONDITIONAL_SET_FLAG(res & 0x100, F_CF); - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the carry chain SEE NOTE AT TOP. */ - cc = (s & d) | ((~res) & (s | d)); - CONDITIONAL_SET_FLAG(XOR2(cc >> 6), F_OF); - CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the ADC instruction and side effects. -****************************************************************************/ -u16 -adc_word(u16 d, u16 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 cc; - - if (ACCESS_FLAG(F_CF)) - res = 1 + d + s; - else - res = d + s; - - CONDITIONAL_SET_FLAG(res & 0x10000, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the carry chain SEE NOTE AT TOP. */ - cc = (s & d) | ((~res) & (s | d)); - CONDITIONAL_SET_FLAG(XOR2(cc >> 14), F_OF); - CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the ADC instruction and side effects. -****************************************************************************/ -u32 -adc_long(u32 d, u32 s) -{ - register u32 lo; /* all operands in native machine order */ - register u32 hi; - register u32 res; - register u32 cc; - - if (ACCESS_FLAG(F_CF)) { - lo = 1 + (d & 0xFFFF) + (s & 0xFFFF); - res = 1 + d + s; - } - else { - lo = (d & 0xFFFF) + (s & 0xFFFF); - res = d + s; - } - hi = (lo >> 16) + (d >> 16) + (s >> 16); - - CONDITIONAL_SET_FLAG(hi & 0x10000, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the carry chain SEE NOTE AT TOP. */ - cc = (s & d) | ((~res) & (s | d)); - CONDITIONAL_SET_FLAG(XOR2(cc >> 30), F_OF); - CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the ADD instruction and side effects. -****************************************************************************/ -u8 -add_byte(u8 d, u8 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 cc; - - res = d + s; - CONDITIONAL_SET_FLAG(res & 0x100, F_CF); - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the carry chain SEE NOTE AT TOP. */ - cc = (s & d) | ((~res) & (s | d)); - CONDITIONAL_SET_FLAG(XOR2(cc >> 6), F_OF); - CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the ADD instruction and side effects. -****************************************************************************/ -u16 -add_word(u16 d, u16 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 cc; - - res = d + s; - CONDITIONAL_SET_FLAG(res & 0x10000, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the carry chain SEE NOTE AT TOP. */ - cc = (s & d) | ((~res) & (s | d)); - CONDITIONAL_SET_FLAG(XOR2(cc >> 14), F_OF); - CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the ADD instruction and side effects. -****************************************************************************/ -u32 -add_long(u32 d, u32 s) -{ - register u32 lo; /* all operands in native machine order */ - register u32 hi; - register u32 res; - register u32 cc; - - lo = (d & 0xFFFF) + (s & 0xFFFF); - res = d + s; - hi = (lo >> 16) + (d >> 16) + (s >> 16); - - CONDITIONAL_SET_FLAG(hi & 0x10000, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the carry chain SEE NOTE AT TOP. */ - cc = (s & d) | ((~res) & (s | d)); - CONDITIONAL_SET_FLAG(XOR2(cc >> 30), F_OF); - CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); - - return res; -} - -/**************************************************************************** -REMARKS: -Implements the AND instruction and side effects. -****************************************************************************/ -u8 -and_byte(u8 d, u8 s) -{ - register u8 res; /* all operands in native machine order */ - - res = d & s; - - /* set the flags */ - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res), F_PF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the AND instruction and side effects. -****************************************************************************/ -u16 -and_word(u16 d, u16 s) -{ - register u16 res; /* all operands in native machine order */ - - res = d & s; - - /* set the flags */ - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the AND instruction and side effects. -****************************************************************************/ -u32 -and_long(u32 d, u32 s) -{ - register u32 res; /* all operands in native machine order */ - - res = d & s; - - /* set the flags */ - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the CMP instruction and side effects. -****************************************************************************/ -u8 -cmp_byte(u8 d, u8 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - res = d - s; - CLEAR_FLAG(F_CF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | s)) | (~d & s); - CONDITIONAL_SET_FLAG(bc & 0x80, F_CF); - CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return d; -} - -/**************************************************************************** -REMARKS: -Implements the CMP instruction and side effects. -****************************************************************************/ -u16 -cmp_word(u16 d, u16 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - res = d - s; - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | s)) | (~d & s); - CONDITIONAL_SET_FLAG(bc & 0x8000, F_CF); - CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return d; -} - -/**************************************************************************** -REMARKS: -Implements the CMP instruction and side effects. -****************************************************************************/ -u32 -cmp_long(u32 d, u32 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - res = d - s; - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | s)) | (~d & s); - CONDITIONAL_SET_FLAG(bc & 0x80000000, F_CF); - CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return d; -} - -/**************************************************************************** -REMARKS: -Implements the DAA instruction and side effects. -****************************************************************************/ -u8 -daa_byte(u8 d) -{ - u32 res = d; - - if ((d & 0xf) > 9 || ACCESS_FLAG(F_AF)) { - res += 6; - SET_FLAG(F_AF); - } - if (res > 0x9F || ACCESS_FLAG(F_CF)) { - res += 0x60; - SET_FLAG(F_CF); - } - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG((res & 0xFF) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the DAS instruction and side effects. -****************************************************************************/ -u8 -das_byte(u8 d) -{ - if ((d & 0xf) > 9 || ACCESS_FLAG(F_AF)) { - d -= 6; - SET_FLAG(F_AF); - } - if (d > 0x9F || ACCESS_FLAG(F_CF)) { - d -= 0x60; - SET_FLAG(F_CF); - } - CONDITIONAL_SET_FLAG(d & 0x80, F_SF); - CONDITIONAL_SET_FLAG(d == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(d & 0xff), F_PF); - return d; -} - -/**************************************************************************** -REMARKS: -Implements the DEC instruction and side effects. -****************************************************************************/ -u8 -dec_byte(u8 d) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - res = d - 1; - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - /* based on sub_byte, uses s==1. */ - bc = (res & (~d | 1)) | (~d & 1); - /* carry flag unchanged */ - CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the DEC instruction and side effects. -****************************************************************************/ -u16 -dec_word(u16 d) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - res = d - 1; - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - /* based on the sub_byte routine, with s==1 */ - bc = (res & (~d | 1)) | (~d & 1); - /* carry flag unchanged */ - CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the DEC instruction and side effects. -****************************************************************************/ -u32 -dec_long(u32 d) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - res = d - 1; - - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | 1)) | (~d & 1); - /* carry flag unchanged */ - CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the INC instruction and side effects. -****************************************************************************/ -u8 -inc_byte(u8 d) -{ - register u32 res; /* all operands in native machine order */ - register u32 cc; - - res = d + 1; - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the carry chain SEE NOTE AT TOP. */ - cc = ((1 & d) | (~res)) & (1 | d); - CONDITIONAL_SET_FLAG(XOR2(cc >> 6), F_OF); - CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the INC instruction and side effects. -****************************************************************************/ -u16 -inc_word(u16 d) -{ - register u32 res; /* all operands in native machine order */ - register u32 cc; - - res = d + 1; - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the carry chain SEE NOTE AT TOP. */ - cc = (1 & d) | ((~res) & (1 | d)); - CONDITIONAL_SET_FLAG(XOR2(cc >> 14), F_OF); - CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the INC instruction and side effects. -****************************************************************************/ -u32 -inc_long(u32 d) -{ - register u32 res; /* all operands in native machine order */ - register u32 cc; - - res = d + 1; - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the carry chain SEE NOTE AT TOP. */ - cc = (1 & d) | ((~res) & (1 | d)); - CONDITIONAL_SET_FLAG(XOR2(cc >> 30), F_OF); - CONDITIONAL_SET_FLAG(cc & 0x8, F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the OR instruction and side effects. -****************************************************************************/ -u8 -or_byte(u8 d, u8 s) -{ - register u8 res; /* all operands in native machine order */ - - res = d | s; - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res), F_PF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the OR instruction and side effects. -****************************************************************************/ -u16 -or_word(u16 d, u16 s) -{ - register u16 res; /* all operands in native machine order */ - - res = d | s; - /* set the carry flag to be bit 8 */ - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the OR instruction and side effects. -****************************************************************************/ -u32 -or_long(u32 d, u32 s) -{ - register u32 res; /* all operands in native machine order */ - - res = d | s; - - /* set the carry flag to be bit 8 */ - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the OR instruction and side effects. -****************************************************************************/ -u8 -neg_byte(u8 s) -{ - register u8 res; - register u8 bc; - - CONDITIONAL_SET_FLAG(s != 0, F_CF); - res = (u8) - s; - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res), F_PF); - /* calculate the borrow chain --- modified such that d=0. - substitutiing d=0 into bc= res&(~d|s)|(~d&s); - (the one used for sub) and simplifying, since ~d=0xff..., - ~d|s == 0xffff..., and res&0xfff... == res. Similarly - ~d&s == s. So the simplified result is: */ - bc = res | s; - CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the OR instruction and side effects. -****************************************************************************/ -u16 -neg_word(u16 s) -{ - register u16 res; - register u16 bc; - - CONDITIONAL_SET_FLAG(s != 0, F_CF); - res = (u16) - s; - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain --- modified such that d=0. - substitutiing d=0 into bc= res&(~d|s)|(~d&s); - (the one used for sub) and simplifying, since ~d=0xff..., - ~d|s == 0xffff..., and res&0xfff... == res. Similarly - ~d&s == s. So the simplified result is: */ - bc = res | s; - CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the OR instruction and side effects. -****************************************************************************/ -u32 -neg_long(u32 s) -{ - register u32 res; - register u32 bc; - - CONDITIONAL_SET_FLAG(s != 0, F_CF); - res = (u32) - s; - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain --- modified such that d=0. - substitutiing d=0 into bc= res&(~d|s)|(~d&s); - (the one used for sub) and simplifying, since ~d=0xff..., - ~d|s == 0xffff..., and res&0xfff... == res. Similarly - ~d&s == s. So the simplified result is: */ - bc = res | s; - CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the NOT instruction and side effects. -****************************************************************************/ -u8 -not_byte(u8 s) -{ - return ~s; -} - -/**************************************************************************** -REMARKS: -Implements the NOT instruction and side effects. -****************************************************************************/ -u16 -not_word(u16 s) -{ - return ~s; -} - -/**************************************************************************** -REMARKS: -Implements the NOT instruction and side effects. -****************************************************************************/ -u32 -not_long(u32 s) -{ - return ~s; -} - -/**************************************************************************** -REMARKS: -Implements the RCL instruction and side effects. -****************************************************************************/ -u8 -rcl_byte(u8 d, u8 s) -{ - register unsigned int res, cnt, mask, cf; - - /* s is the rotate distance. It varies from 0 - 8. */ - /* have - - CF B_7 B_6 B_5 B_4 B_3 B_2 B_1 B_0 - - want to rotate through the carry by "s" bits. We could - loop, but that's inefficient. So the width is 9, - and we split into three parts: - - The new carry flag (was B_n) - the stuff in B_n-1 .. B_0 - the stuff in B_7 .. B_n+1 - - The new rotate is done mod 9, and given this, - for a rotation of n bits (mod 9) the new carry flag is - then located n bits from the MSB. The low part is - then shifted up cnt bits, and the high part is or'd - in. Using CAPS for new values, and lowercase for the - original values, this can be expressed as: - - IF n > 0 - 1) CF <- b_(8-n) - 2) B_(7) .. B_(n) <- b_(8-(n+1)) .. b_0 - 3) B_(n-1) <- cf - 4) B_(n-2) .. B_0 <- b_7 .. b_(8-(n-1)) - */ - res = d; - if ((cnt = s % 9) != 0) { - /* extract the new CARRY FLAG. */ - /* CF <- b_(8-n) */ - cf = (d >> (8 - cnt)) & 0x1; - - /* get the low stuff which rotated - into the range B_7 .. B_cnt */ - /* B_(7) .. B_(n) <- b_(8-(n+1)) .. b_0 */ - /* note that the right hand side done by the mask */ - res = (d << cnt) & 0xff; - - /* now the high stuff which rotated around - into the positions B_cnt-2 .. B_0 */ - /* B_(n-2) .. B_0 <- b_7 .. b_(8-(n-1)) */ - /* shift it downward, 7-(n-2) = 9-n positions. - and mask off the result before or'ing in. - */ - mask = (1 << (cnt - 1)) - 1; - res |= (d >> (9 - cnt)) & mask; - - /* if the carry flag was set, or it in. */ - if (ACCESS_FLAG(F_CF)) { /* carry flag is set */ - /* B_(n-1) <- cf */ - res |= 1 << (cnt - 1); - } - /* set the new carry flag, based on the variable "cf" */ - CONDITIONAL_SET_FLAG(cf, F_CF); - /* OVERFLOW is set *IFF* cnt==1, then it is the - xor of CF and the most significant bit. Blecck. */ - /* parenthesized this expression since it appears to - be causing OF to be misset */ - CONDITIONAL_SET_FLAG(cnt == 1 && XOR2(cf + ((res >> 6) & 0x2)), F_OF); - - } - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the RCL instruction and side effects. -****************************************************************************/ -u16 -rcl_word(u16 d, u8 s) -{ - register unsigned int res, cnt, mask, cf; - - res = d; - if ((cnt = s % 17) != 0) { - cf = (d >> (16 - cnt)) & 0x1; - res = (d << cnt) & 0xffff; - mask = (1 << (cnt - 1)) - 1; - res |= (d >> (17 - cnt)) & mask; - if (ACCESS_FLAG(F_CF)) { - res |= 1 << (cnt - 1); - } - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG(cnt == 1 && XOR2(cf + ((res >> 14) & 0x2)), F_OF); - } - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the RCL instruction and side effects. -****************************************************************************/ -u32 -rcl_long(u32 d, u8 s) -{ - register u32 res, cnt, mask, cf; - - res = d; - if ((cnt = s % 33) != 0) { - cf = (d >> (32 - cnt)) & 0x1; - res = (d << cnt) & 0xffffffff; - mask = (1 << (cnt - 1)) - 1; - res |= (d >> (33 - cnt)) & mask; - if (ACCESS_FLAG(F_CF)) { /* carry flag is set */ - res |= 1 << (cnt - 1); - } - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG(cnt == 1 && XOR2(cf + ((res >> 30) & 0x2)), F_OF); - } - return res; -} - -/**************************************************************************** -REMARKS: -Implements the RCR instruction and side effects. -****************************************************************************/ -u8 -rcr_byte(u8 d, u8 s) -{ - u32 res, cnt; - u32 mask, cf, ocf = 0; - - /* rotate right through carry */ - /* - s is the rotate distance. It varies from 0 - 8. - d is the byte object rotated. - - have - - CF B_7 B_6 B_5 B_4 B_3 B_2 B_1 B_0 - - The new rotate is done mod 9, and given this, - for a rotation of n bits (mod 9) the new carry flag is - then located n bits from the LSB. The low part is - then shifted up cnt bits, and the high part is or'd - in. Using CAPS for new values, and lowercase for the - original values, this can be expressed as: - - IF n > 0 - 1) CF <- b_(n-1) - 2) B_(8-(n+1)) .. B_(0) <- b_(7) .. b_(n) - 3) B_(8-n) <- cf - 4) B_(7) .. B_(8-(n-1)) <- b_(n-2) .. b_(0) - */ - res = d; - if ((cnt = s % 9) != 0) { - /* extract the new CARRY FLAG. */ - /* CF <- b_(n-1) */ - if (cnt == 1) { - cf = d & 0x1; - /* note hackery here. Access_flag(..) evaluates to either - 0 if flag not set - non-zero if flag is set. - doing access_flag(..) != 0 casts that into either - 0..1 in any representation of the flags register - (i.e. packed bit array or unpacked.) - */ - ocf = ACCESS_FLAG(F_CF) != 0; - } - else - cf = (d >> (cnt - 1)) & 0x1; - - /* B_(8-(n+1)) .. B_(0) <- b_(7) .. b_n */ - /* note that the right hand side done by the mask - This is effectively done by shifting the - object to the right. The result must be masked, - in case the object came in and was treated - as a negative number. Needed??? */ - - mask = (1 << (8 - cnt)) - 1; - res = (d >> cnt) & mask; - - /* now the high stuff which rotated around - into the positions B_cnt-2 .. B_0 */ - /* B_(7) .. B_(8-(n-1)) <- b_(n-2) .. b_(0) */ - /* shift it downward, 7-(n-2) = 9-n positions. - and mask off the result before or'ing in. - */ - res |= (d << (9 - cnt)); - - /* if the carry flag was set, or it in. */ - if (ACCESS_FLAG(F_CF)) { /* carry flag is set */ - /* B_(8-n) <- cf */ - res |= 1 << (8 - cnt); - } - /* set the new carry flag, based on the variable "cf" */ - CONDITIONAL_SET_FLAG(cf, F_CF); - /* OVERFLOW is set *IFF* cnt==1, then it is the - xor of CF and the most significant bit. Blecck. */ - /* parenthesized... */ - if (cnt == 1) { - CONDITIONAL_SET_FLAG(XOR2(ocf + ((d >> 6) & 0x2)), F_OF); - } - } - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the RCR instruction and side effects. -****************************************************************************/ -u16 -rcr_word(u16 d, u8 s) -{ - u32 res, cnt; - u32 mask, cf, ocf = 0; - - /* rotate right through carry */ - res = d; - if ((cnt = s % 17) != 0) { - if (cnt == 1) { - cf = d & 0x1; - ocf = ACCESS_FLAG(F_CF) != 0; - } - else - cf = (d >> (cnt - 1)) & 0x1; - mask = (1 << (16 - cnt)) - 1; - res = (d >> cnt) & mask; - res |= (d << (17 - cnt)); - if (ACCESS_FLAG(F_CF)) { - res |= 1 << (16 - cnt); - } - CONDITIONAL_SET_FLAG(cf, F_CF); - if (cnt == 1) { - CONDITIONAL_SET_FLAG(XOR2(ocf + ((d >> 14) & 0x2)), F_OF); - } - } - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the RCR instruction and side effects. -****************************************************************************/ -u32 -rcr_long(u32 d, u8 s) -{ - u32 res, cnt; - u32 mask, cf, ocf = 0; - - /* rotate right through carry */ - res = d; - if ((cnt = s % 33) != 0) { - if (cnt == 1) { - cf = d & 0x1; - ocf = ACCESS_FLAG(F_CF) != 0; - } - else - cf = (d >> (cnt - 1)) & 0x1; - mask = (1 << (32 - cnt)) - 1; - res = (d >> cnt) & mask; - if (cnt != 1) - res |= (d << (33 - cnt)); - if (ACCESS_FLAG(F_CF)) { /* carry flag is set */ - res |= 1 << (32 - cnt); - } - CONDITIONAL_SET_FLAG(cf, F_CF); - if (cnt == 1) { - CONDITIONAL_SET_FLAG(XOR2(ocf + ((d >> 30) & 0x2)), F_OF); - } - } - return res; -} - -/**************************************************************************** -REMARKS: -Implements the ROL instruction and side effects. -****************************************************************************/ -u8 -rol_byte(u8 d, u8 s) -{ - register unsigned int res, cnt, mask; - - /* rotate left */ - /* - s is the rotate distance. It varies from 0 - 8. - d is the byte object rotated. - - have - - CF B_7 ... B_0 - - The new rotate is done mod 8. - Much simpler than the "rcl" or "rcr" operations. - - IF n > 0 - 1) B_(7) .. B_(n) <- b_(8-(n+1)) .. b_(0) - 2) B_(n-1) .. B_(0) <- b_(7) .. b_(8-n) - */ - res = d; - if ((cnt = s % 8) != 0) { - /* B_(7) .. B_(n) <- b_(8-(n+1)) .. b_(0) */ - res = (d << cnt); - - /* B_(n-1) .. B_(0) <- b_(7) .. b_(8-n) */ - mask = (1 << cnt) - 1; - res |= (d >> (8 - cnt)) & mask; - - /* set the new carry flag, Note that it is the low order - bit of the result!!! */ - CONDITIONAL_SET_FLAG(res & 0x1, F_CF); - /* OVERFLOW is set *IFF* s==1, then it is the - xor of CF and the most significant bit. Blecck. */ - CONDITIONAL_SET_FLAG(s == 1 && - XOR2((res & 0x1) + ((res >> 6) & 0x2)), F_OF); - } - if (s != 0) { - /* set the new carry flag, Note that it is the low order - bit of the result!!! */ - CONDITIONAL_SET_FLAG(res & 0x1, F_CF); - } - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the ROL instruction and side effects. -****************************************************************************/ -u16 -rol_word(u16 d, u8 s) -{ - register unsigned int res, cnt, mask; - - res = d; - if ((cnt = s % 16) != 0) { - res = (d << cnt); - mask = (1 << cnt) - 1; - res |= (d >> (16 - cnt)) & mask; - CONDITIONAL_SET_FLAG(res & 0x1, F_CF); - CONDITIONAL_SET_FLAG(s == 1 && - XOR2((res & 0x1) + ((res >> 14) & 0x2)), F_OF); - } - if (s != 0) { - /* set the new carry flag, Note that it is the low order - bit of the result!!! */ - CONDITIONAL_SET_FLAG(res & 0x1, F_CF); - } - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the ROL instruction and side effects. -****************************************************************************/ -u32 -rol_long(u32 d, u8 s) -{ - register u32 res, cnt, mask; - - res = d; - if ((cnt = s % 32) != 0) { - res = (d << cnt); - mask = (1 << cnt) - 1; - res |= (d >> (32 - cnt)) & mask; - CONDITIONAL_SET_FLAG(res & 0x1, F_CF); - CONDITIONAL_SET_FLAG(s == 1 && - XOR2((res & 0x1) + ((res >> 30) & 0x2)), F_OF); - } - if (s != 0) { - /* set the new carry flag, Note that it is the low order - bit of the result!!! */ - CONDITIONAL_SET_FLAG(res & 0x1, F_CF); - } - return res; -} - -/**************************************************************************** -REMARKS: -Implements the ROR instruction and side effects. -****************************************************************************/ -u8 -ror_byte(u8 d, u8 s) -{ - register unsigned int res, cnt, mask; - - /* rotate right */ - /* - s is the rotate distance. It varies from 0 - 8. - d is the byte object rotated. - - have - - B_7 ... B_0 - - The rotate is done mod 8. - - IF n > 0 - 1) B_(8-(n+1)) .. B_(0) <- b_(7) .. b_(n) - 2) B_(7) .. B_(8-n) <- b_(n-1) .. b_(0) - */ - res = d; - if ((cnt = s % 8) != 0) { /* not a typo, do nada if cnt==0 */ - /* B_(7) .. B_(8-n) <- b_(n-1) .. b_(0) */ - res = (d << (8 - cnt)); - - /* B_(8-(n+1)) .. B_(0) <- b_(7) .. b_(n) */ - mask = (1 << (8 - cnt)) - 1; - res |= (d >> (cnt)) & mask; - - /* set the new carry flag, Note that it is the low order - bit of the result!!! */ - CONDITIONAL_SET_FLAG(res & 0x80, F_CF); - /* OVERFLOW is set *IFF* s==1, then it is the - xor of the two most significant bits. Blecck. */ - CONDITIONAL_SET_FLAG(s == 1 && XOR2(res >> 6), F_OF); - } - else if (s != 0) { - /* set the new carry flag, Note that it is the low order - bit of the result!!! */ - CONDITIONAL_SET_FLAG(res & 0x80, F_CF); - } - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the ROR instruction and side effects. -****************************************************************************/ -u16 -ror_word(u16 d, u8 s) -{ - register unsigned int res, cnt, mask; - - res = d; - if ((cnt = s % 16) != 0) { - res = (d << (16 - cnt)); - mask = (1 << (16 - cnt)) - 1; - res |= (d >> (cnt)) & mask; - CONDITIONAL_SET_FLAG(res & 0x8000, F_CF); - CONDITIONAL_SET_FLAG(s == 1 && XOR2(res >> 14), F_OF); - } - else if (s != 0) { - /* set the new carry flag, Note that it is the low order - bit of the result!!! */ - CONDITIONAL_SET_FLAG(res & 0x8000, F_CF); - } - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the ROR instruction and side effects. -****************************************************************************/ -u32 -ror_long(u32 d, u8 s) -{ - register u32 res, cnt, mask; - - res = d; - if ((cnt = s % 32) != 0) { - res = (d << (32 - cnt)); - mask = (1 << (32 - cnt)) - 1; - res |= (d >> (cnt)) & mask; - CONDITIONAL_SET_FLAG(res & 0x80000000, F_CF); - CONDITIONAL_SET_FLAG(s == 1 && XOR2(res >> 30), F_OF); - } - else if (s != 0) { - /* set the new carry flag, Note that it is the low order - bit of the result!!! */ - CONDITIONAL_SET_FLAG(res & 0x80000000, F_CF); - } - return res; -} - -/**************************************************************************** -REMARKS: -Implements the SHL instruction and side effects. -****************************************************************************/ -u8 -shl_byte(u8 d, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 8) { - cnt = s % 8; - - /* last bit shifted out goes into carry flag */ - if (cnt > 0) { - res = d << cnt; - cf = d & (1 << (8 - cnt)); - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = (u8) d; - } - - if (cnt == 1) { - /* Needs simplification. */ - CONDITIONAL_SET_FLAG((((res & 0x80) == 0x80) ^ - (ACCESS_FLAG(F_CF) != 0)), - /* was (M.x86.R_FLG&F_CF)==F_CF)), */ - F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CONDITIONAL_SET_FLAG((d << (s - 1)) & 0x80, F_CF); - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_PF); - SET_FLAG(F_ZF); - } - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the SHL instruction and side effects. -****************************************************************************/ -u16 -shl_word(u16 d, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 16) { - cnt = s % 16; - if (cnt > 0) { - res = d << cnt; - cf = d & (1 << (16 - cnt)); - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = (u16) d; - } - - if (cnt == 1) { - CONDITIONAL_SET_FLAG((((res & 0x8000) == 0x8000) ^ - (ACCESS_FLAG(F_CF) != 0)), F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CONDITIONAL_SET_FLAG((d << (s - 1)) & 0x8000, F_CF); - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_PF); - SET_FLAG(F_ZF); - } - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the SHL instruction and side effects. -****************************************************************************/ -u32 -shl_long(u32 d, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 32) { - cnt = s % 32; - if (cnt > 0) { - res = d << cnt; - cf = d & (1 << (32 - cnt)); - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = d; - } - if (cnt == 1) { - CONDITIONAL_SET_FLAG((((res & 0x80000000) == 0x80000000) ^ - (ACCESS_FLAG(F_CF) != 0)), F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CONDITIONAL_SET_FLAG((d << (s - 1)) & 0x80000000, F_CF); - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_PF); - SET_FLAG(F_ZF); - } - return res; -} - -/**************************************************************************** -REMARKS: -Implements the SHR instruction and side effects. -****************************************************************************/ -u8 -shr_byte(u8 d, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 8) { - cnt = s % 8; - if (cnt > 0) { - cf = d & (1 << (cnt - 1)); - res = d >> cnt; - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = (u8) d; - } - - if (cnt == 1) { - CONDITIONAL_SET_FLAG(XOR2(res >> 6), F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CONDITIONAL_SET_FLAG((d >> (s - 1)) & 0x1, F_CF); - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_PF); - SET_FLAG(F_ZF); - } - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the SHR instruction and side effects. -****************************************************************************/ -u16 -shr_word(u16 d, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 16) { - cnt = s % 16; - if (cnt > 0) { - cf = d & (1 << (cnt - 1)); - res = d >> cnt; - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = d; - } - - if (cnt == 1) { - CONDITIONAL_SET_FLAG(XOR2(res >> 14), F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - SET_FLAG(F_ZF); - CLEAR_FLAG(F_SF); - CLEAR_FLAG(F_PF); - } - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the SHR instruction and side effects. -****************************************************************************/ -u32 -shr_long(u32 d, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 32) { - cnt = s % 32; - if (cnt > 0) { - cf = d & (1 << (cnt - 1)); - res = d >> cnt; - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = d; - } - if (cnt == 1) { - CONDITIONAL_SET_FLAG(XOR2(res >> 30), F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - SET_FLAG(F_ZF); - CLEAR_FLAG(F_SF); - CLEAR_FLAG(F_PF); - } - return res; -} - -/**************************************************************************** -REMARKS: -Implements the SAR instruction and side effects. -****************************************************************************/ -u8 -sar_byte(u8 d, u8 s) -{ - unsigned int cnt, res, cf, mask, sf; - - res = d; - sf = d & 0x80; - cnt = s % 8; - if (cnt > 0 && cnt < 8) { - mask = (1 << (8 - cnt)) - 1; - cf = d & (1 << (cnt - 1)); - res = (d >> cnt) & mask; - CONDITIONAL_SET_FLAG(cf, F_CF); - if (sf) { - res |= ~mask; - } - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - } - else if (cnt >= 8) { - if (sf) { - res = 0xff; - SET_FLAG(F_CF); - CLEAR_FLAG(F_ZF); - SET_FLAG(F_SF); - SET_FLAG(F_PF); - } - else { - res = 0; - CLEAR_FLAG(F_CF); - SET_FLAG(F_ZF); - CLEAR_FLAG(F_SF); - CLEAR_FLAG(F_PF); - } - } - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the SAR instruction and side effects. -****************************************************************************/ -u16 -sar_word(u16 d, u8 s) -{ - unsigned int cnt, res, cf, mask, sf; - - sf = d & 0x8000; - cnt = s % 16; - res = d; - if (cnt > 0 && cnt < 16) { - mask = (1 << (16 - cnt)) - 1; - cf = d & (1 << (cnt - 1)); - res = (d >> cnt) & mask; - CONDITIONAL_SET_FLAG(cf, F_CF); - if (sf) { - res |= ~mask; - } - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else if (cnt >= 16) { - if (sf) { - res = 0xffff; - SET_FLAG(F_CF); - CLEAR_FLAG(F_ZF); - SET_FLAG(F_SF); - SET_FLAG(F_PF); - } - else { - res = 0; - CLEAR_FLAG(F_CF); - SET_FLAG(F_ZF); - CLEAR_FLAG(F_SF); - CLEAR_FLAG(F_PF); - } - } - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the SAR instruction and side effects. -****************************************************************************/ -u32 -sar_long(u32 d, u8 s) -{ - u32 cnt, res, cf, mask, sf; - - sf = d & 0x80000000; - cnt = s % 32; - res = d; - if (cnt > 0 && cnt < 32) { - mask = (1 << (32 - cnt)) - 1; - cf = d & (1 << (cnt - 1)); - res = (d >> cnt) & mask; - CONDITIONAL_SET_FLAG(cf, F_CF); - if (sf) { - res |= ~mask; - } - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else if (cnt >= 32) { - if (sf) { - res = 0xffffffff; - SET_FLAG(F_CF); - CLEAR_FLAG(F_ZF); - SET_FLAG(F_SF); - SET_FLAG(F_PF); - } - else { - res = 0; - CLEAR_FLAG(F_CF); - SET_FLAG(F_ZF); - CLEAR_FLAG(F_SF); - CLEAR_FLAG(F_PF); - } - } - return res; -} - -/**************************************************************************** -REMARKS: -Implements the SHLD instruction and side effects. -****************************************************************************/ -u16 -shld_word(u16 d, u16 fill, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 16) { - cnt = s % 16; - if (cnt > 0) { - res = (d << cnt) | (fill >> (16 - cnt)); - cf = d & (1 << (16 - cnt)); - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = d; - } - if (cnt == 1) { - CONDITIONAL_SET_FLAG((((res & 0x8000) == 0x8000) ^ - (ACCESS_FLAG(F_CF) != 0)), F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CONDITIONAL_SET_FLAG((d << (s - 1)) & 0x8000, F_CF); - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_PF); - SET_FLAG(F_ZF); - } - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the SHLD instruction and side effects. -****************************************************************************/ -u32 -shld_long(u32 d, u32 fill, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 32) { - cnt = s % 32; - if (cnt > 0) { - res = (d << cnt) | (fill >> (32 - cnt)); - cf = d & (1 << (32 - cnt)); - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = d; - } - if (cnt == 1) { - CONDITIONAL_SET_FLAG((((res & 0x80000000) == 0x80000000) ^ - (ACCESS_FLAG(F_CF) != 0)), F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CONDITIONAL_SET_FLAG((d << (s - 1)) & 0x80000000, F_CF); - CLEAR_FLAG(F_OF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_PF); - SET_FLAG(F_ZF); - } - return res; -} - -/**************************************************************************** -REMARKS: -Implements the SHRD instruction and side effects. -****************************************************************************/ -u16 -shrd_word(u16 d, u16 fill, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 16) { - cnt = s % 16; - if (cnt > 0) { - cf = d & (1 << (cnt - 1)); - res = (d >> cnt) | (fill << (16 - cnt)); - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = d; - } - - if (cnt == 1) { - CONDITIONAL_SET_FLAG(XOR2(res >> 14), F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - SET_FLAG(F_ZF); - CLEAR_FLAG(F_SF); - CLEAR_FLAG(F_PF); - } - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the SHRD instruction and side effects. -****************************************************************************/ -u32 -shrd_long(u32 d, u32 fill, u8 s) -{ - unsigned int cnt, res, cf; - - if (s < 32) { - cnt = s % 32; - if (cnt > 0) { - cf = d & (1 << (cnt - 1)); - res = (d >> cnt) | (fill << (32 - cnt)); - CONDITIONAL_SET_FLAG(cf, F_CF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - } - else { - res = d; - } - if (cnt == 1) { - CONDITIONAL_SET_FLAG(XOR2(res >> 30), F_OF); - } - else { - CLEAR_FLAG(F_OF); - } - } - else { - res = 0; - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - SET_FLAG(F_ZF); - CLEAR_FLAG(F_SF); - CLEAR_FLAG(F_PF); - } - return res; -} - -/**************************************************************************** -REMARKS: -Implements the SBB instruction and side effects. -****************************************************************************/ -u8 -sbb_byte(u8 d, u8 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - if (ACCESS_FLAG(F_CF)) - res = d - s - 1; - else - res = d - s; - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | s)) | (~d & s); - CONDITIONAL_SET_FLAG(bc & 0x80, F_CF); - CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the SBB instruction and side effects. -****************************************************************************/ -u16 -sbb_word(u16 d, u16 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - if (ACCESS_FLAG(F_CF)) - res = d - s - 1; - else - res = d - s; - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | s)) | (~d & s); - CONDITIONAL_SET_FLAG(bc & 0x8000, F_CF); - CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the SBB instruction and side effects. -****************************************************************************/ -u32 -sbb_long(u32 d, u32 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - if (ACCESS_FLAG(F_CF)) - res = d - s - 1; - else - res = d - s; - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | s)) | (~d & s); - CONDITIONAL_SET_FLAG(bc & 0x80000000, F_CF); - CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the SUB instruction and side effects. -****************************************************************************/ -u8 -sub_byte(u8 d, u8 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - res = d - s; - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG((res & 0xff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | s)) | (~d & s); - CONDITIONAL_SET_FLAG(bc & 0x80, F_CF); - CONDITIONAL_SET_FLAG(XOR2(bc >> 6), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return (u8) res; -} - -/**************************************************************************** -REMARKS: -Implements the SUB instruction and side effects. -****************************************************************************/ -u16 -sub_word(u16 d, u16 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - res = d - s; - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG((res & 0xffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | s)) | (~d & s); - CONDITIONAL_SET_FLAG(bc & 0x8000, F_CF); - CONDITIONAL_SET_FLAG(XOR2(bc >> 14), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return (u16) res; -} - -/**************************************************************************** -REMARKS: -Implements the SUB instruction and side effects. -****************************************************************************/ -u32 -sub_long(u32 d, u32 s) -{ - register u32 res; /* all operands in native machine order */ - register u32 bc; - - res = d - s; - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG((res & 0xffffffff) == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - - /* calculate the borrow chain. See note at top */ - bc = (res & (~d | s)) | (~d & s); - CONDITIONAL_SET_FLAG(bc & 0x80000000, F_CF); - CONDITIONAL_SET_FLAG(XOR2(bc >> 30), F_OF); - CONDITIONAL_SET_FLAG(bc & 0x8, F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the TEST instruction and side effects. -****************************************************************************/ -void -test_byte(u8 d, u8 s) -{ - register u32 res; /* all operands in native machine order */ - - res = d & s; - - CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - /* AF == don't care */ - CLEAR_FLAG(F_CF); -} - -/**************************************************************************** -REMARKS: -Implements the TEST instruction and side effects. -****************************************************************************/ -void -test_word(u16 d, u16 s) -{ - register u32 res; /* all operands in native machine order */ - - res = d & s; - - CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - /* AF == don't care */ - CLEAR_FLAG(F_CF); -} - -/**************************************************************************** -REMARKS: -Implements the TEST instruction and side effects. -****************************************************************************/ -void -test_long(u32 d, u32 s) -{ - register u32 res; /* all operands in native machine order */ - - res = d & s; - - CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - /* AF == don't care */ - CLEAR_FLAG(F_CF); -} - -/**************************************************************************** -REMARKS: -Implements the XOR instruction and side effects. -****************************************************************************/ -u8 -xor_byte(u8 d, u8 s) -{ - register u8 res; /* all operands in native machine order */ - - res = d ^ s; - CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x80, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res), F_PF); - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the XOR instruction and side effects. -****************************************************************************/ -u16 -xor_word(u16 d, u16 s) -{ - register u16 res; /* all operands in native machine order */ - - res = d ^ s; - CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x8000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the XOR instruction and side effects. -****************************************************************************/ -u32 -xor_long(u32 d, u32 s) -{ - register u32 res; /* all operands in native machine order */ - - res = d ^ s; - CLEAR_FLAG(F_OF); - CONDITIONAL_SET_FLAG(res & 0x80000000, F_SF); - CONDITIONAL_SET_FLAG(res == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(res & 0xff), F_PF); - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - return res; -} - -/**************************************************************************** -REMARKS: -Implements the IMUL instruction and side effects. -****************************************************************************/ -void -imul_byte(u8 s) -{ - s16 res = (s16) ((s8) M.x86.R_AL * (s8) s); - - M.x86.R_AX = res; - if (((M.x86.R_AL & 0x80) == 0 && M.x86.R_AH == 0x00) || - ((M.x86.R_AL & 0x80) != 0 && M.x86.R_AH == 0xFF)) { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - else { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } -} - -/**************************************************************************** -REMARKS: -Implements the IMUL instruction and side effects. -****************************************************************************/ -void -imul_word(u16 s) -{ - s32 res = (s16) M.x86.R_AX * (s16) s; - - M.x86.R_AX = (u16) res; - M.x86.R_DX = (u16) (res >> 16); - if (((M.x86.R_AX & 0x8000) == 0 && M.x86.R_DX == 0x00) || - ((M.x86.R_AX & 0x8000) != 0 && M.x86.R_DX == 0xFF)) { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - else { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } -} - -/**************************************************************************** -REMARKS: -Implements the IMUL instruction and side effects. -****************************************************************************/ -void -imul_long_direct(u32 * res_lo, u32 * res_hi, u32 d, u32 s) -{ -#ifdef __HAS_LONG_LONG__ - s64 res = (s64) (s32) d * (s32) s; - - *res_lo = (u32) res; - *res_hi = (u32) (res >> 32); -#else - u32 d_lo, d_hi, d_sign; - u32 s_lo, s_hi, s_sign; - u32 rlo_lo, rlo_hi, rhi_lo; - - if ((d_sign = d & 0x80000000) != 0) - d = -d; - d_lo = d & 0xFFFF; - d_hi = d >> 16; - if ((s_sign = s & 0x80000000) != 0) - s = -s; - s_lo = s & 0xFFFF; - s_hi = s >> 16; - rlo_lo = d_lo * s_lo; - rlo_hi = (d_hi * s_lo + d_lo * s_hi) + (rlo_lo >> 16); - rhi_lo = d_hi * s_hi + (rlo_hi >> 16); - *res_lo = (rlo_hi << 16) | (rlo_lo & 0xFFFF); - *res_hi = rhi_lo; - if (d_sign != s_sign) { - d = ~*res_lo; - s = (((d & 0xFFFF) + 1) >> 16) + (d >> 16); - *res_lo = ~*res_lo + 1; - *res_hi = ~*res_hi + (s >> 16); - } -#endif -} - -/**************************************************************************** -REMARKS: -Implements the IMUL instruction and side effects. -****************************************************************************/ -void -imul_long(u32 s) -{ - imul_long_direct(&M.x86.R_EAX, &M.x86.R_EDX, M.x86.R_EAX, s); - if (((M.x86.R_EAX & 0x80000000) == 0 && M.x86.R_EDX == 0x00) || - ((M.x86.R_EAX & 0x80000000) != 0 && M.x86.R_EDX == 0xFF)) { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - else { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } -} - -/**************************************************************************** -REMARKS: -Implements the MUL instruction and side effects. -****************************************************************************/ -void -mul_byte(u8 s) -{ - u16 res = (u16) (M.x86.R_AL * s); - - M.x86.R_AX = res; - if (M.x86.R_AH == 0) { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - else { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } -} - -/**************************************************************************** -REMARKS: -Implements the MUL instruction and side effects. -****************************************************************************/ -void -mul_word(u16 s) -{ - u32 res = M.x86.R_AX * s; - - M.x86.R_AX = (u16) res; - M.x86.R_DX = (u16) (res >> 16); - if (M.x86.R_DX == 0) { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - else { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } -} - -/**************************************************************************** -REMARKS: -Implements the MUL instruction and side effects. -****************************************************************************/ -void -mul_long(u32 s) -{ -#ifdef __HAS_LONG_LONG__ - u64 res = (u64) M.x86.R_EAX * s; - - M.x86.R_EAX = (u32) res; - M.x86.R_EDX = (u32) (res >> 32); -#else - u32 a, a_lo, a_hi; - u32 s_lo, s_hi; - u32 rlo_lo, rlo_hi, rhi_lo; - - a = M.x86.R_EAX; - a_lo = a & 0xFFFF; - a_hi = a >> 16; - s_lo = s & 0xFFFF; - s_hi = s >> 16; - rlo_lo = a_lo * s_lo; - rlo_hi = (a_hi * s_lo + a_lo * s_hi) + (rlo_lo >> 16); - rhi_lo = a_hi * s_hi + (rlo_hi >> 16); - M.x86.R_EAX = (rlo_hi << 16) | (rlo_lo & 0xFFFF); - M.x86.R_EDX = rhi_lo; -#endif - - if (M.x86.R_EDX == 0) { - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_OF); - } - else { - SET_FLAG(F_CF); - SET_FLAG(F_OF); - } -} - -/**************************************************************************** -REMARKS: -Implements the IDIV instruction and side effects. -****************************************************************************/ -void -idiv_byte(u8 s) -{ - s32 dvd, div, mod; - - dvd = (s16) M.x86.R_AX; - if (s == 0) { - x86emu_intr_raise(0); - return; - } - div = dvd / (s8) s; - mod = dvd % (s8) s; - if (abs(div) > 0x7f) { - x86emu_intr_raise(0); - return; - } - M.x86.R_AL = (s8) div; - M.x86.R_AH = (s8) mod; -} - -/**************************************************************************** -REMARKS: -Implements the IDIV instruction and side effects. -****************************************************************************/ -void -idiv_word(u16 s) -{ - s32 dvd, div, mod; - - dvd = (((s32) M.x86.R_DX) << 16) | M.x86.R_AX; - if (s == 0) { - x86emu_intr_raise(0); - return; - } - div = dvd / (s16) s; - mod = dvd % (s16) s; - if (abs(div) > 0x7fff) { - x86emu_intr_raise(0); - return; - } - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_SF); - CONDITIONAL_SET_FLAG(div == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); - - M.x86.R_AX = (u16) div; - M.x86.R_DX = (u16) mod; -} - -/**************************************************************************** -REMARKS: -Implements the IDIV instruction and side effects. -****************************************************************************/ -void -idiv_long(u32 s) -{ -#ifdef __HAS_LONG_LONG__ - s64 dvd, div, mod; - - dvd = (((s64) M.x86.R_EDX) << 32) | M.x86.R_EAX; - if (s == 0) { - x86emu_intr_raise(0); - return; - } - div = dvd / (s32) s; - mod = dvd % (s32) s; - if (abs(div) > 0x7fffffff) { - x86emu_intr_raise(0); - return; - } -#else - s32 div = 0, mod; - s32 h_dvd = M.x86.R_EDX; - u32 l_dvd = M.x86.R_EAX; - u32 abs_s = s & 0x7FFFFFFF; - u32 abs_h_dvd = h_dvd & 0x7FFFFFFF; - u32 h_s = abs_s >> 1; - u32 l_s = abs_s << 31; - int counter = 31; - int carry; - - if (s == 0) { - x86emu_intr_raise(0); - return; - } - do { - div <<= 1; - carry = (l_dvd >= l_s) ? 0 : 1; - - if (abs_h_dvd < (h_s + carry)) { - h_s >>= 1; - l_s = abs_s << (--counter); - continue; - } - else { - abs_h_dvd -= (h_s + carry); - l_dvd = carry ? ((0xFFFFFFFF - l_s) + l_dvd + 1) - : (l_dvd - l_s); - h_s >>= 1; - l_s = abs_s << (--counter); - div |= 1; - continue; - } - - } while (counter > -1); - /* overflow */ - if (abs_h_dvd || (l_dvd > abs_s)) { - x86emu_intr_raise(0); - return; - } - /* sign */ - div |= ((h_dvd & 0x10000000) ^ (s & 0x10000000)); - mod = l_dvd; - -#endif - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); - - M.x86.R_EAX = (u32) div; - M.x86.R_EDX = (u32) mod; -} - -/**************************************************************************** -REMARKS: -Implements the DIV instruction and side effects. -****************************************************************************/ -void -div_byte(u8 s) -{ - u32 dvd, div, mod; - - dvd = M.x86.R_AX; - if (s == 0) { - x86emu_intr_raise(0); - return; - } - div = dvd / (u8) s; - mod = dvd % (u8) s; - if (abs(div) > 0xff) { - x86emu_intr_raise(0); - return; - } - M.x86.R_AL = (u8) div; - M.x86.R_AH = (u8) mod; -} - -/**************************************************************************** -REMARKS: -Implements the DIV instruction and side effects. -****************************************************************************/ -void -div_word(u16 s) -{ - u32 dvd, div, mod; - - dvd = (((u32) M.x86.R_DX) << 16) | M.x86.R_AX; - if (s == 0) { - x86emu_intr_raise(0); - return; - } - div = dvd / (u16) s; - mod = dvd % (u16) s; - if (abs(div) > 0xffff) { - x86emu_intr_raise(0); - return; - } - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_SF); - CONDITIONAL_SET_FLAG(div == 0, F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); - - M.x86.R_AX = (u16) div; - M.x86.R_DX = (u16) mod; -} - -/**************************************************************************** -REMARKS: -Implements the DIV instruction and side effects. -****************************************************************************/ -void -div_long(u32 s) -{ -#ifdef __HAS_LONG_LONG__ - u64 dvd, div, mod; - - dvd = (((u64) M.x86.R_EDX) << 32) | M.x86.R_EAX; - if (s == 0) { - x86emu_intr_raise(0); - return; - } - div = dvd / (u32) s; - mod = dvd % (u32) s; - if (abs(div) > 0xffffffff) { - x86emu_intr_raise(0); - return; - } -#else - s32 div = 0, mod; - s32 h_dvd = M.x86.R_EDX; - u32 l_dvd = M.x86.R_EAX; - - u32 h_s = s; - u32 l_s = 0; - int counter = 32; - int carry; - - if (s == 0) { - x86emu_intr_raise(0); - return; - } - do { - div <<= 1; - carry = (l_dvd >= l_s) ? 0 : 1; - - if (h_dvd < (h_s + carry)) { - h_s >>= 1; - l_s = s << (--counter); - continue; - } - else { - h_dvd -= (h_s + carry); - l_dvd = carry ? ((0xFFFFFFFF - l_s) + l_dvd + 1) - : (l_dvd - l_s); - h_s >>= 1; - l_s = s << (--counter); - div |= 1; - continue; - } - - } while (counter > -1); - /* overflow */ - if (h_dvd || (l_dvd > s)) { - x86emu_intr_raise(0); - return; - } - mod = l_dvd; -#endif - CLEAR_FLAG(F_CF); - CLEAR_FLAG(F_AF); - CLEAR_FLAG(F_SF); - SET_FLAG(F_ZF); - CONDITIONAL_SET_FLAG(PARITY(mod & 0xff), F_PF); - - M.x86.R_EAX = (u32) div; - M.x86.R_EDX = (u32) mod; -} - -/**************************************************************************** -REMARKS: -Implements the IN string instruction and side effects. -****************************************************************************/ -void -ins(int size) -{ - int inc = size; - - if (ACCESS_FLAG(F_DF)) { - inc = -size; - } - if (M.x86.mode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE)) { - /* don't care whether REPE or REPNE */ - /* in until CX is ZERO. */ - u32 count = ((M.x86.mode & SYSMODE_PREFIX_DATA) ? - M.x86.R_ECX : M.x86.R_CX); - switch (size) { - case 1: - while (count--) { - store_data_byte_abs(M.x86.R_ES, M.x86.R_DI, - (*sys_inb) (M.x86.R_DX)); - M.x86.R_DI += inc; - } - break; - - case 2: - while (count--) { - store_data_word_abs(M.x86.R_ES, M.x86.R_DI, - (*sys_inw) (M.x86.R_DX)); - M.x86.R_DI += inc; - } - break; - case 4: - while (count--) { - store_data_long_abs(M.x86.R_ES, M.x86.R_DI, - (*sys_inl) (M.x86.R_DX)); - M.x86.R_DI += inc; - break; - } - } - M.x86.R_CX = 0; - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ECX = 0; - } - M.x86.mode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE); - } - else { - switch (size) { - case 1: - store_data_byte_abs(M.x86.R_ES, M.x86.R_DI, - (*sys_inb) (M.x86.R_DX)); - break; - case 2: - store_data_word_abs(M.x86.R_ES, M.x86.R_DI, - (*sys_inw) (M.x86.R_DX)); - break; - case 4: - store_data_long_abs(M.x86.R_ES, M.x86.R_DI, - (*sys_inl) (M.x86.R_DX)); - break; - } - M.x86.R_DI += inc; - } -} - -/**************************************************************************** -REMARKS: -Implements the OUT string instruction and side effects. -****************************************************************************/ -void -outs(int size) -{ - int inc = size; - - if (ACCESS_FLAG(F_DF)) { - inc = -size; - } - if (M.x86.mode & (SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE)) { - /* don't care whether REPE or REPNE */ - /* out until CX is ZERO. */ - u32 count = ((M.x86.mode & SYSMODE_PREFIX_DATA) ? - M.x86.R_ECX : M.x86.R_CX); - switch (size) { - case 1: - while (count--) { - (*sys_outb) (M.x86.R_DX, - fetch_data_byte_abs(M.x86.R_ES, M.x86.R_SI)); - M.x86.R_SI += inc; - } - break; - - case 2: - while (count--) { - (*sys_outw) (M.x86.R_DX, - fetch_data_word_abs(M.x86.R_ES, M.x86.R_SI)); - M.x86.R_SI += inc; - } - break; - case 4: - while (count--) { - (*sys_outl) (M.x86.R_DX, - fetch_data_long_abs(M.x86.R_ES, M.x86.R_SI)); - M.x86.R_SI += inc; - break; - } - } - M.x86.R_CX = 0; - if (M.x86.mode & SYSMODE_PREFIX_DATA) { - M.x86.R_ECX = 0; - } - M.x86.mode &= ~(SYSMODE_PREFIX_REPE | SYSMODE_PREFIX_REPNE); - } - else { - switch (size) { - case 1: - (*sys_outb) (M.x86.R_DX, - fetch_data_byte_abs(M.x86.R_ES, M.x86.R_SI)); - break; - case 2: - (*sys_outw) (M.x86.R_DX, - fetch_data_word_abs(M.x86.R_ES, M.x86.R_SI)); - break; - case 4: - (*sys_outl) (M.x86.R_DX, - fetch_data_long_abs(M.x86.R_ES, M.x86.R_SI)); - break; - } - M.x86.R_SI += inc; - } -} - -/**************************************************************************** -PARAMETERS: -addr - Address to fetch word from - -REMARKS: -Fetches a word from emulator memory using an absolute address. -****************************************************************************/ -u16 -mem_access_word(int addr) -{ - DB(if (CHECK_MEM_ACCESS()) - x86emu_check_mem_access(addr);) - return (*sys_rdw) (addr); -} - -/**************************************************************************** -REMARKS: -Pushes a word onto the stack. - -NOTE: Do not inline this, as (*sys_wrX) is already inline! -****************************************************************************/ -void -push_word(u16 w) -{ - DB(if (CHECK_SP_ACCESS()) - x86emu_check_sp_access();) - M.x86.R_SP -= 2; - (*sys_wrw) (((u32) M.x86.R_SS << 4) + M.x86.R_SP, w); -} - -/**************************************************************************** -REMARKS: -Pushes a long onto the stack. - -NOTE: Do not inline this, as (*sys_wrX) is already inline! -****************************************************************************/ -void -push_long(u32 w) -{ - DB(if (CHECK_SP_ACCESS()) - x86emu_check_sp_access();) - M.x86.R_SP -= 4; - (*sys_wrl) (((u32) M.x86.R_SS << 4) + M.x86.R_SP, w); -} - -/**************************************************************************** -REMARKS: -Pops a word from the stack. - -NOTE: Do not inline this, as (*sys_rdX) is already inline! -****************************************************************************/ -u16 -pop_word(void) -{ - register u16 res; - - DB(if (CHECK_SP_ACCESS()) - x86emu_check_sp_access();) - res = (*sys_rdw) (((u32) M.x86.R_SS << 4) + M.x86.R_SP); - M.x86.R_SP += 2; - return res; -} - -/**************************************************************************** -REMARKS: -Pops a long from the stack. - -NOTE: Do not inline this, as (*sys_rdX) is already inline! -****************************************************************************/ -u32 -pop_long(void) -{ - register u32 res; - - DB(if (CHECK_SP_ACCESS()) - x86emu_check_sp_access();) - res = (*sys_rdl) (((u32) M.x86.R_SS << 4) + M.x86.R_SP); - M.x86.R_SP += 4; - return res; -} - -/**************************************************************************** -REMARKS: -CPUID takes EAX/ECX as inputs, writes EAX/EBX/ECX/EDX as output -****************************************************************************/ -void -cpuid(void) -{ - u32 feature = M.x86.R_EAX; - -#ifdef X86EMU_HAS_HW_CPUID - /* If the platform allows it, we will base our values on the real - * results from the CPUID instruction. We limit support to the - * first two features, and the results of those are sanitized. - */ - if (feature <= 1) - hw_cpuid(&M.x86.R_EAX, &M.x86.R_EBX, &M.x86.R_ECX, &M.x86.R_EDX); -#endif - - switch (feature) { - case 0: - /* Regardless if we have real data from the hardware, the emulator - * will only support up to feature 1, which we set in register EAX. - * Registers EBX:EDX:ECX contain a string identifying the CPU. - */ - M.x86.R_EAX = 1; -#ifndef X86EMU_HAS_HW_CPUID - /* EBX:EDX:ECX = "GenuineIntel" */ - M.x86.R_EBX = 0x756e6547; - M.x86.R_EDX = 0x49656e69; - M.x86.R_ECX = 0x6c65746e; -#endif - break; - case 1: -#ifndef X86EMU_HAS_HW_CPUID - /* If we don't have x86 compatible hardware, we return values from an - * Intel 486dx4; which was one of the first processors to have CPUID. - */ - M.x86.R_EAX = 0x00000480; - M.x86.R_EBX = 0x00000000; - M.x86.R_ECX = 0x00000000; - M.x86.R_EDX = 0x00000002; /* VME */ -#else - /* In the case that we have hardware CPUID instruction, we make sure - * that the features reported are limited to TSC and VME. - */ - M.x86.R_EDX &= 0x00000012; -#endif - break; - default: - /* Finally, we don't support any additional features. Most CPUs - * return all zeros when queried for invalid or unsupported feature - * numbers. - */ - M.x86.R_EAX = 0; - M.x86.R_EBX = 0; - M.x86.R_ECX = 0; - M.x86.R_EDX = 0; - break; - } -} diff --git a/hw/xfree86/x86emu/sys.c b/hw/xfree86/x86emu/sys.c deleted file mode 100644 index 6a648bf39..000000000 --- a/hw/xfree86/x86emu/sys.c +++ /dev/null @@ -1,550 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: This file includes subroutines which are related to -* programmed I/O and memory access. Included in this module -* are default functions with limited usefulness. For real -* uses these functions will most likely be overridden by the -* user library. -* -****************************************************************************/ - -#include "x86emu.h" -#include "x86emu/x86emui.h" -#include "x86emu/regs.h" -#include "x86emu/debug.h" -#include "x86emu/prim_ops.h" -#ifndef NO_SYS_HEADERS -#include -#endif - -#ifdef __GNUC__ - -/* Define some packed structures to use with unaligned accesses */ - -struct __una_u64 { - u64 x __attribute__ ((packed)); -}; -struct __una_u32 { - u32 x __attribute__ ((packed)); -}; -struct __una_u16 { - u16 x __attribute__ ((packed)); -}; - -/* Elemental unaligned loads */ - -static __inline__ u64 -ldq_u(u64 * p) -{ - const struct __una_u64 *ptr = (const struct __una_u64 *) p; - - return ptr->x; -} - -static __inline__ u32 -ldl_u(u32 * p) -{ - const struct __una_u32 *ptr = (const struct __una_u32 *) p; - - return ptr->x; -} - -static __inline__ u16 -ldw_u(u16 * p) -{ - const struct __una_u16 *ptr = (const struct __una_u16 *) p; - - return ptr->x; -} - -/* Elemental unaligned stores */ - -static __inline__ void -stq_u(u64 val, u64 * p) -{ - struct __una_u64 *ptr = (struct __una_u64 *) p; - - ptr->x = val; -} - -static __inline__ void -stl_u(u32 val, u32 * p) -{ - struct __una_u32 *ptr = (struct __una_u32 *) p; - - ptr->x = val; -} - -static __inline__ void -stw_u(u16 val, u16 * p) -{ - struct __una_u16 *ptr = (struct __una_u16 *) p; - - ptr->x = val; -} -#else /* !__GNUC__ */ - -static __inline__ u64 -ldq_u(u64 * p) -{ - u64 ret; - - memmove(&ret, p, sizeof(*p)); - return ret; -} - -static __inline__ u32 -ldl_u(u32 * p) -{ - u32 ret; - - memmove(&ret, p, sizeof(*p)); - return ret; -} - -static __inline__ u16 -ldw_u(u16 * p) -{ - u16 ret; - - memmove(&ret, p, sizeof(*p)); - return ret; -} - -static __inline__ void -stq_u(u64 val, u64 * p) -{ - u64 tmp = val; - - memmove(p, &tmp, sizeof(*p)); -} - -static __inline__ void -stl_u(u32 val, u32 * p) -{ - u32 tmp = val; - - memmove(p, &tmp, sizeof(*p)); -} - -static __inline__ void -stw_u(u16 val, u16 * p) -{ - u16 tmp = val; - - memmove(p, &tmp, sizeof(*p)); -} - -#endif /* __GNUC__ */ -/*------------------------- Global Variables ------------------------------*/ - -X86EMU_sysEnv _X86EMU_env; /* Global emulator machine state */ -X86EMU_intrFuncs _X86EMU_intrTab[256]; - -/*----------------------------- Implementation ----------------------------*/ - -/**************************************************************************** -PARAMETERS: -addr - Emulator memory address to read - -RETURNS: -Byte value read from emulator memory. - -REMARKS: -Reads a byte value from the emulator memory. -****************************************************************************/ -u8 X86API -rdb(u32 addr) -{ - u8 val; - - if (addr > M.mem_size - 1) { - DB(printk("mem_read: address %#" PRIx32 " out of range!\n", addr); - ) - HALT_SYS(); - } - val = *(u8 *) (M.mem_base + addr); - DB(if (DEBUG_MEM_TRACE()) - printk("%#08x 1 -> %#x\n", addr, val);) - return val; -} - -/**************************************************************************** -PARAMETERS: -addr - Emulator memory address to read - -RETURNS: -Word value read from emulator memory. - -REMARKS: -Reads a word value from the emulator memory. -****************************************************************************/ -u16 X86API -rdw(u32 addr) -{ - u16 val = 0; - - if (addr > M.mem_size - 2) { - DB(printk("mem_read: address %#" PRIx32 " out of range!\n", addr); - ) - HALT_SYS(); - } -#ifdef __BIG_ENDIAN__ - if (addr & 0x1) { - val = (*(u8 *) (M.mem_base + addr) | - (*(u8 *) (M.mem_base + addr + 1) << 8)); - } - else -#endif - val = ldw_u((u16 *) (M.mem_base + addr)); - DB(if (DEBUG_MEM_TRACE()) - printk("%#08x 2 -> %#x\n", addr, val);) - return val; -} - -/**************************************************************************** -PARAMETERS: -addr - Emulator memory address to read - -RETURNS: -Long value read from emulator memory. -REMARKS: -Reads a long value from the emulator memory. -****************************************************************************/ -u32 X86API -rdl(u32 addr) -{ - u32 val = 0; - - if (addr > M.mem_size - 4) { - DB(printk("mem_read: address %#" PRIx32 " out of range!\n", addr); - ) - HALT_SYS(); - } -#ifdef __BIG_ENDIAN__ - if (addr & 0x3) { - val = (*(u8 *) (M.mem_base + addr + 0) | - (*(u8 *) (M.mem_base + addr + 1) << 8) | - (*(u8 *) (M.mem_base + addr + 2) << 16) | - (*(u8 *) (M.mem_base + addr + 3) << 24)); - } - else -#endif - val = ldl_u((u32 *) (M.mem_base + addr)); - DB(if (DEBUG_MEM_TRACE()) - printk("%#08x 4 -> %#x\n", addr, val);) - return val; -} - -/**************************************************************************** -PARAMETERS: -addr - Emulator memory address to read -val - Value to store - -REMARKS: -Writes a byte value to emulator memory. -****************************************************************************/ -void X86API -wrb(u32 addr, u8 val) -{ - DB(if (DEBUG_MEM_TRACE()) - printk("%#08x 1 <- %#x\n", addr, val);) - if (addr > M.mem_size - 1) { - DB(printk("mem_write: address %#" PRIx32 " out of range!\n",addr); - ) - HALT_SYS(); - } - *(u8 *) (M.mem_base + addr) = val; -} - -/**************************************************************************** -PARAMETERS: -addr - Emulator memory address to read -val - Value to store - -REMARKS: -Writes a word value to emulator memory. -****************************************************************************/ -void X86API -wrw(u32 addr, u16 val) -{ - DB(if (DEBUG_MEM_TRACE()) - printk("%#08x 2 <- %#x\n", addr, val);) - if (addr > M.mem_size - 2) { - DB(printk("mem_write: address %#" PRIx32 " out of range!\n",addr); - ) - HALT_SYS(); - } -#ifdef __BIG_ENDIAN__ - if (addr & 0x1) { - *(u8 *) (M.mem_base + addr + 0) = (val >> 0) & 0xff; - *(u8 *) (M.mem_base + addr + 1) = (val >> 8) & 0xff; - } - else -#endif - stw_u(val, (u16 *) (M.mem_base + addr)); -} - -/**************************************************************************** -PARAMETERS: -addr - Emulator memory address to read -val - Value to store - -REMARKS: -Writes a long value to emulator memory. -****************************************************************************/ -void X86API -wrl(u32 addr, u32 val) -{ - DB(if (DEBUG_MEM_TRACE()) - printk("%#08x 4 <- %#x\n", addr, val);) - if (addr > M.mem_size - 4) { - DB(printk("mem_write: address %#" PRIx32 " out of range!\n",addr); - ) - HALT_SYS(); - } -#ifdef __BIG_ENDIAN__ - if (addr & 0x1) { - *(u8 *) (M.mem_base + addr + 0) = (val >> 0) & 0xff; - *(u8 *) (M.mem_base + addr + 1) = (val >> 8) & 0xff; - *(u8 *) (M.mem_base + addr + 2) = (val >> 16) & 0xff; - *(u8 *) (M.mem_base + addr + 3) = (val >> 24) & 0xff; - } - else -#endif - stl_u(val, (u32 *) (M.mem_base + addr)); -} - -/**************************************************************************** -PARAMETERS: -addr - PIO address to read -RETURN: -0 -REMARKS: -Default PIO byte read function. Doesn't perform real inb. -****************************************************************************/ -static u8 X86API -p_inb(X86EMU_pioAddr addr) -{ - DB(if (DEBUG_IO_TRACE()) - printk("inb %#04x \n", addr);) - return 0; -} - -/**************************************************************************** -PARAMETERS: -addr - PIO address to read -RETURN: -0 -REMARKS: -Default PIO word read function. Doesn't perform real inw. -****************************************************************************/ -static u16 X86API -p_inw(X86EMU_pioAddr addr) -{ - DB(if (DEBUG_IO_TRACE()) - printk("inw %#04x \n", addr);) - return 0; -} - -/**************************************************************************** -PARAMETERS: -addr - PIO address to read -RETURN: -0 -REMARKS: -Default PIO long read function. Doesn't perform real inl. -****************************************************************************/ -static u32 X86API -p_inl(X86EMU_pioAddr addr) -{ - DB(if (DEBUG_IO_TRACE()) - printk("inl %#04x \n", addr);) - return 0; -} - -/**************************************************************************** -PARAMETERS: -addr - PIO address to write -val - Value to store -REMARKS: -Default PIO byte write function. Doesn't perform real outb. -****************************************************************************/ -static void X86API -p_outb(X86EMU_pioAddr addr, u8 val) -{ - DB(if (DEBUG_IO_TRACE()) - printk("outb %#02x -> %#04x \n", val, addr);) - return; -} - -/**************************************************************************** -PARAMETERS: -addr - PIO address to write -val - Value to store -REMARKS: -Default PIO word write function. Doesn't perform real outw. -****************************************************************************/ -static void X86API -p_outw(X86EMU_pioAddr addr, u16 val) -{ - DB(if (DEBUG_IO_TRACE()) - printk("outw %#04x -> %#04x \n", val, addr);) - return; -} - -/**************************************************************************** -PARAMETERS: -addr - PIO address to write -val - Value to store -REMARKS: -Default PIO ;ong write function. Doesn't perform real outl. -****************************************************************************/ -static void X86API -p_outl(X86EMU_pioAddr addr, u32 val) -{ - DB(if (DEBUG_IO_TRACE()) - printk("outl %#08x -> %#04x \n", val, addr);) - return; -} - -/*------------------------- Global Variables ------------------------------*/ - -u8(X86APIP sys_rdb) (u32 addr) = rdb; -u16(X86APIP sys_rdw) (u32 addr) = rdw; -u32(X86APIP sys_rdl) (u32 addr) = rdl; -void (X86APIP sys_wrb) (u32 addr, u8 val) = wrb; -void (X86APIP sys_wrw) (u32 addr, u16 val) = wrw; -void (X86APIP sys_wrl) (u32 addr, u32 val) = wrl; - -u8(X86APIP sys_inb) (X86EMU_pioAddr addr) = p_inb; -u16(X86APIP sys_inw) (X86EMU_pioAddr addr) = p_inw; -u32(X86APIP sys_inl) (X86EMU_pioAddr addr) = p_inl; -void (X86APIP sys_outb) (X86EMU_pioAddr addr, u8 val) = p_outb; -void (X86APIP sys_outw) (X86EMU_pioAddr addr, u16 val) = p_outw; -void (X86APIP sys_outl) (X86EMU_pioAddr addr, u32 val) = p_outl; - -/*----------------------------- Setup -------------------------------------*/ - -/**************************************************************************** -PARAMETERS: -funcs - New memory function pointers to make active - -REMARKS: -This function is used to set the pointers to functions which access -memory space, allowing the user application to override these functions -and hook them out as necessary for their application. -****************************************************************************/ -void -X86EMU_setupMemFuncs(X86EMU_memFuncs * funcs) -{ - sys_rdb = funcs->rdb; - sys_rdw = funcs->rdw; - sys_rdl = funcs->rdl; - sys_wrb = funcs->wrb; - sys_wrw = funcs->wrw; - sys_wrl = funcs->wrl; -} - -/**************************************************************************** -PARAMETERS: -funcs - New programmed I/O function pointers to make active - -REMARKS: -This function is used to set the pointers to functions which access -I/O space, allowing the user application to override these functions -and hook them out as necessary for their application. -****************************************************************************/ -void -X86EMU_setupPioFuncs(X86EMU_pioFuncs * funcs) -{ - sys_inb = funcs->inb; - sys_inw = funcs->inw; - sys_inl = funcs->inl; - sys_outb = funcs->outb; - sys_outw = funcs->outw; - sys_outl = funcs->outl; -} - -/**************************************************************************** -PARAMETERS: -funcs - New interrupt vector table to make active - -REMARKS: -This function is used to set the pointers to functions which handle -interrupt processing in the emulator, allowing the user application to -hook interrupts as necessary for their application. Any interrupts that -are not hooked by the user application, and reflected and handled internally -in the emulator via the interrupt vector table. This allows the application -to get control when the code being emulated executes specific software -interrupts. -****************************************************************************/ -void -X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[]) -{ - int i; - - for (i = 0; i < 256; i++) - _X86EMU_intrTab[i] = NULL; - if (funcs) { - for (i = 0; i < 256; i++) - _X86EMU_intrTab[i] = funcs[i]; - } -} - -/**************************************************************************** -PARAMETERS: -int - New software interrupt to prepare for - -REMARKS: -This function is used to set up the emulator state to execute a software -interrupt. This can be used by the user application code to allow an -interrupt to be hooked, examined and then reflected back to the emulator -so that the code in the emulator will continue processing the software -interrupt as per normal. This essentially allows system code to actively -hook and handle certain software interrupts as necessary. -****************************************************************************/ -void -X86EMU_prepareForInt(int num) -{ - push_word((u16) M.x86.R_FLG); - CLEAR_FLAG(F_IF); - CLEAR_FLAG(F_TF); - push_word(M.x86.R_CS); - M.x86.R_CS = mem_access_word(num * 4 + 2); - push_word(M.x86.R_IP); - M.x86.R_IP = mem_access_word(num * 4); - M.x86.intr = 0; -} diff --git a/hw/xfree86/x86emu/validate.c b/hw/xfree86/x86emu/validate.c deleted file mode 100644 index 4c36e1df5..000000000 --- a/hw/xfree86/x86emu/validate.c +++ /dev/null @@ -1,769 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: Watcom C 10.6 or later -* Environment: 32-bit DOS -* Developer: Kendall Bennett -* -* Description: Program to validate the x86 emulator library for -* correctness. We run the emulator primitive operations -* functions against the real x86 CPU, and compare the result -* and flags to ensure correctness. -* -* We use inline assembler to compile and build this program. -* -****************************************************************************/ - -#include -#include -#include -#include -#include "x86emu.h" -#include "x86emu/prim_asm.h" - -/*-------------------------- Implementation -------------------------------*/ - -#define true 1 -#define false 0 - -#define ALL_FLAGS (F_CF | F_PF | F_AF | F_ZF | F_SF | F_OF) - -#define VAL_START_BINARY(parm_type,res_type,dmax,smax,dincr,sincr) \ -{ \ - parm_type d,s; \ - res_type r,r_asm; \ - ulong flags,inflags; \ - int f,failed = false; \ - char buf1[80],buf2[80]; \ - for (d = 0; d < dmax; d += dincr) { \ - for (s = 0; s < smax; s += sincr) { \ - M.x86.R_EFLG = inflags = flags = def_flags; \ - for (f = 0; f < 2; f++) { - -#define VAL_TEST_BINARY(name) \ - r_asm = name##_asm(&flags,d,s); \ - r = name(d,s); \ - if (r != r_asm || M.x86.R_EFLG != flags) \ - failed = true; \ - if (failed || trace) { - -#define VAL_TEST_BINARY_VOID(name) \ - name##_asm(&flags,d,s); \ - name(d,s); \ - r = r_asm = 0; \ - if (M.x86.R_EFLG != flags) \ - failed = true; \ - if (failed || trace) { - -#define VAL_FAIL_BYTE_BYTE_BINARY(name) \ - if (failed) \ - printk("fail\n"); \ - printk("0x%02X = %-15s(0x%02X,0x%02X), flags = %s -> %s\n", \ - r, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%02X = %-15s(0x%02X,0x%02X), flags = %s -> %s\n", \ - r_asm, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags)); - -#define VAL_FAIL_WORD_WORD_BINARY(name) \ - if (failed) \ - printk("fail\n"); \ - printk("0x%04X = %-15s(0x%04X,0x%04X), flags = %s -> %s\n", \ - r, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%04X = %-15s(0x%04X,0x%04X), flags = %s -> %s\n", \ - r_asm, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags)); - -#define VAL_FAIL_LONG_LONG_BINARY(name) \ - if (failed) \ - printk("fail\n"); \ - printk("0x%08X = %-15s(0x%08X,0x%08X), flags = %s -> %s\n", \ - r, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%08X = %-15s(0x%08X,0x%08X), flags = %s -> %s\n", \ - r_asm, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags)); - -#define VAL_END_BINARY() \ - } \ - M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF); \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (!failed) \ - printk("passed\n"); \ -} - -#define VAL_BYTE_BYTE_BINARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_BINARY(u8,u8,0xFF,0xFF,1,1) \ - VAL_TEST_BINARY(name) \ - VAL_FAIL_BYTE_BYTE_BINARY(name) \ - VAL_END_BINARY() - -#define VAL_WORD_WORD_BINARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_BINARY(u16,u16,0xFF00,0xFF00,0x100,0x100) \ - VAL_TEST_BINARY(name) \ - VAL_FAIL_WORD_WORD_BINARY(name) \ - VAL_END_BINARY() - -#define VAL_LONG_LONG_BINARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_BINARY(u32,u32,0xFF000000,0xFF000000,0x1000000,0x1000000) \ - VAL_TEST_BINARY(name) \ - VAL_FAIL_LONG_LONG_BINARY(name) \ - VAL_END_BINARY() - -#define VAL_VOID_BYTE_BINARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_BINARY(u8,u8,0xFF,0xFF,1,1) \ - VAL_TEST_BINARY_VOID(name) \ - VAL_FAIL_BYTE_BYTE_BINARY(name) \ - VAL_END_BINARY() - -#define VAL_VOID_WORD_BINARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_BINARY(u16,u16,0xFF00,0xFF00,0x100,0x100) \ - VAL_TEST_BINARY_VOID(name) \ - VAL_FAIL_WORD_WORD_BINARY(name) \ - VAL_END_BINARY() - -#define VAL_VOID_LONG_BINARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_BINARY(u32,u32,0xFF000000,0xFF000000,0x1000000,0x1000000) \ - VAL_TEST_BINARY_VOID(name) \ - VAL_FAIL_LONG_LONG_BINARY(name) \ - VAL_END_BINARY() - -#define VAL_BYTE_ROTATE(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_BINARY(u8,u8,0xFF,8,1,1) \ - VAL_TEST_BINARY(name) \ - VAL_FAIL_BYTE_BYTE_BINARY(name) \ - VAL_END_BINARY() - -#define VAL_WORD_ROTATE(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_BINARY(u16,u16,0xFF00,16,0x100,1) \ - VAL_TEST_BINARY(name) \ - VAL_FAIL_WORD_WORD_BINARY(name) \ - VAL_END_BINARY() - -#define VAL_LONG_ROTATE(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_BINARY(u32,u32,0xFF000000,32,0x1000000,1) \ - VAL_TEST_BINARY(name) \ - VAL_FAIL_LONG_LONG_BINARY(name) \ - VAL_END_BINARY() - -#define VAL_START_TERNARY(parm_type,res_type,dmax,smax,dincr,sincr,maxshift)\ -{ \ - parm_type d,s; \ - res_type r,r_asm; \ - u8 shift; \ - u32 flags,inflags; \ - int f,failed = false; \ - char buf1[80],buf2[80]; \ - for (d = 0; d < dmax; d += dincr) { \ - for (s = 0; s < smax; s += sincr) { \ - for (shift = 0; shift < maxshift; shift += 1) { \ - M.x86.R_EFLG = inflags = flags = def_flags; \ - for (f = 0; f < 2; f++) { - -#define VAL_TEST_TERNARY(name) \ - r_asm = name##_asm(&flags,d,s,shift); \ - r = name(d,s,shift); \ - if (r != r_asm || M.x86.R_EFLG != flags) \ - failed = true; \ - if (failed || trace) { - -#define VAL_FAIL_WORD_WORD_TERNARY(name) \ - if (failed) \ - printk("fail\n"); \ - printk("0x%04X = %-15s(0x%04X,0x%04X,%d), flags = %s -> %s\n", \ - r, #name, d, s, shift, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%04X = %-15s(0x%04X,0x%04X,%d), flags = %s -> %s\n", \ - r_asm, #name"_asm", d, s, shift, print_flags(buf1,inflags), print_flags(buf2,flags)); - -#define VAL_FAIL_LONG_LONG_TERNARY(name) \ - if (failed) \ - printk("fail\n"); \ - printk("0x%08X = %-15s(0x%08X,0x%08X,%d), flags = %s -> %s\n", \ - r, #name, d, s, shift, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%08X = %-15s(0x%08X,0x%08X,%d), flags = %s -> %s\n", \ - r_asm, #name"_asm", d, s, shift, print_flags(buf1,inflags), print_flags(buf2,flags)); - -#define VAL_END_TERNARY() \ - } \ - M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF); \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (!failed) \ - printk("passed\n"); \ -} - -#define VAL_WORD_ROTATE_DBL(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_TERNARY(u16,u16,0xFF00,0xFF00,0x100,0x100,16) \ - VAL_TEST_TERNARY(name) \ - VAL_FAIL_WORD_WORD_TERNARY(name) \ - VAL_END_TERNARY() - -#define VAL_LONG_ROTATE_DBL(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_TERNARY(u32,u32,0xFF000000,0xFF000000,0x1000000,0x1000000,32) \ - VAL_TEST_TERNARY(name) \ - VAL_FAIL_LONG_LONG_TERNARY(name) \ - VAL_END_TERNARY() - -#define VAL_START_UNARY(parm_type,max,incr) \ -{ \ - parm_type d,r,r_asm; \ - u32 flags,inflags; \ - int f,failed = false; \ - char buf1[80],buf2[80]; \ - for (d = 0; d < max; d += incr) { \ - M.x86.R_EFLG = inflags = flags = def_flags; \ - for (f = 0; f < 2; f++) { - -#define VAL_TEST_UNARY(name) \ - r_asm = name##_asm(&flags,d); \ - r = name(d); \ - if (r != r_asm || M.x86.R_EFLG != flags) { \ - failed = true; - -#define VAL_FAIL_BYTE_UNARY(name) \ - printk("fail\n"); \ - printk("0x%02X = %-15s(0x%02X), flags = %s -> %s\n", \ - r, #name, d, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%02X = %-15s(0x%02X), flags = %s -> %s\n", \ - r_asm, #name"_asm", d, print_flags(buf1,inflags), print_flags(buf2,flags)); - -#define VAL_FAIL_WORD_UNARY(name) \ - printk("fail\n"); \ - printk("0x%04X = %-15s(0x%04X), flags = %s -> %s\n", \ - r, #name, d, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%04X = %-15s(0x%04X), flags = %s -> %s\n", \ - r_asm, #name"_asm", d, print_flags(buf1,inflags), print_flags(buf2,flags)); - -#define VAL_FAIL_LONG_UNARY(name) \ - printk("fail\n"); \ - printk("0x%08X = %-15s(0x%08X), flags = %s -> %s\n", \ - r, #name, d, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%08X = %-15s(0x%08X), flags = %s -> %s\n", \ - r_asm, #name"_asm", d, print_flags(buf1,inflags), print_flags(buf2,flags)); - -#define VAL_END_UNARY() \ - } \ - M.x86.R_EFLG = inflags = flags = def_flags | ALL_FLAGS; \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (!failed) \ - printk("passed\n"); \ -} - -#define VAL_BYTE_UNARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_UNARY(u8,0xFF,0x1) \ - VAL_TEST_UNARY(name) \ - VAL_FAIL_BYTE_UNARY(name) \ - VAL_END_UNARY() - -#define VAL_WORD_UNARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_UNARY(u16,0xFF00,0x100) \ - VAL_TEST_UNARY(name) \ - VAL_FAIL_WORD_UNARY(name) \ - VAL_END_UNARY() - -#define VAL_WORD_BYTE_UNARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_UNARY(u16,0xFF,0x1) \ - VAL_TEST_UNARY(name) \ - VAL_FAIL_WORD_UNARY(name) \ - VAL_END_UNARY() - -#define VAL_LONG_UNARY(name) \ - printk("Validating %s ... ", #name); \ - VAL_START_UNARY(u32,0xFF000000,0x1000000) \ - VAL_TEST_UNARY(name) \ - VAL_FAIL_LONG_UNARY(name) \ - VAL_END_UNARY() - -#define VAL_BYTE_MUL(name) \ - printk("Validating %s ... ", #name); \ -{ \ - u8 d,s; \ - u16 r,r_asm; \ - u32 flags,inflags; \ - int f,failed = false; \ - char buf1[80],buf2[80]; \ - for (d = 0; d < 0xFF; d += 1) { \ - for (s = 0; s < 0xFF; s += 1) { \ - M.x86.R_EFLG = inflags = flags = def_flags; \ - for (f = 0; f < 2; f++) { \ - name##_asm(&flags,&r_asm,d,s); \ - M.x86.R_AL = d; \ - name(s); \ - r = M.x86.R_AX; \ - if (r != r_asm || M.x86.R_EFLG != flags) \ - failed = true; \ - if (failed || trace) { \ - if (failed) \ - printk("fail\n"); \ - printk("0x%04X = %-15s(0x%02X,0x%02X), flags = %s -> %s\n", \ - r, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%04X = %-15s(0x%02X,0x%02X), flags = %s -> %s\n", \ - r_asm, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags)); \ - } \ - M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF); \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (!failed) \ - printk("passed\n"); \ -} - -#define VAL_WORD_MUL(name) \ - printk("Validating %s ... ", #name); \ -{ \ - u16 d,s; \ - u16 r_lo,r_asm_lo; \ - u16 r_hi,r_asm_hi; \ - u32 flags,inflags; \ - int f,failed = false; \ - char buf1[80],buf2[80]; \ - for (d = 0; d < 0xFF00; d += 0x100) { \ - for (s = 0; s < 0xFF00; s += 0x100) { \ - M.x86.R_EFLG = inflags = flags = def_flags; \ - for (f = 0; f < 2; f++) { \ - name##_asm(&flags,&r_asm_lo,&r_asm_hi,d,s); \ - M.x86.R_AX = d; \ - name(s); \ - r_lo = M.x86.R_AX; \ - r_hi = M.x86.R_DX; \ - if (r_lo != r_asm_lo || r_hi != r_asm_hi || M.x86.R_EFLG != flags)\ - failed = true; \ - if (failed || trace) { \ - if (failed) \ - printk("fail\n"); \ - printk("0x%04X:0x%04X = %-15s(0x%04X,0x%04X), flags = %s -> %s\n", \ - r_hi,r_lo, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%04X:0x%04X = %-15s(0x%04X,0x%04X), flags = %s -> %s\n", \ - r_asm_hi,r_asm_lo, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags)); \ - } \ - M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF); \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (!failed) \ - printk("passed\n"); \ -} - -#define VAL_LONG_MUL(name) \ - printk("Validating %s ... ", #name); \ -{ \ - u32 d,s; \ - u32 r_lo,r_asm_lo; \ - u32 r_hi,r_asm_hi; \ - u32 flags,inflags; \ - int f,failed = false; \ - char buf1[80],buf2[80]; \ - for (d = 0; d < 0xFF000000; d += 0x1000000) { \ - for (s = 0; s < 0xFF000000; s += 0x1000000) { \ - M.x86.R_EFLG = inflags = flags = def_flags; \ - for (f = 0; f < 2; f++) { \ - name##_asm(&flags,&r_asm_lo,&r_asm_hi,d,s); \ - M.x86.R_EAX = d; \ - name(s); \ - r_lo = M.x86.R_EAX; \ - r_hi = M.x86.R_EDX; \ - if (r_lo != r_asm_lo || r_hi != r_asm_hi || M.x86.R_EFLG != flags)\ - failed = true; \ - if (failed || trace) { \ - if (failed) \ - printk("fail\n"); \ - printk("0x%08X:0x%08X = %-15s(0x%08X,0x%08X), flags = %s -> %s\n", \ - r_hi,r_lo, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%08X:0x%08X = %-15s(0x%08X,0x%08X), flags = %s -> %s\n", \ - r_asm_hi,r_asm_lo, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags)); \ - } \ - M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF); \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (!failed) \ - printk("passed\n"); \ -} - -#define VAL_BYTE_DIV(name) \ - printk("Validating %s ... ", #name); \ -{ \ - u16 d,s; \ - u8 r_quot,r_rem,r_asm_quot,r_asm_rem; \ - u32 flags,inflags; \ - int f,failed = false; \ - char buf1[80],buf2[80]; \ - for (d = 0; d < 0xFF00; d += 0x100) { \ - for (s = 1; s < 0xFF; s += 1) { \ - M.x86.R_EFLG = inflags = flags = def_flags; \ - for (f = 0; f < 2; f++) { \ - M.x86.intr = 0; \ - M.x86.R_AX = d; \ - name(s); \ - r_quot = M.x86.R_AL; \ - r_rem = M.x86.R_AH; \ - if (M.x86.intr & INTR_SYNCH) \ - continue; \ - name##_asm(&flags,&r_asm_quot,&r_asm_rem,d,s); \ - if (r_quot != r_asm_quot || r_rem != r_asm_rem || M.x86.R_EFLG != flags) \ - failed = true; \ - if (failed || trace) { \ - if (failed) \ - printk("fail\n"); \ - printk("0x%02X:0x%02X = %-15s(0x%04X,0x%02X), flags = %s -> %s\n", \ - r_quot, r_rem, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%02X:0x%02X = %-15s(0x%04X,0x%02X), flags = %s -> %s\n", \ - r_asm_quot, r_asm_rem, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags)); \ - } \ - M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF); \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (!failed) \ - printk("passed\n"); \ -} - -#define VAL_WORD_DIV(name) \ - printk("Validating %s ... ", #name); \ -{ \ - u32 d,s; \ - u16 r_quot,r_rem,r_asm_quot,r_asm_rem; \ - u32 flags,inflags; \ - int f,failed = false; \ - char buf1[80],buf2[80]; \ - for (d = 0; d < 0xFF000000; d += 0x1000000) { \ - for (s = 0x100; s < 0xFF00; s += 0x100) { \ - M.x86.R_EFLG = inflags = flags = def_flags; \ - for (f = 0; f < 2; f++) { \ - M.x86.intr = 0; \ - M.x86.R_AX = d & 0xFFFF; \ - M.x86.R_DX = d >> 16; \ - name(s); \ - r_quot = M.x86.R_AX; \ - r_rem = M.x86.R_DX; \ - if (M.x86.intr & INTR_SYNCH) \ - continue; \ - name##_asm(&flags,&r_asm_quot,&r_asm_rem,d & 0xFFFF,d >> 16,s);\ - if (r_quot != r_asm_quot || r_rem != r_asm_rem || M.x86.R_EFLG != flags) \ - failed = true; \ - if (failed || trace) { \ - if (failed) \ - printk("fail\n"); \ - printk("0x%04X:0x%04X = %-15s(0x%08X,0x%04X), flags = %s -> %s\n", \ - r_quot, r_rem, #name, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%04X:0x%04X = %-15s(0x%08X,0x%04X), flags = %s -> %s\n", \ - r_asm_quot, r_asm_rem, #name"_asm", d, s, print_flags(buf1,inflags), print_flags(buf2,flags)); \ - } \ - M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF); \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (!failed) \ - printk("passed\n"); \ -} - -#define VAL_LONG_DIV(name) \ - printk("Validating %s ... ", #name); \ -{ \ - u32 d,s; \ - u32 r_quot,r_rem,r_asm_quot,r_asm_rem; \ - u32 flags,inflags; \ - int f,failed = false; \ - char buf1[80],buf2[80]; \ - for (d = 0; d < 0xFF000000; d += 0x1000000) { \ - for (s = 0x100; s < 0xFF00; s += 0x100) { \ - M.x86.R_EFLG = inflags = flags = def_flags; \ - for (f = 0; f < 2; f++) { \ - M.x86.intr = 0; \ - M.x86.R_EAX = d; \ - M.x86.R_EDX = 0; \ - name(s); \ - r_quot = M.x86.R_EAX; \ - r_rem = M.x86.R_EDX; \ - if (M.x86.intr & INTR_SYNCH) \ - continue; \ - name##_asm(&flags,&r_asm_quot,&r_asm_rem,d,0,s); \ - if (r_quot != r_asm_quot || r_rem != r_asm_rem || M.x86.R_EFLG != flags) \ - failed = true; \ - if (failed || trace) { \ - if (failed) \ - printk("fail\n"); \ - printk("0x%08X:0x%08X = %-15s(0x%08X:0x%08X,0x%08X), flags = %s -> %s\n", \ - r_quot, r_rem, #name, 0, d, s, print_flags(buf1,inflags), print_flags(buf2,M.x86.R_EFLG)); \ - printk("0x%08X:0x%08X = %-15s(0x%08X:0x%08X,0x%08X), flags = %s -> %s\n", \ - r_asm_quot, r_asm_rem, #name"_asm", 0, d, s, print_flags(buf1,inflags), print_flags(buf2,flags)); \ - } \ - M.x86.R_EFLG = inflags = flags = def_flags | (ALL_FLAGS & ~F_OF); \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (failed) \ - break; \ - } \ - if (!failed) \ - printk("passed\n"); \ -} - -void -printk(const char *fmt, ...) -{ - va_list argptr; - - va_start(argptr, fmt); - vfprintf(stdout, fmt, argptr); - fflush(stdout); - va_end(argptr); -} - -char * -print_flags(char *buf, ulong flags) -{ - char *separator = ""; - - buf[0] = 0; - if (flags & F_CF) { - strcat(buf, separator); - strcat(buf, "CF"); - separator = ","; - } - if (flags & F_PF) { - strcat(buf, separator); - strcat(buf, "PF"); - separator = ","; - } - if (flags & F_AF) { - strcat(buf, separator); - strcat(buf, "AF"); - separator = ","; - } - if (flags & F_ZF) { - strcat(buf, separator); - strcat(buf, "ZF"); - separator = ","; - } - if (flags & F_SF) { - strcat(buf, separator); - strcat(buf, "SF"); - separator = ","; - } - if (flags & F_OF) { - strcat(buf, separator); - strcat(buf, "OF"); - separator = ","; - } - if (separator[0] == 0) - strcpy(buf, "None"); - return buf; -} - -int -main(int argc) -{ - ulong def_flags; - int trace = false; - - if (argc > 1) - trace = true; - memset(&M, 0, sizeof(M)); - def_flags = get_flags_asm() & ~ALL_FLAGS; - - VAL_WORD_UNARY(aaa_word); - VAL_WORD_UNARY(aas_word); - - VAL_WORD_UNARY(aad_word); - VAL_WORD_UNARY(aam_word); - - VAL_BYTE_BYTE_BINARY(adc_byte); - VAL_WORD_WORD_BINARY(adc_word); - VAL_LONG_LONG_BINARY(adc_long); - - VAL_BYTE_BYTE_BINARY(add_byte); - VAL_WORD_WORD_BINARY(add_word); - VAL_LONG_LONG_BINARY(add_long); - - VAL_BYTE_BYTE_BINARY(and_byte); - VAL_WORD_WORD_BINARY(and_word); - VAL_LONG_LONG_BINARY(and_long); - - VAL_BYTE_BYTE_BINARY(cmp_byte); - VAL_WORD_WORD_BINARY(cmp_word); - VAL_LONG_LONG_BINARY(cmp_long); - - VAL_BYTE_UNARY(daa_byte); - VAL_BYTE_UNARY(das_byte); /* Fails for 0x9A (out of range anyway) */ - - VAL_BYTE_UNARY(dec_byte); - VAL_WORD_UNARY(dec_word); - VAL_LONG_UNARY(dec_long); - - VAL_BYTE_UNARY(inc_byte); - VAL_WORD_UNARY(inc_word); - VAL_LONG_UNARY(inc_long); - - VAL_BYTE_BYTE_BINARY(or_byte); - VAL_WORD_WORD_BINARY(or_word); - VAL_LONG_LONG_BINARY(or_long); - - VAL_BYTE_UNARY(neg_byte); - VAL_WORD_UNARY(neg_word); - VAL_LONG_UNARY(neg_long); - - VAL_BYTE_UNARY(not_byte); - VAL_WORD_UNARY(not_word); - VAL_LONG_UNARY(not_long); - - VAL_BYTE_ROTATE(rcl_byte); - VAL_WORD_ROTATE(rcl_word); - VAL_LONG_ROTATE(rcl_long); - - VAL_BYTE_ROTATE(rcr_byte); - VAL_WORD_ROTATE(rcr_word); - VAL_LONG_ROTATE(rcr_long); - - VAL_BYTE_ROTATE(rol_byte); - VAL_WORD_ROTATE(rol_word); - VAL_LONG_ROTATE(rol_long); - - VAL_BYTE_ROTATE(ror_byte); - VAL_WORD_ROTATE(ror_word); - VAL_LONG_ROTATE(ror_long); - - VAL_BYTE_ROTATE(shl_byte); - VAL_WORD_ROTATE(shl_word); - VAL_LONG_ROTATE(shl_long); - - VAL_BYTE_ROTATE(shr_byte); - VAL_WORD_ROTATE(shr_word); - VAL_LONG_ROTATE(shr_long); - - VAL_BYTE_ROTATE(sar_byte); - VAL_WORD_ROTATE(sar_word); - VAL_LONG_ROTATE(sar_long); - - VAL_WORD_ROTATE_DBL(shld_word); - VAL_LONG_ROTATE_DBL(shld_long); - - VAL_WORD_ROTATE_DBL(shrd_word); - VAL_LONG_ROTATE_DBL(shrd_long); - - VAL_BYTE_BYTE_BINARY(sbb_byte); - VAL_WORD_WORD_BINARY(sbb_word); - VAL_LONG_LONG_BINARY(sbb_long); - - VAL_BYTE_BYTE_BINARY(sub_byte); - VAL_WORD_WORD_BINARY(sub_word); - VAL_LONG_LONG_BINARY(sub_long); - - VAL_BYTE_BYTE_BINARY(xor_byte); - VAL_WORD_WORD_BINARY(xor_word); - VAL_LONG_LONG_BINARY(xor_long); - - VAL_VOID_BYTE_BINARY(test_byte); - VAL_VOID_WORD_BINARY(test_word); - VAL_VOID_LONG_BINARY(test_long); - - VAL_BYTE_MUL(imul_byte); - VAL_WORD_MUL(imul_word); - VAL_LONG_MUL(imul_long); - - VAL_BYTE_MUL(mul_byte); - VAL_WORD_MUL(mul_word); - VAL_LONG_MUL(mul_long); - - VAL_BYTE_DIV(idiv_byte); - VAL_WORD_DIV(idiv_word); - VAL_LONG_DIV(idiv_long); - - VAL_BYTE_DIV(div_byte); - VAL_WORD_DIV(div_word); - VAL_LONG_DIV(div_long); - - return 0; -} diff --git a/hw/xfree86/x86emu/x86emu.h b/hw/xfree86/x86emu/x86emu.h deleted file mode 100644 index 501dd913c..000000000 --- a/hw/xfree86/x86emu/x86emu.h +++ /dev/null @@ -1,197 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for public specific functions. -* Any application linking against us should only -* include this header -* -****************************************************************************/ - -#ifndef __X86EMU_X86EMU_H -#define __X86EMU_X86EMU_H - -#ifdef SCITECH -#include "scitech.h" -#define X86API _ASMAPI -#define X86APIP _ASMAPIP -typedef int X86EMU_pioAddr; -#else -#include "x86emu/types.h" -#define X86API -#define X86APIP * -#endif -#include "x86emu/regs.h" - -/*---------------------- Macros and type definitions ----------------------*/ - -#ifdef PACK -#pragma PACK /* Don't pack structs with function pointers! */ -#endif - -/**************************************************************************** -REMARKS: -Data structure containing ponters to programmed I/O functions used by the -emulator. This is used so that the user program can hook all programmed -I/O for the emulator to handled as necessary by the user program. By -default the emulator contains simple functions that do not do access the -hardware in any way. To allow the emualtor access the hardware, you will -need to override the programmed I/O functions using the X86EMU_setupPioFuncs -function. - -HEADER: -x86emu.h - -MEMBERS: -inb - Function to read a byte from an I/O port -inw - Function to read a word from an I/O port -inl - Function to read a dword from an I/O port -outb - Function to write a byte to an I/O port -outw - Function to write a word to an I/O port -outl - Function to write a dword to an I/O port -****************************************************************************/ -typedef struct { - u8(X86APIP inb) (X86EMU_pioAddr addr); - u16(X86APIP inw) (X86EMU_pioAddr addr); - u32(X86APIP inl) (X86EMU_pioAddr addr); - void (X86APIP outb) (X86EMU_pioAddr addr, u8 val); - void (X86APIP outw) (X86EMU_pioAddr addr, u16 val); - void (X86APIP outl) (X86EMU_pioAddr addr, u32 val); -} X86EMU_pioFuncs; - -/**************************************************************************** -REMARKS: -Data structure containing ponters to memory access functions used by the -emulator. This is used so that the user program can hook all memory -access functions as necessary for the emulator. By default the emulator -contains simple functions that only access the internal memory of the -emulator. If you need specialised functions to handle access to different -types of memory (ie: hardware framebuffer accesses and BIOS memory access -etc), you will need to override this using the X86EMU_setupMemFuncs -function. - -HEADER: -x86emu.h - -MEMBERS: -rdb - Function to read a byte from an address -rdw - Function to read a word from an address -rdl - Function to read a dword from an address -wrb - Function to write a byte to an address -wrw - Function to write a word to an address -wrl - Function to write a dword to an address -****************************************************************************/ -typedef struct { - u8(X86APIP rdb) (u32 addr); - u16(X86APIP rdw) (u32 addr); - u32(X86APIP rdl) (u32 addr); - void (X86APIP wrb) (u32 addr, u8 val); - void (X86APIP wrw) (u32 addr, u16 val); - void (X86APIP wrl) (u32 addr, u32 val); -} X86EMU_memFuncs; - -/**************************************************************************** - Here are the default memory read and write - function in case they are needed as fallbacks. -***************************************************************************/ -extern u8 X86API rdb(u32 addr); -extern u16 X86API rdw(u32 addr); -extern u32 X86API rdl(u32 addr); -extern void X86API wrb(u32 addr, u8 val); -extern void X86API wrw(u32 addr, u16 val); -extern void X86API wrl(u32 addr, u32 val); - -#ifdef END_PACK -#pragma END_PACK -#endif - -/*--------------------- type definitions -----------------------------------*/ - -typedef void (X86APIP X86EMU_intrFuncs) (int num); -extern X86EMU_intrFuncs _X86EMU_intrTab[256]; - -/*-------------------------- Function Prototypes --------------------------*/ - -#ifdef __cplusplus -extern "C" { /* Use "C" linkage when in C++ mode */ -#endif - - void X86EMU_setupMemFuncs(X86EMU_memFuncs * funcs); - void X86EMU_setupPioFuncs(X86EMU_pioFuncs * funcs); - void X86EMU_setupIntrFuncs(X86EMU_intrFuncs funcs[]); - void X86EMU_prepareForInt(int num); - -/* decode.c */ - - void X86EMU_exec(void); - void X86EMU_halt_sys(void); - -#ifdef DEBUG -#define HALT_SYS() \ - printk("halt_sys: file %s, line %d\n", __FILE__, __LINE__), \ - X86EMU_halt_sys() -#else -#define HALT_SYS() X86EMU_halt_sys() -#endif - -/* Debug options */ - -#define DEBUG_DECODE_F 0x000001 /* print decoded instruction */ -#define DEBUG_TRACE_F 0x000002 /* dump regs before/after execution */ -#define DEBUG_STEP_F 0x000004 -#define DEBUG_DISASSEMBLE_F 0x000008 -#define DEBUG_BREAK_F 0x000010 -#define DEBUG_SVC_F 0x000020 -#define DEBUG_SAVE_IP_CS_F 0x000040 -#define DEBUG_FS_F 0x000080 -#define DEBUG_PROC_F 0x000100 -#define DEBUG_SYSINT_F 0x000200 /* bios system interrupts. */ -#define DEBUG_TRACECALL_F 0x000400 -#define DEBUG_INSTRUMENT_F 0x000800 -#define DEBUG_MEM_TRACE_F 0x001000 -#define DEBUG_IO_TRACE_F 0x002000 -#define DEBUG_TRACECALL_REGS_F 0x004000 -#define DEBUG_DECODE_NOPRINT_F 0x008000 -#define DEBUG_EXIT 0x010000 -#define DEBUG_SYS_F (DEBUG_SVC_F|DEBUG_FS_F|DEBUG_PROC_F) - - void X86EMU_trace_regs(void); - void X86EMU_trace_xregs(void); - void X86EMU_dump_memory(u16 seg, u16 off, u32 amt); - int X86EMU_trace_on(void); - int X86EMU_trace_off(void); - -#ifdef __cplusplus -} /* End of "C" linkage for C++ */ -#endif -#endif /* __X86EMU_X86EMU_H */ diff --git a/hw/xfree86/x86emu/x86emu/debug.h b/hw/xfree86/x86emu/x86emu/debug.h deleted file mode 100644 index 8660ebcb6..000000000 --- a/hw/xfree86/x86emu/x86emu/debug.h +++ /dev/null @@ -1,208 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for debug definitions. -* -****************************************************************************/ - -#ifndef __X86EMU_DEBUG_H -#define __X86EMU_DEBUG_H - -/*---------------------- Macros and type definitions ----------------------*/ - -/* checks to be enabled for "runtime" */ - -#define CHECK_IP_FETCH_F 0x1 -#define CHECK_SP_ACCESS_F 0x2 -#define CHECK_MEM_ACCESS_F 0x4 /*using regular linear pointer */ -#define CHECK_DATA_ACCESS_F 0x8 /*using segment:offset */ - -#ifdef DEBUG -#define CHECK_IP_FETCH() (M.x86.check & CHECK_IP_FETCH_F) -#define CHECK_SP_ACCESS() (M.x86.check & CHECK_SP_ACCESS_F) -#define CHECK_MEM_ACCESS() (M.x86.check & CHECK_MEM_ACCESS_F) -#define CHECK_DATA_ACCESS() (M.x86.check & CHECK_DATA_ACCESS_F) -#else -#define CHECK_IP_FETCH() -#define CHECK_SP_ACCESS() -#define CHECK_MEM_ACCESS() -#define CHECK_DATA_ACCESS() -#endif - -#ifdef DEBUG -#define DEBUG_INSTRUMENT() (M.x86.debug & DEBUG_INSTRUMENT_F) -#define DEBUG_DECODE() (M.x86.debug & DEBUG_DECODE_F) -#define DEBUG_TRACE() (M.x86.debug & DEBUG_TRACE_F) -#define DEBUG_STEP() (M.x86.debug & DEBUG_STEP_F) -#define DEBUG_DISASSEMBLE() (M.x86.debug & DEBUG_DISASSEMBLE_F) -#define DEBUG_BREAK() (M.x86.debug & DEBUG_BREAK_F) -#define DEBUG_SVC() (M.x86.debug & DEBUG_SVC_F) -#define DEBUG_SAVE_IP_CS() (M.x86.debug & DEBUG_SAVE_IP_CS_F) - -#define DEBUG_FS() (M.x86.debug & DEBUG_FS_F) -#define DEBUG_PROC() (M.x86.debug & DEBUG_PROC_F) -#define DEBUG_SYSINT() (M.x86.debug & DEBUG_SYSINT_F) -#define DEBUG_TRACECALL() (M.x86.debug & DEBUG_TRACECALL_F) -#define DEBUG_TRACECALLREGS() (M.x86.debug & DEBUG_TRACECALL_REGS_F) -#define DEBUG_SYS() (M.x86.debug & DEBUG_SYS_F) -#define DEBUG_MEM_TRACE() (M.x86.debug & DEBUG_MEM_TRACE_F) -#define DEBUG_IO_TRACE() (M.x86.debug & DEBUG_IO_TRACE_F) -#define DEBUG_DECODE_NOPRINT() (M.x86.debug & DEBUG_DECODE_NOPRINT_F) -#else -#define DEBUG_INSTRUMENT() 0 -#define DEBUG_DECODE() 0 -#define DEBUG_TRACE() 0 -#define DEBUG_STEP() 0 -#define DEBUG_DISASSEMBLE() 0 -#define DEBUG_BREAK() 0 -#define DEBUG_SVC() 0 -#define DEBUG_SAVE_IP_CS() 0 -#define DEBUG_FS() 0 -#define DEBUG_PROC() 0 -#define DEBUG_SYSINT() 0 -#define DEBUG_TRACECALL() 0 -#define DEBUG_TRACECALLREGS() 0 -#define DEBUG_SYS() 0 -#define DEBUG_MEM_TRACE() 0 -#define DEBUG_IO_TRACE() 0 -#define DEBUG_DECODE_NOPRINT() 0 -#endif - -#ifdef DEBUG - -#define DECODE_PRINTF(x) if (DEBUG_DECODE()) \ - x86emu_decode_printf("%s",x) -#define DECODE_PRINTF2(x,y) if (DEBUG_DECODE()) \ - x86emu_decode_printf(x,y) - -/* - * The following allows us to look at the bytes of an instruction. The - * first INCR_INSTRN_LEN, is called every time bytes are consumed in - * the decoding process. The SAVE_IP_CS is called initially when the - * major opcode of the instruction is accessed. - */ -#define INC_DECODED_INST_LEN(x) \ - if (DEBUG_DECODE()) \ - x86emu_inc_decoded_inst_len(x) - -#define SAVE_IP_CS(x,y) \ - if (DEBUG_DECODE() | DEBUG_TRACECALL() | DEBUG_BREAK() \ - | DEBUG_IO_TRACE() | DEBUG_SAVE_IP_CS()) { \ - M.x86.saved_cs = x; \ - M.x86.saved_ip = y; \ - } -#else -#define INC_DECODED_INST_LEN(x) -#define DECODE_PRINTF(x) -#define DECODE_PRINTF2(x,y) -#define SAVE_IP_CS(x,y) -#endif - -#ifdef DEBUG -#define TRACE_REGS() \ - if (DEBUG_DISASSEMBLE()) { \ - x86emu_just_disassemble(); \ - goto EndOfTheInstructionProcedure; \ - } \ - if (DEBUG_TRACE() || DEBUG_DECODE()) X86EMU_trace_regs() -#else -#define TRACE_REGS() -#endif - -#ifdef DEBUG -#define SINGLE_STEP() if (DEBUG_STEP()) x86emu_single_step() -#else -#define SINGLE_STEP() -#endif - -#define TRACE_AND_STEP() \ - TRACE_REGS(); \ - SINGLE_STEP() - -#ifdef DEBUG -#define START_OF_INSTR() -#define END_OF_INSTR() EndOfTheInstructionProcedure: x86emu_end_instr(); -#define END_OF_INSTR_NO_TRACE() x86emu_end_instr(); -#else -#define START_OF_INSTR() -#define END_OF_INSTR() -#define END_OF_INSTR_NO_TRACE() -#endif - -#ifdef DEBUG -#define CALL_TRACE(u,v,w,x,s) \ - if (DEBUG_TRACECALLREGS()) \ - x86emu_dump_regs(); \ - if (DEBUG_TRACECALL()) \ - printk("%04x:%04x: CALL %s%04x:%04x\n", u , v, s, w, x); -#define RETURN_TRACE(n,u,v) \ - if (DEBUG_TRACECALLREGS()) \ - x86emu_dump_regs(); \ - if (DEBUG_TRACECALL()) \ - printk("%04x:%04x: %s\n",u,v,n); -#else -#define CALL_TRACE(u,v,w,x,s) -#define RETURN_TRACE(n,u,v) -#endif - -#ifdef DEBUG -#define DB(x) x -#else -#define DB(x) -#endif - -/*-------------------------- Function Prototypes --------------------------*/ - -#ifdef __cplusplus -extern "C" { /* Use "C" linkage when in C++ mode */ -#endif - - extern void x86emu_inc_decoded_inst_len(int x); - extern void x86emu_decode_printf(const char *x, ...) _X_ATTRIBUTE_PRINTF(1,2); - extern void x86emu_just_disassemble(void); - extern void x86emu_single_step(void); - extern void x86emu_end_instr(void); - extern void x86emu_dump_regs(void); - extern void x86emu_dump_xregs(void); - extern void x86emu_print_int_vect(u16 iv); - extern void x86emu_instrument_instruction(void); - extern void x86emu_check_ip_access(void); - extern void x86emu_check_sp_access(void); - extern void x86emu_check_mem_access(u32 p); - extern void x86emu_check_data_access(uint s, uint o); - -#ifdef __cplusplus -} /* End of "C" linkage for C++ */ -#endif -#endif /* __X86EMU_DEBUG_H */ diff --git a/hw/xfree86/x86emu/x86emu/decode.h b/hw/xfree86/x86emu/x86emu/decode.h deleted file mode 100644 index 49a1f7b54..000000000 --- a/hw/xfree86/x86emu/x86emu/decode.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for instruction decoding logic. -* -****************************************************************************/ - -#ifndef __X86EMU_DECODE_H -#define __X86EMU_DECODE_H - -/*---------------------- Macros and type definitions ----------------------*/ - -/* Instruction Decoding Stuff */ - -#define FETCH_DECODE_MODRM(mod,rh,rl) fetch_decode_modrm(&mod,&rh,&rl) -#define DECODE_RM_BYTE_REGISTER(r) decode_rm_byte_register(r) -#define DECODE_RM_WORD_REGISTER(r) decode_rm_word_register(r) -#define DECODE_RM_LONG_REGISTER(r) decode_rm_long_register(r) -#define DECODE_CLEAR_SEGOVR() M.x86.mode &= ~SYSMODE_CLRMASK - -/*-------------------------- Function Prototypes --------------------------*/ - -#ifdef __cplusplus -extern "C" { /* Use "C" linkage when in C++ mode */ -#endif - - void x86emu_intr_raise(u8 type); - void fetch_decode_modrm(int *mod, int *regh, int *regl); - u8 fetch_byte_imm(void); - u16 fetch_word_imm(void); - u32 fetch_long_imm(void); - u8 fetch_data_byte(uint offset); - u8 fetch_data_byte_abs(uint segment, uint offset); - u16 fetch_data_word(uint offset); - u16 fetch_data_word_abs(uint segment, uint offset); - u32 fetch_data_long(uint offset); - u32 fetch_data_long_abs(uint segment, uint offset); - void store_data_byte(uint offset, u8 val); - void store_data_byte_abs(uint segment, uint offset, u8 val); - void store_data_word(uint offset, u16 val); - void store_data_word_abs(uint segment, uint offset, u16 val); - void store_data_long(uint offset, u32 val); - void store_data_long_abs(uint segment, uint offset, u32 val); - u8 *decode_rm_byte_register(int reg); - u16 *decode_rm_word_register(int reg); - u32 *decode_rm_long_register(int reg); - u16 *decode_rm_seg_register(int reg); - u32 decode_rm00_address(int rm); - u32 decode_rm01_address(int rm); - u32 decode_rm10_address(int rm); - u32 decode_sib_address(int sib, int mod); - -#ifdef __cplusplus -} /* End of "C" linkage for C++ */ -#endif -#endif /* __X86EMU_DECODE_H */ diff --git a/hw/xfree86/x86emu/x86emu/fpu.h b/hw/xfree86/x86emu/x86emu/fpu.h deleted file mode 100644 index 1c114987f..000000000 --- a/hw/xfree86/x86emu/x86emu/fpu.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for FPU instruction decoding. -* -****************************************************************************/ - -#ifndef __X86EMU_FPU_H -#define __X86EMU_FPU_H - -#ifdef __cplusplus -extern "C" { /* Use "C" linkage when in C++ mode */ -#endif - -/* these have to be defined, whether 8087 support compiled in or not. */ - - extern void x86emuOp_esc_coprocess_d8(u8 op1); - extern void x86emuOp_esc_coprocess_d9(u8 op1); - extern void x86emuOp_esc_coprocess_da(u8 op1); - extern void x86emuOp_esc_coprocess_db(u8 op1); - extern void x86emuOp_esc_coprocess_dc(u8 op1); - extern void x86emuOp_esc_coprocess_dd(u8 op1); - extern void x86emuOp_esc_coprocess_de(u8 op1); - extern void x86emuOp_esc_coprocess_df(u8 op1); - -#ifdef __cplusplus -} /* End of "C" linkage for C++ */ -#endif -#endif /* __X86EMU_FPU_H */ diff --git a/hw/xfree86/x86emu/x86emu/fpu_regs.h b/hw/xfree86/x86emu/x86emu/fpu_regs.h deleted file mode 100644 index 5a780e69c..000000000 --- a/hw/xfree86/x86emu/x86emu/fpu_regs.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for FPU register definitions. -* -****************************************************************************/ - -#ifndef __X86EMU_FPU_REGS_H -#define __X86EMU_FPU_REGS_H - -#ifdef X86_FPU_SUPPORT - -#ifdef PACK -#pragma PACK -#endif - -/* Basic 8087 register can hold any of the following values: */ - -union x86_fpu_reg_u { - s8 tenbytes[10]; - double dval; - float fval; - s16 sval; - s32 lval; -}; - -struct x86_fpu_reg { - union x86_fpu_reg_u reg; - char tag; -}; - -/* - * Since we are not going to worry about the problems of aliasing - * registers, every time a register is modified, its result type is - * set in the tag fields for that register. If some operation - * attempts to access the type in a way inconsistent with its current - * storage format, then we flag the operation. If common, we'll - * attempt the conversion. - */ - -#define X86_FPU_VALID 0x80 -#define X86_FPU_REGTYP(r) ((r) & 0x7F) - -#define X86_FPU_WORD 0x0 -#define X86_FPU_SHORT 0x1 -#define X86_FPU_LONG 0x2 -#define X86_FPU_FLOAT 0x3 -#define X86_FPU_DOUBLE 0x4 -#define X86_FPU_LDBL 0x5 -#define X86_FPU_BSD 0x6 - -#define X86_FPU_STKTOP 0 - -struct x86_fpu_registers { - struct x86_fpu_reg x86_fpu_stack[8]; - int x86_fpu_flags; - int x86_fpu_config; /* rounding modes, etc. */ - short x86_fpu_tos, x86_fpu_bos; -}; - -#ifdef END_PACK -#pragma END_PACK -#endif - -/* - * There are two versions of the following macro. - * - * One version is for opcode D9, for which there are more than 32 - * instructions encoded in the second byte of the opcode. - * - * The other version, deals with all the other 7 i87 opcodes, for - * which there are only 32 strings needed to describe the - * instructions. - */ - -#endif /* X86_FPU_SUPPORT */ - -#ifdef DEBUG -#define DECODE_PRINTINSTR32(t,mod,rh,rl) \ - DECODE_PRINTF(t[(mod<<3)+(rh)]); -#define DECODE_PRINTINSTR256(t,mod,rh,rl) \ - DECODE_PRINTF(t[(mod<<6)+(rh<<3)+(rl)]); -#else -#define DECODE_PRINTINSTR32(t,mod,rh,rl) -#define DECODE_PRINTINSTR256(t,mod,rh,rl) -#endif - -#endif /* __X86EMU_FPU_REGS_H */ diff --git a/hw/xfree86/x86emu/x86emu/ops.h b/hw/xfree86/x86emu/x86emu/ops.h deleted file mode 100644 index 1bc07a4e1..000000000 --- a/hw/xfree86/x86emu/x86emu/ops.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for operand decoding functions. -* -****************************************************************************/ - -#ifndef __X86EMU_OPS_H -#define __X86EMU_OPS_H - -extern void (*x86emu_optab[0x100]) (u8 op1); -extern void (*x86emu_optab2[0x100]) (u8 op2); - -#endif /* __X86EMU_OPS_H */ diff --git a/hw/xfree86/x86emu/x86emu/prim_asm.h b/hw/xfree86/x86emu/x86emu/prim_asm.h deleted file mode 100644 index aca132bf1..000000000 --- a/hw/xfree86/x86emu/x86emu/prim_asm.h +++ /dev/null @@ -1,1053 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: Watcom C++ 10.6 or later -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Inline assembler versions of the primitive operand -* functions for faster performance. At the moment this is -* x86 inline assembler, but these functions could be replaced -* with native inline assembler for each supported processor -* platform. -* -****************************************************************************/ - -#ifndef __X86EMU_PRIM_ASM_H -#define __X86EMU_PRIM_ASM_H - -#ifdef __WATCOMC__ - -#ifndef VALIDATE -#define __HAVE_INLINE_ASSEMBLER__ -#endif - -u32 get_flags_asm(void); - -#pragma aux get_flags_asm = \ - "pushf" \ - "pop eax" \ - value [eax] \ - modify exact [eax]; - -u16 aaa_word_asm(u32 * flags, u16 d); - -#pragma aux aaa_word_asm = \ - "push [edi]" \ - "popf" \ - "aaa" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] \ - value [ax] \ - modify exact [ax]; - -u16 aas_word_asm(u32 * flags, u16 d); - -#pragma aux aas_word_asm = \ - "push [edi]" \ - "popf" \ - "aas" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] \ - value [ax] \ - modify exact [ax]; - -u16 aad_word_asm(u32 * flags, u16 d); - -#pragma aux aad_word_asm = \ - "push [edi]" \ - "popf" \ - "aad" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] \ - value [ax] \ - modify exact [ax]; - -u16 aam_word_asm(u32 * flags, u8 d); - -#pragma aux aam_word_asm = \ - "push [edi]" \ - "popf" \ - "aam" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] \ - value [ax] \ - modify exact [ax]; - -u8 adc_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux adc_byte_asm = \ - "push [edi]" \ - "popf" \ - "adc al,bl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [bl] \ - value [al] \ - modify exact [al bl]; - -u16 adc_word_asm(u32 * flags, u16 d, u16 s); - -#pragma aux adc_word_asm = \ - "push [edi]" \ - "popf" \ - "adc ax,bx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [bx] \ - value [ax] \ - modify exact [ax bx]; - -u32 adc_long_asm(u32 * flags, u32 d, u32 s); - -#pragma aux adc_long_asm = \ - "push [edi]" \ - "popf" \ - "adc eax,ebx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [ebx] \ - value [eax] \ - modify exact [eax ebx]; - -u8 add_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux add_byte_asm = \ - "push [edi]" \ - "popf" \ - "add al,bl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [bl] \ - value [al] \ - modify exact [al bl]; - -u16 add_word_asm(u32 * flags, u16 d, u16 s); - -#pragma aux add_word_asm = \ - "push [edi]" \ - "popf" \ - "add ax,bx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [bx] \ - value [ax] \ - modify exact [ax bx]; - -u32 add_long_asm(u32 * flags, u32 d, u32 s); - -#pragma aux add_long_asm = \ - "push [edi]" \ - "popf" \ - "add eax,ebx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [ebx] \ - value [eax] \ - modify exact [eax ebx]; - -u8 and_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux and_byte_asm = \ - "push [edi]" \ - "popf" \ - "and al,bl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [bl] \ - value [al] \ - modify exact [al bl]; - -u16 and_word_asm(u32 * flags, u16 d, u16 s); - -#pragma aux and_word_asm = \ - "push [edi]" \ - "popf" \ - "and ax,bx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [bx] \ - value [ax] \ - modify exact [ax bx]; - -u32 and_long_asm(u32 * flags, u32 d, u32 s); - -#pragma aux and_long_asm = \ - "push [edi]" \ - "popf" \ - "and eax,ebx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [ebx] \ - value [eax] \ - modify exact [eax ebx]; - -u8 cmp_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux cmp_byte_asm = \ - "push [edi]" \ - "popf" \ - "cmp al,bl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [bl] \ - value [al] \ - modify exact [al bl]; - -u16 cmp_word_asm(u32 * flags, u16 d, u16 s); - -#pragma aux cmp_word_asm = \ - "push [edi]" \ - "popf" \ - "cmp ax,bx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [bx] \ - value [ax] \ - modify exact [ax bx]; - -u32 cmp_long_asm(u32 * flags, u32 d, u32 s); - -#pragma aux cmp_long_asm = \ - "push [edi]" \ - "popf" \ - "cmp eax,ebx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [ebx] \ - value [eax] \ - modify exact [eax ebx]; - -u8 daa_byte_asm(u32 * flags, u8 d); - -#pragma aux daa_byte_asm = \ - "push [edi]" \ - "popf" \ - "daa" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] \ - value [al] \ - modify exact [al]; - -u8 das_byte_asm(u32 * flags, u8 d); - -#pragma aux das_byte_asm = \ - "push [edi]" \ - "popf" \ - "das" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] \ - value [al] \ - modify exact [al]; - -u8 dec_byte_asm(u32 * flags, u8 d); - -#pragma aux dec_byte_asm = \ - "push [edi]" \ - "popf" \ - "dec al" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] \ - value [al] \ - modify exact [al]; - -u16 dec_word_asm(u32 * flags, u16 d); - -#pragma aux dec_word_asm = \ - "push [edi]" \ - "popf" \ - "dec ax" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] \ - value [ax] \ - modify exact [ax]; - -u32 dec_long_asm(u32 * flags, u32 d); - -#pragma aux dec_long_asm = \ - "push [edi]" \ - "popf" \ - "dec eax" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] \ - value [eax] \ - modify exact [eax]; - -u8 inc_byte_asm(u32 * flags, u8 d); - -#pragma aux inc_byte_asm = \ - "push [edi]" \ - "popf" \ - "inc al" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] \ - value [al] \ - modify exact [al]; - -u16 inc_word_asm(u32 * flags, u16 d); - -#pragma aux inc_word_asm = \ - "push [edi]" \ - "popf" \ - "inc ax" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] \ - value [ax] \ - modify exact [ax]; - -u32 inc_long_asm(u32 * flags, u32 d); - -#pragma aux inc_long_asm = \ - "push [edi]" \ - "popf" \ - "inc eax" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] \ - value [eax] \ - modify exact [eax]; - -u8 or_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux or_byte_asm = \ - "push [edi]" \ - "popf" \ - "or al,bl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [bl] \ - value [al] \ - modify exact [al bl]; - -u16 or_word_asm(u32 * flags, u16 d, u16 s); - -#pragma aux or_word_asm = \ - "push [edi]" \ - "popf" \ - "or ax,bx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [bx] \ - value [ax] \ - modify exact [ax bx]; - -u32 or_long_asm(u32 * flags, u32 d, u32 s); - -#pragma aux or_long_asm = \ - "push [edi]" \ - "popf" \ - "or eax,ebx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [ebx] \ - value [eax] \ - modify exact [eax ebx]; - -u8 neg_byte_asm(u32 * flags, u8 d); - -#pragma aux neg_byte_asm = \ - "push [edi]" \ - "popf" \ - "neg al" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] \ - value [al] \ - modify exact [al]; - -u16 neg_word_asm(u32 * flags, u16 d); - -#pragma aux neg_word_asm = \ - "push [edi]" \ - "popf" \ - "neg ax" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] \ - value [ax] \ - modify exact [ax]; - -u32 neg_long_asm(u32 * flags, u32 d); - -#pragma aux neg_long_asm = \ - "push [edi]" \ - "popf" \ - "neg eax" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] \ - value [eax] \ - modify exact [eax]; - -u8 not_byte_asm(u32 * flags, u8 d); - -#pragma aux not_byte_asm = \ - "push [edi]" \ - "popf" \ - "not al" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] \ - value [al] \ - modify exact [al]; - -u16 not_word_asm(u32 * flags, u16 d); - -#pragma aux not_word_asm = \ - "push [edi]" \ - "popf" \ - "not ax" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] \ - value [ax] \ - modify exact [ax]; - -u32 not_long_asm(u32 * flags, u32 d); - -#pragma aux not_long_asm = \ - "push [edi]" \ - "popf" \ - "not eax" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] \ - value [eax] \ - modify exact [eax]; - -u8 rcl_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux rcl_byte_asm = \ - "push [edi]" \ - "popf" \ - "rcl al,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [cl] \ - value [al] \ - modify exact [al cl]; - -u16 rcl_word_asm(u32 * flags, u16 d, u8 s); - -#pragma aux rcl_word_asm = \ - "push [edi]" \ - "popf" \ - "rcl ax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [cl] \ - value [ax] \ - modify exact [ax cl]; - -u32 rcl_long_asm(u32 * flags, u32 d, u8 s); - -#pragma aux rcl_long_asm = \ - "push [edi]" \ - "popf" \ - "rcl eax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [cl] \ - value [eax] \ - modify exact [eax cl]; - -u8 rcr_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux rcr_byte_asm = \ - "push [edi]" \ - "popf" \ - "rcr al,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [cl] \ - value [al] \ - modify exact [al cl]; - -u16 rcr_word_asm(u32 * flags, u16 d, u8 s); - -#pragma aux rcr_word_asm = \ - "push [edi]" \ - "popf" \ - "rcr ax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [cl] \ - value [ax] \ - modify exact [ax cl]; - -u32 rcr_long_asm(u32 * flags, u32 d, u8 s); - -#pragma aux rcr_long_asm = \ - "push [edi]" \ - "popf" \ - "rcr eax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [cl] \ - value [eax] \ - modify exact [eax cl]; - -u8 rol_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux rol_byte_asm = \ - "push [edi]" \ - "popf" \ - "rol al,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [cl] \ - value [al] \ - modify exact [al cl]; - -u16 rol_word_asm(u32 * flags, u16 d, u8 s); - -#pragma aux rol_word_asm = \ - "push [edi]" \ - "popf" \ - "rol ax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [cl] \ - value [ax] \ - modify exact [ax cl]; - -u32 rol_long_asm(u32 * flags, u32 d, u8 s); - -#pragma aux rol_long_asm = \ - "push [edi]" \ - "popf" \ - "rol eax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [cl] \ - value [eax] \ - modify exact [eax cl]; - -u8 ror_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux ror_byte_asm = \ - "push [edi]" \ - "popf" \ - "ror al,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [cl] \ - value [al] \ - modify exact [al cl]; - -u16 ror_word_asm(u32 * flags, u16 d, u8 s); - -#pragma aux ror_word_asm = \ - "push [edi]" \ - "popf" \ - "ror ax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [cl] \ - value [ax] \ - modify exact [ax cl]; - -u32 ror_long_asm(u32 * flags, u32 d, u8 s); - -#pragma aux ror_long_asm = \ - "push [edi]" \ - "popf" \ - "ror eax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [cl] \ - value [eax] \ - modify exact [eax cl]; - -u8 shl_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux shl_byte_asm = \ - "push [edi]" \ - "popf" \ - "shl al,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [cl] \ - value [al] \ - modify exact [al cl]; - -u16 shl_word_asm(u32 * flags, u16 d, u8 s); - -#pragma aux shl_word_asm = \ - "push [edi]" \ - "popf" \ - "shl ax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [cl] \ - value [ax] \ - modify exact [ax cl]; - -u32 shl_long_asm(u32 * flags, u32 d, u8 s); - -#pragma aux shl_long_asm = \ - "push [edi]" \ - "popf" \ - "shl eax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [cl] \ - value [eax] \ - modify exact [eax cl]; - -u8 shr_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux shr_byte_asm = \ - "push [edi]" \ - "popf" \ - "shr al,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [cl] \ - value [al] \ - modify exact [al cl]; - -u16 shr_word_asm(u32 * flags, u16 d, u8 s); - -#pragma aux shr_word_asm = \ - "push [edi]" \ - "popf" \ - "shr ax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [cl] \ - value [ax] \ - modify exact [ax cl]; - -u32 shr_long_asm(u32 * flags, u32 d, u8 s); - -#pragma aux shr_long_asm = \ - "push [edi]" \ - "popf" \ - "shr eax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [cl] \ - value [eax] \ - modify exact [eax cl]; - -u8 sar_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux sar_byte_asm = \ - "push [edi]" \ - "popf" \ - "sar al,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [cl] \ - value [al] \ - modify exact [al cl]; - -u16 sar_word_asm(u32 * flags, u16 d, u8 s); - -#pragma aux sar_word_asm = \ - "push [edi]" \ - "popf" \ - "sar ax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [cl] \ - value [ax] \ - modify exact [ax cl]; - -u32 sar_long_asm(u32 * flags, u32 d, u8 s); - -#pragma aux sar_long_asm = \ - "push [edi]" \ - "popf" \ - "sar eax,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [cl] \ - value [eax] \ - modify exact [eax cl]; - -u16 shld_word_asm(u32 * flags, u16 d, u16 fill, u8 s); - -#pragma aux shld_word_asm = \ - "push [edi]" \ - "popf" \ - "shld ax,dx,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [dx] [cl] \ - value [ax] \ - modify exact [ax dx cl]; - -u32 shld_long_asm(u32 * flags, u32 d, u32 fill, u8 s); - -#pragma aux shld_long_asm = \ - "push [edi]" \ - "popf" \ - "shld eax,edx,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [edx] [cl] \ - value [eax] \ - modify exact [eax edx cl]; - -u16 shrd_word_asm(u32 * flags, u16 d, u16 fill, u8 s); - -#pragma aux shrd_word_asm = \ - "push [edi]" \ - "popf" \ - "shrd ax,dx,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [dx] [cl] \ - value [ax] \ - modify exact [ax dx cl]; - -u32 shrd_long_asm(u32 * flags, u32 d, u32 fill, u8 s); - -#pragma aux shrd_long_asm = \ - "push [edi]" \ - "popf" \ - "shrd eax,edx,cl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [edx] [cl] \ - value [eax] \ - modify exact [eax edx cl]; - -u8 sbb_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux sbb_byte_asm = \ - "push [edi]" \ - "popf" \ - "sbb al,bl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [bl] \ - value [al] \ - modify exact [al bl]; - -u16 sbb_word_asm(u32 * flags, u16 d, u16 s); - -#pragma aux sbb_word_asm = \ - "push [edi]" \ - "popf" \ - "sbb ax,bx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [bx] \ - value [ax] \ - modify exact [ax bx]; - -u32 sbb_long_asm(u32 * flags, u32 d, u32 s); - -#pragma aux sbb_long_asm = \ - "push [edi]" \ - "popf" \ - "sbb eax,ebx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [ebx] \ - value [eax] \ - modify exact [eax ebx]; - -u8 sub_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux sub_byte_asm = \ - "push [edi]" \ - "popf" \ - "sub al,bl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [bl] \ - value [al] \ - modify exact [al bl]; - -u16 sub_word_asm(u32 * flags, u16 d, u16 s); - -#pragma aux sub_word_asm = \ - "push [edi]" \ - "popf" \ - "sub ax,bx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [bx] \ - value [ax] \ - modify exact [ax bx]; - -u32 sub_long_asm(u32 * flags, u32 d, u32 s); - -#pragma aux sub_long_asm = \ - "push [edi]" \ - "popf" \ - "sub eax,ebx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [ebx] \ - value [eax] \ - modify exact [eax ebx]; - -void test_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux test_byte_asm = \ - "push [edi]" \ - "popf" \ - "test al,bl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [bl] \ - modify exact [al bl]; - -void test_word_asm(u32 * flags, u16 d, u16 s); - -#pragma aux test_word_asm = \ - "push [edi]" \ - "popf" \ - "test ax,bx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [bx] \ - modify exact [ax bx]; - -void test_long_asm(u32 * flags, u32 d, u32 s); - -#pragma aux test_long_asm = \ - "push [edi]" \ - "popf" \ - "test eax,ebx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [ebx] \ - modify exact [eax ebx]; - -u8 xor_byte_asm(u32 * flags, u8 d, u8 s); - -#pragma aux xor_byte_asm = \ - "push [edi]" \ - "popf" \ - "xor al,bl" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [al] [bl] \ - value [al] \ - modify exact [al bl]; - -u16 xor_word_asm(u32 * flags, u16 d, u16 s); - -#pragma aux xor_word_asm = \ - "push [edi]" \ - "popf" \ - "xor ax,bx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [ax] [bx] \ - value [ax] \ - modify exact [ax bx]; - -u32 xor_long_asm(u32 * flags, u32 d, u32 s); - -#pragma aux xor_long_asm = \ - "push [edi]" \ - "popf" \ - "xor eax,ebx" \ - "pushf" \ - "pop [edi]" \ - parm [edi] [eax] [ebx] \ - value [eax] \ - modify exact [eax ebx]; - -void imul_byte_asm(u32 * flags, u16 * ax, u8 d, u8 s); - -#pragma aux imul_byte_asm = \ - "push [edi]" \ - "popf" \ - "imul bl" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],ax" \ - parm [edi] [esi] [al] [bl] \ - modify exact [esi ax bl]; - -void imul_word_asm(u32 * flags, u16 * ax, u16 * dx, u16 d, u16 s); - -#pragma aux imul_word_asm = \ - "push [edi]" \ - "popf" \ - "imul bx" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],ax" \ - "mov [ecx],dx" \ - parm [edi] [esi] [ecx] [ax] [bx]\ - modify exact [esi edi ax bx dx]; - -void imul_long_asm(u32 * flags, u32 * eax, u32 * edx, u32 d, u32 s); - -#pragma aux imul_long_asm = \ - "push [edi]" \ - "popf" \ - "imul ebx" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],eax" \ - "mov [ecx],edx" \ - parm [edi] [esi] [ecx] [eax] [ebx] \ - modify exact [esi edi eax ebx edx]; - -void mul_byte_asm(u32 * flags, u16 * ax, u8 d, u8 s); - -#pragma aux mul_byte_asm = \ - "push [edi]" \ - "popf" \ - "mul bl" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],ax" \ - parm [edi] [esi] [al] [bl] \ - modify exact [esi ax bl]; - -void mul_word_asm(u32 * flags, u16 * ax, u16 * dx, u16 d, u16 s); - -#pragma aux mul_word_asm = \ - "push [edi]" \ - "popf" \ - "mul bx" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],ax" \ - "mov [ecx],dx" \ - parm [edi] [esi] [ecx] [ax] [bx]\ - modify exact [esi edi ax bx dx]; - -void mul_long_asm(u32 * flags, u32 * eax, u32 * edx, u32 d, u32 s); - -#pragma aux mul_long_asm = \ - "push [edi]" \ - "popf" \ - "mul ebx" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],eax" \ - "mov [ecx],edx" \ - parm [edi] [esi] [ecx] [eax] [ebx] \ - modify exact [esi edi eax ebx edx]; - -void idiv_byte_asm(u32 * flags, u8 * al, u8 * ah, u16 d, u8 s); - -#pragma aux idiv_byte_asm = \ - "push [edi]" \ - "popf" \ - "idiv bl" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],al" \ - "mov [ecx],ah" \ - parm [edi] [esi] [ecx] [ax] [bl]\ - modify exact [esi edi ax bl]; - -void idiv_word_asm(u32 * flags, u16 * ax, u16 * dx, u16 dlo, u16 dhi, u16 s); - -#pragma aux idiv_word_asm = \ - "push [edi]" \ - "popf" \ - "idiv bx" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],ax" \ - "mov [ecx],dx" \ - parm [edi] [esi] [ecx] [ax] [dx] [bx]\ - modify exact [esi edi ax dx bx]; - -void idiv_long_asm(u32 * flags, u32 * eax, u32 * edx, u32 dlo, u32 dhi, u32 s); - -#pragma aux idiv_long_asm = \ - "push [edi]" \ - "popf" \ - "idiv ebx" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],eax" \ - "mov [ecx],edx" \ - parm [edi] [esi] [ecx] [eax] [edx] [ebx]\ - modify exact [esi edi eax edx ebx]; - -void div_byte_asm(u32 * flags, u8 * al, u8 * ah, u16 d, u8 s); - -#pragma aux div_byte_asm = \ - "push [edi]" \ - "popf" \ - "div bl" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],al" \ - "mov [ecx],ah" \ - parm [edi] [esi] [ecx] [ax] [bl]\ - modify exact [esi edi ax bl]; - -void div_word_asm(u32 * flags, u16 * ax, u16 * dx, u16 dlo, u16 dhi, u16 s); - -#pragma aux div_word_asm = \ - "push [edi]" \ - "popf" \ - "div bx" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],ax" \ - "mov [ecx],dx" \ - parm [edi] [esi] [ecx] [ax] [dx] [bx]\ - modify exact [esi edi ax dx bx]; - -void div_long_asm(u32 * flags, u32 * eax, u32 * edx, u32 dlo, u32 dhi, u32 s); - -#pragma aux div_long_asm = \ - "push [edi]" \ - "popf" \ - "div ebx" \ - "pushf" \ - "pop [edi]" \ - "mov [esi],eax" \ - "mov [ecx],edx" \ - parm [edi] [esi] [ecx] [eax] [edx] [ebx]\ - modify exact [esi edi eax edx ebx]; - -#endif - -#endif /* __X86EMU_PRIM_ASM_H */ diff --git a/hw/xfree86/x86emu/x86emu/prim_ops.h b/hw/xfree86/x86emu/x86emu/prim_ops.h deleted file mode 100644 index 0f0e78d71..000000000 --- a/hw/xfree86/x86emu/x86emu/prim_ops.h +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for primitive operation functions. -* -****************************************************************************/ - -#ifndef __X86EMU_PRIM_OPS_H -#define __X86EMU_PRIM_OPS_H - -#ifdef __cplusplus -extern "C" { /* Use "C" linkage when in C++ mode */ -#endif - - u16 aaa_word(u16 d); - u16 aas_word(u16 d); - u16 aad_word(u16 d); - u16 aam_word(u8 d); - u8 adc_byte(u8 d, u8 s); - u16 adc_word(u16 d, u16 s); - u32 adc_long(u32 d, u32 s); - u8 add_byte(u8 d, u8 s); - u16 add_word(u16 d, u16 s); - u32 add_long(u32 d, u32 s); - u8 and_byte(u8 d, u8 s); - u16 and_word(u16 d, u16 s); - u32 and_long(u32 d, u32 s); - u8 cmp_byte(u8 d, u8 s); - u16 cmp_word(u16 d, u16 s); - u32 cmp_long(u32 d, u32 s); - u8 daa_byte(u8 d); - u8 das_byte(u8 d); - u8 dec_byte(u8 d); - u16 dec_word(u16 d); - u32 dec_long(u32 d); - u8 inc_byte(u8 d); - u16 inc_word(u16 d); - u32 inc_long(u32 d); - u8 or_byte(u8 d, u8 s); - u16 or_word(u16 d, u16 s); - u32 or_long(u32 d, u32 s); - u8 neg_byte(u8 s); - u16 neg_word(u16 s); - u32 neg_long(u32 s); - u8 not_byte(u8 s); - u16 not_word(u16 s); - u32 not_long(u32 s); - u8 rcl_byte(u8 d, u8 s); - u16 rcl_word(u16 d, u8 s); - u32 rcl_long(u32 d, u8 s); - u8 rcr_byte(u8 d, u8 s); - u16 rcr_word(u16 d, u8 s); - u32 rcr_long(u32 d, u8 s); - u8 rol_byte(u8 d, u8 s); - u16 rol_word(u16 d, u8 s); - u32 rol_long(u32 d, u8 s); - u8 ror_byte(u8 d, u8 s); - u16 ror_word(u16 d, u8 s); - u32 ror_long(u32 d, u8 s); - u8 shl_byte(u8 d, u8 s); - u16 shl_word(u16 d, u8 s); - u32 shl_long(u32 d, u8 s); - u8 shr_byte(u8 d, u8 s); - u16 shr_word(u16 d, u8 s); - u32 shr_long(u32 d, u8 s); - u8 sar_byte(u8 d, u8 s); - u16 sar_word(u16 d, u8 s); - u32 sar_long(u32 d, u8 s); - u16 shld_word(u16 d, u16 fill, u8 s); - u32 shld_long(u32 d, u32 fill, u8 s); - u16 shrd_word(u16 d, u16 fill, u8 s); - u32 shrd_long(u32 d, u32 fill, u8 s); - u8 sbb_byte(u8 d, u8 s); - u16 sbb_word(u16 d, u16 s); - u32 sbb_long(u32 d, u32 s); - u8 sub_byte(u8 d, u8 s); - u16 sub_word(u16 d, u16 s); - u32 sub_long(u32 d, u32 s); - void test_byte(u8 d, u8 s); - void test_word(u16 d, u16 s); - void test_long(u32 d, u32 s); - u8 xor_byte(u8 d, u8 s); - u16 xor_word(u16 d, u16 s); - u32 xor_long(u32 d, u32 s); - void imul_byte(u8 s); - void imul_word(u16 s); - void imul_long(u32 s); - void imul_long_direct(u32 * res_lo, u32 * res_hi, u32 d, u32 s); - void mul_byte(u8 s); - void mul_word(u16 s); - void mul_long(u32 s); - void idiv_byte(u8 s); - void idiv_word(u16 s); - void idiv_long(u32 s); - void div_byte(u8 s); - void div_word(u16 s); - void div_long(u32 s); - void ins(int size); - void outs(int size); - u16 mem_access_word(int addr); - void push_word(u16 w); - void push_long(u32 w); - u16 pop_word(void); - u32 pop_long(void); - void cpuid(void); - -#ifdef __cplusplus -} /* End of "C" linkage for C++ */ -#endif -#endif /* __X86EMU_PRIM_OPS_H */ diff --git a/hw/xfree86/x86emu/x86emu/prim_x86_gcc.h b/hw/xfree86/x86emu/x86emu/prim_x86_gcc.h deleted file mode 100644 index 646ec9def..000000000 --- a/hw/xfree86/x86emu/x86emu/prim_x86_gcc.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -* -* Inline helpers for x86emu -* -* Copyright (C) 2008 Bart Trojanowski, Symbio Technologies, LLC -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: GNU C -* Environment: GCC on i386 or x86-64 -* Developer: Bart Trojanowski -* -* Description: This file defines a few x86 macros that can be used by the -* emulator to execute native instructions. -* -* For PIC vs non-PIC code refer to: -* http://sam.zoy.org/blog/2007-04-13-shlib-with-non-pic-code-have-inline-assembly-and-pic-mix-well -* -****************************************************************************/ -#ifndef __X86EMU_PRIM_X86_GCC_H -#define __X86EMU_PRIM_X86_GCC_H - -#include "x86emu/types.h" - -#if !defined(__GNUC__) || !(defined (__i386__) || defined(__i386) || defined(__AMD64__) || defined(__amd64__)) -#error This file is intended to be used by gcc on i386 or x86-64 system -#endif - -#if defined(__PIC__) && defined(__i386__) - -#define X86EMU_HAS_HW_CPUID 1 -static inline void -hw_cpuid(u32 * a, u32 * b, u32 * c, u32 * d) -{ - __asm__ __volatile__("pushl %%ebx \n\t" - "cpuid \n\t" - "movl %%ebx, %1 \n\t" - "popl %%ebx \n\t":"=a"(*a), "=r"(*b), - "=c"(*c), "=d"(*d) - :"a"(*a), "c"(*c) - :"cc"); -} - -#else /* ! (__PIC__ && __i386__) */ - -#define x86EMU_HAS_HW_CPUID 1 -static inline void -hw_cpuid(u32 * a, u32 * b, u32 * c, u32 * d) -{ - __asm__ __volatile__("cpuid":"=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d) - :"a"(*a), "c"(*c) - :"cc"); -} - -#endif /* __PIC__ && __i386__ */ - -#endif /* __X86EMU_PRIM_X86_GCC_H */ diff --git a/hw/xfree86/x86emu/x86emu/regs.h b/hw/xfree86/x86emu/x86emu/regs.h deleted file mode 100644 index edf9be324..000000000 --- a/hw/xfree86/x86emu/x86emu/regs.h +++ /dev/null @@ -1,340 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for x86 register definitions. -* -****************************************************************************/ - -#ifndef __X86EMU_REGS_H -#define __X86EMU_REGS_H - -#include - -/*---------------------- Macros and type definitions ----------------------*/ - -#ifdef PACK -#pragma PACK -#endif - -/* - * General EAX, EBX, ECX, EDX type registers. Note that for - * portability, and speed, the issue of byte swapping is not addressed - * in the registers. All registers are stored in the default format - * available on the host machine. The only critical issue is that the - * registers should line up EXACTLY in the same manner as they do in - * the 386. That is: - * - * EAX & 0xff === AL - * EAX & 0xffff == AX - * - * etc. The result is that a lot of the calculations can then be - * done using the native instruction set fully. - */ - -#ifdef __BIG_ENDIAN__ - -typedef struct { - u32 e_reg; -} I32_reg_t; - -typedef struct { - u16 filler0, x_reg; -} I16_reg_t; - -typedef struct { - u8 filler0, filler1, h_reg, l_reg; -} I8_reg_t; - -#else /* !__BIG_ENDIAN__ */ - -typedef struct { - u32 e_reg; -} I32_reg_t; - -typedef struct { - u16 x_reg; -} I16_reg_t; - -typedef struct { - u8 l_reg, h_reg; -} I8_reg_t; - -#endif /* BIG_ENDIAN */ - -typedef union { - I32_reg_t I32_reg; - I16_reg_t I16_reg; - I8_reg_t I8_reg; -} i386_general_register; - -struct i386_general_regs { - i386_general_register A, B, C, D; -}; - -typedef struct i386_general_regs Gen_reg_t; - -struct i386_special_regs { - i386_general_register SP, BP, SI, DI, IP; - u32 FLAGS; -}; - -/* - * Segment registers here represent the 16 bit quantities - * CS, DS, ES, SS. - */ - -#if defined(__sun) && defined(CS) /* avoid conflicts with Solaris sys/regset.h */ -# undef CS -# undef DS -# undef SS -# undef ES -# undef FS -# undef GS -#endif - -struct i386_segment_regs { - u16 CS, DS, SS, ES, FS, GS; -}; - -/* 8 bit registers */ -#define R_AH gen.A.I8_reg.h_reg -#define R_AL gen.A.I8_reg.l_reg -#define R_BH gen.B.I8_reg.h_reg -#define R_BL gen.B.I8_reg.l_reg -#define R_CH gen.C.I8_reg.h_reg -#define R_CL gen.C.I8_reg.l_reg -#define R_DH gen.D.I8_reg.h_reg -#define R_DL gen.D.I8_reg.l_reg - -/* 16 bit registers */ -#define R_AX gen.A.I16_reg.x_reg -#define R_BX gen.B.I16_reg.x_reg -#define R_CX gen.C.I16_reg.x_reg -#define R_DX gen.D.I16_reg.x_reg - -/* 32 bit extended registers */ -#define R_EAX gen.A.I32_reg.e_reg -#define R_EBX gen.B.I32_reg.e_reg -#define R_ECX gen.C.I32_reg.e_reg -#define R_EDX gen.D.I32_reg.e_reg - -/* special registers */ -#define R_SP spc.SP.I16_reg.x_reg -#define R_BP spc.BP.I16_reg.x_reg -#define R_SI spc.SI.I16_reg.x_reg -#define R_DI spc.DI.I16_reg.x_reg -#define R_IP spc.IP.I16_reg.x_reg -#define R_FLG spc.FLAGS - -/* special registers */ -#define R_ESP spc.SP.I32_reg.e_reg -#define R_EBP spc.BP.I32_reg.e_reg -#define R_ESI spc.SI.I32_reg.e_reg -#define R_EDI spc.DI.I32_reg.e_reg -#define R_EIP spc.IP.I32_reg.e_reg -#define R_EFLG spc.FLAGS - -/* segment registers */ -#define R_CS seg.CS -#define R_DS seg.DS -#define R_SS seg.SS -#define R_ES seg.ES -#define R_FS seg.FS -#define R_GS seg.GS - -/* flag conditions */ -#define FB_CF 0x0001 /* CARRY flag */ -#define FB_PF 0x0004 /* PARITY flag */ -#define FB_AF 0x0010 /* AUX flag */ -#define FB_ZF 0x0040 /* ZERO flag */ -#define FB_SF 0x0080 /* SIGN flag */ -#define FB_TF 0x0100 /* TRAP flag */ -#define FB_IF 0x0200 /* INTERRUPT ENABLE flag */ -#define FB_DF 0x0400 /* DIR flag */ -#define FB_OF 0x0800 /* OVERFLOW flag */ - -/* 80286 and above always have bit#1 set */ -#define F_ALWAYS_ON (0x0002) /* flag bits always on */ - -/* - * Define a mask for only those flag bits we will ever pass back - * (via PUSHF) - */ -#define F_MSK (FB_CF|FB_PF|FB_AF|FB_ZF|FB_SF|FB_TF|FB_IF|FB_DF|FB_OF) - -/* following bits masked in to a 16bit quantity */ - -#define F_CF 0x0001 /* CARRY flag */ -#define F_PF 0x0004 /* PARITY flag */ -#define F_AF 0x0010 /* AUX flag */ -#define F_ZF 0x0040 /* ZERO flag */ -#define F_SF 0x0080 /* SIGN flag */ -#define F_TF 0x0100 /* TRAP flag */ -#define F_IF 0x0200 /* INTERRUPT ENABLE flag */ -#define F_DF 0x0400 /* DIR flag */ -#define F_OF 0x0800 /* OVERFLOW flag */ - -#define TOGGLE_FLAG(flag) (M.x86.R_FLG ^= (flag)) -#define SET_FLAG(flag) (M.x86.R_FLG |= (flag)) -#define CLEAR_FLAG(flag) (M.x86.R_FLG &= ~(flag)) -#define ACCESS_FLAG(flag) (M.x86.R_FLG & (flag)) -#define CLEARALL_FLAG(m) (M.x86.R_FLG = 0) - -#define CONDITIONAL_SET_FLAG(COND,FLAG) \ - if (COND) SET_FLAG(FLAG); else CLEAR_FLAG(FLAG) - -#define F_PF_CALC 0x010000 /* PARITY flag has been calced */ -#define F_ZF_CALC 0x020000 /* ZERO flag has been calced */ -#define F_SF_CALC 0x040000 /* SIGN flag has been calced */ - -#define F_ALL_CALC 0xff0000 /* All have been calced */ - -/* - * Emulator machine state. - * Segment usage control. - */ -#define SYSMODE_SEG_DS_SS 0x00000001 -#define SYSMODE_SEGOVR_CS 0x00000002 -#define SYSMODE_SEGOVR_DS 0x00000004 -#define SYSMODE_SEGOVR_ES 0x00000008 -#define SYSMODE_SEGOVR_FS 0x00000010 -#define SYSMODE_SEGOVR_GS 0x00000020 -#define SYSMODE_SEGOVR_SS 0x00000040 -#define SYSMODE_PREFIX_REPE 0x00000080 -#define SYSMODE_PREFIX_REPNE 0x00000100 -#define SYSMODE_PREFIX_DATA 0x00000200 -#define SYSMODE_PREFIX_ADDR 0x00000400 -#define SYSMODE_INTR_PENDING 0x10000000 -#define SYSMODE_EXTRN_INTR 0x20000000 -#define SYSMODE_HALTED 0x40000000 - -#define SYSMODE_SEGMASK (SYSMODE_SEG_DS_SS | \ - SYSMODE_SEGOVR_CS | \ - SYSMODE_SEGOVR_DS | \ - SYSMODE_SEGOVR_ES | \ - SYSMODE_SEGOVR_FS | \ - SYSMODE_SEGOVR_GS | \ - SYSMODE_SEGOVR_SS) -#define SYSMODE_CLRMASK (SYSMODE_SEG_DS_SS | \ - SYSMODE_SEGOVR_CS | \ - SYSMODE_SEGOVR_DS | \ - SYSMODE_SEGOVR_ES | \ - SYSMODE_SEGOVR_FS | \ - SYSMODE_SEGOVR_GS | \ - SYSMODE_SEGOVR_SS | \ - SYSMODE_PREFIX_DATA | \ - SYSMODE_PREFIX_ADDR) - -#define INTR_SYNCH 0x1 -#define INTR_ASYNCH 0x2 -#define INTR_HALTED 0x4 - -typedef struct { - struct i386_general_regs gen; - struct i386_special_regs spc; - struct i386_segment_regs seg; - /* - * MODE contains information on: - * REPE prefix 2 bits repe,repne - * SEGMENT overrides 5 bits normal,DS,SS,CS,ES - * Delayed flag set 3 bits (zero, signed, parity) - * reserved 6 bits - * interrupt # 8 bits instruction raised interrupt - * BIOS video segregs 4 bits - * Interrupt Pending 1 bits - * Extern interrupt 1 bits - * Halted 1 bits - */ - u32 mode; - volatile int intr; /* mask of pending interrupts */ - int debug; -#ifdef DEBUG - int check; - u16 saved_ip; - u16 saved_cs; - int enc_pos; - int enc_str_pos; - char decode_buf[32]; /* encoded byte stream */ - char decoded_buf[256]; /* disassembled strings */ -#endif - u8 intno; - u8 __pad[3]; -} X86EMU_regs; - -/**************************************************************************** -REMARKS: -Structure maintaining the emulator machine state. - -MEMBERS: -mem_base - Base real mode memory for the emulator -mem_size - Size of the real mode memory block for the emulator -private - private data pointer -x86 - X86 registers -****************************************************************************/ -typedef struct { - unsigned long mem_base; - unsigned long mem_size; - void *private; - X86EMU_regs x86; -} X86EMU_sysEnv; - -#ifdef END_PACK -#pragma END_PACK -#endif - -/*----------------------------- Global Variables --------------------------*/ - -#ifdef __cplusplus -extern "C" { /* Use "C" linkage when in C++ mode */ -#endif - -/* Global emulator machine state. - * - * We keep it global to avoid pointer dereferences in the code for speed. - */ - - extern X86EMU_sysEnv _X86EMU_env; -#define M _X86EMU_env - -/*-------------------------- Function Prototypes --------------------------*/ - -/* Function to log information at runtime */ - - void printk(const char *fmt, ...) - _X_ATTRIBUTE_PRINTF(1, 2); - -#ifdef __cplusplus -} /* End of "C" linkage for C++ */ -#endif -#endif /* __X86EMU_REGS_H */ diff --git a/hw/xfree86/x86emu/x86emu/types.h b/hw/xfree86/x86emu/x86emu/types.h deleted file mode 100644 index 0559bc089..000000000 --- a/hw/xfree86/x86emu/x86emu/types.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for x86 emulator type definitions. -* -****************************************************************************/ - -#ifndef __X86EMU_TYPES_H -#define __X86EMU_TYPES_H - -#ifndef NO_SYS_HEADERS -#include -#endif - -/* - * The following kludge is an attempt to work around typedef conflicts with - * . - */ -#define u8 x86emuu8 -#define u16 x86emuu16 -#define u32 x86emuu32 -#define u64 x86emuu64 -#define s8 x86emus8 -#define s16 x86emus16 -#define s32 x86emus32 -#define s64 x86emus64 -#define uint x86emuuint -#define sint x86emusint - -/*---------------------- Macros and type definitions ----------------------*/ - -#include -#include - -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; - -typedef int8_t s8; -typedef int16_t s16; -typedef int32_t s32; -typedef int64_t s64; - -typedef unsigned int uint; -typedef int sint; - -typedef u16 X86EMU_pioAddr; - -#endif /* __X86EMU_TYPES_H */ diff --git a/hw/xfree86/x86emu/x86emu/x86emui.h b/hw/xfree86/x86emu/x86emu/x86emui.h deleted file mode 100644 index aa2074a87..000000000 --- a/hw/xfree86/x86emu/x86emu/x86emui.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -* -* Realmode X86 Emulator Library -* -* Copyright (C) 1996-1999 SciTech Software, Inc. -* Copyright (C) David Mosberger-Tang -* Copyright (C) 1999 Egbert Eich -* -* ======================================================================== -* -* Permission to use, copy, modify, distribute, and sell this software and -* its documentation for any purpose is hereby granted without fee, -* provided that the above copyright notice appear in all copies and that -* both that copyright notice and this permission notice appear in -* supporting documentation, and that the name of the authors not be used -* in advertising or publicity pertaining to distribution of the software -* without specific, written prior permission. The authors makes no -* representations about the suitability of this software for any purpose. -* It is provided "as is" without express or implied warranty. -* -* THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, -* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO -* EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR -* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF -* USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -* PERFORMANCE OF THIS SOFTWARE. -* -* ======================================================================== -* -* Language: ANSI C -* Environment: Any -* Developer: Kendall Bennett -* -* Description: Header file for system specific functions. These functions -* are always compiled and linked in the OS dependent libraries, -* and never in a binary portable driver. -* -****************************************************************************/ - -#ifndef __X86EMU_X86EMUI_H -#define __X86EMU_X86EMUI_H - -/* If we are compiling in C++ mode, we can compile some functions as - * inline to increase performance (however the code size increases quite - * dramatically in this case). - */ - -#if defined(__cplusplus) -#define _INLINE inline -#else -#define _INLINE static -#endif - -/* Get rid of unused parameters in C++ compilation mode */ - -#ifdef __cplusplus -#define X86EMU_UNUSED(v) -#else -#define X86EMU_UNUSED(v) v -#endif - -#include "x86emu.h" -#include "x86emu/regs.h" -#include "x86emu/debug.h" -#include "x86emu/decode.h" -#include "x86emu/ops.h" -#include "x86emu/prim_ops.h" -#include "x86emu/fpu.h" -#include "x86emu/fpu_regs.h" - -#ifndef NO_SYS_HEADERS -#include -#include -#include -/* avoid conflicts with Solaris sys/regset.h */ -# if defined(__sun) && defined(CS) -# undef CS -# undef DS -# undef SS -# undef ES -# undef FS -# undef GS -# endif -#endif /* NO_SYS_HEADERS */ - -/*--------------------------- Inline Functions ----------------------------*/ - -#ifdef __cplusplus -extern "C" { /* Use "C" linkage when in C++ mode */ -#endif - - extern u8(X86APIP sys_rdb) (u32 addr); - extern u16(X86APIP sys_rdw) (u32 addr); - extern u32(X86APIP sys_rdl) (u32 addr); - extern void (X86APIP sys_wrb) (u32 addr, u8 val); - extern void (X86APIP sys_wrw) (u32 addr, u16 val); - extern void (X86APIP sys_wrl) (u32 addr, u32 val); - - extern u8(X86APIP sys_inb) (X86EMU_pioAddr addr); - extern u16(X86APIP sys_inw) (X86EMU_pioAddr addr); - extern u32(X86APIP sys_inl) (X86EMU_pioAddr addr); - extern void (X86APIP sys_outb) (X86EMU_pioAddr addr, u8 val); - extern void (X86APIP sys_outw) (X86EMU_pioAddr addr, u16 val); - extern void (X86APIP sys_outl) (X86EMU_pioAddr addr, u32 val); - -#ifdef __cplusplus -} /* End of "C" linkage for C++ */ -#endif -#endif /* __X86EMU_X86EMUI_H */ diff --git a/hw/xfree86/xkb/meson.build b/hw/xfree86/xkb/meson.build deleted file mode 100644 index 894aa5ca3..000000000 --- a/hw/xfree86/xkb/meson.build +++ /dev/null @@ -1,12 +0,0 @@ -srcs_xorg_xkb = [ - 'xkbVT.c', - 'xkbPrivate.c', - 'xkbKillSrv.c', -] - -xorg_xkb = static_library('xorg_xkb', - srcs_xorg_xkb, - include_directories: [inc, xorg_inc], - dependencies: common_dep, - c_args: xorg_c_args, -) diff --git a/hw/xfree86/xkb/xkbKillSrv.c b/hw/xfree86/xkb/xkbKillSrv.c deleted file mode 100644 index 79cf08198..000000000 --- a/hw/xfree86/xkb/xkbKillSrv.c +++ /dev/null @@ -1,54 +0,0 @@ -/************************************************************ -Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. - -Permission to use, copy, modify, and distribute this -software and its documentation for any purpose and without -fee is hereby granted, provided that the above copyright -notice appear in all copies and that both that copyright -notice and this permission notice appear in supporting -documentation, and that the name of Silicon Graphics not be -used in advertising or publicity pertaining to distribution -of the software without specific prior written permission. -Silicon Graphics makes no representation about the suitability -of this software for any purpose. It is provided "as is" -without any express or implied warranty. - -SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON -GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH -THE USE OR PERFORMANCE OF THIS SOFTWARE. - -********************************************************/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include "inputstr.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include -#include - -#include "xf86.h" - -int -XkbDDXTerminateServer(DeviceIntPtr dev, KeyCode key, XkbAction *act) -{ - if (dev != inputInfo.keyboard) - xf86ProcessActionEvent(ACTION_TERMINATE, NULL); - - return 0; -} diff --git a/hw/xfree86/xkb/xkbPrivate.c b/hw/xfree86/xkb/xkbPrivate.c deleted file mode 100644 index 009610892..000000000 --- a/hw/xfree86/xkb/xkbPrivate.c +++ /dev/null @@ -1,36 +0,0 @@ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include "windowstr.h" -#define XKBSRV_NEED_FILE_FUNCS -#include - -#include "dixgrabs.h" -#include "os.h" -#include "xf86.h" - -int -XkbDDXPrivate(DeviceIntPtr dev, KeyCode key, XkbAction *act) -{ - XkbAnyAction *xf86act = &(act->any); - char msgbuf[XkbAnyActionDataSize + 1]; - - if (xf86act->type == XkbSA_XFree86Private) { - memcpy(msgbuf, xf86act->data, XkbAnyActionDataSize); - msgbuf[XkbAnyActionDataSize] = '\0'; - if (strcasecmp(msgbuf, "-vmode") == 0) - xf86ProcessActionEvent(ACTION_PREV_MODE, NULL); - else if (strcasecmp(msgbuf, "+vmode") == 0) - xf86ProcessActionEvent(ACTION_NEXT_MODE, NULL); - } - - return 0; -} diff --git a/hw/xfree86/xkb/xkbVT.c b/hw/xfree86/xkb/xkbVT.c deleted file mode 100644 index 984096122..000000000 --- a/hw/xfree86/xkb/xkbVT.c +++ /dev/null @@ -1,64 +0,0 @@ -/************************************************************ -Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. - -Permission to use, copy, modify, and distribute this -software and its documentation for any purpose and without -fee is hereby granted, provided that the above copyright -notice appear in all copies and that both that copyright -notice and this permission notice appear in supporting -documentation, and that the name of Silicon Graphics not be -used in advertising or publicity pertaining to distribution -of the software without specific prior written permission. -Silicon Graphics makes no representation about the suitability -of this software for any purpose. It is provided "as is" -without any express or implied warranty. - -SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS -SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON -GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL -DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH -THE USE OR PERFORMANCE OF THIS SOFTWARE. - -********************************************************/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#ifdef HAVE_XORG_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include "inputstr.h" -#include "scrnintstr.h" -#include "windowstr.h" -#include -#include - -#include "xf86.h" - -int -XkbDDXSwitchScreen(DeviceIntPtr dev, KeyCode key, XkbAction *act) -{ - int scrnnum = XkbSAScreen(&act->screen); - - if (act->screen.flags & XkbSA_SwitchApplication) { - if (act->screen.flags & XkbSA_SwitchAbsolute) - xf86ProcessActionEvent(ACTION_SWITCHSCREEN, (void *) &scrnnum); - else { - if (scrnnum < 0) - xf86ProcessActionEvent(ACTION_SWITCHSCREEN_PREV, NULL); - else - xf86ProcessActionEvent(ACTION_SWITCHSCREEN_NEXT, NULL); - } - } - - return 1; -} diff --git a/hw/xfree86/xorg-wrapper.c b/hw/xfree86/xorg-wrapper.c deleted file mode 100644 index 6c1022358..000000000 --- a/hw/xfree86/xorg-wrapper.c +++ /dev/null @@ -1,288 +0,0 @@ -/* - * Copyright © 2014 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Author: Hans de Goede - */ - -#include "dix-config.h" -#include "xorg-config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_SYS_SYSMACROS_H -#include -#endif -#include -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -#include -#endif -#include -#ifdef WITH_LIBDRM -#include -#include /* For DRM_DEV_NAME */ -#endif - -#include "misc.h" - -#define CONFIG_FILE SYSCONFDIR "/X11/Xwrapper.config" - -static const char *progname; - -enum { ROOT_ONLY, CONSOLE_ONLY, ANYBODY }; - -/* KISS non locale / LANG parsing isspace version */ -static int is_space(char c) -{ - return c == ' ' || c == '\t' || c == '\n'; -} - -static char *strip(char *s) -{ - int i; - - /* Strip leading whitespace */ - while (s[0] && is_space(s[0])) - s++; - - /* Strip trailing whitespace */ - i = strlen(s) - 1; - while (i >= 0 && is_space(s[i])) { - s[i] = 0; - i--; - } - - return s; -} - -static void parse_config(int *allowed, int *needs_root_rights) -{ - FILE *f; - char buf[1024]; - char *stripped, *equals, *key, *value; - int line = 0; - - f = fopen(CONFIG_FILE, "r"); - if (!f) - return; - - while (fgets(buf, sizeof(buf), f)) { - line++; - - /* Skip comments and empty lines */ - stripped = strip(buf); - if (stripped[0] == '#' || stripped[0] == 0) - continue; - - /* Split in a key + value pair */ - equals = strchr(stripped, '='); - if (!equals) { - fprintf(stderr, "%s: Syntax error at %s line %d\n", progname, - CONFIG_FILE, line); - exit(1); - } - *equals = 0; - key = strip(stripped); /* To remove trailing whitespace from key */ - value = strip(equals + 1); /* To remove leading whitespace from val */ - if (!key[0]) { - fprintf(stderr, "%s: Missing key at %s line %d\n", progname, - CONFIG_FILE, line); - exit(1); - } - if (!value[0]) { - fprintf(stderr, "%s: Missing value at %s line %d\n", progname, - CONFIG_FILE, line); - exit(1); - } - - /* And finally process */ - if (strcmp(key, "allowed_users") == 0) { - if (strcmp(value, "rootonly") == 0) - *allowed = ROOT_ONLY; - else if (strcmp(value, "console") == 0) - *allowed = CONSOLE_ONLY; - else if (strcmp(value, "anybody") == 0) - *allowed = ANYBODY; - else { - fprintf(stderr, - "%s: Invalid value '%s' for 'allowed_users' at %s line %d\n", - progname, value, CONFIG_FILE, line); - exit(1); - } - } - else if (strcmp(key, "needs_root_rights") == 0) { - if (strcmp(value, "yes") == 0) - *needs_root_rights = 1; - else if (strcmp(value, "no") == 0) - *needs_root_rights = 0; - else if (strcmp(value, "auto") == 0) - *needs_root_rights = -1; - else { - fprintf(stderr, - "%s: Invalid value '%s' for 'needs_root_rights' at %s line %d\n", - progname, value, CONFIG_FILE, line); - exit(1); - } - } - else if (strcmp(key, "nice_value") == 0) { - /* Backward compatibility with older Debian Xwrapper, ignore */ - } - else { - fprintf(stderr, "%s: Invalid key '%s' at %s line %d\n", key, - progname, CONFIG_FILE, line); - exit(1); - } - } - fclose(f); -} - -static int on_console(int fd) -{ -#if defined(__linux__) - struct stat st; - int r; - - r = fstat(fd, &st); - if (r == 0 && S_ISCHR(st.st_mode) && major(st.st_rdev) == 4) - return 1; -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - int idx; - - if (ioctl(fd, VT_GETINDEX, &idx) != -1) - return 1; -#else -#warning This program needs porting to your kernel. - static int seen; - - if (!seen) { - fprintf(stderr, "%s: Unable to determine if running on a console\n", - progname); - seen = 1; - } -#endif - - return 0; -} - -int main(int argc, char *argv[]) -{ -#ifdef WITH_LIBDRM - struct drm_mode_card_res res; -#endif - char buf[PATH_MAX]; - int i, r, fd; - int kms_cards = 0; - int total_cards = 0; - int allowed = CONSOLE_ONLY; - int needs_root_rights = -1; - char *const empty_envp[1] = { NULL, }; - - progname = argv[0]; - - parse_config(&allowed, &needs_root_rights); - - /* For non root users check if they are allowed to run the X server */ - if (getuid() != 0) { - switch (allowed) { - case ROOT_ONLY: - /* Already checked above */ - fprintf(stderr, "%s: Only root is allowed to run the X server\n", argv[0]); - exit(1); - break; - case CONSOLE_ONLY: - /* Some of stdin / stdout / stderr maybe redirected to a file */ - for (i = STDIN_FILENO; i <= STDERR_FILENO; i++) { - if (on_console(i)) - break; - } - if (i > STDERR_FILENO) { - fprintf(stderr, "%s: Only console users are allowed to run the X server\n", argv[0]); - exit(1); - } - break; - case ANYBODY: - break; - } - } - -#ifdef WITH_LIBDRM - /* Detect if we need root rights, except when overridden by the config */ - if (needs_root_rights == -1) { - for (i = 0; i < 16; i++) { - snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, i); - fd = open(buf, O_RDWR); - if (fd == -1) - continue; - - total_cards++; - - memset(&res, 0, sizeof(struct drm_mode_card_res)); - r = ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &res); - if (r == 0) - kms_cards++; - - close(fd); - } - } -#endif - - /* If we've found cards, and all cards support kms, drop root rights */ - if (needs_root_rights == 0 || (total_cards && kms_cards == total_cards)) { - gid_t realgid = getgid(); - uid_t realuid = getuid(); - - if (setresgid(-1, realgid, realgid) != 0) { - fprintf(stderr, "%s: Could not drop setgid privileges: %s\n", - progname, strerror(errno)); - exit(1); - } - if (setresuid(-1, realuid, realuid) != 0) { - fprintf(stderr, "%s: Could not drop setuid privileges: %s\n", - progname, strerror(errno)); - exit(1); - } - } - - snprintf(buf, sizeof(buf), "%s/Xorg", SUID_WRAPPER_DIR); - - /* Check if the server is executable by our real uid */ - if (access(buf, X_OK) != 0) { - fprintf(stderr, "%s: Missing execute permissions for %s: %s\n", - progname, buf, strerror(errno)); - exit(1); - } - - argv[0] = buf; - if (getuid() == geteuid()) - (void) execv(argv[0], argv); - else - (void) execve(argv[0], argv, empty_envp); - fprintf(stderr, "%s: Failed to execute %s: %s\n", - progname, buf, strerror(errno)); - exit(1); -} diff --git a/hw/xfree86/xorgconf.cpp b/hw/xfree86/xorgconf.cpp deleted file mode 100644 index 4cf677f36..000000000 --- a/hw/xfree86/xorgconf.cpp +++ /dev/null @@ -1,566 +0,0 @@ -# -# Copyright (c) 1994-1998 by The XFree86 Project, 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 XFREE86 PROJECT 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 XFree86 Project 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 -# XFree86 Project. -# -# $XConsortium: XF86Conf.cpp /main/22 1996/10/23 11:43:51 kaleb $ - -# ********************************************************************** -# This is a sample configuration file only, intended to illustrate -# what a config file might look like. Refer to the xorg.conf(__filemansuffix__) -# man page for details about the format of this file. -# ********************************************************************** - -# The ordering of sections is not important in XFree86 4.0 and later, -# nor in any Xorg release. - -# ********************************************************************** -# Files section. This allows default font and module paths to be set -# ********************************************************************** - -Section "Files" - -# Multiple FontPath entries are allowed (which are concatenated together), -# as well as specifying multiple comma-separated entries in one FontPath -# command (or a combination of both methods). -# The default path is shown here. - -# FontPath DEFAULTFONTPATH - -# ModulePath can be used to set a search path for the X server modules. -# The default path is shown here. - -# ModulePath MODULEPATH - -EndSection - -# ********************************************************************** -# Module section -- this is an optional section which is used to specify -# which run-time loadable modules to load when the X server starts up. -# ********************************************************************** - -Section "Module" - -# This loads the DBE extension module. - - Load "dbe" - -# This loads the miscellaneous extensions module, and disables -# initialisation of the XFree86-DGA extension within that module. - - SubSection "extmod" - Option "omit xfree86-dga" - EndSubSection - -EndSection - - -# ********************************************************************** -# Server flags section. This contains various server-wide Options. -# ********************************************************************** - -Section "ServerFlags" - -# Uncomment this to disable the VT switch sequence -# (where n is 1 through 12). This allows clients to receive these key -# events. - -# Option "DontVTSwitch" - -# Uncomment this to disable the server abort sequence -# This allows clients to receive this key event. - -# Option "DontZap" "true" - -# Uncomment this to disable the / mode switching -# sequences. This allows clients to receive these key events. - -# Option "DontZoom" - -# Uncomment this to disable tuning with the xvidtune client. With -# it the client can still run and fetch card and monitor attributes, -# but it will not be allowed to change them. If it tries it will -# receive a protocol error. - -# Option "DisableVidModeExtension" - -# Uncomment this to enable the use of a non-local xvidtune client. - -# Option "AllowNonLocalXvidtune" - -# Set the basic blanking screen saver timeout. - - Option "BlankTime" "10" # 10 minutes - -# Set the DPMS timeouts. These are set here because they are global -# rather than screen-specific. These settings alone don't enable DPMS. -# It is enabled per-screen (or per-monitor), and even then only when -# the driver supports it. - - Option "StandbyTime" "10" # 10 minutes - Option "SuspendTime" "10" # 10 minutes - Option "OffTime" "10" # 10 minutes - -EndSection - -# ********************************************************************** -# Input devices -# ********************************************************************** - -# ********************************************************************** -# Core keyboard's InputDevice section -# ********************************************************************** - -Section "InputDevice" - - Identifier "Keyboard1" - Driver "kbd" - -# Set the keyboard auto repeat parameters. Not all platforms implement -# this. - - Option "AutoRepeat" "500 5" - -# Specify which keyboard LEDs can be user-controlled (eg, with xset(1)). - -# Option "Xleds" "1 2 3" - -# To customise the XKB settings to suit your keyboard, modify the -# lines below (which are the defaults). For example, for a European -# keyboard, you will probably want to use one of: -# -# Option "XkbModel" "pc102" -# Option "XkbModel" "pc105" -# -# If you have a Microsoft Natural keyboard, you can use: -# -# Option "XkbModel" "microsoft" -# -# If you have a US "windows" keyboard you will want: -# -# Option "XkbModel" "pc104" -# -# Then to change the language, change the Layout setting. -# For example, a german layout can be obtained with: -# -# Option "XkbLayout" "de" -# -# or: -# -# Option "XkbLayout" "de" -# Option "XkbVariant" "nodeadkeys" -# -# If you'd like to switch the positions of your capslock and -# control keys, use: -# -# Option "XkbOptions" "ctrl:swapcaps" - - -# These are the default XKB settings for xorg -# -# Option "XkbRules" "xorg" -# Option "XkbModel" "pc105" -# Option "XkbLayout" "us" -# Option "XkbVariant" "" -# Option "XkbOptions" "" - -EndSection - - -# ********************************************************************** -# Core Pointer's InputDevice section -# ********************************************************************** - -Section "InputDevice" - -# Identifier and driver - - Identifier "Mouse1" - Driver "mouse" - -# The mouse protocol and device. The device is normally set to /dev/mouse, -# which is usually a symbolic link to the real device. - - Option "Protocol" "Microsoft" - Option "Device" "/dev/mouse" - -# On platforms where PnP mouse detection is supported the following -# protocol setting can be used when using a newer PnP mouse: - -# Option "Protocol" "Auto" - -# When using mouse connected to a PS/2 port (aka "MousePort"), set the -# the protocol as follows. On some platforms some other settings may -# be available. - -# Option "Protocol" "PS/2" - -# Baudrate and SampleRate are only for some older Logitech mice. In -# almost every case these lines should be omitted. - -# Option "BaudRate" "9600" -# Option "SampleRate" "150" - -# Emulate3Buttons is an option for 2-button mice -# Emulate3Timeout is the timeout in milliseconds (default is 50ms) - -# Option "Emulate3Buttons" -# Option "Emulate3Timeout" "50" - -# ChordMiddle is an option for some 3-button Logitech mice, or any -# 3-button mouse where the middle button generates left+right button -# events. - -# Option "ChordMiddle" - -EndSection - -Section "InputDevice" - Identifier "Mouse2" - Driver "mouse" - Option "Protocol" "MouseMan" - Option "Device" "/dev/mouse2" -EndSection - -# Some examples of extended input devices - -# Section "InputDevice" -# Identifier "spaceball" -# Driver "magellan" -# Option "Device" "/dev/cua0" -# EndSection -# -# Section "InputDevice" -# Identifier "spaceball2" -# Driver "spaceorb" -# Option "Device" "/dev/cua0" -# EndSection -# -# Section "InputDevice" -# Identifier "touchscreen0" -# Driver "microtouch" -# Option "Device" "/dev/ttyS0" -# Option "MinX" "1412" -# Option "MaxX" "15184" -# Option "MinY" "15372" -# Option "MaxY" "1230" -# Option "ScreenNumber" "0" -# Option "ReportingMode" "Scaled" -# Option "ButtonNumber" "1" -# Option "SendCoreEvents" -# EndSection -# -# Section "InputDevice" -# Identifier "touchscreen1" -# Driver "elo2300" -# Option "Device" "/dev/ttyS0" -# Option "MinX" "231" -# Option "MaxX" "3868" -# Option "MinY" "3858" -# Option "MaxY" "272" -# Option "ScreenNumber" "0" -# Option "ReportingMode" "Scaled" -# Option "ButtonThreshold" "17" -# Option "ButtonNumber" "1" -# Option "SendCoreEvents" -# EndSection - -# ********************************************************************** -# Monitor section -# ********************************************************************** - -# Any number of monitor sections may be present - -Section "Monitor" - -# The identifier line must be present. - - Identifier "Generic Monitor" - -# HorizSync is in kHz unless units are specified. -# HorizSync may be a comma separated list of discrete values, or a -# comma separated list of ranges of values. -# NOTE: THE VALUES HERE ARE EXAMPLES ONLY. REFER TO YOUR MONITOR'S -# USER MANUAL FOR THE CORRECT NUMBERS. - -# HorizSync 31.5 # typical for a single frequency fixed-sync monitor -# HorizSync 30-64 # multisync -# HorizSync 31.5, 35.2 # multiple fixed sync frequencies -# HorizSync 15-25, 30-50 # multiple ranges of sync frequencies - -# VertRefresh is in Hz unless units are specified. -# VertRefresh may be a comma separated list of discrete values, or a -# comma separated list of ranges of values. -# NOTE: THE VALUES HERE ARE EXAMPLES ONLY. REFER TO YOUR MONITOR'S -# USER MANUAL FOR THE CORRECT NUMBERS. - -# VertRefresh 60 # typical for a single frequency fixed-sync monitor - -# VertRefresh 50-100 # multisync -# VertRefresh 60, 65 # multiple fixed sync frequencies -# VertRefresh 40-50, 80-100 # multiple ranges of sync frequencies - -# Modes can be specified in two formats. A compact one-line format, or -# a multi-line format. - -# A generic VGA 640x480 mode (hsync = 31.5kHz, refresh = 60Hz) -# These two are equivalent - -# ModeLine "640x480" 25.175 640 664 760 800 480 491 493 525 - - Mode "640x480" - DotClock 25.175 - HTimings 640 664 760 800 - VTimings 480 491 493 525 - EndMode - -# These two are equivalent - -# ModeLine "1024x768i" 45 1024 1048 1208 1264 768 776 784 817 Interlace - -# Mode "1024x768i" -# DotClock 45 -# HTimings 1024 1048 1208 1264 -# VTimings 768 776 784 817 -# Flags "Interlace" -# EndMode - -# If a monitor has DPMS support, that can be indicated here. This will -# enable DPMS when the monitor is used with drivers that support it. - -# Option "dpms" - -# If a monitor requires that the sync signals be superimposed on the -# green signal, the following option will enable this when used with -# drivers that support it. Only a relatively small range of hardware -# (and drivers) actually support this. - -# Option "sync on green" - -EndSection - -# ********************************************************************** -# Graphics device section -# ********************************************************************** - -# Any number of graphics device sections may be present - -Section "Device" - -# The Identifier must be present. - - Identifier "Generic VESA" - -# The Driver line must be present. When using run-time loadable driver -# modules, this line instructs the server to load the specified driver -# module. Even when not using loadable driver modules, this line -# indicates which driver should interpret the information in this section. - - Driver "vesa" - -# The chipset line is optional in most cases. It can be used to override -# the driver's chipset detection, and should not normally be specified. - -# Chipset "generic" - -# Various other lines can be specified to override the driver's automatic -# detection code. In most cases they are not needed. - -# VideoRam 256 -# Clocks 25.2 28.3 - -# The BusID line is used to specify which of possibly multiple devices -# this section is intended for. When this line isn't present, a device -# section can only match up with the primary video device. For PCI -# devices a line like the following could be used. This line should not -# normally be included unless there is more than one video device -# intalled. - -# BusID "PCI:0:10:0" - -# Various option lines can be added here as required. Some options -# are more appropriate in Screen sections, Display subsections or even -# Monitor sections. - -# Option "hw cursor" "off" - -EndSection - -Section "Device" - Identifier "any supported Trident chip" - Driver "trident" -EndSection - -Section "Device" - Identifier "MGA Millennium I" - Driver "mga" - Option "hw cursor" "off" - BusID "PCI:0:10:0" -EndSection - -Section "Device" - Identifier "MGA G200 AGP" - Driver "mga" - BusID "PCI:1:0:0" - Option "pci retry" -EndSection - - -# ********************************************************************** -# Screen sections. -# ********************************************************************** - -# Any number of screen sections may be present. Each describes -# the configuration of a single screen. A single specific screen section -# may be specified from the X server command line with the "-screen" -# option. - -Section "Screen" - -# The Identifier, Device and Monitor lines must be present - - Identifier "Screen 1" - Device "Generic VESA" - Monitor "Generic Monitor" - -# The favoured Depth and/or Bpp may be specified here - - DefaultDepth 8 - - SubSection "Display" - Depth 8 - Modes "640x480" - ViewPort 0 0 - Virtual 800 600 - EndSubsection - - SubSection "Display" - Depth 4 - Modes "640x480" - EndSubSection - - SubSection "Display" - Depth 1 - Modes "640x480" - EndSubSection - -EndSection - - -Section "Screen" - Identifier "Screen MGA1" - Device "MGA Millennium I" - Monitor "Generic Monitor" - Option "no accel" - DefaultDepth 16 -# DefaultDepth 24 - - SubSection "Display" - Depth 8 - Modes "1280x1024" - Option "rgb bits" "8" - Visual "StaticColor" - EndSubSection - SubSection "Display" - Depth 16 - Modes "1280x1024" - EndSubSection - SubSection "Display" - Depth 24 - Modes "1280x1024" - EndSubSection -EndSection - - -Section "Screen" - Identifier "Screen MGA2" - Device "MGA G200 AGP" - Monitor "Generic Monitor" - DefaultDepth 8 - - SubSection "Display" - Depth 8 - Modes "1280x1024" - Option "rgb bits" "8" - Visual "StaticColor" - EndSubSection -EndSection - - -# ********************************************************************** -# ServerLayout sections. -# ********************************************************************** - -# Any number of ServerLayout sections may be present. Each describes -# the way multiple screens are organised. A specific ServerLayout -# section may be specified from the X server command line with the -# "-layout" option. In the absence of this, the first section is used. -# When now ServerLayout section is present, the first Screen section -# is used alone. - -Section "ServerLayout" - -# The Identifier line must be present - - Identifier "Main Layout" - -# Each Screen line specifies a Screen section name, and optionally -# the relative position of other screens. The four names after -# primary screen name are the screens to the top, bottom, left and right -# of the primary screen. In this example, screen 2 is located to the -# right of screen 1. - - Screen "Screen MGA 1" "" "" "" "Screen MGA 2" - Screen "Screen MGA 2" "" "" "Screen MGA 1" "" - -# Each InputDevice line specifies an InputDevice section name and -# optionally some options to specify the way the device is to be -# used. Those options include "CorePointer", "CoreKeyboard" and -# "SendCoreEvents". In this example, "Mouse1" is the core pointer, -# and "Mouse2" is an extended input device that also generates core -# pointer events (i.e., both mice will move the standard pointer). - - InputDevice "Mouse1" "CorePointer" - InputDevice "Mouse2" "SendCoreEvents" - InputDevice "Keyboard1" "CoreKeyboard" - -EndSection - - -Section "ServerLayout" - Identifier "another layout" - Screen "Screen 1" - Screen "Screen MGA 1" - InputDevice "Mouse1" "CorePointer" - InputDevice "Keyboard1" "CoreKeyboard" -EndSection - - -Section "ServerLayout" - Identifier "simple layout" - Screen "Screen 1" - InputDevice "Mouse1" "CorePointer" - InputDevice "Keyboard1" "CoreKeyboard" -EndSection - diff --git a/include/meson.build b/include/meson.build index 79448a080..32ebe3a1b 100644 --- a/include/meson.build +++ b/include/meson.build @@ -119,11 +119,8 @@ conf_data.set('GBM_BO_FD_FOR_PLANE', conf_data.set_quoted('SERVER_MISC_CONFIG_PATH', serverconfigdir) conf_data.set_quoted('PROJECTROOT', get_option('prefix')) conf_data.set_quoted('SYSCONFDIR', join_paths(get_option('prefix'), get_option('sysconfdir'))) -conf_data.set_quoted('SUID_WRAPPER_DIR', join_paths(get_option('prefix'), get_option('libexecdir'))) conf_data.set_quoted('COMPILEDDEFAULTFONTPATH', default_font_path) -conf_data.set('XORG_VERSION_CURRENT', release) - conf_data.set('HASXDMAUTH', has_xdm_auth ? '1' : false) conf_data.set('SECURE_RPC', get_option('secure-rpc') ? '1' : false) @@ -131,12 +128,9 @@ conf_data.set('HAVE_DLFCN_H', cc.has_header('dlfcn.h') ? '1' : false) conf_data.set('HAVE_EXECINFO_H', cc.has_header('execinfo.h') ? '1' : false) conf_data.set('HAVE_FCNTL_H', cc.has_header('fcntl.h') ? '1' : false) conf_data.set('HAVE_FNMATCH_H', cc.has_header('fnmatch.h') ? '1' : false) -conf_data.set('HAVE_LINUX_AGPGART_H', cc.has_header('linux/agpgart.h') ? '1' : false) conf_data.set('HAVE_STDLIB_H', cc.has_header('stdlib.h') ? '1' : false) conf_data.set('HAVE_STRING_H', cc.has_header('string.h') ? '1' : false) conf_data.set('HAVE_STRINGS_H', cc.has_header('strings.h') ? '1' : false) -conf_data.set('HAVE_SYS_AGPGART_H', cc.has_header('sys/agpgart.h') ? '1' : false) -conf_data.set('HAVE_SYS_AGPIO_H', cc.has_header('sys/agpio.h') ? '1' : false) conf_data.set('HAVE_SYS_UTSNAME_H', cc.has_header('sys/utsname.h') ? '1' : false) conf_data.set('HAVE_SYS_SYSMACROS_H', cc.has_header('sys/sysmacros.h') ? '1' : false) conf_data.set('HAVE_UNISTD_H', cc.has_header('unistd.h') ? '1' : false) @@ -206,9 +200,7 @@ conf_data.set('BIGREQS', '1') conf_data.set('COMPOSITE', '1') conf_data.set('DAMAGE', '1') conf_data.set('DBE', '1') -conf_data.set('DGA', build_dga ? '1' : false) conf_data.set('DPMSExtension', build_dpms ? '1' : false) -conf_data.set('DRI2', build_dri2 ? '1' : false) conf_data.set('DRI3', build_dri3 ? '1' : false) if build_glx conf_data.set_quoted('DRI_DRIVER_PATH', dri_dep.get_pkgconfig_variable('dridriverdir')) @@ -227,10 +219,8 @@ conf_data.set('XCMISC', '1') conf_data.set('XCSECURITY', build_xsecurity ? '1' : false) conf_data.set('XDMCP', xdmcp_dep.found() ? '1' : false) conf_data.set('XF86BIGFONT', build_xf86bigfont ? '1' : false) -conf_data.set('XF86DRI', build_dri1 ? '1' : false) conf_data.set('XF86VIDMODE', 1) conf_data.set('XFIXES', '1') -conf_data.set('XFreeXDGA', build_dga ? '1' : false) conf_data.set('XINERAMA', build_xinerama ? '1' : false) conf_data.set('XINPUT', '1') conf_data.set('XRECORD', '1') @@ -239,14 +229,10 @@ conf_data.set('XSYNC', '1') conf_data.set('XTEST', '1') conf_data.set('XV', build_xv ? '1' : false) conf_data.set('XvExtension', build_xv ? '1' : false) -conf_data.set('XvMCExtension', build_xvmc ? '1' : false) conf_data.set('HAVE_SHA1_IN_' + sha1.to_upper(), '1', description: 'Use @0@ SHA1 functions'.format(sha1)) conf_data.set('HAVE_LIBUNWIND', get_option('libunwind')) -conf_data.set('HAVE_APM', (build_apm or build_acpi) ? '1' : false) -conf_data.set('HAVE_ACPI', build_acpi ? '1' : false) - enable_debugging = get_option('buildtype') == 'debug' conf_data.set('DEBUG', enable_debugging ? '1' : false) @@ -256,14 +242,6 @@ conf_data.set_quoted('__VENDORDWEBSUPPORT__', get_option('vendor_web')) conf_data.set_quoted('BUILDERADDR', get_option('builder_addr')) conf_data.set_quoted('BUILDERSTRING', get_option('builder_string')) -# -# for xorg-server.h only -# -defines_svr4 = '''#if !defined(SVR4) && !defined(__svr4__) && !defined(__SVR4) -#error "I am not SVR4" -#endif -''' - # BSD specifics supports_pccons = false supports_pcvt = false @@ -301,29 +279,18 @@ if host_machine.system() == 'darwin' csrg_based = true endif -conf_data.set('SVR4', cc.compiles(defines_svr4) ? '1' : false) conf_data.set_quoted('XKB_DFLT_RULES', get_option('xkb_default_rules')) -conf_data.set('XORGSERVER', build_xorg ? '1' : false) -conf_data.set_quoted('XCONFIGFILE', 'xorg.conf') conf_data.set_quoted('__XSERVERNAME__', 'Xorg') -conf_data.set('WITH_VGAHW', build_vgahw ? '1' : false) conf_data.set('CSRG_BASED', csrg_based ? '1' : false) conf_data.set('PCCONS_SUPPORT', supports_pccons ? '1' : false) conf_data.set('PCVT_SUPPORT', supports_pcvt ? '1' : false) conf_data.set('SYSCONS_SUPPORT', supports_syscons ? '1' : false) conf_data.set('WSCONS_SUPPORT', supports_wscons ? '1' : false) -conf_data.set('XSERVER_LIBPCIACCESS', get_option('pciaccess') ? '1' : false) conf_data.set('XSERVER_PLATFORM_BUS', build_udev_kms ? '1' : false) configure_file(output : 'dix-config.h', configuration : conf_data) -configure_file(output : 'xorg-server.h', - input : 'xorg-server.h.meson.in', - configuration : conf_data, - install: build_xorg, - install_dir: xorgsdkdir) - version_data = configuration_data() version_data.set('VENDOR_RELEASE', '@0@'.format(release)) version_data.set_quoted('VENDOR_NAME', get_option('vendor_name')) @@ -347,50 +314,6 @@ xkb_data.set_quoted('XKM_OUTPUT_DIR', xkb_output_dir + '/') configure_file(output : 'xkb-config.h', configuration : xkb_data) -xorg_data = configuration_data() - -xorg_data.set_quoted('XORG_BIN_DIRECTORY', get_option('bindir')) -xorg_data.set('XORG_VERSION_CURRENT', release) -xorg_data.set_quoted('XF86CONFIGFILE', 'xorg.conf') -xorg_data.set_quoted('XCONFIGFILE', 'xorg.conf') -xorg_data.set_quoted('XCONFIGDIR', 'xorg.conf.d') -xorg_data.set_quoted('DEFAULT_XDG_DATA_HOME', '.local/share') -xorg_data.set_quoted('DEFAULT_XDG_DATA_HOME_LOGDIR', 'xorg') -xorg_data.set_quoted('DEFAULT_LOGDIR', log_dir) -xorg_data.set_quoted('DEFAULT_LOGPREFIX', 'Xorg.') -xorg_data.set_quoted('DEFAULT_MODULE_PATH', join_paths(get_option('prefix'), module_dir)) -xorg_data.set_quoted('DEFAULT_LIBRARY_PATH', join_paths(get_option('prefix'), get_option('libdir'))) -xorg_data.set_quoted('__XSERVERNAME__', 'Xorg') -xorg_data.set('XSERVER_LIBPCIACCESS', get_option('pciaccess') ? '1' : false) -xorg_data.set_quoted('PCI_TXT_IDS_PATH', '') -xorg_data.set('XSERVER_PLATFORM_BUS', build_udev_kms ? '1' : false) -xorg_data.set('WSCONS_SUPPORT', - host_machine.system() == 'netbsd' or host_machine.system() == 'openbsd' ? '1' : false) -xorg_data.set('HAVE_STROPTS_H', cc.has_header('stropts.h') ? '1' : false) -xorg_data.set('HAVE_SYS_KD_H', cc.has_header('sys/kd.h') ? '1' : false) -xorg_data.set('HAVE_SYS_VT_H', cc.has_header('sys/vt.h') ? '1' : false) - -if host_machine.system() == 'freebsd' or host_machine.system() == 'dragonfly' - if host_machine.cpu_family() == 'x86' or host_machine.cpu_family() == 'x86_64' - xorg_data.set('USE_DEV_IO', '1') - endif -elif host_machine.system() == 'netbsd' - if host_machine.cpu_family() == 'x86' or host_machine.cpu_family() == 'x86_64' - xorg_data.set('USE_I386_IOPL', '1') - endif -elif host_machine.system() == 'openbsd' - if host_machine.cpu_family() == 'x86' - xorg_data.set('USE_I386_IOPL', '1') - endif - if host_machine.cpu_family() == 'x86_64' - xorg_data.set('USE_AMD64_IOPL', '1') - endif -endif - -configure_file(output : 'xorg-config.h', - input : 'xorg-config.h.meson.in', - configuration : xorg_data) - xwayland_data = configuration_data() xwayland_data.set('XWL_HAS_GLAMOR', build_glamor and (gbm_dep.found() or build_eglstream) ? '1' : false) xwayland_data.set('XWL_HAS_EGLSTREAM', build_eglstream ? '1' : false) @@ -409,75 +332,3 @@ if with_dtrace dtrace_hdr += dtrace_header.process(dtrace_tmpl) endif - -if build_xorg - install_data( - [ - 'XIstubs.h', - 'Xprintf.h', - 'callback.h', - 'client.h', - 'closestr.h', - 'closure.h', - 'colormap.h', - 'colormapst.h', - 'hotplug.h', - 'cursor.h', - 'cursorstr.h', - 'dix.h', - 'dixaccess.h', - 'dixevents.h', - 'dixfont.h', - 'dixfontstr.h', - 'dixgrabs.h', - 'dixstruct.h', - 'events.h', - 'exevents.h', - 'extension.h', - 'extinit.h', - 'extnsionst.h', - 'fourcc.h', - 'gc.h', - 'gcstruct.h', - 'globals.h', - 'glx_extinit.h', - 'glxvndabi.h', - 'input.h', - 'inputstr.h', - 'list.h', - 'misc.h', - 'miscstruct.h', - 'opaque.h', - 'nonsdk_extinit.h', - 'optionstr.h', - 'os.h', - 'pixmap.h', - 'pixmapstr.h', - 'privates.h', - 'property.h', - 'propertyst.h', - 'ptrveloc.h', - 'region.h', - 'regionstr.h', - 'registry.h', - 'resource.h', - 'rgb.h', - 'screenint.h', - 'scrnintstr.h', - 'selection.h', - 'servermd.h', - 'validate.h', - 'displaymode.h', - 'window.h', - 'windowstr.h', - 'xkbfile.h', - 'xkbsrv.h', - 'xkbstr.h', - 'xkbrules.h', - 'Xprintf.h', - 'xserver_poll.h', - 'xserver-properties.h', - ], - install_dir: xorgsdkdir, - ) -endif diff --git a/include/xorg-config.h.meson.in b/include/xorg-config.h.meson.in deleted file mode 100644 index 59f1c2a8d..000000000 --- a/include/xorg-config.h.meson.in +++ /dev/null @@ -1,148 +0,0 @@ -/* xorg-config.h.in: not at all generated. -*- c -*- - * - * This file differs from xorg-server.h.in in that -server is installed - * with the rest of the SDK for external drivers/modules to use, whereas - * -config is for internal use only (i.e. building the DDX). - * - */ - -#ifndef _XORG_CONFIG_H_ -#define _XORG_CONFIG_H_ - -#include -#include - -/* Building Xorg server. */ -#mesondefine XORGSERVER - -/* Current X.Org version. */ -#mesondefine XORG_VERSION_CURRENT - -/* Name of X server. */ -#mesondefine __XSERVERNAME__ - -/* URL to go to for support. */ -#mesondefine __VENDORDWEBSUPPORT__ - -/* Built-in output drivers. */ -#mesondefine DRIVERS - -/* Built-in input drivers. */ -#mesondefine IDRIVERS - -/* Path to configuration file. */ -#mesondefine XF86CONFIGFILE - -/* Path to configuration file. */ -#mesondefine XCONFIGFILE - -/* Name of configuration directory. */ -#mesondefine XCONFIGDIR - -/* Path to loadable modules. */ -#mesondefine DEFAULT_MODULE_PATH - -/* Path to installed libraries. */ -#mesondefine DEFAULT_LIBRARY_PATH - -/* Default log location */ -#mesondefine DEFAULT_LOGDIR - -/* Default logfile prefix */ -#mesondefine DEFAULT_LOGPREFIX - -/* Default XDG_DATA dir under HOME */ -#mesondefine DEFAULT_XDG_DATA_HOME - -/* Default log dir under XDG_DATA_HOME */ -#mesondefine DEFAULT_XDG_DATA_HOME_LOGDIR - -/* Building DRI-capable DDX. */ -#mesondefine XF86DRI - -/* Build DRI2 extension */ -#mesondefine DRI2 - -/* Define to 1 if you have the header file. */ -#mesondefine HAVE_STROPTS_H - -/* Define to 1 if you have the header file. */ -#mesondefine HAVE_SYS_KD_H - -/* Define to 1 if you have the header file. */ -#mesondefine HAVE_SYS_VT_H - -/* Define to 1 if you have the `walkcontext' function (used on Solaris for - xorg_backtrace in hw/xfree86/common/xf86Events.c */ -#mesondefine HAVE_WALKCONTEXT - -/* Building vgahw module */ -#mesondefine WITH_VGAHW - -/* NetBSD PIO alpha IO */ -#mesondefine USE_ALPHA_PIO - -/* BSD AMD64 iopl */ -#mesondefine USE_AMD64_IOPL - -/* BSD /dev/io */ -#mesondefine USE_DEV_IO - -/* BSD i386 iopl */ -#mesondefine USE_I386_IOPL - -/* System is BSD-like */ -#mesondefine CSRG_BASED - -/* System has PC console */ -#mesondefine PCCONS_SUPPORT - -/* System has PCVT console */ -#mesondefine PCVT_SUPPORT - -/* System has syscons console */ -#mesondefine SYSCONS_SUPPORT - -/* System has wscons console */ -#mesondefine WSCONS_SUPPORT - -/* System has /dev/xf86 aperture driver */ -#mesondefine HAS_APERTURE_DRV - -/* Has backtrace support */ -#mesondefine HAVE_BACKTRACE - -/* Name of the period field in struct kbd_repeat */ -#mesondefine LNX_KBD_PERIOD_NAME - -/* Have execinfo.h */ -#mesondefine HAVE_EXECINFO_H - -/* Define to 1 if you have the header file. */ -#mesondefine HAVE_SYS_MKDEV_H - -/* Path to text files containing PCI IDs */ -#mesondefine PCI_TXT_IDS_PATH - -/* Build with libdrm support */ -#mesondefine WITH_LIBDRM - -/* Use libpciaccess */ -#mesondefine XSERVER_LIBPCIACCESS - -/* Have setugid */ -#mesondefine HAVE_ISSETUGID - -/* Have getresuid */ -#mesondefine HAVE_GETRESUID - -/* Have X server platform bus support */ -#mesondefine XSERVER_PLATFORM_BUS - -/* Define to 1 if you have the `seteuid' function. */ -#mesondefine HAVE_SETEUID - -/* Fallback input driver if the assigned driver fails */ -#mesondefine FALLBACK_INPUT_DRIVER - -#endif /* _XORG_CONFIG_H_ */ diff --git a/include/xorg-server.h.meson.in b/include/xorg-server.h.meson.in deleted file mode 100644 index 093801cad..000000000 --- a/include/xorg-server.h.meson.in +++ /dev/null @@ -1,222 +0,0 @@ -/* xorg-server.h.in -*- c -*- - * - * This file is the template file for the xorg-server.h file which gets - * installed as part of the SDK. The #defines in this file overlap - * with those from config.h, but only for those options that we want - * to export to external modules. Boilerplate autotool #defines such - * as HAVE_STUFF and PACKAGE_NAME is kept in config.h - * - * It is still possible to update config.h.in using autoheader, since - * autoheader only creates a .h.in file for the first - * AM_CONFIG_HEADER() line, and thus does not overwrite this file. - * - * However, it should be kept in sync with this file. - */ - -#ifndef _XORG_SERVER_H_ -#define _XORG_SERVER_H_ - -#ifdef HAVE_XORG_CONFIG_H -#error Include xorg-config.h when building the X server -#endif - -/* Support BigRequests extension */ -#mesondefine BIGREQS - -/* Default font path */ -#mesondefine COMPILEDDEFAULTFONTPATH - -/* Support Composite Extension */ -#mesondefine COMPOSITE - -/* Build DPMS extension */ -#mesondefine DPMSExtension - -/* Build DRI3 extension */ -#mesondefine DRI3 - -/* Build GLX extension */ -#mesondefine GLXEXT - -/* Support XDM-AUTH*-1 */ -#mesondefine HASXDMAUTH - -/* Support SHM */ -#mesondefine HAS_SHM - -/* Define to 1 if you have the `reallocarray' function. */ -#mesondefine HAVE_REALLOCARRAY - -/* Define to 1 if you have the `strcasecmp' function. */ -#mesondefine HAVE_STRCASECMP - -/* Define to 1 if you have the `strcasestr' function. */ -#mesondefine HAVE_STRCASESTR - -/* Define to 1 if you have the `strlcat' function. */ -#mesondefine HAVE_STRLCAT - -/* Define to 1 if you have the `strlcpy' function. */ -#mesondefine HAVE_STRLCPY - -/* Define to 1 if you have the `strncasecmp' function. */ -#mesondefine HAVE_STRNCASECMP - -/* Define to 1 if you have the `strndup' function. */ -#mesondefine HAVE_STRNDUP - -/* Support IPv6 for TCP connections */ -#mesondefine IPv6 - -/* Support MIT-SHM Extension */ -#mesondefine MITSHM - -/* Internal define for Xinerama */ -#mesondefine PANORAMIX - -/* Support Present extension */ -#mesondefine PRESENT - -/* Support RANDR extension */ -#mesondefine RANDR - -/* Support RENDER extension */ -#mesondefine RENDER - -/* Support X resource extension */ -#mesondefine RES - -/* Support MIT-SCREEN-SAVER extension */ -#mesondefine SCREENSAVER - -/* Support SHAPE extension */ -#mesondefine SHAPE - -/* Define to 1 on systems derived from System V Release 4 */ -#mesondefine SVR4 - -/* Support TCP socket connections */ -#mesondefine TCPCONN - -/* Support UNIX socket connections */ -#mesondefine UNIXCONN - -/* Support XCMisc extension */ -#mesondefine XCMISC - -/* Support Xdmcp */ -#mesondefine XDMCP - -/* Build XFree86 BigFont extension */ -#mesondefine XF86BIGFONT - -/* Support XFree86 Video Mode extension */ -#mesondefine XF86VIDMODE - -/* Build XDGA support */ -#mesondefine XFreeXDGA - -/* Support Xinerama extension */ -#mesondefine XINERAMA - -/* Support X Input extension */ -#mesondefine XINPUT - -/* XKB default rules */ -#mesondefine XKB_DFLT_RULES - -/* Build DRI extension */ -#mesondefine XF86DRI - -/* Build DRI2 extension */ -#mesondefine DRI2 - -/* Build Xorg server */ -#mesondefine XORGSERVER - -/* Current Xorg version */ -#mesondefine XORG_VERSION_CURRENT - -/* Build Xv Extension */ -#mesondefine XvExtension - -/* Build XvMC Extension */ -#mesondefine XvMCExtension - -/* Support XSync extension */ -#mesondefine XSYNC - -/* Support XTest extension */ -#mesondefine XTEST - -/* Support Xv Extension */ -#mesondefine XV - -/* Vendor name */ -#mesondefine XVENDORNAME - -/* BSD-compliant source */ -#mesondefine _BSD_SOURCE - -/* POSIX-compliant source */ -#mesondefine _POSIX_SOURCE - -/* X/Open-compliant source */ -#mesondefine _XOPEN_SOURCE - -/* Vendor web address for support */ -#mesondefine __VENDORDWEBSUPPORT__ - -/* Location of configuration file */ -#mesondefine XCONFIGFILE - -/* Name of X server */ -#mesondefine __XSERVERNAME__ - -/* Building vgahw module */ -#mesondefine WITH_VGAHW - -/* System is BSD-like */ -#mesondefine CSRG_BASED - -/* System has PC console */ -#mesondefine PCCONS_SUPPORT - -/* System has PCVT console */ -#mesondefine PCVT_SUPPORT - -/* System has syscons console */ -#mesondefine SYSCONS_SUPPORT - -/* System has wscons console */ -#mesondefine WSCONS_SUPPORT - -/* Loadable XFree86 server awesomeness */ -#define XFree86LOADER - -/* Use libpciaccess */ -#mesondefine XSERVER_LIBPCIACCESS - -/* X Access Control Extension */ -#mesondefine XACE - -/* Have X server platform bus support */ -#mesondefine XSERVER_PLATFORM_BUS - -#ifdef _LP64 -#define _XSERVER64 1 -#endif - -/* Have support for X shared memory fence library (xshmfence) */ -#mesondefine HAVE_XSHMFENCE - -/* Use XTrans FD passing support */ -#mesondefine XTRANS_SEND_FDS - -/* Ask fontsproto to make font path element names const */ -#define FONT_PATH_ELEMENT_NAME_CONST 1 - -/* byte order */ -#mesondefine X_BYTE_ORDER - -#endif /* _XORG_SERVER_H_ */ diff --git a/meson.build b/meson.build index 5b668be51..13679068d 100644 --- a/meson.build +++ b/meson.build @@ -66,7 +66,6 @@ xext_req = '>= 1.0.99.4' wayland_req = '>= 1.5.0' wayland_protocols_req = '>= 1.22' gbm_req = '>= 10.2' -xf86dgaproto_req = '>= 2.0.99.1' xproto_dep = dependency('xproto', version: '>= 7.0.31', fallback: ['xorgproto', 'ext_xorgproto']) randrproto_dep = dependency('randrproto', version: '>= 1.6.0', fallback: ['xorgproto', 'ext_xorgproto']) @@ -86,8 +85,6 @@ compositeproto_dep = dependency('compositeproto', version: '>= 0.4', fallback: [ recordproto_dep = dependency('recordproto', version: '>= 1.13.99.1', fallback: ['xorgproto', 'ext_xorgproto']) scrnsaverproto_dep = dependency('scrnsaverproto', version: '>= 1.1', fallback: ['xorgproto', 'ext_xorgproto']) resourceproto_dep = dependency('resourceproto', version: '>= 1.2.0', fallback: ['xorgproto', 'ext_xorgproto']) -xf86driproto_dep = dependency('xf86driproto', version: '>= 2.1.0', fallback: ['xorgproto', 'ext_xorgproto'], required: get_option('dri1') == 'true') -dri2proto_dep = dependency('dri2proto', version: '>= 2.8', fallback: ['xorgproto', 'ext_xorgproto'], required: get_option('dri2') == 'true') dri3proto_dep = dependency('dri3proto', version: '>= 1.2', fallback: ['xorgproto', 'ext_xorgproto'], required: get_option('dri3') == 'true') xineramaproto_dep = dependency('xineramaproto', fallback: ['xorgproto', 'ext_xorgproto']) xf86bigfontproto_dep = dependency('xf86bigfontproto', version: '>= 1.2.0', fallback: ['xorgproto', 'ext_xorgproto'], required: get_option('xf86bigfont')) @@ -182,19 +179,6 @@ if with_dtrace dtrace = find_program('dtrace', required: true) endif -build_xorg = false -if (host_machine.system() != 'darwin' and - host_machine.system() != 'windows') - if get_option('xorg') == 'auto' - build_xorg = (host_machine.system() != 'darwin' and - host_machine.system() != 'windows') - else - build_xorg = get_option('xorg') == 'true' - endif -endif -xorgsdkdir = join_paths(get_option('prefix'), get_option('includedir'), 'xorg') -libxcvt_dep = dependency('libxcvt', fallback: ['libxcvt', 'libxcvt_dep'], required: build_xorg) - build_xwayland = false if (host_machine.system() != 'darwin' and host_machine.system() != 'windows') @@ -234,17 +218,6 @@ else build_ipv6 = get_option('ipv6') == 'true' endif -int10 = get_option('int10') -if int10 == 'auto' - int10 = 'x86emu' - if host_machine.cpu() == 'powerpc' and host_machine.system() == 'freebsd' - int10 = 'stub' - endif - if host_machine.cpu() == 'arm' - int10 = 'stub' - endif -endif - hal_dep = [] if hal_option == 'auto' if not build_udev @@ -271,15 +244,8 @@ if build_udev or build_udev_kms udev_dep = dependency('libudev', version: '>= 143') endif -log_dir = get_option('log_dir') -if log_dir == '' - log_dir = join_paths(get_option('prefix'), get_option('localstatedir'), 'log') -endif - -module_dir = join_paths(get_option('libdir'), get_option('module_dir')) - if glamor_option == 'auto' - build_glamor = build_xorg or build_xwayland + build_glamor = build_xwayland else build_glamor = glamor_option == 'true' endif @@ -414,18 +380,6 @@ endif libdrm_dep = dependency('libdrm', version: libdrm_req, required: false) -if get_option('dri1') == 'auto' - build_dri1 = xf86driproto_dep.found() and libdrm_dep.found() -else - build_dri1 = get_option('dri1') == 'true' -endif - -if get_option('dri2') == 'auto' - build_dri2 = dri2proto_dep.found() and libdrm_dep.found() -else - build_dri2 = get_option('dri2') == 'true' -endif - if get_option('dri3') == 'auto' build_dri3 = dri3proto_dep.found() and xshmfence_dep.found() and libdrm_dep.found() else @@ -437,24 +391,11 @@ else endif endif -libdrm_required = (build_dri1 or build_dri2 or build_dri3) and get_option('drm') == true +libdrm_required = build_dri3 if not libdrm_dep.found() and libdrm_required error('DRI requested, but LIBDRM not found') endif -build_modesetting = libdrm_dep.found() and dri2proto_dep.found() - -build_vgahw = false -if get_option('vgahw') == 'auto' - if (host_machine.system() != 'darwin' and - host_machine.system() != 'windows' and - host_machine.system() != 'cygwin') - build_vgahw = true - endif -else - build_vgahw = get_option('vgahw') == 'true' -endif - build_dpms = get_option('dpms') build_xf86bigfont = get_option('xf86bigfont') @@ -475,40 +416,6 @@ if build_xsecurity endif build_xv = get_option('xv') -build_xvmc = get_option('xvmc') -if not build_xv - build_xvmc = false -endif - -build_dga = false -xf86dgaproto_dep = dependency('', required: false) -if get_option('dga') == 'auto' - xf86dgaproto_dep = dependency('xf86dgaproto', version: xf86dgaproto_req, required: false) - if xf86dgaproto_dep.found() - build_dga = true - endif -elif get_option('dga') == 'true' - xf86dgaproto_dep = dependency('xf86dgaproto', version: xf86dgaproto_req, required: true) - build_dga = true -endif - -build_apm = false -if (get_option('linux_apm') == true and - host_machine.system() == 'linux') - if cc.has_header('linux/apm_bios.h') - build_apm = true - endif -endif - -build_acpi = false -if (get_option('linux_acpi') == true and - host_machine.system() == 'linux') - if (host_machine.cpu() == 'x86' or - host_machine.cpu() == 'x86_64' or - host_machine.cpu() == 'ia64') - build_acpi = true - endif -endif build_mitshm = false if get_option('mitshm') == 'auto' @@ -540,12 +447,9 @@ common_dep = [ recordproto_dep, scrnsaverproto_dep, resourceproto_dep, - xf86driproto_dep, - dri2proto_dep, dri3proto_dep, xineramaproto_dep, xf86bigfontproto_dep, - xf86dgaproto_dep, xf86vidmodeproto_dep, pixman_dep, @@ -622,7 +526,6 @@ manpage_config.set('adminmansuffix', '8') manpage_config.set('libmansuffix', '3') manpage_config.set('miscmansuffix', '7') manpage_config.set('filemansuffix', '5') -manpage_config.set('logdir', log_dir) manpage_config.set('datadir', join_paths(get_option('prefix'), get_option('datadir'))) manpage_config.set('mandir', join_paths(get_option('prefix'), get_option('mandir'))) manpage_config.set('sysconfdir', join_paths(get_option('prefix'), get_option('sysconfdir'))) @@ -634,10 +537,6 @@ manpage_config.set('XKB_DFLT_LAYOUT', get_option('xkb_default_layout')) manpage_config.set('XKB_DFLT_VARIANT', get_option('xkb_default_variant')) manpage_config.set('XKB_DFLT_OPTIONS', get_option('xkb_default_options')) manpage_config.set('bundle_id_prefix', '...') -manpage_config.set('modulepath', module_dir) -# wtf doesn't this work -# manpage_config.set('suid_wrapper_dir', join_paths(get_option('prefix'), libexecdir)) -manpage_config.set('suid_wrapper_dir', join_paths(get_option('prefix'), 'libexec')) manpage_config.set('default_font_path', default_font_path) require_docs = get_option('docs') == 'true' @@ -714,7 +613,7 @@ subdir('Xi') if build_glamor subdir('glamor') endif -if build_xorg or get_option('xephyr') +if get_option('xephyr') subdir('exa') endif subdir('doc') @@ -754,82 +653,3 @@ install_man(configure_file( output: 'Xserver.1', configuration: manpage_config, )) - -if build_xorg - sdkconfig = configuration_data() - awk = find_program('awk') - - sdkconfig.set('prefix', get_option('prefix')) - sdkconfig.set('exec_prefix', '${prefix}') - sdkconfig.set('libdir', join_paths('${exec_prefix}', get_option('libdir'))) - sdkconfig.set('includedir', join_paths('${prefix}', get_option('includedir'))) - sdkconfig.set('datarootdir', join_paths('${prefix}', get_option('datadir'))) - sdkconfig.set('moduledir', join_paths('${exec_prefix}', module_dir)) - sdkconfig.set('sdkdir', join_paths('${prefix}', get_option('includedir'), 'xorg')) - sdkconfig.set('sysconfigdir', join_paths('${datarootdir}', 'X11/xorg.conf.d')) - - sdkconfig.set('abi_ansic', - run_command(awk, '-F', '[(,)]', - '/^#define ABI_ANSIC.*SET/ { printf "%d.%d", $2, $3 }', - files('hw/xfree86/common/xf86Module.h') - ).stdout() - ) - sdkconfig.set('abi_videodrv', - run_command(awk, '-F', '[(,)]', - '/^#define ABI_VIDEODRV.*SET/ { printf "%d.%d", $2, $3 }', - files('hw/xfree86/common/xf86Module.h') - ).stdout() - ) - sdkconfig.set('abi_xinput', - run_command(awk, '-F', '[(,)]', - '/^#define ABI_XINPUT.*SET/ { printf "%d.%d", $2, $3 }', - files('hw/xfree86/common/xf86Module.h') - ).stdout() - ) - sdkconfig.set('abi_extension', - run_command(awk, '-F', '[(,)]', - '/^#define ABI_EXTENSION.*SET/ { printf "%d.%d", $2, $3 }', - files('hw/xfree86/common/xf86Module.h') - ).stdout() - ) - - sdk_required_modules = [ - 'pixman-1 >= 0.27.2', - ] - - # XXX this isn't trying very hard, but hard enough. - sdkconfig.set('PACKAGE_VERSION', meson.project_version()) - sdkconfig.set('SDK_REQUIRED_MODULES', ' '.join(sdk_required_modules)) - sdkconfig.set('symbol_visibility', '-fvisibility=hidden') - sdkconfig.set('XORG_DRIVER_LIBS', '') - - # On Windows, modules built with the SDK will need to link with server and - # module implibs to resolve symbols - if (host_machine.system() == 'cygwin' or - host_machine.system() == 'windows') - sdkconfig.set('XORG_DRIVER_LIBS', '-lXorg.exe -L\${moduledir} -lshadow -no-undefined') - endif - - configure_file( - input: 'xorg-server.pc.in', - output: 'xorg-server.pc', - configuration: sdkconfig, - install_dir: join_paths(get_option('prefix'), - get_option('libdir'), - 'pkgconfig'), - ) - - install_data('xorg-server.m4', - install_dir: join_paths(get_option('datadir'), 'aclocal')) -endif - -if build_docs or build_docs_devel - docxmlconfig = configuration_data() - docxmlconfig.set('PACKAGE_VERSION', meson.project_version()) - docxmlconfig.set('RELEASE_DATE', release_date) - configure_file( - input: 'xserver.ent.in', - output: 'xserver.ent', - configuration: docxmlconfig - ) -endif diff --git a/meson_options.txt b/meson_options.txt index babf68a8e..887a0b4d5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,11 +1,9 @@ -option('xorg', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', - description: 'Enable Xorg X Server') option('xephyr', type: 'boolean', value: false, description: 'Enable Xephyr nested X server') option('xwayland', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Enable Xwayland X server') option('glamor', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', - description: 'Enable glamor (default yes for Xorg/Xwayland builds)') + description: 'Enable glamor (default yes for Xwayland builds)') option('xwayland_eglstream', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Enable EGLStream support for glamor on Xwayland') option('xvfb', type: 'boolean', value: true, @@ -15,9 +13,6 @@ option('xvfb', type: 'boolean', value: true, option('builder_addr', type: 'string', description: 'Builder address', value: 'xorg@lists.freedesktop.org') option('builder_string', type: 'string', description: 'Additional builder string') -option('log_dir', type: 'string') -option('module_dir', type: 'string', value: 'xorg/modules', - description: 'X.Org modules directory (absolute or relative to the directory specified by the libdir option)') option('default_font_path', type: 'string') option('glx', type: 'boolean', value: true) @@ -36,8 +31,6 @@ option('xkb_default_layout', type: 'string', value: 'us') option('xkb_default_variant', type: 'string') option('xkb_default_options', type: 'string') -option('fallback_input_driver', type: 'string', value: 'auto') - option('vendor_name', type: 'string', value: 'The X.Org Foundation') option('vendor_name_short', type: 'string', value: 'X.Org') option('vendor_web', type: 'string', value: 'http://wiki.x.org') @@ -52,21 +45,12 @@ option('listen_unix', type: 'boolean', value: true, option('listen_local', type: 'boolean', value: true, description: 'Listen on local by default') -option('int10', type: 'combo', choices: ['stub', 'x86emu', 'vm86', 'auto', 'false'], - value: 'auto', - description: 'Xorg int10 backend (default: usually x86emu)') -option('suid_wrapper', type: 'boolean', value: 'false', - description: 'SUID wrapper for legacy driver support') -option('pciaccess', type: 'boolean', value: 'true', - description: 'Xorg pciaccess support') option('udev', type: 'boolean', value: 'true') option('udev_kms', type: 'boolean', value: 'true') option('hal', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Enable HAL integration') option('systemd_logind', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Enable systemd-logind integration') -option('vgahw', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', - description: 'Xorg VGA access module') option('dpms', type: 'boolean', value: true, description: 'Xorg DPMS extension') option('xf86bigfont', type: 'boolean', value: false, @@ -85,25 +69,11 @@ option('xcsecurity', type: 'boolean', value: false, description: 'Security extension') option('xv', type: 'boolean', value: true, description: 'Xv extension') -option('xvmc', type: 'boolean', value: true, - description: 'XvMC extension') -option('dga', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', - description: 'DGA extension') -option('linux_apm', type: 'boolean', value: true, - description: 'APM support on Linux') -option('linux_acpi', type: 'boolean', value: true, - description: 'ACPI support on Linux') option('mitshm', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'SHM extension') -option('agp', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', - description: 'AGP support') option('sha1', type: 'combo', choices: ['libc', 'CommonCrypto', 'CryptoAPI', 'libmd', 'libsha1', 'libnettle', 'libgcrypt', 'libcrypto', 'auto'], value: 'auto', description: 'SHA1 implementation') -option('xf86-input-inputtest', type: 'boolean', value: true, - description: 'Test input driver support on Xorg') -option('dri1', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Build DRI1 extension (default: auto)') -option('dri2', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Build DRI2 extension (default: auto)') option('dri3', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Build DRI3 extension (default: auto)') option('drm', type: 'boolean', value: 'true', description: 'Build Xorg with libdrm support') diff --git a/mi/meson.build b/mi/meson.build index 9f97d149c..dc084f2d7 100644 --- a/mi/meson.build +++ b/mi/meson.build @@ -50,7 +50,3 @@ libxserver_mi = static_library('libxserver_mi', m_dep, ], ) - -if build_xorg - install_data(hdrs_mi, install_dir: xorgsdkdir) -endif diff --git a/miext/damage/meson.build b/miext/damage/meson.build index c7ec10938..71fb09a50 100644 --- a/miext/damage/meson.build +++ b/miext/damage/meson.build @@ -12,7 +12,3 @@ libxserver_miext_damage = static_library('libxserver_miext_damage', include_directories: inc, dependencies: common_dep, ) - -if build_xorg - install_data(hdrs_miext_damage, install_dir: xorgsdkdir) -endif diff --git a/miext/shadow/meson.build b/miext/shadow/meson.build index f91accd69..ccae2f3c0 100644 --- a/miext/shadow/meson.build +++ b/miext/shadow/meson.build @@ -34,7 +34,3 @@ libxserver_miext_shadow = static_library('libxserver_miext_shadow', include_directories: inc, dependencies: common_dep, ) - -if build_xorg - install_data(hdrs_miext_shadow, install_dir: xorgsdkdir) -endif diff --git a/miext/sync/meson.build b/miext/sync/meson.build index 0892fd807..f3ea9ed2e 100644 --- a/miext/sync/meson.build +++ b/miext/sync/meson.build @@ -22,7 +22,3 @@ libxserver_miext_sync = static_library('libxserver_miext_sync', xshmfence_dep, ], ) - -if build_xorg - install_data(hdrs_miext_sync, install_dir: xorgsdkdir) -endif diff --git a/present/meson.build b/present/meson.build index 1a74a9cbc..8bcaf51f9 100644 --- a/present/meson.build +++ b/present/meson.build @@ -24,7 +24,3 @@ libxserver_present = static_library('libxserver_present', dependency('presentproto', version: '>= 1.2') ], ) - -if build_xorg - install_data(hdrs_present, install_dir: xorgsdkdir) -endif diff --git a/randr/meson.build b/randr/meson.build index 9bd751bf2..bf0bf0953 100644 --- a/randr/meson.build +++ b/randr/meson.build @@ -30,7 +30,3 @@ libxserver_randr = static_library('libxserver_randr', include_directories: inc, dependencies: common_dep, ) - -if build_xorg - install_data(hdrs_randr, install_dir: xorgsdkdir) -endif diff --git a/render/meson.build b/render/meson.build index b95b082b3..61152c277 100644 --- a/render/meson.build +++ b/render/meson.build @@ -24,7 +24,3 @@ libxserver_render = static_library('libxserver_render', include_directories: inc, dependencies: common_dep, ) - -if build_xorg - install_data(hdrs_render, install_dir: xorgsdkdir) -endif diff --git a/test/meson.build b/test/meson.build index 4a79394e4..bfa5af4d9 100644 --- a/test/meson.build +++ b/test/meson.build @@ -116,77 +116,3 @@ endif subdir('bigreq') subdir('damage') subdir('sync') - -if build_xorg -# Tests that require at least some DDX functions in order to fully link -# For now, requires xf86 ddx, could be adjusted to use another - unit_sources = [ - '../mi/miinitext.c', - '../mi/miinitext.h', - 'fixes.c', - 'input.c', - 'list.c', - 'misc.c', - 'signal-logging.c', - 'string.c', - 'test_xkb.c', - 'tests-common.c', - 'tests.c', - 'touch.c', - 'xfree86.c', - 'xtest.c', - ] - unit_defines = ['-DXORG_TESTS'] - unit_includes = [inc, xorg_inc] - - if build_res - unit_sources += ['hashtabletest.c'] - unit_defines += ['-DRES_TESTS'] - endif - - unit_c_args = unit_defines - if meson.get_compiler('c').has_link_argument('-Wl,-wrap') - # LTO breaks with -Wl,-wrap on certain configurations - unit_c_args += ['-fno-lto'] - unit_sources += [ - 'xi1/protocol-xchangedevicecontrol.c', - 'xi2/protocol-common.c', - 'xi2/protocol-xiqueryversion.c', - 'xi2/protocol-xiquerydevice.c', - 'xi2/protocol-xiselectevents.c', - 'xi2/protocol-xigetselectedevents.c', - 'xi2/protocol-xisetclientpointer.c', - 'xi2/protocol-xigetclientpointer.c', - 'xi2/protocol-xiquerypointer.c', - 'xi2/protocol-xipassivegrabdevice.c', - 'xi2/protocol-xiwarppointer.c', - 'xi2/protocol-eventconvert.c', - 'xi2/xi2.c', - ] - unit_defines += ['-DLDWRAP_TESTS'] - unit_includes += [include_directories('xi1', 'xi2')] - ldwraps = [ - '-Wl,-wrap,dixLookupWindow', - '-Wl,-wrap,dixLookupClient', - '-Wl,-wrap,WriteToClient', - '-Wl,-wrap,dixLookupWindow', - '-Wl,-wrap,XISetEventMask', - '-Wl,-wrap,AddResource', - '-Wl,-wrap,GrabButton', - ] - else - ldwraps = [] - message('ld -wrap required for xi1 & xi2 unit tests, skipping') - endif - - unit = executable('tests', - unit_sources, - c_args: unit_c_args, - dependencies: [pixman_dep, randrproto_dep, inputproto_dep, libxcvt_dep], - include_directories: unit_includes, - link_args: ldwraps, - link_with: xorg_link, - ) - - test('unit', unit) -endif diff --git a/test/tests.c b/test/tests.c index 97603822a..f9b13980e 100644 --- a/test/tests.c +++ b/test/tests.c @@ -8,37 +8,5 @@ main(int argc, char **argv) run_test(list_test); run_test(string_test); -#ifdef XORG_TESTS - run_test(fixes_test); - run_test(input_test); - run_test(misc_test); - run_test(signal_logging_test); - run_test(touch_test); - run_test(xfree86_test); - run_test(xkb_test); - run_test(xtest_test); - -#ifdef RES_TESTS - run_test(hashtabletest_test); -#endif - -#ifdef LDWRAP_TESTS - run_test(protocol_xchangedevicecontrol_test); - - run_test(protocol_xiqueryversion_test); - run_test(protocol_xiquerydevice_test); - run_test(protocol_xiselectevents_test); - run_test(protocol_xigetselectedevents_test); - run_test(protocol_xisetclientpointer_test); - run_test(protocol_xigetclientpointer_test); - run_test(protocol_xipassivegrabdevice_test); - run_test(protocol_xiquerypointer_test); - run_test(protocol_xiwarppointer_test); - run_test(protocol_eventconvert_test); - run_test(xi2_test); -#endif - -#endif /* XORG_TESTS */ - return 0; } diff --git a/test/tests.h b/test/tests.h index b96ca78bb..e346df80a 100644 --- a/test/tests.h +++ b/test/tests.h @@ -9,7 +9,6 @@ int misc_test(void); int signal_logging_test(void); int string_test(void); int touch_test(void); -int xfree86_test(void); int xkb_test(void); int xtest_test(void); diff --git a/test/xfree86.c b/test/xfree86.c deleted file mode 100644 index 59e371633..000000000 --- a/test/xfree86.c +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright © 2011 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -/* Test relies on assert() */ -#undef NDEBUG - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include - -#include "xf86.h" -#include "xf86Parser.h" - -#include "tests-common.h" - -static void -xfree86_option_list_duplicate(void) -{ - XF86OptionPtr options; - XF86OptionPtr duplicate; - const char *o1 = "foo", *o2 = "bar", *v1 = "one", *v2 = "two"; - const char *o_null = "NULL"; - char *val1, *val2; - XF86OptionPtr a, b; - - duplicate = xf86OptionListDuplicate(NULL); - assert(!duplicate); - - options = xf86AddNewOption(NULL, o1, v1); - assert(options); - options = xf86AddNewOption(options, o2, v2); - assert(options); - options = xf86AddNewOption(options, o_null, NULL); - assert(options); - - duplicate = xf86OptionListDuplicate(options); - assert(duplicate); - - val1 = xf86CheckStrOption(options, o1, "1"); - val2 = xf86CheckStrOption(duplicate, o1, "2"); - - assert(strcmp(val1, v1) == 0); - assert(strcmp(val1, val2) == 0); - - val1 = xf86CheckStrOption(options, o2, "1"); - val2 = xf86CheckStrOption(duplicate, o2, "2"); - - assert(strcmp(val1, v2) == 0); - assert(strcmp(val1, val2) == 0); - - a = xf86FindOption(options, o_null); - b = xf86FindOption(duplicate, o_null); - assert(a); - assert(b); -} - -static void -xfree86_add_comment(void) -{ - char *current = NULL; - const char *comment; - char compare[1024] = { 0 }; - - comment = "# foo"; - current = xf86addComment(current, comment); - strcpy(compare, comment); - strcat(compare, "\n"); - - assert(!strcmp(current, compare)); - - /* this used to overflow */ - strcpy(current, "\n"); - comment = "foobar\n"; - current = xf86addComment(current, comment); - strcpy(compare, "\n#"); - strcat(compare, comment); - assert(!strcmp(current, compare)); - - free(current); -} - -int -xfree86_test(void) -{ - xfree86_option_list_duplicate(); - xfree86_add_comment(); - - return 0; -} diff --git a/xorg-server.m4 b/xorg-server.m4 deleted file mode 100644 index 195bda5d8..000000000 --- a/xorg-server.m4 +++ /dev/null @@ -1,49 +0,0 @@ -dnl Copyright 2005 Red Hat, Inc -dnl -dnl Permission to use, copy, modify, distribute, and sell this software and its -dnl documentation for any purpose is hereby granted without fee, provided that -dnl the above copyright notice appear in all copies and that both that -dnl copyright notice and this permission notice appear in supporting -dnl documentation. -dnl -dnl The above copyright notice and this permission notice shall be included -dnl in all copies or substantial portions of the Software. -dnl -dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -dnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -dnl IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -dnl OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -dnl ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -dnl OTHER DEALINGS IN THE SOFTWARE. -dnl -dnl Except as contained in this notice, the name of the copyright holders shall -dnl not be used in advertising or otherwise to promote the sale, use or -dnl other dealings in this Software without prior written authorization -dnl from the copyright holders. -dnl - -# XORG_DRIVER_CHECK_EXT(MACRO, PROTO) -# -------------------------- -# Checks for the MACRO define in xorg-server.h (from the sdk). If it -# is defined, then add the given PROTO to $REQUIRED_MODULES. - -AC_DEFUN([XORG_DRIVER_CHECK_EXT],[ - AC_REQUIRE([PKG_PROG_PKG_CONFIG]) - SAVE_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS `$PKG_CONFIG --cflags xorg-server`" - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -#include "xorg-server.h" -#if !defined $1 -#error $1 not defined -#endif - ]])], - [_EXT_CHECK=yes], - [_EXT_CHECK=no]) - CFLAGS="$SAVE_CFLAGS" - AC_MSG_CHECKING([if $1 is defined]) - AC_MSG_RESULT([$_EXT_CHECK]) - if test "$_EXT_CHECK" != no; then - REQUIRED_MODULES="$REQUIRED_MODULES $2" - fi -]) diff --git a/xorg-server.pc.in b/xorg-server.pc.in deleted file mode 100644 index 1de1c6c50..000000000 --- a/xorg-server.pc.in +++ /dev/null @@ -1,20 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ -datarootdir=@datarootdir@ -moduledir=@moduledir@ -sdkdir=@sdkdir@ -sysconfigdir=@sysconfigdir@ - -abi_ansic=@abi_ansic@ -abi_videodrv=@abi_videodrv@ -abi_xinput=@abi_xinput@ -abi_extension=@abi_extension@ - -Name: xorg-server -Description: Modular X.Org X Server -Version: @PACKAGE_VERSION@ -Requires.private: @SDK_REQUIRED_MODULES@ -Cflags: -I${sdkdir} @symbol_visibility@ -Libs: -L${libdir} @XORG_DRIVER_LIBS@