linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / char / istallion.c
index 84dfc42..28c5a31 100644 (file)
@@ -26,6 +26,7 @@
 
 /*****************************************************************************/
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 #include <linux/delay.h>
 #include <linux/init.h>
+#include <linux/devfs_fs_kernel.h>
 #include <linux/device.h>
 #include <linux/wait.h>
-#include <linux/eisa.h>
 
 #include <asm/io.h>
 #include <asm/uaccess.h>
 
+#ifdef CONFIG_PCI
 #include <linux/pci.h>
+#endif
 
 /*****************************************************************************/
 
@@ -134,10 +137,6 @@ static stlconf_t   stli_brdconf[] = {
 
 static int     stli_nrbrds = ARRAY_SIZE(stli_brdconf);
 
-/* stli_lock must NOT be taken holding brd_lock */
-static spinlock_t stli_lock;   /* TTY logic lock */
-static spinlock_t brd_lock;    /* Board logic lock */
-
 /*
  *     There is some experimental EISA board detection code in this driver.
  *     By default it is disabled, but for those that want to try it out,
@@ -174,6 +173,15 @@ static char        *stli_serialname = "ttyE";
 
 static struct tty_driver       *stli_serial;
 
+/*
+ *     We will need to allocate a temporary write buffer for chars that
+ *     come direct from user space. The problem is that a copy from user
+ *     space might cause a page fault (typically on a system that is
+ *     swapping!). All ports will share one buffer - since if the system
+ *     is already swapping a shared buffer won't make things any worse.
+ */
+static char                    *stli_tmpwritebuf;
+static DECLARE_MUTEX(stli_tmpwritesem);
 
 #define        STLI_TXBUFSIZE          4096
 
@@ -281,6 +289,7 @@ static char *stli_brdnames[] = {
 
 /*****************************************************************************/
 
+#ifdef MODULE
 /*
  *     Define some string labels for arguments passed from the module
  *     load line. These allow for easy board definitions, and easy
@@ -370,15 +379,17 @@ MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
 MODULE_LICENSE("GPL");
 
 
-module_param_array(board0, charp, NULL, 0);
+MODULE_PARM(board0, "1-3s");
 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
-module_param_array(board1, charp, NULL, 0);
+MODULE_PARM(board1, "1-3s");
 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
-module_param_array(board2, charp, NULL, 0);
+MODULE_PARM(board2, "1-3s");
 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
-module_param_array(board3, charp, NULL, 0);
+MODULE_PARM(board3, "1-3s");
 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
 
+#endif
+
 /*
  *     Set up a default memory address table for EISA board probing.
  *     The default addresses are all bellow 1Mbyte, which has to be the
@@ -409,7 +420,7 @@ static int  stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
 #endif
 
 static struct pci_device_id istallion_pci_tbl[] = {
-       { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
+       { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
@@ -639,8 +650,14 @@ static unsigned int        stli_baudrates[] = {
  *     Prototype all functions in this driver!
  */
 
+#ifdef MODULE
+static void    stli_argbrds(void);
 static int     stli_parsebrd(stlconf_t *confp, char **argp);
-static int     stli_init(void);
+
+static unsigned long   stli_atol(char *str);
+#endif
+
+int            stli_init(void);
 static int     stli_open(struct tty_struct *tty, struct file *filp);
 static void    stli_close(struct tty_struct *tty, struct file *filp);
 static int     stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
@@ -666,7 +683,7 @@ static int  stli_startbrd(stlibrd_t *brdp);
 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
 static int     stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
-static void    stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
+static void    stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp);
 static void    stli_poll(unsigned long arg);
 static int     stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
 static int     stli_initopen(stlibrd_t *brdp, stliport_t *portp);
@@ -677,8 +694,7 @@ static void stli_dohangup(void *arg);
 static int     stli_setport(stliport_t *portp);
 static int     stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
 static void    stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
-static void    __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
-static void    stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
+static void    stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp);
 static void    stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
 static void    stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
 static long    stli_mktiocm(unsigned long sigvalue);
@@ -691,6 +707,7 @@ static int  stli_portcmdstats(stliport_t *portp);
 static int     stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
 static int     stli_getportstruct(stliport_t __user *arg);
 static int     stli_getbrdstruct(stlibrd_t __user *arg);
+static void    *stli_memalloc(int len);
 static stlibrd_t *stli_allocbrd(void);
 
 static void    stli_ecpinit(stlibrd_t *brdp);
@@ -748,7 +765,7 @@ static int  stli_initpcibrd(int brdtype, struct pci_dev *devp);
  *     will give access to the shared memory on the Stallion intelligent
  *     board. This is also a very useful debugging tool.
  */
-static const struct file_operations    stli_fsiomem = {
+static struct file_operations  stli_fsiomem = {
        .owner          = THIS_MODULE,
        .read           = stli_memread,
        .write          = stli_memwrite,
@@ -776,14 +793,26 @@ static int        stli_timeron;
 
 static struct class *istallion_class;
 
+#ifdef MODULE
+
 /*
  *     Loadable module initialization stuff.
  */
 
 static int __init istallion_module_init(void)
 {
+       unsigned long   flags;
+
+#ifdef DEBUG
+       printk("init_module()\n");
+#endif
+
+       save_flags(flags);
+       cli();
        stli_init();
-       return 0;
+       restore_flags(flags);
+
+       return(0);
 }
 
 /*****************************************************************************/
@@ -792,43 +821,56 @@ static void __exit istallion_module_exit(void)
 {
        stlibrd_t       *brdp;
        stliport_t      *portp;
+       unsigned long   flags;
        int             i, j;
 
+#ifdef DEBUG
+       printk("cleanup_module()\n");
+#endif
+
        printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
                stli_drvversion);
 
-       /*
-        *      Free up all allocated resources used by the ports. This includes
-        *      memory and interrupts.
-        */
+       save_flags(flags);
+       cli();
+
+/*
+ *     Free up all allocated resources used by the ports. This includes
+ *     memory and interrupts.
+ */
        if (stli_timeron) {
                stli_timeron = 0;
-               del_timer_sync(&stli_timerlist);
+               del_timer(&stli_timerlist);
        }
 
        i = tty_unregister_driver(stli_serial);
        if (i) {
                printk("STALLION: failed to un-register tty driver, "
                        "errno=%d\n", -i);
+               restore_flags(flags);
                return;
        }
        put_tty_driver(stli_serial);
-       for (i = 0; i < 4; i++)
+       for (i = 0; i < 4; i++) {
+               devfs_remove("staliomem/%d", i);
                class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
+       }
+       devfs_remove("staliomem");
        class_destroy(istallion_class);
        if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
                printk("STALLION: failed to un-register serial memory device, "
                        "errno=%d\n", -i);
 
+       kfree(stli_tmpwritebuf);
        kfree(stli_txcookbuf);
 
        for (i = 0; (i < stli_nrbrds); i++) {
-               if ((brdp = stli_brds[i]) == NULL)
+               if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL)
                        continue;
                for (j = 0; (j < STL_MAXPORTS); j++) {
                        portp = brdp->ports[j];
-                       if (portp != NULL) {
-                               if (portp->tty != NULL)
+                       if (portp != (stliport_t *) NULL) {
+                               if (portp->tty != (struct tty_struct *) NULL)
                                        tty_hangup(portp->tty);
                                kfree(portp);
                        }
@@ -838,8 +880,10 @@ static void __exit istallion_module_exit(void)
                if (brdp->iosize > 0)
                        release_region(brdp->iobase, brdp->iosize);
                kfree(brdp);
-               stli_brds[i] = NULL;
+               stli_brds[i] = (stlibrd_t *) NULL;
        }
+
+       restore_flags(flags);
 }
 
 module_init(istallion_module_init);
@@ -853,15 +897,19 @@ module_exit(istallion_module_exit);
 
 static void stli_argbrds(void)
 {
-       stlconf_t conf;
-       stlibrd_t *brdp;
-       int i;
+       stlconf_t       conf;
+       stlibrd_t       *brdp;
+       int             i;
+
+#ifdef DEBUG
+       printk("stli_argbrds()\n");
+#endif
 
        for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
                memset(&conf, 0, sizeof(conf));
                if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
                        continue;
-               if ((brdp = stli_allocbrd()) == NULL)
+               if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
                        continue;
                stli_nrbrds = i + 1;
                brdp->brdnr = i;
@@ -880,9 +928,9 @@ static void stli_argbrds(void)
 
 static unsigned long stli_atol(char *str)
 {
-       unsigned long val;
-       int base, c;
-       char *sp;
+       unsigned long   val;
+       int             base, c;
+       char            *sp;
 
        val = 0;
        sp = str;
@@ -916,11 +964,15 @@ static unsigned long stli_atol(char *str)
 
 static int stli_parsebrd(stlconf_t *confp, char **argp)
 {
-       char *sp;
-       int i;
+       char    *sp;
+       int     i;
 
-       if (argp[0] == NULL || *argp[0] == 0)
-               return 0;
+#ifdef DEBUG
+       printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
+#endif
+
+       if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
+               return(0);
 
        for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
                *sp = TOLOWER(*sp);
@@ -935,40 +987,58 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
        }
 
        confp->brdtype = stli_brdstr[i].type;
-       if (argp[1] != NULL && *argp[1] != 0)
+       if ((argp[1] != (char *) NULL) && (*argp[1] != 0))
                confp->ioaddr1 = stli_atol(argp[1]);
-       if (argp[2] !=  NULL && *argp[2] != 0)
+       if ((argp[2] != (char *) NULL) && (*argp[2] != 0))
                confp->memaddr = stli_atol(argp[2]);
        return(1);
 }
 
+#endif
+
+/*****************************************************************************/
+
+/*
+ *     Local driver kernel malloc routine.
+ */
+
+static void *stli_memalloc(int len)
+{
+       return((void *) kmalloc(len, GFP_KERNEL));
+}
+
 /*****************************************************************************/
 
 static int stli_open(struct tty_struct *tty, struct file *filp)
 {
-       stlibrd_t *brdp;
-       stliport_t *portp;
-       unsigned int minordev;
-       int brdnr, portnr, rc;
+       stlibrd_t       *brdp;
+       stliport_t      *portp;
+       unsigned int    minordev;
+       int             brdnr, portnr, rc;
+
+#ifdef DEBUG
+       printk("stli_open(tty=%x,filp=%x): device=%s\n", (int) tty,
+               (int) filp, tty->name);
+#endif
 
        minordev = tty->index;
        brdnr = MINOR2BRD(minordev);
        if (brdnr >= stli_nrbrds)
-               return -ENODEV;
+               return(-ENODEV);
        brdp = stli_brds[brdnr];
-       if (brdp == NULL)
-               return -ENODEV;
+       if (brdp == (stlibrd_t *) NULL)
+               return(-ENODEV);
        if ((brdp->state & BST_STARTED) == 0)
-               return -ENODEV;
+               return(-ENODEV);
        portnr = MINOR2PORT(minordev);
        if ((portnr < 0) || (portnr > brdp->nrports))
-               return -ENODEV;
+               return(-ENODEV);
 
        portp = brdp->ports[portnr];
-       if (portp == NULL)
-               return -ENODEV;
+       if (portp == (stliport_t *) NULL)
+               return(-ENODEV);
        if (portp->devnr < 1)
-               return -ENODEV;
+               return(-ENODEV);
 
 
 /*
@@ -980,8 +1050,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
        if (portp->flags & ASYNC_CLOSING) {
                interruptible_sleep_on(&portp->close_wait);
                if (portp->flags & ASYNC_HUP_NOTIFY)
-                       return -EAGAIN;
-               return -ERESTARTSYS;
+                       return(-EAGAIN);
+               return(-ERESTARTSYS);
        }
 
 /*
@@ -997,7 +1067,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_INITIALIZING, &portp->state));
        if (signal_pending(current))
-               return -ERESTARTSYS;
+               return(-ERESTARTSYS);
 
        if ((portp->flags & ASYNC_INITIALIZED) == 0) {
                set_bit(ST_INITIALIZING, &portp->state);
@@ -1008,7 +1078,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
                clear_bit(ST_INITIALIZING, &portp->state);
                wake_up_interruptible(&portp->raw_wait);
                if (rc < 0)
-                       return rc;
+                       return(rc);
        }
 
 /*
@@ -1020,8 +1090,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
        if (portp->flags & ASYNC_CLOSING) {
                interruptible_sleep_on(&portp->close_wait);
                if (portp->flags & ASYNC_HUP_NOTIFY)
-                       return -EAGAIN;
-               return -ERESTARTSYS;
+                       return(-EAGAIN);
+               return(-ERESTARTSYS);
        }
 
 /*
@@ -1031,33 +1101,38 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
  */
        if (!(filp->f_flags & O_NONBLOCK)) {
                if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
-                       return rc;
+                       return(rc);
        }
        portp->flags |= ASYNC_NORMAL_ACTIVE;
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
 
 static void stli_close(struct tty_struct *tty, struct file *filp)
 {
-       stlibrd_t *brdp;
-       stliport_t *portp;
-       unsigned long flags;
+       stlibrd_t       *brdp;
+       stliport_t      *portp;
+       unsigned long   flags;
+
+#ifdef DEBUG
+       printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
+#endif
 
        portp = tty->driver_data;
-       if (portp == NULL)
+       if (portp == (stliport_t *) NULL)
                return;
 
-       spin_lock_irqsave(&stli_lock, flags);
+       save_flags(flags);
+       cli();
        if (tty_hung_up_p(filp)) {
-               spin_unlock_irqrestore(&stli_lock, flags);
+               restore_flags(flags);
                return;
        }
        if ((tty->count == 1) && (portp->refcount != 1))
                portp->refcount = 1;
        if (portp->refcount-- > 1) {
-               spin_unlock_irqrestore(&stli_lock, flags);
+               restore_flags(flags);
                return;
        }
 
@@ -1072,8 +1147,6 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
        if (tty == stli_txcooktty)
                stli_flushchars(tty);
        tty->closing = 1;
-       spin_unlock_irqrestore(&stli_lock, flags);
-
        if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
                tty_wait_until_sent(tty, portp->closing_wait);
 
@@ -1097,7 +1170,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
        stli_flushbuffer(tty);
 
        tty->closing = 0;
-       portp->tty = NULL;
+       portp->tty = (struct tty_struct *) NULL;
 
        if (portp->openwaitcnt) {
                if (portp->close_delay)
@@ -1107,6 +1180,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
 
        portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
        wake_up_interruptible(&portp->close_wait);
+       restore_flags(flags);
 }
 
 /*****************************************************************************/
@@ -1121,41 +1195,45 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
 
 static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
 {
-       struct tty_struct *tty;
-       asynotify_t nt;
-       asyport_t aport;
-       int rc;
+       struct tty_struct       *tty;
+       asynotify_t             nt;
+       asyport_t               aport;
+       int                     rc;
+
+#ifdef DEBUG
+       printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
+#endif
 
        if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
-               return rc;
+               return(rc);
 
        memset(&nt, 0, sizeof(asynotify_t));
        nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
        nt.signal = SG_DCD;
        if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
            sizeof(asynotify_t), 0)) < 0)
-               return rc;
+               return(rc);
 
        tty = portp->tty;
-       if (tty == NULL)
-               return -ENODEV;
+       if (tty == (struct tty_struct *) NULL)
+               return(-ENODEV);
        stli_mkasyport(portp, &aport, tty->termios);
        if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
            sizeof(asyport_t), 0)) < 0)
