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

source

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 be 0 in the current implementation.
  • bus - The PCI bus number. Must be in the range 0..=255.
  • dev - The PCI device number. Must be in the range 0..=31.
  • func - The PCI function number. Must be in the range 0..=7.
§Errors

If any component is out of the valid range, this function will return Error::ComponentOutOfRange.

source

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 resources::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);
source

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.

source

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 resources::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);
source

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-8Bits 7-3Bits 2-0
BusDeviceFunction
source

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-3Bits 2-0
DeviceFunction
source

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-16Bits 15-0
DeviceFunction
source

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

source

pub fn is_root(&self) -> bool

Returns true if the address points to PCI root host-bridge.

This is true if and only if this is the all-zero address (00:0.0).

Trait Implementations§

source§

impl Clone for PciAddress

source§

fn clone(&self) -> PciAddress

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PciAddress

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for PciAddress

source§

fn default() -> PciAddress

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for PciAddress

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

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 resources::PciAddress;

let pci_address = PciAddress::new(0x0000, 0x03, 0x14, 0x1)?;
assert_eq!(pci_address.to_string(), "0000:03:14.1");
source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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 resources::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);
§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(address: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for PciAddress

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for PciAddress

source§

fn cmp(&self, other: &PciAddress) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for PciAddress

source§

fn eq(&self, other: &PciAddress) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for PciAddress

source§

fn partial_cmp(&self, other: &PciAddress) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for PciAddress

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for PciAddress

source§

impl Eq for PciAddress

source§

impl StructuralPartialEq for PciAddress

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,