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