Modifying X.Org Xserver DDX to allow to run X with ordinary user

permissions when no access to HW registers is required. For API changes
    which mostly involve the modifications to make the RRFunc (introduced
    with 6.8) more flexible please check Bugzilla #2407. NOTE: This patch
    applies changes to OS specific files for other OSes which I cannot
    test.
This commit is contained in:
Egbert Eich 2005-01-28 16:13:00 +00:00
commit d23c46dd3e
27 changed files with 539 additions and 327 deletions

View file

@ -208,13 +208,6 @@
#define PCI_MFDEV_SUPPORT 1 /* Include PCI multifunction device support */
#define PCI_BRIDGE_SUPPORT 1 /* Include support for PCI-to-PCI bridges */
#ifdef PC98
#define outb(port,data) _outb(port,data)
#define outl(port,data) _outl(port,data)
#define inb(port) _inb(port)
#define inl(port) _inl(port)
#endif
/*
* Global data
*/
@ -833,90 +826,6 @@ pciGenFindFirst(void)
return pciGenFindNext();
}
#if defined (__powerpc__)
static int buserr_detected;
static
void buserr(int sig)
{
buserr_detected = 1;
}
#endif
CARD32
pciCfgMech1Read(PCITAG tag, int offset)
{
unsigned long rv = 0xffffffff;
#ifdef DEBUGPCI
ErrorF("pciCfgMech1Read(tag=%08x,offset=%08x)\n", tag, offset);
#endif
#if defined(__powerpc__)
signal(SIGBUS, buserr);
buserr_detected = 0;
#endif
outl(0xCF8, PCI_EN | tag | (offset & 0xfc));
rv = inl(0xCFC);
#if defined(__powerpc__)
signal(SIGBUS, SIG_DFL);
if (buserr_detected)
{
#ifdef DEBUGPCI
ErrorF("pciCfgMech1Read() BUS ERROR\n");
#endif
return(0xffffffff);
}
else
#endif
return(rv);
}
void
pciCfgMech1Write(PCITAG tag, int offset, CARD32 val)
{
#ifdef DEBUGPCI
ErrorF("pciCfgMech1Write(tag=%08x,offset=%08x,val=%08x)\n",
tag, offset,val);
#endif
#if defined(__powerpc__)
signal(SIGBUS, SIG_IGN);
#endif
outl(0xCF8, PCI_EN | tag | (offset & 0xfc));
#if defined(Lynx) && defined(__powerpc__)
outb(0x80, 0x00); /* without this the next access fails
* on my Powerstack system when we use
* assembler inlines for outl */
#endif
outl(0xCFC, val);
#if defined(__powerpc__)
signal(SIGBUS, SIG_DFL);
#endif
}
void
pciCfgMech1SetBits(PCITAG tag, int offset, CARD32 mask, CARD32 val)
{
unsigned long rv = 0xffffffff;
#if defined(__powerpc__)
signal(SIGBUS, buserr);
#endif
outl(0xCF8, PCI_EN | tag | (offset & 0xfc));
rv = inl(0xCFC);
rv = (rv & ~mask) | val;
outl(0xCFC, rv);
#if defined(__powerpc__)
signal(SIGBUS, SIG_DFL);
#endif
}
CARD32
pciByteSwap(CARD32 u)
{

View file

@ -140,6 +140,7 @@
#include "compiler.h"
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"
#include "Pci.h"
#ifdef PC98
@ -278,6 +279,8 @@ void ix86PciSelectCfgmech(void)
#endif
case PCIProbe1:
if (!xf86EnableIO())
return;
xf86MsgVerb(X_INFO, 2,
"PCI: Probing config type using method 1\n");
@ -449,6 +452,8 @@ void ix86PciSelectCfgmech(void)
break; /* } */
case PCIProbe2: /* { */
if (!xf86EnableIO())
return;
/* The scanpci-style detection method */
@ -481,6 +486,8 @@ void ix86PciSelectCfgmech(void)
break; /* } */
case PCIForceConfig1:
if (!xf86EnableIO())
return;
xf86MsgVerb(X_INFO, 2, "PCI: Forcing config type 1\n");
@ -490,6 +497,8 @@ void ix86PciSelectCfgmech(void)
return;
case PCIForceConfig2:
if (!xf86EnableIO())
return;
xf86MsgVerb(X_INFO, 2, "PCI: Forcing config type 2\n");

View file

@ -99,9 +99,9 @@ linuxPciInit()
}
static int
linuxPciOpenFile(PCITAG tag)
linuxPciOpenFile(PCITAG tag, Bool write)
{
static int lbus,ldev,lfunc,fd = -1;
static int lbus,ldev,lfunc,fd = -1,is_write = 0;
int bus, dev, func;
char file[32];
struct stat ignored;
@ -109,7 +109,8 @@ linuxPciOpenFile(PCITAG tag)
bus = PCI_BUS_FROM_TAG(tag);
dev = PCI_DEV_FROM_TAG(tag);
func = PCI_FUNC_FROM_TAG(tag);
if (fd == -1 || bus != lbus || dev != ldev || func != lfunc) {
if (fd == -1 || (write && (!is_write))
|| bus != lbus || dev != ldev || func != lfunc) {
if (fd != -1)
close(fd);
if (bus < 256) {
@ -129,7 +130,19 @@ linuxPciOpenFile(PCITAG tag)
sprintf(file, "/proc/bus/pci/%04x/%02x.%1x",
bus, dev, func);
}
fd = open(file,O_RDWR);
if (write) {
fd = open(file,O_RDWR);
if (fd != -1) is_write = TRUE;
} else switch (is_write) {
case TRUE:
fd = open(file,O_RDWR);
if (fd > -1)
break;
default:
fd = open(file,O_RDONLY);
is_write = FALSE;
}
lbus = bus;
ldev = dev;
lfunc = func;
@ -143,7 +156,7 @@ linuxPciCfgRead(PCITAG tag, int off)
int fd;
CARD32 val = 0xffffffff;
if (-1 != (fd = linuxPciOpenFile(tag))) {
if (-1 != (fd = linuxPciOpenFile(tag,FALSE))) {
lseek(fd,off,SEEK_SET);
read(fd,&val,4);
}
@ -155,7 +168,7 @@ linuxPciCfgWrite(PCITAG tag, int off, CARD32 val)
{
int fd;
if (-1 != (fd = linuxPciOpenFile(tag))) {
if (-1 != (fd = linuxPciOpenFile(tag,TRUE))) {
lseek(fd,off,SEEK_SET);
val = PCI_CPU(val);
write(fd,&val,4);
@ -168,7 +181,7 @@ linuxPciCfgSetBits(PCITAG tag, int off, CARD32 mask, CARD32 bits)
int fd;
CARD32 val = 0xffffffff;
if (-1 != (fd = linuxPciOpenFile(tag))) {
if (-1 != (fd = linuxPciOpenFile(tag,TRUE))) {
lseek(fd,off,SEEK_SET);
read(fd,&val,4);
val = PCI_CPU(val);
@ -336,7 +349,7 @@ xf86GetPciDomain(PCITAG Tag)
if (pPCI && (result = PCI_DOM_FROM_BUS(pPCI->busnum)))
return result;
if ((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0)) < 0)
if ((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0)
return 0;
if ((result = ioctl(fd, PCIIOC_CONTROLLER, 0)) < 0)
@ -359,7 +372,7 @@ linuxMapPci(int ScreenNum, int Flags, PCITAG Tag,
pPCI = xf86GetPciHostConfigFromTag(Tag);
if (((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0)) < 0) ||
if (((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0) ||
(ioctl(fd, mmap_ioctl, 0) < 0))
break;

View file

@ -1,4 +1,4 @@
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c,v 1.9 2002/08/27 22:07:07 tsi Exp $ */
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/ppcPci.c,v 1.8 2002/07/24 19:06:52 tsi Exp $ */
/*
* ppcPci.c - PowerPC PCI access functions
*
@ -78,14 +78,15 @@ ppcPciInit()
pmaxPciInit();
#else
extern void motoppcPciInit(void);
static void motoppcPciInit(void);
motoppcPciInit();
#endif
}
#if defined(PowerMAX_OS)
/*
* Motorola PowerPC platform support
*
@ -101,6 +102,11 @@ ppcPciInit()
*/
static ADDRESS motoppcBusAddrToHostAddr(PCITAG, PciAddrType, ADDRESS);
static ADDRESS motoppcHostAddrToBusAddr(PCITAG, PciAddrType, ADDRESS);
static CARD32 pciCfgMech1Read(PCITAG tag, int offset);
static void pciCfgMech1Write(PCITAG tag, int offset, CARD32 val);
static void pciCfgMech1SetBits(PCITAG tag, int offset,
CARD32 mask, CARD32 val);
static pciBusFuncs_t motoppcFuncs0 = {
/* pciReadLong */ pciCfgMech1Read,
@ -126,7 +132,7 @@ static pciBusInfo_t motoppcPci0 = {
extern volatile unsigned char *ioBase;
void
static void
motoppcPciInit()
{
pciNumBuses = 1;
@ -134,6 +140,9 @@ motoppcPciInit()
pciFindFirstFP = pciGenFindFirst;
pciFindNextFP = pciGenFindNext;
if (!xf86EnableIO())
FatalError("motoppcPciInit: EnableIO failed\n");
if (ioBase == MAP_FAILED) {
ppcPciIoMap(0); /* Make inb/outb et al work for pci0 and its secondaries */
@ -210,3 +219,89 @@ motoppcHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr)
/*NOTREACHED*/
}
#if defined (__powerpc__)
static int buserr_detected;
static
void buserr(int sig)
{
buserr_detected = 1;
}
#endif
static CARD32
pciCfgMech1Read(PCITAG tag, int offset)
{
unsigned long rv = 0xffffffff;
#ifdef DEBUGPCI
ErrorF("pciCfgMech1Read(tag=%08x,offset=%08x)\n", tag, offset);
#endif
#if defined(__powerpc__)
signal(SIGBUS, buserr);
buserr_detected = 0;
#endif
outl(0xCF8, PCI_EN | tag | (offset & 0xfc));
rv = inl(0xCFC);
#if defined(__powerpc__)
signal(SIGBUS, SIG_DFL);
if (buserr_detected)
{
#ifdef DEBUGPCI
ErrorF("pciCfgMech1Read() BUS ERROR\n");
#endif
return(0xffffffff);
}
else
#endif
return(rv);
}
static void
pciCfgMech1Write(PCITAG tag, int offset, CARD32 val)
{
#ifdef DEBUGPCI
ErrorF("pciCfgMech1Write(tag=%08x,offset=%08x,val=%08x)\n",
tag, offset,val);
#endif
#if defined(__powerpc__)
signal(SIGBUS, SIG_IGN);
#endif
outl(0xCF8, PCI_EN | tag | (offset & 0xfc));
#if defined(Lynx) && defined(__powerpc__)
outb(0x80, 0x00); /* without this the next access fails
* on my Powerstack system when we use
* assembler inlines for outl */
#endif
outl(0xCFC, val);
#if defined(__powerpc__)
signal(SIGBUS, SIG_DFL);
#endif
}
static void
pciCfgMech1SetBits(PCITAG tag, int offset, CARD32 mask, CARD32 val)
{
unsigned long rv = 0xffffffff;
#if defined(__powerpc__)
signal(SIGBUS, buserr);
#endif
outl(0xCF8, PCI_EN | tag | (offset & 0xfc));
rv = inl(0xCFC);
rv = (rv & ~mask) | val;
outl(0xCFC, rv);
#if defined(__powerpc__)
signal(SIGBUS, SIG_DFL);
#endif
}
#endif /* PowerMAX_OS */