merge of 4.1b and 4.1c
[unix-history] / usr / src / sys / vax / uba / uba.c
index b897a18..4b0a3f3 100644 (file)
@@ -1,21 +1,23 @@
-/*     uba.c   4.27    81/03/22        */
+/*     uba.c   4.56    82/10/23        */
 
 #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/pte.h"
 #include "../h/buf.h"
 #include "../h/vm.h"
 #include "../h/map.h"
 #include "../h/pte.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;
@@ -56,14 +58,12 @@ ubago(ui)
        if (ui->ui_dk >= 0) {
                unit = ui->ui_dk;
                dk_busy |= 1<<unit;
        if (ui->ui_dk >= 0) {
                unit = ui->ui_dk;
                dk_busy |= 1<<unit;
+               dk_xfer[unit]++;
+               dk_wds[unit] += um->um_tab.b_actf->b_actf->b_bcount>>6;
        }
        if (uh->uh_actf == ui)
                uh->uh_actf = ui->ui_forw;
        (*um->um_driver->ud_dgo)(um);
        }
        if (uh->uh_actf == ui)
                uh->uh_actf = ui->ui_forw;
        (*um->um_driver->ud_dgo)(um);
-       if (ui->ui_dk >= 0) {
-               dk_xfer[unit]++;
-               dk_wds[unit] += um->um_tab.b_actf->b_actf->b_bcount>>6;
-       }
        return (1);
 rwait:
        if (uh->uh_actf != ui) {
        return (1);
 rwait:
        if (uh->uh_actf != ui) {
@@ -104,7 +104,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;
@@ -119,9 +119,11 @@ 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) {
-               if (flags & UBA_CANTWAIT)
+       while ((reg = rmalloc(uh->uh_map, (long)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);
        }
@@ -129,42 +131,36 @@ 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) {
-                               rmfree(uh->uh_map, npf, reg);
+                               rmfree(uh->uh_map, (long)npf, (long)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;
        splx(a);
        reg--;
        ubinfo = (bdp << 28) | (npf << 18) | (reg << 9) | o;
-       io = &uh->uh_uba->uba_map[reg];
        temp = (bdp << 21) | UBAMR_MRV;
        temp = (bdp << 21) | UBAMR_MRV;
-       rp = bp->b_flags&B_DIRTY ? &proc[2] : bp->b_proc;
        if (bdp && (o & 01))
                temp |= UBAMR_BO;
        if (bdp && (o & 01))
                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)
-                               panic("uba: zero upage");
-                       *(int *)io++ = rp->p_addr[i].pg_pfnum | temp;
-               }
-       } else if ((bp->b_flags & B_PHYS) == 0) {
+       rp = bp->b_flags&B_DIRTY ? &proc[2] : bp->b_proc;
+       if ((bp->b_flags & B_PHYS) == 0)
                pte = &Sysmap[btop(((int)bp->b_un.b_addr)&0x7fffffff)];
                pte = &Sysmap[btop(((int)bp->b_un.b_addr)&0x7fffffff)];
-               while (--npf != 0)
-                       *(int *)io++ = pte++->pg_pfnum | temp;
-       } else {
-               if (bp->b_flags & B_PAGET)
-                       pte = &Usrptmap[btokmx((struct pte *)bp->b_un.b_addr)];
-               else
-                       pte = vtopte(rp, v);
-               while (--npf != 0) {
-                       if (pte->pg_pfnum == 0)
-                               panic("uba zero uentry");
-                       *(int *)io++ = pte++->pg_pfnum | temp;
-               }
+       else if (bp->b_flags & B_UAREA)
+               pte = &rp->p_addr[v];
+       else if (bp->b_flags & B_PAGET)
+               pte = &Usrptmap[btokmx((struct pte *)bp->b_un.b_addr)];
+       else
+               pte = vtopte(rp, v);
+       io = &uh->uh_uba->uba_map[reg];
+       while (--npf != 0) {
+               if (pte->pg_pfnum == 0)
+                       panic("uba zero uentry");
+               *(int *)io++ = pte++->pg_pfnum | temp;
        }
        *(int *)io++ = 0;
        return (ubinfo);
        }
        *(int *)io++ = 0;
        return (ubinfo);
@@ -244,7 +240,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);
 
        /*
@@ -280,6 +276,29 @@ ubapurge(um)
        }
 }
 
        }
 }
 
+ubainitmaps(uhp)
+       register struct uba_hd *uhp;
+{
+
+       rminit(uhp->uh_map, (long)NUBMREG, (long)1, "uba", UAMSIZ);
+       switch (cpu) {
+#if VAX780
+       case VAX_780:
+               uhp->uh_bdpfree = (1<<NBDP780) - 1;
+               break;
+#endif
+#if VAX750
+       case VAX_750:
+               uhp->uh_bdpfree = (1<<NBDP750) - 1;
+               break;
+#endif
+#if VAX730
+       case VAX_730:
+               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,
@@ -296,16 +315,19 @@ 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;
+       ubainitmaps(uh);
        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);
        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);
+#ifdef INET
+       ifubareset(uban);
+#endif
        printf("\n");
        splx(s);
 }
        printf("\n");
        splx(s);
 }
@@ -348,51 +370,9 @@ 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;
-               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;
 /*
  * 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
@@ -429,11 +409,77 @@ ubaerror(uban, uh, xx, uvec, uba)
        }
        sr = uba->uba_sr;
        s = spl7();
        }
        sr = uba->uba_sr;
        s = spl7();
-       printf("uba%d: uba 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;
        uvec &= UBABRRVR_DIV;
        splx(s);
        uba->uba_sr = sr;
        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 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, its size in blocks of 512 bytes, and a flag indicating whether
+ * to allocate the unibus space form the resource map or whether it already
+ * has been.
+ *
+ * Returns > 0 if successful, 0 if not.
+ */
+ubamem(uban, addr, size, doalloc)
+       int uban, addr, size, doalloc;
+{
+       register struct uba_hd *uh = &uba_hd[uban];
+       register int *m;
+       register int i, a, s;
+
+       if (doalloc) {
+               s = spl6();
+               a = rmget(uh->uh_map, size, (addr>>9)+1); /* starts at ONE! */
+               splx(s);
+       } else
+               a = (addr>>9)+1;
+       if (a) {
+               m = (int *) &uh->uh_uba->uba_map[a-1];
+               for (i=0; i<size; i++)
+                       *m++ = 0;       /* All off, especially 'valid' */
+#if VAX780
+               if (cpu == VAX_780) {           /* map disable */
+                       i = (addr+size*512+8191)/8192;
+                       uh->uh_uba->uba_cr |= i<<26;
+               }
+#endif
+       }
+       return(a);
+}
+
+/*
+ * Map a virtual address into users address space. Actually all we
+ * do is turn on the user mode write protection bits for the particular
+ * page of memory involved.
+ */
+maptouser(vaddress)
+       caddr_t vaddress;
+{
+
+       Sysmap[(((unsigned)(vaddress))-0x80000000) >> 9].pg_prot = (PG_UW>>27);
+}
+
+unmaptouser(vaddress)
+       caddr_t vaddress;
+{
+
+       Sysmap[(((unsigned)(vaddress))-0x80000000) >> 9].pg_prot = (PG_KW>>27);
+}