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