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