remember dma count, as can't calculate correctly on Emulex;
[unix-history] / usr / src / sys / vax / uba / uba.c
index 5ad920e..ba9d9ad 100644 (file)
@@ -1,4 +1,10 @@
-/*     uba.c   6.3     85/01/18        */
+/*
+ * Copyright (c) 1982 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)uba.c       6.10 (Berkeley) %G%
+ */
 
 #include "../machine/pte.h"
 
 
 #include "../machine/pte.h"
 
 #include "ubareg.h"
 #include "ubavar.h"
 
 #include "ubareg.h"
 #include "ubavar.h"
 
-#if VAX780
+#if defined(VAX780) || defined(VAX8600)
 char   ubasr_bits[] = UBASR_BITS;
 #endif
 
 char   ubasr_bits[] = UBASR_BITS;
 #endif
 
+#define        spluba  spl7            /* IPL 17 */
+
 /*
  * Do transfer on device argument.  The controller
  * and uba involved are implied by the device.
 /*
  * Do transfer on device argument.  The controller
  * and uba involved are implied by the device.
@@ -45,7 +53,7 @@ ubago(ui)
        register int s, unit;
 
        uh = &uba_hd[um->um_ubanum];
        register int s, unit;
 
        uh = &uba_hd[um->um_ubanum];
-       s = spl6();
+       s = spluba();
        if (um->um_driver->ud_xclu && uh->uh_users > 0 || uh->uh_xclu)
                goto rwait;
        um->um_ubinfo = ubasetup(um->um_ubanum, um->um_tab.b_actf->b_actf,
        if (um->um_driver->ud_xclu && uh->uh_users > 0 || uh->uh_xclu)
                goto rwait;
        um->um_ubinfo = ubasetup(um->um_ubanum, um->um_tab.b_actf->b_actf,
@@ -105,7 +113,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;
+       int pfnum, temp;
        int npf, reg, bdp;
        unsigned v;
        register struct pte *pte, *io;
        int npf, reg, bdp;
        unsigned v;
        register struct pte *pte, *io;
@@ -119,7 +127,7 @@ ubasetup(uban, bp, flags)
        v = btop(bp->b_un.b_addr);
        o = (int)bp->b_un.b_addr & PGOFSET;
        npf = btoc(bp->b_bcount + o) + 1;
        v = btop(bp->b_un.b_addr);
        o = (int)bp->b_un.b_addr & PGOFSET;
        npf = btoc(bp->b_bcount + o) + 1;
-       a = spl6();
+       a = spluba();
        while ((reg = rmalloc(uh->uh_map, (long)npf)) == 0) {
                if (flags & UBA_CANTWAIT) {
                        splx(a);
        while ((reg = rmalloc(uh->uh_map, (long)npf)) == 0) {
                if (flags & UBA_CANTWAIT) {
                        splx(a);
@@ -139,7 +147,7 @@ ubasetup(uban, bp, flags)
        }
        bdp = 0;
        if (flags & UBA_NEEDBDP) {
        }
        bdp = 0;
        if (flags & UBA_NEEDBDP) {
-               while ((bdp = ffs(uh->uh_bdpfree)) == 0) {
+               while ((bdp = ffs((long)uh->uh_bdpfree)) == 0) {
                        if (flags & UBA_CANTWAIT) {
                                rmfree(uh->uh_map, (long)npf, (long)reg);
                                splx(a);
                        if (flags & UBA_CANTWAIT) {
                                rmfree(uh->uh_map, (long)npf, (long)reg);
                                splx(a);
@@ -168,9 +176,11 @@ ubasetup(uban, bp, flags)
                pte = vtopte(rp, v);
        io = &uh->uh_uba->uba_map[reg];
        while (--npf != 0) {
                pte = vtopte(rp, v);
        io = &uh->uh_uba->uba_map[reg];
        while (--npf != 0) {
-               if (pte->pg_pfnum == 0)
+               pfnum = pte->pg_pfnum;
+               if (pfnum == 0)
                        panic("uba zero uentry");
                        panic("uba zero uentry");
-               *(int *)io++ = pte++->pg_pfnum | temp;
+               pte++;
+               *(int *)io++ = pfnum | temp;
        }
        *(int *)io++ = 0;
        return (ubinfo);
        }
        *(int *)io++ = 0;
        return (ubinfo);
@@ -209,7 +219,7 @@ ubarelse(uban, amr)
         * Carefully see if we should release the space, since
         * it may be released asynchronously at uba reset time.
         */
         * Carefully see if we should release the space, since
         * it may be released asynchronously at uba reset time.
         */
