pcat_interrupts.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. int interrupt_init(void)
  40. {
  41. u8 i;
  42. disable_interrupts();
  43. /* Mask all interrupts */
  44. outb(0xff, MASTER_PIC + IMR);
  45. outb(0xff, SLAVE_PIC + IMR);
  46. /* Master PIC */
  47. /* Place master PIC interrupts at INT20 */
  48. /* ICW3, One slave PIC is present */
  49. outb(ICW1_SEL|ICW1_EICW4, MASTER_PIC + ICW1);
  50. outb(0x20, MASTER_PIC + ICW2);
  51. outb(IR2, MASTER_PIC + ICW3);
  52. outb(ICW4_PM, MASTER_PIC + ICW4);
  53. for (i = 0; i < 8; i++)
  54. outb(OCW2_SEOI | i, MASTER_PIC + OCW2);
  55. /* Slave PIC */
  56. /* Place slave PIC interrupts at INT28 */
  57. /* Slave ID */
  58. outb(ICW1_SEL|ICW1_EICW4, SLAVE_PIC + ICW1);
  59. outb(0x28, SLAVE_PIC + ICW2);
  60. outb(0x02, SLAVE_PIC + ICW3);
  61. outb(ICW4_PM, SLAVE_PIC + ICW4);
  62. for (i = 0; i < 8; i++)
  63. outb(OCW2_SEOI | i, SLAVE_PIC + OCW2);
  64. /*
  65. * Enable cascaded interrupts by unmasking the cascade IRQ pin of
  66. * the master PIC
  67. */
  68. unmask_irq (2);
  69. enable_interrupts();
  70. return 0;
  71. }
  72. void mask_irq(int irq)
  73. {
  74. int imr_port;
  75. if (irq >= CONFIG_SYS_NUM_IRQS)
  76. return;
  77. if (irq > 7)
  78. imr_port = SLAVE_PIC + IMR;
  79. else
  80. imr_port = MASTER_PIC + IMR;
  81. outb(inb(imr_port) | (1 << (irq & 7)), imr_port);
  82. }
  83. void unmask_irq(int irq)
  84. {
  85. int imr_port;
  86. if (irq >= CONFIG_SYS_NUM_IRQS)
  87. return;
  88. if (irq > 7)
  89. imr_port = SLAVE_PIC + IMR;
  90. else
  91. imr_port = MASTER_PIC + IMR;
  92. outb(inb(imr_port) & ~(1 << (irq & 7)), imr_port);
  93. }
  94. void specific_eoi(int irq)
  95. {
  96. if (irq >= CONFIG_SYS_NUM_IRQS)
  97. return;
  98. if (irq > 7) {
  99. /*
  100. * IRQ is on the slave - Issue a corresponding EOI to the
  101. * slave PIC and an EOI for IRQ2 (the cascade interrupt)
  102. * on the master PIC
  103. */
  104. outb(OCW2_SEOI | (irq & 7), SLAVE_PIC + OCW2);
  105. irq = SEOI_IR2;
  106. }
  107. outb(OCW2_SEOI | irq, MASTER_PIC + OCW2);
  108. }