--- xorg-server-1.2.99.905/hw/xfree86/common/xf86Bus.c.device-enable 2007-02-17 20:31:36.000000000 -0500 +++ xorg-server-1.2.99.905/hw/xfree86/common/xf86Bus.c 2007-04-11 18:56:56.000000000 -0400 @@ -42,6 +42,10 @@ #include "xf86.h" #include "xf86Priv.h" #include "xf86Resources.h" +#include "Pci.h" +#include +#include +#include /* Bus-specific headers */ @@ -66,6 +70,7 @@ BusRec primaryBus = { BUS_NONE, {{0}}}; static Bool xf86ResAccessEnter = FALSE; +static int lnxEntityPrivate; #ifdef REDUCER /* Resources that temporarily conflict with estimated resources */ @@ -116,6 +121,9 @@ #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__) xf86SbusProbe(); #endif +#ifdef linux + lnxEntityPrivate = xf86AllocateEntityPrivateIndex(); +#endif } /* @@ -264,6 +272,39 @@ return FALSE; } } + +static void +lnxEntityInit(int entityIndex, pointer private) +{ + EntityProc init; + EntityPtr ent = xf86Entities[entityIndex]; + + if (ent->bus.type == BUS_PCI) do { + char file[256], buf = '\0'; + int fd; + int dom = PCI_DOM_FROM_BUS(ent->bus.id.pci.bus); + int bus = PCI_BUS_NO_DOMAIN(ent->bus.id.pci.bus); + int dev = ent->bus.id.pci.device; + int func = ent->bus.id.pci.func; + sprintf(file, "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/enable", + dom, bus, dev, func); + + if ((fd = open(file, O_RDWR)) < 0) { + xf86Msg(X_ERROR, "Unable to open %s. Be afraid.\n", file); + break; + } + read(fd, &buf, 1); + if (buf = '0') { + xf86Msg(X_INFO, "Enabling PCI device\n"); + write(fd, "1", 2); + } + close(fd); + } while (0); + + init = xf86GetEntityPrivate(entityIndex, lnxEntityPrivate)->ptr; + if (init) + init(entityIndex, private); +} _X_EXPORT Bool xf86SetEntityFuncs(int entityIndex, EntityProc init, EntityProc enter, @@ -271,7 +312,12 @@ { if (entityIndex >= xf86NumEntities) return FALSE; +#ifndef linux xf86Entities[entityIndex]->entityInit = init; +#else + xf86Entities[entityIndex]->entityInit = lnxEntityInit; + xf86GetEntityPrivate(entityIndex, lnxEntityPrivate)->ptr = init; +#endif xf86Entities[entityIndex]->entityEnter = enter; xf86Entities[entityIndex]->entityLeave = leave; xf86Entities[entityIndex]->private = private;