From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-acpi@vger.kernel.org
Cc: linux-media@vger.kernel.org, rafael@kernel.org,
andriy.shevchenko@linux.intel.com,
heikki.krogerus@linux.intel.com
Subject: [PATCH v7 01/10] ACPI: scan: Remove the second DSDT traversal
Date: Tue, 28 Mar 2023 13:12:54 +0300 [thread overview]
Message-ID: <20230328101303.1458570-2-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20230328101303.1458570-1-sakari.ailus@linux.intel.com>
Collect the devices with _DEP into a list and continue processing them
after a full traversal, instead of doing a full second traversal of the
tree.
This makes the second DSDT traversal pass unnecessary as we already have
the nodes we're interested in in a linked list.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/acpi/scan.c | 125 ++++++++++++++++++++++++++++++++------------
1 file changed, 92 insertions(+), 33 deletions(-)
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 0c6f06abe3f4..df97c2babf39 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -2029,10 +2029,52 @@ static u32 acpi_scan_check_dep(acpi_handle handle, bool check_dep)
return count;
}
-static bool acpi_bus_scan_second_pass;
+/**
+ * struct acpi_postponed_handle - A postponed ACPI handle
+ * @handle: The postponed handle
+ * @list: Entry in a postponed list
+ *
+ * One such entry represents an ACPI handle the scanning of which has been
+ * postponed.
+ */
+struct acpi_postponed_handle {
+ acpi_handle handle;
+ struct list_head list;
+};
+
+/**
+ * struct acpi_scan_context - Context for scanning ACPI devices
+ * @device: The first encountered device, typically the root of the scanned tree
+ * @postponed_head: The list head of the postponed ACPI handles
+ */
+struct acpi_scan_context {
+ struct acpi_device *device;
+ struct list_head postponed_head;
+};
+
+/**
+ * acpi_bus_handle_postpone - Add an ACPI handle to a given postponed list
+ * @handle: The ACPI handle
+ * @head: Postponed list head
+ *
+ * Add a given ACPI handle to a list of ACPI objects for which the creation
+ * of the device objects is to be postponed.
+ */
+static void acpi_bus_handle_postpone(acpi_handle handle,
+ struct list_head *head)
+{
+ struct acpi_postponed_handle *ph;
+
+ ph = kzalloc(sizeof(*ph), GFP_KERNEL);
+ if (!ph)
+ return;
+
+ ph->handle = handle;
+ list_add(&ph->list, head);
+}
static acpi_status acpi_bus_check_add(acpi_handle handle, bool check_dep,
- struct acpi_device **adev_p)
+ struct acpi_scan_context *ctx)
{
struct acpi_device *device = acpi_fetch_acpi_dev(handle);
acpi_object_type acpi_type;
@@ -2051,7 +2093,7 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, bool check_dep,
/* Bail out if there are dependencies. */
if (acpi_scan_check_dep(handle, check_dep) > 0) {
- acpi_bus_scan_second_pass = true;
+ acpi_bus_handle_postpone(handle, &ctx->postponed_head);
return AE_CTRL_DEPTH;
}
@@ -2086,22 +2128,22 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, bool check_dep,
acpi_scan_init_hotplug(device);
out:
- if (!*adev_p)
- *adev_p = device;
+ if (!ctx->device)
+ ctx->device = device;
return AE_OK;
}
static acpi_status acpi_bus_check_add_1(acpi_handle handle, u32 lvl_not_used,
- void *not_used, void **ret_p)
+ void *ctx, void **unused)
{
- return acpi_bus_check_add(handle, true, (struct acpi_device **)ret_p);
+ return acpi_bus_check_add(handle, true, (struct acpi_scan_context *)ctx);
}
static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,
- void *not_used, void **ret_p)
+ void *ctx, void **device)
{
- return acpi_bus_check_add(handle, false, (struct acpi_device **)ret_p);
+ return acpi_bus_check_add(handle, false, (struct acpi_scan_context *)ctx);
}
static void acpi_default_enumeration(struct acpi_device *device)
@@ -2422,37 +2464,54 @@ EXPORT_SYMBOL_GPL(acpi_dev_get_next_consumer_dev);
*/
int acpi_bus_scan(acpi_handle handle)
{
- struct acpi_device *device = NULL;
-
- acpi_bus_scan_second_pass = false;
-
- /* Pass 1: Avoid enumerating devices with missing dependencies. */
+ struct acpi_scan_context ctx = {
+ .postponed_head = LIST_HEAD_INIT(ctx.postponed_head),
+ };
+ struct acpi_postponed_handle *ph, *tmp_ph;
+ int ret = 0;
- if (ACPI_SUCCESS(acpi_bus_check_add(handle, true, &device)))
+ if (ACPI_SUCCESS(acpi_bus_check_add(handle, true, &ctx)))
acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
- acpi_bus_check_add_1, NULL, NULL,
- (void **)&device);
-
- if (!device)
- return -ENODEV;
-
- acpi_bus_attach(device, (void *)true);
+ acpi_bus_check_add_1, NULL, (void *)&ctx,
+ NULL);
- if (!acpi_bus_scan_second_pass)
- return 0;
-
- /* Pass 2: Enumerate all of the remaining devices. */
+ if (!ctx.device) {
+ ret = -ENODEV;
+ goto out_release;
+ }
- device = NULL;
+ acpi_bus_attach(ctx.device, (void *)true);
- if (ACPI_SUCCESS(acpi_bus_check_add(handle, false, &device)))
- acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
- acpi_bus_check_add_2, NULL, NULL,
- (void **)&device);
+ /*
+ * Proceed to register ACPI devices that were postponed due to _DEP
+ * objects during the namespace walk.
+ */
+ list_for_each_entry_safe(ph, tmp_ph, &ctx.postponed_head, list) {
+ list_del(&ph->list);
+ /* Set device NULL here to obtain the root for this sub-tree. */
+ ctx.device = NULL;
+ /*
+ * Do this manually, as the namespace walk will only include
+ * sub-nodes, not the node itself. ctx.device is set to the
+ * ACPI device corresponding ph->handle.
+ */
+ acpi_bus_check_add_2(ph->handle, 0, &ctx, NULL);
+ /* Walk the rest of the sub-namespace. */
+ acpi_walk_namespace(ACPI_TYPE_ANY, ph->handle, ACPI_UINT32_MAX,
+ acpi_bus_check_add_2, NULL, (void *)&ctx,
+ NULL);
+ if (ctx.device)
+ acpi_bus_attach(ctx.device, NULL);
+ kfree(ph);
+ }
- acpi_bus_attach(device, NULL);
+out_release:
+ list_for_each_entry_safe(ph, tmp_ph, &ctx.postponed_head, list) {
+ list_del(&ph->list);
+ kfree(ph);
+ }
- return 0;
+ return ret;
}
EXPORT_SYMBOL(acpi_bus_scan);
--
2.30.2
next prev parent reply other threads:[~2023-03-28 10:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 10:12 [PATCH v7 00/10] ACPI _CRS CSI-2 and MIPI DisCo for Imaging support Sakari Ailus
2023-03-28 10:12 ` Sakari Ailus [this message]
2023-03-28 14:45 ` [PATCH v7 01/10] ACPI: scan: Remove the second DSDT traversal Andy Shevchenko
2023-03-28 14:48 ` Sakari Ailus
2023-03-28 14:55 ` Sakari Ailus
2023-03-28 10:12 ` [PATCH v7 02/10] ACPI: property: Parse data node string references in properties Sakari Ailus
2023-03-28 10:12 ` [PATCH v7 03/10] ACPI: property: Parse _CRS CSI-2 descriptor Sakari Ailus
2023-03-28 15:12 ` Andy Shevchenko
2023-03-28 15:27 ` Sakari Ailus
2023-03-28 15:46 ` Andy Shevchenko
2023-03-28 15:48 ` Sakari Ailus
2023-03-28 15:53 ` Andy Shevchenko
2023-03-28 19:26 ` Sakari Ailus
2023-03-28 10:12 ` [PATCH v7 04/10] device property: Add SOFTWARE_NODE() macro for defining software nodes Sakari Ailus
2023-03-28 10:12 ` [PATCH v7 05/10] ACPI: property: Prepare generating swnodes for ACPI and DisCo for Imaging Sakari Ailus
2023-03-28 15:44 ` Andy Shevchenko
2023-03-28 19:21 ` Sakari Ailus
2023-03-29 14:38 ` Andy Shevchenko
2023-03-29 15:20 ` Sakari Ailus
2023-03-28 10:12 ` [PATCH v7 06/10] ACPI: scan: Generate software nodes based on MIPI " Sakari Ailus
2023-03-28 15:51 ` Andy Shevchenko
2023-03-28 19:11 ` Sakari Ailus
2023-03-28 10:13 ` [PATCH v7 07/10] ACPI: property: Dig "rotation" property for devices with CSI2 _CRS Sakari Ailus
2023-03-28 10:13 ` [PATCH v7 08/10] ACPI: property: Rename parsed MIPI DisCo for Imaging properties Sakari Ailus
2023-03-28 10:13 ` [PATCH v7 09/10] ACPI: property: Skip MIPI property table without "mipi-img" prefix Sakari Ailus
2023-03-28 10:13 ` [PATCH v7 10/10] ACPI: property: Document _CRS CSI-2 and DisCo for Imaging support Sakari Ailus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230328101303.1458570-2-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox