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>, Jiang Liu <liuj97@gmail.com>,
Hanjun Guo <guohanjun@huawei.com>
Subject: [RFC PATCH v2 11/16] ACPIHP: analyse dependences among ACPI system device hotplug slots
Date: Sat, 4 Aug 2012 20:13:58 +0800 [thread overview]
Message-ID: <1344082443-4608-12-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>
Some ACPI hotplug slots may have dependencies on other ACPI hotplug slots.
For example, if a hotpluggable memory board is connected to a hotpluggble
physical processor, the physical processor must be powered on before
powering the memory board on.
We could get dependency relationships by analyze ACPI namespace topology
and evaluate ACPI _EDL method. So this patch implements several functions
to analyze dependencies among ACPI hotplug slots.
Signed-off-by: Jiang Liu <liuj97@gmail.com>
Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
---
drivers/acpi/hotplug/Makefile | 1 +
drivers/acpi/hotplug/acpihp_drv.h | 14 ++++
drivers/acpi/hotplug/dependency.c | 167 +++++++++++++++++++++++++++++++++++++
3 files changed, 182 insertions(+)
create mode 100644 drivers/acpi/hotplug/dependency.c
diff --git a/drivers/acpi/hotplug/Makefile b/drivers/acpi/hotplug/Makefile
index d69832f..8477c71 100644
--- a/drivers/acpi/hotplug/Makefile
+++ b/drivers/acpi/hotplug/Makefile
@@ -11,3 +11,4 @@ acpihp_enum-y += slot_enum_ej0.o
obj-$(CONFIG_ACPI_HOTPLUG_DRIVER) += acpihp_drv.o
acpihp_drv-y = drv_main.o
+acpihp_drv-y += dependency.o
diff --git a/drivers/acpi/hotplug/acpihp_drv.h b/drivers/acpi/hotplug/acpihp_drv.h
index 18330f7..c4ff91c 100644
--- a/drivers/acpi/hotplug/acpihp_drv.h
+++ b/drivers/acpi/hotplug/acpihp_drv.h
@@ -53,10 +53,24 @@ struct acpihp_slot_drv {
struct acpihp_cancel_context cancel_ctx;
};
+struct acpihp_slot_dependency {
+ struct list_head node;
+ struct acpihp_slot *slot;
+ u32 opcodes;
+};
+
void acpihp_drv_get_data(struct acpihp_slot *slot,
struct acpihp_slot_drv **data);
int acpihp_drv_enumerate_devices(struct acpihp_slot *slot);
void acpihp_drv_update_slot_state(struct acpihp_slot *slot);
int acpihp_drv_update_slot_status(struct acpihp_slot *slot);
+int acpihp_drv_add_slot_to_dependency_list(struct acpihp_slot *slot,
+ struct list_head *slot_list);
+void acpihp_drv_destroy_dependency_list(struct list_head *slot_list);
+int acpihp_drv_filter_dependency_list(struct list_head *old_head,
+ struct list_head *new_head, u32 opcode);
+int acpihp_drv_generate_dependency_list(struct acpihp_slot *slot,
+ struct list_head *slot_list, enum acpihp_drv_cmd cmd);
+
#endif /* __ACPIHP_DRV_H__ */
diff --git a/drivers/acpi/hotplug/dependency.c b/drivers/acpi/hotplug/dependency.c
new file mode 100644
index 0000000..d2d7dbb
--- /dev/null
+++ b/drivers/acpi/hotplug/dependency.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2011 Huawei Tech. Co., Ltd.
+ * Copyright (C) 2011 Jiang Liu <jiang.liu@huawei.com>
+ * Copyright (C) 2011 Hanjun Guo <guohanjun@huawei.com>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/acpi.h>
+#include <acpi/acpi_hotplug.h>
+#include "acpihp_drv.h"
+
+/* Insert a slot into the dependency list at the head */
+int acpihp_drv_add_slot_to_dependency_list(struct acpihp_slot *slot,
+ struct list_head *slot_list)
+{
+ struct acpihp_slot_dependency *dep;
+
+ list_for_each_entry(dep, slot_list, node)
+ if (dep->slot == slot)
+ return 0;
+
+ dep = kzalloc(sizeof(*dep), GFP_KERNEL);
+ if (!dep) {
+ ACPIHP_DEBUG("fails to allocate memory for %s.\n", slot->name);
+ return -ENOMEM;
+ }
+ dep->slot = slot;
+ list_add(&dep->node, slot_list);
+
+ return 0;
+}
+
+static int acpihp_drv_get_online_dependency(struct acpihp_slot *slot,
+ struct list_head *slot_list)
+{
+ int ret = 0;
+ struct acpihp_slot *temp;
+
+ for (temp = slot; temp && ret == 0; temp = temp->parent)
+ ret = acpihp_drv_add_slot_to_dependency_list(temp, slot_list);
+
+ return ret;
+}
+
+static int acpihp_drv_for_each_edl(struct acpihp_slot *slot, void *argp,
+ int(*cb)(struct device *dev, void *argp))
+{
+ /* TODO */
+ return 0;
+}
+
+static int acpihp_drv_add_offline_dependency(struct device *dev, void *argp)
+{
+ int ret;
+ struct acpihp_slot *slot;
+ struct list_head *list = argp;
+
+ slot = container_of(dev, struct acpihp_slot, dev);
+ ret = acpihp_drv_add_slot_to_dependency_list(slot, list);
+ if (!ret)
+ ret = device_for_each_child(&slot->dev, argp,
+ &acpihp_drv_add_offline_dependency);
+ if (!ret)
+ ret = acpihp_drv_for_each_edl(slot, argp,
+ &acpihp_drv_add_offline_dependency);
+
+ return ret;
+}
+
+static int acpihp_drv_get_offline_dependency(struct acpihp_slot *slot,
+ struct list_head *slot_list)
+{
+ return acpihp_drv_add_offline_dependency(&slot->dev, slot_list);
+}
+
+int acpihp_drv_generate_dependency_list(struct acpihp_slot *slot,
+ struct list_head *slot_list, enum acpihp_drv_cmd cmd)
+{
+ int retval;
+
+ switch (cmd) {
+ case ACPIHP_DRV_CMD_POWERON:
+ /* fall through */
+ case ACPIHP_DRV_CMD_CONNECT:
+ /* fall through */
+ case ACPIHP_DRV_CMD_CONFIGURE:
+ retval = acpihp_drv_get_online_dependency(slot, slot_list);
+ break;
+
+ case ACPIHP_DRV_CMD_POWEROFF:
+ /* fall through */
+ case ACPIHP_DRV_CMD_DISCONNECT:
+ /* fall through */
+ case ACPIHP_DRV_CMD_UNCONFIGURE:
+ retval = acpihp_drv_get_offline_dependency(slot, slot_list);
+ break;
+
+ default:
+ retval = -EINVAL;
+ break;
+ }
+
+ return retval;
+}
+
+/*
+ * Generate a new list with slots from the old list which need to
+ * execute a specific operation.
+ */
+int acpihp_drv_filter_dependency_list(struct list_head *old_head,
+ struct list_head *new_head, u32 opcode)
+{
+ struct acpihp_slot_dependency *old_dep, *new_dep;
+
+ /* Initialize new list to empty */
+ INIT_LIST_HEAD(new_head);
+
+ list_for_each_entry(old_dep, old_head, node) {
+ /* Skip if the specified operation is not needed. */
+ if (!(old_dep->opcodes & opcode))
+ continue;
+
+ new_dep = kzalloc(sizeof(*new_dep), GFP_KERNEL);
+ if (!new_dep) {
+ ACPIHP_DEBUG("fails to filter depend list.\n");
+ acpihp_drv_destroy_dependency_list(new_head);
+ return -ENOMEM;
+ }
+
+ new_dep->slot = old_dep->slot;
+ new_dep->opcodes = old_dep->opcodes;
+ list_add_tail(&new_dep->node, new_head);
+ }
+
+ return 0;
+}
+
+void acpihp_drv_destroy_dependency_list(struct list_head *slot_list)
+{
+ struct acpihp_slot_dependency *asd, *temp;
+
+ list_for_each_entry_safe(asd, temp, slot_list, node) {
+ list_del(&asd->node);
+ kfree(asd);
+ }
+}
--
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 ` [RFC PATCH v2 06/16] ACPIHP: group devices connecting to a hotplug slot according to device types Jiang Liu
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 ` Jiang Liu [this message]
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-12-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).