irq: make IRQs dynamically mappable
This commit is contained in:
parent
4b813d7c86
commit
b8b67aadc9
7 changed files with 108 additions and 21 deletions
12
dev/ahci.c
12
dev/ahci.c
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
static hbamem_t *abar = NULL;
|
static hbamem_t *abar = NULL;
|
||||||
|
|
||||||
|
static void ahci_irq_handler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void ahci_init()
|
void ahci_init()
|
||||||
{
|
{
|
||||||
struct pci_device *dev = pci_find_device(0x01, 0x06);
|
struct pci_device *dev = pci_find_device(0x01, 0x06);
|
||||||
|
|
@ -22,5 +26,13 @@ void ahci_init()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* setup device irq number */
|
||||||
|
uint8_t irq = irq_highest_free();
|
||||||
|
uint16_t tmp = pci_config_read_word(dev->bus, dev->slot, 0, 0x3C);
|
||||||
|
tmp &= 0xFF00;
|
||||||
|
tmp |= irq;
|
||||||
|
pci_config_write_word(dev->bus, dev->slot, 0, 0x3C, tmp);
|
||||||
|
irq_map(irq, ahci_irq_handler);
|
||||||
|
|
||||||
printf(LOG_SUCCESS "AHCI controller ready\n");
|
printf(LOG_SUCCESS "AHCI controller ready\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
43
dev/isr.S
43
dev/isr.S
|
|
@ -22,22 +22,15 @@
|
||||||
iretq
|
iretq
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.global isr_serial_input
|
.macro irq nr
|
||||||
isr_serial_input:
|
.global _irq_\nr
|
||||||
cli
|
_irq_\nr:
|
||||||
call serial_trap
|
cli
|
||||||
movb $4, %dil
|
movq $\nr, %rdi
|
||||||
call pic_eoi
|
call irq
|
||||||
sti
|
sti
|
||||||
iretq
|
iretq
|
||||||
|
.endm
|
||||||
.global isr_sched
|
|
||||||
isr_sched:
|
|
||||||
cli
|
|
||||||
call sched_test
|
|
||||||
call pic_eoi
|
|
||||||
sti
|
|
||||||
iretq
|
|
||||||
|
|
||||||
.global sti
|
.global sti
|
||||||
sti:
|
sti:
|
||||||
|
|
@ -81,3 +74,21 @@ exception 0x1C
|
||||||
exception_err 0x1D
|
exception_err 0x1D
|
||||||
exception_err 0x1E
|
exception_err 0x1E
|
||||||
exception 0x1F
|
exception 0x1F
|
||||||
|
|
||||||
|
irq 0x00
|
||||||
|
irq 0x01
|
||||||
|
irq 0x02
|
||||||
|
irq 0x03
|
||||||
|
irq 0x04
|
||||||
|
irq 0x05
|
||||||
|
irq 0x06
|
||||||
|
irq 0x07
|
||||||
|
irq 0x08
|
||||||
|
irq 0x09
|
||||||
|
irq 0x0A
|
||||||
|
irq 0x0B
|
||||||
|
irq 0x0C
|
||||||
|
irq 0x0D
|
||||||
|
irq 0x0E
|
||||||
|
irq 0x0F
|
||||||
|
|
||||||
|
|
|
||||||
13
dev/pci.c
13
dev/pci.c
|
|
@ -24,6 +24,19 @@ uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t o
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pci_config_write_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint16_t data)
|
||||||
|
{
|
||||||
|
uint32_t addr;
|
||||||
|
uint32_t lbus = bus;
|
||||||
|
uint32_t lslot = slot;
|
||||||
|
uint32_t lfunc = func;
|
||||||
|
|
||||||
|
addr = (lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xfc) | 0x80000000;
|
||||||
|
|
||||||
|
outl(PCIPM_CONFIG_ADDRESS, addr);
|
||||||
|
outl(PCIPM_CONFIG_DATA, data);
|
||||||
|
}
|
||||||
|
|
||||||
static void pci_scan_bus(uint8_t bus)
|
static void pci_scan_bus(uint8_t bus)
|
||||||
{
|
{
|
||||||
for (uint8_t slot = 0; slot < 32; slot++) {
|
for (uint8_t slot = 0; slot < 32; slot++) {
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ struct pci_header_type_1 {
|
||||||
|
|
||||||
void pci_init();
|
void pci_init();
|
||||||
uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset);
|
uint16_t pci_config_read_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset);
|
||||||
|
void pci_config_write_word(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset, uint16_t data);
|
||||||
struct pci_device *pci_find_device(uint8_t class, uint8_t subclass);
|
struct pci_device *pci_find_device(uint8_t class, uint8_t subclass);
|
||||||
|
|
||||||
#endif /* _PCI_H_ */
|
#endif /* _PCI_H_ */
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
void isr_serial_input();
|
void isr_serial_input();
|
||||||
void isr_serial_input_1();
|
void isr_serial_input_1();
|
||||||
void serial_write(char c);
|
void serial_write(char c);
|
||||||
|
void serial_trap();
|
||||||
int serial_init();
|
int serial_init();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include <kernel/common.h>
|
#include <kernel/common.h>
|
||||||
|
|
||||||
int irq_map(uint8_t irq, uint8_t ist, void *func);
|
int irq_map(uint8_t irq, void *func);
|
||||||
void irq_unmap(uint8_t irq);
|
void irq_unmap(uint8_t irq);
|
||||||
int irq_highest_free();
|
int irq_highest_free();
|
||||||
|
|
||||||
|
|
|
||||||
57
init/irq.c
57
init/irq.c
|
|
@ -10,7 +10,11 @@
|
||||||
#define exception(_i) _exception_##_i
|
#define exception(_i) _exception_##_i
|
||||||
#define exception_decl(_j) void exception(_j)()
|
#define exception_decl(_j) void exception(_j)()
|
||||||
|
|
||||||
|
#define irq_decl(_i) void _irq_##_i()
|
||||||
|
#define __irq(_i) _irq_##_i
|
||||||
|
|
||||||
static bool irq_mapped[16] = { false };
|
static bool irq_mapped[16] = { false };
|
||||||
|
static void *irq_handlers[16] = { NULL };
|
||||||
|
|
||||||
exception_decl(0x00);
|
exception_decl(0x00);
|
||||||
exception_decl(0x01);
|
exception_decl(0x01);
|
||||||
|
|
@ -45,8 +49,25 @@ exception_decl(0x1D);
|
||||||
exception_decl(0x1E);
|
exception_decl(0x1E);
|
||||||
exception_decl(0x1F);
|
exception_decl(0x1F);
|
||||||
|
|
||||||
|
irq_decl(0x00);
|
||||||
|
irq_decl(0x01);
|
||||||
|
irq_decl(0x02);
|
||||||
|
irq_decl(0x03);
|
||||||
|
irq_decl(0x04);
|
||||||
|
irq_decl(0x05);
|
||||||
|
irq_decl(0x06);
|
||||||
|
irq_decl(0x07);
|
||||||
|
irq_decl(0x08);
|
||||||
|
irq_decl(0x09);
|
||||||
|
irq_decl(0x0A);
|
||||||
|
irq_decl(0x0B);
|
||||||
|
irq_decl(0x0C);
|
||||||
|
irq_decl(0x0D);
|
||||||
|
irq_decl(0x0E);
|
||||||
|
irq_decl(0x0F);
|
||||||
|
|
||||||
void idt_load(); /* descriptor.S */
|
void idt_load(); /* descriptor.S */
|
||||||
void isr_sched(); /* isr.S */
|
void __irq_handler_base(); /* isr.S */
|
||||||
|
|
||||||
void sched_test()
|
void sched_test()
|
||||||
{
|
{
|
||||||
|
|
@ -66,13 +87,13 @@ void idt_insert(uint16_t gate, uint8_t type, uint8_t ist, uint16_t segment, void
|
||||||
irqdesc->attrs = type;
|
irqdesc->attrs = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
int irq_map(uint8_t irq, uint8_t ist, void *func)
|
int irq_map(uint8_t irq, void *func)
|
||||||
{
|
{
|
||||||
if (irq_mapped[irq])
|
if (irq_mapped[irq])
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
irq_mapped[irq] = true;
|
irq_mapped[irq] = true;
|
||||||
idt_insert(irq + 0x20, GATE_INTR, ist, GDT_SEGMENT_CODE_RING0, func);
|
irq_handlers[irq] = func;
|
||||||
pic_mask(irq, 0);
|
pic_mask(irq, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -81,6 +102,7 @@ int irq_map(uint8_t irq, uint8_t ist, void *func)
|
||||||
void irq_unmap(uint8_t irq)
|
void irq_unmap(uint8_t irq)
|
||||||
{
|
{
|
||||||
irq_mapped[irq] = false;
|
irq_mapped[irq] = false;
|
||||||
|
irq_handlers[irq] = NULL;
|
||||||
idt_insert(irq + 0x20, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, NULL);
|
idt_insert(irq + 0x20, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, NULL);
|
||||||
pic_mask(irq, 1);
|
pic_mask(irq, 1);
|
||||||
}
|
}
|
||||||
|
|
@ -95,6 +117,16 @@ int irq_highest_free()
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void irq(int irq)
|
||||||
|
{
|
||||||
|
if (irq_handlers[irq] != NULL) {
|
||||||
|
void (*handler)() = irq_handlers[irq];
|
||||||
|
handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
pic_eoi(irq);
|
||||||
|
}
|
||||||
|
|
||||||
void idt_init()
|
void idt_init()
|
||||||
{
|
{
|
||||||
idt_insert(0x00, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x00));
|
idt_insert(0x00, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x00));
|
||||||
|
|
@ -130,7 +162,24 @@ void idt_init()
|
||||||
idt_insert(0x1E, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1E));
|
idt_insert(0x1E, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1E));
|
||||||
idt_insert(0x1F, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1F));
|
idt_insert(0x1F, GATE_TRAP, 0, GDT_SEGMENT_CODE_RING0, exception(0x1F));
|
||||||
|
|
||||||
irq_map(4, 0, isr_serial_input);
|
idt_insert(0x20, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x00));
|
||||||
|
idt_insert(0x21, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x01));
|
||||||
|
idt_insert(0x22, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x02));
|
||||||
|
idt_insert(0x23, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x03));
|
||||||
|
idt_insert(0x24, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x04));
|
||||||
|
idt_insert(0x25, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x05));
|
||||||
|
idt_insert(0x26, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x06));
|
||||||
|
idt_insert(0x27, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x07));
|
||||||
|
idt_insert(0x28, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x08));
|
||||||
|
idt_insert(0x29, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x09));
|
||||||
|
idt_insert(0x2A, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0A));
|
||||||
|
idt_insert(0x2B, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0B));
|
||||||
|
idt_insert(0x2C, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0C));
|
||||||
|
idt_insert(0x2D, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0D));
|
||||||
|
idt_insert(0x2E, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0E));
|
||||||
|
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0F));
|
||||||
|
|
||||||
|
irq_map(4, serial_trap);
|
||||||
|
|
||||||
__idtr.size = (IDT_SIZE - 1);
|
__idtr.size = (IDT_SIZE - 1);
|
||||||
__idtr.offset = (uint64_t)__idt;
|
__idtr.offset = (uint64_t)__idt;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue