All of lore.kernel.org
 help / color / mirror / Atom feed
* Hotplug events for system suspend/resume
@ 2004-05-11  1:00 Todd Poynor
  2004-05-11 23:00   ` Greg KH
  0 siblings, 1 reply; 25+ messages in thread
From: Todd Poynor @ 2004-05-11  1:00 UTC (permalink / raw)
  To: mochel, linux-hotplug-devel, linux-kernel

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;
 }


^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2004-05-17 13:22 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-11  1:00 Hotplug events for system suspend/resume Todd Poynor
2004-05-11 23:00 ` Greg KH
2004-05-11 23:00   ` Greg KH
2004-05-12  0:39   ` Todd Poynor
2004-05-12  0:39     ` Todd Poynor
2004-05-12  2:16     ` Nigel Cunningham
2004-05-12  2:16       ` Nigel Cunningham
2004-05-12  2:44       ` Todd Poynor
2004-05-12  2:44         ` Todd Poynor
2004-05-12  3:59         ` Nigel Cunningham
2004-05-12  3:59           ` Nigel Cunningham
2004-05-12 19:36           ` Todd Poynor
2004-05-12 19:36             ` Todd Poynor
2004-05-15  3:03             ` Pavel Machek
2004-05-15  3:03               ` Pavel Machek
2004-05-12 15:08     ` Greg KH
2004-05-12 15:08       ` Greg KH
2004-05-13 22:46       ` Tim Bird
2004-05-13 22:46         ` Tim Bird
2004-05-13 23:28         ` Greg KH
2004-05-13 23:28           ` Greg KH
2004-05-15  2:59     ` Pavel Machek
2004-05-15  2:59       ` Pavel Machek
2004-05-12 18:52   ` Grover, Andrew
2004-05-12 18:52     ` Grover, Andrew

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.