xref: /netbsd/sys/arch/atari/atari/autoconf.c (revision bf9ec67e)
1 /*	$NetBSD: autoconf.c,v 1.36 2001/06/07 08:35:29 leo Exp $	*/
2 
3 /*
4  * Copyright (c) 1995 Leo Weppelman
5  * Copyright (c) 1994 Christian E. Hopps
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Christian E. Hopps.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/reboot.h>
36 #include <sys/conf.h>
37 #include <sys/buf.h>
38 #include <sys/device.h>
39 #include <sys/disklabel.h>
40 #include <sys/disk.h>
41 #include <machine/disklabel.h>
42 #include <machine/cpu.h>
43 #include <atari/atari/device.h>
44 
45 static void findroot __P((void));
46 void mbattach __P((struct device *, struct device *, void *));
47 int mbprint __P((void *, const char *));
48 int mbmatch __P((struct device *, struct cfdata *, void *));
49 
50 struct device *booted_device;
51 int booted_partition;
52 
53 int atari_realconfig;
54 #include <sys/kernel.h>
55 
56 /*
57  * called at boot time, configure all devices on system
58  */
59 void
60 cpu_configure()
61 {
62 	extern int atari_realconfig;
63 
64 	atari_realconfig = 1;
65 
66 	if (config_rootfound("mainbus", "mainbus") == NULL)
67 		panic("no mainbus found");
68 }
69 
70 void
71 cpu_rootconf()
72 {
73 	findroot();
74 	setroot(booted_device, booted_partition);
75 }
76 
77 /*ARGSUSED*/
78 int
79 simple_devprint(auxp, pnp)
80 	void *auxp;
81 	const char *pnp;
82 {
83 	return(QUIET);
84 }
85 
86 /*
87  * use config_search to find appropriate device, then call that device
88  * directly with NULL device variable storage.  A device can then
89  * always tell the difference between the real and console init
90  * by checking for NULL.
91  */
92 int
93 atari_config_found(pcfp, pdp, auxp, pfn)
94 	struct cfdata *pcfp;
95 	struct device *pdp;
96 	void *auxp;
97 	cfprint_t pfn;
98 {
99 	struct device temp;
100 	struct cfdata *cf;
101 	extern int	atari_realconfig;
102 
103 	if (atari_realconfig)
104 		return(config_found(pdp, auxp, pfn) != NULL);
105 
106 	if (pdp == NULL)
107 		pdp = &temp;
108 
109 	pdp->dv_cfdata = pcfp;
110 	if ((cf = config_search((cfmatch_t)NULL, pdp, auxp)) != NULL) {
111 		cf->cf_attach->ca_attach(pdp, NULL, auxp);
112 		pdp->dv_cfdata = NULL;
113 		return(1);
114 	}
115 	pdp->dv_cfdata = NULL;
116 	return(0);
117 }
118 
119 /*
120  * this function needs to get enough configured to do a console
121  * basically this means start attaching the grfxx's that support
122  * the console. Kinda hacky but it works.
123  */
124 void
125 config_console()
126 {
127 	struct cfdata *cf;
128 
129 	/*
130 	 * we need mainbus' cfdata.
131 	 */
132 	cf = config_rootsearch(NULL, "mainbus", "mainbus");
133 	if (cf == NULL)
134 		panic("no mainbus");
135 
136 	/*
137 	 * Note: The order of the 'atari_config_found()' calls is
138 	 * important! On the Hades, the 'pci-side' of the config does
139 	 * some setup for the 'grf-side'. This make it possible to use
140 	 * a PCI card for both wscons and grfabs.
141 	 */
142 	atari_config_found(cf, NULL, "pcibus", NULL);
143 	atari_config_found(cf, NULL, "isabus", NULL);
144 	atari_config_found(cf, NULL, "grfbus", NULL);
145 }
146 
147 /*
148  * The system will assign the "booted device" indicator (and thus
149  * rootdev if rootspec is wildcarded) to the first partition 'a'
150  * in preference of boot.
151  */
152 #include <sys/fcntl.h>		/* XXXX and all that uses it */
153 #include <sys/proc.h>		/* XXXX and all that uses it */
154 
155 #include "fd.h"
156 #include "sd.h"
157 #include "cd.h"
158 #include "wd.h"
159 
160 #if NWD > 0
161 extern	struct cfdriver wd_cd;
162 #endif
163 #if NSD > 0
164 extern	struct cfdriver sd_cd;
165 #endif
166 #if NCD > 0
167 extern	struct cfdriver cd_cd;
168 #endif
169 #if NFD > 0
170 extern	struct cfdriver fd_cd;
171 #endif
172 
173 struct cfdriver *genericconf[] = {
174 #if NWD > 0
175 	&wd_cd,
176 #endif
177 #if NSD > 0
178 	&sd_cd,
179 #endif
180 #if NCD > 0
181 	&cd_cd,
182 #endif
183 #if NFD > 0
184 	&fd_cd,
185 #endif
186 	NULL,
187 };
188 
189 void
190 findroot(void)
191 {
192 	struct disk *dkp;
193 	struct partition *pp;
194 	struct device **devs;
195 	int i, maj, unit;
196 
197 	if (boothowto & RB_ASKNAME)
198 		return;		/* Don't bother looking */
199 
200 	for (i = 0; genericconf[i] != NULL; i++) {
201 		for (unit = 0; unit < genericconf[i]->cd_ndevs; unit++) {
202 			if (genericconf[i]->cd_devs[unit] == NULL)
203 				continue;
204 
205 			/*
206 			 * Find the disk structure corresponding to the
207 			 * current device.
208 			 */
209 			devs = (struct device **)genericconf[i]->cd_devs;
210 			if ((dkp = disk_find(devs[unit]->dv_xname)) == NULL)
211 				continue;
212 
213 			if (dkp->dk_driver == NULL ||
214 			    dkp->dk_driver->d_strategy == NULL)
215 				continue;
216 
217 			for (maj = 0; maj < nblkdev; maj++)
218 				if (bdevsw[maj].d_strategy ==
219 				    dkp->dk_driver->d_strategy)
220 					break;
221 #ifdef DIAGNOSTIC
222 			if (maj >= nblkdev)
223 				panic("findroot: impossible");
224 #endif
225 
226 			/* Open disk; forces read of disklabel. */
227 			if ((*bdevsw[maj].d_open)(MAKEDISKDEV(maj,
228 			    unit, 0), FREAD|FNONBLOCK, 0, &proc0))
229 				continue;
230 			(void)(*bdevsw[maj].d_close)(MAKEDISKDEV(maj,
231 			    unit, 0), FREAD|FNONBLOCK, 0, &proc0);
232 
233 			pp = &dkp->dk_label->d_partitions[booted_partition];
234 			if (pp->p_size != 0 && pp->p_fstype == FS_BSDFFS) {
235 				booted_device = devs[unit];
236 				return;
237 			}
238 		}
239 	}
240 }
241 
242 /*
243  * mainbus driver
244  */
245 struct cfattach mainbus_ca = {
246 	sizeof(struct device), mbmatch, mbattach
247 };
248 
249 int
250 mbmatch(pdp, cfp, auxp)
251 	struct device	*pdp;
252 	struct cfdata	*cfp;
253 	void		*auxp;
254 {
255 	if (cfp->cf_unit > 0)
256 		return(0);
257 	/*
258 	 * We are always here
259 	 */
260 	return(1);
261 }
262 
263 /*
264  * "find" all the things that should be there.
265  */
266 void
267 mbattach(pdp, dp, auxp)
268 	struct device *pdp, *dp;
269 	void *auxp;
270 {
271 	printf ("\n");
272 	config_found(dp, "clock"  , simple_devprint);
273 	config_found(dp, "grfbus" , simple_devprint);
274 	config_found(dp, "kbd"    , simple_devprint);
275 	config_found(dp, "fdc"    , simple_devprint);
276 	config_found(dp, "ser"    , simple_devprint);
277 	config_found(dp, "zs"     , simple_devprint);
278 	config_found(dp, "ncrscsi", simple_devprint);
279 	config_found(dp, "nvr"    , simple_devprint);
280 	config_found(dp, "lpt"    , simple_devprint);
281 	config_found(dp, "wdc"    , simple_devprint);
282 	config_found(dp, "isabus" , simple_devprint);
283 	config_found(dp, "pcibus" , simple_devprint);
284 	config_found(dp, "avmebus" , simple_devprint);
285 }
286 
287 int
288 mbprint(auxp, pnp)
289 	void *auxp;
290 	const char *pnp;
291 {
292 	if (pnp)
293 		printf("%s at %s", (char *)auxp, pnp);
294 	return(UNCONF);
295 }
296