isa_machdep.c revision 1.21 1 /* $NetBSD: isa_machdep.c,v 1.21 2001/03/09 20:55:47 leo Exp $ */
2
3 /*
4 * Copyright (c) 1997 Leo Weppelman. All rights reserved.
5 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
6 * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Charles M. Hannum.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/time.h>
37 #include <sys/systm.h>
38 #include <sys/errno.h>
39 #include <sys/device.h>
40
41 #include <uvm/uvm_extern.h>
42
43 #define _ATARI_BUS_DMA_PRIVATE
44 #include <machine/bus.h>
45 #include <dev/isa/isavar.h>
46 #include <dev/isa/isareg.h>
47
48 #include <m68k/asm_single.h>
49
50 #include <machine/cpu.h>
51 #include <machine/iomap.h>
52 #include <machine/mfp.h>
53 #include <atari/atari/device.h>
54
55 #include "isadma.h"
56
57 #if NISADMA == 0
58
59 /*
60 * Entry points for ISA DMA while no DMA capable devices are attached.
61 * This must be a serious error. Cause a panic...
62 */
63 struct atari_bus_dma_tag isa_bus_dma_tag = {
64 0
65 };
66 #endif /* NISADMA == 0 */
67
68 static int isabusprint __P((void *auxp, const char *));
69 static int isabusmatch __P((struct device *, struct cfdata *, void *));
70 static void isabusattach __P((struct device *, struct device *, void *));
71
72 struct isabus_softc {
73 struct device sc_dev;
74 struct atari_isa_chipset sc_chipset;
75 };
76
77 struct cfattach isabus_ca = {
78 sizeof(struct isabus_softc), isabusmatch, isabusattach
79 };
80
81 int
82 isabusmatch(pdp, cfp, auxp)
83 struct device *pdp;
84 struct cfdata *cfp;
85 void *auxp;
86 {
87 static int nmatched = 0;
88
89 if (strcmp((char *)auxp, "isabus"))
90 return (0); /* Wrong number... */
91
92 if(atari_realconfig == 0)
93 return (0);
94
95 if (machineid & (ATARI_HADES|ATARI_MILAN)) {
96 /*
97 * The Hades and Milan have only one pci bus
98 */
99 if (nmatched)
100 return (0);
101 nmatched++;
102 return (1);
103 }
104 return(0);
105 }
106
107 void
108 isabusattach(pdp, dp, auxp)
109 struct device *pdp, *dp;
110 void *auxp;
111 {
112 struct isabus_softc *sc = (struct isabus_softc *)dp;
113 struct isabus_attach_args iba;
114 extern struct atari_bus_dma_tag isa_bus_dma_tag;
115
116 iba.iba_busname = "isa";
117 iba.iba_dmat = &isa_bus_dma_tag;
118 iba.iba_iot = leb_alloc_bus_space_tag(NULL);
119 iba.iba_memt = leb_alloc_bus_space_tag(NULL);
120 iba.iba_ic = &sc->sc_chipset;
121 if ((iba.iba_iot == NULL) || (iba.iba_memt == NULL)) {
122 printf("leb_alloc_bus_space_tag failed!\n");
123 return;
124 }
125 iba.iba_iot->base = ISA_IOSTART;
126 iba.iba_memt->base = ISA_MEMSTART;
127
128 MFP->mf_aer |= (IO_ISA1|IO_ISA2); /* ISA interrupts: LOW->HIGH */
129
130 printf("\n");
131 config_found(dp, &iba, isabusprint);
132 }
133
134 int
135 isabusprint(auxp, name)
136 void *auxp;
137 const char *name;
138 {
139 if(name == NULL)
140 return(UNCONF);
141 return(QUIET);
142 }
143
144 void
145 isa_attach_hook(parent, self, iba)
146 struct device *parent, *self;
147 struct isabus_attach_args *iba;
148 {
149 }
150
151 /*
152 * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
153 * for a slot are wired together and connected to either IO3 (slot1) or
154 * IO7 (slot2). Since no info can be obtained about the slot position
155 * at isa_intr_establish() time, the following assumption is made:
156 * - irq <= 6 -> slot 1
157 * - irq > 6 -> slot 2
158 */
159
160 #define SLOTNR(irq) ((irq <= 6) ? 0 : 1)
161
162 static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
163
164 static int iifun __P((int, int));
165
166 static int
167 iifun(slot, sr)
168 int slot;
169 int sr;
170 {
171 isa_intr_info_t *iinfo_p;
172 int s;
173
174 iinfo_p = &iinfo[slot];
175
176 /*
177 * Disable the interrupts
178 */
179 if (slot == 0) {
180 single_inst_bclr_b(MFP->mf_imrb, IB_ISA1);
181 }
182 else {
183 single_inst_bclr_b(MFP->mf_imra, IA_ISA2);
184 }
185
186 if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
187 /*
188 * We're running at a too high priority now.
189 */
190 add_sicallback((si_farg)iifun, (void*)slot, 0);
191 }
192 else {
193 s = splx(iinfo_p->ipl);
194 if (slot == 0) {
195 do {
196 MFP->mf_iprb = (u_int8_t)~IB_ISA1;
197 (void) (iinfo_p->ifunc)(iinfo_p->iarg);
198 } while (MFP->mf_iprb & IB_ISA1);
199 single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
200 }
201 else {
202 do {
203 MFP->mf_ipra = (u_int8_t)~IA_ISA2;
204 (void) (iinfo_p->ifunc)(iinfo_p->iarg);
205 } while (MFP->mf_ipra & IA_ISA2);
206 single_inst_bset_b(MFP->mf_imra, IA_ISA2);
207 }
208 splx(s);
209 }
210 return 1;
211 }
212
213
214 /*
215 * XXXX
216 * XXXX Note that this function is not really working yet! The big problem is
217 * XXXX to only generate interrupts for the slot the card is in...
218 */
219 int
220 isa_intr_alloc(ic, mask, type, irq)
221 isa_chipset_tag_t ic;
222 int mask;
223 int type;
224 int *irq;
225 {
226 isa_intr_info_t *iinfo_p;
227 int slot, i;
228
229
230 /*
231 * The Hades only supports edge triggered interrupts!
232 */
233 if (type != IST_EDGE)
234 return 1;
235
236 #define MAXIRQ 10 /* XXX: Pure fiction */
237 for (i = 0; i < MAXIRQ; i++) {
238 if (mask & (1<<i)) {
239 slot = SLOTNR(i);
240 iinfo_p = &iinfo[slot];
241
242 if (iinfo_p->slot < 0) {
243 *irq = i;
244 printf("WARNING: isa_intr_alloc is not yet ready!\n"
245 " make sure the card is in slot %d!\n",
246 slot);
247 return 0;
248 }
249 }
250 }
251 return (1);
252 }
253
254 const struct evcnt *
255 isa_intr_evcnt(isa_chipset_tag_t ic, int irq)
256 {
257
258 /* XXX for now, no evcnt parent reported */
259 return NULL;
260 }
261
262 void *
263 isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
264 isa_chipset_tag_t ic;
265 int irq, type, level;
266 int (*ih_fun) __P((void *));
267 void *ih_arg;
268 {
269 isa_intr_info_t *iinfo_p;
270 struct intrhand *ihand;
271 int slot;
272
273 /*
274 * The Hades only supports edge triggered interrupts!
275 */
276 if (type != IST_EDGE)
277 return NULL;
278
279 slot = SLOTNR(irq);
280 iinfo_p = &iinfo[slot];
281
282 if (iinfo_p->slot >= 0)
283 panic("isa_intr_establish: interrupt was already established\n");
284
285 ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
286 (hw_ifun_t)iifun, (void *)slot);
287 if (ihand != NULL) {
288 iinfo_p->slot = slot;
289 iinfo_p->ipl = level;
290 iinfo_p->ifunc = ih_fun;
291 iinfo_p->iarg = ih_arg;
292 iinfo_p->ihand = ihand;
293
294 /*
295 * Enable (unmask) the interrupt
296 */
297 if (slot == 0) {
298 single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
299 single_inst_bset_b(MFP->mf_ierb, IB_ISA1);
300 }
301 else {
302 single_inst_bset_b(MFP->mf_imra, IA_ISA2);
303 single_inst_bset_b(MFP->mf_iera, IA_ISA2);
304 }
305 return(iinfo_p);
306 }
307 return NULL;
308 }
309
310 void
311 isa_intr_disestablish(ic, handler)
312 isa_chipset_tag_t ic;
313 void *handler;
314 {
315 isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
316
317 if (iinfo_p->slot < 0)
318 panic("isa_intr_disestablish: interrupt was not established\n");
319
320 (void) intr_disestablish(iinfo_p->ihand);
321 iinfo_p->slot = -1;
322 }
323