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: 7682821 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C1B0B9F1D3 for ; Mon, 23 Nov 2015 14:41:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD11720732 for ; Mon, 23 Nov 2015 14:41:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F240820742 for ; Mon, 23 Nov 2015 14:41:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753005AbbKWOlX (ORCPT ); Mon, 23 Nov 2015 09:41:23 -0500 Received: from mailout1.hostsharing.net ([83.223.95.204]:43069 "EHLO mailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752982AbbKWOlW (ORCPT ); Mon, 23 Nov 2015 09:41:22 -0500 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 Subject: [PATCH 1/5] ACPICA: Add acpi_dev_present To: linux-acpi@vger.kernel.org, devel@acpica.org Cc: platform-driver-x86@vger.kernel.org, Darren Hart , Corentin Chary , "Lee, Chun-Yi" , alsa-devel@alsa-project.org, Takashi Iwai , Hui Wang , Mark Brown Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.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))