77
88use std:: collections:: HashMap ;
99use std:: fmt:: Debug ;
10- use std:: ops:: DerefMut ;
1110use std:: sync:: { Arc , Barrier , Mutex } ;
1211
1312use byteorder:: { ByteOrder , LittleEndian } ;
1413
15- use crate :: logger:: error;
1614use crate :: pci:: configuration:: PciConfiguration ;
17- use crate :: pci:: { DeviceRelocation , PciBridgeSubclass , PciClassCode , PciDevice } ;
15+ use crate :: pci:: { PciBridgeSubclass , PciClassCode , PciDevice } ;
1816use crate :: utils:: u64_to_usize;
1917use crate :: vstate:: bus:: BusDevice ;
2018
@@ -80,7 +78,6 @@ pub struct PciBus {
8078 /// Devices attached to this bus.
8179 /// Device 0 is host bridge.
8280 pub devices : HashMap < u8 , Arc < Mutex < dyn PciDevice > > > ,
83- vm : Arc < dyn DeviceRelocation > ,
8481 device_ids : Vec < bool > ,
8582}
8683
@@ -94,7 +91,7 @@ impl Debug for PciBus {
9491
9592impl PciBus {
9693 /// Create a new PCI bus
97- pub fn new ( pci_root : PciRoot , vm : Arc < dyn DeviceRelocation > ) -> Self {
94+ pub fn new ( pci_root : PciRoot ) -> Self {
9895 let mut devices: HashMap < u8 , Arc < Mutex < dyn PciDevice > > > = HashMap :: new ( ) ;
9996 let mut device_ids: Vec < bool > = vec ! [ false ; NUM_DEVICE_IDS ] ;
10097
@@ -103,7 +100,6 @@ impl PciBus {
103100
104101 PciBus {
105102 devices,
106- vm,
107103 device_ids,
108104 }
109105 }
@@ -220,22 +216,6 @@ impl PciConfigIo {
220216 if let Some ( d) = pci_bus. devices . get ( & device) {
221217 let mut device = d. lock ( ) . unwrap ( ) ;
222218
223- // Find out if one of the device's BAR is being reprogrammed, and
224- // reprogram it if needed.
225- if let Some ( params) = device. detect_bar_reprogramming ( register, data)
226- && let Err ( e) = pci_bus. vm . move_bar (
227- params. old_base ,
228- params. new_base ,
229- params. len ,
230- device. deref_mut ( ) ,
231- )
232- {
233- error ! (
234- "Failed moving device BAR: {}: 0x{:x}->0x{:x}(0x{:x})" ,
235- e, params. old_base, params. new_base, params. len
236- ) ;
237- }
238-
239219 // offset is validated to be < 4 at the top of this function.
240220 #[ allow( clippy:: cast_possible_truncation) ]
241221 let offset = offset as u8 ;
@@ -360,22 +340,6 @@ impl PciConfigMmio {
360340 if let Some ( d) = pci_bus. devices . get ( & device) {
361341 let mut device = d. lock ( ) . unwrap ( ) ;
362342
363- // Find out if one of the device's BAR is being reprogrammed, and
364- // reprogram it if needed.
365- if let Some ( params) = device. detect_bar_reprogramming ( register, data)
366- && let Err ( e) = pci_bus. vm . move_bar (
367- params. old_base ,
368- params. new_base ,
369- params. len ,
370- device. deref_mut ( ) ,
371- )
372- {
373- error ! (
374- "Failed moving device BAR: {}: 0x{:x}->0x{:x}(0x{:x})" ,
375- e, params. old_base, params. new_base, params. len
376- ) ;
377- }
378-
379343 // offset is validated to be < 4 at the top of this function.
380344 #[ allow( clippy:: cast_possible_truncation) ]
381345 let offset = offset as u8 ;
@@ -474,37 +438,14 @@ fn parse_io_config_address(config_address: u32) -> (u8, u8, u8, u16) {
474438
475439#[ cfg( test) ]
476440mod tests {
477- use std:: sync:: atomic:: AtomicUsize ;
478441 use std:: sync:: { Arc , Mutex } ;
479442
480443 use super :: { PciBus , PciConfigIo , PciConfigMmio , PciRoot } ;
481444 use crate :: pci:: bus:: { DEVICE_ID_INTEL_VIRT_PCIE_HOST , VENDOR_ID_INTEL } ;
482445 use crate :: pci:: configuration:: PciConfiguration ;
483- use crate :: pci:: {
484- BarReprogrammingParams , DeviceRelocation , DeviceRelocationError , PciClassCode , PciDevice ,
485- PciMassStorageSubclass ,
486- } ;
446+ use crate :: pci:: { PciClassCode , PciDevice , PciMassStorageSubclass } ;
487447 use crate :: vstate:: bus:: BusDevice ;
488448
489- #[ derive( Debug , Default ) ]
490- struct RelocationMock {
491- reloc_cnt : AtomicUsize ,
492- }
493-
494- impl DeviceRelocation for RelocationMock {
495- fn move_bar (
496- & self ,
497- _old_base : u64 ,
498- _new_base : u64 ,
499- _len : u64 ,
500- _pci_dev : & mut dyn PciDevice ,
501- ) -> Result < ( ) , DeviceRelocationError > {
502- self . reloc_cnt
503- . fetch_add ( 1 , std:: sync:: atomic:: Ordering :: SeqCst ) ;
504- Ok ( ( ) )
505- }
506- }
507-
508449 struct PciDevMock ( PciConfiguration ) ;
509450
510451 impl PciDevMock {
@@ -536,21 +477,12 @@ mod tests {
536477 fn read_config_register ( & mut self , reg_idx : u16 ) -> u32 {
537478 self . 0 . read_reg ( reg_idx)
538479 }
539-
540- fn detect_bar_reprogramming (
541- & mut self ,
542- _reg_idx : u16 ,
543- _data : & [ u8 ] ,
544- ) -> Option < BarReprogrammingParams > {
545- None
546- }
547480 }
548481
549482 #[ test]
550483 fn test_writing_io_config_address ( ) {
551- let mock = Arc :: new ( RelocationMock :: default ( ) ) ;
552484 let root = PciRoot :: new ( None ) ;
553- let mut bus = PciConfigIo :: new ( Arc :: new ( Mutex :: new ( PciBus :: new ( root, mock ) ) ) ) ;
485+ let mut bus = PciConfigIo :: new ( Arc :: new ( Mutex :: new ( PciBus :: new ( root) ) ) ) ;
554486
555487 assert_eq ! ( bus. config_address, 0 ) ;
556488 // Writing more than 32 bits will should fail
@@ -590,9 +522,8 @@ mod tests {
590522
591523 #[ test]
592524 fn test_reading_io_config_address ( ) {
593- let mock = Arc :: new ( RelocationMock :: default ( ) ) ;
594525 let root = PciRoot :: new ( None ) ;
595- let mut bus = PciConfigIo :: new ( Arc :: new ( Mutex :: new ( PciBus :: new ( root, mock ) ) ) ) ;
526+ let mut bus = PciConfigIo :: new ( Arc :: new ( Mutex :: new ( PciBus :: new ( root) ) ) ) ;
596527
597528 let mut buffer = [ 0u8 ; 4 ] ;
598529
@@ -637,19 +568,18 @@ mod tests {
637568 assert_eq ! ( buffer, [ 0x45 , 0x44 , 0x43 , 0x42 ] ) ;
638569 }
639570
640- fn initialize_bus ( ) -> ( PciConfigMmio , PciConfigIo , Arc < RelocationMock > ) {
641- let mock = Arc :: new ( RelocationMock :: default ( ) ) ;
571+ fn initialize_bus ( ) -> ( PciConfigMmio , PciConfigIo ) {
642572 let root = PciRoot :: new ( None ) ;
643- let mut bus = PciBus :: new ( root, mock . clone ( ) ) ;
573+ let mut bus = PciBus :: new ( root) ;
644574 bus. add_device ( 1 , Arc :: new ( Mutex :: new ( PciDevMock :: new ( ) ) ) ) ;
645575
646576 let bus = Arc :: new ( Mutex :: new ( bus) ) ;
647- ( PciConfigMmio :: new ( bus. clone ( ) ) , PciConfigIo :: new ( bus) , mock )
577+ ( PciConfigMmio :: new ( bus. clone ( ) ) , PciConfigIo :: new ( bus) )
648578 }
649579
650580 #[ test]
651581 fn test_invalid_register_boundary_reads ( ) {
652- let ( mut mmio_config, mut io_config, _ ) = initialize_bus ( ) ;
582+ let ( mut mmio_config, mut io_config) = initialize_bus ( ) ;
653583
654584 // Read crossing register boundaries
655585 let mut buffer = [ 0u8 ; 4 ] ;
@@ -784,7 +714,7 @@ mod tests {
784714
785715 #[ test]
786716 fn test_mmio_invalid_bus_number ( ) {
787- let ( mut mmio_config, _, _ ) = initialize_bus ( ) ;
717+ let ( mut mmio_config, _) = initialize_bus ( ) ;
788718 let mut buffer = [ 0u8 ; 4 ] ;
789719
790720 // Asking for Bus 1 should return all 1s
@@ -809,7 +739,7 @@ mod tests {
809739
810740 #[ test]
811741 fn test_io_invalid_bus_number ( ) {
812- let ( _, mut pio_config, _ ) = initialize_bus ( ) ;
742+ let ( _, mut pio_config) = initialize_bus ( ) ;
813743 let mut buffer = [ 0u8 ; 4 ] ;
814744
815745 // Asking for Bus 1 should return all 1s
@@ -827,7 +757,7 @@ mod tests {
827757
828758 #[ test]
829759 fn test_mmio_invalid_function ( ) {
830- let ( mut mmio_config, _, _ ) = initialize_bus ( ) ;
760+ let ( mut mmio_config, _) = initialize_bus ( ) ;
831761 let mut buffer = [ 0u8 ; 4 ] ;
832762
833763 // Asking for Bus 1 should return all 1s
@@ -852,7 +782,7 @@ mod tests {
852782
853783 #[ test]
854784 fn test_io_invalid_function ( ) {
855- let ( _, mut pio_config, _ ) = initialize_bus ( ) ;
785+ let ( _, mut pio_config) = initialize_bus ( ) ;
856786 let mut buffer = [ 0u8 ; 4 ] ;
857787
858788 // Asking for Bus 1 should return all 1s
@@ -870,7 +800,7 @@ mod tests {
870800
871801 #[ test]
872802 fn test_io_disabled_reads ( ) {
873- let ( _, mut pio_config, _ ) = initialize_bus ( ) ;
803+ let ( _, mut pio_config) = initialize_bus ( ) ;
874804 let mut buffer = [ 0u8 ; 4 ] ;
875805
876806 // Trying to read without enabling should return all 1s
@@ -888,7 +818,7 @@ mod tests {
888818
889819 #[ test]
890820 fn test_io_disabled_writes ( ) {
891- let ( _, mut pio_config, _ ) = initialize_bus ( ) ;
821+ let ( _, mut pio_config) = initialize_bus ( ) ;
892822
893823 // Try to write the IRQ line used for the root port.
894824 let mut buffer = [ 0u8 ; 4 ] ;
@@ -916,7 +846,7 @@ mod tests {
916846
917847 #[ test]
918848 fn test_mmio_writes ( ) {
919- let ( mut mmio_config, _, _ ) = initialize_bus ( ) ;
849+ let ( mut mmio_config, _) = initialize_bus ( ) ;
920850 let mut buffer = [ 0u8 ; 4 ] ;
921851
922852 read_mmio_config ( & mut mmio_config, 0 , 0 , 0 , 15 , 0 , & mut buffer) ;
0 commit comments