Skip to content

Commit

Permalink
Add HypPciTransport.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Nov 26, 2024
1 parent f2fde34 commit 8b9f116
Show file tree
Hide file tree
Showing 2 changed files with 368 additions and 32 deletions.
62 changes: 31 additions & 31 deletions src/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use core::{
use zerocopy::{FromBytes, Immutable, IntoBytes};

/// The PCI vendor ID for VirtIO devices.
const VIRTIO_VENDOR_ID: u16 = 0x1af4;
pub const VIRTIO_VENDOR_ID: u16 = 0x1af4;

/// The offset to add to a VirtIO device ID to get the corresponding PCI device ID.
const PCI_DEVICE_ID_OFFSET: u16 = 0x1040;
Expand All @@ -35,24 +35,24 @@ const TRANSITIONAL_ENTROPY_SOURCE: u16 = 0x1005;
const TRANSITIONAL_9P_TRANSPORT: u16 = 0x1009;

/// The offset of the bar field within `virtio_pci_cap`.
const CAP_BAR_OFFSET: u8 = 4;
pub(crate) const CAP_BAR_OFFSET: u8 = 4;
/// The offset of the offset field with `virtio_pci_cap`.
const CAP_BAR_OFFSET_OFFSET: u8 = 8;
pub(crate) const CAP_BAR_OFFSET_OFFSET: u8 = 8;
/// The offset of the `length` field within `virtio_pci_cap`.
const CAP_LENGTH_OFFSET: u8 = 12;
pub(crate) const CAP_LENGTH_OFFSET: u8 = 12;
/// The offset of the`notify_off_multiplier` field within `virtio_pci_notify_cap`.
const CAP_NOTIFY_OFF_MULTIPLIER_OFFSET: u8 = 16;
pub(crate) const CAP_NOTIFY_OFF_MULTIPLIER_OFFSET: u8 = 16;

/// Common configuration.
const VIRTIO_PCI_CAP_COMMON_CFG: u8 = 1;
pub const VIRTIO_PCI_CAP_COMMON_CFG: u8 = 1;
/// Notifications.
const VIRTIO_PCI_CAP_NOTIFY_CFG: u8 = 2;
pub const VIRTIO_PCI_CAP_NOTIFY_CFG: u8 = 2;
/// ISR Status.
const VIRTIO_PCI_CAP_ISR_CFG: u8 = 3;
pub const VIRTIO_PCI_CAP_ISR_CFG: u8 = 3;
/// Device specific configuration.
const VIRTIO_PCI_CAP_DEVICE_CFG: u8 = 4;
pub const VIRTIO_PCI_CAP_DEVICE_CFG: u8 = 4;

fn device_type(pci_device_id: u16) -> DeviceType {
pub(crate) fn device_type(pci_device_id: u16) -> DeviceType {
match pci_device_id {
TRANSITIONAL_NETWORK => DeviceType::Network,
TRANSITIONAL_BLOCK => DeviceType::Block,
Expand Down Expand Up @@ -389,34 +389,34 @@ impl Drop for PciTransport {

/// `virtio_pci_common_cfg`, see 4.1.4.3 "Common configuration structure layout".
#[repr(C)]
struct CommonCfg {
device_feature_select: Volatile<u32>,
device_feature: ReadOnly<u32>,
driver_feature_select: Volatile<u32>,
driver_feature: Volatile<u32>,
msix_config: Volatile<u16>,
num_queues: ReadOnly<u16>,
device_status: Volatile<u8>,
config_generation: ReadOnly<u8>,
queue_select: Volatile<u16>,
queue_size: Volatile<u16>,
queue_msix_vector: Volatile<u16>,
queue_enable: Volatile<u16>,
queue_notify_off: Volatile<u16>,
queue_desc: Volatile<u64>,
queue_driver: Volatile<u64>,
queue_device: Volatile<u64>,
pub(crate) struct CommonCfg {
pub device_feature_select: Volatile<u32>,
pub device_feature: ReadOnly<u32>,
pub driver_feature_select: Volatile<u32>,
pub driver_feature: Volatile<u32>,
pub msix_config: Volatile<u16>,
pub num_queues: ReadOnly<u16>,
pub device_status: Volatile<u8>,
pub config_generation: ReadOnly<u8>,
pub queue_select: Volatile<u16>,
pub queue_size: Volatile<u16>,
pub queue_msix_vector: Volatile<u16>,
pub queue_enable: Volatile<u16>,
pub queue_notify_off: Volatile<u16>,
pub queue_desc: Volatile<u64>,
pub queue_driver: Volatile<u64>,
pub queue_device: Volatile<u64>,
}

/// Information about a VirtIO structure within some BAR, as provided by a `virtio_pci_cap`.
#[derive(Clone, Debug, Eq, PartialEq)]
struct VirtioCapabilityInfo {
pub(crate) struct VirtioCapabilityInfo {
/// The bar in which the structure can be found.
bar: u8,
pub bar: u8,
/// The offset within the bar.
offset: u32,
pub offset: u32,
/// The length in bytes of the structure within the bar.
length: u32,
pub length: u32,
}

fn get_bar_region<H: Hal, T, C: ConfigurationAccess>(
Expand Down
Loading

0 comments on commit 8b9f116

Please sign in to comment.