isa_machdep.c revision 1.9 1 /* $NetBSD: isa_machdep.c,v 1.9 1998/06/11 08:32:00 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 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 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 <vm/vm.h>
42 #include <vm/vm_kern.h>
43
44 #include <dev/isa/isavar.h>
45 #include <dev/isa/isareg.h>
46
47 #include <machine/bus.h>
48 #include <machine/cpu.h>
49 #include <machine/iomap.h>
50 #include <machine/mfp.h>
51 #include <atari/atari/device.h>
52
53 static int isabusprint __P((void *auxp, const char *));
54 static int isabusmatch __P((struct device *, struct cfdata *, void *));
55 static void isabusattach __P((struct device *, struct device *, void *));
56
57 struct isabus_softc {
58 struct device sc_dev;
59 struct atari_isa_chipset sc_chipset;
60 };
61
62 struct cfattach isabus_ca = {
63 sizeof(struct isabus_softc), isabusmatch, isabusattach
64 };
65
66 int
67 isabusmatch(pdp, cfp, auxp)
68 struct device *pdp;
69 struct cfdata *cfp;
70 void *auxp;
71 {
72 if(atari_realconfig == 0)
73 return (0);
74 if (strcmp((char *)auxp, "isabus") || cfp->cf_unit != 0)
75 return(0);
76 return(machineid & ATARI_HADES ? 1 : 0);
77 }
78
79 void
80 isabusattach(pdp, dp, auxp)
81 struct device *pdp, *dp;
82 void *auxp;
83 {
84 struct isabus_softc *sc = (struct isabus_softc *)dp;
85 struct isabus_attach_args iba;
86 bus_space_tag_t leb_alloc_bus_space_tag __P((void));
87
88 iba.iba_busname = "isa";
89 iba.iba_dmat = BUS_ISA_DMA_TAG;
90 iba.iba_iot = leb_alloc_bus_space_tag();
91 iba.iba_memt = leb_alloc_bus_space_tag();
92 iba.iba_ic = &sc->sc_chipset;
93 if ((iba.iba_iot == NULL) || (iba.iba_memt == NULL)) {
94 printf("leb_alloc_bus_space_tag failed!\n");
95 return;
96 }
97 iba.iba_iot->base = ISA_IOSTART;
98 iba.iba_memt->base = ISA_MEMSTART;
99
100 MFP->mf_aer |= (IO_ISA1|IO_ISA2); /* ISA interrupts: LOW->HIGH */
101
102 printf("\n");
103 config_found(dp, &iba, isabusprint);
104 }
105
106 int
107 isabusprint(auxp, name)
108 void *auxp;
109 const char *name;
110 {
111 if(name == NULL)
112 return(UNCONF);
113 return(QUIET);
114 }
115
116 void
117 isa_attach_hook(parent, self, iba)
118 struct device *parent, *self;
119 struct isabus_attach_args *iba;
120 {
121 }
122
123 /*
124 * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
125 * for a slot are wired together and connected to either IO3 (slot1) or
126 * IO7 (slot2). Since no info can be obtained about the slot position
127 * at isa_intr_establish() time, the following assumption is made:
128 * - irq <= 6 -> slot 1
129 * - irq > 6 -> slot 2
130 */
131 static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
132
133 static int iifun __P((int, int));
134
135 static int
136 iifun(slot, sr)
137 int slot;
138 int sr;
139 {
140 isa_intr_info_t *iinfo_p;
141 int s;
142
143 iinfo_p = &iinfo[slot];
144
145 /*
146 * Disable the interrupts
147 */
148 if (slot == 0)
149 MFP->mf_imrb &= ~(IB_ISA1);
150 else MFP->mf_imra &= ~(IA_ISA2);
151
152 if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
153 /*
154 * We're running at a too high priority now.
155 */
156 add_sicallback((si_farg)iifun, (void*)slot, 0);
157 }
158 else {
159 s = splx(iinfo_p->ipl);
160 (void) (iinfo_p->ifunc)(iinfo_p->iarg);
161 splx(s);
162
163 /*
164 * Re-enable interrupts after handling
165 */
166 if (slot == 0)
167 MFP->mf_imrb |= IB_ISA1;
168 else MFP->mf_imra |= IA_ISA2;
169 }
170 return 1;
171 }
172
173 void *
174 isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
175 isa_chipset_tag_t ic;
176 int irq, type, level;
177 int (*ih_fun) __P((void *));
178 void *ih_arg;
179 {
180 isa_intr_info_t *iinfo_p;
181 struct intrhand *ihand;
182 int slot;
183
184 slot = (irq <= 6) ? 0 : 1;
185 iinfo_p = &iinfo[slot];
186
187 if (iinfo_p->slot > 0)
188 panic("isa_intr_establish: interrupt was already established\n");
189
190 ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
191 (hw_ifun_t)iifun, (void *)slot);
192 if (ihand != NULL) {
193 iinfo_p->slot = slot;
194 iinfo_p->ipl = level;
195 iinfo_p->ifunc = ih_fun;
196 iinfo_p->iarg = ih_arg;
197 iinfo_p->ihand = ihand;
198
199 /*
200 * Enable (unmask) the interrupt
201 */
202 if (slot == 0) {
203 MFP->mf_imrb |= IB_ISA1;
204 MFP->mf_ierb |= IB_ISA1;
205 }
206 else {
207 MFP->mf_imra |= IA_ISA2;
208 MFP->mf_iera |= IA_ISA2;
209 }
210 return(iinfo_p);
211 }
212 return NULL;
213 }
214
215 void
216 isa_intr_disestablish(ic, handler)
217 isa_chipset_tag_t ic;
218 void *handler;
219 {
220 isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
221
222 if (iinfo_p->slot < 0)
223 panic("isa_intr_disestablish: interrupt was not established\n");
224
225 (void) intr_disestablish(iinfo_p->ihand);
226 iinfo_p->slot = -1;
227 }
228