autoconf.c revision 1.14 1 1.14 agc /* $NetBSD: autoconf.c,v 1.14 2003/08/07 16:28:55 agc Exp $ */
2 1.1 dbj
3 1.1 dbj /*
4 1.1 dbj * Copyright (c) 1982, 1986, 1990, 1993
5 1.1 dbj * The Regents of the University of California. All rights reserved.
6 1.1 dbj *
7 1.1 dbj * This code is derived from software contributed to Berkeley by
8 1.1 dbj * the Systems Programming Group of the University of Utah Computer
9 1.1 dbj * Science Department.
10 1.1 dbj *
11 1.1 dbj * Redistribution and use in source and binary forms, with or without
12 1.1 dbj * modification, are permitted provided that the following conditions
13 1.1 dbj * are met:
14 1.1 dbj * 1. Redistributions of source code must retain the above copyright
15 1.1 dbj * notice, this list of conditions and the following disclaimer.
16 1.1 dbj * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 dbj * notice, this list of conditions and the following disclaimer in the
18 1.1 dbj * documentation and/or other materials provided with the distribution.
19 1.14 agc * 3. Neither the name of the University nor the names of its contributors
20 1.14 agc * may be used to endorse or promote products derived from this software
21 1.14 agc * without specific prior written permission.
22 1.14 agc *
23 1.14 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.14 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.14 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.14 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.14 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.14 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.14 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.14 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.14 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.14 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.14 agc * SUCH DAMAGE.
34 1.14 agc *
35 1.14 agc * from: Utah $Hdr: autoconf.c 1.36 92/12/20$
36 1.14 agc *
37 1.14 agc * @(#)autoconf.c 8.2 (Berkeley) 1/12/94
38 1.14 agc */
39 1.14 agc /*
40 1.14 agc * Copyright (c) 1988 University of Utah.
41 1.14 agc *
42 1.14 agc * This code is derived from software contributed to Berkeley by
43 1.14 agc * the Systems Programming Group of the University of Utah Computer
44 1.14 agc * Science Department.
45 1.14 agc *
46 1.14 agc * Redistribution and use in source and binary forms, with or without
47 1.14 agc * modification, are permitted provided that the following conditions
48 1.14 agc * are met:
49 1.14 agc * 1. Redistributions of source code must retain the above copyright
50 1.14 agc * notice, this list of conditions and the following disclaimer.
51 1.14 agc * 2. Redistributions in binary form must reproduce the above copyright
52 1.14 agc * notice, this list of conditions and the following disclaimer in the
53 1.14 agc * documentation and/or other materials provided with the distribution.
54 1.1 dbj * 3. All advertising materials mentioning features or use of this software
55 1.1 dbj * must display the following acknowledgement:
56 1.1 dbj * This product includes software developed by the University of
57 1.1 dbj * California, Berkeley and its contributors.
58 1.1 dbj * 4. Neither the name of the University nor the names of its contributors
59 1.1 dbj * may be used to endorse or promote products derived from this software
60 1.1 dbj * without specific prior written permission.
61 1.1 dbj *
62 1.1 dbj * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 1.1 dbj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 1.1 dbj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 1.1 dbj * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 1.1 dbj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 1.1 dbj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 1.1 dbj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 1.1 dbj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 1.1 dbj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 1.1 dbj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 1.1 dbj * SUCH DAMAGE.
73 1.1 dbj *
74 1.1 dbj * from: Utah $Hdr: autoconf.c 1.36 92/12/20$
75 1.1 dbj *
76 1.1 dbj * @(#)autoconf.c 8.2 (Berkeley) 1/12/94
77 1.1 dbj */
78 1.1 dbj
79 1.1 dbj /*
80 1.1 dbj * Setup the system to run on the current machine.
81 1.1 dbj *
82 1.1 dbj * Configure() is called at boot time. Available
83 1.1 dbj * devices are determined (from possibilities mentioned in ioconf.c),
84 1.1 dbj * and the drivers are initialized.
85 1.1 dbj */
86 1.13 lukem
87 1.13 lukem #include <sys/cdefs.h>
88 1.14 agc __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.14 2003/08/07 16:28:55 agc Exp $");
89 1.1 dbj
90 1.1 dbj #include <sys/param.h>
91 1.1 dbj #include <sys/systm.h>
92 1.1 dbj #include <sys/buf.h>
93 1.1 dbj #include <sys/conf.h>
94 1.1 dbj #include <sys/reboot.h>
95 1.1 dbj #include <sys/device.h>
96 1.1 dbj
97 1.1 dbj #include <machine/vmparam.h>
98 1.1 dbj #include <machine/autoconf.h>
99 1.1 dbj #include <machine/disklabel.h>
100 1.1 dbj #include <machine/cpu.h>
101 1.1 dbj #include <machine/pte.h>
102 1.1 dbj
103 1.1 dbj #include <next68k/next68k/isr.h>
104 1.8 christos #include <next68k/next68k/nextrom.h>
105 1.1 dbj
106 1.9 mycroft #include <next68k/dev/intiovar.h>
107 1.9 mycroft
108 1.1 dbj struct device *booted_device; /* boot device */
109 1.9 mycroft volatile u_long *intrstat;
110 1.9 mycroft volatile u_long *intrmask;
111 1.1 dbj
112 1.8 christos static struct device *getdevunit __P((char *, int));
113 1.8 christos static int devidentparse __P((const char *, int *, int *, int *));
114 1.8 christos static int atoi __P((const char *));
115 1.8 christos
116 1.8 christos struct device_equiv {
117 1.8 christos char *alias;
118 1.8 christos char *real;
119 1.8 christos };
120 1.8 christos static struct device_equiv device_equiv[] = {
121 1.8 christos { "en", "xe" },
122 1.8 christos { "tp", "xe" },
123 1.8 christos };
124 1.8 christos static int ndevice_equivs = (sizeof(device_equiv)/sizeof(device_equiv[0]));
125 1.8 christos
126 1.1 dbj /*
127 1.1 dbj * Determine mass storage and memory configuration for a machine.
128 1.1 dbj */
129 1.1 dbj void
130 1.6 thorpej cpu_configure()
131 1.1 dbj {
132 1.9 mycroft /* int dma_rev; */
133 1.9 mycroft extern u_int rom_intrmask;
134 1.9 mycroft extern u_int rom_intrstat;
135 1.1 dbj
136 1.1 dbj booted_device = NULL; /* set by device drivers (if found) */
137 1.9 mycroft
138 1.9 mycroft #if 0
139 1.9 mycroft dma_rev = ((volatile u_char *)IIOV(NEXT_P_SCR1))[1];
140 1.9 mycroft switch (dma_rev) {
141 1.9 mycroft case 0:
142 1.9 mycroft intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK_0);
143 1.9 mycroft intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT_0);
144 1.9 mycroft /* dspreg = (volatile u_long *)IIOV(0x2007000); */
145 1.9 mycroft break;
146 1.9 mycroft case 1:
147 1.9 mycroft intrmask = (volatile u_long *)IIOV(NEXT_P_INTRMASK);
148 1.9 mycroft intrstat = (volatile u_long *)IIOV(NEXT_P_INTRSTAT);
149 1.9 mycroft /* dspreg = (volatile u_long *)IIOV(0x2108000); */
150 1.9 mycroft break;
151 1.9 mycroft default:
152 1.11 wiz panic("unknown DMA chip revision");
153 1.9 mycroft }
154 1.9 mycroft #else
155 1.9 mycroft intrmask = (volatile u_long *)IIOV(rom_intrmask);
156 1.9 mycroft intrstat = (volatile u_long *)IIOV(rom_intrstat);
157 1.9 mycroft printf ("intrmask: %p\n", intrmask);
158 1.9 mycroft printf ("intrstat: %p\n", intrstat);
159 1.9 mycroft #endif
160 1.1 dbj
161 1.2 dbj INTR_SETMASK(0);
162 1.1 dbj
163 1.1 dbj init_sir();
164 1.1 dbj
165 1.1 dbj if (config_rootfound("mainbus", NULL) == NULL)
166 1.1 dbj panic("autoconfig failed, no root");
167 1.1 dbj
168 1.2 dbj /* Turn on interrupts */
169 1.2 dbj spl0();
170 1.1 dbj }
171 1.1 dbj
172 1.1 dbj void
173 1.1 dbj cpu_rootconf()
174 1.1 dbj {
175 1.8 christos int count, lun, part;
176 1.8 christos
177 1.8 christos count = lun = part = 0;
178 1.8 christos
179 1.8 christos devidentparse (rom_boot_info, &count, &lun, &part);
180 1.8 christos booted_device = getdevunit (rom_boot_dev, count);
181 1.8 christos
182 1.1 dbj printf("boot device: %s\n",
183 1.1 dbj (booted_device) ? booted_device->dv_xname : "<unknown>");
184 1.1 dbj
185 1.8 christos setroot(booted_device, part);
186 1.1 dbj }
187 1.1 dbj
188 1.1 dbj /*
189 1.1 dbj * find a device matching "name" and unit number
190 1.1 dbj */
191 1.8 christos static struct device *
192 1.1 dbj getdevunit(name, unit)
193 1.1 dbj char *name;
194 1.1 dbj int unit;
195 1.1 dbj {
196 1.1 dbj struct device *dev = alldevs.tqh_first;
197 1.1 dbj char num[10], fullname[16];
198 1.1 dbj int lunit;
199 1.8 christos int i;
200 1.8 christos
201 1.8 christos for (i = 0; i < ndevice_equivs; i++)
202 1.8 christos if (device_equiv->alias && strcmp (name, device_equiv->alias) == 0)
203 1.8 christos name = device_equiv->real;
204 1.1 dbj
205 1.1 dbj /* compute length of name and decimal expansion of unit number */
206 1.1 dbj sprintf(num, "%d", unit);
207 1.1 dbj lunit = strlen(num);
208 1.1 dbj if (strlen(name) + lunit >= sizeof(fullname) - 1)
209 1.1 dbj panic("config_attach: device name too long");
210 1.1 dbj
211 1.1 dbj strcpy(fullname, name);
212 1.1 dbj strcat(fullname, num);
213 1.1 dbj
214 1.1 dbj while (strcmp(dev->dv_xname, fullname) != 0) {
215 1.1 dbj if ((dev = dev->dv_list.tqe_next) == NULL)
216 1.1 dbj return NULL;
217 1.1 dbj }
218 1.1 dbj return dev;
219 1.1 dbj }
220 1.2 dbj
221 1.8 christos /*
222 1.8 christos * Parse a device ident.
223 1.8 christos *
224 1.8 christos * Format:
225 1.8 christos * (count, lun, part)
226 1.8 christos */
227 1.8 christos static int
228 1.8 christos devidentparse(spec, count, lun, part)
229 1.8 christos const char *spec;
230 1.8 christos int *count;
231 1.8 christos int *lun;
232 1.8 christos int *part;
233 1.8 christos {
234 1.8 christos int i;
235 1.8 christos const char *args[3];
236 1.8 christos
237 1.8 christos if (*spec == '(') {
238 1.8 christos /* tokenize device ident */
239 1.8 christos args[0] = ++spec;
240 1.8 christos for (i = 1; *spec && *spec != ')' && i<3; spec++) {
241 1.8 christos if (*spec == ',')
242 1.8 christos args[i++] = ++spec;
243 1.8 christos }
244 1.8 christos if (*spec != ')')
245 1.8 christos goto baddev;
246 1.8 christos
247 1.8 christos switch(i) {
248 1.8 christos case 3:
249 1.8 christos *count = atoi(args[0]);
250 1.8 christos *lun = atoi(args[1]);
251 1.8 christos *part = atoi(args[2]);
252 1.8 christos break;
253 1.8 christos case 2:
254 1.8 christos *lun = atoi(args[0]);
255 1.8 christos *part = atoi(args[1]);
256 1.8 christos break;
257 1.8 christos case 1:
258 1.8 christos *part = atoi(args[0]);
259 1.8 christos break;
260 1.8 christos case 0:
261 1.8 christos break;
262 1.8 christos }
263 1.8 christos }
264 1.8 christos else
265 1.8 christos goto baddev;
266 1.8 christos
267 1.8 christos return 0;
268 1.8 christos
269 1.8 christos baddev:
270 1.8 christos return ENXIO;
271 1.8 christos }
272 1.8 christos
273 1.8 christos static int
274 1.8 christos atoi(s)
275 1.8 christos const char *s;
276 1.8 christos {
277 1.8 christos int val = 0;
278 1.8 christos
279 1.8 christos while(isdigit(*s))
280 1.8 christos val = val * 10 + (*s++ - '0');
281 1.8 christos return val;
282 1.8 christos }
283