Skip to content

Commit c2df5f6

Browse files
RuoqingHerbradford
authored andcommitted
riscv64: Introduce basic ioctls
Enable g/set ioctls of `kvm_mp_state`, `kvm_one_reg`; register/unregister of `irq_fd`; `get_reg_list`, `signal_msi`, `irq_line` and `set_gsi_routing`. Signed-off-by: Ruoqing He <[email protected]>
1 parent 175340a commit c2df5f6

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

src/ioctls/vcpu.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use vmm_sys_util::ioctl::{ioctl, ioctl_with_mut_ref, ioctl_with_ref};
1818
use vmm_sys_util::ioctl::{ioctl_with_mut_ptr, ioctl_with_ptr, ioctl_with_val};
1919

2020
/// Helper method to obtain the size of the register through its id
21-
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
21+
#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))]
2222
pub fn reg_size(reg_id: u64) -> usize {
2323
2_usize.pow(((reg_id & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT) as u32)
2424
}
@@ -789,6 +789,7 @@ impl VcpuFd {
789789
target_arch = "x86_64",
790790
target_arch = "arm",
791791
target_arch = "aarch64",
792+
target_arch = "riscv64",
792793
target_arch = "s390x"
793794
))]
794795
pub fn get_mp_state(&self) -> Result<kvm_mp_state> {
@@ -827,6 +828,7 @@ impl VcpuFd {
827828
target_arch = "x86_64",
828829
target_arch = "arm",
829830
target_arch = "aarch64",
831+
target_arch = "riscv64",
830832
target_arch = "s390x"
831833
))]
832834
pub fn set_mp_state(&self, mp_state: kvm_mp_state) -> Result<()> {
@@ -1219,7 +1221,7 @@ impl VcpuFd {
12191221
/// vcpu.get_reg_list(&mut reg_list).unwrap();
12201222
/// assert!(reg_list.as_fam_struct_ref().n > 0);
12211223
/// ```
1222-
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
1224+
#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))]
12231225
pub fn get_reg_list(&self, reg_list: &mut RegList) -> Result<()> {
12241226
let ret =
12251227
// SAFETY: This is safe because we allocated the struct and we trust the kernel will read
@@ -1297,7 +1299,7 @@ impl VcpuFd {
12971299
///
12981300
/// `data` should be equal or bigger then the register size
12991301
/// oterwise function will return EINVAL error
1300-
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
1302+
#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))]
13011303
pub fn set_one_reg(&self, reg_id: u64, data: &[u8]) -> Result<usize> {
13021304
let reg_size = reg_size(reg_id);
13031305
if data.len() < reg_size {
@@ -1329,7 +1331,7 @@ impl VcpuFd {
13291331
///
13301332
/// `data` should be equal or bigger then the register size
13311333
/// oterwise function will return EINVAL error
1332-
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
1334+
#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))]
13331335
pub fn get_one_reg(&self, reg_id: u64, data: &mut [u8]) -> Result<usize> {
13341336
let reg_size = reg_size(reg_id);
13351337
if data.len() < reg_size {

src/ioctls/vm.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ impl VmFd {
581581
target_arch = "x86",
582582
target_arch = "x86_64",
583583
target_arch = "arm",
584-
target_arch = "aarch64"
584+
target_arch = "aarch64",
585+
target_arch = "riscv64"
585586
))]
586587
pub fn signal_msi(&self, msi: kvm_msi) -> Result<c_int> {
587588
// SAFETY: Safe because we allocated the structure and we know the kernel
@@ -628,7 +629,8 @@ impl VmFd {
628629
target_arch = "x86",
629630
target_arch = "x86_64",
630631
target_arch = "arm",
631-
target_arch = "aarch64"
632+
target_arch = "aarch64",
633+
target_arch = "riscv64"
632634
))]
633635
pub fn set_gsi_routing(&self, irq_routing: &kvm_irq_routing) -> Result<()> {
634636
// SAFETY: Safe because we allocated the structure and we know the kernel
@@ -961,7 +963,8 @@ impl VmFd {
961963
target_arch = "x86",
962964
target_arch = "x86_64",
963965
target_arch = "arm",
964-
target_arch = "aarch64"
966+
target_arch = "aarch64",
967+
target_arch = "riscv64"
965968
))]
966969
pub fn register_irqfd(&self, fd: &EventFd, gsi: u32) -> Result<()> {
967970
let irqfd = kvm_irqfd {
@@ -1013,7 +1016,8 @@ impl VmFd {
10131016
target_arch = "x86",
10141017
target_arch = "x86_64",
10151018
target_arch = "arm",
1016-
target_arch = "aarch64"
1019+
target_arch = "aarch64",
1020+
target_arch = "riscv64"
10171021
))]
10181022
pub fn register_irqfd_with_resample(
10191023
&self,
@@ -1072,7 +1076,8 @@ impl VmFd {
10721076
target_arch = "x86",
10731077
target_arch = "x86_64",
10741078
target_arch = "arm",
1075-
target_arch = "aarch64"
1079+
target_arch = "aarch64",
1080+
target_arch = "riscv64"
10761081
))]
10771082
pub fn unregister_irqfd(&self, fd: &EventFd, gsi: u32) -> Result<()> {
10781083
let irqfd = kvm_irqfd {
@@ -1143,7 +1148,8 @@ impl VmFd {
11431148
target_arch = "x86",
11441149
target_arch = "x86_64",
11451150
target_arch = "arm",
1146-
target_arch = "aarch64"
1151+
target_arch = "aarch64",
1152+
target_arch = "riscv64"
11471153
))]
11481154
pub fn set_irq_line(&self, irq: u32, active: bool) -> Result<()> {
11491155
let mut irq_level = kvm_irq_level::default();

src/kvm_ioctls.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ ioctl_io_nr!(KVM_CREATE_IRQCHIP, KVMIO, 0x60);
6666
target_arch = "x86",
6767
target_arch = "x86_64",
6868
target_arch = "arm",
69-
target_arch = "aarch64"
69+
target_arch = "aarch64",
70+
target_arch = "riscv64"
7071
))]
7172
ioctl_iow_nr!(KVM_IRQ_LINE, KVMIO, 0x61, kvm_irq_level);
7273
/* Available with KVM_CAP_COALESCED_MMIO / KVM_CAP_COALESCED_PIO */
@@ -88,7 +89,8 @@ ioctl_iow_nr!(
8889
target_arch = "x86",
8990
target_arch = "x86_64",
9091
target_arch = "arm",
91-
target_arch = "aarch64"
92+
target_arch = "aarch64",
93+
target_arch = "riscv64"
9294
))]
9395
ioctl_iow_nr!(KVM_SET_GSI_ROUTING, KVMIO, 0x6a, kvm_irq_routing);
9496
/* Available with KVM_CAP_IRQFD */
@@ -97,6 +99,7 @@ ioctl_iow_nr!(KVM_SET_GSI_ROUTING, KVMIO, 0x6a, kvm_irq_routing);
9799
target_arch = "x86_64",
98100
target_arch = "arm",
99101
target_arch = "aarch64",
102+
target_arch = "riscv64",
100103
target_arch = "s390x"
101104
))]
102105
ioctl_iow_nr!(KVM_IRQFD, KVMIO, 0x76, kvm_irqfd);
@@ -182,6 +185,7 @@ ioctl_iowr_nr!(KVM_GET_CPUID2, KVMIO, 0x91, kvm_cpuid2);
182185
target_arch = "x86_64",
183186
target_arch = "arm",
184187
target_arch = "aarch64",
188+
target_arch = "riscv64",
185189
target_arch = "s390x"
186190
))]
187191
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);
191195
target_arch = "x86_64",
192196
target_arch = "arm",
193197
target_arch = "aarch64",
198+
target_arch = "riscv64",
194199
target_arch = "s390x"
195200
))]
196201
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);
250255
target_arch = "x86",
251256
target_arch = "x86_64",
252257
target_arch = "arm",
253-
target_arch = "aarch64"
258+
target_arch = "aarch64",
259+
target_arch = "riscv64"
254260
))]
255261
ioctl_iow_nr!(KVM_SIGNAL_MSI, KVMIO, 0xa5, kvm_msi);
256262
/* Available with KVM_CAP_ONE_REG */
257-
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
263+
#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))]
258264
ioctl_iow_nr!(KVM_GET_ONE_REG, KVMIO, 0xab, kvm_one_reg);
259-
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
265+
#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))]
260266
ioctl_iow_nr!(KVM_SET_ONE_REG, KVMIO, 0xac, kvm_one_reg);
261267
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
262268
ioctl_iow_nr!(KVM_ARM_VCPU_INIT, KVMIO, 0xae, kvm_vcpu_init);
263269
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
264270
ioctl_ior_nr!(KVM_ARM_PREFERRED_TARGET, KVMIO, 0xaf, kvm_vcpu_init);
265-
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
271+
#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))]
266272
ioctl_iowr_nr!(KVM_GET_REG_LIST, KVMIO, 0xb0, kvm_reg_list);
267273

268274
/* Available with KVM_CAP_X86_SMM */

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ mod ioctls;
220220
pub use cap::Cap;
221221
pub use ioctls::device::DeviceFd;
222222
pub use ioctls::system::Kvm;
223-
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
223+
#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "riscv64"))]
224224
pub use ioctls::vcpu::reg_size;
225225
pub use ioctls::vcpu::{HypercallExit, VcpuExit, VcpuFd};
226226

0 commit comments

Comments
 (0)