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