ioasic.c revision 1.6 1 /* $NetBSD: ioasic.c,v 1.6 2000/01/10 01:57:41 simonb Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Keith Bostic, Chris G. Demetriou, Jonathan Stone
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
31 __KERNEL_RCSID(0, "$NetBSD: ioasic.c,v 1.6 2000/01/10 01:57:41 simonb Exp $");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36
37 #include <machine/bus.h>
38 #include <dev/tc/tcvar.h>
39 #include <dev/tc/ioasicvar.h>
40
41 #include <pmax/pmax/pmaxtype.h>
42 #include <pmax/pmax/asic.h>
43 #include <pmax/pmax/kmin.h>
44 #include <pmax/pmax/maxine.h>
45 #include <pmax/pmax/kn03.h>
46 #include <pmax/pmax/turbochannel.h> /* interrupt enable declaration */
47
48 #include "opt_dec_3min.h"
49 #include "opt_dec_maxine.h"
50 #include "opt_dec_3maxplus.h"
51
52 #define C(x) ((void *)(x))
53 #define ARRAY_SIZEOF(x) (sizeof((x)) / sizeof((x)[0]))
54
55 #if defined(DEC_3MIN)
56 static struct ioasic_dev kmin_ioasic_devs[] = {
57 { "lance", 0x0C0000, C(KMIN_LANCE_SLOT), IOASIC_INTR_LANCE, },
58 { "scc", 0x100000, C(KMIN_SCC0_SLOT), IOASIC_INTR_SCC_0, },
59 { "scc", 0x180000, C(KMIN_SCC1_SLOT), IOASIC_INTR_SCC_1, },
60 { "mc146818", 0x200000, C(-1), 0 },
61 { "asc", 0x300000, C(KMIN_SCSI_SLOT), IOASIC_INTR_SCSI, },
62 };
63 static int kmin_builtin_ndevs = ARRAY_SIZEOF(kmin_ioasic_devs);
64 static int kmin_ioasic_ndevs = ARRAY_SIZEOF(kmin_ioasic_devs);
65 #endif
66
67 #if defined(DEC_MAXINE)
68 static struct ioasic_dev xine_ioasic_devs[] = {
69 { "lance", 0x0C0000, C(XINE_LANCE_SLOT), IOASIC_INTR_LANCE },
70 { "scc", 0x100000, C(XINE_SCC0_SLOT), IOASIC_INTR_SCC_0 },
71 { "mc146818", 0x200000, C(-1), 0 },
72 { "isdn", 0x240000, C(XINE_ISDN_SLOT), XINE_INTR_ISDN, },
73 { "dtop", 0x280000, C(XINE_DTOP_SLOT), XINE_INTR_DTOP, },
74 { "fdc", 0x2C0000, C(XINE_FLOPPY_SLOT), 0 },
75 { "asc", 0x300000, C(XINE_SCSI_SLOT), IOASIC_INTR_SCSI, },
76 { "(TC0)", 0x0, C(0), XINE_INTR_TC_0, },
77 { "(TC1)", 0x0, C(1), XINE_INTR_TC_1, },
78 { "(TC2)", 0x0, C(2), XINE_INTR_VINT, },
79 };
80 static int xine_builtin_ndevs = ARRAY_SIZEOF(xine_ioasic_devs) - 3;
81 static int xine_ioasic_ndevs = ARRAY_SIZEOF(xine_ioasic_devs);
82 #endif
83
84 #if defined(DEC_3MAXPLUS)
85 static struct ioasic_dev kn03_ioasic_devs[] = {
86 { "lance", 0x0C0000, C(KN03_LANCE_SLOT), IOASIC_INTR_LANCE, },
87 { "z8530 ", 0x100000, C(KN03_SCC0_SLOT), IOASIC_INTR_SCC_0, },
88 { "z8530 ", 0x180000, C(KN03_SCC1_SLOT), IOASIC_INTR_SCC_1, },
89 { "mc146818", 0x200000, C(-1), 0, },
90 { "asc", 0x300000, C(KN03_SCSI_SLOT), IOASIC_INTR_SCSI, },
91 { "(TC0)", 0x0, C(0), KN03_INTR_TC_0, },
92 { "(TC1)", 0x0, C(1), KN03_INTR_TC_1, },
93 { "(TC2)", 0x0, C(2), KN03_INTR_TC_2, },
94 };
95 static int kn03_builtin_ndevs = ARRAY_SIZEOF(kn03_ioasic_devs) - 3;
96 static int kn03_ioasic_ndevs = ARRAY_SIZEOF(kn03_ioasic_devs);
97 #endif
98
99 static int ioasicmatch __P((struct device *, struct cfdata *, void *));
100 static void ioasicattach __P((struct device *, struct device *, void *));
101
102 const struct cfattach ioasic_ca = {
103 sizeof(struct ioasic_softc), ioasicmatch, ioasicattach
104 };
105
106 tc_addr_t ioasic_base = 0;
107
108 static int
109 ioasicmatch(parent, cfdata, aux)
110 struct device *parent;
111 struct cfdata *cfdata;
112 void *aux;
113 {
114 struct tc_attach_args *ta = aux;
115
116 /* Make sure that we're looking for this type of device. */
117 if (strncmp("IOCTL ", ta->ta_modname, TC_ROM_LLEN))
118 return (0);
119
120 if (cfdata->cf_unit > 0)
121 return (0);
122
123 return (1);
124 }
125
126 static void
127 ioasicattach(parent, self, aux)
128 struct device *parent, *self;
129 void *aux;
130 {
131 struct ioasic_softc *sc = (struct ioasic_softc *)self;
132 struct tc_attach_args *ta = aux;
133 struct ioasic_dev *ioasic_devs;
134 int ioasic_ndevs, builtin_ndevs;
135 int i, imsk;
136
137 sc->sc_bst = ta->ta_memt;
138 if (bus_space_map(ta->ta_memt, ta->ta_addr,
139 0x400000, 0, &sc->sc_bsh)) {
140 printf("%s: unable to map device\n", sc->sc_dv.dv_xname);
141 return;
142 }
143 sc->sc_dmat = ta->ta_dmat;
144 sc->sc_cookie = ta->ta_cookie;
145
146 sc->sc_base = ta->ta_addr; /* XXX XXX XXX */
147
148 printf("\n");
149
150 switch (systype) {
151 #if defined(DEC_3MIN)
152 case DS_3MIN:
153 ioasic_devs = kmin_ioasic_devs;
154 ioasic_ndevs = kmin_ioasic_ndevs;
155 builtin_ndevs = kmin_builtin_ndevs;
156 break;
157 #endif
158 #if defined(DEC_MAXINE)
159 case DS_MAXINE:
160 ioasic_devs = xine_ioasic_devs;
161 ioasic_ndevs = xine_ioasic_ndevs;
162 builtin_ndevs = xine_builtin_ndevs;
163 break;
164 #endif
165 #if defined(DEC_3MAXPLUS)
166 case DS_3MAXPLUS:
167 ioasic_devs = kn03_ioasic_devs;
168 ioasic_ndevs = kn03_ioasic_ndevs;
169 builtin_ndevs = kn03_builtin_ndevs;
170 break;
171 #endif
172 default:
173 panic("ioasicmatch: how did we get here?");
174 }
175
176 /*
177 * Turn off all device interrupt bits.
178 * (This _does_ include TC option slot bits.
179 */
180 imsk = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
181 for (i = 0; i < ioasic_ndevs; i++)
182 imsk &= ~ioasic_devs[i].iad_intrbits;
183 bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, imsk);
184
185 /*
186 * Try to configure each device.
187 */
188 ioasic_attach_devs(sc, ioasic_devs, builtin_ndevs);
189 }
190
191 #if 1 /* XXX for now XXX */
192 void
193 ioasic_intr_establish(dev, cookie, level, handler, val)
194 struct device *dev;
195 void *cookie;
196 int level;
197 int (*handler) __P((void *));
198 void *val;
199 {
200 (*tc_enable_interrupt)((unsigned)cookie, handler, val, 1);
201 }
202
203 #else /* XXX eventually XXX */
204
205 void
206 ioasic_intr_establish(ioa, cookie, level, func, arg)
207 struct device *ioa;
208 void *cookie, *arg;
209 int level;
210 int (*func) __P((void *));
211 {
212 struct ioasic_softc *sc = (void *)ioasic_cd.cd_devs[0];
213 int i, intrbits;
214
215 for (i = 0; i < ioasic_ndevs; i++) {
216 if (ioasic_devs[i].iad_cookie == cookie)
217 goto found;
218 }
219 panic("ioasic_intr_establish: invalid cookie %d", (int)cookie);
220 found:
221
222 intrtab[(int)cookie].ih_func = func;
223 intrtab[(int)cookie].ih_arg = arg;
224
225 intrbits = ioasic_devs[i].iad_intrbits;
226 i = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
227 i |= intrbits;
228 bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, i);
229 }
230
231 void
232 ioasic_intr_disestablish(ioa, cookie)
233 struct device *ioa;
234 void *cookie;
235 {
236 panic("ioasic_intr_disestablish: cookie %d", (int)cookie);
237 }
238 #endif
239