Graeme Russ | abf0cd3 | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 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 | /* |
| 28 | * This file provides the interrupt handling functionality for systems |
| 29 | * based on the standard PC/AT architecture using two cascaded i8259 |
| 30 | * Programmable Interrupt Controllers. |
| 31 | */ |
| 32 | |
| 33 | #include <common.h> |
| 34 | #include <asm/io.h> |
| 35 | #include <asm/i8259.h> |
| 36 | #include <asm/ibmpc.h> |
| 37 | #include <asm/interrupt.h> |
| 38 | |
| 39 | #if CONFIG_SYS_NUM_IRQS != 16 |
| 40 | #error "CONFIG_SYS_NUM_IRQS must equal 16 if CONFIG_SYS_NUM_IRQS is defined" |
| 41 | #endif |
| 42 | |
| 43 | DECLARE_INTERRUPT(0); |
| 44 | DECLARE_INTERRUPT(1); |
| 45 | DECLARE_INTERRUPT(3); |
| 46 | DECLARE_INTERRUPT(4); |
| 47 | DECLARE_INTERRUPT(5); |
| 48 | DECLARE_INTERRUPT(6); |
| 49 | DECLARE_INTERRUPT(7); |
| 50 | DECLARE_INTERRUPT(8); |
| 51 | DECLARE_INTERRUPT(9); |
| 52 | DECLARE_INTERRUPT(10); |
| 53 | DECLARE_INTERRUPT(11); |
| 54 | DECLARE_INTERRUPT(12); |
| 55 | DECLARE_INTERRUPT(13); |
| 56 | DECLARE_INTERRUPT(14); |
| 57 | DECLARE_INTERRUPT(15); |
| 58 | |
| 59 | int interrupt_init(void) |
| 60 | { |
| 61 | u8 i; |
| 62 | |
| 63 | disable_interrupts(); |
| 64 | |
| 65 | /* Setup interrupts */ |
| 66 | set_vector(0x20, irq_0); |
| 67 | set_vector(0x21, irq_1); |
| 68 | set_vector(0x23, irq_3); |
| 69 | set_vector(0x24, irq_4); |
| 70 | set_vector(0x25, irq_5); |
| 71 | set_vector(0x26, irq_6); |
| 72 | set_vector(0x27, irq_7); |
| 73 | set_vector(0x28, irq_8); |
| 74 | set_vector(0x29, irq_9); |
| 75 | set_vector(0x2a, irq_10); |
| 76 | set_vector(0x2b, irq_11); |
| 77 | set_vector(0x2c, irq_12); |
| 78 | set_vector(0x2d, irq_13); |
| 79 | set_vector(0x2e, irq_14); |
| 80 | set_vector(0x2f, irq_15); |
| 81 | |
| 82 | /* Mask all interrupts */ |
| 83 | outb(0xff, MASTER_PIC + IMR); |
| 84 | outb(0xff, SLAVE_PIC + IMR); |
| 85 | |
| 86 | /* Master PIC */ |
| 87 | /* Place master PIC interrupts at INT20 */ |
| 88 | /* ICW3, One slave PIC is present */ |
| 89 | outb(ICW1_SEL|ICW1_EICW4, MASTER_PIC + ICW1); |
| 90 | outb(0x20, MASTER_PIC + ICW2); |
| 91 | outb(IR2, MASTER_PIC + ICW3); |
| 92 | outb(ICW4_PM, MASTER_PIC + ICW4); |
| 93 | |
| 94 | for (i = 0; i < 8; i++) |
| 95 | outb(OCW2_SEOI | i, MASTER_PIC + OCW2); |
| 96 | |
| 97 | /* Slave PIC */ |
| 98 | /* Place slave PIC interrupts at INT28 */ |
| 99 | /* Slave ID */ |
| 100 | outb(ICW1_SEL|ICW1_EICW4, SLAVE_PIC + ICW1); |
| 101 | outb(0x28, SLAVE_PIC + ICW2); |
| 102 | outb(0x02, SLAVE_PIC + ICW3); |
| 103 | outb(ICW4_PM, SLAVE_PIC + ICW4); |
| 104 | |
| 105 | for (i = 0; i < 8; i++) |
| 106 | outb(OCW2_SEOI | i, SLAVE_PIC + OCW2); |
| 107 | |
| 108 | /* |
| 109 | * Enable cascaded interrupts by unmasking the cascade IRQ pin of |
| 110 | * the master PIC |
| 111 | */ |
| 112 | unmask_irq (2); |
| 113 | |
| 114 | enable_interrupts(); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
| 119 | void mask_irq(int irq) |
| 120 | { |
| 121 | int imr_port; |
| 122 | |
| 123 | if (irq >= CONFIG_SYS_NUM_IRQS) |
| 124 | return; |
| 125 | |
| 126 | if (irq > 7) |
| 127 | imr_port = SLAVE_PIC + IMR; |
| 128 | else |
| 129 | imr_port = MASTER_PIC + IMR; |
| 130 | |
| 131 | outb(inb(imr_port) | (1 << (irq & 7)), imr_port); |
| 132 | } |
| 133 | |
| 134 | void unmask_irq(int irq) |
| 135 | { |
| 136 | int imr_port; |
| 137 | |
| 138 | if (irq >= CONFIG_SYS_NUM_IRQS) |
| 139 | return; |
| 140 | |
| 141 | if (irq > 7) |
| 142 | imr_port = SLAVE_PIC + IMR; |
| 143 | else |
| 144 | imr_port = MASTER_PIC + IMR; |
| 145 | |
| 146 | outb(inb(imr_port) & ~(1 << (irq & 7)), imr_port); |
| 147 | } |
| 148 | |
| 149 | void specific_eoi(int irq) |
| 150 | { |
| 151 | if (irq >= CONFIG_SYS_NUM_IRQS) |
| 152 | return; |
| 153 | |
| 154 | if (irq > 7) { |
| 155 | /* |
| 156 | * IRQ is on the slave - Issue a corresponding EOI to the |
| 157 | * slave PIC and an EOI for IRQ2 (the cascade interrupt) |
| 158 | * on the master PIC |
| 159 | */ |
| 160 | outb(OCW2_SEOI | (irq & 7), SLAVE_PIC + OCW2); |
| 161 | irq = SEOI_IR2; |
| 162 | } |
| 163 | |
| 164 | outb(OCW2_SEOI | irq, MASTER_PIC + OCW2); |
| 165 | } |