autoconf.c revision 1.1 1 /* $NetBSD: autoconf.c,v 1.1 1997/02/04 03:52:14 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_433:
110 cpuspeed = MHZ_33 * 2; /* XXX */
111 break;
112 default: /* assume the fastest (largest delay value) */
113 cpuspeed = MHZ_50;
114 break;
115 }
116 find_devs();
117 cninit();
118 #ifdef PRINTROMINFO
119 printrominfo();
120 #endif
121 hpibinit();
122 scsiinit();
123 if ((bootdev & B_MAGICMASK) != B_DEVMAGIC)
124 bootdev = msustobdev();
125 }
126
127 /*
128 * Convert HP MSUS to a valid bootdev layout:
129 * TYPE comes from MSUS device type as mapped by rom2mdev
130 * PARTITION is set to 0 ('a')
131 * UNIT comes from MSUS unit (almost always 0)
132 * CONTROLLER comes from MSUS primary address
133 * ADAPTER comes from SCSI/HPIB driver logical unit number
134 * (passed back via unused hw_pa field)
135 */
136 u_long
137 msustobdev()
138 {
139 struct rominfo *rp = (struct rominfo *) ROMADDR;
140 u_long bdev = 0;
141 register struct hp_hw *hw;
142 int sc, type, ctlr, slave, punit;
143
144 sc = (rp->msus >> 8) & 0xFF;
145 for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++)
146 if (hw->hw_sc == sc)
147 break;
148
149 type = rom2mdev[(rp->msus >> 24) & 0x1F];
150 ctlr = (int)hw->hw_pa;
151 slave = (rp->msus & 0xFF);
152 punit = ((rp->msus >> 16) & 0xFF);
153
154 bdev = MAKEBOOTDEV(type, ctlr, slave, punit, 0);
155
156 #ifdef PRINTROMINFO
157 printf("msus %x -> bdev %x\n", rp->msus, bdev);
158 #endif
159 return (bdev);
160 }
161
162 sctoaddr(sc)
163 int sc;
164 {
165 if (sc == -1)
166 return(GRFIADDR);
167 if (sc == 7 && internalhpib)
168 return(internalhpib);
169 if (sc < 32)
170 return(DIOBASE + sc * DIOCSIZE);
171 if (sc >= 132)
172 return(DIOIIBASE + (sc - 132) * DIOIICSIZE);
173 return(sc);
174 }
175
176 /*
177 * Probe all DIO select codes (0 - 32), the internal display address,
178 * and DIO-II select codes (132 - 256).
179 *
180 * Note that we only care about displays, LANCEs, SCSIs and HP-IBs.
181 */
182 find_devs()
183 {
184 short sc, sctop;
185 u_char *id_reg;
186 register caddr_t addr;
187 register struct hp_hw *hw;
188
189 hw = sc_table;
190 sctop = machineid == HP_320 ? 32 : 256;
191 for (sc = -1; sc < sctop; sc++) {
192 if (sc >= 32 && sc < 132)
193 continue;
194 addr = (caddr_t) sctoaddr(sc);
195 if (badaddr(addr))
196 continue;
197
198 id_reg = (u_char *) addr;
199 hw->hw_pa = 0; /* XXX used to pass back LUN from driver */
200 if (sc >= 132)
201 hw->hw_size = (id_reg[0x101] + 1) * 0x100000;
202 else
203 hw->hw_size = DIOCSIZE;
204 hw->hw_kva = addr;
205 hw->hw_id = id_reg[1];
206 hw->hw_sc = sc;
207
208 /*
209 * Not all internal HP-IBs respond rationally to id requests
210 * so we just go by the "internal HPIB" indicator in SYSFLAG.
211 */
212 if (sc == 7 && internalhpib) {
213 hw->hw_type = C_HPIB;
214 hw++;
215 continue;
216 }
217
218 switch (hw->hw_id) {
219 case 5: /* 98642A */
220 case 5+128: /* 98642A remote */
221 hw->hw_type = D_COMMDCM;
222 break;
223 case 8: /* 98625B */
224 case 128: /* 98624A */
225 hw->hw_type = C_HPIB;
226 break;
227 case 21: /* LANCE */
228 hw->hw_type = D_LAN;
229 break;
230 case 57: /* Displays */
231 hw->hw_type = D_BITMAP;
232 hw->hw_secid = id_reg[0x15];
233 switch (hw->hw_secid) {
234 case 4: /* renaissance */
235 case 8: /* davinci */
236 sc++; /* occupy 2 select codes */
237 break;
238 }
239 break;
240 case 9:
241 hw->hw_type = D_KEYBOARD;
242 break;
243 case 7:
244 case 7+32:
245 case 7+64:
246 case 7+96:
247 hw->hw_type = C_SCSI;
248 break;
249 default: /* who cares */
250 hw->hw_type = D_MISC;
251 break;
252 }
253 hw++;
254 }
255 }
256