From: Leif Lindholm <leif.lindholm@linaro.org>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: edk2-devel@lists.01.org
Subject: Re: [PATCH v2 4/4] ArmPkg/ArmDmaLib: add support for fixed host-to-device DMA offset
Date: Mon, 14 Nov 2016 15:17:01 +0000 [thread overview]
Message-ID: <20161114151701.GS27644@bivouac.eciton.net> (raw)
In-Reply-To: <1478955748-14819-5-git-send-email-ard.biesheuvel@linaro.org>
On Sat, Nov 12, 2016 at 02:02:28PM +0100, Ard Biesheuvel wrote:
> 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>
Much more Leif-friendly, thanks.
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
> ---
> ArmPkg/ArmPkg.dec | 8 ++++++++
> ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 20 ++++++++++++++++++--
> ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf | 1 +
> 3 files changed, 27 insertions(+), 2 deletions(-)
>
> diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec
> index 3cdb5da3d4f3..090ed9951366 100644
> --- a/ArmPkg/ArmPkg.dec
> +++ b/ArmPkg/ArmPkg.dec
> @@ -134,6 +134,14 @@ [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. This
> + # means we can rely on truncation on overflow to specify negative
> + # offsets.
> + #
> + 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 7321388de63e..1de4a6e5b04f 100644
> --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
> +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c
> @@ -37,6 +37,15 @@ typedef struct {
>
> STATIC EFI_CPU_ARCH_PROTOCOL *mCpu;
>
> +STATIC
> +PHYSICAL_ADDRESS
> +HostToDeviceAddress (
> + IN PHYSICAL_ADDRESS HostAddress
> + )
> +{
> + return HostAddress + PcdGet64 (PcdArmDmaDeviceOffset);
> +}
> +
> /**
> Provides the DMA controller-specific addresses needed to access system memory.
>
> @@ -80,7 +89,14 @@ DmaMap (
> return EFI_INVALID_PARAMETER;
> }
>
> - *DeviceAddress = ConvertToPhysicalAddress (HostAddress);
> + //
> + // The debug implementation of UncachedMemoryAllocationLib in ArmPkg returns
> + // a virtual uncached alias, and unmaps the cached ID mapping of the buffer,
> + // in order to catch inadvertent references to the cached mapping.
> + // Since HostToDeviceAddress () expects ID mapped input addresses, convert
> + // the host address to an ID mapped address first.
> + //
> + *DeviceAddress = HostToDeviceAddress (ConvertToPhysicalAddress (HostAddress));
>
> // Remember range so we can flush on the other side
> Map = AllocatePool (sizeof (MAP_INFO_INSTANCE));
> @@ -127,7 +143,7 @@ DmaMap (
> CopyMem (Buffer, HostAddress, *NumberOfBytes);
> }
>
> - *DeviceAddress = ConvertToPhysicalAddress ((UINTN)Buffer);
> + *DeviceAddress = HostToDeviceAddress (ConvertToPhysicalAddress ((UINTN)Buffer));
> Map->BufferAddress = Buffer;
> } else {
> Map->DoubleBuffer = FALSE;
> diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
> index 31de3cfd828c..9b7dad114b18 100644
> --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
> +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
> @@ -44,6 +44,7 @@ [Protocols]
> [Guids]
>
> [Pcd]
> + gArmTokenSpaceGuid.PcdArmDmaDeviceOffset
>
> [Depex]
> gEfiCpuArchProtocolGuid
> --
> 2.7.4
>
prev parent reply other threads:[~2016-11-14 15:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-12 13:02 [PATCH v2 0/4] ArmPkg: more ArmDmaLib fixes Ard Biesheuvel
2016-11-12 13:02 ` [PATCH v2 1/4] ArmPkg/ArmDmaLib: use DMA buffer alignment from CPU arch protocol Ard Biesheuvel
2016-11-14 15:18 ` Leif Lindholm
2016-11-12 13:02 ` [PATCH v2 2/4] ArmPkg/ArmDmaLib: fix incorrect device address of double buffer Ard Biesheuvel
2016-11-14 15:13 ` Leif Lindholm
2016-11-12 13:02 ` [PATCH v2 3/4] ArmPkg/ArmDmaLib: clean up abuse of device address Ard Biesheuvel
2016-11-14 15:16 ` Leif Lindholm
2016-11-15 9:19 ` Ard Biesheuvel
2016-11-15 11:34 ` Ryan Harkin
2016-11-15 13:07 ` Ard Biesheuvel
2016-11-15 18:01 ` Leif Lindholm
2016-11-30 16:45 ` Leif Lindholm
2016-11-12 13:02 ` [PATCH v2 4/4] ArmPkg/ArmDmaLib: add support for fixed host-to-device DMA offset Ard Biesheuvel
2016-11-14 15:17 ` Leif Lindholm [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161114151701.GS27644@bivouac.eciton.net \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox