X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FBaseCacheMaintenanceLib%2Fx86Cache.c;h=276e763309472c595751159e1cacf706c807167d;hb=76474b57669520f29958bcaf336bb300e38ceae8;hp=3879cdfa2d2b05927f32e71324de2f8bfbd80005;hpb=9f84a60982db062161f0c70827f4d844fa87d472;p=mirror_edk2.git diff --git a/MdePkg/Library/BaseCacheMaintenanceLib/x86Cache.c b/MdePkg/Library/BaseCacheMaintenanceLib/x86Cache.c index 3879cdfa2d..276e763309 100644 --- a/MdePkg/Library/BaseCacheMaintenanceLib/x86Cache.c +++ b/MdePkg/Library/BaseCacheMaintenanceLib/x86Cache.c @@ -14,6 +14,17 @@ **/ +// +// Include common header file for this module. +// +#include "CommonHeader.h" + +// +// This size must be at or below the smallest cache size possible among all +// supported processors +// +#define CACHE_LINE_SIZE 0x20 + /** Invalidates the entire instruction cache in cache coherency domain of the calling CPU. @@ -118,19 +129,21 @@ WriteBackInvalidateDataCacheRange ( IN UINTN Length ) { - UINT8 (*Uint8Ptr)[32]; + UINTN Start, End; ASSERT (Length <= MAX_ADDRESS - (UINTN)Address + 1); - Uint8Ptr = Address; - while (Length > sizeof (*Uint8Ptr)) { - AsmFlushCacheLine (Uint8Ptr++); - Length -= sizeof (*Uint8Ptr); - } - if (Length > 0) { - AsmFlushCacheLine (Uint8Ptr); - AsmFlushCacheLine (&(*Uint8Ptr)[Length - 1]); + if (Length == 0) { + return Address; } + + Start = (UINTN)Address; + End = (Start + Length + (CACHE_LINE_SIZE - 1)) & ~(CACHE_LINE_SIZE - 1); + Start &= ~(CACHE_LINE_SIZE - 1); + + do { + Start = (UINTN)AsmFlushCacheLine ((VOID*)Start) + CACHE_LINE_SIZE; + } while (Start != End); return Address; }