xserver: Branch 'pci-rework' - 4 commits

Ian Romanick idr at kemper.freedesktop.org
Thu Jan 18 00:34:01 EET 2007


 hw/xfree86/common/xf86Bus.c     |   26 ++++++----------
 hw/xfree86/common/xf86Bus.h     |    1 
 hw/xfree86/common/xf86Config.c  |    6 ++-
 hw/xfree86/common/xf86Globals.c |    5 ++-
 hw/xfree86/common/xf86Helper.c  |    6 +--
 hw/xfree86/common/xf86Init.c    |   23 ++++++--------
 hw/xfree86/common/xf86Priv.h    |    2 -
 hw/xfree86/common/xf86pciBus.c  |   64 +++++++++-------------------------------
 hw/xfree86/common/xf86str.h     |    8 +----
 9 files changed, 49 insertions(+), 92 deletions(-)

New commits:
diff-tree 88f248e67143175532cbafd6faf8fc6df97c7894 (from 0361611080267727f570e17f2212aaa890223f6e)
Author: Ian Romanick <idr at us.ibm.com>
Date:   Wed Jan 17 14:04:43 2007 -0800

    Replace PciBusId with 'struct pci_device *'
    
    There's no need to store the slot information for a PCI device as its
    ID.  Instead, skip the middle man and just store a pointer to the
    pci_device structure.

diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index 573c924..86ad018 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -254,9 +254,7 @@ xf86IsEntityPrimary(int entityIndex)
 
     switch (pEnt->busType) {
     case BUS_PCI:
-	return (pEnt->pciBusId.bus == primaryBus.id.pci.bus &&
-		pEnt->pciBusId.device == primaryBus.id.pci.device &&
-		pEnt->pciBusId.func == primaryBus.id.pci.func);
+	return (pEnt->bus.id.pci == primaryBus.id.pci);
     case BUS_ISA:
 	return TRUE;
     case BUS_SBUS:
@@ -1863,11 +1861,7 @@ busTypeSpecific(EntityPtr pEnt, xf86Acce
 	*acc_mem = *acc_io = *acc_mem_io = &AccessNULL;
 	break;
     case BUS_PCI: {
-	struct pci_device * const dev = 
-	  pci_device_find_by_slot( PCI_DOM_FROM_BUS( pEnt->pciBusId.bus ),
-				   PCI_BUS_NO_DOMAIN( pEnt->pciBusId.bus ),
-				   pEnt->pciBusId.device,
-				   pEnt->pciBusId.func );
+	struct pci_device *const dev = pEnt->bus.id.pci;
 
 	if ((dev != NULL) && ((void *)dev->user_data != NULL)) {
 	    pciAccPtr const paccp = (pciAccPtr) dev->user_data;
@@ -2988,10 +2982,11 @@ xf86FindPrimaryDevice()
 	switch (primaryBus.type) {
 	case BUS_PCI:
 	    bus = "PCI";
-	    snprintf(loc, sizeof(loc), " %2.2x:%2.2x:%1.1x",
-		     primaryBus.id.pci.bus,
-		     primaryBus.id.pci.device,
-		     primaryBus.id.pci.func);
+	    snprintf(loc, sizeof(loc), " %2.2x@%2.2x:%2.2x:%1.1x",
+		     primaryBus.id.pci->bus,
+		     primaryBus.id.pci->domain,
+		     primaryBus.id.pci->dev,
+		     primaryBus.id.pci->func);
 	    break;
 	case BUS_ISA:
 	    bus = "ISA";
diff --git a/hw/xfree86/common/xf86Bus.h b/hw/xfree86/common/xf86Bus.h
index 8e65023..f1fc627 100644
--- a/hw/xfree86/common/xf86Bus.h
+++ b/hw/xfree86/common/xf86Bus.h
@@ -91,7 +91,6 @@ typedef struct {
 #define NEED_SHARED (NEED_MEM_SHARED | NEED_IO_SHARED)
 
 #define busType bus.type
-#define pciBusId bus.id.pci
 #define isaBusId bus.id.isa
 #define sbusBusId bus.id.sbus
 
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index bad0513..27a90c9 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1991,11 +1991,9 @@ xf86MatchPciInstances(const char *driver
         if (retEntities[numFound - 1] == -1 && instances[i].screen > 0) {
 	    for (j = 0; j < xf86NumEntities; j++) {
 	        EntityPtr pEnt = xf86Entities[j];
-	        if (pEnt->busType != BUS_PCI)
+	        if (pEnt->bus.type != BUS_PCI)
 		    continue;
-	        if (pEnt->pciBusId.bus == PCI_MAKE_BUS( pPci->domain, pPci->bus ) &&
-		    pEnt->pciBusId.device == pPci->dev &&
-		    pEnt->pciBusId.func == pPci->func) {
+	        if (pEnt->bus.id.pci == pPci) {
 		    retEntities[numFound - 1] = j;
 		    xf86AddDevToEntity(j, instances[i].dev);
 		    break;
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 3fc9766..f824f68 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -329,10 +329,10 @@ probe_devices_from_device_sections(Drive
 #endif
 	
 		/* Allocate an entry in the lists to be returned */
-		entry = xf86ClaimPciSlot( pPci, drvp, device_id,
-					  devList[i], devList[i]->active );
+		entry = xf86ClaimPciSlot(pPci, drvp, device_id,
+					  devList[i], devList[i]->active);
 
-		if ( (entry == -1) && (devList[i]->screen > 0) ) {
+		if ((entry == -1) && (devList[i]->screen > 0)) {
 		    unsigned k;
 
 		    for ( k = 0; k < xf86NumEntities; k++ ) {
@@ -340,19 +340,17 @@ probe_devices_from_device_sections(Drive
 			if (pEnt->busType != BUS_PCI)
 			  continue;
 
-			if (pEnt->pciBusId.bus == PCI_MAKE_BUS( pPci->domain, pPci->bus ) &&
-			    pEnt->pciBusId.device == pPci->dev &&
-			    pEnt->pciBusId.func == pPci->func) {
+			if (pEnt->bus.id.pci == pPci) {
 			    entry = k;
-			    xf86AddDevToEntity( k, devList[i] );
+			    xf86AddDevToEntity(k, devList[i]);
 			    break;
 			}
 		    }
 		}
 		
-		if ( entry != -1 ) {
-		    if ( (*drvp->PciProbe)( drvp, entry, pPci,
-					    devices[j].match_data ) ) {
+		if (entry != -1) {
+		    if ((*drvp->PciProbe)(drvp, entry, pPci,
+					  devices[j].match_data)) {
 			foundScreen = TRUE;
 		    }
 		}
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index 5dc96b9..953be48 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -149,9 +149,7 @@ FindPCIVideoInfo(void)
 		&& ((num == 1) || IS_VGA(info->device_class))) {
 		if (primaryBus.type == BUS_NONE) {
 		    primaryBus.type = BUS_PCI;
-		    primaryBus.id.pci.bus = PCI_MAKE_BUS( info->domain, info->bus );
-		    primaryBus.id.pci.device = info->dev;
-		    primaryBus.id.pci.func = info->func;
+		    primaryBus.id.pci = info;
 		} else {
 		    xf86Msg(X_NOTICE,
 			    "More than one possible primary device found\n");
@@ -801,10 +799,8 @@ xf86ClaimPciSlot(struct pci_device * d, 
 	p = xf86Entities[num];
 	p->driver = drvp;
 	p->chipset = chipset;
-	p->busType = BUS_PCI;
-	p->pciBusId.bus = bus;
-	p->pciBusId.device = d->dev;
-	p->pciBusId.func = d->func;
+	p->bus.type = BUS_PCI;
+	p->bus.id.pci = d;
 	p->active = active;
 	p->inUse = FALSE;
 	if (dev)
@@ -937,14 +933,9 @@ xf86ComparePciBusString(const char *busI
  */
  
 _X_EXPORT Bool
-xf86IsPrimaryPci( struct pci_device * pPci )
+xf86IsPrimaryPci(struct pci_device *pPci)
 {
-    const unsigned busnum = PCI_MAKE_BUS( pPci->domain, pPci->bus );
-
-    return ((primaryBus.type == BUS_PCI)
-	    && (busnum == primaryBus.id.pci.bus)
-	    && (pPci->dev == primaryBus.id.pci.device)
-	    && (pPci->func == primaryBus.id.pci.func));
+    return ((primaryBus.type == BUS_PCI) && (pPci == primaryBus.id.pci));
 }
 
 /*
@@ -959,12 +950,7 @@ xf86GetPciInfoForEntity(int entityIndex)
 	return NULL;
 
     p = xf86Entities[entityIndex];
-    return (p->busType == BUS_PCI)
-      ? pci_device_find_by_slot(PCI_DOM_FROM_BUS(p->pciBusId.bus),
-				PCI_BUS_NO_DOMAIN(p->pciBusId.bus),
-				p->pciBusId.device,
-				p->pciBusId.func)
-      : NULL;
+    return (p->bus.type == BUS_PCI) ? p->bus.id.pci : NULL;
 }
 
 /*
@@ -994,10 +980,7 @@ xf86CheckPciSlot(const struct pci_device
     for (i = 0; i < xf86NumEntities; i++) {
 	const EntityPtr p = xf86Entities[i];
 
-	if ((p->busType == BUS_PCI) &&
-	    (p->pciBusId.bus == PCI_MAKE_BUS(d->domain, d->bus)) &&
-	    (p->pciBusId.device == d->dev) &&
-	    (p->pciBusId.func == d->func)) {
+	if ((p->bus.type == BUS_PCI) && (p->bus.id.pci == d)) {
 	    return FALSE;
 	}
     }
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index 55f439f..7fb8842 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -378,11 +378,7 @@ typedef enum {
     BUS_last    /* Keep last */
 } BusType;
 
-typedef struct {
-    int		bus;
-    int		device;
-    int		func;
-} PciBusId;
+struct pci_device;
 
 typedef struct {
     unsigned int dummy;
@@ -396,7 +392,7 @@ typedef struct _bus {
     BusType type;
     union {
 	IsaBusId isa;
-	PciBusId pci;
+	struct pci_device *pci;
 	SbusBusId sbus;
     } id;
 } BusRec, *BusPtr;
diff-tree 0361611080267727f570e17f2212aaa890223f6e (from c1808f148405a28256e0480d6f8714691b0e964e)
Author: Ian Romanick <idr at us.ibm.com>
Date:   Wed Jan 17 13:06:04 2007 -0800

    Convert xf86IsolateDevice to a 'struct pci_slot_match'.
    
    This change was accidentally not committed on the previous commit.

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 02ff7c0..3fc9766 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1785,8 +1785,9 @@ ddxProcessArgument(int argc, char **argv
        FatalError("Bus types other than PCI not yet isolable\n");
     }
     if (sscanf(argv[i], "PCI:%d:%d:%d", &bus, &device, &func) == 3) {
-       xf86IsolateDevice.bus = bus;
-       xf86IsolateDevice.device = device;
+       xf86IsolateDevice.domain = PCI_DOM_FROM_BUS(bus);
+       xf86IsolateDevice.bus = PCI_BUS_NO_DOMAIN(bus);
+       xf86IsolateDevice.dev = device;
        xf86IsolateDevice.func = func;
        return 2;
     } else {
diff-tree c1808f148405a28256e0480d6f8714691b0e964e (from d2f8c42c48ecc398d224d9e3b280a66042e68664)
Author: Ian Romanick <idr at us.ibm.com>
Date:   Wed Jan 17 13:02:27 2007 -0800

    Convert xf86IsolateDevice to a 'struct pci_slot_match'.

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index c0e21dd..676392c 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -66,6 +66,7 @@
 #include "configProcs.h"
 #include "globals.h"
 #include "extension.h"
+#include "Pci.h"
 
 #ifdef XINPUT
 #include "xf86Xinput.h"
@@ -2456,8 +2457,9 @@ xf86HandleConfigFile(Bool autoconfig)
            xf86Msg(X_WARNING, "Bus types other than PCI not yet isolable.\n"
                               "\tIgnoring IsolateDevice option.\n");
        } else if (sscanf(scanptr, "PCI:%d:%d:%d", &bus, &device, &func) == 3) {
-           xf86IsolateDevice.bus = bus;
-           xf86IsolateDevice.device = device;
+           xf86IsolateDevice.domain = PCI_DOM_FROM_BUS(bus);
+           xf86IsolateDevice.bus = PCI_BUS_NO_DOMAIN(bus);
+           xf86IsolateDevice.dev = device;
            xf86IsolateDevice.func = func;
            xf86Msg(X_INFO,
                    "Isolating PCI bus \"%d:%d:%d\"\n", bus, device, func);
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 9b23710..d81b5cc 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -204,4 +204,7 @@ Bool xf86MiscModInDevAllowNonLocal = FAL
 RootWinPropPtr *xf86RegisteredPropertiesTable = NULL;
 _X_EXPORT Bool xf86inSuspend = FALSE;
 Bool xorgHWAccess = FALSE;
-PciBusId xf86IsolateDevice;
+
+struct pci_slot_match xf86IsolateDevice = {
+    PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0
+};
diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h
index 35904fc..60fd31a 100644
--- a/hw/xfree86/common/xf86Priv.h
+++ b/hw/xfree86/common/xf86Priv.h
@@ -78,7 +78,7 @@ extern Bool xf86BestRefresh;
 extern Gamma xf86Gamma;
 extern char *xf86ServerName;
 extern Bool xf86ShowUnresolved;
-extern PciBusId xf86IsolateDevice;
+extern struct pci_slot_match xf86IsolateDevice;
 
 /* Other parameters */
 
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index 05e1e7e..5dc96b9 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -112,9 +112,8 @@ FindPCIVideoInfo(void)
 {
     int i = 0, k;
     int num = 0;
-    struct pci_device * info;
-    struct pci_slot_match   m;
-    struct pci_device_iterator * iter;
+    struct pci_device *info;
+    struct pci_device_iterator *iter;
 
 
     if (!xf86scanpci()) {
@@ -122,29 +121,13 @@ FindPCIVideoInfo(void)
 	return;
     }
 
-    if ( (xf86IsolateDevice.bus != 0)
-	 || (xf86IsolateDevice.device != 0) 
-	 || (xf86IsolateDevice.func != 0) ) {
-	m.domain = PCI_DOM_FROM_BUS( xf86IsolateDevice.bus );
-	m.bus = PCI_BUS_NO_DOMAIN( xf86IsolateDevice.bus );
-	m.dev = xf86IsolateDevice.device;
-	m.func = xf86IsolateDevice.func;
-    }
-    else {
-	m.domain = PCI_MATCH_ANY;
-	m.bus = PCI_MATCH_ANY;
-	m.dev = PCI_MATCH_ANY;
-	m.func = PCI_MATCH_ANY;
-    }
-
-    iter = pci_slot_match_iterator_create( & m );
-
-    while ( (info = pci_device_next( iter )) != NULL ) {
-	if ( PCIINFOCLASSES( info->device_class ) ) {
+    iter = pci_slot_match_iterator_create(& xf86IsolateDevice);
+    while ((info = pci_device_next(iter)) != NULL) {
+	if (PCIINFOCLASSES(info->device_class)) {
 	    num++;
-	    xf86PciVideoInfo = xnfrealloc( xf86PciVideoInfo,
-					   (sizeof( struct pci_device * ) 
-					    * (num + 1)) );
+	    xf86PciVideoInfo = xnfrealloc(xf86PciVideoInfo,
+					  (sizeof(struct pci_device *)
+					   * (num + 1)));
 	    xf86PciVideoInfo[num] = NULL;
 	    xf86PciVideoInfo[num - 1] = info;
 
diff-tree d2f8c42c48ecc398d224d9e3b280a66042e68664 (from 28976bebec8b6475d0703f8356edd116e25d40b2)
Author: Ian Romanick <idr at us.ibm.com>
Date:   Wed Jan 17 12:59:17 2007 -0800

    Convert xf86FindPrimaryDevice to use a static buffer and snprintf.
    
    Rather than allocate a 9 byte buffer on each invocation, use a static
    16 byte buffer.  Use snprintf for safety.  This commit should probably
    be cherry-picked to the trunk.

diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index e6e56e1..573c924 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -2983,14 +2983,15 @@ xf86FindPrimaryDevice()
         CheckGenericGA();
     if (primaryBus.type != BUS_NONE) {
 	char *bus;
-	char *loc = xnfcalloc(1,9);
-	if (loc == NULL) return;
+	char loc[16];
 
 	switch (primaryBus.type) {
 	case BUS_PCI:
 	    bus = "PCI";
-	    sprintf(loc," %2.2x:%2.2x:%1.1x",primaryBus.id.pci.bus,
-	    primaryBus.id.pci.device,primaryBus.id.pci.func);
+	    snprintf(loc, sizeof(loc), " %2.2x:%2.2x:%1.1x",
+		     primaryBus.id.pci.bus,
+		     primaryBus.id.pci.device,
+		     primaryBus.id.pci.func);
 	    break;
 	case BUS_ISA:
 	    bus = "ISA";
@@ -2998,17 +2999,15 @@ xf86FindPrimaryDevice()
 	    break;
 	case BUS_SBUS:
 	    bus = "SBUS";
-	    sprintf(loc," %2.2x",primaryBus.id.sbus.fbNum);
+	    snprintf(loc, sizeof(loc), " %2.2x", primaryBus.id.sbus.fbNum);
 	    break;
 	default:
 	    bus = "";
 	    loc[0] = '\0';
 	}
-	
+
 	xf86MsgVerb(X_INFO, 2, "Primary Device is: %s%s\n",bus,loc);
-	xfree(loc);
     }
-    
 }
 
 #if !defined(__sparc) && !defined(__sparc__) && !defined(__powerpc__) && !defined(__mips__)



More information about the xorg-commit mailing list