xref: /netbsd/sys/arch/mipsco/mipsco/autoconf.c (revision 6550d01e)
1 /*	$NetBSD: autoconf.c,v 1.22 2009/11/05 18:14:21 dyoung 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.22 2009/11/05 18:14:21 dyoung 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/mainboard.h>
103 #include <machine/autoconf.h>
104 
105 /*
106  * The following several variables are related to
107  * the configuration process, and are used in initializing
108  * the machine.
109  */
110 int	cpuspeed = 25;	/* approx # instr per usec. */
111 
112 extern int initcpu(void);		/*XXX*/
113 
114 void	findroot(device_t *, int *);
115 
116 struct mipsco_intrhand intrtab[MAX_INTR_COOKIES];
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   	int s;
129 
130 	/*
131 	 * Kick off autoconfiguration
132 	 */
133 	s = splhigh();
134 	if (config_rootfound("mainbus", NULL) == NULL)
135 		panic("no mainbus found");
136 	initcpu();
137 }
138 
139 void
140 cpu_rootconf(void)
141 {
142 	findroot(&booted_device, &booted_partition);
143 
144 	printf("boot device: %s\n",
145 	       booted_device ? booted_device->dv_xname : "<unknown>");
146 	setroot(booted_device, booted_partition);
147 }
148 
149 dev_t	bootdev = 0;
150 char	boot_class;
151 int	boot_id, boot_lun, boot_part;
152 
153 /*
154  * Attempt to find the device from which we were booted.
155  */
156 void
157 findroot(device_t *devpp, int *partp)
158 {
159 	device_t dv;
160 	deviter_t di;
161 
162 	for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
163 	     dv != NULL;
164 	     dv = deviter_next(&di)) {
165 		if (device_class(dv) == boot_class &&
166 		    /* XXX device_unit() abuse */
167 		    device_unit(dv) == boot_id)
168 		    	break;
169 	}
170 	deviter_release(&di);
171 	if (dv != NULL) {
172 		*devpp = dv;
173 		*partp = boot_part;
174 		return;
175 	}
176 
177 	/*
178 	 * Default to "not found".
179 	 */
180 	*devpp = NULL;
181 	*partp = 0;
182 	return;
183 }
184 
185 void
186 makebootdev(char *cp)
187 {
188 	boot_class = -1;
189 	boot_id = boot_lun = boot_part = 0;
190 
191 	if (strlen(cp) < 6)
192 		return;
193 	if (strncmp(cp, "dk", 2) == 0 && cp[4] == '(') { /* Disk */
194 		cp += 5;
195 		if (*cp >= '0' && *cp <= '9')
196 			boot_lun = *cp++ - '0';
197 		if (*cp == ',')
198 			cp += 1;
199 		if (*cp >= '0' && *cp <= '9')
200 			boot_id = *cp++ - '0';
201 		if (*cp == ',')
202 			cp += 1;
203 		if (*cp >= '0' && *cp <= '7')
204 			boot_part = *cp - '0';
205 		boot_class = DV_DISK;
206 		return;
207 	}
208 }
209