pcat_interrupts.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. /*
  27. * This file provides the interrupt handling functionality for systems
  28. * based on the standard PC/AT architecture using two cascaded i8259
  29. * Programmable Interrupt Controllers.
  30. */
  31. #include <common.h>
  32. #include <asm/io.h>
  33. #include <asm/i8259.h>
  34. #include <asm/ibmpc.h>
  35. #include <asm/interrupt.h>
  36. #if CONFIG_SYS_NUM_IRQS != 16
  37. #error "CONFIG_SYS_NUM_IRQS must equal 16 if CONFIG_SYS_NUM_IRQS is defined"
  38. #endif
  39. DECLARE_INTERRUPT(0);
  40. DECLARE_INTERRUPT(1);
  41. DECLARE_INTERRUPT(3);
  42. DECLARE_INTERRUPT(4);
  43. DECLARE_INTERRUPT(5);
  44. DECLARE_INTERRUPT(6);
  45. DECLARE_INTERRUPT(7);
  46. DECLARE_INTERRUPT(8);
  47. DECLARE_INTERRUPT(9);
  48. DECLARE_INTERRUPT(10);
  49. DECLARE_INTERRUPT(11);
  50. DECLARE_INTERRUPT(12);
  51. DECLARE_INTERRUPT(13);
  52. DECLARE_INTERRUPT(14);
  53. DECLARE_INTERRUPT(15);
  54. int interrupt_init(void)
  55. {
  56. u8 i;
  57. disable_interrupts();
  58. /* Setup interrupts */
  59. set_vector(0x20, irq_0);
  60. set_vector(0x21, irq_1);
  61. set_vector(0x23, irq_3);
  62. set_vector(0x24, irq_4);
  63. set_vector(0x25, irq_5);
  64. set_vector(0x26, irq_6);
  65. set_vector(0x27, irq_7);
  66. set_vector(0x28, irq_8);
  67. set_vector(0x29, irq_9);
  68. set_vector(0x2a, irq_10);
  69. set_vector(0x2b, irq_11);
  70. set_vector(0x2c, irq_12);
  71. set_vector(0x2d, irq_13);
  72. set_vector(0x2e, irq_14);
  73. set_vector(0x2f, irq_15);
  74. /* Mask all interrupts */
  75. outb(0xff, MASTER_PIC + IMR);
  76. outb(0xff, SLAVE_PIC + IMR);
  77. /* Master PIC */
  78. /* Place master PIC interrupts at INT20 */
  79. /* ICW3, One slave PIC is present */
  80. outb(ICW1_SEL|ICW1_EICW4, MASTER_PIC + ICW1);
  81. outb(0x20, MASTER_PIC + ICW2);
  82. outb(IR2, MASTER_PIC + ICW3);
  83. outb(ICW4_PM, MASTER_PIC + ICW4);
  84. for (i = 0; i < 8; i++)
  85. outb(OCW2_SEOI | i, MASTER_PIC + OCW2);
  86. /* Slave PIC */
  87. /* Place slave PIC interrupts at INT28 */
  88. /* Slave ID */
  89. outb(ICW1_SEL|ICW1_EICW4, SLAVE_PIC + ICW1);
  90. outb(0x28, SLAVE_PIC + ICW2);
  91. outb(0x02, SLAVE_PIC + ICW3);
  92. outb(ICW4_PM, SLAVE_PIC + ICW4);
  93. for (i = 0; i < 8; i++)
  94. outb(OCW2_SEOI | i, SLAVE_PIC + OCW2);
  95. /*
  96. * Enable cascaded interrupts by unmasking the cascade IRQ pin of
  97. * the master PIC
  98. */
  99. unmask_irq (2);
  100. enable_interrupts();
  101. return 0;
  102. }
  103. void mask_irq(int irq)
  104. {
  105. int imr_port;
  106. if (irq >= CONFIG_SYS_NUM_IRQS)
  107. return;
  108. if (irq > 7)
  109. imr_port = SLAVE_PIC + IMR;
  110. else
  111. imr_port = MASTER_PIC + IMR;
  112. outb(inb(imr_port) | (1 << (irq & 7)), imr_port);
  113. }
  114. void unmask_irq(int irq)
  115. {
  116. int imr_port;
  117. if (irq >= CONFIG_SYS_NUM_IRQS)
  118. return;
  119. if (irq > 7)
  120. imr_port = SLAVE_PIC + IMR;
  121. else
  122. imr_port = MASTER_PIC + IMR;
  123. outb(inb(imr_port) & ~(1 << (irq & 7)), imr_port);
  124. }
  125. void specific_eoi(int irq)
  126. {
  127. if (irq >= CONFIG_SYS_NUM_IRQS)
  128. return;
  129. if (irq > 7) {
  130. /*
  131. * IRQ is on the slave - Issue a corresponding EOI to the
  132. * slave PIC and an EOI for IRQ2 (the cascade interrupt)
  133. * on the master PIC
  134. */
  135. outb(OCW2_SEOI | (irq & 7), SLAVE_PIC + OCW2);
  136. irq = SEOI_IR2;
  137. }
  138. outb(OCW2_SEOI | irq, MASTER_PIC + OCW2);
  139. }