@@ -712,20 +712,25 @@ impl Scb {
712
712
/// Invalidates cache starting from the lowest 32-byte aligned address represented by `addr`,
713
713
/// in blocks of 32 bytes until at least `size` bytes have been invalidated.
714
714
#[ inline]
715
- pub fn invalidate_dcache_by_address ( & self , addr : u32 , size : u32 ) {
715
+ pub fn invalidate_dcache_by_address ( & self , addr : usize , size : usize ) {
716
+ // No-op zero sized operations
717
+ if size == 0 {
718
+ return ;
719
+ }
720
+
716
721
// All of CBP is write-only so no data races are possible
717
722
let cbp = unsafe { & mut * CBP . get ( ) } ;
718
723
719
724
:: asm:: dsb ( ) ;
720
725
721
-
722
726
// Cache lines are fixed to 32 bit on Cortex-M7 and not present in earlier Cortex-M
723
- const LINESIZE : u32 = 32 ;
727
+ const LINESIZE : usize = 32 ;
728
+ let num_lines = ( ( size - 1 ) /LINESIZE ) + 1 ;
724
729
725
730
let mut addr = addr & 0xFFFF_FFE0 ;
726
731
727
- for _ in 0 ..( size/ LINESIZE ) {
728
- cbp. dcimvac ( addr) ;
732
+ for _ in 0 ..num_lines {
733
+ cbp. dcimvac ( addr as u32 ) ;
729
734
addr += LINESIZE ;
730
735
}
731
736
@@ -741,19 +746,25 @@ impl Scb {
741
746
/// Cleans cache starting from the lowest 32-byte aligned address represented by `addr`,
742
747
/// in blocks of 32 bytes until at least `size` bytes have been cleaned.
743
748
#[ inline]
744
- pub fn clean_dcache_by_address ( & self , addr : u32 , size : u32 ) {
749
+ pub fn clean_dcache_by_address ( & self , addr : usize , size : usize ) {
750
+ // No-op zero sized operations
751
+ if size == 0 {
752
+ return ;
753
+ }
754
+
745
755
// All of CBP is write-only so no data races are possible
746
756
let cbp = unsafe { & mut * CBP . get ( ) } ;
747
757
748
758
:: asm:: dsb ( ) ;
749
759
750
760
// Cache lines are fixed to 32 bit on Cortex-M7 and not present in earlier Cortex-M
751
- const LINESIZE : u32 = 32 ;
761
+ const LINESIZE : usize = 32 ;
762
+ let num_lines = ( ( size - 1 ) /LINESIZE ) + 1 ;
752
763
753
764
let mut addr = addr & 0xFFFF_FFE0 ;
754
765
755
- for _ in 0 ..( size/ LINESIZE ) {
756
- cbp. dccmvac ( addr) ;
766
+ for _ in 0 ..num_lines {
767
+ cbp. dccmvac ( addr as u32 ) ;
757
768
addr += LINESIZE ;
758
769
}
759
770
@@ -770,19 +781,25 @@ impl Scb {
770
781
/// by `addr`, in blocks of 32 bytes until at least `size` bytes have been cleaned and
771
782
/// invalidated.
772
783
#[ inline]
773
- pub fn clean_invalidate_dcache_by_address ( & self , addr : u32 , size : u32 ) {
784
+ pub fn clean_invalidate_dcache_by_address ( & self , addr : usize , size : usize ) {
785
+ // No-op zero sized operations
786
+ if size == 0 {
787
+ return ;
788
+ }
789
+
774
790
// All of CBP is write-only so no data races are possible
775
791
let cbp = unsafe { & mut * CBP . get ( ) } ;
776
792
777
793
:: asm:: dsb ( ) ;
778
794
779
795
// Cache lines are fixed to 32 bit on Cortex-M7 and not present in earlier Cortex-M
780
- const LINESIZE : u32 = 32 ;
796
+ const LINESIZE : usize = 32 ;
797
+ let num_lines = ( ( size - 1 ) /LINESIZE ) + 1 ;
781
798
782
799
let mut addr = addr & 0xFFFF_FFE0 ;
783
800
784
- for _ in 0 ..( size/ LINESIZE ) {
785
- cbp. dccimvac ( addr) ;
801
+ for _ in 0 ..num_lines {
802
+ cbp. dccimvac ( addr as u32 ) ;
786
803
addr += LINESIZE ;
787
804
}
788
805
0 commit comments