1 /* $NetBSD: autoconf.c,v 1.24 2023/12/20 14:50:02 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1994-1998 Mark Brinicombe.
5 * Copyright (c) 1994 Brini.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Mark Brinicombe for
19 * the NetBSD project.
20 * 4. The name of the company nor the name of the author may be used to
21 * endorse or promote products derived from this software without specific
22 * prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 */
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.24 2023/12/20 14:50:02 thorpej Exp $");
40
41 #include "opt_md.h"
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/conf.h>
46 #include <sys/device.h>
47 #include <sys/disklabel.h>
48 #include <sys/intr.h>
49 #include <sys/kernel.h>
50 #include <sys/reboot.h>
51
52 #include <uvm/uvm_extern.h>
53
54 #include <arm/arm32/machdep.h>
55
56 #include <machine/bootconfig.h>
57 #include <machine/config_hook.h>
58
59 #include "opt_cputypes.h"
60 #if defined(CPU_SA1100) || defined(CPU_SA1110)
61 #include "sacom.h"
62 #endif
63
64 extern dev_t dumpdev;
65
66 void isa_intr_init(void);
67
68 #ifndef MEMORY_DISK_IS_ROOT
69 static void get_device(const char *);
70 static void set_root_device(void);
71 #endif
72
73 #ifndef MEMORY_DISK_IS_ROOT
74 /* Decode a device name to a major and minor number */
75 static void
get_device(const char * name)76 get_device(const char *name)
77 {
78 int unit, part;
79 char devname[16];
80 const char *cp;
81 device_t dv;
82
83 if (strncmp(name, "/dev/", 5) == 0)
84 name += 5;
85
86 if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
87 return;
88
89 name += strlen(devname);
90 unit = part = 0;
91
92 cp = name;
93 while (*cp >= '0' && *cp <= '9')
94 unit = (unit * 10) + (*cp++ - '0');
95 if (cp == name)
96 return;
97
98 if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
99 part = *cp - 'a';
100 else if (*cp != '\0' && *cp != ' ')
101 return;
102 if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) {
103 booted_device = dv;
104 booted_partition = part;
105 }
106 }
107
108 /* Set the rootdev variable from the root specifier in the boot args */
109 static void
set_root_device(void)110 set_root_device(void)
111 {
112
113 if (boot_file[0] != '\0')
114 get_device(boot_file);
115 else
116 /* hpcboot doesn't pass a bootdev arg if wd0 */
117 get_device("wd0");
118 }
119 #endif /* ifndef MEMORY_DISK_IS_ROOT */
120
121 /*
122 * Set up the root device from the boot args
123 */
124 void
cpu_rootconf(void)125 cpu_rootconf(void)
126 {
127 #ifndef MEMORY_DISK_IS_ROOT
128 set_root_device();
129
130 printf("boot device: %s\n",
131 booted_device != NULL ? device_xname(booted_device) : "<unknown>");
132 #endif
133 rootconf();
134 }
135
136
137 /*
138 * void cpu_configure()
139 *
140 * Configure all the root devices
141 * The root devices are expected to configure their own children
142 */
143 void
cpu_configure(void)144 cpu_configure(void)
145 {
146
147 config_hook_init();
148
149 /*
150 * Configure all the roots.
151 * We have to have a mainbus
152 */
153 #if 0
154 startrtclock();
155 #endif
156
157 /*
158 * Since the ICU is not standard on the ARM we don't know
159 * if we have one until we find a bridge.
160 * Since various PCI interrupts could be routed via the ICU
161 * (for PCI devices in the bridge) we need to set up the ICU
162 * now so that these interrupts can be established correctly
163 * i.e. This is a hack.
164 */
165
166 if (config_rootfound("mainbus", NULL) == NULL)
167 panic("configure: mainbus not configured");
168
169 /* Debugging information */
170 #if defined(DIAGNOSTIC)
171 #if defined(CPU_SA1100) || defined(CPU_SA1110)
172 dump_spl_masks();
173 #endif
174 #endif /* DIAGNOSTIC */
175
176 /* Time to start taking interrupts so lets open the flood gates .... */
177 (void)spl0();
178 }
179
180 void
device_register(device_t dev,void * aux)181 device_register(device_t dev, void *aux)
182 {
183 }
184
185 /*
186 * This entire table could be autoconfig()ed but that would mean that
187 * the kernel's idea of the console would be out of sync with that of
188 * the standalone boot. I think it best that they both use the same
189 * known algorithm unless we see a pressing need otherwise.
190 */
191
192 #include "biconsdev.h"
193
194 #include <dev/cons.h>
195
196 cons_decl(sacom);
197 #define biconscnpollc nullcnpollc
198 cons_decl(bicons);
199
200 struct consdev constab[] = {
201 #if (NSACOM > 0)
202 cons_init(sacom),
203 #endif
204 #if (NBICONSDEV > 0)
205 cons_init(bicons),
206 #endif
207 { NULL },
208 };
209