autoconf.c revision 1.22 1 /* $NetBSD: autoconf.c,v 1.22 2008/02/12 17:30:58 joerg 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.22 2008/02/12 17:30:58 joerg 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 volatile u_long *intrstat;
109 volatile u_long *intrmask;
110
111 static struct device *getdevunit(const char *, int);
112 static int devidentparse(const char *, int *, int *, int *);
113 static int atoi(const char *);
114
115 struct device_equiv {
116 const char *alias;
117 const char *real;
118 };
119 static struct device_equiv device_equiv[] = {
120 { "en", "xe" },
121 { "tp", "xe" },
122 };
123 static int ndevice_equivs = (sizeof(device_equiv)/sizeof(device_equiv[0]));
124
125 /*
126 * Determine mass storage and memory configuration for a machine.
127 */
128 void
129 cpu_configure(void)
130 {
131 /* int dma_rev; */
132 extern u_int rom_intrmask;
133 extern u_int rom_intrstat;
134
135 booted_device = NULL; /* set by device drivers (if found) */
136
137 #if 0
138 dma_rev = ((volatile u_char *)IIOV(NEXT_P_SCR1))[1];
139 switch (dma_rev) {
140 case 0:
141 intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK_0);
142 intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT_0);
143 /* dspreg = (volatile u_long *)IIOV(0x2007000); */
144 break;
145 case 1:
146 intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK);
147 intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT);
148 /* dspreg = (volatile u_long *)IIOV(0x2108000); */
149 break;
150 default:
151 panic("unknown DMA chip revision");
152 }
153 #else
154 intrmask = (volatile u_long *)IIOV(rom_intrmask);
155 intrstat = (volatile u_long *)IIOV(rom_intrstat);
156 printf ("intrmask: %p\n", intrmask);
157 printf ("intrstat: %p\n", intrstat);
158 #endif
159
160 INTR_SETMASK(0);
161
162 if (config_rootfound("mainbus", NULL) == NULL)
163 panic("autoconfig failed, no root");
164
165 /* Turn on interrupts */
166 spl0();
167 }
168
169 void
170 cpu_rootconf(void)
171 {
172 int count, lun, part;
173
174 count = lun = part = 0;
175
176 devidentparse (rom_boot_info, &count, &lun, &part);
177 booted_device = getdevunit (rom_boot_dev, count);
178
179 printf("boot device: %s\n",
180 (booted_device) ? booted_device->dv_xname : "<unknown>");
181
182 setroot(booted_device, part);
183 }
184
185 /*
186 * find a device matching "name" and unit number
187 */
188 static struct device *
189 getdevunit(const char *name, int unit)
190 {
191 device_t dv;
192 int i;
193
194 for (i = 0; i < ndevice_equivs; i++)
195 if (device_equiv->alias && strcmp (name, device_equiv->alias) == 0)
196 name = device_equiv->real;
197
198 return device_find_by_driver_unit(name, unit);
199 }
200
201 /*
202 * Parse a device ident.
203 *
204 * Format:
205 * (count, lun, part)
206 */
207 static int
208 devidentparse(const char *spec, int *count, int *lun, int *part)
209 {
210 int i;
211 const char *args[3];
212
213 if (*spec == '(') {
214 /* tokenize device ident */
215 args[0] = ++spec;
216 for (i = 1; *spec && *spec != ')' && i<3; spec++) {
217 if (*spec == ',')
218 args[i++] = ++spec;
219 }
220 if (*spec != ')')
221 goto baddev;
222
223 switch(i) {
224 case 3:
225 *count = atoi(args[0]);
226 *lun = atoi(args[1]);
227 *part = atoi(args[2]);
228 break;
229 case 2:
230 *lun = atoi(args[0]);
231 *part = atoi(args[1]);
232 break;
233 case 1:
234 *part = atoi(args[0]);
235 break;
236 case 0:
237 break;
238 }
239 }
240 else
241 goto baddev;
242
243 return 0;
244
245 baddev:
246 return ENXIO;
247 }
248
249 static int
250 atoi(const char *s)
251 {
252 int val = 0;
253
254 while(isdigit(*s))
255 val = val * 10 + (*s++ - '0');
256 return val;
257 }
258