autoconf.c revision 1.38 1 /* $NetBSD: autoconf.c,v 1.38 2001/07/12 23:35:42 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)autoconf.c 8.4 (Berkeley) 10/1/93
45 */
46
47 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
48
49 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.38 2001/07/12 23:35:42 thorpej Exp $");
50
51 #include <sys/param.h>
52 #include <sys/systm.h>
53 #include <sys/buf.h>
54 #include <sys/disklabel.h>
55 #include <sys/reboot.h>
56 #include <sys/device.h>
57 #include <dev/cons.h>
58
59 #include <machine/autoconf.h>
60 #include <machine/alpha.h>
61 #include <machine/cpu.h>
62 #include <machine/prom.h>
63 #include <machine/conf.h>
64 #include <machine/intr.h>
65
66 struct device *booted_device;
67 int booted_partition;
68 struct bootdev_data *bootdev_data;
69
70 void parse_prom_bootdev __P((void));
71 int atoi __P((char *));
72
73 /*
74 * cpu_configure:
75 * called at boot time, configure all devices on system
76 */
77 void
78 cpu_configure()
79 {
80
81 parse_prom_bootdev();
82 softintr_init();
83
84 /*
85 * Disable interrupts during autoconfiguration. splhigh() won't
86 * work, because it simply _raises_ the IPL, so if machine checks
87 * are disabled, they'll stay disabled. Machine checks are needed
88 * during autoconfig.
89 */
90 (void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
91 if (config_rootfound("mainbus", "mainbus") == NULL)
92 panic("no mainbus found");
93 (void)spl0();
94
95 /*
96 * Note that bootstrapping is finished, and set the HWRPB up
97 * to do restarts.
98 */
99 hwrpb_restart_setup();
100 }
101
102 void
103 cpu_rootconf()
104 {
105
106 if (booted_device == NULL)
107 printf("WARNING: can't figure what device matches \"%s\"\n",
108 bootinfo.booted_dev);
109 setroot(booted_device, booted_partition);
110 }
111
112 void
113 parse_prom_bootdev()
114 {
115 static char hacked_boot_dev[128];
116 static struct bootdev_data bd;
117 char *cp, *scp, *boot_fields[8];
118 int i, done;
119
120 booted_device = NULL;
121 booted_partition = 0;
122 bootdev_data = NULL;
123
124 memcpy(hacked_boot_dev, bootinfo.booted_dev,
125 min(sizeof bootinfo.booted_dev, sizeof hacked_boot_dev));
126 #if 0
127 printf("parse_prom_bootdev: boot dev = \"%s\"\n", hacked_boot_dev);
128 #endif
129
130 i = 0;
131 scp = cp = hacked_boot_dev;
132 for (done = 0; !done; cp++) {
133 if (*cp != ' ' && *cp != '\0')
134 continue;
135 if (*cp == '\0')
136 done = 1;
137
138 *cp = '\0';
139 boot_fields[i++] = scp;
140 scp = cp + 1;
141 if (i == 8)
142 done = 1;
143 }
144 if (i != 8)
145 return; /* doesn't look like anything we know! */
146
147 #if 0
148 printf("i = %d, done = %d\n", i, done);
149 for (i--; i >= 0; i--)
150 printf("%d = %s\n", i, boot_fields[i]);
151 #endif
152
153 bd.protocol = boot_fields[0];
154 bd.bus = atoi(boot_fields[1]);
155 bd.slot = atoi(boot_fields[2]);
156 bd.channel = atoi(boot_fields[3]);
157 bd.remote_address = boot_fields[4];
158 bd.unit = atoi(boot_fields[5]);
159 bd.boot_dev_type = atoi(boot_fields[6]);
160 bd.ctrl_dev_type = boot_fields[7];
161
162 #if 0
163 printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
164 bd.protocol, bd.bus, bd.slot, bd.channel);
165 printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
166 bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
167 #endif
168
169 bootdev_data = &bd;
170 }
171
172 int
173 atoi(s)
174 char *s;
175 {
176 int n, neg;
177
178 n = 0;
179 neg = 0;
180
181 while (*s == '-') {
182 s++;
183 neg = !neg;
184 }
185
186 while (*s != '\0') {
187 if (*s < '0' && *s > '9')
188 break;
189
190 n = (10 * n) + (*s - '0');
191 s++;
192 }
193
194 return (neg ? -n : n);
195 }
196
197 void
198 device_register(dev, aux)
199 struct device *dev;
200 void *aux;
201 {
202 if (bootdev_data == NULL) {
203 /*
204 * There is no hope.
205 */
206 return;
207 }
208 if (platform.device_register)
209 (*platform.device_register)(dev, aux);
210 }
211