Skip to contentSkip to conversation

PCI / hotplug / ACPI: Get rid of check_sub_bridges()

PATCH In review Mika Westerberg 2 participants 7 messages Jul 13, 2013 – Jul 16, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI / hotplug / ACPI: Get rid of check_sub_bridges()

Now that acpiphp_check_bridge() always enumerates devices behind the bridge, there is no need to do that for each sub-bridge anymore like it is done in the current ACPI-based PCI hotplug code. Given this we don't need check_sub_bridges() anymore and can drop the function completely.

This also simplifies the ACPIPHP code a bit.

---
This applies on top of v3.10 with Rafael's ACPIPHP + Thunderbolt series applied:

	http://www.spinics.net/lists/linux-acpi/msg44480.html
 drivers/pci/hotplug/acpiphp_glue.c | 25 -------------------------
 1 file changed, 25 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +0 -25
index 62e09af..741504a 100644
@@ -760,25 +760,6 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus)
  * ACPI event handlers
  */
 
-static acpi_status
-check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
-{
-	struct acpiphp_bridge *bridge;
-	char objname[64];
-	struct acpi_buffer buffer = { .length = sizeof(objname),
-				      .pointer = objname };
-
-	bridge = acpiphp_handle_to_bridge(handle);
-	if (bridge) {
-		acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-		dbg("%s: re-enumerating slots under %s\n",
-			__func__, objname);
-		acpiphp_check_bridge(bridge);
-		put_bridge(bridge);
-	}
-	return AE_OK ;
-}
-
 void acpiphp_check_host_bridge(acpi_handle handle)
 {
 	struct acpiphp_bridge *bridge;
@@ -788,9 +769,6 @@ void acpiphp_check_host_bridge(acpi_handle handle)
 		acpiphp_check_bridge(bridge);
 		put_bridge(bridge);
 	}
-
-	acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
-		ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL);
 }
 
 static void hotplug_event(acpi_handle handle, u32 type, void *data)
@@ -818,9 +796,6 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data)
 		dbg("%s: re-enumerating slots under %s\n", __func__, objname);
 		if (bridge) {
 			acpiphp_check_bridge(bridge);
-			acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
-					    ACPI_UINT32_MAX, check_sub_bridges,
-					    NULL, NULL, NULL);
 		} else {
 			struct acpiphp_slot *slot = func->slot;
 
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 5 lines · Mika Westerberg

Now that acpiphp_check_bridge() always enumerates devices behind the bridge, there is no need to do that for each sub-bridge anymore like it is done in the current ACPI-based PCI hotplug code. Given this we don't need check_sub_bridges() anymore and can drop the function completely.

Quoted 7 lines

This also simplifies the ACPIPHP code a bit.

---
This applies on top of v3.10 with Rafael's ACPIPHP + Thunderbolt series applied:

OK, I added it to my bleeding-edge branch along with this series:

Quoted 1 line
	http://www.spinics.net/lists/linux-acpi/msg44480.html

rebased on top of some previous ACPI cleanup commits. I needed to make some changes in the process (and fixed up some breakage reported by the auto build testing), hopefully I didn't break anything. If you're in an adventurous mood, testing would be welcome. ;-) [That already includes the majority of 3.11 material from Linus, though, so unexpected breakage elsewhere may happen.]

Thanks,
Rafael

Quoted 54 lines
 drivers/pci/hotplug/acpiphp_glue.c | 25 -------------------------
 1 file changed, 25 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +0 -25
index 62e09af..741504a 100644
@@ -760,25 +760,6 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus)
  * ACPI event handlers
  */
 
-static acpi_status
-check_sub_bridges(acpi_handle handle, u32 lvl, void *context, void **rv)
-{
-	struct acpiphp_bridge *bridge;
-	char objname[64];
-	struct acpi_buffer buffer = { .length = sizeof(objname),
-				      .pointer = objname };
-
-	bridge = acpiphp_handle_to_bridge(handle);
-	if (bridge) {
-		acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-		dbg("%s: re-enumerating slots under %s\n",
-			__func__, objname);
-		acpiphp_check_bridge(bridge);
-		put_bridge(bridge);
-	}
-	return AE_OK ;
-}
-
 void acpiphp_check_host_bridge(acpi_handle handle)
 {
 	struct acpiphp_bridge *bridge;
@@ -788,9 +769,6 @@ void acpiphp_check_host_bridge(acpi_handle handle)
 		acpiphp_check_bridge(bridge);
 		put_bridge(bridge);
 	}
