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: 7682691 Return-Path: X-Original-To: patchwork-platform-driver-x86@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 6EF8B9F1D3 for ; Mon, 23 Nov 2015 14:35:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 800E620704 for ; Mon, 23 Nov 2015 14:35:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7440E204E4 for ; Mon, 23 Nov 2015 14:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754462AbbKWOfe (ORCPT ); Mon, 23 Nov 2015 09:35:34 -0500 Received: from mailout1.hostsharing.net ([83.223.95.204]:60795 "EHLO mailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752872AbbKWOfb (ORCPT ); Mon, 23 Nov 2015 09:35:31 -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: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@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=ham 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))