xref: /netbsd/sys/arch/newsmips/newsmips/autoconf.c (revision bf9ec67e)
1 /*	$NetBSD: autoconf.c,v 1.15 2002/05/16 02:50:54 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 1988 University of Utah.
5  * Copyright (c) 1992, 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 and Ralph Campbell.
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.31 91/01/21
41  *
42  *	@(#)autoconf.c	8.1 (Berkeley) 6/10/93
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 <dev/scsipi/scsi_all.h>
63 #include <dev/scsipi/scsipi_all.h>
64 #include <dev/scsipi/scsiconf.h>
65 
66 #include <machine/cpu.h>
67 #include <machine/adrsmap.h>
68 #include <machine/romcall.h>
69 
70 #include <newsmips/newsmips/machid.h>
71 
72 /*
73  * The following several variables are related to
74  * the configuration process, and are used in initializing
75  * the machine.
76  */
77 int	cpuspeed = 10;	/* approx # instr per usec. */
78 
79 struct device *booted_device;
80 int booted_partition;
81 
82 static void findroot __P((void));
83 
84 /*
85  * Determine mass storage and memory configuration for a machine.
86  * Print cpu type, and then iterate over an array of devices
87  * found on the baseboard or in turbochannel option slots.
88  * Once devices are configured, enable interrupts, and probe
89  * for attached scsi devices.
90  */
91 void
92 cpu_configure()
93 {
94 	extern struct idrom idrom;
95 
96 	printf("SONY NET WORK STATION, Model %s, ", idrom.id_model);
97 	printf("Machine ID #%d\n", idrom.id_serial);
98 
99 	/*
100 	 * Kick off autoconfiguration
101 	 */
102 	_splnone();	/* enable all interrupts */
103 	splhigh();	/* ...then disable device interrupts */
104 
105 	if (systype == NEWS3400) {
106 		*(char *)INTEN0 = INTEN0_BERR;	/* only buserr occurs */
107 		*(char *)INTEN1 = 0;
108 	}
109 
110 	if (config_rootfound("mainbus", "mainbus") == NULL)
111 		panic("no mainbus found");
112 
113 	/* Enable hardware interrupt registers. */
114 	enable_intr();
115 
116 	/* Configuration is finished, turn on interrupts. */
117 	_splnone();	/* enable all source forcing SOFT_INTs cleared */
118 }
119 
120 void
121 cpu_rootconf()
122 {
123 	findroot();
124 
125 	printf("boot device: %s\n",
126 	       booted_device ? booted_device->dv_xname : "<unknown>");
127 
128 	setroot(booted_device, booted_partition);
129 }
130 
131 u_long	bootdev = 0;		/* should be dev_t, but not until 32 bits */
132 
133 /*
134  * Attempt to find the device from which we were booted.
135  */
136 void
137 findroot()
138 {
139 	int ctlr, unit, part, type;
140 	struct device *dv;
141 
142 	if (BOOTDEV_MAG(bootdev) != 5)	/* NEWS-OS's B_DEVMAGIC */
143 		return;
144 
145 	ctlr = BOOTDEV_CTLR(bootdev);	/* SCSI ID */
146 	unit = BOOTDEV_UNIT(bootdev);
147 	part = BOOTDEV_PART(bootdev);	/* LUN */
148 	type = BOOTDEV_TYPE(bootdev);
149 
150 	if (type != BOOTDEV_SD)
151 		return;
152 
153 	/*
154 	 * XXX assumes only one controller exists.
155 	 */
156 	for (dv = alldevs.tqh_first; dv; dv=dv->dv_list.tqe_next) {
157 		if (strcmp(dv->dv_xname, "scsibus0") == 0) {
158 			struct scsibus_softc *sdv = (void *)dv;
159 			struct scsipi_periph *periph;
160 
161 			periph = scsipi_lookup_periph(sdv->sc_channel,
162 			    ctlr, 0);
163 			if (periph == NULL)
164 				continue;
165 
166 			booted_device = periph->periph_dev;
167 			booted_partition = part;
168 			return;
169 		}
170 	}
171 }
172