From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: linux-kernel@vger.kernel.org, akpm@osdl.org, greg@kroah.com
Subject: [PATCH 01/20] tty: Introduce a tty_port common structure
Date: Mon, 19 May 2008 15:50:13 +0100 [thread overview]
Message-ID: <20080519145013.19326.38344.stgit@core> (raw)
In-Reply-To: <20080519144557.19326.74313.stgit@core>
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.
---
drivers/char/tty_io.c | 37 +++++++++++++++++++++++++++++++++++++
include/linux/tty.h | 29 +++++++++++++++++++++++++++++
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 49c1a22..fb17b18 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -2004,6 +2004,43 @@ 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 7f7121f..a5dc3e9 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -166,6 +166,30 @@ 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
@@ -241,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 */
@@ -351,6 +376,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 */
next prev parent reply other threads:[~2008-05-19 15:02 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-19 14:50 [PATCH 00/20] Implment a tty port structure and supporting logic Alan Cox
2008-05-19 14:50 ` Alan Cox [this message]
2008-05-19 17:47 ` [PATCH 01/20] tty: Introduce a tty_port common structure Sam Ravnborg
2008-05-19 17:51 ` Greg KH
2008-05-19 19:48 ` Alan Cox
2008-05-19 21:36 ` Greg KH
2008-05-19 14:50 ` [PATCH 02/20] tty: Clean up tiocmset Alan Cox
2008-05-19 14:50 ` [PATCH 03/20] epca: use tty_port Alan Cox
2008-05-19 14:50 ` [PATCH 04/20] isicom: " Alan Cox
2008-05-19 14:50 ` [PATCH 05/20] moxa: " Alan Cox
2008-05-19 14:50 ` [PATCH 06/20] mxser: " Alan Cox
2008-05-19 14:50 ` [PATCH 07/20] riscom8: " Alan Cox
2008-05-19 14:50 ` [PATCH 08/20] rocket: " Alan Cox
2008-05-19 14:50 ` [PATCH 09/20] synclink: " Alan Cox
2008-05-19 14:51 ` [PATCH 10/20] esp: " Alan Cox
2008-05-19 14:51 ` [PATCH 11/20] istallion: " Alan Cox
2008-05-19 14:51 ` [PATCH 12/20] stallion: " Alan Cox
2008-05-19 14:51 ` [PATCH 13/20] cyclades: " Alan Cox
2008-05-19 14:51 ` [PATCH 14/20] gs: " Alan Cox
2008-05-19 14:51 ` [PATCH 15/20] serial: " Alan Cox
2008-05-19 14:51 ` [PATCH 17/20] riscom8: remove bogus checks Alan Cox
2008-05-19 14:51 ` [PATCH 18/20] tty: add more tty_port fields Alan Cox
2008-05-19 14:51 ` [PATCH 19/20] whiteheat: coding style Alan Cox
2008-05-19 14:52 ` [PATCH 20/20] whiteheat: fix bugs found in the tidy and audit Alan Cox
2008-05-19 16:50 ` [PATCH 00/20] Implment a tty port structure and supporting logic Greg KH
2008-05-19 18:27 ` Alan Cox
2008-05-20 8:52 ` Andrew Morton
2008-05-20 17:23 ` Greg KH
2008-05-20 18:53 ` Alan Cox
2008-05-19 22:39 ` Aristeu Rozanski
2008-05-20 8:31 ` Alan Cox
2008-05-27 18:05 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080519145013.19326.38344.stgit@core \
--to=alan@lxorguk.ukuu.org.uk \
--cc=akpm@osdl.org \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox