Browse Source

Merge pull request #55 from rcore-os/reset

Reset device when the transport is dropped.
chyyuu 2 years ago
parent
commit
66829b6363
2 changed files with 14 additions and 0 deletions
  1. 7 0
      src/transport/mmio.rs
  2. 7 0
      src/transport/pci.rs

+ 7 - 0
src/transport/mmio.rs

@@ -490,3 +490,10 @@ impl Transport for MmioTransport {
         Ok(NonNull::new((self.header.as_ptr() as usize + CONFIG_SPACE_OFFSET) as _).unwrap())
     }
 }
+
+impl Drop for MmioTransport {
+    fn drop(&mut self) {
+        // Reset the device when the transport is dropped.
+        self.set_status(DeviceStatus::empty())
+    }
+}

+ 7 - 0
src/transport/pci.rs

@@ -338,6 +338,13 @@ impl Transport for PciTransport {
     }
 }
 
+impl Drop for PciTransport {
+    fn drop(&mut self) {
+        // Reset the device when the transport is dropped.
+        self.set_status(DeviceStatus::empty())
+    }
+}
+
 /// `virtio_pci_common_cfg`, see 4.1.4.3 "Common configuration structure layout".
 #[repr(C)]
 struct CommonCfg {