PERFORCE change 191579 for review

John Baldwin jhb at FreeBSD.org
Sat Apr 16 03:49:11 UTC 2011


http://p4web.freebsd.org/@@191579?ac=10

Change 191579 by jhb at jhb_fiver on 2011/04/16 03:48:31

	Make the PCI bus driver allocate a resource for its bus number.
	I'm a bit torn on who should own the resource for the bus number,
	the bridge or the bus, but this approach makes things far less
	convoluted (otherwise bridges have to allocate bus numbers from
	themselves, etc.).

Affected files ...

.. //depot/projects/pci/sys/dev/acpica/acpi_pci.c#2 edit
.. //depot/projects/pci/sys/dev/pci/pci.c#16 edit
.. //depot/projects/pci/sys/dev/pci/pci_private.h#5 edit
.. //depot/projects/pci/sys/powerpc/ofw/ofw_pcibus.c#2 edit
.. //depot/projects/pci/sys/sparc64/pci/ofw_pcibus.c#3 edit

Differences ...

==== //depot/projects/pci/sys/dev/acpica/acpi_pci.c#2 (text+ko) ====

@@ -99,7 +99,8 @@
 
 static devclass_t pci_devclass;
 
-DEFINE_CLASS_1(pci, acpi_pci_driver, acpi_pci_methods, 0, pci_driver);
+DEFINE_CLASS_1(pci, acpi_pci_driver, acpi_pci_methods, sizeof(struct pci_softc),
+    pci_driver);
 DRIVER_MODULE(acpi_pci, pcib, acpi_pci_driver, pci_devclass, 0, 0);
 MODULE_DEPEND(acpi_pci, acpi, 1, 1, 1);
 MODULE_DEPEND(acpi_pci, pci, 1, 1, 1);
@@ -290,7 +291,11 @@
 static int
 acpi_pci_attach(device_t dev)
 {
-	int busno, domain;
+	int busno, domain, error;
+
+	error = pci_attach_common(dev);
+	if (error)
+		return (error);
 
 	/*
 	 * Since there can be multiple independantly numbered PCI
@@ -300,9 +305,6 @@
 	 */
 	domain = pcib_get_domain(dev);
 	busno = pcib_get_bus(dev);
-	if (bootverbose)
-		device_printf(dev, "domain=%d, physical bus=%d\n",
-		    domain, busno);
 
 	/*
 	 * First, PCI devices are added as in the normal PCI bus driver.

==== //depot/projects/pci/sys/dev/pci/pci.c#16 (text+ko) ====

@@ -91,6 +91,9 @@
 			    struct resource_list *rl, int force, int prefetch);
 static int		pci_probe(device_t dev);
 static int		pci_attach(device_t dev);
+#ifdef PCI_RES_BUS
+static int		pci_detach(device_t dev);
+#endif
 static void		pci_load_vendor_data(void);
 static int		pci_describe_parse_line(char **ptr, int *vendor,
 			    int *device, char **desc);
@@ -123,7 +126,11 @@
 	/* Device interface */
 	DEVMETHOD(device_probe,		pci_probe),
 	DEVMETHOD(device_attach,	pci_attach),
+#ifdef PCI_RES_BUS
+	DEVMETHOD(device_detach,	pci_detach),
+#else
 	DEVMETHOD(device_detach,	bus_generic_detach),
+#endif
 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
 	DEVMETHOD(device_suspend,	pci_suspend),
 	DEVMETHOD(device_resume,	pci_resume),
@@ -173,7 +180,7 @@
 	{ 0, 0 }
 };
 
-DEFINE_CLASS_0(pci, pci_driver, pci_methods, 0);
+DEFINE_CLASS_0(pci, pci_driver, pci_methods, sizeof(struct pci_softc));
 
 static devclass_t pci_devclass;
 DRIVER_MODULE(pci, pcib, pci_driver, pci_devclass, pci_modevent, 0);
@@ -3047,10 +3054,41 @@
 	return (BUS_PROBE_GENERIC);
 }
 
+int
+pci_attach_common(device_t dev)
+{
+#ifdef PCI_RES_BUS
+	struct pci_softc *sc;
+	int rid;
+#endif
+	int busno, domain;
+
+	domain = pcib_get_domain(dev);
+	busno = pcib_get_bus(dev);
+#ifdef PCI_RES_BUS
+	sc = device_get_softc(dev);
+	rid = 0;
+	sc->sc_bus = bus_alloc_resource(dev, PCI_RES_BUS, &rid, busno, busno,
+	    1, 0);
+	if (sc->sc_bus == NULL) {
+		device_printf(dev, "failed to allocate bus number\n");
+		return (ENXIO);
+	}
+#endif
+	if (bootverbose)
+		device_printf(dev, "domain=%d, physical bus=%d\n",
+		    domain, busno);
+	return (0);
+}
+
 static int
 pci_attach(device_t dev)
 {
-	int busno, domain;
+	int busno, domain, error;
+
+	error = pci_attach_common(dev);
+	if (error)
+		return (error);
 
 	/*
 	 * Since there can be multiple independantly numbered PCI
@@ -3060,13 +3098,25 @@
 	 */
 	domain = pcib_get_domain(dev);
 	busno = pcib_get_bus(dev);
-	if (bootverbose)
-		device_printf(dev, "domain=%d, physical bus=%d\n",
-		    domain, busno);
 	pci_add_children(dev, domain, busno, sizeof(struct pci_devinfo));
 	return (bus_generic_attach(dev));
 }
 
