1 1.14 tsutsui /* $NetBSD: autoconf.c,v 1.14 2021/07/05 13:41:08 tsutsui Exp $ */ 2 1.1 thorpej 3 1.1 thorpej /* 4 1.13 rmind * Copyright (c) 1988 University of Utah. 5 1.1 thorpej * Copyright (c) 1990, 1993 6 1.1 thorpej * The Regents of the University of California. All rights reserved. 7 1.3 agc * 8 1.3 agc * This code is derived from software contributed to Berkeley by 9 1.3 agc * the Systems Programming Group of the University of Utah Computer 10 1.3 agc * Science Department. 11 1.3 agc * 12 1.3 agc * Redistribution and use in source and binary forms, with or without 13 1.3 agc * modification, are permitted provided that the following conditions 14 1.3 agc * are met: 15 1.3 agc * 1. Redistributions of source code must retain the above copyright 16 1.3 agc * notice, this list of conditions and the following disclaimer. 17 1.3 agc * 2. Redistributions in binary form must reproduce the above copyright 18 1.3 agc * notice, this list of conditions and the following disclaimer in the 19 1.3 agc * documentation and/or other materials provided with the distribution. 20 1.3 agc * 3. Neither the name of the University nor the names of its contributors 21 1.3 agc * may be used to endorse or promote products derived from this software 22 1.3 agc * without specific prior written permission. 23 1.3 agc * 24 1.3 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 1.3 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 1.3 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 1.3 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 1.3 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 1.3 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 1.3 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 1.3 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 1.3 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 1.3 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 1.3 agc * SUCH DAMAGE. 35 1.3 agc * 36 1.3 agc * from: Utah Hdr: autoconf.c 1.16 92/05/29 37 1.3 agc * 38 1.3 agc * @(#)autoconf.c 8.1 (Berkeley) 6/10/93 39 1.3 agc */ 40 1.1 thorpej 41 1.1 thorpej #include <sys/param.h> 42 1.1 thorpej #include <sys/reboot.h> 43 1.1 thorpej 44 1.1 thorpej #include <hp300/stand/common/samachdep.h> 45 1.1 thorpej #include <hp300/stand/common/rominfo.h> 46 1.1 thorpej #include <hp300/stand/common/device.h> 47 1.4 tsutsui #include <hp300/stand/common/hpibvar.h> 48 1.4 tsutsui #include <hp300/stand/common/scsireg.h> 49 1.4 tsutsui #include <hp300/stand/common/scsivar.h> 50 1.1 thorpej 51 1.10 tsutsui #include <hp300/dev/dioreg.h> 52 1.7 tsutsui #include <hp300/dev/intioreg.h> 53 1.1 thorpej 54 1.1 thorpej /* 55 1.1 thorpej * Mapping of ROM MSUS types to BSD major device numbers 56 1.1 thorpej * WARNING: major numbers must match bdevsw indices in hp300/conf.c. 57 1.1 thorpej */ 58 1.4 tsutsui static const char rom2mdev[] = { 59 1.1 thorpej 0, 0, /* 0-1: none */ 60 1.1 thorpej 6, /* 2: network device; special */ 61 1.1 thorpej 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3-13: none */ 62 1.1 thorpej 4, /* 14: SCSI disk */ 63 1.1 thorpej 0, /* 15: none */ 64 1.1 thorpej 2, /* 16: CS/80 device on HPIB */ 65 1.1 thorpej 2, /* 17: CS/80 device on HPIB */ 66 1.1 thorpej 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 18-31: none */ 67 1.1 thorpej }; 68 1.1 thorpej 69 1.1 thorpej struct hp_hw sc_table[MAXCTLRS]; 70 1.1 thorpej int cpuspeed; 71 1.1 thorpej 72 1.4 tsutsui static u_long msustobdev(void); 73 1.4 tsutsui static void find_devs(void); 74 1.1 thorpej 75 1.1 thorpej #ifdef PRINTROMINFO 76 1.4 tsutsui void 77 1.5 tsutsui printrominfo(void) 78 1.1 thorpej { 79 1.1 thorpej struct rominfo *rp = (struct rominfo *)ROMADDR; 80 1.1 thorpej 81 1.1 thorpej printf("boottype %x, name %s, lowram %x, sysflag %x\n", 82 1.1 thorpej rp->boottype, rp->name, rp->lowram, rp->sysflag&0xff); 83 1.1 thorpej printf("rambase %x, ndrives %x, sysflag2 %x, msus %x\n", 84 1.1 thorpej rp->rambase, rp->ndrives, rp->sysflag2&0xff, rp->msus); 85 1.1 thorpej } 86 1.1 thorpej #endif 87 1.1 thorpej 88 1.4 tsutsui void 89 1.5 tsutsui configure(void) 90 1.1 thorpej { 91 1.1 thorpej 92 1.1 thorpej switch (machineid) { 93 1.1 thorpej case HP_320: 94 1.1 thorpej case HP_330: 95 1.1 thorpej case HP_340: 96 1.1 thorpej cpuspeed = MHZ_16; 97 1.1 thorpej break; 98 1.1 thorpej case HP_350: 99 1.1 thorpej case HP_360: 100 1.9 tsutsui case HP_362: 101 1.1 thorpej cpuspeed = MHZ_25; 102 1.1 thorpej break; 103 1.1 thorpej case HP_370: 104 1.1 thorpej cpuspeed = MHZ_33; 105 1.1 thorpej break; 106 1.1 thorpej case HP_375: 107 1.8 tsutsui case HP_400: 108 1.1 thorpej cpuspeed = MHZ_50; 109 1.1 thorpej break; 110 1.1 thorpej case HP_380: 111 1.9 tsutsui case HP_382: 112 1.8 tsutsui case HP_425: 113 1.1 thorpej cpuspeed = MHZ_25 * 2; /* XXX */ 114 1.1 thorpej break; 115 1.2 thorpej case HP_385: 116 1.1 thorpej case HP_433: 117 1.1 thorpej cpuspeed = MHZ_33 * 2; /* XXX */ 118 1.1 thorpej break; 119 1.1 thorpej default: /* assume the fastest (largest delay value) */ 120 1.1 thorpej cpuspeed = MHZ_50; 121 1.1 thorpej break; 122 1.1 thorpej } 123 1.1 thorpej find_devs(); 124 1.1 thorpej cninit(); 125 1.1 thorpej #ifdef PRINTROMINFO 126 1.1 thorpej printrominfo(); 127 1.1 thorpej #endif 128 1.1 thorpej hpibinit(); 129 1.1 thorpej scsiinit(); 130 1.1 thorpej if ((bootdev & B_MAGICMASK) != B_DEVMAGIC) 131 1.1 thorpej bootdev = msustobdev(); 132 1.1 thorpej } 133 1.1 thorpej 134 1.1 thorpej /* 135 1.1 thorpej * Convert HP MSUS to a valid bootdev layout: 136 1.1 thorpej * TYPE comes from MSUS device type as mapped by rom2mdev 137 1.1 thorpej * PARTITION is set to 0 ('a') 138 1.1 thorpej * UNIT comes from MSUS unit (almost always 0) 139 1.1 thorpej * CONTROLLER comes from MSUS primary address 140 1.1 thorpej * ADAPTER comes from SCSI/HPIB driver logical unit number 141 1.1 thorpej * (passed back via unused hw_pa field) 142 1.1 thorpej */ 143 1.4 tsutsui static u_long 144 1.5 tsutsui msustobdev(void) 145 1.1 thorpej { 146 1.1 thorpej struct rominfo *rp = (struct rominfo *) ROMADDR; 147 1.1 thorpej u_long bdev = 0; 148 1.4 tsutsui struct hp_hw *hw; 149 1.1 thorpej int sc, type, ctlr, slave, punit; 150 1.1 thorpej 151 1.1 thorpej sc = (rp->msus >> 8) & 0xFF; 152 1.1 thorpej for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) 153 1.1 thorpej if (hw->hw_sc == sc) 154 1.1 thorpej break; 155 1.1 thorpej 156 1.1 thorpej type = rom2mdev[(rp->msus >> 24) & 0x1F]; 157 1.1 thorpej ctlr = (int)hw->hw_pa; 158 1.1 thorpej slave = (rp->msus & 0xFF); 159 1.1 thorpej punit = ((rp->msus >> 16) & 0xFF); 160 1.1 thorpej 161 1.1 thorpej bdev = MAKEBOOTDEV(type, ctlr, slave, punit, 0); 162 1.1 thorpej 163 1.1 thorpej #ifdef PRINTROMINFO 164 1.1 thorpej printf("msus %x -> bdev %x\n", rp->msus, bdev); 165 1.1 thorpej #endif 166 1.4 tsutsui return bdev; 167 1.1 thorpej } 168 1.1 thorpej 169 1.4 tsutsui int 170 1.5 tsutsui sctoaddr(int sc) 171 1.1 thorpej { 172 1.4 tsutsui 173 1.1 thorpej if (sc == -1) 174 1.7 tsutsui return INTIOBASE + FB_BASE; 175 1.1 thorpej if (sc == 7 && internalhpib) 176 1.4 tsutsui return internalhpib ; 177 1.1 thorpej if (sc < 32) 178 1.4 tsutsui return DIOBASE + sc * DIOCSIZE ; 179 1.10 tsutsui if (sc >= DIOII_SCBASE) 180 1.10 tsutsui return DIOIIBASE + (sc - DIOII_SCBASE) * DIOIICSIZE ; 181 1.4 tsutsui return sc; 182 1.1 thorpej } 183 1.1 thorpej 184 1.1 thorpej /* 185 1.1 thorpej * Probe all DIO select codes (0 - 32), the internal display address, 186 1.1 thorpej * and DIO-II select codes (132 - 256). 187 1.1 thorpej * 188 1.1 thorpej * Note that we only care about displays, LANCEs, SCSIs and HP-IBs. 189 1.1 thorpej */ 190 1.4 tsutsui static void 191 1.5 tsutsui find_devs(void) 192 1.1 thorpej { 193 1.1 thorpej short sc, sctop; 194 1.1 thorpej u_char *id_reg; 195 1.11 christos void *addr; 196 1.4 tsutsui struct hp_hw *hw; 197 1.1 thorpej 198 1.1 thorpej hw = sc_table; 199 1.10 tsutsui sctop = DIO_SCMAX(machineid); 200 1.1 thorpej for (sc = -1; sc < sctop; sc++) { 201 1.10 tsutsui if (DIO_INHOLE(sc)) 202 1.1 thorpej continue; 203 1.11 christos addr = (void *)sctoaddr(sc); 204 1.1 thorpej if (badaddr(addr)) 205 1.1 thorpej continue; 206 1.1 thorpej 207 1.10 tsutsui id_reg = (u_char *)addr; 208 1.1 thorpej hw->hw_pa = 0; /* XXX used to pass back LUN from driver */ 209 1.10 tsutsui if (sc >= DIOII_SCBASE) 210 1.10 tsutsui hw->hw_size = DIOII_SIZE(id_reg); 211 1.1 thorpej else 212 1.1 thorpej hw->hw_size = DIOCSIZE; 213 1.1 thorpej hw->hw_kva = addr; 214 1.10 tsutsui hw->hw_id = DIO_ID(id_reg); 215 1.1 thorpej hw->hw_sc = sc; 216 1.1 thorpej 217 1.1 thorpej /* 218 1.1 thorpej * Not all internal HP-IBs respond rationally to id requests 219 1.1 thorpej * so we just go by the "internal HPIB" indicator in SYSFLAG. 220 1.1 thorpej */ 221 1.1 thorpej if (sc == 7 && internalhpib) { 222 1.1 thorpej hw->hw_type = C_HPIB; 223 1.1 thorpej hw++; 224 1.1 thorpej continue; 225 1.1 thorpej } 226 1.1 thorpej 227 1.1 thorpej switch (hw->hw_id) { 228 1.1 thorpej case 5: /* 98642A */ 229 1.1 thorpej case 5+128: /* 98642A remote */ 230 1.1 thorpej hw->hw_type = D_COMMDCM; 231 1.1 thorpej break; 232 1.1 thorpej case 8: /* 98625B */ 233 1.1 thorpej case 128: /* 98624A */ 234 1.1 thorpej hw->hw_type = C_HPIB; 235 1.1 thorpej break; 236 1.1 thorpej case 21: /* LANCE */ 237 1.1 thorpej hw->hw_type = D_LAN; 238 1.1 thorpej break; 239 1.1 thorpej case 57: /* Displays */ 240 1.1 thorpej hw->hw_type = D_BITMAP; 241 1.1 thorpej hw->hw_secid = id_reg[0x15]; 242 1.1 thorpej switch (hw->hw_secid) { 243 1.1 thorpej case 4: /* renaissance */ 244 1.1 thorpej case 8: /* davinci */ 245 1.1 thorpej sc++; /* occupy 2 select codes */ 246 1.1 thorpej break; 247 1.1 thorpej } 248 1.1 thorpej break; 249 1.1 thorpej case 9: 250 1.1 thorpej hw->hw_type = D_KEYBOARD; 251 1.1 thorpej break; 252 1.1 thorpej case 7: 253 1.1 thorpej case 7+32: 254 1.1 thorpej case 7+64: 255 1.1 thorpej case 7+96: 256 1.1 thorpej hw->hw_type = C_SCSI; 257 1.1 thorpej break; 258 1.1 thorpej default: /* who cares */ 259 1.1 thorpej hw->hw_type = D_MISC; 260 1.1 thorpej break; 261 1.1 thorpej } 262 1.1 thorpej hw++; 263 1.1 thorpej } 264 1.1 thorpej } 265