-
-	acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
-		ACPI_UINT32_MAX, check_sub_bridges, NULL, NULL, NULL);
 }
 
 static void hotplug_event(acpi_handle handle, u32 type, void *data)
@@ -818,9 +796,6 @@ static void hotplug_event(acpi_handle handle, u32 type, void *data)
 		dbg("%s: re-enumerating slots under %s\n", __func__, objname);
 		if (bridge) {
 			acpiphp_check_bridge(bridge);
-			acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,
-					    ACPI_UINT32_MAX, check_sub_bridges,
-					    NULL, NULL, NULL);
 		} else {
 			struct acpiphp_slot *slot = func->slot;
 
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#2 lore raw
Quoted 16 lines · Rafael J. Wysocki
Quoted 5 lines · Mika Westerberg

Now that acpiphp_check_bridge() always enumerates devices behind the bridge, there is no need to do that for each sub-bridge anymore like it is done in the current ACPI-based PCI hotplug code. Given this we don't need check_sub_bridges() anymore and can drop the function completely.

Quoted 7 lines

This also simplifies the ACPIPHP code a bit.

---
This applies on top of v3.10 with Rafael's ACPIPHP + Thunderbolt series applied:

OK, I added it to my bleeding-edge branch along with this series:

Quoted 7 lines
Quoted 1 line
	http://www.spinics.net/lists/linux-acpi/msg44480.html

rebased on top of some previous ACPI cleanup commits. I needed to make some changes in the process (and fixed up some breakage reported by the auto build testing), hopefully I didn't break anything. If you're in an adventurous mood, testing would be welcome. ;-) [That already includes the majority of 3.11 material from Linus, though, so unexpected breakage elsewhere may happen.]

Tried the bleeding-edge branch on both of our test machines and Thunderbolt still works fine.

#3 lore raw
Quoted 19 lines · Mika Westerberg
Quoted 18 lines · Rafael J. Wysocki
Quoted 5 lines · Mika Westerberg

Now that acpiphp_check_bridge() always enumerates devices behind the bridge, there is no need to do that for each sub-bridge anymore like it is done in the current ACPI-based PCI hotplug code. Given this we don't need check_sub_bridges() anymore and can drop the function completely.

Quoted 7 lines

This also simplifies the ACPIPHP code a bit.

---
This applies on top of v3.10 with Rafael's ACPIPHP + Thunderbolt series applied:

OK, I added it to my bleeding-edge branch along with this series:

Quoted 1 line
	http://www.spinics.net/lists/linux-acpi/msg44480.html
Quoted 8 lines
Quoted 5 lines

rebased on top of some previous ACPI cleanup commits. I needed to make some changes in the process (and fixed up some breakage reported by the auto build testing), hopefully I didn't break anything. If you're in an adventurous mood, testing would be welcome. ;-) [That already includes the majority of 3.11 material from Linus, though, so unexpected breakage elsewhere may happen.]

Tried the bleeding-edge branch on both of our test machines and Thunderbolt still works fine.

Awesome! :-)

Thanks a lot for testing. If Bjorn doesn't hate it, I'll put the series into linux-next after 3.11-rc1 is released.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#4 lore raw
In reply to Mika Westerberg
Quoted 19 lines · Mika Westerberg
Quoted 18 lines · Rafael J. Wysocki
Quoted 5 lines · Mika Westerberg

Now that acpiphp_check_bridge() always enumerates devices behind the bridge, there is no need to do that for each sub-bridge anymore like it is done in the current ACPI-based PCI hotplug code. Given this we don't need check_sub_bridges() anymore and can drop the function completely.

Quoted 7 lines

This also simplifies the ACPIPHP code a bit.

