fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / sbus / char / aurora.c
index 1ff81be..a54b4ac 100644 (file)
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/bitops.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/oplib.h>
 #include <asm/system.h>
-#include <asm/bitops.h>
 #include <asm/kdebug.h>
 #include <asm/sbus.h>
 #include <asm/uaccess.h>
@@ -81,10 +81,6 @@ unsigned char irqs[4] = {
 int irqhit=0;
 #endif
 
-#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
 static struct tty_driver *aurora_driver;
 static struct Aurora_board aurora_board[AURORA_NBOARD] = {
        {0,},
@@ -96,7 +92,6 @@ static struct Aurora_port aurora_port[AURORA_TNPORTS] =  {
 
 /* no longer used. static struct Aurora_board * IRQ_to_board[16] = { NULL, } ;*/
 static unsigned char * tmp_buf = NULL;
-static DECLARE_MUTEX(tmp_buf_sem);
 
 DECLARE_TASK_QUEUE(tq_aurora);
 
@@ -128,25 +123,25 @@ static inline int aurora_paranoia_check(struct Aurora_port const * port,
  */
 
 /* Get board number from pointer */
-extern inline int board_No (struct Aurora_board const * bp)
+static inline int board_No (struct Aurora_board const * bp)
 {
        return bp - aurora_board;
 }
 
 /* Get port number from pointer */
-extern inline int port_No (struct Aurora_port const * port)
+static inline int port_No (struct Aurora_port const * port)
 {
        return AURORA_PORT(port - aurora_port); 
 }
 
 /* Get pointer to board from pointer to port */
-extern inline struct Aurora_board * port_Board(struct Aurora_port const * port)
+static inline struct Aurora_board * port_Board(struct Aurora_port const * port)
 {
        return &aurora_board[AURORA_BOARD(port - aurora_port)];
 }
 
 /* Wait for Channel Command Register ready */
-extern inline void aurora_wait_CCR(struct aurora_reg128 * r)
+static inline void aurora_wait_CCR(struct aurora_reg128 * r)
 {
        unsigned long delay;
 
@@ -165,7 +160,7 @@ printk("aurora_wait_CCR\n");
  */
 
 /* Must be called with enabled interrupts */
-extern inline void aurora_long_delay(unsigned long delay)
+static inline void aurora_long_delay(unsigned long delay)
 {
        unsigned long i;
 
@@ -259,7 +254,7 @@ for(i=0;i<TYPE_1_IRQS;i++)
 return 0;
 }
 
-static irqreturn_t aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs);
+static irqreturn_t aurora_interrupt(int irq, void * dev_id);
 
 /* Main probing routine, also sets irq. */
 static int aurora_probe(void)
@@ -342,19 +337,19 @@ static int aurora_probe(void)
                                printk("intr pri %d\n", grrr);
 #endif
                                if ((bp->irq=irqs[bn]) && valid_irq(bp->irq) &&
-                                   !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
+                                   !request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
                                        free_irq(bp->irq|0x30, bp);
                                } else
                                if ((bp->irq=prom_getint(sdev->prom_node, "bintr")) && valid_irq(bp->irq) &&
-                                   !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
+                                   !request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
                                        free_irq(bp->irq|0x30, bp);
                                } else
                                if ((bp->irq=prom_getint(sdev->prom_node, "intr")) && valid_irq(bp->irq) &&
-                                   !request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
+                                   !request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
                                        free_irq(bp->irq|0x30, bp);
                                } else
                                for(grrr=0;grrr<TYPE_1_IRQS;grrr++) {
-                                       if ((bp->irq=type_1_irq[grrr])&&!request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ, "sio16", bp)) {
+                                       if ((bp->irq=type_1_irq[grrr])&&!request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED, "sio16", bp)) {
                                                free_irq(bp->irq|0x30, bp);
                                                break;
                                        } else {
@@ -424,7 +419,7 @@ static void aurora_release_io_range(struct Aurora_board *bp)
        sbus_iounmap((unsigned long)bp->r3, 4);
 }
 
-extern inline void aurora_mark_event(struct Aurora_port * port, int event)
+static inline void aurora_mark_event(struct Aurora_port * port, int event)
 {
 #ifdef AURORA_DEBUG
        printk("aurora_mark_event: start\n");
@@ -594,7 +589,7 @@ static void aurora_transmit(struct Aurora_board const * bp, int chip)
                                            &bp->r[chip]->r[CD180_TDR]);
                                port->COR2 &= ~COR2_ETC;
                        }
-                       count = MIN(port->break_length, 0xff);
+                       count = min(port->break_length, 0xff);
                        sbus_writeb(CD180_C_ESC,
                                    &bp->r[chip]->r[CD180_TDR]);
                        sbus_writeb(CD180_C_DELAY,
@@ -694,7 +689,7 @@ static void aurora_check_modem(struct Aurora_board const * bp, int chip)
 }
 
 /* The main interrupt processing routine */
-static irqreturn_t aurora_interrupt(int irq, void * dev_id, struct pt_regs * regs)
+static irqreturn_t aurora_interrupt(int irq, void * dev_id)
 {
        unsigned char status;
        unsigned char ack,chip/*,chip_id*/;
@@ -875,8 +870,7 @@ static irqreturn_t aurora_interrupt(int irq, void * dev_id, struct pt_regs * reg
 #ifdef AURORA_INT_DEBUG
 static void aurora_timer (unsigned long ignored);
 
-static struct timer_list aurora_poll_timer =
-                       TIMER_INITIALIZER(aurora_timer, 0, 0);
+static DEFINE_TIMER(aurora_poll_timer, aurora_timer, 0, 0);
 
 static void
 aurora_timer (unsigned long ignored)
@@ -915,14 +909,14 @@ static int aurora_setup_board(struct Aurora_board * bp)
 #ifdef AURORA_ALLIRQ
        int i;
        for (i = 0; i < AURORA_ALLIRQ; i++) {
-               error = request_irq(allirq[i]|0x30, aurora_interrupt, SA_SHIRQ,
+               error = request_irq(allirq[i]|0x30, aurora_interrupt, IRQF_SHARED,
                                    "sio16", bp);
                if (error)
                        printk(KERN_ERR "IRQ%d request error %d\n",
                               allirq[i], error);
        }
 #else
-       error = request_irq(bp->irq|0x30, aurora_interrupt, SA_SHIRQ,
+       error = request_irq(bp->irq|0x30, aurora_interrupt, IRQF_SHARED,
                            "sio16", bp);
        if (error) {
                printk(KERN_ERR "IRQ request error %d\n", error);
@@ -1519,8 +1513,7 @@ static void aurora_close(struct tty_struct * tty, struct file * filp)
                 */
                timeout = jiffies+HZ;
                while(port->SRER & SRER_TXEMPTY)  {
-                       current->state = TASK_INTERRUPTIBLE;
-                       schedule_timeout(port->timeout);
+                       msleep_interruptible(jiffies_to_msecs(port->timeout));
                        if (time_after(jiffies, timeout))
                                break;
                }
@@ -1537,8 +1530,7 @@ static void aurora_close(struct tty_struct * tty, struct file * filp)
        port->tty = 0;
        if (port->blocked_open) {
                if (port->close_delay) {
-                       current->state = TASK_INTERRUPTIBLE;
-                       schedule_timeout(port->close_delay);
+                       msleep_interruptible(jiffies_to_msecs(port->close_delay));
                }
                wake_up_interruptible(&port->open_wait);
        }
@@ -1550,7 +1542,7 @@ static void aurora_close(struct tty_struct * tty, struct file * filp)
 #endif
 }
 
-static int aurora_write(struct tty_struct * tty, int from_user, 
+static int aurora_write(struct tty_struct * tty, 
                        const unsigned char *buf, int count)
 {
        struct Aurora_port *port = (struct Aurora_port *) tty->driver_data;
@@ -1573,51 +1565,22 @@ static int aurora_write(struct tty_struct * tty, int from_user,
                return 0;
 
        save_flags(flags);
-       if (from_user) {
-               down(&tmp_buf_sem);
-               while (1) {
-                       c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
-                                          SERIAL_XMIT_SIZE - port->xmit_head));
-                       if (c <= 0)
-                               break;
-
-                       c -= copy_from_user(tmp_buf, buf, c);
-                       if (!c) {
-                               if (!total)
-                                       total = -EFAULT;
-                               break;
-                       }
-                       cli();
-                       c = MIN(c, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
-                                      SERIAL_XMIT_SIZE - port->xmit_head));
-                       memcpy(port->xmit_buf + port->xmit_head, tmp_buf, c);
-                       port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
-                       port->xmit_cnt += c;
+       while (1) {
+               cli();
+               c = min(count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
+                                  SERIAL_XMIT_SIZE - port->xmit_head));
+               if (c <= 0) {
                        restore_flags(flags);
-
-                       buf += c;
-                       count -= c;
-                       total += c;
+                       break;
                }
-               up(&tmp_buf_sem);
-       } else {
-               while (1) {
-                       cli();
-                       c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
-                                          SERIAL_XMIT_SIZE - port->xmit_head));
-                       if (c <= 0) {
-                               restore_flags(flags);
-                               break;
-                       }
-                       memcpy(port->xmit_buf + port->xmit_head, buf, c);
-                       port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
-                       port->xmit_cnt += c;
-                       restore_flags(flags);
+               memcpy(port->xmit_buf + port->xmit_head, buf, c);
+               port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
+               port->xmit_cnt += c;
+               restore_flags(flags);
 
-                       buf += c;
-                       count -= c;
-                       total += c;
-               }
+               buf += c;
+               count -= c;
+               total += c;
        }
 
        cli();
@@ -1916,14 +1879,12 @@ extern int aurora_get_serial_info(struct Aurora_port * port,
 {
        struct serial_struct tmp;
        struct Aurora_board *bp = port_Board(port);
-       int error;
        
 #ifdef AURORA_DEBUG
        printk("aurora_get_serial_info: start\n");
 #endif
-       error = verify_area(VERIFY_WRITE, (void *) retinfo, sizeof(tmp));
-       if (error)
-               return error;
+       if (!access_ok(VERIFY_WRITE, (void *) retinfo, sizeof(tmp)))
+               return -EFAULT;
        
        memset(&tmp, 0, sizeof(tmp));
        tmp.type = PORT_CIRRUS;
@@ -2226,7 +2187,7 @@ static void do_softint(void *private_)
 #endif
 }
 
-static struct tty_operations aurora_ops = {
+static const struct tty_operations aurora_ops = {
        .open  = aurora_open,
        .close = aurora_close,
        .write = aurora_write,
@@ -2368,10 +2329,10 @@ int irq  = 0;
 int irq1 = 0;
 int irq2 = 0;
 int irq3 = 0;
-MODULE_PARM(irq , "i");
-MODULE_PARM(irq1, "i");
-MODULE_PARM(irq2, "i");
-MODULE_PARM(irq3, "i");
+module_param(irq , int, 0);
+module_param(irq1, int, 0);
+module_param(irq2, int, 0);
+module_param(irq3, int, 0);
 
 static int __init aurora_init(void) 
 {