-       s = spl6();
+       s = spluba();
        mr = *amr;
        if (mr == 0) {
                /*
        mr = *amr;
        if (mr == 0) {
                /*
@@ -223,7 +233,8 @@ ubarelse(uban, amr)
        bdp = (mr >> 28) & 0x0f;
        if (bdp) {
                switch (cpu) {
        bdp = (mr >> 28) & 0x0f;
        if (bdp) {
                switch (cpu) {
-#if VAX780
+#if defined(VAX780) || defined(VAX8600)
+               case VAX_8600:
                case VAX_780:
                        uh->uh_uba->uba_dpr[bdp] |= UBADPR_BNE;
                        break;
                case VAX_780:
                        uh->uh_uba->uba_dpr[bdp] |= UBADPR_BNE;
                        break;
@@ -272,7 +283,8 @@ ubapurge(um)
        register int bdp = (um->um_ubinfo >> 28) & 0x0f;
 
        switch (cpu) {
        register int bdp = (um->um_ubinfo >> 28) & 0x0f;
 
        switch (cpu) {
-#if VAX780
+#if defined(VAX780) || defined(VAX8600)
+       case VAX_8600:
        case VAX_780:
                uh->uh_uba->uba_dpr[bdp] |= UBADPR_BNE;
                break;
        case VAX_780:
                uh->uh_uba->uba_dpr[bdp] |= UBADPR_BNE;
                break;
@@ -291,7 +303,8 @@ ubainitmaps(uhp)
 
        rminit(uhp->uh_map, (long)NUBMREG, (long)1, "uba", UAMSIZ);
        switch (cpu) {
 
        rminit(uhp->uh_map, (long)NUBMREG, (long)1, "uba", UAMSIZ);
        switch (cpu) {
-#if VAX780
+#if defined(VAX780) || defined(VAX8600)
+       case VAX_8600:
        case VAX_780:
                uhp->uh_bdpfree = (1<<NBDP780) - 1;
                break;
        case VAX_780:
                uhp->uh_bdpfree = (1<<NBDP780) - 1;
                break;
@@ -320,7 +333,7 @@ ubareset(uban)
        register struct uba_hd *uh = &uba_hd[uban];
        int s;
 
        register struct uba_hd *uh = &uba_hd[uban];
        int s;
 
-       s = spl6();
+       s = spluba();
        uh->uh_users = 0;
        uh->uh_zvcnt = 0;
        uh->uh_xclu = 0;
        uh->uh_users = 0;
        uh->uh_zvcnt = 0;
        uh->uh_xclu = 0;
@@ -335,9 +348,7 @@ ubareset(uban)
        ubameminit(uban);
        for (cdp = cdevsw; cdp < cdevsw + nchrdev; cdp++)
                (*cdp->d_reset)(uban);
        ubameminit(uban);
        for (cdp = cdevsw; cdp < cdevsw + nchrdev; cdp++)
                (*cdp->d_reset)(uban);
-#ifdef INET
        ifubareset(uban);
        ifubareset(uban);
-#endif
        printf("\n");
        splx(s);
 }
        printf("\n");
        splx(s);
 }
@@ -355,7 +366,8 @@ ubainit(uba)
 {
 
        switch (cpu) {
 {
 
        switch (cpu) {
-#if VAX780
+#if defined(VAX780) || defined(VAX8600)
+       case VAX_8600:
        case VAX_780:
                uba->uba_cr = UBACR_ADINIT;
                uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE;
        case VAX_780:
                uba->uba_cr = UBACR_ADINIT;
                uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE;
@@ -380,15 +392,13 @@ ubainit(uba)
        }
 }
 
        }
 }
 
-#ifdef VAX780
+#if defined(VAX780) || defined(VAX8600)
 int    ubawedgecnt = 10;
 int    ubacrazy = 500;
 int    zvcnt_max = 5000;       /* in 8 sec */
 int    ubawedgecnt = 10;
 int    ubacrazy = 500;
 int    zvcnt_max = 5000;       /* in 8 sec */
-int    zvcnt_total;
-long   zvcnt_time;
 /*
 /*
- * This routine is called by the locore code to
- * process a UBA error on an 11/780.  The arguments are passed
+ * This routine is called by the locore code to process a UBA
+ * error on an 11/780 or 8600.  The arguments are passed
  * on the stack, and value-result (through some trickery).
  * In particular, the uvec argument is used for further
  * uba processing so the result aspect of it is very important.
  * on the stack, and value-result (through some trickery).
  * In particular, the uvec argument is used for further
  * uba processing so the result aspect of it is very important.
@@ -404,10 +414,15 @@ ubaerror(uban, uh, ipl, uvec, uba)
        register sr, s;
 
        if (uvec == 0) {
        register sr, s;
 
        if (uvec == 0) {
-               long    dt = time.tv_sec - zvcnt_time;
-               zvcnt_total++;
+               /*
+                * Declare dt as unsigned so that negative values
+                * are handled as >8 below, in case time was set back.
+                */
+               u_long  dt = time.tv_sec - uh->uh_zvtime;
+
+               uh->uh_zvtotal++;
                if (dt > 8) {
                if (dt > 8) {
-                       zvcnt_time = time.tv_sec;
+                       uh->uh_zvtime = time.tv_sec;
                        uh->uh_zvcnt = 0;
                }
                if (++uh->uh_zvcnt > zvcnt_max) {
                        uh->uh_zvcnt = 0;
                }
                if (++uh->uh_zvcnt > zvcnt_max) {
@@ -432,7 +447,7 @@ ubaerror(uban, uh, ipl, uvec, uba)
                return;
        }
        sr = uba->uba_sr;
                return;
        }
        sr = uba->uba_sr;
-       s = spl7();
+       s = spluba();
        printf("uba%d: uba error sr=%b fmer=%x fubar=%o\n",
            uban, uba->uba_sr, ubasr_bits, uba->uba_fmer, 4*uba->uba_fubar);
        splx(s);
        printf("uba%d: uba error sr=%b fmer=%x fubar=%o\n",
            uban, uba->uba_sr, ubasr_bits, uba->uba_fmer, 4*uba->uba_fubar);
        splx(s);
@@ -485,13 +500,13 @@ ubameminit(uban)
                        ui->ui_addr = addr;
                }
        }
                        ui->ui_addr = addr;
                }
        }
