+ while (uh->uh_actf && ubago(uh->uh_actf))
+ ;
+}
+
+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
+ }
+}
+
+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,
+ * giving it a chance to clean up so as to be able to continue.
+ */
+ubareset(uban)
+ int uban;
+{
+ register struct cdevsw *cdp;
+ register struct uba_hd *uh = &uba_hd[uban];
+ int s;
+
+ s = spl6();
+ uh->uh_users = 0;
+ uh->uh_zvcnt = 0;
+ uh->uh_xclu = 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);
+#ifdef INET
+ ifubareset(uban);
+#endif
+ printf("\n");
+ splx(s);
+}
+
+/*
+ * Init a uba. This is called with a pointer
+ * rather than a virtual address since it is called
+ * by code which runs with memory mapping disabled.
+ * In these cases we really don't need the interrupts
+ * enabled, but since we run with ipl high, we don't care
+ * if they are, they will never happen anyways.
+ */
+ubainit(uba)
+ register struct uba_regs *uba;
+{
+
+ 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 VAX730
+ case VAX_730:
+#endif
+#if defined(VAX750) || defined(VAX730)
+ mtpr(IUR, 0);
+ /* give devices time to recover from power fail */
+/* THIS IS PROBABLY UNNECESSARY */
+ DELAY(500000);
+/* END PROBABLY UNNECESSARY */
+ break;
+#endif
+ }
+}
+
+#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
+ * 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.
+ * It must not be declared register.
+ */
+/*ARGSUSED*/
+ubaerror(uban, uh, xx, uvec, uba)
+ register int uban;
+ register struct uba_hd *uh;
+ int uvec;
+ register struct uba_regs *uba;
+{
+ register sr, s;
+
+ if (uvec == 0) {
+ uh->uh_zvcnt++;
+ if (uh->uh_zvcnt > 250000) {
+ printf("uba%d: too many zero vectors\n");
+ ubareset(uban);
+ }
+ uvec = 0;
+ return;
+ }
+ if (uba->uba_cnfgr & NEX_CFGFLT) {
+ 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();
+ 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;
+ if (++uh->uh_errcnt % ubawedgecnt == 0) {
+ if (uh->uh_errcnt > ubacrazy)
+ panic("uba crazy");
+ printf("ERROR LIMIT ");
+ ubareset(uban);
+ uvec = 0;
+ return;
+ }
+ 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);