Staging: wlan-ng: Use standard kernel integer (u32/s32/etc) types.
[safe/jmp/linux-2.6] / drivers / char / sysrq.c
index be73c80..94966ed 100644 (file)
@@ -23,8 +23,8 @@
 #include <linux/reboot.h>
 #include <linux/sysrq.h>
 #include <linux/kbd_kern.h>
+#include <linux/proc_fs.h>
 #include <linux/quotaops.h>
-#include <linux/smp_lock.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/suspend.h>
@@ -36,6 +36,8 @@
 #include <linux/workqueue.h>
 #include <linux/kexec.h>
 #include <linux/irq.h>
+#include <linux/hrtimer.h>
+#include <linux/oom.h>
 
 #include <asm/ptrace.h>
 #include <asm/irq_regs.h>
@@ -107,12 +109,12 @@ static void sysrq_handle_unraw(int key, struct tty_struct *tty)
        struct kbd_struct *kbd = &kbd_table[fg_console];
 
        if (kbd)
-               kbd->kbdmode = VC_XLATE;
+               kbd->kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE;
 }
 static struct sysrq_key_op sysrq_unraw_op = {
        .handler        = sysrq_handle_unraw,
        .help_msg       = "unRaw",
-       .action_msg     = "Keyboard mode set to XLATE",
+       .action_msg     = "Keyboard mode set to system default",
        .enable_mask    = SYSRQ_ENABLE_KEYBOARD,
 };
 #else
@@ -158,6 +160,17 @@ static struct sysrq_key_op sysrq_sync_op = {
        .enable_mask    = SYSRQ_ENABLE_SYNC,
 };
 
