1 #include <hal/acpi/acpi.h>
2 #include <hal/ioapic.h>
4 #include <lunaix/isrm.h>
5 #include <lunaix/spike.h>
9 0~31: reserved for sys use (x32)
10 32~47: reserved for os use (x16)
11 48~ : free to allocate for external hardware use. (x208)
14 static char iv_bmp[(IV_MAX - IV_BASE) / 8];
15 static isr_cb handlers[IV_MAX];
18 intr_routine_fallback(const isr_param* param);
23 for (size_t i = 0; i < 256; i++) {
24 handlers[i] = intr_routine_fallback;
29 __ivalloc_within(size_t a, size_t b, isr_cb handler)
31 a = (a - IV_BASE) / 8;
32 b = (b - IV_BASE) / 8;
34 for (size_t i = a; i < b; i++) {
35 u8_t chunk = iv_bmp[i], j = 0;
40 while ((chunk & 0x1)) {
47 int iv = IV_BASE + i * 8 + j;
48 handlers[iv] = handler ? handler : intr_routine_fallback;
57 isrm_ivosalloc(isr_cb handler)
59 return __ivalloc_within(IV_BASE, IV_EX, handler);
63 isrm_ivexalloc(isr_cb handler)
65 return __ivalloc_within(IV_EX, IV_MAX, handler);
74 iv_bmp[(iv - IV_BASE) / 8] &= ~(1 << ((iv - IV_BASE) % 8));
77 handlers[iv] = intr_routine_fallback;
81 isrm_bindirq(int irq, isr_cb irq_handler)
84 if (!(iv = isrm_ivexalloc(irq_handler))) {
85 panickf("out of IV resource. (irq=%d)", irq);
86 return 0; // never reach
89 // PC_AT_IRQ_RTC -> RTC_TIMER_IV, fixed, edge trigged, polarity=high,
90 // physical, APIC ID 0
91 ioapic_redirect(acpi_gistranslate(irq), iv, 0, IOAPIC_DELMOD_FIXED);
97 isrm_bindiv(int iv, isr_cb handler)
102 iv_bmp[(iv - IV_BASE) / 8] |= 1 << ((iv - IV_BASE) % 8);
105 handlers[iv] = handler;