1 #include <lunaix/spike.h>
3 #include <hal/ahci/ahci.h>
7 ahci_pci_bind(struct device_def* def, struct device* dev)
9 struct pci_device* ahci_dev;
10 struct pci_base_addr* bar6;
11 struct ahci_driver* ahci_drv;
13 ahci_dev = PCI_DEVICE(dev);
14 bar6 = pci_device_bar(ahci_dev, 5);
15 assert_msg(pci_bar_mmio_space(bar6), "AHCI: BAR#6 is not MMIO.");
18 pci_cmd_set_bus_master(&cmd);
19 pci_cmd_set_mmio(&cmd);
20 pci_cmd_set_msi(&cmd);
21 pci_apply_command(ahci_dev, cmd);
24 if (pci_capability_msi(ahci_dev)) {
25 iv = isrm_ivexalloc(ahci_hba_isr);
26 pci_setup_msi(ahci_dev, iv);
29 iv = pci_intr_irq(ahci_dev);
30 iv = isrm_bindirq(iv, ahci_hba_isr);
33 struct ahci_driver_param param = {
34 .mmio_base = bar6->start,
35 .mmio_size = bar6->size,
39 ahci_drv = ahci_driver_init(¶m);
40 pci_bind_instance(ahci_dev, ahci_drv);
46 ahci_pci_init(struct device_def* def)
48 return pci_bind_definition_all(pcidev_def(def));
52 ahci_pci_compat(struct pci_device_def* def,
53 struct pci_device* pcidev)
55 return pci_device_class(pcidev) == AHCI_HBA_CLASS;
59 static struct pci_device_def ahcidef = {
60 .devdef = { .class = DEVCLASS(DEVIF_PCI, DEVFN_STORAGE, DEV_SATA),
61 .name = "Generic AHCI",
62 .init = ahci_pci_init,
63 .bind = ahci_pci_bind },
64 .test_compatibility = ahci_pci_compat
66 EXPORT_PCI_DEVICE(ahci, &ahcidef, load_postboot);