PCI-IDE interrupt based driver fixes, works on QEMU
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include <amd64/apic.h>
|
||||
#include <amd64/intr_defs.h>
|
||||
#include <amd64/io.h>
|
||||
#include <device/device.h>
|
||||
#include <device/idedrv.h>
|
||||
@@ -53,7 +55,7 @@ static void ide_make_device (struct proc* proc, struct reschedule_ctx* rctx,
|
||||
.io = probe.io,
|
||||
.ctrl = probe.ctrl,
|
||||
.devno = probe.devno,
|
||||
.primscnd = probe.primscnd,
|
||||
.irq = probe.irq,
|
||||
};
|
||||
struct device* ide = device_create (device_key, ops, lengthof (ops), &idedrv_init, &idedrv_fini,
|
||||
&init, proc, rctx);
|
||||
@@ -63,7 +65,7 @@ static void ide_make_device (struct proc* proc, struct reschedule_ctx* rctx,
|
||||
bool pci_ide_init (struct proc* proc, struct reschedule_ctx* rctx, struct pci_info pci_info) {
|
||||
uint16_t pci_cmd = pci_read16 (pci_info.bus, pci_info.slot, pci_info.func, PCI_COMMAND);
|
||||
|
||||
uint16_t new_cmd = (pci_cmd | (1 << 0)) & ~(1 << 10);
|
||||
uint16_t new_cmd = (pci_cmd | (1 << 0) | (1 << 2)) & ~(1 << 10);
|
||||
|
||||
if (pci_cmd != new_cmd) {
|
||||
pci_write16 (pci_info.bus, pci_info.slot, pci_info.func, PCI_COMMAND, new_cmd);
|
||||
@@ -88,11 +90,21 @@ bool pci_ide_init (struct proc* proc, struct reschedule_ctx* rctx, struct pci_in
|
||||
pcmd = (uint16_t)(bar0 & 0xFFFC);
|
||||
pctrl = (uint16_t)(bar1 & 0xFFFC);
|
||||
|
||||
if (pctrl)
|
||||
pctrl += 2;
|
||||
uint8_t irq = pci_read8 (pci_info.bus, pci_info.slot, pci_info.func, PCI_INTERRUPT);
|
||||
|
||||
if (irq == 0xFF) {
|
||||
pci_write8 (pci_info.bus, pci_info.slot, pci_info.func, PCI_INTERRUPT, 14);
|
||||
irq = pci_read8 (pci_info.bus, pci_info.slot, pci_info.func, PCI_INTERRUPT);
|
||||
}
|
||||
|
||||
ioapic_route_irq (IDE_DRIVE_PRIM, irq, 0, thiscpu->lapic_id);
|
||||
DEBUG ("N pcmd=%x, pctrl=%x, irq=%u\n", pcmd, pctrl, irq);
|
||||
} else {
|
||||
pcmd = 0x1F0;
|
||||
pctrl = 0x3F6;
|
||||
|
||||
ioapic_route_irq (IDE_DRIVE_PRIM, 14, 0, thiscpu->lapic_id);
|
||||
DEBUG ("L pcmd=%x, pctrl=%x, irq=%u\n", pcmd, pctrl, 14);
|
||||
}
|
||||
|
||||
if ((progif & 0x04)) {
|
||||
@@ -107,27 +119,40 @@ bool pci_ide_init (struct proc* proc, struct reschedule_ctx* rctx, struct pci_in
|
||||
scmd = (uint16_t)(bar2 & 0xFFFC);
|
||||
sctrl = (uint16_t)(bar3 & 0xFFFC);
|
||||
|
||||
if (sctrl)
|
||||
sctrl += 2;
|
||||
uint8_t irq = pci_read8 (pci_info.bus, pci_info.slot, pci_info.func, PCI_INTERRUPT);
|
||||
|
||||
if (irq == 0xFF) {
|
||||
pci_write8 (pci_info.bus, pci_info.slot, pci_info.func, PCI_INTERRUPT, 15);
|
||||
irq = pci_read8 (pci_info.bus, pci_info.slot, pci_info.func, PCI_INTERRUPT);
|
||||
}
|
||||
|
||||
ioapic_route_irq (IDE_DRIVE_SCND, irq, 0, thiscpu->lapic_id);
|
||||
DEBUG ("N pcmd=%x, pctrl=%x, irq=%u\n", scmd, sctrl, irq);
|
||||
} else {
|
||||
scmd = 0x170;
|
||||
sctrl = 0x376;
|
||||
|
||||
ioapic_route_irq (IDE_DRIVE_SCND, 15, 0, thiscpu->lapic_id);
|
||||
DEBUG ("L pcmd=%x, pctrl=%x, irq=%u\n", scmd, sctrl, 15);
|
||||
}
|
||||
|
||||
uint16_t channels[2][2] = {{pcmd, pctrl}, {scmd, sctrl}};
|
||||
uint16_t channels[2][3] = {{pcmd, pctrl, IDE_DRIVE_PRIM}, {scmd, sctrl, IDE_DRIVE_SCND}};
|
||||
|
||||
for (size_t i = 0; i < lengthof (channels); i++) {
|
||||
uint16_t cmd = channels[i][0];
|
||||
uint16_t ctrl = channels[i][1];
|
||||
uint8_t irq = channels[i][2];
|
||||
|
||||
if (cmd == 0)
|
||||
continue;
|
||||
|
||||
probe.primscnd = i + 1;
|
||||
|
||||
for (size_t dev = 0; dev < 2; dev++) {
|
||||
ide_probe (cmd, ctrl, dev, &probe);
|
||||
|
||||
probe.ctrl = ctrl;
|
||||
probe.io = cmd;
|
||||
probe.irq = irq;
|
||||
|
||||
if ((probe.flags & IDE_PROBE_AVAIL))
|
||||
ide_make_device (proc, rctx, probe);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user