diff --git a/devices/src/pci/mod.rs b/devices/src/pci/mod.rs index 07147b4b94..3aab059ab2 100644 --- a/devices/src/pci/mod.rs +++ b/devices/src/pci/mod.rs @@ -14,8 +14,8 @@ mod pci_root; pub use self::ac97::Ac97Dev; pub use self::pci_configuration::{ - PciCapability, PciCapabilityID, PciClassCode, PciConfiguration, PciHeaderType, - PciProgrammingInterface, PciSubclass, + PciBarConfiguration, PciBarPrefetchable, PciBarRegionType, PciCapability, PciCapabilityID, + PciClassCode, PciConfiguration, PciHeaderType, PciProgrammingInterface, PciSubclass, }; pub use self::pci_device::Error as PciDeviceError; pub use self::pci_device::PciDevice; diff --git a/devices/src/pci/pci_configuration.rs b/devices/src/pci/pci_configuration.rs index de96e85cd6..b2bf90daea 100644 --- a/devices/src/pci/pci_configuration.rs +++ b/devices/src/pci/pci_configuration.rs @@ -172,6 +172,32 @@ pub struct PciConfiguration { last_capability: Option<(usize, usize)>, } +/// See pci_regs.h in kernel +#[allow(dead_code)] +#[derive(Copy, Clone)] +pub enum PciBarRegionType { + Memory32BitRegion = 0, + IORegion = 0x01, + Memory64BitRegion = 0x04, +} + +#[allow(dead_code)] +#[derive(Copy, Clone)] +pub enum PciBarPrefetchable { + NotPrefetchable = 0, + Prefetchable = 0x08, +} + +#[allow(dead_code)] +#[derive(Copy, Clone)] +pub struct PciBarConfiguration { + addr: u64, + size: u64, + reg_idx: usize, + region_type: PciBarRegionType, + prefetchable: PciBarPrefetchable, +} + impl PciConfiguration { pub fn new( vendor_id: u16, @@ -369,6 +395,55 @@ impl PciConfiguration { } } +impl Default for PciBarConfiguration { + fn default() -> Self { + PciBarConfiguration { + reg_idx: 0, + addr: 0, + size: 0, + region_type: PciBarRegionType::Memory32BitRegion, + prefetchable: PciBarPrefetchable::NotPrefetchable, + } + } +} + +#[allow(dead_code)] +impl PciBarConfiguration { + pub fn new( + reg_idx: usize, + size: u64, + region_type: PciBarRegionType, + prefetchable: PciBarPrefetchable, + ) -> Self { + PciBarConfiguration { + reg_idx, + addr: 0, + size, + region_type, + prefetchable, + } + } + + pub fn set_register_index(mut self, reg_idx: usize) -> Self { + self.reg_idx = reg_idx; + self + } + + pub fn set_address(mut self, addr: u64) -> Self { + self.addr = addr; + self + } + + pub fn set_size(mut self, size: u64) -> Self { + self.size = size; + self + } + + pub fn get_size(&self) -> u64 { + self.size + } +} + #[cfg(test)] mod tests { use data_model::DataInit;