xref: /netbsd-src/sys/arch/mvme68k/dev/mainbus.c (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /*	$NetBSD: mainbus.c,v 1.10 2001/07/27 18:38:54 scw Exp $	*/
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Steve C. Woodford
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	      This product includes software developed by the NetBSD
21  *	      Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Derived from the mainbus code in mvme68k/autoconf.c by Chuck Cranor.
41  */
42 
43 #include "vmetwo.h"
44 
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/systm.h>
48 #include <sys/device.h>
49 
50 #define _MVME68K_BUS_DMA_PRIVATE
51 #define _MVME68K_BUS_SPACE_PRIVATE
52 #include <machine/bus.h>
53 #undef _MVME68K_BUS_DMA_PRIVATE
54 #undef _MVME68K_BUS_SPACE_PRIVATE
55 #include <machine/cpu.h>
56 
57 #include <mvme68k/dev/mainbus.h>
58 
59 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177)
60 #if NVMETWO == 0
61 #include <dev/vme/vmevar.h>
62 #include <mvme68k/dev/mvmebus.h>
63 #include <mvme68k/dev/vme_twovar.h>
64 #endif
65 #endif
66 
67 void mainbus_attach __P((struct device *, struct device *, void *));
68 int mainbus_match __P((struct device *, struct cfdata *, void *));
69 int mainbus_print __P((void *, const char *));
70 
71 struct cfattach mainbus_ca = {
72 	sizeof(struct device), mainbus_match, mainbus_attach
73 };
74 
75 
76 struct mainbus_devices {
77 	const char *md_name;
78 	bus_addr_t md_offset;
79 };
80 
81 #ifdef MVME147
82 static struct mainbus_devices mainbusdevs_147[] = {
83 	{"pcc", MAINBUS_PCC_OFFSET},
84 	{NULL, 0}
85 };
86 #endif
87 
88 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177)
89 static struct mainbus_devices mainbusdevs_1x7[] = {
90 	{"pcctwo", MAINBUS_PCCTWO_OFFSET},
91 	{"vmetwo", MAINBUS_VMETWO_OFFSET},
92 	{NULL, 0}
93 };
94 #endif
95 
96 struct mvme68k_bus_dma_tag _mainbus_dma_tag = {
97 	NULL,
98 	_bus_dmamap_create,
99 	_bus_dmamap_destroy,
100 	_bus_dmamap_load_direct,
101 	_bus_dmamap_load_mbuf_direct,
102 	_bus_dmamap_load_uio_direct,
103 	_bus_dmamap_load_raw_direct,
104 	_bus_dmamap_unload,
105 	NULL,			/* Set up at run-time */
106 	_bus_dmamem_alloc,
107 	_bus_dmamem_free,
108 	_bus_dmamem_map,
109 	_bus_dmamem_unmap,
110 	_bus_dmamem_mmap
111 };
112 
113 struct mvme68k_bus_space_tag _mainbus_space_tag = {
114 	NULL,
115 	_bus_space_map,
116 	_bus_space_unmap,
117 	_bus_space_peek_1,
118 	_bus_space_peek_2,
119 	_bus_space_peek_4,
120 	_bus_space_poke_1,
121 	_bus_space_poke_2,
122 	_bus_space_poke_4
123 };
124 
125 
126 /* ARGSUSED */
127 int
128 mainbus_match(parent, cf, args)
129 	struct device *parent;
130 	struct cfdata *cf;
131 	void *args;
132 {
133 	static int mainbus_matched;
134 
135 	if (mainbus_matched)
136 		return (0);
137 
138 	return ((mainbus_matched = 1));
139 }
140 
141 /* ARGSUSED */
142 void
143 mainbus_attach(parent, self, args)
144 	struct device *parent;
145 	struct device *self;
146 	void *args;
147 {
148 	struct mainbus_attach_args ma;
149 	struct mainbus_devices *devices;
150 	int i;
151 
152 	printf("\n");
153 
154 	/*
155 	 * Attach children appropriate for this CPU.
156 	 */
157 	switch (machineid) {
158 #ifdef MVME147
159 	case MVME_147:
160 		devices = mainbusdevs_147;
161 		_mainbus_dma_tag._dmamap_sync = _bus_dmamap_sync_030;
162 		break;
163 #endif
164 
165 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177)
166 	case MVME_162:
167 	case MVME_167:
168 	case MVME_172:
169 	case MVME_177:
170 		devices = mainbusdevs_1x7;
171 		_mainbus_dma_tag._dmamap_sync = _bus_dmamap_sync_0460;
172 		break;
173 #endif
174 
175 	default:
176 		panic("mainbus_attach: impossible CPU type");
177 	}
178 
179 	for (i = 0; devices[i].md_name != NULL; ++i) {
180 		ma.ma_name = devices[i].md_name;
181 		ma.ma_dmat = &_mainbus_dma_tag;
182 		ma.ma_bust = &_mainbus_space_tag;
183 		ma.ma_offset = devices[i].md_offset + intiobase_phys;
184 
185 		(void) config_found(self, &ma, mainbus_print);
186 	}
187 
188 	/*
189 	 * On mvme162 and up, if the kernel config file had no vmetwo0
190 	 * device, we have to do some manual initialisation on the
191 	 * VMEChip2 to get local interrupts working (ABORT switch,
192 	 * hardware assisted soft interrupts).
193 	 */
194 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177)
195 #if NVMETWO == 0
196 #if defined(MVME147)
197 	if (machineid != MVME_147)
198 #endif
199 	{
200 		(void) vmetwo_probe(&_mainbus_space_tag,
201 		    intiobase_phys + MAINBUS_VMETWO_OFFSET);
202 	}
203 #endif
204 #endif
205 
206 	/*
207 	 * Attach the memory controllers on mvme162->mvme177.
208 	 * Note: These *must* be attached after the PCCChip2/MCChip.
209 	 * They must also be attached *after* the VMEchip2 has been
210 	 * initialised (either by the driver, or the vmetwo_probe()
211 	 * call above).
212 	 */
213 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177)
214 #if defined(MVME147)
215 	if (machineid != MVME_147)
216 #endif
217 	{
218 		ma.ma_name = "memc";
219 		ma.ma_dmat = &_mainbus_dma_tag;
220 		ma.ma_bust = &_mainbus_space_tag;
221 		ma.ma_offset = MAINBUS_MEMC1_OFFSET + intiobase_phys;
222 		(void) config_found(self, &ma, mainbus_print);
223 		ma.ma_offset = MAINBUS_MEMC2_OFFSET + intiobase_phys;
224 		(void) config_found(self, &ma, mainbus_print);
225 	}
226 #endif
227 
228 	/*
229 	 * Attach Industry Pack modules on mvme162 and mvme172
230 	 */
231 #if defined(MVME162) || defined(MVME172)
232 #if defined(MVME147) || defined(MVME167) || defined(MVME177)
233 	if (machineid == MVME_162 || machineid == MVME_172)
234 #endif
235 	{
236 		ma.ma_name = "ipack";
237 		ma.ma_dmat = &_mainbus_dma_tag;
238 		ma.ma_bust = &_mainbus_space_tag;
239 		ma.ma_offset = MAINBUS_IPACK_OFFSET + intiobase_phys;
240 		(void) config_found(self, &ma, mainbus_print);
241 	}
242 #endif
243 }
244 
245 int
246 mainbus_print(aux, cp)
247 	void *aux;
248 	const char *cp;
249 {
250 	struct mainbus_attach_args *ma;
251 
252 	ma = aux;
253 
254 	if (cp)
255 		printf("%s at %s", ma->ma_name, cp);
256 
257 	printf(" address 0x%lx", ma->ma_offset);
258 
259 	return (UNCONF);
260 }
261