isabus.c revision 1.26 1 1.26 drochner /* $NetBSD: isabus.c,v 1.26 2004/08/30 15:05:16 drochner Exp $ */
2 1.6 soda /* $OpenBSD: isabus.c,v 1.15 1998/03/16 09:38:46 pefo Exp $ */
3 1.5 soda /* NetBSD: isa.c,v 1.33 1995/06/28 04:30:51 cgd Exp */
4 1.1 jonathan
5 1.1 jonathan /*-
6 1.25 agc * Copyright (c) 1990 The Regents of the University of California.
7 1.25 agc * All rights reserved.
8 1.25 agc *
9 1.25 agc * This code is derived from software contributed to Berkeley by
10 1.25 agc * William Jolitz and Don Ahn.
11 1.25 agc *
12 1.25 agc * Redistribution and use in source and binary forms, with or without
13 1.25 agc * modification, are permitted provided that the following conditions
14 1.25 agc * are met:
15 1.25 agc * 1. Redistributions of source code must retain the above copyright
16 1.25 agc * notice, this list of conditions and the following disclaimer.
17 1.25 agc * 2. Redistributions in binary form must reproduce the above copyright
18 1.25 agc * notice, this list of conditions and the following disclaimer in the
19 1.25 agc * documentation and/or other materials provided with the distribution.
20 1.25 agc * 3. Neither the name of the University nor the names of its contributors
21 1.25 agc * may be used to endorse or promote products derived from this software
22 1.25 agc * without specific prior written permission.
23 1.25 agc *
24 1.25 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.25 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.25 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.25 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.25 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.25 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.25 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.25 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.25 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.25 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.25 agc * SUCH DAMAGE.
35 1.25 agc *
36 1.25 agc * @(#)isa.c 7.2 (Berkeley) 5/12/91
37 1.25 agc */
38 1.25 agc /*-
39 1.1 jonathan * Copyright (c) 1995 Per Fogelstrom
40 1.3 mycroft * Copyright (c) 1993, 1994 Charles M. Hannum.
41 1.1 jonathan *
42 1.1 jonathan * This code is derived from software contributed to Berkeley by
43 1.1 jonathan * William Jolitz and Don Ahn.
44 1.1 jonathan *
45 1.1 jonathan * Redistribution and use in source and binary forms, with or without
46 1.1 jonathan * modification, are permitted provided that the following conditions
47 1.1 jonathan * are met:
48 1.1 jonathan * 1. Redistributions of source code must retain the above copyright
49 1.1 jonathan * notice, this list of conditions and the following disclaimer.
50 1.1 jonathan * 2. Redistributions in binary form must reproduce the above copyright
51 1.1 jonathan * notice, this list of conditions and the following disclaimer in the
52 1.1 jonathan * documentation and/or other materials provided with the distribution.
53 1.1 jonathan * 3. All advertising materials mentioning features or use of this software
54 1.1 jonathan * must display the following acknowledgement:
55 1.1 jonathan * This product includes software developed by the University of
56 1.1 jonathan * California, Berkeley and its contributors.
57 1.1 jonathan * 4. Neither the name of the University nor the names of its contributors
58 1.1 jonathan * may be used to endorse or promote products derived from this software
59 1.1 jonathan * without specific prior written permission.
60 1.1 jonathan *
61 1.1 jonathan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62 1.1 jonathan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 1.1 jonathan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 1.1 jonathan * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65 1.1 jonathan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 1.1 jonathan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67 1.1 jonathan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 1.1 jonathan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 1.1 jonathan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 1.1 jonathan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 1.1 jonathan * SUCH DAMAGE.
72 1.1 jonathan *
73 1.1 jonathan * @(#)isa.c 7.2 (Berkeley) 5/12/91
74 1.1 jonathan */
75 1.1 jonathan /*
76 1.1 jonathan * Mach Operating System
77 1.1 jonathan * Copyright (c) 1991,1990,1989 Carnegie Mellon University
78 1.1 jonathan * All Rights Reserved.
79 1.1 jonathan *
80 1.1 jonathan * Permission to use, copy, modify and distribute this software and its
81 1.1 jonathan * documentation is hereby granted, provided that both the copyright
82 1.1 jonathan * notice and this permission notice appear in all copies of the
83 1.1 jonathan * software, derivative works or modified versions, and any portions
84 1.1 jonathan * thereof, and that both notices appear in supporting documentation.
85 1.1 jonathan *
86 1.1 jonathan * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
87 1.1 jonathan * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
88 1.1 jonathan * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
89 1.1 jonathan *
90 1.1 jonathan * Carnegie Mellon requests users of this software to return to
91 1.1 jonathan *
92 1.1 jonathan * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
93 1.1 jonathan * School of Computer Science
94 1.1 jonathan * Carnegie Mellon University
95 1.1 jonathan * Pittsburgh PA 15213-3890
96 1.1 jonathan *
97 1.1 jonathan * any improvements or extensions that they make and grant Carnegie Mellon
98 1.1 jonathan * the rights to redistribute these changes.
99 1.1 jonathan */
100 1.1 jonathan /*
101 1.1 jonathan Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
102 1.1 jonathan
103 1.1 jonathan All Rights Reserved
104 1.1 jonathan
105 1.1 jonathan Permission to use, copy, modify, and distribute this software and
106 1.1 jonathan its documentation for any purpose and without fee is hereby
107 1.1 jonathan granted, provided that the above copyright notice appears in all
108 1.1 jonathan copies and that both the copyright notice and this permission notice
109 1.1 jonathan appear in supporting documentation, and that the name of Intel
110 1.1 jonathan not be used in advertising or publicity pertaining to distribution
111 1.1 jonathan of the software without specific, written prior permission.
112 1.1 jonathan
113 1.1 jonathan INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
114 1.1 jonathan INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
115 1.1 jonathan IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
116 1.1 jonathan CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
117 1.1 jonathan LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
118 1.1 jonathan NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
119 1.1 jonathan WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
120 1.1 jonathan */
121 1.24 lukem
122 1.24 lukem #include <sys/cdefs.h>
123 1.26 drochner __KERNEL_RCSID(0, "$NetBSD: isabus.c,v 1.26 2004/08/30 15:05:16 drochner Exp $");
124 1.1 jonathan
125 1.1 jonathan #include <sys/param.h>
126 1.5 soda #include <sys/proc.h>
127 1.5 soda #include <sys/user.h>
128 1.1 jonathan #include <sys/systm.h>
129 1.8 thorpej #include <sys/callout.h>
130 1.1 jonathan #include <sys/time.h>
131 1.1 jonathan #include <sys/kernel.h>
132 1.1 jonathan #include <sys/device.h>
133 1.5 soda #include <sys/malloc.h>
134 1.23 tsutsui #include <sys/extent.h>
135 1.13 mrg
136 1.13 mrg #include <uvm/uvm_extern.h>
137 1.1 jonathan
138 1.1 jonathan #include <machine/cpu.h>
139 1.1 jonathan #include <machine/pio.h>
140 1.1 jonathan #include <machine/autoconf.h>
141 1.5 soda #include <machine/intr.h>
142 1.1 jonathan
143 1.15 soda #include <dev/ic/i8253reg.h>
144 1.1 jonathan #include <dev/isa/isareg.h>
145 1.1 jonathan #include <dev/isa/isavar.h>
146 1.15 soda #include <arc/isa/isabrvar.h>
147 1.5 soda #include <arc/isa/spkrreg.h>
148 1.5 soda
149 1.5 soda static int beeping;
150 1.8 thorpej static struct callout sysbeep_ch = CALLOUT_INITIALIZER;
151 1.5 soda
152 1.23 tsutsui static long isa_mem_ex_storage[EXTENT_FIXED_STORAGE_SIZE(16) / sizeof(long)];
153 1.23 tsutsui static long isa_io_ex_storage[EXTENT_FIXED_STORAGE_SIZE(16) / sizeof(long)];
154 1.23 tsutsui
155 1.5 soda #define IRQ_SLAVE 2
156 1.5 soda
157 1.5 soda /* Definition of the driver for autoconfig. */
158 1.5 soda int isabrprint(void *, const char *);
159 1.5 soda
160 1.10 soda extern struct arc_bus_space arc_bus_io, arc_bus_mem;
161 1.10 soda
162 1.11 soda void isabr_attach_hook __P((struct device *, struct device *,
163 1.11 soda struct isabus_attach_args *));
164 1.9 cgd const struct evcnt *isabr_intr_evcnt __P((isa_chipset_tag_t, int));
165 1.5 soda void *isabr_intr_establish __P((isa_chipset_tag_t, int, int, int,
166 1.5 soda int (*)(void *), void *));
167 1.5 soda void isabr_intr_disestablish __P((isa_chipset_tag_t, void*));
168 1.5 soda int isabr_iointr __P((unsigned int, struct clockframe *));
169 1.5 soda void isabr_initicu __P((void));
170 1.5 soda void intr_calculatemasks __P((void));
171 1.5 soda int fakeintr __P((void *a));
172 1.5 soda
173 1.15 soda struct isabr_config *isabr_conf = NULL;
174 1.20 tsutsui u_int32_t imask[_IPL_N]; /* XXX */
175 1.5 soda
176 1.5 soda void
177 1.15 soda isabrattach(sc)
178 1.15 soda struct isabr_softc *sc;
179 1.5 soda {
180 1.5 soda struct isabus_attach_args iba;
181 1.5 soda
182 1.15 soda if (isabr_conf == NULL)
183 1.15 soda panic("isabr_conf isn't initialized");
184 1.15 soda
185 1.5 soda printf("\n");
186 1.5 soda
187 1.5 soda /* Initialize interrupt controller */
188 1.5 soda isabr_initicu();
189 1.5 soda
190 1.5 soda /*XXX we may remove the abus part of the softc struct... */
191 1.5 soda sc->sc_bus.ab_dv = (struct device *)sc;
192 1.5 soda sc->sc_bus.ab_type = BUS_ISABR;
193 1.5 soda
194 1.11 soda sc->arc_isa_cs.ic_attach_hook = isabr_attach_hook;
195 1.9 cgd sc->arc_isa_cs.ic_intr_evcnt = isabr_intr_evcnt;
196 1.5 soda sc->arc_isa_cs.ic_intr_establish = isabr_intr_establish;
197 1.5 soda sc->arc_isa_cs.ic_intr_disestablish = isabr_intr_disestablish;
198 1.23 tsutsui
199 1.23 tsutsui arc_bus_space_init_extent(&arc_bus_mem, (caddr_t)isa_mem_ex_storage,
200 1.23 tsutsui sizeof(isa_mem_ex_storage));
201 1.23 tsutsui arc_bus_space_init_extent(&arc_bus_io, (caddr_t)isa_io_ex_storage,
202 1.23 tsutsui sizeof(isa_io_ex_storage));
203 1.5 soda
204 1.11 soda iba.iba_iot = &arc_bus_io;
205 1.11 soda iba.iba_memt = &arc_bus_mem;
206 1.11 soda iba.iba_dmat = &sc->sc_dmat;
207 1.5 soda iba.iba_ic = &sc->arc_isa_cs;
208 1.26 drochner config_found_ia(&sc->sc_dev, "isabus", &iba, isabrprint);
209 1.5 soda }
210 1.5 soda
211 1.5 soda int
212 1.5 soda isabrprint(aux, pnp)
213 1.5 soda void *aux;
214 1.5 soda const char *pnp;
215 1.5 soda {
216 1.5 soda
217 1.5 soda if (pnp)
218 1.26 drochner aprint_normal("isa at %s", pnp);
219 1.17 thorpej aprint_verbose(" isa_io_base 0x%lx isa_mem_base 0x%lx",
220 1.10 soda arc_bus_io.bs_vbase, arc_bus_mem.bs_vbase);
221 1.5 soda return (UNCONF);
222 1.5 soda }
223 1.5 soda
224 1.5 soda
225 1.5 soda /*
226 1.5 soda * Interrupt system driver code
227 1.5 soda * ============================
228 1.5 soda */
229 1.5 soda #define LEGAL_IRQ(x) ((x) >= 0 && (x) < ICU_LEN && (x) != 2)
230 1.5 soda
231 1.5 soda int imen;
232 1.5 soda int intrtype[ICU_LEN], intrmask[ICU_LEN], intrlevel[ICU_LEN];
233 1.5 soda struct intrhand *intrhand[ICU_LEN];
234 1.5 soda
235 1.5 soda int fakeintr(a)
236 1.5 soda void *a;
237 1.5 soda {
238 1.5 soda return 0;
239 1.5 soda }
240 1.5 soda
241 1.5 soda /*
242 1.5 soda * Recalculate the interrupt masks from scratch.
243 1.5 soda * We could code special registry and deregistry versions of this function that
244 1.5 soda * would be faster, but the code would be nastier, and we don't expect this to
245 1.5 soda * happen very much anyway.
246 1.5 soda */
247 1.5 soda void
248 1.5 soda intr_calculatemasks()
249 1.5 soda {
250 1.5 soda int irq, level;
251 1.5 soda struct intrhand *q;
252 1.5 soda
253 1.5 soda /* First, figure out which levels each IRQ uses. */
254 1.5 soda for (irq = 0; irq < ICU_LEN; irq++) {
255 1.19 tsutsui int levels = 0;
256 1.5 soda for (q = intrhand[irq]; q; q = q->ih_next)
257 1.5 soda levels |= 1 << q->ih_level;
258 1.5 soda intrlevel[irq] = levels;
259 1.5 soda }
260 1.5 soda
261 1.5 soda /* Then figure out which IRQs use each level. */
262 1.20 tsutsui for (level = 0; level < _IPL_N; level++) {
263 1.19 tsutsui int irqs = 0;
264 1.5 soda for (irq = 0; irq < ICU_LEN; irq++)
265 1.5 soda if (intrlevel[irq] & (1 << level))
266 1.5 soda irqs |= 1 << irq;
267 1.20 tsutsui imask[level] = irqs;
268 1.5 soda }
269 1.5 soda
270 1.20 tsutsui imask[IPL_NONE] = 0;
271 1.20 tsutsui
272 1.20 tsutsui imask[IPL_SOFT] |= imask[IPL_NONE];
273 1.20 tsutsui imask[IPL_SOFTCLOCK] |= imask[IPL_SOFT];
274 1.20 tsutsui imask[IPL_SOFTNET] |= imask[IPL_SOFTCLOCK];
275 1.20 tsutsui imask[IPL_SOFTSERIAL] |= imask[IPL_SOFTNET];
276 1.5 soda
277 1.5 soda /*
278 1.5 soda * Enforce a hierarchy that gives slow devices a better chance at not
279 1.5 soda * dropping data.
280 1.5 soda */
281 1.20 tsutsui imask[IPL_BIO] |= imask[IPL_SOFTSERIAL];
282 1.5 soda imask[IPL_NET] |= imask[IPL_BIO];
283 1.20 tsutsui imask[IPL_TTY] |= imask[IPL_NET];
284 1.20 tsutsui
285 1.20 tsutsui /*
286 1.20 tsutsui * Since run queues may be manipulated by both the statclock and tty,
287 1.20 tsutsui * network, and diskdrivers, clock > tty.
288 1.20 tsutsui */
289 1.20 tsutsui imask[IPL_CLOCK] |= imask[IPL_TTY];
290 1.20 tsutsui imask[IPL_STATCLOCK] |= imask[IPL_CLOCK];
291 1.5 soda
292 1.5 soda /*
293 1.20 tsutsui * IPL_HIGH must block everything that can manipulate a run queue.
294 1.5 soda */
295 1.20 tsutsui imask[IPL_HIGH] |= imask[IPL_STATCLOCK];
296 1.5 soda
297 1.5 soda /* And eventually calculate the complete masks. */
298 1.5 soda for (irq = 0; irq < ICU_LEN; irq++) {
299 1.19 tsutsui int irqs = 1 << irq;
300 1.5 soda for (q = intrhand[irq]; q; q = q->ih_next)
301 1.5 soda irqs |= imask[q->ih_level];
302 1.20 tsutsui intrmask[irq] = irqs;
303 1.5 soda }
304 1.5 soda
305 1.5 soda /* Lastly, determine which IRQs are actually in use. */
306 1.5 soda {
307 1.19 tsutsui int irqs = 0;
308 1.5 soda for (irq = 0; irq < ICU_LEN; irq++)
309 1.5 soda if (intrhand[irq])
310 1.5 soda irqs |= 1 << irq;
311 1.5 soda if (irqs >= 0x100) /* any IRQs >= 8 in use */
312 1.5 soda irqs |= 1 << IRQ_SLAVE;
313 1.5 soda imen = ~irqs;
314 1.5 soda isa_outb(IO_ICU1 + 1, imen);
315 1.5 soda isa_outb(IO_ICU2 + 1, imen >> 8);
316 1.5 soda }
317 1.11 soda }
318 1.11 soda
319 1.11 soda void
320 1.11 soda isabr_attach_hook(parent, self, iba)
321 1.11 soda struct device *parent, *self;
322 1.11 soda struct isabus_attach_args *iba;
323 1.11 soda {
324 1.11 soda
325 1.11 soda /* Nothing to do. */
326 1.9 cgd }
327 1.9 cgd
328 1.10 soda const struct evcnt *
329 1.10 soda isabr_intr_evcnt(ic, irq)
330 1.10 soda isa_chipset_tag_t ic;
331 1.10 soda int irq;
332 1.9 cgd {
333 1.9 cgd
334 1.9 cgd /* XXX for now, no evcnt parent reported */
335 1.9 cgd return NULL;
336 1.5 soda }
337 1.5 soda
338 1.5 soda /*
339 1.5 soda * Establish a ISA bus interrupt.
340 1.5 soda */
341 1.18 tsutsui void *
342 1.5 soda isabr_intr_establish(ic, irq, type, level, ih_fun, ih_arg)
343 1.5 soda isa_chipset_tag_t ic;
344 1.5 soda int irq;
345 1.5 soda int type;
346 1.5 soda int level;
347 1.5 soda int (*ih_fun) __P((void *));
348 1.5 soda void *ih_arg;
349 1.5 soda {
350 1.5 soda struct intrhand **p, *q, *ih;
351 1.5 soda static struct intrhand fakehand = {NULL, fakeintr};
352 1.5 soda
353 1.5 soda /* no point in sleeping unless someone can free memory. */
354 1.5 soda ih = malloc(sizeof *ih, M_DEVBUF, cold ? M_NOWAIT : M_WAITOK);
355 1.5 soda if (ih == NULL)
356 1.5 soda panic("isa_intr_establish: can't malloc handler info");
357 1.5 soda
358 1.5 soda if (!LEGAL_IRQ(irq) || type == IST_NONE)
359 1.5 soda panic("intr_establish: bogus irq or type");
360 1.5 soda
361 1.5 soda switch (intrtype[irq]) {
362 1.22 tsutsui case IST_NONE:
363 1.22 tsutsui intrtype[irq] = type;
364 1.22 tsutsui break;
365 1.5 soda case IST_EDGE:
366 1.5 soda case IST_LEVEL:
367 1.5 soda if (type == intrtype[irq])
368 1.5 soda break;
369 1.5 soda case IST_PULSE:
370 1.5 soda if (type != IST_NONE)
371 1.5 soda panic("intr_establish: can't share %s with %s",
372 1.5 soda isa_intr_typename(intrtype[irq]),
373 1.5 soda isa_intr_typename(type));
374 1.5 soda break;
375 1.5 soda }
376 1.5 soda
377 1.5 soda /*
378 1.5 soda * Figure out where to put the handler.
379 1.5 soda * This is O(N^2), but we want to preserve the order, and N is
380 1.5 soda * generally small.
381 1.5 soda */
382 1.5 soda for (p = &intrhand[irq]; (q = *p) != NULL; p = &q->ih_next)
383 1.5 soda ;
384 1.5 soda
385 1.5 soda /*
386 1.5 soda * Actually install a fake handler momentarily, since we might be doing
387 1.5 soda * this with interrupts enabled and don't want the real routine called
388 1.5 soda * until masking is set up.
389 1.5 soda */
390 1.5 soda fakehand.ih_level = level;
391 1.5 soda *p = &fakehand;
392 1.5 soda
393 1.5 soda intr_calculatemasks();
394 1.5 soda
395 1.5 soda /*
396 1.5 soda * Poke the real handler in now.
397 1.5 soda */
398 1.5 soda ih->ih_fun = ih_fun;
399 1.5 soda ih->ih_arg = ih_arg;
400 1.5 soda ih->ih_count = 0;
401 1.5 soda ih->ih_next = NULL;
402 1.5 soda ih->ih_level = level;
403 1.5 soda ih->ih_irq = irq;
404 1.5 soda ih->ih_what = ""; /* XXX - should be eliminated */
405 1.5 soda *p = ih;
406 1.5 soda
407 1.5 soda return (ih);
408 1.5 soda }
409 1.5 soda
410 1.18 tsutsui void
411 1.5 soda isabr_intr_disestablish(ic, arg)
412 1.5 soda isa_chipset_tag_t ic;
413 1.18 tsutsui void *arg;
414 1.18 tsutsui {
415 1.5 soda
416 1.5 soda }
417 1.5 soda
418 1.5 soda /*
419 1.5 soda * Process an interrupt from the ISA bus.
420 1.5 soda */
421 1.5 soda int
422 1.5 soda isabr_iointr(mask, cf)
423 1.5 soda unsigned mask;
424 1.5 soda struct clockframe *cf;
425 1.5 soda {
426 1.5 soda struct intrhand *ih;
427 1.5 soda int isa_vector;
428 1.5 soda int o_imen;
429 1.7 soda
430 1.15 soda isa_vector = (*isabr_conf->ic_intr_status)();
431 1.15 soda if (isa_vector < 0)
432 1.15 soda return (~0);
433 1.5 soda
434 1.5 soda o_imen = imen;
435 1.5 soda imen |= 1 << (isa_vector & (ICU_LEN - 1));
436 1.5 soda if(isa_vector & 0x08) {
437 1.5 soda isa_inb(IO_ICU2 + 1);
438 1.5 soda isa_outb(IO_ICU2 + 1, imen >> 8);
439 1.5 soda isa_outb(IO_ICU2, 0x60 + (isa_vector & 7));
440 1.5 soda isa_outb(IO_ICU1, 0x60 + IRQ_SLAVE);
441 1.5 soda }
442 1.5 soda else {
443 1.5 soda isa_inb(IO_ICU1 + 1);
444 1.5 soda isa_outb(IO_ICU1 + 1, imen);
445 1.5 soda isa_outb(IO_ICU1, 0x60 + isa_vector);
446 1.5 soda }
447 1.5 soda ih = intrhand[isa_vector];
448 1.5 soda if(isa_vector == 0) { /* Clock */ /*XXX*/
449 1.5 soda (*ih->ih_fun)(cf);
450 1.5 soda ih = ih->ih_next;
451 1.5 soda }
452 1.5 soda while(ih) {
453 1.5 soda (*ih->ih_fun)(ih->ih_arg);
454 1.5 soda ih = ih->ih_next;
455 1.5 soda }
456 1.5 soda imen = o_imen;
457 1.5 soda isa_inb(IO_ICU1 + 1);
458 1.5 soda isa_inb(IO_ICU2 + 1);
459 1.5 soda isa_outb(IO_ICU1 + 1, imen);
460 1.5 soda isa_outb(IO_ICU2 + 1, imen >> 8);
461 1.5 soda
462 1.5 soda return(~0); /* Dont reenable */
463 1.5 soda }
464 1.5 soda
465 1.5 soda
466 1.18 tsutsui /*
467 1.5 soda * Initialize the Interrupt controller logic.
468 1.5 soda */
469 1.5 soda void
470 1.5 soda isabr_initicu()
471 1.18 tsutsui {
472 1.22 tsutsui
473 1.22 tsutsui int i;
474 1.22 tsutsui
475 1.22 tsutsui for (i = 0; i < ICU_LEN; i++) {
476 1.22 tsutsui switch (i) {
477 1.22 tsutsui case 2:
478 1.22 tsutsui case 8:
479 1.22 tsutsui intrtype[i] = IST_EDGE;
480 1.22 tsutsui break;
481 1.22 tsutsui default:
482 1.22 tsutsui intrtype[i] = IST_NONE;
483 1.22 tsutsui break;
484 1.22 tsutsui }
485 1.22 tsutsui }
486 1.5 soda
487 1.5 soda isa_outb(IO_ICU1, 0x11); /* reset; program device, four bytes */
488 1.5 soda isa_outb(IO_ICU1+1, 0); /* starting at this vector index */
489 1.5 soda isa_outb(IO_ICU1+1, 1 << IRQ_SLAVE); /* slave on line 2 */
490 1.5 soda isa_outb(IO_ICU1+1, 1); /* 8086 mode */
491 1.5 soda isa_outb(IO_ICU1+1, 0xff); /* leave interrupts masked */
492 1.5 soda isa_outb(IO_ICU1, 0x68); /* special mask mode (if available) */
493 1.5 soda isa_outb(IO_ICU1, 0x0a); /* Read IRR by default. */
494 1.18 tsutsui #ifdef REORDER_IRQ
495 1.5 soda isa_outb(IO_ICU1, 0xc0 | (3 - 1)); /* pri order 3-7, 0-2 (com2 first) */
496 1.2 jonathan #endif
497 1.1 jonathan
498 1.5 soda isa_outb(IO_ICU2, 0x11); /* reset; program device, four bytes */
499 1.5 soda isa_outb(IO_ICU2+1, 8); /* staring at this vector index */
500 1.5 soda isa_outb(IO_ICU2+1, IRQ_SLAVE);
501 1.5 soda isa_outb(IO_ICU2+1, 1); /* 8086 mode */
502 1.5 soda isa_outb(IO_ICU2+1, 0xff); /* leave interrupts masked */
503 1.5 soda isa_outb(IO_ICU2, 0x68); /* special mask mode (if available) */
504 1.5 soda isa_outb(IO_ICU2, 0x0a); /* Read IRR by default. */
505 1.18 tsutsui }
506 1.1 jonathan
507 1.1 jonathan
508 1.5 soda /*
509 1.5 soda * SPEAKER BEEPER...
510 1.5 soda */
511 1.1 jonathan void
512 1.1 jonathan sysbeepstop(arg)
513 1.1 jonathan void *arg;
514 1.1 jonathan {
515 1.1 jonathan int s;
516 1.1 jonathan
517 1.1 jonathan /* disable counter 2 */
518 1.1 jonathan s = splhigh();
519 1.1 jonathan isa_outb(PITAUX_PORT, isa_inb(PITAUX_PORT) & ~PIT_SPKR);
520 1.1 jonathan splx(s);
521 1.1 jonathan beeping = 0;
522 1.1 jonathan }
523 1.1 jonathan
524 1.1 jonathan void
525 1.1 jonathan sysbeep(pitch, period)
526 1.1 jonathan int pitch, period;
527 1.1 jonathan {
528 1.1 jonathan static int last_pitch, last_period;
529 1.1 jonathan int s;
530 1.5 soda
531 1.5 soda if (cold)
532 1.5 soda return; /* Can't beep yet. */
533 1.1 jonathan
534 1.1 jonathan if (beeping)
535 1.8 thorpej callout_stop(&sysbeep_ch);
536 1.1 jonathan if (!beeping || last_pitch != pitch) {
537 1.1 jonathan s = splhigh();
538 1.5 soda isa_outb(IO_TIMER1 + TIMER_MODE,
539 1.5 soda TIMER_SEL2 | TIMER_16BIT | TIMER_SQWAVE);
540 1.5 soda isa_outb(IO_TIMER1 + TIMER_CNTR2, TIMER_DIV(pitch) % 256);
541 1.5 soda isa_outb(IO_TIMER1 + TIMER_CNTR2, TIMER_DIV(pitch) / 256);
542 1.1 jonathan isa_outb(PITAUX_PORT, isa_inb(PITAUX_PORT) | PIT_SPKR);
543 1.1 jonathan splx(s);
544 1.1 jonathan }
545 1.1 jonathan last_pitch = pitch;
546 1.1 jonathan beeping = last_period = period;
547 1.8 thorpej callout_reset(&sysbeep_ch, period, sysbeepstop, NULL);
548 1.21 tsutsui }
549 1.21 tsutsui
550 1.21 tsutsui int
551 1.21 tsutsui isa_intr_alloc(isa_chipset_tag_t c, int mask, int type, int *irq_p)
552 1.21 tsutsui {
553 1.21 tsutsui int irq;
554 1.21 tsutsui int maybe_irq = -1;
555 1.21 tsutsui int shared_depth = 0;
556 1.21 tsutsui mask &= 0x8b28; /* choose from 3, 5, 8, 9, 11, 15 XXX */
557 1.21 tsutsui for (irq = 0; mask != 0; mask >>= 1, irq++) {
558 1.21 tsutsui if ((mask & 1) == 0)
559 1.21 tsutsui continue;
560 1.21 tsutsui if (intrtype[irq] == IST_NONE) {
561 1.21 tsutsui *irq_p = irq;
562 1.21 tsutsui return 0;
563 1.21 tsutsui }
564 1.21 tsutsui /* Level interrupts can be shared */
565 1.21 tsutsui if (type == IST_LEVEL && intrtype[irq] == IST_LEVEL) {
566 1.21 tsutsui struct intrhand *ih = intrhand[irq];
567 1.21 tsutsui int depth;
568 1.21 tsutsui if (maybe_irq == -1) {
569 1.21 tsutsui maybe_irq = irq;
570 1.21 tsutsui continue;
571 1.21 tsutsui }
572 1.21 tsutsui for (depth = 0; ih != NULL; ih = ih->ih_next)
573 1.21 tsutsui depth++;
574 1.21 tsutsui if (depth < shared_depth) {
575 1.21 tsutsui maybe_irq = irq;
576 1.21 tsutsui shared_depth = depth;
577 1.21 tsutsui }
578 1.21 tsutsui }
579 1.21 tsutsui }
580 1.21 tsutsui if (maybe_irq != -1) {
581 1.21 tsutsui *irq_p = maybe_irq;
582 1.21 tsutsui return 0;
583 1.21 tsutsui }
584 1.21 tsutsui return 1;
585 1.1 jonathan }
586