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