Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 1 | /* |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 2 | * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 6 | #include "linux/irqreturn.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "linux/kd.h" |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 8 | #include "linux/sched.h" |
Jan Kiszka | 7f3c1fa | 2010-04-19 17:46:23 +0900 | [diff] [blame] | 9 | #include "linux/slab.h" |
Al Viro | 510c72a3 | 2011-08-18 20:08:29 +0100 | [diff] [blame] | 10 | #include "chan.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include "irq_kern.h" |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 12 | #include "irq_user.h" |
Jeff Dike | edea138 | 2008-02-04 22:30:46 -0800 | [diff] [blame] | 13 | #include "kern_util.h" |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 14 | #include "os.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #define LINE_BUFSIZE 4096 |
| 17 | |
Al Viro | 7bea96f | 2006-10-08 22:49:34 +0100 | [diff] [blame] | 18 | static irqreturn_t line_interrupt(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | { |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 20 | struct chan *chan = data; |
| 21 | struct line *line = chan->line; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | if (line) |
Al Viro | 0fcd719 | 2011-09-10 08:17:04 -0400 | [diff] [blame^] | 24 | chan_interrupt(line, line->tty, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | return IRQ_HANDLED; |
| 26 | } |
| 27 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 28 | /* |
| 29 | * Returns the free space inside the ring buffer of this line. |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 30 | * |
Simon Arlott | b60745b | 2007-10-20 01:23:03 +0200 | [diff] [blame] | 31 | * Should be called while holding line->lock (this does not modify data). |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 32 | */ |
| 33 | static int write_room(struct line *line) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 35 | int n; |
| 36 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 37 | if (line->buffer == NULL) |
| 38 | return LINE_BUFSIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 40 | /* This is for the case where the buffer is wrapped! */ |
| 41 | n = line->head - line->tail; |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | if (n <= 0) |
Jeff Dike | acb2cf3 | 2008-02-04 22:30:42 -0800 | [diff] [blame] | 44 | n += LINE_BUFSIZE; /* The other case */ |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 45 | return n - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 48 | int line_write_room(struct tty_struct *tty) |
| 49 | { |
| 50 | struct line *line = tty->driver_data; |
| 51 | unsigned long flags; |
| 52 | int room; |
| 53 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 54 | spin_lock_irqsave(&line->lock, flags); |
| 55 | room = write_room(line); |
| 56 | spin_unlock_irqrestore(&line->lock, flags); |
| 57 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 58 | return room; |
| 59 | } |
| 60 | |
| 61 | int line_chars_in_buffer(struct tty_struct *tty) |
| 62 | { |
| 63 | struct line *line = tty->driver_data; |
| 64 | unsigned long flags; |
| 65 | int ret; |
| 66 | |
| 67 | spin_lock_irqsave(&line->lock, flags); |
Jeff Dike | acb2cf3 | 2008-02-04 22:30:42 -0800 | [diff] [blame] | 68 | /* write_room subtracts 1 for the needed NULL, so we readd it.*/ |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 69 | ret = LINE_BUFSIZE - (write_room(line) + 1); |
| 70 | spin_unlock_irqrestore(&line->lock, flags); |
| 71 | |
| 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * This copies the content of buf into the circular buffer associated with |
| 77 | * this line. |
| 78 | * The return value is the number of characters actually copied, i.e. the ones |
| 79 | * for which there was space: this function is not supposed to ever flush out |
| 80 | * the circular buffer. |
| 81 | * |
| 82 | * Must be called while holding line->lock! |
| 83 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | static int buffer_data(struct line *line, const char *buf, int len) |
| 85 | { |
| 86 | int end, room; |
| 87 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 88 | if (line->buffer == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | line->buffer = kmalloc(LINE_BUFSIZE, GFP_ATOMIC); |
| 90 | if (line->buffer == NULL) { |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 91 | printk(KERN_ERR "buffer_data - atomic allocation " |
| 92 | "failed\n"); |
| 93 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | line->head = line->buffer; |
| 96 | line->tail = line->buffer; |
| 97 | } |
| 98 | |
| 99 | room = write_room(line); |
| 100 | len = (len > room) ? room : len; |
| 101 | |
| 102 | end = line->buffer + LINE_BUFSIZE - line->tail; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 103 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 104 | if (len < end) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | memcpy(line->tail, buf, len); |
| 106 | line->tail += len; |
Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 107 | } |
| 108 | else { |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 109 | /* The circular buffer is wrapping */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | memcpy(line->tail, buf, end); |
| 111 | buf += end; |
| 112 | memcpy(line->buffer, buf, len - end); |
| 113 | line->tail = line->buffer + len - end; |
| 114 | } |
| 115 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 116 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 119 | /* |
| 120 | * Flushes the ring buffer to the output channels. That is, write_chan is |
| 121 | * called, passing it line->head as buffer, and an appropriate count. |
| 122 | * |
| 123 | * On exit, returns 1 when the buffer is empty, |
| 124 | * 0 when the buffer is not empty on exit, |
| 125 | * and -errno when an error occurred. |
| 126 | * |
| 127 | * Must be called while holding line->lock!*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | static int flush_buffer(struct line *line) |
| 129 | { |
| 130 | int n, count; |
| 131 | |
| 132 | if ((line->buffer == NULL) || (line->head == line->tail)) |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 133 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | if (line->tail < line->head) { |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 136 | /* line->buffer + LINE_BUFSIZE is the end of the buffer! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | count = line->buffer + LINE_BUFSIZE - line->head; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 138 | |
Al Viro | bed5e39 | 2011-09-08 10:49:34 -0400 | [diff] [blame] | 139 | n = write_chan(line->chan_out, line->head, count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | line->driver->write_irq); |
| 141 | if (n < 0) |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 142 | return n; |
| 143 | if (n == count) { |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 144 | /* |
| 145 | * We have flushed from ->head to buffer end, now we |
| 146 | * must flush only from the beginning to ->tail. |
| 147 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | line->head = line->buffer; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 149 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | line->head += n; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 151 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | count = line->tail - line->head; |
Al Viro | bed5e39 | 2011-09-08 10:49:34 -0400 | [diff] [blame] | 156 | n = write_chan(line->chan_out, line->head, count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | line->driver->write_irq); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 158 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 159 | if (n < 0) |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 160 | return n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | line->head += n; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 163 | return line->head == line->tail; |
| 164 | } |
| 165 | |
| 166 | void line_flush_buffer(struct tty_struct *tty) |
| 167 | { |
| 168 | struct line *line = tty->driver_data; |
| 169 | unsigned long flags; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 170 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 171 | spin_lock_irqsave(&line->lock, flags); |
Richard Weinberger | f1c93e4 | 2011-07-25 17:12:55 -0700 | [diff] [blame] | 172 | flush_buffer(line); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 173 | spin_unlock_irqrestore(&line->lock, flags); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 176 | /* |
| 177 | * We map both ->flush_chars and ->put_char (which go in pair) onto |
| 178 | * ->flush_buffer and ->write. Hope it's not that bad. |
| 179 | */ |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 180 | void line_flush_chars(struct tty_struct *tty) |
| 181 | { |
| 182 | line_flush_buffer(tty); |
| 183 | } |
| 184 | |
WANG Cong | 3168cb9 | 2008-05-06 20:42:33 -0700 | [diff] [blame] | 185 | int line_put_char(struct tty_struct *tty, unsigned char ch) |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 186 | { |
WANG Cong | 3168cb9 | 2008-05-06 20:42:33 -0700 | [diff] [blame] | 187 | return line_write(tty, &ch, sizeof(ch)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | int line_write(struct tty_struct *tty, const unsigned char *buf, int len) |
| 191 | { |
| 192 | struct line *line = tty->driver_data; |
| 193 | unsigned long flags; |
Jeff Dike | c59dbca | 2007-10-16 01:26:42 -0700 | [diff] [blame] | 194 | int n, ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 196 | spin_lock_irqsave(&line->lock, flags); |
Jeff Dike | c59dbca | 2007-10-16 01:26:42 -0700 | [diff] [blame] | 197 | if (line->head != line->tail) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | ret = buffer_data(line, buf, len); |
Jeff Dike | c59dbca | 2007-10-16 01:26:42 -0700 | [diff] [blame] | 199 | else { |
Al Viro | bed5e39 | 2011-09-08 10:49:34 -0400 | [diff] [blame] | 200 | n = write_chan(line->chan_out, buf, len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | line->driver->write_irq); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 202 | if (n < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | ret = n; |
| 204 | goto out_up; |
| 205 | } |
| 206 | |
| 207 | len -= n; |
| 208 | ret += n; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 209 | if (len > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | ret += buffer_data(line, buf + n, len); |
| 211 | } |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 212 | out_up: |
| 213 | spin_unlock_irqrestore(&line->lock, flags); |
| 214 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Alan Cox | 606d099 | 2006-12-08 02:38:45 -0800 | [diff] [blame] | 217 | void line_set_termios(struct tty_struct *tty, struct ktermios * old) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
| 219 | /* nothing */ |
| 220 | } |
| 221 | |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 222 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | int cmd; |
| 224 | char *level; |
| 225 | char *name; |
| 226 | } tty_ioctls[] = { |
| 227 | /* don't print these, they flood the log ... */ |
| 228 | { TCGETS, NULL, "TCGETS" }, |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 229 | { TCSETS, NULL, "TCSETS" }, |
| 230 | { TCSETSW, NULL, "TCSETSW" }, |
| 231 | { TCFLSH, NULL, "TCFLSH" }, |
| 232 | { TCSBRK, NULL, "TCSBRK" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | /* general tty stuff */ |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 235 | { TCSETSF, KERN_DEBUG, "TCSETSF" }, |
| 236 | { TCGETA, KERN_DEBUG, "TCGETA" }, |
| 237 | { TIOCMGET, KERN_DEBUG, "TIOCMGET" }, |
| 238 | { TCSBRKP, KERN_DEBUG, "TCSBRKP" }, |
| 239 | { TIOCMSET, KERN_DEBUG, "TIOCMSET" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | /* linux-specific ones */ |
| 242 | { TIOCLINUX, KERN_INFO, "TIOCLINUX" }, |
| 243 | { KDGKBMODE, KERN_INFO, "KDGKBMODE" }, |
| 244 | { KDGKBTYPE, KERN_INFO, "KDGKBTYPE" }, |
| 245 | { KDSIGACCEPT, KERN_INFO, "KDSIGACCEPT" }, |
| 246 | }; |
| 247 | |
Richard Weinberger | 8a06dc4d | 2011-03-22 16:33:48 -0700 | [diff] [blame] | 248 | int line_ioctl(struct tty_struct *tty, unsigned int cmd, |
| 249 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
| 251 | int ret; |
| 252 | int i; |
| 253 | |
| 254 | ret = 0; |
| 255 | switch(cmd) { |
| 256 | #ifdef TIOCGETP |
| 257 | case TIOCGETP: |
| 258 | case TIOCSETP: |
| 259 | case TIOCSETN: |
| 260 | #endif |
| 261 | #ifdef TIOCGETC |
| 262 | case TIOCGETC: |
| 263 | case TIOCSETC: |
| 264 | #endif |
| 265 | #ifdef TIOCGLTC |
| 266 | case TIOCGLTC: |
| 267 | case TIOCSLTC: |
| 268 | #endif |
Alan Cox | c564b6f | 2008-10-13 10:36:49 +0100 | [diff] [blame] | 269 | /* Note: these are out of date as we now have TCGETS2 etc but this |
| 270 | whole lot should probably go away */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | case TCGETS: |
| 272 | case TCSETSF: |
| 273 | case TCSETSW: |
| 274 | case TCSETS: |
| 275 | case TCGETA: |
| 276 | case TCSETAF: |
| 277 | case TCSETAW: |
| 278 | case TCSETA: |
| 279 | case TCXONC: |
| 280 | case TCFLSH: |
| 281 | case TIOCOUTQ: |
| 282 | case TIOCINQ: |
| 283 | case TIOCGLCKTRMIOS: |
| 284 | case TIOCSLCKTRMIOS: |
| 285 | case TIOCPKT: |
| 286 | case TIOCGSOFTCAR: |
| 287 | case TIOCSSOFTCAR: |
| 288 | return -ENOIOCTLCMD; |
| 289 | #if 0 |
| 290 | case TCwhatever: |
| 291 | /* do something */ |
| 292 | break; |
| 293 | #endif |
| 294 | default: |
| 295 | for (i = 0; i < ARRAY_SIZE(tty_ioctls); i++) |
| 296 | if (cmd == tty_ioctls[i].cmd) |
| 297 | break; |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 298 | if (i == ARRAY_SIZE(tty_ioctls)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | printk(KERN_ERR "%s: %s: unknown ioctl: 0x%x\n", |
Harvey Harrison | 3595726 | 2008-04-28 02:13:53 -0700 | [diff] [blame] | 300 | __func__, tty->name, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | } |
| 302 | ret = -ENOIOCTLCMD; |
| 303 | break; |
| 304 | } |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 305 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Jeff Dike | e4dcee8 | 2006-01-06 00:18:58 -0800 | [diff] [blame] | 308 | void line_throttle(struct tty_struct *tty) |
| 309 | { |
| 310 | struct line *line = tty->driver_data; |
| 311 | |
Al Viro | bed5e39 | 2011-09-08 10:49:34 -0400 | [diff] [blame] | 312 | deactivate_chan(line->chan_in, line->driver->read_irq); |
Jeff Dike | e4dcee8 | 2006-01-06 00:18:58 -0800 | [diff] [blame] | 313 | line->throttled = 1; |
| 314 | } |
| 315 | |
| 316 | void line_unthrottle(struct tty_struct *tty) |
| 317 | { |
| 318 | struct line *line = tty->driver_data; |
| 319 | |
| 320 | line->throttled = 0; |
Al Viro | 0fcd719 | 2011-09-10 08:17:04 -0400 | [diff] [blame^] | 321 | chan_interrupt(line, tty, line->driver->read_irq); |
Jeff Dike | e4dcee8 | 2006-01-06 00:18:58 -0800 | [diff] [blame] | 322 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 323 | /* |
| 324 | * Maybe there is enough stuff pending that calling the interrupt |
Jeff Dike | e4dcee8 | 2006-01-06 00:18:58 -0800 | [diff] [blame] | 325 | * throttles us again. In this case, line->throttled will be 1 |
| 326 | * again and we shouldn't turn the interrupt back on. |
| 327 | */ |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 328 | if (!line->throttled) |
Al Viro | bed5e39 | 2011-09-08 10:49:34 -0400 | [diff] [blame] | 329 | reactivate_chan(line->chan_in, line->driver->read_irq); |
Jeff Dike | e4dcee8 | 2006-01-06 00:18:58 -0800 | [diff] [blame] | 330 | } |
| 331 | |
Al Viro | 7bea96f | 2006-10-08 22:49:34 +0100 | [diff] [blame] | 332 | static irqreturn_t line_write_interrupt(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 334 | struct chan *chan = data; |
| 335 | struct line *line = chan->line; |
| 336 | struct tty_struct *tty = line->tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | int err; |
| 338 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 339 | /* |
Yong Zhang | c0b79a9 | 2011-09-22 16:58:46 +0800 | [diff] [blame] | 340 | * Interrupts are disabled here because genirq keep irqs disabled when |
| 341 | * calling the action handler. |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 342 | */ |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 343 | |
Paolo 'Blaisorblade' Giarrusso | ec0ac8a | 2007-03-07 20:41:12 -0800 | [diff] [blame] | 344 | spin_lock(&line->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | err = flush_buffer(line); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 346 | if (err == 0) { |
| 347 | return IRQ_NONE; |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 348 | } else if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | line->head = line->buffer; |
| 350 | line->tail = line->buffer; |
| 351 | } |
Paolo 'Blaisorblade' Giarrusso | ec0ac8a | 2007-03-07 20:41:12 -0800 | [diff] [blame] | 352 | spin_unlock(&line->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 354 | if (tty == NULL) |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 355 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
WANG Cong | 06ac667 | 2008-07-29 22:33:34 -0700 | [diff] [blame] | 357 | tty_wakeup(tty); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 358 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 361 | int line_setup_irq(int fd, int input, int output, struct line *line, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
Jeff Dike | 5e7672e | 2006-09-27 01:50:33 -0700 | [diff] [blame] | 363 | const struct line_driver *driver = line->driver; |
Yong Zhang | c0b79a9 | 2011-09-22 16:58:46 +0800 | [diff] [blame] | 364 | int err = 0, flags = IRQF_SHARED | IRQF_SAMPLE_RANDOM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 366 | if (input) |
| 367 | err = um_request_irq(driver->read_irq, fd, IRQ_READ, |
Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 368 | line_interrupt, flags, |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 369 | driver->read_irq_name, data); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 370 | if (err) |
| 371 | return err; |
| 372 | if (output) |
| 373 | err = um_request_irq(driver->write_irq, fd, IRQ_WRITE, |
Jeff Dike | d50084a | 2006-01-06 00:18:50 -0800 | [diff] [blame] | 374 | line_write_interrupt, flags, |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 375 | driver->write_irq_name, data); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 376 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 379 | /* |
| 380 | * Normally, a driver like this can rely mostly on the tty layer |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 381 | * locking, particularly when it comes to the driver structure. |
| 382 | * However, in this case, mconsole requests can come in "from the |
| 383 | * side", and race with opens and closes. |
| 384 | * |
Jeff Dike | c6256c6 | 2007-02-10 01:44:08 -0800 | [diff] [blame] | 385 | * mconsole config requests will want to be sure the device isn't in |
| 386 | * use, and get_config, open, and close will want a stable |
| 387 | * configuration. The checking and modification of the configuration |
| 388 | * is done under a spinlock. Checking whether the device is in use is |
| 389 | * line->tty->count > 1, also under the spinlock. |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 390 | * |
Al Viro | f71f948 | 2011-09-14 16:21:25 -0700 | [diff] [blame] | 391 | * line->count serves to decide whether the device should be enabled or |
| 392 | * disabled on the host. If it's equal to 0, then we are doing the |
Jeff Dike | c6256c6 | 2007-02-10 01:44:08 -0800 | [diff] [blame] | 393 | * first open or last close. Otherwise, open and close just return. |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 394 | */ |
| 395 | |
Jeff Dike | 1f80171 | 2006-01-06 00:18:55 -0800 | [diff] [blame] | 396 | int line_open(struct line *lines, struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 398 | struct line *line = &lines[tty->index]; |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 399 | int err = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Al Viro | d8c215a | 2011-09-09 17:36:37 -0400 | [diff] [blame] | 401 | mutex_lock(&line->count_lock); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 402 | if (!line->valid) |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 403 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 405 | err = 0; |
Al Viro | f71f948 | 2011-09-14 16:21:25 -0700 | [diff] [blame] | 406 | if (line->count++) |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 407 | goto out_unlock; |
| 408 | |
Al Viro | f71f948 | 2011-09-14 16:21:25 -0700 | [diff] [blame] | 409 | BUG_ON(tty->driver_data); |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 410 | tty->driver_data = line; |
| 411 | line->tty = tty; |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 412 | |
Jeff Dike | d14ad81 | 2007-07-15 23:38:54 -0700 | [diff] [blame] | 413 | err = enable_chan(line); |
Al Viro | f71f948 | 2011-09-14 16:21:25 -0700 | [diff] [blame] | 414 | if (err) /* line_close() will be called by our caller */ |
Al Viro | d8c215a | 2011-09-09 17:36:37 -0400 | [diff] [blame] | 415 | goto out_unlock; |
Jeff Dike | d14ad81 | 2007-07-15 23:38:54 -0700 | [diff] [blame] | 416 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 417 | if (!line->sigio) { |
Al Viro | bed5e39 | 2011-09-08 10:49:34 -0400 | [diff] [blame] | 418 | chan_enable_winch(line->chan_out, tty); |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 419 | line->sigio = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Al Viro | bed5e39 | 2011-09-08 10:49:34 -0400 | [diff] [blame] | 422 | chan_window_size(line, &tty->winsize.ws_row, |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 423 | &tty->winsize.ws_col); |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 424 | out_unlock: |
Al Viro | d8c215a | 2011-09-09 17:36:37 -0400 | [diff] [blame] | 425 | mutex_unlock(&line->count_lock); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 426 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Jeff Dike | cd2ee4a | 2005-05-05 16:15:32 -0700 | [diff] [blame] | 429 | static void unregister_winch(struct tty_struct *tty); |
| 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | void line_close(struct tty_struct *tty, struct file * filp) |
| 432 | { |
| 433 | struct line *line = tty->driver_data; |
| 434 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 435 | /* |
| 436 | * If line_open fails (and tty->driver_data is never set), |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 437 | * tty_open will call line_close. So just return in this case. |
| 438 | */ |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 439 | if (line == NULL) |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 440 | return; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 441 | |
| 442 | /* We ignore the error anyway! */ |
| 443 | flush_buffer(line); |
| 444 | |
Al Viro | d8c215a | 2011-09-09 17:36:37 -0400 | [diff] [blame] | 445 | mutex_lock(&line->count_lock); |
Al Viro | f71f948 | 2011-09-14 16:21:25 -0700 | [diff] [blame] | 446 | BUG_ON(!line->valid); |
Jeff Dike | cd2ee4a | 2005-05-05 16:15:32 -0700 | [diff] [blame] | 447 | |
Al Viro | f71f948 | 2011-09-14 16:21:25 -0700 | [diff] [blame] | 448 | if (--line->count) |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 449 | goto out_unlock; |
| 450 | |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 451 | line->tty = NULL; |
| 452 | tty->driver_data = NULL; |
| 453 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 454 | if (line->sigio) { |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 455 | unregister_winch(tty); |
| 456 | line->sigio = 0; |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 457 | } |
Jeff Dike | cd2ee4a | 2005-05-05 16:15:32 -0700 | [diff] [blame] | 458 | |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 459 | out_unlock: |
Al Viro | d8c215a | 2011-09-09 17:36:37 -0400 | [diff] [blame] | 460 | mutex_unlock(&line->count_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void close_lines(struct line *lines, int nlines) |
| 464 | { |
| 465 | int i; |
| 466 | |
| 467 | for(i = 0; i < nlines; i++) |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 468 | close_chan(&lines[i].chan_list, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Al Viro | 04292b2 | 2011-09-09 20:07:05 -0400 | [diff] [blame] | 471 | int setup_one_line(struct line *lines, int n, char *init, |
| 472 | const struct chan_opts *opts, char **error_out) |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 473 | { |
| 474 | struct line *line = &lines[n]; |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 475 | struct tty_driver *driver = line->driver->driver; |
Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 476 | int err = -EINVAL; |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 477 | |
Al Viro | d8c215a | 2011-09-09 17:36:37 -0400 | [diff] [blame] | 478 | mutex_lock(&line->count_lock); |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 479 | |
Al Viro | f71f948 | 2011-09-14 16:21:25 -0700 | [diff] [blame] | 480 | if (line->count) { |
Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 481 | *error_out = "Device is already open"; |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 482 | goto out; |
| 483 | } |
| 484 | |
Al Viro | 31efceb | 2011-09-09 19:14:02 -0400 | [diff] [blame] | 485 | if (!strcmp(init, "none")) { |
| 486 | if (line->valid) { |
| 487 | line->valid = 0; |
| 488 | kfree(line->init_str); |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 489 | tty_unregister_device(driver, n); |
Al Viro | 31efceb | 2011-09-09 19:14:02 -0400 | [diff] [blame] | 490 | parse_chan_pair(NULL, line, n, opts, error_out); |
| 491 | err = 0; |
| 492 | } |
| 493 | } else { |
| 494 | char *new = kstrdup(init, GFP_KERNEL); |
| 495 | if (!new) { |
| 496 | *error_out = "Failed to allocate memory"; |
| 497 | return -ENOMEM; |
| 498 | } |
Al Viro | c8e2876 | 2011-09-09 20:08:48 -0400 | [diff] [blame] | 499 | if (line->valid) { |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 500 | tty_unregister_device(driver, n); |
Al Viro | c8e2876 | 2011-09-09 20:08:48 -0400 | [diff] [blame] | 501 | kfree(line->init_str); |
| 502 | } |
Al Viro | 31efceb | 2011-09-09 19:14:02 -0400 | [diff] [blame] | 503 | line->init_str = new; |
Al Viro | 43574c1 | 2011-09-09 17:25:00 -0400 | [diff] [blame] | 504 | line->valid = 1; |
Al Viro | 31efceb | 2011-09-09 19:14:02 -0400 | [diff] [blame] | 505 | err = parse_chan_pair(new, line, n, opts, error_out); |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 506 | if (!err) { |
| 507 | struct device *d = tty_register_device(driver, n, NULL); |
| 508 | if (IS_ERR(d)) { |
| 509 | *error_out = "Failed to register device"; |
| 510 | err = PTR_ERR(d); |
| 511 | parse_chan_pair(NULL, line, n, opts, error_out); |
| 512 | } |
| 513 | } |
Al Viro | 31efceb | 2011-09-09 19:14:02 -0400 | [diff] [blame] | 514 | if (err) { |
| 515 | line->init_str = NULL; |
| 516 | line->valid = 0; |
| 517 | kfree(new); |
| 518 | } |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 519 | } |
| 520 | out: |
Al Viro | d8c215a | 2011-09-09 17:36:37 -0400 | [diff] [blame] | 521 | mutex_unlock(&line->count_lock); |
Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 522 | return err; |
Jeff Dike | d79a580 | 2007-02-10 01:43:52 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 525 | /* |
| 526 | * Common setup code for both startup command line and mconsole initialization. |
Matt LaPlante | 4b3f686 | 2006-10-03 22:21:02 +0200 | [diff] [blame] | 527 | * @lines contains the array (of size @num) to modify; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 528 | * @init is the setup string; |
Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 529 | * @error_out is an error string in the case of failure; |
Jeff Dike | d571cd1 | 2006-01-06 00:18:53 -0800 | [diff] [blame] | 530 | */ |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 531 | |
Al Viro | 43574c1 | 2011-09-09 17:25:00 -0400 | [diff] [blame] | 532 | int line_setup(char **conf, unsigned int num, char **def, |
| 533 | char *init, char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | { |
Al Viro | 43574c1 | 2011-09-09 17:25:00 -0400 | [diff] [blame] | 535 | char *error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 537 | if (*init == '=') { |
| 538 | /* |
| 539 | * We said con=/ssl= instead of con#=, so we are configuring all |
| 540 | * consoles at once. |
| 541 | */ |
Al Viro | 43574c1 | 2011-09-09 17:25:00 -0400 | [diff] [blame] | 542 | *def = init + 1; |
| 543 | } else { |
| 544 | char *end; |
| 545 | unsigned n = simple_strtoul(init, &end, 0); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 546 | |
Al Viro | 43574c1 | 2011-09-09 17:25:00 -0400 | [diff] [blame] | 547 | if (*end != '=') { |
| 548 | error = "Couldn't parse device number"; |
| 549 | goto out; |
Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 550 | } |
Al Viro | 43574c1 | 2011-09-09 17:25:00 -0400 | [diff] [blame] | 551 | if (n >= num) { |
| 552 | error = "Device number out of range"; |
| 553 | goto out; |
| 554 | } |
| 555 | conf[n] = end + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
Al Viro | 43574c1 | 2011-09-09 17:25:00 -0400 | [diff] [blame] | 557 | return 0; |
| 558 | |
| 559 | out: |
| 560 | printk(KERN_ERR "Failed to set up %s with " |
| 561 | "configuration string \"%s\" : %s\n", name, init, error); |
| 562 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Jeff Dike | 1f80171 | 2006-01-06 00:18:55 -0800 | [diff] [blame] | 565 | int line_config(struct line *lines, unsigned int num, char *str, |
Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 566 | const struct chan_opts *opts, char **error_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | { |
Al Viro | fe9a6b0 | 2011-09-08 20:44:06 -0400 | [diff] [blame] | 568 | char *end; |
Al Viro | 31efceb | 2011-09-09 19:14:02 -0400 | [diff] [blame] | 569 | int n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 571 | if (*str == '=') { |
Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 572 | *error_out = "Can't configure all devices from mconsole"; |
| 573 | return -EINVAL; |
Jeff Dike | d571cd1 | 2006-01-06 00:18:53 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Al Viro | fe9a6b0 | 2011-09-08 20:44:06 -0400 | [diff] [blame] | 576 | n = simple_strtoul(str, &end, 0); |
| 577 | if (*end++ != '=') { |
| 578 | *error_out = "Couldn't parse device number"; |
| 579 | return -EINVAL; |
| 580 | } |
| 581 | if (n >= num) { |
| 582 | *error_out = "Device number out of range"; |
| 583 | return -EINVAL; |
| 584 | } |
| 585 | |
Al Viro | 31efceb | 2011-09-09 19:14:02 -0400 | [diff] [blame] | 586 | return setup_one_line(lines, n, end, opts, error_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 589 | int line_get_config(char *name, struct line *lines, unsigned int num, char *str, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | int size, char **error_out) |
| 591 | { |
| 592 | struct line *line; |
| 593 | char *end; |
| 594 | int dev, n = 0; |
| 595 | |
| 596 | dev = simple_strtoul(name, &end, 0); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 597 | if ((*end != '\0') || (end == name)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | *error_out = "line_get_config failed to parse device number"; |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 599 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 602 | if ((dev < 0) || (dev >= num)) { |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 603 | *error_out = "device number out of range"; |
| 604 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | line = &lines[dev]; |
| 608 | |
Al Viro | d8c215a | 2011-09-09 17:36:37 -0400 | [diff] [blame] | 609 | mutex_lock(&line->count_lock); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 610 | if (!line->valid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | CONFIG_CHUNK(str, size, n, "none", 1); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 612 | else if (line->tty == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | CONFIG_CHUNK(str, size, n, line->init_str, 1); |
Al Viro | bed5e39 | 2011-09-08 10:49:34 -0400 | [diff] [blame] | 614 | else n = chan_config_string(line, str, size, error_out); |
Al Viro | d8c215a | 2011-09-09 17:36:37 -0400 | [diff] [blame] | 615 | mutex_unlock(&line->count_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 617 | return n; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Jeff Dike | 29d56cf | 2005-06-25 14:55:25 -0700 | [diff] [blame] | 620 | int line_id(char **str, int *start_out, int *end_out) |
| 621 | { |
| 622 | char *end; |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 623 | int n; |
Jeff Dike | 29d56cf | 2005-06-25 14:55:25 -0700 | [diff] [blame] | 624 | |
| 625 | n = simple_strtoul(*str, &end, 0); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 626 | if ((*end != '\0') || (end == *str)) |
| 627 | return -1; |
Jeff Dike | 29d56cf | 2005-06-25 14:55:25 -0700 | [diff] [blame] | 628 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 629 | *str = end; |
| 630 | *start_out = n; |
| 631 | *end_out = n; |
| 632 | return n; |
Jeff Dike | 29d56cf | 2005-06-25 14:55:25 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Jeff Dike | f28169d | 2007-02-10 01:43:53 -0800 | [diff] [blame] | 635 | int line_remove(struct line *lines, unsigned int num, int n, char **error_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
Al Viro | da645f3 | 2011-09-08 20:34:52 -0400 | [diff] [blame] | 637 | if (n >= num) { |
| 638 | *error_out = "Device number out of range"; |
| 639 | return -EINVAL; |
| 640 | } |
Al Viro | 31efceb | 2011-09-09 19:14:02 -0400 | [diff] [blame] | 641 | return setup_one_line(lines, n, "none", NULL, error_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 644 | int register_lines(struct line_driver *line_driver, |
| 645 | const struct tty_operations *ops, |
| 646 | struct line *lines, int nlines) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | struct tty_driver *driver = alloc_tty_driver(nlines); |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 649 | int err; |
Al Viro | 04292b2 | 2011-09-09 20:07:05 -0400 | [diff] [blame] | 650 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
| 652 | if (!driver) |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 653 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
| 655 | driver->driver_name = line_driver->name; |
| 656 | driver->name = line_driver->device_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | driver->major = line_driver->major; |
| 658 | driver->minor_start = line_driver->minor_start; |
| 659 | driver->type = line_driver->type; |
| 660 | driver->subtype = line_driver->subtype; |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 661 | driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | driver->init_termios = tty_std_termios; |
Al Viro | 04292b2 | 2011-09-09 20:07:05 -0400 | [diff] [blame] | 663 | |
| 664 | for (i = 0; i < nlines; i++) { |
| 665 | spin_lock_init(&lines[i].lock); |
| 666 | mutex_init(&lines[i].count_lock); |
| 667 | lines[i].driver = line_driver; |
| 668 | INIT_LIST_HEAD(&lines[i].chan_list); |
| 669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | tty_set_operations(driver, ops); |
| 671 | |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 672 | err = tty_register_driver(driver); |
| 673 | if (err) { |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 674 | printk(KERN_ERR "register_lines : can't register %s driver\n", |
| 675 | line_driver->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | put_tty_driver(driver); |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 677 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | } |
| 679 | |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 680 | line_driver->driver = driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | mconsole_register_dev(&line_driver->mc); |
Al Viro | cfe6b7c | 2011-09-09 19:45:42 -0400 | [diff] [blame] | 682 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Jeff Dike | 9010772 | 2006-01-06 00:18:54 -0800 | [diff] [blame] | 685 | static DEFINE_SPINLOCK(winch_handler_lock); |
| 686 | static LIST_HEAD(winch_handlers); |
Paolo 'Blaisorblade' Giarrusso | 605a69a | 2005-07-07 17:56:52 -0700 | [diff] [blame] | 687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | struct winch { |
| 689 | struct list_head list; |
| 690 | int fd; |
| 691 | int tty_fd; |
| 692 | int pid; |
| 693 | struct tty_struct *tty; |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 694 | unsigned long stack; |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 695 | struct work_struct work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | }; |
| 697 | |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 698 | static void __free_winch(struct work_struct *work) |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 699 | { |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 700 | struct winch *winch = container_of(work, struct winch, work); |
| 701 | free_irq(WINCH_IRQ, winch); |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 702 | |
| 703 | if (winch->pid != -1) |
| 704 | os_kill_process(winch->pid, 1); |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 705 | if (winch->stack != 0) |
| 706 | free_stack(winch->stack, 0); |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 707 | kfree(winch); |
| 708 | } |
| 709 | |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 710 | static void free_winch(struct winch *winch) |
| 711 | { |
| 712 | int fd = winch->fd; |
| 713 | winch->fd = -1; |
| 714 | if (fd != -1) |
| 715 | os_close_file(fd); |
| 716 | list_del(&winch->list); |
| 717 | __free_winch(&winch->work); |
| 718 | } |
| 719 | |
Al Viro | 7bea96f | 2006-10-08 22:49:34 +0100 | [diff] [blame] | 720 | static irqreturn_t winch_interrupt(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | { |
| 722 | struct winch *winch = data; |
| 723 | struct tty_struct *tty; |
| 724 | struct line *line; |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 725 | int fd = winch->fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | int err; |
| 727 | char c; |
| 728 | |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 729 | if (fd != -1) { |
| 730 | err = generic_read(fd, &c, NULL); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 731 | if (err < 0) { |
| 732 | if (err != -EAGAIN) { |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 733 | winch->fd = -1; |
| 734 | list_del(&winch->list); |
| 735 | os_close_file(fd); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 736 | printk(KERN_ERR "winch_interrupt : " |
| 737 | "read failed, errno = %d\n", -err); |
| 738 | printk(KERN_ERR "fd %d is losing SIGWINCH " |
| 739 | "support\n", winch->tty_fd); |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 740 | INIT_WORK(&winch->work, __free_winch); |
| 741 | schedule_work(&winch->work); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 742 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | goto out; |
| 745 | } |
| 746 | } |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 747 | tty = winch->tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | if (tty != NULL) { |
| 749 | line = tty->driver_data; |
Jeff Dike | 438ee67 | 2008-02-04 22:31:19 -0800 | [diff] [blame] | 750 | if (line != NULL) { |
Al Viro | bed5e39 | 2011-09-08 10:49:34 -0400 | [diff] [blame] | 751 | chan_window_size(line, &tty->winsize.ws_row, |
Jeff Dike | 438ee67 | 2008-02-04 22:31:19 -0800 | [diff] [blame] | 752 | &tty->winsize.ws_col); |
| 753 | kill_pgrp(tty->pgrp, SIGWINCH, 1); |
| 754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
| 756 | out: |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 757 | if (winch->fd != -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | reactivate_fd(winch->fd, WINCH_IRQ); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 759 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 762 | void register_winch_irq(int fd, int tty_fd, int pid, struct tty_struct *tty, |
| 763 | unsigned long stack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | { |
| 765 | struct winch *winch; |
| 766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | winch = kmalloc(sizeof(*winch), GFP_KERNEL); |
| 768 | if (winch == NULL) { |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 769 | printk(KERN_ERR "register_winch_irq - kmalloc failed\n"); |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 770 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
Paolo 'Blaisorblade' Giarrusso | 605a69a | 2005-07-07 17:56:52 -0700 | [diff] [blame] | 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | *winch = ((struct winch) { .list = LIST_HEAD_INIT(winch->list), |
| 774 | .fd = fd, |
| 775 | .tty_fd = tty_fd, |
| 776 | .pid = pid, |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 777 | .tty = tty, |
| 778 | .stack = stack }); |
| 779 | |
| 780 | if (um_request_irq(WINCH_IRQ, fd, IRQ_READ, winch_interrupt, |
Yong Zhang | c0b79a9 | 2011-09-22 16:58:46 +0800 | [diff] [blame] | 781 | IRQF_SHARED | IRQF_SAMPLE_RANDOM, |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 782 | "winch", winch) < 0) { |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 783 | printk(KERN_ERR "register_winch_irq - failed to register " |
| 784 | "IRQ\n"); |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 785 | goto out_free; |
| 786 | } |
Paolo 'Blaisorblade' Giarrusso | 605a69a | 2005-07-07 17:56:52 -0700 | [diff] [blame] | 787 | |
| 788 | spin_lock(&winch_handler_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | list_add(&winch->list, &winch_handlers); |
Paolo 'Blaisorblade' Giarrusso | 605a69a | 2005-07-07 17:56:52 -0700 | [diff] [blame] | 790 | spin_unlock(&winch_handler_lock); |
| 791 | |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 792 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 794 | out_free: |
Jeff Dike | e464bf2 | 2006-01-06 00:19:01 -0800 | [diff] [blame] | 795 | kfree(winch); |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 796 | cleanup: |
| 797 | os_kill_process(pid, 1); |
| 798 | os_close_file(fd); |
| 799 | if (stack != 0) |
| 800 | free_stack(stack, 0); |
Jeff Dike | cd2ee4a | 2005-05-05 16:15:32 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Jeff Dike | e464bf2 | 2006-01-06 00:19:01 -0800 | [diff] [blame] | 803 | static void unregister_winch(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
Will Newton | 48a0b74 | 2011-01-12 16:59:26 -0800 | [diff] [blame] | 805 | struct list_head *ele, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | struct winch *winch; |
| 807 | |
Jeff Dike | e464bf2 | 2006-01-06 00:19:01 -0800 | [diff] [blame] | 808 | spin_lock(&winch_handler_lock); |
| 809 | |
Will Newton | 48a0b74 | 2011-01-12 16:59:26 -0800 | [diff] [blame] | 810 | list_for_each_safe(ele, next, &winch_handlers) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | winch = list_entry(ele, struct winch, list); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 812 | if (winch->tty == tty) { |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 813 | free_winch(winch); |
Jeff Dike | e464bf2 | 2006-01-06 00:19:01 -0800 | [diff] [blame] | 814 | break; |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 815 | } |
| 816 | } |
Jeff Dike | e464bf2 | 2006-01-06 00:19:01 -0800 | [diff] [blame] | 817 | spin_unlock(&winch_handler_lock); |
| 818 | } |
| 819 | |
| 820 | static void winch_cleanup(void) |
| 821 | { |
| 822 | struct list_head *ele, *next; |
| 823 | struct winch *winch; |
| 824 | |
| 825 | spin_lock(&winch_handler_lock); |
| 826 | |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 827 | list_for_each_safe(ele, next, &winch_handlers) { |
Jeff Dike | e464bf2 | 2006-01-06 00:19:01 -0800 | [diff] [blame] | 828 | winch = list_entry(ele, struct winch, list); |
Al Viro | 7cf3cf2 | 2011-09-14 16:21:31 -0700 | [diff] [blame] | 829 | free_winch(winch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
Jeff Dike | e464bf2 | 2006-01-06 00:19:01 -0800 | [diff] [blame] | 831 | |
| 832 | spin_unlock(&winch_handler_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | } |
| 834 | __uml_exitcall(winch_cleanup); |
| 835 | |
| 836 | char *add_xterm_umid(char *base) |
| 837 | { |
| 838 | char *umid, *title; |
| 839 | int len; |
| 840 | |
Jeff Dike | 7eebe8a | 2006-01-06 00:19:01 -0800 | [diff] [blame] | 841 | umid = get_umid(); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 842 | if (*umid == '\0') |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 843 | return base; |
Jeff Dike | 165dc59 | 2006-01-06 00:18:57 -0800 | [diff] [blame] | 844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | len = strlen(base) + strlen(" ()") + strlen(umid) + 1; |
| 846 | title = kmalloc(len, GFP_KERNEL); |
Jeff Dike | 2f8a2dc | 2007-10-16 01:26:43 -0700 | [diff] [blame] | 847 | if (title == NULL) { |
| 848 | printk(KERN_ERR "Failed to allocate buffer for xterm title\n"); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 849 | return base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | snprintf(title, len, "%s (%s)", base, umid); |
Paolo 'Blaisorblade' Giarrusso | b97b77c | 2005-05-01 08:58:56 -0700 | [diff] [blame] | 853 | return title; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | } |