xref: /netbsd-src/sys/arch/mvme68k/dev/mainbus.c (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: mainbus.c,v 1.18 2005/12/11 12:18:17 christos 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 <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.18 2005/12/11 12:18:17 christos Exp $");
45 
46 #include "vmetwo.h"
47 
48 #include <sys/param.h>
49 #include <sys/kernel.h>
50 #include <sys/systm.h>
51 #include <sys/device.h>
52 
53 #define _MVME68K_BUS_DMA_PRIVATE
54 #define _MVME68K_BUS_SPACE_PRIVATE
55 #include <machine/bus.h>
56 #undef _MVME68K_BUS_DMA_PRIVATE
57 #undef _MVME68K_BUS_SPACE_PRIVATE
58 #include <machine/cpu.h>
59 
60 #include <mvme68k/dev/mainbus.h>
61 
62 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177)
63 #if NVMETWO == 0
64 #include <dev/vme/vmevar.h>
65 #include <dev/mvme/mvmebus.h>
66 #include <dev/mvme/vme_twovar.h>
67 #endif
68 #endif
69 
70 void mainbus_attach __P((struct device *, struct device *, void *));
71 int mainbus_match __P((struct device *, struct cfdata *, void *));
72 int mainbus_print __P((void *, const char *));
73 
74 CFATTACH_DECL(mainbus, sizeof(struct device),
75     mainbus_match, mainbus_attach, NULL, NULL);
76 
77 
78 struct mainbus_devices {
79 	const char *md_name;
80 	bus_addr_t md_offset;
81 };
82 
83 #ifdef MVME147
84 static struct mainbus_devices mainbusdevs_147[] = {
85 	{"pcc", MAINBUS_PCC_OFFSET},
86 	{"timekeeper", MAINBUS_TK147_OFFSET},
87 	{NULL, 0}
88 };
89 #endif
90 
91 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177)
92 static struct mainbus_devices mainbusdevs_1x7[] = {
93 	{"pcctwo", MAINBUS_PCCTWO_OFFSET},
94 	{"vmetwo", MAINBUS_VMETWO_OFFSET},
95 	{"timekeeper", MAINBUS_TIMEKEEPER_OFFSET},
96 	{NULL, 0}
97 };
98 #endif
99 
100 struct mvme68k_bus_dma_tag _mainbus_dma_tag = {
101 	NULL,
102 	_bus_dmamap_create,
103 	_bus_dmamap_destroy,
104 	_bus_dmamap_load_direct,
105 	_bus_dmamap_load_mbuf_direct,
106 	_bus_dmamap_load_uio_direct,
107 	_bus_dmamap_load_raw_direct,
108 	_bus_dmamap_unload,
109 	NULL,			/* Set up at run-time */
110 	_bus_dmamem_alloc,
111 	_bus_dmamem_free,
112 	_bus_dmamem_map,
113 	_bus_dmamem_unmap,
114 	_bus_dmamem_mmap
115 };
116 
117 struct mvme68k_bus_space_tag _mainbus_space_tag = {
118 	NULL,
119 	_bus_space_map,
120 	_bus_space_unmap,
121 	_bus_space_peek_1,
122 	_bus_space_peek_2,
123 	_bus_space_peek_4,
124 	_bus_space_poke_1,
125 	_bus_space_poke_2,
126 	_bus_space_poke_4
127 };
128 
129 
130 /* ARGSUSED */
131 int
132 mainbus_match(parent, cf, args)
133 	struct device *parent;
134 	struct cfdata *cf;
135 	void *args;
136 {
137 	static int mainbus_matched;
138 
139 	if (mainbus_matched)
140 		return (0);
141 
142 	return ((mainbus_matched = 1));
143 }
144 
145 /* ARGSUSED */
146 void
147 mainbus_attach(parent, self, args)
148 	struct device *parent;
149 	struct device *self;
150 	void *args;
151 {
152 	struct mainbus_attach_args ma;
153 	struct mainbus_devices *devices;
154 	int i;
155 
156 	printf("\n");
157 
158 	/*
159 	 * Attach children appropriate for this CPU.
160 	 */
161 	switch (machineid) {
162 #ifdef MVME147
163 	case MVME_147:
164 		devices = mainbusdevs_147;
165 		_mainbus_dma_tag._dmamap_sync = _bus_dmamap_sync_030;
166 		break;
167 #endif
168 
169 #if defined(MVME162) || defined(MVME167) || defined(MVME172) || defined(MVME177)
170 	case MVME_162:
171 	case MVME_167:
172 	case MVME_172:
173 	case MVME_177:
174 		devices = mainbusdevs_1x7;
175 		_mainbus_dma_tag._dmamap_sync = _bus_dmamap_sync_0460;
176 		break;
177 #endif
178 
179 	default:
180 		panic("mainbus_attach: impossible CPU type");
181 	}
182 
183 	for (i = 0; devices[i].md_name != NULL; ++i) {
184 		/*
185 		 * On mvme162 and up, if the kernel config file had no vmetwo0
186 		 * device, we have to do some manual initialisation on the
187 		 * VMEChip2 to get local interrupts working (ABORT switch,
188 		 * hardware assisted soft interrupts).
189 		 */
190 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177)
191 #if NVMETWO == 0
192 		if (devices[i].md_offset == MAINBUS_VMETWO_OFFSET
193 #if defined(MVME147)
194 		    && machineid != MVME_147
195 #endif
196 		    ) {
197 			(void) vmetwo_probe(&_mainbus_space_tag,
198 			    intiobase_phys + MAINBUS_VMETWO_OFFSET);
199 			continue;
200 		}
201 #endif
202 #endif
203 		ma.ma_name = devices[i].md_name;
204 		ma.ma_dmat = &_mainbus_dma_tag;
205 		ma.ma_bust = &_mainbus_space_tag;
206 		ma.ma_offset = devices[i].md_offset + intiobase_phys;
207 
208 		(void) config_found(self, &ma, mainbus_print);
209 	}
210 
211 
212 	/*
213 	 * Attach the memory controllers on mvme162->mvme177.
214 	 * Note: These *must* be attached after the PCCChip2/MCChip.
215 	 * They must also be attached *after* the VMEchip2 has been
216 	 * initialised (either by the driver, or the vmetwo_probe()
217 	 * call above).
218 	 */
219 #if defined(MVME162) || defined(MVME172) || defined(MVME167) || defined(MVME177)
220 #if defined(MVME147)
221 	if (machineid != MVME_147)
222 #endif
223 	{
224 		ma.ma_name = "memc";
225 		ma.ma_dmat = &_mainbus_dma_tag;
226 		ma.ma_bust = &_mainbus_space_tag;
227 		ma.ma_offset = MAINBUS_MEMC1_OFFSET + intiobase_phys;
228 		(void) config_found(self, &ma, mainbus_print);
229 		ma.ma_offset = MAINBUS_MEMC2_OFFSET + intiobase_phys;
230 		(void) config_found(self, &ma, mainbus_print);
231 	}
232 #endif
233 
234 	/*
235 	 * Attach Industry Pack modules on mvme162 and mvme172
236 	 */
237 #if defined(MVME162) || defined(MVME172)
238 #if defined(MVME147) || defined(MVME167) || defined(MVME177)
239 	if (machineid == MVME_162 || machineid == MVME_172)
240 #endif
241 	{
242 		ma.ma_name = "ipack";
243 		ma.ma_dmat = &_mainbus_dma_tag;
244 		ma.ma_bust = &_mainbus_space_tag;
245 		ma.ma_offset = MAINBUS_IPACK_OFFSET + intiobase_phys;
246 		(void) config_found(self, &ma, mainbus_print);
247 	}
248 #endif
249 }
250 
251 int
252 mainbus_print(aux, cp)
253 	void *aux;
254 	const char *cp;
255 {
256 	struct mainbus_attach_args *ma;
257 
258 	ma = aux;
259 
260 	if (cp)
261 		aprint_normal("%s at %s", ma->ma_name, cp);
262 
263 	aprint_normal(" address 0x%lx", ma->ma_offset);
264 
265 	return (UNCONF);
266 }
267