+static void sysrq_handle_show_timers(int key, struct tty_struct *tty)
+{
+       sysrq_timer_list_show();
+}
+
+static struct sysrq_key_op sysrq_show_timers_op = {
+       .handler        = sysrq_handle_show_timers,
+       .help_msg       = "show-all-timers(Q)",
+       .action_msg     = "Show clockevent devices & pending hrtimers (no others)",
+};
+
 static void sysrq_handle_mountro(int key, struct tty_struct *tty)
 {
        emergency_remount();
@@ -184,6 +197,48 @@ static struct sysrq_key_op sysrq_showlocks_op = {
 #define sysrq_showlocks_op (*(struct sysrq_key_op *)0)
 #endif
 
+#ifdef CONFIG_SMP
+static DEFINE_SPINLOCK(show_lock);
+
+static void showacpu(void *dummy)
+{
+       unsigned long flags;
+
+       /* Idle CPUs have no interesting backtrace. */
+       if (idle_cpu(smp_processor_id()))
+               return;
+
+       spin_lock_irqsave(&show_lock, flags);
+       printk(KERN_INFO "CPU%d:\n", smp_processor_id());
+       show_stack(NULL, NULL);
+       spin_unlock_irqrestore(&show_lock, flags);
+}
+
+static void sysrq_showregs_othercpus(struct work_struct *dummy)
+{
+       smp_call_function(showacpu, NULL, 0);
+}
+
+static DECLARE_WORK(sysrq_showallcpus, sysrq_showregs_othercpus);
+
+static void sysrq_handle_showallcpus(int key, struct tty_struct *tty)
+{
+       struct pt_regs *regs = get_irq_regs();
+       if (regs) {
+               printk(KERN_INFO "CPU%d:\n", smp_processor_id());
+               show_regs(regs);
+       }
+       schedule_work(&sysrq_showallcpus);
+}
+
+static struct sysrq_key_op sysrq_showallcpus_op = {
+       .handler        = sysrq_handle_showallcpus,
+       .help_msg       = "aLlcpus",
+       .action_msg     = "Show backtrace of all active CPUs",
+       .enable_mask    = SYSRQ_ENABLE_DUMP,
+};
+#endif
+
 static void sysrq_handle_showregs(int key, struct tty_struct *tty)
 {
        struct pt_regs *regs = get_irq_regs();
@@ -219,6 +274,22 @@ static struct sysrq_key_op sysrq_showstate_blocked_op = {
        .enable_mask    = SYSRQ_ENABLE_DUMP,
 };
 
+#ifdef CONFIG_TRACING
+#include <linux/ftrace.h>
+
+static void sysrq_ftrace_dump(int key, struct tty_struct *tty)
+{
+       ftrace_dump();
+}
+static struct sysrq_key_op sysrq_ftrace_dump_op = {
+       .handler        = sysrq_ftrace_dump,
+       .help_msg       = "dumpZ-ftrace-buffer",
+       .action_msg     = "Dump ftrace buffer",
+       .enable_mask    = SYSRQ_ENABLE_DUMP,
+};
+#else
+#define sysrq_ftrace_dump_op (*(struct sysrq_key_op *)0)
+#endif
 
 static void sysrq_handle_showmem(int key, struct tty_struct *tty)
 {
@@ -239,7 +310,7 @@ static void send_sig_all(int sig)
        struct task_struct *p;
 
        for_each_process(p) {
-               if (p->mm && !is_init(p))
+               if (p->mm && !is_global_init(p))
                        /* Not swapper, init nor kernel thread */
                        force_sig(sig, p);
        }
@@ -259,8 +330,7 @@ static struct sysrq_key_op sysrq_term_op = {
 
 static void moom_callback(struct work_struct *ignored)
 {
-       out_of_memory(&NODE_DATA(0)->node_zonelists[ZONE_NORMAL],
-                       GFP_KERNEL, 0);
+       out_of_memory(node_zonelist(0, GFP_KERNEL), GFP_KERNEL, 0);
 }
 
 static DECLARE_WORK(moom_work, moom_callback);
@@ -273,6 +343,7 @@ static struct sysrq_key_op sysrq_moom_op = {
        .handler        = sysrq_handle_moom,
        .help_msg       = "Full",
        .action_msg     = "Manual OOM execution",
+       .enable_mask    = SYSRQ_ENABLE_SIGNAL,
 };
 
 static void sysrq_handle_kill(int key, struct tty_struct *tty)
@@ -329,13 +400,17 @@ static struct sysrq_key_op *sysrq_key_table[36] = {
        &sysrq_kill_op,                 /* i */
        NULL,                           /* j */
        &sysrq_SAK_op,                  /* k */
+#ifdef CONFIG_SMP
+       &sysrq_showallcpus_op,          /* l */
+#else
        NULL,                           /* l */
+#endif
        &sysrq_showmem_op,              /* m */
        &sysrq_unrt_op,                 /* n */
        /* o: This will often be registered as 'Off' at init time */
        NULL,                           /* o */
        &sysrq_showregs_op,             /* p */
-       NULL,                           /* q */
+       &sysrq_show_timers_op,          /* q */
        &sysrq_unraw_op,                /* r */
        &sysrq_sync_op,                 /* s */
        &sysrq_showstate_op,            /* t */
@@ -345,8 +420,9 @@ static struct sysrq_key_op *sysrq_key_table[36] = {
        &sysrq_showstate_blocked_op,    /* w */
        /* x: May be registered on ppc/powerpc for xmon */
        NULL,                           /* x */
+       /* y: May be registered on sparc64 for global register dump */
        NULL,                           /* y */
-       NULL                            /* z */
+       &sysrq_ftrace_dump_op,          /* z */
 };
 
 /* key2index calculation, -1 on invalid index */
@@ -475,3 +551,32 @@ int unregister_sysrq_key(int key, struct sysrq_key_op *op_p)
        return __sysrq_swap_key_ops(key, NULL, op_p);
 }
 EXPORT_SYMBOL(unregister_sysrq_key);
+
+#ifdef CONFIG_PROC_FS
+/*
+ * writing 'C' to /proc/sysrq-trigger is like sysrq-C
+ */
+static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
+                                  size_t count, loff_t *ppos)
+{
+       if (count) {
+               char c;
+
+               if (get_user(c, buf))
+                       return -EFAULT;
+               __handle_sysrq(c, NULL, 0);
+       }
+       return count;
+}
+
+static const struct file_operations proc_sysrq_trigger_operations = {
+       .write          = write_sysrq_trigger,
+};
+
+static int __init sysrq_init(void)
+{
+       proc_create("sysrq-trigger", S_IWUSR, NULL, &proc_sysrq_trigger_operations);
+       return 0;
+}
+module_init(sysrq_init);
+#endif