+#ifdef PCI_RES_BUS
+static int
+pci_detach(device_t dev)
+{
+	struct pci_softc *sc;
+	int error;
+
+	error = bus_generic_detach(dev);
+	if (error)
+		return (error);
+	sc = device_get_softc(dev);
+	return (bus_release_resource(dev, PCI_RES_BUS, 0, sc->sc_bus));
+}
+#endif
+
 static void
 pci_set_power_children(device_t dev, device_t *devlist, int numdevs,
     int state)

==== //depot/projects/pci/sys/dev/pci/pci_private.h#5 (text+ko) ====

@@ -38,6 +38,12 @@
  */
 DECLARE_CLASS(pci_driver);
 
+struct pci_softc {
+#ifdef PCI_RES_BUS
+	struct resource *sc_bus;
+#endif
+};
+
 extern int 	pci_do_power_resume;
 extern int 	pci_do_power_suspend;
 
@@ -46,6 +52,7 @@
 void		pci_add_child(device_t bus, struct pci_devinfo *dinfo);
 void		pci_add_resources(device_t bus, device_t dev, int force,
 		    uint32_t prefetchmask);
+int		pci_attach_common(device_t dev);
 void		pci_delete_child(device_t dev, device_t child);
 void		pci_driver_added(device_t dev, driver_t *driver);
 int		pci_print_child(device_t dev, device_t child);

==== //depot/projects/pci/sys/powerpc/ofw/ofw_pcibus.c#2 (text+ko) ====

@@ -95,8 +95,8 @@
 
 static devclass_t pci_devclass;
 
-DEFINE_CLASS_1(pci, ofw_pcibus_driver, ofw_pcibus_methods, 1 /* no softc */,
-    pci_driver);
+DEFINE_CLASS_1(pci, ofw_pcibus_driver, ofw_pcibus_methods,
+    sizeof(struct pci_softc), pci_driver);
 DRIVER_MODULE(ofw_pcibus, pcib, ofw_pcibus_driver, pci_devclass, 0, 0);
 MODULE_VERSION(ofw_pcibus, 1);
 MODULE_DEPEND(ofw_pcibus, pci, 1, 1, 1);
@@ -116,12 +116,13 @@
 ofw_pcibus_attach(device_t dev)
 {
 	u_int busno, domain;
+	int error;
 
+	error = pci_attach_common(dev);
+	if (error)
+		return (error);
 	domain = pcib_get_domain(dev);
 	busno = pcib_get_bus(dev);
-	if (bootverbose)
-		device_printf(dev, "domain=%d, physical bus=%d\n",
-		    domain, busno);
 
 	/*
 	 * Attach those children represented in the device tree.

==== //depot/projects/pci/sys/sparc64/pci/ofw_pcibus.c#3 (text+ko) ====

@@ -100,8 +100,8 @@
 
 static devclass_t pci_devclass;
 
-DEFINE_CLASS_1(pci, ofw_pcibus_driver, ofw_pcibus_methods, 1 /* no softc */,
-    pci_driver);
+DEFINE_CLASS_1(pci, ofw_pcibus_driver, ofw_pcibus_methods,
+    sizeof(struct pci_softc), pci_driver);
 EARLY_DRIVER_MODULE(ofw_pcibus, pcib, ofw_pcibus_driver, pci_devclass, 0, 0,
     BUS_PASS_BUS);
 MODULE_VERSION(ofw_pcibus, 1);
@@ -230,13 +230,14 @@
 	phandle_t node, child;
 	uint32_t clock;
 	u_int busno, domain, func, slot;
+	int error;
 
+	error = pci_attach_common(dev);
+	if (error)
+		return (error);
 	pcib = device_get_parent(dev);
 	domain = pcib_get_domain(dev);
 	busno = pcib_get_bus(dev);
-	if (bootverbose)
-		device_printf(dev, "domain=%d, physical bus=%d\n",
-		    domain, busno);
 	node = ofw_bus_get_node(dev);
 
 	/*


More information about the p4-projects mailing list