-#if VAX780
+#if defined(VAX780) || defined(VAX8600)
        /*
         * On a 780, throw away any map registers disabled by rounding
         * the map disable in the configuration register
         * up to the next 8K boundary, or below the last unibus memory.
         */
        /*
         * On a 780, throw away any map registers disabled by rounding
         * the map disable in the configuration register
         * up to the next 8K boundary, or below the last unibus memory.
         */
-       if (cpu == VAX_780) {
+       if ((cpu == VAX_780) || (cpu == VAX_8600)) {
                register i;
 
                i = btop(((uh->uh_lastmem + 8191) / 8192) * 8192);
                register i;
 
                i = btop(((uh->uh_lastmem + 8191) / 8192) * 8192);
@@ -520,7 +535,7 @@ ubamem(uban, addr, npg, doalloc)
        int s;
 
        a = (addr >> 9) + 1;
        int s;
 
        a = (addr >> 9) + 1;
-       s = spl6();
+       s = spluba();
        if (doalloc)
                a = rmget(uh->uh_map, npg, a);
        else
        if (doalloc)
                a = rmget(uh->uh_map, npg, a);
        else
@@ -537,7 +552,7 @@ ubamem(uban, addr, npg, doalloc)
                        uh->uh_lastmem = i;
                else if (doalloc == 0 && i == uh->uh_lastmem)
                        uh->uh_lastmem = addr;
                        uh->uh_lastmem = i;
                else if (doalloc == 0 && i == uh->uh_lastmem)
                        uh->uh_lastmem = addr;
-#if VAX780
+#if defined(VAX780) || defined(VAX8600)
                /*
                 * On a 780, set up the map register disable
                 * field in the configuration register.  Beware
                /*
                 * On a 780, set up the map register disable
                 * field in the configuration register.  Beware
@@ -545,7 +560,7 @@ ubamem(uban, addr, npg, doalloc)
                 * or in sections other than 8K multiples.
                 * Ubameminit handles such requests properly, however.
                 */
                 * or in sections other than 8K multiples.
                 * Ubameminit handles such requests properly, however.
                 */
-               if (cpu == VAX_780) {
+               if ((cpu == VAX_780) || (cpu == VAX_8600)) {
                        i = uh->uh_uba->uba_cr &~ 0x7c000000;
                        i |= ((uh->uh_lastmem + 8191) / 8192) << 26;
                        uh->uh_uba->uba_cr = i;
                        i = uh->uh_uba->uba_cr &~ 0x7c000000;
                        i |= ((uh->uh_lastmem + 8191) / 8192) << 26;
                        uh->uh_uba->uba_cr = i;
@@ -556,7 +571,8 @@ ubamem(uban, addr, npg, doalloc)
 }
 
 #include "ik.h"
 }
 
 #include "ik.h"
-#if NIK > 0
+#include "vs.h"
+#if NIK > 0 || NVS > 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