vme_pcc.c revision 1.10 1 /* $NetBSD: vme_pcc.c,v 1.10 2000/08/13 17:00:52 scw 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 (*)(void *), void *);
82 void vme_pcc_intr_disestablish(void *, int, int, int);
83
84
85 static struct mvmebus_range vme_pcc_masters[] = {
86 {VME_AM_MBO | VME_AM_A24 | VME_AM_DATA | VME_AM_SUPER,
87 VME_D32 | VME_D16,
88 VME1_A24D32_LOC_START,
89 VME1_A24_MASK,
90 VME1_A24D32_START,
91 VME1_A24D32_END},
92
93 {VME_AM_MBO | VME_AM_A32 | VME_AM_DATA | VME_AM_SUPER,
94 VME_D32 | VME_D16,
95 VME1_A32D32_LOC_START,
96 VME1_A32_MASK,
97 VME1_A32D32_START,
98 VME1_A32D32_END},
99
100 {VME_AM_MBO | VME_AM_A24 | VME_AM_DATA | VME_AM_SUPER,
101 VME_D16,
102 VME1_A24D16_LOC_START,
103 VME1_A24_MASK,
104 VME1_A24D16_START,
105 VME1_A24D16_END},
106
107 {VME_AM_MBO | VME_AM_A32 | VME_AM_DATA | VME_AM_SUPER,
108 VME_D16 | VME_D8,
109 VME1_A32D16_LOC_START,
110 VME1_A32_MASK,
111 VME1_A32D16_START,
112 VME1_A32D16_END},
113
114 {VME_AM_MBO | VME_AM_A16 | VME_AM_DATA | VME_AM_SUPER,
115 VME_D16 | VME_D8,
116 VME1_A16D16_LOC_START,
117 VME1_A16_MASK,
118 VME1_A16D16_START,
119 VME1_A16D16_END}
120 };
121 #define VME1_NMASTERS (sizeof(vme_pcc_masters)/sizeof(struct mvmebus_range))
122
123
124 /* ARGSUSED */
125 int
126 vme_pcc_match(parent, cf, aux)
127 struct device *parent;
128 struct cfdata *cf;
129 void *aux;
130 {
131 struct pcc_attach_args *pa;
132
133 pa = aux;
134
135 /* Only one VME chip, please. */
136 if (vme_pcc_attached)
137 return (0);
138
139 if (strcmp(pa->pa_name, vmepcc_cd.cd_name))
140 return (0);
141
142 return (1);
143 }
144
145 void
146 vme_pcc_attach(parent, self, aux)
147 struct device *parent;
148 struct device *self;
149 void *aux;
150 {
151 struct pcc_attach_args *pa;
152 struct vme_pcc_softc *sc;
153 u_int8_t reg;
154
155 sc = (struct vme_pcc_softc *) self;
156 pa = aux;
157
158 sc->sc_bust = pa->pa_bust;
159
160 /* Map the VMEchip's registers */
161 bus_space_map(sc->sc_bust, pa->pa_offset, VME1REG_SIZE, 0,
162 &sc->sc_bush);
163
164 /* Initialize the chip. */
165 reg = vme1_reg_read(sc, VME1REG_SCON) & ~VME1_SCON_SYSFAIL;
166 vme1_reg_write(sc, VME1REG_SCON, reg);
167
168 printf(": Type 1 VMEchip, scon jumper %s\n",
169 (reg & VME1_SCON_SWITCH) ? "enabled" : "disabled");
170
171 /*
172 * Adjust the start address of the first range in vme_pcc_masters[]
173 * according to how much onboard memory exists. Disable the first
174 * range if onboard memory >= 16Mb, and adjust the start of the
175 * second range (A32D32).
176 */
177 vme_pcc_masters[0].vr_vmestart = (vme_addr_t) mem_clusters[0].size;
178 if (mem_clusters[0].size >= 0x01000000) {
179 vme_pcc_masters[0].vr_am = MVMEBUS_AM_DISABLED;
180 vme_pcc_masters[1].vr_vmestart +=
181 (vme_addr_t) (mem_clusters[0].size - 0x01000000);
182 }
183
184 vme_pcc_attached = 1;
185
186 /* Attach to the mvme68k common VMEbus front-end */
187 sc->sc_mvmebus.sc_dmat = pa->pa_dmat;
188 sc->sc_mvmebus.sc_chip = sc;
189 sc->sc_mvmebus.sc_nmasters = VME1_NMASTERS;
190 sc->sc_mvmebus.sc_masters = &vme_pcc_masters[0];
191 sc->sc_mvmebus.sc_nslaves = 0;
192 sc->sc_mvmebus.sc_slaves = NULL;
193 sc->sc_mvmebus.sc_intr_establish = vme_pcc_intr_establish;
194 sc->sc_mvmebus.sc_intr_disestablish = vme_pcc_intr_disestablish;
195
196 mvmebus_attach(&sc->sc_mvmebus);
197 }
198
199 void
200 vme_pcc_intr_establish(csc, level, vector, first, func, arg)
201 void *csc;
202 int level, vector, first;
203 int (*func)(void *);
204 void *arg;
205 {
206 struct vme_pcc_softc *sc = csc;
207
208 isrlink_vectored(func, arg, level, vector);
209
210 if (first) {
211 /*
212 * There had better not be another VMEbus master responding
213 * to this interrupt level...
214 */
215 vme1_reg_write(sc, VME1REG_IRQEN,
216 vme1_reg_read(sc, VME1REG_IRQEN) | VME1_IRQ_VME(level));
217 }
218 }
219
220 void
221 vme_pcc_intr_disestablish(csc, level, vector, last)
222 void *csc;
223 int level, vector, last;
224 {
225 struct vme_pcc_softc *sc = csc;
226
227 isrunlink_vectored(vector);
228
229 if (last) {
230 vme1_reg_write(sc, VME1REG_IRQEN,
231 vme1_reg_read(sc, VME1REG_IRQEN) & ~VME1_IRQ_VME(level));
232 }
233 }
234