Struct devices::pci::pci_address::PciAddress
source · pub struct PciAddress {
pub bus: u8,
pub dev: u8,
pub func: u8,
}
Expand description
PCI Device Address, AKA Bus:Device.Function
Fields§
§bus: u8
Bus number, in the range 0..=255
.
dev: u8
Device number, in the range 0..=31
.
func: u8
Function number, in the range 0..=7
.
Implementations§
source§impl PciAddress
impl PciAddress
sourcepub fn new(domain: u32, bus: u32, dev: u32, func: u32) -> Result<Self, Error>
pub fn new(domain: u32, bus: u32, dev: u32, func: u32) -> Result<Self, Error>
Construct PciAddress
from separate domain, bus, device, and function numbers.
§Arguments
domain
- The PCI domain number. Must be0
in the current implementation.bus
- The PCI bus number. Must be in the range0..=255
.dev
- The PCI device number. Must be in the range0..=31
.func
- The PCI function number. Must be in the range0..=7
.
§Errors
If any component is out of the valid range, this function will return
Error::ComponentOutOfRange
.
sourcepub fn from_config_address(
config_address: u32,
register_bits_num: usize
) -> (Self, usize)
pub fn from_config_address( config_address: u32, register_bits_num: usize ) -> (Self, usize)
Decode a PciAddress
and register index from a CONFIG_ADDRESS value.
The configuration address should be in the format used with the PCI CAM or ECAM configuration space access mechanisms, with the lowest bits encoding a register index and the bits above that encoding the PCI function (3 bits), device (5 bits), and bus (8 bits). The low two bits of the configuration address, which are technically part of the register number, are ignored, since PCI configuration space accesses must be DWORD (4-byte) aligned.
On success, returns a PciAddress
and the extracted register index in DWORDs.
§Arguments
config_address
- The PCI configuration address.register_bits_num
- The size of the register value in bits.
§Example
use devices::PciAddress;
let (pci_address, register_index) = PciAddress::from_config_address(0x32a354, 8);
assert_eq!(pci_address.bus, 0x32);
assert_eq!(pci_address.dev, 0x14);
assert_eq!(pci_address.func, 0x3);
assert_eq!(register_index, 0x15);
sourcepub fn from_path(path: &Path) -> Result<Self, Error>
pub fn from_path(path: &Path) -> Result<Self, Error>
Construct PciAddress
from a system PCI path
§Arguments
path
- The system PCI path. The file name of this path must be a valid PCI address.
§Errors
If the path given is invalid or filename is an invalid PCI address, this function will return error.
sourcepub fn to_config_address(
&self,
register: usize,
register_bits_num: usize
) -> u32
pub fn to_config_address( &self, register: usize, register_bits_num: usize ) -> u32
Encode PciAddress
into CONFIG_ADDRESS value.
See PciAddress::from_config_address()
for details of the encoding.
§Arguments
register
- The register index in DWORDs.register_bits_num
- The width of the register field, not including the two lowest bits.
§Example
use devices::PciAddress;
let pci_address = PciAddress::new(0x0000, 0x32, 0x14, 0x3)?;
let config_address = pci_address.to_config_address(0x15, 8);
assert_eq!(config_address, 0x32a354);
sourcepub fn to_u32(&self) -> u32
pub fn to_u32(&self) -> u32
Convert B:D:F PCI address to unsigned 32 bit integer.
The bus, device, and function numbers are packed into an integer as follows:
Bits 15-8 | Bits 7-3 | Bits 2-0 |
---|---|---|
Bus | Device | Function |
sourcepub fn devfn(&self) -> u8
pub fn devfn(&self) -> u8
Convert D:F PCI address to a linux style devfn.
The device and function numbers are packed into an u8 as follows:
Bits 7-3 | Bits 2-0 |
---|---|
Device | Function |
sourcepub fn acpi_adr(&self) -> u32
pub fn acpi_adr(&self) -> u32
Convert D:F PCI address to an ACPI _ADR.
The device and function numbers are packed into an u32 as follows:
Bits 31-16 | Bits 15-0 |
---|---|
Device | Function |
sourcepub fn pme_requester_id(&self) -> u16
pub fn pme_requester_id(&self) -> u16
Convert B:D:F PCI address to a PCI PME Requester ID.
The output is identical to to_u32()
except that only the lower 16 bits are needed
Trait Implementations§
source§impl Clone for PciAddress
impl Clone for PciAddress
source§fn clone(&self) -> PciAddress
fn clone(&self) -> PciAddress
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PciAddress
impl Debug for PciAddress
source§impl Default for PciAddress
impl Default for PciAddress
source§fn default() -> PciAddress
fn default() -> PciAddress
source§impl<'de> Deserialize<'de> for PciAddress
impl<'de> Deserialize<'de> for PciAddress
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl Display for PciAddress
impl Display for PciAddress
Convert PciAddress
to a human-readable string format.
The display format will always include the domain component, even if it is zero.
§Example
use devices::PciAddress;
let pci_address = PciAddress::new(0x0000, 0x03, 0x14, 0x1)?;
assert_eq!(pci_address.to_string(), "0000:03:14.1");
source§impl FromStr for PciAddress
impl FromStr for PciAddress
Construct PciAddress
from string “[domain:]bus:device.function”.
Each component of the address is unprefixed hexadecimal.
§Example
use std::str::FromStr;
use devices::PciAddress;
let pci_address = PciAddress::from_str("d7:15.4")?;
assert_eq!(pci_address.bus, 0xd7);
assert_eq!(pci_address.dev, 0x15);
assert_eq!(pci_address.func, 0x4);
source§impl Hash for PciAddress
impl Hash for PciAddress
source§impl Ord for PciAddress
impl Ord for PciAddress
source§fn cmp(&self, other: &PciAddress) -> Ordering
fn cmp(&self, other: &PciAddress) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for PciAddress
impl PartialEq for PciAddress
source§fn eq(&self, other: &PciAddress) -> bool
fn eq(&self, other: &PciAddress) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for PciAddress
impl PartialOrd for PciAddress
source§fn partial_cmp(&self, other: &PciAddress) -> Option<Ordering>
fn partial_cmp(&self, other: &PciAddress) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for PciAddress
impl Serialize for PciAddress
impl Copy for PciAddress
impl Eq for PciAddress
impl StructuralPartialEq for PciAddress
Auto Trait Implementations§
impl RefUnwindSafe for PciAddress
impl Send for PciAddress
impl Sync for PciAddress
impl Unpin for PciAddress
impl UnwindSafe for PciAddress
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.