Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / atari / isa / isa_hades.c
blob7b54570a03fc565c1fc723b392fd6de3ba9fcb7c
1 /* $NetBSD: isa_hades.c,v 1.8 2009/03/16 23:11:10 dsl Exp $ */
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Leo Weppelman.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: isa_hades.c,v 1.8 2009/03/16 23:11:10 dsl Exp $");
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
40 #include <dev/isa/isavar.h>
41 #include <dev/isa/isareg.h>
43 #include <m68k/asm_single.h>
45 #include <machine/iomap.h>
46 #include <machine/mfp.h>
48 void isa_bus_init(void);
50 void
51 isa_bus_init(void)
56 * The interrupt stuff is rather ugly. On the Hades, all interrupt lines
57 * for a slot are wired together and connected to either IO3 (slot1) or
58 * IO7 (slot2). Since no info can be obtained about the slot position
59 * at isa_intr_establish() time, the following assumption is made:
60 * - irq <= 6 -> slot 1
61 * - irq > 6 -> slot 2
64 #define SLOTNR(irq) ((irq <= 6) ? 0 : 1)
66 static isa_intr_info_t iinfo[2] = { { -1 }, { -1 } };
68 static int iifun(int, int);
70 static int
71 iifun(int slot, int sr)
73 isa_intr_info_t *iinfo_p;
74 int s;
76 iinfo_p = &iinfo[slot];
79 * Disable the interrupts
81 if (slot == 0) {
82 single_inst_bclr_b(MFP->mf_imrb, IB_ISA1);
84 else {
85 single_inst_bclr_b(MFP->mf_imra, IA_ISA2);
88 if ((sr & PSL_IPL) >= (iinfo_p->ipl & PSL_IPL)) {
90 * We're running at a too high priority now.
92 add_sicallback((si_farg)iifun, (void*)slot, 0);
94 else {
95 s = splx(iinfo_p->ipl);
96 if (slot == 0) {
97 do {
98 MFP->mf_iprb = (u_int8_t)~IB_ISA1;
99 (void) (iinfo_p->ifunc)(iinfo_p->iarg);
100 } while (MFP->mf_iprb & IB_ISA1);
101 single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
103 else {
104 do {
105 MFP->mf_ipra = (u_int8_t)~IA_ISA2;
106 (void) (iinfo_p->ifunc)(iinfo_p->iarg);
107 } while (MFP->mf_ipra & IA_ISA2);
108 single_inst_bset_b(MFP->mf_imra, IA_ISA2);
110 splx(s);
112 return 1;
117 * XXXX
118 * XXXX Note that this function is not really working yet! The big problem is
119 * XXXX to only generate interrupts for the slot the card is in...
122 isa_intr_alloc(isa_chipset_tag_t ic, int mask, int type, int *irq)
124 isa_intr_info_t *iinfo_p;
125 int slot, i;
129 * The Hades only supports edge triggered interrupts!
131 if (type != IST_EDGE)
132 return 1;
134 #define MAXIRQ 10 /* XXX: Pure fiction */
135 for (i = 0; i < MAXIRQ; i++) {
136 if (mask & (1<<i)) {
137 slot = SLOTNR(i);
138 iinfo_p = &iinfo[slot];
140 if (iinfo_p->slot < 0) {
141 *irq = i;
142 printf("WARNING: isa_intr_alloc is not yet ready!\n"
143 " make sure the card is in slot %d!\n",
144 slot);
145 return 0;
149 return (1);
151 void *
152 isa_intr_establish(isa_chipset_tag_t ic, int irq, int type, int level, int (*ih_fun)(void *), void *ih_arg)
154 isa_intr_info_t *iinfo_p;
155 struct intrhand *ihand;
156 int slot;
159 * The Hades only supports edge triggered interrupts!
161 if (type != IST_EDGE)
162 return NULL;
164 slot = SLOTNR(irq);
165 iinfo_p = &iinfo[slot];
167 if (iinfo_p->slot >= 0)
168 panic("isa_intr_establish: interrupt was already established");
170 ihand = intr_establish((slot == 0) ? 3 : 15, USER_VEC, 0,
171 (hw_ifun_t)iifun, (void *)slot);
172 if (ihand != NULL) {
173 iinfo_p->slot = slot;
174 iinfo_p->ipl = level;
175 iinfo_p->ifunc = ih_fun;
176 iinfo_p->iarg = ih_arg;
177 iinfo_p->ihand = ihand;
180 * Enable (unmask) the interrupt
182 if (slot == 0) {
183 single_inst_bset_b(MFP->mf_imrb, IB_ISA1);
184 single_inst_bset_b(MFP->mf_ierb, IB_ISA1);
186 else {
187 single_inst_bset_b(MFP->mf_imra, IA_ISA2);
188 single_inst_bset_b(MFP->mf_iera, IA_ISA2);
190 return(iinfo_p);
192 return NULL;
195 void
196 isa_intr_disestablish(isa_chipset_tag_t ic, void *handler)
198 isa_intr_info_t *iinfo_p = (isa_intr_info_t *)handler;
200 if (iinfo_p->slot < 0)
201 panic("isa_intr_disestablish: interrupt was not established");
203 (void) intr_disestablish(iinfo_p->ihand);
204 iinfo_p->slot = -1;