-               return rc;
+               return(rc);
 
        set_bit(ST_GETSIGS, &portp->state);
        if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
            sizeof(asysigs_t), 1)) < 0)
-               return rc;
+               return(rc);
        if (test_and_clear_bit(ST_GETSIGS, &portp->state))
                portp->sigs = stli_mktiocm(portp->asig.sigvalue);
        stli_mkasysigs(&portp->asig, 1, 1);
        if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
            sizeof(asysigs_t), 0)) < 0)
-               return rc;
+               return(rc);
 
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -1169,15 +1247,22 @@ static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
 
 static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
 {
-       cdkhdr_t __iomem *hdrp;
-       cdkctrl_t __iomem *cp;
-       unsigned char __iomem *bits;
-       unsigned long flags;
-       int rc;
+       volatile cdkhdr_t       *hdrp;
+       volatile cdkctrl_t      *cp;
+       volatile unsigned char  *bits;
+       unsigned long           flags;
+       int                     rc;
+
+#ifdef DEBUG
+       printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
+               (int) brdp, (int) portp, (int) arg, wait);
+#endif
 
 /*
  *     Send a message to the slave to open this port.
  */
+       save_flags(flags);
+       cli();
 
 /*
  *     Slave is already closing this port. This can happen if a hangup
@@ -1188,6 +1273,7 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_CLOSING, &portp->state));
        if (signal_pending(current)) {
+               restore_flags(flags);
                return -ERESTARTSYS;
        }
 
@@ -1196,20 +1282,19 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
  *     memory. Once the message is in set the service bits to say that
  *     this port wants service.
  */
-       spin_lock_irqsave(&brd_lock, flags);
        EBRDENABLE(brdp);
-       cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
-       writel(arg, &cp->openarg);
-       writeb(1, &cp->open);
-       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
+       cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
+       cp->openarg = arg;
+       cp->open = 1;
+       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
                portp->portidx;
-       writeb(readb(bits) | portp->portbit, bits);
+       *bits |= portp->portbit;
        EBRDDISABLE(brdp);
 
        if (wait == 0) {
-               spin_unlock_irqrestore(&brd_lock, flags);
-               return 0;
+               restore_flags(flags);
+               return(0);
        }
 
 /*
@@ -1218,16 +1303,15 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
  */
        rc = 0;
        set_bit(ST_OPENING, &portp->state);
-       spin_unlock_irqrestore(&brd_lock, flags);
-
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_OPENING, &portp->state));
        if (signal_pending(current))
                rc = -ERESTARTSYS;
+       restore_flags(flags);
 
        if ((rc == 0) && (portp->rc != 0))
                rc = -EIO;
-       return rc;
+       return(rc);
 }
 
 /*****************************************************************************/
@@ -1240,11 +1324,19 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
 
 static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
 {
-       cdkhdr_t __iomem *hdrp;
-       cdkctrl_t __iomem *cp;
-       unsigned char __iomem *bits;
-       unsigned long flags;
-       int rc;
+       volatile cdkhdr_t       *hdrp;
+       volatile cdkctrl_t      *cp;
+       volatile unsigned char  *bits;
+       unsigned long           flags;
+       int                     rc;
+
+#ifdef DEBUG
+       printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
+               (int) brdp, (int) portp, (int) arg, wait);
+#endif
+
+       save_flags(flags);
+       cli();
 
 /*
  *     Slave is already closing this port. This can happen if a hangup
@@ -1254,6 +1346,7 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
                wait_event_interruptible(portp->raw_wait,
                                !test_bit(ST_CLOSING, &portp->state));
                if (signal_pending(current)) {
+                       restore_flags(flags);
                        return -ERESTARTSYS;
                }
        }
@@ -1261,22 +1354,21 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
 /*
  *     Write the close command into shared memory.
  */
-       spin_lock_irqsave(&brd_lock, flags);
        EBRDENABLE(brdp);
-       cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
-       writel(arg, &cp->closearg);
-       writeb(1, &cp->close);
-       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
+       cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
+       cp->closearg = arg;
+       cp->close = 1;
+       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
                portp->portidx;
-       writeb(readb(bits) |portp->portbit, bits);
+       *bits |= portp->portbit;
        EBRDDISABLE(brdp);
 
        set_bit(ST_CLOSING, &portp->state);
-       spin_unlock_irqrestore(&brd_lock, flags);
-
-       if (wait == 0)
-               return 0;
+       if (wait == 0) {
+               restore_flags(flags);
+               return(0);
+       }
 
 /*
  *     Slave is in action, so now we must wait for the open acknowledgment
@@ -1287,10 +1379,11 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
                        !test_bit(ST_CLOSING, &portp->state));
        if (signal_pending(current))
                rc = -ERESTARTSYS;
+       restore_flags(flags);
 
        if ((rc == 0) && (portp->rc != 0))
                rc = -EIO;
-       return rc;
+       return(rc);
 }
 
 /*****************************************************************************/
@@ -1304,21 +1397,36 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
 
 static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
 {
+       unsigned long   flags;
+
+#ifdef DEBUG
+       printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
+               "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
+               (int) arg, size, copyback);
+#endif
+
+       save_flags(flags);
+       cli();
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_CMDING, &portp->state));
-       if (signal_pending(current))
+       if (signal_pending(current)) {
+               restore_flags(flags);
                return -ERESTARTSYS;
+       }
 
        stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
 
        wait_event_interruptible(portp->raw_wait,
                        !test_bit(ST_CMDING, &portp->state));
-       if (signal_pending(current))
+       if (signal_pending(current)) {
+               restore_flags(flags);
                return -ERESTARTSYS;
+       }
+       restore_flags(flags);
 
        if (portp->rc != 0)
-               return -EIO;
-       return 0;
+               return(-EIO);
+       return(0);
 }
 
 /*****************************************************************************/
@@ -1330,18 +1438,22 @@ static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, v
 
 static int stli_setport(stliport_t *portp)
 {
-       stlibrd_t *brdp;
-       asyport_t aport;
+       stlibrd_t       *brdp;
+       asyport_t       aport;
 
-       if (portp == NULL)
-               return -ENODEV;
-       if (portp->tty == NULL)
-               return -ENODEV;
-       if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
-               return -ENODEV;
+#ifdef DEBUG
+       printk("stli_setport(portp=%x)\n", (int) portp);
+#endif
+
+       if (portp == (stliport_t *) NULL)
+               return(-ENODEV);
+       if (portp->tty == (struct tty_struct *) NULL)
+               return(-ENODEV);
+       if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
+               return(-ENODEV);
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
-               return -ENODEV;
+       if (brdp == (stlibrd_t *) NULL)
+               return(-ENODEV);
 
        stli_mkasyport(portp, &aport, portp->tty->termios);
        return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
@@ -1356,8 +1468,13 @@ static int stli_setport(stliport_t *portp)
 
 static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
 {
-       unsigned long flags;
-       int rc, doclocal;
+       unsigned long   flags;
+       int             rc, doclocal;
+
+#ifdef DEBUG
+       printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
+               (int) brdp, (int) portp, (int) filp);
+#endif
 
        rc = 0;
        doclocal = 0;
@@ -1365,11 +1482,11 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
        if (portp->tty->termios->c_cflag & CLOCAL)
                doclocal++;
 
-       spin_lock_irqsave(&stli_lock, flags);
+       save_flags(flags);
+       cli();
        portp->openwaitcnt++;
        if (! tty_hung_up_p(filp))
                portp->refcount--;
-       spin_unlock_irqrestore(&stli_lock, flags);
 
        for (;;) {
                stli_mkasysigs(&portp->asig, 1, 1);
@@ -1395,13 +1512,12 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
                interruptible_sleep_on(&portp->open_wait);
        }
 
-       spin_lock_irqsave(&stli_lock, flags);
        if (! tty_hung_up_p(filp))
                portp->refcount++;
        portp->openwaitcnt--;
-       spin_unlock_irqrestore(&stli_lock, flags);
+       restore_flags(flags);
 
-       return rc;
+       return(rc);
 }
 
 /*****************************************************************************/
@@ -1414,38 +1530,46 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
 
 static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
 {
-       cdkasy_t __iomem *ap;
-       cdkhdr_t __iomem *hdrp;
-       unsigned char __iomem *bits;
-       unsigned char __iomem *shbuf;
-       unsigned char *chbuf;
-       stliport_t *portp;
-       stlibrd_t *brdp;
-       unsigned int len, stlen, head, tail, size;
-       unsigned long flags;
+       volatile cdkasy_t       *ap;
+       volatile cdkhdr_t       *hdrp;
+       volatile unsigned char  *bits;
+       unsigned char           *shbuf, *chbuf;
+       stliport_t              *portp;
+       stlibrd_t               *brdp;
+       unsigned int            len, stlen, head, tail, size;
+       unsigned long           flags;
 
+#ifdef DEBUG
+       printk("stli_write(tty=%x,buf=%x,count=%d)\n",
+               (int) tty, (int) buf, count);
+#endif
+
+       if ((tty == (struct tty_struct *) NULL) ||
+           (stli_tmpwritebuf == (char *) NULL))
+               return(0);
        if (tty == stli_txcooktty)
                stli_flushchars(tty);
        portp = tty->driver_data;
-       if (portp == NULL)
-               return 0;
+       if (portp == (stliport_t *) NULL)
+               return(0);
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return 0;
+               return(0);
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
-               return 0;
+       if (brdp == (stlibrd_t *) NULL)
+               return(0);
        chbuf = (unsigned char *) buf;
 
 /*
  *     All data is now local, shove as much as possible into shared memory.
  */
-       spin_lock_irqsave(&brd_lock, flags);
+       save_flags(flags);
+       cli();
        EBRDENABLE(brdp);
-       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
-       head = (unsigned int) readw(&ap->txq.head);
-       tail = (unsigned int) readw(&ap->txq.tail);
-       if (tail != ((unsigned int) readw(&ap->txq.tail)))
-               tail = (unsigned int) readw(&ap->txq.tail);
+       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
+       head = (unsigned int) ap->txq.head;
+       tail = (unsigned int) ap->txq.tail;
+       if (tail != ((unsigned int) ap->txq.tail))
+               tail = (unsigned int) ap->txq.tail;
        size = portp->txsize;
        if (head >= tail) {
                len = size - (head - tail) - 1;
@@ -1457,11 +1581,11 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
 
        len = MIN(len, count);
        count = 0;
-       shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
+       shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
 
        while (len > 0) {
                stlen = MIN(len, stlen);
-               memcpy_toio(shbuf + head, chbuf, stlen);
+               memcpy((shbuf + head), chbuf, stlen);
                chbuf += stlen;
                len -= stlen;
                count += stlen;
@@ -1472,19 +1596,20 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
                }
        }
 
-       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
-       writew(head, &ap->txq.head);
+       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
+       ap->txq.head = head;
        if (test_bit(ST_TXBUSY, &portp->state)) {
-               if (readl(&ap->changed.data) & DT_TXEMPTY)
-                       writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
+               if (ap->changed.data & DT_TXEMPTY)
+                       ap->changed.data &= ~DT_TXEMPTY;
        }
-       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
+       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
                portp->portidx;
-       writeb(readb(bits) | portp->portbit, bits);
+       *bits |= portp->portbit;
        set_bit(ST_TXBUSY, &portp->state);
        EBRDDISABLE(brdp);
-       spin_unlock_irqrestore(&brd_lock, flags);
+
+       restore_flags(flags);
 
        return(count);
 }
