From: Jiang Liu <jiang.liu@huawei.com>
To: Yinghai Lu <yinghai@kernel.org>,
Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>,
Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>,
Wen Congyang <wency@cn.fujitsu.com>,
Tang Chen <tangchen@cn.fujitsu.com>,
Taku Izumi <izumi.taku@jp.fujitsu.com>
Cc: Jiang Liu <jiang.liu@huawei.com>, Tony Luck <tony.luck@intel.com>,
Huang Ying <ying.huang@intel.com>,
Bob Moore <robert.moore@intel.com>, Len Brown <lenb@kernel.org>,
"Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
Bjorn Helgaas <bhelgaas@google.com>,
<linux-kernel@vger.kernel.org>, <linux-acpi@vger.kernel.org>,
<linux-pci@vger.kernel.org>, Hanjun Guo <guohanjun@huawei.com>,
Jiang Liu <liuj97@gmail.com>
Subject: [RFC PATCH v2 06/16] ACPIHP: group devices connecting to a hotplug slot according to device types
Date: Sat, 4 Aug 2012 20:13:53 +0800 [thread overview]
Message-ID: <1344082443-4608-7-git-send-email-jiang.liu@huawei.com> (raw)
In-Reply-To: <1344082443-4608-1-git-send-email-jiang.liu@huawei.com>
From: Jiang Liu <jiang.liu@huawei.com>
ACPI devices connecting to an ACPI hotplug slot are divided into groups
according to device types. Those devices will be configured/unconfigured
in order of device types when hot-adding/hot-removing system devices.
For example, when hot-adding a computer node with CPUs, memory, PCI host
bridges, IOAPICs, the order optimized for performance should be:
memory -> CPU -> IOAPIC -> PCI host bridge.
Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Jiang Liu <liuj97@gmail.com>
---
drivers/acpi/hotplug/core.c | 113 +++++++++++++++++++++++++++++++++++++++++++
include/acpi/acpi_hotplug.h | 27 +++++++++++
2 files changed, 140 insertions(+)
diff --git a/drivers/acpi/hotplug/core.c b/drivers/acpi/hotplug/core.c
index 6fac499..14b3d61 100644
--- a/drivers/acpi/hotplug/core.c
+++ b/drivers/acpi/hotplug/core.c
@@ -115,6 +115,23 @@ static char *acpihp_dev_ioapic_ids[] = {
NULL
};
+static void acpihp_dev_node_get(struct klist_node *lp)
+{
+ struct acpihp_dev_node *dp;
+
+ dp = container_of(lp, struct acpihp_dev_node, node);
+ get_device(dp->dev);
+}
+
+static void acpihp_dev_node_put(struct klist_node *lp)
+{
+ struct acpihp_dev_node *dp;
+
+ dp = container_of(lp, struct acpihp_dev_node, node);
+ put_device(dp->dev);
+ kfree(dp);
+}
+
static void acpihp_slot_release(struct device *dev)
{
struct acpihp_slot *slot = to_acpihp_slot(dev);
@@ -134,6 +151,7 @@ static void acpihp_slot_release(struct device *dev)
struct acpihp_slot *acpihp_create_slot(acpi_handle handle, char *name)
{
+ int i;
struct acpihp_slot *slot;
if (name == NULL) {
@@ -154,6 +172,9 @@ struct acpihp_slot *acpihp_create_slot(acpi_handle handle, char *name)
INIT_LIST_HEAD(&slot->slot_list);
INIT_LIST_HEAD(&slot->drvdata_list);
INIT_LIST_HEAD(&slot->slot_id_list);
+ for (i = ACPIHP_DEV_TYPE_UNKNOWN; i < ACPIHP_DEV_TYPE_MAX; i++)
+ klist_init(&slot->dev_lists[i],
+ &acpihp_dev_node_get, &acpihp_dev_node_put);
strncpy(slot->name, name, sizeof(slot->name) - 1);
mutex_init(&slot->slot_mutex);
@@ -433,6 +454,98 @@ acpi_status acpihp_slot_poweroff(struct acpihp_slot *slot)
}
EXPORT_SYMBOL_GPL(acpihp_slot_poweroff);
+/* Insert a device onto a hotplug slot's device klist. */
+int acpihp_slot_add_device(struct acpihp_slot *slot, enum acpihp_dev_type type,
+ enum acpihp_dev_state state, struct device *dev)
+{
+ struct acpihp_dev_node *np;
+
+ if (type < ACPIHP_DEV_TYPE_UNKNOWN || type >= ACPIHP_DEV_TYPE_MAX) {
+ ACPIHP_DEBUG("device type %d is invalid.\n", type);
+ return -EINVAL;
+ } else if (slot == NULL) {
+ ACPIHP_DEBUG("invalid parameter, slot is NULL.\n");
+ return -EINVAL;
+ } else if (dev == NULL) {
+ ACPIHP_DEBUG("invalid parameter, dev is NULL.\n");
+ return -EINVAL;
+ }
+
+ np = kzalloc(sizeof(*np), GFP_KERNEL);
+ if (np == NULL)
+ return -ENOMEM;
+
+ np->dev = dev;
+ np->state = state;
+ mutex_init(&np->lock);
+ klist_add_tail(&np->node, &slot->dev_lists[type]);
+ ACPIHP_DEBUG("add device %s to slot %s.\n",
+ dev_name(dev), slot->name);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(acpihp_slot_add_device);
+
+/* Remove a device from a hotplug slot's device klist. */
+int acpihp_slot_remove_device(struct acpihp_slot *slot,
+ enum acpihp_dev_type type, struct device *dev)
+{
+ int ret = -ENOENT;
+ struct klist_iter iter;
+ struct klist_node *ip;
+ struct acpihp_dev_node *np;
+
+ if (type < ACPIHP_DEV_TYPE_UNKNOWN || type >= ACPIHP_DEV_TYPE_MAX) {
+ ACPIHP_DEBUG("device type %d is invalid.\n", type);
+ return -EINVAL;
+ } else if (slot == NULL) {
+ ACPIHP_DEBUG("invalid parameter, slot is NULL.\n");
+ return -EINVAL;
+ } else if (dev == NULL) {
+ ACPIHP_DEBUG("invalid parameter, dev is NULL.\n");
+ return -EINVAL;
+ }
+
+ klist_iter_init(&slot->dev_lists[type], &iter);
+ while ((ip = klist_next(&iter)) != NULL) {
+ np = container_of(ip, struct acpihp_dev_node, node);
+ if (np->dev == dev) {
+ ACPIHP_DEBUG("remove device %s from slot %s.\n",
+ dev_name(dev), slot->name);
+ klist_del(&np->node);
+ ret = 0;
+ break;
+ }
+ }
+ klist_iter_exit(&iter);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(acpihp_slot_remove_device);
+
+/* Remove all devices from the klist */
+int acpihp_remove_device_list(struct klist *dev_list)
+{
+ struct klist_iter iter;
+ struct klist_node *ip;
+ struct acpihp_dev_node *np;
+
+ if (dev_list == NULL) {
+ ACPIHP_DEBUG("invalid parameter, dev_list is NULL.\n");
+ return -EINVAL;
+ }
+
+ klist_iter_init(dev_list, &iter);
+ while ((ip = klist_next(&iter)) != NULL) {
+ np = container_of(ip, struct acpihp_dev_node, node);
+ klist_del(&np->node);
+ }
+ klist_iter_exit(&iter);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(acpihp_remove_device_list);
+
/* 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 b81d934..cd8dd99 100644
--- a/include/acpi/acpi_hotplug.h
+++ b/include/acpi/acpi_hotplug.h
@@ -48,6 +48,24 @@ enum acpihp_dev_type {
ACPIHP_DEV_TYPE_MAX
};
+enum acpihp_dev_state {
+ DEVICE_STATE_UNKOWN = 0x00,
+ DEVICE_STATE_CONNECTED,
+ DEVICE_STATE_PRE_CONFIGURE,
+ DEVICE_STATE_CONFIGURED,
+ DEVICE_STATE_PRE_RELEASE,
+ DEVICE_STATE_RELEASED,
+ DEVICE_STATE_PRE_UNCONFIGURE,
+ DEVICE_STATE_MAX
+};
+
+struct acpihp_dev_node {
+ struct device *dev;
+ enum acpihp_dev_state state;
+ struct mutex lock;
+ struct klist_node node;
+};
+
/*
* ACPI hotplug slot is an abstraction of receptacles where a group of
* system devices could be attached, just like PCI slot in PCI hotplug.
@@ -190,6 +208,15 @@ typedef acpi_status (*acpihp_walk_device_cb)(struct acpi_device *acpi_device,
extern int acpihp_walk_devices(acpi_handle handle, acpihp_walk_device_cb cb,
void *argp);
+extern int acpihp_slot_add_device(struct acpihp_slot *slot,
+ enum acpihp_dev_type type,
+ enum acpihp_dev_state state,
+ struct device *dev);
+extern int acpihp_slot_remove_device(struct acpihp_slot *slot,
+ enum acpihp_dev_type type,
+ struct device *dev);
+extern int acpihp_remove_device_list(struct klist *dev_list);
+
extern int acpihp_debug;
#define ACPIHP_DEBUG(fmt, ...) \
--
1.7.9.5
next prev parent reply other threads:[~2012-08-04 12:13 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-04 12:13 [RFC PATCH v2 00/16] ACPI based system device hotplug framework Jiang Liu
2012-08-04 12:13 ` [RFC PATCH v2 01/16] ACPIHP: introduce a framework for ACPI based system device hotplug Jiang Liu
2012-08-04 12:13 ` [RFC PATCH v2 02/16] ACPIHP: ACPI system device hotplug slot enumerator Jiang Liu
2012-08-04 12:13 ` [RFC PATCH v2 03/16] ACPIHP: detect ACPI hotplug slots by checking ACPI _EJ0 method Jiang Liu
2012-08-04 12:13 ` [RFC PATCH v2 04/16] ACPI: introduce interfaces to manage ACPI device reference count Jiang Liu
2012-08-04 12:13 ` [RFC PATCH v2 05/16] ACPIHP: scan and walk ACPI devices connecting to an ACPI hotplug slot Jiang Liu
2012-08-04 12:13 ` Jiang Liu [this message]
2012-08-04 12:13 ` [RFC PATCH v2 07/16] ACPIHP: add callbacks into acpi_device_ops to support new hotplug framework Jiang Liu
2012-08-04 12:13 ` [RFC PATCH v2 08/16] ACPIHP: provide interfaces to associate driver specific data to hotplug slots Jiang Liu
2012-08-04 12:13 ` [RFC PATCH v2 09/16] ACPIHP: implement utility functions to support system device hotplug Jiang Liu
2012-08-04 12:13 ` [RFC PATCH v2 10/16] ACPIHP: system device hotplug driver skeleton Jiang Liu
2012-08-09 7:12 ` Tang Chen
2012-08-09 7:40 ` Jiang Liu
2012-08-09 8:41 ` Tang Chen
2012-08-09 9:36 ` Jiang Liu
2012-08-10 4:39 ` Tang Chen
2012-08-04 12:13 ` [RFC PATCH v2 11/16] ACPIHP: analyse dependences among ACPI system device hotplug slots Jiang Liu
2012-08-04 12:13 ` [RFC PATCH v2 12/16] ACPIHP: cancel inprogress ACPI system device hotplug operations Jiang Liu
2012-08-04 12:14 ` [RFC PATCH v2 13/16] ACPIHP: configure/unconfigure system devices connecting to a hotplug slot Jiang Liu
2012-08-04 12:14 ` [RFC PATCH v2 14/16] ACPIHP: implement the state machine for ACPI hotplug slots Jiang Liu
2012-08-04 12:14 ` [RFC PATCH v2 15/16] ACPIHP: implement ACPI hotplug sysfs interfaces Jiang Liu
2012-08-04 12:14 ` [RFC PATCH v2 16/16] ACPIHP: enhance ACPI container driver to support new hotplug framework Jiang Liu
2012-08-07 23:38 ` [RFC PATCH v2 00/16] ACPI based system device " Toshi Kani
2012-08-08 15:44 ` Jiang Liu
2012-08-08 16:27 ` Bjorn Helgaas
2012-08-09 15:24 ` Jiang Liu
2012-08-08 21:05 ` Toshi Kani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1344082443-4608-7-git-send-email-jiang.liu@huawei.com \
--to=jiang.liu@huawei.com \
--cc=bhelgaas@google.com \
--cc=guohanjun@huawei.com \
--cc=isimatu.yasuaki@jp.fujitsu.com \
--cc=izumi.taku@jp.fujitsu.com \
--cc=kaneshige.kenji@jp.fujitsu.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=liuj97@gmail.com \
--cc=robert.moore@intel.com \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=tangchen@cn.fujitsu.com \
--cc=tony.luck@intel.com \
--cc=wency@cn.fujitsu.com \
--cc=ying.huang@intel.com \
--cc=yinghai@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).