From patchwork Sat Aug 4 12:13:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1273661 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 EFF9C3FD4F for ; Sat, 4 Aug 2012 12:21:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753078Ab2HDMVF (ORCPT ); Sat, 4 Aug 2012 08:21:05 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:53008 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753729Ab2HDMUs (ORCPT ); Sat, 4 Aug 2012 08:20:48 -0400 Received: from 172.24.2.119 (EHLO szxeml213-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id AMY70103; Sat, 04 Aug 2012 20:20:30 +0800 (CST) Received: from SZXEML401-HUB.china.huawei.com (10.82.67.31) by szxeml213-edg.china.huawei.com (172.24.2.30) with Microsoft SMTP Server (TLS) id 14.1.323.3; Sat, 4 Aug 2012 20:14:29 +0800 Received: from localhost (10.108.108.229) by szxeml401-hub.china.huawei.com (10.82.67.31) with Microsoft SMTP Server id 14.1.323.3; Sat, 4 Aug 2012 20:14:25 +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 , Gaohuai Han Subject: [RFC PATCH v2 08/16] ACPIHP: provide interfaces to associate driver specific data to hotplug slots Date: Sat, 4 Aug 2012 20:13:55 +0800 Message-ID: <1344082443-4608-9-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 provides interfaces to attach/detach/get class driver specific data to/from ACPI hotplug slots. Signed-off-by: Jiang Liu Signed-off-by: Gaohuai Han --- drivers/acpi/hotplug/core.c | 88 +++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_hotplug.h | 8 ++++ 2 files changed, 96 insertions(+) diff --git a/drivers/acpi/hotplug/core.c b/drivers/acpi/hotplug/core.c index 14b3d61..5e78867 100644 --- a/drivers/acpi/hotplug/core.c +++ b/drivers/acpi/hotplug/core.c @@ -34,11 +34,18 @@ #include #include +struct acpihp_drv_data { + struct list_head node; + struct class_interface *key; + void *data; +}; + #define to_acpihp_slot(d) container_of(d, struct acpihp_slot, dev) extern struct acpi_device *acpi_root; static DEFINE_MUTEX(acpihp_mutex); +static DEFINE_MUTEX(acpihp_drvdata_mutex); static int acpihp_class_count; static struct kset *acpihp_slot_kset; @@ -407,6 +414,87 @@ char *acpihp_get_slot_type_name(enum acpihp_slot_type type) } EXPORT_SYMBOL_GPL(acpihp_get_slot_type_name); +int acpihp_slot_attach_drv_data(struct acpihp_slot *slot, + struct class_interface *drv, void *data) +{ + struct acpihp_drv_data *dp, *cp; + + if (slot == NULL || drv == NULL) { + ACPIHP_DEBUG("invalid parameters.\n"); + return -EINVAL; + } + + dp = kzalloc(sizeof(*dp), GFP_KERNEL); + if (dp == NULL) + return -ENOMEM; + + INIT_LIST_HEAD(&dp->node); + dp->key = drv; + dp->data = data; + + mutex_lock(&acpihp_drvdata_mutex); + list_for_each_entry(cp, &slot->drvdata_list, node) + if (cp->key == drv) { + mutex_unlock(&acpihp_drvdata_mutex); + kfree(dp); + return -EEXIST; + } + list_add(&dp->node, &slot->drvdata_list); + mutex_unlock(&acpihp_drvdata_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(acpihp_slot_attach_drv_data); + +int acpihp_slot_detach_drv_data(struct acpihp_slot *slot, + struct class_interface *drv, void **data) +{ + struct acpihp_drv_data *cp; + + if (slot == NULL || drv == NULL || data == NULL) { + ACPIHP_DEBUG("invalid parameters.\n"); + return -EINVAL; + } + + mutex_lock(&acpihp_drvdata_mutex); + list_for_each_entry(cp, &slot->drvdata_list, node) + if (cp->key == drv) { + list_del(&cp->node); + *data = cp->data; + mutex_unlock(&acpihp_drvdata_mutex); + kfree(cp); + return 0; + } + mutex_unlock(&acpihp_drvdata_mutex); + + return -ENOENT; +} +EXPORT_SYMBOL_GPL(acpihp_slot_detach_drv_data); + +int acpihp_slot_get_drv_data(struct acpihp_slot *slot, + struct class_interface *drv, void **data) +{ + int ret = -ENOENT; + struct acpihp_drv_data *cp; + + if (slot == NULL || drv == NULL || data == NULL) { + ACPIHP_DEBUG("invalid parameters.\n"); + return -EINVAL; + } + + mutex_lock(&acpihp_drvdata_mutex); + list_for_each_entry(cp, &slot->drvdata_list, node) + if (cp->key == drv) { + *data = cp->data; + ret = 0; + break; + } + mutex_unlock(&acpihp_drvdata_mutex); + + return ret; +} +EXPORT_SYMBOL_GPL(acpihp_slot_get_drv_data); + /* * slot_ops should be valid during the life cycle of a slot, so no protection. */ diff --git a/include/acpi/acpi_hotplug.h b/include/acpi/acpi_hotplug.h index 2589ccb..1d43079 100644 --- a/include/acpi/acpi_hotplug.h +++ b/include/acpi/acpi_hotplug.h @@ -256,6 +256,14 @@ extern acpi_status acpihp_slot_get_capabilities(struct acpihp_slot *slot, extern acpi_status acpihp_slot_poweron(struct acpihp_slot *slot); extern acpi_status acpihp_slot_poweroff(struct acpihp_slot *slot); +/* Help routines to assoicate driver data with hotplug slot devices. */ +extern int acpihp_slot_attach_drv_data(struct acpihp_slot *slot, + struct class_interface *drv, void *data); +extern int acpihp_slot_detach_drv_data(struct acpihp_slot *slot, + struct class_interface *drv, void **data); +extern int acpihp_slot_get_drv_data(struct acpihp_slot *slot, + struct class_interface *drv, void **data); + /* * Add devices for ACPI objects connecting to an ACPI hotplug slot, * and don't cross the hotplug slot boundary.