vme_pcc.c revision 1.14.8.3 1 1.14.8.3 nathanw /* $NetBSD: vme_pcc.c,v 1.14.8.3 2002/10/18 02:38:58 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.3 nathanw CFATTACH_DECL(vmepcc, sizeof(struct vme_pcc_softc),
72 1.14.8.3 nathanw vme_pcc_match, vme_pcc_attach, NULL, NULL);
73 1.14.8.2 nathanw
74 1.14.8.2 nathanw extern struct cfdriver vmepcc_cd;
75 1.14.8.2 nathanw
76 1.14.8.2 nathanw extern phys_ram_seg_t mem_clusters[];
77 1.14.8.2 nathanw static int vme_pcc_attached;
78 1.14.8.2 nathanw
79 1.14.8.2 nathanw void vme_pcc_intr_establish(void *, int, int, int, int,
80 1.14.8.2 nathanw int (*)(void *), void *, struct evcnt *);
81 1.14.8.2 nathanw void vme_pcc_intr_disestablish(void *, int, int, int, struct evcnt *);
82 1.14.8.2 nathanw
83 1.14.8.2 nathanw
84 1.14.8.2 nathanw static struct mvmebus_range vme_pcc_masters[] = {
85 1.14.8.2 nathanw {VME_AM_A24 |
86 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
87 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
88 1.14.8.2 nathanw VME_D32 | VME_D16 | VME_D8,
89 1.14.8.2 nathanw VME1_A24D32_LOC_START,
90 1.14.8.2 nathanw VME1_A24_MASK,
91 1.14.8.2 nathanw VME1_A24D32_START,
92 1.14.8.2 nathanw VME1_A24D32_END},
93 1.14.8.2 nathanw
94 1.14.8.2 nathanw {VME_AM_A32 |
95 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
96 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
97 1.14.8.2 nathanw VME_D32 | VME_D16 | VME_D8,
98 1.14.8.2 nathanw VME1_A32D32_LOC_START,
99 1.14.8.2 nathanw VME1_A32_MASK,
100 1.14.8.2 nathanw VME1_A32D32_START,
101 1.14.8.2 nathanw VME1_A32D32_END},
102 1.14.8.2 nathanw
103 1.14.8.2 nathanw {VME_AM_A24 |
104 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
105 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
106 1.14.8.2 nathanw VME_D16 | VME_D8,
107 1.14.8.2 nathanw VME1_A24D16_LOC_START,
108 1.14.8.2 nathanw VME1_A24_MASK,
109 1.14.8.2 nathanw VME1_A24D16_START,
110 1.14.8.2 nathanw VME1_A24D16_END},
111 1.14.8.2 nathanw
112 1.14.8.2 nathanw {VME_AM_A32 |
113 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA | MVMEBUS_AM_CAP_PROG |
114 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
115 1.14.8.2 nathanw VME_D16 | VME_D8,
116 1.14.8.2 nathanw VME1_A32D16_LOC_START,
117 1.14.8.2 nathanw VME1_A32_MASK,
118 1.14.8.2 nathanw VME1_A32D16_START,
119 1.14.8.2 nathanw VME1_A32D16_END},
120 1.14.8.2 nathanw
121 1.14.8.2 nathanw {VME_AM_A16 |
122 1.14.8.2 nathanw MVMEBUS_AM_CAP_DATA |
123 1.14.8.2 nathanw MVMEBUS_AM_CAP_SUPER | MVMEBUS_AM_CAP_USER,
124 1.14.8.2 nathanw VME_D16 | VME_D8,
125 1.14.8.2 nathanw VME1_A16D16_LOC_START,
126 1.14.8.2 nathanw VME1_A16_MASK,
127 1.14.8.2 nathanw VME1_A16D16_START,
128 1.14.8.2 nathanw VME1_A16D16_END}
129 1.14.8.2 nathanw };
130 1.14.8.2 nathanw #define VME1_NMASTERS (sizeof(vme_pcc_masters)/sizeof(struct mvmebus_range))
131 1.14.8.2 nathanw
132 1.14.8.2 nathanw
133 1.14.8.2 nathanw /* ARGSUSED */
134 1.14.8.2 nathanw int
135 1.14.8.2 nathanw vme_pcc_match(parent, cf, aux)
136 1.14.8.2 nathanw struct device *parent;
137 1.14.8.2 nathanw struct cfdata *cf;
138 1.14.8.2 nathanw void *aux;
139 1.14.8.2 nathanw {
140 1.14.8.2 nathanw struct pcc_attach_args *pa;
141 1.14.8.2 nathanw
142 1.14.8.2 nathanw pa = aux;
143 1.14.8.2 nathanw
144 1.14.8.2 nathanw /* Only one VME chip, please. */
145 1.14.8.2 nathanw if (vme_pcc_attached)
146 1.14.8.2 nathanw return (0);
147 1.14.8.2 nathanw
148 1.14.8.2 nathanw if (strcmp(pa->pa_name, vmepcc_cd.cd_name))
149 1.14.8.2 nathanw return (0);
150 1.14.8.2 nathanw
151 1.14.8.2 nathanw return (1);
152 1.14.8.2 nathanw }
153 1.14.8.2 nathanw
154 1.14.8.2 nathanw void
155 1.14.8.2 nathanw vme_pcc_attach(parent, self, aux)
156 1.14.8.2 nathanw struct device *parent;
157 1.14.8.2 nathanw struct device *self;
158 1.14.8.2 nathanw void *aux;
159 1.14.8.2 nathanw {
160 1.14.8.2 nathanw struct pcc_attach_args *pa;
161 1.14.8.2 nathanw struct vme_pcc_softc *sc;
162 1.14.8.2 nathanw vme_am_t am;
163 1.14.8.2 nathanw u_int8_t reg;
164 1.14.8.2 nathanw
165 1.14.8.2 nathanw sc = (struct vme_pcc_softc *) self;
166 1.14.8.2 nathanw pa = aux;
167 1.14.8.2 nathanw
168 1.14.8.2 nathanw /* Map the VMEchip's registers */
169 1.14.8.2 nathanw bus_space_map(pa->pa_bust, pa->pa_offset, VME1REG_SIZE, 0,
170 1.14.8.2 nathanw &sc->sc_bush);
171 1.14.8.2 nathanw
172 1.14.8.2 nathanw /* Initialise stuff used by the mvme68k common VMEbus front-end */
173 1.14.8.2 nathanw sc->sc_mvmebus.sc_bust = pa->pa_bust;
174 1.14.8.2 nathanw sc->sc_mvmebus.sc_dmat = pa->pa_dmat;
175 1.14.8.2 nathanw sc->sc_mvmebus.sc_chip = sc;
176 1.14.8.2 nathanw sc->sc_mvmebus.sc_nmasters = VME1_NMASTERS;
177 1.14.8.2 nathanw sc->sc_mvmebus.sc_masters = &vme_pcc_masters[0];
178 1.14.8.2 nathanw sc->sc_mvmebus.sc_nslaves = VME1_NSLAVES;
179 1.14.8.2 nathanw sc->sc_mvmebus.sc_slaves = &sc->sc_slave[0];
180 1.14.8.2 nathanw sc->sc_mvmebus.sc_intr_establish = vme_pcc_intr_establish;
181 1.14.8.2 nathanw sc->sc_mvmebus.sc_intr_disestablish = vme_pcc_intr_disestablish;
182 1.14.8.2 nathanw
183 1.14.8.2 nathanw /* Initialize the chip. */
184 1.14.8.2 nathanw reg = vme1_reg_read(sc, VME1REG_SCON) & ~VME1_SCON_SYSFAIL;
185 1.14.8.2 nathanw vme1_reg_write(sc, VME1REG_SCON, reg);
186 1.14.8.2 nathanw
187 1.14.8.2 nathanw printf(": Type 1 VMEchip, scon jumper %s\n",
188 1.14.8.2 nathanw (reg & VME1_SCON_SWITCH) ? "enabled" : "disabled");
189 1.14.8.2 nathanw
190 1.14.8.2 nathanw /*
191 1.14.8.2 nathanw * Adjust the start address of the first range in vme_pcc_masters[]
192 1.14.8.2 nathanw * according to how much onboard memory exists. Disable the first
193 1.14.8.2 nathanw * range if onboard memory >= 16Mb, and adjust the start of the
194 1.14.8.2 nathanw * second range (A32D32).
195 1.14.8.2 nathanw */
196 1.14.8.2 nathanw vme_pcc_masters[0].vr_vmestart = (vme_addr_t) mem_clusters[0].size;
197 1.14.8.2 nathanw if (mem_clusters[0].size >= 0x01000000) {
198 1.14.8.2 nathanw vme_pcc_masters[0].vr_am = MVMEBUS_AM_DISABLED;
199 1.14.8.2 nathanw vme_pcc_masters[1].vr_vmestart +=
200 1.14.8.2 nathanw (vme_addr_t) (mem_clusters[0].size - 0x01000000);
201 1.14.8.2 nathanw }
202 1.14.8.2 nathanw
203 1.14.8.2 nathanw am = 0;
204 1.14.8.2 nathanw reg = vme1_reg_read(sc, VME1REG_SLADDRMOD);
205 1.14.8.2 nathanw if ((reg & VME1_SLMOD_DATA) != 0)
206 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_DATA;
207 1.14.8.2 nathanw if ((reg & VME1_SLMOD_PRGRM) != 0)
208 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_PROG;
209 1.14.8.2 nathanw if ((reg & VME1_SLMOD_SUPER) != 0)
210 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_SUPER;
211 1.14.8.2 nathanw if ((reg & VME1_SLMOD_USER) != 0)
212 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_USER;
213 1.14.8.2 nathanw if ((reg & VME1_SLMOD_BLOCK) != 0)
214 1.14.8.2 nathanw am |= MVMEBUS_AM_CAP_BLK;
215 1.14.8.2 nathanw
216 1.14.8.2 nathanw #ifdef notyet
217 1.14.8.2 nathanw if ((reg & VME1_SLMOD_SHORT) != 0) {
218 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A16].vr_am = am | VME_AM_A16;
219 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A16].vr_mask = 0xffffu;
220 1.14.8.2 nathanw } else
221 1.14.8.2 nathanw #endif
222 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A16].vr_am = MVMEBUS_AM_DISABLED;
223 1.14.8.2 nathanw
224 1.14.8.2 nathanw if (pcc_slave_base_addr < 0x01000000u && (reg & VME1_SLMOD_STND) != 0) {
225 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_am = am | VME_AM_A24;
226 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_datasize = VME_D32 |
227 1.14.8.2 nathanw VME_D16 | VME_D8;
228 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_mask = 0xffffffu;
229 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_locstart = 0;
230 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_vmestart = pcc_slave_base_addr;
231 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_vmeend = (pcc_slave_base_addr +
232 1.14.8.2 nathanw mem_clusters[0].size - 1) & 0x00ffffffu;
233 1.14.8.2 nathanw } else
234 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A24].vr_am = MVMEBUS_AM_DISABLED;
235 1.14.8.2 nathanw
236 1.14.8.2 nathanw if ((reg & VME1_SLMOD_EXTED) != 0) {
237 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_am = am | VME_AM_A32;
238 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_datasize = VME_D32 |
239 1.14.8.2 nathanw VME_D16 | VME_D8;
240 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_mask = 0xffffffffu;
241 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_locstart = 0;
242 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_vmestart = pcc_slave_base_addr;
243 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_vmeend =
244 1.14.8.2 nathanw pcc_slave_base_addr + mem_clusters[0].size - 1;
245 1.14.8.2 nathanw } else
246 1.14.8.2 nathanw sc->sc_slave[VME1_SLAVE_A32].vr_am = MVMEBUS_AM_DISABLED;
247 1.14.8.2 nathanw
248 1.14.8.2 nathanw vme_pcc_attached = 1;
249 1.14.8.2 nathanw
250 1.14.8.2 nathanw mvmebus_attach(&sc->sc_mvmebus);
251 1.14.8.2 nathanw }
252 1.14.8.2 nathanw
253 1.14.8.2 nathanw void
254 1.14.8.2 nathanw vme_pcc_intr_establish(csc, prior, level, vector, first, func, arg, evcnt)
255 1.14.8.2 nathanw void *csc;
256 1.14.8.2 nathanw int prior, level, vector, first;
257 1.14.8.2 nathanw int (*func)(void *);
258 1.14.8.2 nathanw void *arg;
259 1.14.8.2 nathanw struct evcnt *evcnt;
260 1.14.8.2 nathanw {
261 1.14.8.2 nathanw struct vme_pcc_softc *sc = csc;
262 1.14.8.2 nathanw
263 1.14.8.2 nathanw if (prior != level)
264 1.14.8.2 nathanw panic("vme_pcc_intr_establish: cpu priority != VMEbus irq level");
265 1.14.8.2 nathanw
266 1.14.8.2 nathanw isrlink_vectored(func, arg, prior, vector, evcnt);
267 1.14.8.2 nathanw
268 1.14.8.2 nathanw if (first) {
269 1.14.8.2 nathanw evcnt_attach_dynamic(evcnt, EVCNT_TYPE_INTR,
270 1.14.8.2 nathanw isrlink_evcnt(prior), sc->sc_mvmebus.sc_dev.dv_xname,
271 1.14.8.2 nathanw mvmebus_irq_name[level]);
272 1.14.8.2 nathanw
273 1.14.8.2 nathanw /*
274 1.14.8.2 nathanw * There had better not be another VMEbus master responding
275 1.14.8.2 nathanw * to this interrupt level...
276 1.14.8.2 nathanw */
277 1.14.8.2 nathanw vme1_reg_write(sc, VME1REG_IRQEN,
278 1.14.8.2 nathanw vme1_reg_read(sc, VME1REG_IRQEN) | VME1_IRQ_VME(level));
279 1.14.8.2 nathanw }
280 1.14.8.2 nathanw }
281 1.14.8.2 nathanw
282 1.14.8.2 nathanw void
283 1.14.8.2 nathanw vme_pcc_intr_disestablish(csc, level, vector, last, evcnt)
284 1.14.8.2 nathanw void *csc;
285 1.14.8.2 nathanw int level, vector, last;
286 1.14.8.2 nathanw struct evcnt *evcnt;
287 1.14.8.2 nathanw {
288 1.14.8.2 nathanw struct vme_pcc_softc *sc = csc;
289 1.14.8.2 nathanw
290 1.14.8.2 nathanw isrunlink_vectored(vector);
291 1.14.8.2 nathanw
292 1.14.8.2 nathanw if (last) {
293 1.14.8.2 nathanw vme1_reg_write(sc, VME1REG_IRQEN,
294 1.14.8.2 nathanw vme1_reg_read(sc, VME1REG_IRQEN) & ~VME1_IRQ_VME(level));
295 1.14.8.2 nathanw evcnt_detach(evcnt);
296 1.14.8.2 nathanw }
297 1.14.8.2 nathanw }
298