---
This applies on top of v3.10 with Rafael's ACPIPHP + Thunderbolt series applied:

OK, I added it to my bleeding-edge branch along with this series:

Quoted 1 line
	http://www.spinics.net/lists/linux-acpi/msg44480.html
Quoted 8 lines
Quoted 5 lines

rebased on top of some previous ACPI cleanup commits. I needed to make some changes in the process (and fixed up some breakage reported by the auto build testing), hopefully I didn't break anything. If you're in an adventurous mood, testing would be welcome. ;-) [That already includes the majority of 3.11 material from Linus, though, so unexpected breakage elsewhere may happen.]

Tried the bleeding-edge branch on both of our test machines and Thunderbolt still works fine.

Can you please apply the appended patch on top of the current linux-pm.git/bleeding-edge and check if things still work then on the test systems?

Rafael

---
 drivers/pci/hotplug/acpiphp_glue.c |   42 ++++++++++++++++++++++++++++++++++++-
 drivers/pci/remove.c               |   20 -----------------
 include/linux/pci.h                |    1 
 3 files changed, 41 insertions(+), 22 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +41 -1
Index: linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================
@@ -46,6 +46,7 @@
 #include <linux/pci.h>
 #include <linux/pci_hotplug.h>
 #include <linux/pci-acpi.h>
+#include <linux/pm_runtime.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
@@ -680,6 +681,45 @@ static unsigned int get_slot_status(stru
 }
 
 /**
+ * trim_stale_devices - remove PCI devices that are not responding.
+ * @dev: PCI device to start walking the hierarchy from.
+ */
+static void trim_stale_devices(struct pci_dev *dev)
+{
+	acpi_handle handle = ACPI_HANDLE(&dev->dev);
+	struct pci_bus *bus = dev->subordinate;
+	bool alive = false;
+
+	if (handle) {
+		acpi_status status;
+		unsigned long long sta;
+
+		status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
+		alive = ACPI_SUCCESS(status) && sta == ACPI_STA_ALL;
+	}
+	if (!alive) {
+		u32 v;
+
+		/* Check if the device responds. */
+		alive = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &v, 0);
+	}
+	if (!alive) {
+		pci_stop_and_remove_bus_device(dev);
+		if (handle)
+			acpiphp_bus_trim(handle);
+	} else if (bus) {
+		struct pci_dev *child, *tmp;
+
+		/* The device is a bridge. so check the bus below it. */
+		pm_runtime_get_sync(&dev->dev);
+		list_for_each_entry_safe(child, tmp, &bus->devices, bus_list)
+			trim_stale_devices(child);
+
+		pm_runtime_put(&dev->dev);
+	}
+}
+
+/**
  * acpiphp_check_bridge - re-enumerate devices
  * @bridge: where to begin re-enumeration
  *
@@ -701,7 +741,7 @@ static void acpiphp_check_bridge(struct
 			list_for_each_entry_safe(dev, tmp, &bus->devices,
 						 bus_list)
 				if (PCI_SLOT(dev->devfn) == slot->device)
-					pci_trim_stale_devices(dev);
+					trim_stale_devices(dev);
 
 			/* configure all functions */
 			enable_slot(slot);
drivers/pci/remove.c +0 -20
Index: linux-pm/drivers/pci/remove.c
===================================================================
@@ -112,26 +112,6 @@ void pci_stop_and_remove_bus_device(stru
 }
 EXPORT_SYMBOL(pci_stop_and_remove_bus_device);
 
