File: /usr/src/linux/include/linux/sysrq.h
1 /* -*- linux-c -*-
2 *
3 * $Id: sysrq.h,v 1.3 1997/07/17 11:54:33 mj Exp $
4 *
5 * Linux Magic System Request Key Hacks
6 *
7 * (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
8 *
9 * (c) 2000 Crutcher Dunnavant <crutcher+kernel@datastacks.com>
10 * overhauled to use key registration
11 * based upon discusions in irc://irc.openprojects.net/#kernelnewbies
12 */
13
14 #include <linux/config.h>
15
16 struct pt_regs;
17 struct kbd_struct;
18 struct tty_struct;
19
20 struct sysrq_key_op {
21 void (*handler)(int, struct pt_regs *,
22 struct kbd_struct *, struct tty_struct *);
23 char *help_msg;
24 char *action_msg;
25 };
26
27 /* Generic SysRq interface -- you may call it from any device driver, supplying
28 * ASCII code of the key, pointer to registers and kbd/tty structs (if they
29 * are available -- else NULL's).
30 */
31
32 void handle_sysrq(int, struct pt_regs *,
33 struct kbd_struct *, struct tty_struct *);
34
35
36 /*
37 * Nonlocking version of handle sysrq, used by sysrq handlers that need to
38 * call sysrq handlers
39 */
40
41 void __handle_sysrq_nolock(int, struct pt_regs *,
42 struct kbd_struct *, struct tty_struct *);
43
44
45 #ifdef CONFIG_MAGIC_SYSRQ
46
47 /*
48 * Sysrq registration manipulation functions
49 */
50
51 void __sysrq_lock_table (void);
52 void __sysrq_unlock_table (void);
53 struct sysrq_key_op *__sysrq_get_key_op (int key);
54 void __sysrq_put_key_op (int key, struct sysrq_key_op *op_p);
55
56 extern __inline__ int
57 __sysrq_swap_key_ops_nolock(int key, struct sysrq_key_op *insert_op_p,
58 struct sysrq_key_op *remove_op_p) {
59 int retval;
60 if (__sysrq_get_key_op(key) == remove_op_p) {
61 __sysrq_put_key_op(key, insert_op_p);
62 retval = 0;
63 } else {
64 retval = -1;
65 }
66 return retval;
67 }
68
69 extern __inline__ int
70 __sysrq_swap_key_ops(int key, struct sysrq_key_op *insert_op_p,
71 struct sysrq_key_op *remove_op_p) {
72 int retval;
73 __sysrq_lock_table();
74 retval = __sysrq_swap_key_ops_nolock(key, insert_op_p, remove_op_p);
75 __sysrq_unlock_table();
76 return retval;
77 }
78
79 static inline int register_sysrq_key(int key, struct sysrq_key_op *op_p)
80 {
81 return __sysrq_swap_key_ops(key, op_p, NULL);
82 }
83
84 static inline int unregister_sysrq_key(int key, struct sysrq_key_op *op_p)
85 {
86 return __sysrq_swap_key_ops(key, NULL, op_p);
87 }
88
89 #else
90 #define register_sysrq_key(a,b) do {} while(0)
91 #define unregister_sysrq_key(a,b) do {} while(0)
92 #endif
93
94 /* Deferred actions */
95
96 extern int emergency_sync_scheduled;
97
98 #define EMERG_SYNC 1
99 #define EMERG_REMOUNT 2
100
101 void do_emergency_sync(void);
102
103 #ifdef CONFIG_MAGIC_SYSRQ
104 #define CHECK_EMERGENCY_SYNC \
105 if (emergency_sync_scheduled) \
106 do_emergency_sync();
107 #else
108 #define CHECK_EMERGENCY_SYNC
109 #endif
110