isa_hades.c revision 1.3 1 1.3 lukem /* $NetBSD: isa_hades.c,v 1.3 2003/07/15 01:19:53 lukem Exp $ */
2 1.1 leo
3 1.1 leo /*-
4 1.1 leo * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1 leo * All rights reserved.
6 1.1 leo *
7 1.1 leo * This code is derived from software contributed to The NetBSD Foundation
8 1.1 leo * by Leo Weppelman.
9 1.1 leo *
10 1.1 leo * Redistribution and use in source and binary forms, with or without
11 1.1 leo * modification, are permitted provided that the following conditions
12 1.1 leo * are met:
13 1.1 leo * 1. Redistributions of source code must retain the above copyright
14 1.1 leo * notice, this list of conditions and the following disclaimer.
15 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 leo * notice, this list of conditions and the following disclaimer in the
17 1.1 leo * documentation and/or other materials provided with the distribution.
18 1.1 leo * 3. All advertising materials mentioning features or use of this software
19 1.1 leo * must display the following acknowledgement:
20 1.1 leo * This product includes software developed by the NetBSD
21 1.1 leo * Foundation, Inc. and its contributors.
22 1.1 leo * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 leo * contributors may be used to endorse or promote products derived
24 1.1 leo * from this software without specific prior written permission.
25 1.1 leo *
26 1.1 leo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 leo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 leo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 leo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 leo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 leo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 leo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 leo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 leo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 leo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 leo * POSSIBILITY OF SUCH DAMAGE.
37 1.1 leo */
38 1.3 lukem
39 1.3 lukem #include <sys/cdefs.h>
40 1.3 lukem __KERNEL_RCSID(0, "$NetBSD: isa_hades.c,v 1.3 2003/07/15 01:19:53 lukem Exp $");
41 1.1 leo
42 1.1 leo #include <sys/types.h>
43 1.1 leo #include <sys/param.h>
44 1.1 leo #include <sys/systm.h>
45 1.1 leo #include <sys/device.h>
46 1.1 leo
47 1.1 leo #include <dev/isa/isavar.h>
48 1.1 leo #include <dev/isa/isareg.h>
49 1.1 leo
50 1.1 leo #include <m68k/asm_single.h>
51 1.1 leo
52 1.1 leo #include <machine/iomap.h>
53 1.1 leo #include <machine/mfp.h>
54 1.1 leo
55 1.1 leo void isa_bus_init(void);
56 1.1 leo
57 1.1 leo void
58 1.1 leo isa_bus_init()
59 1.1 leo {
60 1.1 leo }
61 1.1 leo
62 1.1 leo /*
63 1.1 leo * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
64 1.1 leo * for a slot are wired together and connected to either IO3 (slot1) or
65 1.1 leo * IO7 (slot2). Since no info can be obtained about the slot position
66 1.1 leo * at isa_intr_establish() time, the following assumption is made:
67 1.1 leo * - irq <= 6 -> slot 1
68 1.1 leo * - irq > 6 -> slot 2
69 1.1 leo */
70 1.1 leo
71 1.1 leo #define SLOTNR(irq) ((irq <= 6) ? 0 : 1)
72 1.1 leo
73 1.1 leo static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
74 1.1 leo
75 1.1 leo static int iifun __P((int, int));
76 1.1 leo
77 1.1 leo static int
78 1.1 leo iifun(slot, sr)
79 1.1 leo int slot;
80 1.1 leo int sr;
81 1.1 leo {
82 1.1 leo isa_intr_info_t *iinfo_p;
83 1.1 leo int s;
84 1.1 leo
85 1.1 leo iinfo_p = &iinfo[slot];
86 1.1 leo
87 1.1 leo /*
88 1.1 leo * Disable the interrupts
89 1.1 leo */
90 1.1 leo if (slot == 0) {
91 1.1 leo single_inst_bclr_b(MFP->mf_imrb, IB_ISA1);
92 1.1 leo }
93 1.1 leo else {
94 1.1 leo single_inst_bclr_b(MFP->mf_imra, IA_ISA2);
95 1.1 leo }
96 1.1 leo
97 1.1 leo if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
98 1.1 leo /*
99 1.1 leo * We're running at a too high priority now.
100 1.1 leo */
101 1.1 leo add_sicallback((si_farg)iifun, (void*)slot, 0);
102 1.1 leo }
103 1.1 leo else {
104 1.1 leo s = splx(iinfo_p->ipl);
105 1.1 leo if (slot == 0) {
106 1.1 leo do {
107 1.1 leo MFP->mf_iprb = (u_int8_t)~IB_ISA1;
108 1.1 leo (void) (iinfo_p->ifunc)(iinfo_p->iarg);
109 1.1 leo } while (MFP->mf_iprb & IB_ISA1);
110 1.1 leo single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
111 1.1 leo }
112 1.1 leo else {
113 1.1 leo do {
114 1.1 leo MFP->mf_ipra = (u_int8_t)~IA_ISA2;
115 1.1 leo (void) (iinfo_p->ifunc)(iinfo_p->iarg);
116 1.1 leo } while (MFP->mf_ipra & IA_ISA2);
117 1.1 leo single_inst_bset_b(MFP->mf_imra, IA_ISA2);
118 1.1 leo }
119 1.1 leo splx(s);
120 1.1 leo }
121 1.1 leo return 1;
122 1.1 leo }
123 1.1 leo
124 1.1 leo
125 1.1 leo /*
126 1.1 leo * XXXX
127 1.1 leo * XXXX Note that this function is not really working yet! The big problem is
128 1.1 leo * XXXX to only generate interrupts for the slot the card is in...
129 1.1 leo */
130 1.1 leo int
131 1.1 leo isa_intr_alloc(ic, mask, type, irq)
132 1.1 leo isa_chipset_tag_t ic;
133 1.1 leo int mask;
134 1.1 leo int type;
135 1.1 leo int *irq;
136 1.1 leo {
137 1.1 leo isa_intr_info_t *iinfo_p;
138 1.1 leo int slot, i;
139 1.1 leo
140 1.1 leo
141 1.1 leo /*
142 1.1 leo * The Hades only supports edge triggered interrupts!
143 1.1 leo */
144 1.1 leo if (type != IST_EDGE)
145 1.1 leo return 1;
146 1.1 leo
147 1.1 leo #define MAXIRQ 10 /* XXX: Pure fiction */
148 1.1 leo for (i = 0; i < MAXIRQ; i++) {
149 1.1 leo if (mask & (1<<i)) {
150 1.1 leo slot = SLOTNR(i);
151 1.1 leo iinfo_p = &iinfo[slot];
152 1.1 leo
153 1.1 leo if (iinfo_p->slot < 0) {
154 1.1 leo *irq = i;
155 1.1 leo printf("WARNING: isa_intr_alloc is not yet ready!\n"
156 1.1 leo " make sure the card is in slot %d!\n",
157 1.1 leo slot);
158 1.1 leo return 0;
159 1.1 leo }
160 1.1 leo }
161 1.1 leo }
162 1.1 leo return (1);
163 1.1 leo }
164 1.1 leo void *
165 1.1 leo isa_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
166 1.1 leo isa_chipset_tag_t ic;
167 1.1 leo int irq, type, level;
168 1.1 leo int (*ih_fun) __P((void *));
169 1.1 leo void *ih_arg;
170 1.1 leo {
171 1.1 leo isa_intr_info_t *iinfo_p;
172 1.1 leo struct intrhand *ihand;
173 1.1 leo int slot;
174 1.1 leo
175 1.1 leo /*
176 1.1 leo * The Hades only supports edge triggered interrupts!
177 1.1 leo */
178 1.1 leo if (type != IST_EDGE)
179 1.1 leo return NULL;
180 1.1 leo
181 1.1 leo slot = SLOTNR(irq);
182 1.1 leo iinfo_p = &iinfo[slot];
183 1.1 leo
184 1.1 leo if (iinfo_p->slot >= 0)
185 1.2 provos panic("isa_intr_establish: interrupt was already established");
186 1.1 leo
187 1.1 leo ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
188 1.1 leo (hw_ifun_t)iifun, (void *)slot);
189 1.1 leo if (ihand != NULL) {
190 1.1 leo iinfo_p->slot = slot;
191 1.1 leo iinfo_p->ipl = level;
192 1.1 leo iinfo_p->ifunc = ih_fun;
193 1.1 leo iinfo_p->iarg = ih_arg;
194 1.1 leo iinfo_p->ihand = ihand;
195 1.1 leo
196 1.1 leo /*
197 1.1 leo * Enable (unmask) the interrupt
198 1.1 leo */
199 1.1 leo if (slot == 0) {
200 1.1 leo single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
201 1.1 leo single_inst_bset_b(MFP->mf_ierb, IB_ISA1);
202 1.1 leo }
203 1.1 leo else {
204 1.1 leo single_inst_bset_b(MFP->mf_imra, IA_ISA2);
205 1.1 leo single_inst_bset_b(MFP->mf_iera, IA_ISA2);
206 1.1 leo }
207 1.1 leo return(iinfo_p);
208 1.1 leo }
209 1.1 leo return NULL;
210 1.1 leo }
211 1.1 leo
212 1.1 leo void
213 1.1 leo isa_intr_disestablish(ic, handler)
214 1.1 leo isa_chipset_tag_t ic;
215 1.1 leo void *handler;
216 1.1 leo {
217 1.1 leo isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
218 1.1 leo
219 1.1 leo if (iinfo_p->slot < 0)
220 1.2 provos panic("isa_intr_disestablish: interrupt was not established");
221 1.1 leo
222 1.1 leo (void) intr_disestablish(iinfo_p->ihand);
223 1.1 leo iinfo_p->slot = -1;
224 1.1 leo }
225