]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmDmaLib: clean up abuse of device address
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Sat, 12 Nov 2016 13:02:27 +0000 (14:02 +0100)
committerLeif Lindholm <leif.lindholm@linaro.org>
Wed, 30 Nov 2016 16:43:08 +0000 (16:43 +0000)
In preparation of adding support to ArmDmalib for DMA bus masters whose
view of memory is offset by a constant compared to the CPU's view, clean
up some abuse of the device address.

The device address is not defined in terms of the CPU's address space,
and so it should not be used in CopyMem () or cache maintenance operations
that require a valid mapping. This not only applies to the above use case,
but also to the DebugUncachedMemoryAllocationLib that unmaps the
primary, cached mapping of an allocation, and returns a host address
which is an uncached alias offset by a constant.

Since we should never access the device address from the CPU, there is
no need to record it in the MAPINFO struct. Instead, record the buffer
address in case of double buffering, since we do need to copy the contents
(in case of a bus master write) and free the buffer (in all cases) when
DmaUnmap() is called.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Ryan Harkin <ryan.harkin@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPkg/Library/ArmDmaLib/ArmDmaLib.c

index 6afce87024e7a2d018076b25ba7ec3a590868c19..f39d30c44e22553a62050e9d4e757de6a3637a9c 100644 (file)
@@ -27,7 +27,7 @@
 \r
 typedef struct {\r
   EFI_PHYSICAL_ADDRESS      HostAddress;\r
-  EFI_PHYSICAL_ADDRESS      DeviceAddress;\r
+  VOID                      *BufferAddress;\r
   UINTN                     NumberOfBytes;\r
   DMA_MAP_OPERATION         Operation;\r
   BOOLEAN                   DoubleBuffer;\r
@@ -92,7 +92,7 @@ DmaMap (
       ((*NumberOfBytes & (mCpu->DmaBufferAlignment - 1)) != 0)) {\r
 \r
     // Get the cacheability of the region\r
-    Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);\r
+    Status = gDS->GetMemorySpaceDescriptor ((UINTN)HostAddress, &GcdDescriptor);\r
     if (EFI_ERROR(Status)) {\r
       goto FreeMapInfo;\r
     }\r
@@ -127,6 +127,7 @@ DmaMap (
       }\r
 \r
       *DeviceAddress = ConvertToPhysicalAddress ((UINTN)Buffer);\r
+      Map->BufferAddress = Buffer;\r
     } else {\r
       Map->DoubleBuffer  = FALSE;\r
     }\r
@@ -142,7 +143,7 @@ DmaMap (
     // So duplicate the check here when running in DEBUG mode, just to assert\r
     // that we are not trying to create a consistent mapping for cached memory.\r
     //\r
-    Status = gDS->GetMemorySpaceDescriptor (*DeviceAddress, &GcdDescriptor);\r
+    Status = gDS->GetMemorySpaceDescriptor ((UINTN)HostAddress, &GcdDescriptor);\r
     ASSERT_EFI_ERROR(Status);\r
 \r
     ASSERT (Operation != MapOperationBusMasterCommonBuffer ||\r
@@ -151,12 +152,11 @@ DmaMap (
     DEBUG_CODE_END ();\r
 \r
     // Flush the Data Cache (should not have any effect if the memory region is uncached)\r
-    mCpu->FlushDataCache (mCpu, *DeviceAddress, *NumberOfBytes,\r
+    mCpu->FlushDataCache (mCpu, (UINTN)HostAddress, *NumberOfBytes,\r
             EfiCpuFlushTypeWriteBackInvalidate);\r
   }\r
 \r
   Map->HostAddress   = (UINTN)HostAddress;\r
-  Map->DeviceAddress = *DeviceAddress;\r
   Map->NumberOfBytes = *NumberOfBytes;\r
   Map->Operation     = Operation;\r
 \r
@@ -206,10 +206,11 @@ DmaUnmap (
     if (Map->Operation == MapOperationBusMasterCommonBuffer) {\r
       Status = EFI_INVALID_PARAMETER;\r
     } else if (Map->Operation == MapOperationBusMasterWrite) {\r
-      CopyMem ((VOID *)(UINTN)Map->HostAddress, (VOID *)(UINTN)Map->DeviceAddress, Map->NumberOfBytes);\r
+      CopyMem ((VOID *)(UINTN)Map->HostAddress, Map->BufferAddress,\r
+        Map->NumberOfBytes);\r
     }\r
 \r
-    DmaFreeBuffer (EFI_SIZE_TO_PAGES (Map->NumberOfBytes), (VOID *)(UINTN)Map->DeviceAddress);\r
+    DmaFreeBuffer (EFI_SIZE_TO_PAGES (Map->NumberOfBytes), Map->BufferAddress);\r
 \r
   } else {\r
     if (Map->Operation == MapOperationBusMasterWrite) {\r