5 #include <linux/types.h>
6 #include <linux/errno.h>
8 #include <linux/tty_driver.h>
9 #include <linux/tty_flip.h>
10 #include <linux/timer.h>
11 #include <linux/string.h>
12 #include <linux/slab.h>
13 #include <linux/sched.h>
14 #include <linux/init.h>
15 #include <linux/wait.h>
16 #include <linux/bitops.h>
17 #include <linux/delay.h>
18 #include <linux/module.h>
20 void tty_port_init(struct tty_port *port)
22 memset(port, 0, sizeof(*port));
23 init_waitqueue_head(&port->open_wait);
24 init_waitqueue_head(&port->close_wait);
25 mutex_init(&port->mutex);
26 spin_lock_init(&port->lock);
27 port->close_delay = (50 * HZ) / 100;
28 port->closing_wait = (3000 * HZ) / 100;
30 EXPORT_SYMBOL(tty_port_init);
32 int tty_port_alloc_xmit_buf(struct tty_port *port)
34 /* We may sleep in get_zeroed_page() */
35 mutex_lock(&port->mutex);
36 if (port->xmit_buf == NULL)
37 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
38 mutex_unlock(&port->mutex);
39 if (port->xmit_buf == NULL)
43 EXPORT_SYMBOL(tty_port_alloc_xmit_buf);
45 void tty_port_free_xmit_buf(struct tty_port *port)
47 mutex_lock(&port->mutex);
48 if (port->xmit_buf != NULL) {
49 free_page((unsigned long)port->xmit_buf);
50 port->xmit_buf = NULL;
52 mutex_unlock(&port->mutex);
54 EXPORT_SYMBOL(tty_port_free_xmit_buf);
58 * tty_port_tty_get - get a tty reference
61 * Return a refcount protected tty instance or NULL if the port is not
62 * associated with a tty (eg due to close or hangup)
65 struct tty_struct *tty_port_tty_get(struct tty_port *port)
68 struct tty_struct *tty;
70 spin_lock_irqsave(&port->lock, flags);
71 tty = tty_kref_get(port->tty);
72 spin_unlock_irqrestore(&port->lock, flags);
75 EXPORT_SYMBOL(tty_port_tty_get);
78 * tty_port_tty_set - set the tty of a port
82 * Associate the port and tty pair. Manages any internal refcounts.
83 * Pass NULL to deassociate a port
86 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
90 spin_lock_irqsave(&port->lock, flags);
92 tty_kref_put(port->tty);
94 spin_unlock_irqrestore(&port->lock, flags);
96 EXPORT_SYMBOL(tty_port_tty_set);