1/* -*- linux-c -*- 2 * 3 * $Id: sysrq.h,v 1.1.1.1 2008/10/15 03:29:28 james26_jang 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#ifndef __LINUX_SYSRQ_H__ 14#define __LINUX_SYSRQ_H__ 15 16#include <linux/config.h> 17 18struct pt_regs; 19struct kbd_struct; 20struct tty_struct; 21 22struct sysrq_key_op { 23 void (*handler)(int, struct pt_regs *, 24 struct kbd_struct *, struct tty_struct *); 25 char *help_msg; 26 char *action_msg; 27}; 28 29#ifdef CONFIG_MAGIC_SYSRQ 30 31/* Generic SysRq interface -- you may call it from any device driver, supplying 32 * ASCII code of the key, pointer to registers and kbd/tty structs (if they 33 * are available -- else NULL's). 34 */ 35 36void handle_sysrq(int, struct pt_regs *, 37 struct kbd_struct *, struct tty_struct *); 38 39 40/* 41 * Nonlocking version of handle sysrq, used by sysrq handlers that need to 42 * call sysrq handlers 43 */ 44 45void __handle_sysrq_nolock(int, struct pt_regs *, 46 struct kbd_struct *, struct tty_struct *); 47 48 49 50/* 51 * Sysrq registration manipulation functions 52 */ 53 54void __sysrq_lock_table (void); 55void __sysrq_unlock_table (void); 56struct sysrq_key_op *__sysrq_get_key_op (int key); 57void __sysrq_put_key_op (int key, struct sysrq_key_op *op_p); 58 59extern __inline__ int 60__sysrq_swap_key_ops_nolock(int key, struct sysrq_key_op *insert_op_p, 61 struct sysrq_key_op *remove_op_p) 62{ 63 int retval; 64 if (__sysrq_get_key_op(key) == remove_op_p) { 65 __sysrq_put_key_op(key, insert_op_p); 66 retval = 0; 67 } else { 68 retval = -1; 69 } 70 return retval; 71} 72 73extern __inline__ int 74__sysrq_swap_key_ops(int key, struct sysrq_key_op *insert_op_p, 75 struct sysrq_key_op *remove_op_p) { 76 int retval; 77 __sysrq_lock_table(); 78 retval = __sysrq_swap_key_ops_nolock(key, insert_op_p, remove_op_p); 79 __sysrq_unlock_table(); 80 return retval; 81} 82 83static inline int register_sysrq_key(int key, struct sysrq_key_op *op_p) 84{ 85 return __sysrq_swap_key_ops(key, op_p, NULL); 86} 87 88static inline int unregister_sysrq_key(int key, struct sysrq_key_op *op_p) 89{ 90 return __sysrq_swap_key_ops(key, NULL, op_p); 91} 92 93#else 94 95static inline int __reterr(void) 96{ 97 return -EINVAL; 98} 99 100#define register_sysrq_key(ig,nore) __reterr() 101#define unregister_sysrq_key(ig,nore) __reterr() 102 103#endif 104 105 106/* Deferred actions */ 107 108extern volatile int emergency_sync_scheduled; 109 110#define EMERG_SYNC 1 111#define EMERG_REMOUNT 2 112 113void do_emergency_sync(void); 114 115#ifdef CONFIG_MAGIC_SYSRQ 116#define CHECK_EMERGENCY_SYNC \ 117 if (emergency_sync_scheduled) \ 118 do_emergency_sync(); 119#else 120#define CHECK_EMERGENCY_SYNC 121#endif 122 123#endif /* __LINUX_SYSRQ_H__ */ 124