@@ -12,8 +12,8 @@ use vm_memory::ByteValued;
1212
1313use crate :: Vm ;
1414use crate :: logger:: { debug, error, warn} ;
15- use crate :: pci:: PciCapabilityId ;
1615use crate :: pci:: configuration:: PciCapability ;
16+ use crate :: pci:: { PciCapabilityId , PciSBDF } ;
1717use crate :: snapshot:: Persist ;
1818use crate :: vstate:: interrupts:: { InterruptError , MsixVectorConfig , MsixVectorGroup } ;
1919
@@ -71,8 +71,8 @@ pub struct MsixConfig {
7171 pub table_entries : Vec < MsixTableEntry > ,
7272 /// Pending bit array
7373 pub pba_entries : Vec < u64 > ,
74- /// Id of the device using this set of vectors
75- pub devid : u32 ,
74+ /// SBDF of the device using this set of vectors
75+ pub sbdf : PciSBDF ,
7676 /// Interrupts vectors used
7777 pub vectors : Arc < MsixVectorGroup > ,
7878 /// Whether vectors are masked
@@ -86,7 +86,7 @@ impl std::fmt::Debug for MsixConfig {
8686 f. debug_struct ( "MsixConfig" )
8787 . field ( "table_entries" , & self . table_entries )
8888 . field ( "pba_entries" , & self . pba_entries )
89- . field ( "devid" , & self . devid )
89+ . field ( "devid" , & self . sbdf )
9090 . field ( "masked" , & self . masked )
9191 . field ( "enabled" , & self . enabled )
9292 . finish ( )
@@ -95,7 +95,7 @@ impl std::fmt::Debug for MsixConfig {
9595
9696impl MsixConfig {
9797 /// Create a new MSI-X configuration
98- pub fn new ( vectors : Arc < MsixVectorGroup > , devid : u32 ) -> Self {
98+ pub fn new ( vectors : Arc < MsixVectorGroup > , sbdf : PciSBDF ) -> Self {
9999 assert ! ( vectors. num_vectors( ) <= MAX_MSIX_VECTORS_PER_DEVICE ) ;
100100
101101 let mut table_entries: Vec < MsixTableEntry > = Vec :: new ( ) ;
@@ -107,7 +107,7 @@ impl MsixConfig {
107107 MsixConfig {
108108 table_entries,
109109 pba_entries,
110- devid ,
110+ sbdf ,
111111 vectors,
112112 masked : true ,
113113 enabled : false ,
@@ -118,7 +118,7 @@ impl MsixConfig {
118118 pub fn from_state (
119119 state : MsixConfigState ,
120120 vm : Arc < Vm > ,
121- devid : u32 ,
121+ sbdf : PciSBDF ,
122122 ) -> Result < Self , InterruptError > {
123123 let vectors = Arc :: new ( MsixVectorGroup :: restore ( vm, & state. vectors ) ?) ;
124124 if state. enabled && !state. masked {
@@ -131,7 +131,7 @@ impl MsixConfig {
131131 high_addr : table_entry. msg_addr_hi ,
132132 low_addr : table_entry. msg_addr_lo ,
133133 data : table_entry. msg_data ,
134- devid ,
134+ sbdf ,
135135 } ;
136136
137137 vectors. update ( idx, config, state. masked , true ) ?;
@@ -142,7 +142,7 @@ impl MsixConfig {
142142 Ok ( MsixConfig {
143143 table_entries : state. table_entries ,
144144 pba_entries : state. pba_entries ,
145- devid ,
145+ sbdf ,
146146 vectors,
147147 masked : state. masked ,
148148 enabled : state. enabled ,
@@ -171,21 +171,21 @@ impl MsixConfig {
171171 // Update interrupt routing
172172 if old_masked != self . masked || old_enabled != self . enabled {
173173 if self . enabled && !self . masked {
174- debug ! ( "MSI-X enabled for device 0x{:x }" , self . devid ) ;
174+ debug ! ( "MSI-X enabled for device { }" , self . sbdf ) ;
175175 for ( idx, table_entry) in self . table_entries . iter ( ) . enumerate ( ) {
176176 let config = MsixVectorConfig {
177177 high_addr : table_entry. msg_addr_hi ,
178178 low_addr : table_entry. msg_addr_lo ,
179179 data : table_entry. msg_data ,
180- devid : self . devid ,
180+ sbdf : self . sbdf ,
181181 } ;
182182
183183 if let Err ( e) = self . vectors . update ( idx, config, table_entry. masked ( ) , true ) {
184184 error ! ( "Failed updating vector: {:?}" , e) ;
185185 }
186186 }
187187 } else if old_enabled || !old_masked {
188- debug ! ( "MSI-X disabled for device 0x{:x }" , self . devid ) ;
188+ debug ! ( "MSI-X disabled for device { }" , self . sbdf ) ;
189189 if let Err ( e) = self . vectors . disable ( ) {
190190 error ! ( "Failed disabling irq_fd: {:?}" , e) ;
191191 }
@@ -323,7 +323,7 @@ impl MsixConfig {
323323 high_addr : table_entry. msg_addr_hi ,
324324 low_addr : table_entry. msg_addr_lo ,
325325 data : table_entry. msg_data ,
326- devid : self . devid ,
326+ sbdf : self . sbdf ,
327327 } ;
328328
329329 if let Err ( e) = self
@@ -521,13 +521,13 @@ mod tests {
521521 #[ test]
522522 #[ should_panic]
523523 fn test_too_many_vectors ( ) {
524- MsixConfig :: new ( msix_vector_group ( 2049 ) , 0x42 ) ;
524+ MsixConfig :: new ( msix_vector_group ( 2049 ) , PciSBDF :: from ( 0x42 ) ) ;
525525 }
526526
527527 #[ test]
528528 fn test_new_msix_config ( ) {
529- let config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
530- assert_eq ! ( config. devid , 0x42 ) ;
529+ let config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
530+ assert_eq ! ( config. sbdf , PciSBDF :: from ( 0x42 ) ) ;
531531 assert ! ( config. masked) ;
532532 assert ! ( !config. enabled) ;
533533 assert_eq ! ( config. table_entries. len( ) , 2 ) ;
@@ -536,7 +536,7 @@ mod tests {
536536
537537 #[ test]
538538 fn test_enable_msix_vectors ( ) {
539- let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
539+ let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
540540
541541 assert ! ( !config. enabled) ;
542542 assert ! ( config. masked) ;
@@ -563,15 +563,15 @@ mod tests {
563563 #[ test]
564564 #[ should_panic]
565565 fn test_table_access_read_too_big ( ) {
566- let config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
566+ let config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
567567 let mut buffer = [ 0u8 ; 16 ] ;
568568
569569 config. read_table ( 0 , & mut buffer) ;
570570 }
571571
572572 #[ test]
573573 fn test_read_table_past_end ( ) {
574- let config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
574+ let config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
575575 let mut buffer = [ 0u8 ; 8 ] ;
576576
577577 // We have 2 vectors (16 bytes each), so we should be able to read up to 32 bytes.
@@ -582,7 +582,7 @@ mod tests {
582582
583583 #[ test]
584584 fn test_read_table_bad_length ( ) {
585- let config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
585+ let config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
586586 let mut buffer = [ 0u8 ; 8 ] ;
587587
588588 // We can either read 4 or 8 bytes
@@ -608,7 +608,7 @@ mod tests {
608608
609609 #[ test]
610610 fn test_access_table ( ) {
611- let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
611+ let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
612612 // enabled and not masked
613613 check_metric_after_block ! (
614614 METRICS . interrupts. config_updates,
@@ -725,15 +725,15 @@ mod tests {
725725 #[ test]
726726 #[ should_panic]
727727 fn test_table_access_write_too_big ( ) {
728- let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
728+ let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
729729 let buffer = [ 0u8 ; 16 ] ;
730730
731731 config. write_table ( 0 , & buffer) ;
732732 }
733733
734734 #[ test]
735735 fn test_pba_read_too_big ( ) {
736- let config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
736+ let config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
737737 let mut buffer = [ 0u8 ; 16 ] ;
738738
739739 config. read_pba ( 0 , & mut buffer) ;
@@ -742,7 +742,7 @@ mod tests {
742742
743743 #[ test]
744744 fn test_pba_invalid_offset ( ) {
745- let config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
745+ let config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
746746 let mut buffer = [ 0u8 ; 8 ] ;
747747
748748 // Past the end of the PBA array
@@ -760,22 +760,22 @@ mod tests {
760760 #[ test]
761761 #[ should_panic]
762762 fn test_set_pba_bit_vector_too_big ( ) {
763- let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
763+ let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
764764
765765 config. set_pba_bit ( 2048 , false ) ;
766766 }
767767
768768 #[ test]
769769 #[ should_panic]
770770 fn test_get_pba_bit_vector_too_big ( ) {
771- let config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
771+ let config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
772772
773773 config. get_pba_bit ( 2048 ) ;
774774 }
775775
776776 #[ test]
777777 fn test_pba_bit_invalid_vector ( ) {
778- let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
778+ let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
779779
780780 // We have two vectors, so setting the pending bit for the third one
781781 // should be ignored
@@ -788,7 +788,7 @@ mod tests {
788788
789789 #[ test]
790790 fn test_pba_read ( ) {
791- let mut config = MsixConfig :: new ( msix_vector_group ( 128 ) , 0x42 ) ;
791+ let mut config = MsixConfig :: new ( msix_vector_group ( 128 ) , PciSBDF :: from ( 0x42 ) ) ;
792792 let mut buffer = [ 0u8 ; 8 ] ;
793793
794794 config. set_pba_bit ( 1 , false ) ;
@@ -809,7 +809,7 @@ mod tests {
809809
810810 #[ test]
811811 fn test_pending_interrupt ( ) {
812- let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , 0x42 ) ;
812+ let mut config = MsixConfig :: new ( msix_vector_group ( 2 ) , PciSBDF :: from ( 0x42 ) ) ;
813813 config. set_pba_bit ( 1 , false ) ;
814814 assert_eq ! ( config. get_pba_bit( 1 ) , 1 ) ;
815815 // Enable MSI-X vector and unmask interrupts
0 commit comments