renamed and cleaned up export header files to match linux convention
[lunaix-os.git] / lunaix-os / hal / ahci / ahci_pci.c
index 7c9288fa3b5b37b0677e6d1ae0005d76f8302a97..2bc0ad979dcdb04a15d3b132b293cb5606053830 100644 (file)
@@ -1,62 +1,75 @@
 #include <lunaix/spike.h>
+#include <lunaix/status.h>
 
 #include <hal/ahci/ahci.h>
 #include <hal/pci.h>
 
 static int
-ahci_pci_bind(struct device_def* def, struct device* dev)
+ahci_pci_create(struct device_def* def, morph_t* morphed)
 {
-    struct pci_device* ahci_dev;
+    struct pci_probe* probe;
+    struct device* dev;
     struct pci_base_addr* bar6;
     struct ahci_driver* ahci_drv;
-    msi_vector_t msiv;
+    irq_t irq;
 
-    ahci_dev = PCI_DEVICE(dev);
-    bar6 = pci_device_bar(ahci_dev, 5);
+    probe = changeling_try_reveal(morphed, pci_probe_morpher);
+    if (!probe) {
+        return EINVAL;
+    }
+
+    bar6 = pci_device_bar(probe, 5);
     assert_msg(pci_bar_mmio_space(bar6), "AHCI: BAR#6 is not MMIO.");
 
     pci_reg_t cmd = 0;
     pci_cmd_set_bus_master(&cmd);
     pci_cmd_set_mmio(&cmd);
     pci_cmd_set_msi(&cmd);
-    pci_apply_command(ahci_dev, cmd);
+    pci_apply_command(probe, cmd);
     
-    assert(pci_capability_msi(ahci_dev));
+    assert(pci_capability_msi(probe));
 
-    msiv = isrm_msialloc(ahci_hba_isr);
-    pci_setup_msi(ahci_dev, msiv);
+    irq = pci_declare_msi_irq(ahci_hba_isr, probe);
+    pci_assign_msi(probe, irq, NULL);
 
     struct ahci_driver_param param = {
         .mmio_base = bar6->start,
         .mmio_size = bar6->size,
-        .ahci_iv = msi_vect(msiv),
+        .irq = irq,
     };
 
     ahci_drv = ahci_driver_init(&param);
-    pci_bind_instance(ahci_dev, ahci_drv);
+    dev = device_allocvol(NULL, ahci_drv);
+
+    device_setname(dev_meta(dev), 
+                   "pci-ahci%d", devclass_mkvar(&def->class));
+
+    pci_bind_instance(probe, dev);
 
     return 0;
 }
 
-static int
-ahci_pci_init(struct device_def* def)
+static bool
+ahci_pci_compat(struct pci_probe* probe)
 {
-    return pci_bind_definition_all(pcidev_def(def));
+    return pci_device_class(probe) == AHCI_HBA_CLASS;
 }
 
-static bool
-ahci_pci_compat(struct pci_device_def* def, 
-                struct pci_device* pcidev)
+static int
+ahci_pci_register(struct device_def* def)
 {
-    return pci_device_class(pcidev) == AHCI_HBA_CLASS;
+    return !pci_register_driver(def, ahci_pci_compat);
 }
 
 
-static struct pci_device_def ahcidef = {
-    .devdef = { .class = DEVCLASS(DEVIF_PCI, DEVFN_STORAGE, DEV_SATA),
-                .name = "Generic AHCI",
-                .init = ahci_pci_init,
-                .bind = ahci_pci_bind },
-    .test_compatibility = ahci_pci_compat
+static struct device_def ahcidef = 
+{
+    def_device_class(GENERIC, STORAGE, SATA),
+    def_device_name("Generic AHCI (pci-bus)"),
+
+    def_on_register(ahci_pci_register),
+    def_on_create(ahci_pci_create),
+
+    def_non_trivial
 };
-EXPORT_PCI_DEVICE(ahci, &ahcidef, load_postboot);
\ No newline at end of file
+EXPORT_DEVICE(ahci, &ahcidef, load_postboot);
\ No newline at end of file