You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Basic support for controlling the 8259 Programmable Interrupt Controllers.
  3. *
  4. * Initially written by Michael Brown (mcb30).
  5. */
  6. #ifndef PIC8259_H
  7. #define PIC8259_H
  8. /* For segoff_t */
  9. #include "realmode.h"
  10. #define IRQ_PIC_CUTOFF (8)
  11. /* 8259 register locations */
  12. #define PIC1_ICW1 (0x20)
  13. #define PIC1_OCW2 (0x20)
  14. #define PIC1_OCW3 (0x20)
  15. #define PIC1_ICR (0x20)
  16. #define PIC1_IRR (0x20)
  17. #define PIC1_ISR (0x20)
  18. #define PIC1_ICW2 (0x21)
  19. #define PIC1_ICW3 (0x21)
  20. #define PIC1_ICW4 (0x21)
  21. #define PIC1_IMR (0x21)
  22. #define PIC2_ICW1 (0xa0)
  23. #define PIC2_OCW2 (0xa0)
  24. #define PIC2_OCW3 (0xa0)
  25. #define PIC2_ICR (0xa0)
  26. #define PIC2_IRR (0xa0)
  27. #define PIC2_ISR (0xa0)
  28. #define PIC2_ICW2 (0xa1)
  29. #define PIC2_ICW3 (0xa1)
  30. #define PIC2_ICW4 (0xa1)
  31. #define PIC2_IMR (0xa1)
  32. /* Register command values */
  33. #define OCW3_ID (0x08)
  34. #define OCW3_READ_IRR (0x03)
  35. #define OCW3_READ_ISR (0x02)
  36. #define ICR_EOI_NON_SPECIFIC (0x20)
  37. #define ICR_EOI_NOP (0x40)
  38. #define ICR_EOI_SPECIFIC (0x60)
  39. #define ICR_EOI_SET_PRIORITY (0xc0)
  40. /* Macros to enable/disable IRQs */
  41. #define IMR_REG(x) ( (x) < IRQ_PIC_CUTOFF ? PIC1_IMR : PIC2_IMR )
  42. #define IMR_BIT(x) ( 1 << ( (x) % IRQ_PIC_CUTOFF ) )
  43. #define irq_enabled(x) ( ( inb ( IMR_REG(x) ) & IMR_BIT(x) ) == 0 )
  44. #define enable_irq(x) outb ( inb( IMR_REG(x) ) & ~IMR_BIT(x), IMR_REG(x) )
  45. #define disable_irq(x) outb ( inb( IMR_REG(x) ) | IMR_BIT(x), IMR_REG(x) )
  46. /* Macros for acknowledging IRQs */
  47. #define ICR_REG(x) ( (x) < IRQ_PIC_CUTOFF ? PIC1_ICR : PIC2_ICR )
  48. #define ICR_VALUE(x) ( (x) % IRQ_PIC_CUTOFF )
  49. #define CHAINED_IRQ 2
  50. /* Utility macros to convert IRQ numbers to INT numbers and INT vectors */
  51. #define IRQ_INT(x) ( (x)<IRQ_PIC_CUTOFF ? (x)+0x08 : (x)-IRQ_PIC_CUTOFF+0x70 )
  52. #define INT_VECTOR(x) ( (segoff_t*) phys_to_virt( 4 * (x) ) )
  53. #define IRQ_VECTOR(x) ( INT_VECTOR ( IRQ_INT(x) ) )
  54. /* Other constants */
  55. typedef uint8_t irq_t;
  56. #define IRQ_MAX (15)
  57. #define IRQ_NONE (0xff)
  58. /* Function prototypes
  59. */
  60. int install_irq_handler ( irq_t irq, segoff_t *handler,
  61. uint8_t *previously_enabled,
  62. segoff_t *previous_handler );
  63. int remove_irq_handler ( irq_t irq, segoff_t *handler,
  64. uint8_t *previously_enabled,
  65. segoff_t *previous_handler );
  66. int install_trivial_irq_handler ( irq_t irq );
  67. int remove_trivial_irq_handler ( irq_t irq );
  68. int trivial_irq_triggered ( irq_t irq );
  69. int copy_trivial_irq_handler ( void *target, size_t target_size );
  70. void send_non_specific_eoi ( irq_t irq );
  71. void send_specific_eoi ( irq_t irq );
  72. void fake_irq ( irq_t irq );
  73. #ifdef DEBUG_IRQ
  74. void dump_irq_status ( void );
  75. #else
  76. #define dump_irq_status()
  77. #endif
  78. /* Other code (e.g. undi.c) needs to know the size of the trivial IRQ
  79. * handler code, so we put prototypes and the size macro here.
  80. */
  81. extern void _trivial_irq_handler ( void );
  82. extern char _trivial_irq_handler_size[];
  83. #define TRIVIAL_IRQ_HANDLER_SIZE FRAGMENT_SIZE(_trivial_irq_handler)
  84. #endif /* PIC8259_H */