xserver

xserver with xephyr scale patch
git clone https://git.neptards.moe/u3shit/xserver.git
Log | Files | Refs | README | LICENSE

lnx_video.c (4822B)


      1 /*
      2  * Copyright 1992 by Orest Zborowski <obz@Kodak.com>
      3  * Copyright 1993 by David Wexelblat <dwex@goblin.org>
      4  *
      5  * Permission to use, copy, modify, distribute, and sell this software and its
      6  * documentation for any purpose is hereby granted without fee, provided that
      7  * the above copyright notice appear in all copies and that both that
      8  * copyright notice and this permission notice appear in supporting
      9  * documentation, and that the names of Orest Zborowski and David Wexelblat
     10  * not be used in advertising or publicity pertaining to distribution of
     11  * the software without specific, written prior permission.  Orest Zborowski
     12  * and David Wexelblat make no representations about the suitability of this
     13  * software for any purpose.  It is provided "as is" without express or
     14  * implied warranty.
     15  *
     16  * OREST ZBOROWSKI AND DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD
     17  * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
     18  * FITNESS, IN NO EVENT SHALL OREST ZBOROWSKI OR DAVID WEXELBLAT BE LIABLE
     19  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     20  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     21  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     22  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     23  *
     24  */
     25 
     26 #ifdef HAVE_XORG_CONFIG_H
     27 #include <xorg-config.h>
     28 #endif
     29 
     30 #include <errno.h>
     31 #include <string.h>
     32 
     33 #include <X11/X.h>
     34 #include "input.h"
     35 #include "scrnintstr.h"
     36 
     37 #include "xf86.h"
     38 #include "xf86Priv.h"
     39 #include "xf86_OSlib.h"
     40 #include "xf86OSpriv.h"
     41 
     42 static Bool ExtendedEnabled = FALSE;
     43 
     44 #ifdef __ia64__
     45 
     46 #include "compiler.h"
     47 #include <sys/io.h>
     48 
     49 #elif !defined(__powerpc__) && \
     50       !defined(__mc68000__) && \
     51       !defined(__sparc__) && \
     52       !defined(__mips__) && \
     53       !defined(__nds32__) && \
     54       !defined(__arm__) && \
     55       !defined(__aarch64__) && \
     56       !defined(__arc__) && \
     57       !defined(__xtensa__)
     58 
     59 /*
     60  * Due to conflicts with "compiler.h", don't rely on <sys/io.h> to declare
     61  * these.
     62  */
     63 extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on);
     64 extern int iopl(int __level);
     65 
     66 #endif
     67 
     68 /***************************************************************************/
     69 /* Video Memory Mapping section                                            */
     70 /***************************************************************************/
     71 
     72 void
     73 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
     74 {
     75     pVidMem->initialised = TRUE;
     76 }
     77 
     78 /***************************************************************************/
     79 /* I/O Permissions section                                                 */
     80 /***************************************************************************/
     81 
     82 #if defined(__powerpc__)
     83 volatile unsigned char *ioBase = NULL;
     84 
     85 #ifndef __NR_pciconfig_iobase
     86 #define __NR_pciconfig_iobase	200
     87 #endif
     88 
     89 static Bool
     90 hwEnableIO(void)
     91 {
     92     int fd;
     93     unsigned int ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0);
     94 
     95     fd = open("/dev/mem", O_RDWR);
     96     if (ioBase == NULL) {
     97         ioBase = (volatile unsigned char *) mmap(0, 0x20000,
     98                                                  PROT_READ | PROT_WRITE,
     99                                                  MAP_SHARED, fd, ioBase_phys);
    100     }
    101     close(fd);
    102 
    103     return ioBase != MAP_FAILED;
    104 }
    105 
    106 static void
    107 hwDisableIO(void)
    108 {
    109     munmap(ioBase, 0x20000);
    110     ioBase = NULL;
    111 }
    112 
    113 #elif defined(__i386__) || defined(__x86_64__) || defined(__ia64__) || \
    114       defined(__alpha__)
    115 
    116 static Bool
    117 hwEnableIO(void)
    118 {
    119     short i;
    120     size_t n=0;
    121     int begin, end;
    122     char *buf=NULL, target[5];
    123     FILE *fp;
    124 
    125     if (ioperm(0, 1024, 1)) {
    126         ErrorF("xf86EnableIO: failed to enable I/O ports 0000-03ff (%s)\n",
    127                strerror(errno));
    128         return FALSE;
    129     }
    130 
    131 #if !defined(__alpha__)
    132     target[4] = '\0';
    133 
    134     /* trap access to the keyboard controller(s) and timer chip(s) */
    135     fp = fopen("/proc/ioports", "r");
    136     while (getline(&buf, &n, fp) != -1) {
    137         if ((strstr(buf, "keyboard") != NULL) || (strstr(buf, "timer") != NULL)) {
    138             for (i=0; i<4; i++)
    139                 target[i] = buf[i+2];
    140             begin = atoi(target);
    141 
    142             for (i=0; i<4; i++)
    143                 target[i] = buf[i+7];
    144             end = atoi(target);
    145 
    146             ioperm(begin, end-begin+1, 0);
    147         }
    148     }
    149     free(buf);
    150     fclose(fp);
    151 #endif
    152 
    153     return TRUE;
    154 }
    155 
    156 static void
    157 hwDisableIO(void)
    158 {
    159     iopl(0);
    160     ioperm(0, 1024, 0);
    161 }
    162 
    163 #else /* non-IO architectures */
    164 
    165 #define hwEnableIO() TRUE
    166 #define hwDisableIO() do {} while (0)
    167 
    168 #endif
    169 
    170 Bool
    171 xf86EnableIO(void)
    172 {
    173     if (ExtendedEnabled)
    174         return TRUE;
    175 
    176     ExtendedEnabled = hwEnableIO();
    177 
    178     return ExtendedEnabled;
    179 }
    180 
    181 void
    182 xf86DisableIO(void)
    183 {
    184     if (!ExtendedEnabled)
    185         return;
    186 
    187     hwDisableIO();
    188 
    189     ExtendedEnabled = FALSE;
    190 }