[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220825164103.27694-4-andriy.shevchenko@linux.intel.com>
Date: Thu, 25 Aug 2022 19:41:02 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: "Rafael J. Wysocki" <rafael.j.wysocki@...el.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
linux-acpi@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: "Rafael J. Wysocki" <rafael@...nel.org>,
Len Brown <lenb@...nel.org>
Subject: [PATCH v1 4/5] ACPI: bus: Move bus type operations upper in the code
Move ACPI bus type operations upper in the code, it may be used later
by ACPI device matching code. No functional change intended.
While at it, provide dev_is_acpi() macro helper as it's done for some
other bus types.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
---
drivers/acpi/bus.c | 250 +++++++++++++++++++++++----------------------
1 file changed, 126 insertions(+), 124 deletions(-)
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 607e664b7976..3c0f2d050d47 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -647,6 +647,132 @@ static int __init acpi_setup_sb_notify_handler(void)
return 0;
}
+/* --------------------------------------------------------------------------
+ ACPI Bus operations
+ -------------------------------------------------------------------------- */
+
+static int acpi_bus_match(struct device *dev, struct device_driver *drv)
+{
+ struct acpi_device *acpi_dev = to_acpi_device(dev);
+ struct acpi_driver *acpi_drv = to_acpi_driver(drv);
+
+ return acpi_dev->flags.match_driver
+ && !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
+}
+
+static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+ return __acpi_device_uevent_modalias(to_acpi_device(dev), env);
+}
+
+static int acpi_device_probe(struct device *dev)
+{
+ struct acpi_device *acpi_dev = to_acpi_device(dev);
+ struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
+ int ret;
+
+ if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev))
+ return -EINVAL;
+
+ if (!acpi_drv->ops.add)
+ return -ENOSYS;
+
+ ret = acpi_drv->ops.add(acpi_dev);
+ if (ret)
+ return ret;
+
+ pr_debug("Driver [%s] successfully bound to device [%s]\n",
+ acpi_drv->name, acpi_dev->pnp.bus_id);
+
+ if (acpi_drv->ops.notify) {
+ ret = acpi_device_install_notify_handler(acpi_dev);
+ if (ret) {
+ if (acpi_drv->ops.remove)
+ acpi_drv->ops.remove(acpi_dev);
+
+ acpi_dev->driver_data = NULL;
+ return ret;
+ }
+ }
+
+ pr_debug("Found driver [%s] for device [%s]\n", acpi_drv->name,
+ acpi_dev->pnp.bus_id);
+
+ get_device(dev);
+ return 0;
+}
+
+static void acpi_device_remove(struct device *dev)
+{
+ struct acpi_device *acpi_dev = to_acpi_device(dev);
+ struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
+
+ if (acpi_drv->ops.notify)
+ acpi_device_remove_notify_handler(acpi_dev);
+
+ if (acpi_drv->ops.remove)
+ acpi_drv->ops.remove(acpi_dev);
+
+ acpi_dev->driver_data = NULL;
+
+ put_device(dev);
+}
+
+struct bus_type acpi_bus_type = {
+ .name = "acpi",
+ .match = acpi_bus_match,
+ .probe = acpi_device_probe,
+ .remove = acpi_device_remove,
+ .uevent = acpi_device_uevent,
+};
+
+#define dev_is_acpi(dev) ((dev)->bus == &acpi_bus_type)
+
+int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data)
+{
+ return bus_for_each_dev(&acpi_bus_type, NULL, data, fn);
+}
+EXPORT_SYMBOL_GPL(acpi_bus_for_each_dev);
+
+struct acpi_dev_walk_context {
+ int (*fn)(struct acpi_device *, void *);
+ void *data;
+};
+
+static int acpi_dev_for_one_check(struct device *dev, void *context)
+{
+ struct acpi_dev_walk_context *adwc = context;
+
+ if (!dev_is_acpi(dev))
+ return 0;
+
+ return adwc->fn(to_acpi_device(dev), adwc->data);
+}
+EXPORT_SYMBOL_GPL(acpi_dev_for_each_child);
+
+int acpi_dev_for_each_child(struct acpi_device *adev,
+ int (*fn)(struct acpi_device *, void *), void *data)
+{
+ struct acpi_dev_walk_context adwc = {
+ .fn = fn,
+ .data = data,
+ };
+
+ return device_for_each_child(&adev->dev, &adwc, acpi_dev_for_one_check);
+}
+
+int acpi_dev_for_each_child_reverse(struct acpi_device *adev,
+ int (*fn)(struct acpi_device *, void *),
+ void *data)
+{
+ struct acpi_dev_walk_context adwc = {
+ .fn = fn,
+ .data = data,
+ };
+
+ return device_for_each_child_reverse(&adev->dev, &adwc, acpi_dev_for_one_check);
+}
+
/* --------------------------------------------------------------------------
Device Matching
-------------------------------------------------------------------------- */
@@ -998,130 +1124,6 @@ void acpi_bus_unregister_driver(struct acpi_driver *driver)
EXPORT_SYMBOL(acpi_bus_unregister_driver);
-/* --------------------------------------------------------------------------
- ACPI Bus operations
- -------------------------------------------------------------------------- */
-
-static int acpi_bus_match(struct device *dev, struct device_driver *drv)
-{
- struct acpi_device *acpi_dev = to_acpi_device(dev);
- struct acpi_driver *acpi_drv = to_acpi_driver(drv);
-
- return acpi_dev->flags.match_driver
- && !acpi_match_device_ids(acpi_dev, acpi_drv->ids);
-}
-
-static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
-{
- return __acpi_device_uevent_modalias(to_acpi_device(dev), env);
-}
-
-static int acpi_device_probe(struct device *dev)
-{
- struct acpi_device *acpi_dev = to_acpi_device(dev);
- struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
- int ret;
-
- if (acpi_dev->handler && !acpi_is_pnp_device(acpi_dev))
- return -EINVAL;
-
- if (!acpi_drv->ops.add)
- return -ENOSYS;
-
- ret = acpi_drv->ops.add(acpi_dev);
- if (ret)
- return ret;
-
- pr_debug("Driver [%s] successfully bound to device [%s]\n",
- acpi_drv->name, acpi_dev->pnp.bus_id);
-
- if (acpi_drv->ops.notify) {
- ret = acpi_device_install_notify_handler(acpi_dev);
- if (ret) {
- if (acpi_drv->ops.remove)
- acpi_drv->ops.remove(acpi_dev);
-
- acpi_dev->driver_data = NULL;
- return ret;
- }
- }
-
- pr_debug("Found driver [%s] for device [%s]\n", acpi_drv->name,
- acpi_dev->pnp.bus_id);
-
- get_device(dev);
- return 0;
-}
-
-static void acpi_device_remove(struct device *dev)
-{
- struct acpi_device *acpi_dev = to_acpi_device(dev);
- struct acpi_driver *acpi_drv = to_acpi_driver(dev->driver);
-
- if (acpi_drv->ops.notify)
- acpi_device_remove_notify_handler(acpi_dev);
-
- if (acpi_drv->ops.remove)
- acpi_drv->ops.remove(acpi_dev);
-
- acpi_dev->driver_data = NULL;
-
- put_device(dev);
-}
-
-struct bus_type acpi_bus_type = {
- .name = "acpi",
- .match = acpi_bus_match,
- .probe = acpi_device_probe,
- .remove = acpi_device_remove,
- .uevent = acpi_device_uevent,
-};
-
-int acpi_bus_for_each_dev(int (*fn)(struct device *, void *), void *data)
-{
- return bus_for_each_dev(&acpi_bus_type, NULL, data, fn);
-}
-EXPORT_SYMBOL_GPL(acpi_bus_for_each_dev);
-
-struct acpi_dev_walk_context {
- int (*fn)(struct acpi_device *, void *);
- void *data;
-};
-
-static int acpi_dev_for_one_check(struct device *dev, void *context)
-{
- struct acpi_dev_walk_context *adwc = context;
-
- if (dev->bus != &acpi_bus_type)
- return 0;
-
- return adwc->fn(to_acpi_device(dev), adwc->data);
-}
-EXPORT_SYMBOL_GPL(acpi_dev_for_each_child);
-
-int acpi_dev_for_each_child(struct acpi_device *adev,
- int (*fn)(struct acpi_device *, void *), void *data)
-{
- struct acpi_dev_walk_context adwc = {
- .fn = fn,
- .data = data,
- };
-
- return device_for_each_child(&adev->dev, &adwc, acpi_dev_for_one_check);
-}
-
-int acpi_dev_for_each_child_reverse(struct acpi_device *adev,
- int (*fn)(struct acpi_device *, void *),
- void *data)
-{
- struct acpi_dev_walk_context adwc = {
- .fn = fn,
- .data = data,
- };
-
- return device_for_each_child_reverse(&adev->dev, &adwc, acpi_dev_for_one_check);
-}
-
/* --------------------------------------------------------------------------
Initialization/Cleanup
-------------------------------------------------------------------------- */
--
2.35.1
Powered by blists - more mailing lists