Lines Matching +full:key +full:- +full:code
1 // SPDX-License-Identifier: GPL-2.0
3 * Linux Magic System Request Key Hacks
9 * overhauled to use key registration
68 * sysrq_mask - Getter for sysrq_enabled mask.
101 static void sysrq_handle_loglevel(int key) in sysrq_handle_loglevel() argument
105 i = key - '0'; in sysrq_handle_loglevel()
112 .help_msg = "loglevel(0-9)",
118 static void sysrq_handle_SAK(int key) in sysrq_handle_SAK() argument
135 static void sysrq_handle_unraw(int key) in sysrq_handle_unraw() argument
150 static void sysrq_handle_crash(int key) in sysrq_handle_crash() argument
164 static void sysrq_handle_reboot(int key) in sysrq_handle_reboot() argument
179 static void sysrq_handle_sync(int key) in sysrq_handle_sync() argument
190 static void sysrq_handle_show_timers(int key) in sysrq_handle_show_timers() argument
197 .help_msg = "show-all-timers(q)",
201 static void sysrq_handle_mountro(int key) in sysrq_handle_mountro() argument
213 static void sysrq_handle_showlocks(int key) in sysrq_handle_showlocks() argument
220 .help_msg = "show-all-locks(d)",
253 static void sysrq_handle_showallcpus(int key) in sysrq_handle_showallcpus() argument
278 .help_msg = "show-backtrace-all-active-cpus(l)",
286 static void sysrq_handle_showregs(int key) in sysrq_handle_showregs() argument
298 .help_msg = "show-registers(p)",
303 static void sysrq_handle_showstate(int key) in sysrq_handle_showstate() argument
310 .help_msg = "show-task-states(t)",
315 static void sysrq_handle_showstate_blocked(int key) in sysrq_handle_showstate_blocked() argument
321 .help_msg = "show-blocked-tasks(w)",
329 static void sysrq_ftrace_dump(int key) in sysrq_ftrace_dump() argument
335 .help_msg = "dump-ftrace-buffer(z)",
343 static void sysrq_handle_showmem(int key) in sysrq_handle_showmem() argument
349 .help_msg = "show-memory-usage(m)",
363 if (p->flags & PF_KTHREAD) in send_sig_all()
373 static void sysrq_handle_term(int key) in sysrq_handle_term() argument
380 .help_msg = "terminate-all-tasks(e)",
393 .order = -1, in moom_callback()
404 static void sysrq_handle_moom(int key) in sysrq_handle_moom() argument
410 .help_msg = "memory-full-oom-kill(f)",
416 static void sysrq_handle_thaw(int key) in sysrq_handle_thaw() argument
422 .help_msg = "thaw-filesystems(j)",
430 static void sysrq_handle_kill(int key) in sysrq_handle_kill() argument
437 .help_msg = "kill-all-tasks(i)",
442 static void sysrq_handle_unrt(int key) in sysrq_handle_unrt() argument
448 .help_msg = "nice-all-RT-tasks(n)",
453 /* Key Operations table and lock */
480 NULL, /* h - reserved for help */
533 /* key2index calculation, -1 on invalid index */
534 static int sysrq_key_table_key2index(int key) in sysrq_key_table_key2index() argument
538 if ((key >= '0') && (key <= '9')) in sysrq_key_table_key2index()
539 retval = key - '0'; in sysrq_key_table_key2index()
540 else if ((key >= 'a') && (key <= 'z')) in sysrq_key_table_key2index()
541 retval = key + 10 - 'a'; in sysrq_key_table_key2index()
542 else if ((key >= 'A') && (key <= 'Z')) in sysrq_key_table_key2index()
543 retval = key + 36 - 'A'; in sysrq_key_table_key2index()
545 retval = -1; in sysrq_key_table_key2index()
552 static const struct sysrq_key_op *__sysrq_get_key_op(int key) in __sysrq_get_key_op() argument
557 i = sysrq_key_table_key2index(key); in __sysrq_get_key_op()
558 if (i != -1) in __sysrq_get_key_op()
564 static void __sysrq_put_key_op(int key, const struct sysrq_key_op *op_p) in __sysrq_put_key_op() argument
566 int i = sysrq_key_table_key2index(key); in __sysrq_put_key_op()
568 if (i != -1) in __sysrq_put_key_op()
572 void __handle_sysrq(int key, bool check_mask) in __handle_sysrq() argument
593 op_p = __sysrq_get_key_op(key); in __handle_sysrq()
596 * Should we check for enabled operations (/proc/sysrq-trigger in __handle_sysrq()
599 if (!check_mask || sysrq_on_mask(op_p->enable_mask)) { in __handle_sysrq()
600 pr_info("%s\n", op_p->action_msg); in __handle_sysrq()
602 op_p->handler(key); in __handle_sysrq()
619 pr_cont("%s ", sysrq_key_table[i]->help_msg); in __handle_sysrq()
631 void handle_sysrq(int key) in handle_sysrq() argument
634 __handle_sysrq(key, true); in handle_sysrq()
643 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
644 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
645 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
646 "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
647 "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
648 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
649 "\r\000/"; /* 0x60 - 0x6f */
681 unsigned short key; in sysrq_parse_reset_sequence() local
683 state->reset_seq_cnt = 0; in sysrq_parse_reset_sequence()
686 key = sysrq_reset_seq[i]; in sysrq_parse_reset_sequence()
688 if (key == KEY_RESERVED || key > KEY_MAX) in sysrq_parse_reset_sequence()
691 __set_bit(key, state->reset_keybit); in sysrq_parse_reset_sequence()
692 state->reset_seq_len++; in sysrq_parse_reset_sequence()
694 if (test_bit(key, state->key_down)) in sysrq_parse_reset_sequence()
695 state->reset_seq_cnt++; in sysrq_parse_reset_sequence()
699 state->reset_canceled = state->reset_seq_cnt != 0; in sysrq_parse_reset_sequence()
701 state->reset_seq_version = sysrq_reset_seq_version; in sysrq_parse_reset_sequence()
708 state->reset_requested = true; in sysrq_do_reset()
715 if (state->reset_requested) in sysrq_handle_reset_request()
719 mod_timer(&state->keyreset_timer, in sysrq_handle_reset_request()
722 sysrq_do_reset(&state->keyreset_timer); in sysrq_handle_reset_request()
726 unsigned int code, int value) in sysrq_detect_reset_sequence() argument
728 if (!test_bit(code, state->reset_keybit)) { in sysrq_detect_reset_sequence()
730 * Pressing any key _not_ in reset sequence cancels in sysrq_detect_reset_sequence()
735 if (value && state->reset_seq_cnt) { in sysrq_detect_reset_sequence()
736 state->reset_canceled = true; in sysrq_detect_reset_sequence()
737 del_timer(&state->keyreset_timer); in sysrq_detect_reset_sequence()
741 * Key release - all keys in the reset sequence need in sysrq_detect_reset_sequence()
745 del_timer(&state->keyreset_timer); in sysrq_detect_reset_sequence()
747 if (--state->reset_seq_cnt == 0) in sysrq_detect_reset_sequence()
748 state->reset_canceled = false; in sysrq_detect_reset_sequence()
750 /* key press, not autorepeat */ in sysrq_detect_reset_sequence()
751 if (++state->reset_seq_cnt == state->reset_seq_len && in sysrq_detect_reset_sequence()
752 !state->reset_canceled) { in sysrq_detect_reset_sequence()
761 u32 key; in sysrq_of_get_keyreset_config() local
766 np = of_find_node_by_path("/chosen/linux,sysrq-reset-seq"); in sysrq_of_get_keyreset_config()
775 of_property_for_each_u32(np, "keyset", prop, p, key) { in sysrq_of_get_keyreset_config()
776 if (key == KEY_RESERVED || key > KEY_MAX || in sysrq_of_get_keyreset_config()
780 sysrq_reset_seq[sysrq_reset_seq_len++] = (unsigned short)key; in sysrq_of_get_keyreset_config()
784 of_property_read_u32(np, "timeout-ms", &sysrq_reset_downtime_ms); in sysrq_of_get_keyreset_config()
798 struct input_handle *handle = &sysrq->handle; in sysrq_reinject_alt_sysrq()
799 unsigned int alt_code = sysrq->alt_use; in sysrq_reinject_alt_sysrq()
801 if (sysrq->need_reinject) { in sysrq_reinject_alt_sysrq()
803 sysrq->reinjecting = true; in sysrq_reinject_alt_sysrq()
816 sysrq->reinjecting = false; in sysrq_reinject_alt_sysrq()
821 unsigned int code, int value) in sysrq_handle_keypress() argument
823 bool was_active = sysrq->active; in sysrq_handle_keypress()
826 switch (code) { in sysrq_handle_keypress()
832 if (sysrq->active && code == sysrq->alt_use) in sysrq_handle_keypress()
833 sysrq->active = false; in sysrq_handle_keypress()
835 sysrq->alt = KEY_RESERVED; in sysrq_handle_keypress()
838 sysrq->alt = code; in sysrq_handle_keypress()
839 sysrq->need_reinject = false; in sysrq_handle_keypress()
846 sysrq->shift = KEY_RESERVED; in sysrq_handle_keypress()
848 sysrq->shift = code; in sysrq_handle_keypress()
849 if (sysrq->active) in sysrq_handle_keypress()
850 sysrq->shift_use = sysrq->shift; in sysrq_handle_keypress()
854 if (value == 1 && sysrq->alt != KEY_RESERVED) { in sysrq_handle_keypress()
855 sysrq->active = true; in sysrq_handle_keypress()
856 sysrq->alt_use = sysrq->alt; in sysrq_handle_keypress()
857 /* either RESERVED (for released) or actual code */ in sysrq_handle_keypress()
858 sysrq->shift_use = sysrq->shift; in sysrq_handle_keypress()
861 * to re-inject Alt-SysRq keysroke. in sysrq_handle_keypress()
863 sysrq->need_reinject = true; in sysrq_handle_keypress()
870 * do not clear key bit it KGDB will end up sending in sysrq_handle_keypress()
874 if (sysrq->active) in sysrq_handle_keypress()
875 clear_bit(KEY_SYSRQ, sysrq->handle.dev->key); in sysrq_handle_keypress()
880 if (sysrq->active && value && value != 2) { in sysrq_handle_keypress()
881 unsigned char c = sysrq_xlate[code]; in sysrq_handle_keypress()
883 sysrq->need_reinject = false; in sysrq_handle_keypress()
884 if (sysrq->shift_use != KEY_RESERVED) in sysrq_handle_keypress()
891 suppress = sysrq->active; in sysrq_handle_keypress()
893 if (!sysrq->active) { in sysrq_handle_keypress()
898 if (sysrq->reset_seq_version != sysrq_reset_seq_version) in sysrq_handle_keypress()
902 * If we are not suppressing key presses keep track of in sysrq_handle_keypress()
907 set_bit(code, sysrq->key_down); in sysrq_handle_keypress()
909 clear_bit(code, sysrq->key_down); in sysrq_handle_keypress()
912 schedule_work(&sysrq->reinject_work); in sysrq_handle_keypress()
915 sysrq_detect_reset_sequence(sysrq, code, value); in sysrq_handle_keypress()
917 } else if (value == 0 && test_and_clear_bit(code, sysrq->key_down)) { in sysrq_handle_keypress()
929 unsigned int type, unsigned int code, int value) in sysrq_filter() argument
931 struct sysrq_state *sysrq = handle->private; in sysrq_filter()
935 * Do not filter anything if we are in the process of re-injecting in sysrq_filter()
938 if (sysrq->reinjecting) in sysrq_filter()
948 suppress = sysrq_handle_keypress(sysrq, code, value); in sysrq_filter()
952 suppress = sysrq->active; in sysrq_filter()
968 return -ENOMEM; in sysrq_connect()
970 INIT_WORK(&sysrq->reinject_work, sysrq_reinject_alt_sysrq); in sysrq_connect()
972 sysrq->handle.dev = dev; in sysrq_connect()
973 sysrq->handle.handler = handler; in sysrq_connect()
974 sysrq->handle.name = "sysrq"; in sysrq_connect()
975 sysrq->handle.private = sysrq; in sysrq_connect()
976 timer_setup(&sysrq->keyreset_timer, sysrq_do_reset, 0); in sysrq_connect()
978 error = input_register_handle(&sysrq->handle); in sysrq_connect()
985 error = input_open_device(&sysrq->handle); in sysrq_connect()
994 input_unregister_handle(&sysrq->handle); in sysrq_connect()
1002 struct sysrq_state *sysrq = handle->private; in sysrq_disconnect()
1005 cancel_work_sync(&sysrq->reinject_work); in sysrq_disconnect()
1006 del_timer_sync(&sysrq->keyreset_timer); in sysrq_disconnect()
1013 * keyboards have SysRq key predefined and so user may add it to keymap
1061 return -EINVAL; in sysrq_reset_seq_param_set()
1063 *((unsigned short *)kp->arg) = val; in sysrq_reset_seq_param_set()
1115 static int __sysrq_swap_key_ops(int key, const struct sysrq_key_op *insert_op_p, in __sysrq_swap_key_ops() argument
1121 if (__sysrq_get_key_op(key) == remove_op_p) { in __sysrq_swap_key_ops()
1122 __sysrq_put_key_op(key, insert_op_p); in __sysrq_swap_key_ops()
1125 retval = -1; in __sysrq_swap_key_ops()
1131 * Wait for it to go away before returning, so the code for an old in __sysrq_swap_key_ops()
1139 int register_sysrq_key(int key, const struct sysrq_key_op *op_p) in register_sysrq_key() argument
1141 return __sysrq_swap_key_ops(key, op_p, NULL); in register_sysrq_key()
1145 int unregister_sysrq_key(int key, const struct sysrq_key_op *op_p) in unregister_sysrq_key() argument
1147 return __sysrq_swap_key_ops(key, NULL, op_p); in unregister_sysrq_key()
1153 * writing 'C' to /proc/sysrq-trigger is like sysrq-C
1162 return -EFAULT; in write_sysrq_trigger()
1176 if (!proc_create("sysrq-trigger", S_IWUSR, NULL, in sysrq_init_procfs()