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
602 op_p = __sysrq_get_key_op(key); in __handle_sysrq()
605 * Should we check for enabled operations (/proc/sysrq-trigger in __handle_sysrq()
608 if (!check_mask || sysrq_on_mask(op_p->enable_mask)) { in __handle_sysrq()
609 pr_info("%s\n", op_p->action_msg); in __handle_sysrq()
611 op_p->handler(key); in __handle_sysrq()
628 pr_cont("%s ", sysrq_key_table[i]->help_msg); in __handle_sysrq()
640 void handle_sysrq(u8 key) in handle_sysrq() argument
643 __handle_sysrq(key, true); in handle_sysrq()
652 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
653 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
654 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
655 "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
656 "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
657 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
658 "\r\000/"; /* 0x60 - 0x6f */
690 unsigned short key; in sysrq_parse_reset_sequence() local
692 state->reset_seq_cnt = 0; in sysrq_parse_reset_sequence()
695 key = sysrq_reset_seq[i]; in sysrq_parse_reset_sequence()
697 if (key == KEY_RESERVED || key > KEY_MAX) in sysrq_parse_reset_sequence()
700 __set_bit(key, state->reset_keybit); in sysrq_parse_reset_sequence()
701 state->reset_seq_len++; in sysrq_parse_reset_sequence()
703 if (test_bit(key, state->key_down)) in sysrq_parse_reset_sequence()
704 state->reset_seq_cnt++; in sysrq_parse_reset_sequence()
708 state->reset_canceled = state->reset_seq_cnt != 0; in sysrq_parse_reset_sequence()
710 state->reset_seq_version = sysrq_reset_seq_version; in sysrq_parse_reset_sequence()
717 state->reset_requested = true; in sysrq_do_reset()
724 if (state->reset_requested) in sysrq_handle_reset_request()
728 mod_timer(&state->keyreset_timer, in sysrq_handle_reset_request()
731 sysrq_do_reset(&state->keyreset_timer); in sysrq_handle_reset_request()
737 if (!test_bit(code, state->reset_keybit)) { in sysrq_detect_reset_sequence()
739 * Pressing any key _not_ in reset sequence cancels in sysrq_detect_reset_sequence()
744 if (value && state->reset_seq_cnt) { in sysrq_detect_reset_sequence()
745 state->reset_canceled = true; in sysrq_detect_reset_sequence()
746 del_timer(&state->keyreset_timer); in sysrq_detect_reset_sequence()
750 * Key release - all keys in the reset sequence need in sysrq_detect_reset_sequence()
754 del_timer(&state->keyreset_timer); in sysrq_detect_reset_sequence()
756 if (--state->reset_seq_cnt == 0) in sysrq_detect_reset_sequence()
757 state->reset_canceled = false; in sysrq_detect_reset_sequence()
759 /* key press, not autorepeat */ in sysrq_detect_reset_sequence()
760 if (++state->reset_seq_cnt == state->reset_seq_len && in sysrq_detect_reset_sequence()
761 !state->reset_canceled) { in sysrq_detect_reset_sequence()
770 u32 key; in sysrq_of_get_keyreset_config() local
773 np = of_find_node_by_path("/chosen/linux,sysrq-reset-seq"); in sysrq_of_get_keyreset_config()
782 of_property_for_each_u32(np, "keyset", key) { in sysrq_of_get_keyreset_config()
783 if (key == KEY_RESERVED || key > KEY_MAX || in sysrq_of_get_keyreset_config()
787 sysrq_reset_seq[sysrq_reset_seq_len++] = (unsigned short)key; in sysrq_of_get_keyreset_config()
791 of_property_read_u32(np, "timeout-ms", &sysrq_reset_downtime_ms); in sysrq_of_get_keyreset_config()
805 struct input_handle *handle = &sysrq->handle; in sysrq_reinject_alt_sysrq()
806 unsigned int alt_code = sysrq->alt_use; in sysrq_reinject_alt_sysrq()
808 if (sysrq->need_reinject) { in sysrq_reinject_alt_sysrq()
810 sysrq->reinjecting = true; in sysrq_reinject_alt_sysrq()
813 /* Simulate press and release of Alt + SysRq */ in sysrq_reinject_alt_sysrq()
823 sysrq->reinjecting = false; in sysrq_reinject_alt_sysrq()
830 bool was_active = sysrq->active; in sysrq_handle_keypress()
839 if (sysrq->active && code == sysrq->alt_use) in sysrq_handle_keypress()
840 sysrq->active = false; in sysrq_handle_keypress()
842 sysrq->alt = KEY_RESERVED; in sysrq_handle_keypress()
845 sysrq->alt = code; in sysrq_handle_keypress()
846 sysrq->need_reinject = false; in sysrq_handle_keypress()
853 sysrq->shift = KEY_RESERVED; in sysrq_handle_keypress()
855 sysrq->shift = code; in sysrq_handle_keypress()
856 if (sysrq->active) in sysrq_handle_keypress()
857 sysrq->shift_use = sysrq->shift; in sysrq_handle_keypress()
861 if (value == 1 && sysrq->alt != KEY_RESERVED) { in sysrq_handle_keypress()
862 sysrq->active = true; in sysrq_handle_keypress()
863 sysrq->alt_use = sysrq->alt; in sysrq_handle_keypress()
865 sysrq->shift_use = sysrq->shift; in sysrq_handle_keypress()
868 * to re-inject Alt-SysRq keysroke. in sysrq_handle_keypress()
870 sysrq->need_reinject = true; in sysrq_handle_keypress()
876 * to release all keys after exiting debugger. If we in sysrq_handle_keypress()
877 * do not clear key bit it KGDB will end up sending in sysrq_handle_keypress()
878 * release events for Alt and SysRq, potentially in sysrq_handle_keypress()
881 if (sysrq->active) in sysrq_handle_keypress()
882 clear_bit(KEY_SYSRQ, sysrq->handle.dev->key); in sysrq_handle_keypress()
887 if (sysrq->active && value && value != 2) { in sysrq_handle_keypress()
890 sysrq->need_reinject = false; in sysrq_handle_keypress()
891 if (sysrq->shift_use != KEY_RESERVED) in sysrq_handle_keypress()
898 suppress = sysrq->active; in sysrq_handle_keypress()
900 if (!sysrq->active) { in sysrq_handle_keypress()
905 if (sysrq->reset_seq_version != sysrq_reset_seq_version) in sysrq_handle_keypress()
909 * If we are not suppressing key presses keep track of in sysrq_handle_keypress()
910 * keyboard state so we can release keys that have been in sysrq_handle_keypress()
914 set_bit(code, sysrq->key_down); in sysrq_handle_keypress()
916 clear_bit(code, sysrq->key_down); in sysrq_handle_keypress()
919 schedule_work(&sysrq->reinject_work); in sysrq_handle_keypress()
924 } else if (value == 0 && test_and_clear_bit(code, sysrq->key_down)) { in sysrq_handle_keypress()
926 * Pass on release events for keys that was pressed before in sysrq_handle_keypress()
938 struct sysrq_state *sysrq = handle->private; in sysrq_filter()
942 * Do not filter anything if we are in the process of re-injecting in sysrq_filter()
945 if (sysrq->reinjecting) in sysrq_filter()
959 suppress = sysrq->active; in sysrq_filter()
975 return -ENOMEM; in sysrq_connect()
977 INIT_WORK(&sysrq->reinject_work, sysrq_reinject_alt_sysrq); in sysrq_connect()
979 sysrq->handle.dev = dev; in sysrq_connect()
980 sysrq->handle.handler = handler; in sysrq_connect()
981 sysrq->handle.name = "sysrq"; in sysrq_connect()
982 sysrq->handle.private = sysrq; in sysrq_connect()
983 timer_setup(&sysrq->keyreset_timer, sysrq_do_reset, 0); in sysrq_connect()
985 error = input_register_handle(&sysrq->handle); in sysrq_connect()
992 error = input_open_device(&sysrq->handle); in sysrq_connect()
1001 input_unregister_handle(&sysrq->handle); in sysrq_connect()
1009 struct sysrq_state *sysrq = handle->private; in sysrq_disconnect()
1012 cancel_work_sync(&sysrq->reinject_work); in sysrq_disconnect()
1013 timer_shutdown_sync(&sysrq->keyreset_timer); in sysrq_disconnect()
1020 * keyboards have SysRq key predefined and so user may add it to keymap
1068 return -EINVAL; in sysrq_reset_seq_param_set()
1070 *((unsigned short *)kp->arg) = val; in sysrq_reset_seq_param_set()
1122 static int __sysrq_swap_key_ops(u8 key, const struct sysrq_key_op *insert_op_p, in __sysrq_swap_key_ops() argument
1128 if (__sysrq_get_key_op(key) == remove_op_p) { in __sysrq_swap_key_ops()
1129 __sysrq_put_key_op(key, insert_op_p); in __sysrq_swap_key_ops()
1132 retval = -1; in __sysrq_swap_key_ops()
1146 int register_sysrq_key(u8 key, const struct sysrq_key_op *op_p) in register_sysrq_key() argument
1148 return __sysrq_swap_key_ops(key, op_p, NULL); in register_sysrq_key()
1152 int unregister_sysrq_key(u8 key, const struct sysrq_key_op *op_p) in unregister_sysrq_key() argument
1154 return __sysrq_swap_key_ops(key, NULL, op_p); in unregister_sysrq_key()
1160 * writing 'C' to /proc/sysrq-trigger is like sysrq-C
1175 return -EFAULT; in write_sysrq_trigger()
1196 if (!proc_create("sysrq-trigger", S_IWUSR, NULL, in sysrq_init_procfs()