aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/serial167.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/serial167.c')
-rw-r--r--drivers/char/serial167.c110
1 files changed, 47 insertions, 63 deletions
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index 21a710cb4bba..af50d32ae2c7 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -62,6 +62,7 @@
62#include <linux/console.h> 62#include <linux/console.h>
63#include <linux/module.h> 63#include <linux/module.h>
64#include <linux/bitops.h> 64#include <linux/bitops.h>
65#include <linux/tty_flip.h>
65 66
66#include <asm/system.h> 67#include <asm/system.h>
67#include <asm/io.h> 68#include <asm/io.h>
@@ -119,17 +120,6 @@ struct cyclades_port cy_port[] = {
119#define NR_PORTS ARRAY_SIZE(cy_port) 120#define NR_PORTS ARRAY_SIZE(cy_port)
120 121
121/* 122/*
122 * tmp_buf is used as a temporary buffer by serial_write. We need to
123 * lock it in case the copy_from_user blocks while swapping in a page,
124 * and some other program tries to do a serial write at the same time.
125 * Since the lock will only come under contention when the system is
126 * swapping and available memory is low, it makes sense to share one
127 * buffer across all the serial ports, since it significantly saves
128 * memory if large numbers of serial ports are open.
129 */
130static unsigned char *tmp_buf = 0;
131
132/*
133 * This is used to look up the divisor speeds and the timeouts 123 * This is used to look up the divisor speeds and the timeouts
134 * We're normally limited to 15 distinct baud rates. The extra 124 * We're normally limited to 15 distinct baud rates. The extra
135 * are accessed via settings in info->flags. 125 * are accessed via settings in info->flags.
@@ -381,7 +371,7 @@ cy_sched_event(struct cyclades_port *info, int event)
381 received, out buffer empty, modem change, etc. 371 received, out buffer empty, modem change, etc.
382 */ 372 */
383static irqreturn_t 373static irqreturn_t
384cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp) 374cd2401_rxerr_interrupt(int irq, void *dev_id)
385{ 375{
386 struct tty_struct *tty; 376 struct tty_struct *tty;
387 struct cyclades_port *info; 377 struct cyclades_port *info;
@@ -438,8 +428,9 @@ cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp)
438 overflowing, we still loose 428 overflowing, we still loose
439 the next incoming character. 429 the next incoming character.
440 */ 430 */
441 tty_insert_flip_char(tty, data, TTY_NORMAL); 431 if (tty_buffer_request_room(tty, 1) != 0){
442 } 432 tty_insert_flip_char(tty, data, TTY_FRAME);
433 }
443 /* These two conditions may imply */ 434 /* These two conditions may imply */
444 /* a normal read should be done. */ 435 /* a normal read should be done. */
445 /* else if(data & CyTIMEOUT) */ 436 /* else if(data & CyTIMEOUT) */
@@ -448,21 +439,21 @@ cd2401_rxerr_interrupt(int irq, void *dev_id, struct pt_regs *fp)
448 tty_insert_flip_char(tty, 0, TTY_NORMAL); 439 tty_insert_flip_char(tty, 0, TTY_NORMAL);
449 } 440 }
450 }else{ 441 }else{
451 tty_insert_flip_char(tty, data, TTY_NORMAL); 442 tty_insert_flip_char(tty, data, TTY_NORMAL);
452 } 443 }
453 }else{ 444 }else{
454 /* there was a software buffer overrun 445 /* there was a software buffer overrun
455 and nothing could be done about it!!! */ 446 and nothing could be done about it!!! */
456 } 447 }
457 } 448 }
458 schedule_delayed_work(&tty->flip.work, 1); 449 tty_schedule_flip(tty);
459 /* end of service */ 450 /* end of service */
460 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS; 451 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
461 return IRQ_HANDLED; 452 return IRQ_HANDLED;
462} /* cy_rxerr_interrupt */ 453} /* cy_rxerr_interrupt */
463 454
464static irqreturn_t 455static irqreturn_t
465cd2401_modem_interrupt(int irq, void *dev_id, struct pt_regs *fp) 456cd2401_modem_interrupt(int irq, void *dev_id)
466{ 457{
467 struct cyclades_port *info; 458 struct cyclades_port *info;
468 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 459 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
@@ -517,7 +508,7 @@ cd2401_modem_interrupt(int irq, void *dev_id, struct pt_regs *fp)
517} /* cy_modem_interrupt */ 508} /* cy_modem_interrupt */
518 509
519static irqreturn_t 510static irqreturn_t
520cd2401_tx_interrupt(int irq, void *dev_id, struct pt_regs *fp) 511cd2401_tx_interrupt(int irq, void *dev_id)
521{ 512{
522 struct cyclades_port *info; 513 struct cyclades_port *info;
523 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 514 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
@@ -637,7 +628,7 @@ cd2401_tx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
637} /* cy_tx_interrupt */ 628} /* cy_tx_interrupt */
638 629
639static irqreturn_t 630static irqreturn_t
640cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp) 631cd2401_rx_interrupt(int irq, void *dev_id)
641{ 632{
642 struct tty_struct *tty; 633 struct tty_struct *tty;
643 struct cyclades_port *info; 634 struct cyclades_port *info;
@@ -646,6 +637,7 @@ cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
646 char data; 637 char data;
647 int char_count; 638 int char_count;
648 int save_cnt; 639 int save_cnt;
640 int len;
649 641
650 /* determine the channel and change to that context */ 642 /* determine the channel and change to that context */
651 channel = (u_short ) (base_addr[CyLICR] >> 2); 643 channel = (u_short ) (base_addr[CyLICR] >> 2);
@@ -678,14 +670,15 @@ cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
678 info->mon.char_max = char_count; 670 info->mon.char_max = char_count;
679 info->mon.char_last = char_count; 671 info->mon.char_last = char_count;
680#endif 672#endif
681 while(char_count--){ 673 len = tty_buffer_request_room(tty, char_count);
674 while(len--){
682 data = base_addr[CyRDR]; 675 data = base_addr[CyRDR];
683 tty_insert_flip_char(tty, data, TTY_NORMAL); 676 tty_insert_flip_char(tty, data, TTY_NORMAL);
684#ifdef CYCLOM_16Y_HACK 677#ifdef CYCLOM_16Y_HACK
685 udelay(10L); 678 udelay(10L);
686#endif 679#endif
687 } 680 }
688 schedule_delayed_work(&tty->flip.work, 1); 681 tty_schedule_flip(tty);
689 } 682 }
690 /* end of service */ 683 /* end of service */
691 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS; 684 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
@@ -713,9 +706,9 @@ cd2401_rx_interrupt(int irq, void *dev_id, struct pt_regs *fp)
713 * had to poll every port to see if that port needed servicing. 706 * had to poll every port to see if that port needed servicing.
714 */ 707 */
715static void 708static void
716do_softint(void *private_) 709do_softint(struct work_struct *ugly_api)
717{ 710{
718 struct cyclades_port *info = (struct cyclades_port *) private_; 711 struct cyclades_port *info = container_of(ugly_api, struct cyclades_port, tqueue);
719 struct tty_struct *tty; 712 struct tty_struct *tty;
720 713
721 tty = info->tty; 714 tty = info->tty;
@@ -846,7 +839,7 @@ shutdown(struct cyclades_port * info)
846 local_irq_save(flags); 839 local_irq_save(flags);
847 if (info->xmit_buf){ 840 if (info->xmit_buf){
848 free_page((unsigned long) info->xmit_buf); 841 free_page((unsigned long) info->xmit_buf);
849 info->xmit_buf = 0; 842 info->xmit_buf = NULL;
850 } 843 }
851 844
852 base_addr[CyCAR] = (u_char)channel; 845 base_addr[CyCAR] = (u_char)channel;
@@ -1132,7 +1125,7 @@ cy_put_char(struct tty_struct *tty, unsigned char ch)
1132 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 1125 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1133 return; 1126 return;
1134 1127
1135 if (!tty || !info->xmit_buf) 1128 if (!info->xmit_buf)
1136 return; 1129 return;
1137 1130
1138 local_irq_save(flags); 1131 local_irq_save(flags);
@@ -1198,7 +1191,7 @@ cy_write(struct tty_struct * tty,
1198 return 0; 1191 return 0;
1199 } 1192 }
1200 1193
1201 if (!tty || !info->xmit_buf || !tmp_buf){ 1194 if (!info->xmit_buf){
1202 return 0; 1195 return 0;
1203 } 1196 }
1204 1197
@@ -1361,7 +1354,7 @@ cy_unthrottle(struct tty_struct * tty)
1361 1354
1362static int 1355static int
1363get_serial_info(struct cyclades_port * info, 1356get_serial_info(struct cyclades_port * info,
1364 struct serial_struct * retinfo) 1357 struct serial_struct __user * retinfo)
1365{ 1358{
1366 struct serial_struct tmp; 1359 struct serial_struct tmp;
1367 1360
@@ -1383,7 +1376,7 @@ get_serial_info(struct cyclades_port * info,
1383 1376
1384static int 1377static int
1385set_serial_info(struct cyclades_port * info, 1378set_serial_info(struct cyclades_port * info,
1386 struct serial_struct * new_info) 1379 struct serial_struct __user * new_info)
1387{ 1380{
1388 struct serial_struct new_serial; 1381 struct serial_struct new_serial;
1389 struct cyclades_port old_info; 1382 struct cyclades_port old_info;
@@ -1433,7 +1426,6 @@ cy_tiocmget(struct tty_struct *tty, struct file *file)
1433 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1426 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1434 unsigned long flags; 1427 unsigned long flags;
1435 unsigned char status; 1428 unsigned char status;
1436 unsigned int result;
1437 1429
1438 channel = info->line; 1430 channel = info->line;
1439 1431
@@ -1457,7 +1449,6 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
1457 int channel; 1449 int channel;
1458 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1450 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1459 unsigned long flags; 1451 unsigned long flags;
1460 unsigned int arg;
1461 1452
1462 channel = info->line; 1453 channel = info->line;
1463 1454
@@ -1512,7 +1503,7 @@ send_break( struct cyclades_port * info, int duration)
1512} /* send_break */ 1503} /* send_break */
1513 1504
1514static int 1505static int
1515get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon) 1506get_mon_info(struct cyclades_port * info, struct cyclades_monitor __user * mon)
1516{ 1507{
1517 1508
1518 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor))) 1509 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
@@ -1525,7 +1516,7 @@ get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
1525} 1516}
1526 1517
1527static int 1518static int
1528set_threshold(struct cyclades_port * info, unsigned long *arg) 1519set_threshold(struct cyclades_port * info, unsigned long __user *arg)
1529{ 1520{
1530 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1521 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1531 unsigned long value; 1522 unsigned long value;
@@ -1542,7 +1533,7 @@ set_threshold(struct cyclades_port * info, unsigned long *arg)
1542} 1533}
1543 1534
1544static int 1535static int
1545get_threshold(struct cyclades_port * info, unsigned long *value) 1536get_threshold(struct cyclades_port * info, unsigned long __user *value)
1546{ 1537{
1547 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1538 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1548 int channel; 1539 int channel;
@@ -1555,7 +1546,7 @@ get_threshold(struct cyclades_port * info, unsigned long *value)
1555} 1546}
1556 1547
1557static int 1548static int
1558set_default_threshold(struct cyclades_port * info, unsigned long *arg) 1549set_default_threshold(struct cyclades_port * info, unsigned long __user *arg)
1559{ 1550{
1560 unsigned long value; 1551 unsigned long value;
1561 1552
@@ -1567,13 +1558,13 @@ set_default_threshold(struct cyclades_port * info, unsigned long *arg)
1567} 1558}
1568 1559
1569static int 1560static int
1570get_default_threshold(struct cyclades_port * info, unsigned long *value) 1561get_default_threshold(struct cyclades_port * info, unsigned long __user *value)
1571{ 1562{
1572 return put_user(info->default_threshold,value); 1563 return put_user(info->default_threshold,value);
1573} 1564}
1574 1565
1575static int 1566static int
1576set_timeout(struct cyclades_port * info, unsigned long *arg) 1567set_timeout(struct cyclades_port * info, unsigned long __user *arg)
1577{ 1568{
1578 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1569 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1579 int channel; 1570 int channel;
@@ -1590,7 +1581,7 @@ set_timeout(struct cyclades_port * info, unsigned long *arg)
1590} 1581}
1591 1582
1592static int 1583static int
1593get_timeout(struct cyclades_port * info, unsigned long *value) 1584get_timeout(struct cyclades_port * info, unsigned long __user *value)
1594{ 1585{
1595 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1586 volatile unsigned char *base_addr = (u_char *)BASE_ADDR;
1596 int channel; 1587 int channel;
@@ -1610,7 +1601,7 @@ set_default_timeout(struct cyclades_port * info, unsigned long value)
1610} 1601}
1611 1602
1612static int 1603static int
1613get_default_timeout(struct cyclades_port * info, unsigned long *value) 1604get_default_timeout(struct cyclades_port * info, unsigned long __user *value)
1614{ 1605{
1615 return put_user(info->default_timeout,value); 1606 return put_user(info->default_timeout,value);
1616} 1607}
@@ -1622,6 +1613,7 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
1622 unsigned long val; 1613 unsigned long val;
1623 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1614 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
1624 int ret_val = 0; 1615 int ret_val = 0;
1616 void __user *argp = (void __user *)arg;
1625 1617
1626#ifdef SERIAL_DEBUG_OTHER 1618#ifdef SERIAL_DEBUG_OTHER
1627 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */ 1619 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
@@ -1629,28 +1621,28 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
1629 1621
1630 switch (cmd) { 1622 switch (cmd) {
1631 case CYGETMON: 1623 case CYGETMON:
1632 ret_val = get_mon_info(info, (struct cyclades_monitor *)arg); 1624 ret_val = get_mon_info(info, argp);
1633 break; 1625 break;
1634 case CYGETTHRESH: 1626 case CYGETTHRESH:
1635 ret_val = get_threshold(info, (unsigned long *)arg); 1627 ret_val = get_threshold(info, argp);
1636 break; 1628 break;
1637 case CYSETTHRESH: 1629 case CYSETTHRESH:
1638 ret_val = set_threshold(info, (unsigned long *)arg); 1630 ret_val = set_threshold(info, argp);
1639 break; 1631 break;
1640 case CYGETDEFTHRESH: 1632 case CYGETDEFTHRESH:
1641 ret_val = get_default_threshold(info, (unsigned long *)arg); 1633 ret_val = get_default_threshold(info, argp);
1642 break; 1634 break;
1643 case CYSETDEFTHRESH: 1635 case CYSETDEFTHRESH:
1644 ret_val = set_default_threshold(info, (unsigned long *)arg); 1636 ret_val = set_default_threshold(info, argp);
1645 break; 1637 break;
1646 case CYGETTIMEOUT: 1638 case CYGETTIMEOUT:
1647 ret_val = get_timeout(info, (unsigned long *)arg); 1639 ret_val = get_timeout(info, argp);
1648 break; 1640 break;
1649 case CYSETTIMEOUT: 1641 case CYSETTIMEOUT:
1650 ret_val = set_timeout(info, (unsigned long *)arg); 1642 ret_val = set_timeout(info, argp);
1651 break; 1643 break;
1652 case CYGETDEFTIMEOUT: 1644 case CYGETDEFTIMEOUT:
1653 ret_val = get_default_timeout(info, (unsigned long *)arg); 1645 ret_val = get_default_timeout(info, argp);
1654 break; 1646 break;
1655 case CYSETDEFTIMEOUT: 1647 case CYSETDEFTIMEOUT:
1656 ret_val = set_default_timeout(info, (unsigned long)arg); 1648 ret_val = set_default_timeout(info, (unsigned long)arg);
@@ -1673,21 +1665,20 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
1673 1665
1674/* The following commands are incompletely implemented!!! */ 1666/* The following commands are incompletely implemented!!! */
1675 case TIOCGSOFTCAR: 1667 case TIOCGSOFTCAR:
1676 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg); 1668 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) argp);
1677 break; 1669 break;
1678 case TIOCSSOFTCAR: 1670 case TIOCSSOFTCAR:
1679 ret_val = get_user(val, (unsigned long *) arg); 1671 ret_val = get_user(val, (unsigned long __user *) argp);
1680 if (ret_val) 1672 if (ret_val)
1681 break; 1673 break;
1682 tty->termios->c_cflag = 1674 tty->termios->c_cflag =
1683 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0)); 1675 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1684 break; 1676 break;
1685 case TIOCGSERIAL: 1677 case TIOCGSERIAL:
1686 ret_val = get_serial_info(info, (struct serial_struct *) arg); 1678 ret_val = get_serial_info(info, argp);
1687 break; 1679 break;
1688 case TIOCSSERIAL: 1680 case TIOCSSERIAL:
1689 ret_val = set_serial_info(info, 1681 ret_val = set_serial_info(info, argp);
1690 (struct serial_struct *) arg);
1691 break; 1682 break;
1692 default: 1683 default:
1693 ret_val = -ENOIOCTLCMD; 1684 ret_val = -ENOIOCTLCMD;
@@ -1704,7 +1695,7 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
1704 1695
1705 1696
1706static void 1697static void
1707cy_set_termios(struct tty_struct *tty, struct termios * old_termios) 1698cy_set_termios(struct tty_struct *tty, struct ktermios * old_termios)
1708{ 1699{
1709 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1700 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1710 1701
@@ -1782,7 +1773,7 @@ cy_close(struct tty_struct * tty, struct file * filp)
1782 tty->driver->flush_buffer(tty); 1773 tty->driver->flush_buffer(tty);
1783 tty_ldisc_flush(tty); 1774 tty_ldisc_flush(tty);
1784 info->event = 0; 1775 info->event = 0;
1785 info->tty = 0; 1776 info->tty = NULL;
1786 if (info->blocked_open) { 1777 if (info->blocked_open) {
1787 if (info->close_delay) { 1778 if (info->close_delay) {
1788 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 1779 msleep_interruptible(jiffies_to_msecs(info->close_delay));
@@ -1983,13 +1974,6 @@ cy_open(struct tty_struct *tty, struct file * filp)
1983 tty->driver_data = info; 1974 tty->driver_data = info;
1984 info->tty = tty; 1975 info->tty = tty;
1985 1976
1986 if (!tmp_buf) {
1987 tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL);
1988 if (!tmp_buf){
1989 return -ENOMEM;
1990 }
1991 }
1992
1993 /* 1977 /*
1994 * Start up serial port 1978 * Start up serial port
1995 */ 1979 */
@@ -2158,7 +2142,7 @@ mvme167_serial_console_setup(int cflag)
2158 rcor >> 5, rbpr); 2142 rcor >> 5, rbpr);
2159} /* serial_console_init */ 2143} /* serial_console_init */
2160 2144
2161static struct tty_operations cy_ops = { 2145static const struct tty_operations cy_ops = {
2162 .open = cy_open, 2146 .open = cy_open,
2163 .close = cy_close, 2147 .close = cy_close,
2164 .write = cy_write, 2148 .write = cy_write,
@@ -2266,7 +2250,7 @@ scrn[1] = '\0';
2266 info->card = index; 2250 info->card = index;
2267 info->line = port_num; 2251 info->line = port_num;
2268 info->flags = STD_COM_FLAGS; 2252 info->flags = STD_COM_FLAGS;
2269 info->tty = 0; 2253 info->tty = NULL;
2270 info->xmit_fifo_size = 12; 2254 info->xmit_fifo_size = 12;
2271 info->cor1 = CyPARITY_NONE|Cy_8_BITS; 2255 info->cor1 = CyPARITY_NONE|Cy_8_BITS;
2272 info->cor2 = CyETC; 2256 info->cor2 = CyETC;
@@ -2289,7 +2273,7 @@ scrn[1] = '\0';
2289 info->blocked_open = 0; 2273 info->blocked_open = 0;
2290 info->default_threshold = 0; 2274 info->default_threshold = 0;
2291 info->default_timeout = 0; 2275 info->default_timeout = 0;
2292 INIT_WORK(&info->tqueue, do_softint, info); 2276 INIT_WORK(&info->tqueue, do_softint);
2293 init_waitqueue_head(&info->open_wait); 2277 init_waitqueue_head(&info->open_wait);
2294 init_waitqueue_head(&info->close_wait); 2278 init_waitqueue_head(&info->close_wait);
2295 /* info->session */ 2279 /* info->session */