From patchwork Fri Jul 31 21:37:34 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 38606 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6VLbBIE017264 for ; Fri, 31 Jul 2009 21:37:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752860AbZGaVhg (ORCPT ); Fri, 31 Jul 2009 17:37:36 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753004AbZGaVhg (ORCPT ); Fri, 31 Jul 2009 17:37:36 -0400 Received: from g4t0016.houston.hp.com ([15.201.24.19]:37451 "EHLO g4t0016.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752860AbZGaVhf (ORCPT ); Fri, 31 Jul 2009 17:37:35 -0400 Received: from g4t0018.houston.hp.com (g4t0018.houston.hp.com [16.234.32.27]) by g4t0016.houston.hp.com (Postfix) with ESMTP id A497D14200; Fri, 31 Jul 2009 21:37:36 +0000 (UTC) Received: from ldl.fc.hp.com (ldl.fc.hp.com [15.11.146.30]) by g4t0018.houston.hp.com (Postfix) with ESMTP id 820B81005E; Fri, 31 Jul 2009 21:37:36 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl.fc.hp.com (Postfix) with ESMTP id 50BEB39C008; Fri, 31 Jul 2009 15:37:36 -0600 (MDT) X-Virus-Scanned: Debian amavisd-new at ldl.fc.hp.com Received: from ldl.fc.hp.com ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YVnb8Go1rls0; Fri, 31 Jul 2009 15:37:34 -0600 (MDT) Received: from eh.fc.hp.com (eh.fc.hp.com [15.11.146.105]) by ldl.fc.hp.com (Postfix) with ESMTP id B299039C009; Fri, 31 Jul 2009 15:37:34 -0600 (MDT) Received: from bob.kio (localhost [127.0.0.1]) by eh.fc.hp.com (Postfix) with ESMTP id 99B3426169; Fri, 31 Jul 2009 15:37:34 -0600 (MDT) Subject: [PATCH 12/19] ACPI: add acpi_bus_get_parent() and remove "parent" arguments To: Len Brown From: Bjorn Helgaas Cc: linux-acpi@vger.kernel.org Date: Fri, 31 Jul 2009 15:37:34 -0600 Message-ID: <20090731213734.29930.2854.stgit@bob.kio> In-Reply-To: <20090731213501.29930.39957.stgit@bob.kio> References: <20090731213501.29930.39957.stgit@bob.kio> User-Agent: StGit/0.14.3.386.gb02d MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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 --- drivers/acpi/scan.c | 50 +++++++++++++++++++++++++++++++++++++------------- 1 files changed, 37 insertions(+), 13 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 35ea4c2..a57a7ae 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -658,6 +658,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) { @@ -1165,10 +1192,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; @@ -1182,7 +1208,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); @@ -1390,8 +1416,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); @@ -1444,7 +1470,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); @@ -1540,15 +1566,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); } @@ -1574,7 +1598,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;