isa_hades.c revision 1.3 1 /* $NetBSD: isa_hades.c,v 1.3 2003/07/15 01:19:53 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Leo Weppelman.
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 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: isa_hades.c,v 1.3 2003/07/15 01:19:53 lukem Exp $");
41
42 #include <sys/types.h>
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46
47 #include <dev/isa/isavar.h>
48 #include <dev/isa/isareg.h>
49
50 #include <m68k/asm_single.h>
51
52 #include <machine/iomap.h>
53 #include <machine/mfp.h>
54
55 void isa_bus_init(void);
56
57 void
58 isa_bus_init()
59 {
60 }
61
62 /*
63 * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
64 * for a slot are wired together and connected to either IO3 (slot1) or
65 * IO7 (slot2). Since no info can be obtained about the slot position
66 * at isa_intr_establish() time, the following assumption is made:
67 * - irq <= 6 -> slot 1
68 * - irq > 6 -> slot 2
69 */
70
71 #define SLOTNR(irq) ((irq <= 6) ? 0 : 1)
72
73 static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
74
75 static int iifun __P((int, int));
76
77 static int
78 iifun(slot, sr)
79 int slot;
80 int sr;
81 {
82 isa_intr_info_t *iinfo_p;
83 int s;
84
85 iinfo_p = &iinfo[slot];
86
87 /*
88 * Disable the interrupts
89 */
90 if (slot == 0) {
91 single_inst_bclr_b(MFP->mf_imrb, IB_ISA1);
92 }
93 else {
94 single_inst_bclr_b(MFP->mf_imra, IA_ISA2);
95 }
96
97 if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
98 /*
99 * We're running at a too high priority now.
100 */
101 add_sicallback((si_farg)iifun, (void*)slot, 0);
102 }
103 else {
104 s = splx(iinfo_p->ipl);
105 if (slot == 0) {
106 do {
107 MFP->mf_iprb = (u_int8_t)~IB_ISA1;
108 (void) (iinfo_p->ifunc)(iinfo_p->iarg);
109 } while (MFP->mf_iprb & IB_ISA1);
110 single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
111 }
112 else {
113 do {
114 MFP->mf_ipra = (u_int8_t)~IA_ISA2;
115 (void) (iinfo_p->ifunc)(iinfo_p->iarg);
116 } while (MFP->mf_ipra & IA_ISA2);
117 single_inst_bset_b(MFP->mf_imra, IA_ISA2);
118 }
119 splx(s);
120 }
121 return 1;
122 }
123
124
125 /*
126 * XXXX
127 * XXXX Note that this function is not really working yet! The big problem is
128 * XXXX to only generate interrupts for the slot the card is in...
129 */
130 int
131 isa_intr_alloc(ic, mask, type, irq)
132 isa_chipset_tag_t ic;
133 int mask;
134 int type;
135 int *irq;
136 {
137 isa_intr_info_t *iinfo_p;
138 int slot, i;
139
140
141 /*
142 * The Hades only supports edge triggered interrupts!
143 */
144 if (type != IST_EDGE)
145 return 1;
146
147 #define MAXIRQ 10 /* XXX: Pure fiction */
148 for (i = 0; i < MAXIRQ; i++) {
149 if (mask & (1<<i)) {
150 slot = SLOTNR(i);
151 iinfo_p = &iinfo[slot];
152
153 if (iinfo_p->slot < 0) {
154 *irq = i;
155 printf("WARNING: isa_intr_alloc is not yet ready!\n"
156 " make sure the card is in slot %d!\n",
157 slot);
158 return 0;
159 }
160 }
161 }
162 return (1);
163 }
164 void *
165 isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
166 isa_chipset_tag_t ic;
167 int irq, type, level;
168 int (*ih_fun) __P((void *));
169 void *ih_arg;
170 {
171 isa_intr_info_t *iinfo_p;
172 struct intrhand *ihand;
173 int slot;
174
175 /*
176 * The Hades only supports edge triggered interrupts!
177 */
178 if (type != IST_EDGE)
179 return NULL;
180
181 slot = SLOTNR(irq);
182 iinfo_p = &iinfo[slot];
183
184 if (iinfo_p->slot >= 0)
185 panic("isa_intr_establish: interrupt was already established");
186
187 ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
188 (hw_ifun_t)iifun, (void *)slot);
189 if (ihand != NULL) {
190 iinfo_p->slot = slot;
191 iinfo_p->ipl = level;
192 iinfo_p->ifunc = ih_fun;
193 iinfo_p->iarg = ih_arg;
194 iinfo_p->ihand = ihand;
195
196 /*
197 * Enable (unmask) the interrupt
198 */
199 if (slot == 0) {
200 single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
201 single_inst_bset_b(MFP->mf_ierb, IB_ISA1);
202 }
203 else {
204 single_inst_bset_b(MFP->mf_imra, IA_ISA2);
205 single_inst_bset_b(MFP->mf_iera, IA_ISA2);
206 }
207 return(iinfo_p);
208 }
209 return NULL;
210 }
211
212 void
213 isa_intr_disestablish(ic, handler)
214 isa_chipset_tag_t ic;
215 void *handler;
216 {
217 isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
218
219 if (iinfo_p->slot < 0)
220 panic("isa_intr_disestablish: interrupt was not established");
221
222 (void) intr_disestablish(iinfo_p->ihand);
223 iinfo_p->slot = -1;
224 }
225