io_uring/cmd: add cmd lazy tw wake helper
[linux-block.git] / include / linux / kdb.h
CommitLineData
5d5314d6
JW
1#ifndef _KDB_H
2#define _KDB_H
3
4/*
5 * Kernel Debugger Architecture Independent Global Headers
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 *
11 * Copyright (c) 2000-2007 Silicon Graphics, Inc. All Rights Reserved.
12 * Copyright (C) 2000 Stephane Eranian <eranian@hpl.hp.com>
13 * Copyright (C) 2009 Jason Wessel <jason.wessel@windriver.com>
14 */
15
c25abcd6
SG
16#include <linux/list.h>
17
9452e977
DT
18/* Shifted versions of the command enable bits are be used if the command
19 * has no arguments (see kdb_check_flags). This allows commands, such as
20 * go, to have different permissions depending upon whether it is called
21 * with an argument.
22 */
23#define KDB_ENABLE_NO_ARGS_SHIFT 10
24
729043e8 25typedef enum {
9452e977
DT
26 KDB_ENABLE_ALL = (1 << 0), /* Enable everything */
27 KDB_ENABLE_MEM_READ = (1 << 1),
28 KDB_ENABLE_MEM_WRITE = (1 << 2),
29 KDB_ENABLE_REG_READ = (1 << 3),
30 KDB_ENABLE_REG_WRITE = (1 << 4),
31 KDB_ENABLE_INSPECT = (1 << 5),
32 KDB_ENABLE_FLOW_CTRL = (1 << 6),
33 KDB_ENABLE_SIGNAL = (1 << 7),
34 KDB_ENABLE_REBOOT = (1 << 8),
35 /* User exposed values stop here, all remaining flags are
36 * exclusively used to describe a commands behaviour.
37 */
38
39 KDB_ENABLE_ALWAYS_SAFE = (1 << 9),
40 KDB_ENABLE_MASK = (1 << KDB_ENABLE_NO_ARGS_SHIFT) - 1,
41
42 KDB_ENABLE_ALL_NO_ARGS = KDB_ENABLE_ALL << KDB_ENABLE_NO_ARGS_SHIFT,
43 KDB_ENABLE_MEM_READ_NO_ARGS = KDB_ENABLE_MEM_READ
44 << KDB_ENABLE_NO_ARGS_SHIFT,
45 KDB_ENABLE_MEM_WRITE_NO_ARGS = KDB_ENABLE_MEM_WRITE
46 << KDB_ENABLE_NO_ARGS_SHIFT,
47 KDB_ENABLE_REG_READ_NO_ARGS = KDB_ENABLE_REG_READ
48 << KDB_ENABLE_NO_ARGS_SHIFT,
49 KDB_ENABLE_REG_WRITE_NO_ARGS = KDB_ENABLE_REG_WRITE
50 << KDB_ENABLE_NO_ARGS_SHIFT,
51 KDB_ENABLE_INSPECT_NO_ARGS = KDB_ENABLE_INSPECT
52 << KDB_ENABLE_NO_ARGS_SHIFT,
53 KDB_ENABLE_FLOW_CTRL_NO_ARGS = KDB_ENABLE_FLOW_CTRL
54 << KDB_ENABLE_NO_ARGS_SHIFT,
55 KDB_ENABLE_SIGNAL_NO_ARGS = KDB_ENABLE_SIGNAL
56 << KDB_ENABLE_NO_ARGS_SHIFT,
57 KDB_ENABLE_REBOOT_NO_ARGS = KDB_ENABLE_REBOOT
58 << KDB_ENABLE_NO_ARGS_SHIFT,
59 KDB_ENABLE_ALWAYS_SAFE_NO_ARGS = KDB_ENABLE_ALWAYS_SAFE
60 << KDB_ENABLE_NO_ARGS_SHIFT,
61 KDB_ENABLE_MASK_NO_ARGS = KDB_ENABLE_MASK << KDB_ENABLE_NO_ARGS_SHIFT,
62
63 KDB_REPEAT_NO_ARGS = 0x40000000, /* Repeat the command w/o arguments */
64 KDB_REPEAT_WITH_ARGS = 0x80000000, /* Repeat the command with args */
15a42a9b 65} kdb_cmdflags_t;
729043e8
AV
66
67typedef int (*kdb_func_t)(int, const char **);
68
c25abcd6
SG
69/* The KDB shell command table */
70typedef struct _kdbtab {
e868f0a3
SG
71 char *name; /* Command name */
72 kdb_func_t func; /* Function to execute command */
73 char *usage; /* Usage String for this command */
74 char *help; /* Help message for this command */
75 short minlen; /* Minimum legal # cmd chars required */
76 kdb_cmdflags_t flags; /* Command behaviour flags */
c25abcd6
SG
77 struct list_head list_node; /* Command list */
78} kdbtab_t;
79
5d5314d6
JW
80#ifdef CONFIG_KGDB_KDB
81#include <linux/init.h>
82#include <linux/sched.h>
60063497 83#include <linux/atomic.h>
5d5314d6
JW
84
85#define KDB_POLL_FUNC_MAX 5
f5316b4a 86extern int kdb_poll_idx;
5d5314d6
JW
87
88/*
89 * kdb_initial_cpu is initialized to -1, and is set to the cpu
90 * number whenever the kernel debugger is entered.
91 */
92extern int kdb_initial_cpu;
5d5314d6 93
f7030bbc
JW
94/* Types and messages used for dynamically added kdb shell commands */
95
96#define KDB_MAXARGS 16 /* Maximum number of arguments to a function */
97
f7030bbc
JW
98/* KDB return codes from a command or internal kdb function */
99#define KDB_NOTFOUND (-1)
100#define KDB_ARGCOUNT (-2)
101#define KDB_BADWIDTH (-3)
102#define KDB_BADRADIX (-4)
103#define KDB_NOTENV (-5)
104#define KDB_NOENVVALUE (-6)
105#define KDB_NOTIMP (-7)
106#define KDB_ENVFULL (-8)
107#define KDB_ENVBUFFULL (-9)
108#define KDB_TOOMANYBPT (-10)
109#define KDB_TOOMANYDBREGS (-11)
110#define KDB_DUPBPT (-12)
111#define KDB_BPTNOTFOUND (-13)
112#define KDB_BADMODE (-14)
113#define KDB_BADINT (-15)
114#define KDB_INVADDRFMT (-16)
115#define KDB_BADREG (-17)
116#define KDB_BADCPUNUM (-18)
117#define KDB_BADLENGTH (-19)
118#define KDB_NOBP (-20)
119#define KDB_BADADDR (-21)
420c2b1b 120#define KDB_NOPERM (-22)
f7030bbc 121
5d5314d6
JW
122/*
123 * kdb_diemsg
124 *
125 * Contains a pointer to the last string supplied to the
126 * kernel 'die' panic function.
127 */
128extern const char *kdb_diemsg;
129
130#define KDB_FLAG_EARLYKDB (1 << 0) /* set from boot parameter kdb=early */
131#define KDB_FLAG_CATASTROPHIC (1 << 1) /* A catastrophic event has occurred */
132#define KDB_FLAG_CMD_INTERRUPT (1 << 2) /* Previous command was interrupted */
133#define KDB_FLAG_NOIPI (1 << 3) /* Do not send IPIs */
5d5314d6
JW
134#define KDB_FLAG_NO_CONSOLE (1 << 5) /* No console is available,
135 * kdb is disabled */
136#define KDB_FLAG_NO_VT_CONSOLE (1 << 6) /* No VT console is available, do
137 * not use keyboard */
138#define KDB_FLAG_NO_I8042 (1 << 7) /* No i8042 chip is available, do
139 * not use keyboard */
140
c893de12 141extern unsigned int kdb_flags; /* Global flags, see kdb_state for per cpu state */
5d5314d6
JW
142
143extern void kdb_save_flags(void);
144extern void kdb_restore_flags(void);
145
146#define KDB_FLAG(flag) (kdb_flags & KDB_FLAG_##flag)
147#define KDB_FLAG_SET(flag) ((void)(kdb_flags |= KDB_FLAG_##flag))
148#define KDB_FLAG_CLEAR(flag) ((void)(kdb_flags &= ~KDB_FLAG_##flag))
149
150/*
151 * External entry point for the kernel debugger. The pt_regs
152 * at the time of entry are supplied along with the reason for
153 * entry to the kernel debugger.
154 */
155
156typedef enum {
157 KDB_REASON_ENTER = 1, /* KDB_ENTER() trap/fault - regs valid */
158 KDB_REASON_ENTER_SLAVE, /* KDB_ENTER_SLAVE() trap/fault - regs valid */
159 KDB_REASON_BREAK, /* Breakpoint inst. - regs valid */
160 KDB_REASON_DEBUG, /* Debug Fault - regs valid */
161 KDB_REASON_OOPS, /* Kernel Oops - regs valid */
162 KDB_REASON_SWITCH, /* CPU switch - regs valid*/
163 KDB_REASON_KEYBOARD, /* Keyboard entry - regs valid */
164 KDB_REASON_NMI, /* Non-maskable interrupt; regs valid */
165 KDB_REASON_RECURSE, /* Recursive entry to kdb;
166 * regs probably valid */
167 KDB_REASON_SSTEP, /* Single Step trap. - regs valid */
8daaa5f8 168 KDB_REASON_SYSTEM_NMI, /* In NMI due to SYSTEM cmd; regs valid */
5d5314d6
JW
169} kdb_reason_t;
170
f7d4ca8b
DT
171enum kdb_msgsrc {
172 KDB_MSGSRC_INTERNAL, /* direct call to kdb_printf() */
173 KDB_MSGSRC_PRINTK, /* trapped from printk() */
174};
175
d37d39ae 176extern int kdb_trap_printk;
34aaff40 177extern int kdb_printf_cpu;
f7d4ca8b
DT
178extern __printf(2, 0) int vkdb_printf(enum kdb_msgsrc src, const char *fmt,
179 va_list args);
b9075fa9
JP
180extern __printf(1, 2) int kdb_printf(const char *, ...);
181typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
5d5314d6
JW
182
183extern void kdb_init(int level);
184
185/* Access to kdb specific polling devices */
186typedef int (*get_char_func)(void);
187extern get_char_func kdb_poll_funcs[];
188extern int kdb_get_kbd_char(void);
189
190static inline
191int kdb_process_cpu(const struct task_struct *p)
192{
e558af65 193 unsigned int cpu = task_cpu(p);
5d5314d6
JW
194 if (cpu > num_possible_cpus())
195 cpu = 0;
196 return cpu;
197}
198
91b152aa
JW
199#ifdef CONFIG_KALLSYMS
200extern const char *kdb_walk_kallsyms(loff_t *pos);
201#else /* ! CONFIG_KALLSYMS */
202static inline const char *kdb_walk_kallsyms(loff_t *pos)
203{
204 return NULL;
205}
206#endif /* ! CONFIG_KALLSYMS */
5d5314d6 207
f7030bbc 208/* Dynamic kdb shell command registration */
c25abcd6
SG
209extern int kdb_register(kdbtab_t *cmd);
210extern void kdb_unregister(kdbtab_t *cmd);
5d5314d6 211#else /* ! CONFIG_KGDB_KDB */
729043e8
AV
212static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
213static inline void kdb_init(int level) {}
c25abcd6
SG
214static inline int kdb_register(kdbtab_t *cmd) { return 0; }
215static inline void kdb_unregister(kdbtab_t *cmd) {}
5d5314d6
JW
216#endif /* CONFIG_KGDB_KDB */
217enum {
218 KDB_NOT_INITIALIZED,
219 KDB_INIT_EARLY,
220 KDB_INIT_FULL,
221};
81d44507
JW
222
223extern int kdbgetintenv(const char *, int *);
224extern int kdb_set(int, const char **);
f64205a4 225int kdb_lsmod(int argc, const char **argv);
81d44507 226
5d5314d6 227#endif /* !_KDB_H */