diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 03a2328..b4870cf 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -204,7 +204,7 @@ dependencies = [ [[package]] name = "isomorphic_drivers" version = "0.1.0" -source = "git+https://github.com/rcore-os/isomorphic_drivers#fe4af36d5f7bf3ac32be77597ccc61fc8cf8bd98" +source = "git+https://github.com/rcore-os/isomorphic_drivers#b6492b0759e4d6819f6591c3d29ef5ed83138531" dependencies = [ "bit_field 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/kernel/src/drivers/block/ahci.rs b/kernel/src/drivers/block/ahci.rs index 8e256bd..6688019 100644 --- a/kernel/src/drivers/block/ahci.rs +++ b/kernel/src/drivers/block/ahci.rs @@ -43,10 +43,13 @@ impl Driver for AHCIDriver { } } -pub fn init(_irq: Option, header: usize, size: usize) -> Arc { - let ahci = AHCI::new(header, size); - let driver = Arc::new(AHCIDriver(Mutex::new(ahci))); - DRIVERS.write().push(driver.clone()); - BLK_DRIVERS.write().push(driver.clone()); - driver +pub fn init(_irq: Option, header: usize, size: usize) -> Option> { + if let Some(ahci) = AHCI::new(header, size) { + let driver = Arc::new(AHCIDriver(Mutex::new(ahci))); + DRIVERS.write().push(driver.clone()); + BLK_DRIVERS.write().push(driver.clone()); + Some(driver) + } else { + None + } } diff --git a/kernel/src/drivers/bus/pci.rs b/kernel/src/drivers/bus/pci.rs index 7640dfe..48a254f 100644 --- a/kernel/src/drivers/bus/pci.rs +++ b/kernel/src/drivers/bus/pci.rs @@ -174,9 +174,11 @@ pub fn init_driver(dev: &PCIDevice) { let irq = unsafe { enable(dev.loc) }; assert!(len as usize <= PAGE_SIZE); let vaddr = phys_to_virt(addr as usize); - PCI_DRIVERS - .lock() - .insert(dev.loc, ahci::init(irq, vaddr, len as usize)); + if let Some(driver) = ahci::init(irq, vaddr, len as usize) { + PCI_DRIVERS + .lock() + .insert(dev.loc, driver); + } } } _ => {}