@@ -1501,8 +1626,14 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
 
 static void stli_putchar(struct tty_struct *tty, unsigned char ch)
 {
+#ifdef DEBUG
+       printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
+#endif
+
+       if (tty == (struct tty_struct *) NULL)
+               return;
        if (tty != stli_txcooktty) {
-               if (stli_txcooktty != NULL)
+               if (stli_txcooktty != (struct tty_struct *) NULL)
                        stli_flushchars(stli_txcooktty);
                stli_txcooktty = tty;
        }
@@ -1522,26 +1653,29 @@ static void stli_putchar(struct tty_struct *tty, unsigned char ch)
 
 static void stli_flushchars(struct tty_struct *tty)
 {
-       cdkhdr_t __iomem *hdrp;
-       unsigned char __iomem *bits;
-       cdkasy_t __iomem *ap;
-       struct tty_struct *cooktty;
-       stliport_t *portp;
-       stlibrd_t *brdp;
-       unsigned int len, stlen, head, tail, size, count, cooksize;
-       unsigned char *buf;
-       unsigned char __iomem *shbuf;
-       unsigned long flags;
+       volatile cdkhdr_t       *hdrp;
+       volatile unsigned char  *bits;
+       volatile cdkasy_t       *ap;
+       struct tty_struct       *cooktty;
+       stliport_t              *portp;
+       stlibrd_t               *brdp;
+       unsigned int            len, stlen, head, tail, size, count, cooksize;
+       unsigned char           *buf, *shbuf;
+       unsigned long           flags;
+
+#ifdef DEBUG
+       printk("stli_flushchars(tty=%x)\n", (int) tty);
+#endif
 
        cooksize = stli_txcooksize;
        cooktty = stli_txcooktty;
        stli_txcooksize = 0;
        stli_txcookrealsize = 0;
-       stli_txcooktty = NULL;
+       stli_txcooktty = (struct tty_struct *) NULL;
 
-       if (tty == NULL)
+       if (tty == (struct tty_struct *) NULL)
                return;
-       if (cooktty == NULL)
+       if (cooktty == (struct tty_struct *) NULL)
                return;
        if (tty != cooktty)
                tty = cooktty;
@@ -1549,22 +1683,23 @@ static void stli_flushchars(struct tty_struct *tty)
                return;
 
        portp = tty->driver_data;
-       if (portp == NULL)
+       if (portp == (stliport_t *) NULL)
                return;
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
+       if (brdp == (stlibrd_t *) NULL)
                return;
 
-       spin_lock_irqsave(&brd_lock, flags);
+       save_flags(flags);
+       cli();
        EBRDENABLE(brdp);
 
-       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
-       head = (unsigned int) readw(&ap->txq.head);
-       tail = (unsigned int) readw(&ap->txq.tail);
-       if (tail != ((unsigned int) readw(&ap->txq.tail)))
-               tail = (unsigned int) readw(&ap->txq.tail);
+       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
+       head = (unsigned int) ap->txq.head;
+       tail = (unsigned int) ap->txq.tail;
+       if (tail != ((unsigned int) ap->txq.tail))
+               tail = (unsigned int) ap->txq.tail;
        size = portp->txsize;
        if (head >= tail) {
                len = size - (head - tail) - 1;
@@ -1581,7 +1716,7 @@ static void stli_flushchars(struct tty_struct *tty)
 
        while (len > 0) {
                stlen = MIN(len, stlen);
-               memcpy_toio(shbuf + head, buf, stlen);
+               memcpy((shbuf + head), buf, stlen);
                buf += stlen;
                len -= stlen;
                count += stlen;
@@ -1592,66 +1727,73 @@ static void stli_flushchars(struct tty_struct *tty)
                }
        }
 
-       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
-       writew(head, &ap->txq.head);
+       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
+       ap->txq.head = head;
 
        if (test_bit(ST_TXBUSY, &portp->state)) {
-               if (readl(&ap->changed.data) & DT_TXEMPTY)
-                       writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
+               if (ap->changed.data & DT_TXEMPTY)
+                       ap->changed.data &= ~DT_TXEMPTY;
        }
-       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
+       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
                portp->portidx;
-       writeb(readb(bits) | portp->portbit, bits);
+       *bits |= portp->portbit;
        set_bit(ST_TXBUSY, &portp->state);
 
        EBRDDISABLE(brdp);
-       spin_unlock_irqrestore(&brd_lock, flags);
+       restore_flags(flags);
 }
 
 /*****************************************************************************/
 
 static int stli_writeroom(struct tty_struct *tty)
 {
-       cdkasyrq_t __iomem *rp;
-       stliport_t *portp;
-       stlibrd_t *brdp;
-       unsigned int head, tail, len;
-       unsigned long flags;
+       volatile cdkasyrq_t     *rp;
+       stliport_t              *portp;
+       stlibrd_t               *brdp;
+       unsigned int            head, tail, len;
+       unsigned long           flags;
+
+#ifdef DEBUG
+       printk("stli_writeroom(tty=%x)\n", (int) tty);
+#endif
 
+       if (tty == (struct tty_struct *) NULL)
+               return(0);
        if (tty == stli_txcooktty) {
                if (stli_txcookrealsize != 0) {
                        len = stli_txcookrealsize - stli_txcooksize;
-                       return len;
+                       return(len);
                }
        }
 
        portp = tty->driver_data;
-       if (portp == NULL)
-               return 0;
+       if (portp == (stliport_t *) NULL)
+               return(0);
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return 0;
+               return(0);
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
-               return 0;
+       if (brdp == (stlibrd_t *) NULL)
+               return(0);
 
-       spin_lock_irqsave(&brd_lock, flags);
+       save_flags(flags);
+       cli();
        EBRDENABLE(brdp);
-       rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
-       head = (unsigned int) readw(&rp->head);
-       tail = (unsigned int) readw(&rp->tail);
-       if (tail != ((unsigned int) readw(&rp->tail)))
-               tail = (unsigned int) readw(&rp->tail);
+       rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
+       head = (unsigned int) rp->head;
+       tail = (unsigned int) rp->tail;
+       if (tail != ((unsigned int) rp->tail))
+               tail = (unsigned int) rp->tail;
        len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
        len--;
        EBRDDISABLE(brdp);
-       spin_unlock_irqrestore(&brd_lock, flags);
+       restore_flags(flags);
 
        if (tty == stli_txcooktty) {
                stli_txcookrealsize = len;
                len -= stli_txcooksize;
        }
-       return len;
+       return(len);
 }
 
 /*****************************************************************************/
@@ -1666,37 +1808,44 @@ static int stli_writeroom(struct tty_struct *tty)
 
 static int stli_charsinbuffer(struct tty_struct *tty)
 {
-       cdkasyrq_t __iomem *rp;
-       stliport_t *portp;
-       stlibrd_t *brdp;
-       unsigned int head, tail, len;
-       unsigned long flags;
+       volatile cdkasyrq_t     *rp;
+       stliport_t              *portp;
+       stlibrd_t               *brdp;
+       unsigned int            head, tail, len;
+       unsigned long           flags;
 
+#ifdef DEBUG
+       printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
+#endif
+
+       if (tty == (struct tty_struct *) NULL)
+               return(0);
        if (tty == stli_txcooktty)
                stli_flushchars(tty);
        portp = tty->driver_data;
-       if (portp == NULL)
-               return 0;
+       if (portp == (stliport_t *) NULL)
+               return(0);
        if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
-               return 0;
+               return(0);
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
-               return 0;
+       if (brdp == (stlibrd_t *) NULL)
+               return(0);
 
-       spin_lock_irqsave(&brd_lock, flags);
+       save_flags(flags);
+       cli();
        EBRDENABLE(brdp);
-       rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
-       head = (unsigned int) readw(&rp->head);
-       tail = (unsigned int) readw(&rp->tail);
-       if (tail != ((unsigned int) readw(&rp->tail)))
-               tail = (unsigned int) readw(&rp->tail);
+       rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
+       head = (unsigned int) rp->head;
+       tail = (unsigned int) rp->tail;
+       if (tail != ((unsigned int) rp->tail))
+               tail = (unsigned int) rp->tail;
        len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
        if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
                len = 1;
        EBRDDISABLE(brdp);
-       spin_unlock_irqrestore(&brd_lock, flags);
+       restore_flags(flags);
 
-       return len;
+       return(len);
 }
 
 /*****************************************************************************/
@@ -1707,8 +1856,12 @@ static int stli_charsinbuffer(struct tty_struct *tty)
 
 static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
 {
-       struct serial_struct sio;
-       stlibrd_t *brdp;
+       struct serial_struct    sio;
+       stlibrd_t               *brdp;
+
+#ifdef DEBUG
+       printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
+#endif
 
        memset(&sio, 0, sizeof(struct serial_struct));
        sio.type = PORT_UNKNOWN;
@@ -1723,7 +1876,7 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
        sio.hub6 = 0;
 
        brdp = stli_brds[portp->brdnr];
-       if (brdp != NULL)
+       if (brdp != (stlibrd_t *) NULL)
                sio.port = brdp->iobase;
                
        return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
@@ -1740,8 +1893,12 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
 
 static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
 {
-       struct serial_struct sio;
-       int rc;
+       struct serial_struct    sio;
+       int                     rc;
+
+#ifdef DEBUG
+       printk("stli_setserial(portp=%p,sp=%p)\n", portp, sp);
+#endif
 
        if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
                return -EFAULT;
@@ -1750,7 +1907,7 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
                    (sio.close_delay != portp->close_delay) ||
                    ((sio.flags & ~ASYNC_USR_MASK) !=
                    (portp->flags & ~ASYNC_USR_MASK)))
-                       return -EPERM;
+                       return(-EPERM);
        } 
 
        portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
@@ -1761,8 +1918,8 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
        portp->custom_divisor = sio.custom_divisor;
 
        if ((rc = stli_setport(portp)) < 0)
-               return rc;
-       return 0;
+               return(rc);
+       return(0);
 }
 
 /*****************************************************************************/
@@ -1773,19 +1930,19 @@ static int stli_tiocmget(struct tty_struct *tty, struct file *file)
        stlibrd_t *brdp;
        int rc;
 
-       if (portp == NULL)
-               return -ENODEV;
-       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
-               return 0;
+       if (portp == (stliport_t *) NULL)
+               return(-ENODEV);
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+               return(0);
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
-               return 0;
+       if (brdp == (stlibrd_t *) NULL)
+               return(0);
        if (tty->flags & (1 << TTY_IO_ERROR))
-               return -EIO;
+               return(-EIO);
 
        if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
                               &portp->asig, sizeof(asysigs_t), 1)) < 0)
-               return rc;
+               return(rc);
 
        return stli_mktiocm(portp->asig.sigvalue);
 }
@@ -1797,15 +1954,15 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
        stlibrd_t *brdp;
        int rts = -1, dtr = -1;
 
-       if (portp == NULL)
-               return -ENODEV;
-       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
-               return 0;
+       if (portp == (stliport_t *) NULL)
+               return(-ENODEV);
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+               return(0);
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
-               return 0;
+       if (brdp == (stlibrd_t *) NULL)
+               return(0);
        if (tty->flags & (1 << TTY_IO_ERROR))
-               return -EIO;
+               return(-EIO);
 
        if (set & TIOCM_RTS)
                rts = 1;
@@ -1824,25 +1981,32 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
 
 static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
 {
-       stliport_t *portp;
-       stlibrd_t *brdp;
-       unsigned int ival;
-       int rc;
+       stliport_t      *portp;
+       stlibrd_t       *brdp;
+       unsigned int    ival;
+       int             rc;
        void __user *argp = (void __user *)arg;
 
+#ifdef DEBUG
+       printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
+               (int) tty, (int) file, cmd, (int) arg);
+#endif
+
+       if (tty == (struct tty_struct *) NULL)
+               return(-ENODEV);
        portp = tty->driver_data;
-       if (portp == NULL)
-               return -ENODEV;
-       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
-               return 0;
+       if (portp == (stliport_t *) NULL)
+               return(-ENODEV);
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+               return(0);
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
-               return 0;
+       if (brdp == (stlibrd_t *) NULL)
+               return(0);
 
        if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
            (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
                if (tty->flags & (1 << TTY_IO_ERROR))
-                       return -EIO;
+                       return(-EIO);
        }
 
        rc = 0;
@@ -1889,7 +2053,7 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
                break;
        }
 
-       return rc;
+       return(rc);
 }
 
 /*****************************************************************************/
