fix include to use "ioctl.h" instead of /usr/include/sys/ioctl.h for kernel
[unix-history] / usr / src / sys / vax / uba / uba.c
index c619ae2..2888b37 100644 (file)
@@ -1,21 +1,24 @@
-/*     uba.c   4.46    82/06/26        */
+/*     uba.c   6.1     83/08/21        */
+
+#include "../machine/pte.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
-#include "../h/cpu.h"
 #include "../h/map.h"
 #include "../h/map.h"
-#include "../h/pte.h"
 #include "../h/buf.h"
 #include "../h/vm.h"
 #include "../h/buf.h"
 #include "../h/vm.h"
-#include "../h/ubareg.h"
-#include "../h/ubavar.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/proc.h"
 #include "../h/conf.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/proc.h"
 #include "../h/conf.h"
-#include "../h/mtpr.h"
-#include "../h/nexus.h"
 #include "../h/dk.h"
 #include "../h/dk.h"
+#include "../h/kernel.h"
+
+#include "../vax/cpu.h"
+#include "../vax/mtpr.h"
+#include "../vax/nexus.h"
+#include "../vaxuba/ubareg.h"
+#include "../vaxuba/ubavar.h"
 
 #if VAX780
 char   ubasr_bits[] = UBASR_BITS;
 
 #if VAX780
 char   ubasr_bits[] = UBASR_BITS;
