1 /* $NetBSD: pic_prepivr.c,v 1.3 2007/12/11 18:04:20 garbled Exp $ */
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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: pic_prepivr.c,v 1.3 2007/12/11 18:04:20 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 static int prepivr_get_irq(struct pic_ops
*, int);
50 static int motivr_get_irq(struct pic_ops
*, int);
51 static void prepivr_establish_irq(struct pic_ops
*, int, int, int);
53 vaddr_t prep_intr_reg
; /* PReP interrupt vector register */
54 uint32_t prep_intr_reg_off
; /* IVR offset within the mapped page */
56 #define IO_ELCR1 0x4d0
57 #define IO_ELCR2 0x4d1
60 * Prior to calling init_prepivr, the port is expected to have mapped the
61 * page containing the IVR with mapiodev to prep_intr_reg and set up the
66 setup_prepivr(int ivrtype
)
68 struct i8259_ops
*prepivr
;
72 prepivr
= malloc(sizeof(struct i8259_ops
), M_DEVBUF
, M_NOWAIT
);
73 KASSERT(prepivr
!= NULL
);
76 pivr
= prep_intr_reg
+ prep_intr_reg_off
;
77 pic
->pic_numintrs
= 16;
78 pic
->pic_cookie
= (void *)pivr
;
79 pic
->pic_enable_irq
= i8259_enable_irq
;
80 pic
->pic_reenable_irq
= i8259_enable_irq
;
81 pic
->pic_disable_irq
= i8259_disable_irq
;
82 if (ivrtype
== PIC_IVR_MOT
)
83 pic
->pic_get_irq
= motivr_get_irq
;
85 pic
->pic_get_irq
= prepivr_get_irq
;
86 pic
->pic_ack_irq
= i8259_ack_irq
;
87 pic
->pic_establish_irq
= prepivr_establish_irq
;
88 pic
->pic_finish_setup
= NULL
;
89 strcpy(pic
->pic_name
, "prepivr");
91 prepivr
->pending_events
= 0;
92 prepivr
->enable_mask
= 0xffffffff;
95 /* initialize the ELCR */
96 isa_outb(IO_ELCR1
, (0 >> 0) & 0xff);
97 isa_outb(IO_ELCR2
, (0 >> 8) & 0xff);
104 prepivr_establish_irq(struct pic_ops
*pic
, int irq
, int type
, int maxlevel
)
111 elcr
[0] = isa_inb(IO_ELCR1
);
112 elcr
[1] = isa_inb(IO_ELCR2
);
114 if (type
== IST_LEVEL
)
115 elcr
[icu
] |= 1 << bit
;
117 elcr
[icu
] &= ~(1 << bit
);
119 isa_outb(IO_ELCR1
, elcr
[0]);
120 isa_outb(IO_ELCR2
, elcr
[1]);
124 motivr_get_irq(struct pic_ops
*pic
, int mode
)
128 irq
= i8259_get_irq(pic
, mode
);
129 /* read the IVR to ack it */
130 (void)inb(pic
->pic_cookie
);
132 /* i8259_get_irq will return 255 by itself, so just pass it on */
137 prepivr_get_irq(struct pic_ops
*pic
, int mode
)
141 irq
= inb(pic
->pic_cookie
);
143 if (irq
== 0 && mode
== PIC_GET_IRQ
)
145 if (irq
== 7 && mode
== PIC_GET_RECHECK
)