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