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