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 <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
This commit is contained in:
Ard Biesheuvel 2017-08-30 08:02:15 +01:00
parent 7385d2543e
commit 0bcb801067
3 changed files with 19 additions and 1 deletions

View File

@ -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

View File

@ -19,6 +19,14 @@
#include <Library/MemoryAllocationLib.h>
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;
}

View File

@ -31,3 +31,6 @@
[LibraryClasses]
DebugLib
MemoryAllocationLib
[Pcd]
gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset