From patchwork Mon Nov 23 14:34:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 7682721 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4E0B6BF90C for ; Mon, 23 Nov 2015 14:36:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 748BC20729 for ; Mon, 23 Nov 2015 14:36:46 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 128572073A for ; Mon, 23 Nov 2015 14:36:45 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 009892654BC; Mon, 23 Nov 2015 15:36:38 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D209E265522; Mon, 23 Nov 2015 15:36:05 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id CDAD4265522; Mon, 23 Nov 2015 15:36:04 +0100 (CET) Received: from mailout1.hostsharing.net (mailout1.hostsharing.net [83.223.95.204]) by alsa0.perex.cz (Postfix) with ESMTP id 7175926553A for ; Mon, 23 Nov 2015 15:35:32 +0100 (CET) Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout1.hostsharing.net (Postfix) with ESMTPS id BEF1710340033; Mon, 23 Nov 2015 15:35:29 +0100 (CET) Received: from localhost (6-38-90-81.adsl.cmo.de [81.90.38.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id EE03A603E044; Mon, 23 Nov 2015 15:35:27 +0100 (CET) X-Mailbox-Line: From d66501819cfa8f3d3b07708d3f20e3e20d07e4f8 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Lukas Wunner Date: Mon, 23 Nov 2015 15:34:55 +0100 To: linux-acpi@vger.kernel.org, devel@acpica.org Cc: Hui Wang , alsa-devel@alsa-project.org, Takashi Iwai , platform-driver-x86@vger.kernel.org, "Lee, Chun-Yi" , Mark Brown , Corentin Chary , Darren Hart Subject: [alsa-devel] [PATCH 1/5] ACPICA: Add acpi_dev_present X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP There are 7 drivers which call acpi_get_devices to check for the presence of a particular ACPI HID, each defining its own copy of a mostly identical callback. Add acpi_dev_present, the ACPI equivalent to pci_dev_present, allowing us to deduplicate all that boilerplate in the drivers. Signed-off-by: Lukas Wunner --- drivers/acpi/acpica/nsxfeval.c | 46 ++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpixf.h | 7 +++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/acpi/acpica/nsxfeval.c b/drivers/acpi/acpica/nsxfeval.c index 6ee1e52..19293fa 100644 --- a/drivers/acpi/acpica/nsxfeval.c +++ b/drivers/acpi/acpica/nsxfeval.c @@ -828,6 +828,52 @@ ACPI_EXPORT_SYMBOL(acpi_get_devices) /******************************************************************************* * + * FUNCTION: acpi_ns_dev_present_callback + * + * PARAMETERS: Callback from acpi_get_devices + * + * RETURN: Status + * + * DESCRIPTION: Minimal callback to be passed to acpi_get_devices which + * performs no further filtering and terminates the search + * immediately. + * + ******************************************************************************/ +static acpi_status acpi_ns_dev_present_callback(acpi_handle handle, u32 level, + void *context, void **retval) +{ + *(bool *)context = true; + return AE_CTRL_TERMINATE; +} + +/******************************************************************************* + * + * FUNCTION: acpi_dev_present + * + * PARAMETERS: HID - HID to search for. + * + * RETURNS True if a matching object of type Device was found. + * + * DESCRIPTION: Performs a walk of the namespace tree. When a matching object + * of type Device is found, the search is terminated immediately. + * + ******************************************************************************/ + +bool +acpi_dev_present(const char *HID) +{ + acpi_status status; + bool found = false; + + status = acpi_get_devices(HID, acpi_ns_dev_present_callback, &found, + NULL); + return ACPI_SUCCESS(status) && found; +} + +ACPI_EXPORT_SYMBOL(acpi_dev_present) + +/******************************************************************************* + * * FUNCTION: acpi_attach_data * * PARAMETERS: obj_handle - Namespace node diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h index 3aaaa86..f299347 100644 --- a/include/acpi/acpixf.h +++ b/include/acpi/acpixf.h @@ -115,6 +115,11 @@ prototype; #endif +#ifndef ACPI_EXTERNAL_RETURN_BOOL +#define ACPI_EXTERNAL_RETURN_BOOL(prototype) \ + prototype; +#endif + /***************************************************************************** * * Public globals and runtime configuration options @@ -483,6 +488,8 @@ ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_walk_callback user_function, void *context, void **return_value)) +ACPI_EXTERNAL_RETURN_BOOL(bool + acpi_dev_present(const char *HID)) ACPI_EXTERNAL_RETURN_STATUS(acpi_status acpi_get_name(acpi_handle object, u32 name_type, struct acpi_buffer *ret_path_ptr))