-/**
- * pci_trim_stale_devices - remove PCI devices that are not responding
- * @dev: the device to start walking the hierarchy from
- */
-void pci_trim_stale_devices(struct pci_dev *dev)
-{
-	struct pci_bus *bus = dev->subordinate;
-	struct pci_dev *child, *tmp;
-	bool alive;
-	u32 val;
-
-	/* check if the device responds */
-	alive = pci_bus_read_dev_vendor_id(dev->bus, dev->devfn, &val, 0);
-	if (!alive)
-		pci_stop_and_remove_bus_device(dev);
-	else if (bus)
-		list_for_each_entry_safe(child, tmp, &bus->devices, bus_list)
-			pci_trim_stale_devices(child);
-}
-
 void pci_stop_root_bus(struct pci_bus *bus)
 {
 	struct pci_dev *child, *tmp;
include/linux/pci.h +0 -1
Index: linux-pm/include/linux/pci.h
===================================================================
@@ -755,7 +755,6 @@ struct pci_dev *pci_dev_get(struct pci_d
 void pci_dev_put(struct pci_dev *dev);
 void pci_remove_bus(struct pci_bus *b);
 void pci_stop_and_remove_bus_device(struct pci_dev *dev);
-void pci_trim_stale_devices(struct pci_dev *dev);
 void pci_stop_root_bus(struct pci_bus *bus);
 void pci_remove_root_bus(struct pci_bus *bus);
 void pci_setup_cardbus(struct pci_bus *bus);
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#5 lore raw
Quoted 26 lines · Rafael J. Wysocki
Quoted 25 lines · Mika Westerberg
Quoted 23 lines · Rafael J. Wysocki
Quoted 5 lines · Mika Westerberg

Now that acpiphp_check_bridge() always enumerates devices behind the bridge, there is no need to do that for each sub-bridge anymore like it is done in the current ACPI-based PCI hotplug code. Given this we don't need check_sub_bridges() anymore and can drop the function completely.

Quoted 7 lines

This also simplifies the ACPIPHP code a bit.

---
This applies on top of v3.10 with Rafael's ACPIPHP + Thunderbolt series applied:

OK, I added it to my bleeding-edge branch along with this series:

Quoted 1 line
	http://www.spinics.net/lists/linux-acpi/msg44480.html

rebased on top of some previous ACPI cleanup commits. I needed to make some changes in the process (and fixed up some breakage reported by the auto build testing), hopefully I didn't break anything. If you're in an adventurous mood, testing would be welcome. ;-) [That already includes the majority of 3.11 material from Linus, though, so unexpected breakage elsewhere may happen.]

Quoted 6 lines
Quoted 2 lines

Tried the bleeding-edge branch on both of our test machines and Thunderbolt still works fine.

Can you please apply the appended patch on top of the current linux-pm.git/bleeding-edge and check if things still work then on the test systems?

Tested on both systems with the patch applied and Thunderbolt still works fine.

#6 lore raw
Quoted 30 lines · Mika Westerberg
Quoted 29 lines · Rafael J. Wysocki
Quoted 27 lines · Mika Westerberg
Quoted 16 lines · Rafael J. Wysocki
Quoted 5 lines · Mika Westerberg

Now that acpiphp_check_bridge() always enumerates devices behind the bridge, there is no need to do that for each sub-bridge anymore like it is done in the current ACPI-based PCI hotplug code. Given this we don't need check_sub_bridges() anymore and can drop the function completely.

Quoted 7 lines

This also simplifies the ACPIPHP code a bit.

---
This applies on top of v3.10 with Rafael's ACPIPHP + Thunderbolt series applied:

OK, I added it to my bleeding-edge branch along with this series:

Quoted 7 lines
Quoted 1 line
	http://www.spinics.net/lists/linux-acpi/msg44480.html

rebased on top of some previous ACPI cleanup commits. I needed to make some changes in the process (and fixed up some breakage reported by the auto build testing), hopefully I didn't break anything. If you're in an adventurous mood, testing would be welcome. ;-) [That already includes the majority of 3.11 material from Linus, though, so unexpected breakage elsewhere may happen.]

Tried the bleeding-edge branch on both of our test machines and Thunderbolt still works fine.

Quoted 6 lines
Quoted 3 lines

Can you please apply the appended patch on top of the current linux-pm.git/bleeding-edge and check if things still work then on the test systems?

Tested on both systems with the patch applied and Thunderbolt still works fine.

Thanks for the confirmation!

I'm going to fold this code into the "ACPI / hotplug / PCI: Check for new devices on enabled slots" patch and resend the whole series without the "RFC" mark. I'll add your "Tested-by" to it if you don't mind.

Thanks,
Rafael

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.