| @@ -1,389 +1,395 @@ | | | @@ -1,389 +1,395 @@ |
1 | /* $NetBSD: jensenio_intr.c,v 1.17 2021/07/04 22:42:35 thorpej Exp $ */ | | 1 | /* $NetBSD: jensenio_intr.c,v 1.18 2021/07/15 01:43:54 thorpej Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Jason R. Thorpe. | | 8 | * by Jason R. Thorpe. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 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 | | 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 | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 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 | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 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 | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ | | 32 | #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ |
33 | | | 33 | |
34 | __KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.17 2021/07/04 22:42:35 thorpej Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: jensenio_intr.c,v 1.18 2021/07/15 01:43:54 thorpej Exp $"); |
35 | | | 35 | |
36 | #include <sys/types.h> | | 36 | #include <sys/types.h> |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | #include <sys/time.h> | | 38 | #include <sys/time.h> |
39 | #include <sys/systm.h> | | 39 | #include <sys/systm.h> |
40 | #include <sys/errno.h> | | 40 | #include <sys/errno.h> |
41 | #include <sys/device.h> | | 41 | #include <sys/device.h> |
42 | #include <sys/cpu.h> | | 42 | #include <sys/cpu.h> |
43 | #include <sys/syslog.h> | | 43 | #include <sys/syslog.h> |
44 | | | 44 | |
45 | #include <machine/autoconf.h> | | 45 | #include <machine/autoconf.h> |
46 | | | 46 | |
| | | 47 | #include <dev/ic/i8259reg.h> |
| | | 48 | |
47 | #include <dev/eisa/eisavar.h> | | 49 | #include <dev/eisa/eisavar.h> |
48 | | | 50 | |
49 | #include <dev/isa/isareg.h> | | 51 | #include <dev/isa/isareg.h> |
50 | #include <dev/isa/isavar.h> | | 52 | #include <dev/isa/isavar.h> |
51 | | | 53 | |
52 | #include <alpha/jensenio/jenseniovar.h> | | 54 | #include <alpha/jensenio/jenseniovar.h> |
53 | | | 55 | |
54 | static bus_space_tag_t pic_iot; | | 56 | static bus_space_tag_t pic_iot; |
55 | static bus_space_handle_t pic_ioh[2]; | | 57 | static bus_space_handle_t pic_ioh[2]; |
56 | static bus_space_handle_t pic_elcr_ioh; | | 58 | static bus_space_handle_t pic_elcr_ioh; |
57 | | | 59 | |
58 | static int jensenio_eisa_intr_map(void *, u_int, | | 60 | static int jensenio_eisa_intr_map(void *, u_int, |
59 | eisa_intr_handle_t *); | | 61 | eisa_intr_handle_t *); |
60 | static const char * jensenio_eisa_intr_string(void *, int, char *, size_t); | | 62 | static const char * jensenio_eisa_intr_string(void *, int, char *, size_t); |
61 | static const struct evcnt *jensenio_eisa_intr_evcnt(void *, int); | | 63 | static const struct evcnt *jensenio_eisa_intr_evcnt(void *, int); |
62 | static void * jensenio_eisa_intr_establish(void *, int, int, int, | | 64 | static void * jensenio_eisa_intr_establish(void *, int, int, int, |
63 | int (*)(void *), void *); | | 65 | int (*)(void *), void *); |
64 | static void jensenio_eisa_intr_disestablish(void *, void *); | | 66 | static void jensenio_eisa_intr_disestablish(void *, void *); |
65 | static int jensenio_eisa_intr_alloc(void *, int, int, int *); | | 67 | static int jensenio_eisa_intr_alloc(void *, int, int, int *); |
66 | | | 68 | |
67 | #define JENSEN_MAX_IRQ 16 | | 69 | #define JENSEN_MAX_IRQ 16 |
68 | | | 70 | |
69 | static struct alpha_shared_intr *jensenio_eisa_intr; | | 71 | static struct alpha_shared_intr *jensenio_eisa_intr; |
70 | | | 72 | |
71 | static void jensenio_iointr(void *, u_long); | | 73 | static void jensenio_iointr(void *, u_long); |
72 | | | 74 | |
73 | static void jensenio_enable_intr(int, int); | | 75 | static void jensenio_enable_intr(int, int); |
74 | static void jensenio_setlevel(int, int); | | 76 | static void jensenio_setlevel(int, int); |
75 | static void jensenio_pic_init(void); | | 77 | static void jensenio_pic_init(void); |
76 | | | 78 | |
77 | static const int jensenio_intr_deftype[JENSEN_MAX_IRQ] = { | | 79 | static const int jensenio_intr_deftype[JENSEN_MAX_IRQ] = { |
78 | IST_EDGE, /* 0: interval timer 0 output */ | | 80 | IST_EDGE, /* 0: interval timer 0 output */ |
79 | IST_EDGE, /* 1: line printer */ | | 81 | IST_EDGE, /* 1: line printer */ |
80 | IST_UNUSABLE, /* 2: (cascade) */ | | 82 | IST_UNUSABLE, /* 2: (cascade) */ |
81 | IST_NONE, /* 3: EISA pin B25 */ | | 83 | IST_NONE, /* 3: EISA pin B25 */ |
82 | IST_NONE, /* 4: EISA pin B24 */ | | 84 | IST_NONE, /* 4: EISA pin B24 */ |
83 | IST_NONE, /* 5: EISA pin B23 */ | | 85 | IST_NONE, /* 5: EISA pin B23 */ |
84 | IST_NONE, /* 6: EISA pin B22 (floppy) */ | | 86 | IST_NONE, /* 6: EISA pin B22 (floppy) */ |
85 | IST_NONE, /* 7: EISA pin B21 */ | | 87 | IST_NONE, /* 7: EISA pin B21 */ |
86 | IST_EDGE, /* 8: RTC */ | | 88 | IST_EDGE, /* 8: RTC */ |
87 | IST_NONE, /* 9: EISA pin B04 */ | | 89 | IST_NONE, /* 9: EISA pin B04 */ |
88 | IST_NONE, /* 10: EISA pin D03 */ | | 90 | IST_NONE, /* 10: EISA pin D03 */ |
89 | IST_NONE, /* 11: EISA pin D04 */ | | 91 | IST_NONE, /* 11: EISA pin D04 */ |
90 | IST_NONE, /* 12: EISA pin D05 */ | | 92 | IST_NONE, /* 12: EISA pin D05 */ |
91 | IST_UNUSABLE, /* 13: not connected */ | | 93 | IST_UNUSABLE, /* 13: not connected */ |
92 | IST_NONE, /* 14: EISA pin D07 (SCSI) */ | | 94 | IST_NONE, /* 14: EISA pin D07 (SCSI) */ |
93 | IST_NONE, /* 15: EISA pin D06 */ | | 95 | IST_NONE, /* 15: EISA pin D06 */ |
94 | }; | | 96 | }; |
95 | | | 97 | |
96 | static inline void | | 98 | static inline void |
97 | jensenio_specific_eoi(int irq) | | 99 | jensenio_specific_eoi(int irq) |
98 | { | | 100 | { |
99 | | | 101 | |
100 | if (irq > 7) | | 102 | if (irq > 7) { |
101 | bus_space_write_1(pic_iot, pic_ioh[1], | | 103 | bus_space_write_1(pic_iot, pic_ioh[1], PIC_OCW2, |
102 | 0, 0x20 | (irq & 0x07)); | | 104 | OCW2_EOI | OCW2_SL | (irq & 0x07)); |
103 | bus_space_write_1(pic_iot, pic_ioh[0], | | 105 | } |
104 | 0, 0x20 | (irq > 7 ? 2 : irq)); | | 106 | bus_space_write_1(pic_iot, pic_ioh[0], PIC_OCW2, |
| | | 107 | OCW2_EOI | OCW2_SL | (irq > 7 ? 2 : irq)); |
105 | } | | 108 | } |
106 | | | 109 | |
107 | void | | 110 | void |
108 | jensenio_intr_init(struct jensenio_config *jcp) | | 111 | jensenio_intr_init(struct jensenio_config *jcp) |
109 | { | | 112 | { |
110 | eisa_chipset_tag_t ec = &jcp->jc_ec; | | 113 | eisa_chipset_tag_t ec = &jcp->jc_ec; |
111 | isa_chipset_tag_t ic = &jcp->jc_ic; | | 114 | isa_chipset_tag_t ic = &jcp->jc_ic; |
112 | struct evcnt *ev; | | 115 | struct evcnt *ev; |
113 | const char *cp; | | 116 | const char *cp; |
114 | int i; | | 117 | int i; |
115 | | | 118 | |
116 | pic_iot = &jcp->jc_eisa_iot; | | 119 | pic_iot = &jcp->jc_eisa_iot; |
117 | | | 120 | |
118 | jensenio_pic_init(); | | 121 | jensenio_pic_init(); |
119 | | | 122 | |
120 | jensenio_eisa_intr = alpha_shared_intr_alloc(JENSEN_MAX_IRQ); | | 123 | jensenio_eisa_intr = alpha_shared_intr_alloc(JENSEN_MAX_IRQ); |
121 | for (i = 0; i < JENSEN_MAX_IRQ; i++) { | | 124 | for (i = 0; i < JENSEN_MAX_IRQ; i++) { |
122 | alpha_shared_intr_set_dfltsharetype(jensenio_eisa_intr, | | 125 | alpha_shared_intr_set_dfltsharetype(jensenio_eisa_intr, |
123 | i, jensenio_intr_deftype[i]); | | 126 | i, jensenio_intr_deftype[i]); |
124 | | | 127 | |
125 | ev = alpha_shared_intr_evcnt(jensenio_eisa_intr, i); | | 128 | ev = alpha_shared_intr_evcnt(jensenio_eisa_intr, i); |
126 | cp = alpha_shared_intr_string(jensenio_eisa_intr, i); | | 129 | cp = alpha_shared_intr_string(jensenio_eisa_intr, i); |
127 | | | 130 | |
128 | evcnt_attach_dynamic(ev, EVCNT_TYPE_INTR, NULL, "eisa", cp); | | 131 | evcnt_attach_dynamic(ev, EVCNT_TYPE_INTR, NULL, "eisa", cp); |
129 | } | | 132 | } |
130 | | | 133 | |
131 | /* | | 134 | /* |
132 | * The cascasde interrupt must be edge triggered and always enabled. | | 135 | * The cascasde interrupt must be edge triggered and always enabled. |
133 | */ | | 136 | */ |
134 | jensenio_setlevel(2, 0); | | 137 | jensenio_setlevel(2, 0); |
135 | jensenio_enable_intr(2, 1); | | 138 | jensenio_enable_intr(2, 1); |
136 | | | 139 | |
137 | /* | | 140 | /* |
138 | * Initialize the EISA chipset. | | 141 | * Initialize the EISA chipset. |
139 | */ | | 142 | */ |
140 | ec->ec_v = jcp; | | 143 | ec->ec_v = jcp; |
141 | ec->ec_intr_map = jensenio_eisa_intr_map; | | 144 | ec->ec_intr_map = jensenio_eisa_intr_map; |
142 | ec->ec_intr_string = jensenio_eisa_intr_string; | | 145 | ec->ec_intr_string = jensenio_eisa_intr_string; |
143 | ec->ec_intr_evcnt = jensenio_eisa_intr_evcnt; | | 146 | ec->ec_intr_evcnt = jensenio_eisa_intr_evcnt; |
144 | ec->ec_intr_establish = jensenio_eisa_intr_establish; | | 147 | ec->ec_intr_establish = jensenio_eisa_intr_establish; |
145 | ec->ec_intr_disestablish = jensenio_eisa_intr_disestablish; | | 148 | ec->ec_intr_disestablish = jensenio_eisa_intr_disestablish; |
146 | | | 149 | |
147 | /* | | 150 | /* |
148 | * Initialize the ISA chipset. | | 151 | * Initialize the ISA chipset. |
149 | */ | | 152 | */ |
150 | ic->ic_v = jcp; | | 153 | ic->ic_v = jcp; |
151 | ic->ic_intr_establish = jensenio_eisa_intr_establish; | | 154 | ic->ic_intr_establish = jensenio_eisa_intr_establish; |
152 | ic->ic_intr_disestablish = jensenio_eisa_intr_disestablish; | | 155 | ic->ic_intr_disestablish = jensenio_eisa_intr_disestablish; |
153 | ic->ic_intr_alloc = jensenio_eisa_intr_alloc; | | 156 | ic->ic_intr_alloc = jensenio_eisa_intr_alloc; |
154 | ic->ic_intr_evcnt = jensenio_eisa_intr_evcnt; | | 157 | ic->ic_intr_evcnt = jensenio_eisa_intr_evcnt; |
155 | } | | 158 | } |
156 | | | 159 | |
157 | static void | | 160 | static void |
158 | jensenio_intr_dispatch(void *arg, unsigned long vec) | | 161 | jensenio_intr_dispatch(void *arg, unsigned long vec) |
159 | { | | 162 | { |
160 | struct jensenio_scb_intrhand *jih = arg; | | 163 | struct jensenio_scb_intrhand *jih = arg; |
161 | | | 164 | |
162 | jih->jih_evcnt.ev_count++; | | 165 | jih->jih_evcnt.ev_count++; |
163 | (void) jih->jih_func(jih->jih_arg); | | 166 | (void) jih->jih_func(jih->jih_arg); |
164 | } | | 167 | } |
165 | | | 168 | |
166 | static void | | 169 | static void |
167 | jensenio_intr_dispatch_wrapped(void *arg, unsigned long vec) | | 170 | jensenio_intr_dispatch_wrapped(void *arg, unsigned long vec) |
168 | { | | 171 | { |
169 | KERNEL_LOCK(1, NULL); | | 172 | KERNEL_LOCK(1, NULL); |
170 | jensenio_intr_dispatch(arg, vec); | | 173 | jensenio_intr_dispatch(arg, vec); |
171 | KERNEL_UNLOCK_ONE(NULL); | | 174 | KERNEL_UNLOCK_ONE(NULL); |
172 | } | | 175 | } |
173 | | | 176 | |
174 | void | | 177 | void |
175 | jensenio_intr_establish(struct jensenio_scb_intrhand *jih, | | 178 | jensenio_intr_establish(struct jensenio_scb_intrhand *jih, |
176 | unsigned long vec, int flags, int (*func)(void *), void *arg) | | 179 | unsigned long vec, int flags, int (*func)(void *), void *arg) |
177 | { | | 180 | { |
178 | void (*scb_func)(void *, unsigned long); | | 181 | void (*scb_func)(void *, unsigned long); |
179 | | | 182 | |
180 | /* | | 183 | /* |
181 | * Jensen systems are all uniprocessors, but we still do all | | 184 | * Jensen systems are all uniprocessors, but we still do all |
182 | * of the KERNEL_LOCK handling as a formality to keep assertions | | 185 | * of the KERNEL_LOCK handling as a formality to keep assertions |
183 | * valid in MI code. | | 186 | * valid in MI code. |
184 | */ | | 187 | */ |
185 | KASSERT(CPU_IS_PRIMARY(curcpu())); | | 188 | KASSERT(CPU_IS_PRIMARY(curcpu())); |
186 | KASSERT(ncpu == 1); | | 189 | KASSERT(ncpu == 1); |
187 | if (flags & ALPHA_INTR_MPSAFE) | | 190 | if (flags & ALPHA_INTR_MPSAFE) |
188 | scb_func = jensenio_intr_dispatch; | | 191 | scb_func = jensenio_intr_dispatch; |
189 | else | | 192 | else |
190 | scb_func = jensenio_intr_dispatch_wrapped; | | 193 | scb_func = jensenio_intr_dispatch_wrapped; |
191 | | | 194 | |
192 | jih->jih_func = func; | | 195 | jih->jih_func = func; |
193 | jih->jih_arg = arg; | | 196 | jih->jih_arg = arg; |
194 | jih->jih_vec = vec; | | 197 | jih->jih_vec = vec; |
195 | | | 198 | |
196 | snprintf(jih->jih_vecstr, sizeof(jih->jih_vecstr), "0x%lx", | | 199 | snprintf(jih->jih_vecstr, sizeof(jih->jih_vecstr), "0x%lx", |
197 | jih->jih_vec); | | 200 | jih->jih_vec); |
198 | evcnt_attach_dynamic(&jih->jih_evcnt, EVCNT_TYPE_INTR, | | 201 | evcnt_attach_dynamic(&jih->jih_evcnt, EVCNT_TYPE_INTR, |
199 | NULL, "vector", jih->jih_vecstr); | | 202 | NULL, "vector", jih->jih_vecstr); |
200 | | | 203 | |
201 | mutex_enter(&cpu_lock); | | 204 | mutex_enter(&cpu_lock); |
202 | | | 205 | |
203 | scb_set(vec, scb_func, jih); | | 206 | scb_set(vec, scb_func, jih); |
204 | curcpu()->ci_nintrhand++; | | 207 | curcpu()->ci_nintrhand++; |
205 | | | 208 | |
206 | mutex_exit(&cpu_lock); | | 209 | mutex_exit(&cpu_lock); |
207 | } | | 210 | } |
208 | | | 211 | |
209 | static int | | 212 | static int |
210 | jensenio_eisa_intr_map(void *v, u_int eirq, eisa_intr_handle_t *ihp) | | 213 | jensenio_eisa_intr_map(void *v, u_int eirq, eisa_intr_handle_t *ihp) |
211 | { | | 214 | { |
212 | | | 215 | |
213 | if (eirq >= JENSEN_MAX_IRQ) { | | 216 | if (eirq >= JENSEN_MAX_IRQ) { |
214 | printf("jensenio_eisa_intr_map: bogus IRQ %d", eirq); | | 217 | printf("jensenio_eisa_intr_map: bogus IRQ %d", eirq); |
215 | *ihp = -1; | | 218 | *ihp = -1; |
216 | return (1); | | 219 | return (1); |
217 | } | | 220 | } |
218 | | | 221 | |
219 | if (jensenio_intr_deftype[eirq] == IST_UNUSABLE) { | | 222 | if (jensenio_intr_deftype[eirq] == IST_UNUSABLE) { |
220 | printf("jensenio_eisa_intr_map: unusable irq %d\n", | | 223 | printf("jensenio_eisa_intr_map: unusable irq %d\n", |
221 | eirq); | | 224 | eirq); |
222 | *ihp = -1; | | 225 | *ihp = -1; |
223 | return (1); | | 226 | return (1); |
224 | } | | 227 | } |
225 | | | 228 | |
226 | *ihp = eirq; | | 229 | *ihp = eirq; |
227 | return (0); | | 230 | return (0); |
228 | } | | 231 | } |
229 | | | 232 | |
230 | static const char * | | 233 | static const char * |
231 | jensenio_eisa_intr_string(void *v, int eirq, char *buf, size_t len) | | 234 | jensenio_eisa_intr_string(void *v, int eirq, char *buf, size_t len) |
232 | { | | 235 | { |
233 | if (eirq >= JENSEN_MAX_IRQ) | | 236 | if (eirq >= JENSEN_MAX_IRQ) |
234 | panic("%s: bogus IRQ %d", __func__, eirq); | | 237 | panic("%s: bogus IRQ %d", __func__, eirq); |
235 | | | 238 | |
236 | snprintf(buf, len, "eisa irq %d", eirq); | | 239 | snprintf(buf, len, "eisa irq %d", eirq); |
237 | return buf; | | 240 | return buf; |
238 | } | | 241 | } |
239 | | | 242 | |
240 | static const struct evcnt * | | 243 | static const struct evcnt * |
241 | jensenio_eisa_intr_evcnt(void *v, int eirq) | | 244 | jensenio_eisa_intr_evcnt(void *v, int eirq) |
242 | { | | 245 | { |
243 | | | 246 | |
244 | if (eirq >= JENSEN_MAX_IRQ) | | 247 | if (eirq >= JENSEN_MAX_IRQ) |
245 | panic("%s: bogus IRQ %d", __func__, eirq); | | 248 | panic("%s: bogus IRQ %d", __func__, eirq); |
246 | | | 249 | |
247 | return (alpha_shared_intr_evcnt(jensenio_eisa_intr, eirq)); | | 250 | return (alpha_shared_intr_evcnt(jensenio_eisa_intr, eirq)); |
248 | } | | 251 | } |
249 | | | 252 | |
250 | static void * | | 253 | static void * |
251 | jensenio_eisa_intr_establish(void *v, int irq, int type, int level, | | 254 | jensenio_eisa_intr_establish(void *v, int irq, int type, int level, |
252 | int (*fn)(void *), void *arg) | | 255 | int (*fn)(void *), void *arg) |
253 | { | | 256 | { |
254 | void *cookie; | | 257 | void *cookie; |
255 | | | 258 | |
256 | if (irq >= JENSEN_MAX_IRQ || type == IST_NONE) | | 259 | if (irq >= JENSEN_MAX_IRQ || type == IST_NONE) |
257 | panic("jensenio_eisa_intr_establish: bogus irq or type"); | | 260 | panic("jensenio_eisa_intr_establish: bogus irq or type"); |
258 | | | 261 | |
259 | if (jensenio_intr_deftype[irq] == IST_UNUSABLE) { | | 262 | if (jensenio_intr_deftype[irq] == IST_UNUSABLE) { |
260 | printf("jensenio_eisa_intr_establish: IRQ %d not usable\n", | | 263 | printf("jensenio_eisa_intr_establish: IRQ %d not usable\n", |
261 | irq); | | 264 | irq); |
262 | return NULL; | | 265 | return NULL; |
263 | } | | 266 | } |
264 | | | 267 | |
265 | cookie = alpha_shared_intr_alloc_intrhand(jensenio_eisa_intr, irq, | | 268 | cookie = alpha_shared_intr_alloc_intrhand(jensenio_eisa_intr, irq, |
266 | type, level, 0, fn, arg, "eisa"); | | 269 | type, level, 0, fn, arg, "eisa"); |
267 | | | 270 | |
268 | if (cookie == NULL) | | 271 | if (cookie == NULL) |
269 | return NULL; | | 272 | return NULL; |
270 | | | 273 | |
271 | mutex_enter(&cpu_lock); | | 274 | mutex_enter(&cpu_lock); |
272 | | | 275 | |
273 | if (! alpha_shared_intr_link(jensenio_eisa_intr, cookie, "eisa")) { | | 276 | if (! alpha_shared_intr_link(jensenio_eisa_intr, cookie, "eisa")) { |
274 | mutex_exit(&cpu_lock); | | 277 | mutex_exit(&cpu_lock); |
275 | alpha_shared_intr_free_intrhand(cookie); | | 278 | alpha_shared_intr_free_intrhand(cookie); |
276 | return NULL; | | 279 | return NULL; |
277 | } | | 280 | } |
278 | | | 281 | |
279 | if (alpha_shared_intr_firstactive(jensenio_eisa_intr, irq)) { | | 282 | if (alpha_shared_intr_firstactive(jensenio_eisa_intr, irq)) { |
280 | scb_set(0x800 + SCB_IDXTOVEC(irq), jensenio_iointr, NULL); | | 283 | scb_set(0x800 + SCB_IDXTOVEC(irq), jensenio_iointr, NULL); |
281 | jensenio_setlevel(irq, | | 284 | jensenio_setlevel(irq, |
282 | alpha_shared_intr_get_sharetype(jensenio_eisa_intr, | | 285 | alpha_shared_intr_get_sharetype(jensenio_eisa_intr, |
283 | irq) == IST_LEVEL); | | 286 | irq) == IST_LEVEL); |
284 | jensenio_enable_intr(irq, 1); | | 287 | jensenio_enable_intr(irq, 1); |
285 | } | | 288 | } |
286 | | | 289 | |
287 | mutex_exit(&cpu_lock); | | 290 | mutex_exit(&cpu_lock); |
288 | | | 291 | |
289 | return cookie; | | 292 | return cookie; |
290 | } | | 293 | } |
291 | | | 294 | |
292 | static void | | 295 | static void |
293 | jensenio_eisa_intr_disestablish(void *v, void *cookie) | | 296 | jensenio_eisa_intr_disestablish(void *v, void *cookie) |
294 | { | | 297 | { |
295 | struct alpha_shared_intrhand *ih = cookie; | | 298 | struct alpha_shared_intrhand *ih = cookie; |
296 | int irq = ih->ih_num; | | 299 | int irq = ih->ih_num; |
297 | | | 300 | |
298 | mutex_enter(&cpu_lock); | | 301 | mutex_enter(&cpu_lock); |
299 | | | 302 | |
300 | if (alpha_shared_intr_firstactive(jensenio_eisa_intr, irq)) { | | 303 | if (alpha_shared_intr_firstactive(jensenio_eisa_intr, irq)) { |
301 | jensenio_enable_intr(irq, 0); | | 304 | jensenio_enable_intr(irq, 0); |
302 | alpha_shared_intr_set_dfltsharetype(jensenio_eisa_intr, | | 305 | alpha_shared_intr_set_dfltsharetype(jensenio_eisa_intr, |
303 | irq, jensenio_intr_deftype[irq]); | | 306 | irq, jensenio_intr_deftype[irq]); |
304 | scb_free(0x800 + SCB_IDXTOVEC(irq)); | | 307 | scb_free(0x800 + SCB_IDXTOVEC(irq)); |
305 | } | | 308 | } |
306 | | | 309 | |
307 | alpha_shared_intr_unlink(jensenio_eisa_intr, cookie, "eisa"); | | 310 | alpha_shared_intr_unlink(jensenio_eisa_intr, cookie, "eisa"); |
308 | | | 311 | |
309 | mutex_exit(&cpu_lock); | | 312 | mutex_exit(&cpu_lock); |
310 | | | 313 | |
311 | alpha_shared_intr_free_intrhand(cookie); | | 314 | alpha_shared_intr_free_intrhand(cookie); |
312 | } | | 315 | } |
313 | | | 316 | |
314 | static int | | 317 | static int |
315 | jensenio_eisa_intr_alloc(void *v, int mask, int type, int *rqp) | | 318 | jensenio_eisa_intr_alloc(void *v, int mask, int type, int *rqp) |
316 | { | | 319 | { |
317 | | | 320 | |
318 | /* XXX Not supported right now. */ | | 321 | /* XXX Not supported right now. */ |
319 | return (1); | | 322 | return (1); |
320 | } | | 323 | } |
321 | | | 324 | |
322 | static void | | 325 | static void |
323 | jensenio_iointr(void *framep, u_long vec) | | 326 | jensenio_iointr(void *framep, u_long vec) |
324 | { | | 327 | { |
325 | int irq; | | 328 | int irq; |
326 | | | 329 | |
327 | irq = SCB_VECTOIDX(vec - 0x800); | | 330 | irq = SCB_VECTOIDX(vec - 0x800); |
328 | | | 331 | |
329 | if (!alpha_shared_intr_dispatch(jensenio_eisa_intr, irq)) | | 332 | if (!alpha_shared_intr_dispatch(jensenio_eisa_intr, irq)) |
330 | alpha_shared_intr_stray(jensenio_eisa_intr, irq, "eisa"); | | 333 | alpha_shared_intr_stray(jensenio_eisa_intr, irq, "eisa"); |
331 | | | 334 | |
332 | jensenio_specific_eoi(irq); | | 335 | jensenio_specific_eoi(irq); |
333 | } | | 336 | } |
334 | | | 337 | |
335 | static void | | 338 | static void |
336 | jensenio_enable_intr(int irq, int onoff) | | 339 | jensenio_enable_intr(int irq, int onoff) |
337 | { | | 340 | { |
338 | int pic; | | 341 | int pic; |
339 | uint8_t bit, mask; | | 342 | uint8_t bit, mask; |
340 | | | 343 | |
341 | pic = irq >> 3; | | 344 | pic = irq >> 3; |
342 | bit = 1 << (irq & 0x7); | | 345 | bit = 1 << (irq & 0x7); |
343 | | | 346 | |
344 | mask = bus_space_read_1(pic_iot, pic_ioh[pic], 1); | | 347 | mask = bus_space_read_1(pic_iot, pic_ioh[pic], PIC_OCW1); |
345 | if (onoff) | | 348 | if (onoff) |
346 | mask &= ~bit; | | 349 | mask &= ~bit; |
347 | else | | 350 | else |
348 | mask |= bit; | | 351 | mask |= bit; |
349 | bus_space_write_1(pic_iot, pic_ioh[pic], 1, mask); | | 352 | bus_space_write_1(pic_iot, pic_ioh[pic], PIC_OCW1, mask); |
350 | } | | 353 | } |
351 | | | 354 | |
352 | void | | 355 | void |
353 | jensenio_setlevel(int irq, int level) | | 356 | jensenio_setlevel(int irq, int level) |
354 | { | | 357 | { |
355 | int elcr; | | 358 | int elcr; |
356 | uint8_t bit, mask; | | 359 | uint8_t bit, mask; |
357 | | | 360 | |
358 | elcr = irq >> 3; | | 361 | elcr = irq >> 3; |
359 | bit = 1 << (irq & 0x7); | | 362 | bit = 1 << (irq & 0x7); |
360 | | | 363 | |
361 | mask = bus_space_read_1(pic_iot, pic_elcr_ioh, elcr); | | 364 | mask = bus_space_read_1(pic_iot, pic_elcr_ioh, elcr); |
362 | if (level) | | 365 | if (level) |
363 | mask |= bit; | | 366 | mask |= bit; |
364 | else | | 367 | else |
365 | mask &= ~bit; | | 368 | mask &= ~bit; |
366 | bus_space_write_1(pic_iot, pic_elcr_ioh, elcr, mask); | | 369 | bus_space_write_1(pic_iot, pic_elcr_ioh, elcr, mask); |
367 | } | | 370 | } |
368 | | | 371 | |
369 | static void | | 372 | static void |
370 | jensenio_pic_init(void) | | 373 | jensenio_pic_init(void) |
371 | { | | 374 | { |
372 | static const int picaddr[2] = { IO_ICU1, IO_ICU2 }; | | 375 | static const int picaddr[2] = { IO_ICU1, IO_ICU2 }; |
373 | int pic; | | 376 | int pic; |
374 | | | 377 | |
375 | /* | | 378 | /* |
376 | * Map the PICs and mask off the interrupts on them. | | 379 | * Map the PICs and mask off the interrupts on them. |
377 | */ | | 380 | */ |
378 | for (pic = 0; pic < 2; pic++) { | | 381 | for (pic = 0; pic < 2; pic++) { |
379 | if (bus_space_map(pic_iot, picaddr[pic], 2, 0, &pic_ioh[pic])) | | 382 | if (bus_space_map(pic_iot, picaddr[pic], 2, 0, &pic_ioh[pic])) |
380 | panic("jensenio_init_intr: unable to map PIC %d", pic); | | 383 | panic("jensenio_init_intr: unable to map PIC %d", pic); |
381 | bus_space_write_1(pic_iot, pic_ioh[pic], 1, 0xff); | | 384 | bus_space_write_1(pic_iot, pic_ioh[pic], PIC_OCW1, 0xff); |
382 | } | | 385 | } |
383 | | | 386 | |
384 | /* | | 387 | /* |
385 | * Map the ELCR registers. | | 388 | * Map the ELCR registers and initialize all interrupts to EDGE |
| | | 389 | * trigger. |
386 | */ | | 390 | */ |
387 | if (bus_space_map(pic_iot, 0x4d0, 2, 0, &pic_elcr_ioh)) | | 391 | if (bus_space_map(pic_iot, 0x4d0, 2, 0, &pic_elcr_ioh)) |
388 | panic("jensenio_init_intr: unable to map ELCR registers"); | | 392 | panic("jensenio_init_intr: unable to map ELCR registers"); |
| | | 393 | bus_space_write_1(pic_iot, pic_elcr_ioh, 0, 0); |
| | | 394 | bus_space_write_1(pic_iot, pic_elcr_ioh, 1, 0); |
389 | } | | 395 | } |