1 /* $NetBSD: autoconf.c,v 1.48 2024/01/18 05:12:30 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.48 2024/01/18 05:12:30 thorpej Exp $");
49
50 #include "opt_mvmeconf.h"
51
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/buf.h>
55 #include <sys/conf.h>
56 #include <sys/reboot.h>
57 #include <sys/device.h>
58
59 #include <machine/vmparam.h>
60 #include <machine/disklabel.h>
61 #include <machine/cpu.h>
62 #include <machine/autoconf.h>
63 #include <machine/pte.h>
64
65 #include <dev/scsipi/scsi_all.h>
66 #include <dev/scsipi/scsipi_all.h>
67 #include <dev/scsipi/scsiconf.h>
68
69 #include <mvme68k/mvme68k/isr.h>
70
71 #ifdef MVME147
72 #include <mvme68k/dev/pccreg.h>
73 #endif
74 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177)
75 #include <dev/mvme/pcctworeg.h>
76 #endif
77
78
79 /*
80 * Determine mass storage and memory configuration for a machine.
81 */
82 void
cpu_configure(void)83 cpu_configure(void)
84 {
85
86 booted_device = NULL; /* set by device drivers (if found) */
87
88 /* Initialise interrupt handlers */
89 isrinit();
90
91 if (config_rootfound("mainbus", NULL) == NULL)
92 panic("autoconfig failed, no root");
93 }
94
95 void
cpu_rootconf(void)96 cpu_rootconf(void)
97 {
98
99 printf("boot device: %s",
100 (booted_device) ? device_xname(booted_device) : "<unknown>");
101
102 if (bootpart)
103 printf(" (partition %d)\n", bootpart);
104 else
105 printf("\n");
106
107 booted_partition = bootpart;
108 rootconf();
109 }
110
111 void
device_register(device_t dev,void * aux)112 device_register(device_t dev, void *aux)
113 {
114 static device_t controller;
115 static int foundboot;
116 device_t parent = device_parent(dev);
117
118 if (foundboot)
119 return;
120
121 if (controller == NULL && parent) {
122
123 switch (machineid) {
124 #ifdef MVME147
125 case MVME_147:
126 /*
127 * We currently only support booting from the 147's
128 * onboard scsi and ethernet. So ensure this
129 * device's parent is the PCC driver.
130 */
131 if (!device_is_a(parent, "pcc"))
132 return;
133
134 if (bootaddr == PCC_PADDR(PCC_WDSC_OFF) &&
135 device_is_a(dev, "wdsc")) {
136 controller = dev;
137 return;
138 }
139
140 if (bootaddr == PCC_PADDR(PCC_LE_OFF) &&
141 device_is_a(dev, "le")) {
142 booted_device = dev;
143 foundboot = 1;
144 return;
145 }
146
147 break;
148 #endif /* MVME_147 */
149
150 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177)
151 case MVME_162:
152 case MVME_167:
153 case MVME_172:
154 case MVME_177:
155 /*
156 * We currently only support booting from the 16x and
157 * 17x onboard scsi and ethernet. So ensure this
158 * device's parent is the PCCTWO driver.
159 */
160 if (!device_is_a(parent, "pcctwo"))
161 return;
162
163 if (bootaddr == PCCTWO_PADDR(PCCTWO_NCRSC_OFF) &&
164 device_is_a(dev, "osiop")) {
165 controller = dev;
166 return;
167 }
168
169 if (bootaddr == PCCTWO_PADDR(PCCTWO_IE_OFF) &&
170 device_is_a(dev, "ie")) {
171 booted_device = dev;
172 foundboot = 1;
173 return;
174 }
175
176 break;
177 #endif /* MVME_162 || MVME_167 || MVME_172 || MVME_177 */
178
179 default:
180 break;
181 }
182
183 return;
184 }
185
186 /*
187 * Find out which device on the scsibus we booted from
188 */
189 if (device_is_a(dev, "sd") ||
190 device_is_a(dev, "cd") ||
191 device_is_a(dev, "st")) {
192 struct scsipibus_attach_args *sa = aux;
193
194 if (device_parent(parent) != controller ||
195 bootdevlun != sa->sa_periph->periph_target)
196 return;
197
198 booted_device = dev;
199 foundboot = 1;
200 }
201 }
202