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