From cf580da1bc4c16026cb1732f741a892b2d3d3d67 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Wed, 11 May 2016 10:38:47 +0200 Subject: ArmPkg/ArmLib: don't invalidate entire I-cache on range operation Instead of cleaning the data cache to the PoU by virtual address and subsequently invalidating the entire I-cache, invalidate only the range that we just cleaned. This way, we don't invalidate other cachelines unnecessarily. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- .../ArmCacheMaintenanceLib.c | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'ArmPkg/Library/ArmCacheMaintenanceLib') diff --git a/ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c b/ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c index 1045f9068f..0759e38cd4 100644 --- a/ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c +++ b/ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c @@ -17,15 +17,16 @@ #include #include +STATIC VOID CacheRangeOperation ( IN VOID *Start, IN UINTN Length, - IN LINE_OPERATION LineOperation + IN LINE_OPERATION LineOperation, + IN UINTN LineLength ) { - UINTN ArmCacheLineLength = ArmDataCacheLineLength(); - UINTN ArmCacheLineAlignmentMask = ArmCacheLineLength - 1; + UINTN ArmCacheLineAlignmentMask = LineLength - 1; // Align address (rounding down) UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask); @@ -34,7 +35,7 @@ CacheRangeOperation ( // Perform the line operation on an address in each cache line while (AlignedAddress < EndAddress) { LineOperation(AlignedAddress); - AlignedAddress += ArmCacheLineLength; + AlignedAddress += LineLength; } ArmDataSynchronizationBarrier (); } @@ -64,8 +65,14 @@ InvalidateInstructionCacheRange ( IN UINTN Length ) { - CacheRangeOperation (Address, Length, ArmCleanDataCacheEntryToPoUByMVA); - ArmInvalidateInstructionCache (); + CacheRangeOperation (Address, Length, ArmCleanDataCacheEntryToPoUByMVA, + ArmDataCacheLineLength ()); + CacheRangeOperation (Address, Length, + ArmInvalidateInstructionCacheEntryToPoUByMVA, + ArmInstructionCacheLineLength ()); + + ArmInstructionSynchronizationBarrier (); + return Address; } @@ -85,7 +92,8 @@ WriteBackInvalidateDataCacheRange ( IN UINTN Length ) { - CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCacheEntryByMVA); + CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCacheEntryByMVA, + ArmDataCacheLineLength ()); return Address; } @@ -105,7 +113,8 @@ WriteBackDataCacheRange ( IN UINTN Length ) { - CacheRangeOperation(Address, Length, ArmCleanDataCacheEntryByMVA); + CacheRangeOperation(Address, Length, ArmCleanDataCacheEntryByMVA, + ArmDataCacheLineLength ()); return Address; } @@ -116,6 +125,7 @@ InvalidateDataCacheRange ( IN UINTN Length ) { - CacheRangeOperation(Address, Length, ArmInvalidateDataCacheEntryByMVA); + CacheRangeOperation(Address, Length, ArmInvalidateDataCacheEntryByMVA, + ArmDataCacheLineLength ()); return Address; } -- cgit v1.2.3