From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x230.google.com (mail-wm0-x230.google.com [IPv6:2a00:1450:400c:c09::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 25B2881E0A for ; Mon, 14 Nov 2016 07:17:00 -0800 (PST) Received: by mail-wm0-x230.google.com with SMTP id g23so103822223wme.1 for ; Mon, 14 Nov 2016 07:17:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RiAfuVMCpajbziHMbruSdWQHWIFzT9PbKW3sEB1e8Nc=; b=RMmEUEIweeG38qNwJ2je+LbgDS2D8MKqVmKkK9U5ATdYq+HzkPx6LiXpQMWm0Yd4CG zjCYhhyprV9yi3r1v07wWonQtgElBffEs1CrRM+OWLQz5mCsVlxFXLIX5k+VrNj0GZEp sFoaFSlkSRo7HRHugVIJmFrvm661ZPe5bnZeU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=RiAfuVMCpajbziHMbruSdWQHWIFzT9PbKW3sEB1e8Nc=; b=lj9L8X0ZS06+8ike+TKwyUmsGsp8cTqx4CTHynwTlbLaNzPHHCOsMO7bQpPfZnzGOv aV7c0ffj6WBbO9/38qSaltNJHO+WApxiUrFmH3FMDJ1TSAzKP1jDpl/MX4OH7EXNG17B toeXV8E/3CovaUU7YQj2NYdX2yErevLQ03x2hRYfOpJjiekQL/eTDO1x8YTlrMsVVB9B 8rZ4SiUJrrrux8ojQD7fxg7Fs8EF9gfle+N8UXXF9X4FEdJtc3wtw9tcl/OO9uekhPSr tjF1iWrECxBGqugDuejyM1q7juuqGLZMfazFZrJqNjkdKfiUxWCT5gTRcVddc3h3RlF9 1MfQ== X-Gm-Message-State: ABUngvdVdrjVPuTA0BITAui2z7niTe6SLtTHyYBsibormT9I/GDI8CbpjUlESjJ5/cunT111 X-Received: by 10.28.111.70 with SMTP id k67mr10679443wmc.32.1479136623334; Mon, 14 Nov 2016 07:17:03 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id b9sm13595254wjv.48.2016.11.14.07.17.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Nov 2016 07:17:02 -0800 (PST) Date: Mon, 14 Nov 2016 15:17:01 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org Message-ID: <20161114151701.GS27644@bivouac.eciton.net> References: <1478955748-14819-1-git-send-email-ard.biesheuvel@linaro.org> <1478955748-14819-5-git-send-email-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <1478955748-14819-5-git-send-email-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [PATCH v2 4/4] ArmPkg/ArmDmaLib: add support for fixed host-to-device DMA offset X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Nov 2016 15:17:00 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 Much more Leif-friendly, thanks. Reviewed-by: Leif Lindholm > --- > 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 >