more cleanup
[unix-history] / usr / src / sys / vax / uba / uba.c
index 8244bb6..62e16c4 100644 (file)
@@ -1,6 +1,4 @@
-/*     uba.c   4.12    %G%     */
-
-#define        DELAY(N)        { register int d; d = N; while (--d > 0); }
+/*     uba.c   4.36    81/11/07        */
 
 #include "../h/param.h"
 #include "../h/systm.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
@@ -9,7 +7,8 @@
 #include "../h/pte.h"
 #include "../h/buf.h"
 #include "../h/vm.h"
 #include "../h/pte.h"
 #include "../h/buf.h"
 #include "../h/vm.h"
-#include "../h/uba.h"
+#include "../h/ubareg.h"
+#include "../h/ubavar.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/proc.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/proc.h"
@@ -18,9 +17,8 @@
 #include "../h/nexus.h"
 #include "../h/dk.h"
 
 #include "../h/nexus.h"
 #include "../h/dk.h"
 
-#include "rk.h"
-#if NRK11 > 0
-extern struct uba_driver hkdriver;
+#if VAX780
+char   ubasr_bits[] = UBASR_BITS;
 #endif
 
 /*
 #endif
 
 /*
@@ -37,27 +35,23 @@ extern      struct uba_driver hkdriver;
  * of the request queue is likely to be a disaster.
  */
 ubago(ui)
  * of the request queue is likely to be a disaster.
  */
 ubago(ui)
