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