[PATCH 04/14] xfree86: configure: move buses references to their own location

Tiago Vignatti tiago.vignatti at nokia.com
Tue Jun 1 07:59:00 PDT 2010


This patch makes xf86Configure.c free of PCI and SBUS code, moving to a more
meaningful location.

Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
---
 hw/xfree86/common/xf86Configure.c |  137 ++++++-------------------------------
 hw/xfree86/common/xf86pciBus.c    |   57 +++++++++++++++
 hw/xfree86/common/xf86pciBus.h    |    3 +
 hw/xfree86/common/xf86sbusBus.c   |   29 ++++++++
 hw/xfree86/common/xf86sbusBus.h   |    4 +
 5 files changed, 115 insertions(+), 115 deletions(-)

diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index 2f93bb1..04fa8f7 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -34,6 +34,7 @@
 #define IN_XSERVER
 #include "Configint.h"
 #include "xf86DDC.h"
+#include "xf86pciBus.h"
 #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
 #include "xf86Bus.h"
 #include "xf86Sbus.h"
@@ -71,107 +72,6 @@ static char *DFLT_MOUSE_DEV = "/dev/mouse";
 static char *DFLT_MOUSE_PROTO = "auto";
 #endif
 
-static Bool
-bus_pci_configure(void *busData)
-{
-    int i;
-    struct pci_device * pVideo = NULL;
-
-	pVideo = (struct pci_device *) busData;
-	for (i = 0;  i < nDevToConfig;  i++)
-	    if (DevToConfig[i].pVideo &&
-		(DevToConfig[i].pVideo->domain == pVideo->domain) &&
-		(DevToConfig[i].pVideo->bus == pVideo->bus) &&
-		(DevToConfig[i].pVideo->dev == pVideo->dev) &&
-		(DevToConfig[i].pVideo->func == pVideo->func))
-		return 0;
-
-	return 1;
-}
-
-static Bool
-bus_sbus_configure(void *busData)
-{
-#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
-    int i;
-
-    for (i = 0;  i < nDevToConfig;  i++)
-        if (DevToConfig[i].sVideo &&
-        DevToConfig[i].sVideo->fbNum == ((sbusDevicePtr) busData)->fbNum)
-            return 0;
-
-#endif
-    return 1;
-}
-
-static void
-bus_pci_newdev_configure(void *busData, int i, int *chipset)
-{
-	const char *VendorName;
-	const char *CardName;
-	char busnum[8];
-    struct pci_device * pVideo = NULL;
-
-    pVideo = (struct pci_device *) busData;
-
-	DevToConfig[i].pVideo = pVideo;
-
-	VendorName = pci_device_get_vendor_name( pVideo );
-	CardName = pci_device_get_device_name( pVideo );
-
-	if (!VendorName) {
-	    VendorName = xnfalloc(15);
-	    sprintf((char*)VendorName, "Unknown Vendor");
-	}
-
-	if (!CardName) {
-	    CardName = xnfalloc(14);
-	    sprintf((char*)CardName, "Unknown Board");
-	}
-
-	DevToConfig[i].GDev.identifier =
-	    xnfalloc(strlen(VendorName) + strlen(CardName) + 2);
-	sprintf(DevToConfig[i].GDev.identifier, "%s %s", VendorName, CardName);
-
-	DevToConfig[i].GDev.vendor = (char *)VendorName;
-	DevToConfig[i].GDev.board = (char *)CardName;
-
-	DevToConfig[i].GDev.busID = xnfalloc(16);
-	xf86FormatPciBusNumber(pVideo->bus, busnum);
-	sprintf(DevToConfig[i].GDev.busID, "PCI:%s:%d:%d",
-	    busnum, pVideo->dev, pVideo->func);
-
-	DevToConfig[i].GDev.chipID = pVideo->device_id;
-	DevToConfig[i].GDev.chipRev = pVideo->revision;
-
-	if (*chipset < 0) {
-	    *chipset = (pVideo->vendor_id << 16) | pVideo->device_id;
-	}
-}
-
-static void
-bus_sbus_newdev_configure(void *busData, int i)
-{
-#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
-	char *promPath = NULL;
-	DevToConfig[i].sVideo = (sbusDevicePtr) busData;
-	DevToConfig[i].GDev.identifier = DevToConfig[i].sVideo->descr;
-	if (sparcPromInit() >= 0) {
-	    promPath = sparcPromNode2Pathname(&DevToConfig[i].sVideo->node);
-	    sparcPromClose();
-	}
-	if (promPath) {
-	    DevToConfig[i].GDev.busID = xnfalloc(strlen(promPath) + 6);
-	    sprintf(DevToConfig[i].GDev.busID, "SBUS:%s", promPath);
-	    free(promPath);
-	} else {
-	    DevToConfig[i].GDev.busID = xnfalloc(12);
-	    sprintf(DevToConfig[i].GDev.busID, "SBUS:fb%d",
-                                DevToConfig[i].sVideo->fbNum);
-	}
-#endif
-}
-
 /*
  * This is called by the driver, either through xf86Match???Instances() or
  * directly.  We allocate a GDevRec and fill it in as much as we can, letting
@@ -186,20 +86,23 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int
 	return NULL;
 
     /* Check for duplicates */
-    switch (bus) {
-        case BUS_PCI:
-            ret = bus_pci_configure(busData);
-	        break;
-        case BUS_SBUS:
-            ret = bus_sbus_configure(busData);
-	        break;
-        default:
-	        return NULL;
+	for (i = 0;  i < nDevToConfig;  i++) {
+        switch (bus) {
+            case BUS_PCI:
+                ret = xf86PciConfigure(busData, DevToConfig[i].pVideo);
+	            break;
+#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
+            case BUS_SBUS:
+                ret = xf86SbusConfigure(busData, DevToConfig[i].sVideo);
+	            break;
+#endif
+            default:
+	            return NULL;
+        }
+        if (ret == 0)
+            goto out;
     }
 
-    if (ret == 0)
-        goto out;
-
     /* Allocate new structure occurrence */
     i = nDevToConfig++;
     DevToConfig =
@@ -217,11 +120,15 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData, int
 
     switch (bus) {
         case BUS_PCI:
-            bus_pci_newdev_configure(busData, i, &chipset);
+            xf86PciConfigureNewDev(busData, DevToConfig[i].pVideo,
+                                   &DevToConfig[i].GDev, &chipset);
 	        break;
+#if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
         case BUS_SBUS:
-            bus_sbus_newdev_configure(busData, i);
+            xf86SbusConfigureNewDev(busData, DevToConfig[i].sVideo,
+                                    &DevToConfig[i].GDev);
 	        break;
+#endif
         default:
 	        break;
     }
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index 9085ec3..a751427 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -1338,3 +1338,60 @@ xf86PciMatchDriver(char* matches[], int nmatches) {
 
     return i;
 }
+
+Bool
+xf86PciConfigure(void *busData, struct pci_device *pDev)
+{
+    struct pci_device * pVideo = NULL;
+
+    pVideo = (struct pci_device *) busData;
+    if (pDev &&
+        (pDev->domain == pVideo->domain) &&
+        (pDev->bus == pVideo->bus) &&
+        (pDev->dev == pVideo->dev) &&
+        (pDev->func == pVideo->func))
+        return 0;
+
+    return 1;
+}
+
+void
+xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo,
+                         GDevRec *GDev, int *chipset)
+{
+    const char *VendorName;
+    const char *CardName;
+    char busnum[8];
+
+    pVideo = (struct pci_device *) busData;
+
+    VendorName = pci_device_get_vendor_name( pVideo );
+    CardName = pci_device_get_device_name( pVideo );
+
+    if (!VendorName) {
+        VendorName = xnfalloc(15);
+        sprintf((char*)VendorName, "Unknown Vendor");
+    }
+
+    if (!CardName) {
+        CardName = xnfalloc(14);
+        sprintf((char*)CardName, "Unknown Board");
+    }
+
+    GDev->identifier =
+        xnfalloc(strlen(VendorName) + strlen(CardName) + 2);
+    sprintf(GDev->identifier, "%s %s", VendorName, CardName);
+
+    GDev->vendor = (char *)VendorName;
+    GDev->board = (char *)CardName;
+
+    GDev->busID = xnfalloc(16);
+    xf86FormatPciBusNumber(pVideo->bus, busnum);
+    sprintf(GDev->busID, "PCI:%s:%d:%d", busnum, pVideo->dev, pVideo->func);
+
+    GDev->chipID = pVideo->device_id;
+    GDev->chipRev = pVideo->revision;
+
+    if (*chipset < 0)
+        *chipset = (pVideo->vendor_id << 16) | pVideo->device_id;
+}
diff --git a/hw/xfree86/common/xf86pciBus.h b/hw/xfree86/common/xf86pciBus.h
index 3f02b93..e625e51 100644
--- a/hw/xfree86/common/xf86pciBus.h
+++ b/hw/xfree86/common/xf86pciBus.h
@@ -38,5 +38,8 @@ Bool xf86PciAddMatchingDev(DriverPtr drvp);
 Bool xf86PciProbeDev(DriverPtr drvp);
 void xf86PciIsolateDevice(char *argument);
 int xf86PciMatchDriver(char* matches[], int nmatches);
