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