xref: /netbsd/sys/arch/vax/vax/autoconf.c (revision 99588b01)
1 /*	$NetBSD: autoconf.c,v 1.100 2022/03/03 06:28:26 riastradh 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.100 2022/03/03 06:28:26 riastradh Exp $");
30 
31 #include "opt_compat_netbsd.h"
32 #include "opt_cputype.h"
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/bus.h>
37 #include <sys/cpu.h>
38 #include <sys/device.h>
39 #include <sys/disk.h>
40 #include <sys/buf.h>
41 #include <sys/bufq.h>
42 #include <sys/conf.h>
43 #include <sys/malloc.h>
44 
45 #include <uvm/uvm_extern.h>
46 
47 #include <machine/sid.h>
48 #include <machine/nexus.h>
49 #include <machine/ioa.h>
50 #include <machine/ka820.h>
51 #include <machine/ka750.h>
52 #include <machine/ka650.h>
53 #include <machine/clock.h>
54 #include <machine/rpb.h>
55 #include <machine/mainbus.h>
56 
57 #include <vax/vax/gencons.h>
58 
59 #include <dev/bi/bireg.h>
60 
61 #include "locators.h"
62 #include "ioconf.h"
63 
64 void	gencnslask(void);
65 
66 const struct cpu_dep *dep_call;
67 
68 #define MAINBUS	0
69 
70 void
cpu_configure(void)71 cpu_configure(void)
72 {
73 
74 	if (config_rootfound("mainbus", NULL) == NULL)
75 		panic("mainbus not configured");
76 
77 	/*
78 	 * We're ready to start up. Clear CPU cold start flag.
79 	 * Soft cold-start flag will be cleared in configure().
80 	 */
81 	if (dep_call->cpu_clrf)
82 		(*dep_call->cpu_clrf)();
83 }
84 
85 void
cpu_rootconf(void)86 cpu_rootconf(void)
87 {
88 	/*
89 	 * The device we booted from are looked for during autoconfig.
90 	 * If there has been a match, it's already been done.
91 	 */
92 
93 #ifdef DEBUG
94 	printf("booted from type %d unit %d csr 0x%lx adapter %lx slave %d\n",
95 	    rpb.devtyp, rpb.unit, rpb.csrphy, rpb.adpphy, rpb.slave);
96 #endif
97 	printf("boot device: %s\n",
98 	    booted_device ? device_xname(booted_device) : "<unknown>");
99 
100 	rootconf();
101 }
102 
103 static int	mainbus_print(void *, const char *);
104 static int	mainbus_match(device_t, cfdata_t, void *);
105 static void	mainbus_attach(device_t, device_t, void *);
106 
107 extern struct vax_bus_space vax_mem_bus_space;
108 extern struct vax_bus_dma_tag vax_bus_dma_tag;
109 
110 int
mainbus_print(void * aux,const char * name)111 mainbus_print(void *aux, const char *name)
112 {
113 	struct mainbus_attach_args * const ma = aux;
114 	if (name) {
115 		aprint_naive("%s at %s", ma->ma_type, name);
116 		aprint_normal("%s at %s", ma->ma_type, name);
117         }
118 	return UNCONF;
119 }
120 
121 int
mainbus_match(device_t parent,cfdata_t cf,void * aux)122 mainbus_match(device_t parent, cfdata_t cf, void *aux)
123 {
124 	return 1; /* First (and only) mainbus */
125 }
126 
127 void
mainbus_attach(device_t parent,device_t self,void * aux)128 mainbus_attach(device_t parent, device_t self, void *aux)
129 {
130 	struct mainbus_attach_args ma;
131 	const char * const * devp;
132 
133 	aprint_naive("\n");
134 	aprint_normal("\n");
135 
136 	for (devp = dep_call->cpu_devs; *devp != NULL; devp++) {
137 		ma.ma_type = *devp;
138 		ma.ma_iot = &vax_mem_bus_space;
139 		ma.ma_dmat = &vax_bus_dma_tag;
140 		config_found(self, &ma, mainbus_print, CFARGS_NONE);
141 	}
142 
143 	/*
144 	 * Hopefully there a master bus?
145 	 * Maybe should have this as master instead of mainbus.
146 	 */
147 
148 #if defined(COMPAT_14)
149 	if (rpb.rpb_base == (void *)-1)
150 		printf("\nWARNING: you must update your boot blocks.\n\n");
151 #endif
152 
153 }
154 
155 CFATTACH_DECL_NEW(mainbus, 0,
156     mainbus_match, mainbus_attach, NULL, NULL);
157 
158 static int	cpu_mainbus_match(device_t, cfdata_t, void *);
159 static void	cpu_mainbus_attach(device_t, device_t, void *);
160 
161 int
cpu_mainbus_match(device_t self,cfdata_t cf,void * aux)162 cpu_mainbus_match(device_t self, cfdata_t cf, void *aux)
163 {
164 	struct mainbus_attach_args *ma = aux;
165 
166 	return strcmp(cpu_cd.cd_name, ma->ma_type) == 0;
167 }
168 
169 void
cpu_mainbus_attach(device_t parent,device_t self,void * aux)170 cpu_mainbus_attach(device_t parent, device_t self, void *aux)
171 {
172 	struct cpu_info *ci;
173 
174 	KASSERT(device_private(self) == NULL);
175 	ci = curcpu();
176 	device_set_private(self, ci);
177 	ci->ci_dev = self;
178 	ci->ci_cpuid = device_unit(self);
179 
180 	if (dep_call->cpu_attach_cpu != NULL)
181 		(*dep_call->cpu_attach_cpu)(self);
182 	else if (ci->ci_cpustr) {
183 		aprint_naive(": %s\n", ci->ci_cpustr);
184 		aprint_normal(": %s\n", ci->ci_cpustr);
185         } else {
186 		aprint_naive("\n");
187 		aprint_normal("\n");
188         }
189 }
190 
191 CFATTACH_DECL_NEW(cpu_mainbus, 0,
192     cpu_mainbus_match, cpu_mainbus_attach, NULL, NULL);
193 
194 #include "sd.h"
195 #include "cd.h"
196 #include "rl.h"
197 #include "ra.h"
198 #include "hp.h"
199 #include "ry.h"
200 
201 static int ubtest(void *);
202 static int jmfr(const char *, device_t, int);
203 static int booted_qe(device_t, void *);
204 static int booted_qt(device_t, void *);
205 static int booted_le(device_t, void *);
206 static int booted_ze(device_t, void *);
207 static int booted_de(device_t, void *);
208 static int booted_ni(device_t, void *);
209 #if NSD > 0 || NCD > 0
210 static int booted_sd(device_t, void *);
211 #endif
212 #if NRL > 0
213 static int booted_rl(device_t, void *);
214 #endif
215 #if NRA > 0 || NRACD > 0
216 static int booted_ra(device_t, void *);
217 #endif
218 #if NHP
219 static int booted_hp(device_t, void *);
220 #endif
221 #if NRD
222 static int booted_rd(device_t, void *);
223 #endif
224 
225 int (* const devreg[])(device_t, void *) = {
226 	booted_qe,
227 	booted_qt,
228 	booted_le,
229 	booted_ze,
230 	booted_de,
231 	booted_ni,
232 #if NSD > 0 || NCD > 0
233 	booted_sd,
234 #endif
235 #if NRL > 0
236 	booted_rl,
237 #endif
238 #if NRA
239 	booted_ra,
240 #endif
241 #if NHP
242 	booted_hp,
243 #endif
244 #if NRD
245 	booted_rd,
246 #endif
247 	0,
248 };
249 
250 #define	ubreg(x) ((x) & 017777)
251 
252 void
device_register(device_t dev,void * aux)253 device_register(device_t dev, void *aux)
254 {
255 	int (* const * dp)(device_t, void *) = devreg;
256 
257 	/* If there's a synthetic RPB, we can't trust it */
258 	if (rpb.rpb_base == (void *)-1)
259 		return;
260 
261 	while (*dp) {
262 		if ((**dp)(dev, aux)) {
263 			booted_device = dev;
264 			break;
265 		}
266 		dp++;
267 	}
268 }
269 
270 /*
271  * Simple checks. Return 1 on fail.
272  */
273 int
jmfr(const char * n,device_t dev,int nr)274 jmfr(const char *n, device_t dev, int nr)
275 {
276 	if (rpb.devtyp != nr)
277 		return 1;
278 	return !device_is_a(dev, n);
279 }
280 
281 #include <dev/qbus/ubavar.h>
282 int
ubtest(void * aux)283 ubtest(void *aux)
284 {
285 	paddr_t p;
286 
287 	p = kvtophys(((struct uba_attach_args *)aux)->ua_ioh);
288 	if (rpb.csrphy != p)
289 		return 1;
290 	return 0;
291 }
292 
293 #if 1 /* NNI */
294 #include <dev/bi/bivar.h>
295 int
booted_ni(device_t dev,void * aux)296 booted_ni(device_t dev, void *aux)
297 {
298 	struct bi_attach_args *ba = aux;
299 
300 	if (jmfr("ni", dev, BDEV_NI) || (kvtophys(ba->ba_ioh) != rpb.csrphy))
301 		return 0;
302 
303 	return 1;
304 }
305 #endif /* NNI */
306 
307 #if 1 /* NDE */
308 int
booted_de(device_t dev,void * aux)309 booted_de(device_t dev, void *aux)
310 {
311 
312 	if (jmfr("de", dev, BDEV_DE) || ubtest(aux))
313 		return 0;
314 
315 	return 1;
316 }
317 #endif /* NDE */
318 
319 int
booted_le(device_t dev,void * aux)320 booted_le(device_t dev, void *aux)
321 {
322 	if (jmfr("le", dev, BDEV_LE))
323 		return 0;
324 	return 1;
325 }
326 
327 int
booted_ze(device_t dev,void * aux)328 booted_ze(device_t dev, void *aux)
329 {
330 	if (jmfr("ze", dev, BDEV_ZE))
331 		return 0;
332 	return 1;
333 }
334 
335 int
booted_qt(device_t dev,void * aux)336 booted_qt(device_t dev, void *aux)
337 {
338 	if (jmfr("qt", dev, BDEV_QE) || ubtest(aux))
339 		return 0;
340 
341 	return 1;
342 }
343 
344 #if 1 /* NQE */
345 int
booted_qe(device_t dev,void * aux)346 booted_qe(device_t dev, void *aux)
347 {
348 	if (jmfr("qe", dev, BDEV_QE) || ubtest(aux))
349 		return 0;
350 
351 	return 1;
352 }
353 #endif /* NQE */
354 
355 #if NSD > 0 || NCD > 0
356 #include <dev/scsipi/scsipi_all.h>
357 #include <dev/scsipi/scsipiconf.h>
358 int
booted_sd(device_t dev,void * aux)359 booted_sd(device_t dev, void *aux)
360 {
361 	struct scsipibus_attach_args *sa = aux;
362 	device_t ppdev;
363 
364 	/* Is this a SCSI device? */
365 	if (jmfr("sd", dev, BDEV_SD) && jmfr("sd", dev, BDEV_SDN) &&
366 	    jmfr("cd", dev, BDEV_SD) && jmfr("cd", dev, BDEV_SDN))
367 		return 0;
368 
369 	if (sa->sa_periph->periph_channel->chan_bustype->bustype_type !=
370 	    SCSIPI_BUSTYPE_SCSI)
371 		return 0; /* ``Cannot happen'' */
372 
373 	if (sa->sa_periph->periph_target != (rpb.unit/100) ||
374 	    sa->sa_periph->periph_lun != (rpb.unit % 100))
375 		return 0; /* Wrong unit */
376 
377 	ppdev = device_parent(device_parent(dev));
378 
379 	/* VS3100 NCR 53C80 (si) & VS4000 NCR 53C94 (asc) */
380 	if ((jmfr("si",  ppdev, BDEV_SD) == 0 ||	/* new name */
381 	     jmfr("asc", ppdev, BDEV_SD) == 0 ||
382 	     jmfr("asc", ppdev, BDEV_SDN) == 0) &&
383 	    (device_cfdata(ppdev)->cf_loc[VSBUSCF_CSR] == rpb.csrphy))
384 			return 1;
385 
386 	return 0; /* Where did we come from??? */
387 }
388 #endif
389 #if NRL > 0
390 #include <dev/qbus/rlvar.h>
391 int
booted_rl(device_t dev,void * aux)392 booted_rl(device_t dev, void *aux)
393 {
394 	struct rlc_attach_args *raa = aux;
395 	static int ub;
396 
397 	if (jmfr("rlc", dev, BDEV_RL) == 0)
398 		ub = ubtest(aux);
399 	if (ub)
400 		return 0;
401 	if (jmfr("rl", dev, BDEV_RL))
402 		return 0;
403 	if (raa->hwid != rpb.unit)
404 		return 0; /* Wrong unit number */
405 	return 1;
406 }
407 #endif
408 
409 #if NRA > 0 || NRACD > 0
410 #include <dev/mscp/mscp.h>
411 #include <dev/mscp/mscpreg.h>
412 #include <dev/mscp/mscpvar.h>
413 int
booted_ra(device_t dev,void * aux)414 booted_ra(device_t dev, void *aux)
415 {
416 	struct drive_attach_args *da = aux;
417 	struct mscp_softc *pdev = device_private(device_parent(dev));
418 	paddr_t ioaddr;
419 
420 	if (jmfr("ra", dev, BDEV_UDA) && jmfr("racd", dev, BDEV_UDA))
421 		return 0;
422 
423 	if (da->da_mp->mscp_unit != rpb.unit)
424 		return 0; /* Wrong unit number */
425 
426 	ioaddr = kvtophys(pdev->mi_iph); /* Get phys addr of CSR */
427 	if (rpb.devtyp == BDEV_UDA && rpb.csrphy == ioaddr)
428 		return 1; /* Did match CSR */
429 
430 	return 0;
431 }
432 #endif
433 
434 #if NHP
435 #include <vax/mba/mbavar.h>
436 int
booted_hp(device_t dev,void * aux)437 booted_hp(device_t dev, void *aux)
438 {
439 	static int mbaaddr;
440 
441 	/* Save last adapter address */
442 	if (jmfr("mba", dev, BDEV_HP) == 0) {
443 		struct sbi_attach_args *sa = aux;
444 
445 		mbaaddr = kvtophys(sa->sa_ioh);
446 		return 0;
447 	}
448 
449 	if (jmfr("hp", dev, BDEV_HP))
450 		return 0;
451 
452 	if (((struct mba_attach_args *)aux)->ma_unit != rpb.unit)
453 		return 0;
454 
455 	if (mbaaddr != rpb.adpphy)
456 		return 0;
457 
458 	return 1;
459 }
460 #endif
461 #if NRD
462 int
booted_rd(device_t dev,void * aux)463 booted_rd(device_t dev, void *aux)
464 {
465 	int *nr = aux; /* XXX - use the correct attach struct */
466 
467 	if (jmfr("rd", dev, BDEV_RD))
468 		return 0;
469 
470 	if (*nr != rpb.unit)
471 		return 0;
472 
473 	return 1;
474 }
475 #endif
476