linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 12/16] ACPIHP: cancel inprogress ACPI system device  hotplug operations
Date: Sat, 4 Aug 2012 20:13:59 +0800	[thread overview]
Message-ID: <1344082443-4608-13-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>

This patch implements functions to cancel inprogress ACPI system device
hotplug operations.

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 |   18 +++-
 drivers/acpi/hotplug/cancel.c     |  171 +++++++++++++++++++++++++++++++++++++
 3 files changed, 189 insertions(+), 1 deletion(-)
 create mode 100644 drivers/acpi/hotplug/cancel.c

diff --git a/drivers/acpi/hotplug/Makefile b/drivers/acpi/hotplug/Makefile
index 8477c71..7e10f69 100644
--- a/drivers/acpi/hotplug/Makefile
+++ b/drivers/acpi/hotplug/Makefile
@@ -12,3 +12,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
+acpihp_drv-y					+= cancel.o
diff --git a/drivers/acpi/hotplug/acpihp_drv.h b/drivers/acpi/hotplug/acpihp_drv.h
index c4ff91c..5d69272 100644
--- a/drivers/acpi/hotplug/acpihp_drv.h
+++ b/drivers/acpi/hotplug/acpihp_drv.h
@@ -44,12 +44,21 @@ enum acpihp_dev_event {
 	ACPIHP_DRV_EVENT_FROM_OS
 };
 
+enum acpihp_drv_cancel_state {
+	ACPIHP_DRV_CANCEL_INIT = 0,
+	ACPIHP_DRV_CANCEL_STARTED,
+	ACPIHP_DRV_CANCEL_OK,
+	ACPIHP_DRV_CANCEL_FAILED,
+	ACPIHP_DRV_CANCEL_MISSED,
+	ACPIHP_DRV_CANCEL_FINISHED
+};
+
 struct acpihp_slot_drv {
 	enum acpihp_dev_event	event_flag;
 	struct mutex		op_mutex; /* Prevent concurrent hotplugs. */
 	struct list_head	depend_list; /* Dependency relationship */
 	atomic_t		cancel_status;
-	atomic_t		cancel_flag;
+	atomic_t		cancel_users;
 	struct acpihp_cancel_context	cancel_ctx;
 };
 
