xref: /netbsd-src/sys/arch/newsmips/newsmips/autoconf.c (revision 0c4ddb1599a0bea866fde8522a74cfbd2f68cd1b)
1 /*	$NetBSD: autoconf.c,v 1.32 2008/02/16 22:02:15 he Exp $	*/
2 
3 /*
4  * Copyright (c) 1992, 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 and Ralph Campbell.
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.31 91/01/21
36  *
37  *	@(#)autoconf.c	8.1 (Berkeley) 6/10/93
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 and Ralph Campbell.
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.31 91/01/21
75  *
76  *	@(#)autoconf.c	8.1 (Berkeley) 6/10/93
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.32 2008/02/16 22:02:15 he 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 <dev/scsipi/scsi_all.h>
98 #include <dev/scsipi/scsipi_all.h>
99 #include <dev/scsipi/scsiconf.h>
100 
101 #include <machine/cpu.h>
102 #include <machine/adrsmap.h>
103 #include <machine/romcall.h>
104 
105 #include <newsmips/newsmips/machid.h>
106 
107 #include "scsibus.h"
108 
109 /*
110  * The following several variables are related to
111  * the configuration process, and are used in initializing
112  * the machine.
113  */
114 int	cpuspeed = 10;	/* approx # instr per usec. */
115 
116 static void findroot(void);
117 
118 /*
119  * Determine mass storage and memory configuration for a machine.
120  * Print CPU type, and then iterate over an array of devices
121  * found on the baseboard or in turbochannel option slots.
122  * Once devices are configured, enable interrupts, and probe
123  * for attached scsi devices.
124  */
125 void
126 cpu_configure(void)
127 {
128 
129 	/*
130 	 * Kick off autoconfiguration
131 	 */
132 	_splnone();	/* enable all interrupts */
133 	splhigh();	/* ...then disable device interrupts */
134 
135 	if (systype == NEWS3400) {
136 		*(char *)INTEN0 = INTEN0_BERR;	/* only buserr occurs */
137 		*(char *)INTEN1 = 0;
138 	}
139 
140 	if (config_rootfound("mainbus", NULL) == NULL)
141 		panic("no mainbus found");
142 
143 	/* Enable hardware interrupt registers. */
144 	enable_intr();
145 
146 	/* Configuration is finished, turn on interrupts. */
147 	_splnone();	/* enable all source forcing SOFT_INTs cleared */
148 }
149 
150 void
151 cpu_rootconf(void)
152 {
153 	findroot();
154 
155 	printf("boot device: %s\n",
156 	       booted_device ? booted_device->dv_xname : "<unknown>");
157 
158 	setroot(booted_device, booted_partition);
159 }
160 
161 u_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
162 
163 /*
164  * Attempt to find the device from which we were booted.
165  */
166 static void
167 findroot(void)
168 {
169 	int ctlr, unit, part, type;
170 	device_t dv;
171 
172 	if (BOOTDEV_MAG(bootdev) != 5)	/* NEWS-OS's B_DEVMAGIC */
173 		return;
174 
175 	ctlr = BOOTDEV_CTLR(bootdev);	/* SCSI ID */
176 	unit = BOOTDEV_UNIT(bootdev);
177 	part = BOOTDEV_PART(bootdev);	/* LUN */
178 	type = BOOTDEV_TYPE(bootdev);
179 
180 	if (type != BOOTDEV_SD)
181 		return;
182 
183 	/*
184 	 * XXX assumes only one controller exists.
185 	 */
186 	if ((dv = device_find_by_xname("scsibus0")) != NULL) {
187 #if NSCSIBUS > 0
188 		struct scsibus_softc *sdv = device_private(dv);
189 		struct scsipi_periph *periph;
190 
191 		periph = scsipi_lookup_periph(sdv->sc_channel, ctlr, 0);
192 		if (periph != NULL) {
193 			booted_device = periph->periph_dev;
194 			booted_partition = part;
195 		}
196 #endif /* NSCSIBUS > 0 */
197 	}
198 }
199