1*23352Smckusick /* 2*23352Smckusick * Copyright (c) 1982 Regents of the University of California. 3*23352Smckusick * All rights reserved. The Berkeley software License Agreement 4*23352Smckusick * specifies the terms and conditions for redistribution. 5*23352Smckusick * 6*23352Smckusick * @(#)uba.c 6.5 (Berkeley) 06/08/85 7*23352Smckusick */ 840Sbill 99780Ssam #include "../machine/pte.h" 109780Ssam 1117081Sbloom #include "param.h" 1217081Sbloom #include "systm.h" 1317081Sbloom #include "map.h" 1417081Sbloom #include "buf.h" 1517081Sbloom #include "vm.h" 1617081Sbloom #include "dir.h" 1717081Sbloom #include "user.h" 1817081Sbloom #include "proc.h" 1917081Sbloom #include "conf.h" 2017081Sbloom #include "dk.h" 2117081Sbloom #include "kernel.h" 2240Sbill 238481Sroot #include "../vax/cpu.h" 248481Sroot #include "../vax/mtpr.h" 258481Sroot #include "../vax/nexus.h" 2617081Sbloom #include "ubareg.h" 2717081Sbloom #include "ubavar.h" 288481Sroot 292929Swnj #if VAX780 302929Swnj char ubasr_bits[] = UBASR_BITS; 312929Swnj #endif 322929Swnj 3340Sbill /* 342570Swnj * Do transfer on device argument. The controller 352570Swnj * and uba involved are implied by the device. 362570Swnj * We queue for resource wait in the uba code if necessary. 372570Swnj * We return 1 if the transfer was started, 0 if it was not. 382570Swnj * If you call this routine with the head of the queue for a 392570Swnj * UBA, it will automatically remove the device from the UBA 402570Swnj * queue before it returns. If some other device is given 412570Swnj * as argument, it will be added to the request queue if the 422570Swnj * request cannot be started immediately. This means that 432570Swnj * passing a device which is on the queue but not at the head 442570Swnj * of the request queue is likely to be a disaster. 452570Swnj */ 462570Swnj ubago(ui) 472958Swnj register struct uba_device *ui; 482570Swnj { 492958Swnj register struct uba_ctlr *um = ui->ui_mi; 502570Swnj register struct uba_hd *uh; 512570Swnj register int s, unit; 522570Swnj 532570Swnj uh = &uba_hd[um->um_ubanum]; 542570Swnj s = spl6(); 552628Swnj if (um->um_driver->ud_xclu && uh->uh_users > 0 || uh->uh_xclu) 562616Swnj goto rwait; 572570Swnj um->um_ubinfo = ubasetup(um->um_ubanum, um->um_tab.b_actf->b_actf, 582570Swnj UBA_NEEDBDP|UBA_CANTWAIT); 592616Swnj if (um->um_ubinfo == 0) 602616Swnj goto rwait; 612616Swnj uh->uh_users++; 622628Swnj if (um->um_driver->ud_xclu) 632616Swnj uh->uh_xclu = 1; 642570Swnj splx(s); 652570Swnj if (ui->ui_dk >= 0) { 662570Swnj unit = ui->ui_dk; 672570Swnj dk_busy |= 1<<unit; 686348Swnj dk_xfer[unit]++; 696348Swnj dk_wds[unit] += um->um_tab.b_actf->b_actf->b_bcount>>6; 702570Swnj } 712570Swnj if (uh->uh_actf == ui) 722570Swnj uh->uh_actf = ui->ui_forw; 732570Swnj (*um->um_driver->ud_dgo)(um); 742570Swnj return (1); 752616Swnj rwait: 762616Swnj if (uh->uh_actf != ui) { 772616Swnj ui->ui_forw = NULL; 782616Swnj if (uh->uh_actf == NULL) 792616Swnj uh->uh_actf = ui; 802616Swnj else 812616Swnj uh->uh_actl->ui_forw = ui; 822616Swnj uh->uh_actl = ui; 832616Swnj } 842616Swnj splx(s); 852616Swnj return (0); 862570Swnj } 872570Swnj 882616Swnj ubadone(um) 892958Swnj register struct uba_ctlr *um; 902616Swnj { 912616Swnj register struct uba_hd *uh = &uba_hd[um->um_ubanum]; 922616Swnj 932628Swnj if (um->um_driver->ud_xclu) 942616Swnj uh->uh_xclu = 0; 952616Swnj uh->uh_users--; 962616Swnj ubarelse(um->um_ubanum, &um->um_ubinfo); 972616Swnj } 982616Swnj 992570Swnj /* 1002395Swnj * Allocate and setup UBA map registers, and bdp's 1012395Swnj * Flags says whether bdp is needed, whether the caller can't 1022395Swnj * wait (e.g. if the caller is at interrupt level). 10340Sbill * 1042570Swnj * Return value: 10540Sbill * Bits 0-8 Byte offset 10640Sbill * Bits 9-17 Start map reg. no. 10740Sbill * Bits 18-27 No. mapping reg's 10840Sbill * Bits 28-31 BDP no. 10940Sbill */ 1102395Swnj ubasetup(uban, bp, flags) 1112395Swnj struct buf *bp; 11240Sbill { 1132395Swnj register struct uba_hd *uh = &uba_hd[uban]; 11418417Smckusick int pfnum, temp; 11540Sbill int npf, reg, bdp; 11640Sbill unsigned v; 11740Sbill register struct pte *pte, *io; 11840Sbill struct proc *rp; 11940Sbill int a, o, ubinfo; 12040Sbill 1216948Ssam #if VAX730 1226948Ssam if (cpu == VAX_730) 1233332Swnj flags &= ~UBA_NEEDBDP; 1243332Swnj #endif 12540Sbill v = btop(bp->b_un.b_addr); 12640Sbill o = (int)bp->b_un.b_addr & PGOFSET; 12740Sbill npf = btoc(bp->b_bcount + o) + 1; 12840Sbill a = spl6(); 1298811Sroot while ((reg = rmalloc(uh->uh_map, (long)npf)) == 0) { 1303913Swnj if (flags & UBA_CANTWAIT) { 1313913Swnj splx(a); 1322395Swnj return (0); 1333913Swnj } 1342395Swnj uh->uh_mrwant++; 1359353Ssam sleep((caddr_t)&uh->uh_mrwant, PSWP); 13640Sbill } 13717731Skarels if ((flags & UBA_NEED16) && reg + npf > 128) { 13817731Skarels /* 13917731Skarels * Could hang around and try again (if we can ever succeed). 14017731Skarels * Won't help any current device... 14117731Skarels */ 14217731Skarels rmfree(uh->uh_map, (long)npf, (long)reg); 14317731Skarels splx(a); 14417731Skarels return (0); 14517731Skarels } 14640Sbill bdp = 0; 1472395Swnj if (flags & UBA_NEEDBDP) { 1482395Swnj while ((bdp = ffs(uh->uh_bdpfree)) == 0) { 1492395Swnj if (flags & UBA_CANTWAIT) { 1508811Sroot rmfree(uh->uh_map, (long)npf, (long)reg); 1513913Swnj splx(a); 1522395Swnj return (0); 1532395Swnj } 1542395Swnj uh->uh_bdpwant++; 1559353Ssam sleep((caddr_t)&uh->uh_bdpwant, PSWP); 15640Sbill } 1572463Swnj uh->uh_bdpfree &= ~(1 << (bdp-1)); 1584758Swnj } else if (flags & UBA_HAVEBDP) 1594758Swnj bdp = (flags >> 28) & 0xf; 16040Sbill splx(a); 1612463Swnj reg--; 16240Sbill ubinfo = (bdp << 28) | (npf << 18) | (reg << 9) | o; 1632958Swnj temp = (bdp << 21) | UBAMR_MRV; 16440Sbill if (bdp && (o & 01)) 1652958Swnj temp |= UBAMR_BO; 1666382Swnj rp = bp->b_flags&B_DIRTY ? &proc[2] : bp->b_proc; 1676382Swnj if ((bp->b_flags & B_PHYS) == 0) 168728Sbill pte = &Sysmap[btop(((int)bp->b_un.b_addr)&0x7fffffff)]; 1696382Swnj else if (bp->b_flags & B_UAREA) 1706382Swnj pte = &rp->p_addr[v]; 1716382Swnj else if (bp->b_flags & B_PAGET) 1726382Swnj pte = &Usrptmap[btokmx((struct pte *)bp->b_un.b_addr)]; 1736382Swnj else 1746382Swnj pte = vtopte(rp, v); 1756382Swnj io = &uh->uh_uba->uba_map[reg]; 1766382Swnj while (--npf != 0) { 17718417Smckusick pfnum = pte->pg_pfnum; 17818417Smckusick if (pfnum == 0) 1796382Swnj panic("uba zero uentry"); 18018417Smckusick pte++; 18118417Smckusick *(int *)io++ = pfnum | temp; 18240Sbill } 18340Sbill *(int *)io++ = 0; 18440Sbill return (ubinfo); 18540Sbill } 18640Sbill 18740Sbill /* 1882570Swnj * Non buffer setup interface... set up a buffer and call ubasetup. 18940Sbill */ 1902395Swnj uballoc(uban, addr, bcnt, flags) 1913107Swnj int uban; 19240Sbill caddr_t addr; 1933107Swnj int bcnt, flags; 19440Sbill { 195883Sbill struct buf ubabuf; 19640Sbill 19740Sbill ubabuf.b_un.b_addr = addr; 19840Sbill ubabuf.b_flags = B_BUSY; 19940Sbill ubabuf.b_bcount = bcnt; 200883Sbill /* that's all the fields ubasetup() needs */ 2012395Swnj return (ubasetup(uban, &ubabuf, flags)); 20240Sbill } 20340Sbill 2042053Swnj /* 2052570Swnj * Release resources on uba uban, and then unblock resource waiters. 2062570Swnj * The map register parameter is by value since we need to block 2072570Swnj * against uba resets on 11/780's. 2082053Swnj */ 2092395Swnj ubarelse(uban, amr) 2102053Swnj int *amr; 21140Sbill { 2122395Swnj register struct uba_hd *uh = &uba_hd[uban]; 2132570Swnj register int bdp, reg, npf, s; 2142053Swnj int mr; 21540Sbill 2162570Swnj /* 2172570Swnj * Carefully see if we should release the space, since 2182570Swnj * it may be released asynchronously at uba reset time. 2192570Swnj */ 2202570Swnj s = spl6(); 2212053Swnj mr = *amr; 2222053Swnj if (mr == 0) { 2232570Swnj /* 2242570Swnj * A ubareset() occurred before we got around 2252570Swnj * to releasing the space... no need to bother. 2262570Swnj */ 2272570Swnj splx(s); 2282053Swnj return; 2292053Swnj } 2302067Swnj *amr = 0; 23140Sbill bdp = (mr >> 28) & 0x0f; 23240Sbill if (bdp) { 2332729Swnj switch (cpu) { 2342423Skre #if VAX780 2352423Skre case VAX_780: 2362958Swnj uh->uh_uba->uba_dpr[bdp] |= UBADPR_BNE; 2372423Skre break; 2382423Skre #endif 2392423Skre #if VAX750 2402423Skre case VAX_750: 2412958Swnj uh->uh_uba->uba_dpr[bdp] |= 2422958Swnj UBADPR_PURGE|UBADPR_NXM|UBADPR_UCE; 2432423Skre break; 2442423Skre #endif 2452423Skre } 2462570Swnj uh->uh_bdpfree |= 1 << (bdp-1); /* atomic */ 2472395Swnj if (uh->uh_bdpwant) { 2482395Swnj uh->uh_bdpwant = 0; 2499353Ssam wakeup((caddr_t)&uh->uh_bdpwant); 25040Sbill } 25140Sbill } 2522570Swnj /* 2532570Swnj * Put back the registers in the resource map. 25417731Skarels * The map code must not be reentered, 25517731Skarels * nor can the registers be freed twice. 25617731Skarels * Unblock interrupts once this is done. 2572570Swnj */ 25840Sbill npf = (mr >> 18) & 0x3ff; 25940Sbill reg = ((mr >> 9) & 0x1ff) + 1; 2608811Sroot rmfree(uh->uh_map, (long)npf, (long)reg); 2612570Swnj splx(s); 2622570Swnj 2632570Swnj /* 2642570Swnj * Wakeup sleepers for map registers, 2652570Swnj * and also, if there are processes blocked in dgo(), 2662570Swnj * give them a chance at the UNIBUS. 2672570Swnj */ 2682395Swnj if (uh->uh_mrwant) { 2692395Swnj uh->uh_mrwant = 0; 2709353Ssam wakeup((caddr_t)&uh->uh_mrwant); 27140Sbill } 2722570Swnj while (uh->uh_actf && ubago(uh->uh_actf)) 2732570Swnj ; 27440Sbill } 27540Sbill 2762729Swnj ubapurge(um) 2772958Swnj register struct uba_ctlr *um; 2782729Swnj { 2792729Swnj register struct uba_hd *uh = um->um_hd; 2802729Swnj register int bdp = (um->um_ubinfo >> 28) & 0x0f; 2812729Swnj 2822729Swnj switch (cpu) { 2832729Swnj #if VAX780 2842729Swnj case VAX_780: 2852958Swnj uh->uh_uba->uba_dpr[bdp] |= UBADPR_BNE; 2862729Swnj break; 2872729Swnj #endif 2882729Swnj #if VAX750 2892729Swnj case VAX_750: 2902958Swnj uh->uh_uba->uba_dpr[bdp] |= UBADPR_PURGE|UBADPR_NXM|UBADPR_UCE; 2912729Swnj break; 2922729Swnj #endif 2932729Swnj } 2942729Swnj } 2952729Swnj 2966863Swnj ubainitmaps(uhp) 2976863Swnj register struct uba_hd *uhp; 2986863Swnj { 2996863Swnj 3008811Sroot rminit(uhp->uh_map, (long)NUBMREG, (long)1, "uba", UAMSIZ); 3016863Swnj switch (cpu) { 3026863Swnj #if VAX780 3036863Swnj case VAX_780: 3046863Swnj uhp->uh_bdpfree = (1<<NBDP780) - 1; 3056863Swnj break; 3066863Swnj #endif 3076863Swnj #if VAX750 3086863Swnj case VAX_750: 3096863Swnj uhp->uh_bdpfree = (1<<NBDP750) - 1; 3106863Swnj break; 3116863Swnj #endif 3126948Ssam #if VAX730 3136948Ssam case VAX_730: 3146863Swnj break; 3156863Swnj #endif 3166863Swnj } 3176863Swnj } 3186863Swnj 3192570Swnj /* 3202570Swnj * Generate a reset on uba number uban. Then 3212570Swnj * call each device in the character device table, 3222570Swnj * giving it a chance to clean up so as to be able to continue. 3232570Swnj */ 3242395Swnj ubareset(uban) 3252570Swnj int uban; 326284Sbill { 327284Sbill register struct cdevsw *cdp; 3282646Swnj register struct uba_hd *uh = &uba_hd[uban]; 3291781Sbill int s; 330284Sbill 331302Sbill s = spl6(); 3322646Swnj uh->uh_users = 0; 3332646Swnj uh->uh_zvcnt = 0; 3342646Swnj uh->uh_xclu = 0; 3352646Swnj uh->uh_actf = uh->uh_actl = 0; 3362646Swnj uh->uh_bdpwant = 0; 3372646Swnj uh->uh_mrwant = 0; 3386863Swnj ubainitmaps(uh); 3392646Swnj wakeup((caddr_t)&uh->uh_bdpwant); 3402646Swnj wakeup((caddr_t)&uh->uh_mrwant); 3412958Swnj printf("uba%d: reset", uban); 3422958Swnj ubainit(uh->uh_uba); 34317731Skarels ubameminit(uban); 34411722Ssam for (cdp = cdevsw; cdp < cdevsw + nchrdev; cdp++) 3452395Swnj (*cdp->d_reset)(uban); 3465221Swnj #ifdef INET 3475221Swnj ifubareset(uban); 3485221Swnj #endif 349284Sbill printf("\n"); 350302Sbill splx(s); 351284Sbill } 3522395Swnj 3532570Swnj /* 3542570Swnj * Init a uba. This is called with a pointer 3552570Swnj * rather than a virtual address since it is called 3562570Swnj * by code which runs with memory mapping disabled. 3572570Swnj * In these cases we really don't need the interrupts 3582570Swnj * enabled, but since we run with ipl high, we don't care 3592570Swnj * if they are, they will never happen anyways. 3602570Swnj */ 3612423Skre ubainit(uba) 3622423Skre register struct uba_regs *uba; 3632395Swnj { 3642395Swnj 3652958Swnj switch (cpu) { 3662958Swnj #if VAX780 3673248Swnj case VAX_780: 3682958Swnj uba->uba_cr = UBACR_ADINIT; 3692958Swnj uba->uba_cr = UBACR_IFS|UBACR_BRIE|UBACR_USEFIE|UBACR_SUEFIE; 3702958Swnj while ((uba->uba_cnfgr & UBACNFGR_UBIC) == 0) 3712958Swnj ; 3722958Swnj break; 3732958Swnj #endif 3742958Swnj #if VAX750 3753248Swnj case VAX_750: 3763352Swnj #endif 3776948Ssam #if VAX730 3786948Ssam case VAX_730: 3793352Swnj #endif 3806948Ssam #if defined(VAX750) || defined(VAX730) 3813352Swnj mtpr(IUR, 0); 3822958Swnj /* give devices time to recover from power fail */ 3833332Swnj /* THIS IS PROBABLY UNNECESSARY */ 3843352Swnj DELAY(500000); 3853332Swnj /* END PROBABLY UNNECESSARY */ 3862958Swnj break; 3872958Swnj #endif 3882958Swnj } 3892395Swnj } 3902395Swnj 3918780Sroot #ifdef VAX780 3924024Swnj int ubawedgecnt = 10; 3934024Swnj int ubacrazy = 500; 39417731Skarels int zvcnt_max = 5000; /* in 8 sec */ 39517731Skarels int zvcnt_total; 39617731Skarels long zvcnt_time; 3972570Swnj /* 3982570Swnj * This routine is called by the locore code to 3992570Swnj * process a UBA error on an 11/780. The arguments are passed 4002570Swnj * on the stack, and value-result (through some trickery). 4012570Swnj * In particular, the uvec argument is used for further 4022570Swnj * uba processing so the result aspect of it is very important. 4032570Swnj * It must not be declared register. 4042570Swnj */ 4052423Skre /*ARGSUSED*/ 40617731Skarels ubaerror(uban, uh, ipl, uvec, uba) 4072395Swnj register int uban; 4082395Swnj register struct uba_hd *uh; 40917731Skarels int ipl, uvec; 4102395Swnj register struct uba_regs *uba; 4112395Swnj { 4122395Swnj register sr, s; 4132395Swnj 4142395Swnj if (uvec == 0) { 41517731Skarels long dt = time.tv_sec - zvcnt_time; 41617731Skarels zvcnt_total++; 41717731Skarels if (dt > 8) { 41817731Skarels zvcnt_time = time.tv_sec; 41917731Skarels uh->uh_zvcnt = 0; 42017731Skarels } 42117731Skarels if (++uh->uh_zvcnt > zvcnt_max) { 42217731Skarels printf("uba%d: too many zero vectors (%d in <%d sec)\n", 42317731Skarels uban, uh->uh_zvcnt, dt + 1); 42417731Skarels printf("\tIPL 0x%x\n\tcnfgr: %b Adapter Code: 0x%x\n", 42517731Skarels ipl, uba->uba_cnfgr&(~0xff), UBACNFGR_BITS, 42617731Skarels uba->uba_cnfgr&0xff); 42717731Skarels printf("\tsr: %b\n\tdcr: %x (MIC %sOK)\n", 42817731Skarels uba->uba_sr, ubasr_bits, uba->uba_dcr, 42917731Skarels (uba->uba_dcr&0x8000000)?"":"NOT "); 4302395Swnj ubareset(uban); 4312395Swnj } 4322395Swnj return; 4332395Swnj } 4342395Swnj if (uba->uba_cnfgr & NEX_CFGFLT) { 4352929Swnj printf("uba%d: sbi fault sr=%b cnfgr=%b\n", 4362929Swnj uban, uba->uba_sr, ubasr_bits, 4373248Swnj uba->uba_cnfgr, NEXFLT_BITS); 4382395Swnj ubareset(uban); 4392395Swnj uvec = 0; 4402395Swnj return; 4412395Swnj } 4422395Swnj sr = uba->uba_sr; 4432395Swnj s = spl7(); 4443473Swnj printf("uba%d: uba error sr=%b fmer=%x fubar=%o\n", 4453473Swnj uban, uba->uba_sr, ubasr_bits, uba->uba_fmer, 4*uba->uba_fubar); 4462395Swnj splx(s); 4472395Swnj uba->uba_sr = sr; 4482958Swnj uvec &= UBABRRVR_DIV; 4494024Swnj if (++uh->uh_errcnt % ubawedgecnt == 0) { 4504024Swnj if (uh->uh_errcnt > ubacrazy) 4514024Swnj panic("uba crazy"); 4524024Swnj printf("ERROR LIMIT "); 4534024Swnj ubareset(uban); 4544024Swnj uvec = 0; 4554024Swnj return; 4564024Swnj } 4572395Swnj return; 4582395Swnj } 4592395Swnj #endif 4603745Sroot 4613745Sroot /* 46217731Skarels * Look for devices with unibus memory, allow them to configure, then disable 46317731Skarels * map registers as necessary. Called during autoconfiguration and ubareset. 46417731Skarels * The device ubamem routine returns 0 on success, 1 on success if it is fully 46517731Skarels * configured (has no csr or interrupt, so doesn't need to be probed), 46617731Skarels * and -1 on failure. 46717731Skarels */ 46817731Skarels ubameminit(uban) 46917731Skarels { 47017731Skarels register struct uba_device *ui; 47117731Skarels register struct uba_hd *uh = &uba_hd[uban]; 47217731Skarels caddr_t umembase = umem[uban] + 0x3e000, addr; 47317731Skarels #define ubaoff(off) ((int)(off) & 0x1fff) 47417731Skarels 47517731Skarels uh->uh_lastmem = 0; 47617731Skarels for (ui = ubdinit; ui->ui_driver; ui++) { 47717731Skarels if (ui->ui_ubanum != uban && ui->ui_ubanum != '?') 47817731Skarels continue; 47917731Skarels if (ui->ui_driver->ud_ubamem) { 48017731Skarels /* 48117731Skarels * During autoconfiguration, need to fudge ui_addr. 48217731Skarels */ 48317731Skarels addr = ui->ui_addr; 48417731Skarels ui->ui_addr = umembase + ubaoff(addr); 48517731Skarels switch ((*ui->ui_driver->ud_ubamem)(ui, uban)) { 48617731Skarels case 1: 48717731Skarels ui->ui_alive = 1; 48817731Skarels /* FALLTHROUGH */ 48917731Skarels case 0: 49017731Skarels ui->ui_ubanum = uban; 49117731Skarels break; 49217731Skarels } 49317731Skarels ui->ui_addr = addr; 49417731Skarels } 49517731Skarels } 49617731Skarels #if VAX780 49717731Skarels /* 49817731Skarels * On a 780, throw away any map registers disabled by rounding 49917731Skarels * the map disable in the configuration register 50017731Skarels * up to the next 8K boundary, or below the last unibus memory. 50117731Skarels */ 50217731Skarels if (cpu == VAX_780) { 50317731Skarels register i; 50417731Skarels 50517731Skarels i = btop(((uh->uh_lastmem + 8191) / 8192) * 8192); 50617731Skarels while (i) 50717731Skarels (void) rmget(uh->uh_map, 1, i--); 50817731Skarels } 50917731Skarels #endif 51017731Skarels } 51117731Skarels 51217731Skarels /* 51314790Ssam * Allocate UNIBUS memory. Allocates and initializes 51414790Ssam * sufficient mapping registers for access. On a 780, 51514790Ssam * the configuration register is setup to disable UBA 51614790Ssam * response on DMA transfers to addresses controlled 51714790Ssam * by the disabled mapping registers. 51817731Skarels * On a 780, should only be called from ubameminit, or in ascending order 51917731Skarels * from 0 with 8K-sized and -aligned addresses; freeing memory that isn't 52017731Skarels * the last unibus memory would free unusable map registers. 52117731Skarels * Doalloc is 1 to allocate, 0 to deallocate. 5226518Sfeldman */ 52314790Ssam ubamem(uban, addr, npg, doalloc) 52414790Ssam int uban, addr, npg, doalloc; 5256518Sfeldman { 5266518Sfeldman register struct uba_hd *uh = &uba_hd[uban]; 52714790Ssam register int a; 52817731Skarels int s; 5296518Sfeldman 53017731Skarels a = (addr >> 9) + 1; 53117731Skarels s = spl6(); 53217731Skarels if (doalloc) 53317731Skarels a = rmget(uh->uh_map, npg, a); 53417731Skarels else 53517731Skarels rmfree(uh->uh_map, (long)npg, (long)a); 53617731Skarels splx(s); 5376518Sfeldman if (a) { 53814790Ssam register int i, *m; 53914790Ssam 54014790Ssam m = (int *)&uh->uh_uba->uba_map[a - 1]; 54114790Ssam for (i = 0; i < npg; i++) 5426518Sfeldman *m++ = 0; /* All off, especially 'valid' */ 54317731Skarels i = addr + npg * 512; 54417731Skarels if (doalloc && i > uh->uh_lastmem) 54517731Skarels uh->uh_lastmem = i; 54617731Skarels else if (doalloc == 0 && i == uh->uh_lastmem) 54717731Skarels uh->uh_lastmem = addr; 5487473Sfeldman #if VAX780 54914790Ssam /* 55014790Ssam * On a 780, set up the map register disable 55114790Ssam * field in the configuration register. Beware 55217731Skarels * of callers that request memory ``out of order'' 55317731Skarels * or in sections other than 8K multiples. 55417731Skarels * Ubameminit handles such requests properly, however. 55514790Ssam */ 55614790Ssam if (cpu == VAX_780) { 55717731Skarels i = uh->uh_uba->uba_cr &~ 0x7c000000; 55817731Skarels i |= ((uh->uh_lastmem + 8191) / 8192) << 26; 55917731Skarels uh->uh_uba->uba_cr = i; 5607473Sfeldman } 5617473Sfeldman #endif 5626518Sfeldman } 56314790Ssam return (a); 5646518Sfeldman } 5657304Ssam 5669875Ssam #include "ik.h" 5679875Ssam #if NIK > 0 5687304Ssam /* 5697304Ssam * Map a virtual address into users address space. Actually all we 5707304Ssam * do is turn on the user mode write protection bits for the particular 5717304Ssam * page of memory involved. 5727304Ssam */ 5737304Ssam maptouser(vaddress) 5747304Ssam caddr_t vaddress; 5757304Ssam { 5767304Ssam 5777304Ssam Sysmap[(((unsigned)(vaddress))-0x80000000) >> 9].pg_prot = (PG_UW>>27); 5787304Ssam } 5797304Ssam 5807304Ssam unmaptouser(vaddress) 5817304Ssam caddr_t vaddress; 5827304Ssam { 5837304Ssam 5847304Ssam Sysmap[(((unsigned)(vaddress))-0x80000000) >> 9].pg_prot = (PG_KW>>27); 5857304Ssam } 5869174Ssam #endif 587