xref: /netbsd-src/sys/arch/sun3/sun3/autoconf.c (revision 6ea46cb5e46c49111a6ecf3bcbe3c7e2730fe9f6)
1 /*
2  * Copyright (c) 1993 Adam Glass
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by Adam Glass.
16  * 4. The name of the Author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY Adam Glass ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * $Id: autoconf.c,v 1.12 1994/07/27 04:51:58 gwr Exp $
32  */
33 
34 /*
35  * Setup the system to run on the current machine.
36  *
37  * Configure() is called at boot time.  Available
38  * devices are determined (from possibilities mentioned in ioconf.c),
39  * and the drivers are initialized.
40  */
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/map.h>
45 #include <sys/buf.h>
46 #include <sys/dkstat.h>
47 #include <sys/conf.h>
48 #include <sys/dmap.h>
49 #include <sys/reboot.h>
50 #include <sys/device.h>
51 
52 #include <machine/autoconf.h>
53 #include <machine/vmparam.h>
54 #include <machine/cpu.h>
55 #include <machine/pte.h>
56 #include <machine/isr.h>
57 
58 extern void mainbusattach __P((struct device *, struct device *, void *));
59 
60 struct mainbus_softc {
61     struct device mainbus_dev;
62 };
63 
64 struct cfdriver mainbuscd =
65 { NULL, "mainbus", always_match, mainbusattach, DV_DULL,
66       sizeof(struct mainbus_softc), 0};
67 
68 void mainbusattach(parent, self, args)
69      struct device *parent;
70      struct device *self;
71      void *args;
72 {
73     struct cfdata *new_match;
74 
75     printf("\n");
76     while (1) {
77 	new_match = config_search(NULL, self, NULL);
78 	if (!new_match) break;
79 	config_attach(self, new_match, NULL, NULL);
80     }
81 }
82 
83 int nmi_intr(arg)
84      int arg;
85 {
86     printf("nmi interrupt received\n");
87     return 1;
88 }
89 
90 void configure()
91 {
92     int root_found;
93     extern int soft1intr();
94 
95     isr_init();
96     root_found = config_rootfound("mainbus", NULL);
97     if (!root_found)
98 	panic("configure: autoconfig failed, no device tree root found");
99     isr_add(7, nmi_intr, 0);
100     isr_add(1, soft1intr, 0);
101     isr_cleanup();
102     conf_init();
103 }
104 
105 int always_match(parent, cf, args)
106      struct device *parent;
107      struct cfdata *cf;
108      void *args;
109 {
110     return 1;
111 }
112 
113 /*
114  * Configure swap space and related parameters.
115  */
116 void
117 swapconf()
118 {
119 	struct swdevt *swp;
120 	u_int maj;
121 	int nblks;
122 
123 	for (swp = swdevt; swp->sw_dev != NODEV; swp++) {
124 		maj = major(swp->sw_dev);
125 
126 		if (maj > nblkdev) /* paranoid? */
127 			break;
128 
129 		if (bdevsw[maj].d_psize) {
130 			nblks = (*bdevsw[maj].d_psize)(swp->sw_dev);
131 			if (nblks > 0 &&
132 			    (swp->sw_nblks == 0 || swp->sw_nblks > nblks))
133 				swp->sw_nblks = nblks;
134 			swp->sw_nblks = ctod(dtoc(swp->sw_nblks));
135 		}
136 	}
137 }
138