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