Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / i386 / include / pic8259.h
1 /*
2  * Basic support for controlling the 8259 Programmable Interrupt Controllers.
3  *
4  * Initially written by Michael Brown (mcb30).
5  */
6
7 FILE_LICENCE ( GPL2_OR_LATER );
8
9 #ifndef PIC8259_H
10 #define PIC8259_H
11
12 #include <ipxe/io.h>
13
14 /* For segoff_t */
15 #include "realmode.h"
16
17 #define IRQ_PIC_CUTOFF 8
18
19 /* 8259 register locations */
20 #define PIC1_ICW1 0x20
21 #define PIC1_OCW2 0x20
22 #define PIC1_OCW3 0x20
23 #define PIC1_ICR 0x20
24 #define PIC1_IRR 0x20
25 #define PIC1_ISR 0x20
26 #define PIC1_ICW2 0x21
27 #define PIC1_ICW3 0x21
28 #define PIC1_ICW4 0x21
29 #define PIC1_IMR 0x21
30 #define PIC2_ICW1 0xa0
31 #define PIC2_OCW2 0xa0
32 #define PIC2_OCW3 0xa0
33 #define PIC2_ICR 0xa0
34 #define PIC2_IRR 0xa0
35 #define PIC2_ISR 0xa0
36 #define PIC2_ICW2 0xa1
37 #define PIC2_ICW3 0xa1
38 #define PIC2_ICW4 0xa1
39 #define PIC2_IMR 0xa1
40
41 /* Register command values */
42 #define OCW3_ID 0x08
43 #define OCW3_READ_IRR 0x03
44 #define OCW3_READ_ISR 0x02
45 #define ICR_EOI_NON_SPECIFIC 0x20
46 #define ICR_EOI_NOP 0x40
47 #define ICR_EOI_SPECIFIC 0x60
48 #define ICR_EOI_SET_PRIORITY 0xc0
49
50 /* Macros to enable/disable IRQs */
51 #define IMR_REG(x) ( (x) < IRQ_PIC_CUTOFF ? PIC1_IMR : PIC2_IMR )
52 #define IMR_BIT(x) ( 1 << ( (x) % IRQ_PIC_CUTOFF ) )
53 #define irq_enabled(x) ( ( inb ( IMR_REG(x) ) & IMR_BIT(x) ) == 0 )
54 #define enable_irq(x) outb ( inb( IMR_REG(x) ) & ~IMR_BIT(x), IMR_REG(x) )
55 #define disable_irq(x) outb ( inb( IMR_REG(x) ) | IMR_BIT(x), IMR_REG(x) )
56
57 /* Macros for acknowledging IRQs */
58 #define ICR_REG( irq ) ( (irq) < IRQ_PIC_CUTOFF ? PIC1_ICR : PIC2_ICR )
59 #define ICR_VALUE( irq ) ( (irq) % IRQ_PIC_CUTOFF )
60 #define CHAINED_IRQ 2
61
62 /* Utility macros to convert IRQ numbers to INT numbers and INT vectors  */
63 #define IRQ_INT( irq ) ( ( ( (irq) - IRQ_PIC_CUTOFF ) ^ 0x70 ) & 0x7f )
64
65 /* Other constants */
66 #define IRQ_MAX 15
67 #define IRQ_NONE -1U
68
69 /* Function prototypes
70  */
71 void send_eoi ( unsigned int irq );
72
73 #endif /* PIC8259_H */