Skip to content

Commit 9993b35

Browse files
committed
pci: remove unused members of the PciDevice trait
We are not really using the `as_any` and `id` members of the PciDevice trait. At the moment, only VirtIO devices and the PCI root port is implementing PciDevice and we are never iterating over the container of PCI devices. Signed-off-by: Babis Chalios <[email protected]>
1 parent 0197652 commit 9993b35

File tree

3 files changed

+3
-48
lines changed

3 files changed

+3
-48
lines changed

src/pci/src/bus.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//
66
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
77

8-
use std::any::Any;
98
use std::collections::HashMap;
109
use std::ops::DerefMut;
1110
use std::sync::{Arc, Barrier, Mutex};
@@ -87,14 +86,6 @@ impl PciDevice for PciRoot {
8786
fn read_config_register(&mut self, reg_idx: usize) -> u32 {
8887
self.config.read_reg(reg_idx)
8988
}
90-
91-
fn as_any_mut(&mut self) -> &mut dyn Any {
92-
self
93-
}
94-
95-
fn id(&self) -> Option<String> {
96-
None
97-
}
9889
}
9990

10091
pub struct PciBus {

src/pci/src/device.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55
//
66
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
77

8-
use std::any::Any;
98
use std::sync::{Arc, Barrier};
109
use std::{io, result};
1110

1211
use vm_allocator::AddressAllocator;
1312

1413
use crate::configuration::{self, PciBarRegionType};
15-
use crate::PciBarConfiguration;
1614

1715
#[derive(Debug, thiserror::Error, displaydoc::Display)]
1816
pub enum Error {
@@ -42,8 +40,8 @@ pub trait PciDevice: Send {
4240
&mut self,
4341
_mmio32_allocator: &mut AddressAllocator,
4442
_mmio64_allocator: &mut AddressAllocator,
45-
) -> Result<Vec<PciBarConfiguration>> {
46-
Ok(Vec::new())
43+
) -> Result<()> {
44+
Ok(())
4745
}
4846

4947
/// Frees the PCI BARs previously allocated with a call to allocate_bars().
@@ -89,12 +87,6 @@ pub trait PciDevice: Send {
8987
fn move_bar(&mut self, _old_base: u64, _new_base: u64) -> result::Result<(), io::Error> {
9088
Ok(())
9189
}
92-
/// Provides a mutable reference to the Any trait. This is useful to let
93-
/// the caller have access to the underlying type behind the trait.
94-
fn as_any_mut(&mut self) -> &mut dyn Any;
95-
96-
/// Optionally returns a unique identifier.
97-
fn id(&self) -> Option<String>;
9890
}
9991

10092
/// This trait defines a set of functions which can be triggered whenever a

src/vmm/src/devices/virtio/transport/pci/device.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
99

10-
use std::any::Any;
1110
use std::cmp;
1211
use std::collections::HashMap;
1312
use std::fmt::{Debug, Formatter};
@@ -870,7 +869,7 @@ impl PciDevice for VirtioPciDevice {
870869
&mut self,
871870
mmio32_allocator: &mut AddressAllocator,
872871
mmio64_allocator: &mut AddressAllocator,
873-
) -> std::result::Result<Vec<PciBarConfiguration>, PciDeviceError> {
872+
) -> std::result::Result<(), PciDeviceError> {
874873
let device_clone = self.device.clone();
875874
let device = device_clone.lock().unwrap();
876875

@@ -905,25 +904,6 @@ impl PciDevice for VirtioPciDevice {
905904
self.add_pci_capabilities()?;
906905
self.bar_region = bar;
907906

908-
Ok(vec![bar])
909-
}
910-
911-
fn free_bars(
912-
&mut self,
913-
mmio32_allocator: &mut AddressAllocator,
914-
mmio64_allocator: &mut AddressAllocator,
915-
) -> std::result::Result<(), PciDeviceError> {
916-
assert_eq!(
917-
self.bar_region.region_type,
918-
PciBarRegionType::Memory64BitRegion
919-
);
920-
921-
let range = RangeInclusive::new(
922-
self.bar_region.addr,
923-
self.bar_region.addr + self.bar_region.size,
924-
)
925-
.unwrap();
926-
mmio64_allocator.free(&range);
927907
Ok(())
928908
}
929909

@@ -1083,14 +1063,6 @@ impl PciDevice for VirtioPciDevice {
10831063

10841064
None
10851065
}
1086-
1087-
fn id(&self) -> Option<String> {
1088-
Some(self.id.clone())
1089-
}
1090-
1091-
fn as_any_mut(&mut self) -> &mut dyn Any {
1092-
self
1093-
}
10941066
}
10951067

10961068
impl BusDevice for VirtioPciDevice {

0 commit comments

Comments
 (0)