PCI-IDE interrupt based driver fixes, works on QEMU

This commit is contained in:
2026-03-15 10:15:01 +01:00
parent 3c10b76b3f
commit 5b432b2b01
6 changed files with 167 additions and 132 deletions

View File

@@ -114,26 +114,45 @@ void ioapic_route_irq (uint32_t vec, uint32_t irq, uint64_t flags, uint64_t lapi
}
}
uint64_t calc_flags = (lapic_id << 56) | (flags) | (vec & 0xFF);
uint64_t gsi = found_override ? override->gsi : irq;
uint64_t redirflags = 0;
redirflags |= (vec & 0xFF);
redirflags |= flags;
redirflags |= (lapic_id << 56);
if (found_override) {
uint32_t polarity = ((override->flags & 0x03) == 0x03) ? 1 : 0;
uint32_t mode = (((override->flags >> 2) & 0x03) == 0x03) ? 1 : 0;
calc_flags |= (uint64_t)mode << 15;
calc_flags |= (uint64_t)polarity << 13;
}
switch (override->flags & 0x03) {
case 0:
break;
case 1:
redirflags &= ~(1 << 13);
break;
case 3:
redirflags |= (1 << 13);
break;
}
uint32_t gsi = found_override ? override->gsi : irq;
switch ((override->flags >> 2) & 0x03) {
case 0:
break;
case 1:
redirflags &= ~(1 << 15);
break;
case 3:
redirflags |= (1 << 15);
break;
}
}
ioapic = ioapic_find (gsi);
if (ioapic == NULL)
if (!ioapic)
return;
uint32_t irq_reg = ((gsi - ioapic->table_data.gsi_base) * 2) + 0x10;
ioapic_write (ioapic, irq_reg + 1, (uint32_t)(calc_flags >> 32));
ioapic_write (ioapic, irq_reg, (uint32_t)calc_flags);
ioapic_write (ioapic, irq_reg + 1, (uint32_t)(redirflags >> 32));
ioapic_write (ioapic, irq_reg, (uint32_t)redirflags);
}
/* Find and initialize the IOAPIC */
@@ -171,6 +190,9 @@ void ioapic_init (void) {
struct acpi_madt_interrupt_source_override* override =
(struct acpi_madt_interrupt_source_override*)current;
intr_src_overrides[intr_src_override_entries++] = *override;
DEBUG ("Interrupt override: source=%u gsi=%u flags=%04x bus=%u\n", override->source,
override->gsi, override->flags, override->bus);
} break;
}