Skip to content

Commit

Permalink
wip: msi cap
Browse files Browse the repository at this point in the history
Signed-off-by: Changyuan Lyu <[email protected]>
  • Loading branch information
Lencerf committed Dec 11, 2024
1 parent 60452aa commit 844321e
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 53 deletions.
15 changes: 9 additions & 6 deletions alioth/src/pci/cap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,26 @@ bitfield! {
impl Debug;
pub enable, set_enable: 0;
pub multi_msg_cap, set_multi_msg_cap: 3, 1;
pub multi_msg_enable, set_multi_msg_enable: 6, 4;
pub addr_64, set_addr_64: 7;
pub per_vector_masking, set_per_vector_masking: 8;
pub multi_msg, set_multi_msg: 6, 4;
pub addr_64_cap, set_addr_64_cap: 7;
pub per_vector_masking_cap, set_per_vector_masking_cap: 8;
pub ext_msg_data_cap, set_ext_msg_data_cap: 9;
pub ext_msg_data_enable, set_ext_msg_data_enable: 10;
pub ext_msg_data, set_ext_msg_data: 10;
}

impl MsiMsgCtrl {
pub fn cap_size(&self) -> u8 {
let mut size = 12;
if self.addr_64() {
if self.addr_64_cap() {
size += 4;
}
if self.per_vector_masking() {
if self.per_vector_masking_cap() {
size += 8;
}
size
}

pub const WRITABLE: u16 = 1 | 0xb111 << 4 | 1 << 10;
}

#[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, Layout)]
Expand All @@ -112,6 +114,7 @@ pub struct MsiCapHdr {
pub header: PciCapHdr,
pub control: MsiMsgCtrl,
}
impl_mmio_for_zerocopy!(MsiCapHdr);

bitfield! {
#[derive(Copy, Clone, Default, FromBytes, Immutable, IntoBytes, KnownLayout)]
Expand Down
17 changes: 16 additions & 1 deletion alioth/src/vfio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use std::os::fd::AsRawFd;
use std::os::unix::fs::FileExt;

use crate::mem;
use crate::vfio::bindings::{VfioDeviceInfo, VfioIrqInfo, VfioIrqSet, VfioRegionInfo};
use crate::vfio::bindings::{
VfioDeviceInfo, VfioIrqInfo, VfioIrqSet, VfioIrqSetData, VfioIrqSetFlag, VfioPciIrq,
VfioRegionInfo,
};
use crate::vfio::ioctls::{
vfio_device_get_info, vfio_device_get_irq_info, vfio_device_get_region_info, vfio_device_reset,
vfio_device_set_irqs,
Expand Down Expand Up @@ -63,6 +66,18 @@ pub trait Device: Debug + Send + Sync + 'static {
Ok(())
}

fn disable_all_irqs(&self, index: VfioPciIrq) -> Result<()> {
let vfio_irq_disable_all = VfioIrqSet {
argsz: size_of::<VfioIrqSet<0>>() as u32,
flags: VfioIrqSetFlag::DATA_NONE | VfioIrqSetFlag::ACTION_TRIGGER,
index: index.raw(),
start: 0,
count: 0,
data: VfioIrqSetData { eventfds: [] },
};
self.set_irqs(&vfio_irq_disable_all)
}

fn reset(&self) -> Result<()> {
unsafe { vfio_device_reset(self.fd()) }?;
Ok(())
Expand Down
Loading

0 comments on commit 844321e

Please sign in to comment.