diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-20 13:33:06 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-05-20 13:33:06 -0400 |
commit | a0fe3cc5d36a5f5b4f60abfe1a4b1caf4a5cce5a (patch) | |
tree | 99a735d89df5bf49cf4edda1ba53bd9175d0f163 /drivers/char | |
parent | 04afb40593f9a3007e5ea817d009529ef10fb685 (diff) | |
parent | a62f0d27b4196bad5e900d766b285feb7069cd16 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (40 commits)
Input: psmouse - small formatting changes to better follow coding style
Input: synaptics - set dimensions as reported by firmware
Input: elantech - relax signature checks
Input: elantech - enforce common prefix on messages
Input: wistron_btns - switch to using kmemdup()
Input: usbtouchscreen - switch to using kmemdup()
Input: do not force selecting i8042 on Moorestown
Input: Documentation/sysrq.txt - update KEY_SYSRQ info
Input: 88pm860x_onkey - remove invalid irq number assignment
Input: i8042 - add a PNP entry to the aux device list
Input: i8042 - add some extra PNP keyboard types
Input: wm9712 - fix wm97xx_set_gpio() logic
Input: add keypad driver for keys interfaced to TCA6416
Input: remove obsolete {corgi,spitz,tosa}kbd.c
Input: kbtab - do not advertise unsupported events
Input: kbtab - simplify kbtab_disconnect()
Input: kbtab - fix incorrect size parameter in usb_buffer_free
Input: acecad - don't advertise mouse events
Input: acecad - fix some formatting issues
Input: acecad - simplify usb_acecad_disconnect()
...
Trivial conflict in Documentation/feature-removal-schedule.txt
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/keyboard.c | 325 | ||||
-rw-r--r-- | drivers/char/sysrq.c | 243 |
2 files changed, 368 insertions, 200 deletions
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c index ada25bb8941e..54109dc9240c 100644 --- a/drivers/char/keyboard.c +++ b/drivers/char/keyboard.c | |||
@@ -24,6 +24,8 @@ | |||
24 | * 21-08-02: Converted to input API, major cleanup. (Vojtech Pavlik) | 24 | * 21-08-02: Converted to input API, major cleanup. (Vojtech Pavlik) |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
28 | |||
27 | #include <linux/consolemap.h> | 29 | #include <linux/consolemap.h> |
28 | #include <linux/module.h> | 30 | #include <linux/module.h> |
29 | #include <linux/sched.h> | 31 | #include <linux/sched.h> |
@@ -38,7 +40,6 @@ | |||
38 | #include <linux/kbd_kern.h> | 40 | #include <linux/kbd_kern.h> |
39 | #include <linux/kbd_diacr.h> | 41 | #include <linux/kbd_diacr.h> |
40 | #include <linux/vt_kern.h> | 42 | #include <linux/vt_kern.h> |
41 | #include <linux/sysrq.h> | ||
42 | #include <linux/input.h> | 43 | #include <linux/input.h> |
43 | #include <linux/reboot.h> | 44 | #include <linux/reboot.h> |
44 | #include <linux/notifier.h> | 45 | #include <linux/notifier.h> |
@@ -82,8 +83,7 @@ void compute_shiftstate(void); | |||
82 | typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value, | 83 | typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value, |
83 | char up_flag); | 84 | char up_flag); |
84 | static k_handler_fn K_HANDLERS; | 85 | static k_handler_fn K_HANDLERS; |
85 | k_handler_fn *k_handler[16] = { K_HANDLERS }; | 86 | static k_handler_fn *k_handler[16] = { K_HANDLERS }; |
86 | EXPORT_SYMBOL_GPL(k_handler); | ||
87 | 87 | ||
88 | #define FN_HANDLERS\ | 88 | #define FN_HANDLERS\ |
89 | fn_null, fn_enter, fn_show_ptregs, fn_show_mem,\ | 89 | fn_null, fn_enter, fn_show_ptregs, fn_show_mem,\ |
@@ -133,7 +133,7 @@ static struct input_handler kbd_handler; | |||
133 | static DEFINE_SPINLOCK(kbd_event_lock); | 133 | static DEFINE_SPINLOCK(kbd_event_lock); |
134 | static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */ | 134 | static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */ |
135 | static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ | 135 | static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ |
136 | static int dead_key_next; | 136 | static bool dead_key_next; |
137 | static int npadch = -1; /* -1 or number assembled on pad */ | 137 | static int npadch = -1; /* -1 or number assembled on pad */ |
138 | static unsigned int diacr; | 138 | static unsigned int diacr; |
139 | static char rep; /* flag telling character repeat */ | 139 | static char rep; /* flag telling character repeat */ |
@@ -147,22 +147,6 @@ static struct ledptr { | |||
147 | unsigned char valid:1; | 147 | unsigned char valid:1; |
148 | } ledptrs[3]; | 148 | } ledptrs[3]; |
149 | 149 | ||
150 | /* Simple translation table for the SysRq keys */ | ||
151 | |||
152 | #ifdef CONFIG_MAGIC_SYSRQ | ||
153 | unsigned char kbd_sysrq_xlate[KEY_MAX + 1] = | ||
154 | "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */ | ||
155 | "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */ | ||
156 | "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */ | ||
157 | "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */ | ||
158 | "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */ | ||
159 | "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */ | ||
160 | "\r\000/"; /* 0x60 - 0x6f */ | ||
161 | static int sysrq_down; | ||
162 | static int sysrq_alt_use; | ||
163 | #endif | ||
164 | static int sysrq_alt; | ||
165 | |||
166 | /* | 150 | /* |
167 | * Notifier list for console keyboard events | 151 | * Notifier list for console keyboard events |
168 | */ | 152 | */ |
@@ -361,8 +345,8 @@ static void to_utf8(struct vc_data *vc, uint c) | |||
361 | /* 110***** 10****** */ | 345 | /* 110***** 10****** */ |
362 | put_queue(vc, 0xc0 | (c >> 6)); | 346 | put_queue(vc, 0xc0 | (c >> 6)); |
363 | put_queue(vc, 0x80 | (c & 0x3f)); | 347 | put_queue(vc, 0x80 | (c & 0x3f)); |
364 | } else if (c < 0x10000) { | 348 | } else if (c < 0x10000) { |
365 | if (c >= 0xD800 && c < 0xE000) | 349 | if (c >= 0xD800 && c < 0xE000) |
366 | return; | 350 | return; |
367 | if (c == 0xFFFF) | 351 | if (c == 0xFFFF) |
368 | return; | 352 | return; |
@@ -370,7 +354,7 @@ static void to_utf8(struct vc_data *vc, uint c) | |||
370 | put_queue(vc, 0xe0 | (c >> 12)); | 354 | put_queue(vc, 0xe0 | (c >> 12)); |
371 | put_queue(vc, 0x80 | ((c >> 6) & 0x3f)); | 355 | put_queue(vc, 0x80 | ((c >> 6) & 0x3f)); |
372 | put_queue(vc, 0x80 | (c & 0x3f)); | 356 | put_queue(vc, 0x80 | (c & 0x3f)); |
373 | } else if (c < 0x110000) { | 357 | } else if (c < 0x110000) { |
374 | /* 11110*** 10****** 10****** 10****** */ | 358 | /* 11110*** 10****** 10****** 10****** */ |
375 | put_queue(vc, 0xf0 | (c >> 18)); | 359 | put_queue(vc, 0xf0 | (c >> 18)); |
376 | put_queue(vc, 0x80 | ((c >> 12) & 0x3f)); | 360 | put_queue(vc, 0x80 | ((c >> 12) & 0x3f)); |
@@ -469,6 +453,7 @@ static void fn_enter(struct vc_data *vc) | |||
469 | } | 453 | } |
470 | diacr = 0; | 454 | diacr = 0; |
471 | } | 455 | } |
456 | |||
472 | put_queue(vc, 13); | 457 | put_queue(vc, 13); |
473 | if (vc_kbd_mode(kbd, VC_CRLF)) | 458 | if (vc_kbd_mode(kbd, VC_CRLF)) |
474 | put_queue(vc, 10); | 459 | put_queue(vc, 10); |
@@ -478,6 +463,7 @@ static void fn_caps_toggle(struct vc_data *vc) | |||
478 | { | 463 | { |
479 | if (rep) | 464 | if (rep) |
480 | return; | 465 | return; |
466 | |||
481 | chg_vc_kbd_led(kbd, VC_CAPSLOCK); | 467 | chg_vc_kbd_led(kbd, VC_CAPSLOCK); |
482 | } | 468 | } |
483 | 469 | ||
@@ -485,12 +471,14 @@ static void fn_caps_on(struct vc_data *vc) | |||
485 | { | 471 | { |
486 | if (rep) | 472 | if (rep) |
487 | return; | 473 | return; |
474 | |||
488 | set_vc_kbd_led(kbd, VC_CAPSLOCK); | 475 | set_vc_kbd_led(kbd, VC_CAPSLOCK); |
489 | } | 476 | } |
490 | 477 | ||
491 | static void fn_show_ptregs(struct vc_data *vc) | 478 | static void fn_show_ptregs(struct vc_data *vc) |
492 | { | 479 | { |
493 | struct pt_regs *regs = get_irq_regs(); | 480 | struct pt_regs *regs = get_irq_regs(); |
481 | |||
494 | if (regs) | 482 | if (regs) |
495 | show_regs(regs); | 483 | show_regs(regs); |
496 | } | 484 | } |
@@ -515,7 +503,7 @@ static void fn_hold(struct vc_data *vc) | |||
515 | 503 | ||
516 | static void fn_num(struct vc_data *vc) | 504 | static void fn_num(struct vc_data *vc) |
517 | { | 505 | { |
518 | if (vc_kbd_mode(kbd,VC_APPLIC)) | 506 | if (vc_kbd_mode(kbd, VC_APPLIC)) |
519 | applkey(vc, 'P', 1); | 507 | applkey(vc, 'P', 1); |
520 | else | 508 | else |
521 | fn_bare_num(vc); | 509 | fn_bare_num(vc); |
@@ -610,7 +598,7 @@ static void fn_boot_it(struct vc_data *vc) | |||
610 | 598 | ||
611 | static void fn_compose(struct vc_data *vc) | 599 | static void fn_compose(struct vc_data *vc) |
612 | { | 600 | { |
613 | dead_key_next = 1; | 601 | dead_key_next = true; |
614 | } | 602 | } |
615 | 603 | ||
616 | static void fn_spawn_con(struct vc_data *vc) | 604 | static void fn_spawn_con(struct vc_data *vc) |
@@ -657,7 +645,7 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag) | |||
657 | 645 | ||
658 | static void k_lowercase(struct vc_data *vc, unsigned char value, char up_flag) | 646 | static void k_lowercase(struct vc_data *vc, unsigned char value, char up_flag) |
659 | { | 647 | { |
660 | printk(KERN_ERR "keyboard.c: k_lowercase was called - impossible\n"); | 648 | pr_err("k_lowercase was called - impossible\n"); |
661 | } | 649 | } |
662 | 650 | ||
663 | static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag) | 651 | static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag) |
@@ -669,7 +657,7 @@ static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag) | |||
669 | value = handle_diacr(vc, value); | 657 | value = handle_diacr(vc, value); |
670 | 658 | ||
671 | if (dead_key_next) { | 659 | if (dead_key_next) { |
672 | dead_key_next = 0; | 660 | dead_key_next = false; |
673 | diacr = value; | 661 | diacr = value; |
674 | return; | 662 | return; |
675 | } | 663 | } |
@@ -691,6 +679,7 @@ static void k_deadunicode(struct vc_data *vc, unsigned int value, char up_flag) | |||
691 | { | 679 | { |
692 | if (up_flag) | 680 | if (up_flag) |
693 | return; | 681 | return; |
682 | |||
694 | diacr = (diacr ? handle_diacr(vc, value) : value); | 683 | diacr = (diacr ? handle_diacr(vc, value) : value); |
695 | } | 684 | } |
696 | 685 | ||
@@ -710,29 +699,28 @@ static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag) | |||
710 | static void k_dead(struct vc_data *vc, unsigned char value, char up_flag) | 699 | static void k_dead(struct vc_data *vc, unsigned char value, char up_flag) |
711 | { | 700 | { |
712 | static const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' }; | 701 | static const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' }; |
713 | value = ret_diacr[value]; | 702 | |
714 | k_deadunicode(vc, value, up_flag); | 703 | k_deadunicode(vc, ret_diacr[value], up_flag); |
715 | } | 704 | } |
716 | 705 | ||
717 | static void k_cons(struct vc_data *vc, unsigned char value, char up_flag) | 706 | static void k_cons(struct vc_data *vc, unsigned char value, char up_flag) |
718 | { | 707 | { |
719 | if (up_flag) | 708 | if (up_flag) |
720 | return; | 709 | return; |
710 | |||
721 | set_console(value); | 711 | set_console(value); |
722 | } | 712 | } |
723 | 713 | ||
724 | static void k_fn(struct vc_data *vc, unsigned char value, char up_flag) | 714 | static void k_fn(struct vc_data *vc, unsigned char value, char up_flag) |
725 | { | 715 | { |
726 | unsigned v; | ||
727 | |||
728 | if (up_flag) | 716 | if (up_flag) |
729 | return; | 717 | return; |
730 | v = value; | 718 | |
731 | if (v < ARRAY_SIZE(func_table)) { | 719 | if ((unsigned)value < ARRAY_SIZE(func_table)) { |
732 | if (func_table[value]) | 720 | if (func_table[value]) |
733 | puts_queue(vc, func_table[value]); | 721 | puts_queue(vc, func_table[value]); |
734 | } else | 722 | } else |
735 | printk(KERN_ERR "k_fn called with value=%d\n", value); | 723 | pr_err("k_fn called with value=%d\n", value); |
736 | } | 724 | } |
737 | 725 | ||
738 | static void k_cur(struct vc_data *vc, unsigned char value, char up_flag) | 726 | static void k_cur(struct vc_data *vc, unsigned char value, char up_flag) |
@@ -741,6 +729,7 @@ static void k_cur(struct vc_data *vc, unsigned char value, char up_flag) | |||
741 | 729 | ||
742 | if (up_flag) | 730 | if (up_flag) |
743 | return; | 731 | return; |
732 | |||
744 | applkey(vc, cur_chars[value], vc_kbd_mode(kbd, VC_CKMODE)); | 733 | applkey(vc, cur_chars[value], vc_kbd_mode(kbd, VC_CKMODE)); |
745 | } | 734 | } |
746 | 735 | ||
@@ -758,43 +747,45 @@ static void k_pad(struct vc_data *vc, unsigned char value, char up_flag) | |||
758 | return; | 747 | return; |
759 | } | 748 | } |
760 | 749 | ||
761 | if (!vc_kbd_led(kbd, VC_NUMLOCK)) | 750 | if (!vc_kbd_led(kbd, VC_NUMLOCK)) { |
751 | |||
762 | switch (value) { | 752 | switch (value) { |
763 | case KVAL(K_PCOMMA): | 753 | case KVAL(K_PCOMMA): |
764 | case KVAL(K_PDOT): | 754 | case KVAL(K_PDOT): |
765 | k_fn(vc, KVAL(K_REMOVE), 0); | 755 | k_fn(vc, KVAL(K_REMOVE), 0); |
766 | return; | 756 | return; |
767 | case KVAL(K_P0): | 757 | case KVAL(K_P0): |
768 | k_fn(vc, KVAL(K_INSERT), 0); | 758 | k_fn(vc, KVAL(K_INSERT), 0); |
769 | return; | 759 | return; |
770 | case KVAL(K_P1): | 760 | case KVAL(K_P1): |
771 | k_fn(vc, KVAL(K_SELECT), 0); | 761 | k_fn(vc, KVAL(K_SELECT), 0); |
772 | return; | 762 | return; |
773 | case KVAL(K_P2): | 763 | case KVAL(K_P2): |
774 | k_cur(vc, KVAL(K_DOWN), 0); | 764 | k_cur(vc, KVAL(K_DOWN), 0); |
775 | return; | 765 | return; |
776 | case KVAL(K_P3): | 766 | case KVAL(K_P3): |
777 | k_fn(vc, KVAL(K_PGDN), 0); | 767 | k_fn(vc, KVAL(K_PGDN), 0); |
778 | return; | 768 | return; |
779 | case KVAL(K_P4): | 769 | case KVAL(K_P4): |
780 | k_cur(vc, KVAL(K_LEFT), 0); | 770 | k_cur(vc, KVAL(K_LEFT), 0); |
781 | return; | 771 | return; |
782 | case KVAL(K_P6): | 772 | case KVAL(K_P6): |
783 | k_cur(vc, KVAL(K_RIGHT), 0); | 773 | k_cur(vc, KVAL(K_RIGHT), 0); |
784 | return; | 774 | return; |
785 | case KVAL(K_P7): | 775 | case KVAL(K_P7): |
786 | k_fn(vc, KVAL(K_FIND), 0); | 776 | k_fn(vc, KVAL(K_FIND), 0); |
787 | return; | 777 | return; |
788 | case KVAL(K_P8): | 778 | case KVAL(K_P8): |
789 | k_cur(vc, KVAL(K_UP), 0); | 779 | k_cur(vc, KVAL(K_UP), 0); |
790 | return; | 780 | return; |
791 | case KVAL(K_P9): | 781 | case KVAL(K_P9): |
792 | k_fn(vc, KVAL(K_PGUP), 0); | 782 | k_fn(vc, KVAL(K_PGUP), 0); |
793 | return; | 783 | return; |
794 | case KVAL(K_P5): | 784 | case KVAL(K_P5): |
795 | applkey(vc, 'G', vc_kbd_mode(kbd, VC_APPLIC)); | 785 | applkey(vc, 'G', vc_kbd_mode(kbd, VC_APPLIC)); |
796 | return; | 786 | return; |
797 | } | 787 | } |
788 | } | ||
798 | 789 | ||
799 | put_queue(vc, pad_chars[value]); | 790 | put_queue(vc, pad_chars[value]); |
800 | if (value == KVAL(K_PENTER) && vc_kbd_mode(kbd, VC_CRLF)) | 791 | if (value == KVAL(K_PENTER) && vc_kbd_mode(kbd, VC_CRLF)) |
@@ -880,6 +871,7 @@ static void k_lock(struct vc_data *vc, unsigned char value, char up_flag) | |||
880 | { | 871 | { |
881 | if (up_flag || rep) | 872 | if (up_flag || rep) |
882 | return; | 873 | return; |
874 | |||
883 | chg_vc_kbd_lock(kbd, value); | 875 | chg_vc_kbd_lock(kbd, value); |
884 | } | 876 | } |
885 | 877 | ||
@@ -888,6 +880,7 @@ static void k_slock(struct vc_data *vc, unsigned char value, char up_flag) | |||
888 | k_shift(vc, value, up_flag); | 880 | k_shift(vc, value, up_flag); |
889 | if (up_flag || rep) | 881 | if (up_flag || rep) |
890 | return; | 882 | return; |
883 | |||
891 | chg_vc_kbd_slock(kbd, value); | 884 | chg_vc_kbd_slock(kbd, value); |
892 | /* try to make Alt, oops, AltGr and such work */ | 885 | /* try to make Alt, oops, AltGr and such work */ |
893 | if (!key_maps[kbd->lockstate ^ kbd->slockstate]) { | 886 | if (!key_maps[kbd->lockstate ^ kbd->slockstate]) { |
@@ -925,12 +918,12 @@ static void k_brlcommit(struct vc_data *vc, unsigned int pattern, char up_flag) | |||
925 | 918 | ||
926 | static void k_brl(struct vc_data *vc, unsigned char value, char up_flag) | 919 | static void k_brl(struct vc_data *vc, unsigned char value, char up_flag) |
927 | { | 920 | { |
928 | static unsigned pressed,committing; | 921 | static unsigned pressed, committing; |
929 | static unsigned long releasestart; | 922 | static unsigned long releasestart; |
930 | 923 | ||
931 | if (kbd->kbdmode != VC_UNICODE) { | 924 | if (kbd->kbdmode != VC_UNICODE) { |
932 | if (!up_flag) | 925 | if (!up_flag) |
933 | printk("keyboard mode must be unicode for braille patterns\n"); | 926 | pr_warning("keyboard mode must be unicode for braille patterns\n"); |
934 | return; | 927 | return; |
935 | } | 928 | } |
936 | 929 | ||
@@ -942,32 +935,28 @@ static void k_brl(struct vc_data *vc, unsigned char value, char up_flag) | |||
942 | if (value > 8) | 935 | if (value > 8) |
943 | return; | 936 | return; |
944 | 937 | ||
945 | if (up_flag) { | 938 | if (!up_flag) { |
946 | if (brl_timeout) { | ||
947 | if (!committing || | ||
948 | time_after(jiffies, | ||
949 | releasestart + msecs_to_jiffies(brl_timeout))) { | ||
950 | committing = pressed; | ||
951 | releasestart = jiffies; | ||
952 | } | ||
953 | pressed &= ~(1 << (value - 1)); | ||
954 | if (!pressed) { | ||
955 | if (committing) { | ||
956 | k_brlcommit(vc, committing, 0); | ||
957 | committing = 0; | ||
958 | } | ||
959 | } | ||
960 | } else { | ||
961 | if (committing) { | ||
962 | k_brlcommit(vc, committing, 0); | ||
963 | committing = 0; | ||
964 | } | ||
965 | pressed &= ~(1 << (value - 1)); | ||
966 | } | ||
967 | } else { | ||
968 | pressed |= 1 << (value - 1); | 939 | pressed |= 1 << (value - 1); |
969 | if (!brl_timeout) | 940 | if (!brl_timeout) |
970 | committing = pressed; | 941 | committing = pressed; |
942 | } else if (brl_timeout) { | ||
943 | if (!committing || | ||
944 | time_after(jiffies, | ||
945 | releasestart + msecs_to_jiffies(brl_timeout))) { | ||
946 | committing = pressed; | ||
947 | releasestart = jiffies; | ||
948 | } | ||
949 | pressed &= ~(1 << (value - 1)); | ||
950 | if (!pressed && committing) { | ||
951 | k_brlcommit(vc, committing, 0); | ||
952 | committing = 0; | ||
953 | } | ||
954 | } else { | ||
955 | if (committing) { | ||
956 | k_brlcommit(vc, committing, 0); | ||
957 | committing = 0; | ||
958 | } | ||
959 | pressed &= ~(1 << (value - 1)); | ||
971 | } | 960 | } |
972 | } | 961 | } |
973 | 962 | ||
@@ -988,6 +977,7 @@ void setledstate(struct kbd_struct *kbd, unsigned int led) | |||
988 | kbd->ledmode = LED_SHOW_IOCTL; | 977 | kbd->ledmode = LED_SHOW_IOCTL; |
989 | } else | 978 | } else |
990 | kbd->ledmode = LED_SHOW_FLAGS; | 979 | kbd->ledmode = LED_SHOW_FLAGS; |
980 | |||
991 | set_leds(); | 981 | set_leds(); |
992 | } | 982 | } |
993 | 983 | ||
@@ -1075,7 +1065,7 @@ static const unsigned short x86_keycodes[256] = | |||
1075 | 332,340,365,342,343,344,345,346,356,270,341,368,369,370,371,372 }; | 1065 | 332,340,365,342,343,344,345,346,356,270,341,368,369,370,371,372 }; |
1076 | 1066 | ||
1077 | #ifdef CONFIG_SPARC | 1067 | #ifdef CONFIG_SPARC |
1078 | static int sparc_l1_a_state = 0; | 1068 | static int sparc_l1_a_state; |
1079 | extern void sun_do_break(void); | 1069 | extern void sun_do_break(void); |
1080 | #endif | 1070 | #endif |
1081 | 1071 | ||
@@ -1085,52 +1075,54 @@ static int emulate_raw(struct vc_data *vc, unsigned int keycode, | |||
1085 | int code; | 1075 | int code; |
1086 | 1076 | ||
1087 | switch (keycode) { | 1077 | switch (keycode) { |
1088 | case KEY_PAUSE: | ||
1089 | put_queue(vc, 0xe1); | ||
1090 | put_queue(vc, 0x1d | up_flag); | ||
1091 | put_queue(vc, 0x45 | up_flag); | ||
1092 | break; | ||
1093 | 1078 | ||
1094 | case KEY_HANGEUL: | 1079 | case KEY_PAUSE: |
1095 | if (!up_flag) | 1080 | put_queue(vc, 0xe1); |
1096 | put_queue(vc, 0xf2); | 1081 | put_queue(vc, 0x1d | up_flag); |
1097 | break; | 1082 | put_queue(vc, 0x45 | up_flag); |
1083 | break; | ||
1098 | 1084 | ||
1099 | case KEY_HANJA: | 1085 | case KEY_HANGEUL: |
1100 | if (!up_flag) | 1086 | if (!up_flag) |
1101 | put_queue(vc, 0xf1); | 1087 | put_queue(vc, 0xf2); |
1102 | break; | 1088 | break; |
1103 | 1089 | ||
1104 | case KEY_SYSRQ: | 1090 | case KEY_HANJA: |
1105 | /* | 1091 | if (!up_flag) |
1106 | * Real AT keyboards (that's what we're trying | 1092 | put_queue(vc, 0xf1); |
1107 | * to emulate here emit 0xe0 0x2a 0xe0 0x37 when | 1093 | break; |
1108 | * pressing PrtSc/SysRq alone, but simply 0x54 | ||
1109 | * when pressing Alt+PrtSc/SysRq. | ||
1110 | */ | ||
1111 | if (sysrq_alt) { | ||
1112 | put_queue(vc, 0x54 | up_flag); | ||
1113 | } else { | ||
1114 | put_queue(vc, 0xe0); | ||
1115 | put_queue(vc, 0x2a | up_flag); | ||
1116 | put_queue(vc, 0xe0); | ||
1117 | put_queue(vc, 0x37 | up_flag); | ||
1118 | } | ||
1119 | break; | ||
1120 | 1094 | ||
1121 | default: | 1095 | case KEY_SYSRQ: |
1122 | if (keycode > 255) | 1096 | /* |
1123 | return -1; | 1097 | * Real AT keyboards (that's what we're trying |
1098 | * to emulate here emit 0xe0 0x2a 0xe0 0x37 when | ||
1099 | * pressing PrtSc/SysRq alone, but simply 0x54 | ||
1100 | * when pressing Alt+PrtSc/SysRq. | ||
1101 | */ | ||
1102 | if (test_bit(KEY_LEFTALT, key_down) || | ||
1103 | test_bit(KEY_RIGHTALT, key_down)) { | ||
1104 | put_queue(vc, 0x54 | up_flag); | ||
1105 | } else { | ||
1106 | put_queue(vc, 0xe0); | ||
1107 | put_queue(vc, 0x2a | up_flag); | ||
1108 | put_queue(vc, 0xe0); | ||
1109 | put_queue(vc, 0x37 | up_flag); | ||
1110 | } | ||
1111 | break; | ||
1124 | 1112 | ||
1125 | code = x86_keycodes[keycode]; | 1113 | default: |
1126 | if (!code) | 1114 | if (keycode > 255) |
1127 | return -1; | 1115 | return -1; |
1128 | 1116 | ||
1129 | if (code & 0x100) | 1117 | code = x86_keycodes[keycode]; |
1130 | put_queue(vc, 0xe0); | 1118 | if (!code) |
1131 | put_queue(vc, (code & 0x7f) | up_flag); | 1119 | return -1; |
1132 | 1120 | ||
1133 | break; | 1121 | if (code & 0x100) |
1122 | put_queue(vc, 0xe0); | ||
1123 | put_queue(vc, (code & 0x7f) | up_flag); | ||
1124 | |||
1125 | break; | ||
1134 | } | 1126 | } |
1135 | 1127 | ||
1136 | return 0; | 1128 | return 0; |
@@ -1153,6 +1145,7 @@ static int emulate_raw(struct vc_data *vc, unsigned int keycode, unsigned char u | |||
1153 | static void kbd_rawcode(unsigned char data) | 1145 | static void kbd_rawcode(unsigned char data) |
1154 | { | 1146 | { |
1155 | struct vc_data *vc = vc_cons[fg_console].d; | 1147 | struct vc_data *vc = vc_cons[fg_console].d; |
1148 | |||
1156 | kbd = kbd_table + vc->vc_num; | 1149 | kbd = kbd_table + vc->vc_num; |
1157 | if (kbd->kbdmode == VC_RAW) | 1150 | if (kbd->kbdmode == VC_RAW) |
1158 | put_queue(vc, data); | 1151 | put_queue(vc, data); |
@@ -1162,10 +1155,12 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) | |||
1162 | { | 1155 | { |
1163 | struct vc_data *vc = vc_cons[fg_console].d; | 1156 | struct vc_data *vc = vc_cons[fg_console].d; |
1164 | unsigned short keysym, *key_map; | 1157 | unsigned short keysym, *key_map; |
1165 | unsigned char type, raw_mode; | 1158 | unsigned char type; |
1159 | bool raw_mode; | ||
1166 | struct tty_struct *tty; | 1160 | struct tty_struct *tty; |
1167 | int shift_final; | 1161 | int shift_final; |
1168 | struct keyboard_notifier_param param = { .vc = vc, .value = keycode, .down = down }; | 1162 | struct keyboard_notifier_param param = { .vc = vc, .value = keycode, .down = down }; |
1163 | int rc; | ||
1169 | 1164 | ||
1170 | tty = vc->vc_tty; | 1165 | tty = vc->vc_tty; |
1171 | 1166 | ||
@@ -1176,8 +1171,6 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) | |||
1176 | 1171 | ||
1177 | kbd = kbd_table + vc->vc_num; | 1172 | kbd = kbd_table + vc->vc_num; |
1178 | 1173 | ||
1179 | if (keycode == KEY_LEFTALT || keycode == KEY_RIGHTALT) | ||
1180 | sysrq_alt = down ? keycode : 0; | ||
1181 | #ifdef CONFIG_SPARC | 1174 | #ifdef CONFIG_SPARC |
1182 | if (keycode == KEY_STOP) | 1175 | if (keycode == KEY_STOP) |
1183 | sparc_l1_a_state = down; | 1176 | sparc_l1_a_state = down; |
@@ -1185,29 +1178,16 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) | |||
1185 | 1178 | ||
1186 | rep = (down == 2); | 1179 | rep = (down == 2); |
1187 | 1180 | ||
1188 | if ((raw_mode = (kbd->kbdmode == VC_RAW)) && !hw_raw) | 1181 | raw_mode = (kbd->kbdmode == VC_RAW); |
1182 | if (raw_mode && !hw_raw) | ||
1189 | if (emulate_raw(vc, keycode, !down << 7)) | 1183 | if (emulate_raw(vc, keycode, !down << 7)) |
1190 | if (keycode < BTN_MISC && printk_ratelimit()) | 1184 | if (keycode < BTN_MISC && printk_ratelimit()) |
1191 | printk(KERN_WARNING "keyboard.c: can't emulate rawmode for keycode %d\n", keycode); | 1185 | pr_warning("can't emulate rawmode for keycode %d\n", |
1186 | keycode); | ||
1192 | 1187 | ||
1193 | #ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */ | ||
1194 | if (keycode == KEY_SYSRQ && (sysrq_down || (down == 1 && sysrq_alt))) { | ||
1195 | if (!sysrq_down) { | ||
1196 | sysrq_down = down; | ||
1197 | sysrq_alt_use = sysrq_alt; | ||
1198 | } | ||
1199 | return; | ||
1200 | } | ||
1201 | if (sysrq_down && !down && keycode == sysrq_alt_use) | ||
1202 | sysrq_down = 0; | ||
1203 | if (sysrq_down && down && !rep) { | ||
1204 | handle_sysrq(kbd_sysrq_xlate[keycode], tty); | ||
1205 | return; | ||
1206 | } | ||
1207 | #endif | ||
1208 | #ifdef CONFIG_SPARC | 1188 | #ifdef CONFIG_SPARC |
1209 | if (keycode == KEY_A && sparc_l1_a_state) { | 1189 | if (keycode == KEY_A && sparc_l1_a_state) { |
1210 | sparc_l1_a_state = 0; | 1190 | sparc_l1_a_state = false; |
1211 | sun_do_break(); | 1191 | sun_do_break(); |
1212 | } | 1192 | } |
1213 | #endif | 1193 | #endif |
@@ -1229,7 +1209,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) | |||
1229 | put_queue(vc, (keycode >> 7) | 0x80); | 1209 | put_queue(vc, (keycode >> 7) | 0x80); |
1230 | put_queue(vc, keycode | 0x80); | 1210 | put_queue(vc, keycode | 0x80); |
1231 | } | 1211 | } |
1232 | raw_mode = 1; | 1212 | raw_mode = true; |
1233 | } | 1213 | } |
1234 | 1214 | ||
1235 | if (down) | 1215 | if (down) |
@@ -1252,29 +1232,32 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) | |||
1252 | param.ledstate = kbd->ledflagstate; | 1232 | param.ledstate = kbd->ledflagstate; |
1253 | key_map = key_maps[shift_final]; | 1233 | key_map = key_maps[shift_final]; |
1254 | 1234 | ||
1255 | if (atomic_notifier_call_chain(&keyboard_notifier_list, KBD_KEYCODE, ¶m) == NOTIFY_STOP || !key_map) { | 1235 | rc = atomic_notifier_call_chain(&keyboard_notifier_list, |
1256 | atomic_notifier_call_chain(&keyboard_notifier_list, KBD_UNBOUND_KEYCODE, ¶m); | 1236 | KBD_KEYCODE, ¶m); |
1237 | if (rc == NOTIFY_STOP || !key_map) { | ||
1238 | atomic_notifier_call_chain(&keyboard_notifier_list, | ||
1239 | KBD_UNBOUND_KEYCODE, ¶m); | ||
1257 | compute_shiftstate(); | 1240 | compute_shiftstate(); |
1258 | kbd->slockstate = 0; | 1241 | kbd->slockstate = 0; |
1259 | return; | 1242 | return; |
1260 | } | 1243 | } |
1261 | 1244 | ||
1262 | if (keycode >= NR_KEYS) | 1245 | if (keycode < NR_KEYS) |
1263 | if (keycode >= KEY_BRL_DOT1 && keycode <= KEY_BRL_DOT8) | ||
1264 | keysym = U(K(KT_BRL, keycode - KEY_BRL_DOT1 + 1)); | ||
1265 | else | ||
1266 | return; | ||
1267 | else | ||
1268 | keysym = key_map[keycode]; | 1246 | keysym = key_map[keycode]; |
1247 | else if (keycode >= KEY_BRL_DOT1 && keycode <= KEY_BRL_DOT8) | ||
1248 | keysym = U(K(KT_BRL, keycode - KEY_BRL_DOT1 + 1)); | ||
1249 | else | ||
1250 | return; | ||
1269 | 1251 | ||
1270 | type = KTYP(keysym); | 1252 | type = KTYP(keysym); |
1271 | 1253 | ||
1272 | if (type < 0xf0) { | 1254 | if (type < 0xf0) { |
1273 | param.value = keysym; | 1255 | param.value = keysym; |
1274 | if (atomic_notifier_call_chain(&keyboard_notifier_list, KBD_UNICODE, ¶m) == NOTIFY_STOP) | 1256 | rc = atomic_notifier_call_chain(&keyboard_notifier_list, |
1275 | return; | 1257 | KBD_UNICODE, ¶m); |
1276 | if (down && !raw_mode) | 1258 | if (rc != NOTIFY_STOP) |
1277 | to_utf8(vc, keysym); | 1259 | if (down && !raw_mode) |
1260 | to_utf8(vc, keysym); | ||
1278 | return; | 1261 | return; |
1279 | } | 1262 | } |
1280 | 1263 | ||
@@ -1288,9 +1271,11 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) | |||
1288 | keysym = key_map[keycode]; | 1271 | keysym = key_map[keycode]; |
1289 | } | 1272 | } |
1290 | } | 1273 | } |
1291 | param.value = keysym; | ||
1292 | 1274 | ||
1293 | if (atomic_notifier_call_chain(&keyboard_notifier_list, KBD_KEYSYM, ¶m) == NOTIFY_STOP) | 1275 | param.value = keysym; |
1276 | rc = atomic_notifier_call_chain(&keyboard_notifier_list, | ||
1277 | KBD_KEYSYM, ¶m); | ||
1278 | if (rc == NOTIFY_STOP) | ||
1294 | return; | 1279 | return; |
1295 | 1280 | ||
1296 | if (raw_mode && type != KT_SPEC && type != KT_SHIFT) | 1281 | if (raw_mode && type != KT_SPEC && type != KT_SHIFT) |
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c index d4e8b213a462..5d15630a5830 100644 --- a/drivers/char/sysrq.c +++ b/drivers/char/sysrq.c | |||
@@ -1,7 +1,4 @@ | |||
1 | /* -*- linux-c -*- | 1 | /* |
2 | * | ||
3 | * $Id: sysrq.c,v 1.15 1998/08/23 14:56:41 mj Exp $ | ||
4 | * | ||
5 | * Linux Magic System Request Key Hacks | 2 | * Linux Magic System Request Key Hacks |
6 | * | 3 | * |
7 | * (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz> | 4 | * (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz> |
@@ -10,8 +7,13 @@ | |||
10 | * (c) 2000 Crutcher Dunnavant <crutcher+kernel@datastacks.com> | 7 | * (c) 2000 Crutcher Dunnavant <crutcher+kernel@datastacks.com> |
11 | * overhauled to use key registration | 8 | * overhauled to use key registration |
12 | * based upon discusions in irc://irc.openprojects.net/#kernelnewbies | 9 | * based upon discusions in irc://irc.openprojects.net/#kernelnewbies |
10 | * | ||
11 | * Copyright (c) 2010 Dmitry Torokhov | ||
12 | * Input handler conversion | ||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
16 | |||
15 | #include <linux/sched.h> | 17 | #include <linux/sched.h> |
16 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
17 | #include <linux/mm.h> | 19 | #include <linux/mm.h> |
@@ -39,33 +41,34 @@ | |||
39 | #include <linux/hrtimer.h> | 41 | #include <linux/hrtimer.h> |
40 | #include <linux/oom.h> | 42 | #include <linux/oom.h> |
41 | #include <linux/slab.h> | 43 | #include <linux/slab.h> |
44 | #include <linux/input.h> | ||
42 | 45 | ||
43 | #include <asm/ptrace.h> | 46 | #include <asm/ptrace.h> |
44 | #include <asm/irq_regs.h> | 47 | #include <asm/irq_regs.h> |
45 | 48 | ||
46 | /* Whether we react on sysrq keys or just ignore them */ | 49 | /* Whether we react on sysrq keys or just ignore them */ |
47 | int __read_mostly __sysrq_enabled = 1; | 50 | static int __read_mostly sysrq_enabled = 1; |
48 | 51 | static bool __read_mostly sysrq_always_enabled; | |
49 | static int __read_mostly sysrq_always_enabled; | ||
50 | 52 | ||
51 | int sysrq_on(void) | 53 | static bool sysrq_on(void) |
52 | { | 54 | { |
53 | return __sysrq_enabled || sysrq_always_enabled; | 55 | return sysrq_enabled || sysrq_always_enabled; |
54 | } | 56 | } |
55 | 57 | ||
56 | /* | 58 | /* |
57 | * A value of 1 means 'all', other nonzero values are an op mask: | 59 | * A value of 1 means 'all', other nonzero values are an op mask: |
58 | */ | 60 | */ |
59 | static inline int sysrq_on_mask(int mask) | 61 | static bool sysrq_on_mask(int mask) |
60 | { | 62 | { |
61 | return sysrq_always_enabled || __sysrq_enabled == 1 || | 63 | return sysrq_always_enabled || |
62 | (__sysrq_enabled & mask); | 64 | sysrq_enabled == 1 || |
65 | (sysrq_enabled & mask); | ||
63 | } | 66 | } |
64 | 67 | ||
65 | static int __init sysrq_always_enabled_setup(char *str) | 68 | static int __init sysrq_always_enabled_setup(char *str) |
66 | { | 69 | { |
67 | sysrq_always_enabled = 1; | 70 | sysrq_always_enabled = true; |
68 | printk(KERN_INFO "debug: sysrq always enabled.\n"); | 71 | pr_info("sysrq always enabled.\n"); |
69 | 72 | ||
70 | return 1; | 73 | return 1; |
71 | } | 74 | } |
@@ -76,6 +79,7 @@ __setup("sysrq_always_enabled", sysrq_always_enabled_setup); | |||
76 | static void sysrq_handle_loglevel(int key, struct tty_struct *tty) | 79 | static void sysrq_handle_loglevel(int key, struct tty_struct *tty) |
77 | { | 80 | { |
78 | int i; | 81 | int i; |
82 | |||
79 | i = key - '0'; | 83 | i = key - '0'; |
80 | console_loglevel = 7; | 84 | console_loglevel = 7; |
81 | printk("Loglevel set to %d\n", i); | 85 | printk("Loglevel set to %d\n", i); |
@@ -101,7 +105,7 @@ static struct sysrq_key_op sysrq_SAK_op = { | |||
101 | .enable_mask = SYSRQ_ENABLE_KEYBOARD, | 105 | .enable_mask = SYSRQ_ENABLE_KEYBOARD, |
102 | }; | 106 | }; |
103 | #else | 107 | #else |
104 | #define sysrq_SAK_op (*(struct sysrq_key_op *)0) | 108 | #define sysrq_SAK_op (*(struct sysrq_key_op *)NULL) |
105 | #endif | 109 | #endif |
106 | 110 | ||
107 | #ifdef CONFIG_VT | 111 | #ifdef CONFIG_VT |
@@ -119,7 +123,7 @@ static struct sysrq_key_op sysrq_unraw_op = { | |||
119 | .enable_mask = SYSRQ_ENABLE_KEYBOARD, | 123 | .enable_mask = SYSRQ_ENABLE_KEYBOARD, |
120 | }; | 124 | }; |
121 | #else | 125 | #else |
122 | #define sysrq_unraw_op (*(struct sysrq_key_op *)0) | 126 | #define sysrq_unraw_op (*(struct sysrq_key_op *)NULL) |
123 | #endif /* CONFIG_VT */ | 127 | #endif /* CONFIG_VT */ |
124 | 128 | ||
125 | static void sysrq_handle_crash(int key, struct tty_struct *tty) | 129 | static void sysrq_handle_crash(int key, struct tty_struct *tty) |
@@ -195,7 +199,7 @@ static struct sysrq_key_op sysrq_showlocks_op = { | |||
195 | .action_msg = "Show Locks Held", | 199 | .action_msg = "Show Locks Held", |
196 | }; | 200 | }; |
197 | #else | 201 | #else |
198 | #define sysrq_showlocks_op (*(struct sysrq_key_op *)0) | 202 | #define sysrq_showlocks_op (*(struct sysrq_key_op *)NULL) |
199 | #endif | 203 | #endif |
200 | 204 | ||
201 | #ifdef CONFIG_SMP | 205 | #ifdef CONFIG_SMP |
@@ -298,7 +302,7 @@ static struct sysrq_key_op sysrq_ftrace_dump_op = { | |||
298 | .enable_mask = SYSRQ_ENABLE_DUMP, | 302 | .enable_mask = SYSRQ_ENABLE_DUMP, |
299 | }; | 303 | }; |
300 | #else | 304 | #else |
301 | #define sysrq_ftrace_dump_op (*(struct sysrq_key_op *)0) | 305 | #define sysrq_ftrace_dump_op (*(struct sysrq_key_op *)NULL) |
302 | #endif | 306 | #endif |
303 | 307 | ||
304 | static void sysrq_handle_showmem(int key, struct tty_struct *tty) | 308 | static void sysrq_handle_showmem(int key, struct tty_struct *tty) |
@@ -477,6 +481,7 @@ struct sysrq_key_op *__sysrq_get_key_op(int key) | |||
477 | i = sysrq_key_table_key2index(key); | 481 | i = sysrq_key_table_key2index(key); |
478 | if (i != -1) | 482 | if (i != -1) |
479 | op_p = sysrq_key_table[i]; | 483 | op_p = sysrq_key_table[i]; |
484 | |||
480 | return op_p; | 485 | return op_p; |
481 | } | 486 | } |
482 | 487 | ||
@@ -488,11 +493,7 @@ static void __sysrq_put_key_op(int key, struct sysrq_key_op *op_p) | |||
488 | sysrq_key_table[i] = op_p; | 493 | sysrq_key_table[i] = op_p; |
489 | } | 494 | } |
490 | 495 | ||
491 | /* | 496 | static void __handle_sysrq(int key, struct tty_struct *tty, int check_mask) |
492 | * This is the non-locking version of handle_sysrq. It must/can only be called | ||
493 | * by sysrq key handlers, as they are inside of the lock | ||
494 | */ | ||
495 | void __handle_sysrq(int key, struct tty_struct *tty, int check_mask) | ||
496 | { | 497 | { |
497 | struct sysrq_key_op *op_p; | 498 | struct sysrq_key_op *op_p; |
498 | int orig_log_level; | 499 | int orig_log_level; |
@@ -544,10 +545,6 @@ void __handle_sysrq(int key, struct tty_struct *tty, int check_mask) | |||
544 | spin_unlock_irqrestore(&sysrq_key_table_lock, flags); | 545 | spin_unlock_irqrestore(&sysrq_key_table_lock, flags); |
545 | } | 546 | } |
546 | 547 | ||
547 | /* | ||
548 | * This function is called by the keyboard handler when SysRq is pressed | ||
549 | * and any other keycode arrives. | ||
550 | */ | ||
551 | void handle_sysrq(int key, struct tty_struct *tty) | 548 | void handle_sysrq(int key, struct tty_struct *tty) |
552 | { | 549 | { |
553 | if (sysrq_on()) | 550 | if (sysrq_on()) |
@@ -555,10 +552,177 @@ void handle_sysrq(int key, struct tty_struct *tty) | |||
555 | } | 552 | } |
556 | EXPORT_SYMBOL(handle_sysrq); | 553 | EXPORT_SYMBOL(handle_sysrq); |
557 | 554 | ||
555 | #ifdef CONFIG_INPUT | ||
556 | |||
557 | /* Simple translation table for the SysRq keys */ | ||
558 | static const unsigned char sysrq_xlate[KEY_MAX + 1] = | ||
559 | "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */ | ||
560 | "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */ | ||
561 | "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */ | ||
562 | "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */ | ||
563 | "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */ | ||
564 | "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */ | ||
565 | "\r\000/"; /* 0x60 - 0x6f */ | ||
566 | |||
567 | static bool sysrq_down; | ||
568 | static int sysrq_alt_use; | ||
569 | static int sysrq_alt; | ||
570 | |||
571 | static bool sysrq_filter(struct input_handle *handle, unsigned int type, | ||
572 | unsigned int code, int value) | ||
573 | { | ||
574 | if (type != EV_KEY) | ||
575 | goto out; | ||
576 | |||
577 | switch (code) { | ||
578 | |||
579 | case KEY_LEFTALT: | ||
580 | case KEY_RIGHTALT: | ||
581 | if (value) | ||
582 | sysrq_alt = code; | ||
583 | else if (sysrq_down && code == sysrq_alt_use) | ||
584 | sysrq_down = false; | ||
585 | break; | ||
586 | |||
587 | case KEY_SYSRQ: | ||
588 | if (value == 1 && sysrq_alt) { | ||
589 | sysrq_down = true; | ||
590 | sysrq_alt_use = sysrq_alt; | ||
591 | } | ||
592 | break; | ||
593 | |||
594 | default: | ||
595 | if (sysrq_down && value && value != 2) | ||
596 | __handle_sysrq(sysrq_xlate[code], NULL, 1); | ||
597 | break; | ||
598 | } | ||
599 | |||
600 | out: | ||
601 | return sysrq_down; | ||
602 | } | ||
603 | |||
604 | static int sysrq_connect(struct input_handler *handler, | ||
605 | struct input_dev *dev, | ||
606 | const struct input_device_id *id) | ||
607 | { | ||
608 | struct input_handle *handle; | ||
609 | int error; | ||
610 | |||
611 | sysrq_down = false; | ||
612 | sysrq_alt = 0; | ||
613 | |||
614 | handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); | ||
615 | if (!handle) | ||
616 | return -ENOMEM; | ||
617 | |||
618 | handle->dev = dev; | ||
619 | handle->handler = handler; | ||
620 | handle->name = "sysrq"; | ||
621 | |||
622 | error = input_register_handle(handle); | ||
623 | if (error) { | ||
624 | pr_err("Failed to register input sysrq handler, error %d\n", | ||
625 | error); | ||
626 | goto err_free; | ||
627 | } | ||
628 | |||
629 | error = input_open_device(handle); | ||
630 | if (error) { | ||
631 | pr_err("Failed to open input device, error %d\n", error); | ||
632 | goto err_unregister; | ||
633 | } | ||
634 | |||
635 | return 0; | ||
636 | |||
637 | err_unregister: | ||
638 | input_unregister_handle(handle); | ||
639 | err_free: | ||
640 | kfree(handle); | ||
641 | return error; | ||
642 | } | ||
643 | |||
644 | static void sysrq_disconnect(struct input_handle *handle) | ||
645 | { | ||
646 | input_close_device(handle); | ||
647 | input_unregister_handle(handle); | ||
648 | kfree(handle); | ||
649 | } | ||
650 | |||
651 | /* | ||
652 | * We are matching on KEY_LEFTALT insteard of KEY_SYSRQ because not all | ||
653 | * keyboards have SysRq ikey predefined and so user may add it to keymap | ||
654 | * later, but we expect all such keyboards to have left alt. | ||
655 | */ | ||
656 | static const struct input_device_id sysrq_ids[] = { | ||
657 | { | ||
658 | .flags = INPUT_DEVICE_ID_MATCH_EVBIT | | ||
659 | INPUT_DEVICE_ID_MATCH_KEYBIT, | ||
660 | .evbit = { BIT_MASK(EV_KEY) }, | ||
661 | .keybit = { BIT_MASK(KEY_LEFTALT) }, | ||
662 | }, | ||
663 | { }, | ||
664 | }; | ||
665 | |||
666 | static struct input_handler sysrq_handler = { | ||
667 | .filter = sysrq_filter, | ||
668 | .connect = sysrq_connect, | ||
669 | .disconnect = sysrq_disconnect, | ||
670 | .name = "sysrq", | ||
671 | .id_table = sysrq_ids, | ||
672 | }; | ||
673 | |||
674 | static bool sysrq_handler_registered; | ||
675 | |||
676 | static inline void sysrq_register_handler(void) | ||
677 | { | ||
678 | int error; | ||
679 | |||
680 | error = input_register_handler(&sysrq_handler); | ||
681 | if (error) | ||
682 | pr_err("Failed to register input handler, error %d", error); | ||
683 | else | ||
684 | sysrq_handler_registered = true; | ||
685 | } | ||
686 | |||
687 | static inline void sysrq_unregister_handler(void) | ||
688 | { | ||
689 | if (sysrq_handler_registered) { | ||
690 | input_unregister_handler(&sysrq_handler); | ||
691 | sysrq_handler_registered = false; | ||
692 | } | ||
693 | } | ||
694 | |||
695 | #else | ||
696 | |||
697 | static inline void sysrq_register_handler(void) | ||
698 | { | ||
699 | } | ||
700 | |||
701 | static inline void sysrq_unregister_handler(void) | ||
702 | { | ||
703 | } | ||
704 | |||
705 | #endif /* CONFIG_INPUT */ | ||
706 | |||
707 | int sysrq_toggle_support(int enable_mask) | ||
708 | { | ||
709 | bool was_enabled = sysrq_on(); | ||
710 | |||
711 | sysrq_enabled = enable_mask; | ||
712 | |||
713 | if (was_enabled != sysrq_on()) { | ||
714 | if (sysrq_on()) | ||
715 | sysrq_register_handler(); | ||
716 | else | ||
717 | sysrq_unregister_handler(); | ||
718 | } | ||
719 | |||
720 | return 0; | ||
721 | } | ||
722 | |||
558 | static int __sysrq_swap_key_ops(int key, struct sysrq_key_op *insert_op_p, | 723 | static int __sysrq_swap_key_ops(int key, struct sysrq_key_op *insert_op_p, |
559 | struct sysrq_key_op *remove_op_p) | 724 | struct sysrq_key_op *remove_op_p) |
560 | { | 725 | { |
561 | |||
562 | int retval; | 726 | int retval; |
563 | unsigned long flags; | 727 | unsigned long flags; |
564 | 728 | ||
@@ -599,6 +763,7 @@ static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf, | |||
599 | return -EFAULT; | 763 | return -EFAULT; |
600 | __handle_sysrq(c, NULL, 0); | 764 | __handle_sysrq(c, NULL, 0); |
601 | } | 765 | } |
766 | |||
602 | return count; | 767 | return count; |
603 | } | 768 | } |
604 | 769 | ||
@@ -606,10 +771,28 @@ static const struct file_operations proc_sysrq_trigger_operations = { | |||
606 | .write = write_sysrq_trigger, | 771 | .write = write_sysrq_trigger, |
607 | }; | 772 | }; |
608 | 773 | ||
774 | static void sysrq_init_procfs(void) | ||
775 | { | ||
776 | if (!proc_create("sysrq-trigger", S_IWUSR, NULL, | ||
777 | &proc_sysrq_trigger_operations)) | ||
778 | pr_err("Failed to register proc interface\n"); | ||
779 | } | ||
780 | |||
781 | #else | ||
782 | |||
783 | static inline void sysrq_init_procfs(void) | ||
784 | { | ||
785 | } | ||
786 | |||
787 | #endif /* CONFIG_PROC_FS */ | ||
788 | |||
609 | static int __init sysrq_init(void) | 789 | static int __init sysrq_init(void) |
610 | { | 790 | { |
611 | proc_create("sysrq-trigger", S_IWUSR, NULL, &proc_sysrq_trigger_operations); | 791 | sysrq_init_procfs(); |
792 | |||
793 | if (sysrq_on()) | ||
794 | sysrq_register_handler(); | ||
795 | |||
612 | return 0; | 796 | return 0; |
613 | } | 797 | } |
614 | module_init(sysrq_init); | 798 | module_init(sysrq_init); |
615 | #endif | ||