i8259.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * include/asm-mips/i8259.h
  4. *
  5. * i8259A interrupt definitions.
  6. *
  7. * Copyright (C) 2003 Maciej W. Rozycki
  8. * Copyright (C) 2003 Ralf Baechle <[email protected]>
  9. */
  10. #ifndef _ASM_I8259_H
  11. #define _ASM_I8259_H
  12. #include <linux/compiler.h>
  13. #include <linux/spinlock.h>
  14. #include <asm/io.h>
  15. #include <irq.h>
  16. /* i8259A PIC registers */
  17. #define PIC_MASTER_CMD 0x20
  18. #define PIC_MASTER_IMR 0x21
  19. #define PIC_MASTER_ISR PIC_MASTER_CMD
  20. #define PIC_MASTER_POLL PIC_MASTER_ISR
  21. #define PIC_MASTER_OCW3 PIC_MASTER_ISR
  22. #define PIC_SLAVE_CMD 0xa0
  23. #define PIC_SLAVE_IMR 0xa1
  24. /* i8259A PIC related value */
  25. #define PIC_CASCADE_IR 2
  26. #define MASTER_ICW4_DEFAULT 0x01
  27. #define SLAVE_ICW4_DEFAULT 0x01
  28. #define PIC_ICW4_AEOI 2
  29. extern raw_spinlock_t i8259A_lock;
  30. extern void make_8259A_irq(unsigned int irq);
  31. extern void init_i8259_irqs(void);
  32. extern struct irq_domain *__init_i8259_irqs(struct device_node *node);
  33. /**
  34. * i8159_set_poll() - Override the i8259 polling function
  35. * @poll: pointer to platform-specific polling function
  36. *
  37. * Call this to override the generic i8259 polling function, which directly
  38. * accesses i8259 registers, with a platform specific one which may be faster
  39. * in cases where hardware provides a more optimal means of polling for an
  40. * interrupt.
  41. */
  42. extern void i8259_set_poll(int (*poll)(void));
  43. /*
  44. * Do the traditional i8259 interrupt polling thing. This is for the few
  45. * cases where no better interrupt acknowledge method is available and we
  46. * absolutely must touch the i8259.
  47. */
  48. static inline int i8259_irq(void)
  49. {
  50. int irq;
  51. raw_spin_lock(&i8259A_lock);
  52. /* Perform an interrupt acknowledge cycle on controller 1. */
  53. outb(0x0C, PIC_MASTER_CMD); /* prepare for poll */
  54. irq = inb(PIC_MASTER_CMD) & 7;
  55. if (irq == PIC_CASCADE_IR) {
  56. /*
  57. * Interrupt is cascaded so perform interrupt
  58. * acknowledge on controller 2.
  59. */
  60. outb(0x0C, PIC_SLAVE_CMD); /* prepare for poll */
  61. irq = (inb(PIC_SLAVE_CMD) & 7) + 8;
  62. }
  63. if (unlikely(irq == 7)) {
  64. /*
  65. * This may be a spurious interrupt.
  66. *
  67. * Read the interrupt status register (ISR). If the most
  68. * significant bit is not set then there is no valid
  69. * interrupt.
  70. */
  71. outb(0x0B, PIC_MASTER_ISR); /* ISR register */
  72. if(~inb(PIC_MASTER_ISR) & 0x80)
  73. irq = -1;
  74. }
  75. raw_spin_unlock(&i8259A_lock);
  76. return likely(irq >= 0) ? irq + I8259A_IRQ_BASE : irq;
  77. }
  78. #endif /* _ASM_I8259_H */