1/* $NetBSD: autoconf.c,v 1.12 2011/02/07 13:11:41 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/stand/common/grfreg.h> 53#include <hp300/dev/intioreg.h> 54 55/* 56 * Mapping of ROM MSUS types to BSD major device numbers 57 * WARNING: major numbers must match bdevsw indices in hp300/conf.c. 58 */ 59static const char rom2mdev[] = { 60 0, 0, /* 0-1: none */ 61 6, /* 2: network device; special */ 62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 3-13: none */ 63 4, /* 14: SCSI disk */ 64 0, /* 15: none */ 65 2, /* 16: CS/80 device on HPIB */ 66 2, /* 17: CS/80 device on HPIB */ 67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 18-31: none */ 68}; 69 70struct hp_hw sc_table[MAXCTLRS]; 71int cpuspeed; 72 73static u_long msustobdev(void); 74static void find_devs(void); 75 76#ifdef PRINTROMINFO 77void 78printrominfo(void) 79{ 80 struct rominfo *rp = (struct rominfo *)ROMADDR; 81 82 printf("boottype %x, name %s, lowram %x, sysflag %x\n", 83 rp->boottype, rp->name, rp->lowram, rp->sysflag&0xff); 84 printf("rambase %x, ndrives %x, sysflag2 %x, msus %x\n", 85 rp->rambase, rp->ndrives, rp->sysflag2&0xff, rp->msus); 86} 87#endif 88 89void 90configure(void) 91{ 92 93 switch (machineid) { 94 case HP_320: 95 case HP_330: 96 case HP_340: 97 cpuspeed = MHZ_16; 98 break; 99 case HP_350: 100 case HP_360: 101 case HP_362: 102 cpuspeed = MHZ_25; 103 break; 104 case HP_370: 105 cpuspeed = MHZ_33; 106 break; 107 case HP_375: 108 case HP_400: 109 cpuspeed = MHZ_50; 110 break; 111 case HP_380: 112 case HP_382: 113 case HP_425: 114 cpuspeed = MHZ_25 * 2; /* XXX */ 115 break; 116 case HP_385: 117 case HP_433: 118 cpuspeed = MHZ_33 * 2; /* XXX */ 119 break; 120 default: /* assume the fastest (largest delay value) */ 121 cpuspeed = MHZ_50; 122 break; 123 } 124 find_devs(); 125 cninit(); 126#ifdef PRINTROMINFO 127 printrominfo(); 128#endif 129 hpibinit(); 130 scsiinit(); 131 if ((bootdev & B_MAGICMASK) != B_DEVMAGIC) 132 bootdev = msustobdev(); 133} 134 135/* 136 * Convert HP MSUS to a valid bootdev layout: 137 * TYPE comes from MSUS device type as mapped by rom2mdev 138 * PARTITION is set to 0 ('a') 139 * UNIT comes from MSUS unit (almost always 0) 140 * CONTROLLER comes from MSUS primary address 141 * ADAPTER comes from SCSI/HPIB driver logical unit number 142 * (passed back via unused hw_pa field) 143 */ 144static u_long 145msustobdev(void) 146{ 147 struct rominfo *rp = (struct rominfo *) ROMADDR; 148 u_long bdev = 0; 149 struct hp_hw *hw; 150 int sc, type, ctlr, slave, punit; 151 152 sc = (rp->msus >> 8) & 0xFF; 153 for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++) 154 if (hw->hw_sc == sc) 155 break; 156 157 type = rom2mdev[(rp->msus >> 24) & 0x1F]; 158 ctlr = (int)hw->hw_pa; 159 slave = (rp->msus & 0xFF); 160 punit = ((rp->msus >> 16) & 0xFF); 161 162 bdev = MAKEBOOTDEV(type, ctlr, slave, punit, 0); 163 164#ifdef PRINTROMINFO 165 printf("msus %x -> bdev %x\n", rp->msus, bdev); 166#endif 167 return bdev; 168} 169 170int 171sctoaddr(int sc) 172{ 173 174 if (sc == -1) 175 return INTIOBASE + FB_BASE; 176 if (sc == 7 && internalhpib) 177 return internalhpib ; 178 if (sc < 32) 179 return DIOBASE + sc * DIOCSIZE ; 180 if (sc >= DIOII_SCBASE) 181 return DIOIIBASE + (sc - DIOII_SCBASE) * DIOIICSIZE ; 182 return sc; 183} 184 185/* 186 * Probe all DIO select codes (0 - 32), the internal display address, 187 * and DIO-II select codes (132 - 256). 188 * 189 * Note that we only care about displays, LANCEs, SCSIs and HP-IBs. 190 */ 191static void 192find_devs(void) 193{ 194 short sc, sctop; 195 u_char *id_reg; 196 void *addr; 197 struct hp_hw *hw; 198 199 hw = sc_table; 200 sctop = DIO_SCMAX(machineid); 201 for (sc = -1; sc < sctop; sc++) { 202 if (DIO_INHOLE(sc)) 203 continue; 204 addr = (void *)sctoaddr(sc); 205 if (badaddr(addr)) 206 continue; 207 208 id_reg = (u_char *)addr; 209 hw->hw_pa = 0; /* XXX used to pass back LUN from driver */ 210 if (sc >= DIOII_SCBASE) 211 hw->hw_size = DIOII_SIZE(id_reg); 212 else 213 hw->hw_size = DIOCSIZE; 214 hw->hw_kva = addr; 215 hw->hw_id = DIO_ID(id_reg); 216 hw->hw_sc = sc; 217 218 /* 219 * Not all internal HP-IBs respond rationally to id requests 220 * so we just go by the "internal HPIB" indicator in SYSFLAG. 221 */ 222 if (sc == 7 && internalhpib) { 223 hw->hw_type = C_HPIB; 224 hw++; 225 continue; 226 } 227 228 switch (hw->hw_id) { 229 case 5: /* 98642A */ 230 case 5+128: /* 98642A remote */ 231 hw->hw_type = D_COMMDCM; 232 break; 233 case 8: /* 98625B */ 234 case 128: /* 98624A */ 235 hw->hw_type = C_HPIB; 236 break; 237 case 21: /* LANCE */ 238 hw->hw_type = D_LAN; 239 break; 240 case 57: /* Displays */ 241 hw->hw_type = D_BITMAP; 242 hw->hw_secid = id_reg[0x15]; 243 switch (hw->hw_secid) { 244 case 4: /* renaissance */ 245 case 8: /* davinci */ 246 sc++; /* occupy 2 select codes */ 247 break; 248 } 249 break; 250 case 9: 251 hw->hw_type = D_KEYBOARD; 252 break; 253 case 7: 254 case 7+32: 255 case 7+64: 256 case 7+96: 257 hw->hw_type = C_SCSI; 258 break; 259 default: /* who cares */ 260 hw->hw_type = D_MISC; 261 break; 262 } 263 hw++; 264 } 265} 266