From patchwork Sat Aug 4 12:13:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1273631 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id DEB09DF24C for ; Sat, 4 Aug 2012 12:21:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753745Ab2HDMUr (ORCPT ); Sat, 4 Aug 2012 08:20:47 -0400 Received: from szxga01-in.huawei.com ([119.145.14.64]:51709 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753078Ab2HDMUo (ORCPT ); Sat, 4 Aug 2012 08:20:44 -0400 Received: from 172.24.2.119 (EHLO szxeml214-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id AMQ61818; Sat, 04 Aug 2012 20:20:26 +0800 (CST) Received: from SZXEML403-HUB.china.huawei.com (10.82.67.35) by szxeml214-edg.china.huawei.com (172.24.2.29) with Microsoft SMTP Server (TLS) id 14.1.323.3; Sat, 4 Aug 2012 20:14:28 +0800 Received: from localhost (10.108.108.229) by szxeml403-hub.china.huawei.com (10.82.67.35) with Microsoft SMTP Server id 14.1.323.3; Sat, 4 Aug 2012 20:14:26 +0800 From: Jiang Liu To: Yinghai Lu , Yasuaki Ishimatsu , Kenji Kaneshige , Wen Congyang , Tang Chen , Taku Izumi CC: Jiang Liu , Tony Luck , Huang Ying , Bob Moore , Len Brown , "Srivatsa S. Bhat" , Bjorn Helgaas , , , , Jiang Liu , Hanjun Guo Subject: [RFC PATCH v2 09/16] ACPIHP: implement utility functions to support system device hotplug Date: Sat, 4 Aug 2012 20:13:56 +0800 Message-ID: <1344082443-4608-10-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.11.msysgit.1 In-Reply-To: <1344082443-4608-1-git-send-email-jiang.liu@huawei.com> References: <1344082443-4608-1-git-send-email-jiang.liu@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.108.108.229] X-CFilter-Loop: Reflected Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Jiang Liu This patch implements some utility funcitons to support system device hotplug. Signed-off-by: Jiang Liu Signed-off-by: Hanjun Guo --- drivers/acpi/hotplug/core.c | 80 +++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_hotplug.h | 9 +++++ 2 files changed, 89 insertions(+) diff --git a/drivers/acpi/hotplug/core.c b/drivers/acpi/hotplug/core.c index 5e78867..230375e 100644 --- a/drivers/acpi/hotplug/core.c +++ b/drivers/acpi/hotplug/core.c @@ -634,6 +634,86 @@ int acpihp_remove_device_list(struct klist *dev_list) } EXPORT_SYMBOL_GPL(acpihp_remove_device_list); +bool acpihp_slot_present(struct acpihp_slot *slot) +{ + acpi_status status; + unsigned long long sta; + + /* A hotplug slot must implement ACPI _STA method */ + status = acpi_evaluate_integer(slot->handle, + METHOD_NAME__STA, NULL, &sta); + if (ACPI_FAILURE(status)) { + ACPIHP_WARN("fails to evaluate _STA for %p.\n", slot->name); + return false; + } + + return !!(sta & ACPI_STA_DEVICE_PRESENT); +} +EXPORT_SYMBOL_GPL(acpihp_slot_present); + +bool acpihp_slot_powered(struct acpihp_slot *slot) +{ + acpi_status status; + unsigned long long sta; + + /* hotplug slot must implement _STA method */ + status = acpi_evaluate_integer(slot->handle, + METHOD_NAME__STA, NULL, &sta); + if (ACPI_FAILURE(status)) { + ACPIHP_WARN("fails to evaluate _STA for %p.\n", slot->name); + return false; + } + + if ((sta & ACPI_STA_DEVICE_PRESENT) && + ((sta & ACPI_STA_DEVICE_ENABLED) || + (sta & ACPI_STA_DEVICE_FUNCTIONING))) + return true; + + return false; +} +EXPORT_SYMBOL_GPL(acpihp_slot_powered); + +void acpihp_slot_set_flag(struct acpihp_slot *slot, u32 flags) +{ + mutex_lock(&slot->slot_mutex); + slot->flags |= flags; + mutex_unlock(&slot->slot_mutex); +} +EXPORT_SYMBOL_GPL(acpihp_slot_set_flag); + +void acpihp_slot_clear_flag(struct acpihp_slot *slot, u32 flags) +{ + mutex_lock(&slot->slot_mutex); + slot->flags &= ~flags; + mutex_unlock(&slot->slot_mutex); +} +EXPORT_SYMBOL_GPL(acpihp_slot_clear_flag); + +u32 acpihp_slot_get_flag(struct acpihp_slot *slot, u32 flags) +{ + mutex_lock(&slot->slot_mutex); + flags &= slot->flags; + mutex_unlock(&slot->slot_mutex); + + return flags; +} +EXPORT_SYMBOL_GPL(acpihp_slot_get_flag); + +void acpihp_slot_change_state(struct acpihp_slot *slot, + enum acpihp_slot_state state) +{ + if (state < ACPIHP_SLOT_STATE_UNKNOWN || + state > ACPIHP_SLOT_STATE_MAX) { + ACPIHP_WARN("slot state %d is invalid.\n", state); + BUG_ON(state); + } + + mutex_lock(&slot->slot_mutex); + slot->state = state; + mutex_unlock(&slot->slot_mutex); +} +EXPORT_SYMBOL_GPL(acpihp_slot_change_state); + /* SYSFS interfaces */ static ssize_t acpihp_slot_object_show(struct device *d, struct device_attribute *attr, char *buf) diff --git a/include/acpi/acpi_hotplug.h b/include/acpi/acpi_hotplug.h index 1d43079..a13d9f0 100644 --- a/include/acpi/acpi_hotplug.h +++ b/include/acpi/acpi_hotplug.h @@ -289,6 +289,15 @@ extern int acpihp_slot_remove_device(struct acpihp_slot *slot, struct device *dev); extern int acpihp_remove_device_list(struct klist *dev_list); +/* Utility Functions */ +extern bool acpihp_slot_present(struct acpihp_slot *slot); +extern bool acpihp_slot_powered(struct acpihp_slot *slot); +extern void acpihp_slot_set_flag(struct acpihp_slot *slot, u32 flags); +extern void acpihp_slot_clear_flag(struct acpihp_slot *slot, u32 flags); +extern u32 acpihp_slot_get_flag(struct acpihp_slot *slot, u32 flags); +extern void acpihp_slot_change_state(struct acpihp_slot *slot, + enum acpihp_slot_state state); + extern int acpihp_debug; #define ACPIHP_DEBUG(fmt, ...) \