From patchwork Thu Jun 13 16:32:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2717711 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E3CE39F472 for ; Thu, 13 Jun 2013 16:36:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B6CDB20453 for ; Thu, 13 Jun 2013 16:36:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1753620462 for ; Thu, 13 Jun 2013 16:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758743Ab3FMQgM (ORCPT ); Thu, 13 Jun 2013 12:36:12 -0400 Received: from mail-pb0-f54.google.com ([209.85.160.54]:46822 "EHLO mail-pb0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756078Ab3FMQgK (ORCPT ); Thu, 13 Jun 2013 12:36:10 -0400 Received: by mail-pb0-f54.google.com with SMTP id ro2so10548828pbb.27 for ; Thu, 13 Jun 2013 09:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=Uy01n10QAGe6cZxPxyi6hOB5iFrHFUUyKhtZPwsERoA=; b=wYCUA2bDOIxPHVj+h0+roGhiiMDu3lg1mtjruFgYBemv7S0ZykYbnW62zmX/fwEHn/ QyOJeNbO3H12RcvZgpKDMbakDeb8Tt1UTRTgLZweBgxX0mGGlumVELo/zY89WD24BEXC Y2Ugm2M0VeaJ7LnvNCLdtwygWaZ93fq9DPlXs95gMHUKXn7jfVERdiepcRt9CiNH/JWq TI2WDkPn1hDmJMcELISVjajYlIKbi37/8Bo51QK+liZ4T7GDWMaJ/DqDLYt+Rxd1RNzT bpdVQ4o5IVi+M3fc6aFtSMN7yuzeGeCVmMasWs8OB8zN7iU4cyp+goLSuFdy2iHkW7rB 8lsw== X-Received: by 10.66.164.232 with SMTP id yt8mr3646434pab.21.1371141369694; Thu, 13 Jun 2013 09:36:09 -0700 (PDT) Received: from localhost.localdomain ([114.250.95.159]) by mx.google.com with ESMTPSA id ty8sm176964pac.8.2013.06.13.09.36.04 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Jun 2013 09:36:09 -0700 (PDT) From: Jiang Liu To: "Rafael J . Wysocki" , Bjorn Helgaas , Yinghai Lu , "Alexander E . Patrakov" Cc: Jiang Liu , Greg Kroah-Hartman , Yijing Wang , Jiang Liu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [BUGFIX 8/9] ACPI: introduce several helper functions Date: Fri, 14 Jun 2013 00:32:31 +0800 Message-Id: <1371141152-9468-9-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1371141152-9468-1-git-send-email-jiang.liu@huawei.com> References: <1371141152-9468-1-git-send-email-jiang.liu@huawei.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Introduce several helper functions, which will be used to simplify code. Signed-off-by: Jiang Liu --- drivers/acpi/utils.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_bus.h | 5 ++++ 2 files changed, 79 insertions(+) diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index 74437130..cb66fce 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c @@ -495,3 +495,77 @@ acpi_handle_printk(const char *level, acpi_handle handle, const char *fmt, ...) kfree(buffer.pointer); } EXPORT_SYMBOL(acpi_handle_printk); + +/** + * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations + * @handle: ACPI device handle + * + * Evaluate device's _EJ0 method for hotplug operations. + */ +acpi_status acpi_evaluate_ej0(acpi_handle handle) +{ + acpi_status status; + union acpi_object arg; + struct acpi_object_list arg_list; + + arg.type = ACPI_TYPE_INTEGER; + arg.integer.value = 1; + arg_list.count = 1; + arg_list.pointer = &arg; + status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL); + if (status == AE_NOT_FOUND) { + acpi_handle_warn(handle, "No _EJ0 support for device\n"); + } else if (ACPI_FAILURE(status)) { + acpi_handle_warn(handle, "Eject failed (0x%x)\n", status); + } + + return status; +} + +/** + * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device + * @handle: ACPI device handle + * @lock: lock device if non-zero, otherwise unlock device + * + * Evaluate device's _LCK method if present to lock/unlock device + */ +acpi_status acpi_evaluate_lck(acpi_handle handle, int lock) +{ + acpi_status status; + union acpi_object arg; + struct acpi_object_list arg_list; + + arg_list.count = 1; + arg_list.pointer = &arg; + arg.type = ACPI_TYPE_INTEGER; + arg.integer.value = !!lock; + status = acpi_evaluate_object(handle, "_LCK", &arg_list, NULL); + if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { + if (lock) + acpi_handle_warn(handle, + "Locking device failed (0x%x)\n", status); + else + acpi_handle_warn(handle, + "Unlocking device failed (0x%x)\n", status); + } + + return status; +} + +/** + * acpi_has_method: Check whether @handle has a method named @name + * @handle: ACPI device handle + * @name: name of object or method + * + * Check whether @handle has a method named @name. + */ +int acpi_has_method(acpi_handle handle, char *name) +{ + acpi_status status; + acpi_handle tmp; + + status = acpi_get_handle(handle, name, &tmp); + + return ACPI_FAILURE(status) ? 0 : 1; +} +EXPORT_SYMBOL(acpi_has_method); diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 636c59f..5df5f89 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -56,6 +56,11 @@ acpi_evaluate_hotplug_ost(acpi_handle handle, u32 source_event, acpi_status acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld); + +acpi_status acpi_evaluate_ej0(acpi_handle handle); +acpi_status acpi_evaluate_lck(acpi_handle handle, int lock); +int acpi_has_method(acpi_handle handle, char *name); + #ifdef CONFIG_ACPI #include