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