* [Suspend2][ 00/21] User interface
@ 2006-06-27 4:41 Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 01/21] [Suspend2] User interface c header Nigel Cunningham
` (20 more replies)
0 siblings, 21 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
These patches add user interface support. We support using
simple printks if no userspace helper is available, or
passing messages through to such a helper.
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 01/21] [Suspend2] User interface c header.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 02/21] [Suspend2] Modify action state Nigel Cunningham
` (19 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
kernel/power/ui.c header. This implements the kernel side of the user
interface.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
new file mode 100644
index 0000000..1ef8957
--- /dev/null
+++ b/kernel/power/ui.c
@@ -0,0 +1,69 @@
+/*
+ * kernel/power/ui.c
+ *
+ * Copyright (C) 1998-2001 Gabor Kuti <seasons@fornax.hu>
+ * Copyright (C) 1998,2001,2002 Pavel Machek <pavel@suse.cz>
+ * Copyright (C) 2002-2003 Florent Chabaud <fchabaud@free.fr>
+ * Copyright (C) 2002-2006 Nigel Cunningham <nigel@suspend2.net>
+ *
+ * This file is released under the GPLv2.
+ *
+ * Routines for Suspend2's user interface.
+ *
+ * The user interface code talks to a userspace program via a
+ * netlink socket.
+ *
+ * The kernel side:
+ * - starts the userui program;
+ * - sends text messages and progress bar status;
+ *
+ * The user space side:
+ * - passes messages regarding user requests (abort, toggle reboot etc)
+ *
+ */
+
+#define __KERNEL_SYSCALLS__
+
+#include <linux/suspend.h>
+#include <linux/freezer.h>
+#include <linux/console.h>
+#include <linux/ctype.h>
+#include <linux/tty.h>
+#include <linux/vt_kern.h>
+#include <linux/module.h>
+#include <linux/reboot.h>
+#include <linux/kmod.h>
+#include <linux/security.h>
+#include <linux/syscalls.h>
+
+#include "proc.h"
+#include "modules.h"
+#include "suspend2.h"
+#include "suspend2_common.h"
+#include "ui.h"
+#include "version.h"
+#include "netlink.h"
+#include "power.h"
+#include "power_off.h"
+
+static char local_printf_buf[1024]; /* Same as printk - should be safe */
+
+/*! The console log level we default to. */
+int suspend_default_console_level = 0;
+
+#ifdef CONFIG_NET
+static struct user_helper_data ui_helper_data;
+static struct suspend_module_ops userui_ops;
+static int orig_loglevel;
+static int orig_default_message_loglevel;
+static int orig_kmsg;
+
+static char lastheader[512];
+static int lastheader_message_len = 0;
+extern int console_suspended;
+
+/* Number of distinct progress amounts that userspace can display */
+static int progress_granularity = 30;
+
+DECLARE_WAIT_QUEUE_HEAD(userui_wait_for_key);
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 02/21] [Suspend2] Modify action state.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 01/21] [Suspend2] User interface c header Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 03/21] [Suspend2] Tell userspace to redraw the screen Nigel Cunningham
` (18 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Modify the suspend_action state in response to a userspace message. This
variable is an unsigned long treated as bitflags tell us whether to reboot
instead of powering down, pause between step, log everything and so on.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 1ef8957..b952bf7 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -67,3 +67,19 @@ static int progress_granularity = 30;
DECLARE_WAIT_QUEUE_HEAD(userui_wait_for_key);
+static void ui_nl_set_state(int n)
+{
+ /* Only let them change certain settings */
+ static const int suspend_action_mask =
+ (1 << SUSPEND_REBOOT) | (1 << SUSPEND_PAUSE) | (1 << SUSPEND_SLOW) |
+ (1 << SUSPEND_LOGALL) | (1 << SUSPEND_SINGLESTEP) |
+ (1 << SUSPEND_PAUSE_NEAR_PAGESET_END);
+
+ suspend_action = (suspend_action & (~suspend_action_mask)) |
+ (n & suspend_action_mask);
+
+ if (!test_action_state(SUSPEND_PAUSE) &&
+ !test_action_state(SUSPEND_SINGLESTEP))
+ wake_up_interruptible(&userui_wait_for_key);
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 03/21] [Suspend2] Tell userspace to redraw the screen.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 01/21] [Suspend2] User interface c header Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 02/21] [Suspend2] Modify action state Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 04/21] [Suspend2] Process abort request Nigel Cunningham
` (17 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Tell userspace to redraw the screen. Used after the atomic restore.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index b952bf7..0441be5 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -83,3 +83,12 @@ static void ui_nl_set_state(int n)
wake_up_interruptible(&userui_wait_for_key);
}
+void userui_redraw(void)
+{
+ if (ui_helper_data.pid == -1)
+ return;
+
+ suspend_send_netlink_message(&ui_helper_data,
+ USERUI_MSG_REDRAW, NULL, 0);
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 04/21] [Suspend2] Process abort request.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (2 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 03/21] [Suspend2] Tell userspace to redraw the screen Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 05/21] [Suspend2] Receive a message from the userui Nigel Cunningham
` (16 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Handle a request via the userui that we abort a cycle. This is ignored at
resume time or if we're already aborting.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 0441be5..365c033 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -92,3 +92,29 @@ void userui_redraw(void)
USERUI_MSG_REDRAW, NULL, 0);
}
+/* request_abort_suspend
+ *
+ * Description: Handle the user requesting the cancellation of a suspend by
+ * pressing escape.
+ * Callers: Invoked from a netlink packet from userspace when the user presses
+ * escape.
+ */
+void request_abort_suspend(void)
+{
+ if (test_result_state(SUSPEND_ABORT_REQUESTED))
+ return;
+
+ if (test_suspend_state(SUSPEND_NOW_RESUMING)) {
+ suspend_prepare_status(CLEAR_BAR, "Escape pressed. "
+ "Powering down again.");
+ suspend_power_down();
+ } else {
+ suspend_prepare_status(CLEAR_BAR, "--- ESCAPE PRESSED :"
+ " ABORTING PROCESS ---");
+ set_result_state(SUSPEND_ABORTED);
+ set_result_state(SUSPEND_ABORT_REQUESTED);
+
+ wake_up_interruptible(&userui_wait_for_key);
+ }
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 05/21] [Suspend2] Receive a message from the userui.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (3 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 04/21] [Suspend2] Process abort request Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 06/21] [Suspend2] Get userui storage needed Nigel Cunningham
` (15 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Receive a message from the userspace user interface.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 365c033..48719de 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -118,3 +118,61 @@ void request_abort_suspend(void)
}
}
+static int userui_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
+{
+ int type;
+ int *data;
+
+ type = nlh->nlmsg_type;
+
+ /* A control message: ignore them */
+ if (type < NETLINK_MSG_BASE)
+ return 0;
+
+ /* Unknown message: reply with EINVAL */
+ if (type >= USERUI_MSG_MAX)
+ return -EINVAL;
+
+ /* All operations require privileges, even GET */
+ if (security_netlink_recv(skb))
+ return -EPERM;
+
+ /* Only allow one task to receive NOFREEZE privileges */
+ if (type == NETLINK_MSG_NOFREEZE_ME && ui_helper_data.pid != -1)
+ return -EBUSY;
+
+ data = (int*)NLMSG_DATA(nlh);
+
+ switch (type) {
+ case USERUI_MSG_ABORT:
+ request_abort_suspend();
+ break;
+ case USERUI_MSG_GET_STATE:
+ suspend_send_netlink_message(&ui_helper_data,
+ USERUI_MSG_GET_STATE, &suspend_action,
+ sizeof(suspend_action));
+ break;
+ case USERUI_MSG_GET_DEBUG_STATE:
+ suspend_send_netlink_message(&ui_helper_data,
+ USERUI_MSG_GET_DEBUG_STATE,
+ &suspend_debug_state,
+ sizeof(suspend_debug_state));
+ break;
+ case USERUI_MSG_SET_STATE:
+ if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(int)))
+ return -EINVAL;
+ ui_nl_set_state(*data);
+ break;
+ case USERUI_MSG_SET_DEBUG_STATE:
+ if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(int)))
+ return -EINVAL;
+ suspend_debug_state = (*data);
+ break;
+ case USERUI_MSG_SPACE:
+ wake_up_interruptible(&userui_wait_for_key);
+ break;
+ }
+
+ return 1;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 06/21] [Suspend2] Get userui storage needed.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (4 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 05/21] [Suspend2] Receive a message from the userui Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 07/21] [Suspend2] Serialise userui configuration info Nigel Cunningham
` (14 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Return the amount of space needed in the image header for userui settings.
This is currently just the name of the program we're running.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 48719de..21c6be7 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -176,3 +176,8 @@ static int userui_user_rcv_msg(struct sk
return 1;
}
+static unsigned long userui_storage_needed(void)
+{
+ return sizeof(ui_helper_data.program) + 1 + sizeof(int);
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 07/21] [Suspend2] Serialise userui configuration info.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (5 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 06/21] [Suspend2] Get userui storage needed Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 08/21] [Suspend2] Get amount of memory needed for userui Nigel Cunningham
` (13 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Save and load routines for storing the userspace user interface
configuration information in the image header.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 21c6be7..16e540d 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -181,3 +181,26 @@ static unsigned long userui_storage_need
return sizeof(ui_helper_data.program) + 1 + sizeof(int);
}
+static int userui_save_config_info(char *buf)
+{
+ *((int *) buf) = progress_granularity;
+ memcpy(buf + sizeof(int), ui_helper_data.program, sizeof(ui_helper_data.program));
+ return sizeof(ui_helper_data.program) + sizeof(int) + 1;
+}
+
+static void userui_load_config_info(char *buf, int size)
+{
+ progress_granularity = *((int *) buf);
+ size -= sizeof(int);
+
+ /* Don't load the saved path if one has already been set */
+ if (ui_helper_data.program[0])
+ return;
+
+ if (size > sizeof(ui_helper_data.program))
+ size = sizeof(ui_helper_data.program);
+
+ memcpy(ui_helper_data.program, buf + sizeof(int), size);
+ ui_helper_data.program[sizeof(ui_helper_data.program)-1] = '\0';
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 08/21] [Suspend2] Get amount of memory needed for userui.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (6 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 07/21] [Suspend2] Serialise userui configuration info Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 09/21] [Suspend2] Update progress bar Nigel Cunningham
` (12 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Return the amount of memory needed for the userui to operate. This doesn't
need to include the size of the program and it's data, just extra pages
needed while writing the image.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 16e540d..2f779a5 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -204,3 +204,9 @@ static void userui_load_config_info(char
ui_helper_data.program[sizeof(ui_helper_data.program)-1] = '\0';
}
+static unsigned long userui_memory_needed(void)
+{
+ /* ball park figure of 128 pages */
+ return (128 * PAGE_SIZE);
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 09/21] [Suspend2] Update progress bar.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (7 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 08/21] [Suspend2] Get amount of memory needed for userui Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 10/21] [Suspend2] __suspend_message Nigel Cunningham
` (11 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Update the progress bar (if userui is displaying one), and possbly display
some text in the bar itself (eg a/b MB written).
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 73 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 2f779a5..b01c89b 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -210,3 +210,76 @@ static unsigned long userui_memory_neede
return (128 * PAGE_SIZE);
}
+/* suspend_update_status
+ *
+ * Description: Update the progress bar and (if on) in-bar message.
+ * Arguments: UL value, maximum: Current progress percentage (value/max).
+ * const char *fmt, ...: Message to be displayed in the middle
+ * of the progress bar.
+ * Note that a NULL message does not mean that any previous
+ * message is erased! For that, you need suspend_prepare_status with
+ * clearbar on.
+ * Returns: Unsigned long: The next value where status needs to be updated.
+ * This is to reduce unnecessary calls to update_status.
+ */
+unsigned long suspend_update_status(unsigned long value, unsigned long maximum,
+ const char *fmt, ...)
+{
+ static int last_step = -1;
+ struct userui_msg_params msg;
+ int bitshift;
+ int this_step;
+ unsigned long next_update;
+
+ if (ui_helper_data.pid == -1)
+ return 0;
+
+ if ((!maximum) || (!progress_granularity))
+ return maximum;
+
+ if (value < 0)
+ value = 0;
+
+ if (value > maximum)
+ value = maximum;
+
+ /* Try to avoid math problems - we can't do 64 bit math here
+ * (and shouldn't need it - anyone got screen resolution
+ * of 65536 pixels or more?) */
+ bitshift = fls(maximum) - 16;
+ if (bitshift > 0) {
+ unsigned long temp_maximum = maximum >> bitshift;
+ unsigned long temp_value = value >> bitshift;
+ this_step = (int)
+ (temp_value * progress_granularity / temp_maximum);
+ next_update = (((this_step + 1) * temp_maximum /
+ progress_granularity) + 1) << bitshift;
+ } else {
+ this_step = (int) (value * progress_granularity / maximum);
+ next_update = ((this_step + 1) * maximum /
+ progress_granularity) + 1;
+ }
+
+ if (this_step == last_step)
+ return next_update;
+
+ memset(&msg, 0, sizeof(msg));
+
+ msg.a = this_step;
+ msg.b = progress_granularity;
+
+ if (fmt) {
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(msg.text, sizeof(msg.text), fmt, args);
+ va_end(args);
+ msg.text[sizeof(msg.text)-1] = '\0';
+ }
+
+ suspend_send_netlink_message(&ui_helper_data, USERUI_MSG_PROGRESS,
+ &msg, sizeof(msg));
+ last_step = this_step;
+
+ return next_update;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 10/21] [Suspend2] __suspend_message.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (8 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 09/21] [Suspend2] Update progress bar Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 11/21] [Suspend2] Wait for keypress Nigel Cunningham
` (10 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
The guts of the suspend_message routine. This is for highlevel descriptions
of what we're doing, which are also printk'd if we're logging everything.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index b01c89b..3378766 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -283,3 +283,51 @@ unsigned long suspend_update_status(unsi
return next_update;
}
+/* __suspend_message.
+ *
+ * Description: This function is intended to do the same job as printk, but
+ * without normally logging what is printed. The point is to be
+ * able to get debugging info on screen without filling the logs
+ * with "1/534. ^M 2/534^M. 3/534^M"
+ *
+ * It may be called from an interrupt context - can't sleep!
+ *
+ * Arguments: int mask: The debugging section(s) this message belongs to.
+ * int level: The level of verbosity of this message.
+ * int restartline: Whether to output a \r or \n with this line
+ * (\n if we're logging all output).
+ * const char *fmt, ...: Message to be displayed a la printk.
+ */
+void __suspend_message(unsigned long section, unsigned long level,
+ int normally_logged,
+ const char *fmt, ...)
+{
+ struct userui_msg_params msg;
+
+ if ((level) && (level > console_loglevel))
+ return;
+
+ memset(&msg, 0, sizeof(msg));
+
+ msg.a = section;
+ msg.b = level;
+ msg.c = normally_logged;
+
+ if (fmt) {
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(msg.text, sizeof(msg.text), fmt, args);
+ va_end(args);
+ msg.text[sizeof(msg.text)-1] = '\0';
+ }
+
+ if (test_action_state(SUSPEND_LOGALL))
+ printk("%s\n", msg.text);
+
+ if (ui_helper_data.pid == -1)
+ return;
+
+ suspend_send_netlink_message(&ui_helper_data, USERUI_MSG_MESSAGE,
+ &msg, sizeof(msg));
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 11/21] [Suspend2] Wait for keypress.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (9 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 10/21] [Suspend2] __suspend_message Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 12/21] [Suspend2] Abort a cycle Nigel Cunningham
` (9 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Wait for a keypress. This might be via userspace (normal case), or in the
special case of an emergency message early in the process, via reading
/dev/console. In these later cases, we can't rely on the userspace process
existing, and want to give the user some control over what happens. We do
implement a timeout though, so unattended boots don't hang indefinitely.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 3378766..6271a24 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -331,3 +331,74 @@ void __suspend_message(unsigned long sec
&msg, sizeof(msg));
}
+static void wait_for_key_via_userui(void)
+{
+ DECLARE_WAITQUEUE(wait, current);
+
+ add_wait_queue(&userui_wait_for_key, &wait);
+ set_current_state(TASK_INTERRUPTIBLE);
+
+ interruptible_sleep_on(&userui_wait_for_key);
+
+ set_current_state(TASK_RUNNING);
+ remove_wait_queue(&userui_wait_for_key, &wait);
+}
+
+char suspend_wait_for_keypress(int timeout)
+{
+ int fd;
+ char key = '\0';
+ struct termios t, t_backup;
+
+ if (ui_helper_data.pid != -1) {
+ wait_for_key_via_userui();
+ key = ' ';
+ goto out;
+ }
+
+ /* We should be guaranteed /dev/console exists after populate_rootfs() in
+ * init/main.c
+ */
+ if ((fd = sys_open("/dev/console", O_RDONLY, 0)) < 0) {
+ printk("Couldn't open /dev/console.\n");
+ goto out;
+ }
+
+ if (sys_ioctl(fd, TCGETS, (long)&t) < 0)
+ goto out_close;
+
+ memcpy(&t_backup, &t, sizeof(t));
+
+ t.c_lflag &= ~(ISIG|ICANON|ECHO);
+ t.c_cc[VMIN] = 0;
+ if (timeout)
+ t.c_cc[VTIME] = timeout*10;
+
+ if (sys_ioctl(fd, TCSETS, (long)&t) < 0)
+ goto out_restore;
+
+ while (1) {
+ if (sys_read(fd, &key, 1) <= 0) {
+ key = '\0';
+ break;
+ }
+ key = tolower(key);
+ if (test_suspend_state(SUSPEND_SANITY_CHECK_PROMPT)) {
+ if (key == 'c') {
+ set_suspend_state(SUSPEND_CONTINUE_REQ);
+ break;
+ } else if (key == ' ')
+ break;
+ } else
+ break;
+ }
+
+out_restore:
+ sys_ioctl(fd, TCSETS, (long)&t_backup);
+
+out_close:
+ sys_close(fd);
+out:
+ return key;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 12/21] [Suspend2] Abort a cycle.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (10 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 11/21] [Suspend2] Wait for keypress Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 13/21] [Suspend2] Main message output Nigel Cunningham
` (8 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Let the user know that we're aborting if they don't already know, possibly
also waiting for a keypress expressing acknowledgement.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 6271a24..6542f3f 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -402,3 +402,40 @@ out:
return key;
}
+/* abort_suspend
+ *
+ * Description: Begin to abort a cycle. If this wasn't at the user's request
+ * (and we're displaying output), tell the user why and wait for
+ * them to acknowledge the message.
+ * Arguments: A parameterised string (imagine this is printk) to display,
+ * telling the user why we're aborting.
+ */
+
+void abort_suspend(const char *fmt, ...)
+{
+ va_list args;
+ int printed_len = 0;
+
+ if (!test_result_state(SUSPEND_ABORTED)) {
+ if (!test_result_state(SUSPEND_ABORT_REQUESTED)) {
+ va_start(args, fmt);
+ printed_len = vsnprintf(local_printf_buf,
+ sizeof(local_printf_buf), fmt, args);
+ va_end(args);
+ if (ui_helper_data.pid != -1)
+ printed_len = sprintf(local_printf_buf + printed_len,
+ " (Press SPACE to continue)");
+ suspend_prepare_status(CLEAR_BAR, local_printf_buf);
+
+ /*
+ * Make sure message seen - wait for shift to be
+ * released if being pressed
+ */
+ if (ui_helper_data.pid != -1)
+ suspend_wait_for_keypress(0);
+ }
+ /* Turn on aborting flag */
+ set_result_state(SUSPEND_ABORTED);
+ }
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 13/21] [Suspend2] Main message output.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (11 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 12/21] [Suspend2] Abort a cycle Nigel Cunningham
@ 2006-06-27 4:41 ` Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 14/21] [Suspend2] Conditionally pause Nigel Cunningham
` (7 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:41 UTC (permalink / raw)
To: linux-kernel
Output one of the main messages describing our progress, possibly also
clearing the progress bar. These messages are printk'd if there is no
active userui.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 6542f3f..b11edb8 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -439,3 +439,30 @@ void abort_suspend(const char *fmt, ...)
}
}
+/* suspend_prepare_status
+ * Description: Prepare the 'nice display', drawing the header and version,
+ * along with the current action and perhaps also resetting the
+ * progress bar.
+ * Arguments:
+ * int clearbar: Whether to reset the progress bar.
+ * const char *fmt, ...: The action to be displayed.
+ */
+void suspend_prepare_status(int clearbar, const char *fmt, ...)
+{
+ va_list args;
+
+ if (fmt) {
+ va_start(args, fmt);
+ lastheader_message_len = vsnprintf(lastheader, 512, fmt, args);
+ va_end(args);
+ }
+
+ if (clearbar)
+ suspend_update_status(0, 1, NULL);
+
+ __suspend_message(0, SUSPEND_STATUS, 1, lastheader, NULL);
+
+ if (ui_helper_data.pid == -1)
+ printk(KERN_EMERG "%s\n", lastheader);
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 14/21] [Suspend2] Conditionally pause.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (12 preceding siblings ...)
2006-06-27 4:41 ` [Suspend2][ 13/21] [Suspend2] Main message output Nigel Cunningham
@ 2006-06-27 4:42 ` Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 15/21] [Suspend2] Prepare ui for work Nigel Cunningham
` (6 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:42 UTC (permalink / raw)
To: linux-kernel
Pause until the user presses the space bar while we have a userui helper
and the abort flag isn't set and we're pausing or single stepping. Pausing
is also conditional on a parameter so that we can pause at some places when
singlestepping and not pause if not singlestepping.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index b11edb8..a915a75 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -466,3 +466,36 @@ void suspend_prepare_status(int clearbar
printk(KERN_EMERG "%s\n", lastheader);
}
+/* suspend_cond_pause
+ *
+ * Description: Potentially pause and wait for the user to tell us to continue.
+ * We normally only pause when @pause is set.
+ * Arguments: int pause: Whether we normally pause.
+ * char *message: The message to display. Not parameterised
+ * because it's normally a constant.
+ */
+
+void suspend_cond_pause(int pause, char *message)
+{
+#ifdef CONFIG_PM_DEBUG
+ int displayed_message = 0, last_key = 0;
+
+ while (last_key != 32 &&
+ ui_helper_data.pid != -1 &&
+ (!test_result_state(SUSPEND_ABORTED)) &&
+ ((test_action_state(SUSPEND_PAUSE) && pause) ||
+ (test_action_state(SUSPEND_SINGLESTEP)))) {
+ if (!displayed_message) {
+ suspend_prepare_status(DONT_CLEAR_BAR,
+ "%s Press SPACE to continue.%s",
+ message ? message : "",
+ (test_action_state(SUSPEND_SINGLESTEP)) ?
+ " Single step on." : "");
+ displayed_message = 1;
+ }
+ last_key = suspend_wait_for_keypress(0);
+ }
+#endif
+ schedule();
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 15/21] [Suspend2] Prepare ui for work.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (13 preceding siblings ...)
2006-06-27 4:42 ` [Suspend2][ 14/21] [Suspend2] Conditionally pause Nigel Cunningham
@ 2006-06-27 4:42 ` Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 16/21] [Suspend2] Cleanup console after suspending Nigel Cunningham
` (5 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:42 UTC (permalink / raw)
To: linux-kernel
Set logging settings and attempt to start the userspace helper ('userui').
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index a915a75..eedab56 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -499,3 +499,36 @@ void suspend_cond_pause(int pause, char
schedule();
}
+extern asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd,
+ unsigned long arg);
+
+/* suspend_prepare_console
+ *
+ * Description: Prepare a console for use, save current settings.
+ * Returns: Boolean: Whether an error occured. Errors aren't
+ * treated as fatal, but a warning is printed.
+ */
+void suspend_prepare_console(void)
+{
+ orig_loglevel = console_loglevel;
+ orig_default_message_loglevel = default_message_loglevel;
+ orig_kmsg = kmsg_redirect;
+ kmsg_redirect = fg_console + 1;
+ default_message_loglevel = 1;
+ console_loglevel = suspend_default_console_level;
+
+ ui_helper_data.pid = -1;
+
+ if (userui_ops.disabled)
+ return;
+
+ if (!*ui_helper_data.program) {
+ printk("suspend_userui: program not configured. suspend_userui disabled.\n");
+ return;
+ }
+
+ suspend_netlink_setup(&ui_helper_data);
+
+ return;
+}
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 16/21] [Suspend2] Cleanup console after suspending.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (14 preceding siblings ...)
2006-06-27 4:42 ` [Suspend2][ 15/21] [Suspend2] Prepare ui for work Nigel Cunningham
@ 2006-06-27 4:42 ` Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 17/21] [Suspend2] Early boot message support Nigel Cunningham
` (4 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:42 UTC (permalink / raw)
To: linux-kernel
Close down the userspace program (if one was running) and reset logging.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index eedab56..2012c2a 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -532,3 +532,34 @@ void suspend_prepare_console(void)
return;
}
+/* suspend_cleanup_console
+ *
+ * Description: Restore the settings we saved above.
+ */
+
+void suspend_cleanup_console(void)
+{
+ suspend_default_console_level = console_loglevel;
+
+ if (ui_helper_data.pid > -1) {
+ struct task_struct *t;
+
+ suspend_send_netlink_message(&ui_helper_data,
+ NETLINK_MSG_CLEANUP, NULL, 0);
+
+ read_lock(&tasklist_lock);
+ if ((t = find_task_by_pid(ui_helper_data.pid)))
+ t->flags &= ~PF_NOFREEZE;
+ read_unlock(&tasklist_lock);
+
+ suspend_netlink_close(&ui_helper_data);
+
+ ui_helper_data.pid = -1;
+ }
+
+ console_loglevel = orig_loglevel;
+ kmsg_redirect = orig_kmsg;
+ default_message_loglevel = orig_default_message_loglevel;
+}
+#endif
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 17/21] [Suspend2] Early boot message support.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (15 preceding siblings ...)
2006-06-27 4:42 ` [Suspend2][ 16/21] [Suspend2] Cleanup console after suspending Nigel Cunningham
@ 2006-06-27 4:42 ` Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 18/21] [Suspend2] Userspace proc entries Nigel Cunningham
` (3 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:42 UTC (permalink / raw)
To: linux-kernel
Give the user the option of continuing or rebooting when we discover a
problem really early in the resume, prior to userspace program being
started. We may not even be able to start the userspace program, so we need
limited support for user interaction - that or we need to always invalidate
images if problems occur or such like.
Some would complain that the kernel shouldn't be seeking to interact with
the user. While I see that argument, it seems to me that helping the user
do what they want to do is far more important. The prompt has a timeout, so
we won't hang indefinitely if there's no response.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 108 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 2012c2a..3d246e4 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -563,3 +563,111 @@ void suspend_cleanup_console(void)
}
#endif
+/* suspend_early_boot_message()
+ * Description: Handle errors early in the process of booting.
+ * The user may press C to continue booting, perhaps
+ * invalidating the image, or space to reboot.
+ * This works from either the serial console or normally
+ * attached keyboard.
+ *
+ * Note that we come in here from init, while the kernel is
+ * locked. If we want to get events from the serial console,
+ * we need to temporarily unlock the kernel.
+ *
+ * suspend_early_boot_message may also be called post-boot.
+ * In this case, it simply printks the message and returns.
+ *
+ * Arguments: int Whether we are able to erase the image.
+ * int default_answer. What to do when we timeout. This
+ * will normally be continue, but the user might
+ * provide command line options (__setup) to override
+ * particular cases.
+ * Char *. Pointer to a string explaining why we're moaning.
+ */
+
+#define say(message, a...) printk(KERN_EMERG message, ##a)
+#define message_timeout 25 /* message_timeout * 10 must fit in 8 bits */
+
+int suspend_early_boot_message(int message_detail, int default_answer, char *warning_reason, ...)
+{
+ unsigned long orig_state = get_suspend_state(), continue_req = 0;
+ va_list args;
+ int printed_len;
+
+ if (warning_reason) {
+ va_start(args, warning_reason);
+ printed_len = vsnprintf(local_printf_buf,
+ sizeof(local_printf_buf),
+ warning_reason,
+ args);
+ va_end(args);
+ }
+
+ if (!test_suspend_state(SUSPEND_BOOT_TIME)) {
+ printk(name_suspend "%s\n", local_printf_buf);
+ return default_answer;
+ }
+
+ /* We might be called directly from do_mounts_initrd if the
+ * user fails to set up their initrd properly. We need to
+ * enable the keyboard handler by setting the running flag */
+ set_suspend_state(SUSPEND_RUNNING);
+
+#if defined(CONFIG_VT) || defined(CONFIG_SERIAL_CONSOLE)
+ console_loglevel = 7;
+
+ say("=== Suspend2 ===\n\n");
+ if (warning_reason) {
+ say("BIG FAT WARNING!! %s\n\n", local_printf_buf);
+ switch (message_detail) {
+ case 0:
+ say("If you continue booting, note that any image WILL NOT BE REMOVED.\n");
+ say("Suspend is unable to do so because the appropriate modules aren't\n");
+ say("loaded. You should manually remove the image to avoid any\n");
+ say("possibility of corrupting your filesystem(s) later.\n");
+ break;
+ case 1:
+ say("If you want to use the current suspend image, reboot and try\n");
+ say("again with the same kernel that you suspended from. If you want\n");
+ say("to forget that image, continue and the image will be erased.\n");
+ break;
+ }
+ say("Press SPACE to reboot or C to continue booting with this kernel\n\n");
+ say("Default action if you don't select one in %d seconds is: %s.\n",
+ message_timeout,
+ default_answer == SUSPEND_CONTINUE_REQ ?
+ "continue booting" : "reboot");
+ } else {
+ say("BIG FAT WARNING!!\n\n");
+ say("You have tried to resume from this image before.\n");
+ say("If it failed once, it may well fail again.\n");
+ say("Would you like to remove the image and boot normally?\n");
+ say("This will be equivalent to entering noresume2 on the\n");
+ say("kernel command line.\n\n");
+ say("Press SPACE to remove the image or C to continue resuming.\n\n");
+ say("Default action if you don't select one in %d seconds is: %s.\n",
+ message_timeout,
+ !!default_answer ?
+ "continue resuming" : "remove the image");
+ }
+
+ set_suspend_state(SUSPEND_SANITY_CHECK_PROMPT);
+ clear_suspend_state(SUSPEND_CONTINUE_REQ);
+
+ if (suspend_wait_for_keypress(message_timeout) == 0) /* We timed out */
+ continue_req = !!default_answer;
+ else
+ continue_req = test_suspend_state(SUSPEND_CONTINUE_REQ);
+
+ if ((warning_reason) && (!continue_req))
+ machine_restart(NULL);
+
+ restore_suspend_state(orig_state);
+ if (continue_req)
+ set_suspend_state(SUSPEND_CONTINUE_REQ);
+
+#endif /* CONFIG_VT or CONFIG_SERIAL_CONSOLE */
+ return -EPERM;
+}
+#undef say
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 18/21] [Suspend2] Userspace proc entries.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (16 preceding siblings ...)
2006-06-27 4:42 ` [Suspend2][ 17/21] [Suspend2] Early boot message support Nigel Cunningham
@ 2006-06-27 4:42 ` Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 19/21] [Suspend2] Operations for userspace interface module Nigel Cunningham
` (2 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:42 UTC (permalink / raw)
To: linux-kernel
Declare proc entries for the userspace interface.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 3d246e4..4955d5f 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -671,3 +671,109 @@ int suspend_early_boot_message(int messa
}
#undef say
+/*
+ * User interface specific /proc/suspend entries.
+ */
+
+static struct suspend_proc_data proc_params[] = {
+#ifdef CONFIG_NET
+#ifdef CONFIG_PROC_FS
+ { .filename = "default_console_level",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_INTEGER,
+ .data = {
+ .integer = {
+ .variable = &suspend_default_console_level,
+ .minimum = 0,
+#ifdef CONFIG_PM_DEBUG
+ .maximum = 7,
+#else
+ .maximum = 1,
+#endif
+
+ }
+ }
+ },
+
+ { .filename = "enable_escape",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_BIT,
+ .data = {
+ .bit = {
+ .bit_vector = &suspend_action,
+ .bit = SUSPEND_CAN_CANCEL,
+ }
+ }
+ },
+
+#ifdef CONFIG_PM_DEBUG
+ { .filename = "debug_sections",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_UL,
+ .data = {
+ .ul = {
+ .variable = &suspend_debug_state,
+ .minimum = 0,
+ .maximum = 2 << 30,
+ }
+ }
+ },
+
+ { .filename = "log_everything",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_BIT,
+ .data = {
+ .bit = {
+ .bit_vector = &suspend_action,
+ .bit = SUSPEND_LOGALL,
+ }
+ }
+ },
+
+ { .filename = "pause_between_steps",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_BIT,
+ .data = {
+ .bit = {
+ .bit_vector = &suspend_action,
+ .bit = SUSPEND_PAUSE,
+ }
+ }
+ },
+#endif
+ { .filename = "disable_userui_support",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_INTEGER,
+ .data = {
+ .integer = {
+ .variable = &userui_ops.disabled,
+ .minimum = 0,
+ .maximum = 1,
+ }
+ }
+ },
+ { .filename = "userui_progress_granularity",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_INTEGER,
+ .data = {
+ .integer = {
+ .variable = &progress_granularity,
+ .minimum = 1,
+ .maximum = 2048,
+ }
+ }
+ },
+ { .filename = "userui_program",
+ .permissions = PROC_RW,
+ .type = SUSPEND_PROC_DATA_STRING,
+ .data = {
+ .string = {
+ .variable = ui_helper_data.program,
+ .max_length = 255,
+ }
+ }
+ }
+#endif
+#endif
+};
+
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 19/21] [Suspend2] Operations for userspace interface module.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (17 preceding siblings ...)
2006-06-27 4:42 ` [Suspend2][ 18/21] [Suspend2] Userspace proc entries Nigel Cunningham
@ 2006-06-27 4:42 ` Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 20/21] [Suspend2] Load time initialisation for user interface code Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 21/21] [Suspend2] kernel/power/ui.h Nigel Cunningham
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:42 UTC (permalink / raw)
To: linux-kernel
Declare the operations for the core to store our configuration information
in the image header and know how much memory is needed for work.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 4955d5f..3f2f549 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -777,3 +777,14 @@ static struct suspend_proc_data proc_par
#endif
};
+static struct suspend_module_ops userui_ops = {
+ .type = MISC_MODULE,
+ .name = "Userspace UI Support",
+ .module = THIS_MODULE,
+#ifdef CONFIG_NET
+ .storage_needed = userui_storage_needed,
+ .save_config_info = userui_save_config_info,
+ .load_config_info = userui_load_config_info,
+ .memory_needed = userui_memory_needed,
+#endif
+};
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 20/21] [Suspend2] Load time initialisation for user interface code.
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (18 preceding siblings ...)
2006-06-27 4:42 ` [Suspend2][ 19/21] [Suspend2] Operations for userspace interface module Nigel Cunningham
@ 2006-06-27 4:42 ` Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 21/21] [Suspend2] kernel/power/ui.h Nigel Cunningham
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:42 UTC (permalink / raw)
To: linux-kernel
Initialise when userui code is loaded.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.c | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.c b/kernel/power/ui.c
index 3f2f549..83a0370 100644
--- a/kernel/power/ui.c
+++ b/kernel/power/ui.c
@@ -788,3 +788,34 @@ static struct suspend_module_ops userui_
.memory_needed = userui_memory_needed,
#endif
};
+
+/* suspend_console_proc_init
+ * Description: Boot time initialisation for user interface.
+ */
+static __init int suspend_console_proc_init(void)
+{
+ int result, i, numfiles = sizeof(proc_params) / sizeof(struct suspend_proc_data);
+
+ if (!(result = suspend_register_module(&userui_ops)))
+ for (i=0; i< numfiles; i++)
+ suspend_register_procfile(&proc_params[i]);
+
+#ifdef CONFIG_NET
+ ui_helper_data.nl = NULL;
+ ui_helper_data.program[0] = '\0';
+ ui_helper_data.pid = -1;
+ ui_helper_data.skb_size = sizeof(struct userui_msg_params);
+ ui_helper_data.pool_limit = 6;
+ ui_helper_data.netlink_id = NETLINK_SUSPEND2_USERUI;
+ ui_helper_data.name = "userspace ui";
+ ui_helper_data.rcv_msg = userui_user_rcv_msg;
+ ui_helper_data.interface_version = 6;
+ ui_helper_data.must_init = 0;
+ ui_helper_data.not_ready = suspend_cleanup_console;
+ init_completion(&ui_helper_data.wait_for_process);
+#endif
+
+ return result;
+}
+
+late_initcall(suspend_console_proc_init);
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
* [Suspend2][ 21/21] [Suspend2] kernel/power/ui.h
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
` (19 preceding siblings ...)
2006-06-27 4:42 ` [Suspend2][ 20/21] [Suspend2] Load time initialisation for user interface code Nigel Cunningham
@ 2006-06-27 4:42 ` Nigel Cunningham
20 siblings, 0 replies; 22+ messages in thread
From: Nigel Cunningham @ 2006-06-27 4:42 UTC (permalink / raw)
To: linux-kernel
Userspace user interface header file.
Signed-off-by: Nigel Cunningham <nigel@suspend2.net>
kernel/power/ui.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/kernel/power/ui.h b/kernel/power/ui.h
new file mode 100644
index 0000000..8b295e2
--- /dev/null
+++ b/kernel/power/ui.h
@@ -0,0 +1,71 @@
+/*
+ * kernel/power/ui.h
+ *
+ * Copyright 2004-2006 Nigel Cunningham <nigel@suspend2.net>
+ */
+
+extern int suspend_default_console_level;
+
+enum {
+ DONT_CLEAR_BAR,
+ CLEAR_BAR
+};
+
+enum {
+ /* Userspace -> Kernel */
+ USERUI_MSG_ABORT = 0x11,
+ USERUI_MSG_SET_STATE = 0x12,
+ USERUI_MSG_GET_STATE = 0x13,
+ USERUI_MSG_GET_DEBUG_STATE = 0x14,
+ USERUI_MSG_SET_DEBUG_STATE = 0x15,
+ USERUI_MSG_SET_PROGRESS_GRANULARITY = 0x17,
+ USERUI_MSG_SPACE = 0x18,
+
+ /* Kernel -> Userspace */
+ USERUI_MSG_MESSAGE = 0x21,
+ USERUI_MSG_PROGRESS = 0x22,
+ USERUI_MSG_REDRAW = 0x25,
+ USERUI_MSG_KEYPRESS = 0x26,
+ USERUI_MSG_DEBUG_STATE = 0x29,
+
+ USERUI_MSG_MAX,
+};
+
+struct userui_msg_params {
+ unsigned long a, b, c, d;
+ char text[255];
+};
+
+#if defined(CONFIG_NET)
+
+extern unsigned long suspend_update_status(unsigned long value, unsigned long maximum,
+ const char *fmt, ...);
+extern void suspend_prepare_status (int clearbar, const char *fmt, ...);
+extern void suspend_cond_pause(int pause, char *message);
+extern void abort_suspend(const char *fmt, ...);
+extern void suspend_prepare_console(void);
+extern void suspend_cleanup_console(void);
+extern void userui_redraw(void);
+
+#else
+static inline char suspend_wait_for_keypress(int timeout)
+{
+ return 0;
+}
+
+static inline unsigned long suspend_update_status(unsigned long value, unsigned long maximum,
+ const char *fmt, ...)
+{
+ return maximum;
+}
+
+static inline void __suspend_message(unsigned long section, unsigned long level,
+ int normally_logged,
+ const char *fmt, ...) { }
+static inline void suspend_prepare_status(int clearbar, const char *fmt, ...) { }
+static inline void suspend_cond_pause(int pause, char *message) { }
+static inline void abort_suspend(const char *fmt, ...) { }
+static inline void suspend_prepare_console(void) { }
+static inline void suspend_cleanup_console(void) { }
+static inline void userui_redraw(void) { }
+#endif
--
Nigel Cunningham nigel at suspend2 dot net
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2006-06-27 4:58 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-06-27 4:41 [Suspend2][ 00/21] User interface Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 01/21] [Suspend2] User interface c header Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 02/21] [Suspend2] Modify action state Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 03/21] [Suspend2] Tell userspace to redraw the screen Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 04/21] [Suspend2] Process abort request Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 05/21] [Suspend2] Receive a message from the userui Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 06/21] [Suspend2] Get userui storage needed Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 07/21] [Suspend2] Serialise userui configuration info Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 08/21] [Suspend2] Get amount of memory needed for userui Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 09/21] [Suspend2] Update progress bar Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 10/21] [Suspend2] __suspend_message Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 11/21] [Suspend2] Wait for keypress Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 12/21] [Suspend2] Abort a cycle Nigel Cunningham
2006-06-27 4:41 ` [Suspend2][ 13/21] [Suspend2] Main message output Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 14/21] [Suspend2] Conditionally pause Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 15/21] [Suspend2] Prepare ui for work Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 16/21] [Suspend2] Cleanup console after suspending Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 17/21] [Suspend2] Early boot message support Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 18/21] [Suspend2] Userspace proc entries Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 19/21] [Suspend2] Operations for userspace interface module Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 20/21] [Suspend2] Load time initialisation for user interface code Nigel Cunningham
2006-06-27 4:42 ` [Suspend2][ 21/21] [Suspend2] kernel/power/ui.h Nigel Cunningham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome