public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
Subject: [PATCH v3 10/17] ACPI: add acpi_bus_get_parent() and remove "parent" arguments
Date: Mon, 21 Sep 2009 13:29:35 -0600	[thread overview]
Message-ID: <20090921192935.21322.94526.stgit@bob.kio> (raw)
In-Reply-To: <20090921192656.21322.23072.stgit@bob.kio>

This patch adds acpi_bus_get_parent(), which ascends the namespace until
it finds a parent with an acpi_device.

Then we use acpi_bus_get_parent() in acpi_add_single_object(), so callers
don't have to figure out or keep track of the parent acpi_device.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
---
 drivers/acpi/scan.c |   50 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index f2e2834..f205b36 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -662,6 +662,33 @@ EXPORT_SYMBOL(acpi_bus_unregister_driver);
 /* --------------------------------------------------------------------------
                                  Device Enumeration
    -------------------------------------------------------------------------- */
+static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
+{
+	acpi_status status;
+	int ret;
+	struct acpi_device *device;
+
+	/*
+	 * Fixed hardware devices do not appear in the namespace and do not
+	 * have handles, but we fabricate acpi_devices for them, so we have
+	 * to deal with them specially.
+	 */
+	if (handle == NULL)
+		return acpi_root;
+
+	do {
+		status = acpi_get_parent(handle, &handle);
+		if (status == AE_NULL_ENTRY)
+			return NULL;
+		if (ACPI_FAILURE(status))
+			return acpi_root;
+
+		ret = acpi_bus_get_device(handle, &device);
+		if (ret == 0)
+			return device;
+	} while (1);
+}
+
 acpi_status
 acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
 {
@@ -1217,10 +1244,9 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
 	return 0;
 }
 
-static int
-acpi_add_single_object(struct acpi_device **child,
-		       struct acpi_device *parent, acpi_handle handle, int type,
-			struct acpi_bus_ops *ops)
+static int acpi_add_single_object(struct acpi_device **child,
+				  acpi_handle handle, int type,
+				  struct acpi_bus_ops *ops)
 {
 	int result;
 	struct acpi_device *device;
@@ -1234,7 +1260,7 @@ acpi_add_single_object(struct acpi_device **child,
 
 	device->device_type = type;
 	device->handle = handle;
-	device->parent = parent;
+	device->parent = acpi_bus_get_parent(handle);
 	device->bus_ops = *ops; /* workround for not call .start */
 
 	acpi_device_get_busid(device);
@@ -1434,8 +1460,8 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
 		}
 
 		if (ops->acpi_op_add)
-			status = acpi_add_single_object(&child, parent,
-				chandle, type, ops);
+			status = acpi_add_single_object(&child, chandle, type,
+							ops);
 		else
 			status = acpi_bus_get_device(chandle, &child);
 
@@ -1488,7 +1514,7 @@ acpi_bus_add(struct acpi_device **child,
 	memset(&ops, 0, sizeof(ops));
 	ops.acpi_op_add = 1;
 
-	result = acpi_add_single_object(child, parent, handle, type, &ops);
+	result = acpi_add_single_object(child, handle, type, &ops);
 	if (!result)
 		result = acpi_bus_scan(*child, &ops);
 
@@ -1584,15 +1610,13 @@ static int acpi_bus_scan_fixed(void)
 	 * Enumerate all fixed-feature devices.
 	 */
 	if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {
-		result = acpi_add_single_object(&device, acpi_root,
-						NULL,
+		result = acpi_add_single_object(&device, NULL,
 						ACPI_BUS_TYPE_POWER_BUTTON,
 						&ops);
 	}
 
 	if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
-		result = acpi_add_single_object(&device, acpi_root,
-						NULL,
+		result = acpi_add_single_object(&device, NULL,
 						ACPI_BUS_TYPE_SLEEP_BUTTON,
 						&ops);
 	}
@@ -1618,7 +1642,7 @@ int __init acpi_scan_init(void)
 	/*
 	 * Create the root device in the bus's device tree
 	 */
-	result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
+	result = acpi_add_single_object(&acpi_root, ACPI_ROOT_OBJECT,
 					ACPI_BUS_TYPE_SYSTEM, &ops);
 	if (result)
 		goto Done;


  parent reply	other threads:[~2009-09-21 19:31 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-21 19:28 [PATCH v3 00/17] ACPI: cleanups for hotplug Bjorn Helgaas
2009-09-21 19:28 ` [PATCH v3 01/17] ACPICA: fixup after acpi_get_object_info() change Bjorn Helgaas
2009-09-21 19:28 ` [PATCH v3 02/17] ACPI: add debug for device addition Bjorn Helgaas
2009-09-21 19:28 ` [PATCH v3 03/17] ACPI: remove unused acpi_bus_scan_fixed() argument Bjorn Helgaas
2009-09-21 19:29 ` [PATCH v3 04/17] ACPI: remove redundant "handle" and "parent" arguments Bjorn Helgaas
2009-09-21 19:29 ` [PATCH v3 05/17] ACPI: save device_type in acpi_device Bjorn Helgaas
2009-09-21 19:29 ` [PATCH v3 06/17] ACPI: use device_type rather than comparing HID Bjorn Helgaas
2009-09-21 19:29 ` [PATCH v3 07/17] ACPI: remove acpi_device_set_context() "type" argument Bjorn Helgaas
2009-09-21 19:29 ` [PATCH v3 08/17] ACPI: remove redundant "type" arguments Bjorn Helgaas
2009-09-21 19:29 ` [PATCH v3 09/17] ACPI: remove unnecessary argument checking Bjorn Helgaas
2009-09-21 19:29 ` Bjorn Helgaas [this message]
2009-09-21 19:29 ` [PATCH v3 11/17] ACPI: convert acpi_bus_scan() to operate on an acpi_handle Bjorn Helgaas
2009-09-21 19:29 ` [PATCH v3 12/17] ACPI: enumerate namespace before adding functional fixed hardware devices Bjorn Helgaas
2009-09-21 19:29 ` [PATCH v3 13/17] ACPI: identify device tree root by null parent pointer, not ACPI_BUS_TYPE Bjorn Helgaas
2009-09-23  3:09   ` ykzhao
2009-09-23 16:14     ` Bjorn Helgaas
2009-09-24  2:10       ` ykzhao
2009-09-24  3:31         ` Bjorn Helgaas
2009-09-21 19:29 ` [PATCH v3 14/17] ACPI: use acpi_walk_namespace() to enumerate devices Bjorn Helgaas
2009-09-21 19:30 ` [PATCH v3 15/17] ACPI: add acpi_bus_get_status_handle() Bjorn Helgaas
2009-09-21 19:30 ` [PATCH v3 16/17] ACPI: factor out device type and status checking Bjorn Helgaas
2009-09-21 19:30 ` [PATCH v3 17/17] ACPI: handle re-enumeration, when acpi_devices might already exist Bjorn Helgaas

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=20090921192935.21322.94526.stgit@bob.kio \
    --to=bjorn.helgaas@hp.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.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