Alan Cox | 9e48565 | 2008-10-13 10:37:07 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Tty port functions |
| 3 | */ |
| 4 | |
| 5 | #include <linux/types.h> |
| 6 | #include <linux/errno.h> |
| 7 | #include <linux/tty.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> |
| 19 | |
| 20 | void tty_port_init(struct tty_port *port) |
| 21 | { |
| 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 | port->close_delay = (50 * HZ) / 100; |
| 27 | port->closing_wait = (3000 * HZ) / 100; |
| 28 | } |
| 29 | EXPORT_SYMBOL(tty_port_init); |
| 30 | |
| 31 | int tty_port_alloc_xmit_buf(struct tty_port *port) |
| 32 | { |
| 33 | /* We may sleep in get_zeroed_page() */ |
| 34 | mutex_lock(&port->mutex); |
| 35 | if (port->xmit_buf == NULL) |
| 36 | port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); |
| 37 | mutex_unlock(&port->mutex); |
| 38 | if (port->xmit_buf == NULL) |
| 39 | return -ENOMEM; |
| 40 | return 0; |
| 41 | } |
| 42 | EXPORT_SYMBOL(tty_port_alloc_xmit_buf); |
| 43 | |
| 44 | void tty_port_free_xmit_buf(struct tty_port *port) |
| 45 | { |
| 46 | mutex_lock(&port->mutex); |
| 47 | if (port->xmit_buf != NULL) { |
| 48 | free_page((unsigned long)port->xmit_buf); |
| 49 | port->xmit_buf = NULL; |
| 50 | } |
| 51 | mutex_unlock(&port->mutex); |
| 52 | } |
| 53 | EXPORT_SYMBOL(tty_port_free_xmit_buf); |
| 54 | |
| 55 | |