#include #include #include "pci/pci.h" #include "storedev/storedev.h" #include "storedev/atasd.h" #include "kprintf.h" #define TAG "ata" #define ATA_PROBE(STRING, IOBASE, CTRLBASE, S_OR_M) \ ps = ata_probesize_bytes((IOBASE), (CTRLBASE), (S_OR_M)); \ if (ps > 0) { \ AtaSdInitExtra extra = { \ .devno = (S_OR_M), \ .capacity = ps, \ .iobase = (IOBASE), \ .ctrlbase = (CTRLBASE), \ }; \ storedev_create(STOREDEV_ATASD, (STRING), (void *)&extra); \ } #define ATA_MASTER 0x00 #define ATA_SLAVE 0x01 #define ATA_PRIM_IO 0x1F0 #define ATA_PRIM_CTRL 0x3F6 #define ATA_SCND_IO 0x170 #define ATA_SCND_CTRL 0x376 void pci_ata_init(void) { PciDev dev = pci_getdev(0x8086, 0x7010, -1); if (!dev.bits) { return; } static const char *progif_msg[] = { [0x00] = "ISA Compatibility mode-only controller", [0x05] = "PCI native mode-only controller", [0x0A] = "ISA Compatibility mode controller, supports both channels switched to PCI native mode", [0x0F] = "PCI native mode controller, supports both channels switched to ISA compatibility mode", [0x80] = "ISA Compatibility mode-only controller, supports bus mastering", [0x85] = "PCI native mode-only controller, supports bus mastering", [0x8A] = "ISA Compatibility mode controller, supports both channels switched to PCI native mode, supports bus mastering", [0x8F] = "PCI native mode controller, supports both channels switched to ISA compatibility mode, supports bus mastering", }; uint8_t progif = pci_read8(dev, PCI_PROGIF); LOG("pci/"TAG, "progif=0x%02x\n", progif); LOG("pci/"TAG, "DESCRIPTION: %s\n", progif_msg[progif]); switch (progif) { case 0x80: { uint64_t ps; ATA_PROBE("atasd0m", ATA_PRIM_IO, ATA_PRIM_CTRL, ATA_MASTER); ATA_PROBE("atasd0s", ATA_PRIM_IO, ATA_PRIM_CTRL, ATA_SLAVE); ATA_PROBE("atasd1m", ATA_SCND_IO, ATA_SCND_CTRL, ATA_MASTER); ATA_PROBE("atasd2s", ATA_SCND_IO, ATA_SCND_CTRL, ATA_SLAVE); } break; default: LOG("pci/"TAG, "Unsupported progif=0x%02x\n", progif); break; } }