From 3ea3ff88e3fb91dd63da29718bdc454f0d043cee Mon Sep 17 00:00:00 2001 From: andrewfish Date: Thu, 15 Jul 2010 17:27:13 +0000 Subject: [PATCH] Fix issue in DmaMap with buffers that are smaller than a cache line. Also make any buffer that is not an even quanta of cache lines double buffer. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10654 6f19259b-4bc3-4df7-8a09-765794883524 --- ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c index 9467fa5b47..7fef208c78 100755 --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c @@ -95,7 +95,12 @@ DmaMap ( *Mapping = Map; - if (((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) { + if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) || + ((*NumberOfBytes % gCacheAlignment) != 0)) { + // + // If the buffer does not fill entire cache lines we must double buffer into + // uncached memory. Device (PCI) address becomes uncached page. + // Map->DoubleBuffer = TRUE; Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer); if (EFI_ERROR (Status)) { @@ -108,8 +113,6 @@ DmaMap ( Map->DoubleBuffer = FALSE; } - *NumberOfBytes &= *NumberOfBytes & ~(gCacheAlignment - 1); // Only do it on full cache lines - Map->HostAddress = (UINTN)HostAddress; Map->DeviceAddress = *DeviceAddress; Map->NumberOfBytes = *NumberOfBytes; -- 2.39.2