xref: /netbsd/sys/arch/cats/cats/autoconf.c (revision c4a72b64)
1 /*	$NetBSD: autoconf.c,v 1.4 2002/11/03 21:43:31 chris 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 "opt_md.h"
44 
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/reboot.h>
48 #include <sys/disklabel.h>
49 #include <sys/device.h>
50 #include <sys/conf.h>
51 #include <sys/kernel.h>
52 #include <sys/malloc.h>
53 #include <machine/bootconfig.h>
54 #include <machine/intr.h>
55 
56 #include "isa.h"
57 
58 struct device *booted_device;
59 int booted_partition;
60 
61 void isa_intr_init (void);
62 
63 static void get_device __P((char *name));
64 static void set_root_device __P((void));
65 
66 /* Decode a device name to a major and minor number */
67 
68 static void
69 get_device(name)
70 	char *name;
71 {
72 	int unit, part;
73 	char devname[16], buf[32], *cp;
74 	struct device *dv;
75 
76 	if (strncmp(name, "/dev/", 5) == 0)
77 		name += 5;
78 
79 	if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
80 		return;
81 
82 	name += strlen(devname);
83 	unit = part = 0;
84 
85 	cp = name;
86 	while (*cp >= '0' && *cp <= '9')
87 		unit = (unit * 10) + (*cp++ - '0');
88 	if (cp == name)
89 		return;
90 
91 	if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
92 		part = *cp - 'a';
93 	else if (*cp != '\0' && *cp != ' ')
94 		return;
95 	sprintf(buf, "%s%d", devname, unit);
96 	for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
97 		if (strcmp(buf, dv->dv_xname) == 0) {
98 			booted_device = dv;
99 			booted_partition = part;
100 			return;
101 		}
102 	}
103 }
104 
105 static void
106 set_root_device()
107 {
108 	char *ptr;
109 
110 	if (boot_file)
111 		get_device(boot_file);
112 	if (boot_args &&
113 	    get_bootconf_option(boot_args, "root", BOOTOPT_TYPE_STRING, &ptr))
114 		get_device(ptr);
115 }
116 
117 /*
118  * Set up the root device from the boot args
119  */
120 void
121 cpu_rootconf(void)
122 {
123 	set_root_device();
124 	printf("boot device: %s\n",
125 	    booted_device != NULL ? booted_device->dv_xname : "<unknown>");
126 	setroot(booted_device, booted_partition);
127 }
128 
129 
130 /*
131  * void cpu_configure()
132  *
133  * Configure all the root devices
134  * The root devices are expected to configure their own children
135  */
136 extern int footbridge_imask[NIPL];
137 
138 void
139 cpu_configure(void)
140 {
141 	softintr_init();
142 	/*
143 	 * Since various PCI interrupts could be routed via the ICU
144 	 * (for PCI devices in the bridge) we need to set up the ICU
145 	 * now so that these interrupts can be established correctly
146 	 * i.e. This is a hack.
147 	 */
148 	isa_intr_init();
149 
150 
151 	config_rootfound("mainbus", NULL);
152 
153 	/* Debugging information */
154 #ifndef TERSE
155 	printf("ipl_bio=%08x ipl_net=%08x ipl_tty=%08x ipl_imp=%08x\n",
156 	    footbridge_imask[IPL_BIO], footbridge_imask[IPL_NET],
157 	    footbridge_imask[IPL_TTY], footbridge_imask[IPL_IMP]);
158 	printf("ipl_audio=%08x ipl_imp=%08x ipl_high=%08x ipl_serial=%08x\n",
159 	    footbridge_imask[IPL_AUDIO], footbridge_imask[IPL_CLOCK],
160 	    footbridge_imask[IPL_HIGH], footbridge_imask[IPL_SERIAL]);
161 #endif
162 
163 	/* Time to start taking interrupts so lets open the flood gates .... */
164 	(void)spl0();
165 }
166 
167 void
168 device_register(struct device *dev, void *aux)
169 {
170 }
171 /* End of autoconf.c */
172