1 /* $NetBSD: autoconf.c,v 1.5 2024/01/08 05:10:51 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1982, 1986, 1990, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR 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 * from: Utah $Hdr: autoconf.c 1.36 92/12/20$
37 *
38 * @(#)autoconf.c 8.2 (Berkeley) 1/12/94
39 */
40
41 /*
42 * Setup the system to run on the current machine.
43 *
44 * Configure() is called at boot time.
45 */
46
47 #include <sys/cdefs.h>
48 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.5 2024/01/08 05:10:51 thorpej Exp $");
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/buf.h>
53 #include <sys/conf.h>
54 #include <sys/reboot.h>
55 #include <sys/device.h>
56
57 #include <machine/bootinfo.h>
58 #include <machine/intr.h>
59
60 #include <virt68k/dev/mainbusvar.h>
61
62 /*
63 * Determine mass storage and memory configuration for a machine.
64 */
65 void
cpu_configure(void)66 cpu_configure(void)
67 {
68
69 booted_device = NULL; /* set by device drivers (if found) */
70
71 /* Initialise interrupt handlers */
72 intr_init();
73
74 if (config_rootfound("mainbus", NULL) == NULL)
75 panic("autoconfig failed, no root");
76
77 /*
78 * XXX Go ahead and enable interrupts now that we've configured
79 * XXX everything.
80 * XXX
81 * XXX See locore.s, right before main() is called.
82 */
83 spl0();
84 }
85
86 void
cpu_rootconf(void)87 cpu_rootconf(void)
88 {
89 bootinfo_setup_initrd();
90 rootconf();
91 }
92
93 paddr_t consdev_addr;
94
95 void
device_register(device_t dev,void * aux)96 device_register(device_t dev, void *aux)
97 {
98 device_t parent = device_parent(dev);
99 char rootname[DEVICE_XNAME_SIZE];
100 bool rootname_valid = false;
101
102 if (booted_device == NULL) {
103 rootname_valid = bootinfo_getarg("root",
104 rootname, sizeof(rootname));
105 if (rootname_valid) {
106 size_t len = strlen(rootname);
107 while (len) {
108 len--;
109 if (isdigit(rootname[len])) {
110 break;
111 }
112 rootname[len] = '\0';
113 }
114 if (strcmp(device_xname(dev), rootname) == 0) {
115 booted_device = dev;
116 }
117 }
118 }
119
120 if (device_is_a(parent, "mainbus")) {
121 struct mainbus_attach_args *ma = aux;
122
123 if (ma->ma_addr == consdev_addr) {
124 prop_dictionary_set_bool(device_properties(dev),
125 "is-console", true);
126 }
127 }
128 }
129