xref: /netbsd/sys/arch/mipsco/mipsco/autoconf.c (revision c4a72b64)
1 /*	$NetBSD: autoconf.c,v 1.7 2002/09/25 22:21:12 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/buf.h>
56 #include <sys/dkstat.h>
57 #include <sys/conf.h>
58 #include <sys/reboot.h>
59 #include <sys/device.h>
60 
61 #include <dev/scsipi/scsi_all.h>
62 #include <dev/scsipi/scsipi_all.h>
63 #include <dev/scsipi/scsiconf.h>
64 
65 #include <machine/cpu.h>
66 #include <machine/mainboard.h>
67 #include <machine/autoconf.h>
68 
69 /*
70  * The following several variables are related to
71  * the configuration process, and are used in initializing
72  * the machine.
73  */
74 int	cpuspeed = 25;	/* approx # instr per usec. */
75 
76 extern int initcpu __P((void));		/*XXX*/
77 
78 void	findroot __P((struct device **, int *));
79 
80 struct mipsco_intrhand intrtab[MAX_INTR_COOKIES];
81 struct device  *booted_device;
82 static int	booted_partition;
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   	int s;
95 
96 	softintr_init();
97 	/*
98 	 * Kick off autoconfiguration
99 	 */
100 	s = splhigh();
101 	if (config_rootfound("mainbus", "mainbus") == NULL)
102 		panic("no mainbus found");
103 	initcpu();
104 }
105 
106 void
107 cpu_rootconf()
108 {
109 	findroot(&booted_device, &booted_partition);
110 
111 	printf("boot device: %s\n",
112 	       booted_device ? booted_device->dv_xname : "<unknown>");
113 	setroot(booted_device, booted_partition);
114 }
115 
116 dev_t	bootdev = NULL;
117 char	boot_class;
118 int	boot_id, boot_lun, boot_part;
119 
120 /*
121  * Attempt to find the device from which we were booted.
122  */
123 void
124 findroot(devpp, partp)
125 	struct device **devpp;
126 	int *partp;
127 {
128 	struct device *dv;
129 
130 	for (dv = TAILQ_FIRST(&alldevs); dv; dv = TAILQ_NEXT(dv, dv_list)) {
131 		if (dv->dv_class == boot_class && dv->dv_unit == boot_id) {
132 			*devpp = dv;
133 			*partp = boot_part;
134 			return;
135 		}
136 	}
137 
138 	/*
139 	 * Default to "not found".
140 	 */
141 	*devpp = NULL;
142 	*partp = 0;
143 	return;
144 }
145 
146 void
147 makebootdev(cp)
148 	char *cp;
149 {
150 	boot_class = -1;
151 	boot_id = boot_lun = boot_part = 0;
152 
153 	if (strlen(cp) < 6)
154 		return;
155 	if (strncmp(cp, "dk", 2) == 0 && cp[4] == '(') { /* Disk */
156 		cp += 5;
157 		if (*cp >= '0' && *cp <= '9')
158 			boot_lun = *cp++ - '0';
159 		if (*cp == ',')
160 			cp += 1;
161 		if (*cp >= '0' && *cp <= '9')
162 			boot_id = *cp++ - '0';
163 		if (*cp == ',')
164 			cp += 1;
165 		if (*cp >= '0' && *cp <= '7')
166 			boot_part = *cp - '0';
167 		boot_class = DV_DISK;
168 		return;
169 	}
170 }
171