Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / powerpc / pic / i8259_common.c
blob649dfce62b203f2cf0816ded5853de879944e76e
1 /* $NetBSD: i8259_common.c,v 1.3 2007/12/11 18:04:19 garbled Exp $ */
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour
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>
33 __KERNEL_RCSID(0, "$NetBSD: i8259_common.c,v 1.3 2007/12/11 18:04:19 garbled Exp $");
35 #include <sys/param.h>
36 #include <sys/malloc.h>
37 #include <sys/kernel.h>
39 #include <uvm/uvm_extern.h>
41 #include <machine/pio.h>
42 #include <machine/intr.h>
44 #include <arch/powerpc/pic/picvar.h>
46 #include <dev/isa/isareg.h>
47 #include <dev/isa/isavar.h>
49 void
50 i8259_initialize(void)
52 isa_outb(IO_ICU1, 0x11); /* program device, four bytes */
53 isa_outb(IO_ICU1+1, 0); /* starting at this vector */
54 isa_outb(IO_ICU1+1, 1 << IRQ_SLAVE); /* slave on line 2 */
55 isa_outb(IO_ICU1+1, 1); /* 8086 mode */
56 isa_outb(IO_ICU1+1, 0xff); /* leave interrupts masked */
58 isa_outb(IO_ICU2, 0x11); /* program device, four bytes */
59 isa_outb(IO_ICU2+1, 8); /* starting at this vector */
60 isa_outb(IO_ICU2+1, IRQ_SLAVE);
61 isa_outb(IO_ICU2+1, 1); /* 8086 mode */
62 isa_outb(IO_ICU2+1, 0xff); /* leave interrupts masked */
65 void
66 i8259_enable_irq(struct pic_ops *pic, int irq, int type)
68 struct i8259_ops *i8259 = (struct i8259_ops *)pic;
70 i8259->irqs |= 1 << irq;
71 if (i8259->irqs >= 0x100) /* IRQS >= 8 in use? */
72 i8259->irqs |= 1 << IRQ_SLAVE;
74 i8259->enable_mask = ~i8259->irqs;
75 isa_outb(IO_ICU1+1, i8259->enable_mask);
76 isa_outb(IO_ICU2+1, i8259->enable_mask >> 8);
79 void
80 i8259_disable_irq(struct pic_ops *pic, int irq)
82 struct i8259_ops *i8259 = (struct i8259_ops *)pic;
83 uint32_t mask = 1 << irq;
85 i8259->enable_mask |= mask;
86 isa_outb(IO_ICU1+1, i8259->enable_mask);
87 isa_outb(IO_ICU2+1, i8259->enable_mask >> 8);
90 void
91 i8259_ack_irq(struct pic_ops *pic, int irq)
93 if (irq < 8) {
94 isa_outb(IO_ICU1, 0xe0 | irq);
95 } else {
96 isa_outb(IO_ICU2, 0xe0 | (irq & 7));
97 isa_outb(IO_ICU1, 0xe0 | IRQ_SLAVE);
102 i8259_get_irq(struct pic_ops *pic, int mode)
104 int irq;
106 isa_outb(IO_ICU1, 0x0c);
107 irq = isa_inb(IO_ICU1) & 0x07;
108 if (irq == IRQ_SLAVE) {
109 isa_outb(IO_ICU2, 0x0c);
110 irq = (isa_inb(IO_ICU2) & 0x07) + 8;
113 if (irq == 0 && mode == PIC_GET_IRQ)
114 return 255;
115 if (irq == 7 && mode == PIC_GET_RECHECK)
116 return 255;
118 return irq;