autoconf.c revision 1.53 1 /* $NetBSD: autoconf.c,v 1.53 2014/01/20 15:05:13 tsutsui 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.53 2014/01/20 15:05:13 tsutsui Exp $");
46
47 #include "pci.h"
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/buf.h>
52 #include <sys/disklabel.h>
53 #include <sys/reboot.h>
54 #include <sys/device.h>
55 #include <sys/conf.h>
56 #include <dev/cons.h>
57
58 #include <dev/pci/pcivar.h>
59
60 #include <machine/autoconf.h>
61 #include <machine/alpha.h>
62 #include <machine/cpu.h>
63 #include <machine/prom.h>
64 #include <machine/cpuconf.h>
65 #include <machine/intr.h>
66
67 struct bootdev_data *bootdev_data;
68
69 void parse_prom_bootdev(void);
70 static inline int atoi(const char *);
71
72 /*
73 * cpu_configure:
74 * called at boot time, configure all devices on system
75 */
76 void
77 cpu_configure(void)
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", NULL) == NULL)
90 panic("no mainbus found");
91 (void)spl0();
92
93 /*
94 * Note that bootstrapping is finished, and set the HWRPB up
95 * to do restarts.
96 */
97 hwrpb_restart_setup();
98 }
99
100 void
101 cpu_rootconf(void)
102 {
103
104 if (booted_device == NULL)
105 printf("WARNING: can't figure what device matches \"%s\"\n",
106 bootinfo.booted_dev);
107 rootconf();
108 }
109
110 void
111 parse_prom_bootdev(void)
112 {
113 static char hacked_boot_dev[128];
114 static struct bootdev_data bd;
115 char *cp, *scp, *boot_fields[8];
116 int i, done;
117
118 booted_device = NULL;
119 booted_partition = 0;
120 bootdev_data = NULL;
121
122 memcpy(hacked_boot_dev, bootinfo.booted_dev,
123 min(sizeof bootinfo.booted_dev, sizeof hacked_boot_dev));
124 #if 0
125 printf("parse_prom_bootdev: boot dev = \"%s\"\n", hacked_boot_dev);
126 #endif
127
128 i = 0;
129 scp = cp = hacked_boot_dev;
130 for (done = 0; !done; cp++) {
131 if (*cp != ' ' && *cp != '\0')
132 continue;
133 if (*cp == '\0')
134 done = 1;
135
136 *cp = '\0';
137 boot_fields[i++] = scp;
138 scp = cp + 1;
139 if (i == 8)
140 done = 1;
141 }
142 if (i != 8)
143 return; /* doesn't look like anything we know! */
144
145 #if 0
146 printf("i = %d, done = %d\n", i, done);
147 for (i--; i >= 0; i--)
148 printf("%d = %s\n", i, boot_fields[i]);
149 #endif
150
151 bd.protocol = boot_fields[0];
152 bd.bus = atoi(boot_fields[1]);
153 bd.slot = atoi(boot_fields[2]);
154 bd.channel = atoi(boot_fields[3]);
155 bd.remote_address = boot_fields[4];
156 bd.unit = atoi(boot_fields[5]);
157 bd.boot_dev_type = atoi(boot_fields[6]);
158 bd.ctrl_dev_type = boot_fields[7];
159
160 #if 0
161 printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
162 bd.protocol, bd.bus, bd.slot, bd.channel);
163 printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
164 bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
165 #endif
166
167 bootdev_data = &bd;
168 }
169
170 static inline int
171 atoi(const char *s)
172 {
173 return (int)strtoll(s, NULL, 10);
174 }
175
176 void
177 device_register(device_t dev, void *aux)
178 {
179 #if NPCI > 0
180 device_t parent = device_parent(dev);
181
182 if (parent != NULL && device_is_a(parent, "pci"))
183 device_pci_register(dev, aux);
184 #endif
185
186 if (bootdev_data == NULL) {
187 /*
188 * There is no hope.
189 */
190 return;
191 }
192 if (platform.device_register)
193 (*platform.device_register)(dev, aux);
194 }
195