@@ -1901,20 +2065,24 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
 
 static void stli_settermios(struct tty_struct *tty, struct termios *old)
 {
-       stliport_t *portp;
-       stlibrd_t *brdp;
-       struct termios *tiosp;
-       asyport_t aport;
+       stliport_t      *portp;
+       stlibrd_t       *brdp;
+       struct termios  *tiosp;
+       asyport_t       aport;
 
-       if (tty == NULL)
+#ifdef DEBUG
+       printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
+#endif
+
+       if (tty == (struct tty_struct *) NULL)
                return;
        portp = tty->driver_data;
-       if (portp == NULL)
+       if (portp == (stliport_t *) NULL)
                return;
-       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
+       if (brdp == (stlibrd_t *) NULL)
                return;
 
        tiosp = tty->termios;
@@ -1947,9 +2115,18 @@ static void stli_settermios(struct tty_struct *tty, struct termios *old)
 
 static void stli_throttle(struct tty_struct *tty)
 {
-       stliport_t      *portp = tty->driver_data;
-       if (portp == NULL)
+       stliport_t      *portp;
+
+#ifdef DEBUG
+       printk("stli_throttle(tty=%x)\n", (int) tty);
+#endif
+
+       if (tty == (struct tty_struct *) NULL)
                return;
+       portp = tty->driver_data;
+       if (portp == (stliport_t *) NULL)
+               return;
+
        set_bit(ST_RXSTOP, &portp->state);
 }
 
@@ -1963,30 +2140,88 @@ static void stli_throttle(struct tty_struct *tty)
 
 static void stli_unthrottle(struct tty_struct *tty)
 {
-       stliport_t      *portp = tty->driver_data;
-       if (portp == NULL)
+       stliport_t      *portp;
+
+#ifdef DEBUG
+       printk("stli_unthrottle(tty=%x)\n", (int) tty);
+#endif
+
+       if (tty == (struct tty_struct *) NULL)
                return;
+       portp = tty->driver_data;
+       if (portp == (stliport_t *) NULL)
+               return;
+
        clear_bit(ST_RXSTOP, &portp->state);
 }
 
 /*****************************************************************************/
 
 /*
- *     Stop the transmitter.
+ *     Stop the transmitter. Basically to do this we will just turn TX
+ *     interrupts off.
  */
 
 static void stli_stop(struct tty_struct *tty)
 {
+       stlibrd_t       *brdp;
+       stliport_t      *portp;
+       asyctrl_t       actrl;
+
+#ifdef DEBUG
+       printk("stli_stop(tty=%x)\n", (int) tty);
+#endif
+
+       if (tty == (struct tty_struct *) NULL)
+               return;
+       portp = tty->driver_data;
+       if (portp == (stliport_t *) NULL)
+               return;
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+               return;
+       brdp = stli_brds[portp->brdnr];
+       if (brdp == (stlibrd_t *) NULL)
+               return;
+
+       memset(&actrl, 0, sizeof(asyctrl_t));
+       actrl.txctrl = CT_STOPFLOW;
+#if 0
+       stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
+#endif
 }
 
 /*****************************************************************************/
 
 /*
- *     Start the transmitter again.
+ *     Start the transmitter again. Just turn TX interrupts back on.
  */
 
 static void stli_start(struct tty_struct *tty)
 {
+       stliport_t      *portp;
+       stlibrd_t       *brdp;
+       asyctrl_t       actrl;
+
+#ifdef DEBUG
+       printk("stli_start(tty=%x)\n", (int) tty);
+#endif
+
+       if (tty == (struct tty_struct *) NULL)
+               return;
+       portp = tty->driver_data;
+       if (portp == (stliport_t *) NULL)
+               return;
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
+               return;
+       brdp = stli_brds[portp->brdnr];
+       if (brdp == (stlibrd_t *) NULL)
+               return;
+
+       memset(&actrl, 0, sizeof(asyctrl_t));
+       actrl.txctrl = CT_STARTFLOW;
+#if 0
+       stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
+#endif
 }
 
 /*****************************************************************************/
@@ -2002,9 +2237,22 @@ static void stli_start(struct tty_struct *tty)
 
 static void stli_dohangup(void *arg)
 {
-       stliport_t *portp = (stliport_t *) arg;
-       if (portp->tty != NULL) {
-               tty_hangup(portp->tty);
+       stliport_t      *portp;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_dohangup(portp=%x)\n", (int) arg);
+#endif
+
+       /*
+        * FIXME: There's a module removal race here: tty_hangup
+        * calls schedule_work which will call into this
+        * driver later.
+        */
+       portp = (stliport_t *) arg;
+       if (portp != (stliport_t *) NULL) {
+               if (portp->tty != (struct tty_struct *) NULL) {
+                       tty_hangup(portp->tty);
+               }
        }
 }
 
@@ -2019,25 +2267,31 @@ static void stli_dohangup(void *arg)
 
 static void stli_hangup(struct tty_struct *tty)
 {
-       stliport_t *portp;
-       stlibrd_t *brdp;
-       unsigned long flags;
+       stliport_t      *portp;
+       stlibrd_t       *brdp;
+       unsigned long   flags;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_hangup(tty=%x)\n", (int) tty);
+#endif
 
+       if (tty == (struct tty_struct *) NULL)
+               return;
        portp = tty->driver_data;
-       if (portp == NULL)
+       if (portp == (stliport_t *) NULL)
                return;
-       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
+       if (brdp == (stlibrd_t *) NULL)
                return;
 
        portp->flags &= ~ASYNC_INITIALIZED;
 
-       if (!test_bit(ST_CLOSING, &portp->state))
+       save_flags(flags);
+       cli();
+       if (! test_bit(ST_CLOSING, &portp->state))
                stli_rawclose(brdp, portp, 0, 0);
-
-       spin_lock_irqsave(&stli_lock, flags);
        if (tty->termios->c_cflag & HUPCL) {
                stli_mkasysigs(&portp->asig, 0, 0);
                if (test_bit(ST_CMDING, &portp->state)) {
@@ -2049,15 +2303,14 @@ static void stli_hangup(struct tty_struct *tty)
                                &portp->asig, sizeof(asysigs_t), 0);
                }
        }
+       restore_flags(flags);
 
        clear_bit(ST_TXBUSY, &portp->state);
        clear_bit(ST_RXSTOP, &portp->state);
        set_bit(TTY_IO_ERROR, &tty->flags);
-       portp->tty = NULL;
+       portp->tty = (struct tty_struct *) NULL;
        portp->flags &= ~ASYNC_NORMAL_ACTIVE;
        portp->refcount = 0;
-       spin_unlock_irqrestore(&stli_lock, flags);
-
        wake_up_interruptible(&portp->open_wait);
 }
 
@@ -2072,22 +2325,29 @@ static void stli_hangup(struct tty_struct *tty)
 
 static void stli_flushbuffer(struct tty_struct *tty)
 {
-       stliport_t *portp;
-       stlibrd_t *brdp;
-       unsigned long ftype, flags;
+       stliport_t      *portp;
+       stlibrd_t       *brdp;
+       unsigned long   ftype, flags;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_flushbuffer(tty=%x)\n", (int) tty);
+#endif
 
+       if (tty == (struct tty_struct *) NULL)
+               return;
        portp = tty->driver_data;
-       if (portp == NULL)
+       if (portp == (stliport_t *) NULL)
                return;
-       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
+       if (brdp == (stlibrd_t *) NULL)
                return;
 
-       spin_lock_irqsave(&brd_lock, flags);
+       save_flags(flags);
+       cli();
        if (tty == stli_txcooktty) {
-               stli_txcooktty = NULL;
+               stli_txcooktty = (struct tty_struct *) NULL;
                stli_txcooksize = 0;
                stli_txcookrealsize = 0;
        }
@@ -2099,10 +2359,15 @@ static void stli_flushbuffer(struct tty_struct *tty)
                        ftype |= FLUSHRX;
                        clear_bit(ST_DOFLUSHRX, &portp->state);
                }
-               __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
+               stli_sendcmd(brdp, portp, A_FLUSH, &ftype,
+                       sizeof(unsigned long), 0);
        }
-       spin_unlock_irqrestore(&brd_lock, flags);
-       tty_wakeup(tty);
+       restore_flags(flags);
+
+       wake_up_interruptible(&tty->write_wait);
+       if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
+           tty->ldisc.write_wakeup)
+               (tty->ldisc.write_wakeup)(tty);
 }
 
 /*****************************************************************************/
@@ -2112,31 +2377,55 @@ static void stli_breakctl(struct tty_struct *tty, int state)
        stlibrd_t       *brdp;
        stliport_t      *portp;
        long            arg;
+       /* long savestate, savetime; */
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
+#endif
 
+       if (tty == (struct tty_struct *) NULL)
+               return;
        portp = tty->driver_data;
-       if (portp == NULL)
+       if (portp == (stliport_t *) NULL)
                return;
-       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
+       if (brdp == (stlibrd_t *) NULL)
                return;
 
+/*
+ *     Due to a bug in the tty send_break() code we need to preserve
+ *     the current process state and timeout...
+       savetime = current->timeout;
+       savestate = current->state;
+ */
+
        arg = (state == -1) ? BREAKON : BREAKOFF;
        stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
+
+/*
+ *
+       current->timeout = savetime;
+       current->state = savestate;
+ */
 }
 
 /*****************************************************************************/
 
 static void stli_waituntilsent(struct tty_struct *tty, int timeout)
 {
-       stliport_t *portp;
-       unsigned long tend;
+       stliport_t      *portp;
+       unsigned long   tend;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
+#endif
 
-       if (tty == NULL)
+       if (tty == (struct tty_struct *) NULL)
                return;
        portp = tty->driver_data;
-       if (portp == NULL)
+       if (portp == (stliport_t *) NULL)
                return;
 
        if (timeout == 0)
@@ -2160,13 +2449,19 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
        stliport_t      *portp;
        asyctrl_t       actrl;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
+#endif
+
+       if (tty == (struct tty_struct *) NULL)
+               return;
        portp = tty->driver_data;
-       if (portp == NULL)
+       if (portp == (stliport_t *) NULL)
                return;
-       if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
+       if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
                return;
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
+       if (brdp == (stlibrd_t *) NULL)
                return;
 
        memset(&actrl, 0, sizeof(asyctrl_t));
@@ -2178,6 +2473,7 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
                actrl.txctrl = CT_SENDCHR;
                actrl.tximdch = ch;
        }
+
        stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
 }
 
