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