fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / char / rio / rioctrl.c
index fcf18a0..7ce7761 100644 (file)
@@ -51,15 +51,12 @@ static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c      1.3";
 
 #include "linux_compat.h"
 #include "rio_linux.h"
-#include "typdef.h"
 #include "pkt.h"
 #include "daemon.h"
 #include "rio.h"
 #include "riospace.h"
-#include "top.h"
 #include "cmdpkt.h"
 #include "map.h"
-#include "riotypes.h"
 #include "rup.h"
 #include "port.h"
 #include "riodrvr.h"
@@ -72,12 +69,10 @@ static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c      1.3";
 #include "unixrup.h"
 #include "board.h"
 #include "host.h"
-#include "error.h"
 #include "phb.h"
 #include "link.h"
 #include "cmdblk.h"
 #include "route.h"
-#include "control.h"
 #include "cirrus.h"
 #include "rioioctl.h"
 
@@ -85,7 +80,7 @@ static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c        1.3";
 static struct LpbReq LpbReq;
 static struct RupReq RupReq;
 static struct PortReq PortReq;
-static struct HostReq HostReq;
+static struct HostReq HostReq; /* oh really?  global?  and no locking? */
 static struct HostDpRam HostDpRam;
 static struct DebugCtrl DebugCtrl;
 static struct Map MapEnt;
@@ -131,36 +126,19 @@ static int
 
 #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
 
-int copyin(int arg, caddr_t dp, int siz)
+static int copy_from_io(void __user *to, void __iomem *from, size_t size)
 {
-       int rv;
-
-       rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes from user %p to %p.\n", siz, (void *) arg, dp);
-       rv = copy_from_user(dp, (void *) arg, siz);
-       if (rv)
-               return COPYFAIL;
-       else
-               return rv;
-}
-
-static int copyout(caddr_t dp, int arg, int siz)
-{
-       int rv;
-
-       rio_dprintk(RIO_DEBUG_CTRL, "Copying %d bytes to user %p from %p.\n", siz, (void *) arg, dp);
-       rv = copy_to_user((void *) arg, dp, siz);
-       if (rv)
-               return COPYFAIL;
-       else
-               return rv;
+       void *buf = kmalloc(size, GFP_KERNEL);
+       int res = -ENOMEM;
+       if (buf) {
+               rio_memcpy_fromio(buf, from, size);
+               res = copy_to_user(to, buf, size);
+               kfree(buf);
+       }
+       return res;
 }
 
