Skip to content

Commit

Permalink
riscv64: Introduce AIA related methods
Browse files Browse the repository at this point in the history
Implement `create_aia_device`, `set_supported_nr_irqs` and
`request_aia_init` method to manipulate KVM AIA device.

Signed-off-by: Ruoqing He <[email protected]>
  • Loading branch information
TimePrinciple committed Sep 26, 2024
1 parent 9aac4a3 commit 5687585
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/ioctls/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,58 @@ pub(crate) fn request_gic_init(vgic: &DeviceFd) {
assert!(vgic.set_device_attr(&vgic_attr).is_ok());
}

/// Create a dummy AIA device.
///
/// # Arguments
///
/// * `vm` - The vm file descriptor.
/// * `flags` - Flags to be passed to `KVM_CREATE_DEVICE`.
#[cfg(test)]
#[cfg(target_arch = "riscv64")]
pub(crate) fn create_aia_device(vm: &VmFd, flags: u32) -> DeviceFd {
let mut aia_device = kvm_bindings::kvm_create_device {
type_: kvm_device_type_KVM_DEV_TYPE_RISCV_AIA,
fd: 0,
flags,
};
vm.create_device(&mut aia_device).expect("Cannot create KVM vAIA device");
}

/// Set supported number of IRQs for vAIA.
///
/// # Arguments
///
/// * `vaia` - The vAIA file descriptor.
/// * `nr_irqs` - Number of IRQs.
#[cfg(test)]
#[cfg(target_arch = "riscv64")]
pub(crate) fn set_supported_nr_irqs(vaia: &DeviceFd, nr_irqs: u32) {
let vaia_attr = kvm_bindings::kvm_device_attr {
group: kvm_bindings::KVM_DEV_RISCV_AIA_GRP_CONFIG,
attr: u64::from(kvm_bindings::KVM_DEV_RISCV_AIA_CONFIG_SRCS),
addr: &nr_irqs as *const u32 as u64,
flags: 0,
};
assert!(vaia.set_device_attr(&vaia_attr).is_ok());
}

/// Request the initialization of the vAIA.
///
/// # Arguments
///
/// * `vaia` - The vAIA file descriptor.
#[cfg(test)]
#[cfg(target_arch = "riscv64")]
pub(crate) fn request_aia_init(vaia: &DeviceFd) {
let vaia_attr = kvm_bindings::kvm_device_attr {
group: kvm_bindings::KVM_DEV_RISCV_AIA_GRP_CTRL,
attr: u64::from(kvm_bindings::KVM_DEV_RISCV_AIA_CTRL_INIT),
addr: 0,
flags: 0,
};
assert!(vaia.set_device_attr(&vaia_attr).is_ok());
}

#[cfg(test)]
mod tests {
#![allow(clippy::undocumented_unsafe_blocks)]
Expand Down

0 comments on commit 5687585

Please sign in to comment.