X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/99f2ed669601a61f4f0210e0b481ff877cd9bea7..35a7d633d3f16c1e0539af6ca5d8e7482926cd93:/lunaix-os/hal/ahci/ahci_pci.c diff --git a/lunaix-os/hal/ahci/ahci_pci.c b/lunaix-os/hal/ahci/ahci_pci.c index 7c9288f..4435da1 100644 --- a/lunaix-os/hal/ahci/ahci_pci.c +++ b/lunaix-os/hal/ahci/ahci_pci.c @@ -1,30 +1,35 @@ #include +#include #include #include 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; - 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); + msiv = pci_msi_setup_simple(probe, ahci_hba_isr); struct ahci_driver_param param = { .mmio_base = bar6->start, @@ -33,30 +38,37 @@ ahci_pci_bind(struct device_def* def, struct device* dev) }; ahci_drv = ahci_driver_init(¶m); - 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