diff --git a/alioth/src/device/pvpanic.rs b/alioth/src/device/pvpanic.rs index d49f1bd..7bfe268 100644 --- a/alioth/src/device/pvpanic.rs +++ b/alioth/src/device/pvpanic.rs @@ -55,7 +55,7 @@ impl Mmio for PvPanicBar { #[derive(Debug)] pub struct PvPanic { - pub config: Arc, + pub config: EmulatedConfig, } impl PvPanic { @@ -82,9 +82,7 @@ impl PvPanic { let mut bars = [const { PciBar::Empty }; 6]; bars[0] = bar0; let config = EmulatedConfig::new_device(header, bar_masks, bars, PciCapList::new()); - PvPanic { - config: Arc::new(config), - } + PvPanic { config } } } @@ -95,8 +93,8 @@ impl Default for PvPanic { } impl Pci for PvPanic { - fn config(&self) -> Arc { - self.config.clone() + fn config(&self) -> &dyn PciConfig { + &self.config } fn reset(&self) -> pci::Result<()> { diff --git a/alioth/src/pci/host_bridge.rs b/alioth/src/pci/host_bridge.rs index c48e629..434b960 100644 --- a/alioth/src/pci/host_bridge.rs +++ b/alioth/src/pci/host_bridge.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::sync::Arc; - use crate::pci; use crate::pci::cap::PciCapList; use crate::pci::config::{CommonHeader, DeviceHeader, EmulatedConfig, HeaderType, PciConfig}; @@ -21,7 +19,7 @@ use crate::pci::{Pci, PciBar}; #[derive(Debug)] pub struct HostBridge { - pub config: Arc, + pub config: EmulatedConfig, } impl Default for HostBridge { @@ -45,15 +43,13 @@ impl HostBridge { }; let bars = [const { PciBar::Empty }; 6]; let config = EmulatedConfig::new_device(header, [0; 6], bars, PciCapList::new()); - HostBridge { - config: Arc::new(config), - } + HostBridge { config } } } impl Pci for HostBridge { - fn config(&self) -> Arc { - self.config.clone() + fn config(&self) -> &dyn PciConfig { + &self.config } fn reset(&self) -> pci::Result<()> { diff --git a/alioth/src/pci/pci.rs b/alioth/src/pci/pci.rs index 7a15457..7a3f374 100644 --- a/alioth/src/pci/pci.rs +++ b/alioth/src/pci/pci.rs @@ -61,7 +61,7 @@ pub enum Error { pub type Result = std::result::Result; pub trait Pci: Debug + Send + Sync + 'static { - fn config(&self) -> Arc; + fn config(&self) -> &dyn PciConfig; fn reset(&self) -> Result<()>; } diff --git a/alioth/src/pci/segment.rs b/alioth/src/pci/segment.rs index 5a80f0d..3814c6c 100644 --- a/alioth/src/pci/segment.rs +++ b/alioth/src/pci/segment.rs @@ -26,7 +26,7 @@ use crate::pci::{Bdf, Pci, PciDevice, Result}; struct EmptyDevice; impl Pci for EmptyDevice { - fn config(&self) -> Arc { + fn config(&self) -> &dyn PciConfig { unreachable!() } diff --git a/alioth/src/vfio/pci.rs b/alioth/src/vfio/pci.rs index f10132b..cd4fbfa 100644 --- a/alioth/src/vfio/pci.rs +++ b/alioth/src/vfio/pci.rs @@ -387,7 +387,7 @@ pub struct VfioPciDev where M: MsiSender, { - config: Arc>, + config: PciPthConfig, msix_table: Arc>, } @@ -396,8 +396,8 @@ where D: Device, M: MsiSender, { - fn config(&self) -> Arc { - self.config.clone() + fn config(&self) -> &dyn PciConfig { + &self.config } fn reset(&self) -> pci::Result<()> { @@ -538,7 +538,7 @@ where } Ok(VfioPciDev { - config: Arc::new(PciPthConfig { + config: PciPthConfig { header: EmulatedHeader { data: Arc::new(RwLock::new(HeaderData { header: config_header, @@ -555,7 +555,7 @@ where offset: region_config.offset, size: region_config.size as usize, }, - }), + }, msix_table, }) } diff --git a/alioth/src/virtio/pci.rs b/alioth/src/virtio/pci.rs index dae0aca..219c82f 100644 --- a/alioth/src/virtio/pci.rs +++ b/alioth/src/virtio/pci.rs @@ -635,7 +635,7 @@ where E: IoeventFd, { pub dev: VirtioDevice, E>, - pub config: Arc, + pub config: EmulatedConfig, pub registers: Arc>, } @@ -854,9 +854,7 @@ where } } - let config = Arc::new(EmulatedConfig::new_device( - header, bar_masks, bars, cap_list, - )); + let config = EmulatedConfig::new_device(header, bar_masks, bars, cap_list); Ok(VirtioPciDevice { dev, @@ -872,8 +870,8 @@ where D: Virtio, E: IoeventFd, { - fn config(&self) -> Arc { - self.config.clone() + fn config(&self) -> &dyn PciConfig { + &self.config } fn reset(&self) -> pci::Result<()> { self.registers.wake_up_dev(WakeEvent::Reset); diff --git a/alioth/src/vm.rs b/alioth/src/vm.rs index 93c94c6..842b8e6 100644 --- a/alioth/src/vm.rs +++ b/alioth/src/vm.rs @@ -212,10 +212,8 @@ where } else { self.board.pci_bus.reserve(None, name.clone()).unwrap() }; - let config = dev.dev.config(); + dev.dev.config().get_header().set_bdf(bdf); self.board.pci_bus.add(bdf, dev); - let header = config.get_header(); - header.set_bdf(bdf); log::info!("{bdf}: device: {name}"); Ok(()) }