iPXE
pic8259.h
Go to the documentation of this file.
00001 /*
00002  * Basic support for controlling the 8259 Programmable Interrupt Controllers.
00003  *
00004  * Initially written by Michael Brown (mcb30).
00005  */
00006 
00007 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00008 
00009 #ifndef PIC8259_H
00010 #define PIC8259_H
00011 
00012 #include <ipxe/io.h>
00013 
00014 #define IRQ_PIC_CUTOFF 8
00015 
00016 /* 8259 register locations */
00017 #define PIC1_ICW1 0x20
00018 #define PIC1_OCW2 0x20
00019 #define PIC1_OCW3 0x20
00020 #define PIC1_ICR 0x20
00021 #define PIC1_IRR 0x20
00022 #define PIC1_ISR 0x20
00023 #define PIC1_ICW2 0x21
00024 #define PIC1_ICW3 0x21
00025 #define PIC1_ICW4 0x21
00026 #define PIC1_IMR 0x21
00027 #define PIC2_ICW1 0xa0
00028 #define PIC2_OCW2 0xa0
00029 #define PIC2_OCW3 0xa0
00030 #define PIC2_ICR 0xa0
00031 #define PIC2_IRR 0xa0
00032 #define PIC2_ISR 0xa0
00033 #define PIC2_ICW2 0xa1
00034 #define PIC2_ICW3 0xa1
00035 #define PIC2_ICW4 0xa1
00036 #define PIC2_IMR 0xa1
00037 
00038 /* Register command values */
00039 #define OCW3_ID 0x08
00040 #define OCW3_READ_IRR 0x02
00041 #define OCW3_READ_ISR 0x03
00042 #define ICR_EOI_NON_SPECIFIC 0x20
00043 #define ICR_EOI_NOP 0x40
00044 #define ICR_EOI_SPECIFIC 0x60
00045 #define ICR_EOI_SET_PRIORITY 0xc0
00046 
00047 /* Macros to enable/disable IRQs */
00048 #define IMR_REG(x) ( (x) < IRQ_PIC_CUTOFF ? PIC1_IMR : PIC2_IMR )
00049 #define IMR_BIT(x) ( 1 << ( (x) % IRQ_PIC_CUTOFF ) )
00050 #define irq_enabled(x) ( ( inb ( IMR_REG(x) ) & IMR_BIT(x) ) == 0 )
00051 #define enable_irq(x) outb ( inb( IMR_REG(x) ) & ~IMR_BIT(x), IMR_REG(x) )
00052 #define disable_irq(x) outb ( inb( IMR_REG(x) ) | IMR_BIT(x), IMR_REG(x) )
00053 
00054 /* Macros for acknowledging IRQs */
00055 #define ICR_REG( irq ) ( (irq) < IRQ_PIC_CUTOFF ? PIC1_ICR : PIC2_ICR )
00056 #define ICR_VALUE( irq ) ( (irq) % IRQ_PIC_CUTOFF )
00057 #define CHAINED_IRQ 2
00058 
00059 /* Utility macros to convert IRQ numbers to INT numbers and INT vectors  */
00060 #define IRQ_INT( irq ) ( ( ( (irq) - IRQ_PIC_CUTOFF ) ^ 0x70 ) & 0x7f )
00061 
00062 /* Other constants */
00063 #define IRQ_MAX 15
00064 #define IRQ_NONE -1U
00065 
00066 /* Function prototypes
00067  */
00068 void send_eoi ( unsigned int irq );
00069 
00070 #endif /* PIC8259_H */