[PATCH 04/70] tty: Introduce a tty_port common structure

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Alan Cox
Date: Friday, June 20, 2008 - 12:58 pm

From: Alan Cox <alan@redhat.com>

Every tty driver has its own concept of a port structure and because they all
differ we cannot extract commonality. Begin fixing this by creating a structure
drivers can elect to use so that over time we can push fields into this and
create commonality and then introduce common methods.

Signed-off-by: Alan Cox <alan@redhat.com>
---

 drivers/char/tty_io.c |   34 ++++++++++++++++++++++++++++++++++
 include/linux/tty.h   |   30 +++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletions(-)


diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index ab1dd0a..1856096 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -2088,6 +2088,40 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
 	return tty_write(file, buf, count, ppos);
 }
 
+void tty_port_init(struct tty_port *port)
+{
+	memset(port, 0, sizeof(*port));
+	init_waitqueue_head(&port->open_wait);
+	init_waitqueue_head(&port->close_wait);
+	mutex_init(&port->mutex);
+}
+EXPORT_SYMBOL(tty_port_init);
+
+int tty_port_alloc_xmit_buf(struct tty_port *port)
+{
+	/* We may sleep in get_zeroed_page() */
+	mutex_lock(&port->mutex);
+	if (port->xmit_buf == NULL)
+		port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
+	mutex_unlock(&port->mutex);
+	if (port->xmit_buf == NULL)
+		return -ENOMEM;
+	return 0;
+}
+EXPORT_SYMBOL(tty_port_alloc_xmit_buf);
+
+void tty_port_free_xmit_buf(struct tty_port *port)
+{
+	mutex_lock(&port->mutex);
+	if (port->xmit_buf != NULL) {
+		free_page((unsigned long)port->xmit_buf);
+		port->xmit_buf = NULL;
+	}
+	mutex_unlock(&port->mutex);
+}
+EXPORT_SYMBOL(tty_port_free_xmit_buf);
+
+
 static char ptychar[] = "pqrstuvwxyzabcde";
 
 /**
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 013711e..d7c695b 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -166,6 +166,29 @@ struct tty_bufhead {
 
 struct device;
 struct signal_struct;
+
+/*
+ * Port level information. Each device keeps its own port level information
+ * so provide a common structure for those ports wanting to use common support
+ * routines.
+ *
+ * The tty port has a different lifetime to the tty so must be kept apart.
+ * In addition be careful as tty -> port mappings are valid for the life
+ * of the tty object but in many cases port -> tty mappings are valid only
+ * until a hangup so don't use the wrong path.
+ */
+ 
+struct tty_port {
+	struct tty_struct	*tty;		/* Back pointer */
+	int			blocked_open;	/* Waiting to open */
+	int			count;		/* Usage count */
+	wait_queue_head_t	open_wait;	/* Open waiters */
+	wait_queue_head_t	close_wait;	/* Close waiters */
+	unsigned long		flags;		/* TTY flags ASY_*/
+	struct mutex		mutex;		/* Locking */
+	unsigned char		*xmit_buf;	/* Optional buffer */
+};
+
 /*
  * Where all of the state associated with a tty is kept while the tty
  * is open.  Since the termios state should be kept even if the tty
@@ -214,7 +237,7 @@ struct tty_struct {
 	struct list_head tty_files;
 
 #define N_TTY_BUF_SIZE 4096
-	
+
 	/*
 	 * The following is data for the N_TTY line discipline.  For
 	 * historical reasons, this is included in the tty structure.
@@ -242,6 +265,7 @@ struct tty_struct {
 	spinlock_t read_lock;
 	/* If the tty has a pending do_SAK, queue it here - akpm */
 	struct work_struct SAK_work;
+	struct tty_port *port;
 };
 
 /* tty magic number */
@@ -350,6 +374,10 @@ extern void tty_write_unlock(struct tty_struct *tty);
 extern int tty_write_lock(struct tty_struct *tty, int ndelay);
 #define tty_is_writelocked(tty)  (mutex_is_locked(&tty->atomic_write_lock))
 
