vme_pcc.c revision 1.6.16.1 1 /* $NetBSD: vme_pcc.c,v 1.6.16.1 2000/11/20 20:15:19 bouyer Exp $ */
2
3 /*-
4 * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe and 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 * VME support specific to the Type 1 VMEchip found on the
41 * MVME-147.
42 *
43 * For a manual on the MVME-147, call: 408.991.8634. (Yes, this
44 * is the Sunnyvale sales office.)
45 */
46
47 #include <sys/param.h>
48 #include <sys/kernel.h>
49 #include <sys/systm.h>
50 #include <sys/device.h>
51 #include <sys/malloc.h>
52 #include <sys/kcore.h>
53
54 #include <machine/cpu.h>
55 #include <machine/bus.h>
56
57 #include <dev/vme/vmereg.h>
58 #include <dev/vme/vmevar.h>
59
60 #include <mvme68k/mvme68k/isr.h>
61
62 #include <mvme68k/dev/pccreg.h>
63 #include <mvme68k/dev/pccvar.h>
64 #include <mvme68k/dev/mvmebus.h>
65 #include <mvme68k/dev/vme_pccreg.h>
66 #include <mvme68k/dev/vme_pccvar.h>
67
68
69 int vme_pcc_match(struct device *, struct cfdata *, void *);
70 void vme_pcc_attach(struct device *, struct device *, void *);
71
72 struct cfattach vmepcc_ca = {
73 sizeof(struct vme_pcc_softc), vme_pcc_match, vme_pcc_attach
74 };
75
76 extern struct cfdriver vmepcc_cd;
77
78 extern phys_ram_seg_t mem_clusters[];
79 static int vme_pcc_attached;
80
81 void vme_pcc_intr_establish(void *, int, int, int, int,
82 int (*)(void *), void *);
83 void vme_pcc_intr_disestablish(void *, int, int, int);
84
85
86 static struct mvmebus_range vme_pcc_masters[] = {
87 {VME_AM_A24 |
88 MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
89 MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
90 VME_D32 | VME_D16 | VME_D8,
91 VME1_A24D32_LOC_START,
92 VME1_A24_MASK,
93 VME1_A24D32_START,
94 VME1_A24D32_END},
95
96 {VME_AM_A32 |
97 MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
98 MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
99 VME_D32 | VME_D16 | VME_D8,
100 VME1_A32D32_LOC_START,
101 VME1_A32_MASK,
102 VME1_A32D32_START,
103 VME1_A32D32_END},
104
105 {VME_AM_A24 |
106 MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
107 MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
108 VME_D16 | VME_D8,
109 VME1_A24D16_LOC_START,
110 VME1_A24_MASK,
111 VME1_A24D16_START,
112 VME1_A24D16_END},
113
114 {VME_AM_A32 |
115 MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
116 MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
117 VME_D16 | VME_D8,
118 VME1_A32D16_LOC_START,
119 VME1_A32_MASK,
120 VME1_A32D16_START,
121 VME1_A32D16_END},
122
123 {VME_AM_A16 |
124 MVMEBUS_AM_CAP_DATA |
125 MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
126 VME_D16 | VME_D8,
127 VME1_A16D16_LOC_START,
128 VME1_A16_MASK,
129 VME1_A16D16_START,
130 VME1_A16D16_END}
131 };
132 #define VME1_NMASTERS (sizeof(vme_pcc_masters)/sizeof(struct mvmebus_range))
133
134
135 /* ARGSUSED */
136 int
137 vme_pcc_match(parent, cf, aux)
138 struct device *parent;
139 struct cfdata *cf;
140 void *aux;
141 {
142 struct pcc_attach_args *pa;
143
144 pa = aux;
145
146 /* Only one VME chip, please. */
147 if (vme_pcc_attached)
148 return (0);
149
150 if (strcmp(pa->pa_name, vmepcc_cd.cd_name))
151 return (0);
152
153 return (1);
154 }
155
156 void
157 vme_pcc_attach(parent, self, aux)
158 struct device *parent;
159 struct device *self;
160 void *aux;
161 {
162 struct pcc_attach_args *pa;
163 struct vme_pcc_softc *sc;
164 vme_am_t am;
165 u_int8_t reg;
166
167 sc = (struct vme_pcc_softc *) self;
168 pa = aux;
169
170 sc->sc_bust = pa->pa_bust;
171
172 /* Map the VMEchip's registers */
173 bus_space_map(sc->sc_bust, pa->pa_offset, VME1REG_SIZE, 0,
174 &sc->sc_bush);
175
176 /* Initialize the chip. */
177 reg = vme1_reg_read(sc, VME1REG_SCON) & ~VME1_SCON_SYSFAIL;
178 vme1_reg_write(sc, VME1REG_SCON, reg);
179
180 printf(": Type 1 VMEchip, scon jumper %s\n",
181 (reg & VME1_SCON_SWITCH) ? "enabled" : "disabled");
182
183 /*
184 * Adjust the start address of the first range in vme_pcc_masters[]
185 * according to how much onboard memory exists. Disable the first
186 * range if onboard memory >= 16Mb, and adjust the start of the
187 * second range (A32D32).
188 */
189 vme_pcc_masters[0].vr_vmestart = (vme_addr_t) mem_clusters[0].size;
190 if (mem_clusters[0].size >= 0x01000000) {
191 vme_pcc_masters[0].vr_am = MVMEBUS_AM_DISABLED;
192 vme_pcc_masters[1].vr_vmestart +=
193 (vme_addr_t) (mem_clusters[0].size - 0x01000000);
194 }
195
196 am = 0;
197 reg = vme1_reg_read(sc, VME1REG_SLADDRMOD);
198 if ((reg & VME1_SLMOD_DATA) != 0)
199 am |= MVMEBUS_AM_CAP_DATA;
200 if ((reg & VME1_SLMOD_PRGRM) != 0)
201 am |= MVMEBUS_AM_CAP_PROG;
202 if ((reg & VME1_SLMOD_SUPER) != 0)
203 am |= MVMEBUS_AM_CAP_SUPER;
204 if ((reg & VME1_SLMOD_USER) != 0)
205 am |= MVMEBUS_AM_CAP_USER;
206 if ((reg & VME1_SLMOD_BLOCK) != 0)
207 am |= MVMEBUS_AM_CAP_BLK;
208
209 #ifdef notyet
210 if ((reg & VME1_SLMOD_SHORT) != 0) {
211 sc->sc_slave[VME1_SLAVE_A16].vr_am = am | VME_AM_A16;
212 sc->sc_slave[VME1_SLAVE_A16].vr_mask = 0xffffu;
213 } else
214 #endif
215 sc->sc_slave[VME1_SLAVE_A16].vr_am = MVMEBUS_AM_DISABLED;
216
217 if (pcc_slave_base_addr < 0x01000000u && (reg & VME1_SLMOD_STND) != 0) {
218 sc->sc_slave[VME1_SLAVE_A24].vr_am = am | VME_AM_A24;
219 sc->sc_slave[VME1_SLAVE_A24].vr_datasize = VME_D32 |
220 VME_D16 | VME_D8;
221 sc->sc_slave[VME1_SLAVE_A24].vr_mask = 0xffffffu;
222 sc->sc_slave[VME1_SLAVE_A24].vr_locstart = 0;
223 sc->sc_slave[VME1_SLAVE_A24].vr_vmestart = pcc_slave_base_addr;
224 sc->sc_slave[VME1_SLAVE_A24].vr_vmeend = (pcc_slave_base_addr +
225 mem_clusters[0].size - 1) & 0x00ffffffu;
226 } else
227 sc->sc_slave[VME1_SLAVE_A24].vr_am = MVMEBUS_AM_DISABLED;
228
229 if ((reg & VME1_SLMOD_EXTED) != 0) {
230 sc->sc_slave[VME1_SLAVE_A32].vr_am = am | VME_AM_A32;
231 sc->sc_slave[VME1_SLAVE_A32].vr_datasize = VME_D32 |
232 VME_D16 | VME_D8;
233 sc->sc_slave[VME1_SLAVE_A32].vr_mask = 0xffffffffu;
234 sc->sc_slave[VME1_SLAVE_A32].vr_locstart = 0;
235 sc->sc_slave[VME1_SLAVE_A32].vr_vmestart = pcc_slave_base_addr;
236 sc->sc_slave[VME1_SLAVE_A32].vr_vmeend =
237 pcc_slave_base_addr + mem_clusters[0].size - 1;
238 } else
239 sc->sc_slave[VME1_SLAVE_A32].vr_am = MVMEBUS_AM_DISABLED;
240
241 /* Attach to the mvme68k common VMEbus front-end */
242 sc->sc_mvmebus.sc_dmat = pa->pa_dmat;
243 sc->sc_mvmebus.sc_chip = sc;
244 sc->sc_mvmebus.sc_nmasters = VME1_NMASTERS;
245 sc->sc_mvmebus.sc_masters = &vme_pcc_masters[0];
246 sc->sc_mvmebus.sc_nslaves = VME1_NSLAVES;
247 sc->sc_mvmebus.sc_slaves = &sc->sc_slave[0];
248 sc->sc_mvmebus.sc_intr_establish = vme_pcc_intr_establish;
249 sc->sc_mvmebus.sc_intr_disestablish = vme_pcc_intr_disestablish;
250
251 vme_pcc_attached = 1;
252
253 mvmebus_attach(&sc->sc_mvmebus);
254 }
255
256 void
257 vme_pcc_intr_establish(csc, prior, level, vector, first, func, arg)
258 void *csc;
259 int prior, level, vector, first;
260 int (*func)(void *);
261 void *arg;
262 {
263 struct vme_pcc_softc *sc = csc;
264
265 if (prior != level)
266 panic("vme_pcc_intr_establish: cpu priority != VMEbus irq level");
267
268 isrlink_vectored(func, arg, prior, vector);
269
270 if (first) {
271 /*
272 * There had better not be another VMEbus master responding
273 * to this interrupt level...
274 */
275 vme1_reg_write(sc, VME1REG_IRQEN,
276 vme1_reg_read(sc, VME1REG_IRQEN) | VME1_IRQ_VME(level));
277 }
278 }
279
280 void
281 vme_pcc_intr_disestablish(csc, level, vector, last)
282 void *csc;
283 int level, vector, last;
284 {
285 struct vme_pcc_softc *sc = csc;
286
287 isrunlink_vectored(vector);
288
289 if (last) {
290 vme1_reg_write(sc, VME1REG_IRQEN,
291 vme1_reg_read(sc, VME1REG_IRQEN) & ~VME1_IRQ_VME(level));
292 }
293 }
294