All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] PCI: ACPI: glue: Get rid of acpi_pci_bus and rearrange code
@ 2021-09-18 12:51 Rafael J. Wysocki
  2021-09-18 12:53 ` [PATCH v1 1/3] PCI: ACPI: Drop acpi_pci_bus Rafael J. Wysocki
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2021-09-18 12:51 UTC (permalink / raw)
  To: Linux ACPI, Linux PCI
  Cc: LKML, Bjorn Helgaas, Mika Westerberg, Andy Shevchenko

Hi All,

After commit 375553a93201 ("PCI: Setup ACPI fwnode early and at the same time
with OF"), PCI only uses acpi_pci_bus for running the ->setup() and ->cleanup()
callbacks from there, but the functions pointed to by them can be invoked
directly from the ACPI "glue" code if the device being processed is a PCI one,
so patch [1/3] drops acpi_pci_bus and rearranges the code to call the PCI
"setup" and "cleanup" routines directly.

After that, the ->cleanup callback in struct acpi_bus_type has no users, so
patch [2/3] gets rid of it.

Finally, patch [3/3] rearranges acpi_device_notify() to avoid looking up
the "ACPI bus type" of the device in bus_type_list if its ACPI companion has
been set upfront.

Thanks!




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 1/3] PCI: ACPI: Drop acpi_pci_bus
  2021-09-18 12:51 [PATCH v1 0/3] PCI: ACPI: glue: Get rid of acpi_pci_bus and rearrange code Rafael J. Wysocki
@ 2021-09-18 12:53 ` Rafael J. Wysocki
  2021-09-18 12:56 ` [PATCH v1 2/3] ACPI: glue: Drop cleanup callback from struct acpi_bus_type Rafael J. Wysocki
  2021-09-18 13:02 ` [PATCH v1 3/3] ACPI: glue: Look for ACPI bus type only if ACPI companion is not known Rafael J. Wysocki
  2 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2021-09-18 12:53 UTC (permalink / raw)
  To: Linux ACPI, Linux PCI
  Cc: LKML, Bjorn Helgaas, Mika Westerberg, Andy Shevchenko

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The acpi_pci_bus structure was used primarily for running
acpi_pci_find_companion() during PCI device objects registration,
but after commit 375553a93201 ("PCI: Setup ACPI fwnode early and at
the same time with OF") that function is called by pci_setup_device()
via pci_set_acpi_fwnode(), which happens before calling
pci_device_add() on the new PCI device object, so its ACPI companion
has been set already when acpi_device_notify() runs and it will never
call ->find_companion() from acpi_pci_bus.

For this reason, modify acpi_device_notify() and
acpi_device_notify_remove() to call pci_acpi_setup() and
pci_acpi_cleanup(), respectively, directly on PCI device objects
and drop acpi_pci_bus altogether.

While at it, notice that pci_acpi_setup() and pci_acpi_cleanup()
can obtain the ACPI companion pointer, which is guaranteed to not
be NULL, from their callers and modify them to work that way so
as to reduce the number of redundant checks somewhat.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/glue.c      |   36 +++++++++++++++++++++++-------------
 drivers/pci/pci-acpi.c   |   31 +++----------------------------
 include/linux/pci-acpi.h |    8 ++++++++
 3 files changed, 34 insertions(+), 41 deletions(-)

Index: linux-pm/drivers/pci/pci-acpi.c
===================================================================
--- linux-pm.orig/drivers/pci/pci-acpi.c
+++ linux-pm/drivers/pci/pci-acpi.c
@@ -1353,13 +1353,9 @@ static void pci_acpi_set_external_facing
 		dev->external_facing = 1;
 }
 
