Skip to contentSkip to conversation

deprecate usage of pci_scan_bus_parented()

PATCH Superseded Jiang Liu 3 participants 10 messages Jun 20, 2013 – Jun 21, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jiang Liu

author
#0 lore raw

cover deprecate usage of pci_scan_bus_parented()

From: Jiang Liu <[email protected]>

This patch tries to deprecate usage of pci_scan_bus_parented(). It applies to
https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next

Jiang Liu (3):
PCI: export three functions to support modular host bridge driver PCI, xen-pcifront: use new PCI interfaces to simplify implementation
PCI: mark pci_scan_bus_parented() as __deprecated

 arch/tile/kernel/pci.c     |  3 --
 drivers/pci/host-bridge.c  |  1 +
 drivers/pci/probe.c        |  1 +
 drivers/pci/remove.c       |  7 +++++
 drivers/pci/xen-pcifront.c | 70 ++++++++++++++++++++--------------------------
 include/linux/pci.h        |  5 ++--
 6 files changed, 42 insertions(+), 45 deletions(-)
Signature · 1 line
1.8.1.2
author
#1 lore raw

PATCH 1/3 PCI: export three functions to support modular host bridge driver

From: Jiang Liu <[email protected]>

The xen-pcifront host bridge driver could be built as a module, so export pci_create_root_bus(), pci_stop_and_remove_root_bus() and pci_set_host_bridge_release() to support modular host bridge drivers. This patch is a preparation for coming xen-pcifront refinement.

---
 drivers/pci/host-bridge.c | 1 +
 drivers/pci/probe.c       | 1 +
 drivers/pci/remove.c      | 7 +++++++
 include/linux/pci.h       | 1 +
 4 files changed, 10 insertions(+)
drivers/pci/host-bridge.c +1 -0
index a68dc61..6e390a6 100644
@@ -34,6 +34,7 @@ void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
 	bridge->release_fn = release_fn;
 	bridge->release_data = release_data;
 }
+EXPORT_SYMBOL(pci_set_host_bridge_release);
 
 static bool resource_contains(struct resource *res1, struct resource *res2)
 {
drivers/pci/probe.c +1 -0
index 46ada5c..ed768d8 100644
@@ -1801,6 +1801,7 @@ err_out:
 	kfree(b);
 	return NULL;
 }
+EXPORT_SYMBOL(pci_create_root_bus);
 
 int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int bus_max)
 {
drivers/pci/remove.c +7 -0
index 8fc54b7..f328668 100644
@@ -147,3 +147,10 @@ void pci_remove_root_bus(struct pci_bus *bus)
 	/* remove the host bridge */
 	put_device(&host_bridge->dev);
 }
+
+void pci_stop_and_remove_root_bus(struct pci_bus *bus)
+{
+	pci_stop_root_bus(bus);
+	pci_remove_root_bus(bus);
+}
+EXPORT_SYMBOL(pci_stop_and_remove_root_bus);
include/linux/pci.h +1 -0
index 0fd1f15..f1229c7 100644
@@ -757,6 +757,7 @@ void pci_remove_bus(struct pci_bus *b);
 void pci_stop_and_remove_bus_device(struct pci_dev *dev);
 void pci_stop_root_bus(struct pci_bus *bus);
 void pci_remove_root_bus(struct pci_bus *bus);
+void pci_stop_and_remove_root_bus(struct pci_bus *bus);
 void pci_setup_cardbus(struct pci_bus *bus);
 void pci_sort_breadthfirst(void);
 #define dev_is_pci(d) ((d)->bus == &pci_bus_type)
Signature · 1 line
1.8.1.2
author
#2 lore raw

PATCH 2/3 PCI, xen-pcifront: use new PCI interfaces to simplify implementation

In reply to Jiang Liu

From: Jiang Liu <[email protected]>

Use new PCI interfaces to simplify xen-pcifront implementation:
1) Use pci_create_root_bus() instead of pci_scan_bus_parented() because pci_scan_bus_parented() will be marked as __deprecated. This also gets rid of a duplicated call to pci_bus_start_devices().
2) Use pci_stop_and_remove_root_bus() instead of open-coded private implementation.
3) Use pci_set_host_bridge_release() to release data structures associated with PCI root buses.

---
 drivers/pci/xen-pcifront.c | 70 ++++++++++++++++++++--------------------------
 1 file changed, 30 insertions(+), 40 deletions(-)
drivers/pci/xen-pcifront.c +30 -40
index 966abc6..1b01960 100644
@@ -25,11 +25,6 @@
 #define INVALID_GRANT_REF (0)
 #define INVALID_EVTCHN    (-1)
 
-struct pci_bus_entry {
-	struct list_head list;
-	struct pci_bus *bus;
-};
-
 #define _PDEVB_op_active		(0)
 #define PDEVB_op_active			(1 << (_PDEVB_op_active))
 
@@ -47,12 +42,12 @@ struct pcifront_device {
 	struct xen_pci_sharedinfo *sh_info;
 	struct work_struct op_work;
 	unsigned long flags;
-
 };
 
 struct pcifront_sd {
 	int domain;
 	struct pcifront_device *pdev;
+	struct resource busn_res;
 };
 
 static inline struct pcifront_device *
@@ -67,6 +62,12 @@ static inline void pcifront_init_sd(struct pcifront_sd *sd,
 {
 	sd->domain = domain;
 	sd->pdev = pdev;
+
+	/* Xen pci-backend doesn't export P2P bridges */
+	sd->busn_res.start = bus;
+	sd->busn_res.end = bus;
+	sd->busn_res.flags = IORESOURCE_BUS;
+	sd->busn_res.name = "PCI busn";
 }
 
 static DEFINE_SPINLOCK(pcifront_dev_lock);
@@ -441,12 +442,19 @@ static int pcifront_scan_bus(struct pcifront_device *pdev,
 	return 0;
 }
 
+static void pcifront_release_sd(struct pci_host_bridge *bridge)
+{
+	struct pcifront_sd *sd = bridge->release_data;
+
+	kfree(sd);
+}
+
 static int pcifront_scan_root(struct pcifront_device *pdev,
 				 unsigned int domain, unsigned int bus)
 {
 	struct pci_bus *b;
 	struct pcifront_sd *sd = NULL;
-	struct pci_bus_entry *bus_entry = NULL;
+	LIST_HEAD(resources);
 	int err = 0;
 
 #ifndef CONFIG_PCI_DOMAINS
@@ -463,16 +471,18 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
 	dev_info(&pdev->xdev->dev, "Creating PCI Frontend Bus %04x:%02x\n",
 		 domain, bus);
 
-	bus_entry = kmalloc(sizeof(*bus_entry), GFP_KERNEL);
-	sd = kmalloc(sizeof(*sd), GFP_KERNEL);
-	if (!bus_entry || !sd) {
+	sd = kzalloc(sizeof(*sd), GFP_KERNEL);
+	if (!sd) {
 		err = -ENOMEM;
 		goto err_out;
 	}
 	pcifront_init_sd(sd, domain, bus, pdev);
 
-	b = pci_scan_bus_parented(&pdev->xdev->dev, bus,
-				  &pcifront_bus_ops, sd);
+	pci_add_resource(&resources, &ioport_resource);
+	pci_add_resource(&resources, &iomem_resource);
+	pci_add_resource(&resources, &sd->busn_res);
+	b = pci_create_root_bus(&pdev->xdev->dev, bus, &pcifront_bus_ops,
+				sd, &resources);
 	if (!b) {
 		dev_err(&pdev->xdev->dev,
 			"Error creating PCI Frontend Bus!\n");
@@ -480,9 +490,8 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
 		goto err_out;
 	}
 
-	bus_entry->bus = b;
-
-	list_add(&bus_entry->list, &pdev->root_buses);
+	pci_set_host_bridge_release(to_pci_host_bridge(b->bridge),
+				    pcifront_release_sd, sd);
 
 	/* pci_scan_bus_parented skips devices which do not have a have
 	* devfn==0. The pcifront_scan_bus enumerates all devfn. */
@@ -497,7 +506,6 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
 	return err;
 
 err_out:
-	kfree(bus_entry);
 	kfree(sd);
 
 	return err;
@@ -538,35 +546,17 @@ static int pcifront_rescan_root(struct pcifront_device *pdev,
 	return err;
 }
 
-static void free_root_bus_devs(struct pci_bus *bus)
-{
-	struct pci_dev *dev;
-
-	while (!list_empty(&bus->devices)) {
-		dev = container_of(bus->devices.next, struct pci_dev,
-				   bus_list);
-		dev_dbg(&dev->dev, "removing device\n");
-		pci_stop_and_remove_bus_device(dev);
-	}
-}
-
 static void pcifront_free_roots(struct pcifront_device *pdev)
 {
-	struct pci_bus_entry *bus_entry, *t;
+	struct pcifront_sd *sd;
+	struct pci_bus *bus, *temp;
 
 	dev_dbg(&pdev->xdev->dev, "cleaning up root buses\n");
 
-	list_for_each_entry_safe(bus_entry, t, &pdev->root_buses, list) {
-		list_del(&bus_entry->list);
-
-		free_root_bus_devs(bus_entry->bus);
-
-		kfree(bus_entry->bus->sysdata);
-
-		device_unregister(bus_entry->bus->bridge);
-		pci_remove_bus(bus_entry->bus);
-
-		kfree(bus_entry);
+	list_for_each_entry_safe(bus, temp, &pci_root_buses, node) {
+		sd = bus->sysdata;
+		if (sd->pdev == pdev)
+			pci_stop_and_remove_root_bus(bus);
 	}
 }
 
Signature · 1 line
1.8.1.2
author
#3 lore raw

PATCH 2/3 PCI, xen-pcifront: use new PCI interfaces to simplify implementation

In reply to Jiang Liu

From: Jiang Liu <[email protected]>

Use new PCI interfaces to simplify xen-pcifront implementation:
1) Use pci_create_root_bus() instead of pci_scan_bus_parented() because pci_scan_bus_parented() will be marked as __deprecated. This also gets rid of a duplicated call to pci_bus_start_devices().
2) Use pci_stop_and_remove_root_bus() instead of open-coded private implementation.
3) Use pci_set_host_bridge_release() to release data structures associated with PCI root buses.

---
 drivers/pci/xen-pcifront.c | 70 ++++++++++++++++++++--------------------------
 1 file changed, 30 insertions(+), 40 deletions(-)
drivers/pci/xen-pcifront.c +30 -40
index 966abc6..1b01960 100644
@@ -25,11 +25,6 @@
 #define INVALID_GRANT_REF (0)
 #define INVALID_EVTCHN    (-1)
 
-struct pci_bus_entry {
-	struct list_head list;
-	struct pci_bus *bus;
-};
-
 #define _PDEVB_op_active		(0)
 #define PDEVB_op_active			(1 << (_PDEVB_op_active))
 
@@ -47,12 +42,12 @@ struct pcifront_device {
 	struct xen_pci_sharedinfo *sh_info;
 	struct work_struct op_work;
 	unsigned long flags;
-
 };
 
 struct pcifront_sd {
 	int domain;
 	struct pcifront_device *pdev;
+	struct resource busn_res;
 };
 
 static inline struct pcifront_device *
@@ -67,6 +62,12 @@ static inline void pcifront_init_sd(struct pcifront_sd *sd,
 {
 	sd->domain = domain;
 	sd->pdev = pdev;
+
+	/* Xen pci-backend doesn't export P2P bridges */
+	sd->busn_res.start = bus;
+	sd->busn_res.end = bus;
+	sd->busn_res.flags = IORESOURCE_BUS;
+	sd->busn_res.name = "PCI busn";
 }
 
 static DEFINE_SPINLOCK(pcifront_dev_lock);
@@ -441,12 +442,19 @@ static int pcifront_scan_bus(struct pcifront_device *pdev,
 	return 0;
 }
 
+static void pcifront_release_sd(struct pci_host_bridge *bridge)
+{
+	struct pcifront_sd *sd = bridge->release_data;
+
+	kfree(sd);
+}
+
 static int pcifront_scan_root(struct pcifront_device *pdev,
 				 unsigned int domain, unsigned int bus)
 {
 	struct pci_bus *b;
 	struct pcifront_sd *sd = NULL;
-	struct pci_bus_entry *bus_entry = NULL;
+	LIST_HEAD(resources);
 	int err = 0;
 
 #ifndef CONFIG_PCI_DOMAINS
@@ -463,16 +471,18 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
 	dev_info(&pdev->xdev->dev, "Creating PCI Frontend Bus %04x:%02x\n",
 		 domain, bus);
 
-	bus_entry = kmalloc(sizeof(*bus_entry), GFP_KERNEL);
-	sd = kmalloc(sizeof(*sd), GFP_KERNEL);
-	if (!bus_entry || !sd) {
+	sd = kzalloc(sizeof(*sd), GFP_KERNEL);
+	if (!sd) {
 		err = -ENOMEM;
 		goto err_out;
 	}
 	pcifront_init_sd(sd, domain, bus, pdev);
 
-	b = pci_scan_bus_parented(&pdev->xdev->dev, bus,
-				  &pcifront_bus_ops, sd);
+	pci_add_resource(&resources, &ioport_resource);
+	pci_add_resource(&resources, &iomem_resource);
+	pci_add_resource(&resources, &sd->busn_res);
+	b = pci_create_root_bus(&pdev->xdev->dev, bus, &pcifront_bus_ops,
+				sd, &resources);
 	if (!b) {
 		dev_err(&pdev->xdev->dev,
 			"Error creating PCI Frontend Bus!\n");
@@ -480,9 +490,8 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
 		goto err_out;
 	}
 
-	bus_entry->bus = b;
-
-	list_add(&bus_entry->list, &pdev->root_buses);
+	pci_set_host_bridge_release(to_pci_host_bridge(b->bridge),
+				    pcifront_release_sd, sd);
 
 	/* pci_scan_bus_parented skips devices which do not have a have
 	* devfn==0. The pcifront_scan_bus enumerates all devfn. */
@@ -497,7 +506,6 @@ static int pcifront_scan_root(struct pcifront_device *pdev,
 	return err;
 
 err_out:
-	kfree(bus_entry);
 	kfree(sd);
 
 	return err;
@@ -538,35 +546,17 @@ static int pcifront_rescan_root(struct pcifront_device *pdev,
 	return err;
 }
 
-static void free_root_bus_devs(struct pci_bus *bus)
-{
-	struct pci_dev *dev;
-
-	while (!list_empty(&bus->devices)) {
-		dev = container_of(bus->devices.next, struct pci_dev,
-				   bus_list);
-		dev_dbg(&dev->dev, "removing device\n");
-		pci_stop_and_remove_bus_device(dev);
-	}
-}
-
 static void pcifront_free_roots(struct pcifront_device *pdev)
 {
-	struct pci_bus_entry *bus_entry, *t;
+	struct pcifront_sd *sd;
+	struct pci_bus *bus, *temp;
 
 	dev_dbg(&pdev->xdev->dev, "cleaning up root buses\n");
 
-	list_for_each_entry_safe(bus_entry, t, &pdev->root_buses, list) {
-		list_del(&bus_entry->list);
-
-		free_root_bus_devs(bus_entry->bus);
-
-		kfree(bus_entry->bus->sysdata);
-
-		device_unregister(bus_entry->bus->bridge);
-		pci_remove_bus(bus_entry->bus);
-
-		kfree(bus_entry);
+	list_for_each_entry_safe(bus, temp, &pci_root_buses, node) {
+		sd = bus->sysdata;
+		if (sd->pdev == pdev)
+			pci_stop_and_remove_root_bus(bus);
 	}
 }
 
Signature · 1 line
1.8.1.2
author
#4 lore raw

PATCH 3/3 PCI: mark pci_scan_bus_parented() as __deprecated

In reply to Jiang Liu

From: Jiang Liu <[email protected]>

Mark pci_scan_bus_parented() as __deprecated and clean up outdated comments.

Cc Chris Metcalf <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Thierry Reding <[email protected]>
---
 arch/tile/kernel/pci.c | 3 ---
 include/linux/pci.h    | 4 ++--
 2 files changed, 2 insertions(+), 5 deletions(-)
arch/tile/kernel/pci.c +0 -3
index 67237d3..936e087 100644
@@ -309,9 +309,6 @@ int __init pcibios_init(void)
 			 *
 			 * It reads the PCI tree for this bus into the Linux
 			 * data structures.
-			 *
-			 * This is inlined in linux/pci.h and calls into
-			 * pci_scan_bus_parented() in probe.c.
 			 */
 			pci_add_resource(&resources, &ioport_resource);
 			pci_add_resource(&resources, &iomem_resource);
include/linux/pci.h +2 -2
index f1229c7..b72d275 100644
@@ -720,8 +720,8 @@ void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
 void pcibios_scan_specific_bus(int busn);
 struct pci_bus *pci_find_bus(int domain, int busnr);
 void pci_bus_add_devices(const struct pci_bus *bus);
-struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus,
-				      struct pci_ops *ops, void *sysdata);
+struct pci_bus * __deprecated pci_scan_bus_parented(struct device *parent,
+			int bus, struct pci_ops *ops, void *sysdata);
 struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata);
 struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
 				    struct pci_ops *ops, void *sysdata,
Signature · 1 line
1.8.1.2
#5 lore raw

Re: [PATCH 3/3] PCI: mark pci_scan_bus_parented() as __deprecated

Quoted 4 lines · Jiang Liu

From: Jiang Liu <[email protected]>

Mark pci_scan_bus_parented() as __deprecated and clean up outdated comments.

Why not just delete the function, if no in-kernel users are calling it, it's no longer needed at all.

thanks,

greg k-h

author
#6 lore raw

Re: [PATCH 3/3] PCI: mark pci_scan_bus_parented() as __deprecated

Quoted 8 lines · Greg Kroah-Hartman
Quoted 4 lines · Jiang Liu

From: Jiang Liu <[email protected]>

Mark pci_scan_bus_parented() as __deprecated and clean up outdated comments.

Why not just delete the function, if no in-kernel users are calling it, it's no longer needed at all.

Hi Greg,
I thought that may break out of tree drivers, so give a warning first for smooth transitions. Any guidelines here? I have some other similar cases to keep some exported symbols just for out of tree drivers. Regards!
Gerry

Quoted 5 lines

thanks,

greg k-h

#7 lore raw

Re: [PATCH 3/3] PCI: mark pci_scan_bus_parented() as __deprecated

Quoted 7 lines · Jiang Liu
Quoted 6 lines · Greg Kroah-Hartman
Quoted 4 lines · Jiang Liu

From: Jiang Liu <[email protected]>

Mark pci_scan_bus_parented() as __deprecated and clean up outdated comments.

Quoted 6 lines
Quoted 2 lines

Why not just delete the function, if no in-kernel users are calling it, it's no longer needed at all.

Hi Greg,
I thought that may break out of tree drivers, so give a warning first for smooth transitions. Any guidelines here? I have some other similar cases to keep some exported symbols just for out of tree drivers.

Don't care about out-of-tree drivers, as they obviously don't care about you, or the in-kernel code. You are doing no one any favors by keeping these functions around for a while, only delaying the time that these out-of-tree drivers will have to be updated, they will not be updated by a mere __depreciated warning.

So just delete them, that's what the rest of the kernel does, it's the price that out-of-tree drivers pay, and the authors of them know this quite well.

thanks,

greg k-h

author
#8 lore raw

Re: [PATCH 3/3] PCI: mark pci_scan_bus_parented() as __deprecated

In reply to Greg Kroah-Hartman
Quoted 8 lines · Greg Kroah-Hartman
Quoted 4 lines · Jiang Liu

From: Jiang Liu <[email protected]>

Mark pci_scan_bus_parented() as __deprecated and clean up outdated comments.

Why not just delete the function, if no in-kernel users are calling it, it's no longer needed at all.

Hi Greg,
I thought that may break out of tree drivers, so give a warning first for smooth transitions. Any guidelines here? I have some other similar cases to keep some exported symbols just for out of tree drivers. Regards!
Gerry

Quoted 5 lines

thanks,

greg k-h

#9 lore raw
In reply to Jiang Liu
Quoted 5 lines · Jiang Liu

From: Jiang Liu <[email protected]>

This patch tries to deprecate usage of pci_scan_bus_parented(). It applies to
https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next

They look OK to me, but let me double-test them in case some last minute regression has reared its head.

Quoted 17 lines

Jiang Liu (3):
PCI: export three functions to support modular host bridge driver PCI, xen-pcifront: use new PCI interfaces to simplify implementation
PCI: mark pci_scan_bus_parented() as __deprecated

 arch/tile/kernel/pci.c     |  3 --
 drivers/pci/host-bridge.c  |  1 +
 drivers/pci/probe.c        |  1 +
 drivers/pci/remove.c       |  7 +++++
 drivers/pci/xen-pcifront.c | 70 ++++++++++++++++++++--------------------------
 include/linux/pci.h        |  5 ++--
 6 files changed, 42 insertions(+), 45 deletions(-)
Signature · 1 line
1.8.1.2