From patchwork Sat Oct 6 15:27:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1558671 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 9E59CDF238 for ; Sat, 6 Oct 2012 15:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754016Ab2JFPcV (ORCPT ); Sat, 6 Oct 2012 11:32:21 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:34290 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753605Ab2JFPcT (ORCPT ); Sat, 6 Oct 2012 11:32:19 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so2754692pad.19 for ; Sat, 06 Oct 2012 08:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=VOZRmQD6gsYIQI7aUrV+e/w9DTaU6R1twY8wNBl9VuU=; b=iWp1PbXbuNTN82v01SMjgqbS02VC/iQZajGLVne2OcTOEUlqzuiNEzK0hYCIuK8hDK uHKjP3otMckm7C7vo1W3c27bhrB7NuWBt0ExZF2koB4WwonKKjWZvl1b/py77fJlugne sNFsK9RLaJtrFiHCkoWY5KCo6qEzqbAyeZLj+u5f2Y7UoAyjschIfrTs/D1kXxDAlfaE 9BKSl7Yb9qDGwUHUgsxN42u8W37Prh2MrAn2cP/kl33B82fDEc+GHfX/CJjyNOTPeWKH ftbFOw7DR/NvQ35I4tU4FAvOS59GnNldI5VR8IcTk4G+lSVdLW8UZsQYT25Jvco0ZRIy uUZg== Received: by 10.68.129.233 with SMTP id nz9mr39400779pbb.136.1349537538858; Sat, 06 Oct 2012 08:32:18 -0700 (PDT) Received: from localhost.localdomain ([221.221.24.247]) by mx.google.com with ESMTPS id vz8sm7785292pbc.63.2012.10.06.08.32.01 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 06 Oct 2012 08:32:18 -0700 (PDT) From: Jiang Liu To: Yinghai Lu , Yasuaki Ishimatsu , Kenji Kaneshige , Wen Congyang , Tang Chen , Taku Izumi Cc: Hanjun Guo , Yijing Wang , Gong Chen , Jiang Liu , Tony Luck , Huang Ying , Bob Moore , Len Brown , "Srivatsa S . Bhat" , Bjorn Helgaas , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org Subject: [RFC PATCH v3 10/28] ACPIHP: implement utility functions to support system device hotplug Date: Sat, 6 Oct 2012 23:27:18 +0800 Message-Id: <1349537256-21670-11-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1349537256-21670-1-git-send-email-jiang.liu@huawei.com> References: <1349537256-21670-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 This patch implements some utility functions to support system device hotplug. Signed-off-by: Jiang Liu Signed-off-by: Hanjun Guo --- drivers/acpi/hotplug/core.c | 77 +++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_hotplug.h | 9 +++++ 2 files changed, 86 insertions(+) diff --git a/drivers/acpi/hotplug/core.c b/drivers/acpi/hotplug/core.c index ffd3b54..ffc9e40 100644 --- a/drivers/acpi/hotplug/core.c +++ b/drivers/acpi/hotplug/core.c @@ -605,6 +605,83 @@ 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; + + status = acpihp_slot_get_status(slot, &sta); + if (ACPI_FAILURE(status)) { + ACPIHP_SLOT_WARN(slot, "fails to get status.\n"); + 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 = acpihp_slot_get_status(slot, &sta); + if (ACPI_FAILURE(status)) { + ACPIHP_SLOT_WARN(slot, "fails to get status.\n"); + 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_SLOT_WARN(slot, "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 97febcb..0506f73 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_WARN(fmt, ...) \