@@ -102,7 +105,7 @@ ubasetup(uban, bp, flags)
        struct buf *bp;
 {
        register struct uba_hd *uh = &uba_hd[uban];
        struct buf *bp;
 {
        register struct uba_hd *uh = &uba_hd[uban];
-       register int temp, i;
+       register int temp;
        int npf, reg, bdp;
        unsigned v;
        register struct pte *pte, *io;
        int npf, reg, bdp;
        unsigned v;
        register struct pte *pte, *io;
@@ -117,24 +120,24 @@ ubasetup(uban, bp, flags)
        o = (int)bp->b_un.b_addr & PGOFSET;
        npf = btoc(bp->b_bcount + o) + 1;
        a = spl6();
        o = (int)bp->b_un.b_addr & PGOFSET;
        npf = btoc(bp->b_bcount + o) + 1;
        a = spl6();
-       while ((reg = rmalloc(uh->uh_map, npf)) == 0) {
+       while ((reg = rmalloc(uh->uh_map, (long)npf)) == 0) {
                if (flags & UBA_CANTWAIT) {
                        splx(a);
                        return (0);
                }
                uh->uh_mrwant++;
                if (flags & UBA_CANTWAIT) {
                        splx(a);
                        return (0);
                }
                uh->uh_mrwant++;
-               sleep((caddr_t)uh->uh_map, PSWP);
+               sleep((caddr_t)&uh->uh_mrwant, PSWP);
        }
        bdp = 0;
        if (flags & UBA_NEEDBDP) {
                while ((bdp = ffs(uh->uh_bdpfree)) == 0) {
                        if (flags & UBA_CANTWAIT) {
        }
        bdp = 0;
        if (flags & UBA_NEEDBDP) {
                while ((bdp = ffs(uh->uh_bdpfree)) == 0) {
                        if (flags & UBA_CANTWAIT) {
-                               rmfree(uh->uh_map, npf, reg);
+                               rmfree(uh->uh_map, (long)npf, (long)reg);
                                splx(a);
                                return (0);
                        }
                        uh->uh_bdpwant++;
                                splx(a);
                                return (0);
                        }
                        uh->uh_bdpwant++;
-                       sleep((caddr_t)uh->uh_map, PSWP);
+                       sleep((caddr_t)&uh->uh_bdpwant, PSWP);
                }
                uh->uh_bdpfree &= ~(1 << (bdp-1));
        } else if (flags & UBA_HAVEBDP)
                }
                uh->uh_bdpfree &= ~(1 << (bdp-1));
        } else if (flags & UBA_HAVEBDP)
@@ -227,7 +230,7 @@ ubarelse(uban, amr)
                uh->uh_bdpfree |= 1 << (bdp-1);         /* atomic */
                if (uh->uh_bdpwant) {
                        uh->uh_bdpwant = 0;
                uh->uh_bdpfree |= 1 << (bdp-1);         /* atomic */
                if (uh->uh_bdpwant) {
                        uh->uh_bdpwant = 0;
-                       wakeup((caddr_t)uh->uh_map);
+                       wakeup((caddr_t)&uh->uh_bdpwant);
                }
        }
        /*
                }
        }
        /*
@@ -238,7 +241,7 @@ ubarelse(uban, amr)
        npf = (mr >> 18) & 0x3ff;
        reg = ((mr >> 9) & 0x1ff) + 1;
        s = spl6();
        npf = (mr >> 18) & 0x3ff;
        reg = ((mr >> 9) & 0x1ff) + 1;
        s = spl6();
-       rmfree(uh->uh_map, npf, reg);
+       rmfree(uh->uh_map, (long)npf, (long)reg);
        splx(s);
 
        /*
        splx(s);
 
        /*
@@ -248,7 +251,7 @@ ubarelse(uban, amr)
         */
        if (uh->uh_mrwant) {
                uh->uh_mrwant = 0;
         */
        if (uh->uh_mrwant) {
                uh->uh_mrwant = 0;
-               wakeup((caddr_t)uh->uh_map);
+               wakeup((caddr_t)&uh->uh_mrwant);
        }
        while (uh->uh_actf && ubago(uh->uh_actf))
                ;
        }
        while (uh->uh_actf && ubago(uh->uh_actf))
                ;
@@ -278,7 +281,7 @@ ubainitmaps(uhp)
        register struct uba_hd *uhp;
 {
 
        register struct uba_hd *uhp;
 {
 
-       rminit(uhp->uh_map, NUBMREG, 1, "uba", UAMSIZ);
+       rminit(uhp->uh_map, (long)NUBMREG, (long)1, "uba", UAMSIZ);
        switch (cpu) {
 #if VAX780
        case VAX_780:
        switch (cpu) {
 #if VAX780
        case VAX_780:
@@ -313,7 +316,6 @@ ubareset(uban)
        uh->uh_users = 0;
        uh->uh_zvcnt = 0;
        uh->uh_xclu = 0;
        uh->uh_users = 0;
        uh->uh_zvcnt = 0;
        uh->uh_xclu = 0;
-       uh->uh_hangcnt = 0;
        uh->uh_actf = uh->uh_actl = 0;
        uh->uh_bdpwant = 0;
        uh->uh_mrwant = 0;
        uh->uh_actf = uh->uh_actl = 0;
        uh->uh_bdpwant = 0;
        uh->uh_mrwant = 0;
@@ -322,7 +324,7 @@ ubareset(uban)
        wakeup((caddr_t)&uh->uh_mrwant);
        printf("uba%d: reset", uban);
        ubainit(uh->uh_uba);
        wakeup((caddr_t)&uh->uh_mrwant);
        printf("uba%d: reset", uban);
        ubainit(uh->uh_uba);
-       for (cdp = cdevsw; cdp->d_open; cdp++)
+       for (cdp = cdevsw; cdp < cdevsw + nchrdev; cdp++)
                (*cdp->d_reset)(uban);
 #ifdef INET
        ifubareset(uban);
                (*cdp->d_reset)(uban);
 #ifdef INET
        ifubareset(uban);
@@ -369,52 +371,7 @@ ubainit(uba)
        }
 }
 
        }
 }
 
-#if VAX780
-/*
- * Check to make sure the UNIBUS adaptor is not hung,
- * with an interrupt in the register to be presented,
- * but not presenting it for an extended period (5 seconds).
- */
-unhang()
-{
-       register int uban;
-
-       for (uban = 0; uban < numuba; uban++) {
-               register struct uba_hd *uh = &uba_hd[uban];
-               register struct uba_regs *up = uh->uh_uba;
-
-               if (up->uba_sr == 0)
-                       return;
-               up->uba_sr = UBASR_CRD|UBASR_LEB;
-               uh->uh_hangcnt++;
-               if (uh->uh_hangcnt > 5*hz) {
-                       uh->uh_hangcnt = 0;
-                       printf("uba%d: hung\n", uban);
-                       ubareset(uban);
-               }
-       }
-}
-
-/*
- * This is a timeout routine which decrements the ``i forgot to
- * interrupt'' counts, on an 11/780.  This prevents slowly growing
- * counts from causing a UBA reset since we are interested only
- * in hang situations.
- */
-ubawatch()
-{
-       register struct uba_hd *uh;
-       register int uban;
-
-       if (panicstr)
-               return;
-       for (uban = 0; uban < numuba; uban++) {
-               uh = &uba_hd[uban];
-               if (uh->uh_hangcnt)
-                       uh->uh_hangcnt--;
-       }
-}
-
+#ifdef VAX780
 int    ubawedgecnt = 10;
 int    ubacrazy = 500;
 /*
 int    ubawedgecnt = 10;
 int    ubacrazy = 500;
 /*
@@ -470,99 +427,51 @@ ubaerror(uban, uh, xx, uvec, uba)
 }
 #endif
 
 }
 #endif
 
-#ifdef notdef
 /*
 /*
- * This routine allows remapping of previously
- * allocated UNIBUS bdp and map resources
- * onto different memory addresses.
- * It should only be used by routines which need
- * small fixed length mappings for long periods of time
- * (like the ARPANET ACC IMP interface).
- * It only maps kernel addresses.
+ * Allocate UNIBUS memory.  Allocates and initializes
+ * sufficient mapping registers for access.  On a 780,
+ * the configuration register is setup to disable UBA
+ * response on DMA transfers to addresses controlled
+ * by the disabled mapping registers.
  */
  */
-ubaremap(uban, ubinfo, addr)
-       int uban;
-       register unsigned ubinfo;
-       caddr_t addr;
+ubamem(uban, addr, npg, doalloc)
+       int uban, addr, npg, doalloc;
 {
        register struct uba_hd *uh = &uba_hd[uban];
 {
        register struct uba_hd *uh = &uba_hd[uban];
-       register struct pte *pte, *io;
-       register int temp, bdp;
-       int npf, o;
+       register int a;
 
 
-       o = (int)addr & PGOFSET;
-       bdp = (ubinfo >> 28) & 0xf;
-       npf = (ubinfo >> 18) & 0x3ff;
-       io = &uh->uh_uba->uba_map[(ubinfo >> 9) & 0x1ff];
-       temp = (bdp << 21) | UBAMR_MRV;
+       if (doalloc) {
+               int s = spl6();
+               a = rmget(uh->uh_map, npg, (addr >> 9) + 1);
+               splx(s);
+       } else
+               a = (addr >> 9) + 1;
+       if (a) {
+               register int i, *m;
 
 
-       /*
-        * If using buffered data path initiate purge
-        * of old data and set byte offset bit if next
-        * transfer will be from odd address.
-        */
-       if (bdp) {
-               switch (cpu) {
+               m = (int *)&uh->uh_uba->uba_map[a - 1];
+               for (i = 0; i < npg; i++)
+                       *m++ = 0;       /* All off, especially 'valid' */
 #if VAX780
 #if VAX780
-               case VAX_780:
-                       uh->uh_uba->uba_dpr[bdp] |= UBADPR_BNE;
-                       break;
-#endif
-#if VAX750
-               case VAX_750:
-                       uh->uh_uba->uba_dpr[bdp] |=
-                           UBADPR_PURGE|UBADPR_NXM|UBADPR_UCE;
-                       break;
-#endif
-               }
-               if (o & 1)
-                       temp |= UBAMR_BO;
-       }
-
-       /*
-        * Set up the map registers, leaving an invalid reg
-        * at the end to guard against wild unibus transfers.
-        */
-       pte = &Sysmap[btop(((int)addr)&0x7fffffff)];
-       while (--npf != 0)
-               *(int *)io++ = pte++->pg_pfnum | temp;
-       *(int *)io = 0;
+               /*
+                * On a 780, set up the map register disable
+                * field in the configuration register.  Beware
+                * of callers that request memory ``out of order''.
+                */
+               if (cpu == VAX_780) {
+                       int cr = uh->uh_uba->uba_cr;
 
 
-       /*
-        * Return effective UNIBUS address.
-        */
-       return (ubinfo | o);
-}
+                       i = (addr + npg * 512 + 8191) / 8192;
+                       if (i > (cr >> 26))
+                               uh->uh_uba->uba_cr |= i << 26;
+               }
 #endif
 #endif
-
-/*
- * This routine is called by a driver for a device with on-board Unibus
- * memory.  It removes the memory block from the Unibus resource map
- * and clears the map registers for the block.
- *
- * Arguments are the Unibus number, the Unibus address of the memory
- * block, and its size in blocks of 512 bytes.
- *
- * Returns addr if successful, 0 if not.
- */
-
-ubamem(uban, addr, size)
-{
-       register struct uba_hd *uh = &uba_hd[uban];
-       register int *m;
-       register int i, a, s;
-
-       s = spl6();
-       a = rmget(uh->uh_map, size, addr>>9);
-       splx(s);
-       if (a) {
-               m = (int *) &uh->uh_uba->uba_map[a];
-               for (i=0; i<size; i++)
-                       *m++ = 0;       /* All off, especially 'valid' */
        }
        }
-       return(a);
+       return (a);
 }
 
 }
 
+#include "ik.h"
+#if NIK > 0
 /*
  * Map a virtual address into users address space. Actually all we
  * do is turn on the user mode write protection bits for the particular
 /*
  * Map a virtual address into users address space. Actually all we
  * do is turn on the user mode write protection bits for the particular
@@ -581,3 +490,4 @@ unmaptouser(vaddress)
 
        Sysmap[(((unsigned)(vaddress))-0x80000000) >> 9].pg_prot = (PG_KW>>27);
 }
 
        Sysmap[(((unsigned)(vaddress))-0x80000000) >> 9].pg_prot = (PG_KW>>27);
 }
+#endif