From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com [IPv6:2a00:1450:400c:c09::235]) (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 65AC281C8D for ; Wed, 9 Nov 2016 16:03:34 -0800 (PST) Received: by mail-wm0-x235.google.com with SMTP id f82so273589253wmf.1 for ; Wed, 09 Nov 2016 16:03:37 -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=Vc/AVfUyj2ONqnXjfxKseJjMXS4aItTu5H8WOO0E20Q=; b=MCPx4Ur2Bej407oq7A+M8axtnuHsTwAR4LGZnnZqmpTcwMeeUoIBJzGZd4LIZZZ/Pa Vi3zGIdLGdXkTOdz0ke8buTzqkos/jOrQbFNh9U8/7OMr6W21ZMy/OFvWAOf88Q3/Gpi TdQ7Mn3P8WDn3jgsQH8/NhljFkZY9PlDOY8xQ= 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=Vc/AVfUyj2ONqnXjfxKseJjMXS4aItTu5H8WOO0E20Q=; b=exG0NwjcaJ0N3QbKrGZ2QrM+uTgL1eZ+Jrse7S7FYc3dmIcm6fjMo0Epj3s2u86WqX QMk62IurXBblbjO7yDFOajV/7iXMV1rTBWVWRVLsKRvhG9MA/HIltTDB8qOoj6Jvo3nA 73zwafYjdkyLSgYkLJDdG8IjIRyY9oxMcnhHyrZqsf64Bx2udUApwOFoo1HqSX/n9HyH RDuh6eNm4E7ZSecG+K80kfeSs5TFsDBjl0nUHgNW0Ks5rdiZnVhFbQV+I02WSEenvgin ELOnLIdoQqmEpFXRIcm3XamJUGYJDO3lFVj+hZm9RMv6X0UfHeuk7M+NOb1hop7xjt0D AVAA== X-Gm-Message-State: ABUngvfawqrxxUop+XWTOiV40skXlQ+yRMBt2XbBRoGK7HD8N+hW/skF7rkNIad0qRE15iu1 X-Received: by 10.194.103.165 with SMTP id fx5mr1826465wjb.188.1478736216004; Wed, 09 Nov 2016 16:03:36 -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 za1sm2330897wjb.8.2016.11.09.16.03.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Nov 2016 16:03:35 -0800 (PST) Date: Thu, 10 Nov 2016 00:03:33 +0000 From: Leif Lindholm To: Ard Biesheuvel Cc: edk2-devel@lists.01.org Message-ID: <20161110000333.GP27644@bivouac.eciton.net> References: <1478610295-22065-1-git-send-email-ard.biesheuvel@linaro.org> <20161109211322.GO27644@bivouac.eciton.net> <5A799EA5-3A9D-4164-9EE8-0862A5FE5A66@linaro.org> MIME-Version: 1.0 In-Reply-To: <5A799EA5-3A9D-4164-9EE8-0862A5FE5A66@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: Thu, 10 Nov 2016 00:03:34 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Nov 10, 2016 at 01:31:38AM +0400, Ard Biesheuvel wrote: > > > > On 10 Nov 2016, at 01:13, Leif Lindholm wrote: > > > >> 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? > > > > 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 expressed by wrapping unsigned integer arithmetic, e.g., > 0xffffffff_fffff000 for -4 kB Ah, ok. Yes, I can use something more obvious in the comment anyway :) Although I think the word 'wrap' making an appearance would have been sufficient. / Leif > >> [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 > >>