-static void pci_acpi_setup(struct device *dev)
+void pci_acpi_setup(struct device *dev, struct acpi_device *adev)
 {
 	struct pci_dev *pci_dev = to_pci_dev(dev);
-	struct acpi_device *adev = ACPI_COMPANION(dev);
-
-	if (!adev)
-		return;
 
 	pci_acpi_optimize_delay(pci_dev, adev->handle);
 	pci_acpi_set_external_facing(pci_dev);
@@ -1383,14 +1379,10 @@ static void pci_acpi_setup(struct device
 	acpi_device_power_add_dependent(adev, dev);
 }
 
-static void pci_acpi_cleanup(struct device *dev)
+void pci_acpi_cleanup(struct device *dev, struct acpi_device *adev)
 {
-	struct acpi_device *adev = ACPI_COMPANION(dev);
 	struct pci_dev *pci_dev = to_pci_dev(dev);
 
-	if (!adev)
-		return;
-
 	pci_acpi_remove_edr_notifier(pci_dev);
 	pci_acpi_remove_pm_notifier(adev);
 	if (adev->wakeup.flags.valid) {
@@ -1402,20 +1394,6 @@ static void pci_acpi_cleanup(struct devi
 	}
 }
 
-static bool pci_acpi_bus_match(struct device *dev)
-{
-	return dev_is_pci(dev);
-}
-
-static struct acpi_bus_type acpi_pci_bus = {
-	.name = "PCI",
-	.match = pci_acpi_bus_match,
-	.find_companion = acpi_pci_find_companion,
-	.setup = pci_acpi_setup,
-	.cleanup = pci_acpi_cleanup,
-};
-
-
 static struct fwnode_handle *(*pci_msi_get_fwnode_cb)(struct device *dev);
 
 /**
@@ -1457,8 +1435,6 @@ struct irq_domain *pci_host_bridge_acpi_
 
 static int __init acpi_pci_init(void)
 {
-	int ret;
-
 	if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_MSI) {
 		pr_info("ACPI FADT declares the system doesn't support MSI, so disable it\n");
 		pci_no_msi();
@@ -1469,8 +1445,7 @@ static int __init acpi_pci_init(void)
 		pcie_no_aspm();
 	}
 
-	ret = register_acpi_bus_type(&acpi_pci_bus);
-	if (ret)
+	if (acpi_pci_disabled)
 		return 0;
 
 	pci_set_platform_pm(&acpi_pci_platform_pm);
Index: linux-pm/include/linux/pci-acpi.h
===================================================================
--- linux-pm.orig/include/linux/pci-acpi.h
+++ linux-pm/include/linux/pci-acpi.h
@@ -84,6 +84,14 @@ extern struct pci_bus *acpi_pci_root_cre
 void acpi_pci_add_bus(struct pci_bus *bus);
 void acpi_pci_remove_bus(struct pci_bus *bus);
 
+#ifdef CONFIG_PCI
+void pci_acpi_setup(struct device *dev, struct acpi_device *adev);
+void pci_acpi_cleanup(struct device *dev, struct acpi_device *adev);
+#else
+static inline void pci_acpi_setup(struct device *dev, struct acpi_device *adev) {}
+static inline void pci_acpi_cleanup(struct device *dev, struct acpi_device *adev) {}
+#endif
+
 #ifdef	CONFIG_ACPI_PCI_SLOT
 void acpi_pci_slot_init(void);
 void acpi_pci_slot_enumerate(struct pci_bus *bus);
Index: linux-pm/drivers/acpi/glue.c
===================================================================
--- linux-pm.orig/drivers/acpi/glue.c
+++ linux-pm/drivers/acpi/glue.c
@@ -17,6 +17,8 @@
 #include <linux/rwsem.h>
 #include <linux/acpi.h>
 #include <linux/dma-mapping.h>
+#include <linux/pci.h>
+#include <linux/pci-acpi.h>
 #include <linux/platform_device.h>
 
 #include "internal.h"
@@ -307,13 +309,17 @@ void acpi_device_notify(struct device *d
 	}
 	adev = ACPI_COMPANION(dev);
 
-	if (dev_is_platform(dev))
-		acpi_configure_pmsi_domain(dev);
-
-	if (type && type->setup)
-		type->setup(dev);
-	else if (adev->handler && adev->handler->bind)
-		adev->handler->bind(dev);
+	if (dev_is_pci(dev)) {
+		pci_acpi_setup(dev, adev);
+	} else {
+		if (dev_is_platform(dev))
+			acpi_configure_pmsi_domain(dev);
+
+		if (type && type->setup)
+			type->setup(dev);
+		else if (adev->handler && adev->handler->bind)
+			adev->handler->bind(dev);
+	}
 
 	acpi_handle_debug(ACPI_HANDLE(dev), "Bound to device %s\n",
 			  dev_name(dev));
@@ -327,16 +333,20 @@ err:
 void acpi_device_notify_remove(struct device *dev)
 {
 	struct acpi_device *adev = ACPI_COMPANION(dev);
-	struct acpi_bus_type *type;
 
 	if (!adev)
 		return;
 
-	type = acpi_get_bus_type(dev);
-	if (type && type->cleanup)
-		type->cleanup(dev);
-	else if (adev->handler && adev->handler->unbind)
-		adev->handler->unbind(dev);
+	if (dev_is_pci(dev)) {
+		pci_acpi_cleanup(dev, adev);
+	} else {
+		struct acpi_bus_type *type = acpi_get_bus_type(dev);
+
+		if (type && type->cleanup)
+			type->cleanup(dev);
+		else if (adev->handler && adev->handler->unbind)
+			adev->handler->unbind(dev);
+	}
 
 	acpi_unbind_one(dev);
 }




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 2/3] ACPI: glue: Drop cleanup callback from struct acpi_bus_type
  2021-09-18 12:51 [PATCH v1 0/3] PCI: ACPI: glue: Get rid of acpi_pci_bus and rearrange code Rafael J. Wysocki
  2021-09-18 12:53 ` [PATCH v1 1/3] PCI: ACPI: Drop acpi_pci_bus Rafael J. Wysocki
@ 2021-09-18 12:56 ` Rafael J. Wysocki
  2021-09-18 13:02 ` [PATCH v1 3/3] ACPI: glue: Look for ACPI bus type only if ACPI companion is not known Rafael J. Wysocki
  2 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2021-09-18 12:56 UTC (permalink / raw)
  To: Linux ACPI, Linux PCI
  Cc: LKML, Bjorn Helgaas, Mika Westerberg, Andy Shevchenko

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Since PCI was the only user of the ->cleanup callback in struct
acpi_bus_type and it is not using struct acpi_bus_type any more,
drop that callback from there and update acpi_device_notify_remove()
accordingly.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/glue.c     |   12 +++---------
 include/acpi/acpi_bus.h |    1 -
 2 files changed, 3 insertions(+), 10 deletions(-)

Index: linux-pm/include/acpi/acpi_bus.h
===================================================================
--- linux-pm.orig/include/acpi/acpi_bus.h
+++ linux-pm/include/acpi/acpi_bus.h
@@ -570,7 +570,6 @@ struct acpi_bus_type {
 	bool (*match)(struct device *dev);
 	struct acpi_device * (*find_companion)(struct device *);
 	void (*setup)(struct device *);
-	void (*cleanup)(struct device *);
 };
 int register_acpi_bus_type(struct acpi_bus_type *);
 int unregister_acpi_bus_type(struct acpi_bus_type *);
Index: linux-pm/drivers/acpi/glue.c
===================================================================
--- linux-pm.orig/drivers/acpi/glue.c
+++ linux-pm/drivers/acpi/glue.c
@@ -337,16 +337,10 @@ void acpi_device_notify_remove(struct de
 	if (!adev)
 		return;
 
-	if (dev_is_pci(dev)) {
+	if (dev_is_pci(dev))
 		pci_acpi_cleanup(dev, adev);
-	} else {
-		struct acpi_bus_type *type = acpi_get_bus_type(dev);
-
-		if (type && type->cleanup)
-			type->cleanup(dev);
-		else if (adev->handler && adev->handler->unbind)
-			adev->handler->unbind(dev);
-	}
+	else if (adev->handler && adev->handler->unbind)
+		adev->handler->unbind(dev);
 
 	acpi_unbind_one(dev);
 }




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 3/3] ACPI: glue: Look for ACPI bus type only if ACPI companion is not known
  2021-09-18 12:51 [PATCH v1 0/3] PCI: ACPI: glue: Get rid of acpi_pci_bus and rearrange code Rafael J. Wysocki
  2021-09-18 12:53 ` [PATCH v1 1/3] PCI: ACPI: Drop acpi_pci_bus Rafael J. Wysocki
  2021-09-18 12:56 ` [PATCH v1 2/3] ACPI: glue: Drop cleanup callback from struct acpi_bus_type Rafael J. Wysocki
@ 2021-09-18 13:02 ` Rafael J. Wysocki
  2 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2021-09-18 13:02 UTC (permalink / raw)
  To: Linux ACPI, Linux PCI
  Cc: LKML, Bjorn Helgaas, Mika Westerberg, Andy Shevchenko

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Notice that it is not necessary to look for the "ACPI bus type" of
the device in acpi_device_notify() if the device's ACPI companion
is set upfront, so modify the code to do that lookup only if it is
necessary to find the ACPI companion.

Also notice that if the device's ACPI companion is not set upfront
in acpi_device_notify(), the device cannot be either a PCI one or a
platform one, so check for these bus types only if the device's
ACPI companion is set.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/glue.c |   28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

Index: linux-pm/drivers/acpi/glue.c
===================================================================
--- linux-pm.orig/drivers/acpi/glue.c
+++ linux-pm/drivers/acpi/glue.c
@@ -289,12 +289,13 @@ EXPORT_SYMBOL_GPL(acpi_unbind_one);
 
 void acpi_device_notify(struct device *dev)
 {
-	struct acpi_bus_type *type = acpi_get_bus_type(dev);
 	struct acpi_device *adev;
 	int ret;
 
 	ret = acpi_bind_one(dev, NULL);
 	if (ret) {
+		struct acpi_bus_type *type = acpi_get_bus_type(dev);
+
 		if (!type)
 			goto err;
 
@@ -306,21 +307,26 @@ void acpi_device_notify(struct device *d
 		ret = acpi_bind_one(dev, adev);
 		if (ret)
 			goto err;
-	}
-	adev = ACPI_COMPANION(dev);
 
-	if (dev_is_pci(dev)) {
-		pci_acpi_setup(dev, adev);
+		if (type->setup) {
+			type->setup(dev);
+			goto done;
+		}
 	} else {
-		if (dev_is_platform(dev))
-			acpi_configure_pmsi_domain(dev);
+		adev = ACPI_COMPANION(dev);
 
-		if (type && type->setup)
-			type->setup(dev);
-		else if (adev->handler && adev->handler->bind)
-			adev->handler->bind(dev);
+		if (dev_is_pci(dev)) {
+			pci_acpi_setup(dev, adev);
+			goto done;
+		} else if (dev_is_platform(dev)) {
+			acpi_configure_pmsi_domain(dev);
+		}
 	}
 
+	if (adev->handler && adev->handler->bind)
+		adev->handler->bind(dev);
+
+done:
 	acpi_handle_debug(ACPI_HANDLE(dev), "Bound to device %s\n",
 			  dev_name(dev));
 




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-18 13:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-18 12:51 [PATCH v1 0/3] PCI: ACPI: glue: Get rid of acpi_pci_bus and rearrange code Rafael J. Wysocki
2021-09-18 12:53 ` [PATCH v1 1/3] PCI: ACPI: Drop acpi_pci_bus Rafael J. Wysocki
2021-09-18 12:56 ` [PATCH v1 2/3] ACPI: glue: Drop cleanup callback from struct acpi_bus_type Rafael J. Wysocki
2021-09-18 13:02 ` [PATCH v1 3/3] ACPI: glue: Look for ACPI bus type only if ACPI companion is not known Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.