]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
Fix issue in DmaMap with buffers that are smaller than a cache line. Also make any...
[mirror_edk2.git] / ArmPkg / Library / ArmDmaLib / ArmDmaLib.c
index 9467fa5b474ea9cda23bcf157f2c109fe5314c8b..7fef208c78c1867122275960bb912c4c7d011503 100755 (executable)
@@ -95,7 +95,12 @@ DmaMap (
   \r
   *Mapping = Map;\r
 \r
-  if (((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) {\r
+  if ((((UINTN)HostAddress & (gCacheAlignment - 1)) != 0) ||\r
+      ((*NumberOfBytes % gCacheAlignment) != 0)) {\r
+    //\r
+    // If the buffer does not fill entire cache lines we must double buffer into \r
+    // uncached memory. Device (PCI) address becomes uncached page.\r
+    //\r
     Map->DoubleBuffer  = TRUE;\r
     Status = DmaAllocateBuffer (EfiBootServicesData, EFI_SIZE_TO_PAGES (*NumberOfBytes), &Buffer);\r
     if (EFI_ERROR (Status)) {\r
@@ -108,8 +113,6 @@ DmaMap (
     Map->DoubleBuffer  = FALSE;\r
   }\r
 \r
-  *NumberOfBytes &= *NumberOfBytes & ~(gCacheAlignment - 1); // Only do it on full cache lines\r
-  \r
   Map->HostAddress   = (UINTN)HostAddress;\r
   Map->DeviceAddress = *DeviceAddress;\r
   Map->NumberOfBytes = *NumberOfBytes;\r