From patchwork Sun Nov 4 12:50:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1693861 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 5FF5640060 for ; Sun, 4 Nov 2012 12:51:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753782Ab2KDMvO (ORCPT ); Sun, 4 Nov 2012 07:51:14 -0500 Received: from mail-pb0-f46.google.com ([209.85.160.46]:46858 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753839Ab2KDMvH (ORCPT ); Sun, 4 Nov 2012 07:51:07 -0500 Received: by mail-pb0-f46.google.com with SMTP id rr4so3339156pbb.19 for ; Sun, 04 Nov 2012 04:51:07 -0800 (PST) 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=8K//GyaoCTLpum5d6cOARiT+r8lx2ukm9MAlxU6oye8=; b=KsOPC81BedBZrRuwoo450X4qTMJ6kp6CCh9zfpdw+95N0KJCNV13PhYdvNT5D/mqzu o41tkjL26E5sc3JPafcHyyprj575VFPrnoRwqxU+P1iRQDkNTAFcPDRMIo8WSZ3IyRSZ ECWJy/ZlHDtW34c6jIh3ewrNGXXWCu1C/gMxWS/nHDaf+FAZEHM37Gc6MUWLZdkFFaf1 48o+SEq/E61/vTftV7qz+ij8V0ybAFd3NoYr02qCmdnjyIP/UbsG7VBwgJzatd9GzyGH tsDS4S29BAWI/pJfdmGQeWILvzrhy1RuJvLcinouIBYzn1gSOiHNwn+3wYkidBLFeH4K 9puw== Received: by 10.68.227.162 with SMTP id sb2mr22534607pbc.4.1352033467097; Sun, 04 Nov 2012 04:51:07 -0800 (PST) Received: from localhost.localdomain ([120.196.98.117]) by mx.google.com with ESMTPS id a4sm8922768pax.12.2012.11.04.04.51.00 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 04 Nov 2012 04:51:06 -0800 (PST) From: Jiang Liu To: "Rafael J . Wysocki" , Yinghai Lu , Tony Luck , Yasuaki Ishimatsu , Wen Congyang , Tang Chen , Taku Izumi , Bjorn Helgaas Cc: Jiang Liu , Kenji Kaneshige , Huang Ying , Bob Moore , Len Brown , "Srivatsa S . Bhat" , Yijing Wang , Hanjun Guo , Jiang Liu , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org Subject: [ACPIHP PATCH part2 05/13] ACPIHP: implement utility interfaces to support system device hotplug Date: Sun, 4 Nov 2012 20:50:07 +0800 Message-Id: <1352033415-5606-6-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1352033415-5606-1-git-send-email-jiang.liu@huawei.com> References: <1352033415-5606-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 interfaces to support ACPI based 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 bad8e99..139b9c2 100644 --- a/drivers/acpi/hotplug/core.c +++ b/drivers/acpi/hotplug/core.c @@ -591,6 +591,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 9d466ea..3297f51 100644 --- a/include/acpi/acpi_hotplug.h +++ b/include/acpi/acpi_hotplug.h @@ -295,6 +295,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 Interfaces */ +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, ...) \