-       register struct uba_dinfo *ui;
+       register struct uba_device *ui;
 {
 {
-       register struct uba_minfo *um = ui->ui_mi;
+       register struct uba_ctlr *um = ui->ui_mi;
        register struct uba_hd *uh;
        register int s, unit;
 
        uh = &uba_hd[um->um_ubanum];
        s = spl6();
        register struct uba_hd *uh;
        register int s, unit;
 
        uh = &uba_hd[um->um_ubanum];
        s = spl6();
-#if NRK11 > 0
-       if (um->um_driver == &hkdriver && uh->uh_users > 0 || uh->uh_xclu)
+       if (um->um_driver->ud_xclu && uh->uh_users > 0 || uh->uh_xclu)
                goto rwait;
                goto rwait;
-#endif
        um->um_ubinfo = ubasetup(um->um_ubanum, um->um_tab.b_actf->b_actf,
            UBA_NEEDBDP|UBA_CANTWAIT);
        if (um->um_ubinfo == 0)
                goto rwait;
        um->um_ubinfo = ubasetup(um->um_ubanum, um->um_tab.b_actf->b_actf,
            UBA_NEEDBDP|UBA_CANTWAIT);
        if (um->um_ubinfo == 0)
                goto rwait;
-#if NRK11 > 0
        uh->uh_users++;
        uh->uh_users++;
-       if (um->um_driver == &hkdriver)
+       if (um->um_driver->ud_xclu)
                uh->uh_xclu = 1;
                uh->uh_xclu = 1;
-#endif
        splx(s);
        if (ui->ui_dk >= 0) {
                unit = ui->ui_dk;
        splx(s);
        if (ui->ui_dk >= 0) {
                unit = ui->ui_dk;
@@ -68,7 +62,7 @@ ubago(ui)
        (*um->um_driver->ud_dgo)(um);
        if (ui->ui_dk >= 0) {
                dk_xfer[unit]++;
        (*um->um_driver->ud_dgo)(um);
        if (ui->ui_dk >= 0) {
                dk_xfer[unit]++;
-               dk_wds[unit] += um->um_tab.b_actf->b_bcount>>6;
+               dk_wds[unit] += um->um_tab.b_actf->b_actf->b_bcount>>6;
        }
        return (1);
 rwait:
        }
        return (1);
 rwait:
@@ -85,15 +79,13 @@ rwait:
 }
 
 ubadone(um)
 }
 
 ubadone(um)
-       register struct uba_minfo *um;
+       register struct uba_ctlr *um;
 {
        register struct uba_hd *uh = &uba_hd[um->um_ubanum];
 
 {
        register struct uba_hd *uh = &uba_hd[um->um_ubanum];
 
-#if NRK11 > 0
-       if (um->um_driver == &hkdriver)
+       if (um->um_driver->ud_xclu)
                uh->uh_xclu = 0;
        uh->uh_users--;
                uh->uh_xclu = 0;
        uh->uh_users--;
-#endif
        ubarelse(um->um_ubanum, &um->um_ubinfo);
 }
 
        ubarelse(um->um_ubanum, &um->um_ubinfo);
 }
 
@@ -119,13 +111,19 @@ ubasetup(uban, bp, flags)
        struct proc *rp;
        int a, o, ubinfo;
 
        struct proc *rp;
        int a, o, ubinfo;
 
+#if VAX7ZZ
+       if (cpu == VAX_7ZZ)
+               flags &= ~UBA_NEEDBDP;
+#endif
        v = btop(bp->b_un.b_addr);
        o = (int)bp->b_un.b_addr & PGOFSET;
        npf = btoc(bp->b_bcount + o) + 1;
        a = spl6();
        v = btop(bp->b_un.b_addr);
        o = (int)bp->b_un.b_addr & PGOFSET;
        npf = btoc(bp->b_bcount + o) + 1;
        a = spl6();
-       while ((reg = malloc(uh->uh_map, npf)) == 0) {
-               if (flags & UBA_CANTWAIT)
+       while ((reg = rmalloc(uh->uh_map, npf)) == 0) {
+               if (flags & UBA_CANTWAIT) {
+                       splx(a);
                        return (0);
                        return (0);
+               }
                uh->uh_mrwant++;
                sleep((caddr_t)uh->uh_map, PSWP);
        }
                uh->uh_mrwant++;
                sleep((caddr_t)uh->uh_map, PSWP);
        }
@@ -133,22 +131,24 @@ ubasetup(uban, bp, flags)
        if (flags & UBA_NEEDBDP) {
                while ((bdp = ffs(uh->uh_bdpfree)) == 0) {
                        if (flags & UBA_CANTWAIT) {
        if (flags & UBA_NEEDBDP) {
                while ((bdp = ffs(uh->uh_bdpfree)) == 0) {
                        if (flags & UBA_CANTWAIT) {
-                               mfree(uh->uh_map, npf, reg);
+                               rmfree(uh->uh_map, npf, reg);
+                               splx(a);
                                return (0);
                        }
                        uh->uh_bdpwant++;
                        sleep((caddr_t)uh->uh_map, PSWP);
                }
                uh->uh_bdpfree &= ~(1 << (bdp-1));
                                return (0);
                        }
                        uh->uh_bdpwant++;
                        sleep((caddr_t)uh->uh_map, PSWP);
                }
                uh->uh_bdpfree &= ~(1 << (bdp-1));
-       }
+       } else if (flags & UBA_HAVEBDP)
+               bdp = (flags >> 28) & 0xf;
        splx(a);
        reg--;
        ubinfo = (bdp << 28) | (npf << 18) | (reg << 9) | o;
        io = &uh->uh_uba->uba_map[reg];
        splx(a);
        reg--;
        ubinfo = (bdp << 28) | (npf << 18) | (reg << 9) | o;
        io = &uh->uh_uba->uba_map[reg];
-       temp = (bdp << 21) | UBA_MRV;
+       temp = (bdp << 21) | UBAMR_MRV;
        rp = bp->b_flags&B_DIRTY ? &proc[2] : bp->b_proc;
        if (bdp && (o & 01))
        rp = bp->b_flags&B_DIRTY ? &proc[2] : bp->b_proc;
        if (bdp && (o & 01))
-               temp |= UBA_BO;
+               temp |= UBAMR_BO;
        if (bp->b_flags & B_UAREA) {
                for (i = UPAGES - bp->b_bcount / NBPG; i < UPAGES; i++) {
                        if (rp->p_addr[i].pg_pfnum == 0)
        if (bp->b_flags & B_UAREA) {
                for (i = UPAGES - bp->b_bcount / NBPG; i < UPAGES; i++) {
                        if (rp->p_addr[i].pg_pfnum == 0)
@@ -178,8 +178,9 @@ ubasetup(uban, bp, flags)
  * Non buffer setup interface... set up a buffer and call ubasetup.
  */
 uballoc(uban, addr, bcnt, flags)
  * Non buffer setup interface... set up a buffer and call ubasetup.
  */
 uballoc(uban, addr, bcnt, flags)
+       int uban;
        caddr_t addr;
        caddr_t addr;
-       unsigned short bcnt;
+       int bcnt, flags;
 {
        struct buf ubabuf;
 
 {
        struct buf ubabuf;
 
@@ -220,16 +221,16 @@ ubarelse(uban, amr)
        splx(s);                /* let interrupts in, we're safe for a while */
        bdp = (mr >> 28) & 0x0f;
        if (bdp) {
        splx(s);                /* let interrupts in, we're safe for a while */
        bdp = (mr >> 28) & 0x0f;
        if (bdp) {
-               switch (cpu)
-               {
+               switch (cpu) {
 #if VAX780
                case VAX_780:
 #if VAX780
                case VAX_780:
-                       uh->uh_uba->uba_dpr[bdp] |= UBA_BNE;
+                       uh->uh_uba->uba_dpr[bdp] |= UBADPR_BNE;
                        break;
 #endif
 #if VAX750
                case VAX_750:
                        break;
 #endif
 #if VAX750
                case VAX_750:
-                       uh->uh_uba->uba_dpr[bdp] |= UBA_PURGE|UBA_NXM|UBA_UCE;
+                       uh->uh_uba->uba_dpr[bdp] |=
+                           UBADPR_PURGE|UBADPR_NXM|UBADPR_UCE;
                        break;
 #endif
                }
                        break;
 #endif
                }
@@ -247,7 +248,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();
-       mfree(uh->uh_map, npf, reg);
+       rmfree(uh->uh_map, npf, reg);
        splx(s);
 
        /*
        splx(s);
 
        /*
@@ -263,6 +264,26 @@ ubarelse(uban, amr)
                ;
 }
 
                ;
 }
 
+ubapurge(um)
+       register struct uba_ctlr *um;
+{
+       register struct uba_hd *uh = um->um_hd;
+       register int bdp = (um->um_ubinfo >> 28) & 0x0f;
+
+       switch (cpu) {
+#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
+       }
+}
+
 /*
  * Generate a reset on uba number uban.  Then
  * call each device in the character device table,
 /*
  * Generate a reset on uba number uban.  Then
  * call each device in the character device table,
@@ -272,24 +293,21 @@ ubareset(uban)
        int uban;
 {
        register struct cdevsw *cdp;
        int uban;
 {
        register struct cdevsw *cdp;
+       register struct uba_hd *uh = &uba_hd[uban];
        int s;
 
        s = spl6();
        int s;
 
        s = spl6();
-       switch (cpu) {
-#if VAX==780
-       case VAX_780:
-               printf("UBA RESET %d:", uban);
-               ubainit(uba_hd[uban].uh_uba);
-               break;
-#endif
-#if VAX==750
-       case VAX_750:
-               printf("UNIBUS INIT:");
-               mtpr(IUR, 1);
-               DELAY(100000);
-               break;
-#endif
-       }
+       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;
+       wakeup((caddr_t)&uh->uh_bdpwant);
+       wakeup((caddr_t)&uh->uh_mrwant);
+       printf("uba%d: reset", uban);
+       ubainit(uh->uh_uba);
        for (cdp = cdevsw; cdp->d_open; cdp++)
                (*cdp->d_reset)(uban);
        printf("\n");
        for (cdp = cdevsw; cdp->d_open; cdp++)
                (*cdp->d_reset)(uban);
        printf("\n");
@@ -308,10 +326,30 @@ ubainit(uba)
        register struct uba_regs *uba;
 {
 
        register struct uba_regs *uba;
 {
 
-       uba->uba_cr = UBA_ADINIT;
-       uba->uba_cr = UBA_IFS|UBA_BRIE|UBA_USEFIE|UBA_SUEFIE;
-       while ((uba->uba_cnfgr & UBA_UBIC) == 0)
-               ;
+       switch (cpu) {
+#if VAX780
+       case VAX_780:
+               uba->uba_cr = UBACR_ADINIT;
+               uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE;
+               while ((uba->uba_cnfgr & UBACNFGR_UBIC) == 0)
+                       ;
+               break;
+#endif
+#if VAX750
+       case VAX_750:
+#endif
+#if VAX7ZZ
+       case VAX_7ZZ:
+#endif
+#if defined(VAX750) || defined(VAX7ZZ)
+               mtpr(IUR, 0);
+               /* give devices time to recover from power fail */
+/* THIS IS PROBABLY UNNECESSARY */
+               DELAY(500000);
+/* END PROBABLY UNNECESSARY */
+               break;
+#endif
+       }
 }
 
 #if VAX780
 }
 
 #if VAX780
@@ -330,10 +368,11 @@ unhang()
 
                if (up->uba_sr == 0)
                        return;
 
                if (up->uba_sr == 0)
                        return;
+               up->uba_sr = UBASR_CRD|UBASR_LEB;
                uh->uh_hangcnt++;
                uh->uh_hangcnt++;
-               if (uh->uh_hangcnt > 5*HZ) {
+               if (uh->uh_hangcnt > 5*hz) {
                        uh->uh_hangcnt = 0;
                        uh->uh_hangcnt = 0;
-                       printf("HANG ");
+                       printf("uba%d: hung\n", uban);
                        ubareset(uban);
                }
        }
                        ubareset(uban);
                }
        }
@@ -350,6 +389,8 @@ ubawatch()
        register struct uba_hd *uh;
        register int uban;
 
        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)
        for (uban = 0; uban < numuba; uban++) {
                uh = &uba_hd[uban];
                if (uh->uh_hangcnt)
@@ -357,6 +398,8 @@ ubawatch()
        }
 }
 
        }
 }
 
+int    ubawedgecnt = 10;
+int    ubacrazy = 500;
 /*
  * 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.  The arguments are passed
@@ -377,26 +420,98 @@ ubaerror(uban, uh, xx, uvec, uba)
        if (uvec == 0) {
                uh->uh_zvcnt++;
                if (uh->uh_zvcnt > 250000) {
        if (uvec == 0) {
                uh->uh_zvcnt++;
                if (uh->uh_zvcnt > 250000) {
-                       printf("ZERO VECTOR ");
+                       printf("uba%d: too many zero vectors\n");
                        ubareset(uban);
                }
                uvec = 0;
                return;
        }
        if (uba->uba_cnfgr & NEX_CFGFLT) {
                        ubareset(uban);
                }
                uvec = 0;
                return;
        }
        if (uba->uba_cnfgr & NEX_CFGFLT) {
-               printf("UBA%d SBI FAULT sr %x cnfgr %x\n",
-                   uban, uba->uba_sr, uba->uba_cnfgr);
+               printf("uba%d: sbi fault sr=%b cnfgr=%b\n",
+                   uban, uba->uba_sr, ubasr_bits,
+                   uba->uba_cnfgr, NEXFLT_BITS);
                ubareset(uban);
                uvec = 0;
                return;
        }
        sr = uba->uba_sr;
        s = spl7();
                ubareset(uban);
                uvec = 0;
                return;
        }
        sr = uba->uba_sr;
        s = spl7();
-       printf("UBA%d ERROR SR %x FMER %x FUBAR %o\n",
-           uban, uba->uba_sr, uba->uba_fmer, 4*uba->uba_fubar);
+       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);
        uba->uba_sr = sr;
        splx(s);
        uba->uba_sr = sr;
-       uvec &= UBA_DIV;
+       uvec &= UBABRRVR_DIV;
+       if (++uh->uh_errcnt % ubawedgecnt == 0) {
+               if (uh->uh_errcnt > ubacrazy)
+                       panic("uba crazy");
+               printf("ERROR LIMIT ");
+               ubareset(uban);
+               uvec = 0;
+               return;
+       }
        return;
 }
 #endif
        return;
 }
 #endif
+
+/*
+ * 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.
+ */
+ubaremap(uban, ubinfo, addr)
+       int uban;
+       register unsigned ubinfo;
+       caddr_t addr;
+{
+       register struct uba_hd *uh = &uba_hd[uban];
+       register struct pte *pte, *io;
+       register int temp, bdp;
+       int npf, o;
+
+       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 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) {
+#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;
+
+       /*
+        * Return effective UNIBUS address.
+        */
+       return (ubinfo | o);
+}