1 /* 2 * Copyright (c) 1982,1986 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)autoconf.c 7.10 (Berkeley) 10/28/87 7 */ 8 9 /* 10 * Setup the system to run on the current machine. 11 * 12 * Configure() is called at boot time and initializes the uba and mba 13 * device tables and the memory controller monitoring. Available 14 * devices are determined (from possibilities mentioned in ioconf.c), 15 * and the drivers are initialized. 16 */ 17 18 #include "mba.h" 19 #include "uba.h" 20 21 #include "param.h" 22 #include "systm.h" 23 #include "map.h" 24 #include "buf.h" 25 #include "dkstat.h" 26 #include "vm.h" 27 #include "malloc.h" 28 #include "conf.h" 29 #include "dmap.h" 30 #include "reboot.h" 31 32 #include "pte.h" 33 #include "cpu.h" 34 #include "mem.h" 35 #include "mtpr.h" 36 #include "nexus.h" 37 #include "scb.h" 38 #include "ioa.h" 39 #include "../vaxmba/mbareg.h" 40 #include "../vaxmba/mbavar.h" 41 #include "../vaxuba/ubareg.h" 42 #include "../vaxuba/ubavar.h" 43 44 /* 45 * The following several variables are related to 46 * the configuration process, and are used in initializing 47 * the machine. 48 */ 49 int cold; /* if 1, still working on cold-start */ 50 int dkn; /* number of iostat dk numbers assigned so far */ 51 int cpuspeed = 1; /* relative cpu speed */ 52 53 /* 54 * Addresses of the (locore) routines which bootstrap us from 55 * hardware traps to C code. Filled into the system control block 56 * as necessary. 57 */ 58 #if NMBA > 0 59 int (*mbaintv[4])() = { Xmba0int, Xmba1int, Xmba2int, Xmba3int }; 60 #if NMBA > 4 61 Need to expand the table for more than 4 massbus adaptors 62 #endif 63 #endif 64 #if defined(VAX780) || defined(VAX8600) 65 int (*ubaintv[])() = 66 { 67 Xua0int, Xua1int, Xua2int, Xua3int, 68 #if NUBA > 4 69 Xua4int, Xua5int, Xua6int, Xua7int, 70 #endif 71 #if NUBA > 8 72 Need to expand the table for more than 8 unibus adaptors 73 #endif 74 }; 75 #endif 76 77 /* 78 * This allocates the space for the per-uba information, 79 * such as buffered data path usage. 80 */ 81 struct uba_hd uba_hd[NUBA]; 82 83 /* 84 * Determine mass storage and memory configuration for a machine. 85 * Get cpu type, and then switch out to machine specific procedures 86 * which will probe adaptors to see what is out there. 87 */ 88 configure() 89 { 90 union cpusid cpusid; 91 register struct percpu *ocp; 92 register int *ip; 93 extern char Sysbase[]; 94 95 cpusid.cpusid = mfpr(SID); 96 for (ocp = percpu; ocp->pc_cputype; ocp++) 97 if (ocp->pc_cputype == cpusid.cpuany.cp_type) { 98 cpuspeed = ocp->pc_cpuspeed; 99 probeio(ocp); 100 /* 101 * Write protect the scb and UNIBUS interrupt vectors. 102 * It is strange that this code is here, but this is 103 * as soon as we are done mucking with it, and the 104 * write-enable was done in assembly language 105 * to which we will never return. 106 */ 107 ip = (int *)Sysmap + 1; *ip &= ~PG_PROT; *ip |= PG_KR; 108 ip++; *ip &= ~PG_PROT; *ip |= PG_KR; 109 #if NUBA > 1 110 ip++; *ip &= ~PG_PROT; *ip |= PG_KR; 111 #endif 112 mtpr(TBIS, Sysbase); 113 #if GENERIC 114 if ((boothowto & RB_ASKNAME) == 0) 115 setroot(); 116 setconf(); 117 #else 118 setroot(); 119 #endif 120 /* 121 * Configure swap area and related system 122 * parameter based on device(s) used. 123 */ 124 swapconf(); 125 cold = 0; 126 memenable(); 127 return; 128 } 129 printf("cpu type %d not configured\n", cpusid.cpuany.cp_type); 130 asm("halt"); 131 } 132 133 #if VAX8600 || VAX780 || VAX750 || VAX730 134 int nexnum; /* current nexus number */ 135 int nsbi; /* current sbi number */ 136 #endif 137 138 /* 139 * Probe the main IO bus(es). 140 * The percpu structure gives us a handle on the addresses and/or types. 141 */ 142 probeio(pcpu) 143 register struct percpu *pcpu; 144 { 145 register struct iobus *iob; 146 int ioanum; 147 148 ioanum = 0; 149 for (iob = pcpu->pc_io; ioanum < pcpu->pc_nioa; ioanum++, iob++) { 150 151 switch (iob->io_type) { 152 153 #if VAX630 154 case IO_QBUS: 155 probeqbus((struct qbus *)iob->io_details); 156 break; 157 #endif 158 159 #if VAX780 || VAX750 || VAX730 160 case IO_SBI780: 161 case IO_CMI750: 162 case IO_XXX730: 163 probenexi((struct nexusconnect *)iob->io_details); 164 break; 165 #endif 166 167 #if VAX8600 168 case IO_ABUS: 169 probe_Abus(ioanum, iob); 170 break; 171 #endif 172 default: 173 if (iob->io_addr) { 174 printf( 175 "IO adaptor %d, type %d, at address 0x%x is unsupported\n", 176 ioanum, iob->io_type, iob->io_addr); 177 } else 178 printf("IO adaptor %d, type %d, is unsupported\n", 179 ioanum, iob->io_type); 180 break; 181 } 182 } 183 } 184 185 #if VAX8600 186 probe_Abus(ioanum, iob) 187 register struct iobus *iob; 188 { 189 register struct ioa *ioap; 190 union ioacsr ioacsr; 191 int type; 192 struct sbia_regs *sbiaregs; 193 194 ioap = &ioa[ioanum]; 195 ioaccess(iob->io_addr, Ioamap[ioanum], iob->io_size); 196 if (badaddr((caddr_t)ioap, 4)) 197 return; 198 ioacsr.ioa_csr = ioap->ioacsr.ioa_csr; 199 type = ioacsr.ioa_type & IOA_TYPMSK; 200 201 switch (type) { 202 203 case IOA_SBIA: 204 printf("SBIA%d at IO adaptor %d address 0x%x\n", 205 nsbi, ioanum, iob->io_addr); 206 probenexi((struct nexusconnect *)iob->io_details); 207 nsbi++; 208 sbiaregs = (struct sbia_regs *)ioap; 209 sbiaregs->sbi_errsum = -1; 210 sbiaregs->sbi_error = 0x1000; 211 sbiaregs->sbi_fltsts = 0xc0000; 212 break; 213 214 default: 215 printf("IOA%d at address 0x%x is unsupported (type = 0x%x)\n", 216 ioanum, iob->io_addr, ioacsr.ioa_type); 217 break; 218 } 219 } 220 #endif 221 222 #if VAX8600 || VAX780 || VAX750 || VAX730 223 /* 224 * Probe nexus space, finding the interconnects 225 * and setting up and probing mba's and uba's for devices. 226 */ 227 /*ARGSUSED*/ 228 probenexi(pnc) 229 register struct nexusconnect *pnc; 230 { 231 register struct nexus *nxv; 232 struct nexus *nxp = pnc->psb_nexbase; 233 union nexcsr nexcsr; 234 int i; 235 236 nexnum = 0, nxv = &nexus[nsbi * NNEXSBI]; 237 for (; nexnum < pnc->psb_nnexus; nexnum++, nxp++, nxv++) { 238 ioaccess((caddr_t)nxp, Nexmap[nsbi * NNEXSBI + nexnum], 239 sizeof(struct nexus)); 240 if (badaddr((caddr_t)nxv, 4)) 241 continue; 242 if (pnc->psb_nextype && pnc->psb_nextype[nexnum] != NEX_ANY) 243 nexcsr.nex_csr = pnc->psb_nextype[nexnum]; 244 else 245 nexcsr = nxv->nexcsr; 246 if (nexcsr.nex_csr&NEX_APD) 247 continue; 248 switch (nexcsr.nex_type) { 249 250 case NEX_MBA: 251 printf("mba%d at tr%d\n", nummba, nexnum); 252 if (nummba >= NMBA) { 253 printf("%d mba's", nummba++); 254 goto unconfig; 255 } 256 #if NMBA > 0 257 mbafind(nxv, nxp); 258 nummba++; 259 #endif 260 break; 261 262 case NEX_UBA0: 263 case NEX_UBA1: 264 case NEX_UBA2: 265 case NEX_UBA3: 266 printf("uba%d at tr%d\n", numuba, nexnum); 267 #if VAX750 268 if (numuba >= 2 && cpu == VAX_750) { 269 printf("More than 2 UBA's"); 270 goto unsupp; 271 } 272 #endif 273 if (numuba >= NUBA) { 274 printf("%d uba's", ++numuba); 275 goto unconfig; 276 } 277 #if defined(VAX780) || defined(VAX8600) 278 if ((cpu == VAX_780) || (cpu == VAX_8600)) 279 setscbnex(ubaintv[numuba]); 280 #endif 281 i = nexcsr.nex_type - NEX_UBA0; 282 probeuba((struct uba_regs *)nxv, (struct uba_regs *)nxp, 283 pnc->psb_umaddr[i]); 284 break; 285 286 case NEX_DR32: 287 /* there can be more than one... are there other codes??? */ 288 printf("dr32"); 289 goto unsupp; 290 291 case NEX_MEM4: 292 case NEX_MEM4I: 293 case NEX_MEM16: 294 case NEX_MEM16I: 295 printf("mcr%d at tr%d\n", nmcr, nexnum); 296 if (nmcr >= 4) { 297 printf("5 mcr's"); 298 goto unsupp; 299 } 300 switch (cpu) { 301 case VAX_780: 302 mcrtype[nmcr] = M780C; 303 break; 304 case VAX_750: 305 mcrtype[nmcr] = M750; 306 break; 307 case VAX_730: 308 mcrtype[nmcr] = M730; 309 break; 310 } 311 mcraddr[nmcr++] = (struct mcr *)nxv; 312 break; 313 314 case NEX_MEM64I: 315 case NEX_MEM64L: 316 case NEX_MEM64LI: 317 case NEX_MEM256I: 318 case NEX_MEM256L: 319 case NEX_MEM256LI: 320 printf("mcr%d (el) at tr%d\n", nmcr, nexnum); 321 if (nmcr >= 4) { 322 printf("5 mcr's"); 323 goto unsupp; 324 } 325 if (cpu == VAX_780) 326 mcrtype[nmcr] = M780EL; 327 mcraddr[nmcr++] = (struct mcr *)nxv; 328 if (nexcsr.nex_type != NEX_MEM64I && 329 nexcsr.nex_type != NEX_MEM256I) 330 break; 331 /* fall into ... */ 332 333 case NEX_MEM64U: 334 case NEX_MEM64UI: 335 case NEX_MEM256U: 336 case NEX_MEM256UI: 337 printf("mcr%d (eu) at tr%d\n", nmcr, nexnum); 338 if (nmcr >= 4) { 339 printf("5 mcr's"); 340 goto unsupp; 341 } 342 if (cpu == VAX_780) 343 mcrtype[nmcr] = M780EU; 344 mcraddr[nmcr++] = (struct mcr *)nxv; 345 break; 346 347 case NEX_MPM0: 348 case NEX_MPM1: 349 case NEX_MPM2: 350 case NEX_MPM3: 351 printf("mpm"); 352 goto unsupp; 353 354 case NEX_CI: 355 printf("ci"); 356 goto unsupp; 357 358 default: 359 printf("nexus type %x", nexcsr.nex_type); 360 unsupp: 361 printf(" unsupported (at tr %d)\n", nexnum); 362 continue; 363 unconfig: 364 printf(" not configured\n"); 365 continue; 366 } 367 } 368 if (nummba > NMBA) 369 nummba = NMBA; 370 if (numuba > NUBA) 371 numuba = NUBA; 372 } 373 374 setscbnex(fn) 375 int (*fn)(); 376 { 377 register struct scb *scbp = &scb; 378 379 scbp = (struct scb *)((caddr_t)scbp + nsbi * 512); 380 scbp->scb_ipl14[nexnum] = scbp->scb_ipl15[nexnum] = 381 scbp->scb_ipl16[nexnum] = scbp->scb_ipl17[nexnum] = 382 scbentry(fn, SCB_ISTACK); 383 } 384 #endif 385 386 #if NMBA > 0 387 struct mba_device *mbaconfig(); 388 /* 389 * Find devices attached to a particular mba 390 * and look for each device found in the massbus 391 * initialization tables. 392 */ 393 mbafind(nxv, nxp) 394 struct nexus *nxv, *nxp; 395 { 396 register struct mba_regs *mdp; 397 register struct mba_drv *mbd; 398 register struct mba_device *mi; 399 register struct mba_slave *ms; 400 int dn, dt, sn; 401 struct mba_device fnd; 402 403 mdp = (struct mba_regs *)nxv; 404 mba_hd[nummba].mh_mba = mdp; 405 mba_hd[nummba].mh_physmba = (struct mba_regs *)nxp; 406 setscbnex(mbaintv[nummba]); 407 mdp->mba_cr = MBCR_INIT; 408 mdp->mba_cr = MBCR_IE; 409 fnd.mi_mba = mdp; 410 fnd.mi_mbanum = nummba; 411 for (mbd = mdp->mba_drv, dn = 0; mbd < &mdp->mba_drv[8]; mbd++, dn++) { 412 if ((mbd->mbd_ds&MBDS_DPR) == 0) 413 continue; 414 mdp->mba_sr |= MBSR_NED; /* si kludge */ 415 dt = mbd->mbd_dt & 0xffff; 416 if (dt == 0) 417 continue; 418 if (mdp->mba_sr&MBSR_NED) 419 continue; /* si kludge */ 420 if (dt == MBDT_MOH) 421 continue; 422 fnd.mi_drive = dn; 423 #define qeq(a, b) ( a == b || a == '?' ) 424 if ((mi = mbaconfig(&fnd, dt)) && (dt & MBDT_TAP)) 425 for (sn = 0; sn < 8; sn++) { 426 mbd->mbd_tc = sn; 427 for (ms = mbsinit; ms->ms_driver; ms++) 428 if (ms->ms_driver == mi->mi_driver && 429 ms->ms_alive == 0 && 430 qeq(ms->ms_ctlr, mi->mi_unit) && 431 qeq(ms->ms_slave, sn) && 432 (*ms->ms_driver->md_slave)(mi, ms, sn)) { 433 printf("%s%d at %s%d slave %d\n" 434 , ms->ms_driver->md_sname 435 , ms->ms_unit 436 , mi->mi_driver->md_dname 437 , mi->mi_unit 438 , sn 439 ); 440 ms->ms_alive = 1; 441 ms->ms_ctlr = mi->mi_unit; 442 ms->ms_slave = sn; 443 break; 444 } 445 } 446 } 447 } 448 449 /* 450 * Have found a massbus device; 451 * see if it is in the configuration table. 452 * If so, fill in its data. 453 */ 454 struct mba_device * 455 mbaconfig(ni, type) 456 register struct mba_device *ni; 457 register int type; 458 { 459 register struct mba_device *mi; 460 register short *tp; 461 register struct mba_hd *mh; 462 463 for (mi = mbdinit; mi->mi_driver; mi++) { 464 if (mi->mi_alive) 465 continue; 466 tp = mi->mi_driver->md_type; 467 for (mi->mi_type = 0; *tp; tp++, mi->mi_type++) 468 if (*tp == (type&MBDT_TYPE)) 469 goto found; 470 continue; 471 found: 472 #define match(fld) (ni->fld == mi->fld || mi->fld == '?') 473 if (!match(mi_drive) || !match(mi_mbanum)) 474 continue; 475 printf("%s%d at mba%d drive %d", 476 mi->mi_driver->md_dname, mi->mi_unit, 477 ni->mi_mbanum, ni->mi_drive); 478 mi->mi_alive = 1; 479 mh = &mba_hd[ni->mi_mbanum]; 480 mi->mi_hd = mh; 481 mh->mh_mbip[ni->mi_drive] = mi; 482 mh->mh_ndrive++; 483 mi->mi_mba = ni->mi_mba; 484 mi->mi_drv = &mi->mi_mba->mba_drv[ni->mi_drive]; 485 mi->mi_mbanum = ni->mi_mbanum; 486 mi->mi_drive = ni->mi_drive; 487 /* 488 * If drive has never been seen before, 489 * give it a dkn for statistics. 490 */ 491 if (mi->mi_driver->md_info[mi->mi_unit] == 0) { 492 mi->mi_driver->md_info[mi->mi_unit] = mi; 493 if (mi->mi_dk && dkn < DK_NDRIVE) 494 mi->mi_dk = dkn++; 495 else 496 mi->mi_dk = -1; 497 } 498 (*mi->mi_driver->md_attach)(mi); 499 printf("\n"); 500 return (mi); 501 } 502 return (0); 503 } 504 #endif 505 506 /* 507 * Fixctlrmask fixes the masks of the driver ctlr routines 508 * which otherwise save r10 and r11 where the interrupt and br 509 * level are passed through. 510 */ 511 fixctlrmask() 512 { 513 register struct uba_ctlr *um; 514 register struct uba_device *ui; 515 register struct uba_driver *ud; 516 #define phys(a,b) ((b)(((int)(a))&0x7fffffff)) 517 518 for (um = ubminit; ud = phys(um->um_driver, struct uba_driver *); um++) 519 *phys(ud->ud_probe, short *) &= ~0xc00; 520 for (ui = ubdinit; ud = phys(ui->ui_driver, struct uba_driver *); ui++) 521 *phys(ud->ud_probe, short *) &= ~0xc00; 522 } 523 524 #if VAX630 525 /* 526 * Configure a Q-bus. 527 */ 528 probeqbus(qb) 529 struct qbus *qb; 530 { 531 register struct uba_hd *uhp = &uba_hd[numuba]; 532 533 ioaccess(qb->qb_map, Nexmap[0], qb->qb_memsize * sizeof (struct pte)); 534 uhp->uh_type = qb->qb_type; 535 uhp->uh_uba = (struct uba_regs *)0xc0000000; /* no uba adaptor regs */ 536 uhp->uh_mr = (struct pte *)&nexus[0]; 537 /* 538 * The map registers start right at 20088000 on the 539 * ka630, so we have to subtract out the 2k offset to make the 540 * pointers work.. 541 */ 542 uhp->uh_physuba = (struct uba_regs *)(((u_long)qb->qb_map)-0x800); 543 544 uhp->uh_memsize = qb->qb_memsize; 545 ioaccess(qb->qb_maddr, UMEMmap[numuba], uhp->uh_memsize * NBPG); 546 uhp->uh_mem = umem[numuba]; 547 548 /* 549 * The I/O page is mapped to the 8K of the umem address space 550 * immediately after the memory section that is mapped. 551 */ 552 ioaccess(qb->qb_iopage, UMEMmap[numuba] + uhp->uh_memsize, 553 UBAIOPAGES * NBPG); 554 uhp->uh_iopage = umem[numuba] + (uhp->uh_memsize * NBPG); 555 556 unifind(uhp, qb->qb_iopage); 557 } 558 #endif 559 560 probeuba(vubp, pubp, pumem) 561 struct uba_regs *vubp, *pubp; 562 caddr_t pumem; 563 { 564 register struct uba_hd *uhp = &uba_hd[numuba]; 565 caddr_t vumem; 566 567 /* 568 * Save virtual and physical addresses of adaptor. 569 */ 570 switch (cpu) { 571 #ifdef DW780 572 case VAX_8600: 573 case VAX_780: 574 uhp->uh_type = DW780; 575 break; 576 #endif 577 #ifdef DW750 578 case VAX_750: 579 uhp->uh_type = DW750; 580 break; 581 #endif 582 #ifdef DW730 583 case VAX_730: 584 uhp->uh_type = DW730; 585 break; 586 #endif 587 default: 588 panic("unknown UBA type"); 589 /*NOTREACHED*/ 590 } 591 uhp->uh_uba = vubp; 592 uhp->uh_physuba = pubp; 593 uhp->uh_mr = vubp->uba_map; 594 uhp->uh_memsize = UBAPAGES; 595 596 ioaccess(pumem, UMEMmap[numuba], (UBAPAGES + UBAIOPAGES) * NBPG); 597 uhp->uh_mem = umem[numuba]; 598 uhp->uh_iopage = umem[numuba] + (uhp->uh_memsize * NBPG); 599 600 unifind(uhp, pumem + (uhp->uh_memsize * NBPG)); 601 } 602 603 /* 604 * Find devices on a UNIBUS. 605 * Uses per-driver routine to set <br,cvec> into <r11,r10>, 606 * and then fills in the tables, with help from a per-driver 607 * slave initialization routine. 608 */ 609 unifind(uhp0, pumem) 610 struct uba_hd *uhp0; 611 caddr_t pumem; 612 { 613 #ifndef lint 614 register int br, cvec; /* MUST BE r11, r10 */ 615 #else 616 /* 617 * Lint doesn't realize that these 618 * can be initialized asynchronously 619 * when devices interrupt. 620 */ 621 register int br = 0, cvec = 0; 622 #endif 623 register struct uba_device *ui; 624 register struct uba_ctlr *um; 625 register struct uba_hd *uhp = uhp0; 626 u_short *reg, *ap, addr; 627 struct uba_driver *udp; 628 int i, (**ivec)(); 629 caddr_t ualloc; 630 extern int catcher[256]; 631 #ifdef DW780 632 struct uba_regs *vubp = uhp->uh_uba; 633 #endif 634 635 /* 636 * Initialize the UNIBUS, by freeing the map 637 * registers and the buffered data path registers 638 */ 639 uhp->uh_map = (struct map *) 640 malloc(UAMSIZ * sizeof (struct map), M_DEVBUF, M_NOWAIT); 641 ubainitmaps(uhp); 642 643 /* 644 * Allocate and initialize space 645 * for the UNIBUS interrupt vectors. 646 * On the 8600, can't use UNIvec; 647 * the vectors for the second SBI overlap it. 648 */ 649 #if VAX8600 650 if (cpu == VAX_8600) 651 uhp->uh_vec = (int(**)())malloc(512, M_DEVBUF, M_NOWAIT); 652 else 653 #endif 654 if (numuba == 0) 655 uhp->uh_vec = UNIvec; 656 #if NUBA > 1 657 else if (numuba == 1) 658 uhp->uh_vec = UNI1vec; 659 else 660 uhp->uh_vec = (int(**)())malloc(512, M_DEVBUF, M_NOWAIT); 661 #endif 662 for (i = 0; i < 128; i++) 663 uhp->uh_vec[i] = 664 scbentry(&catcher[i*2], SCB_ISTACK); 665 /* 666 * Set last free interrupt vector for devices with 667 * programmable interrupt vectors. Use is to decrement 668 * this number and use result as interrupt vector. 669 */ 670 uhp->uh_lastiv = 0x200; 671 672 #ifdef DW780 673 if (uhp->uh_type == DW780) { 674 vubp->uba_sr = vubp->uba_sr; 675 vubp->uba_cr = UBACR_IFS|UBACR_BRIE; 676 } 677 #endif 678 /* 679 * First configure devices that have unibus memory, 680 * allowing them to allocate the correct map registers. 681 */ 682 ubameminit(numuba); 683 /* 684 * Grab some memory to record the umem address space we allocate, 685 * so we can be sure not to place two devices at the same address. 686 * 687 * We could use just 1/8 of this (we only want a 1 bit flag) but 688 * we are going to give it back anyway, and that would make the 689 * code here bigger (which we can't give back), so ... 690 * 691 * One day, someone will make a unibus with something other than 692 * an 8K i/o address space, & screw this totally. 693 */ 694 ualloc = (caddr_t)malloc(8*1024, M_TEMP, M_NOWAIT); 695 if (ualloc == (caddr_t)0) 696 panic("no mem for unifind"); 697 bzero(ualloc, 8*1024); 698 699 /* 700 * Map the first page of UNIBUS i/o 701 * space to the first page of memory 702 * for devices which will need to dma 703 * output to produce an interrupt. 704 */ 705 *(int *)(&uhp->uh_mr[0]) = UBAMR_MRV; 706 707 #define ubaddr(uhp, off) (u_short *)((int)(uhp)->uh_iopage + ubdevreg(off)) 708 /* 709 * Check each unibus mass storage controller. 710 * For each one which is potentially on this uba, 711 * see if it is really there, and if it is record it and 712 * then go looking for slaves. 713 */ 714 for (um = ubminit; udp = um->um_driver; um++) { 715 if (um->um_ubanum != numuba && um->um_ubanum != '?') 716 continue; 717 addr = (u_short)um->um_addr; 718 /* 719 * use the particular address specified first, 720 * or if it is given as "0", of there is no device 721 * at that address, try all the standard addresses 722 * in the driver til we find it 723 */ 724 for (ap = udp->ud_addr; addr || (addr = *ap++); addr = 0) { 725 726 if (ualloc[ubdevreg(addr)]) 727 continue; 728 reg = ubaddr(uhp, addr); 729 if (badaddr((caddr_t)reg, 2)) 730 continue; 731 #ifdef DW780 732 if (uhp->uh_type == DW780 && vubp->uba_sr) { 733 vubp->uba_sr = vubp->uba_sr; 734 continue; 735 } 736 #endif 737 cvec = 0x200; 738 i = (*udp->ud_probe)(reg, um->um_ctlr, um); 739 #ifdef DW780 740 if (uhp->uh_type == DW780 && vubp->uba_sr) { 741 vubp->uba_sr = vubp->uba_sr; 742 continue; 743 } 744 #endif 745 if (i == 0) 746 continue; 747 printf("%s%d at uba%d csr %o ", 748 udp->ud_mname, um->um_ctlr, numuba, addr); 749 if (cvec == 0) { 750 printf("zero vector\n"); 751 continue; 752 } 753 if (cvec == 0x200) { 754 printf("didn't interrupt\n"); 755 continue; 756 } 757 printf("vec %o, ipl %x\n", cvec, br); 758 csralloc(ualloc, addr, i); 759 um->um_alive = 1; 760 um->um_ubanum = numuba; 761 um->um_hd = &uba_hd[numuba]; 762 um->um_addr = (caddr_t)reg; 763 udp->ud_minfo[um->um_ctlr] = um; 764 for (ivec = um->um_intr; *ivec; ivec++) { 765 um->um_hd->uh_vec[cvec/4] = 766 scbentry(*ivec, SCB_ISTACK); 767 cvec += 4; 768 } 769 for (ui = ubdinit; ui->ui_driver; ui++) { 770 if (ui->ui_driver != udp || ui->ui_alive || 771 ui->ui_ctlr != um->um_ctlr && ui->ui_ctlr != '?' || 772 ui->ui_ubanum != numuba && ui->ui_ubanum != '?') 773 continue; 774 if ((*udp->ud_slave)(ui, reg)) { 775 ui->ui_alive = 1; 776 ui->ui_ctlr = um->um_ctlr; 777 ui->ui_ubanum = numuba; 778 ui->ui_hd = &uba_hd[numuba]; 779 ui->ui_addr = (caddr_t)reg; 780 ui->ui_physaddr = pumem + ubdevreg(addr); 781 if (ui->ui_dk && dkn < DK_NDRIVE) 782 ui->ui_dk = dkn++; 783 else 784 ui->ui_dk = -1; 785 ui->ui_mi = um; 786 /* ui_type comes from driver */ 787 udp->ud_dinfo[ui->ui_unit] = ui; 788 printf("%s%d at %s%d slave %d\n", 789 udp->ud_dname, ui->ui_unit, 790 udp->ud_mname, um->um_ctlr, ui->ui_slave); 791 (*udp->ud_attach)(ui); 792 } 793 } 794 break; 795 } 796 } 797 /* 798 * Now look for non-mass storage peripherals. 799 */ 800 for (ui = ubdinit; udp = ui->ui_driver; ui++) { 801 if (ui->ui_ubanum != numuba && ui->ui_ubanum != '?' || 802 ui->ui_alive || ui->ui_slave != -1) 803 continue; 804 addr = (u_short)ui->ui_addr; 805 806 for (ap = udp->ud_addr; addr || (addr = *ap++); addr = 0) { 807 808 if (ualloc[ubdevreg(addr)]) 809 continue; 810 reg = ubaddr(uhp, addr); 811 if (badaddr((caddr_t)reg, 2)) 812 continue; 813 #ifdef DW780 814 if (uhp->uh_type == DW780 && vubp->uba_sr) { 815 vubp->uba_sr = vubp->uba_sr; 816 continue; 817 } 818 #endif 819 cvec = 0x200; 820 i = (*udp->ud_probe)(reg, ui); 821 #ifdef DW780 822 if (uhp->uh_type == DW780 && vubp->uba_sr) { 823 vubp->uba_sr = vubp->uba_sr; 824 continue; 825 } 826 #endif 827 if (i == 0) 828 continue; 829 printf("%s%d at uba%d csr %o ", 830 ui->ui_driver->ud_dname, ui->ui_unit, numuba, addr); 831 if (cvec == 0) { 832 printf("zero vector\n"); 833 continue; 834 } 835 if (cvec == 0x200) { 836 printf("didn't interrupt\n"); 837 continue; 838 } 839 printf("vec %o, ipl %x\n", cvec, br); 840 csralloc(ualloc, addr, i); 841 ui->ui_hd = &uba_hd[numuba]; 842 for (ivec = ui->ui_intr; *ivec; ivec++) { 843 ui->ui_hd->uh_vec[cvec/4] = 844 scbentry(*ivec, SCB_ISTACK); 845 cvec += 4; 846 } 847 ui->ui_alive = 1; 848 ui->ui_ubanum = numuba; 849 ui->ui_addr = (caddr_t)reg; 850 ui->ui_physaddr = pumem + ubdevreg(addr); 851 ui->ui_dk = -1; 852 /* ui_type comes from driver */ 853 udp->ud_dinfo[ui->ui_unit] = ui; 854 (*udp->ud_attach)(ui); 855 break; 856 } 857 } 858 859 #ifdef DW780 860 if (uhp->uh_type == DW780) 861 uhp->uh_uba->uba_cr = UBACR_IFS | UBACR_BRIE | 862 UBACR_USEFIE | UBACR_SUEFIE | 863 (uhp->uh_uba->uba_cr & 0x7c000000); 864 #endif 865 numuba++; 866 867 #ifdef AUTO_DEBUG 868 printf("Unibus allocation map"); 869 for (i = 0; i < 8*1024; ) { 870 register n, m; 871 872 if ((i % 128) == 0) { 873 printf("\n%6o:", i); 874 for (n = 0; n < 128; n++) 875 if (ualloc[i+n]) 876 break; 877 if (n == 128) { 878 i += 128; 879 continue; 880 } 881 } 882 883 for (n = m = 0; n < 16; n++) { 884 m <<= 1; 885 m |= ualloc[i++]; 886 } 887 888 printf(" %4x", m); 889 } 890 printf("\n"); 891 #endif 892 893 free(ualloc, M_TEMP); 894 } 895 896 /* 897 * Mark addresses starting at "addr" and continuing 898 * "size" bytes as allocated in the map "ualloc". 899 * Warn if the new allocation overlaps a previous allocation. 900 */ 901 static 902 csralloc(ualloc, addr, size) 903 caddr_t ualloc; 904 u_short addr; 905 register int size; 906 { 907 register caddr_t p; 908 int warned = 0; 909 910 p = &ualloc[ubdevreg(addr+size)]; 911 while (--size >= 0) { 912 if (*--p && !warned) { 913 printf( 914 "WARNING: device registers overlap those for a previous device!\n"); 915 warned = 1; 916 } 917 *p = 1; 918 } 919 } 920 921 /* 922 * Make an IO register area accessible at physical address physa 923 * by mapping kernel ptes starting at pte. 924 */ 925 ioaccess(physa, pte, size) 926 caddr_t physa; 927 register struct pte *pte; 928 int size; 929 { 930 register int i = btoc(size); 931 register unsigned v = btop(physa); 932 933 do 934 *(int *)pte++ = PG_V|PG_KW|v++; 935 while (--i > 0); 936 mtpr(TBIA, 0); 937 } 938 939 /* 940 * Configure swap space and related parameters. 941 */ 942 swapconf() 943 { 944 register struct swdevt *swp; 945 register int nblks; 946 947 for (swp = swdevt; swp->sw_dev; swp++) 948 if (bdevsw[major(swp->sw_dev)].d_psize) { 949 nblks = 950 (*bdevsw[major(swp->sw_dev)].d_psize)(swp->sw_dev); 951 if (nblks != -1 && 952 (swp->sw_nblks == 0 || swp->sw_nblks > nblks)) 953 swp->sw_nblks = nblks; 954 } 955 if (dumplo == 0 && bdevsw[major(dumpdev)].d_psize) 956 dumplo = (*bdevsw[major(dumpdev)].d_psize)(dumpdev) - physmem; 957 if (dumplo < 0) 958 dumplo = 0; 959 } 960 961 #define DOSWAP /* Change swdevt, argdev, and dumpdev too */ 962 u_long bootdev; /* should be dev_t, but not until 32 bits */ 963 964 static char devname[][2] = { 965 'h','p', /* 0 = hp */ 966 0,0, /* 1 = ht */ 967 'u','p', /* 2 = up */ 968 'r','k', /* 3 = hk */ 969 0,0, /* 4 = sw */ 970 0,0, /* 5 = tm */ 971 0,0, /* 6 = ts */ 972 0,0, /* 7 = mt */ 973 0,0, /* 8 = tu */ 974 'r','a', /* 9 = ra */ 975 0,0, /* 10 = ut */ 976 'r','b', /* 11 = rb */ 977 0,0, /* 12 = uu */ 978 0,0, /* 13 = rx */ 979 'r','l', /* 14 = rl */ 980 }; 981 982 #define PARTITIONMASK 0x7 983 #define PARTITIONSHIFT 3 984 985 /* 986 * Attempt to find the device from which we were booted. 987 * If we can do so, and not instructed not to do so, 988 * change rootdev to correspond to the load device. 989 */ 990 setroot() 991 { 992 int majdev, mindev, unit, part, adaptor; 993 dev_t temp, orootdev; 994 struct swdevt *swp; 995 996 if (boothowto & RB_DFLTROOT || 997 (bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC) 998 return; 999 majdev = (bootdev >> B_TYPESHIFT) & B_TYPEMASK; 1000 if (majdev > sizeof(devname) / sizeof(devname[0])) 1001 return; 1002 adaptor = (bootdev >> B_ADAPTORSHIFT) & B_ADAPTORMASK; 1003 part = (bootdev >> B_PARTITIONSHIFT) & B_PARTITIONMASK; 1004 unit = (bootdev >> B_UNITSHIFT) & B_UNITMASK; 1005 if (majdev == 0) { /* MBA device */ 1006 #if NMBA > 0 1007 register struct mba_device *mbap; 1008 int mask; 1009 1010 /* 1011 * The MBA number used at boot time is not necessarily the same as the 1012 * MBA number used by the kernel. In order to change the rootdev we need to 1013 * convert the boot MBA number to the kernel MBA number. The address space 1014 * for an MBA used by the boot code is 0x20010000 + 0x2000 * MBA_number 1015 * on the 78? and 86?0, 0xf28000 + 0x2000 * MBA_number on the 750. 1016 * Therefore we can search the mba_hd table for the MBA that has the physical 1017 * address corresponding to the boot MBA number. 1018 */ 1019 #define PHYSADRSHFT 13 1020 #define PHYSMBAMASK780 0x7 1021 #define PHYSMBAMASK750 0x3 1022 1023 switch (cpu) { 1024 1025 case VAX_780: 1026 case VAX_8600: 1027 default: 1028 mask = PHYSMBAMASK780; 1029 break; 1030 1031 case VAX_750: 1032 mask = PHYSMBAMASK750; 1033 break; 1034 } 1035 for (mbap = mbdinit; mbap->mi_driver; mbap++) 1036 if (mbap->mi_alive && mbap->mi_drive == unit && 1037 (((long)mbap->mi_hd->mh_physmba >> PHYSADRSHFT) 1038 & mask) == adaptor) 1039 break; 1040 if (mbap->mi_driver == 0) 1041 return; 1042 mindev = mbap->mi_unit; 1043 #else 1044 return; 1045 #endif 1046 } else { 1047 register struct uba_device *ubap; 1048 1049 for (ubap = ubdinit; ubap->ui_driver; ubap++) 1050 if (ubap->ui_alive && ubap->ui_slave == unit && 1051 ubap->ui_ubanum == adaptor && 1052 ubap->ui_driver->ud_dname[0] == devname[majdev][0] && 1053 ubap->ui_driver->ud_dname[1] == devname[majdev][1]) 1054 break; 1055 1056 if (ubap->ui_driver == 0) 1057 return; 1058 mindev = ubap->ui_unit; 1059 } 1060 mindev = (mindev << PARTITIONSHIFT) + part; 1061 orootdev = rootdev; 1062 rootdev = makedev(majdev, mindev); 1063 /* 1064 * If the original rootdev is the same as the one 1065 * just calculated, don't need to adjust the swap configuration. 1066 */ 1067 if (rootdev == orootdev) 1068 return; 1069 1070 printf("Changing root device to %c%c%d%c\n", 1071 devname[majdev][0], devname[majdev][1], 1072 mindev >> PARTITIONSHIFT, part + 'a'); 1073 1074 #ifdef DOSWAP 1075 mindev &= ~PARTITIONMASK; 1076 for (swp = swdevt; swp->sw_dev; swp++) { 1077 if (majdev == major(swp->sw_dev) && 1078 mindev == (minor(swp->sw_dev) & ~PARTITIONMASK)) { 1079 temp = swdevt[0].sw_dev; 1080 swdevt[0].sw_dev = swp->sw_dev; 1081 swp->sw_dev = temp; 1082 break; 1083 } 1084 } 1085 if (swp->sw_dev == 0) 1086 return; 1087 1088 /* 1089 * If argdev and dumpdev were the same as the old primary swap 1090 * device, move them to the new primary swap device. 1091 */ 1092 if (temp == dumpdev) 1093 dumpdev = swdevt[0].sw_dev; 1094 if (temp == argdev) 1095 argdev = swdevt[0].sw_dev; 1096 #endif 1097 } 1098