@@ -73,4 +82,11 @@ int acpihp_drv_filter_dependency_list(struct list_head *old_head,
 int acpihp_drv_generate_dependency_list(struct acpihp_slot *slot,
 		struct list_head *slot_list, enum acpihp_drv_cmd cmd);
 
+void acpihp_drv_cancel_init(struct list_head *list);
+void acpihp_drv_cancel_notify(struct acpihp_slot *slot,
+			      enum acpihp_drv_cancel_state state);
+void acpihp_drv_cancel_fini(struct list_head *list);
+int acpihp_drv_cancel_start(struct list_head *list);
+int acpihp_drv_cancel_wait(struct list_head *list);
+
 #endif	/* __ACPIHP_DRV_H__ */
diff --git a/drivers/acpi/hotplug/cancel.c b/drivers/acpi/hotplug/cancel.c
new file mode 100644
index 0000000..6c4d95c
--- /dev/null
+++ b/drivers/acpi/hotplug/cancel.c
@@ -0,0 +1,171 @@
+/*
+ * 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/wait.h>
+#include <acpi/acpi_hotplug.h>
+#include "acpihp_drv.h"
+
+/*
+ * Implements interfaces to cancel inprogress hotplug operations.
+ * Currently only CONFIGURE and RELEASE operation stages support cancellation.
+ * Caller must serialize calls to functions by holding state_machine_mutex:
+ *	acpihp_drv_cancel_init()
+ *	acpihp_drv_cancel_fini()
+ *	acpihp_drv_cancel_start()
+ */
+static DECLARE_WAIT_QUEUE_HEAD(acpihp_drv_cancel_queue);
+
+static int acpihp_drv_check_cancel(struct acpihp_cancel_context *ctx)
+{
+	struct acpihp_slot_drv *drv_data;
+
+	BUG_ON(ctx == NULL);
+	drv_data = container_of(ctx, struct acpihp_slot_drv, cancel_ctx);
+
+	return atomic_read(&drv_data->cancel_status) != ACPIHP_DRV_CANCEL_INIT;
+}
+
+void acpihp_drv_cancel_init(struct list_head *list)
+{
+	struct acpihp_slot_drv *drv_data;
+	struct acpihp_slot_dependency *dep;
+
+	/* Wait for all cancellation threads to exit */
+	list_for_each_entry(dep, list, node) {
+		acpihp_drv_get_data(dep->slot, &drv_data);
+		drv_data->cancel_ctx.check_cancel = acpihp_drv_check_cancel;
+		atomic_set(&drv_data->cancel_status, ACPIHP_DRV_CANCEL_INIT);
+		atomic_set(&drv_data->cancel_users, 0);
+	}
+}
+
+void acpihp_drv_cancel_notify(struct acpihp_slot *slot,
+			      enum acpihp_drv_cancel_state state)
+{
+	struct acpihp_slot_drv *drv_data;
+
+	acpihp_drv_get_data(slot, &drv_data);
+	if (atomic_cmpxchg(&drv_data->cancel_status, ACPIHP_DRV_CANCEL_FINISHED,
+			   ACPIHP_DRV_CANCEL_INIT) != ACPIHP_DRV_CANCEL_INIT) {
+		atomic_set(&drv_data->cancel_status, state);
+		wake_up_all(&acpihp_drv_cancel_queue);
+	}
+}
+
+/*
+ * Wait for all cancellation threads to give up their reference count.
+ *
+ * Caller must provide mechanism to avoid currently running
+ * acpihp_drv_cancel_start() and acpihp_drv_cancel_fini()
+ * on the same list.
+ */
+void acpihp_drv_cancel_fini(struct list_head *list)
+{
+	int state;
+	struct acpihp_slot_drv *drv_data;
+	struct acpihp_slot_dependency *dep;
+
+	list_for_each_entry(dep, list, node) {
+		acpihp_drv_get_data(dep->slot, &drv_data);
+
+		/*
+		 * Wake up all cancellation threads if they are still
+		 * STARTED state.
+		 */
+		state = atomic_cmpxchg(&drv_data->cancel_status,
+				       ACPIHP_DRV_CANCEL_MISSED,
+				       ACPIHP_DRV_CANCEL_STARTED);
+		if (state == ACPIHP_DRV_CANCEL_STARTED)
+			wake_up_all(&acpihp_drv_cancel_queue);
+
+		/* Wait for all cancellation threads to exit */
+		wait_event(acpihp_drv_cancel_queue,
+			   !atomic_read(&drv_data->cancel_users));
+	}
+}
+
+/*
+ * Start cancellation on a list of hotplug slots.
+ *
+ * Caller must provide mechanism to avoid currently running
+ * acpihp_drv_cancel_start() and acpihp_drv_cancel_fini()
+ * on the same list.
+ */
+int acpihp_drv_cancel_start(struct list_head *list)
+{
+	struct acpihp_slot_drv *drv_data;
+	struct acpihp_slot_dependency *dep;
+
+	if (list_empty(list)) {
+		ACPIHP_DEBUG("dependency list is empty.\n");
+		return -ENODEV;
+	}
+
+	/* Start cancellation on all slots. */
+	list_for_each_entry(dep, list, node) {
+		acpihp_drv_get_data(dep->slot, &drv_data);
+		atomic_inc(&drv_data->cancel_users);
+		atomic_cmpxchg(&drv_data->cancel_status,
+			       ACPIHP_DRV_CANCEL_STARTED,
+			       ACPIHP_DRV_CANCEL_INIT);
+	}
+
+	return 0;
+}
+
+/*
+ * Wait for all slots on the list to reach a stable state and then check
+ * cancellation result.
+ */
+int acpihp_drv_cancel_wait(struct list_head *list)
+{
+	int status, result = 0;
+	struct acpihp_slot_drv *drv_data;
+	struct acpihp_slot_dependency *dep;
+
+	list_for_each_entry(dep, list, node) {
+		acpihp_drv_get_data(dep->slot, &drv_data);
+		wait_event(acpihp_drv_cancel_queue,
+			   atomic_read(&drv_data->cancel_status)
+				!= ACPIHP_DRV_CANCEL_STARTED);
+
+		status = atomic_read(&drv_data->cancel_status);
+		if (status == ACPIHP_DRV_CANCEL_FAILED) {
+			ACPIHP_DEBUG("fails to cancel operatin for %s.\n",
+				     dep->slot->name);
+			result = result ? : -EBUSY;
+		} else if (status == ACPIHP_DRV_CANCEL_MISSED) {
+			ACPIHP_DEBUG("misses to cancel operatin for %s.\n",
+				     dep->slot->name);
+			result = result ? : -EBUSY;
+		}
+
+		atomic_set(&drv_data->cancel_status,
+			   ACPIHP_DRV_CANCEL_FINISHED);
+		atomic_dec(&drv_data->cancel_users);
+		wake_up_all(&acpihp_drv_cancel_queue);
+	}
+
+	return result;
+}
-- 
1.7.9.5



  parent reply	other threads:[~2012-08-04 12:18 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 ` [RFC PATCH v2 11/16] ACPIHP: analyse dependences among ACPI system device hotplug slots Jiang Liu
2012-08-04 12:13 ` Jiang Liu [this message]
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-13-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).