]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
ArmPkg/ArmDmaLib: add support for fixed host-to-device DMA offset
[mirror_edk2.git] / ArmPkg / Library / ArmDmaLib / ArmDmaLib.c
index f39d30c44e22553a62050e9d4e757de6a3637a9c..acc106bcf4a8b609943660ac1293cf2571607c8e 100644 (file)
@@ -37,6 +37,15 @@ typedef struct {
 \r
 STATIC EFI_CPU_ARCH_PROTOCOL      *mCpu;\r
 \r
+STATIC\r
+PHYSICAL_ADDRESS\r
+HostToDeviceAddress (\r
+  IN  PHYSICAL_ADDRESS  HostAddress\r
+  )\r
+{\r
+  return HostAddress + PcdGet64 (PcdArmDmaDeviceOffset);\r
+}\r
+\r
 /**\r
   Provides the DMA controller-specific addresses needed to access system memory.\r
 \r
@@ -80,7 +89,14 @@ DmaMap (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  *DeviceAddress = ConvertToPhysicalAddress (HostAddress);\r
+  //\r
+  // The debug implementation of UncachedMemoryAllocationLib in ArmPkg returns\r
+  // a virtual uncached alias, and unmaps the cached ID mapping of the buffer,\r
+  // in order to catch inadvertent references to the cached mapping.\r
+  // Since HostToDeviceAddress () expects ID mapped input addresses, convert\r
+  // the host address to an ID mapped address first.\r
+  //\r
+  *DeviceAddress = HostToDeviceAddress (ConvertToPhysicalAddress (HostAddress));\r
 \r
   // Remember range so we can flush on the other side\r
   Map = AllocatePool (sizeof (MAP_INFO_INSTANCE));\r
@@ -126,7 +142,7 @@ DmaMap (
         CopyMem (Buffer, HostAddress, *NumberOfBytes);\r
       }\r
 \r
-      *DeviceAddress = ConvertToPhysicalAddress ((UINTN)Buffer);\r
+      *DeviceAddress = HostToDeviceAddress (ConvertToPhysicalAddress ((UINTN)Buffer));\r
       Map->BufferAddress = Buffer;\r
     } else {\r
       Map->DoubleBuffer  = FALSE;\r