Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/irqreturn.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "chan.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <irq_kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <irq_user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <kern_util.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <os.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define LINE_BUFSIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static irqreturn_t line_interrupt(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct chan *chan = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct line *line = chan->line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	if (line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		chan_interrupt(line, irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * Returns the free space inside the ring buffer of this line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * Should be called while holding line->lock (this does not modify data).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static int write_room(struct line *line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (line->buffer == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		return LINE_BUFSIZE - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	/* This is for the case where the buffer is wrapped! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	n = line->head - line->tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (n <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		n += LINE_BUFSIZE; /* The other case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	return n - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) int line_write_room(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	spin_lock_irqsave(&line->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	room = write_room(line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	spin_unlock_irqrestore(&line->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) int line_chars_in_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	spin_lock_irqsave(&line->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	/* write_room subtracts 1 for the needed NULL, so we readd it.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	ret = LINE_BUFSIZE - (write_room(line) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	spin_unlock_irqrestore(&line->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * This copies the content of buf into the circular buffer associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * this line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * The return value is the number of characters actually copied, i.e. the ones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * for which there was space: this function is not supposed to ever flush out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * the circular buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * Must be called while holding line->lock!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int buffer_data(struct line *line, const char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int end, room;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (line->buffer == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		line->buffer = kmalloc(LINE_BUFSIZE, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if (line->buffer == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			printk(KERN_ERR "buffer_data - atomic allocation "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			       "failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		line->head = line->buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		line->tail = line->buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	room = write_room(line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	len = (len > room) ? room : len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	end = line->buffer + LINE_BUFSIZE - line->tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (len < end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		memcpy(line->tail, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		line->tail += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		/* The circular buffer is wrapping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		memcpy(line->tail, buf, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		buf += end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		memcpy(line->buffer, buf, len - end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		line->tail = line->buffer + len - end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * Flushes the ring buffer to the output channels. That is, write_chan is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * called, passing it line->head as buffer, and an appropriate count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * On exit, returns 1 when the buffer is empty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * 0 when the buffer is not empty on exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * and -errno when an error occurred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * Must be called while holding line->lock!*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static int flush_buffer(struct line *line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	int n, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if ((line->buffer == NULL) || (line->head == line->tail))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (line->tail < line->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		/* line->buffer + LINE_BUFSIZE is the end of the buffer! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		count = line->buffer + LINE_BUFSIZE - line->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		n = write_chan(line->chan_out, line->head, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			       line->driver->write_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (n < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		if (n == count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			 * We have flushed from ->head to buffer end, now we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			 * must flush only from the beginning to ->tail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			line->head = line->buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			line->head += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	count = line->tail - line->head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	n = write_chan(line->chan_out, line->head, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		       line->driver->write_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (n < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	line->head += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return line->head == line->tail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) void line_flush_buffer(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	spin_lock_irqsave(&line->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	flush_buffer(line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	spin_unlock_irqrestore(&line->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * We map both ->flush_chars and ->put_char (which go in pair) onto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * ->flush_buffer and ->write. Hope it's not that bad.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) void line_flush_chars(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	line_flush_buffer(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int line_write(struct tty_struct *tty, const unsigned char *buf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	int n, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	spin_lock_irqsave(&line->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (line->head != line->tail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		ret = buffer_data(line, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		n = write_chan(line->chan_out, buf, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			       line->driver->write_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		if (n < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			ret = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			goto out_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		len -= n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		ret += n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (len > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			ret += buffer_data(line, buf + n, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) out_up:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	spin_unlock_irqrestore(&line->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) void line_set_termios(struct tty_struct *tty, struct ktermios * old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	/* nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) void line_throttle(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	deactivate_chan(line->chan_in, line->driver->read_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	line->throttled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void line_unthrottle(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	line->throttled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	chan_interrupt(line, line->driver->read_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static irqreturn_t line_write_interrupt(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct chan *chan = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	struct line *line = chan->line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	 * Interrupts are disabled here because genirq keep irqs disabled when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	 * calling the action handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	spin_lock(&line->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	err = flush_buffer(line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		spin_unlock(&line->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	} else if ((err < 0) && (err != -EAGAIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		line->head = line->buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		line->tail = line->buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	spin_unlock(&line->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	tty_port_tty_wakeup(&line->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int line_setup_irq(int fd, int input, int output, struct line *line, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	const struct line_driver *driver = line->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		err = um_request_irq(driver->read_irq, fd, IRQ_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				     line_interrupt, IRQF_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				     driver->read_irq_name, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		err = um_request_irq(driver->write_irq, fd, IRQ_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 				     line_write_interrupt, IRQF_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				     driver->write_irq_name, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int line_activate(struct tty_port *port, struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	ret = enable_chan(line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!line->sigio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		chan_enable_winch(line->chan_out, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		line->sigio = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	chan_window_size(line, &tty->winsize.ws_row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		&tty->winsize.ws_col);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static void unregister_winch(struct tty_struct *tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static void line_destruct(struct tty_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	struct tty_struct *tty = tty_port_tty_get(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (line->sigio) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		unregister_winch(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		line->sigio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static const struct tty_port_operations line_port_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	.activate = line_activate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	.destruct = line_destruct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int line_open(struct tty_struct *tty, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	return tty_port_open(&line->port, tty, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int line_install(struct tty_driver *driver, struct tty_struct *tty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		 struct line *line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	ret = tty_standard_install(driver, tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	tty->driver_data = line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) void line_close(struct tty_struct *tty, struct file * filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	tty_port_close(&line->port, tty, filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) void line_hangup(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	struct line *line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	tty_port_hangup(&line->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) void close_lines(struct line *lines, int nlines)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	for(i = 0; i < nlines; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		close_chan(&lines[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int setup_one_line(struct line *lines, int n, char *init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		   const struct chan_opts *opts, char **error_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	struct line *line = &lines[n];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct tty_driver *driver = line->driver->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	if (line->port.count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		*error_out = "Device is already open";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (!strcmp(init, "none")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		if (line->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			line->valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			kfree(line->init_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			tty_unregister_device(driver, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 			parse_chan_pair(NULL, line, n, opts, error_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		char *new = kstrdup(init, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		if (!new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			*error_out = "Failed to allocate memory";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		if (line->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			tty_unregister_device(driver, n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			kfree(line->init_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		line->init_str = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		line->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		err = parse_chan_pair(new, line, n, opts, error_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 			struct device *d = tty_port_register_device(&line->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 					driver, n, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			if (IS_ERR(d)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 				*error_out = "Failed to register device";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 				err = PTR_ERR(d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 				parse_chan_pair(NULL, line, n, opts, error_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			line->init_str = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			line->valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 			kfree(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  * Common setup code for both startup command line and mconsole initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  * @lines contains the array (of size @num) to modify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  * @init is the setup string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  * @error_out is an error string in the case of failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) int line_setup(char **conf, unsigned int num, char **def,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	       char *init, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	char *error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (*init == '=') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		 * We said con=/ssl= instead of con#=, so we are configuring all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		 * consoles at once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		*def = init + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		char *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		unsigned n = simple_strtoul(init, &end, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		if (*end != '=') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			error = "Couldn't parse device number";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		if (n >= num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			error = "Device number out of range";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		conf[n] = end + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	printk(KERN_ERR "Failed to set up %s with "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	       "configuration string \"%s\" : %s\n", name, init, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) int line_config(struct line *lines, unsigned int num, char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		const struct chan_opts *opts, char **error_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	char *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	if (*str == '=') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		*error_out = "Can't configure all devices from mconsole";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	n = simple_strtoul(str, &end, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	if (*end++ != '=') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		*error_out = "Couldn't parse device number";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	if (n >= num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		*error_out = "Device number out of range";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	return setup_one_line(lines, n, end, opts, error_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) int line_get_config(char *name, struct line *lines, unsigned int num, char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		    int size, char **error_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	struct line *line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	char *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	int dev, n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	dev = simple_strtoul(name, &end, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	if ((*end != '\0') || (end == name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		*error_out = "line_get_config failed to parse device number";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	if ((dev < 0) || (dev >= num)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		*error_out = "device number out of range";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	line = &lines[dev];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	if (!line->valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		CONFIG_CHUNK(str, size, n, "none", 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		struct tty_struct *tty = tty_port_tty_get(&line->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		if (tty == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 			CONFIG_CHUNK(str, size, n, line->init_str, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 			n = chan_config_string(line, str, size, error_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 			tty_kref_put(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) int line_id(char **str, int *start_out, int *end_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	char *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	n = simple_strtoul(*str, &end, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if ((*end != '\0') || (end == *str))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	*str = end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	*start_out = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	*end_out = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) int line_remove(struct line *lines, unsigned int num, int n, char **error_out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	if (n >= num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		*error_out = "Device number out of range";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	return setup_one_line(lines, n, "none", NULL, error_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) int register_lines(struct line_driver *line_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		   const struct tty_operations *ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		   struct line *lines, int nlines)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	struct tty_driver *driver = alloc_tty_driver(nlines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	if (!driver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	driver->driver_name = line_driver->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	driver->name = line_driver->device_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	driver->major = line_driver->major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	driver->minor_start = line_driver->minor_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	driver->type = line_driver->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	driver->subtype = line_driver->subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	driver->init_termios = tty_std_termios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	for (i = 0; i < nlines; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		tty_port_init(&lines[i].port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		lines[i].port.ops = &line_port_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		spin_lock_init(&lines[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		lines[i].driver = line_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		INIT_LIST_HEAD(&lines[i].chan_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	tty_set_operations(driver, ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	err = tty_register_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 		printk(KERN_ERR "register_lines : can't register %s driver\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 		       line_driver->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		put_tty_driver(driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		for (i = 0; i < nlines; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 			tty_port_destroy(&lines[i].port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	line_driver->driver = driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	mconsole_register_dev(&line_driver->mc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static DEFINE_SPINLOCK(winch_handler_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static LIST_HEAD(winch_handlers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct winch {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	int tty_fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	int pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	struct tty_port *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	unsigned long stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	struct work_struct work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static void __free_winch(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	struct winch *winch = container_of(work, struct winch, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	um_free_irq(WINCH_IRQ, winch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	if (winch->pid != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		os_kill_process(winch->pid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	if (winch->stack != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		free_stack(winch->stack, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	kfree(winch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static void free_winch(struct winch *winch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	int fd = winch->fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	winch->fd = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	if (fd != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		os_close_file(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	list_del(&winch->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	__free_winch(&winch->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) static irqreturn_t winch_interrupt(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	struct winch *winch = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	struct tty_struct *tty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	struct line *line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	int fd = winch->fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	struct pid *pgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	if (fd != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 		err = generic_read(fd, &c, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 		if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 			if (err != -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 				winch->fd = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 				list_del(&winch->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 				os_close_file(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 				printk(KERN_ERR "winch_interrupt : "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 				       "read failed, errno = %d\n", -err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 				printk(KERN_ERR "fd %d is losing SIGWINCH "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 				       "support\n", winch->tty_fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 				INIT_WORK(&winch->work, __free_winch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 				schedule_work(&winch->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 				return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	tty = tty_port_tty_get(winch->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	if (tty != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		line = tty->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		if (line != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 			chan_window_size(line, &tty->winsize.ws_row,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 					 &tty->winsize.ws_col);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 			pgrp = tty_get_pgrp(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 			if (pgrp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 				kill_pgrp(pgrp, SIGWINCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 			put_pid(pgrp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		tty_kref_put(tty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) void register_winch_irq(int fd, int tty_fd, int pid, struct tty_port *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 			unsigned long stack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	struct winch *winch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	winch = kmalloc(sizeof(*winch), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	if (winch == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		printk(KERN_ERR "register_winch_irq - kmalloc failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 		goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	*winch = ((struct winch) { .list  	= LIST_HEAD_INIT(winch->list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 				   .fd  	= fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 				   .tty_fd 	= tty_fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 				   .pid  	= pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 				   .port 	= port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 				   .stack	= stack });
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	if (um_request_irq(WINCH_IRQ, fd, IRQ_READ, winch_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 			   IRQF_SHARED, "winch", winch) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		printk(KERN_ERR "register_winch_irq - failed to register "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		       "IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	spin_lock(&winch_handler_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	list_add(&winch->list, &winch_handlers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	spin_unlock(&winch_handler_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)  out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 	kfree(winch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)  cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	os_kill_process(pid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	os_close_file(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	if (stack != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 		free_stack(stack, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static void unregister_winch(struct tty_struct *tty)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	struct list_head *ele, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	struct winch *winch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	struct tty_struct *wtty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	spin_lock(&winch_handler_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	list_for_each_safe(ele, next, &winch_handlers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 		winch = list_entry(ele, struct winch, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 		wtty = tty_port_tty_get(winch->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		if (wtty == tty) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 			free_winch(winch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 		tty_kref_put(wtty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	spin_unlock(&winch_handler_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) static void winch_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	struct list_head *ele, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	struct winch *winch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	spin_lock(&winch_handler_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	list_for_each_safe(ele, next, &winch_handlers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 		winch = list_entry(ele, struct winch, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		free_winch(winch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	spin_unlock(&winch_handler_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) __uml_exitcall(winch_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) char *add_xterm_umid(char *base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	char *umid, *title;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 	umid = get_umid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	if (*umid == '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 		return base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	len = strlen(base) + strlen(" ()") + strlen(umid) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	title = kmalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	if (title == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 		printk(KERN_ERR "Failed to allocate buffer for xterm title\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 		return base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	snprintf(title, len, "%s (%s)", base, umid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	return title;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }