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