autoconf.c revision 1.25 1 /* $NetBSD: autoconf.c,v 1.25 1997/06/06 19:52:42 cgd 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 <machine/options.h> /* Config options headers */
48 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
49
50 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.25 1997/06/06 19:52:42 cgd Exp $");
51
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/buf.h>
55 #include <sys/disklabel.h>
56 #include <sys/reboot.h>
57 #include <sys/device.h>
58 #include <dev/cons.h>
59
60 #include <machine/autoconf.h>
61 #include <machine/prom.h>
62 #include <machine/conf.h>
63
64 struct device *booted_device;
65 int booted_partition;
66 struct bootdev_data *bootdev_data;
67 char boot_dev[128];
68
69 void parse_prom_bootdev __P((void));
70 int atoi __P((char *));
71
72 struct devnametobdevmaj alpha_nam2blk[] = {
73 { "st", 2 },
74 { "cd", 3 },
75 { "md", 6 },
76 { "sd", 8 },
77 { "fd", 0 },
78 { "wd", 4 },
79 { NULL, 0 },
80 };
81
82 /*
83 * configure:
84 * called at boot time, configure all devices on system
85 */
86 void
87 configure()
88 {
89
90 parse_prom_bootdev();
91
92 /*
93 * Disable interrupts during autoconfiguration. splhigh() won't
94 * work, because it simply _raises_ the IPL, so if machine checks
95 * are disabled, they'll stay disabled. Machine checks are needed
96 * during autoconfig.
97 */
98 (void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
99 if (config_rootfound("mainbus", "mainbus") == NULL)
100 panic("no mainbus found");
101 (void)spl0();
102 cold = 0;
103 }
104
105 void
106 cpu_rootconf()
107 {
108
109 if (booted_device == NULL)
110 printf("WARNING: can't figure what device matches \"%s\"\n",
111 boot_dev);
112 setroot(booted_device, booted_partition, alpha_nam2blk);
113 }
114
115 void
116 parse_prom_bootdev()
117 {
118 static char hacked_boot_dev[128];
119 static struct bootdev_data bd;
120 char *cp, *scp, *boot_fields[8];
121 int i, done;
122
123 booted_device = NULL;
124 booted_partition = 0;
125 bootdev_data = NULL;
126
127 prom_getenv(PROM_E_BOOTED_DEV, boot_dev, sizeof(boot_dev));
128 bcopy(boot_dev, hacked_boot_dev, sizeof hacked_boot_dev);
129 #if 0
130 printf("parse_prom_bootdev: boot dev = \"%s\"\n", boot_dev);
131 #endif
132
133 i = 0;
134 scp = cp = hacked_boot_dev;
135 for (done = 0; !done; cp++) {
136 if (*cp != ' ' && *cp != '\0')
137 continue;
138 if (*cp == '\0')
139 done = 1;
140
141 *cp = '\0';
142 boot_fields[i++] = scp;
143 scp = cp + 1;
144 if (i == 8)
145 done = 1;
146 }
147 if (i != 8)
148 return; /* doesn't look like anything we know! */
149
150 #if 0
151 printf("i = %d, done = %d\n", i, done);
152 for (i--; i >= 0; i--)
153 printf("%d = %s\n", i, boot_fields[i]);
154 #endif
155
156 bd.protocol = boot_fields[0];
157 bd.bus = atoi(boot_fields[1]);
158 bd.slot = atoi(boot_fields[2]);
159 bd.channel = atoi(boot_fields[3]);
160 bd.remote_address = boot_fields[4];
161 bd.unit = atoi(boot_fields[5]);
162 bd.boot_dev_type = atoi(boot_fields[6]);
163 bd.ctrl_dev_type = boot_fields[7];
164
165 #if 0
166 printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
167 bd.protocol, bd.bus, bd.slot, bd.channel);
168 printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
169 bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
170 #endif
171
172 bootdev_data = &bd;
173 }
174
175 int
176 atoi(s)
177 char *s;
178 {
179 int n, neg;
180
181 n = 0;
182 neg = 0;
183
184 while (*s == '-') {
185 s++;
186 neg = !neg;
187 }
188
189 while (*s != '\0') {
190 if (*s < '0' && *s > '9')
191 break;
192
193 n = (10 * n) + (*s - '0');
194 s++;
195 }
196
197 return (neg ? -n : n);
198 }
199
200 void
201 device_register(dev, aux)
202 struct device *dev;
203 void *aux;
204 {
205 extern const struct cpusw *cpu_fn_switch;
206
207 if (bootdev_data == NULL) {
208 /*
209 * There is no hope.
210 */
211
212 return;
213 }
214
215 (*cpu_fn_switch->device_register)(dev, aux);
216 }
217