Struct mycelium_pci::device::Header
source · #[repr(C)]pub struct Header {
pub id: RawIds,
pub command: Command,
pub status: Status,
pub revision_id: u8,
pub cache_line_size: u8,
pub latency_timer: u8,
pub bist: Bist,
/* private fields */
}
Expand description
A PCI device header.
This stores data common to all PCI devices, whether they are standard PCI devices, PCI-to-PCI bridges, or PCI-to-CardBus bridges.
The header has the following layout:
Word | Bits 31-24 | Bits 23-16 | Bits 15-8 | Bits 7-0 |
---|---|---|---|---|
0x0 | Device ID | … | Vendor ID | … |
0x1 | Status | … | Command | … |
0x2 | Class | Subclass | ProgIf | Revision ID |
0x3 | BIST register | HeaderType | Latency timer | Cache line size |
Much of the documentation for this struct’s fields was copied from the OSDev Wiki.
Fields§
§id: RawIds
The device’s raw vendor ID and device ID.
Use the Header::id
method to attempt to resolve the raw numeric IDs
to a known vendor and device in the PCI IDs database.
command: Command
The device’s Command
register.
This register provides control over a device’s ability to generate and respond to PCI cycles. When a 0 is written to this register, the device is disconnected from the PCI bus. Other values may be written to this register to send other commands, depending on the device.
status: Status
The device’s Status
register.
This register can be read from to access status information about PCI events.
revision_id: u8
Specifies a revision identifier for a particular device.
Revision IDs are allocated by the device’s vendor.
cache_line_size: u8
Specifies the system cache line size in 32-bit units.
A device can limit the number of cacheline sizes it can support, if a unsupported value is written to this field, the device will behave as if a value of 0 was written.
latency_timer: u8
Specifies the latency timer in units of PCI bus clocks.
bist: Bist
A read-write register for running the device’s Built-In Self Test (BIST).
Implementations§
source§impl Header
impl Header
sourcepub fn header_type(&self) -> Result<HeaderType, UnexpectedValue<u8>>
pub fn header_type(&self) -> Result<HeaderType, UnexpectedValue<u8>>
Returns the device’s header type, or an error if the header type code is invalid.
This value identifies the device kind, and the layout of the rest of the device’s PCI configuration space header.
A device is one of the following:
- A standard PCI device (
StandardDetails
) - A PCI-to-PCI bridge (
PciBridgeDetails
) - A PCI-to-CardBus bridge (
CardBusDetails
)
sourcepub fn is_multifunction(&self) -> bool
pub fn is_multifunction(&self) -> bool
Returns true
if this device has multiple functions.
sourcepub fn id(&self) -> Id
pub fn id(&self) -> Id
Returns the device’s Id
.
This will attempt to resolve the device’s vendor ID and
device ID in the PCI IDs database. If the device ID can be
resolved, an Id::Known
is returned. Otherwise, if the device’s
vendor ID or device ID does not exist in the PCI ID database, an
Id::Unknown
is returned.
sourcepub fn classes(&self) -> Result<Classes, UnexpectedValue<RawClasses>>
pub fn classes(&self) -> Result<Classes, UnexpectedValue<RawClasses>>
sourcepub fn class(&self) -> Result<Class, UnexpectedValue<u8>>
pub fn class(&self) -> Result<Class, UnexpectedValue<u8>>
Returns the device’s Class
.
The class indicates what general category of device (e.g. a display
controller, network controller, etc) this header describes. The class
value is used to determine the meaning of the Subclass
code, which
describes a subcategory of device within that class.
Returns
Ok
(
Class
)
if the header’s class code exists in the PCI ID database.Err
(
error::UnexpectedValue
)
if the header’s class code was not present in the PCI ID database. This generally indicates that the device header was read incorrectly or the device is malfunctioning, as all devices should have a known class code.
sourcepub fn subclass(&self) -> Result<Subclass, UnexpectedValue<u8>>
pub fn subclass(&self) -> Result<Subclass, UnexpectedValue<u8>>
Returns the device’s Subclass
.
The subclass describes a more specific category of device within a
Class
.
Returns
Ok
(
Subclass
)
if the header’s class and subclass codes exist in the PCI ID database.Err
(
error::UnexpectedValue
)
if the header’s class or subclass code was not present in the PCI ID database. This generally indicates that the device header was read incorrectly or the device is malfunctioning, as all devices should have known class and subclass codes.
sourcepub fn prog_if(&self) -> Result<ProgIf, UnexpectedValue<u8>>
pub fn prog_if(&self) -> Result<ProgIf, UnexpectedValue<u8>>
Returns the register-level programming interface (“prog IF”) for this device, or an error if the device’s class or subclass code (which are necessary for determining the programming interface) could not be resolved.
sourcepub fn raw_prog_if(&self) -> u8
pub fn raw_prog_if(&self) -> u8
Returns the raw programming interface code of this device.
This can be used with the Subclass::prog_if
method.