Annotation of sys/arch/amd64/amd64/i8259.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: i8259.c,v 1.5 2007/05/03 18:51:08 grange Exp $ */
2: /* $NetBSD: i8259.c,v 1.2 2003/03/02 18:27:15 fvdl Exp $ */
3:
4: /*
5: * Copyright 2002 (c) Wasabi Systems, Inc.
6: * All rights reserved.
7: *
8: * Written by Frank van der Linden for Wasabi Systems, Inc.
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 for the NetBSD Project by
21: * Wasabi Systems, Inc.
22: * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23: * or promote products derived from this software without specific prior
24: * written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27: * 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 WASABI SYSTEMS, INC
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: /*-
40: * Copyright (c) 1991 The Regents of the University of California.
41: * All rights reserved.
42: *
43: * This code is derived from software contributed to Berkeley by
44: * William Jolitz.
45: *
46: * Redistribution and use in source and binary forms, with or without
47: * modification, are permitted provided that the following conditions
48: * are met:
49: * 1. Redistributions of source code must retain the above copyright
50: * notice, this list of conditions and the following disclaimer.
51: * 2. Redistributions in binary form must reproduce the above copyright
52: * notice, this list of conditions and the following disclaimer in the
53: * documentation and/or other materials provided with the distribution.
54: * 3. Neither the name of the University nor the names of its contributors
55: * may be used to endorse or promote products derived from this software
56: * without specific prior written permission.
57: *
58: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68: * SUCH DAMAGE.
69: *
70: * @(#)isa.c 7.2 (Berkeley) 5/13/91
71: */
72:
73: #include <sys/param.h>
74: #include <sys/systm.h>
75: #include <sys/kernel.h>
76: #include <sys/syslog.h>
77: #include <sys/device.h>
78: #include <sys/malloc.h>
79: #include <sys/proc.h>
80:
81: #include <dev/isa/isareg.h>
82:
83: #include <machine/pio.h>
84: #include <machine/cpufunc.h>
85: #include <machine/cpu.h>
86: #include <machine/pic.h>
87: #include <machine/i8259.h>
88:
89: static void i8259_hwmask(struct pic *, int);
90: static void i8259_hwunmask(struct pic *, int);
91: static void i8259_setup(struct pic *, struct cpu_info *, int, int, int);
92: static void i8259_reinit_irqs(void);
93:
94: unsigned i8259_imen;
95:
96: /*
97: * Perhaps this should be made into a real device.
98: */
99: struct pic i8259_pic = {
100: {0, {NULL}, NULL, 0, "pic0", NULL, 0, 0},
101: PIC_I8259,
102: #ifdef MULTIPROCESSOR
103: {},
104: #endif
105: i8259_hwmask,
106: i8259_hwunmask,
107: i8259_setup,
108: i8259_setup,
109: i8259_stubs,
110: i8259_stubs,
111: };
112:
113: void
114: i8259_default_setup(void)
115: {
116: outb(IO_ICU1, 0x11); /* reset; program device, four bytes */
117:
118: outb(IO_ICU1+1, ICU_OFFSET); /* starting at this vector index */
119: outb(IO_ICU1+1, 1 << IRQ_SLAVE); /* slave on line 2 */
120: #ifdef AUTO_EOI_1
121: outb(IO_ICU1+1, 2 | 1); /* auto EOI, 8086 mode */
122: #else
123: outb(IO_ICU1+1, 1); /* 8086 mode */
124: #endif
125: outb(IO_ICU1+1, 0xff); /* leave interrupts masked */
126: outb(IO_ICU1, 0x68); /* special mask mode (if available) */
127: outb(IO_ICU1, 0x0a); /* Read IRR by default. */
128: #ifdef REORDER_IRQ
129: outb(IO_ICU1, 0xc0 | (3 - 1)); /* pri order 3-7, 0-2 (com2 first) */
130: #endif
131:
132: outb(IO_ICU2, 0x11); /* reset; program device, four bytes */
133:
134: outb(IO_ICU2+1, ICU_OFFSET+8); /* staring at this vector index */
135: outb(IO_ICU2+1, IRQ_SLAVE);
136: #ifdef AUTO_EOI_2
137: outb(IO_ICU2+1, 2 | 1); /* auto EOI, 8086 mode */
138: #else
139: outb(IO_ICU2+1, 1); /* 8086 mode */
140: #endif
141: outb(IO_ICU2+1, 0xff); /* leave interrupts masked */
142: outb(IO_ICU2, 0x68); /* special mask mode (if available) */
143: outb(IO_ICU2, 0x0a); /* Read IRR by default. */
144: }
145:
146: static void
147: i8259_hwmask(struct pic *pic, int pin)
148: {
149: unsigned port;
150: u_int8_t byte;
151:
152: i8259_imen |= (1 << pin);
153: #ifdef PIC_MASKDELAY
154: delay(10);
155: #endif
156: if (pin > 7) {
157: port = IO_ICU2 + 1;
158: byte = i8259_imen >> 8;
159: } else {
160: port = IO_ICU1 + 1;
161: byte = i8259_imen & 0xff;
162: }
163: outb(port, byte);
164: }
165:
166: static void
167: i8259_hwunmask(struct pic *pic, int pin)
168: {
169: unsigned port;
170: u_int8_t byte;
171:
172: disable_intr(); /* XXX */
173: i8259_imen &= ~(1 << pin);
174: #ifdef PIC_MASKDELAY
175: delay(10);
176: #endif
177: if (pin > 7) {
178: port = IO_ICU2 + 1;
179: byte = i8259_imen >> 8;
180: } else {
181: port = IO_ICU1 + 1;
182: byte = i8259_imen & 0xff;
183: }
184: outb(port, byte);
185: enable_intr();
186: }
187:
188: static void
189: i8259_reinit_irqs(void)
190: {
191: int irqs, irq;
192: struct cpu_info *ci = &cpu_info_primary;
193:
194: irqs = 0;
195: for (irq = 0; irq < NUM_LEGACY_IRQS; irq++)
196: if (ci->ci_isources[irq] != NULL)
197: irqs |= 1 << irq;
198: if (irqs >= 0x100) /* any IRQs >= 8 in use */
199: irqs |= 1 << IRQ_SLAVE;
200: i8259_imen = ~irqs;
201:
202: outb(IO_ICU1 + 1, i8259_imen);
203: outb(IO_ICU2 + 1, i8259_imen >> 8);
204: }
205:
206: static void
207: i8259_setup(struct pic *pic, struct cpu_info *ci, int pin, int idtvec, int type)
208: {
209: if (CPU_IS_PRIMARY(ci))
210: i8259_reinit_irqs();
211: }
212:
213: void
214: i8259_reinit(void)
215: {
216: i8259_default_setup();
217: i8259_reinit_irqs();
218: }
219:
220: unsigned
221: i8259_setmask(unsigned mask)
222: {
223: unsigned old = i8259_imen;
224:
225: i8259_imen = mask;
226: outb(IO_ICU1 + 1, i8259_imen);
227: outb(IO_ICU2 + 1, i8259_imen >> 8);
228: return old;
229: }
CVSweb