xref: /netbsd/sys/arch/hpcmips/hpcmips/autoconf.c (revision 6550d01e)
1 /*	$NetBSD: autoconf.c,v 1.22 2009/03/18 10:22:29 cegger 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 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
80 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.22 2009/03/18 10:22:29 cegger Exp $");
81 
82 #include <sys/param.h>
83 #include <sys/systm.h>
84 #include <sys/conf.h>	/* setroot() */
85 #include <sys/device.h>
86 
87 #include <machine/disklabel.h>
88 
89 #include <machine/sysconf.h>
90 #include <machine/config_hook.h>
91 
92 void makebootdev(const char *);
93 
94 static char __booted_device_name[16];
95 static void get_device(const char *);
96 
97 /*
98  * Setup the system to run on the current machine.
99  *
100  * cpu_configure() is called at boot time.  Available
101  * devices are determined (from possibilities mentioned in ioconf.c),
102  * and the drivers are initialized.
103  */
104 void
105 cpu_configure(void)
106 {
107 
108 	/* Kick off autoconfiguration. */
109 	(void)splhigh();
110 
111 	config_hook_init();
112 
113 	if (config_rootfound("mainbus", NULL) == NULL)
114 		panic("no mainbus found");
115 
116 	/* Configuration is finished, turn on interrupts. */
117 	_splnone();	/* enable all source forcing SOFT_INTs cleared */
118 }
119 
120 void
121 cpu_rootconf(void)
122 {
123 
124 	get_device(__booted_device_name);
125 
126 	printf("boot device: %s\n",
127 	    booted_device ? booted_device->dv_xname : "<unknown>");
128 
129 	setroot(booted_device, booted_partition);
130 }
131 
132 void
133 makebootdev(const char *cp)
134 {
135 
136 	strncpy(__booted_device_name, cp, 16);
137 }
138 
139 static void
140 get_device(const char *name)
141 {
142 	int unit, part;
143 	char devname[16];
144 	const char *cp;
145 	device_t dv;
146 
147 	if (strncmp(name, "/dev/", 5) == 0)
148 		name += 5;
149 
150 	if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
151 		return;
152 
153 	name += strlen(devname);
154 	unit = part = 0;
155 
156 	cp = name;
157 	while (*cp >= '0' && *cp <= '9')
158 		unit = (unit * 10) + (*cp++ - '0');
159 	if (cp == name)
160 		return;
161 
162 	if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
163 		part = *cp - 'a';
164 	else if (*cp != '\0' && *cp != ' ')
165 		return;
166 	if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) {
167 		booted_device = dv;
168 		booted_partition = part;
169 	}
170 }
171