ecef6e1a599a5d3ddb560925942302876db31740
2 * Based on the same principle as kgdboe using the NETPOLL api, this
3 * driver uses a console polling api to implement a gdb serial inteface
4 * which is multiplexed on a console port.
6 * Maintainer: Jason Wessel <jason.wessel@windriver.com>
8 * 2007-2008 (c) Jason Wessel - Wind River Systems, Inc.
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
14 #include <linux/kernel.h>
15 #include <linux/ctype.h>
16 #include <linux/kgdb.h>
17 #include <linux/kdb.h>
18 #include <linux/tty.h>
20 #define MAX_CONFIG_LEN 40
22 static struct kgdb_io kgdboc_io_ops
;
24 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
25 static int configured
= -1;
27 static char config
[MAX_CONFIG_LEN
];
28 static struct kparam_string kps
= {
30 .maxlen
= MAX_CONFIG_LEN
,
33 static struct tty_driver
*kgdb_tty_driver
;
34 static int kgdb_tty_line
;
36 #ifdef CONFIG_KDB_KEYBOARD
37 static int kgdboc_register_kbd(char **cptr
)
39 if (strncmp(*cptr
, "kbd", 3) == 0) {
40 if (kdb_poll_idx
< KDB_POLL_FUNC_MAX
) {
41 kdb_poll_funcs
[kdb_poll_idx
] = kdb_get_kbd_char
;
43 if (cptr
[0][3] == ',')
52 static void kgdboc_unregister_kbd(void)
56 for (i
= 0; i
< kdb_poll_idx
; i
++) {
57 if (kdb_poll_funcs
[i
] == kdb_get_kbd_char
) {
59 kdb_poll_funcs
[i
] = kdb_poll_funcs
[kdb_poll_idx
];
60 kdb_poll_funcs
[kdb_poll_idx
] = NULL
;
65 #else /* ! CONFIG_KDB_KEYBOARD */
66 #define kgdboc_register_kbd(x) 0
67 #define kgdboc_unregister_kbd()
68 #endif /* ! CONFIG_KDB_KEYBOARD */
70 static int kgdboc_option_setup(char *opt
)
72 if (strlen(opt
) > MAX_CONFIG_LEN
) {
73 printk(KERN_ERR
"kgdboc: config string too long\n");
81 __setup("kgdboc=", kgdboc_option_setup
);
83 static void cleanup_kgdboc(void)
85 kgdboc_unregister_kbd();
87 kgdb_unregister_io_module(&kgdboc_io_ops
);
90 static int configure_kgdboc(void)
97 err
= kgdboc_option_setup(config
);
98 if (err
|| !strlen(config
) || isspace(config
[0]))
102 kgdb_tty_driver
= NULL
;
104 if (kgdboc_register_kbd(&cptr
))
107 p
= tty_find_polling_driver(cptr
, &tty_line
);
112 kgdb_tty_line
= tty_line
;
115 err
= kgdb_register_io_module(&kgdboc_io_ops
);
131 static int __init
init_kgdboc(void)
133 /* Already configured? */
137 return configure_kgdboc();
140 static int kgdboc_get_char(void)
142 if (!kgdb_tty_driver
)
144 return kgdb_tty_driver
->ops
->poll_get_char(kgdb_tty_driver
,
148 static void kgdboc_put_char(u8 chr
)
150 if (!kgdb_tty_driver
)
152 kgdb_tty_driver
->ops
->poll_put_char(kgdb_tty_driver
,
156 static int param_set_kgdboc_var(const char *kmessage
, struct kernel_param
*kp
)
158 int len
= strlen(kmessage
);
160 if (len
>= MAX_CONFIG_LEN
) {
161 printk(KERN_ERR
"kgdboc: config string too long\n");
165 /* Only copy in the string if the init function has not run yet */
166 if (configured
< 0) {
167 strcpy(config
, kmessage
);
171 if (kgdb_connected
) {
173 "kgdboc: Cannot reconfigure while KGDB is connected.\n");
178 strcpy(config
, kmessage
);
179 /* Chop out \n char as a result of echo */
180 if (config
[len
- 1] == '\n')
181 config
[len
- 1] = '\0';
186 /* Go and configure with the new params. */
187 return configure_kgdboc();
190 static void kgdboc_pre_exp_handler(void)
192 /* Increment the module count when the debugger is active */
194 try_module_get(THIS_MODULE
);
197 static void kgdboc_post_exp_handler(void)
199 /* decrement the module count when the debugger detaches */
201 module_put(THIS_MODULE
);
204 static struct kgdb_io kgdboc_io_ops
= {
206 .read_char
= kgdboc_get_char
,
207 .write_char
= kgdboc_put_char
,
208 .pre_exception
= kgdboc_pre_exp_handler
,
209 .post_exception
= kgdboc_post_exp_handler
,
212 module_init(init_kgdboc
);
213 module_exit(cleanup_kgdboc
);
214 module_param_call(kgdboc
, param_set_kgdboc_var
, param_get_string
, &kps
, 0644);
215 MODULE_PARM_DESC(kgdboc
, "<serial_device>[,baud]");
216 MODULE_DESCRIPTION("KGDB Console TTY Driver");
217 MODULE_LICENSE("GPL");
This page took 0.0349 seconds and 4 git commands to generate.