Re: [PATCH] [RFC]: drivers/tty: Folding Android's keyreset driver in sysRQ

2012-08-17 Thread Jiri Slaby
On 08/17/2012 12:06 AM, mathieu.poir...@linaro.org wrote:
> +static int do_keyreset_event(struct sysrq_state *state,
> +  unsigned int code, int value)
> +{
> + int ret;
> + int processed = 0;
> +
> + /* Is the code is of interestest to us */
> + if (!test_bit(code, state->keybit))
> + return processed;
> +
> + /* No need to take care of key up events */
> + if (!test_bit(code, state->key) == !value)
> + return processed;
> +
> + /* Record new entry */
> + __change_bit(code, state->key);

Hmm, this function is not atomic. Can do_keyreset_event be called
simultaneously from different CPUs? I suppose not...

> + if (value && !state->restart_disabled &&
> + state->key_down_ctn == state->key_down_target) {
> + state->restart_disabled = 1;
> + if (atomic_read(_requested))
> + panic(KERN_ERR "keyboard reset failed, %d - panic\n",
> +  atomic_read(_requested));

panic() does not take KERN_* prefixes.

regards,
-- 
js
suse labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] [RFC]: drivers/tty: Folding Android's keyreset driver in sysRQ

2012-08-17 Thread Alan Cox
> This functionality comes from the keyreset driver submitted by
> Arve Hjønnevåg in the Android kernel.  It is sent out as an initial
> draft and comments are welcomed.

Looks reasonable to me as a basis.

Alan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] [RFC]: drivers/tty: Folding Android's keyreset driver in sysRQ

2012-08-17 Thread Alan Cox
 This functionality comes from the keyreset driver submitted by
 Arve Hjønnevåg in the Android kernel.  It is sent out as an initial
 draft and comments are welcomed.

Looks reasonable to me as a basis.

Alan
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] [RFC]: drivers/tty: Folding Android's keyreset driver in sysRQ

2012-08-17 Thread Jiri Slaby
On 08/17/2012 12:06 AM, mathieu.poir...@linaro.org wrote:
 +static int do_keyreset_event(struct sysrq_state *state,
 +  unsigned int code, int value)
 +{
 + int ret;
 + int processed = 0;
 +
 + /* Is the code is of interestest to us */
 + if (!test_bit(code, state-keybit))
 + return processed;
 +
 + /* No need to take care of key up events */
 + if (!test_bit(code, state-key) == !value)
 + return processed;
 +
 + /* Record new entry */
 + __change_bit(code, state-key);

Hmm, this function is not atomic. Can do_keyreset_event be called
simultaneously from different CPUs? I suppose not...

 + if (value  !state-restart_disabled 
 + state-key_down_ctn == state-key_down_target) {
 + state-restart_disabled = 1;
 + if (atomic_read(restart_requested))
 + panic(KERN_ERR keyboard reset failed, %d - panic\n,
 +  atomic_read(restart_requested));

panic() does not take KERN_* prefixes.

regards,
-- 
js
suse labs
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] [RFC]: drivers/tty: Folding Android's keyreset driver in sysRQ

2012-08-16 Thread mathieu . poirier
From: "Mathieu J. Poirier" 

This patch adds keyreset functionality to the sysrq driver. It
allows certain button/key combinations to be used in order to
trigger device resets.

The first time the key-combo is detected a work function that syncs
the filesystems is scheduled and the kernel rebooted. If all the keys
are released and then pressed again, it calls panic. Reboot on panic
should be set for this to work.  A platform device that specify a
reset key-combo should be added to the board file to trigger the
feature.

This functionality comes from the keyreset driver submitted by
Arve Hjønnevåg in the Android kernel.  It is sent out as an initial
draft and comments are welcomed.

In the design most of the original author's code has been added
alongside the sysrq functionality, taking great care not to
remove or constrain functionality people might currently be using.

The keyreset platform data and driver name were kept intact to
minimize disruption on products that already instantiate the
keyreset driver.

Cc: a...@android.com
Cc: kernel-t...@android.com
Cc: dmitry.torok...@gmail.com
Cc: john.stu...@linaro.org
Signed-off-by: Mathieu Poirier 
---
 drivers/tty/sysrq.c   |  159 +
 include/linux/sysrq.h |8 +++
 2 files changed, 167 insertions(+), 0 deletions(-)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 05728894..c2b869d 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -41,6 +41,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 #include 
 #include 
@@ -49,6 +52,11 @@
 static int __read_mostly sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
 static bool __read_mostly sysrq_always_enabled;
 
+static struct input_handler sysrq_handler;
+
+/* Keep track of what has been called */
+static atomic_t restart_requested;
+
 static bool sysrq_on(void)
 {
return sysrq_enabled || sysrq_always_enabled;
@@ -570,6 +578,15 @@ struct sysrq_state {
struct input_handle handle;
struct work_struct reinject_work;
unsigned long key_down[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long upbit[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long key[BITS_TO_LONGS(KEY_CNT)];
+   int (*reset_fn)(void);
+   int key_down_target;
+   int key_down_ctn;
+   int key_up_ctn;
+   int keyreset_data;
+   int restart_disabled;
unsigned int alt;
unsigned int alt_use;
bool active;
@@ -603,6 +620,92 @@ static void sysrq_reinject_alt_sysrq(struct work_struct 
*work)
}
 }
 
+
+static int sysrq_probe(struct platform_device *pdev)
+{
+   struct keyreset_platform_data *pdata = pdev->dev.platform_data;
+
+   /* No sequence of keys to trigger on,
+* assuming default sysRQ behavior.
+*/
+   if (pdata) {
+   atomic_set(_requested, 0);
+   sysrq_handler.private = pdata;
+   } else
+   sysrq_handler.private = NULL;
+
+   /* FETCH DT INFO HERE */
+
+   return 0;
+
+}
+
+static void deferred_restart(struct work_struct *dummy)
+{
+   atomic_inc(_requested);
+   sys_sync();
+   atomic_inc(_requested);
+   kernel_restart(NULL);
+}
+static DECLARE_WORK(restart_work, deferred_restart);
+
+static int do_keyreset_event(struct sysrq_state *state,
+unsigned int code, int value)
+{
+   int ret;
+   int processed = 0;
+
+   /* Is the code is of interestest to us */
+   if (!test_bit(code, state->keybit))
+   return processed;
+
+   /* No need to take care of key up events */
+   if (!test_bit(code, state->key) == !value)
+   return processed;
+
+   /* Record new entry */
+   __change_bit(code, state->key);
+
+   processed = 1;
+
+   if (test_bit(code, state->upbit)) {
+   if (value) {
+   state->restart_disabled = 1;
+   state->key_up_ctn++;
+   } else
+   state->key_up_ctn--;
+   } else {
+   if (value)
+   state->key_down_ctn++;
+   else
+   state->key_down_ctn--;
+   }
+
+   if (state->key_down_ctn == 0 && state->key_up_ctn == 0)
+   state->restart_disabled = 0;
+
+   if (value && !state->restart_disabled &&
+   state->key_down_ctn == state->key_down_target) {
+   state->restart_disabled = 1;
+   if (atomic_read(_requested))
+   panic(KERN_ERR "keyboard reset failed, %d - panic\n",
+atomic_read(_requested));
+   if (state->reset_fn) {
+   ret = state->reset_fn();
+   atomic_set(_requested, ret);
+   } else {
+   pr_info("keyboard reset\n");
+   schedule_work(_work);
+  

[PATCH] [RFC]: drivers/tty: Folding Android's keyreset driver in sysRQ

2012-08-16 Thread mathieu . poirier
From: Mathieu J. Poirier mathieu.poir...@linaro.org

This patch adds keyreset functionality to the sysrq driver. It
allows certain button/key combinations to be used in order to
trigger device resets.

The first time the key-combo is detected a work function that syncs
the filesystems is scheduled and the kernel rebooted. If all the keys
are released and then pressed again, it calls panic. Reboot on panic
should be set for this to work.  A platform device that specify a
reset key-combo should be added to the board file to trigger the
feature.

This functionality comes from the keyreset driver submitted by
Arve Hjønnevåg in the Android kernel.  It is sent out as an initial
draft and comments are welcomed.

In the design most of the original author's code has been added
alongside the sysrq functionality, taking great care not to
remove or constrain functionality people might currently be using.

The keyreset platform data and driver name were kept intact to
minimize disruption on products that already instantiate the
keyreset driver.

Cc: a...@android.com
Cc: kernel-t...@android.com
Cc: dmitry.torok...@gmail.com
Cc: john.stu...@linaro.org
Signed-off-by: Mathieu Poirier mathieu.poir...@linaro.org
---
 drivers/tty/sysrq.c   |  159 +
 include/linux/sysrq.h |8 +++
 2 files changed, 167 insertions(+), 0 deletions(-)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 05728894..c2b869d 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -41,6 +41,9 @@
 #include linux/slab.h
 #include linux/input.h
 #include linux/uaccess.h
+#include linux/platform_device.h
+#include linux/syscalls.h
+#include linux/atomic.h
 
 #include asm/ptrace.h
 #include asm/irq_regs.h
@@ -49,6 +52,11 @@
 static int __read_mostly sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
 static bool __read_mostly sysrq_always_enabled;
 
+static struct input_handler sysrq_handler;
+
+/* Keep track of what has been called */
+static atomic_t restart_requested;
+
 static bool sysrq_on(void)
 {
return sysrq_enabled || sysrq_always_enabled;
@@ -570,6 +578,15 @@ struct sysrq_state {
struct input_handle handle;
struct work_struct reinject_work;
unsigned long key_down[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long upbit[BITS_TO_LONGS(KEY_CNT)];
+   unsigned long key[BITS_TO_LONGS(KEY_CNT)];
+   int (*reset_fn)(void);
+   int key_down_target;
+   int key_down_ctn;
+   int key_up_ctn;
+   int keyreset_data;
+   int restart_disabled;
unsigned int alt;
unsigned int alt_use;
bool active;
@@ -603,6 +620,92 @@ static void sysrq_reinject_alt_sysrq(struct work_struct 
*work)
}
 }
 
+
+static int sysrq_probe(struct platform_device *pdev)
+{
+   struct keyreset_platform_data *pdata = pdev-dev.platform_data;
+
+   /* No sequence of keys to trigger on,
+* assuming default sysRQ behavior.
+*/
+   if (pdata) {
+   atomic_set(restart_requested, 0);
+   sysrq_handler.private = pdata;
+   } else
+   sysrq_handler.private = NULL;
+
+   /* FETCH DT INFO HERE */
+
+   return 0;
+
+}
+
+static void deferred_restart(struct work_struct *dummy)
+{
+   atomic_inc(restart_requested);
+   sys_sync();
+   atomic_inc(restart_requested);
+   kernel_restart(NULL);
+}
+static DECLARE_WORK(restart_work, deferred_restart);
+
+static int do_keyreset_event(struct sysrq_state *state,
+unsigned int code, int value)
+{
+   int ret;
+   int processed = 0;
+
+   /* Is the code is of interestest to us */
+   if (!test_bit(code, state-keybit))
+   return processed;
+
+   /* No need to take care of key up events */
+   if (!test_bit(code, state-key) == !value)
+   return processed;
+
+   /* Record new entry */
+   __change_bit(code, state-key);
+
+   processed = 1;
+
+   if (test_bit(code, state-upbit)) {
+   if (value) {
+   state-restart_disabled = 1;
+   state-key_up_ctn++;
+   } else
+   state-key_up_ctn--;
+   } else {
+   if (value)
+   state-key_down_ctn++;
+   else
+   state-key_down_ctn--;
+   }
+
+   if (state-key_down_ctn == 0  state-key_up_ctn == 0)
+   state-restart_disabled = 0;
+
+   if (value  !state-restart_disabled 
+   state-key_down_ctn == state-key_down_target) {
+   state-restart_disabled = 1;
+   if (atomic_read(restart_requested))
+   panic(KERN_ERR keyboard reset failed, %d - panic\n,
+atomic_read(restart_requested));
+   if (state-reset_fn) {
+   ret = state-reset_fn();
+