From 0bcb80106762c65463b1eac4009a59980a65b351 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Wed, 30 Aug 2017 08:02:15 +0100 Subject: [PATCH] EmbeddedPkg/CoherentDmaLib: add support for non-1:1 DMA translation Bring CoherentDmaLib in line with ArmDmaLib, and add support for defining a static offset between the host's and the bus master's view of memory. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- EmbeddedPkg/EmbeddedPkg.dec | 7 +++++++ EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c | 10 +++++++++- EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec index e6861cb59c..0be102ad9c 100644 --- a/EmbeddedPkg/EmbeddedPkg.dec +++ b/EmbeddedPkg/EmbeddedPkg.dec @@ -205,3 +205,10 @@ [PcdsFixedAtBuild.common, PcdsDynamic.common] gEmbeddedTokenSpaceGuid.PcdFdtDevicePaths|L""|VOID*|0x00000055 + + # + # Value to add to a host address to obtain a device address, using + # unsigned 64-bit integer arithmetic. This means we can rely on + # truncation on overflow to specify negative offsets. + # + gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset|0x0|UINT64|0x0000058 diff --git a/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c b/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c index 4cbe349190..564db83c90 100644 --- a/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c +++ b/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c @@ -19,6 +19,14 @@ #include +STATIC +PHYSICAL_ADDRESS +HostToDeviceAddress ( + IN VOID *Address + ) +{ + return (PHYSICAL_ADDRESS)(UINTN)Address + PcdGet64 (PcdDmaDeviceOffset); +} /** Provides the DMA controller-specific addresses needed to access system memory. @@ -50,7 +58,7 @@ DmaMap ( OUT VOID **Mapping ) { - *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)HostAddress; + *DeviceAddress = HostToDeviceAddress (HostAddress); *Mapping = NULL; return EFI_SUCCESS; } diff --git a/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf b/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf index c40a600cf6..f64d780e16 100644 --- a/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf +++ b/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf @@ -31,3 +31,6 @@ [LibraryClasses] DebugLib MemoryAllocationLib + +[Pcd] + gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset