public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] ArmPkg/ArmDmaLib: add support for fixed host-to-device DMA offset
@ 2016-11-08 13:04 Ard Biesheuvel
  2016-11-09 21:13 ` Leif Lindholm
  0 siblings, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2016-11-08 13:04 UTC (permalink / raw)
  To: edk2-devel, leif.lindholm; +Cc: Ard Biesheuvel

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>
---
 ArmPkg/ArmPkg.dec                      |  6 ++++++
 ArmPkg/Library/ArmDmaLib/ArmDmaLib.c   | 13 +++++++++++--
 ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf |  1 +
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec
index 3cdb5da3d4f3..b2d59a168337 100644
--- a/ArmPkg/ArmPkg.dec
+++ b/ArmPkg/ArmPkg.dec
@@ -134,6 +134,12 @@ [PcdsFixedAtBuild.common]
   gArmTokenSpaceGuid.PcdFdSize|0|UINT32|0x0000002C
   gArmTokenSpaceGuid.PcdFvSize|0|UINT32|0x0000002E
 
+  #
+  # Value to add to a host address to obtain a device address
+  # (using unsigned 64-bit integer arithmetic on both ARM and AArch64)
+  #
+  gArmTokenSpaceGuid.PcdArmDmaDeviceOffset|0x0|UINT64|0x0000044
+
 [PcdsFixedAtBuild.common, PcdsPatchableInModule.common]
   gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B
   gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D
diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
index d48d6ff6dbbb..d6dee78a254d 100644
--- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
+++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
@@ -39,6 +39,15 @@ typedef struct {
 EFI_CPU_ARCH_PROTOCOL      *gCpu;
 UINTN                      gCacheAlignment = 0;
 
+STATIC
+PHYSICAL_ADDRESS
+HostToDeviceAddress (
+  IN  PHYSICAL_ADDRESS  HostAddress
+  )
+{
+  return HostAddress + PcdGet64 (PcdArmDmaDeviceOffset);
+}
+
 /**
   Provides the DMA controller-specific addresses needed to access system memory.
 
@@ -82,7 +91,7 @@ DmaMap (
     return EFI_INVALID_PARAMETER;
   }
 
-  *DeviceAddress = ConvertToPhysicalAddress (HostAddress);
+  *DeviceAddress = HostToDeviceAddress (ConvertToPhysicalAddress (HostAddress));
 
   // Remember range so we can flush on the other side
   Map = AllocatePool (sizeof (MAP_INFO_INSTANCE));
@@ -129,7 +138,7 @@ DmaMap (
         CopyMem (Buffer, HostAddress, *NumberOfBytes);
       }
 
-      *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)Buffer;
+      *DeviceAddress = HostToDeviceAddress ((PHYSICAL_ADDRESS)(UINTN)Buffer);
     } else {
       Map->DoubleBuffer  = FALSE;
     }
diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
index 95c13006eaac..36c23f486974 100644
--- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
+++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
@@ -46,6 +46,7 @@ [Protocols]
 [Guids]
 
 [Pcd]
+  gArmTokenSpaceGuid.PcdArmDmaDeviceOffset
 
 [Depex]
   gEfiCpuArchProtocolGuid
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-11-10  0:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-08 13:04 [PATCH] ArmPkg/ArmDmaLib: add support for fixed host-to-device DMA offset Ard Biesheuvel
2016-11-09 21:13 ` Leif Lindholm
2016-11-09 21:31   ` Ard Biesheuvel
2016-11-10  0:03     ` Leif Lindholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox