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