autoconf.c revision 1.35 1 /* $NetBSD: autoconf.c,v 1.35 1999/09/15 18:10:35 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.35 1999/09/15 18:10:35 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
65 struct device *booted_device;
66 int booted_partition;
67 struct bootdev_data *bootdev_data;
68
69 void parse_prom_bootdev __P((void));
70 int atoi __P((char *));
71
72 /*
73 * cpu_configure:
74 * called at boot time, configure all devices on system
75 */
76 void
77 cpu_configure()
78 {
79
80 parse_prom_bootdev();
81
82 /*
83 * Disable interrupts during autoconfiguration. splhigh() won't
84 * work, because it simply _raises_ the IPL, so if machine checks
85 * are disabled, they'll stay disabled. Machine checks are needed
86 * during autoconfig.
87 */
88 (void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
89 if (config_rootfound("mainbus", "mainbus") == NULL)
90 panic("no mainbus found");
91 (void)spl0();
92 cold = 0;
93
94 /*
95 * Note that bootstrapping is finished, and set the HWRPB up
96 * to do restarts.
97 */
98 hwrpb_restart_setup();
99 }
100
101 void
102 cpu_rootconf()
103 {
104
105 if (booted_device == NULL)
106 printf("WARNING: can't figure what device matches \"%s\"\n",
107 bootinfo.booted_dev);
108 setroot(booted_device, booted_partition);
109 }
110
111 void
112 parse_prom_bootdev()
113 {
114 static char hacked_boot_dev[128];
115 static struct bootdev_data bd;
116 char *cp, *scp, *boot_fields[8];
117 int i, done;
118
119 booted_device = NULL;
120 booted_partition = 0;
121 bootdev_data = NULL;
122
123 bcopy(bootinfo.booted_dev, hacked_boot_dev,
124 min(sizeof bootinfo.booted_dev, sizeof hacked_boot_dev));
125 #if 0
126 printf("parse_prom_bootdev: boot dev = \"%s\"\n", hacked_boot_dev);
127 #endif
128
129 i = 0;
130 scp = cp = hacked_boot_dev;
131 for (done = 0; !done; cp++) {
132 if (*cp != ' ' && *cp != '\0')
133 continue;
134 if (*cp == '\0')
135 done = 1;
136
137 *cp = '\0';
138 boot_fields[i++] = scp;
139 scp = cp + 1;
140 if (i == 8)
141 done = 1;
142 }
143 if (i != 8)
144 return; /* doesn't look like anything we know! */
145
146 #if 0
147 printf("i = %d, done = %d\n", i, done);
148 for (i--; i >= 0; i--)
149 printf("%d = %s\n", i, boot_fields[i]);
150 #endif
151
152 bd.protocol = boot_fields[0];
153 bd.bus = atoi(boot_fields[1]);
154 bd.slot = atoi(boot_fields[2]);
155 bd.channel = atoi(boot_fields[3]);
156 bd.remote_address = boot_fields[4];
157 bd.unit = atoi(boot_fields[5]);
158 bd.boot_dev_type = atoi(boot_fields[6]);
159 bd.ctrl_dev_type = boot_fields[7];
160
161 #if 0
162 printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
163 bd.protocol, bd.bus, bd.slot, bd.channel);
164 printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
165 bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
166 #endif
167
168 bootdev_data = &bd;
169 }
170
171 int
172 atoi(s)
173 char *s;
174 {
175 int n, neg;
176
177 n = 0;
178 neg = 0;
179
180 while (*s == '-') {
181 s++;
182 neg = !neg;
183 }
184
185 while (*s != '\0') {
186 if (*s < '0' && *s > '9')
187 break;
188
189 n = (10 * n) + (*s - '0');
190 s++;
191 }
192
193 return (neg ? -n : n);
194 }
195
196 void
197 device_register(dev, aux)
198 struct device *dev;
199 void *aux;
200 {
201 if (bootdev_data == NULL) {
202 /*
203 * There is no hope.
204 */
205 return;
206 }
207 if (platform.device_register)
208 (*platform.device_register)(dev, aux);
209 }
210