From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x232.google.com (mail-wm0-x232.google.com [IPv6:2a00:1450:400c:c09::232]) (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 1E87781CC5 for ; Wed, 9 Nov 2016 13:13:23 -0800 (PST) Received: by mail-wm0-x232.google.com with SMTP id f82so267335180wmf.1 for ; Wed, 09 Nov 2016 13:13:26 -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=crmDKpgQ9jOoptpFm0R0RKbAwSX7NbTgKkNORZTdtlI=; b=DMR4todSxue/K/dtXUS2wjjqCQp8PzRop1HiPFASQY0hAZlWZGo+bBSelnRE6SuAoO jppslhE/a5bdp5vpdOL6Wq4UTLjyC6cjicFfwRawiaX+cGyj4DCHwYoto5fxk6FN5CK1 SSL+siDFKOuAEfjA6Eqq/4uMypAPuJs9rABpQ= 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=crmDKpgQ9jOoptpFm0R0RKbAwSX7NbTgKkNORZTdtlI=; b=NEDnhV9DkMpkwaoFT+MCBiVWSikau6UPz9ebhPT52cC8gyNQWiVRmE0SVQs8vK7mdJ fnUCjwAJmSH0hQD4AGoM10oJZN7ip0jnxHExxvImOUX0KfSp3UsraDo1LQAaRI1aM5Ke qztrdzB+UEfgiriQehl9NgeHSUYf0Q9uG67kV+nzyfGMdJxZLuQnhZ1qxlUabGW9TDOt GZHR/QCmgxvH0jwIkbD1evvFwgptuyIv8f2/V6JyiyLU6epShpT7f+fUqQDXIWoy5tlY xLWf4233AS3UD2JMFI9MgN1rme7R2K7PnLpTsThfO2RV3Fao19a/CdWVhrGrfdKKL1bl enLA== X-Gm-Message-State: ABUngvdYOYL6acyWyLzxfxOxmqDxjGBanQq6J6h8uh/iXyTJn44G3PmJtZz2xVC9YJlhl/G7 X-Received: by 10.194.120.226 with SMTP id lf2mr1458582wjb.130.1478726004722; Wed, 09 Nov 2016 13:13:24 -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 p184sm2403296wmg.3.2016.11.09.13.13.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Nov 2016 13:13:24 -0800 (PST) Date: Wed, 9 Nov 2016 21:13:22 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org Message-ID: <20161109211322.GO27644@bivouac.eciton.net> References: <1478610295-22065-1-git-send-email-ard.biesheuvel@linaro.org> MIME-Version: 1.0 In-Reply-To: <1478610295-22065-1-git-send-email-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [PATCH] 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: Wed, 09 Nov 2016 21:13:23 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Nov 08, 2016 at 01:04:55PM +0000, 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 > --- > 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 > + Is the offset always positive? > [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 >