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