@@ -20,6 +20,11 @@ use super::*;
20
20
mod legacy_irq;
21
21
#[ cfg( feature = "kvm-legacy-irq" ) ]
22
22
use self :: legacy_irq:: LegacyIrq ;
23
+ #[ cfg( feature = "kvm-msi-generic" ) ]
24
+ mod msi_generic;
25
+
26
+ /// Maximum number of global interrupt sources.
27
+ pub const MAX_IRQS : InterruptIndex = 1024 ;
23
28
24
29
/// Structure to manage interrupt sources for a virtual machine based on the Linux KVM framework.
25
30
///
@@ -178,6 +183,46 @@ impl KvmIrqRouting {
178
183
}
179
184
}
180
185
186
+ #[ cfg( feature = "kvm-msi-generic" ) ]
187
+ impl KvmIrqRouting {
188
+ pub ( super ) fn add ( & self , entries : & [ kvm_irq_routing_entry ] ) -> Result < ( ) > {
189
+ // Safe to unwrap because there's no legal way to break the mutex.
190
+ let mut routes = self . routes . lock ( ) . unwrap ( ) ;
191
+ for entry in entries {
192
+ if entry. gsi >= MAX_IRQS {
193
+ return Err ( std:: io:: Error :: from_raw_os_error ( libc:: EINVAL ) ) ;
194
+ } else if routes. contains_key ( & hash_key ( entry) ) {
195
+ return Err ( std:: io:: Error :: from_raw_os_error ( libc:: EEXIST ) ) ;
196
+ }
197
+ }
198
+
199
+ for entry in entries {
200
+ let _ = routes. insert ( hash_key ( entry) , * entry) ;
201
+ }
202
+ self . set_routing ( & routes)
203
+ }
204
+
205
+ pub ( super ) fn remove ( & self , entries : & [ kvm_irq_routing_entry ] ) -> Result < ( ) > {
206
+ // Safe to unwrap because there's no legal way to break the mutex.
207
+ let mut routes = self . routes . lock ( ) . unwrap ( ) ;
208
+ for entry in entries {
209
+ let _ = routes. remove ( & hash_key ( entry) ) ;
210
+ }
211
+ self . set_routing ( & routes)
212
+ }
213
+
214
+ pub ( super ) fn modify ( & self , entry : & kvm_irq_routing_entry ) -> Result < ( ) > {
215
+ // Safe to unwrap because there's no legal way to break the mutex.
216
+ let mut routes = self . routes . lock ( ) . unwrap ( ) ;
217
+ if !routes. contains_key ( & hash_key ( entry) ) {
218
+ return Err ( std:: io:: Error :: from_raw_os_error ( libc:: ENOENT ) ) ;
219
+ }
220
+
221
+ let _ = routes. insert ( hash_key ( entry) , * entry) ;
222
+ self . set_routing ( & routes)
223
+ }
224
+ }
225
+
181
226
/// Helper function convert from vmm_sys_util::errno::Error to std::io::Error.
182
227
pub fn from_sys_util_errno ( e : vmm_sys_util:: errno:: Error ) -> std:: io:: Error {
183
228
std:: io:: Error :: from_raw_os_error ( e. errno ( ) )
0 commit comments