1 /* This file contains routines for initializing the 8259 interrupt controller:
2 * put_irq_handler: register an interrupt handler
3 * rm_irq_handler: deregister an interrupt handler
4 * intr_handle: handle a hardware interrupt
5 * intr_init: initialize the interrupt controller(s)
8 #include "kernel/kernel.h"
9 #include "kernel/proc.h"
11 #include <minix/portio.h>
12 #include <machine/cpu.h>
14 #define ICW1_AT 0x11 /* edge triggered, cascade, need ICW4 */
15 #define ICW1_PC 0x13 /* edge triggered, no cascade, need ICW4 */
16 #define ICW1_PS 0x19 /* level triggered, cascade, need ICW4 */
17 #define ICW4_AT_SLAVE 0x01 /* not SFNM, not buffered, normal EOI, 8086 */
18 #define ICW4_AT_MASTER 0x05 /* not SFNM, not buffered, normal EOI, 8086 */
19 #define ICW4_PC_SLAVE 0x09 /* not SFNM, buffered, normal EOI, 8086 */
20 #define ICW4_PC_MASTER 0x0D /* not SFNM, buffered, normal EOI, 8086 */
21 #define ICW4_AT_AEOI_SLAVE 0x03 /* not SFNM, not buffered, auto EOI, 8086 */
22 #define ICW4_AT_AEOI_MASTER 0x07 /* not SFNM, not buffered, auto EOI, 8086 */
23 #define ICW4_PC_AEOI_SLAVE 0x0B /* not SFNM, buffered, auto EOI, 8086 */
24 #define ICW4_PC_AEOI_MASTER 0x0F /* not SFNM, buffered, auto EOI, 8086 */
26 /*===========================================================================*
28 *===========================================================================*/
29 PUBLIC
int intr_init(const int mine
, const int auto_eoi
)
31 /* Initialize the 8259s, finishing with all interrupts disabled. This is
32 * only done in protected mode, in real mode we don't touch the 8259s, but
33 * use the BIOS locations instead. The flag "mine" is set if the 8259s are
34 * to be programmed for MINIX, or to be reset to what the BIOS expects.
37 /* The AT and newer PS/2 have two interrupt controllers, one master,
38 * one slaved at IRQ 2. (We don't have to deal with the PC that
39 * has just one controller, because it must run in real mode.)
41 outb( INT_CTL
, machine
.ps_mca
? ICW1_PS
: ICW1_AT
);
42 outb( INT_CTLMASK
, mine
== INTS_MINIX
? IRQ0_VECTOR
: BIOS_IRQ0_VEC
);
44 outb( INT_CTLMASK
, (1 << CASCADE_IRQ
));
45 /* ICW3 tells slaves */
47 outb( INT_CTLMASK
, ICW4_AT_AEOI_MASTER
);
49 outb( INT_CTLMASK
, ICW4_AT_MASTER
);
50 outb( INT_CTLMASK
, ~(1 << CASCADE_IRQ
)); /* IRQ 0-7 mask */
51 outb( INT2_CTL
, machine
.ps_mca
? ICW1_PS
: ICW1_AT
);
52 outb( INT2_CTLMASK
, mine
== INTS_MINIX
? IRQ8_VECTOR
: BIOS_IRQ8_VEC
);
54 outb( INT2_CTLMASK
, CASCADE_IRQ
); /* ICW3 is slave nr */
56 outb( INT2_CTLMASK
, ICW4_AT_AEOI_SLAVE
);
58 outb( INT2_CTLMASK
, ICW4_AT_SLAVE
);
59 outb( INT2_CTLMASK
, ~0); /* IRQ 8-15 mask */
61 /* Copy the BIOS vectors from the BIOS to the Minix location, so we
62 * can still make BIOS calls without reprogramming the i8259s.
64 #if IRQ0_VECTOR != BIOS_IRQ0_VEC
65 phys_copy(BIOS_VECTOR(0) * 4L, VECTOR(0) * 4L, 8 * 4L);
67 #if IRQ8_VECTOR != BIOS_IRQ8_VEC
68 phys_copy(BIOS_VECTOR(8) * 4L, VECTOR(8) * 4L, 8 * 4L);
74 PUBLIC
void irq_8259_unmask(const int irq
)
76 const unsigned ctl_mask
= irq
< 8 ? INT_CTLMASK
: INT2_CTLMASK
;
77 outb(ctl_mask
, inb(ctl_mask
) & ~(1 << (irq
& 0x7)));
80 PUBLIC
void irq_8259_mask(const int irq
)
82 const unsigned ctl_mask
= irq
< 8 ? INT_CTLMASK
: INT2_CTLMASK
;
83 outb(ctl_mask
, inb(ctl_mask
) | (1 << (irq
& 0x7)));
86 /* Disable 8259 - write 0xFF in OCW1 master and slave. */
87 PRIVATE
void i8259_disable(void)
89 outb(INT2_CTLMASK
, 0xFF);
90 outb(INT_CTLMASK
, 0xFF);