| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 1 | /* | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL | 
|  | 4 | */ | 
|  | 5 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/slab.h> | 
|  | 7 | #include <linux/tty.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/tty_flip.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include "chan_kern.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "os.h" | 
|  | 11 |  | 
| Paolo 'Blaisorblade' Giarrusso | fac97ae | 2005-09-22 21:44:22 -0700 | [diff] [blame] | 12 | #ifdef CONFIG_NOCONFIG_CHAN | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 13 | static void *not_configged_init(char *str, int device, | 
|  | 14 | const struct chan_opts *opts) | 
| Paolo 'Blaisorblade' Giarrusso | fac97ae | 2005-09-22 21:44:22 -0700 | [diff] [blame] | 15 | { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 16 | printk(KERN_ERR "Using a channel type which is configured out of " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | "UML\n"); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 18 | return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | } | 
|  | 20 |  | 
|  | 21 | static int not_configged_open(int input, int output, int primary, void *data, | 
|  | 22 | char **dev_out) | 
|  | 23 | { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 24 | printk(KERN_ERR "Using a channel type which is configured out of " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | "UML\n"); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 26 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | } | 
|  | 28 |  | 
|  | 29 | static void not_configged_close(int fd, void *data) | 
|  | 30 | { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 31 | printk(KERN_ERR "Using a channel type which is configured out of " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | "UML\n"); | 
|  | 33 | } | 
|  | 34 |  | 
|  | 35 | static int not_configged_read(int fd, char *c_out, void *data) | 
|  | 36 | { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 37 | printk(KERN_ERR "Using a channel type which is configured out of " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | "UML\n"); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 39 | return -EIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } | 
|  | 41 |  | 
|  | 42 | static int not_configged_write(int fd, const char *buf, int len, void *data) | 
|  | 43 | { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 44 | printk(KERN_ERR "Using a channel type which is configured out of " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | "UML\n"); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 46 | return -EIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } | 
|  | 48 |  | 
| Paolo 'Blaisorblade' Giarrusso | 55c033c | 2005-11-13 16:07:11 -0800 | [diff] [blame] | 49 | static int not_configged_console_write(int fd, const char *buf, int len) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 51 | printk(KERN_ERR "Using a channel type which is configured out of " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | "UML\n"); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 53 | return -EIO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } | 
|  | 55 |  | 
|  | 56 | static int not_configged_window_size(int fd, void *data, unsigned short *rows, | 
|  | 57 | unsigned short *cols) | 
|  | 58 | { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 59 | printk(KERN_ERR "Using a channel type which is configured out of " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | "UML\n"); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 61 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } | 
|  | 63 |  | 
|  | 64 | static void not_configged_free(void *data) | 
|  | 65 | { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 66 | printk(KERN_ERR "Using a channel type which is configured out of " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | "UML\n"); | 
|  | 68 | } | 
|  | 69 |  | 
| Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 70 | static const struct chan_ops not_configged_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | .init		= not_configged_init, | 
|  | 72 | .open		= not_configged_open, | 
|  | 73 | .close		= not_configged_close, | 
|  | 74 | .read		= not_configged_read, | 
|  | 75 | .write		= not_configged_write, | 
|  | 76 | .console_write	= not_configged_console_write, | 
|  | 77 | .window_size	= not_configged_window_size, | 
|  | 78 | .free		= not_configged_free, | 
|  | 79 | .winch		= 0, | 
|  | 80 | }; | 
|  | 81 | #endif /* CONFIG_NOCONFIG_CHAN */ | 
|  | 82 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | static void tty_receive_char(struct tty_struct *tty, char ch) | 
|  | 84 | { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 85 | if (tty == NULL) | 
|  | 86 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 88 | if (I_IXON(tty) && !I_IXOFF(tty) && !tty->raw) { | 
|  | 89 | if (ch == STOP_CHAR(tty)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | stop_tty(tty); | 
|  | 91 | return; | 
|  | 92 | } | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 93 | else if (ch == START_CHAR(tty)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | start_tty(tty); | 
|  | 95 | return; | 
|  | 96 | } | 
|  | 97 | } | 
|  | 98 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | tty_insert_flip_char(tty, ch, TTY_NORMAL); | 
|  | 100 | } | 
|  | 101 |  | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 102 | static int open_one_chan(struct chan *chan) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { | 
| Jeff Dike | 6676ae6 | 2007-07-31 00:37:44 -0700 | [diff] [blame] | 104 | int fd, err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 106 | if (chan->opened) | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 107 | return 0; | 
|  | 108 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 109 | if (chan->ops->open == NULL) | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 110 | fd = 0; | 
|  | 111 | else fd = (*chan->ops->open)(chan->input, chan->output, chan->primary, | 
|  | 112 | chan->data, &chan->dev); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 113 | if (fd < 0) | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 114 | return fd; | 
| Jeff Dike | 6676ae6 | 2007-07-31 00:37:44 -0700 | [diff] [blame] | 115 |  | 
|  | 116 | err = os_set_fd_block(fd, 0); | 
|  | 117 | if (err) { | 
|  | 118 | (*chan->ops->close)(fd, chan->data); | 
|  | 119 | return err; | 
|  | 120 | } | 
|  | 121 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | chan->fd = fd; | 
|  | 123 |  | 
|  | 124 | chan->opened = 1; | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 125 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } | 
|  | 127 |  | 
| WANG Cong | 3af7cb7 | 2008-04-28 02:13:55 -0700 | [diff] [blame] | 128 | static int open_chan(struct list_head *chans) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { | 
|  | 130 | struct list_head *ele; | 
|  | 131 | struct chan *chan; | 
|  | 132 | int ret, err = 0; | 
|  | 133 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 134 | list_for_each(ele, chans) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | chan = list_entry(ele, struct chan, list); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 136 | ret = open_one_chan(chan); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 137 | if (chan->primary) | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 138 | err = ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 140 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } | 
|  | 142 |  | 
|  | 143 | void chan_enable_winch(struct list_head *chans, struct tty_struct *tty) | 
|  | 144 | { | 
|  | 145 | struct list_head *ele; | 
|  | 146 | struct chan *chan; | 
|  | 147 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 148 | list_for_each(ele, chans) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | chan = list_entry(ele, struct chan, list); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 150 | if (chan->primary && chan->output && chan->ops->winch) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | register_winch(chan->fd, tty); | 
|  | 152 | return; | 
|  | 153 | } | 
|  | 154 | } | 
|  | 155 | } | 
|  | 156 |  | 
| Jeff Dike | d14ad81 | 2007-07-15 23:38:54 -0700 | [diff] [blame] | 157 | int enable_chan(struct line *line) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { | 
|  | 159 | struct list_head *ele; | 
|  | 160 | struct chan *chan; | 
| Jeff Dike | d14ad81 | 2007-07-15 23:38:54 -0700 | [diff] [blame] | 161 | int err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 163 | list_for_each(ele, &line->chan_list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | chan = list_entry(ele, struct chan, list); | 
| Jeff Dike | d14ad81 | 2007-07-15 23:38:54 -0700 | [diff] [blame] | 165 | err = open_one_chan(chan); | 
|  | 166 | if (err) { | 
|  | 167 | if (chan->primary) | 
|  | 168 | goto out_close; | 
|  | 169 |  | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 170 | continue; | 
| Jeff Dike | d14ad81 | 2007-07-15 23:38:54 -0700 | [diff] [blame] | 171 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 173 | if (chan->enabled) | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 174 | continue; | 
| Jeff Dike | d14ad81 | 2007-07-15 23:38:54 -0700 | [diff] [blame] | 175 | err = line_setup_irq(chan->fd, chan->input, chan->output, line, | 
|  | 176 | chan); | 
|  | 177 | if (err) | 
|  | 178 | goto out_close; | 
|  | 179 |  | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 180 | chan->enabled = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | } | 
| Jeff Dike | d14ad81 | 2007-07-15 23:38:54 -0700 | [diff] [blame] | 182 |  | 
|  | 183 | return 0; | 
|  | 184 |  | 
|  | 185 | out_close: | 
|  | 186 | close_chan(&line->chan_list, 0); | 
|  | 187 | return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
| Jeff Dike | 190c3e4 | 2007-02-10 01:43:55 -0800 | [diff] [blame] | 190 | /* Items are added in IRQ context, when free_irq can't be called, and | 
|  | 191 | * removed in process context, when it can. | 
|  | 192 | * This handles interrupt sources which disappear, and which need to | 
|  | 193 | * be permanently disabled.  This is discovered in IRQ context, but | 
|  | 194 | * the freeing of the IRQ must be done later. | 
|  | 195 | */ | 
|  | 196 | static DEFINE_SPINLOCK(irqs_to_free_lock); | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 197 | static LIST_HEAD(irqs_to_free); | 
|  | 198 |  | 
|  | 199 | void free_irqs(void) | 
|  | 200 | { | 
|  | 201 | struct chan *chan; | 
| Jeff Dike | 190c3e4 | 2007-02-10 01:43:55 -0800 | [diff] [blame] | 202 | LIST_HEAD(list); | 
|  | 203 | struct list_head *ele; | 
| Jeff Dike | 3076212 | 2007-03-29 01:20:30 -0700 | [diff] [blame] | 204 | unsigned long flags; | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 205 |  | 
| Jeff Dike | 3076212 | 2007-03-29 01:20:30 -0700 | [diff] [blame] | 206 | spin_lock_irqsave(&irqs_to_free_lock, flags); | 
| Jeff Dike | 190c3e4 | 2007-02-10 01:43:55 -0800 | [diff] [blame] | 207 | list_splice_init(&irqs_to_free, &list); | 
| Jeff Dike | 3076212 | 2007-03-29 01:20:30 -0700 | [diff] [blame] | 208 | spin_unlock_irqrestore(&irqs_to_free_lock, flags); | 
| Jeff Dike | 190c3e4 | 2007-02-10 01:43:55 -0800 | [diff] [blame] | 209 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 210 | list_for_each(ele, &list) { | 
| Jeff Dike | 190c3e4 | 2007-02-10 01:43:55 -0800 | [diff] [blame] | 211 | chan = list_entry(ele, struct chan, free_list); | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 212 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 213 | if (chan->input) | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 214 | free_irq(chan->line->driver->read_irq, chan); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 215 | if (chan->output) | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 216 | free_irq(chan->line->driver->write_irq, chan); | 
|  | 217 | chan->enabled = 0; | 
|  | 218 | } | 
|  | 219 | } | 
|  | 220 |  | 
|  | 221 | static void close_one_chan(struct chan *chan, int delay_free_irq) | 
|  | 222 | { | 
| Jeff Dike | 3076212 | 2007-03-29 01:20:30 -0700 | [diff] [blame] | 223 | unsigned long flags; | 
|  | 224 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 225 | if (!chan->opened) | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 226 | return; | 
|  | 227 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 228 | if (delay_free_irq) { | 
| Jeff Dike | 3076212 | 2007-03-29 01:20:30 -0700 | [diff] [blame] | 229 | spin_lock_irqsave(&irqs_to_free_lock, flags); | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 230 | list_add(&chan->free_list, &irqs_to_free); | 
| Jeff Dike | 3076212 | 2007-03-29 01:20:30 -0700 | [diff] [blame] | 231 | spin_unlock_irqrestore(&irqs_to_free_lock, flags); | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 232 | } | 
|  | 233 | else { | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 234 | if (chan->input) | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 235 | free_irq(chan->line->driver->read_irq, chan); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 236 | if (chan->output) | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 237 | free_irq(chan->line->driver->write_irq, chan); | 
|  | 238 | chan->enabled = 0; | 
|  | 239 | } | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 240 | if (chan->ops->close != NULL) | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 241 | (*chan->ops->close)(chan->fd, chan->data); | 
|  | 242 |  | 
|  | 243 | chan->opened = 0; | 
|  | 244 | chan->fd = -1; | 
|  | 245 | } | 
|  | 246 |  | 
|  | 247 | void close_chan(struct list_head *chans, int delay_free_irq) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { | 
|  | 249 | struct chan *chan; | 
|  | 250 |  | 
|  | 251 | /* Close in reverse order as open in case more than one of them | 
|  | 252 | * refers to the same device and they save and restore that device's | 
|  | 253 | * state.  Then, the first one opened will have the original state, | 
|  | 254 | * so it must be the last closed. | 
|  | 255 | */ | 
|  | 256 | list_for_each_entry_reverse(chan, chans, list) { | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 257 | close_one_chan(chan, delay_free_irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } | 
|  | 259 | } | 
|  | 260 |  | 
| Jeff Dike | e4dcee8 | 2006-01-06 00:18:58 -0800 | [diff] [blame] | 261 | void deactivate_chan(struct list_head *chans, int irq) | 
|  | 262 | { | 
|  | 263 | struct list_head *ele; | 
|  | 264 |  | 
|  | 265 | struct chan *chan; | 
|  | 266 | list_for_each(ele, chans) { | 
|  | 267 | chan = list_entry(ele, struct chan, list); | 
|  | 268 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 269 | if (chan->enabled && chan->input) | 
| Jeff Dike | e4dcee8 | 2006-01-06 00:18:58 -0800 | [diff] [blame] | 270 | deactivate_fd(chan->fd, irq); | 
|  | 271 | } | 
|  | 272 | } | 
|  | 273 |  | 
|  | 274 | void reactivate_chan(struct list_head *chans, int irq) | 
|  | 275 | { | 
|  | 276 | struct list_head *ele; | 
|  | 277 | struct chan *chan; | 
|  | 278 |  | 
|  | 279 | list_for_each(ele, chans) { | 
|  | 280 | chan = list_entry(ele, struct chan, list); | 
|  | 281 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 282 | if (chan->enabled && chan->input) | 
| Jeff Dike | e4dcee8 | 2006-01-06 00:18:58 -0800 | [diff] [blame] | 283 | reactivate_fd(chan->fd, irq); | 
|  | 284 | } | 
|  | 285 | } | 
|  | 286 |  | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 287 | int write_chan(struct list_head *chans, const char *buf, int len, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | int write_irq) | 
|  | 289 | { | 
|  | 290 | struct list_head *ele; | 
|  | 291 | struct chan *chan = NULL; | 
|  | 292 | int n, ret = 0; | 
|  | 293 |  | 
| Jeff Dike | c59dbca | 2007-10-16 01:26:42 -0700 | [diff] [blame] | 294 | if (len == 0) | 
|  | 295 | return 0; | 
|  | 296 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | list_for_each(ele, chans) { | 
|  | 298 | chan = list_entry(ele, struct chan, list); | 
|  | 299 | if (!chan->output || (chan->ops->write == NULL)) | 
|  | 300 | continue; | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 301 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | n = chan->ops->write(chan->fd, buf, len, chan->data); | 
|  | 303 | if (chan->primary) { | 
|  | 304 | ret = n; | 
|  | 305 | if ((ret == -EAGAIN) || ((ret >= 0) && (ret < len))) | 
|  | 306 | reactivate_fd(chan->fd, write_irq); | 
|  | 307 | } | 
|  | 308 | } | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 309 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } | 
|  | 311 |  | 
|  | 312 | int console_write_chan(struct list_head *chans, const char *buf, int len) | 
|  | 313 | { | 
|  | 314 | struct list_head *ele; | 
|  | 315 | struct chan *chan; | 
|  | 316 | int n, ret = 0; | 
|  | 317 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 318 | list_for_each(ele, chans) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | chan = list_entry(ele, struct chan, list); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 320 | if (!chan->output || (chan->ops->console_write == NULL)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | continue; | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 322 |  | 
| Paolo 'Blaisorblade' Giarrusso | 55c033c | 2005-11-13 16:07:11 -0800 | [diff] [blame] | 323 | n = chan->ops->console_write(chan->fd, buf, len); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 324 | if (chan->primary) | 
|  | 325 | ret = n; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 327 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } | 
|  | 329 |  | 
| Jeff Dike | a52f362 | 2007-02-10 01:44:06 -0800 | [diff] [blame] | 330 | int console_open_chan(struct line *line, struct console *co) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { | 
| Jeff Dike | 1f80171 | 2006-01-06 00:18:55 -0800 | [diff] [blame] | 332 | int err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 |  | 
| Jeff Dike | 1f80171 | 2006-01-06 00:18:55 -0800 | [diff] [blame] | 334 | err = open_chan(&line->chan_list); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 335 | if (err) | 
| Jeff Dike | 1f80171 | 2006-01-06 00:18:55 -0800 | [diff] [blame] | 336 | return err; | 
|  | 337 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 338 | printk(KERN_INFO "Console initialized on /dev/%s%d\n", co->name, | 
|  | 339 | co->index); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | return 0; | 
|  | 341 | } | 
|  | 342 |  | 
|  | 343 | int chan_window_size(struct list_head *chans, unsigned short *rows_out, | 
|  | 344 | unsigned short *cols_out) | 
|  | 345 | { | 
|  | 346 | struct list_head *ele; | 
|  | 347 | struct chan *chan; | 
|  | 348 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 349 | list_for_each(ele, chans) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | chan = list_entry(ele, struct chan, list); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 351 | if (chan->primary) { | 
|  | 352 | if (chan->ops->window_size == NULL) | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 353 | return 0; | 
|  | 354 | return chan->ops->window_size(chan->fd, chan->data, | 
|  | 355 | rows_out, cols_out); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } | 
|  | 357 | } | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 358 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } | 
|  | 360 |  | 
| Paolo 'Blaisorblade' Giarrusso | 42947cb | 2006-02-01 03:06:29 -0800 | [diff] [blame] | 361 | static void free_one_chan(struct chan *chan, int delay_free_irq) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { | 
|  | 363 | list_del(&chan->list); | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 364 |  | 
|  | 365 | close_one_chan(chan, delay_free_irq); | 
|  | 366 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 367 | if (chan->ops->free != NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | (*chan->ops->free)(chan->data); | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 369 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 370 | if (chan->primary && chan->output) | 
|  | 371 | ignore_sigio_fd(chan->fd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | kfree(chan); | 
|  | 373 | } | 
|  | 374 |  | 
| Paolo 'Blaisorblade' Giarrusso | 42947cb | 2006-02-01 03:06:29 -0800 | [diff] [blame] | 375 | static void free_chan(struct list_head *chans, int delay_free_irq) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { | 
|  | 377 | struct list_head *ele, *next; | 
|  | 378 | struct chan *chan; | 
|  | 379 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 380 | list_for_each_safe(ele, next, chans) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | chan = list_entry(ele, struct chan, list); | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 382 | free_one_chan(chan, delay_free_irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } | 
|  | 384 | } | 
|  | 385 |  | 
|  | 386 | static int one_chan_config_string(struct chan *chan, char *str, int size, | 
|  | 387 | char **error_out) | 
|  | 388 | { | 
|  | 389 | int n = 0; | 
|  | 390 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 391 | if (chan == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | CONFIG_CHUNK(str, size, n, "none", 1); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 393 | return n; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } | 
|  | 395 |  | 
|  | 396 | CONFIG_CHUNK(str, size, n, chan->ops->type, 0); | 
|  | 397 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 398 | if (chan->dev == NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | CONFIG_CHUNK(str, size, n, "", 1); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 400 | return n; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } | 
|  | 402 |  | 
|  | 403 | CONFIG_CHUNK(str, size, n, ":", 0); | 
|  | 404 | CONFIG_CHUNK(str, size, n, chan->dev, 0); | 
|  | 405 |  | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 406 | return n; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } | 
|  | 408 |  | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 409 | static int chan_pair_config_string(struct chan *in, struct chan *out, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | char *str, int size, char **error_out) | 
|  | 411 | { | 
|  | 412 | int n; | 
|  | 413 |  | 
|  | 414 | n = one_chan_config_string(in, str, size, error_out); | 
|  | 415 | str += n; | 
|  | 416 | size -= n; | 
|  | 417 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 418 | if (in == out) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | CONFIG_CHUNK(str, size, n, "", 1); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 420 | return n; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } | 
|  | 422 |  | 
|  | 423 | CONFIG_CHUNK(str, size, n, ",", 1); | 
|  | 424 | n = one_chan_config_string(out, str, size, error_out); | 
|  | 425 | str += n; | 
|  | 426 | size -= n; | 
|  | 427 | CONFIG_CHUNK(str, size, n, "", 1); | 
|  | 428 |  | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 429 | return n; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } | 
|  | 431 |  | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 432 | int chan_config_string(struct list_head *chans, char *str, int size, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | char **error_out) | 
|  | 434 | { | 
|  | 435 | struct list_head *ele; | 
|  | 436 | struct chan *chan, *in = NULL, *out = NULL; | 
|  | 437 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 438 | list_for_each(ele, chans) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | chan = list_entry(ele, struct chan, list); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 440 | if (!chan->primary) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | continue; | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 442 | if (chan->input) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | in = chan; | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 444 | if (chan->output) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | out = chan; | 
|  | 446 | } | 
|  | 447 |  | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 448 | return chan_pair_config_string(in, out, str, size, error_out); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | } | 
|  | 450 |  | 
|  | 451 | struct chan_type { | 
|  | 452 | char *key; | 
| Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 453 | const struct chan_ops *ops; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | }; | 
|  | 455 |  | 
| Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 456 | static const struct chan_type chan_table[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | { "fd", &fd_ops }, | 
|  | 458 |  | 
|  | 459 | #ifdef CONFIG_NULL_CHAN | 
|  | 460 | { "null", &null_ops }, | 
|  | 461 | #else | 
|  | 462 | { "null", ¬_configged_ops }, | 
|  | 463 | #endif | 
|  | 464 |  | 
|  | 465 | #ifdef CONFIG_PORT_CHAN | 
|  | 466 | { "port", &port_ops }, | 
|  | 467 | #else | 
|  | 468 | { "port", ¬_configged_ops }, | 
|  | 469 | #endif | 
|  | 470 |  | 
|  | 471 | #ifdef CONFIG_PTY_CHAN | 
|  | 472 | { "pty", &pty_ops }, | 
|  | 473 | { "pts", &pts_ops }, | 
|  | 474 | #else | 
|  | 475 | { "pty", ¬_configged_ops }, | 
|  | 476 | { "pts", ¬_configged_ops }, | 
|  | 477 | #endif | 
|  | 478 |  | 
|  | 479 | #ifdef CONFIG_TTY_CHAN | 
|  | 480 | { "tty", &tty_ops }, | 
|  | 481 | #else | 
|  | 482 | { "tty", ¬_configged_ops }, | 
|  | 483 | #endif | 
|  | 484 |  | 
|  | 485 | #ifdef CONFIG_XTERM_CHAN | 
|  | 486 | { "xterm", &xterm_ops }, | 
|  | 487 | #else | 
|  | 488 | { "xterm", ¬_configged_ops }, | 
|  | 489 | #endif | 
|  | 490 | }; | 
|  | 491 |  | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 492 | static struct chan *parse_chan(struct line *line, char *str, int device, | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 493 | const struct chan_opts *opts, char **error_out) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | { | 
| Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 495 | const struct chan_type *entry; | 
|  | 496 | const struct chan_ops *ops; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | struct chan *chan; | 
|  | 498 | void *data; | 
|  | 499 | int i; | 
|  | 500 |  | 
|  | 501 | ops = NULL; | 
|  | 502 | data = NULL; | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 503 | for(i = 0; i < ARRAY_SIZE(chan_table); i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | entry = &chan_table[i]; | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 505 | if (!strncmp(str, entry->key, strlen(entry->key))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | ops = entry->ops; | 
|  | 507 | str += strlen(entry->key); | 
|  | 508 | break; | 
|  | 509 | } | 
|  | 510 | } | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 511 | if (ops == NULL) { | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 512 | *error_out = "No match for configured backends"; | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 513 | return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 515 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | data = (*ops->init)(str, device, opts); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 517 | if (data == NULL) { | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 518 | *error_out = "Configuration failed"; | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 519 | return NULL; | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 520 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 |  | 
| Paolo 'Blaisorblade' Giarrusso | 79ae2cb | 2005-09-22 21:44:21 -0700 | [diff] [blame] | 522 | chan = kmalloc(sizeof(*chan), GFP_ATOMIC); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 523 | if (chan == NULL) { | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 524 | *error_out = "Memory allocation failed"; | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 525 | return NULL; | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 526 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | *chan = ((struct chan) { .list	 	= LIST_HEAD_INIT(chan->list), | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 528 | .free_list 	= | 
|  | 529 | LIST_HEAD_INIT(chan->free_list), | 
|  | 530 | .line		= line, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | .primary	= 1, | 
|  | 532 | .input		= 0, | 
|  | 533 | .output 	= 0, | 
|  | 534 | .opened  	= 0, | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 535 | .enabled  	= 0, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | .fd 		= -1, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | .ops 		= ops, | 
|  | 538 | .data 		= data }); | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 539 | return chan; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } | 
|  | 541 |  | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 542 | int parse_chan_pair(char *str, struct line *line, int device, | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 543 | const struct chan_opts *opts, char **error_out) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | { | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 545 | struct list_head *chans = &line->chan_list; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | struct chan *new, *chan; | 
|  | 547 | char *in, *out; | 
|  | 548 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 549 | if (!list_empty(chans)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | chan = list_entry(chans->next, struct chan, list); | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 551 | free_chan(chans, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | INIT_LIST_HEAD(chans); | 
|  | 553 | } | 
|  | 554 |  | 
|  | 555 | out = strchr(str, ','); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 556 | if (out != NULL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | in = str; | 
|  | 558 | *out = '\0'; | 
|  | 559 | out++; | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 560 | new = parse_chan(line, in, device, opts, error_out); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 561 | if (new == NULL) | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 562 | return -1; | 
|  | 563 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | new->input = 1; | 
|  | 565 | list_add(&new->list, chans); | 
|  | 566 |  | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 567 | new = parse_chan(line, out, device, opts, error_out); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 568 | if (new == NULL) | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 569 | return -1; | 
|  | 570 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | list_add(&new->list, chans); | 
|  | 572 | new->output = 1; | 
|  | 573 | } | 
|  | 574 | else { | 
| Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 575 | new = parse_chan(line, str, device, opts, error_out); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 576 | if (new == NULL) | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 577 | return -1; | 
|  | 578 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | list_add(&new->list, chans); | 
|  | 580 | new->input = 1; | 
|  | 581 | new->output = 1; | 
|  | 582 | } | 
| Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 583 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } | 
|  | 585 |  | 
| David Howells | 6d5aefb | 2006-12-05 19:36:26 +0000 | [diff] [blame] | 586 | void chan_interrupt(struct list_head *chans, struct delayed_work *task, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | struct tty_struct *tty, int irq) | 
|  | 588 | { | 
|  | 589 | struct list_head *ele, *next; | 
|  | 590 | struct chan *chan; | 
|  | 591 | int err; | 
|  | 592 | char c; | 
|  | 593 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 594 | list_for_each_safe(ele, next, chans) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | chan = list_entry(ele, struct chan, list); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 596 | if (!chan->input || (chan->ops->read == NULL)) | 
|  | 597 | continue; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | do { | 
| Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 599 | if (tty && !tty_buffer_request_room(tty, 1)) { | 
| Jeff Dike | 9159c9d | 2006-01-06 00:18:58 -0800 | [diff] [blame] | 600 | schedule_delayed_work(task, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | goto out; | 
|  | 602 | } | 
|  | 603 | err = chan->ops->read(chan->fd, &c, chan->data); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 604 | if (err > 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | tty_receive_char(tty, c); | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 606 | } while (err > 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 |  | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 608 | if (err == 0) | 
|  | 609 | reactivate_fd(chan->fd, irq); | 
|  | 610 | if (err == -EIO) { | 
|  | 611 | if (chan->primary) { | 
|  | 612 | if (tty != NULL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | tty_hangup(tty); | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 614 | close_chan(chans, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | return; | 
|  | 616 | } | 
| Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 617 | else close_one_chan(chan, 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | } | 
|  | 619 | } | 
|  | 620 | out: | 
| Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 621 | if (tty) | 
|  | 622 | tty_flip_buffer_push(tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | } |