| 1 |
|
| 2 |
|
| 3 |
#include <arch/io.h> |
| 4 |
#include <pc80/i8259.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <stdint.h> |
| 7 |
|
| 8 |
|
| 9 |
u16 pic_read_irq_mask(void) |
| 10 |
{ |
| 11 |
u16 mask; |
| 12 |
int i; |
| 13 |
|
| 14 |
mask = inb(MASTER_PIC_OCW1) | (inb(SLAVE_PIC_OCW1) << 8); |
| 15 |
|
| 16 |
printk(BIOS_DEBUG, "8259 PIC: OCW1 IRQ Mask: 0x%x\n", mask); |
| 17 |
printk(BIOS_SPEW, "\tEnabled IRQs (0 = Unmasked, 1 = Masked off):\n" |
| 18 |
"\t\tMaster\t\tSlave\n"); |
| 19 |
for (i = 0; i <= 7; i++) { |
| 20 |
printk(BIOS_SPEW, "\t\tIRQ%X: %x\t\tIRQ%X: %x\n", |
| 21 |
i, (mask >> i) & 1, i + 8, (mask >> (i + 8)) & 1); |
| 22 |
} |
| 23 |
return mask; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
void pic_write_irq_mask(u16 mask) |
| 31 |
{ |
| 32 |
outb(mask, MASTER_PIC_OCW1); |
| 33 |
outb(mask >> 8, SLAVE_PIC_OCW1); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
void pic_irq_enable(u8 int_num, u8 mask) |
| 42 |
{ |
| 43 |
pic_write_irq_mask(pic_read_irq_mask() & ~(mask << int_num)); |
| 44 |
pic_read_irq_mask(); |
| 45 |
} |
| 46 |
|
| 47 |
void setup_i8259(void) |
| 48 |
{ |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
outb(ICW_SELECT|IC4, MASTER_PIC_ICW1); |
| 60 |
outb(ICW_SELECT|IC4, SLAVE_PIC_ICW1); |
| 61 |
|
| 62 |
|
| 63 |
outb(INT_VECTOR_MASTER | IRQ0, MASTER_PIC_ICW2); |
| 64 |
outb(INT_VECTOR_SLAVE | IRQ8, SLAVE_PIC_ICW2); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
outb(CASCADED_PIC, MASTER_PIC_ICW3); |
| 72 |
outb(SLAVE_ID, SLAVE_PIC_ICW3); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
outb(MICROPROCESSOR_MODE, MASTER_PIC_ICW2); |
| 80 |
outb(MICROPROCESSOR_MODE, SLAVE_PIC_ICW2); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
outb(ALL_IRQS, SLAVE_PIC_OCW1); |
| 88 |
outb(ALL_IRQS & ~IRQ2, MASTER_PIC_OCW1); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
void i8259_configure_irq_trigger(int int_num, int is_level_triggered) |
| 101 |
{ |
| 102 |
u16 int_bits = inb(ELCR1) | (((u16)inb(ELCR2)) << 8); |
| 103 |
|
| 104 |
if (is_level_triggered) |
| 105 |
int_bits |= (1 << int_num); |
| 106 |
else |
| 107 |
int_bits &= ~(1 << int_num); |
| 108 |
|
| 109 |
|
| 110 |
outb((u8)(int_bits & 0xff), ELCR1); |
| 111 |
outb((u8)(int_bits >> 8), ELCR2); |
| 112 |
} |