Skip to content

Commit

Permalink
refactor(virtio-spec): rename pci::Cap to pci::CapCfgType
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Jun 6, 2024
1 parent d450c15 commit c6eab3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
26 changes: 13 additions & 13 deletions src/drivers/virtio/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::{mem, ptr};

use pci_types::capability::PciCapability;
use virtio_spec::pci::{
CommonCfg, CommonCfgVolatileFieldAccess, CommonCfgVolatileWideFieldAccess,
CapCfgType, CommonCfg, CommonCfgVolatileFieldAccess, CommonCfgVolatileWideFieldAccess,
IsrStatus as IsrStatusRaw,
};
use virtio_spec::DeviceStatus;
Expand Down Expand Up @@ -45,7 +45,7 @@ pub struct Origin {
/// Maps a given device specific pci configuration structure and
/// returns a static reference to it.
pub fn map_dev_cfg<T>(cap: &PciCap) -> Option<&'static mut T> {
if cap.cfg_type != virtio_spec::pci::Cap::DeviceCfg {
if cap.cfg_type != CapCfgType::Device {
error!("Capability of device config has wrong id. Mapping not possible...");
return None;
};
Expand Down Expand Up @@ -84,10 +84,10 @@ pub fn map_dev_cfg<T>(cap: &PciCap) -> Option<&'static mut T> {
/// as it is not directly mapped into address space from PCI device
/// configuration space.
/// Therefore the struct only contains necessary information to map
/// corresponding config type (`pci::Cap`) into address space.
/// corresponding config type into address space.
#[derive(Clone)]
pub struct PciCap {
cfg_type: virtio_spec::pci::Cap,
cfg_type: CapCfgType,
bar: PciBar,
id: u8,
offset: MemOff,
Expand Down Expand Up @@ -215,7 +215,7 @@ impl PartialEq for PciCapRaw {
/// a given Virtio PCI device.
///
/// As Virtio's PCI devices are allowed to present multiple capability
/// structures of the same config type (`pci::Cap`), the structure
/// structures of the same config type, the structure
/// provides a driver with all capabilities, sorted in descending priority,
/// allowing the driver to choose.
/// The structure contains a special dev_cfg_list field, a vector holding
Expand Down Expand Up @@ -939,9 +939,9 @@ fn read_caps(
_ => None,
})
.map(|capability| (capability.offset, read_cap_raw(device, capability.offset)))
.filter(|(_ptr, capability)| capability.cfg_type != virtio_spec::pci::Cap::PciCfg.into())
.filter(|(_ptr, capability)| capability.cfg_type != CapCfgType::Pci.into())
.map(|(ptr, capability)| PciCap {
cfg_type: virtio_spec::pci::Cap::from(capability.cfg_type),
cfg_type: CapCfgType::from(capability.cfg_type),
bar: *bars
.iter()
.find(|bar| bar.index == capability.bar_index)
Expand Down Expand Up @@ -1008,36 +1008,36 @@ pub(crate) fn map_caps(device: &PciDevice<PciConfigRegion>) -> Result<UniCapsCol
// Map Caps in virtual memory
for pci_cap in cap_list {
match pci_cap.cfg_type {
virtio_spec::pci::Cap::CommonCfg => match pci_cap.map_common_cfg() {
CapCfgType::Common => match pci_cap.map_common_cfg() {
Some(cap) => caps.add_cfg_common(ComCfg::new(cap, pci_cap.id)),
None => error!(
"Common config capability with id {}, of device {:x}, could not be mapped!",
pci_cap.id, device_id
),
},
virtio_spec::pci::Cap::NotifyCfg => match NotifCfg::new(&pci_cap) {
CapCfgType::Notify => match NotifCfg::new(&pci_cap) {
Some(notif) => caps.add_cfg_notif(notif),
None => error!(
"Notification config capability with id {}, of device {:x} could not be used!",
pci_cap.id, device_id
),
},
virtio_spec::pci::Cap::IsrCfg => match pci_cap.map_isr_status() {
CapCfgType::Isr => match pci_cap.map_isr_status() {
Some(isr_stat) => caps.add_cfg_isr(IsrStatus::new(isr_stat, pci_cap.id)),
None => error!(
"ISR status config capability with id {}, of device {:x} could not be used!",
pci_cap.id, device_id
),
},
virtio_spec::pci::Cap::PciCfg => caps.add_cfg_alt(PciCfgAlt::new(&pci_cap)),
virtio_spec::pci::Cap::SharedMemoryCfg => match ShMemCfg::new(&pci_cap) {
CapCfgType::Pci => caps.add_cfg_alt(PciCfgAlt::new(&pci_cap)),
CapCfgType::SharedMemory => match ShMemCfg::new(&pci_cap) {
Some(sh_mem) => caps.add_cfg_sh_mem(sh_mem),
None => error!(
"Shared Memory config capability with id {}, of device {:x} could not be used!",
pci_cap.id, device_id
),
},
virtio_spec::pci::Cap::DeviceCfg => caps.add_cfg_dev(pci_cap),
CapCfgType::Device => caps.add_cfg_dev(pci_cap),

// PCI's configuration space is allowed to hold other structures, which are not virtio specific and are therefore ignored
// in the following
Expand Down
16 changes: 8 additions & 8 deletions virtio-spec/src/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,34 +160,34 @@ virtio_bitflags! {
#[derive(IntoPrimitive, FromPrimitive, PartialEq, Eq, Clone, Copy, Debug)]
#[non_exhaustive]
#[repr(u8)]
pub enum Cap {
pub enum CapCfgType {
/// Common configuration
#[doc(alias = "VIRTIO_PCI_CAP_COMMON_CFG")]
CommonCfg = 1,
Common = 1,

/// Notifications
#[doc(alias = "VIRTIO_PCI_CAP_NOTIFY_CFG")]
NotifyCfg = 2,
Notify = 2,

/// ISR Status
#[doc(alias = "VIRTIO_PCI_CAP_ISR_CFG")]
IsrCfg = 3,
Isr = 3,

/// Device specific configuration
#[doc(alias = "VIRTIO_PCI_CAP_DEVICE_CFG")]
DeviceCfg = 4,
Device = 4,

/// PCI configuration access
#[doc(alias = "VIRTIO_PCI_CAP_PCI_CFG")]
PciCfg = 5,
Pci = 5,

/// Shared memory region
#[doc(alias = "VIRTIO_PCI_CAP_SHARED_MEMORY_CFG")]
SharedMemoryCfg = 8,
SharedMemory = 8,

/// Vendor-specific data
#[doc(alias = "VIRTIO_PCI_CAP_VENDOR_CFG")]
VencodCfg = 9,
Vendor = 9,

/// Unknown device
#[num_enum(catch_all)]
Expand Down

0 comments on commit c6eab3b

Please sign in to comment.