feat: support user-spcae pci rescan
[lunaix-os.git] / lunaix-os / hal / ahci / ahci.c
index c20e21dffe9bb248ae7f6f5c043b5556c34bab43..61ea95b511dc28a5d658bd9d19d951aae94e153b 100644 (file)
@@ -31,6 +31,7 @@
 #define HBA_CLB_SIZE 1024
 
 #define HBA_MY_IE (HBA_PxINTR_DHR | HBA_PxINTR_TFE | HBA_PxINTR_OF)
 #define HBA_CLB_SIZE 1024
 
 #define HBA_MY_IE (HBA_PxINTR_DHR | HBA_PxINTR_TFE | HBA_PxINTR_OF)
+#define AHCI_DEVCLASS DEVCLASS(DEVIF_PCI, DEVFN_STORAGE, DEV_SATA)
 
 // #define DO_HBA_FULL_RESET
 
 
 // #define DO_HBA_FULL_RESET
 
@@ -43,6 +44,8 @@ static char sata_ifs[][20] = { "Not detected",
                                "SATA II (3.0Gbps)",
                                "SATA III (6.0Gbps)" };
 
                                "SATA II (3.0Gbps)",
                                "SATA III (6.0Gbps)" };
 
+static struct devclass ahci_class = AHCI_DEVCLASS;
+
 extern void
 ahci_fsexport(struct block_dev* bdev, void* fs_node);
 
 extern void
 ahci_fsexport(struct block_dev* bdev, void* fs_node);
 
@@ -197,7 +200,7 @@ ahci_driver_init(struct device_def* def, struct device* dev)
         ahci_register_device(hbadev);
     }
 
         ahci_register_device(hbadev);
     }
 
-    dev->underlay = ahci_drv;
+    pci_bind_instance(ahci_dev, ahci_drv);
     return 0;
 }
 
     return 0;
 }
 
@@ -209,6 +212,7 @@ ahci_register_device(struct hba_device* hbadev)
 
     bdev->end_lba = hbadev->max_lba;
     bdev->blk_size = hbadev->block_size;
 
     bdev->end_lba = hbadev->max_lba;
     bdev->blk_size = hbadev->block_size;
+    bdev->class = &ahci_class;
 
     block_mount(bdev, ahci_fsexport);
 }
 
     block_mount(bdev, ahci_fsexport);
 }
@@ -440,10 +444,9 @@ achi_register_ops(struct hba_port* port)
 
 static struct pci_device_def ahcidef = {
     .dev_class = AHCI_HBA_CLASS,
 
 static struct pci_device_def ahcidef = {
     .dev_class = AHCI_HBA_CLASS,
-    .dev_vendor = PCI_ID_ANY,
-    .dev_id = PCI_ID_ANY,
-    .devdef = { .class = DEVCLASS(DEVIF_PCI, DEVFN_STORAGE, DEV_SATA, 0),
-                .name = "SATA AHCI",
-                .init_for = ahci_driver_init }
+    .ident_mask = PCI_MATCH_ANY,
+    .devdef = { .class = DEVCLASS(DEVIF_PCI, DEVFN_STORAGE, DEV_SATA),
+                .name = "Serial ATA Controller",
+                .bind = ahci_driver_init }
 };
 };
-EXPORT_DEVICE(ahci, &ahcidef.devdef, load_on_demand);
\ No newline at end of file
+EXPORT_PCI_DEVICE(ahci, &ahcidef);
\ No newline at end of file