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