1N/A/*
1N/A * Basic support for controlling the 8259 Programmable Interrupt Controllers.
1N/A *
1N/A * Initially written by Michael Brown (mcb30).
1N/A */
1N/A
1N/A#ifndef PIC8259_H
1N/A#define PIC8259_H
1N/A
1N/A/* For segoff_t */
1N/A#include <segoff.h>
1N/A
1N/A#define IRQ_PIC_CUTOFF (8)
1N/A
1N/A/* 8259 register locations */
1N/A#define PIC1_ICW1 (0x20)
1N/A#define PIC1_OCW2 (0x20)
1N/A#define PIC1_OCW3 (0x20)
1N/A#define PIC1_ICR (0x20)
1N/A#define PIC1_IRR (0x20)
1N/A#define PIC1_ISR (0x20)
1N/A#define PIC1_ICW2 (0x21)
1N/A#define PIC1_ICW3 (0x21)
1N/A#define PIC1_ICW4 (0x21)
1N/A#define PIC1_IMR (0x21)
1N/A#define PIC2_ICW1 (0xa0)
1N/A#define PIC2_OCW2 (0xa0)
1N/A#define PIC2_OCW3 (0xa0)
1N/A#define PIC2_ICR (0xa0)
1N/A#define PIC2_IRR (0xa0)
1N/A#define PIC2_ISR (0xa0)
1N/A#define PIC2_ICW2 (0xa1)
1N/A#define PIC2_ICW3 (0xa1)
1N/A#define PIC2_ICW4 (0xa1)
1N/A#define PIC2_IMR (0xa1)
1N/A
1N/A/* Register command values */
1N/A#define OCW3_ID (0x08)
1N/A#define OCW3_READ_IRR (0x03)
1N/A#define OCW3_READ_ISR (0x02)
1N/A#define ICR_EOI_NON_SPECIFIC (0x20)
1N/A#define ICR_EOI_NOP (0x40)
1N/A#define ICR_EOI_SPECIFIC (0x60)
1N/A#define ICR_EOI_SET_PRIORITY (0xc0)
1N/A
1N/A/* Macros to enable/disable IRQs */
1N/A#define IMR_REG(x) ( (x) < IRQ_PIC_CUTOFF ? PIC1_IMR : PIC2_IMR )
1N/A#define IMR_BIT(x) ( 1 << ( (x) % IRQ_PIC_CUTOFF ) )
1N/A#define irq_enabled(x) ( ( inb ( IMR_REG(x) ) & IMR_BIT(x) ) == 0 )
1N/A#define enable_irq(x) outb ( inb( IMR_REG(x) ) & ~IMR_BIT(x), IMR_REG(x) )
1N/A#define disable_irq(x) outb ( inb( IMR_REG(x) ) | IMR_BIT(x), IMR_REG(x) )
1N/A
1N/A/* Macros for acknowledging IRQs */
1N/A#define ICR_REG(x) ( (x) < IRQ_PIC_CUTOFF ? PIC1_ICR : PIC2_ICR )
1N/A#define ICR_VALUE(x) ( (x) % IRQ_PIC_CUTOFF )
1N/A#define CHAINED_IRQ 2
1N/A
1N/A/* Utility macros to convert IRQ numbers to INT numbers and INT vectors */
1N/A#define IRQ_INT(x) ( (x)<IRQ_PIC_CUTOFF ? (x)+0x08 : (x)-IRQ_PIC_CUTOFF+0x70 )
1N/A#define INT_VECTOR(x) ( (segoff_t*) phys_to_virt( 4 * (x) ) )
1N/A#define IRQ_VECTOR(x) ( INT_VECTOR ( IRQ_INT(x) ) )
1N/A
1N/A/* Other constants */
1N/Atypedef uint8_t irq_t;
1N/A#define IRQ_MAX (15)
1N/A#define IRQ_NONE (0xff)
1N/A
1N/A/* Labels in assembly code (asm.S)
1N/A */
1N/Aextern void _undi_irq_handler_start;
1N/Aextern void _undi_irq_handler ( void );
1N/Aextern volatile uint16_t _undi_irq_trigger_count;
1N/Aextern volatile uint16_t _undi_irq_fail_count;
1N/Aextern volatile uint16_t _undi_irq_not_ours_count;
1N/Aextern segoff_t _undi_irq_chain_to;
1N/Aextern uint8_t _undi_irq_chain;
1N/Aextern uint8_t _pxenv_undi_irq;
1N/Aextern segoff_t _pxenv_undi_entrypointsp;
1N/A
1N/A/* Function prototypes
1N/A */
1N/Aint install_irq_handler ( irq_t irq, segoff_t *handler,
1N/A uint8_t *previously_enabled,
1N/A segoff_t *previous_handler );
1N/Aint remove_irq_handler ( irq_t irq, segoff_t *handler,
1N/A uint8_t *previously_enabled,
1N/A segoff_t *previous_handler );
1N/Aint install_undi_irq_handler ( irq_t irq, segoff_t );
1N/Aint remove_undi_irq_handler ( irq_t irq );
1N/Aint undi_irq_triggered ( irq_t irq );
1N/Avoid send_specific_eoi ( irq_t irq );
1N/A#ifdef DEBUG_IRQ
1N/Avoid dump_irq_status ( void );
1N/A#else
1N/A#define dump_irq_status()
1N/A#endif
1N/A
1N/A#endif /* PIC8259_H */