i8259_common.c revision 1.2.12.1 1 /* $NetBSD: i8259_common.c,v 1.2.12.1 2007/12/13 05:05:21 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour
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 by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND 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 THE FOUNDATION OR CONTRIBUTORS
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 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: i8259_common.c,v 1.2.12.1 2007/12/13 05:05:21 yamt Exp $");
41
42 #include <sys/param.h>
43 #include <sys/malloc.h>
44 #include <sys/kernel.h>
45
46 #include <uvm/uvm_extern.h>
47
48 #include <machine/pio.h>
49 #include <machine/intr.h>
50
51 #include <arch/powerpc/pic/picvar.h>
52
53 #include <dev/isa/isareg.h>
54 #include <dev/isa/isavar.h>
55
56 void
57 i8259_initialize(void)
58 {
59 isa_outb(IO_ICU1, 0x11); /* program device, four bytes */
60 isa_outb(IO_ICU1+1, 0); /* starting at this vector */
61 isa_outb(IO_ICU1+1, 1 << IRQ_SLAVE); /* slave on line 2 */
62 isa_outb(IO_ICU1+1, 1); /* 8086 mode */
63 isa_outb(IO_ICU1+1, 0xff); /* leave interrupts masked */
64
65 isa_outb(IO_ICU2, 0x11); /* program device, four bytes */
66 isa_outb(IO_ICU2+1, 8); /* starting at this vector */
67 isa_outb(IO_ICU2+1, IRQ_SLAVE);
68 isa_outb(IO_ICU2+1, 1); /* 8086 mode */
69 isa_outb(IO_ICU2+1, 0xff); /* leave interrupts masked */
70 }
71
72 void
73 i8259_enable_irq(struct pic_ops *pic, int irq, int type)
74 {
75 struct i8259_ops *i8259 = (struct i8259_ops *)pic;
76
77 i8259->irqs |= 1 << irq;
78 if (i8259->irqs >= 0x100) /* IRQS >= 8 in use? */
79 i8259->irqs |= 1 << IRQ_SLAVE;
80
81 i8259->enable_mask = ~i8259->irqs;
82 isa_outb(IO_ICU1+1, i8259->enable_mask);
83 isa_outb(IO_ICU2+1, i8259->enable_mask >> 8);
84 }
85
86 void
87 i8259_disable_irq(struct pic_ops *pic, int irq)
88 {
89 struct i8259_ops *i8259 = (struct i8259_ops *)pic;
90 uint32_t mask = 1 << irq;
91
92 i8259->enable_mask |= mask;
93 isa_outb(IO_ICU1+1, i8259->enable_mask);
94 isa_outb(IO_ICU2+1, i8259->enable_mask >> 8);
95 }
96
97 void
98 i8259_ack_irq(struct pic_ops *pic, int irq)
99 {
100 if (irq < 8) {
101 isa_outb(IO_ICU1, 0xe0 | irq);
102 } else {
103 isa_outb(IO_ICU2, 0xe0 | (irq & 7));
104 isa_outb(IO_ICU1, 0xe0 | IRQ_SLAVE);
105 }
106 }
107
108 int
109 i8259_get_irq(struct pic_ops *pic, int mode)
110 {
111 int irq;
112
113 isa_outb(IO_ICU1, 0x0c);
114 irq = isa_inb(IO_ICU1) & 0x07;
115 if (irq == IRQ_SLAVE) {
116 isa_outb(IO_ICU2, 0x0c);
117 irq = (isa_inb(IO_ICU2) & 0x07) + 8;
118 }
119
120 if (irq == 0 && mode == PIC_GET_IRQ)
121 return 255;
122 if (irq == 7 && mode == PIC_GET_RECHECK)
123 return 255;
124
125 return irq;
126 }
127