xref: /netbsd-src/sys/arch/next68k/next68k/autoconf.c (revision 21e37cc72a480a47828990a439cde7ac9ffaf0c6)
1 /*	$NetBSD: autoconf.c,v 1.14 2003/08/07 16:28:55 agc Exp $	*/
2 
3 /*
4  * Copyright (c) 1982, 1986, 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.36 92/12/20$
36  *
37  *	@(#)autoconf.c  8.2 (Berkeley) 1/12/94
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.36 92/12/20$
75  *
76  *	@(#)autoconf.c  8.2 (Berkeley) 1/12/94
77  */
78 
79 /*
80  * Setup the system to run on the current machine.
81  *
82  * Configure() is called at boot time.  Available
83  * devices are determined (from possibilities mentioned in ioconf.c),
84  * and the drivers are initialized.
85  */
86 
87 #include <sys/cdefs.h>
88 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.14 2003/08/07 16:28:55 agc Exp $");
89 
90 #include <sys/param.h>
91 #include <sys/systm.h>
92 #include <sys/buf.h>
93 #include <sys/conf.h>
94 #include <sys/reboot.h>
95 #include <sys/device.h>
96 
97 #include <machine/vmparam.h>
98 #include <machine/autoconf.h>
99 #include <machine/disklabel.h>
100 #include <machine/cpu.h>
101 #include <machine/pte.h>
102 
103 #include <next68k/next68k/isr.h>
104 #include <next68k/next68k/nextrom.h>
105 
106 #include <next68k/dev/intiovar.h>
107 
108 struct device *booted_device;	/* boot device */
109 volatile u_long *intrstat;
110 volatile u_long *intrmask;
111 
112 static struct device *getdevunit __P((char *, int));
113 static int devidentparse __P((const char *, int *, int *, int *));
114 static int atoi __P((const char *));
115 
116 struct device_equiv {
117 	char *alias;
118 	char *real;
119 };
120 static struct device_equiv device_equiv[] = {
121 	{ "en", "xe" },
122 	{ "tp", "xe" },
123 };
124 static int ndevice_equivs = (sizeof(device_equiv)/sizeof(device_equiv[0]));
125 
126 /*
127  * Determine mass storage and memory configuration for a machine.
128  */
129 void
130 cpu_configure()
131 {
132 /* 	int dma_rev; */
133 	extern u_int rom_intrmask;
134 	extern u_int rom_intrstat;
135 
136 	booted_device = NULL;	/* set by device drivers (if found) */
137 
138 #if 0
139 	dma_rev = ((volatile u_char *)IIOV(NEXT_P_SCR1))[1];
140 	switch (dma_rev) {
141 	case 0:
142 		intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK_0);
143 		intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT_0);
144 		/* dspreg = (volatile u_long *)IIOV(0x2007000); */
145 		break;
146 	case 1:
147 		intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK);
148 		intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT);
149 		/* dspreg = (volatile u_long *)IIOV(0x2108000); */
150 		break;
151 	default:
152 		panic("unknown DMA chip revision");
153 	}
154 #else
155 	intrmask = (volatile u_long *)IIOV(rom_intrmask);
156 	intrstat = (volatile u_long *)IIOV(rom_intrstat);
157 	printf ("intrmask: %p\n", intrmask);
158 	printf ("intrstat: %p\n", intrstat);
159 #endif
160 
161 	INTR_SETMASK(0);
162 
163 	init_sir();
164 
165 	if (config_rootfound("mainbus", NULL) == NULL)
166 		panic("autoconfig failed, no root");
167 
168 	/* Turn on interrupts */
169 	spl0();
170 }
171 
172 void
173 cpu_rootconf()
174 {
175 	int count, lun, part;
176 
177 	count = lun = part = 0;
178 
179 	devidentparse (rom_boot_info, &count, &lun, &part);
180 	booted_device = getdevunit (rom_boot_dev, count);
181 
182 	printf("boot device: %s\n",
183 		(booted_device) ? booted_device->dv_xname : "<unknown>");
184 
185 	setroot(booted_device, part);
186 }
187 
188 /*
189  * find a device matching "name" and unit number
190  */
191 static struct device *
192 getdevunit(name, unit)
193 	char *name;
194 	int unit;
195 {
196 	struct device *dev = alldevs.tqh_first;
197 	char num[10], fullname[16];
198 	int lunit;
199 	int i;
200 
201 	for (i = 0; i < ndevice_equivs; i++)
202 		if (device_equiv->alias && strcmp (name, device_equiv->alias) == 0)
203 			name = device_equiv->real;
204 
205 	/* compute length of name and decimal expansion of unit number */
206 	sprintf(num, "%d", unit);
207 	lunit = strlen(num);
208 	if (strlen(name) + lunit >= sizeof(fullname) - 1)
209 		panic("config_attach: device name too long");
210 
211 	strcpy(fullname, name);
212 	strcat(fullname, num);
213 
214 	while (strcmp(dev->dv_xname, fullname) != 0) {
215 		if ((dev = dev->dv_list.tqe_next) == NULL)
216 			return NULL;
217 	}
218 	return dev;
219 }
220 
221 /*
222  * Parse a device ident.
223  *
224  * Format:
225  *   (count, lun, part)
226  */
227 static int
228 devidentparse(spec, count, lun, part)
229 	const char *spec;
230 	int *count;
231 	int *lun;
232 	int *part;
233 {
234 	int i;
235 	const char *args[3];
236 
237 	if (*spec == '(') {
238 		/* tokenize device ident */
239 		args[0] = ++spec;
240 		for (i = 1; *spec && *spec != ')' && i<3; spec++) {
241 			if (*spec == ',')
242 				args[i++] = ++spec;
243 		}
244 		if (*spec != ')')
245 			goto baddev;
246 
247 		switch(i) {
248 		case 3:
249 			*count  = atoi(args[0]);
250 			*lun  = atoi(args[1]);
251 			*part  = atoi(args[2]);
252 			break;
253 		case 2:
254 			*lun  = atoi(args[0]);
255 			*part  = atoi(args[1]);
256 			break;
257 		case 1:
258 			*part  = atoi(args[0]);
259 			break;
260 		case 0:
261 			break;
262 		}
263 	}
264 	else
265 		goto baddev;
266 
267 	return 0;
268 
269  baddev:
270 	return ENXIO;
271 }
272 
273 static int
274 atoi(s)
275 	const char *s;
276 {
277 	int val = 0;
278 
279 	while(isdigit(*s))
280 		val = val * 10 + (*s++ - '0');
281 	return val;
282 }
283