vme_pcc.c revision 1.14.8.2 1 1.14.8.2 nathanw /* $NetBSD: vme_pcc.c,v 1.14.8.2 2002/02/28 04:10:51 nathanw Exp $ */
2 1.14.8.2 nathanw
3 1.14.8.2 nathanw /*-
4 1.14.8.2 nathanw * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
5 1.14.8.2 nathanw * All rights reserved.
6 1.14.8.2 nathanw *
7 1.14.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.14.8.2 nathanw * by Jason R. Thorpe and Steve C. Woodford.
9 1.14.8.2 nathanw *
10 1.14.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.14.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.14.8.2 nathanw * are met:
13 1.14.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.14.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.14.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.14.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.14.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.14.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.14.8.2 nathanw * must display the following acknowledgement:
20 1.14.8.2 nathanw * This product includes software developed by the NetBSD
21 1.14.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.14.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.14.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.14.8.2 nathanw * from this software without specific prior written permission.
25 1.14.8.2 nathanw *
26 1.14.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.14.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.14.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.14.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.14.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.14.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.14.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.14.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.14.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.14.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.14.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.14.8.2 nathanw */
38 1.14.8.2 nathanw
39 1.14.8.2 nathanw /*
40 1.14.8.2 nathanw * VME support specific to the Type 1 VMEchip found on the
41 1.14.8.2 nathanw * MVME-147.
42 1.14.8.2 nathanw *
43 1.14.8.2 nathanw * For a manual on the MVME-147, call: 408.991.8634. (Yes, this
44 1.14.8.2 nathanw * is the Sunnyvale sales office.)
45 1.14.8.2 nathanw */
46 1.14.8.2 nathanw
47 1.14.8.2 nathanw #include <sys/param.h>
48 1.14.8.2 nathanw #include <sys/kernel.h>
49 1.14.8.2 nathanw #include <sys/systm.h>
50 1.14.8.2 nathanw #include <sys/device.h>
51 1.14.8.2 nathanw #include <sys/malloc.h>
52 1.14.8.2 nathanw #include <sys/kcore.h>
53 1.14.8.2 nathanw
54 1.14.8.2 nathanw #include <machine/cpu.h>
55 1.14.8.2 nathanw #include <machine/bus.h>
56 1.14.8.2 nathanw
57 1.14.8.2 nathanw #include <dev/vme/vmereg.h>
58 1.14.8.2 nathanw #include <dev/vme/vmevar.h>
59 1.14.8.2 nathanw
60 1.14.8.2 nathanw #include <mvme68k/dev/pccreg.h>
61 1.14.8.2 nathanw #include <mvme68k/dev/pccvar.h>
62 1.14.8.2 nathanw
63 1.14.8.2 nathanw #include <dev/mvme/mvmebus.h>
64 1.14.8.2 nathanw #include <mvme68k/dev/vme_pccreg.h>
65 1.14.8.2 nathanw #include <mvme68k/dev/vme_pccvar.h>
66 1.14.8.2 nathanw
67 1.14.8.2 nathanw
68 1.14.8.2 nathanw int vme_pcc_match(struct device *, struct cfdata *, void *);
69 1.14.8.2 nathanw void vme_pcc_attach(struct device *, struct device *, void *);
70 1.14.8.2 nathanw
71 1.14.8.2 nathanw struct cfattach vmepcc_ca = {
72 1.14.8.2 nathanw sizeof(struct vme_pcc_softc), vme_pcc_match, vme_pcc_attach
73 1.14.8.2 nathanw };
74 1.14.8.2 nathanw
75 1.14.8.2 nathanw extern struct cfdriver vmepcc_cd;
76 1.14.8.2 nathanw
77 1.14.8.2 nathanw extern phys_ram_seg_t mem_clusters[];
78 1.14.8.2 nathanw static int vme_pcc_attached;
79 1.14.8.2 nathanw
80 1.14.8.2 nathanw void vme_pcc_intr_establish(void *, int, int, int, int,
81 1.14.8.2 nathanw int (*)(void *), void *, struct evcnt *);
82 1.14.8.2 nathanw void vme_pcc_intr_disestablish(void *, int, int, int, struct evcnt *);
83 1.14.8.2 nathanw
84 1.14.8.2 nathanw
85 1.14.8.2 nathanw static struct mvmebus_range vme_pcc_masters[] = {
86 1.14.8.2 nathanw {VME_AM_A24 |
87 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
88 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
89 1.14.8.2 nathanw VME_D32 | VME_D16 | VME_D8,
90 1.14.8.2 nathanw VME1_A24D32_LOC_START,
91 1.14.8.2 nathanw VME1_A24_MASK,
92 1.14.8.2 nathanw VME1_A24D32_START,
93 1.14.8.2 nathanw VME1_A24D32_END},
94 1.14.8.2 nathanw
95 1.14.8.2 nathanw {VME_AM_A32 |
96 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
97 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
98 1.14.8.2 nathanw VME_D32 | VME_D16 | VME_D8,
99 1.14.8.2 nathanw VME1_A32D32_LOC_START,
100 1.14.8.2 nathanw VME1_A32_MASK,
101 1.14.8.2 nathanw VME1_A32D32_START,
102 1.14.8.2 nathanw VME1_A32D32_END},
103 1.14.8.2 nathanw
104 1.14.8.2 nathanw {VME_AM_A24 |
105 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
106 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
107 1.14.8.2 nathanw VME_D16 | VME_D8,
108 1.14.8.2 nathanw VME1_A24D16_LOC_START,
109 1.14.8.2 nathanw VME1_A24_MASK,
110 1.14.8.2 nathanw VME1_A24D16_START,
111 1.14.8.2 nathanw VME1_A24D16_END},
112 1.14.8.2 nathanw
113 1.14.8.2 nathanw {VME_AM_A32 |
114 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
115 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
116 1.14.8.2 nathanw VME_D16 | VME_D8,
117 1.14.8.2 nathanw VME1_A32D16_LOC_START,
118 1.14.8.2 nathanw VME1_A32_MASK,
119 1.14.8.2 nathanw VME1_A32D16_START,
120 1.14.8.2 nathanw VME1_A32D16_END},
121 1.14.8.2 nathanw
122 1.14.8.2 nathanw {VME_AM_A16 |
123 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA |
124 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
125 1.14.8.2 nathanw VME_D16 | VME_D8,
126 1.14.8.2 nathanw VME1_A16D16_LOC_START,
127 1.14.8.2 nathanw VME1_A16_MASK,
128 1.14.8.2 nathanw VME1_A16D16_START,
129 1.14.8.2 nathanw VME1_A16D16_END}
130 1.14.8.2 nathanw };
131 1.14.8.2 nathanw #define VME1_NMASTERS (sizeof(vme_pcc_masters)/sizeof(struct mvmebus_range))
132 1.14.8.2 nathanw
133 1.14.8.2 nathanw
134 1.14.8.2 nathanw /* ARGSUSED */
135 1.14.8.2 nathanw int
136 1.14.8.2 nathanw vme_pcc_match(parent, cf, aux)
137 1.14.8.2 nathanw struct device *parent;
138 1.14.8.2 nathanw struct cfdata *cf;
139 1.14.8.2 nathanw void *aux;
140 1.14.8.2 nathanw {
141 1.14.8.2 nathanw struct pcc_attach_args *pa;
142 1.14.8.2 nathanw
143 1.14.8.2 nathanw pa = aux;
144 1.14.8.2 nathanw
145 1.14.8.2 nathanw /* Only one VME chip, please. */
146 1.14.8.2 nathanw if (vme_pcc_attached)
147 1.14.8.2 nathanw return (0);
148 1.14.8.2 nathanw
149 1.14.8.2 nathanw if (strcmp(pa->pa_name, vmepcc_cd.cd_name))
150 1.14.8.2 nathanw return (0);
151 1.14.8.2 nathanw
152 1.14.8.2 nathanw return (1);
153 1.14.8.2 nathanw }
154 1.14.8.2 nathanw
155 1.14.8.2 nathanw void
156 1.14.8.2 nathanw vme_pcc_attach(parent, self, aux)
157 1.14.8.2 nathanw struct device *parent;
158 1.14.8.2 nathanw struct device *self;
159 1.14.8.2 nathanw void *aux;
160 1.14.8.2 nathanw {
161 1.14.8.2 nathanw struct pcc_attach_args *pa;
162 1.14.8.2 nathanw struct vme_pcc_softc *sc;
163 1.14.8.2 nathanw vme_am_t am;
164 1.14.8.2 nathanw u_int8_t reg;
165 1.14.8.2 nathanw
166 1.14.8.2 nathanw sc = (struct vme_pcc_softc *) self;
167 1.14.8.2 nathanw pa = aux;
168 1.14.8.2 nathanw
169 1.14.8.2 nathanw /* Map the VMEchip's registers */
170 1.14.8.2 nathanw bus_space_map(pa->pa_bust, pa->pa_offset, VME1REG_SIZE, 0,
171 1.14.8.2 nathanw &sc->sc_bush);
172 1.14.8.2 nathanw
173 1.14.8.2 nathanw /* Initialise stuff used by the mvme68k common VMEbus front-end */
174 1.14.8.2 nathanw sc->sc_mvmebus.sc_bust = pa->pa_bust;
175 1.14.8.2 nathanw sc->sc_mvmebus.sc_dmat = pa->pa_dmat;
176 1.14.8.2 nathanw sc->sc_mvmebus.sc_chip = sc;
177 1.14.8.2 nathanw sc->sc_mvmebus.sc_nmasters = VME1_NMASTERS;
178 1.14.8.2 nathanw sc->sc_mvmebus.sc_masters = &vme_pcc_masters[0];
179 1.14.8.2 nathanw sc->sc_mvmebus.sc_nslaves = VME1_NSLAVES;
180 1.14.8.2 nathanw sc->sc_mvmebus.sc_slaves = &sc->sc_slave[0];
181 1.14.8.2 nathanw sc->sc_mvmebus.sc_intr_establish = vme_pcc_intr_establish;
182 1.14.8.2 nathanw sc->sc_mvmebus.sc_intr_disestablish = vme_pcc_intr_disestablish;
183 1.14.8.2 nathanw
184 1.14.8.2 nathanw /* Initialize the chip. */
185 1.14.8.2 nathanw reg = vme1_reg_read(sc, VME1REG_SCON) & ~VME1_SCON_SYSFAIL;
186 1.14.8.2 nathanw vme1_reg_write(sc, VME1REG_SCON, reg);
187 1.14.8.2 nathanw
188 1.14.8.2 nathanw printf(": Type 1 VMEchip, scon jumper %s\n",
189 1.14.8.2 nathanw (reg & VME1_SCON_SWITCH) ? "enabled" : "disabled");
190 1.14.8.2 nathanw
191 1.14.8.2 nathanw /*
192 1.14.8.2 nathanw * Adjust the start address of the first range in vme_pcc_masters[]
193 1.14.8.2 nathanw * according to how much onboard memory exists. Disable the first
194 1.14.8.2 nathanw * range if onboard memory >= 16Mb, and adjust the start of the
195 1.14.8.2 nathanw * second range (A32D32).
196 1.14.8.2 nathanw */
197 1.14.8.2 nathanw vme_pcc_masters[0].vr_vmestart = (vme_addr_t) mem_clusters[0].size;
198 1.14.8.2 nathanw if (mem_clusters[0].size >= 0x01000000) {
199 1.14.8.2 nathanw vme_pcc_masters[0].vr_am = MVMEBUS_AM_DISABLED;
200 1.14.8.2 nathanw vme_pcc_masters[1].vr_vmestart +=
201 1.14.8.2 nathanw (vme_addr_t) (mem_clusters[0].size - 0x01000000);
202 1.14.8.2 nathanw }
203 1.14.8.2 nathanw
204 1.14.8.2 nathanw am = 0;
205 1.14.8.2 nathanw reg = vme1_reg_read(sc, VME1REG_SLADDRMOD);
206 1.14.8.2 nathanw if ((reg & VME1_SLMOD_DATA) != 0)
207 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_DATA;
208 1.14.8.2 nathanw if ((reg & VME1_SLMOD_PRGRM) != 0)
209 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_PROG;
210 1.14.8.2 nathanw if ((reg & VME1_SLMOD_SUPER) != 0)
211 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_SUPER;
212 1.14.8.2 nathanw if ((reg & VME1_SLMOD_USER) != 0)
213 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_USER;
214 1.14.8.2 nathanw if ((reg & VME1_SLMOD_BLOCK) != 0)
215 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_BLK;
216 1.14.8.2 nathanw
217 1.14.8.2 nathanw #ifdef notyet
218 1.14.8.2 nathanw if ((reg & VME1_SLMOD_SHORT) != 0) {
219 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A16].vr_am = am | VME_AM_A16;
220 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A16].vr_mask = 0xffffu;
221 1.14.8.2 nathanw } else
222 1.14.8.2 nathanw #endif
223 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A16].vr_am = MVMEBUS_AM_DISABLED;
224 1.14.8.2 nathanw
225 1.14.8.2 nathanw if (pcc_slave_base_addr < 0x01000000u && (reg & VME1_SLMOD_STND) != 0) {
226 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_am = am | VME_AM_A24;
227 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_datasize = VME_D32 |
228 1.14.8.2 nathanw VME_D16 | VME_D8;
229 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_mask = 0xffffffu;
230 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_locstart = 0;
231 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_vmestart = pcc_slave_base_addr;
232 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_vmeend = (pcc_slave_base_addr +
233 1.14.8.2 nathanw mem_clusters[0].size - 1) & 0x00ffffffu;
234 1.14.8.2 nathanw } else
235 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_am = MVMEBUS_AM_DISABLED;
236 1.14.8.2 nathanw
237 1.14.8.2 nathanw if ((reg & VME1_SLMOD_EXTED) != 0) {
238 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_am = am | VME_AM_A32;
239 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_datasize = VME_D32 |
240 1.14.8.2 nathanw VME_D16 | VME_D8;
241 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_mask = 0xffffffffu;
242 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_locstart = 0;
243 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_vmestart = pcc_slave_base_addr;
244 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_vmeend =
245 1.14.8.2 nathanw pcc_slave_base_addr + mem_clusters[0].size - 1;
246 1.14.8.2 nathanw } else
247 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_am = MVMEBUS_AM_DISABLED;
248 1.14.8.2 nathanw
249 1.14.8.2 nathanw vme_pcc_attached = 1;
250 1.14.8.2 nathanw
251 1.14.8.2 nathanw mvmebus_attach(&sc->sc_mvmebus);
252 1.14.8.2 nathanw }
253 1.14.8.2 nathanw
254 1.14.8.2 nathanw void
255 1.14.8.2 nathanw vme_pcc_intr_establish(csc, prior, level, vector, first, func, arg, evcnt)
256 1.14.8.2 nathanw void *csc;
257 1.14.8.2 nathanw int prior, level, vector, first;
258 1.14.8.2 nathanw int (*func)(void *);
259 1.14.8.2 nathanw void *arg;
260 1.14.8.2 nathanw struct evcnt *evcnt;
261 1.14.8.2 nathanw {
262 1.14.8.2 nathanw struct vme_pcc_softc *sc = csc;
263 1.14.8.2 nathanw
264 1.14.8.2 nathanw if (prior != level)
265 1.14.8.2 nathanw panic("vme_pcc_intr_establish: cpu priority != VMEbus irq level");
266 1.14.8.2 nathanw
267 1.14.8.2 nathanw isrlink_vectored(func, arg, prior, vector, evcnt);
268 1.14.8.2 nathanw
269 1.14.8.2 nathanw if (first) {
270 1.14.8.2 nathanw evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
271 1.14.8.2 nathanw isrlink_evcnt(prior), sc->sc_mvmebus.sc_dev.dv_xname,
272 1.14.8.2 nathanw mvmebus_irq_name[level]);
273 1.14.8.2 nathanw
274 1.14.8.2 nathanw /*
275 1.14.8.2 nathanw * There had better not be another VMEbus master responding
276 1.14.8.2 nathanw * to this interrupt level...
277 1.14.8.2 nathanw */
278 1.14.8.2 nathanw vme1_reg_write(sc, VME1REG_IRQEN,
279 1.14.8.2 nathanw vme1_reg_read(sc, VME1REG_IRQEN) | VME1_IRQ_VME(level));
280 1.14.8.2 nathanw }
281 1.14.8.2 nathanw }
282 1.14.8.2 nathanw
283 1.14.8.2 nathanw void
284 1.14.8.2 nathanw vme_pcc_intr_disestablish(csc, level, vector, last, evcnt)
285 1.14.8.2 nathanw void *csc;
286 1.14.8.2 nathanw int level, vector, last;
287 1.14.8.2 nathanw struct evcnt *evcnt;
288 1.14.8.2 nathanw {
289 1.14.8.2 nathanw struct vme_pcc_softc *sc = csc;
290 1.14.8.2 nathanw
291 1.14.8.2 nathanw isrunlink_vectored(vector);
292 1.14.8.2 nathanw
293 1.14.8.2 nathanw if (last) {
294 1.14.8.2 nathanw vme1_reg_write(sc, VME1REG_IRQEN,
295 1.14.8.2 nathanw vme1_reg_read(sc, VME1REG_IRQEN) & ~VME1_IRQ_VME(level));
296 1.14.8.2 nathanw evcnt_detach(evcnt);
297 1.14.8.2 nathanw }
298 1.14.8.2 nathanw }
299