aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial/kgdboc.c
diff options
context:
space:
mode:
authorJason Wessel <jason.wessel@windriver.com>2008-04-17 14:05:37 -0400
committerIngo Molnar <mingo@elte.hu>2008-04-17 14:05:37 -0400
commitf2d937f3bf00665ccf048b3b6616ef95859b0945 (patch)
tree6136ded0706be0d39a09a0a912e8f79a4ab63322 /drivers/serial/kgdboc.c
parentdc7d552705215ac50a0617fcf51bb9c736255b8e (diff)
consoles: polling support, kgdboc
polled console handling support, to access a console in an irq-less way while in debug or irq context. absolutely zero impact as long as CONFIG_CONSOLE_POLL is disabled. (which is the default) [ jan.kiszka@siemens.com: lots of cleanups ] [ mingo@elte.hu: redesign, splitups, cleanups. ] Signed-off-by: Jason Wessel <jason.wessel@windriver.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Jan Kiszka <jan.kiszka@web.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/serial/kgdboc.c')
-rw-r--r--drivers/serial/kgdboc.c163
1 files changed, 163 insertions, 0 deletions
diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c
new file mode 100644
index 000000000000..341830791608
--- /dev/null
+++ b/drivers/serial/kgdboc.c
@@ -0,0 +1,163 @@
1/*
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.
5 *
6 * Maintainer: Jason Wessel <jason.wessel@windriver.com>
7 *
8 * 2007-2008 (c) Jason Wessel - Wind River Systems, Inc.
9 *
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.
13 */
14#include <linux/kernel.h>
15#include <linux/ctype.h>
16#include <linux/kgdb.h>
17#include <linux/tty.h>
18
19#define MAX_CONFIG_LEN 40
20
21static struct kgdb_io kgdboc_io_ops;
22
23/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
24static int configured = -1;
25
26static char config[MAX_CONFIG_LEN];
27static struct kparam_string kps = {
28 .string = config,
29 .maxlen = MAX_CONFIG_LEN,
30};
31
32static struct tty_driver *kgdb_tty_driver;
33static int kgdb_tty_line;
34
35static int kgdboc_option_setup(char *opt)
36{
37 if (strlen(opt) > MAX_CONFIG_LEN) {
38 printk(KERN_ERR "kgdboc: config string too long\n");
39 return -ENOSPC;
40 }
41 strcpy(config, opt);
42
43 return 0;
44}
45
46__setup("kgdboc=", kgdboc_option_setup);
47
48static int configure_kgdboc(void)
49{
50 struct tty_driver *p;
51 int tty_line = 0;
52 int err;
53
54 err = kgdboc_option_setup(config);
55 if (err || !strlen(config) || isspace(config[0]))
56 goto noconfig;
57
58 err = -ENODEV;
59
60 p = tty_find_polling_driver(config, &tty_line);
61 if (!p)
62 goto noconfig;
63
64 kgdb_tty_driver = p;
65 kgdb_tty_line = tty_line;
66
67 err = kgdb_register_io_module(&kgdboc_io_ops);
68 if (err)
69 goto noconfig;
70
71 configured = 1;
72
73 return 0;
74
75noconfig:
76 config[0] = 0;
77 configured = 0;
78
79 return err;
80}
81
82static int __init init_kgdboc(void)
83{
84 /* Already configured? */
85 if (configured == 1)
86 return 0;
87
88 return configure_kgdboc();
89}
90
91static void cleanup_kgdboc(void)
92{
93 if (configured == 1)
94 kgdb_unregister_io_module(&kgdboc_io_ops);
95}
96
97static int kgdboc_get_char(void)
98{
99 return kgdb_tty_driver->poll_get_char(kgdb_tty_driver, kgdb_tty_line);
100}
101
102static void kgdboc_put_char(u8 chr)
103{
104 kgdb_tty_driver->poll_put_char(kgdb_tty_driver, kgdb_tty_line, chr);
105}
106
107static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
108{
109 if (strlen(kmessage) >= MAX_CONFIG_LEN) {
110 printk(KERN_ERR "kgdboc: config string too long\n");
111 return -ENOSPC;
112 }
113
114 /* Only copy in the string if the init function has not run yet */
115 if (configured < 0) {
116 strcpy(config, kmessage);
117 return 0;
118 }
119
120 if (kgdb_connected) {
121 printk(KERN_ERR
122 "kgdboc: Cannot reconfigure while KGDB is connected.\n");
123
124 return -EBUSY;
125 }
126
127 strcpy(config, kmessage);
128
129 if (configured == 1)
130 cleanup_kgdboc();
131
132 /* Go and configure with the new params. */
133 return configure_kgdboc();
134}
135
136static void kgdboc_pre_exp_handler(void)
137{
138 /* Increment the module count when the debugger is active */
139 if (!kgdb_connected)
140 try_module_get(THIS_MODULE);
141}
142
143static void kgdboc_post_exp_handler(void)
144{
145 /* decrement the module count when the debugger detaches */
146 if (!kgdb_connected)
147 module_put(THIS_MODULE);
148}
149
150static struct kgdb_io kgdboc_io_ops = {
151 .name = "kgdboc",
152 .read_char = kgdboc_get_char,
153 .write_char = kgdboc_put_char,
154 .pre_exception = kgdboc_pre_exp_handler,
155 .post_exception = kgdboc_post_exp_handler,
156};
157
158module_init(init_kgdboc);
159module_exit(cleanup_kgdboc);
160module_param_call(kgdboc, param_set_kgdboc_var, param_get_string, &kps, 0644);
161MODULE_PARM_DESC(kgdboc, "<serial_device>[,baud]");
162MODULE_DESCRIPTION("KGDB Console TTY Driver");
163MODULE_LICENSE("GPL");