xref: /netbsd-src/sys/arch/cats/cats/autoconf.c (revision 4b896b232495b7a9b8b94a1cf1e21873296d53b8)
1 /*	$NetBSD: autoconf.c,v 1.6 2003/07/15 01:29:18 lukem Exp $	*/
2 
3 /*
4  * Copyright (c) 1994-1998 Mark Brinicombe.
5  * Copyright (c) 1994 Brini.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by Mark Brinicombe for
19  *      the NetBSD project.
20  * 4. The name of the company nor the name of the author may be used to
21  *    endorse or promote products derived from this software without specific
22  *    prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30  * 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  * RiscBSD kernel project
37  *
38  * autoconf.c
39  *
40  * Autoconfiguration functions
41  */
42 
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.6 2003/07/15 01:29:18 lukem Exp $");
45 
46 #include "opt_md.h"
47 
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/reboot.h>
51 #include <sys/disklabel.h>
52 #include <sys/device.h>
53 #include <sys/conf.h>
54 #include <sys/kernel.h>
55 #include <sys/malloc.h>
56 #include <machine/bootconfig.h>
57 #include <machine/intr.h>
58 
59 #include "isa.h"
60 
61 struct device *booted_device;
62 int booted_partition;
63 
64 void isa_intr_init (void);
65 
66 static void get_device __P((char *name));
67 static void set_root_device __P((void));
68 
69 /* Decode a device name to a major and minor number */
70 
71 static void
72 get_device(name)
73 	char *name;
74 {
75 	int unit, part;
76 	char devname[16], buf[32], *cp;
77 	struct device *dv;
78 
79 	if (strncmp(name, "/dev/", 5) == 0)
80 		name += 5;
81 
82 	if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
83 		return;
84 
85 	name += strlen(devname);
86 	unit = part = 0;
87 
88 	cp = name;
89 	while (*cp >= '0' && *cp <= '9')
90 		unit = (unit * 10) + (*cp++ - '0');
91 	if (cp == name)
92 		return;
93 
94 	if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
95 		part = *cp - 'a';
96 	else if (*cp != '\0' && *cp != ' ')
97 		return;
98 	sprintf(buf, "%s%d", devname, unit);
99 	for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
100 		if (strcmp(buf, dv->dv_xname) == 0) {
101 			booted_device = dv;
102 			booted_partition = part;
103 			return;
104 		}
105 	}
106 }
107 
108 static void
109 set_root_device()
110 {
111 	char *ptr;
112 
113 	if (boot_file)
114 		get_device(boot_file);
115 	if (boot_args &&
116 	    get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr))
117 		get_device(ptr);
118 }
119 
120 /*
121  * Set up the root device from the boot args
122  */
123 void
124 cpu_rootconf(void)
125 {
126 	set_root_device();
127 	printf("boot device: %s\n",
128 	    booted_device != NULL ? booted_device->dv_xname : "<unknown>");
129 	setroot(booted_device, booted_partition);
130 }
131 
132 
133 /*
134  * void cpu_configure()
135  *
136  * Configure all the root devices
137  * The root devices are expected to configure their own children
138  */
139 extern int footbridge_imask[NIPL];
140 
141 void
142 cpu_configure(void)
143 {
144 	softintr_init();
145 	/*
146 	 * Since various PCI interrupts could be routed via the ICU
147 	 * (for PCI devices in the bridge) we need to set up the ICU
148 	 * now so that these interrupts can be established correctly
149 	 * i.e. This is a hack.
150 	 */
151 	isa_intr_init();
152 
153 
154 	config_rootfound("mainbus", NULL);
155 
156 	/* Debugging information */
157 #ifndef TERSE
158 	printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_vm=%08x\n",
159 	    footbridge_imask[IPL_BIO], footbridge_imask[IPL_NET],
160 	    footbridge_imask[IPL_TTY], footbridge_imask[IPL_VM]);
161 	printf("ipl_audio=%08x ipl_imp=%08x ipl_high=%08x ipl_serial=%08x\n",
162 	    footbridge_imask[IPL_AUDIO], footbridge_imask[IPL_CLOCK],
163 	    footbridge_imask[IPL_HIGH], footbridge_imask[IPL_SERIAL]);
164 #endif
165 
166 	/* Time to start taking interrupts so lets open the flood gates .... */
167 	(void)spl0();
168 }
169 
170 void
171 device_register(struct device *dev, void *aux)
172 {
173 }
174 /* End of autoconf.c */
175