From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-x22b.google.com (mail-lf0-x22b.google.com [IPv6:2a00:1450:4010:c07::22b]) (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 1966181C91 for ; Wed, 9 Nov 2016 13:31:41 -0800 (PST) Received: by mail-lf0-x22b.google.com with SMTP id c13so174639903lfg.0 for ; Wed, 09 Nov 2016 13:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:mime-version:content-transfer-encoding :message-id:cc:from:subject:date:to; bh=JHxMpBAqsmG97NbkJ5Krz5hRk/FGw56BSaYnmSNRrsw=; b=eVRbFHy6FR1jmi1/hjKvJ1+SCyo/lMJPCegkmV8hiadSOG4nkgyTOPYJOQH13pccy6 Y5gaetKQQy1aqLf4Abv4+7WG/D79bO2UgMJwr8b3+LjKQZkuTKXbO5UjKzMPLWChEHxD SGROyfca460/3b04vERTo4b+VRAAeh6plhEmk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:references:in-reply-to:mime-version :content-transfer-encoding:message-id:cc:from:subject:date:to; bh=JHxMpBAqsmG97NbkJ5Krz5hRk/FGw56BSaYnmSNRrsw=; b=AmWbRRReTROEJ5Nqc2vqwggmBnUzWBuIAuMKmv1EQ65dZXiCiYMUscPjU9kUqp0DlD HR10vsSG2KmJRAP2DAPDUjTrBpw6M2d0FR63yfvkyA3ujLkj9ZDpL1UY7bbYLWO6W4yy vJXt0qE7xtdU0GJRmNgUOF4zF81Nd5uyKWY67FtXRzGVNrzMHCCJ3aEPfhizIqSQQG3K W7+DTk+8F5JJUHhj70yAw9Kwdgg09RIEg9nYmeSmkcmvJWEEN2P31I0c1SfOh7u7sGIS cW/AtQsEtPcrAncT3F4Kf83hcrJb6Au3Ch9vYUfR6yltO/O+Qh7hvr0VFSuu2UAyMrlG xB1A== X-Gm-Message-State: ABUngvdbpVutudF9DDG23fZC+UKsJEnT482GXLRWd+tBNdh2Us6ogOqWWNcu9n7ctjZJ58xB X-Received: by 10.25.165.144 with SMTP id o138mr972347lfe.80.1478727102191; Wed, 09 Nov 2016 13:31:42 -0800 (PST) Received: from [10.234.205.18] ([91.73.131.133]) by smtp.gmail.com with ESMTPSA id h95sm310924ljh.13.2016.11.09.13.31.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Nov 2016 13:31:41 -0800 (PST) References: <1478610295-22065-1-git-send-email-ard.biesheuvel@linaro.org> <20161109211322.GO27644@bivouac.eciton.net> In-Reply-To: <20161109211322.GO27644@bivouac.eciton.net> Mime-Version: 1.0 (1.0) Message-Id: <5A799EA5-3A9D-4164-9EE8-0862A5FE5A66@linaro.org> Cc: edk2-devel@lists.01.org X-Mailer: iPhone Mail (14B100) From: Ard Biesheuvel Date: Thu, 10 Nov 2016 01:31:38 +0400 To: Leif Lindholm 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:31:41 -0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On 10 Nov 2016, at 01:13, Leif Lindholm wrote: >=20 >> 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 memo= ry >> addresses as seen by the host and as seen by the other bus masters. So ad= d >> a new PCD that allows this fixed offset to be recorded, and to be used wh= en >> returning device addresses from the DmaLib mapping routines. >>=20 >> 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(-) >>=20 >> 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 >>=20 >> + # >> + # 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 >> + >=20 > Is the offset always positive? >=20 No, hence the comment (which apparently deserves some clarification) The idea is that, even on a pure 32-bit system, a negative offset can be exp= ressed by wrapping unsigned integer arithmetic, e.g., 0xffffffff_fffff000 fo= r -4 kB >> [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/ArmDma= Lib/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 =3D 0; >>=20 >> +STATIC >> +PHYSICAL_ADDRESS >> +HostToDeviceAddress ( >> + IN PHYSICAL_ADDRESS HostAddress >> + ) >> +{ >> + return HostAddress + PcdGet64 (PcdArmDmaDeviceOffset); >> +} >> + >> /** >> Provides the DMA controller-specific addresses needed to access system m= emory. >>=20 >> @@ -82,7 +91,7 @@ DmaMap ( >> return EFI_INVALID_PARAMETER; >> } >>=20 >> - *DeviceAddress =3D ConvertToPhysicalAddress (HostAddress); >> + *DeviceAddress =3D HostToDeviceAddress (ConvertToPhysicalAddress (Host= Address)); >>=20 >> // Remember range so we can flush on the other side >> Map =3D AllocatePool (sizeof (MAP_INFO_INSTANCE)); >> @@ -129,7 +138,7 @@ DmaMap ( >> CopyMem (Buffer, HostAddress, *NumberOfBytes); >> } >>=20 >> - *DeviceAddress =3D (PHYSICAL_ADDRESS)(UINTN)Buffer; >> + *DeviceAddress =3D HostToDeviceAddress ((PHYSICAL_ADDRESS)(UINTN)B= uffer); >> } else { >> Map->DoubleBuffer =3D FALSE; >> } >> diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf b/ArmPkg/Library/ArmD= maLib/ArmDmaLib.inf >> index 95c13006eaac..36c23f486974 100644 >> --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf >> +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf >> @@ -46,6 +46,7 @@ [Protocols] >> [Guids] >>=20 >> [Pcd] >> + gArmTokenSpaceGuid.PcdArmDmaDeviceOffset >>=20 >> [Depex] >> gEfiCpuArchProtocolGuid >> --=20 >> 2.7.4 >>=20