Better PCI IDE init with fallback to IO bars
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m26s

This commit is contained in:
2026-03-10 21:56:48 +01:00
parent 3d9503260e
commit 37ec117abc
2 changed files with 56 additions and 32 deletions

View File

@@ -57,35 +57,47 @@ bool pci_ide_init (struct pci_info pci_info) {
struct ide_probe probe;
uint8_t progif = pci_read8 (pci_info.bus, pci_info.slot, pci_info.func, PCI_PROG_IF);
DEBUG ("progif: %s\n", progif_msg[progif]);
switch (progif) {
case 0x80:
ide_probe (0x1F0, 0x3F6, 0, &probe);
uint16_t pcmd, pctrl, scmd, sctrl;
if ((probe.flags & IDE_PROBE_AVAIL))
ide_make_device (probe);
if ((progif & 0x01)) {
pcmd = (uint16_t)(pci_read32 (pci_info.bus, pci_info.slot, pci_info.func, PCI_BAR0) & 0xFFFC);
pctrl = (uint16_t)(pci_read32 (pci_info.bus, pci_info.slot, pci_info.func, PCI_BAR1) & 0xFFFC);
ide_probe (0x1F0, 0x3F6, 1, &probe);
if (pctrl)
pctrl += 2;
} else {
pcmd = 0x1F0;
pctrl = 0x3F6;
}
if ((probe.flags & IDE_PROBE_AVAIL))
ide_make_device (probe);
if ((progif & 0x04)) {
scmd = (uint16_t)(pci_read32 (pci_info.bus, pci_info.slot, pci_info.func, PCI_BAR2) & 0xFFFC);
sctrl = (uint16_t)(pci_read32 (pci_info.bus, pci_info.slot, pci_info.func, PCI_BAR3) & 0xFFFC);
ide_probe (0x170, 0x376, 0, &probe);
if (sctrl)
sctrl += 2;
} else {
scmd = 0x170;
sctrl = 0x376;
}
if ((probe.flags & IDE_PROBE_AVAIL))
ide_make_device (probe);
uint16_t channels[2][2] = {{pcmd, pctrl}, {scmd, sctrl}};
ide_probe (0x170, 0x376, 1, &probe);
for (size_t i = 0; i < lengthof (channels); i++) {
uint16_t cmd = channels[i][0];
uint16_t ctrl = channels[i][1];
if ((probe.flags & IDE_PROBE_AVAIL))
ide_make_device (probe);
if (cmd == 0)
continue;
break;
default:
DEBUG ("PCI unsupported progif=%02x\n", progif);
return false;
for (size_t dev = 0; dev < 2; dev++) {
ide_probe (cmd, ctrl, dev, &probe);
if ((probe.flags & IDE_PROBE_AVAIL))
ide_make_device (probe);
}
}
return true;