x86, mce: disable machine checks on suspend
[linux-2.6/verdex.git] / drivers / serial / kgdboc.c
blobeadc1ab6bbcead8918a19773a7db2f08d85ec0a3
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.
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/tty.h>
19 #define MAX_CONFIG_LEN 40
21 static struct kgdb_io kgdboc_io_ops;
23 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
24 static int configured = -1;
26 static char config[MAX_CONFIG_LEN];
27 static struct kparam_string kps = {
28 .string = config,
29 .maxlen = MAX_CONFIG_LEN,
32 static struct tty_driver *kgdb_tty_driver;
33 static int kgdb_tty_line;
35 static int kgdboc_option_setup(char *opt)
37 if (strlen(opt) > MAX_CONFIG_LEN) {
38 printk(KERN_ERR "kgdboc: config string too long\n");
39 return -ENOSPC;
41 strcpy(config, opt);
43 return 0;
46 __setup("kgdboc=", kgdboc_option_setup);
48 static int configure_kgdboc(void)
50 struct tty_driver *p;
51 int tty_line = 0;
52 int err;
54 err = kgdboc_option_setup(config);
55 if (err || !strlen(config) || isspace(config[0]))
56 goto noconfig;
58 err = -ENODEV;
60 p = tty_find_polling_driver(config, &tty_line);
61 if (!p)
62 goto noconfig;
64 kgdb_tty_driver = p;
65 kgdb_tty_line = tty_line;
67 err = kgdb_register_io_module(&kgdboc_io_ops);
68 if (err)
69 goto noconfig;
71 configured = 1;
73 return 0;
75 noconfig:
76 config[0] = 0;
77 configured = 0;
79 return err;
82 static int __init init_kgdboc(void)
84 /* Already configured? */
85 if (configured == 1)
86 return 0;
88 return configure_kgdboc();
91 static void cleanup_kgdboc(void)
93 if (configured == 1)
94 kgdb_unregister_io_module(&kgdboc_io_ops);
97 static int kgdboc_get_char(void)
99 return kgdb_tty_driver->ops->poll_get_char(kgdb_tty_driver,
100 kgdb_tty_line);
103 static void kgdboc_put_char(u8 chr)
105 kgdb_tty_driver->ops->poll_put_char(kgdb_tty_driver,
106 kgdb_tty_line, chr);
109 static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
111 int len = strlen(kmessage);
113 if (len >= MAX_CONFIG_LEN) {
114 printk(KERN_ERR "kgdboc: config string too long\n");
115 return -ENOSPC;
118 /* Only copy in the string if the init function has not run yet */
119 if (configured < 0) {
120 strcpy(config, kmessage);
121 return 0;
124 if (kgdb_connected) {
125 printk(KERN_ERR
126 "kgdboc: Cannot reconfigure while KGDB is connected.\n");
128 return -EBUSY;
131 strcpy(config, kmessage);
132 /* Chop out \n char as a result of echo */
133 if (config[len - 1] == '\n')
134 config[len - 1] = '\0';
136 if (configured == 1)
137 cleanup_kgdboc();
139 /* Go and configure with the new params. */
140 return configure_kgdboc();
143 static void kgdboc_pre_exp_handler(void)
145 /* Increment the module count when the debugger is active */
146 if (!kgdb_connected)
147 try_module_get(THIS_MODULE);
150 static void kgdboc_post_exp_handler(void)
152 /* decrement the module count when the debugger detaches */
153 if (!kgdb_connected)
154 module_put(THIS_MODULE);
157 static struct kgdb_io kgdboc_io_ops = {
158 .name = "kgdboc",
159 .read_char = kgdboc_get_char,
160 .write_char = kgdboc_put_char,
161 .pre_exception = kgdboc_pre_exp_handler,
162 .post_exception = kgdboc_post_exp_handler,
165 module_init(init_kgdboc);
166 module_exit(cleanup_kgdboc);
167 module_param_call(kgdboc, param_set_kgdboc_var, param_get_string, &kps, 0644);
168 MODULE_PARM_DESC(kgdboc, "<serial_device>[,baud]");
169 MODULE_DESCRIPTION("KGDB Console TTY Driver");
170 MODULE_LICENSE("GPL");