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