Lines Matching +full:key +full:- +full:release

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(u8 key) in sysrq_handle_loglevel() argument
103 u8 loglevel = key - '0'; in sysrq_handle_loglevel()
111 .help_msg = "loglevel(0-9)",
117 static void sysrq_handle_SAK(u8 key) in sysrq_handle_SAK() argument
134 static void sysrq_handle_unraw(u8 key) in sysrq_handle_unraw() argument
149 static void sysrq_handle_crash(u8 key) in sysrq_handle_crash() argument
151 /* release the RCU read lock before crashing */ in sysrq_handle_crash()
163 static void sysrq_handle_reboot(u8 key) in sysrq_handle_reboot() argument
178 static void sysrq_handle_sync(u8 key) in sysrq_handle_sync() argument
189 static void sysrq_handle_show_timers(u8 key) in sysrq_handle_show_timers() argument
196 .help_msg = "show-all-timers(q)",
200 static void sysrq_handle_mountro(u8 key) in sysrq_handle_mountro() argument
212 static void sysrq_handle_showlocks(u8 key) in sysrq_handle_showlocks() argument
219 .help_msg = "show-all-locks(d)",
252 static void sysrq_handle_showallcpus(u8 key) in sysrq_handle_showallcpus() argument
278 .help_msg = "show-backtrace-all-active-cpus(l)",
286 static void sysrq_handle_showregs(u8 key) in sysrq_handle_showregs() argument
298 .help_msg = "show-registers(p)",
303 static void sysrq_handle_showstate(u8 key) in sysrq_handle_showstate() argument
310 .help_msg = "show-task-states(t)",
315 static void sysrq_handle_showstate_blocked(u8 key) in sysrq_handle_showstate_blocked() argument
321 .help_msg = "show-blocked-tasks(w)",
329 static void sysrq_ftrace_dump(u8 key) in sysrq_ftrace_dump() argument
335 .help_msg = "dump-ftrace-buffer(z)",
343 static void sysrq_handle_showmem(u8 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(u8 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(u8 key) in sysrq_handle_moom() argument
410 .help_msg = "memory-full-oom-kill(f)",
416 static void sysrq_handle_thaw(u8 key) in sysrq_handle_thaw() argument
422 .help_msg = "thaw-filesystems(j)",
430 static void sysrq_handle_kill(u8 key) in sysrq_handle_kill() argument
437 .help_msg = "kill-all-tasks(i)",
442 static void sysrq_handle_unrt(u8 key) in sysrq_handle_unrt() argument
448 .help_msg = "nice-all-RT-tasks(n)",
453 static void sysrq_handle_replay_logs(u8 key) in sysrq_handle_replay_logs() argument
459 .help_msg = "replay-kernel-logs(R)",
464 /* Key Operations table and lock */
491 NULL, /* h - reserved for help */
545 /* key2index calculation, -1 on invalid index */
546 static int sysrq_key_table_key2index(u8 key) in sysrq_key_table_key2index() argument
548 switch (key) { in sysrq_key_table_key2index()
550 return key - '0'; in sysrq_key_table_key2index()
552 return key - 'a' + 10; in sysrq_key_table_key2index()
554 return key - 'A' + 10 + 26; in sysrq_key_table_key2index()
556 return -1; in sysrq_key_table_key2index()
563 static const struct sysrq_key_op *__sysrq_get_key_op(u8 key) in __sysrq_get_key_op() argument
568 i = sysrq_key_table_key2index(key); in __sysrq_get_key_op()
569 if (i != -1) in __sysrq_get_key_op()
575 static void __sysrq_put_key_op(u8 key, const struct sysrq_key_op *op_p) in __sysrq_put_key_op() argument
577 int i = sysrq_key_table_key2index(key); in __sysrq_put_key_op()
579 if (i != -1) in __sysrq_put_key_op()
583 void __handle_sysrq(u8 key, bool check_mask) in __handle_sysrq() argument
604 op_p = __sysrq_get_key_op(key); in __handle_sysrq()
607 * Should we check for enabled operations (/proc/sysrq-trigger in __handle_sysrq()
610 if (!check_mask || sysrq_on_mask(op_p->enable_mask)) { in __handle_sysrq()
611 pr_info("%s\n", op_p->action_msg); in __handle_sysrq()
613 op_p->handler(key); in __handle_sysrq()
630 pr_cont("%s ", sysrq_key_table[i]->help_msg); in __handle_sysrq()
642 void handle_sysrq(u8 key) in handle_sysrq() argument
645 __handle_sysrq(key, true); in handle_sysrq()
654 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
655 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
656 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
657 "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
658 "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
659 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
660 "\r\000/"; /* 0x60 - 0x6f */
692 unsigned short key; in sysrq_parse_reset_sequence() local
694 state->reset_seq_cnt = 0; in sysrq_parse_reset_sequence()
697 key = sysrq_reset_seq[i]; in sysrq_parse_reset_sequence()
699 if (key == KEY_RESERVED || key > KEY_MAX) in sysrq_parse_reset_sequence()
702 __set_bit(key, state->reset_keybit); in sysrq_parse_reset_sequence()
703 state->reset_seq_len++; in sysrq_parse_reset_sequence()
705 if (test_bit(key, state->key_down)) in sysrq_parse_reset_sequence()
706 state->reset_seq_cnt++; in sysrq_parse_reset_sequence()
710 state->reset_canceled = state->reset_seq_cnt != 0; in sysrq_parse_reset_sequence()
712 state->reset_seq_version = sysrq_reset_seq_version; in sysrq_parse_reset_sequence()
719 state->reset_requested = true; in sysrq_do_reset()
726 if (state->reset_requested) in sysrq_handle_reset_request()
730 mod_timer(&state->keyreset_timer, in sysrq_handle_reset_request()
733 sysrq_do_reset(&state->keyreset_timer); in sysrq_handle_reset_request()
739 if (!test_bit(code, state->reset_keybit)) { in sysrq_detect_reset_sequence()
741 * Pressing any key _not_ in reset sequence cancels in sysrq_detect_reset_sequence()
746 if (value && state->reset_seq_cnt) { in sysrq_detect_reset_sequence()
747 state->reset_canceled = true; in sysrq_detect_reset_sequence()
748 del_timer(&state->keyreset_timer); in sysrq_detect_reset_sequence()
752 * Key release - all keys in the reset sequence need in sysrq_detect_reset_sequence()
756 del_timer(&state->keyreset_timer); in sysrq_detect_reset_sequence()
758 if (--state->reset_seq_cnt == 0) in sysrq_detect_reset_sequence()
759 state->reset_canceled = false; in sysrq_detect_reset_sequence()
761 /* key press, not autorepeat */ in sysrq_detect_reset_sequence()
762 if (++state->reset_seq_cnt == state->reset_seq_len && in sysrq_detect_reset_sequence()
763 !state->reset_canceled) { in sysrq_detect_reset_sequence()
772 u32 key; in sysrq_of_get_keyreset_config() local
775 np = of_find_node_by_path("/chosen/linux,sysrq-reset-seq"); in sysrq_of_get_keyreset_config()
784 of_property_for_each_u32(np, "keyset", key) { in sysrq_of_get_keyreset_config()
785 if (key == KEY_RESERVED || key > KEY_MAX || in sysrq_of_get_keyreset_config()
789 sysrq_reset_seq[sysrq_reset_seq_len++] = (unsigned short)key; in sysrq_of_get_keyreset_config()
793 of_property_read_u32(np, "timeout-ms", &sysrq_reset_downtime_ms); in sysrq_of_get_keyreset_config()
807 struct input_handle *handle = &sysrq->handle; in sysrq_reinject_alt_sysrq()
808 unsigned int alt_code = sysrq->alt_use; in sysrq_reinject_alt_sysrq()
810 if (sysrq->need_reinject) { in sysrq_reinject_alt_sysrq()
812 sysrq->reinjecting = true; in sysrq_reinject_alt_sysrq()
815 /* Simulate press and release of Alt + SysRq */ in sysrq_reinject_alt_sysrq()
825 sysrq->reinjecting = false; in sysrq_reinject_alt_sysrq()
832 bool was_active = sysrq->active; in sysrq_handle_keypress()
841 if (sysrq->active && code == sysrq->alt_use) in sysrq_handle_keypress()
842 sysrq->active = false; in sysrq_handle_keypress()
844 sysrq->alt = KEY_RESERVED; in sysrq_handle_keypress()
847 sysrq->alt = code; in sysrq_handle_keypress()
848 sysrq->need_reinject = false; in sysrq_handle_keypress()
855 sysrq->shift = KEY_RESERVED; in sysrq_handle_keypress()
857 sysrq->shift = code; in sysrq_handle_keypress()
858 if (sysrq->active) in sysrq_handle_keypress()
859 sysrq->shift_use = sysrq->shift; in sysrq_handle_keypress()
863 if (value == 1 && sysrq->alt != KEY_RESERVED) { in sysrq_handle_keypress()
864 sysrq->active = true; in sysrq_handle_keypress()
865 sysrq->alt_use = sysrq->alt; in sysrq_handle_keypress()
867 sysrq->shift_use = sysrq->shift; in sysrq_handle_keypress()
870 * to re-inject Alt-SysRq keysroke. in sysrq_handle_keypress()
872 sysrq->need_reinject = true; in sysrq_handle_keypress()
878 * to release all keys after exiting debugger. If we in sysrq_handle_keypress()
879 * do not clear key bit it KGDB will end up sending in sysrq_handle_keypress()
880 * release events for Alt and SysRq, potentially in sysrq_handle_keypress()
883 if (sysrq->active) in sysrq_handle_keypress()
884 clear_bit(KEY_SYSRQ, sysrq->handle.dev->key); in sysrq_handle_keypress()
889 if (sysrq->active && value && value != 2) { in sysrq_handle_keypress()
892 sysrq->need_reinject = false; in sysrq_handle_keypress()
893 if (sysrq->shift_use != KEY_RESERVED) in sysrq_handle_keypress()
900 suppress = sysrq->active; in sysrq_handle_keypress()
902 if (!sysrq->active) { in sysrq_handle_keypress()
907 if (sysrq->reset_seq_version != sysrq_reset_seq_version) in sysrq_handle_keypress()
911 * If we are not suppressing key presses keep track of in sysrq_handle_keypress()
912 * keyboard state so we can release keys that have been in sysrq_handle_keypress()
916 set_bit(code, sysrq->key_down); in sysrq_handle_keypress()
918 clear_bit(code, sysrq->key_down); in sysrq_handle_keypress()
921 schedule_work(&sysrq->reinject_work); in sysrq_handle_keypress()
926 } else if (value == 0 && test_and_clear_bit(code, sysrq->key_down)) { in sysrq_handle_keypress()
928 * Pass on release events for keys that was pressed before in sysrq_handle_keypress()
940 struct sysrq_state *sysrq = handle->private; in sysrq_filter()
944 * Do not filter anything if we are in the process of re-injecting in sysrq_filter()
947 if (sysrq->reinjecting) in sysrq_filter()
961 suppress = sysrq->active; in sysrq_filter()
977 return -ENOMEM; in sysrq_connect()
979 INIT_WORK(&sysrq->reinject_work, sysrq_reinject_alt_sysrq); in sysrq_connect()
981 sysrq->handle.dev = dev; in sysrq_connect()
982 sysrq->handle.handler = handler; in sysrq_connect()
983 sysrq->handle.name = "sysrq"; in sysrq_connect()
984 sysrq->handle.private = sysrq; in sysrq_connect()
985 timer_setup(&sysrq->keyreset_timer, sysrq_do_reset, 0); in sysrq_connect()
987 error = input_register_handle(&sysrq->handle); in sysrq_connect()
994 error = input_open_device(&sysrq->handle); in sysrq_connect()
1003 input_unregister_handle(&sysrq->handle); in sysrq_connect()
1011 struct sysrq_state *sysrq = handle->private; in sysrq_disconnect()
1014 cancel_work_sync(&sysrq->reinject_work); in sysrq_disconnect()
1015 timer_shutdown_sync(&sysrq->keyreset_timer); in sysrq_disconnect()
1022 * keyboards have SysRq key predefined and so user may add it to keymap
1070 return -EINVAL; in sysrq_reset_seq_param_set()
1072 *((unsigned short *)kp->arg) = val; in sysrq_reset_seq_param_set()
1124 static int __sysrq_swap_key_ops(u8 key, const struct sysrq_key_op *insert_op_p, in __sysrq_swap_key_ops() argument
1130 if (__sysrq_get_key_op(key) == remove_op_p) { in __sysrq_swap_key_ops()
1131 __sysrq_put_key_op(key, insert_op_p); in __sysrq_swap_key_ops()
1134 retval = -1; in __sysrq_swap_key_ops()
1148 int register_sysrq_key(u8 key, const struct sysrq_key_op *op_p) in register_sysrq_key() argument
1150 return __sysrq_swap_key_ops(key, op_p, NULL); in register_sysrq_key()
1154 int unregister_sysrq_key(u8 key, const struct sysrq_key_op *op_p) in unregister_sysrq_key() argument
1156 return __sysrq_swap_key_ops(key, NULL, op_p); in unregister_sysrq_key()
1162 * writing 'C' to /proc/sysrq-trigger is like sysrq-C
1177 return -EFAULT; in write_sysrq_trigger()
1198 if (!proc_create("sysrq-trigger", S_IWUSR, NULL, in sysrq_init_procfs()