@@ -213,7 +213,6 @@ impl PciConfigIo {
213
213
params. new_base ,
214
214
params. len ,
215
215
device. deref_mut ( ) ,
216
- params. region_type ,
217
216
) {
218
217
error ! (
219
218
"Failed moving device BAR: {}: 0x{:x}->0x{:x}(0x{:x})" ,
@@ -348,7 +347,6 @@ impl PciConfigMmio {
348
347
params. new_base ,
349
348
params. len ,
350
349
device. deref_mut ( ) ,
351
- params. region_type ,
352
350
) {
353
351
error ! (
354
352
"Failed moving device BAR: {}: 0x{:x}->0x{:x}(0x{:x})" ,
@@ -445,8 +443,8 @@ mod tests {
445
443
use super :: { PciBus , PciConfigIo , PciConfigMmio , PciRoot } ;
446
444
use crate :: bus:: { DEVICE_ID_INTEL_VIRT_PCIE_HOST , VENDOR_ID_INTEL } ;
447
445
use crate :: {
448
- DeviceRelocation , PciBarConfiguration , PciBarPrefetchable , PciBarRegionType , PciClassCode ,
449
- PciConfiguration , PciDevice , PciHeaderType , PciMassStorageSubclass ,
446
+ DeviceRelocation , PciClassCode , PciConfiguration , PciDevice , PciHeaderType ,
447
+ PciMassStorageSubclass ,
450
448
} ;
451
449
452
450
#[ derive( Debug , Default ) ]
@@ -467,7 +465,6 @@ mod tests {
467
465
_new_base : u64 ,
468
466
_len : u64 ,
469
467
_pci_dev : & mut dyn crate :: PciDevice ,
470
- _region_type : crate :: PciBarRegionType ,
471
468
) -> std:: result:: Result < ( ) , std:: io:: Error > {
472
469
self . reloc_cnt
473
470
. fetch_add ( 1 , std:: sync:: atomic:: Ordering :: SeqCst ) ;
@@ -493,15 +490,7 @@ mod tests {
493
490
None ,
494
491
) ;
495
492
496
- config
497
- . add_pci_bar ( & PciBarConfiguration {
498
- addr : 0x1000 ,
499
- size : 0x1000 ,
500
- idx : 0 ,
501
- region_type : PciBarRegionType :: Memory32BitRegion ,
502
- prefetchable : PciBarPrefetchable :: Prefetchable ,
503
- } )
504
- . unwrap ( ) ;
493
+ config. add_pci_bar ( 0 , 0x1000 , 0x1000 ) . unwrap ( ) ;
505
494
506
495
PciDevMock ( config)
507
496
}
@@ -920,23 +909,32 @@ mod tests {
920
909
read_mmio_config ( & mut mmio_config, 0 , 1 , 0 , 0x4 , 0 , & mut buffer) ;
921
910
let old_addr = u32:: from_le_bytes ( buffer) & 0xffff_fff0 ;
922
911
assert_eq ! ( old_addr, 0x1000 ) ;
912
+
913
+ // Writing the lower 32bits first should not trigger any reprogramming
923
914
write_mmio_config (
924
915
& mut mmio_config,
925
916
0 ,
926
917
1 ,
927
918
0 ,
928
919
0x4 ,
929
920
0 ,
930
- & u32:: to_le_bytes ( 0x1312_1110 ) ,
921
+ & u32:: to_le_bytes ( 0x1312_0000 ) ,
931
922
) ;
932
923
933
924
read_mmio_config ( & mut mmio_config, 0 , 1 , 0 , 0x4 , 0 , & mut buffer) ;
934
925
let new_addr = u32:: from_le_bytes ( buffer) & 0xffff_fff0 ;
935
- assert_eq ! ( new_addr, 0x1312_1110 ) ;
936
- assert_eq ! ( mock. cnt( ) , 1 ) ;
926
+ assert_eq ! ( new_addr, 0x1312_0000 ) ;
927
+ assert_eq ! ( mock. cnt( ) , 0 ) ;
937
928
938
- // BAR1 should not be used, so reading its address should return all 0s
929
+ // Writing the upper 32bits first should now trigger the reprogramming logic
930
+ write_mmio_config ( & mut mmio_config, 0 , 1 , 0 , 0x5 , 0 , & u32:: to_le_bytes ( 0x1110 ) ) ;
939
931
read_mmio_config ( & mut mmio_config, 0 , 1 , 0 , 0x5 , 0 , & mut buffer) ;
932
+ let new_addr = u32:: from_le_bytes ( buffer) ;
933
+ assert_eq ! ( new_addr, 0x1110 ) ;
934
+ assert_eq ! ( mock. cnt( ) , 1 ) ;
935
+
936
+ // BAR2 should not be used, so reading its address should return all 0s
937
+ read_mmio_config ( & mut mmio_config, 0 , 1 , 0 , 0x6 , 0 , & mut buffer) ;
940
938
assert_eq ! ( buffer, [ 0x0 , 0x0 , 0x0 , 0x0 ] ) ;
941
939
942
940
// and reprogramming shouldn't have any effect
@@ -950,7 +948,7 @@ mod tests {
950
948
& u32:: to_le_bytes ( 0x1312_1110 ) ,
951
949
) ;
952
950
953
- read_mmio_config ( & mut mmio_config, 0 , 1 , 0 , 0x5 , 0 , & mut buffer) ;
951
+ read_mmio_config ( & mut mmio_config, 0 , 1 , 0 , 0x6 , 0 , & mut buffer) ;
954
952
assert_eq ! ( buffer, [ 0x0 , 0x0 , 0x0 , 0x0 ] ) ;
955
953
}
956
954
}
0 commit comments