devices: pci: define a PCI bar configuration struct

We want to support 64-bit BARs and some additional functionality
is required.

BUG=chromium:924405
TEST=compile

Change-Id: I06aba41b6dfb9649437a417a32cb450d19d0d937
Reviewed-on: https://chromium-review.googlesource.com/1480740
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Gurchetan Singh 2019-01-28 15:25:45 -08:00 committed by chrome-bot
parent 8f4d7687ea
commit 948a3ab6b5
2 changed files with 77 additions and 2 deletions

View file

@ -14,8 +14,8 @@ mod pci_root;
pub use self::ac97::Ac97Dev; pub use self::ac97::Ac97Dev;
pub use self::pci_configuration::{ pub use self::pci_configuration::{
PciCapability, PciCapabilityID, PciClassCode, PciConfiguration, PciHeaderType, PciBarConfiguration, PciBarPrefetchable, PciBarRegionType, PciCapability, PciCapabilityID,
PciProgrammingInterface, PciSubclass, PciClassCode, PciConfiguration, PciHeaderType, PciProgrammingInterface, PciSubclass,
}; };
pub use self::pci_device::Error as PciDeviceError; pub use self::pci_device::Error as PciDeviceError;
pub use self::pci_device::PciDevice; pub use self::pci_device::PciDevice;

View file

@ -172,6 +172,32 @@ pub struct PciConfiguration {
last_capability: Option<(usize, usize)>, 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 { impl PciConfiguration {
pub fn new( pub fn new(
vendor_id: u16, 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)] #[cfg(test)]
mod tests { mod tests {
use data_model::DataInit; use data_model::DataInit;