@@ -1952,6 +1952,61 @@ pub(crate) fn request_gic_init(vgic: &DeviceFd) {
1952
1952
vgic. set_device_attr ( & vgic_attr) . unwrap ( ) ;
1953
1953
}
1954
1954
1955
+ /// Create a dummy AIA device.
1956
+ ///
1957
+ /// # Arguments
1958
+ ///
1959
+ /// * `vm` - The vm file descriptor.
1960
+ /// * `flags` - Flags to be passed to `KVM_CREATE_DEVICE`.
1961
+ #[ cfg( test) ]
1962
+ #[ cfg( target_arch = "riscv64" ) ]
1963
+ pub ( crate ) fn create_aia_device ( vm : & VmFd , flags : u32 ) -> DeviceFd {
1964
+ let mut aia_device = kvm_bindings:: kvm_create_device {
1965
+ type_ : kvm_device_type_KVM_DEV_TYPE_RISCV_AIA,
1966
+ fd : 0 ,
1967
+ flags,
1968
+ } ;
1969
+ vm. create_device ( & mut aia_device)
1970
+ . expect ( "Cannot create KVM vAIA device" )
1971
+ }
1972
+
1973
+ /// Set supported number of IRQs for vAIA.
1974
+ ///
1975
+ /// # Arguments
1976
+ ///
1977
+ /// * `vaia` - The vAIA file descriptor.
1978
+ /// * `nr_irqs` - Number of IRQs.
1979
+ #[ cfg( test) ]
1980
+ #[ cfg( target_arch = "riscv64" ) ]
1981
+ pub ( crate ) fn set_supported_nr_irqs ( vaia : & DeviceFd , nr_irqs : u32 ) {
1982
+ let vaia_attr = kvm_bindings:: kvm_device_attr {
1983
+ group : kvm_bindings:: KVM_DEV_RISCV_AIA_GRP_CONFIG ,
1984
+ attr : u64:: from ( kvm_bindings:: KVM_DEV_RISCV_AIA_CONFIG_SRCS ) ,
1985
+ addr : & nr_irqs as * const u32 as u64 ,
1986
+ flags : 0 ,
1987
+ } ;
1988
+ vaia. has_device_attr ( & vaia_attr) . unwrap ( ) ;
1989
+ vaia. set_device_attr ( & vaia_attr) . unwrap ( ) ;
1990
+ }
1991
+
1992
+ /// Request the initialization of the vAIA.
1993
+ ///
1994
+ /// # Arguments
1995
+ ///
1996
+ /// * `vaia` - The vAIA file descriptor.
1997
+ #[ cfg( test) ]
1998
+ #[ cfg( target_arch = "riscv64" ) ]
1999
+ pub ( crate ) fn request_aia_init ( vaia : & DeviceFd ) {
2000
+ let vaia_attr = kvm_bindings:: kvm_device_attr {
2001
+ group : kvm_bindings:: KVM_DEV_RISCV_AIA_GRP_CTRL ,
2002
+ attr : u64:: from ( kvm_bindings:: KVM_DEV_RISCV_AIA_CTRL_INIT ) ,
2003
+ addr : 0 ,
2004
+ flags : 0 ,
2005
+ } ;
2006
+ vaia. has_device_attr ( & vaia_attr) . unwrap ( ) ;
2007
+ vaia. set_device_attr ( & vaia_attr) . unwrap ( ) ;
2008
+ }
2009
+
1955
2010
#[ cfg( test) ]
1956
2011
mod tests {
1957
2012
#![ allow( clippy:: undocumented_unsafe_blocks) ]
0 commit comments