@@ -2193,17 +2489,17 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
 
 static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
 {
-       char *sp, *uart;
-       int rc, cnt;
+       char    *sp, *uart;
+       int     rc, cnt;
 
        rc = stli_portcmdstats(portp);
 
        uart = "UNKNOWN";
        if (brdp->state & BST_STARTED) {
                switch (stli_comstats.hwid) {
-               case 0: uart = "2681"; break;
-               case 1: uart = "SC26198"; break;
-               default:uart = "CD1400"; break;
+               case 0:         uart = "2681"; break;
+               case 1:         uart = "SC26198"; break;
+               default:        uart = "CD1400"; break;
                }
        }
 
@@ -2254,11 +2550,17 @@ static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *p
 
 static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
 {
-       stlibrd_t *brdp;
-       stliport_t *portp;
-       int brdnr, portnr, totalport;
-       int curoff, maxoff;
-       char *pos;
+       stlibrd_t       *brdp;
+       stliport_t      *portp;
+       int             brdnr, portnr, totalport;
+       int             curoff, maxoff;
+       char            *pos;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
+               "data=%x\n", (int) page, (int) start, (int) off, count,
+               (int) eof, (int) data);
+#endif
 
        pos = page;
        totalport = 0;
@@ -2279,7 +2581,7 @@ static int stli_readproc(char *page, char **start, off_t off, int count, int *eo
  */
        for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
                brdp = stli_brds[brdnr];
-               if (brdp == NULL)
+               if (brdp == (stlibrd_t *) NULL)
                        continue;
                if (brdp->state == 0)
                        continue;
@@ -2294,7 +2596,7 @@ static int stli_readproc(char *page, char **start, off_t off, int count, int *eo
                for (portnr = 0; (portnr < brdp->nrports); portnr++,
                    totalport++) {
                        portp = brdp->ports[portnr];
-                       if (portp == NULL)
+                       if (portp == (stliport_t *) NULL)
                                continue;
                        if (off >= (curoff += MAXLINE))
                                continue;
@@ -2321,54 +2623,49 @@ stli_readdone:
  *     a poll routine that does not have user context. Therefore you cannot
  *     copy back directly into user space, or to the kernel stack of a
  *     process. This routine does not sleep, so can be called from anywhere.
- *
- *     The caller must hold the brd_lock (see also stli_sendcmd the usual
- *     entry point)
  */
 
-static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
+static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
 {
-       cdkhdr_t __iomem *hdrp;
-       cdkctrl_t __iomem *cp;
-       unsigned char __iomem *bits;
-       unsigned long flags;
+       volatile cdkhdr_t       *hdrp;
+       volatile cdkctrl_t      *cp;
+       volatile unsigned char  *bits;
+       unsigned long           flags;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
+               "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
+               (int) arg, size, copyback);
+#endif
 
-       spin_lock_irqsave(&brd_lock, flags);
+       save_flags(flags);
+       cli();
 
        if (test_bit(ST_CMDING, &portp->state)) {
                printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
                                (int) cmd);
-               spin_unlock_irqrestore(&brd_lock, flags);
+               restore_flags(flags);
                return;
        }
 
        EBRDENABLE(brdp);
-       cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
+       cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
        if (size > 0) {
-               memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
+               memcpy((void *) &(cp->args[0]), arg, size);
                if (copyback) {
                        portp->argp = arg;
                        portp->argsize = size;
                }
-       }
-       writel(0, &cp->status);
-       writel(cmd, &cp->cmd);
-       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-       bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
-               portp->portidx;
-       writeb(readb(bits) | portp->portbit, bits);
-       set_bit(ST_CMDING, &portp->state);
-       EBRDDISABLE(brdp);
-       spin_unlock_irqrestore(&brd_lock, flags);
-}
-
-static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
-{
-       unsigned long           flags;
-
-       spin_lock_irqsave(&brd_lock, flags);
-       __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
-       spin_unlock_irqrestore(&brd_lock, flags);
+       }
+       cp->status = 0;
+       cp->cmd = cmd;
+       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
+               portp->portidx;
+       *bits |= portp->portbit;
+       set_bit(ST_CMDING, &portp->state);
+       EBRDDISABLE(brdp);
+       restore_flags(flags);
 }
 
 /*****************************************************************************/
@@ -2383,23 +2680,28 @@ static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd,
 
 static void stli_read(stlibrd_t *brdp, stliport_t *portp)
 {
-       cdkasyrq_t __iomem *rp;
-       char __iomem *shbuf;
+       volatile cdkasyrq_t     *rp;
+       volatile char           *shbuf;
        struct tty_struct       *tty;
-       unsigned int head, tail, size;
-       unsigned int len, stlen;
+       unsigned int            head, tail, size;
+       unsigned int            len, stlen;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_read(brdp=%x,portp=%d)\n",
+                       (int) brdp, (int) portp);
+#endif
 
        if (test_bit(ST_RXSTOP, &portp->state))
                return;
        tty = portp->tty;
-       if (tty == NULL)
+       if (tty == (struct tty_struct *) NULL)
                return;
 
-       rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
-       head = (unsigned int) readw(&rp->head);
-       if (head != ((unsigned int) readw(&rp->head)))
-               head = (unsigned int) readw(&rp->head);
-       tail = (unsigned int) readw(&rp->tail);
+       rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
+       head = (unsigned int) rp->head;
+       if (head != ((unsigned int) rp->head))
+               head = (unsigned int) rp->head;
+       tail = (unsigned int) rp->tail;
        size = portp->rxsize;
        if (head >= tail) {
                len = head - tail;
@@ -2410,15 +2712,12 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
        }
 
        len = tty_buffer_request_room(tty, len);
-
-       shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
+       /* FIXME : iomap ? */
+       shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
 
        while (len > 0) {
-               unsigned char *cptr;
-
                stlen = MIN(len, stlen);
-               tty_prepare_flip_string(tty, &cptr, stlen);
-               memcpy_fromio(cptr, shbuf + tail, stlen);
+               tty_insert_flip_string(tty, (char *)(shbuf + tail), stlen);
                len -= stlen;
                tail += stlen;
                if (tail >= size) {
@@ -2426,8 +2725,8 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
                        stlen = head;
                }
        }
-       rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
-       writew(tail, &rp->tail);
+       rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
+       rp->tail = tail;
 
        if (head != tail)
                set_bit(ST_RXING, &portp->state);
@@ -2443,9 +2742,9 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
  *     difficult to deal with them here.
  */
 
-static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
+static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
 {
-       int cmd;
+       int     cmd;
 
        if (test_bit(ST_DOSIGS, &portp->state)) {
                if (test_bit(ST_DOFLUSHTX, &portp->state) &&
@@ -2460,10 +2759,10 @@ static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
                clear_bit(ST_DOFLUSHTX, &portp->state);
                clear_bit(ST_DOFLUSHRX, &portp->state);
                clear_bit(ST_DOSIGS, &portp->state);
-               memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
+               memcpy((void *) &(cp->args[0]), (void *) &portp->asig,
                        sizeof(asysigs_t));
-               writel(0, &cp->status);
-               writel(cmd, &cp->cmd);
+               cp->status = 0;
+               cp->cmd = cmd;
                set_bit(ST_CMDING, &portp->state);
        } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
            test_bit(ST_DOFLUSHRX, &portp->state)) {
@@ -2471,9 +2770,9 @@ static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
                cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
                clear_bit(ST_DOFLUSHTX, &portp->state);
                clear_bit(ST_DOFLUSHRX, &portp->state);
-               memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
-               writel(0, &cp->status);
-               writel(A_FLUSH, &cp->cmd);
+               memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
+               cp->status = 0;
+               cp->cmd = A_FLUSH;
                set_bit(ST_CMDING, &portp->state);
        }
 }
@@ -2493,25 +2792,30 @@ static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
 
 static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
 {
-       cdkasy_t __iomem *ap;
-       cdkctrl_t __iomem *cp;
-       struct tty_struct *tty;
-       asynotify_t nt;
-       unsigned long oldsigs;
-       int rc, donerx;
-
-       ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
+       volatile cdkasy_t       *ap;
+       volatile cdkctrl_t      *cp;
+       struct tty_struct       *tty;
+       asynotify_t             nt;
+       unsigned long           oldsigs;
+       int                     rc, donerx;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_hostcmd(brdp=%x,channr=%d)\n",
+                       (int) brdp, channr);
+#endif
+
+       ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
        cp = &ap->ctrl;
 
 /*
  *     Check if we are waiting for an open completion message.
  */
        if (test_bit(ST_OPENING, &portp->state)) {
-               rc = readl(&cp->openarg);
-               if (readb(&cp->open) == 0 && rc != 0) {
+               rc = (int) cp->openarg;
+               if ((cp->open == 0) && (rc != 0)) {
                        if (rc > 0)
                                rc--;
-                       writel(0, &cp->openarg);
+                       cp->openarg = 0;
                        portp->rc = rc;
                        clear_bit(ST_OPENING, &portp->state);
                        wake_up_interruptible(&portp->raw_wait);
@@ -2522,11 +2826,11 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  *     Check if we are waiting for a close completion message.
  */
        if (test_bit(ST_CLOSING, &portp->state)) {
-               rc = (int) readl(&cp->closearg);
-               if (readb(&cp->close) == 0 && rc != 0) {
+               rc = (int) cp->closearg;
+               if ((cp->close == 0) && (rc != 0)) {
                        if (rc > 0)
                                rc--;
-                       writel(0, &cp->closearg);
+                       cp->closearg = 0;
                        portp->rc = rc;
                        clear_bit(ST_CLOSING, &portp->state);
                        wake_up_interruptible(&portp->raw_wait);
@@ -2538,16 +2842,16 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  *     need to copy out the command results associated with this command.
  */
        if (test_bit(ST_CMDING, &portp->state)) {
-               rc = readl(&cp->status);
-               if (readl(&cp->cmd) == 0 && rc != 0) {
+               rc = cp->status;
+               if ((cp->cmd == 0) && (rc != 0)) {
                        if (rc > 0)
                                rc--;
-                       if (portp->argp != NULL) {
-                               memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
+                       if (portp->argp != (void *) NULL) {
+                               memcpy(portp->argp, (void *) &(cp->args[0]),
                                        portp->argsize);
-                               portp->argp = NULL;
+                               portp->argp = (void *) NULL;
                        }
-                       writel(0, &cp->status);
+                       cp->status = 0;
                        portp->rc = rc;
                        clear_bit(ST_CMDING, &portp->state);
                        stli_dodelaycmd(portp, cp);
@@ -2586,15 +2890,18 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
                if (nt.data & DT_TXEMPTY)
                        clear_bit(ST_TXBUSY, &portp->state);
                if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
-                       if (tty != NULL) {
-                               tty_wakeup(tty);
-                               EBRDENABLE(brdp);
+                       if (tty != (struct tty_struct *) NULL) {
+                               if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
+                                   tty->ldisc.write_wakeup) {
+                                       (tty->ldisc.write_wakeup)(tty);
+                                       EBRDENABLE(brdp);
+                               }
                                wake_up_interruptible(&tty->write_wait);
                        }
                }
 
                if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
-                       if (tty != NULL) {
+                       if (tty != (struct tty_struct *) NULL) {
                                tty_insert_flip_char(tty, 0, TTY_BREAK);
                                if (portp->flags & ASYNC_SAK) {
                                        do_SAK(tty);
@@ -2638,14 +2945,14 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  *     at the cdk header structure.
  */
 
-static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
+static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
 {
-       stliport_t *portp;
-       unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
-       unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
-       unsigned char __iomem *slavep;
-       int bitpos, bitat, bitsize;
-       int channr, nrdevs, slavebitchange;
+       stliport_t      *portp;
+       unsigned char   hostbits[(STL_MAXCHANS / 8) + 1];
+       unsigned char   slavebits[(STL_MAXCHANS / 8) + 1];
+       unsigned char   *slavep;
+       int             bitpos, bitat, bitsize;
+       int             channr, nrdevs, slavebitchange;
 
        bitsize = brdp->bitsize;
        nrdevs = brdp->nrdevs;
@@ -2657,7 +2964,7 @@ static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
  *     8 service bits at a time in the inner loop, so we can bypass
  *     the lot if none of them want service.
  */
-       memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
+       memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset),
                bitsize);
 
        memset(&slavebits[0], 0, bitsize);
@@ -2684,11 +2991,11 @@ static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
  *     service may initiate more slave requests.
  */
        if (slavebitchange) {
-               hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-               slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
+               hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+               slavep = ((unsigned char *) hdrp) + brdp->slaveoffset;
                for (bitpos = 0; (bitpos < bitsize); bitpos++) {
-                       if (readb(slavebits + bitpos))
-                               writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
+                       if (slavebits[bitpos])
+                               slavep[bitpos] &= ~slavebits[bitpos];
                }
        }
 }
@@ -2706,9 +3013,9 @@ static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
 
 static void stli_poll(unsigned long arg)
 {
-       cdkhdr_t __iomem *hdrp;
-       stlibrd_t *brdp;
-       int brdnr;
+       volatile cdkhdr_t       *hdrp;
+       stlibrd_t               *brdp;
+       int                     brdnr;
 
        stli_timerlist.expires = STLI_TIMEOUT;
        add_timer(&stli_timerlist);
@@ -2718,18 +3025,16 @@ static void stli_poll(unsigned long arg)
  */
        for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
                brdp = stli_brds[brdnr];
-               if (brdp == NULL)
+               if (brdp == (stlibrd_t *) NULL)
                        continue;
                if ((brdp->state & BST_STARTED) == 0)
                        continue;
 
-               spin_lock(&brd_lock);
                EBRDENABLE(brdp);
-               hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
-               if (readb(&hdrp->hostreq))
+               hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+               if (hdrp->hostreq)
                        stli_brdpoll(brdp, hdrp);
                EBRDDISABLE(brdp);
-               spin_unlock(&brd_lock);
        }
 }
 
@@ -2742,6 +3047,11 @@ static void stli_poll(unsigned long arg)
 
 static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
 {
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
+               (int) portp, (int) pp, (int) tiosp);
+#endif
+
        memset(pp, 0, sizeof(asyport_t));
 
 /*
@@ -2860,6 +3170,11 @@ static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tio
 
 static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
 {
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n",
+                       (int) sp, dtr, rts);
+#endif
+
        memset(sp, 0, sizeof(asysigs_t));
        if (dtr >= 0) {
                sp->signal |= SG_DTR;
@@ -2880,7 +3195,13 @@ static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
 
 static long stli_mktiocm(unsigned long sigvalue)
 {
-       long    tiocm = 0;
+       long    tiocm;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
+#endif
+
+       tiocm = 0;
        tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
        tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
        tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
@@ -2902,13 +3223,18 @@ static int stli_initports(stlibrd_t *brdp)
        stliport_t      *portp;
        int             i, panelnr, panelport;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_initports(brdp=%x)\n", (int) brdp);
+#endif
+
        for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
-               portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
-               if (!portp) {
+               portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
+               if (portp == (stliport_t *) NULL) {
                        printk("STALLION: failed to allocate port structure\n");
                        continue;
                }
 
+               memset(portp, 0, sizeof(stliport_t));
                portp->magic = STLI_PORTMAGIC;
                portp->portnr = i;
                portp->brdnr = brdp->brdnr;
@@ -2928,7 +3254,7 @@ static int stli_initports(stlibrd_t *brdp)
                brdp->ports[i] = portp;
        }
 
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -2941,6 +3267,10 @@ static void stli_ecpinit(stlibrd_t *brdp)
 {
        unsigned long   memconf;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecpinit(brdp=%d)\n", (int) brdp);
+#endif
+
        outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
        udelay(10);
        outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
@@ -2954,6 +3284,9 @@ static void stli_ecpinit(stlibrd_t *brdp)
 
 static void stli_ecpenable(stlibrd_t *brdp)
 {      
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecpenable(brdp=%x)\n", (int) brdp);
+#endif
        outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
 }
 
@@ -2961,6 +3294,9 @@ static void stli_ecpenable(stlibrd_t *brdp)
 
 static void stli_ecpdisable(stlibrd_t *brdp)
 {      
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecpdisable(brdp=%x)\n", (int) brdp);
+#endif
        outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
 }
 
@@ -2968,8 +3304,13 @@ static void stli_ecpdisable(stlibrd_t *brdp)
 
 static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       void *ptr;
-       unsigned char val;
+       void            *ptr;
+       unsigned char   val;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
+               (int) offset);
+#endif
 
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -2989,6 +3330,10 @@ static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 
 static void stli_ecpreset(stlibrd_t *brdp)
 {      
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecpreset(brdp=%x)\n", (int) brdp);
+#endif
+
        outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
        udelay(10);
        outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
@@ -2999,6 +3344,9 @@ static void stli_ecpreset(stlibrd_t *brdp)
 
 static void stli_ecpintr(stlibrd_t *brdp)
 {      
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecpintr(brdp=%x)\n", (int) brdp);
+#endif
        outb(0x1, brdp->iobase);
 }
 
@@ -3012,6 +3360,10 @@ static void stli_ecpeiinit(stlibrd_t *brdp)
 {
        unsigned long   memconf;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecpeiinit(brdp=%x)\n", (int) brdp);
+#endif
+
        outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
        outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
        udelay(10);
@@ -3045,6 +3397,11 @@ static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line
        void            *ptr;
        unsigned char   val;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
+               (int) brdp, (int) offset, line);
+#endif
+
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
                                "range at line=%d(%d), brd=%d\n",
@@ -3094,8 +3451,8 @@ static void stli_ecpmcdisable(stlibrd_t *brdp)
 
 static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       void *ptr;
-       unsigned char val;
+       void            *ptr;
+       unsigned char   val;
 
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3129,6 +3486,10 @@ static void stli_ecpmcreset(stlibrd_t *brdp)
 
 static void stli_ecppciinit(stlibrd_t *brdp)
 {
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecppciinit(brdp=%x)\n", (int) brdp);
+#endif
+
        outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
        udelay(10);
        outb(0, (brdp->iobase + ECP_PCICONFR));
@@ -3142,6 +3503,11 @@ static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int lin
        void            *ptr;
        unsigned char   val;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
+               (int) brdp, (int) offset, line);
+#endif
+
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
                                "range at line=%d(%d), board=%d\n",
@@ -3176,6 +3542,10 @@ static void stli_onbinit(stlibrd_t *brdp)
 {
        unsigned long   memconf;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_onbinit(brdp=%d)\n", (int) brdp);
+#endif
+
        outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
        udelay(10);
        outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
@@ -3191,6 +3561,9 @@ static void stli_onbinit(stlibrd_t *brdp)
 
 static void stli_onbenable(stlibrd_t *brdp)
 {      
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_onbenable(brdp=%x)\n", (int) brdp);
+#endif
        outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
 }
 
@@ -3198,6 +3571,9 @@ static void stli_onbenable(stlibrd_t *brdp)
 
 static void stli_onbdisable(stlibrd_t *brdp)
 {      
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_onbdisable(brdp=%x)\n", (int) brdp);
+#endif
        outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
 }
 
@@ -3207,6 +3583,11 @@ static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
        void    *ptr;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
+               (int) offset);
+#endif
+
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
                                "range at line=%d(%d), brd=%d\n",
@@ -3222,6 +3603,11 @@ static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 
 static void stli_onbreset(stlibrd_t *brdp)
 {      
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_onbreset(brdp=%x)\n", (int) brdp);
+#endif
+
        outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
        udelay(10);
        outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
@@ -3238,6 +3624,10 @@ static void stli_onbeinit(stlibrd_t *brdp)
 {
        unsigned long   memconf;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_onbeinit(brdp=%d)\n", (int) brdp);
+#endif
+
        outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
        outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
        udelay(10);
@@ -3256,6 +3646,9 @@ static void stli_onbeinit(stlibrd_t *brdp)
 
 static void stli_onbeenable(stlibrd_t *brdp)
 {      
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_onbeenable(brdp=%x)\n", (int) brdp);
+#endif
        outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
 }
 
@@ -3263,6 +3656,9 @@ static void stli_onbeenable(stlibrd_t *brdp)
 
 static void stli_onbedisable(stlibrd_t *brdp)
 {      
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_onbedisable(brdp=%x)\n", (int) brdp);
+#endif
        outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
 }
 
@@ -3270,8 +3666,13 @@ static void stli_onbedisable(stlibrd_t *brdp)
 
 static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       void *ptr;
-       unsigned char val;
+       void            *ptr;
+       unsigned char   val;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
+               (int) brdp, (int) offset, line);
+#endif
 
        if (offset > brdp->memsize) {
                printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3294,6 +3695,11 @@ static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 
 static void stli_onbereset(stlibrd_t *brdp)
 {      
+
+#ifdef DEBUG
+       printk(KERN_ERR "stli_onbereset(brdp=%x)\n", (int) brdp);
+#endif
+
        outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
        udelay(10);
        outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
@@ -3308,6 +3714,11 @@ static void stli_onbereset(stlibrd_t *brdp)
 
 static void stli_bbyinit(stlibrd_t *brdp)
 {
+
+#ifdef DEBUG
+       printk(KERN_ERR "stli_bbyinit(brdp=%d)\n", (int) brdp);
+#endif
+
        outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
        udelay(10);
        outb(0, (brdp->iobase + BBY_ATCONFR));
@@ -3320,13 +3731,24 @@ static void stli_bbyinit(stlibrd_t *brdp)
 
 static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       void *ptr;
-       unsigned char val;
+       void            *ptr;
+       unsigned char   val;
 
-       BUG_ON(offset > brdp->memsize);
+#ifdef DEBUG
+       printk(KERN_ERR "stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
+               (int) offset);
+#endif
 
-       ptr = brdp->membase + (offset % BBY_PAGESIZE);
-       val = (unsigned char) (offset / BBY_PAGESIZE);
+       if (offset > brdp->memsize) {
+               printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
+                               "range at line=%d(%d), brd=%d\n",
+                               (int) offset, line, __LINE__, brdp->brdnr);
+               ptr = NULL;
+               val = 0;
+       } else {
+               ptr = brdp->membase + (offset % BBY_PAGESIZE);
+               val = (unsigned char) (offset / BBY_PAGESIZE);
+       }
        outb(val, (brdp->iobase + BBY_ATCONFR));
        return(ptr);
 }
@@ -3335,6 +3757,11 @@ static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 
 static void stli_bbyreset(stlibrd_t *brdp)
 {      
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_bbyreset(brdp=%x)\n", (int) brdp);
+#endif
+
        outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
        udelay(10);
        outb(0, (brdp->iobase + BBY_ATCONFR));
@@ -3349,6 +3776,11 @@ static void stli_bbyreset(stlibrd_t *brdp)
 
 static void stli_stalinit(stlibrd_t *brdp)
 {
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_stalinit(brdp=%d)\n", (int) brdp);
+#endif
+
        outb(0x1, brdp->iobase);
        mdelay(1000);
 }
@@ -3357,18 +3789,36 @@ static void stli_stalinit(stlibrd_t *brdp)
 
 static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
 {      
-       BUG_ON(offset > brdp->memsize);
-       return brdp->membase + (offset % STAL_PAGESIZE);
+       void    *ptr;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
+               (int) offset);
+#endif
+
+       if (offset > brdp->memsize) {
+               printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
+                               "range at line=%d(%d), brd=%d\n",
+                               (int) offset, line, __LINE__, brdp->brdnr);
+               ptr = NULL;
+       } else {
+               ptr = brdp->membase + (offset % STAL_PAGESIZE);
+       }
+       return(ptr);
 }
 
 /*****************************************************************************/
 
 static void stli_stalreset(stlibrd_t *brdp)
 {      
-       u32 __iomem *vecp;
+       volatile unsigned long  *vecp;
 
-       vecp = (u32 __iomem *) (brdp->membase + 0x30);
-       writel(0xffff0000, vecp);
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_stalreset(brdp=%x)\n", (int) brdp);
+#endif
+
+       vecp = (volatile unsigned long *) (brdp->membase + 0x30);
+       *vecp = 0xffff0000;
        outb(0, brdp->iobase);
        mdelay(1000);
 }
@@ -3382,11 +3832,15 @@ static void stli_stalreset(stlibrd_t *brdp)
 
 static int stli_initecp(stlibrd_t *brdp)
 {
-       cdkecpsig_t sig;
-       cdkecpsig_t __iomem *sigsp;
-       unsigned int status, nxtid;
-       char *name;
-       int panelnr, nrports;
+       cdkecpsig_t     sig;
+       cdkecpsig_t     *sigsp;
+       unsigned int    status, nxtid;
+       char            *name;
+       int             panelnr, nrports;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_initecp(brdp=%x)\n", (int) brdp);
+#endif
 
        if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
                return -EIO;
@@ -3394,7 +3848,7 @@ static int stli_initecp(stlibrd_t *brdp)
        if ((brdp->iobase == 0) || (brdp->memaddr == 0))
        {
                release_region(brdp->iobase, brdp->iosize);
-               return -ENODEV;
+               return(-ENODEV);
        }
 
        brdp->iosize = ECP_IOSIZE;
@@ -3463,7 +3917,7 @@ static int stli_initecp(stlibrd_t *brdp)
 
        default:
                release_region(brdp->iobase, brdp->iosize);
-               return -EINVAL;
+               return(-EINVAL);
        }
 
 /*
@@ -3475,10 +3929,10 @@ static int stli_initecp(stlibrd_t *brdp)
        EBRDINIT(brdp);
 
        brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
-       if (brdp->membase == NULL)
+       if (brdp->membase == (void *) NULL)
        {
                release_region(brdp->iobase, brdp->iosize);
-               return -ENOMEM;
+               return(-ENOMEM);
        }
 
 /*
@@ -3487,14 +3941,23 @@ static int stli_initecp(stlibrd_t *brdp)
  *     this is, and what it is connected to it.
  */
        EBRDENABLE(brdp);
-       sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
+       sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
        memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
        EBRDDISABLE(brdp);
 
-       if (sig.magic != cpu_to_le32(ECP_MAGIC))
+#if 0
+       printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
+               __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
+               (int) sig.panelid[1], (int) sig.panelid[2],
+               (int) sig.panelid[3], (int) sig.panelid[4],
+               (int) sig.panelid[5], (int) sig.panelid[6],
+               (int) sig.panelid[7]);
+#endif
+
+       if (sig.magic != ECP_MAGIC)
        {
                release_region(brdp->iobase, brdp->iosize);
-               return -ENODEV;
+               return(-ENODEV);
        }
 
 /*
@@ -3518,7 +3981,7 @@ static int stli_initecp(stlibrd_t *brdp)
 
 
        brdp->state |= BST_FOUND;
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -3530,16 +3993,20 @@ static int stli_initecp(stlibrd_t *brdp)
 
 static int stli_initonb(stlibrd_t *brdp)
 {
-       cdkonbsig_t sig;
-       cdkonbsig_t __iomem *sigsp;
-       char *name;
-       int i;
+       cdkonbsig_t     sig;
+       cdkonbsig_t     *sigsp;
+       char            *name;
+       int             i;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_initonb(brdp=%x)\n", (int) brdp);
+#endif
 
 /*
  *     Do a basic sanity check on the IO and memory addresses.
  */
-       if (brdp->iobase == 0 || brdp->memaddr == 0)
-               return -ENODEV;
+       if ((brdp->iobase == 0) || (brdp->memaddr == 0))
+               return(-ENODEV);
 
        brdp->iosize = ONB_IOSIZE;
        
@@ -3557,6 +4024,7 @@ static int stli_initonb(stlibrd_t *brdp)
        case BRD_ONBOARD2:
        case BRD_ONBOARD2_32:
        case BRD_ONBOARDRS:
+               brdp->membase = (void *) brdp->memaddr;
                brdp->memsize = ONB_MEMSIZE;
                brdp->pagesize = ONB_ATPAGESIZE;
                brdp->init = stli_onbinit;
@@ -3574,6 +4042,7 @@ static int stli_initonb(stlibrd_t *brdp)
                break;
 
        case BRD_ONBOARDE:
+               brdp->membase = (void *) brdp->memaddr;
                brdp->memsize = ONB_EIMEMSIZE;
                brdp->pagesize = ONB_EIPAGESIZE;
                brdp->init = stli_onbeinit;
@@ -3589,6 +4058,7 @@ static int stli_initonb(stlibrd_t *brdp)
        case BRD_BRUMBY4:
        case BRD_BRUMBY8:
        case BRD_BRUMBY16:
+               brdp->membase = (void *) brdp->memaddr;
                brdp->memsize = BBY_MEMSIZE;
                brdp->pagesize = BBY_PAGESIZE;
                brdp->init = stli_bbyinit;
@@ -3602,6 +4072,7 @@ static int stli_initonb(stlibrd_t *brdp)
                break;
 
        case BRD_STALLION:
+               brdp->membase = (void *) brdp->memaddr;
                brdp->memsize = STAL_MEMSIZE;
                brdp->pagesize = STAL_PAGESIZE;
                brdp->init = stli_stalinit;
@@ -3616,7 +4087,7 @@ static int stli_initonb(stlibrd_t *brdp)
 
        default:
                release_region(brdp->iobase, brdp->iosize);
-               return -EINVAL;
+               return(-EINVAL);
        }
 
 /*
@@ -3628,10 +4099,10 @@ static int stli_initonb(stlibrd_t *brdp)
        EBRDINIT(brdp);
 
        brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
-       if (brdp->membase == NULL)
+       if (brdp->membase == (void *) NULL)
        {
                release_region(brdp->iobase, brdp->iosize);
-               return -ENOMEM;
+               return(-ENOMEM);
        }
 
 /*
@@ -3640,17 +4111,21 @@ static int stli_initonb(stlibrd_t *brdp)
  *     this is, and how many ports.
  */
        EBRDENABLE(brdp);
-       sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
-       memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
+       sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
+       memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
        EBRDDISABLE(brdp);
 
-       if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
-           sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
-           sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
-           sig.magic3 != cpu_to_le16(ONB_MAGIC3))
+#if 0
+       printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
+               __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
+               sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
+#endif
+
+       if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
+           (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
        {
                release_region(brdp->iobase, brdp->iosize);
-               return -ENODEV;
+               return(-ENODEV);
        }
 
 /*
@@ -3671,7 +4146,7 @@ static int stli_initonb(stlibrd_t *brdp)
 
 
        brdp->state |= BST_FOUND;
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -3684,25 +4159,31 @@ static int stli_initonb(stlibrd_t *brdp)
 
 static int stli_startbrd(stlibrd_t *brdp)
 {
-       cdkhdr_t __iomem *hdrp;
-       cdkmem_t __iomem *memp;
-       cdkasy_t __iomem *ap;
-       unsigned long flags;
-       stliport_t *portp;
-       int portnr, nrdevs, i, rc = 0;
-       u32 memoff;
-
-       spin_lock_irqsave(&brd_lock, flags);
+       volatile cdkhdr_t       *hdrp;
+       volatile cdkmem_t       *memp;
+       volatile cdkasy_t       *ap;
+       unsigned long           flags;
+       stliport_t              *portp;
+       int                     portnr, nrdevs, i, rc;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_startbrd(brdp=%x)\n", (int) brdp);
+#endif
+
+       rc = 0;
+
+       save_flags(flags);
+       cli();
        EBRDENABLE(brdp);
-       hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
+       hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
        nrdevs = hdrp->nrdevs;
 
 #if 0
        printk("%s(%d): CDK version %d.%d.%d --> "
                "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
-                __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
-                readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
-                readl(&hdrp->slavep));
+                __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
+                hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
+                (int) hdrp->slavep);
 #endif
 
        if (nrdevs < (brdp->nrports + 1)) {
@@ -3714,14 +4195,14 @@ static int stli_startbrd(stlibrd_t *brdp)
        brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
        brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
        brdp->bitsize = (nrdevs + 7) / 8;
-       memoff = readl(&hdrp->memp);
-       if (memoff > brdp->memsize) {
+       memp = (volatile cdkmem_t *) hdrp->memp;
+       if (((unsigned long) memp) > brdp->memsize) {
                printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
                rc = -EIO;
                goto stli_donestartup;
        }
-       memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
-       if (readw(&memp->dtype) != TYP_ASYNCTRL) {
+       memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
+       if (memp->dtype != TYP_ASYNCTRL) {
                printk(KERN_ERR "STALLION: no slave control device found\n");
                goto stli_donestartup;
        }
@@ -3733,19 +4214,19 @@ static int stli_startbrd(stlibrd_t *brdp)
  *     change pages while reading memory map.
  */
        for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
-               if (readw(&memp->dtype) != TYP_ASYNC)
+               if (memp->dtype != TYP_ASYNC)
                        break;
                portp = brdp->ports[portnr];
-               if (portp == NULL)
+               if (portp == (stliport_t *) NULL)
                        break;
                portp->devnr = i;
-               portp->addr = readl(&memp->offset);
+               portp->addr = memp->offset;
                portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
                portp->portidx = (unsigned char) (i / 8);
                portp->portbit = (unsigned char) (0x1 << (i % 8));
        }
 
-       writeb(0xff, &hdrp->slavereq);
+       hdrp->slavereq = 0xff;
 
 /*
  *     For each port setup a local copy of the RX and TX buffer offsets
@@ -3754,22 +4235,22 @@ static int stli_startbrd(stlibrd_t *brdp)
  */
        for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
                portp = brdp->ports[portnr];
-               if (portp == NULL)
+               if (portp == (stliport_t *) NULL)
                        break;
                if (portp->addr == 0)
                        break;
-               ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
-               if (ap != NULL) {
-                       portp->rxsize = readw(&ap->rxq.size);
-                       portp->txsize = readw(&ap->txq.size);
-                       portp->rxoffset = readl(&ap->rxq.offset);
-                       portp->txoffset = readl(&ap->txq.offset);
+               ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
+               if (ap != (volatile cdkasy_t *) NULL) {
+                       portp->rxsize = ap->rxq.size;
+                       portp->txsize = ap->txq.size;
+                       portp->rxoffset = ap->rxq.offset;
+                       portp->txoffset = ap->txq.offset;
                }
        }
 
 stli_donestartup:
        EBRDDISABLE(brdp);
-       spin_unlock_irqrestore(&brd_lock, flags);
+       restore_flags(flags);
 
        if (rc == 0)
                brdp->state |= BST_STARTED;
@@ -3780,7 +4261,7 @@ stli_donestartup:
                add_timer(&stli_timerlist);
        }
 
-       return rc;
+       return(rc);
 }
 
 /*****************************************************************************/
@@ -3791,6 +4272,10 @@ stli_donestartup:
 
 static int __init stli_brdinit(stlibrd_t *brdp)
 {
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_brdinit(brdp=%x)\n", (int) brdp);
+#endif
+
        stli_brds[brdp->brdnr] = brdp;
 
        switch (brdp->brdtype) {
@@ -3818,11 +4303,11 @@ static int __init stli_brdinit(stlibrd_t *brdp)
        case BRD_ECHPCI:
                printk(KERN_ERR "STALLION: %s board type not supported in "
                                "this driver\n", stli_brdnames[brdp->brdtype]);
-               return -ENODEV;
+               return(ENODEV);
        default:
                printk(KERN_ERR "STALLION: board=%d is unknown board "
                                "type=%d\n", brdp->brdnr, brdp->brdtype);
-               return -ENODEV;
+               return(ENODEV);
        }
 
        if ((brdp->state & BST_FOUND) == 0) {
@@ -3830,7 +4315,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
                                "io=%x mem=%x\n",
                        stli_brdnames[brdp->brdtype], brdp->brdnr,
                        brdp->iobase, (int) brdp->memaddr);
-               return -ENODEV;
+               return(ENODEV);
        }
 
        stli_initports(brdp);
@@ -3838,7 +4323,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
                "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
                brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
                brdp->nrpanels, brdp->nrports);
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -3850,10 +4335,14 @@ static int __init stli_brdinit(stlibrd_t *brdp)
 
 static int stli_eisamemprobe(stlibrd_t *brdp)
 {
-       cdkecpsig_t     ecpsig, __iomem *ecpsigp;
-       cdkonbsig_t     onbsig, __iomem *onbsigp;
+       cdkecpsig_t     ecpsig, *ecpsigp;
+       cdkonbsig_t     onbsig, *onbsigp;
        int             i, foundit;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_eisamemprobe(brdp=%x)\n", (int) brdp);
+#endif
+
 /*
  *     First up we reset the board, to get it into a known state. There
  *     is only 2 board types here we need to worry about. Don;t use the
@@ -3877,7 +4366,7 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
                mdelay(1);
                stli_onbeenable(brdp);
        } else {
-               return -ENODEV;
+               return(-ENODEV);
        }
 
        foundit = 0;
@@ -3889,24 +4378,25 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
  */
        for (i = 0; (i < stli_eisamempsize); i++) {
                brdp->memaddr = stli_eisamemprobeaddrs[i];
+               brdp->membase = (void *) brdp->memaddr;
                brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
-               if (brdp->membase == NULL)
+               if (brdp->membase == (void *) NULL)
                        continue;
 
                if (brdp->brdtype == BRD_ECPE) {
-                       ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp,
+                       ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp,
                                CDK_SIGADDR, __LINE__);
-                       memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
-                       if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
+                       memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
+                       if (ecpsig.magic == ECP_MAGIC)
                                foundit = 1;
                } else {
-                       onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
+                       onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp,
                                CDK_SIGADDR, __LINE__);
-                       memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
-                       if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
-                           (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
-                           (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
-                           (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
+                       memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
+                       if ((onbsig.magic0 == ONB_MAGIC0) &&
+                           (onbsig.magic1 == ONB_MAGIC1) &&
+                           (onbsig.magic2 == ONB_MAGIC2) &&
+                           (onbsig.magic3 == ONB_MAGIC3))
                                foundit = 1;
                }
 
@@ -3930,9 +4420,9 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
                printk(KERN_ERR "STALLION: failed to probe shared memory "
                                "region for %s in EISA slot=%d\n",
                        stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
-               return -ENODEV;
+               return(-ENODEV);
        }
-       return 0;
+       return(0);
 }
 
 static int stli_getbrdnr(void)
@@ -3963,16 +4453,22 @@ static int stli_getbrdnr(void)
 
 static int stli_findeisabrds(void)
 {
-       stlibrd_t *brdp;
-       unsigned int iobase, eid;
-       int i;
+       stlibrd_t       *brdp;
+       unsigned int    iobase, eid;
+       int             i;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_findeisabrds()\n");
+#endif
 
 /*
- *     Firstly check if this is an EISA system.  If this is not an EISA system then
+ *     Firstly check if this is an EISA system. Do this by probing for
+ *     the system board EISA ID. If this is not an EISA system then
  *     don't bother going any further!
  */
-       if (EISA_bus)
-               return 0;
+       outb(0xff, 0xc80);
+       if (inb(0xc80) == 0xff)
+               return(0);
 
 /*
  *     Looks like an EISA system, so go searching for EISA boards.
@@ -3990,7 +4486,7 @@ static int stli_findeisabrds(void)
  */
                for (i = 0; (i < STL_MAXBRDS); i++) {
                        brdp = stli_brds[i];
-                       if (brdp == NULL)
+                       if (brdp == (stlibrd_t *) NULL)
                                continue;
                        if (brdp->iobase == iobase)
                                break;
@@ -4002,10 +4498,10 @@ static int stli_findeisabrds(void)
  *             We have found a Stallion board and it is not configured already.
  *             Allocate a board structure and initialize it.
  */
-               if ((brdp = stli_allocbrd()) == NULL)
-                       return -ENOMEM;
+               if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
+                       return(-ENOMEM);
                if ((brdp->brdnr = stli_getbrdnr()) < 0)
-                       return -ENOMEM;
+                       return(-ENOMEM);
                eid = inb(iobase + 0xc82);
                if (eid == ECP_EISAID)
                        brdp->brdtype = BRD_ECPE;
@@ -4020,7 +4516,7 @@ static int stli_findeisabrds(void)
                stli_brdinit(brdp);
        }
 
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -4041,18 +4537,32 @@ static int stli_findeisabrds(void)
 
 static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
 {
-       stlibrd_t *brdp;
+       stlibrd_t       *brdp;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
+               brdtype, dev->bus->number, dev->devfn);
+#endif
 
        if (pci_enable_device(devp))
-               return -EIO;
-       if ((brdp = stli_allocbrd()) == NULL)
-               return -ENOMEM;
+               return(-EIO);
+       if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
+               return(-ENOMEM);
        if ((brdp->brdnr = stli_getbrdnr()) < 0) {
                printk(KERN_INFO "STALLION: too many boards found, "
                        "maximum supported %d\n", STL_MAXBRDS);
-               return 0;
+               return(0);
        }
        brdp->brdtype = brdtype;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__, __LINE__,
+               pci_resource_start(devp, 0),
+               pci_resource_start(devp, 1),
+               pci_resource_start(devp, 2),
+               pci_resource_start(devp, 3));
+#endif
+
 /*
  *     We have all resources from the board, so lets setup the actual
  *     board structure now.
@@ -4061,7 +4571,7 @@ static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
        brdp->memaddr = pci_resource_start(devp, 2);
        stli_brdinit(brdp);
 
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -4073,12 +4583,20 @@ static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
 
 static int stli_findpcibrds(void)
 {
-       struct pci_dev *dev = NULL;
+       struct pci_dev  *dev = NULL;
+       int             rc;
+
+#ifdef DEBUG
+       printk("stli_findpcibrds()\n");
+#endif
 
-       while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) {
-               stli_initpcibrd(BRD_ECPPCI, dev);
+       while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION,
+           PCI_DEVICE_ID_ECRA, dev))) {
+               if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
+                       return(rc);
        }
-       return 0;
+
+       return(0);
 }
 
 #endif
@@ -4091,16 +4609,18 @@ static int stli_findpcibrds(void)
 
 static stlibrd_t *stli_allocbrd(void)
 {
-       stlibrd_t *brdp;
+       stlibrd_t       *brdp;
 
-       brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
-       if (!brdp) {
+       brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
+       if (brdp == (stlibrd_t *) NULL) {
                printk(KERN_ERR "STALLION: failed to allocate memory "
-                               "(size=%Zd)\n", sizeof(stlibrd_t));
-               return NULL;
+                               "(size=%d)\n", sizeof(stlibrd_t));
+               return((stlibrd_t *) NULL);
        }
+
+       memset(brdp, 0, sizeof(stlibrd_t));
        brdp->magic = STLI_BOARDMAGIC;
-       return brdp;
+       return(brdp);
 }
 
 /*****************************************************************************/
@@ -4112,9 +4632,13 @@ static stlibrd_t *stli_allocbrd(void)
 
 static int stli_initbrds(void)
 {
-       stlibrd_t *brdp, *nxtbrdp;
-       stlconf_t *confp;
-       int i, j;
+       stlibrd_t       *brdp, *nxtbrdp;
+       stlconf_t       *confp;
+       int             i, j;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_initbrds()\n");
+#endif
 
        if (stli_nrbrds > STL_MAXBRDS) {
                printk(KERN_INFO "STALLION: too many boards in configuration "
@@ -4129,9 +4653,11 @@ static int stli_initbrds(void)
  */
        for (i = 0; (i < stli_nrbrds); i++) {
                confp = &stli_brdconf[i];
+#ifdef MODULE
                stli_parsebrd(confp, stli_brdsp[i]);
-               if ((brdp = stli_allocbrd()) == NULL)
-                       return -ENOMEM;
+#endif
+               if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
+                       return(-ENOMEM);
                brdp->brdnr = i;
                brdp->brdtype = confp->brdtype;
                brdp->iobase = confp->ioaddr1;
@@ -4143,7 +4669,9 @@ static int stli_initbrds(void)
  *     Static configuration table done, so now use dynamic methods to
  *     see if any more boards should be configured.
  */
+#ifdef MODULE
        stli_argbrds();
+#endif
        if (STLI_EISAPROBE)
                stli_findeisabrds();
 #ifdef CONFIG_PCI
@@ -4159,11 +4687,11 @@ static int stli_initbrds(void)
        if (stli_nrbrds > 1) {
                for (i = 0; (i < stli_nrbrds); i++) {
                        brdp = stli_brds[i];
-                       if (brdp == NULL)
+                       if (brdp == (stlibrd_t *) NULL)
                                continue;
                        for (j = i + 1; (j < stli_nrbrds); j++) {
                                nxtbrdp = stli_brds[j];
-                               if (nxtbrdp == NULL)
+                               if (nxtbrdp == (stlibrd_t *) NULL)
                                        continue;
                                if ((brdp->membase >= nxtbrdp->membase) &&
                                    (brdp->membase <= (nxtbrdp->membase +
@@ -4178,7 +4706,7 @@ static int stli_initbrds(void)
        if (stli_shared == 0) {
                for (i = 0; (i < stli_nrbrds); i++) {
                        brdp = stli_brds[i];
-                       if (brdp == NULL)
+                       if (brdp == (stlibrd_t *) NULL)
                                continue;
                        if (brdp->state & BST_FOUND) {
                                EBRDENABLE(brdp);
@@ -4188,7 +4716,7 @@ static int stli_initbrds(void)
                }
        }
 
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -4201,55 +4729,48 @@ static int stli_initbrds(void)
 
 static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
 {
-       unsigned long flags;
-       void *memptr;
-       stlibrd_t *brdp;
-       int brdnr, size, n;
-       void *p;
-       loff_t off = *offp;
+       unsigned long   flags;
+       void            *memptr;
+       stlibrd_t       *brdp;
+       int             brdnr, size, n;
+
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n",
+                       (int) fp, (int) buf, count, (int) offp);
+#endif
 
        brdnr = iminor(fp->f_dentry->d_inode);
        if (brdnr >= stli_nrbrds)
-               return -ENODEV;
+               return(-ENODEV);
        brdp = stli_brds[brdnr];
-       if (brdp == NULL)
-               return -ENODEV;
+       if (brdp == (stlibrd_t *) NULL)
+               return(-ENODEV);
        if (brdp->state == 0)
-               return -ENODEV;
-       if (off >= brdp->memsize || off + count < off)
-               return 0;
+               return(-ENODEV);
+       if (fp->f_pos >= brdp->memsize)
+               return(0);
 
-       size = MIN(count, (brdp->memsize - off));
-
-       /*
-        *      Copy the data a page at a time
-        */
-
-       p = (void *)__get_free_page(GFP_KERNEL);
-       if(p == NULL)
-               return -ENOMEM;
+       size = MIN(count, (brdp->memsize - fp->f_pos));
 
+       save_flags(flags);
+       cli();
+       EBRDENABLE(brdp);
        while (size > 0) {
-               spin_lock_irqsave(&brd_lock, flags);
-               EBRDENABLE(brdp);
-               memptr = (void *) EBRDGETMEMPTR(brdp, off);
-               n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
-               n = MIN(n, PAGE_SIZE);
-               memcpy_fromio(p, memptr, n);
-               EBRDDISABLE(brdp);
-               spin_unlock_irqrestore(&brd_lock, flags);
-               if (copy_to_user(buf, p, n)) {
+               memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
+               n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
+               if (copy_to_user(buf, memptr, n)) {
                        count = -EFAULT;
                        goto out;
                }
-               off += n;
+               fp->f_pos += n;
                buf += n;
                size -= n;
        }
 out:
-       *offp = off;
-       free_page((unsigned long)p);
-       return count;
+       EBRDDISABLE(brdp);
+       restore_flags(flags);
+
+       return(count);
 }
 
 /*****************************************************************************/
@@ -4258,65 +4779,54 @@ out:
  *     Code to handle an "staliomem" write operation. This device is the 
  *     contents of the board shared memory. It is used for down loading
  *     the slave image (and debugging :-)
- *
- *     FIXME: copy under lock
  */
 
 static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
 {
-       unsigned long flags;
-       void *memptr;
-       stlibrd_t *brdp;
-       char __user *chbuf;
-       int brdnr, size, n;
-       void *p;
-       loff_t off = *offp;
+       unsigned long   flags;
+       void            *memptr;
+       stlibrd_t       *brdp;
+       char            __user *chbuf;
+       int             brdnr, size, n;
 
-       brdnr = iminor(fp->f_dentry->d_inode);
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n",
+                       (int) fp, (int) buf, count, (int) offp);
+#endif
 
+       brdnr = iminor(fp->f_dentry->d_inode);
        if (brdnr >= stli_nrbrds)
-               return -ENODEV;
+               return(-ENODEV);
        brdp = stli_brds[brdnr];
-       if (brdp == NULL)
-               return -ENODEV;
+       if (brdp == (stlibrd_t *) NULL)
+               return(-ENODEV);
        if (brdp->state == 0)
-               return -ENODEV;
-       if (off >= brdp->memsize || off + count < off)
-               return 0;
+               return(-ENODEV);
+       if (fp->f_pos >= brdp->memsize)
+               return(0);
 
        chbuf = (char __user *) buf;
-       size = MIN(count, (brdp->memsize - off));
-
-       /*
-        *      Copy the data a page at a time
-        */
-
-       p = (void *)__get_free_page(GFP_KERNEL);
-       if(p == NULL)
-               return -ENOMEM;
+       size = MIN(count, (brdp->memsize - fp->f_pos));
 
+       save_flags(flags);
+       cli();
+       EBRDENABLE(brdp);
        while (size > 0) {
-               n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
-               n = MIN(n, PAGE_SIZE);
-               if (copy_from_user(p, chbuf, n)) {
-                       if (count == 0)
-                               count = -EFAULT;
+               memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
+               n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
+               if (copy_from_user(memptr, chbuf, n)) {
+                       count = -EFAULT;
                        goto out;
                }
-               spin_lock_irqsave(&brd_lock, flags);
-               EBRDENABLE(brdp);
-               memptr = (void *) EBRDGETMEMPTR(brdp, off);
-               memcpy_toio(memptr, p, n);
-               EBRDDISABLE(brdp);
-               spin_unlock_irqrestore(&brd_lock, flags);
-               off += n;
+               fp->f_pos += n;
                chbuf += n;
                size -= n;
        }
 out:
-       free_page((unsigned long) p);
-       *offp = off;
-       return count;
+       EBRDDISABLE(brdp);
+       restore_flags(flags);
+
+       return(count);
 }
 
 /*****************************************************************************/
@@ -4327,16 +4837,16 @@ out:
 
 static int stli_getbrdstats(combrd_t __user *bp)
 {
-       stlibrd_t *brdp;
-       int i;
+       stlibrd_t       *brdp;
+       int             i;
 
        if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
                return -EFAULT;
        if (stli_brdstats.brd >= STL_MAXBRDS)
-               return -ENODEV;
+               return(-ENODEV);
        brdp = stli_brds[stli_brdstats.brd];
-       if (brdp == NULL)
-               return -ENODEV;
+       if (brdp == (stlibrd_t *) NULL)
+               return(-ENODEV);
 
        memset(&stli_brdstats, 0, sizeof(combrd_t));
        stli_brdstats.brd = brdp->brdnr;
@@ -4355,7 +4865,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
 
        if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
                return -EFAULT;
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -4366,19 +4876,19 @@ static int stli_getbrdstats(combrd_t __user *bp)
 
 static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
 {
-       stlibrd_t *brdp;
-       int i;
+       stlibrd_t       *brdp;
+       int             i;
 
-       if (brdnr < 0 || brdnr >= STL_MAXBRDS)
-               return NULL;
+       if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
+               return((stliport_t *) NULL);
        brdp = stli_brds[brdnr];
-       if (brdp == NULL)
-               return NULL;
+       if (brdp == (stlibrd_t *) NULL)
+               return((stliport_t *) NULL);
        for (i = 0; (i < panelnr); i++)
                portnr += brdp->panels[i];
        if ((portnr < 0) || (portnr >= brdp->nrports))
-               return NULL;
-       return brdp->ports[portnr];
+               return((stliport_t *) NULL);
+       return(brdp->ports[portnr]);
 }
 
 /*****************************************************************************/
@@ -4397,16 +4907,16 @@ static int stli_portcmdstats(stliport_t *portp)
 
        memset(&stli_comstats, 0, sizeof(comstats_t));
 
-       if (portp == NULL)
-               return -ENODEV;
+       if (portp == (stliport_t *) NULL)
+               return(-ENODEV);
        brdp = stli_brds[portp->brdnr];
-       if (brdp == NULL)
-               return -ENODEV;
+       if (brdp == (stlibrd_t *) NULL)
+               return(-ENODEV);
 
        if (brdp->state & BST_STARTED) {
                if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
                    &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
-                       return rc;
+                       return(rc);
        } else {
                memset(&stli_cdkstats, 0, sizeof(asystats_t));
        }
@@ -4417,12 +4927,13 @@ static int stli_portcmdstats(stliport_t *portp)
        stli_comstats.state = portp->state;
        stli_comstats.flags = portp->flags;
 
-       spin_lock_irqsave(&brd_lock, flags);
-       if (portp->tty != NULL) {
+       save_flags(flags);
+       cli();
+       if (portp->tty != (struct tty_struct *) NULL) {
                if (portp->tty->driver_data == portp) {
                        stli_comstats.ttystate = portp->tty->flags;
-                       stli_comstats.rxbuffered = -1;
-                       if (portp->tty->termios != NULL) {
+                       stli_comstats.rxbuffered = -1 /*portp->tty->flip.count*/;
+                       if (portp->tty->termios != (struct termios *) NULL) {
                                stli_comstats.cflags = portp->tty->termios->c_cflag;
                                stli_comstats.iflags = portp->tty->termios->c_iflag;
                                stli_comstats.oflags = portp->tty->termios->c_oflag;
@@ -4430,7 +4941,7 @@ static int stli_portcmdstats(stliport_t *portp)
                        }
                }
        }
-       spin_unlock_irqrestore(&brd_lock, flags);
+       restore_flags(flags);
 
        stli_comstats.txtotal = stli_cdkstats.txchars;
        stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
@@ -4452,7 +4963,7 @@ static int stli_portcmdstats(stliport_t *portp)
        stli_comstats.hwid = stli_cdkstats.hwid;
        stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
 
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/
@@ -4465,8 +4976,8 @@ static int stli_portcmdstats(stliport_t *portp)
 
 static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
 {
-       stlibrd_t *brdp;
-       int rc;
+       stlibrd_t       *brdp;
+       int             rc;
 
        if (!portp) {
                if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
@@ -4496,8 +5007,8 @@ static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
 
 static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
 {
-       stlibrd_t *brdp;
-       int rc;
+       stlibrd_t       *brdp;
+       int             rc;
 
        if (!portp) {
                if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
@@ -4535,7 +5046,7 @@ static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
 
 static int stli_getportstruct(stliport_t __user *arg)
 {
-       stliport_t *portp;
+       stliport_t      *portp;
 
        if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
                return -EFAULT;
@@ -4556,7 +5067,7 @@ static int stli_getportstruct(stliport_t __user *arg)
 
 static int stli_getbrdstruct(stlibrd_t __user *arg)
 {
-       stlibrd_t *brdp;
+       stlibrd_t       *brdp;
 
        if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
                return -EFAULT;
@@ -4580,10 +5091,15 @@ static int stli_getbrdstruct(stlibrd_t __user *arg)
 
 static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
 {
-       stlibrd_t *brdp;
-       int brdnr, rc, done;
+       stlibrd_t       *brdp;
+       int             brdnr, rc, done;
        void __user *argp = (void __user *)arg;
 
+#ifdef DEBUG
+       printk(KERN_DEBUG "stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n",
+                       (int) ip, (int) fp, cmd, (int) arg);
+#endif
+
 /*
  *     First up handle the board independent ioctls.
  */
@@ -4614,7 +5130,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
        }
 
        if (done)
-               return rc;
+               return(rc);
 
 /*
  *     Now handle the board specific ioctls. These all depend on the
@@ -4622,12 +5138,12 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
  */
        brdnr = iminor(ip);
        if (brdnr >= STL_MAXBRDS)
-               return -ENODEV;
+               return(-ENODEV);
        brdp = stli_brds[brdnr];
        if (!brdp)
-               return -ENODEV;
+               return(-ENODEV);
        if (brdp->state == 0)
-               return -ENODEV;
+               return(-ENODEV);
 
        switch (cmd) {
        case STL_BINTR:
@@ -4651,7 +5167,8 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
                rc = -ENOIOCTLCMD;
                break;
        }
-       return rc;
+
+       return(rc);
 }
 
 static struct tty_operations stli_ops = {
@@ -4680,14 +5197,11 @@ static struct tty_operations stli_ops = {
 
 /*****************************************************************************/
 
-static int __init stli_init(void)
+int __init stli_init(void)
 {
        int i;
        printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
 
-       spin_lock_init(&stli_lock);
-       spin_lock_init(&brd_lock);
-
        stli_initbrds();
 
        stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
@@ -4697,8 +5211,12 @@ static int __init stli_init(void)
 /*
  *     Allocate a temporary write buffer.
  */
-       stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
-       if (!stli_txcookbuf)
+       stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
+       if (stli_tmpwritebuf == (char *) NULL)
+               printk(KERN_ERR "STALLION: failed to allocate memory "
+                               "(size=%d)\n", STLI_TXBUFSIZE);
+       stli_txcookbuf = stli_memalloc(STLI_TXBUFSIZE);
+       if (stli_txcookbuf == (char *) NULL)
                printk(KERN_ERR "STALLION: failed to allocate memory "
                                "(size=%d)\n", STLI_TXBUFSIZE);
 
@@ -4710,11 +5228,16 @@ static int __init stli_init(void)
                printk(KERN_ERR "STALLION: failed to register serial memory "
                                "device\n");
 
+       devfs_mk_dir("staliomem");
        istallion_class = class_create(THIS_MODULE, "staliomem");
-       for (i = 0; i < 4; i++)
+       for (i = 0; i < 4; i++) {
+               devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
+                              S_IFCHR | S_IRUSR | S_IWUSR,
+                              "staliomem/%d", i);
                class_device_create(istallion_class, NULL,
                                MKDEV(STL_SIOMEMMAJOR, i),
                                NULL, "staliomem%d", i);
+       }
 
 /*
  *     Set up the tty driver structure and register us as a driver.
@@ -4735,7 +5258,7 @@ static int __init stli_init(void)
                printk(KERN_ERR "STALLION: failed to register serial driver\n");
                return -EBUSY;
        }
-       return 0;
+       return(0);
 }
 
 /*****************************************************************************/