merge of 4.1b and 4.1c
[unix-history] / usr / src / sys / vax / uba / uba.c
index a4e419d..4b0a3f3 100644 (file)
@@ -1,21 +1,23 @@
-/*     uba.c   4.45    82/05/26        */
+/*     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;
@@ -102,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;
@@ -117,7 +119,7 @@ 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);
                if (flags & UBA_CANTWAIT) {
                        splx(a);
                        return (0);
@@ -129,7 +131,7 @@ 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);
                        }
                                splx(a);
                                return (0);
                        }
@@ -238,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);
 
        /*
@@ -278,7 +280,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 +315,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;
@@ -369,52 +370,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,95 +426,60 @@ 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.
- */
-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);
-}
-#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
 /*
  * 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.
+ * 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 addr if successful, 0 if not.
+ * Returns > 0 if successful, 0 if not.
  */
  */
-
-ubamem(uban, addr, size)
+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;
 
 {
        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 (doalloc) {
+               s = spl6();
+               a = rmget(uh->uh_map, size, (addr>>9)+1); /* starts at ONE! */
+               splx(s);
+       } else
+               a = (addr>>9)+1;
        if (a) {
        if (a) {
-               m = (int *) &uh->uh_uba->uba_map[a];
+               m = (int *) &uh->uh_uba->uba_map[a-1];
                for (i=0; i<size; i++)
                        *m++ = 0;       /* All off, especially 'valid' */
                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);
 }
        }
        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);
+}