xref: /netbsd/sys/arch/vax/vax/autoconf.c (revision bf9ec67e)
1 /*	$NetBSD: autoconf.c,v 1.71 2002/03/23 18:13:04 ragge Exp $	*/
2 
3 /*
4  * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *     This product includes software developed at Ludd, University of Lule}.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include "opt_compat_netbsd.h"
34 
35 #include <sys/param.h>
36 #include <sys/types.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/reboot.h>
40 #include <sys/disk.h>
41 #include <sys/buf.h>
42 #include <sys/conf.h>
43 
44 #include <uvm/uvm_extern.h>
45 
46 #include <machine/cpu.h>
47 #include <machine/sid.h>
48 #include <machine/param.h>
49 #include <machine/vmparam.h>
50 #include <machine/nexus.h>
51 #include <machine/ioa.h>
52 #include <machine/ka820.h>
53 #include <machine/ka750.h>
54 #include <machine/ka650.h>
55 #include <machine/clock.h>
56 #include <machine/rpb.h>
57 #include <machine/bus.h>
58 
59 #include <vax/vax/gencons.h>
60 
61 #include <dev/bi/bireg.h>
62 
63 #include "locators.h"
64 #include "opt_cputype.h"
65 
66 void	gencnslask __P((void));
67 
68 struct cpu_dep *dep_call;
69 struct device *booted_device;
70 int booted_partition;	/* defaults to 0 (aka 'a' partition */
71 
72 struct evcnt softnet_intrcnt =
73 	EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "soft", "net");
74 struct evcnt softserial_intrcnt =
75 	EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "soft", "serial");
76 struct evcnt softclock_intrcnt =
77 	EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "soft", "clock");
78 
79 #define MAINBUS	0
80 
81 void
82 cpu_configure(void)
83 {
84 
85 	if (config_rootfound("mainbus", NULL) == NULL)
86 		panic("mainbus not configured");
87 
88 	evcnt_attach_static(&softserial_intrcnt);
89 	evcnt_attach_static(&softnet_intrcnt);
90 	evcnt_attach_static(&softclock_intrcnt);
91 
92 	/*
93 	 * We're ready to start up. Clear CPU cold start flag.
94 	 * Soft cold-start flag will be cleared in configure().
95 	 */
96 	if (dep_call->cpu_clrf)
97 		(*dep_call->cpu_clrf)();
98 }
99 
100 void
101 cpu_rootconf(void)
102 {
103 	/*
104 	 * The device we booted from are looked for during autoconfig.
105 	 * If there has been a match, it's already been done.
106 	 */
107 
108 #ifdef DEBUG
109 	printf("booted from type %d unit %d csr 0x%lx adapter %lx slave %d\n",
110 	    rpb.devtyp, rpb.unit, rpb.csrphy, rpb.adpphy, rpb.slave);
111 #endif
112 	printf("boot device: %s\n",
113 	    booted_device ? booted_device->dv_xname : "<unknown>");
114 
115 	setroot(booted_device, booted_partition);
116 }
117 
118 int	mainbus_print __P((void *, const char *));
119 int	mainbus_match __P((struct device *, struct cfdata *, void *));
120 void	mainbus_attach __P((struct device *, struct device *, void *));
121 
122 int
123 mainbus_print(aux, hej)
124 	void *aux;
125 	const char *hej;
126 {
127 	if (hej)
128 		printf("nothing at %s", hej);
129 	return (UNCONF);
130 }
131 
132 int
133 mainbus_match(parent, cf, aux)
134 	struct	device	*parent;
135 	struct cfdata *cf;
136 	void	*aux;
137 {
138 	return 1; /* First (and only) mainbus */
139 }
140 
141 void
142 mainbus_attach(parent, self, hej)
143 	struct	device	*parent, *self;
144 	void	*hej;
145 {
146 
147 	printf("\n");
148 
149 	/*
150 	 * Hopefully there a master bus?
151 	 * Maybe should have this as master instead of mainbus.
152 	 */
153 	config_found(self, NULL, mainbus_print);
154 
155 #if VAX53 || VAXANY
156 	/* Kludge: To have two master buses */
157 	if (vax_boardtype == VAX_BTYP_53)
158 		config_found(self, (void *)1, mainbus_print);
159 #endif
160 
161 	if (dep_call->cpu_subconf)
162 		(*dep_call->cpu_subconf)(self);
163 
164 #if defined(COMPAT_14)
165 	if (rpb.rpb_base == (void *)-1)
166 		printf("\nWARNING: you must update your boot blocks.\n\n");
167 #endif
168 
169 }
170 
171 struct	cfattach mainbus_ca = {
172 	sizeof(struct device), mainbus_match, mainbus_attach
173 };
174 
175 #include "sd.h"
176 #include "cd.h"
177 #include "rl.h"
178 #include "ra.h"
179 #include "hp.h"
180 #include "ry.h"
181 
182 static int ubtest(void *);
183 static int jmfr(char *, struct device *, int);
184 static int booted_qe(struct device *, void *);
185 static int booted_le(struct device *, void *);
186 static int booted_ze(struct device *, void *);
187 static int booted_de(struct device *, void *);
188 static int booted_ni(struct device *, void *);
189 #if NSD > 0 || NCD > 0
190 static int booted_sd(struct device *, void *);
191 #endif
192 #if NRL > 0
193 static int booted_rl(struct device *, void *);
194 #endif
195 #if NRA
196 static int booted_ra(struct device *, void *);
197 #endif
198 #if NHP
199 static int booted_hp(struct device *, void *);
200 #endif
201 #if NRD
202 static int booted_rd(struct device *, void *);
203 #endif
204 
205 int (*devreg[])(struct device *, void *) = {
206 	booted_qe,
207 	booted_le,
208 	booted_ze,
209 	booted_de,
210 	booted_ni,
211 #if NSD > 0 || NCD > 0
212 	booted_sd,
213 #endif
214 #if NRL > 0
215 	booted_rl,
216 #endif
217 #if NRA
218 	booted_ra,
219 #endif
220 #if NHP
221 	booted_hp,
222 #endif
223 #if NRD
224 	booted_rd,
225 #endif
226 	0,
227 };
228 
229 #define	ubreg(x) ((x) & 017777)
230 
231 void
232 device_register(struct device *dev, void *aux)
233 {
234 	int (**dp)(struct device *, void *) = devreg;
235 
236 	/* If there's a synthetic RPB, we can't trust it */
237 	if (rpb.rpb_base == (void *)-1)
238 		return;
239 
240 	while (*dp) {
241 		if ((*dp)(dev, aux)) {
242 			booted_device = dev;
243 			break;
244 		}
245 		dp++;
246 	}
247 }
248 
249 /*
250  * Simple checks. Return 1 on fail.
251  */
252 int
253 jmfr(char *n, struct device *dev, int nr)
254 {
255 	if (rpb.devtyp != nr)
256 		return 1;
257 	return strcmp(n, dev->dv_cfdata->cf_driver->cd_name);
258 }
259 
260 #include <dev/qbus/ubavar.h>
261 int
262 ubtest(void *aux)
263 {
264 	paddr_t p;
265 
266 	p = kvtophys(((struct uba_attach_args *)aux)->ua_ioh);
267 	if (rpb.csrphy != p)
268 		return 1;
269 	return 0;
270 }
271 
272 #if 1 /* NNI */
273 #include <dev/bi/bivar.h>
274 int
275 booted_ni(struct device *dev, void *aux)
276 {
277 	struct bi_attach_args *ba = aux;
278 
279 	if (jmfr("ni", dev, BDEV_NI) || (kvtophys(ba->ba_ioh) != rpb.csrphy))
280 		return 0;
281 
282 	return 1;
283 }
284 #endif /* NNI */
285 
286 #if 1 /* NDE */
287 int
288 booted_de(struct device *dev, void *aux)
289 {
290 
291 	if (jmfr("de", dev, BDEV_DE) || ubtest(aux))
292 		return 0;
293 
294 	return 1;
295 }
296 #endif /* NDE */
297 
298 int
299 booted_le(struct device *dev, void *aux)
300 {
301 	if (jmfr("le", dev, BDEV_LE))
302 		return 0;
303 	return 1;
304 }
305 
306 int
307 booted_ze(struct device *dev, void *aux)
308 {
309 	if (jmfr("ze", dev, BDEV_ZE))
310 		return 0;
311 	return 1;
312 }
313 
314 #if 1 /* NQE */
315 int
316 booted_qe(struct device *dev, void *aux)
317 {
318 	if (jmfr("qe", dev, BDEV_QE) || ubtest(aux))
319 		return 0;
320 
321 	return 1;
322 }
323 #endif /* NQE */
324 
325 #if NSD > 0 || NCD > 0
326 #include <dev/scsipi/scsipi_all.h>
327 #include <dev/scsipi/scsipiconf.h>
328 int
329 booted_sd(struct device *dev, void *aux)
330 {
331 	struct scsipibus_attach_args *sa = aux;
332 	struct device *ppdev;
333 
334 	/* Is this a SCSI device? */
335 	if (jmfr("sd", dev, BDEV_SD) && jmfr("cd", dev, BDEV_SD))
336 		return 0;
337 
338 	if (sa->sa_periph->periph_channel->chan_bustype->bustype_type !=
339 	    SCSIPI_BUSTYPE_SCSI)
340 		return 0; /* ``Cannot happen'' */
341 
342 	if (sa->sa_periph->periph_target != rpb.unit)
343 		return 0; /* Wrong unit */
344 
345 	ppdev = dev->dv_parent->dv_parent;
346 
347 	/* VS3100 NCR 53C80 (si) & VS4000 NCR 53C94 (asc) */
348 	if (((jmfr("si",  ppdev, BDEV_SD) == 0) ||	/* new name */
349 	     (jmfr("asc", ppdev, BDEV_SD) == 0)) &&
350 	    (ppdev->dv_cfdata->cf_loc[0] == rpb.csrphy))
351 			return 1;
352 
353 	return 0; /* Where did we come from??? */
354 }
355 #endif
356 #if NRL > 0
357 #include <dev/qbus/rlvar.h>
358 int
359 booted_rl(struct device *dev, void *aux)
360 {
361 	struct rlc_attach_args *raa = aux;
362 	static int ub;
363 
364 	if (jmfr("rlc", dev, BDEV_RL) == 0)
365 		ub = ubtest(aux);
366 	if (ub)
367 		return 0;
368 	if (jmfr("rl", dev, BDEV_RL))
369 		return 0;
370 	if (raa->hwid != rpb.unit)
371 		return 0; /* Wrong unit number */
372 	return 1;
373 }
374 #endif
375 
376 #if NRA
377 #include <dev/mscp/mscp.h>
378 #include <dev/mscp/mscpreg.h>
379 #include <dev/mscp/mscpvar.h>
380 int
381 booted_ra(struct device *dev, void *aux)
382 {
383 	struct drive_attach_args *da = aux;
384 	struct mscp_softc *pdev = (void *)dev->dv_parent;
385 	paddr_t ioaddr;
386 
387 	if (jmfr("ra", dev, BDEV_UDA))
388 		return 0;
389 
390 	if (da->da_mp->mscp_unit != rpb.unit)
391 		return 0; /* Wrong unit number */
392 
393 	ioaddr = kvtophys(pdev->mi_iph); /* Get phys addr of CSR */
394 	if (rpb.devtyp == BDEV_UDA && rpb.csrphy == ioaddr)
395 		return 1; /* Did match CSR */
396 
397 	return 0;
398 }
399 #endif
400 #if NHP
401 #include <vax/mba/mbavar.h>
402 int
403 booted_hp(struct device *dev, void *aux)
404 {
405 	static int mbaaddr;
406 
407 	/* Save last adapter address */
408 	if (jmfr("mba", dev, BDEV_HP) == 0) {
409 		struct sbi_attach_args *sa = aux;
410 
411 		mbaaddr = kvtophys(sa->sa_ioh);
412 		return 0;
413 	}
414 
415 	if (jmfr("hp", dev, BDEV_HP))
416 		return 0;
417 
418 	if (((struct mba_attach_args *)aux)->ma_unit != rpb.unit)
419 		return 0;
420 
421 	if (mbaaddr != rpb.adpphy)
422 		return 0;
423 
424 	return 1;
425 }
426 #endif
427 #if NRD
428 int
429 booted_rd(struct device *dev, void *aux)
430 {
431 	int *nr = aux; /* XXX - use the correct attach struct */
432 
433 	if (jmfr("rd", dev, BDEV_RD))
434 		return 0;
435 
436 	if (*nr != rpb.unit)
437 		return 0;
438 
439 	return 1;
440 }
441 #endif
442