2003-11-14 15:54:54 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 1992 by Orest Zborowski <obz@Kodak.com>
|
|
|
|
|
* Copyright 1993 by David Wexelblat <dwex@goblin.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 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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2005-07-03 07:02:09 +00:00
|
|
|
#ifdef HAVE_XORG_CONFIG_H
|
|
|
|
|
#include <xorg-config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-08-26 06:48:24 +00:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2005-04-20 12:25:48 +00:00
|
|
|
#include <X11/X.h>
|
2003-11-14 15:54:54 +00:00
|
|
|
#include "input.h"
|
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
|
|
|
|
|
|
#include "xf86.h"
|
|
|
|
|
#include "xf86Priv.h"
|
|
|
|
|
#include "xf86_OSlib.h"
|
2003-11-14 16:49:22 +00:00
|
|
|
#include "xf86OSpriv.h"
|
2003-11-14 15:54:54 +00:00
|
|
|
|
2003-11-14 16:49:22 +00:00
|
|
|
static Bool ExtendedEnabled = FALSE;
|
|
|
|
|
|
|
|
|
|
#ifdef __ia64__
|
|
|
|
|
|
|
|
|
|
#include "compiler.h"
|
|
|
|
|
#include <sys/io.h>
|
|
|
|
|
|
|
|
|
|
#elif !defined(__powerpc__) && \
|
|
|
|
|
!defined(__mc68000__) && \
|
|
|
|
|
!defined(__sparc__) && \
|
2007-06-18 12:05:55 -04:00
|
|
|
!defined(__mips__) && \
|
2010-09-21 15:13:31 +08:00
|
|
|
!defined(__nds32__) && \
|
2013-08-15 12:03:42 +02:00
|
|
|
!defined(__arm__) && \
|
2014-05-01 15:39:29 +03:00
|
|
|
!defined(__aarch64__) && \
|
2014-06-02 01:17:31 +04:00
|
|
|
!defined(__arc__) && \
|
|
|
|
|
!defined(__xtensa__)
|
2003-11-14 15:54:54 +00:00
|
|
|
|
|
|
|
|
/*
|
2003-11-14 16:49:22 +00:00
|
|
|
* Due to conflicts with "compiler.h", don't rely on <sys/io.h> to declare
|
|
|
|
|
* these.
|
2003-11-14 15:54:54 +00:00
|
|
|
*/
|
2003-11-14 16:49:22 +00:00
|
|
|
extern int ioperm(unsigned long __from, unsigned long __num, int __turn_on);
|
|
|
|
|
extern int iopl(int __level);
|
2003-11-14 15:54:54 +00:00
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/***************************************************************************/
|
2003-11-14 16:49:22 +00:00
|
|
|
/* Video Memory Mapping section */
|
2003-11-14 15:54:54 +00:00
|
|
|
/***************************************************************************/
|
|
|
|
|
|
2003-11-14 16:49:22 +00:00
|
|
|
void
|
|
|
|
|
xf86OSInitVidMem(VidMemInfoPtr pVidMem)
|
|
|
|
|
{
|
2012-03-21 12:55:09 -07:00
|
|
|
pVidMem->initialised = TRUE;
|
2003-11-14 15:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-14 16:49:22 +00:00
|
|
|
/***************************************************************************/
|
|
|
|
|
/* I/O Permissions section */
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#if defined(__powerpc__)
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 05:43:34 -02:00
|
|
|
volatile unsigned char *ioBase = NULL;
|
2003-11-14 16:49:22 +00:00
|
|
|
|
|
|
|
|
#ifndef __NR_pciconfig_iobase
|
|
|
|
|
#define __NR_pciconfig_iobase 200
|
2003-11-14 15:54:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-06-26 13:12:45 -04:00
|
|
|
static Bool
|
|
|
|
|
hwEnableIO(void)
|
2003-11-14 16:49:22 +00:00
|
|
|
{
|
2012-03-21 12:55:09 -07:00
|
|
|
int fd;
|
2012-06-26 13:12:45 -04:00
|
|
|
unsigned int ioBase_phys = syscall(__NR_pciconfig_iobase, 2, 0, 0);
|
2003-11-14 16:49:22 +00:00
|
|
|
|
2012-03-21 12:55:09 -07:00
|
|
|
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);
|
2012-06-26 13:12:45 -04:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2012-03-21 12:55:09 -07:00
|
|
|
if (ioperm(0, 1024, 1) || iopl(3)) {
|
2012-06-26 13:15:45 -04:00
|
|
|
ErrorF("xf86EnableIOPorts: failed to set IOPL for I/O (%s)\n",
|
|
|
|
|
strerror(errno));
|
2012-03-21 12:55:09 -07:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
#if !defined(__alpha__)
|
|
|
|
|
/* XXX: this is actually not trapping anything because of iopl(3)
|
|
|
|
|
* above */
|
|
|
|
|
ioperm(0x40, 4, 0); /* trap access to the timer chip */
|
|
|
|
|
ioperm(0x60, 4, 0); /* trap access to the keyboard controller */
|
|
|
|
|
#endif
|
2003-11-14 16:49:22 +00:00
|
|
|
|
2012-03-21 12:55:09 -07:00
|
|
|
return TRUE;
|
2003-11-14 15:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-26 13:12:45 -04:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
Rework symbol visibility for easier maintenance
Save in a few special cases, _X_EXPORT should not be used in C source
files. Instead, it should be used in headers, and the proper C source
include that header. Some special cases are symbols that need to be
shared between modules, but not expected to be used by external drivers,
and symbols that are accessible via LoaderSymbol/dlopen.
This patch also adds conditionally some new sdk header files, depending
on extensions enabled. These files were added to match pattern for
other extensions/modules, that is, have the headers "deciding" symbol
visibility in the sdk. These headers are:
o Xext/panoramiXsrv.h, Xext/panoramiX.h
o fbpict.h (unconditionally)
o vidmodeproc.h
o mioverlay.h (unconditionally, used only by xaa)
o xfixes.h (unconditionally, symbols required by dri2)
LoaderSymbol and similar functions now don't have different prototypes,
in loaderProcs.h and xf86Module.h, so that both headers can be included,
without the need of defining IN_LOADER.
xf86NewInputDevice() device prototype readded to xf86Xinput.h, but
not exported (and with a comment about it).
2008-12-03 05:43:34 -02:00
|
|
|
void
|
2003-11-14 16:49:22 +00:00
|
|
|
xf86DisableIO(void)
|
2003-11-14 15:54:54 +00:00
|
|
|
{
|
2012-03-21 12:55:09 -07:00
|
|
|
if (!ExtendedEnabled)
|
|
|
|
|
return;
|
2003-11-14 16:49:22 +00:00
|
|
|
|
2012-06-26 13:12:45 -04:00
|
|
|
hwDisableIO();
|
|
|
|
|
|
|
|
|
|
ExtendedEnabled = FALSE;
|
2003-11-14 15:54:54 +00:00
|
|
|
}
|
|
|
|
|
|
2003-11-14 16:49:22 +00:00
|
|
|
#if defined (__alpha__)
|
2003-11-14 15:54:54 +00:00
|
|
|
|
2013-12-15 01:05:51 -08:00
|
|
|
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);
|
2003-11-14 16:49:22 +00:00
|
|
|
extern void
|
2013-12-15 01:05:51 -08:00
|
|
|
writeDense8(int Value, void *Base, register unsigned long Offset);
|
2003-11-14 16:49:22 +00:00
|
|
|
extern void
|
2013-12-15 01:05:51 -08:00
|
|
|
writeDense16(int Value, void *Base, register unsigned long Offset);
|
2003-11-14 16:49:22 +00:00
|
|
|
extern void
|
2013-12-15 01:05:51 -08:00
|
|
|
writeDense32(int Value, void *Base, register unsigned long Offset);
|
2003-11-14 16:49:22 +00:00
|
|
|
|
2013-12-15 01:05:51 -08:00
|
|
|
void (*xf86WriteMmio8) (int Value, void *Base, unsigned long Offset)
|
2012-03-21 12:55:09 -07:00
|
|
|
= writeDense8;
|
2013-12-15 01:05:51 -08:00
|
|
|
void (*xf86WriteMmio16) (int Value, void *Base, unsigned long Offset)
|
2012-03-21 12:55:09 -07:00
|
|
|
= writeDense16;
|
2013-12-15 01:05:51 -08:00
|
|
|
void (*xf86WriteMmio32) (int Value, void *Base, unsigned long Offset)
|
2012-03-21 12:55:09 -07:00
|
|
|
= writeDense32;
|
2013-12-15 01:05:51 -08:00
|
|
|
int (*xf86ReadMmio8) (void *Base, unsigned long Offset)
|
2012-03-21 12:55:09 -07:00
|
|
|
= readDense8;
|
2013-12-15 01:05:51 -08:00
|
|
|
int (*xf86ReadMmio16) (void *Base, unsigned long Offset)
|
2012-03-21 12:55:09 -07:00
|
|
|
= readDense16;
|
2013-12-15 01:05:51 -08:00
|
|
|
int (*xf86ReadMmio32) (void *Base, unsigned long Offset)
|
2012-03-21 12:55:09 -07:00
|
|
|
= readDense32;
|
|
|
|
|
|
|
|
|
|
#endif /* __alpha__ */
|