]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
ArmPkg/ArmDmaLib: clean up abuse of device address
[mirror_edk2.git] / 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