vme_two.c revision 1.7 1 /* $NetBSD: vme_two.c,v 1.7 2008/04/28 20:23:54 martin Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2002 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * VME support specific to the VMEchip2 found on all high-end MVME boards
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: vme_two.c,v 1.7 2008/04/28 20:23:54 martin Exp $");
38
39 #include "vmetwo.h"
40
41 #include <sys/param.h>
42 #include <sys/kernel.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45
46 #include <sys/cpu.h>
47 #include <sys/bus.h>
48
49 #include <dev/vme/vmereg.h>
50 #include <dev/vme/vmevar.h>
51
52 #include <dev/mvme/mvmebus.h>
53 #include <dev/mvme/vme_tworeg.h>
54 #include <dev/mvme/vme_twovar.h>
55
56 void vmetwo_master_range(struct vmetwo_softc *, int, struct mvmebus_range *);
57 void vmetwo_slave_range(struct vmetwo_softc *, int, vme_am_t,
58 struct mvmebus_range *);
59
60 /* ARGSUSED */
61 void
62 vmetwo_init(sc)
63 struct vmetwo_softc *sc;
64 {
65 u_int32_t reg;
66 int i;
67
68 /* Initialise stuff for the common mvmebus front-end */
69 sc->sc_mvmebus.sc_chip = sc;
70 sc->sc_mvmebus.sc_nmasters = VME2_NMASTERS;
71 sc->sc_mvmebus.sc_masters = &sc->sc_master[0];
72 sc->sc_mvmebus.sc_nslaves = VME2_NSLAVES;
73 sc->sc_mvmebus.sc_slaves = &sc->sc_slave[0];
74 sc->sc_mvmebus.sc_intr_establish = vmetwo_intr_establish;
75 sc->sc_mvmebus.sc_intr_disestablish = vmetwo_intr_disestablish;
76
77 /* Initialise interrupts */
78 vmetwo_intr_init(sc);
79
80 reg = vme2_lcsr_read(sc, VME2LCSR_BOARD_CONTROL);
81 printf(": Type 2 VMEchip, scon jumper %s\n",
82 (reg & VME2_BOARD_CONTROL_SCON) ? "enabled" : "disabled");
83
84 /*
85 * Figure out what bits of the VMEbus we can access.
86 * First record the `fixed' maps (if they're enabled)
87 */
88 reg = vme2_lcsr_read(sc, VME2LCSR_IO_CONTROL);
89 if (reg & VME2_IO_CONTROL_I1EN) {
90 /* This range is fixed to A16, DATA */
91 sc->sc_master[0].vr_am = VME_AM_A16 | MVMEBUS_AM_CAP_DATA;
92
93 /* However, SUPER/USER is selectable... */
94 if (reg & VME2_IO_CONTROL_I1SU)
95 sc->sc_master[0].vr_am |= MVMEBUS_AM_CAP_SUPER;
96 else
97 sc->sc_master[0].vr_am |= MVMEBUS_AM_CAP_USER;
98
99 /* As is the datasize */
100 sc->sc_master[0].vr_datasize = VME_D32 | VME_D16;
101 if (reg & VME2_IO_CONTROL_I1D16)
102 sc->sc_master[0].vr_datasize &= ~VME_D32;
103
104 sc->sc_master[0].vr_locstart = VME2_IO0_LOCAL_START;
105 sc->sc_master[0].vr_mask = VME2_IO0_MASK;
106 sc->sc_master[0].vr_vmestart = VME2_IO0_VME_START;
107 sc->sc_master[0].vr_vmeend = VME2_IO0_VME_END;
108 } else
109 sc->sc_master[0].vr_am = MVMEBUS_AM_DISABLED;
110
111 if (reg & VME2_IO_CONTROL_I2EN) {
112 /* These two ranges are fixed to A24D16 and A32D16 */
113 sc->sc_master[1].vr_am = VME_AM_A24;
114 sc->sc_master[1].vr_datasize = VME_D16;
115 sc->sc_master[2].vr_am = VME_AM_A32;
116 sc->sc_master[2].vr_datasize = VME_D16;
117
118 /* However, SUPER/USER is selectable */
119 if (reg & VME2_IO_CONTROL_I2SU) {
120 sc->sc_master[1].vr_am |= MVMEBUS_AM_CAP_SUPER;
121 sc->sc_master[2].vr_am |= MVMEBUS_AM_CAP_SUPER;
122 } else {
123 sc->sc_master[1].vr_am |= MVMEBUS_AM_CAP_USER;
124 sc->sc_master[2].vr_am |= MVMEBUS_AM_CAP_USER;
125 }
126
127 /* As is PROGRAM/DATA */
128 if (reg & VME2_IO_CONTROL_I2PD) {
129 sc->sc_master[1].vr_am |= MVMEBUS_AM_CAP_PROG;
130 sc->sc_master[2].vr_am |= MVMEBUS_AM_CAP_PROG;
131 } else {
132 sc->sc_master[1].vr_am |= MVMEBUS_AM_CAP_DATA;
133 sc->sc_master[2].vr_am |= MVMEBUS_AM_CAP_DATA;
134 }
135
136 sc->sc_master[1].vr_locstart = VME2_IO1_LOCAL_START;
137 sc->sc_master[1].vr_mask = VME2_IO1_MASK;
138 sc->sc_master[1].vr_vmestart = VME2_IO1_VME_START;
139 sc->sc_master[1].vr_vmeend = VME2_IO1_VME_END;
140
141 sc->sc_master[2].vr_locstart = VME2_IO2_LOCAL_START;
142 sc->sc_master[2].vr_mask = VME2_IO2_MASK;
143 sc->sc_master[2].vr_vmestart = VME2_IO2_VME_START;
144 sc->sc_master[2].vr_vmeend = VME2_IO2_VME_END;
145 } else {
146 sc->sc_master[1].vr_am = MVMEBUS_AM_DISABLED;
147 sc->sc_master[2].vr_am = MVMEBUS_AM_DISABLED;
148 }
149
150 /*
151 * Now read the progammable maps
152 */
153 for (i = 0; i < VME2_MASTER_WINDOWS; i++)
154 vmetwo_master_range(sc, i,
155 &(sc->sc_master[i + VME2_MASTER_PROG_START]));
156
157 /* XXX: No A16 slave yet :XXX */
158 sc->sc_slave[VME2_SLAVE_A16].vr_am = MVMEBUS_AM_DISABLED;
159
160 for (i = 0; i < VME2_SLAVE_WINDOWS; i++) {
161 vmetwo_slave_range(sc, i, VME_AM_A32,
162 &sc->sc_slave[i + VME2_SLAVE_PROG_START]);
163 vmetwo_slave_range(sc, i, VME_AM_A24,
164 &sc->sc_slave[i + VME2_SLAVE_PROG_START + 2]);
165 }
166
167 mvmebus_attach(&sc->sc_mvmebus);
168 }
169
170 void
171 vmetwo_master_range(sc, range, vr)
172 struct vmetwo_softc *sc;
173 int range;
174 struct mvmebus_range *vr;
175 {
176 u_int32_t start, end, attr;
177 u_int32_t reg;
178
179 /*
180 * First, check if the range is actually enabled...
181 */
182 reg = vme2_lcsr_read(sc, VME2LCSR_MASTER_ENABLE);
183 if ((reg & VME2_MASTER_ENABLE(range)) == 0) {
184 vr->vr_am = MVMEBUS_AM_DISABLED;
185 return;
186 }
187
188 /*
189 * Fetch and record the range's attributes
190 */
191 attr = vme2_lcsr_read(sc, VME2LCSR_MASTER_ATTR);
192 attr >>= VME2_MASTER_ATTR_AM_SHIFT(range);
193
194 /*
195 * Fix up the datasizes available through this range
196 */
197 vr->vr_datasize = VME_D32 | VME_D16;
198 if (attr & VME2_MASTER_ATTR_D16)
199 vr->vr_datasize &= ~VME_D32;
200 attr &= VME2_MASTER_ATTR_AM_MASK;
201
202 vr->vr_am = (attr & VME_AM_ADRSIZEMASK) | MVMEBUS_AM2CAP(attr);
203 switch (vr->vr_am & VME_AM_ADRSIZEMASK) {
204 case VME_AM_A32:
205 default:
206 vr->vr_mask = 0xffffffffu;
207 break;
208
209 case VME_AM_A24:
210 vr->vr_mask = 0x00ffffffu;
211 break;
212
213 case VME_AM_A16:
214 vr->vr_mask = 0x0000ffffu;
215 break;
216 }
217
218 /*
219 * XXX
220 * It would be nice if users of the MI VMEbus code could pass down
221 * whether they can tolerate Write-Posting to their device(s).
222 * XXX
223 */
224
225 /*
226 * Fetch the local-bus start and end addresses for the range
227 */
228 reg = vme2_lcsr_read(sc, VME2LCSR_MASTER_ADDRESS(range));
229 start = (reg & VME2_MAST_ADDRESS_START_MASK);
230 start <<= VME2_MAST_ADDRESS_START_SHIFT;
231 vr->vr_locstart = start & ~vr->vr_mask;
232 end = (reg & VME2_MAST_ADDRESS_END_MASK);
233 end <<= VME2_MAST_ADDRESS_END_SHIFT;
234 end |= 0xffffu;
235 end += 1;
236
237 /*
238 * Local->VMEbus map '4' has optional translation bits, so
239 * the VMEbus start and end addresses may need to be adjusted.
240 */
241 if (range == 3 && (reg = vme2_lcsr_read(sc, VME2LCSR_MAST4_TRANS))!=0) {
242 uint32_t addr, sel, len = end - start;
243
244 reg = vme2_lcsr_read(sc, VME2LCSR_MAST4_TRANS);
245 reg &= VME2_MAST4_TRANS_SELECT_MASK;
246 sel = reg << VME2_MAST4_TRANS_SELECT_SHIFT;
247
248 reg = vme2_lcsr_read(sc, VME2LCSR_MAST4_TRANS);
249 reg &= VME2_MAST4_TRANS_ADDRESS_MASK;
250 addr = reg << VME2_MAST4_TRANS_ADDRESS_SHIFT;
251
252 start = (addr & sel) | (start & (~sel));
253 end = start + len;
254 vr->vr_mask &= len - 1;
255 }
256
257 /* XXX Deal with overlap of onboard RAM address space */
258 /* XXX Then again, 167-Bug warns about this at setup time ... */
259
260 /*
261 * Fixup the addresses this range corresponds to
262 */
263 vr->vr_vmestart = start & vr->vr_mask;
264 vr->vr_vmeend = (end - 1) & vr->vr_mask;
265 }
266
267 void
268 vmetwo_slave_range(sc, range, am, vr)
269 struct vmetwo_softc *sc;
270 int range;
271 vme_am_t am;
272 struct mvmebus_range *vr;
273 {
274 u_int32_t reg;
275
276 /*
277 * First, check if the range is actually enabled.
278 * Note that bit 1 of `range' is used to indicte if we're
279 * looking for an A24 range (set) or an A32 range (clear).
280 */
281 reg = vme2_lcsr_read(sc, VME2LCSR_SLAVE_CTRL);
282
283 if (am == VME_AM_A32 && (reg & VME2_SLAVE_AMSEL_A32(range))) {
284 vr->vr_am = VME_AM_A32;
285 vr->vr_mask = 0xffffffffu;
286 } else
287 if (am == VME_AM_A24 && (reg & VME2_SLAVE_AMSEL_A24(range))) {
288 vr->vr_am = VME_AM_A24;
289 vr->vr_mask = 0x00ffffffu;
290 } else {
291 /* The range is not enabled */
292 vr->vr_am = MVMEBUS_AM_DISABLED;
293 return;
294 }
295
296 if ((reg & VME2_SLAVE_AMSEL_DAT(range)) != 0)
297 vr->vr_am |= MVMEBUS_AM_CAP_DATA;
298
299 if ((reg & VME2_SLAVE_AMSEL_PGM(range)) != 0)
300 vr->vr_am |= MVMEBUS_AM_CAP_PROG;
301
302 if ((reg & VME2_SLAVE_AMSEL_USR(range)) != 0)
303 vr->vr_am |= MVMEBUS_AM_CAP_USER;
304
305 if ((reg & VME2_SLAVE_AMSEL_SUP(range)) != 0)
306 vr->vr_am |= MVMEBUS_AM_CAP_SUPER;
307
308 if ((reg & VME2_SLAVE_AMSEL_BLK(range)) != 0)
309 vr->vr_am |= MVMEBUS_AM_CAP_BLK;
310
311 if ((reg & VME2_SLAVE_AMSEL_BLKD64(range)) != 0)
312 vr->vr_am |= MVMEBUS_AM_CAP_BLKD64;
313
314 vr->vr_datasize = VME_D32 | VME_D16 | VME_D8;
315
316 /*
317 * Record the VMEbus start and end addresses of the slave image
318 */
319 reg = vme2_lcsr_read(sc, VME2LCSR_SLAVE_ADDRESS(range));
320 vr->vr_vmestart = reg & VME2_SLAVE_ADDRESS_START_MASK;
321 vr->vr_vmestart <<= VME2_SLAVE_ADDRESS_START_SHIFT;
322 vr->vr_vmestart &= vr->vr_mask;
323 vr->vr_vmeend = reg & VME2_SLAVE_ADDRESS_END_MASK;
324 vr->vr_vmeend <<= VME2_SLAVE_ADDRESS_END_SHIFT;
325 vr->vr_vmeend &= vr->vr_mask;
326 vr->vr_vmeend |= 0xffffu;
327
328 /*
329 * Now figure out the local-bus address
330 */
331 reg = vme2_lcsr_read(sc, VME2LCSR_SLAVE_CTRL);
332 if ((reg & VME2_SLAVE_CTRL_ADDER(range)) != 0) {
333 reg = vme2_lcsr_read(sc, VME2LCSR_SLAVE_TRANS(range));
334 reg &= VME2_SLAVE_TRANS_ADDRESS_MASK;
335 reg <<= VME2_SLAVE_TRANS_ADDRESS_SHIFT;
336 vr->vr_locstart = vr->vr_vmestart + reg;
337 } else {
338 u_int32_t sel, addr;
339
340 reg = vme2_lcsr_read(sc, VME2LCSR_SLAVE_TRANS(range));
341 sel = reg & VME2_SLAVE_TRANS_SELECT_MASK;
342 sel <<= VME2_SLAVE_TRANS_SELECT_SHIFT;
343 addr = reg & VME2_SLAVE_TRANS_ADDRESS_MASK;
344 addr <<= VME2_SLAVE_TRANS_ADDRESS_SHIFT;
345
346 vr->vr_locstart = addr & sel;
347 vr->vr_locstart |= vr->vr_vmestart & (~sel);
348 }
349 }
350