+Bool xf86PciConfigure(void *busData, struct pci_device *pDev);
+void xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo,
+                            GDevRec *GDev, int *chipset);
 
 #endif /* _XF86_PCI_BUS_H */
diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c
index ea8c3e1..ccb8d04 100644
--- a/hw/xfree86/common/xf86sbusBus.c
+++ b/hw/xfree86/common/xf86sbusBus.c
@@ -686,3 +686,32 @@ xf86SbusHandleColormaps(ScreenPtr pScreen, sbusDevicePtr psdp)
     return xf86HandleColormaps(pScreen, 256, 8,
 			       xf86SbusCmapLoadPalette, NULL, 0);
 }
+
+Bool
+xf86SbusConfigure(void *busData, sbusDevicePtr sBus)
+{
+    if (sBus && sBus->fbNum == ((sbusDevicePtr) busData)->fbNum)
+        return 0;
+    return 1;
+}
+
+void
+xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec *GDev)
+{
+    char *promPath = NULL;
+
+    sBus = (sbusDevicePtr) busData;
+    GDev->identifier = sBus->descr;
+    if (sparcPromInit() >= 0) {
+        promPath = sparcPromNode2Pathname(&sBus->node);
+        sparcPromClose();
+    }
+    if (promPath) {
+        GDev->busID = xnfalloc(strlen(promPath) + 6);
+        sprintf(GDev->busID, "SBUS:%s", promPath);
+        free(promPath);
+    } else {
+        GDev->busID = xnfalloc(12);
+        sprintf(GDev->busID, "SBUS:fb%d", sBus->fbNum);
+    }
+}
diff --git a/hw/xfree86/common/xf86sbusBus.h b/hw/xfree86/common/xf86sbusBus.h
index 5cdb095..66a96e3 100644
--- a/hw/xfree86/common/xf86sbusBus.h
+++ b/hw/xfree86/common/xf86sbusBus.h
@@ -97,4 +97,8 @@ extern _X_EXPORT char * sparcPromNode2Pathname(sbusPromNodePtr pnode);
 extern _X_EXPORT int sparcPromPathname2Node(const char *pathName);
 extern _X_EXPORT char *sparcDriverName(void);
 
+extern Bool xf86SbusConfigure(void *busData, sbusDevicePtr sBus);
+extern void xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus,
+                                    GDevRec *GDev);
+
 #endif /* _XF86_SBUSBUS_H */
-- 
1.7.1.226.g770c5



More information about the xorg-devel mailing list