+extern void tty_port_init(struct tty_port *port);
+extern int tty_port_alloc_xmit_buf(struct tty_port *port);
+extern void tty_port_free_xmit_buf(struct tty_port *port);
+
 
 
 /* n_tty.c */

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/70] tty updates proposed for 2.6.27, Alan Cox, (Fri Jun 20, 12:57 pm)
[PATCH 01/70] tty: Ldisc revamp, Alan Cox, (Fri Jun 20, 12:58 pm)
[PATCH 02/70] drivers/char/rio/: remove VCS tags, Alan Cox, (Fri Jun 20, 12:58 pm)
[PATCH 03/70] drivers/serial/: remove CVS keywords, Alan Cox, (Fri Jun 20, 12:58 pm)
[PATCH 04/70] tty: Introduce a tty_port common structure, Alan Cox, (Fri Jun 20, 12:58 pm)
[PATCH 05/70] tty.h: clean up, Alan Cox, (Fri Jun 20, 12:58 pm)
[PATCH 06/70] epca: use tty_port, Alan Cox, (Fri Jun 20, 12:59 pm)
[PATCH 07/70] esp: use tty_port, Alan Cox, (Fri Jun 20, 12:59 pm)
[PATCH 08/70] gs: use tty_port, Alan Cox, (Fri Jun 20, 12:59 pm)
[PATCH 09/70] riscom8: use tty_port, Alan Cox, (Fri Jun 20, 12:59 pm)
[PATCH 10/70] riscom8: remove bogus checks, Alan Cox, (Fri Jun 20, 12:59 pm)
[PATCH 11/70] isicom: use tty_port, Alan Cox, (Fri Jun 20, 12:59 pm)
[PATCH 12/70] istallion: use tty_port, Alan Cox, (Fri Jun 20, 12:59 pm)
[PATCH 13/70] moxa: use tty_port, Alan Cox, (Fri Jun 20, 12:59 pm)
[PATCH 14/70] mxser: use tty_port, Alan Cox, (Fri Jun 20, 12:59 pm)
[PATCH 15/70] rocket: use tty_port, Alan Cox, (Fri Jun 20, 1:00 pm)
[PATCH 16/70] serial: use tty_port, Alan Cox, (Fri Jun 20, 1:00 pm)
[PATCH 17/70] stallion: use tty_port, Alan Cox, (Fri Jun 20, 1:00 pm)
[PATCH 18/70] synclink: use tty_port, Alan Cox, (Fri Jun 20, 1:00 pm)
[PATCH 19/70] tty: Clean up tiocmset, Alan Cox, (Fri Jun 20, 1:00 pm)
[PATCH 20/70] cyclades: use tty_port, Alan Cox, (Fri Jun 20, 1:00 pm)
[PATCH 22/70] tty: add more tty_port fields, Alan Cox, (Fri Jun 20, 1:00 pm)
[PATCH 24/70] whiteheat: coding style, Alan Cox, (Fri Jun 20, 1:01 pm)
[PATCH 26/70] belkin_sa: clean up code, Alan Cox, (Fri Jun 20, 1:01 pm)
[PATCH 27/70] usb-serial-bus: tidy coding style, Alan Cox, (Fri Jun 20, 1:01 pm)
[PATCH 29/70] tty-usb-console: Fix termios, Alan Cox, (Fri Jun 20, 1:01 pm)
[PATCH 30/70] cp2101: coding style, Alan Cox, (Fri Jun 20, 1:02 pm)
[PATCH 31/70] cyberjack: Coding style, Alan Cox, (Fri Jun 20, 1:02 pm)
[PATCH 32/70] cypress_m8: coding style, Alan Cox, (Fri Jun 20, 1:02 pm)
[PATCH 34/70] digi_acceleport: coding style, Alan Cox, (Fri Jun 20, 1:02 pm)
[PATCH 35/70] empeg: Coding style, Alan Cox, (Fri Jun 20, 1:02 pm)
[PATCH 36/70] ftdi_sio: Coding style, Alan Cox, (Fri Jun 20, 1:02 pm)
[PATCH 37/70] funsoft: Switch to linux/uaccess, Alan Cox, (Fri Jun 20, 1:02 pm)
[PATCH 38/70] garmin_gps: Coding style, Alan Cox, (Fri Jun 20, 1:03 pm)
[PATCH 39/70] tty-usb-generic: Code cleanup, Alan Cox, (Fri Jun 20, 1:03 pm)
[PATCH 40/70] tty-usb-hp4x: Fix overlong line, Alan Cox, (Fri Jun 20, 1:03 pm)
[PATCH 41/70] tty-usb-visor: Coding style, Alan Cox, (Fri Jun 20, 1:03 pm)
[PATCH 42/70] tty-usb-io_edgeport: Coding style, Alan Cox, (Fri Jun 20, 1:03 pm)
[PATCH 44/70] usb-serial: Coding style, Alan Cox, (Fri Jun 20, 1:03 pm)
[PATCH 45/70] io_ti: Minor coding style, Alan Cox, (Fri Jun 20, 1:04 pm)
[PATCH 46/70] ipaq: Coding style, Alan Cox, (Fri Jun 20, 1:04 pm)
[PATCH 47/70] tty-usb-ipw: Coding style, Alan Cox, (Fri Jun 20, 1:04 pm)
[PATCH 50/70] tty-usb-keyspan: Coding style, Alan Cox, (Fri Jun 20, 1:04 pm)
[PATCH 52/70] tty-usb-keyspan-pda: Coding style, Alan Cox, (Fri Jun 20, 1:04 pm)
[PATCH 53/70] tty-usb-kl5kusb105: Coding style, Alan Cox, (Fri Jun 20, 1:05 pm)
[PATCH 55/70] tty-usb-kobil-sct: Coding style, Alan Cox, (Fri Jun 20, 1:05 pm)
[PATCH 56/70] kobil_sct: Fix ioctls, Alan Cox, (Fri Jun 20, 1:05 pm)
[PATCH 57/70] tty-usb-mct-u232: Coding style, Alan Cox, (Fri Jun 20, 1:05 pm)
[PATCH 58/70] mct_u232: Use flip buffer functions, Alan Cox, (Fri Jun 20, 1:05 pm)
[PATCH 59/70] tty-usb-pl2303: Coding style, Alan Cox, (Fri Jun 20, 1:06 pm)
[PATCH 61/70] tty-usb-spcp8x5: Minor coding style, Alan Cox, (Fri Jun 20, 1:06 pm)
[PATCH 62/70] tty-usb-ti-usb: Coding style, Alan Cox, (Fri Jun 20, 1:06 pm)
[PATCH 63/70] tty-usb-safe-serial: Coding style, Alan Cox, (Fri Jun 20, 1:06 pm)
[PATCH 64/70] tty-usb-oti6858: Coding style, Alan Cox, (Fri Jun 20, 1:06 pm)
[PATCH 65/70] tty-usb-option: Coding style, Alan Cox, (Fri Jun 20, 1:06 pm)
[PATCH 66/70] tty-usb-omninet: Coding style, Alan Cox, (Fri Jun 20, 1:06 pm)
[PATCH 67/70] omninet: Use string flip functions, Alan Cox, (Fri Jun 20, 1:07 pm)
[PATCH 69/70] whiteheat: remove unused variable, Alan Cox, (Fri Jun 20, 1:07 pm)
[PATCH 70/70] tty-usb-mos7720: Coding style, Alan Cox, (Fri Jun 20, 1:07 pm)
Re: [PATCH 00/70] tty updates proposed for 2.6.27, Johannes Weiner, (Fri Jun 20, 4:39 pm)
Re: [PATCH 00/70] tty updates proposed for 2.6.27, Marcel Holtmann, (Sat Jun 21, 6:23 am)
Re: [PATCH 01/70] tty: Ldisc revamp, Louis Rilling, (Mon Jun 23, 6:39 am)
Re: [PATCH 01/70] tty: Ldisc revamp, Alan Cox, (Mon Jun 23, 7:11 am)