mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Todd Poynor <tpoynor@mvista.com>
To: mochel@digitalimplant.org,
	linux-hotplug-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Hotplug events for system suspend/resume
Date: Mon, 10 May 2004 18:00:15 -0700	[thread overview]
Message-ID: <20040511010015.GA21831@dhcp193.mvista.com> (raw)

Generate synchronous hotplug events for system suspend and resume
events, via the power subsystem.  Recent discussions have indicated
various methods for notification of these events are in use today; this
is an attempt to move these into the generic power subsystem.  The patch
relies on the "synchronous hotplug events via kobject" patch sent
previously.

I fumbled around with the best to way to hook this into kobject.
Subsystems apparently aren't setup to generate hotplug events directly,
only kobjects below a subsystem may issue hotplug events.  A notifier
kobject has been created within the power subsystem for this purpose.
Any advice welcome.

Thanks -- Todd

--- linux-2.6.6-orig/kernel/power/main.c	2004-05-10 11:26:35.000000000 -0700
+++ linux-2.6.6-pm/kernel/power/main.c	2004-05-10 17:25:30.000000000 -0700
@@ -25,6 +25,9 @@
 
 struct pm_ops * pm_ops = NULL;
 u32 pm_disk_mode = PM_DISK_SHUTDOWN;
+int pm_state = PM_SUSPEND_ON;
+
+static void power_notify(void);
 
 /**
  *	pm_set_ops - Set the global power method table. 
@@ -150,20 +153,26 @@
 		goto Unlock;
 	}
 
+	pm_state = state;
+	power_notify();
+
 	if (state == PM_SUSPEND_DISK) {
 		error = pm_suspend_disk();
-		goto Unlock;
+		goto NotifyUnlock;
 	}
 
 	pr_debug("PM: Preparing system for suspend\n");
 	if ((error = suspend_prepare(state)))
-		goto Unlock;
+		goto NotifyUnlock;
 
 	pr_debug("PM: Entering state.\n");
 	error = suspend_enter(state);
 
 	pr_debug("PM: Finishing up.\n");
 	suspend_finish(state);
+ NotifyUnlock:
+	pm_state = PM_SUSPEND_ON;
+	power_notify();
  Unlock:
 	up(&pm_sem);
 	return error;
@@ -186,8 +195,28 @@
 }
 
 
+static int power_hotplug(struct kset *kset, struct kobject *kobj, char **envp,
+			 int num_envp, char *buffer, int buffer_size)
+{
+	int i = 0;
+	int length = 0;
 
-decl_subsys(power,NULL,NULL);
+	envp[i++] = buffer;
+	length += scnprintf (buffer, buffer_size - length, "STATE=%s",
+			     pm_states[pm_state] ? pm_states[pm_state] : "on");
+	if ((buffer_size - length <= 0) || (i >= num_envp))
+		return -ENOMEM;
+	++length;
+
+	envp[i] = 0;
+	return 0;
+}
+
+static struct kset_hotplug_ops power_hotplug_ops = {
+	.hotplug =	power_hotplug,
+};
+
+decl_subsys(power,NULL,&power_hotplug_ops);
 
 
 /**
@@ -247,12 +276,28 @@
 	.attrs = g,
 };
 
+struct power_notifier {
+	struct kobject kobj;
+};
+
+static struct power_notifier power_notifier;
+
+static void power_notify()
+{
+	kobject_hotplug_wait("state-change", &power_notifier.kobj);
+}
 
 static int __init pm_init(void)
 {
 	int error = subsystem_register(&power_subsys);
 	if (!error)
 		error = sysfs_create_group(&power_subsys.kset.kobj,&attr_group);
+	if (!error) {
+		kobj_set_kset_s(&power_notifier, power_subsys);
+		error = kobject_set_name(&power_notifier.kobj, "notifier");
+		if (! error)
+			kobject_register(&power_notifier.kobj);
+	}
 	return error;
 }


             reply	other threads:[~2004-05-11  1:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-11  1:00 Todd Poynor [this message]
2004-05-11 23:00 ` Greg KH
2004-05-12  0:39   ` Todd Poynor
2004-05-12  2:16     ` Nigel Cunningham
2004-05-12  2:44       ` Todd Poynor
2004-05-12  3:59         ` Nigel Cunningham
2004-05-12 19:36           ` Todd Poynor
2004-05-15  3:03             ` Pavel Machek
2004-05-12 15:08     ` Greg KH
2004-05-13 22:46       ` Tim Bird
2004-05-13 23:28         ` Greg KH
2004-05-15  2:59     ` Pavel Machek
2004-05-12 18:52 Grover, Andrew

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=20040511010015.GA21831@dhcp193.mvista.com \
    --to=tpoynor@mvista.com \
    --cc=linux-hotplug-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mochel@digitalimplant.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

all inboxes | Powered by JetHome®