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