From patchwork Sat Oct 6 15:27:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 189722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id ADD6F2C0336 for ; Sun, 7 Oct 2012 01:32:22 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753306Ab2JFPcD (ORCPT ); Sat, 6 Oct 2012 11:32:03 -0400 Received: from mail-da0-f46.google.com ([209.85.210.46]:44906 "EHLO mail-da0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752543Ab2JFPcB (ORCPT ); Sat, 6 Oct 2012 11:32:01 -0400 Received: by mail-da0-f46.google.com with SMTP id n41so785787dak.19 for ; Sat, 06 Oct 2012 08:32:01 -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=E6ENuyGedK1z8I8ijKHbquVN7Xagenoqtd/3+4jzwKM=; b=dDBj1bnc89NmIqld7C4KNPCz3tsAc+PkwyHzNtkwFjtBxUHX6kg9tMTvCqpTywZrA9 RsXlpotFvk3BHBUXkgc8pavZhZyt5wAfi1TAQzxcdn84xLw5Gt2L/OGG+goPbrfCYR4w v7zNEUTPIOQelYCI7EqxaHlGIJAKGKZ4Aw+3Jj7PLBPUKHp+Bhu5FEYnaHaWlVZtr2tg cnSrwmgkcXLweWgfkZODkVwopouOE4vuLb956HH435ActytmRo0UspR1l2bhW0ItT7+h ofwcTCGIS+FL+dAh2swNqvonerPesOrWbOpLUiYYEBYTXnx9UupFzzWKlcelg5iZDTAo aSWQ== Received: by 10.68.238.34 with SMTP id vh2mr25815660pbc.6.1349537521307; Sat, 06 Oct 2012 08:32:01 -0700 (PDT) Received: from localhost.localdomain ([221.221.24.247]) by mx.google.com with ESMTPS id vz8sm7785292pbc.63.2012.10.06.08.31.47 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 06 Oct 2012 08:32:00 -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, Gaohuai Han Subject: [RFC PATCH v3 09/28] ACPIHP: provide interfaces to associate driver specific data with slots Date: Sat, 6 Oct 2012 23:27:17 +0800 Message-Id: <1349537256-21670-10-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 interfaces to attach/detach/get 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 1e6dbc8..ffd3b54 100644 --- a/drivers/acpi/hotplug/core.c +++ b/drivers/acpi/hotplug/core.c @@ -35,9 +35,16 @@ #include #include "acpihp.h" +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) static DEFINE_MUTEX(acpihp_mutex); +static DEFINE_MUTEX(acpihp_drvdata_mutex); static int acpihp_class_count; static struct kset *acpihp_slot_kset; @@ -367,6 +374,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 fd46997..97febcb 100644 --- a/include/acpi/acpi_hotplug.h +++ b/include/acpi/acpi_hotplug.h @@ -257,6 +257,14 @@ extern acpi_status acpihp_slot_get_status(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 associate driver data with hotplug slots. */ +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 device objects for ACPI devices connecting to an ACPI hotplug slot, * but don't cross the hotplug slot boundary.