autoconf.c revision 1.2 1 1.2 dbj /* $NetBSD: autoconf.c,v 1.2 1998/11/10 22:45:44 dbj Exp $ */
2 1.1 dbj
3 1.1 dbj /*
4 1.1 dbj * Copyright (c) 1988 University of Utah.
5 1.1 dbj * Copyright (c) 1982, 1986, 1990, 1993
6 1.1 dbj * The Regents of the University of California. All rights reserved.
7 1.1 dbj *
8 1.1 dbj * This code is derived from software contributed to Berkeley by
9 1.1 dbj * the Systems Programming Group of the University of Utah Computer
10 1.1 dbj * Science Department.
11 1.1 dbj *
12 1.1 dbj * Redistribution and use in source and binary forms, with or without
13 1.1 dbj * modification, are permitted provided that the following conditions
14 1.1 dbj * are met:
15 1.1 dbj * 1. Redistributions of source code must retain the above copyright
16 1.1 dbj * notice, this list of conditions and the following disclaimer.
17 1.1 dbj * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 dbj * notice, this list of conditions and the following disclaimer in the
19 1.1 dbj * documentation and/or other materials provided with the distribution.
20 1.1 dbj * 3. All advertising materials mentioning features or use of this software
21 1.1 dbj * must display the following acknowledgement:
22 1.1 dbj * This product includes software developed by the University of
23 1.1 dbj * California, Berkeley and its contributors.
24 1.1 dbj * 4. Neither the name of the University nor the names of its contributors
25 1.1 dbj * may be used to endorse or promote products derived from this software
26 1.1 dbj * without specific prior written permission.
27 1.1 dbj *
28 1.1 dbj * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.1 dbj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.1 dbj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.1 dbj * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.1 dbj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1 dbj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1 dbj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1 dbj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.1 dbj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.1 dbj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.1 dbj * SUCH DAMAGE.
39 1.1 dbj *
40 1.1 dbj * from: Utah $Hdr: autoconf.c 1.36 92/12/20$
41 1.1 dbj *
42 1.1 dbj * @(#)autoconf.c 8.2 (Berkeley) 1/12/94
43 1.1 dbj */
44 1.1 dbj
45 1.1 dbj /*
46 1.1 dbj * Setup the system to run on the current machine.
47 1.1 dbj *
48 1.1 dbj * Configure() is called at boot time. Available
49 1.1 dbj * devices are determined (from possibilities mentioned in ioconf.c),
50 1.1 dbj * and the drivers are initialized.
51 1.1 dbj */
52 1.1 dbj
53 1.1 dbj #include <sys/param.h>
54 1.1 dbj #include <sys/systm.h>
55 1.1 dbj #include <sys/map.h>
56 1.1 dbj #include <sys/buf.h>
57 1.1 dbj #include <sys/dkstat.h>
58 1.1 dbj #include <sys/conf.h>
59 1.1 dbj #include <sys/dmap.h>
60 1.1 dbj #include <sys/reboot.h>
61 1.1 dbj #include <sys/device.h>
62 1.1 dbj
63 1.1 dbj #include <machine/vmparam.h>
64 1.1 dbj #include <machine/autoconf.h>
65 1.1 dbj #include <machine/disklabel.h>
66 1.1 dbj #include <machine/cpu.h>
67 1.1 dbj #include <machine/pte.h>
68 1.1 dbj
69 1.1 dbj #include <next68k/next68k/isr.h>
70 1.1 dbj
71 1.1 dbj struct device *booted_device; /* boot device */
72 1.1 dbj
73 1.1 dbj /*
74 1.1 dbj * The following several variables are related to
75 1.1 dbj * the configuration process, and are used in initializing
76 1.1 dbj * the machine.
77 1.1 dbj */
78 1.1 dbj int cold; /* if 1, still working on cold-start */
79 1.1 dbj
80 1.1 dbj void mainbus_attach __P((struct device *, struct device *, void *));
81 1.1 dbj int mainbus_match __P((struct device *, struct cfdata *, void *));
82 1.1 dbj int mainbus_print __P((void *, const char *));
83 1.1 dbj
84 1.1 dbj struct mainbus_softc {
85 1.1 dbj struct device sc_dev;
86 1.1 dbj };
87 1.1 dbj
88 1.1 dbj struct cfattach mainbus_ca = {
89 1.1 dbj sizeof(struct mainbus_softc), mainbus_match, mainbus_attach
90 1.1 dbj };
91 1.1 dbj
92 1.1 dbj #if 0
93 1.1 dbj struct cfdriver mainbus_cd = {
94 1.1 dbj NULL, "mainbus", DV_DULL, 0
95 1.1 dbj };
96 1.1 dbj #endif
97 1.1 dbj
98 1.1 dbj static char *mainbusdevs[] = {
99 1.1 dbj "intio",
100 1.1 dbj NULL
101 1.1 dbj };
102 1.1 dbj
103 1.1 dbj int
104 1.1 dbj mainbus_match(parent, cf, args)
105 1.1 dbj struct device *parent;
106 1.1 dbj struct cfdata *cf;
107 1.1 dbj void *args;
108 1.1 dbj {
109 1.1 dbj static int mainbus_matched;
110 1.1 dbj
111 1.1 dbj if (mainbus_matched)
112 1.1 dbj return (0);
113 1.1 dbj
114 1.1 dbj return ((mainbus_matched = 1));
115 1.1 dbj }
116 1.1 dbj
117 1.1 dbj void
118 1.1 dbj mainbus_attach(parent, self, args)
119 1.1 dbj struct device *parent, *self;
120 1.1 dbj void *args;
121 1.1 dbj {
122 1.1 dbj char **devices;
123 1.1 dbj int i;
124 1.1 dbj
125 1.1 dbj printf("\n");
126 1.1 dbj
127 1.1 dbj /*
128 1.1 dbj * Attach children.
129 1.1 dbj */
130 1.1 dbj devices = mainbusdevs;
131 1.1 dbj
132 1.1 dbj for (i = 0; devices[i] != NULL; ++i)
133 1.1 dbj (void)config_found(self, devices[i], mainbus_print);
134 1.1 dbj }
135 1.1 dbj
136 1.1 dbj int
137 1.1 dbj mainbus_print(aux, cp)
138 1.1 dbj void *aux;
139 1.1 dbj const char *cp;
140 1.1 dbj {
141 1.1 dbj char *devname = aux;
142 1.1 dbj
143 1.1 dbj if (cp)
144 1.1 dbj printf("%s at %s\n", devname, cp);
145 1.1 dbj
146 1.1 dbj return (UNCONF);
147 1.1 dbj }
148 1.1 dbj
149 1.1 dbj struct devnametobdevmaj next68k_nam2blk[] = {
150 1.1 dbj { "sd", 4 },
151 1.1 dbj { "st", 5 },
152 1.1 dbj { "cd", 6 },
153 1.1 dbj { "md", 13 },
154 1.1 dbj { NULL, 0 },
155 1.1 dbj };
156 1.1 dbj
157 1.1 dbj /*
158 1.1 dbj * Determine mass storage and memory configuration for a machine.
159 1.1 dbj */
160 1.1 dbj void
161 1.1 dbj configure()
162 1.1 dbj {
163 1.1 dbj
164 1.1 dbj booted_device = NULL; /* set by device drivers (if found) */
165 1.1 dbj
166 1.2 dbj INTR_SETMASK(0);
167 1.1 dbj
168 1.1 dbj init_sir();
169 1.1 dbj
170 1.1 dbj if (config_rootfound("mainbus", NULL) == NULL)
171 1.1 dbj panic("autoconfig failed, no root");
172 1.1 dbj
173 1.1 dbj cold = 0;
174 1.1 dbj
175 1.2 dbj /* Turn on interrupts */
176 1.2 dbj spl0();
177 1.1 dbj }
178 1.1 dbj
179 1.1 dbj void
180 1.1 dbj cpu_rootconf()
181 1.1 dbj {
182 1.1 dbj
183 1.1 dbj printf("boot device: %s\n",
184 1.1 dbj (booted_device) ? booted_device->dv_xname : "<unknown>");
185 1.1 dbj
186 1.1 dbj setroot(booted_device, 0, next68k_nam2blk);
187 1.1 dbj }
188 1.1 dbj
189 1.2 dbj #if 0 /* @@@ Does anything use this? Is it a required interface? */
190 1.1 dbj /*
191 1.1 dbj * find a device matching "name" and unit number
192 1.1 dbj */
193 1.1 dbj struct device *
194 1.1 dbj getdevunit(name, unit)
195 1.1 dbj char *name;
196 1.1 dbj int unit;
197 1.1 dbj {
198 1.1 dbj struct device *dev = alldevs.tqh_first;
199 1.1 dbj char num[10], fullname[16];
200 1.1 dbj int lunit;
201 1.1 dbj
202 1.1 dbj /* compute length of name and decimal expansion of unit number */
203 1.1 dbj sprintf(num, "%d", unit);
204 1.1 dbj lunit = strlen(num);
205 1.1 dbj if (strlen(name) + lunit >= sizeof(fullname) - 1)
206 1.1 dbj panic("config_attach: device name too long");
207 1.1 dbj
208 1.1 dbj strcpy(fullname, name);
209 1.1 dbj strcat(fullname, num);
210 1.1 dbj
211 1.1 dbj while (strcmp(dev->dv_xname, fullname) != 0) {
212 1.1 dbj if ((dev = dev->dv_list.tqe_next) == NULL)
213 1.1 dbj return NULL;
214 1.1 dbj }
215 1.1 dbj return dev;
216 1.1 dbj }
217 1.2 dbj
218 1.2 dbj #endif
219