diff --git a/src/ioctls/vcpu.rs b/src/ioctls/vcpu.rs index c4bf833..a2aa334 100644 --- a/src/ioctls/vcpu.rs +++ b/src/ioctls/vcpu.rs @@ -18,7 +18,7 @@ use vmm_sys_util::ioctl::{ioctl, ioctl_with_mut_ref, ioctl_with_ref}; use vmm_sys_util::ioctl::{ioctl_with_mut_ptr, ioctl_with_ptr, ioctl_with_val}; /// Helper method to obtain the size of the register through its id -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] +#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))] pub fn reg_size(reg_id: u64) -> usize { 2_usize.pow(((reg_id & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT) as u32) } @@ -796,6 +796,7 @@ impl VcpuFd { target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64", + target_arch = "riscv64", target_arch = "s390x" ))] pub fn get_mp_state(&self) -> Result { @@ -834,6 +835,7 @@ impl VcpuFd { target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64", + target_arch = "riscv64", target_arch = "s390x" ))] pub fn set_mp_state(&self, mp_state: kvm_mp_state) -> Result<()> { @@ -1227,7 +1229,7 @@ impl VcpuFd { /// vcpu.get_reg_list(&mut reg_list).unwrap(); /// assert!(reg_list.as_fam_struct_ref().n > 0); /// ``` - #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] + #[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))] pub fn get_reg_list(&self, reg_list: &mut RegList) -> Result<()> { let ret = // SAFETY: This is safe because we allocated the struct and we trust the kernel will read @@ -1305,7 +1307,7 @@ impl VcpuFd { /// /// `data` should be equal or bigger then the register size /// oterwise function will return EINVAL error - #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] + #[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))] pub fn set_one_reg(&self, reg_id: u64, data: &[u8]) -> Result { let reg_size = reg_size(reg_id); if data.len() < reg_size { @@ -1337,7 +1339,7 @@ impl VcpuFd { /// /// `data` should be equal or bigger then the register size /// oterwise function will return EINVAL error - #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] + #[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))] pub fn get_one_reg(&self, reg_id: u64, data: &mut [u8]) -> Result { let reg_size = reg_size(reg_id); if data.len() < reg_size { diff --git a/src/ioctls/vm.rs b/src/ioctls/vm.rs index 1f49077..a62c11f 100644 --- a/src/ioctls/vm.rs +++ b/src/ioctls/vm.rs @@ -578,7 +578,8 @@ impl VmFd { target_arch = "x86", target_arch = "x86_64", target_arch = "arm", - target_arch = "aarch64" + target_arch = "aarch64", + target_arch = "riscv64" ))] pub fn signal_msi(&self, msi: kvm_msi) -> Result { // SAFETY: Safe because we allocated the structure and we know the kernel @@ -625,7 +626,8 @@ impl VmFd { target_arch = "x86", target_arch = "x86_64", target_arch = "arm", - target_arch = "aarch64" + target_arch = "aarch64", + target_arch = "riscv64" ))] pub fn set_gsi_routing(&self, irq_routing: &kvm_irq_routing) -> Result<()> { // SAFETY: Safe because we allocated the structure and we know the kernel @@ -959,7 +961,8 @@ impl VmFd { target_arch = "x86", target_arch = "x86_64", target_arch = "arm", - target_arch = "aarch64" + target_arch = "aarch64", + target_arch = "riscv64" ))] pub fn register_irqfd(&self, fd: &EventFd, gsi: u32) -> Result<()> { let irqfd = kvm_irqfd { @@ -1011,7 +1014,8 @@ impl VmFd { target_arch = "x86", target_arch = "x86_64", target_arch = "arm", - target_arch = "aarch64" + target_arch = "aarch64", + target_arch = "riscv64" ))] pub fn register_irqfd_with_resample( &self, @@ -1070,7 +1074,8 @@ impl VmFd { target_arch = "x86", target_arch = "x86_64", target_arch = "arm", - target_arch = "aarch64" + target_arch = "aarch64", + target_arch = "riscv64" ))] pub fn unregister_irqfd(&self, fd: &EventFd, gsi: u32) -> Result<()> { let irqfd = kvm_irqfd { @@ -1141,7 +1146,8 @@ impl VmFd { target_arch = "x86", target_arch = "x86_64", target_arch = "arm", - target_arch = "aarch64" + target_arch = "aarch64", + target_arch = "riscv64" ))] pub fn set_irq_line(&self, irq: u32, active: bool) -> Result<()> { let mut irq_level = kvm_irq_level::default(); diff --git a/src/kvm_ioctls.rs b/src/kvm_ioctls.rs index 60b294d..aa69624 100644 --- a/src/kvm_ioctls.rs +++ b/src/kvm_ioctls.rs @@ -66,7 +66,8 @@ ioctl_io_nr!(KVM_CREATE_IRQCHIP, KVMIO, 0x60); target_arch = "x86", target_arch = "x86_64", target_arch = "arm", - target_arch = "aarch64" + target_arch = "aarch64", + target_arch = "riscv64" ))] ioctl_iow_nr!(KVM_IRQ_LINE, KVMIO, 0x61, kvm_irq_level); /* Available with KVM_CAP_COALESCED_MMIO / KVM_CAP_COALESCED_PIO */ @@ -88,7 +89,8 @@ ioctl_iow_nr!( target_arch = "x86", target_arch = "x86_64", target_arch = "arm", - target_arch = "aarch64" + target_arch = "aarch64", + target_arch = "riscv64" ))] ioctl_iow_nr!(KVM_SET_GSI_ROUTING, KVMIO, 0x6a, kvm_irq_routing); /* Available with KVM_CAP_IRQFD */ @@ -97,6 +99,7 @@ ioctl_iow_nr!(KVM_SET_GSI_ROUTING, KVMIO, 0x6a, kvm_irq_routing); target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64", + target_arch = "riscv64", target_arch = "s390x" ))] ioctl_iow_nr!(KVM_IRQFD, KVMIO, 0x76, kvm_irqfd); @@ -182,6 +185,7 @@ ioctl_iowr_nr!(KVM_GET_CPUID2, KVMIO, 0x91, kvm_cpuid2); target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64", + target_arch = "riscv64", target_arch = "s390x" ))] ioctl_ior_nr!(KVM_GET_MP_STATE, KVMIO, 0x98, kvm_mp_state); @@ -191,6 +195,7 @@ ioctl_ior_nr!(KVM_GET_MP_STATE, KVMIO, 0x98, kvm_mp_state); target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64", + target_arch = "riscv64", target_arch = "s390x" ))] ioctl_iow_nr!(KVM_SET_MP_STATE, KVMIO, 0x99, kvm_mp_state); @@ -250,19 +255,20 @@ ioctl_iow_nr!(KVM_ENABLE_CAP, KVMIO, 0xa3, kvm_enable_cap); target_arch = "x86", target_arch = "x86_64", target_arch = "arm", - target_arch = "aarch64" + target_arch = "aarch64", + target_arch = "riscv64" ))] ioctl_iow_nr!(KVM_SIGNAL_MSI, KVMIO, 0xa5, kvm_msi); /* Available with KVM_CAP_ONE_REG */ -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] +#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))] ioctl_iow_nr!(KVM_GET_ONE_REG, KVMIO, 0xab, kvm_one_reg); -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] +#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))] ioctl_iow_nr!(KVM_SET_ONE_REG, KVMIO, 0xac, kvm_one_reg); #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] ioctl_iow_nr!(KVM_ARM_VCPU_INIT, KVMIO, 0xae, kvm_vcpu_init); #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] ioctl_ior_nr!(KVM_ARM_PREFERRED_TARGET, KVMIO, 0xaf, kvm_vcpu_init); -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] +#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))] ioctl_iowr_nr!(KVM_GET_REG_LIST, KVMIO, 0xb0, kvm_reg_list); /* Available with KVM_CAP_X86_SMM */ diff --git a/src/lib.rs b/src/lib.rs index c1d1ec5..1c29075 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -219,7 +219,7 @@ mod ioctls; pub use cap::Cap; pub use ioctls::device::DeviceFd; pub use ioctls::system::Kvm; -#[cfg(any(target_arch = "arm", target_arch = "aarch64"))] +#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))] pub use ioctls::vcpu::reg_size; pub use ioctls::vcpu::{HypercallExit, VcpuExit, VcpuFd};