xref: /netbsd-src/sys/arch/hpcmips/hpcmips/autoconf.c (revision cbab9cadce21ae72fac13910001079fff214cc29)
1 /*	$NetBSD: autoconf.c,v 1.26 2012/10/27 17:17:53 chs 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. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * from: Utah Hdr: autoconf.c 1.31 91/01/21
37  *
38  *	@(#)autoconf.c	8.1 (Berkeley) 6/10/93
39  */
40 
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.26 2012/10/27 17:17:53 chs Exp $");
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/conf.h>
47 #include <sys/device.h>
48 
49 #include <machine/disklabel.h>
50 
51 #include <machine/sysconf.h>
52 #include <machine/config_hook.h>
53 
54 void makebootdev(const char *);
55 
56 static char __booted_device_name[16];
57 static void get_device(const char *);
58 
59 /*
60  * Setup the system to run on the current machine.
61  *
62  * cpu_configure() is called at boot time.  Available
63  * devices are determined (from possibilities mentioned in ioconf.c),
64  * and the drivers are initialized.
65  */
66 void
cpu_configure(void)67 cpu_configure(void)
68 {
69 
70 	/* Kick off autoconfiguration. */
71 	(void)splhigh();
72 
73 	config_hook_init();
74 
75 	if (config_rootfound("mainbus", NULL) == NULL)
76 		panic("no mainbus found");
77 
78 	/* Configuration is finished, turn on interrupts. */
79 	spl0();		/* enable all source forcing SOFT_INTs cleared */
80 }
81 
82 void
cpu_rootconf(void)83 cpu_rootconf(void)
84 {
85 
86 	get_device(__booted_device_name);
87 
88 	printf("boot device: %s\n",
89 	    booted_device ? device_xname(booted_device) : "<unknown>");
90 
91 	rootconf();
92 }
93 
94 void
makebootdev(const char * cp)95 makebootdev(const char *cp)
96 {
97 
98 	strncpy(__booted_device_name, cp, 16);
99 }
100 
101 static void
get_device(const char * name)102 get_device(const char *name)
103 {
104 	int unit, part;
105 	char devname[16];
106 	const char *cp;
107 	device_t dv;
108 
109 	if (strncmp(name, "/dev/", 5) == 0)
110 		name += 5;
111 
112 	if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
113 		return;
114 
115 	name += strlen(devname);
116 	unit = part = 0;
117 
118 	cp = name;
119 	while (*cp >= '0' && *cp <= '9')
120 		unit = (unit * 10) + (*cp++ - '0');
121 	if (cp == name)
122 		return;
123 
124 	if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
125 		part = *cp - 'a';
126 	else if (*cp != '\0' && *cp != ' ')
127 		return;
128 	if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) {
129 		booted_device = dv;
130 		booted_partition = part;
131 	}
132 }
133