2003-11-14 16:54:54 +01:00
|
|
|
/*
|
|
|
|
* Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany
|
|
|
|
* 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 Thomas Roell and David Wexelblat
|
|
|
|
* not be used in advertising or publicity pertaining to distribution of
|
|
|
|
* the software without specific, written prior permission. Thomas Roell and
|
|
|
|
* David Wexelblat 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 DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
|
|
|
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS, IN NO EVENT SHALL THOMAS ROELL 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 09:02:09 +02:00
|
|
|
#ifdef HAVE_XORG_CONFIG_H
|
|
|
|
#include <xorg-config.h>
|
|
|
|
#endif
|
|
|
|
|
2005-04-20 14:25:48 +02:00
|
|
|
#include <X11/X.h>
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
#define _NEED_SYSI86
|
|
|
|
#include "xf86.h"
|
|
|
|
#include "xf86Priv.h"
|
|
|
|
#include "xf86_OSlib.h"
|
2003-11-14 17:49:22 +01:00
|
|
|
#include "xf86OSpriv.h"
|
|
|
|
|
|
|
|
#ifndef MAP_FAILED
|
|
|
|
#define MAP_FAILED ((void *)-1)
|
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
#ifndef SI86IOPL
|
|
|
|
#define SET_IOPL() sysi86(SI86V86,V86SC_IOPL,PS_IOPL)
|
|
|
|
#define RESET_IOPL() sysi86(SI86V86,V86SC_IOPL,0)
|
|
|
|
#else
|
|
|
|
#define SET_IOPL() sysi86(SI86IOPL,3)
|
|
|
|
#define RESET_IOPL() sysi86(SI86IOPL,0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/* Video Memory Mapping section */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
/*
|
|
|
|
* XXX Support for SVR3 will need to be reworked if needed. In particular
|
|
|
|
* the Region parameter is no longer passed, and will need to be dealt
|
|
|
|
* with internally if required.
|
|
|
|
* OK, i'll rework that thing ... (clean it up a lot)
|
|
|
|
* SVR3 Support only with SVR3_MMAPDRV (mr)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAS_SVR3_MMAPDRV
|
|
|
|
#ifndef MMAP_DEBUG
|
|
|
|
#define MMAP_DEBUG 3
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
2003-11-14 17:49:22 +01:00
|
|
|
|
|
|
|
struct kd_memloc MapDSC;
|
|
|
|
int mmapFd = -2;
|
|
|
|
|
|
|
|
static int
|
|
|
|
mmapStat(pointer Base, unsigned long Size) {
|
|
|
|
|
|
|
|
int nmmreg,i=0,region=-1;
|
|
|
|
mmapinfo_t *ibuf;
|
|
|
|
|
|
|
|
nmmreg = ioctl(mmapFd, GETNMMREG);
|
|
|
|
|
|
|
|
if(nmmreg <= 0)
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"\nNo physical memory mapped currently.\n\n");
|
|
|
|
else {
|
|
|
|
if((ibuf = (mmapinfo_t *)malloc(nmmreg*sizeof(mmapinfo_t))) == NULL)
|
|
|
|
xf86Msg(X_WARNING,
|
|
|
|
"Couldn't allocate memory 4 mmapinfo_t\n");
|
|
|
|
else {
|
|
|
|
if(ioctl(mmapFd, GETMMREG, ibuf) != -1)
|
|
|
|
{
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"# mmapStat: [Size=%x,Base=%x]\n", Size, Base);
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"# Physical Address Size Reference Count\n");
|
|
|
|
for(i = 0; i < nmmreg; i++) {
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"%-4d 0x%08X %5dk %5d ",
|
|
|
|
i, ibuf[i].physaddr, ibuf[i].length/1024, ibuf[i].refcnt);
|
|
|
|
if (ibuf[i].physaddr == Base || ibuf[i].length == Size ) {
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,"MATCH !!!");
|
|
|
|
if (region==-1) region=i;
|
|
|
|
}
|
|
|
|
xf86ErrorFVerb(MMAP_DEBUG, "\n");
|
|
|
|
}
|
|
|
|
xf86ErrorFVerb(MMAP_DEBUG, "\n");
|
|
|
|
}
|
|
|
|
free(ibuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (region == -1 && nmmreg > 0) region=region * i;
|
|
|
|
return(region);
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
|
|
|
|
static Bool
|
|
|
|
linearVidMem()
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
#ifdef SVR4
|
|
|
|
return TRUE;
|
2003-11-14 17:49:22 +01:00
|
|
|
#elif defined(HAS_SVR3_MMAPDRV)
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"# xf86LinearVidMem: MMAP 2.2.2 called\n");
|
|
|
|
|
|
|
|
if(mmapFd >= 0) return TRUE;
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
if ((mmapFd = open("/dev/mmap", O_RDWR)) != -1)
|
|
|
|
{
|
|
|
|
if(ioctl(mmapFd, GETVERSION) < 0x0222) {
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_WARNING,
|
|
|
|
"xf86LinearVidMem: MMAP 2.2.2 or above required\n");
|
|
|
|
xf86ErrorF("\tlinear memory access disabled\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86Msg(X_WARNING, "xf86LinearVidMem: failed to open /dev/mmap (%s)\n",
|
|
|
|
strerror(errno));
|
|
|
|
xf86ErrorF("\tlinear memory access disabled\n");
|
2003-11-14 16:54:54 +01:00
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
static pointer
|
|
|
|
mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
pointer base;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
#if defined(SVR4)
|
2003-11-25 20:29:01 +01:00
|
|
|
fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
|
|
|
|
if (fd < 0)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
FatalError("xf86MapVidMem: failed to open %s (%s)\n",
|
|
|
|
DEV_MEM, strerror(errno));
|
|
|
|
}
|
2003-11-25 20:29:01 +01:00
|
|
|
base = mmap((caddr_t)0, Size,
|
|
|
|
(flags & VIDMEM_READONLY) ?
|
|
|
|
PROT_READ : (PROT_READ | PROT_WRITE),
|
|
|
|
MAP_SHARED, fd, (off_t)Base);
|
2003-11-14 16:54:54 +01:00
|
|
|
close(fd);
|
2003-11-14 17:49:22 +01:00
|
|
|
if (base == MAP_FAILED)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
|
|
|
|
"xf86MapVidMem", Size, Base, strerror(errno));
|
|
|
|
}
|
|
|
|
#else /* SVR4 */
|
|
|
|
#ifdef HAS_SVR3_MMAPDRV
|
2003-11-14 17:49:22 +01:00
|
|
|
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG, "# xf86MapVidMem: MMAP 2.2.2 called\n");
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"MMAP_VERSION: 0x%x\n",ioctl(mmapFd, GETVERSION));
|
|
|
|
if (ioctl(mmapFd, GETVERSION) == -1)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86LinearVidMem();
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"MMAP_VERSION: 0x%x\n",ioctl(mmapFd, GETVERSION));
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"xf86MapVidMem: Screen: %d\n", ScreenNum);
|
|
|
|
mmapStat(Base,Size);
|
|
|
|
/* To force the MMAP driver to provide the address */
|
|
|
|
base = (pointer)0;
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"xf86MapVidMem: [s=%x,a=%x]\n", Size, Base);
|
|
|
|
MapDSC.vaddr = (char *)base;
|
|
|
|
MapDSC.physaddr = (char *)Base;
|
|
|
|
MapDSC.length = Size;
|
|
|
|
MapDSC.ioflg = 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
if(mmapFd >= 0)
|
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
if((base = (pointer)ioctl(mmapFd, MAP, &MapDSC)) == (pointer)-1)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
FatalError("%s: Could not mmap framebuffer [s=%x,a=%x] (%s)\n",
|
|
|
|
"xf86MapVidMem", Size, Base, strerror(errno));
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Next time we want the same address! */
|
2003-11-14 17:49:22 +01:00
|
|
|
MapDSC.vaddr = (char *)base;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"MapDSC.vaddr : 0x%x\n", MapDSC.vaddr);
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"MapDSC.physaddr: 0x%x\n", MapDSC.physaddr);
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"MapDSC.length : %d\n", MapDSC.length);
|
|
|
|
mmapStat(Base,Size);
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"xf86MapVidMem: [s=%x,a=%x,b=%x]\n", Size, Base, base);
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"xf86MapVidMem: SUCCEED Mapping FrameBuffer \n");
|
|
|
|
#endif /* HAS_SVR3_MMAPDRV */
|
|
|
|
#endif /* SVR4 */
|
|
|
|
return(base);
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
2003-11-14 17:49:22 +01:00
|
|
|
static void
|
|
|
|
unmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
#if defined (SVR4)
|
|
|
|
munmap(Base, Size);
|
|
|
|
#else /* SVR4 */
|
|
|
|
#ifdef HAS_SVR3_MMAPDRV
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"# xf86UnMapVidMem: UNMapping FrameBuffer\n");
|
|
|
|
mmapStat(Base,Size);
|
|
|
|
ioctl(mmapFd, UNMAPRM , Base);
|
|
|
|
mmapStat(Base,Size);
|
|
|
|
xf86MsgVerb(X_INFO, MMAP_DEBUG,
|
|
|
|
"# xf86UnMapVidMem: Screen: %d [v=%x]\n", ScreenNum, Base);
|
|
|
|
#endif /* HAS_SVR3_MMAPDRV */
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif /* SVR4 */
|
2003-11-14 17:49:22 +01:00
|
|
|
return;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2007-10-15 03:07:03 +02:00
|
|
|
#if defined(SVR4) && defined(__i386__) && !defined(sun)
|
2003-11-14 17:49:22 +01:00
|
|
|
/*
|
|
|
|
* For some SVR4 versions, a 32-bit read is done for the first location
|
|
|
|
* in each page when the page is first mapped. If this is done while
|
|
|
|
* memory access is enabled for regions that have read side-effects,
|
|
|
|
* this can cause unexpected results, including lockups on some hardware.
|
|
|
|
* This function is called to make sure each page is mapped while it is
|
|
|
|
* safe to do so.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Should get this the correct way (see os/xalloc.c), but since this is
|
|
|
|
* for one platform I'll be lazy.
|
|
|
|
*/
|
|
|
|
#define X_PAGE_SIZE 4096
|
|
|
|
|
|
|
|
static void
|
|
|
|
readSideEffects(int ScreenNum, pointer Base, unsigned long Size)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
unsigned long base, end, addr;
|
|
|
|
CARD32 val;
|
|
|
|
|
|
|
|
base = (unsigned long)Base;
|
|
|
|
end = base + Size;
|
|
|
|
|
|
|
|
for (addr = base; addr < end; addr += X_PAGE_SIZE)
|
|
|
|
val = *(volatile CARD32 *)addr;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
#endif
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2003-11-14 17:49:22 +01:00
|
|
|
void
|
|
|
|
xf86OSInitVidMem(VidMemInfoPtr pVidMem)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2003-11-14 17:49:22 +01:00
|
|
|
pVidMem->linearSupported = linearVidMem();
|
|
|
|
pVidMem->mapMem = mapVidMem;
|
|
|
|
pVidMem->unmapMem = unmapVidMem;
|
2007-10-15 03:07:03 +02:00
|
|
|
#if defined(SVR4) && defined(__i386__) && !defined(sun)
|
2003-11-14 17:49:22 +01:00
|
|
|
pVidMem->readSideEffects = readSideEffects;
|
2003-11-14 16:54:54 +01:00
|
|
|
#endif
|
2003-11-14 17:49:22 +01:00
|
|
|
pVidMem->initialised = TRUE;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
2003-11-14 17:49:22 +01:00
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* I/O Permissions section */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
static Bool ExtendedEnabled = FALSE;
|
|
|
|
static Bool InitDone = FALSE;
|
|
|
|
|
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 08:43:34 +01:00
|
|
|
Bool
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86EnableIO()
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ExtendedEnabled)
|
2005-01-28 17:13:00 +01:00
|
|
|
return TRUE;
|
2003-11-14 16:54:54 +01:00
|
|
|
|
|
|
|
if (SET_IOPL() < 0)
|
|
|
|
{
|
2005-01-28 17:13:00 +01:00
|
|
|
xf86Msg(X_WARNING,
|
2003-11-14 17:49:22 +01:00
|
|
|
"xf86EnableIO: Failed to set IOPL for extended I/O\n");
|
2005-01-28 17:13:00 +01:00
|
|
|
return FALSE;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
ExtendedEnabled = TRUE;
|
|
|
|
|
2005-01-28 17:13:00 +01:00
|
|
|
return TRUE;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
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 08:43:34 +01:00
|
|
|
void
|
2003-11-14 17:49:22 +01:00
|
|
|
xf86DisableIO()
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
if (!ExtendedEnabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RESET_IOPL();
|
|
|
|
ExtendedEnabled = FALSE;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|