]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmDmaLib: add support for fixed host-to-device DMA offset
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Sat, 12 Nov 2016 13:02:28 +0000 (14:02 +0100)
committerLeif Lindholm <leif.lindholm@linaro.org>
Wed, 30 Nov 2016 16:43:14 +0000 (16:43 +0000)
Some devices, such as the Raspberry Pi3, have a fixed offset between memory
addresses as seen by the host and as seen by the other bus masters. So add
a new PCD that allows this fixed offset to be recorded, and to be used when
returning device addresses from the DmaLib mapping routines.

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/ArmPkg.dec
ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf

index 3cdb5da3d4f3fcdfa8e13f465d0a25fc04c9c515..090ed99513669e32aee2f083e1dcf8327be40842 100644 (file)
   gArmTokenSpaceGuid.PcdFdSize|0|UINT32|0x0000002C\r
   gArmTokenSpaceGuid.PcdFvSize|0|UINT32|0x0000002E\r
 \r
+  #\r
+  # Value to add to a host address to obtain a device address, using\r
+  # unsigned 64-bit integer arithmetic on both ARM and AArch64. This\r
+  # means we can rely on truncation on overflow to specify negative\r
+  # offsets.\r
+  #\r
+  gArmTokenSpaceGuid.PcdArmDmaDeviceOffset|0x0|UINT64|0x0000044\r
+\r
 [PcdsFixedAtBuild.common, PcdsPatchableInModule.common]\r
   gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B\r
   gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D\r
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
index 31de3cfd828c69316e52ae66a83ca8a3ca4b5fe8..9b7dad114b184586346050363d0dac36f35cb0ad 100644 (file)
@@ -44,6 +44,7 @@
 [Guids]\r
 \r
 [Pcd]\r
+  gArmTokenSpaceGuid.PcdArmDmaDeviceOffset\r
 \r
 [Depex]\r
   gEfiCpuArchProtocolGuid\r