From patchwork Sun Nov 4 12:50:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1694141 Return-Path: X-Original-To: patchwork-linux-acpi@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 A242C3FDD2 for ; Sun, 4 Nov 2012 12:53:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753783Ab2KDMvF (ORCPT ); Sun, 4 Nov 2012 07:51:05 -0500 Received: from mail-pa0-f46.google.com ([209.85.220.46]:63072 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752930Ab2KDMvA (ORCPT ); Sun, 4 Nov 2012 07:51:00 -0500 Received: by mail-pa0-f46.google.com with SMTP id hz1so3347088pad.19 for ; Sun, 04 Nov 2012 04:51:00 -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=qaHtf7nNd1uSs62mltMMbVtDbkd3u4c3clYVFBSxNg4=; b=0J1c8YA6ucRBUu1PdmhUnURlwadnDTJpMuizPjoC18HQeCPXwdyHUC4cCqrOm8oy+C 1D9uJAWFeY8px5uqWLaUVCqGxRsTEoX0aWjBYLD2t+Cw8hHr3B1oJYLZHwaoNpfW7EOE RD/nyYIUL2MTSMZdFCh/CUIlR0Y6fgxZxNZ4NUvdlE2OlDY5C7sP40qhh0hPx5DNFr2F M2NGw+rseaNN7pmcYLLG39Uu/ofigYHDGP+rMq2SwoCeATyKAF7AUS5nCaLlpcUQ5ING HCi7Y/OkvGqz13MzO18w2M666qZhb8AroFpq3trm6GUYGWi+owrO5SJRcfzKCTBPqBj9 2fEg== Received: by 10.68.233.201 with SMTP id ty9mr22466373pbc.14.1352033460046; Sun, 04 Nov 2012 04:51:00 -0800 (PST) Received: from localhost.localdomain ([120.196.98.117]) by mx.google.com with ESMTPS id a4sm8922768pax.12.2012.11.04.04.50.46 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 04 Nov 2012 04:50:59 -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, Gaohuai Han Subject: [ACPIHP PATCH part2 04/13] ACPIHP: provide interfaces to manage driver data associated with hotplug slots Date: Sun, 4 Nov 2012 20:50:06 +0800 Message-Id: <1352033415-5606-5-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-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org This patch implements interfaces to manage driver data associated with ACPI hotplug slots. Signed-off-by: Jiang Liu Signed-off-by: Gaohuai Han --- drivers/acpi/hotplug/core.c | 88 +++++++++++++++++++++++++++++++++++++++++++ include/acpi/acpi_hotplug.h | 7 ++++ 2 files changed, 95 insertions(+) diff --git a/drivers/acpi/hotplug/core.c b/drivers/acpi/hotplug/core.c index 7ef8f9b..bad8e99 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; @@ -355,6 +362,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); + acpi_status acpihp_slot_get_status(struct acpihp_slot *slot, u64 *status) { acpi_status rc; diff --git a/include/acpi/acpi_hotplug.h b/include/acpi/acpi_hotplug.h index 35f15a8..9d466ea 100644 --- a/include/acpi/acpi_hotplug.h +++ b/include/acpi/acpi_hotplug.h @@ -264,6 +264,13 @@ 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); +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); + /* * Scan and create ACPI device objects for devices attached to the handle, * but don't cross the hotplug slot boundary.