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