pcat_interrupts.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * (C) Copyright 2009
  3. * Graeme Russ, <graeme.russ@gmail.com>
  4. *
  5. * (C) Copyright 2002
  6. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. /*
  11. * This file provides the interrupt handling functionality for systems
  12. * based on the standard PC/AT architecture using two cascaded i8259
  13. * Programmable Interrupt Controllers.
  14. */
  15. #include <common.h>
  16. #include <asm/io.h>
  17. #include <asm/i8259.h>
  18. #include <asm/ibmpc.h>
  19. #include <asm/interrupt.h>
  20. #if CONFIG_SYS_NUM_IRQS != 16
  21. #error "CONFIG_SYS_NUM_IRQS must equal 16 if CONFIG_SYS_NUM_IRQS is defined"
  22. #endif
  23. int interrupt_init(void)
  24. {
  25. u8 i;
  26. disable_interrupts();
  27. /* Mask all interrupts */
  28. outb(0xff, MASTER_PIC + IMR);
  29. outb(0xff, SLAVE_PIC + IMR);
  30. /* Master PIC */
  31. /* Place master PIC interrupts at INT20 */
  32. /* ICW3, One slave PIC is present */
  33. outb(ICW1_SEL|ICW1_EICW4, MASTER_PIC + ICW1);
  34. outb(0x20, MASTER_PIC + ICW2);
  35. outb(IR2, MASTER_PIC + ICW3);
  36. outb(ICW4_PM, MASTER_PIC + ICW4);
  37. for (i = 0; i < 8; i++)
  38. outb(OCW2_SEOI | i, MASTER_PIC + OCW2);
  39. /* Slave PIC */
  40. /* Place slave PIC interrupts at INT28 */
  41. /* Slave ID */
  42. outb(ICW1_SEL|ICW1_EICW4, SLAVE_PIC + ICW1);
  43. outb(0x28, SLAVE_PIC + ICW2);
  44. outb(0x02, SLAVE_PIC + ICW3);
  45. outb(ICW4_PM, SLAVE_PIC + ICW4);
  46. for (i = 0; i < 8; i++)
  47. outb(OCW2_SEOI | i, SLAVE_PIC + OCW2);
  48. /*
  49. * Enable cascaded interrupts by unmasking the cascade IRQ pin of
  50. * the master PIC
  51. */
  52. unmask_irq(2);
  53. enable_interrupts();
  54. return 0;
  55. }
  56. void mask_irq(int irq)
  57. {
  58. int imr_port;
  59. if (irq >= CONFIG_SYS_NUM_IRQS)
  60. return;
  61. if (irq > 7)
  62. imr_port = SLAVE_PIC + IMR;
  63. else
  64. imr_port = MASTER_PIC + IMR;
  65. outb(inb(imr_port) | (1 << (irq & 7)), imr_port);
  66. }
  67. void unmask_irq(int irq)
  68. {
  69. int imr_port;
  70. if (irq >= CONFIG_SYS_NUM_IRQS)
  71. return;
  72. if (irq > 7)
  73. imr_port = SLAVE_PIC + IMR;
  74. else
  75. imr_port = MASTER_PIC + IMR;
  76. outb(inb(imr_port) & ~(1 << (irq & 7)), imr_port);
  77. }
  78. void specific_eoi(int irq)
  79. {
  80. if (irq >= CONFIG_SYS_NUM_IRQS)
  81. return;
  82. if (irq > 7) {
  83. /*
  84. * IRQ is on the slave - Issue a corresponding EOI to the
  85. * slave PIC and an EOI for IRQ2 (the cascade interrupt)
  86. * on the master PIC
  87. */
  88. outb(OCW2_SEOI | (irq & 7), SLAVE_PIC + OCW2);
  89. irq = SEOI_IR2;
  90. }
  91. outb(OCW2_SEOI | irq, MASTER_PIC + OCW2);
  92. }