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