Fix up mix of man(7)/mdoc(7).
[netbsd-mini2440.git] / sys / arch / alpha / jensenio / jensenio_intr.c
blob205243b4d98aba5646963a495c83b7598130449e
1 /* $NetBSD: jensenio_intr.c,v 1.8 2007/12/03 15:33:05 ad Exp $ */
3 /*-
4 * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
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> /* RCS ID & Copyright macro defns */
34 __KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.8 2007/12/03 15:33:05 ad Exp $");
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/time.h>
39 #include <sys/systm.h>
40 #include <sys/errno.h>
41 #include <sys/malloc.h>
42 #include <sys/device.h>
43 #include <sys/syslog.h>
45 #include <machine/autoconf.h>
47 #include <dev/eisa/eisavar.h>
49 #include <dev/isa/isareg.h>
50 #include <dev/isa/isavar.h>
52 #include <alpha/jensenio/jenseniovar.h>
54 static bus_space_tag_t pic_iot;
55 static bus_space_handle_t pic_ioh[2];
56 static bus_space_handle_t pic_elcr_ioh;
58 int jensenio_eisa_intr_map(void *, u_int, eisa_intr_handle_t *);
59 const char *jensenio_eisa_intr_string(void *, int);
60 const struct evcnt *jensenio_eisa_intr_evcnt(void *, int);
61 void *jensenio_eisa_intr_establish(void *, int, int, int,
62 int (*)(void *), void *);
63 void jensenio_eisa_intr_disestablish(void *, void *);
64 int jensenio_eisa_intr_alloc(void *, int, int, int *);
66 #define JENSEN_MAX_IRQ 16
68 struct alpha_shared_intr *jensenio_eisa_intr;
70 void jensenio_iointr(void *, u_long);
72 void jensenio_enable_intr(int, int);
73 void jensenio_setlevel(int, int);
74 void jensenio_pic_init(void);
76 const int jensenio_intr_deftype[JENSEN_MAX_IRQ] = {
77 IST_EDGE, /* 0: interval timer 0 output */
78 IST_EDGE, /* 1: line printer */
79 IST_UNUSABLE, /* 2: (cascade) */
80 IST_NONE, /* 3: EISA pin B25 */
81 IST_NONE, /* 4: EISA pin B24 */
82 IST_NONE, /* 5: EISA pin B23 */
83 IST_NONE, /* 6: EISA pin B22 (floppy) */
84 IST_NONE, /* 7: EISA pin B21 */
85 IST_EDGE, /* 8: RTC */
86 IST_NONE, /* 9: EISA pin B04 */
87 IST_NONE, /* 10: EISA pin D03 */
88 IST_NONE, /* 11: EISA pin D04 */
89 IST_NONE, /* 12: EISA pin D05 */
90 IST_UNUSABLE, /* 13: not connected */
91 IST_NONE, /* 14: EISA pin D07 (SCSI) */
92 IST_NONE, /* 15: EISA pin D06 */
95 static inline void
96 jensenio_specific_eoi(int irq)
99 if (irq > 7)
100 bus_space_write_1(pic_iot, pic_ioh[1],
101 0, 0x20 | (irq & 0x07));
102 bus_space_write_1(pic_iot, pic_ioh[0],
103 0, 0x20 | (irq > 7 ? 2 : irq));
106 void
107 jensenio_intr_init(struct jensenio_config *jcp)
109 eisa_chipset_tag_t ec = &jcp->jc_ec;
110 isa_chipset_tag_t ic = &jcp->jc_ic;
111 char *cp;
112 int i;
114 pic_iot = &jcp->jc_eisa_iot;
116 jensenio_pic_init();
118 jensenio_eisa_intr = alpha_shared_intr_alloc(JENSEN_MAX_IRQ, 16);
119 for (i = 0; i < JENSEN_MAX_IRQ; i++) {
120 alpha_shared_intr_set_dfltsharetype(jensenio_eisa_intr,
121 i, jensenio_intr_deftype[i]);
122 /* Don't bother with stray interrupts. */
123 alpha_shared_intr_set_maxstrays(jensenio_eisa_intr,
124 i, 0);
126 cp = alpha_shared_intr_string(jensenio_eisa_intr, i);
127 sprintf(cp, "irq %d", i);
128 evcnt_attach_dynamic(alpha_shared_intr_evcnt(
129 jensenio_eisa_intr, i), EVCNT_TYPE_INTR,
130 NULL, "eisa", cp);
134 * The cascasde interrupt must be edge triggered and always enabled.
136 jensenio_setlevel(2, 0);
137 jensenio_enable_intr(2, 1);
140 * Initialize the EISA chipset.
142 ec->ec_v = jcp;
143 ec->ec_intr_map = jensenio_eisa_intr_map;
144 ec->ec_intr_string = jensenio_eisa_intr_string;
145 ec->ec_intr_evcnt = jensenio_eisa_intr_evcnt;
146 ec->ec_intr_establish = jensenio_eisa_intr_establish;
147 ec->ec_intr_disestablish = jensenio_eisa_intr_disestablish;
150 * Initialize the ISA chipset.
152 ic->ic_v = jcp;
153 ic->ic_intr_establish = jensenio_eisa_intr_establish;
154 ic->ic_intr_disestablish = jensenio_eisa_intr_disestablish;
155 ic->ic_intr_alloc = jensenio_eisa_intr_alloc;
156 ic->ic_intr_evcnt = jensenio_eisa_intr_evcnt;
160 jensenio_eisa_intr_map(void *v, u_int eirq, eisa_intr_handle_t *ihp)
163 if (eirq >= JENSEN_MAX_IRQ) {
164 printf("jensenio_eisa_intr_map: bogus IRQ %d", eirq);
165 *ihp = -1;
166 return (1);
169 if (jensenio_intr_deftype[eirq] == IST_UNUSABLE) {
170 printf("jensenio_eisa_intr_map: unusable irq %d\n",
171 eirq);
172 *ihp = -1;
173 return (1);
176 *ihp = eirq;
177 return (0);
180 const char *
181 jensenio_eisa_intr_string(void *v, int eirq)
183 static char irqstr[64];
185 if (eirq >= JENSEN_MAX_IRQ)
186 panic("jensenio_eisa_intr_string: bogus IRQ %d", eirq);
188 sprintf(irqstr, "eisa irq %d", eirq);
190 return (irqstr);
193 const struct evcnt *
194 jensenio_eisa_intr_evcnt(void *v, int eirq)
197 if (eirq >= JENSEN_MAX_IRQ)
198 panic("jensenio_eisa_intr_evcnt: bogus IRQ %d", eirq);
200 return (alpha_shared_intr_evcnt(jensenio_eisa_intr, eirq));
203 void *
204 jensenio_eisa_intr_establish(void *v, int irq, int type, int level,
205 int (*fn)(void *), void *arg)
207 void *cookie;
209 if (irq >= JENSEN_MAX_IRQ || type == IST_NONE)
210 panic("jensenio_eisa_intr_establish: bogus irq or type");
212 if (jensenio_intr_deftype[irq] == IST_UNUSABLE) {
213 printf("jensenio_eisa_intr_establish: IRQ %d not usable\n",
214 irq);
215 return (NULL);
218 cookie = alpha_shared_intr_establish(jensenio_eisa_intr, irq,
219 type, level, fn, arg, "eisa irq");
221 if (cookie != NULL &&
222 alpha_shared_intr_firstactive(jensenio_eisa_intr, irq)) {
223 scb_set(0x800 + SCB_IDXTOVEC(irq), jensenio_iointr, NULL,
224 level);
225 jensenio_setlevel(irq,
226 alpha_shared_intr_get_sharetype(jensenio_eisa_intr,
227 irq) == IST_LEVEL);
228 jensenio_enable_intr(irq, 1);
231 return (cookie);
234 void
235 jensenio_eisa_intr_disestablish(void *v, void *cookie)
237 struct alpha_shared_intrhand *ih = cookie;
238 int s, irq = ih->ih_num;
240 s = splhigh();
242 /* Remove it from the link. */
243 alpha_shared_intr_disestablish(jensenio_eisa_intr, cookie,
244 "eisa irq");
246 if (alpha_shared_intr_isactive(jensenio_eisa_intr, irq) == 0) {
247 jensenio_enable_intr(irq, 0);
248 alpha_shared_intr_set_dfltsharetype(jensenio_eisa_intr,
249 irq, jensenio_intr_deftype[irq]);
250 scb_free(0x800 + SCB_IDXTOVEC(irq));
253 splx(s);
257 jensenio_eisa_intr_alloc(void *v, int mask, int type, int *rqp)
260 /* XXX Not supported right now. */
261 return (1);
264 void
265 jensenio_iointr(void *framep, u_long vec)
267 int irq;
269 irq = SCB_VECTOIDX(vec - 0x800);
271 if (!alpha_shared_intr_dispatch(jensenio_eisa_intr, irq))
272 alpha_shared_intr_stray(jensenio_eisa_intr, irq, "eisa irq");
274 jensenio_specific_eoi(irq);
277 void
278 jensenio_enable_intr(int irq, int onoff)
280 int pic;
281 u_int8_t bit, mask;
283 pic = irq >> 3;
284 bit = 1 << (irq & 0x7);
286 mask = bus_space_read_1(pic_iot, pic_ioh[pic], 1);
287 if (onoff)
288 mask &= ~bit;
289 else
290 mask |= bit;
291 bus_space_write_1(pic_iot, pic_ioh[pic], 1, mask);
294 void
295 jensenio_setlevel(int irq, int level)
297 int elcr;
298 u_int8_t bit, mask;
300 elcr = irq >> 3;
301 bit = 1 << (irq & 0x7);
303 mask = bus_space_read_1(pic_iot, pic_elcr_ioh, elcr);
304 if (level)
305 mask |= bit;
306 else
307 mask &= ~bit;
308 bus_space_write_1(pic_iot, pic_elcr_ioh, elcr, mask);
311 void
312 jensenio_pic_init(void)
314 static const int picaddr[2] = { IO_ICU1, IO_ICU2 };
315 int pic;
318 * Map the PICs and mask off the interrupts on them.
320 for (pic = 0; pic < 2; pic++) {
321 if (bus_space_map(pic_iot, picaddr[pic], 2, 0, &pic_ioh[pic]))
322 panic("jensenio_init_intr: unable to map PIC %d", pic);
323 bus_space_write_1(pic_iot, pic_ioh[pic], 1, 0xff);
327 * Map the ELCR registers.
329 if (bus_space_map(pic_iot, 0x4d0, 2, 0, &pic_elcr_ioh))
330 panic("jensenio_init_intr: unable to map ELCR registers");