-int riocontrol(p, dev, cmd, arg, su)
-struct rio_info *p;
-dev_t dev;
-int cmd;
-caddr_t arg;
-int su;
+int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su)
 {
        uint Host;              /* leave me unsigned! */
        uint port;              /* and me! */
@@ -168,9 +146,10 @@ int su;
        ushort loop;
        int Entry;
        struct Port *PortP;
-       PKT *PacketP;
+       struct PKT __iomem *PacketP;
        int retval = 0;
        unsigned long flags;
+       void __user *argp = (void __user *)arg;
 
        func_enter();
 
@@ -178,7 +157,7 @@ int su;
        Host = 0;
        PortP = NULL;
 
-       rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: 0x%x\n", cmd, (int) arg);
+       rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, argp);
 
        switch (cmd) {
                /*
@@ -189,105 +168,49 @@ int su;
                 ** otherwise just the specified host card will be changed.
                 */
        case RIO_SET_TIMER:
-               rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %dms\n", (uint) arg);
+               rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", arg);
                {
                        int host, value;
-                       host = (uint) arg >> 16;
-                       value = (uint) arg & 0x0000ffff;
+                       host = (arg >> 16) & 0x0000FFFF;
+                       value = arg & 0x0000ffff;
                        if (host == -1) {
                                for (host = 0; host < p->RIONumHosts; host++) {
                                        if (p->RIOHosts[host].Flags == RC_RUNNING) {
-                                               WWORD(p->RIOHosts[host].ParmMapP->timer, value);
+                                               writew(value, &p->RIOHosts[host].ParmMapP->timer);
                                        }
                                }
                        } else if (host >= p->RIONumHosts) {
                                return -EINVAL;
                        } else {
                                if (p->RIOHosts[host].Flags == RC_RUNNING) {
-                                       WWORD(p->RIOHosts[host].ParmMapP->timer, value);
+                                       writew(value, &p->RIOHosts[host].ParmMapP->timer);
                                }
                        }
                }
                return 0;
 
-       case RIO_IDENTIFY_DRIVER:
-               /*
-                ** 15.10.1998 ARG - ESIL 0760 part fix
-                ** Added driver ident string output.
-                **
-                #ifndef __THIS_RELEASE__
-                #warning Driver Version string not defined !
-                #endif
-                cprintf("%s %s %s %s\n",
-                RIO_DRV_STR,
-                __THIS_RELEASE__,
-                __DATE__, __TIME__ );
-
-                return 0;
-
-                case RIO_DISPLAY_HOST_CFG:
-                **
-                ** 15.10.1998 ARG - ESIL 0760 part fix
-                ** Added driver host card ident string output.
-                **
-                ** Note that the only types currently supported
-                ** are ISA and PCI. Also this driver does not
-                ** (yet) distinguish between the Old PCI card
-                ** and the Jet PCI card. In fact I think this
-                ** driver only supports JET PCI !
-                **
-
-                for (Host = 0; Host < p->RIONumHosts; Host++)
-                {
-                HostP = &(p->RIOHosts[Host]);
-
-                switch ( HostP->Type )
-                {
-                case RIO_AT :
-                strcpy( host_type, RIO_AT_HOST_STR );
-                break;
-
-                case RIO_PCI :
-                strcpy( host_type, RIO_PCI_HOST_STR );
-                break;
-
-                default :
-                strcpy( host_type, "Unknown" );
-                break;
-                }
-
-                cprintf(
-                "RIO Host %d - Type:%s Addr:%X IRQ:%d\n",
-                Host, host_type,
-                (uint)HostP->PaddrP,
-                (int)HostP->Ivec - 32  );
-                }
-                return 0;
-                **
-                */
-
        case RIO_FOAD_RTA:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
-               return RIOCommandRta(p, (uint) arg, RIOFoadRta);
+               return RIOCommandRta(p, arg, RIOFoadRta);
 
        case RIO_ZOMBIE_RTA:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
-               return RIOCommandRta(p, (uint) arg, RIOZombieRta);
+               return RIOCommandRta(p, arg, RIOZombieRta);
 
        case RIO_IDENTIFY_RTA:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
-               return RIOIdentifyRta(p, arg);
+               return RIOIdentifyRta(p, argp);
 
        case RIO_KILL_NEIGHBOUR:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
-               return RIOKillNeighbour(p, arg);
+               return RIOKillNeighbour(p, argp);
 
        case SPECIAL_RUP_CMD:
                {
                        struct CmdBlk *CmdBlkP;
 
                        rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
-                       if (copyin((int) arg, (caddr_t) & SpecialRupCmd, sizeof(SpecialRupCmd)) == COPYFAIL) {
+                       if (copy_from_user(&SpecialRupCmd, argp, sizeof(SpecialRupCmd))) {
                                rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
                                p->RIOError.Error = COPYIN_FAILED;
                                return -EFAULT;
@@ -302,7 +225,7 @@ int su;
                                SpecialRupCmd.Host = 0;
                        rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
                        if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
-                               cprintf("FAILED TO QUEUE SPECIAL RUP COMMAND\n");
+                               printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
                        }
                        return 0;
                }
@@ -324,7 +247,7 @@ int su;
                if ((retval = RIOApel(p)) != 0)
                        return retval;
 
-               if (copyout((caddr_t) p->RIOConnectTable, (int) arg, TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
+               if (copy_to_user(argp, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -369,7 +292,7 @@ int su;
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copyin((int) arg, (caddr_t) & p->RIOConnectTable[0], TOTAL_MAP_ENTRIES * sizeof(struct Map)) == COPYFAIL) {
+               if (copy_from_user(&p->RIOConnectTable[0], argp, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -415,7 +338,7 @@ int su;
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copyout((caddr_t) p->RIOBindTab, (int) arg, (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
+               if (copy_to_user(argp, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -434,7 +357,7 @@ int su;
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copyin((int) arg, (caddr_t) & p->RIOBindTab[0], (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL) {
+               if (copy_from_user(&p->RIOBindTab[0], argp, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -458,12 +381,12 @@ int su;
                        for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
                                if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
                                        EmptySlot = Entry;
-                               else if (p->RIOBindTab[Entry] == (int) arg) {
+                               else if (p->RIOBindTab[Entry] == arg) {
                                        /*
                                         ** Already exists - delete
                                         */
                                        p->RIOBindTab[Entry] = 0L;
-                                       rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %x from p->RIOBindTab\n", (int) arg);
+                                       rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", arg);
                                        return 0;
                                }
                        }
@@ -471,10 +394,10 @@ int su;
                         ** Dosen't exist - add
                         */
                        if (EmptySlot != -1) {
-                               p->RIOBindTab[EmptySlot] = (int) arg;
-                               rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %x to p->RIOBindTab\n", (int) arg);
+                               p->RIOBindTab[EmptySlot] = arg;
+                               rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", arg);
                        } else {
-                               rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %x not added\n", (int) arg);
+                               rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", arg);
                                return -ENOMEM;
                        }
                        return 0;
@@ -482,7 +405,7 @@ int su;
 
        case RIO_RESUME:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
-               port = (uint) arg;
+               port = arg;
                if ((port < 0) || (port > 511)) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
@@ -518,8 +441,7 @@ int su;
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
-                   == COPYFAIL) {
+               if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -533,8 +455,7 @@ int su;
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
-                   == COPYFAIL) {
+               if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -548,8 +469,7 @@ int su;
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copyin((int) arg, (caddr_t) & MapEnt, sizeof(MapEnt))
-                   == COPYFAIL) {
+               if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -557,30 +477,14 @@ int su;
                return RIODeleteRta(p, &MapEnt);
 
        case RIO_QUICK_CHECK:
-               /*
-                ** 09.12.1998 ARG - ESIL 0776 part fix
-                ** A customer was using this to get the RTAs
-                ** connect/disconnect status.
-                ** RIOConCon() had been botched use RIOHalted
-                ** to keep track of RTA connections and
-                ** disconnections. That has been changed and
-                ** RIORtaDisCons in the rio_info struct now
-                ** does the job. So we need to return the value
-                ** of RIORtaCons instead of RIOHalted.
-                **
-                if (copyout((caddr_t)&p->RIOHalted,(int)arg,
-                sizeof(uint))==COPYFAIL) {
-                **
-                */
-
-               if (copyout((caddr_t) & p->RIORtaDisCons, (int) arg, sizeof(uint)) == COPYFAIL) {
+               if (copy_to_user(argp, &p->RIORtaDisCons, sizeof(unsigned int))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return 0;
 
        case RIO_LAST_ERROR:
-               if (copyout((caddr_t) & p->RIOError, (int) arg, sizeof(struct Error)) == COPYFAIL)
+               if (copy_to_user(argp, &p->RIOError, sizeof(struct Error)))
                        return -EFAULT;
                return 0;
 
@@ -589,7 +493,7 @@ int su;
                return -EINVAL;
 
        case RIO_GET_MODTYPE:
-               if (copyin((int) arg, (caddr_t) & port, sizeof(uint)) == COPYFAIL) {
+               if (copy_from_user(&port, argp, sizeof(unsigned int))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -609,36 +513,11 @@ int su;
                 ** Return module type of port
                 */
                port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
-               if (copyout((caddr_t) & port, (int) arg, sizeof(uint)) == COPYFAIL) {
+               if (copy_to_user(argp, &port, sizeof(unsigned int))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return (0);
-               /*
-                ** 02.03.1999 ARG - ESIL 0820 fix
-                ** We are no longer using "Boot Mode", so these ioctls
-                ** are not required :
-                **
-                case RIO_GET_BOOT_MODE :
-                rio_dprint(RIO_DEBUG_CTRL, ("Get boot mode - %x\n", p->RIOBootMode));
-                **
-                ** Return boot state of system - BOOT_ALL, BOOT_OWN or BOOT_NONE
-                **
-                if (copyout((caddr_t)&p->RIOBootMode, (int)arg,
-                sizeof(p->RIOBootMode)) == COPYFAIL) {
-                p->RIOError.Error = COPYOUT_FAILED;
-                return -EFAULT;
-                }
-                return(0);
-
-                case RIO_SET_BOOT_MODE :
-                p->RIOBootMode = (uint) arg;
-                rio_dprint(RIO_DEBUG_CTRL, ("Set boot mode to 0x%x\n", p->RIOBootMode));
-                return(0);
-                **
-                ** End ESIL 0820 fix
-                */
-
        case RIO_BLOCK_OPENS:
                rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
                for (Entry = 0; Entry < RIO_PORTS; Entry++) {
@@ -650,8 +529,7 @@ int su;
 
        case RIO_SETUP_PORTS:
                rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
-               if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
-                   == COPYFAIL) {
+               if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
                        return -EFAULT;
@@ -667,7 +545,7 @@ int su;
                        return -EINVAL;
                }
                if (!p->RIOPortp) {
-                       cprintf("No p->RIOPortp array!\n");
+                       printk(KERN_ERR "rio: No p->RIOPortp array!\n");
                        rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
                        return -EIO;
                }
@@ -681,8 +559,7 @@ int su;
 
        case RIO_GET_PORT_SETUP:
                rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
-               if (copyin((int) arg, (caddr_t) & PortSetup, sizeof(PortSetup))
-                   == COPYFAIL) {
+               if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -698,13 +575,12 @@ int su;
                PortSetup.Store = p->RIOPortp[port]->Store;
                PortSetup.Lock = p->RIOPortp[port]->Lock;
                PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
-               bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn, MAX_XP_CTRL_LEN);
-               bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff, MAX_XP_CTRL_LEN);
+               memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
+               memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
                PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
                PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
 
-               if (copyout((caddr_t) & PortSetup, (int) arg, sizeof(PortSetup))
-                   == COPYFAIL) {
+               if (copy_to_user(argp, &PortSetup, sizeof(PortSetup))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
@@ -712,7 +588,7 @@ int su;
 
        case RIO_GET_PORT_PARAMS:
                rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
-               if (copyin((int) arg, (caddr_t) & PortParams, sizeof(struct PortParams)) == COPYFAIL) {
+               if (copy_from_user(&PortParams, argp, sizeof(struct PortParams))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -725,7 +601,7 @@ int su;
                PortParams.State = PortP->State;
                rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
 
-               if (copyout((caddr_t) & PortParams, (int) arg, sizeof(struct PortParams)) == COPYFAIL) {
+               if (copy_to_user(argp, &PortParams, sizeof(struct PortParams))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
@@ -733,8 +609,7 @@ int su;
 
        case RIO_GET_PORT_TTY:
                rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
-               if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty))
-                   == COPYFAIL) {
+               if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -745,14 +620,14 @@ int su;
 
                rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
                PortP = (p->RIOPortp[PortTty.port]);
-               if (copyout((caddr_t) & PortTty, (int) arg, sizeof(struct PortTty)) == COPYFAIL) {
+               if (copy_to_user(argp, &PortTty, sizeof(struct PortTty))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return retval;
 
        case RIO_SET_PORT_TTY:
-               if (copyin((int) arg, (caddr_t) & PortTty, sizeof(struct PortTty)) == COPYFAIL) {
+               if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -767,8 +642,7 @@ int su;
 
        case RIO_SET_PORT_PARAMS:
                rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
-               if (copyin((int) arg, (caddr_t) & PortParams, sizeof(PortParams))
-                   == COPYFAIL) {
+               if (copy_from_user(&PortParams, argp, sizeof(PortParams))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -784,11 +658,11 @@ int su;
 
        case RIO_GET_PORT_STATS:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
-               if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
+               if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
-               if (portStats.port >= RIO_PORTS) {
+               if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
                        return -ENXIO;
                }
@@ -799,14 +673,14 @@ int su;
                portStats.opens = PortP->opens;
                portStats.closes = PortP->closes;
                portStats.ioctls = PortP->ioctls;
-               if (copyout((caddr_t) & portStats, (int) arg, sizeof(struct portStats)) == COPYFAIL) {
+               if (copy_to_user(argp, &portStats, sizeof(struct portStats))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return retval;
 
        case RIO_RESET_PORT_STATS:
-               port = (uint) arg;
+               port = arg;
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
                if (port >= RIO_PORTS) {
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
@@ -824,11 +698,11 @@ int su;
 
        case RIO_GATHER_PORT_STATS:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
-               if (copyin((int) arg, (caddr_t) & portStats, sizeof(struct portStats)) == COPYFAIL) {
+               if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
-               if (portStats.port >= RIO_PORTS) {
+               if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
                        return -ENXIO;
                }
@@ -840,7 +714,7 @@ int su;
 
        case RIO_READ_CONFIG:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
-               if (copyout((caddr_t) & p->RIOConf, (int) arg, sizeof(struct Conf)) == COPYFAIL) {
+               if (copy_to_user(argp, &p->RIOConf, sizeof(struct Conf))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
@@ -852,8 +726,7 @@ int su;
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copyin((int) arg, (caddr_t) & p->RIOConf, sizeof(struct Conf))
-                   == COPYFAIL) {
+               if (copy_from_user(&p->RIOConf, argp, sizeof(struct Conf))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -862,7 +735,7 @@ int su;
                 */
                for (Host = 0; Host < p->RIONumHosts; Host++)
                        if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
-                               WWORD(p->RIOHosts[Host].ParmMapP->timer, p->RIOConf.Timer);
+                               writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
                return retval;
 
        case RIO_START_POLLER:
@@ -881,8 +754,7 @@ int su;
        case RIO_SETDEBUG:
        case RIO_GETDEBUG:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
-               if (copyin((int) arg, (caddr_t) & DebugCtrl, sizeof(DebugCtrl))
-                   == COPYFAIL) {
+               if (copy_from_user(&DebugCtrl, argp, sizeof(DebugCtrl))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -899,7 +771,7 @@ int su;
                                rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
                                DebugCtrl.Debug = p->rio_debug;
                                DebugCtrl.Wait = p->RIODebugWait;
-                               if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
+                               if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
                                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
                                        p->RIOError.Error = COPYOUT_FAILED;
                                        return -EFAULT;
@@ -921,7 +793,7 @@ int su;
                } else {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
                        DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
-                       if (copyout((caddr_t) & DebugCtrl, (int) arg, sizeof(DebugCtrl)) == COPYFAIL) {
+                       if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
                                rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
                                p->RIOError.Error = COPYOUT_FAILED;
                                return -EFAULT;
@@ -936,43 +808,20 @@ int su;
                 ** textual null terminated string.
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
-               if (copyout((caddr_t) RIOVersid(), (int) arg, sizeof(struct rioVersion)) == COPYFAIL) {
+               if (copy_to_user(argp, RIOVersid(), sizeof(struct rioVersion))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return retval;
 
-               /*
-                ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-                ** !! commented out previous 'RIO_VERSID' functionality !!
-                ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-                **
-                case RIO_VERSID:
-                **
-                ** Enquire about the release and version.
-                ** We return MAX_VERSION_LEN bytes, being a textual null
-                ** terminated string.
-                **
-                rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n"));
-                if (copyout((caddr_t)RIOVersid(),
-                (int)arg, MAX_VERSION_LEN ) == COPYFAIL ) {
-                rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space\n",Host));
-                p->RIOError.Error = COPYOUT_FAILED;
-                return -EFAULT;
-                }
-                return retval;
-                **
-                ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-                */
-
        case RIO_NUM_HOSTS:
                /*
                 ** Enquire as to the number of hosts located
                 ** at init time.
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
-               if (copyout((caddr_t) & p->RIONumHosts, (int) arg, sizeof(p->RIONumHosts)) == COPYFAIL) {
+               if (copy_to_user(argp, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -983,7 +832,7 @@ int su;
                /*
                 ** Kill host. This may not be in the final version...
                 */
-               rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %d\n", (int) arg);
+               rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", arg);
                if (!su) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
                        p->RIOError.Error = NOT_SUPER_USER;
@@ -994,7 +843,7 @@ int su;
 
                for (Host = 0; Host < p->RIONumHosts; Host++) {
                        (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
-                       bzero((caddr_t) & p->RIOHosts[Host].Flags, ((int) &p->RIOHosts[Host].____end_marker____) - ((int) &p->RIOHosts[Host].Flags));
+                       memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
                        p->RIOHosts[Host].Flags = RC_WAITING;
                }
                RIOFoadWakeup(p);
@@ -1017,7 +866,7 @@ int su;
                        p->RIOError.Error = NOT_SUPER_USER;
                        return -EPERM;
                }
-               if (copyin((int) arg, (caddr_t) & DownLoad, sizeof(DownLoad)) == COPYFAIL) {
+               if (copy_from_user(&DownLoad, argp, sizeof(DownLoad))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1045,9 +894,9 @@ int su;
 
        case RIO_PARMS:
                {
-                       uint host;
+                       unsigned int host;
 
-                       if (copyin((int) arg, (caddr_t) & host, sizeof(host)) == COPYFAIL) {
+                       if (copy_from_user(&host, argp, sizeof(host))) {
                                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
                                p->RIOError.Error = COPYIN_FAILED;
                                return -EFAULT;
@@ -1056,7 +905,7 @@ int su;
                         ** Fetch the parmmap
                         */
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
-                       if (copyout((caddr_t) p->RIOHosts[host].ParmMapP, (int) arg, sizeof(PARM_MAP)) == COPYFAIL) {
+                       if (copy_from_io(argp, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
                                p->RIOError.Error = COPYOUT_FAILED;
                                rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
                                return -EFAULT;
@@ -1066,7 +915,7 @@ int su;
 
        case RIO_HOST_REQ:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
-               if (copyin((int) arg, (caddr_t) & HostReq, sizeof(HostReq)) == COPYFAIL) {
+               if (copy_from_user(&HostReq, argp, sizeof(HostReq))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1078,7 +927,7 @@ int su;
                }
                rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
 
-               if (copyout((caddr_t) & p->RIOHosts[HostReq.HostNum], (int) HostReq.HostP, sizeof(struct Host)) == COPYFAIL) {
+               if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
                        return -EFAULT;
@@ -1087,7 +936,7 @@ int su;
 
        case RIO_HOST_DPRAM:
                rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
-               if (copyin((int) arg, (caddr_t) & HostDpRam, sizeof(HostDpRam)) == COPYFAIL) {
+               if (copy_from_user(&HostDpRam, argp, sizeof(HostDpRam))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1104,13 +953,13 @@ int su;
                        /* It's hardware like this that really gets on my tits. */
                        static unsigned char copy[sizeof(struct DpRam)];
                        for (off = 0; off < sizeof(struct DpRam); off++)
-                               copy[off] = p->RIOHosts[HostDpRam.HostNum].Caddr[off];
-                       if (copyout((caddr_t) copy, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
+                               copy[off] = readb(p->RIOHosts[HostDpRam.HostNum].Caddr + off);
+                       if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
                                p->RIOError.Error = COPYOUT_FAILED;
                                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
                                return -EFAULT;
                        }
-               } else if (copyout((caddr_t) p->RIOHosts[HostDpRam.HostNum].Caddr, (int) HostDpRam.DpRamP, sizeof(struct DpRam)) == COPYFAIL) {
+               } else if (copy_from_io(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
                        return -EFAULT;
@@ -1119,13 +968,13 @@ int su;
 
        case RIO_SET_BUSY:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
-               if ((int) arg < 0 || (int) arg > 511) {
-                       rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %d\n", (int) arg);
+               if (arg > 511) {
+                       rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", arg);
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
                        return -EINVAL;
                }
                rio_spin_lock_irqsave(&PortP->portSem, flags);
-               p->RIOPortp[(int) arg]->State |= RIO_BUSY;
+               p->RIOPortp[arg]->State |= RIO_BUSY;
                rio_spin_unlock_irqrestore(&PortP->portSem, flags);
                return retval;
 
@@ -1135,7 +984,7 @@ int su;
                 ** (probably for debug reasons)
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
-               if (copyin((int) arg, (caddr_t) & PortReq, sizeof(PortReq)) == COPYFAIL) {
+               if (copy_from_user(&PortReq, argp, sizeof(PortReq))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1147,7 +996,7 @@ int su;
                        return -ENXIO;
                }
                rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
-               if (copyout((caddr_t) p->RIOPortp[PortReq.SysPort], (int) PortReq.PortP, sizeof(struct Port)) == COPYFAIL) {
+               if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
                        return -EFAULT;
@@ -1160,7 +1009,7 @@ int su;
                 ** (probably for debug reasons)
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
-               if (copyin((int) arg, (caddr_t) & RupReq, sizeof(RupReq)) == COPYFAIL) {
+               if (copy_from_user(&RupReq, argp, sizeof(RupReq))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1184,7 +1033,7 @@ int su;
                }
                rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
 
-               if (copyout((caddr_t) HostP->UnixRups[RupReq.RupNum].RupP, (int) RupReq.RupP, sizeof(struct RUP)) == COPYFAIL) {
+               if (copy_from_io(RupReq.RupP, HostP->UnixRups[RupReq.RupNum].RupP, sizeof(struct RUP))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
                        return -EFAULT;
@@ -1197,7 +1046,7 @@ int su;
                 ** (probably for debug reasons)
                 */
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
-               if (copyin((int) arg, (caddr_t) & LpbReq, sizeof(LpbReq)) == COPYFAIL) {
+               if (copy_from_user(&LpbReq, argp, sizeof(LpbReq))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1221,7 +1070,7 @@ int su;
                }
                rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
 
-               if (copyout((caddr_t) & HostP->LinkStrP[LpbReq.Link], (int) LpbReq.LpbP, sizeof(struct LPB)) == COPYFAIL) {
+               if (copy_from_io(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -1252,12 +1101,13 @@ int su;
                        p->RIOError.Error = SIGNALS_ALREADY_SET;
                        return -EBUSY;
                }
-               p->RIOSignalProcess = getpid();
+               /* FIXME: PID tracking */
+               p->RIOSignalProcess = current->pid;
                p->RIOPrintDisabled = DONT_PRINT;
                return retval;
 
        case RIO_SIGNALS_OFF:
-               if (p->RIOSignalProcess != getpid()) {
+               if (p->RIOSignalProcess != current->pid) {
                        p->RIOError.Error = NOT_RECEIVING_PROCESS;
                        return -EPERM;
                }
@@ -1294,7 +1144,7 @@ int su;
        case RIO_MAP_B110_TO_110:
        case RIO_MAP_B110_TO_115200:
                rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
-               port = (uint) arg;
+               port = arg;
                if (port < 0 || port > 511) {
                        rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
                        p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
@@ -1324,7 +1174,7 @@ int su;
 
        case RIO_SEND_PACKET:
                rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
-               if (copyin((int) arg, (caddr_t) & SendPack, sizeof(SendPack)) == COPYFAIL) {
+               if (copy_from_user(&SendPack, argp, sizeof(SendPack))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
@@ -1344,9 +1194,9 @@ int su;
                }
 
                for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
-                       WBYTE(PacketP->data[loop], SendPack.Data[loop]);
+                       writeb(SendPack.Data[loop], &PacketP->data[loop]);
 
-               WBYTE(PacketP->len, SendPack.Len);
+               writeb(SendPack.Len, &PacketP->len);
 
                add_transmit(PortP);
                /*
@@ -1368,7 +1218,7 @@ int su;
                return su ? 0 : -EPERM;
 
        case RIO_WHAT_MESG:
-               if (copyout((caddr_t) & p->RIONoMessage, (int) arg, sizeof(p->RIONoMessage)) == COPYFAIL) {
+               if (copy_to_user(argp, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -1376,7 +1226,7 @@ int su;
                return 0;
 
        case RIO_MEM_DUMP:
-               if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
+               if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -1406,7 +1256,7 @@ int su;
                        PortP->State |= RIO_BUSY;
 
                rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-               if (copyout((caddr_t) p->RIOMemDump, (int) arg, MEMDUMP_SIZE) == COPYFAIL) {
+               if (copy_to_user(argp, p->RIOMemDump, MEMDUMP_SIZE)) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -1414,30 +1264,30 @@ int su;
                return 0;
 
        case RIO_TICK:
-               if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
+               if (arg >= p->RIONumHosts)
                        return -EINVAL;
-               rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %d\n", (int) arg);
-               WBYTE(p->RIOHosts[(int) arg].SetInt, 0xff);
+               rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", arg);
+               writeb(0xFF, &p->RIOHosts[arg].SetInt);
                return 0;
 
        case RIO_TOCK:
-               if ((int) arg < 0 || (int) arg >= p->RIONumHosts)
+               if (arg >= p->RIONumHosts)
                        return -EINVAL;
-               rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %d\n", (int) arg);
-               WBYTE((p->RIOHosts[(int) arg].ResetInt), 0xff);
+               rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", arg);
+               writeb(0xFF, &p->RIOHosts[arg].ResetInt);
                return 0;
 
        case RIO_READ_CHECK:
                /* Check reads for pkts with data[0] the same */
                p->RIOReadCheck = !p->RIOReadCheck;
-               if (copyout((caddr_t) & p->RIOReadCheck, (int) arg, sizeof(uint)) == COPYFAIL) {
+               if (copy_to_user(argp, &p->RIOReadCheck, sizeof(unsigned int))) {
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
                }
                return 0;
 
        case RIO_READ_REGISTER:
-               if (copyin((int) arg, (caddr_t) & SubCmd, sizeof(struct SubCmdStruct)) == COPYFAIL) {
+               if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
                        p->RIOError.Error = COPYIN_FAILED;
                        return -EFAULT;
                }
@@ -1472,7 +1322,7 @@ int su;
                        PortP->State |= RIO_BUSY;
 
                rio_spin_unlock_irqrestore(&PortP->portSem, flags);
-               if (copyout((caddr_t) & p->CdRegister, (int) arg, sizeof(uint)) == COPYFAIL) {
+               if (copy_to_user(argp, &p->CdRegister, sizeof(unsigned int))) {
                        rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
                        p->RIOError.Error = COPYOUT_FAILED;
                        return -EFAULT;
@@ -1485,21 +1335,22 @@ int su;
                 */
        case RIO_MAKE_DEV:
                {
-                       uint port = (uint) arg & RIO_MODEM_MASK;
+                       unsigned int port = arg & RIO_MODEM_MASK;
+                       unsigned int ret;
 
-                       switch ((uint) arg & RIO_DEV_MASK) {
+                       switch (arg & RIO_DEV_MASK) {
                        case RIO_DEV_DIRECT:
-                               arg = (caddr_t) drv_makedev(MAJOR(dev), port);
-                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, (int) arg);
-                               return (int) arg;
+                               ret = drv_makedev(MAJOR(dev), port);
+                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
+                               return ret;
                        case RIO_DEV_MODEM:
-                               arg = (caddr_t) drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
-                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, (int) arg);
-                               return (int) arg;
+                               ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
+                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
+                               return ret;
                        case RIO_DEV_XPRINT:
-                               arg = (caddr_t) drv_makedev(MAJOR(dev), port);
-                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, (int) arg);
-                               return (int) arg;
+                               ret = drv_makedev(MAJOR(dev), port);
+                               rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
+                               return ret;
                        }
                        rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
                        return -EINVAL;
@@ -1513,18 +1364,19 @@ int su;
                {
                        dev_t dv;
                        int mino;
+                       unsigned long ret;
 
-                       dv = (dev_t) ((int) arg);
+                       dv = (dev_t) (arg);
                        mino = RIO_UNMODEM(dv);
 
                        if (RIO_ISMODEM(dv)) {
                                rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
-                               arg = (caddr_t) (mino | RIO_DEV_MODEM);
+                               ret = mino | RIO_DEV_MODEM;
                        } else {
                                rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
-                               arg = (caddr_t) (mino | RIO_DEV_DIRECT);
+                               ret = mino | RIO_DEV_DIRECT;
                        }
-                       return (int) arg;
+                       return ret;
                }
        }
        rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
@@ -1537,10 +1389,7 @@ int su;
 /*
 ** Pre-emptive commands go on RUPs and are only one byte long.
 */
-int RIOPreemptiveCmd(p, PortP, Cmd)
-struct rio_info *p;
-struct Port *PortP;
-uchar Cmd;
+int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
 {
        struct CmdBlk *CmdBlkP;
        struct PktCmd_M *PktCmdP;
@@ -1553,14 +1402,17 @@ uchar Cmd;
                return RIO_FAIL;
        }
 
-       if (((int) ((char) PortP->InUse) == -1) || !(CmdBlkP = RIOGetCmdBlk())) {
-               rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block for command %d on port %d\n", Cmd, PortP->PortNum);
+       if ((PortP->InUse == (typeof(PortP->InUse))-1) ||
+                       !(CmdBlkP = RIOGetCmdBlk())) {
+               rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block "
+                       "for command %d on port %d\n", Cmd, PortP->PortNum);
                return RIO_FAIL;
        }
 
-       rio_dprintk(RIO_DEBUG_CTRL, "Command blk 0x%x - InUse now %d\n", (int) CmdBlkP, PortP->InUse);
+       rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n",
+                       CmdBlkP, PortP->InUse);
 
-       PktCmdP = (struct PktCmd_M *) &CmdBlkP->Packet.data[0];
+       PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
 
        CmdBlkP->Packet.src_unit = 0;
        if (PortP->SecondBlock)
@@ -1572,7 +1424,7 @@ uchar Cmd;
        CmdBlkP->Packet.dest_port = COMMAND_RUP;
        CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
        CmdBlkP->PostFuncP = RIOUnUse;
-       CmdBlkP->PostArg = (int) PortP;
+       CmdBlkP->PostArg = (unsigned long) PortP;
        PktCmdP->Command = Cmd;
        port = PortP->HostPort % (ushort) PORTS_PER_RTA;
        /*
@@ -1584,38 +1436,46 @@ uchar Cmd;
 
        switch (Cmd) {
        case MEMDUMP:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk 0x%x (addr 0x%x)\n", (int) CmdBlkP, (int) SubCmd.Addr);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p "
+                               "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
                PktCmdP->SubCommand = MEMDUMP;
                PktCmdP->SubAddr = SubCmd.Addr;
                break;
        case FCLOSE:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk 0x%x\n", (int) CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n",
+                               CmdBlkP);
                break;
        case READ_REGISTER:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk 0x%x\n", (int) SubCmd.Addr, (int) CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) "
+                               "command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
                PktCmdP->SubCommand = READ_REGISTER;
                PktCmdP->SubAddr = SubCmd.Addr;
                break;
        case RESUME:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk 0x%x\n", (int) CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n",
+                               CmdBlkP);
                break;
        case RFLUSH:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk 0x%x\n", (int) CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n",
+                               CmdBlkP);
                CmdBlkP->PostFuncP = RIORFlushEnable;
                break;
        case SUSPEND:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk 0x%x\n", (int) CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n",
+                               CmdBlkP);
                break;
 
        case MGET:
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk 0x%x\n", (int) CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n",
+                               CmdBlkP);
                break;
 
        case MSET:
        case MBIC:
        case MBIS:
                CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
-               rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk 0x%x\n", (int) CmdBlkP);
+               rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command "
+                               "blk %p\n", CmdBlkP);
                break;
 
        case WFLUSH:
@@ -1624,12 +1484,14 @@ uchar Cmd;
                 ** allowed then we should not bother sending any more to the
                 ** RTA.
                 */
-               if ((int) ((char) PortP->WflushFlag) == (int) -1) {
-                       rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
+               if (PortP->WflushFlag == (typeof(PortP->WflushFlag))-1) {
+                       rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, "
+                                       "WflushFlag about to wrap!");
                        RIOFreeCmdBlk(CmdBlkP);
                        return (RIO_FAIL);
                } else {
-                       rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command blk 0x%x\n", (int) CmdBlkP);
+                       rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command "
+                                       "blk %p\n", CmdBlkP);
                        CmdBlkP->PostFuncP = RIOWFlushMark;
                }
                break;