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