vme_pcc.c revision 1.6 1 /* $NetBSD: vme_pcc.c,v 1.6 1998/01/12 19:51:10 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1996 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.
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
52 #include <machine/psl.h>
53 #include <machine/cpu.h>
54
55 #include <mvme68k/dev/pccreg.h>
56 #include <mvme68k/dev/pccvar.h>
57 #include <mvme68k/dev/vme_pccreg.h>
58 #include <mvme68k/dev/vmevar.h>
59
60 int vmechip_pcc_match __P((struct device *, struct cfdata *, void *));
61 void vmechip_pcc_attach __P((struct device *, struct device *, void *));
62
63 struct cfattach vmechip_pcc_ca = {
64 sizeof(struct vmechip_softc), vmechip_pcc_match, vmechip_pcc_attach
65 };
66
67 extern struct cfdriver vmechip_cd;
68 extern struct cfdriver vmes_cd;
69 extern struct cfdriver vmel_cd;
70
71 int vmechip_pcc_translate_addr __P((u_long, size_t, int, int, u_long *));
72 void vmechip_pcc_intrline_enable __P((int));
73 void vmechip_pcc_intrline_disable __P((int));
74
75 struct vme_chip vme_pcc_switch = {
76 vmechip_pcc_translate_addr,
77 vmechip_pcc_intrline_enable,
78 vmechip_pcc_intrline_disable
79 };
80
81 struct vme_pcc *sys_vme_pcc;
82
83 extern int physmem;
84
85 int
86 vmechip_pcc_match(parent, cf, aux)
87 struct device *parent;
88 struct cfdata *cf;
89 void *aux;
90 {
91 struct pcc_attach_args *pa = aux;
92
93 /* Only one VME chip, please. */
94 if (sys_vme_pcc)
95 return (0);
96
97 if (strcmp(pa->pa_name, vmechip_cd.cd_name))
98 return (0);
99
100 return (1);
101 }
102
103 void
104 vmechip_pcc_attach(parent, self, aux)
105 struct device *parent, *self;
106 void *aux;
107 {
108 struct vmechip_softc *sc = (struct vmechip_softc *)self;
109 struct pcc_attach_args *pa = aux;
110 struct vme_pcc *vme;
111
112 /* Glue into generic VME code. */
113 sc->sc_reg = PCC_VADDR(pa->pa_offset);
114 sc->sc_chip = &vme_pcc_switch;
115
116 /* Initialize the chip. */
117 vme = (struct vme_pcc *)sc->sc_reg;
118 vme->vme_scon &= ~VME1_SCON_SYSFAIL; /* XXX doesn't work */
119
120 sys_vme_pcc = vme;
121
122 printf(": Type 1 VMEchip, scon jumper %s\n",
123 (vme->vme_scon & VME1_SCON_SWITCH) ? "enabled" : "disabled");
124
125 /* Attach children. */
126 vme_config(sc);
127 }
128
129 int
130 vmechip_pcc_translate_addr(start, len, bustype, atype, addrp)
131 u_long start;
132 size_t len;
133 int bustype, atype;
134 u_long *addrp; /* result */
135 {
136 u_long end = (start + len) - 1;
137
138 switch (bustype) {
139 case VME_D16:
140 switch (atype) {
141 case VME_A16:
142 if (end < VME1_A16D16_LEN) {
143 *addrp = VME1_A16D16_START + start;
144 return (0);
145 }
146 break;
147
148 case VME_A24:
149 if (((end & 0x00ffffff) == end) &&
150 (end < VME1_A32D16_LEN)) {
151 *addrp = VME1_A32D16_START + start;
152 return (0);
153 }
154 break;
155
156 case VME_A32:
157 if (end < VME1_A32D16_LEN) {
158 *addrp = VME1_A32D16_START + start;
159 return (0);
160 }
161 break;
162
163 default:
164 printf("vmechip: impossible atype `%d'\n", atype);
165 panic("vmechip_pcc_translate_addr");
166 }
167
168 printf("vmechip: can't map %s atype %d addr 0x%lx len 0x%x\n",
169 vmes_cd.cd_name, atype, start, len);
170 break;
171
172 case VME_D32:
173 switch (atype) {
174 case VME_A16:
175 /* Can't map A16D32 */
176 break;
177
178 case VME_A24:
179 if (((u_long)physmem < 0x1000000) && /* 16MB */
180 (start >= (u_long)physmem) &&
181 (end < VME1_A32D32_LEN)) {
182 *addrp = start;
183 return (0);
184 }
185 break;
186
187 case VME_A32:
188 if ((start >= (u_long)physmem) &&
189 (end < VME1_A32D32_LEN)) {
190 *addrp = start;
191 return (0);
192 }
193 break;
194
195 default:
196 printf("vmechip: impossible atype `%d'\n", atype);
197 panic("vmechip_pcc_translate_addr");
198 }
199
200 printf("vmechip: can't map %s atype %d addr 0x%lx len 0x%x\n",
201 vmel_cd.cd_name, atype, start, len);
202 break;
203
204 default:
205 panic("vmechip_pcc_translate_addr: bad bustype");
206 }
207
208 return (1);
209 }
210
211 void
212 vmechip_pcc_intrline_enable(ipl)
213 int ipl;
214 {
215
216 sys_vme_pcc->vme_irqen |= VME1_IRQ_VME(ipl);
217 }
218
219 void
220 vmechip_pcc_intrline_disable(ipl)
221 int ipl;
222 {
223
224 sys_vme_pcc->vme_irqen &= ~VME1_IRQ_VME(ipl);
225 }
226