From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-x22d.google.com (mail-wr0-x22d.google.com [IPv6:2a00:1450:400c:c0c::22d]) (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 AAF2421E95E0F for ; Wed, 30 Aug 2017 01:18:39 -0700 (PDT) Received: by mail-wr0-x22d.google.com with SMTP id k9so4035687wre.4 for ; Wed, 30 Aug 2017 01:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SgtBES6SoFg23UKzdJujgYroDdhbOcZqSjp3kaa8R+A=; b=R5b//KOwKBnGJ5lcED39JT21ICC4T7APPBx4JVupzkMZo+PBRKKpCVKrOIz8DuA9n4 oYeP0w+dOA49eGxvqRq4up7EOmbSfEbK2IpOqFx8wz0W2xPD7cS0jgIjlyfwgHiuo6a7 IjkSK5C8VN1b4d3pTrocTAIHeNstxCmZCyks8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SgtBES6SoFg23UKzdJujgYroDdhbOcZqSjp3kaa8R+A=; b=QajPVR4AYbiW7XgzMniZRG+TeZpuLAgC0BbybFn4fGydDF2Z8QmTiW79kJJloBfHS+ QigaNSLuIuSSoZA4MDFgrVyjO69Ysl2Cf3S9BYOQ1XvF/AEJXpgYYm/gYrao+7nINq03 FY/h5WouZeEtOPC2ZFJVUWQ12a8GheoqgaAuOAHoYDbfMf7GyjJoj3vyqubTtsVio80U qfRHPWbseNT0XBv4uQr8tycCC2HoI6iTwYQ6E2uGeiMYffrFgjEQ+bNt5z5weHU4zXAc /Hcx8WWWHA2ybCqdOrrAZp7wav10D1vTzjnXhxdch/1ceOB194XJtfk6hTFdib2WvWMp eJsw== X-Gm-Message-State: AHYfb5gwuigx1ytg4Sb8Ba0kSxRM/w01cNbXfXo+AHnW0jqew079evhm SGEi5moPBPUpikm9eaWI0g== X-Received: by 10.223.132.39 with SMTP id 36mr538117wrf.69.1504081279505; Wed, 30 Aug 2017 01:21:19 -0700 (PDT) Received: from localhost.localdomain ([105.133.189.215]) by smtp.gmail.com with ESMTPSA id h8sm3051642wma.46.2017.08.30.01.21.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Aug 2017 01:21:18 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Cc: Ard Biesheuvel Date: Wed, 30 Aug 2017 09:21:04 +0100 Message-Id: <20170830082108.7470-3-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170830082108.7470-1-ard.biesheuvel@linaro.org> References: <20170830082108.7470-1-ard.biesheuvel@linaro.org> Subject: [PATCH 2/6] EmbeddedPkg/CoherentDmaLib: add support for non-1:1 DMA translation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Aug 2017 08:18:40 -0000 Bring CoherentDmaLib in line with ArmDmaLib, and add support for defining a static offset between the host's and the bus master's view of memory. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- EmbeddedPkg/EmbeddedPkg.dec | 7 +++++++ EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c | 10 +++++++++- EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec index 8ad2a84c045c..ccdf38e36a8c 100644 --- a/EmbeddedPkg/EmbeddedPkg.dec +++ b/EmbeddedPkg/EmbeddedPkg.dec @@ -208,3 +208,10 @@ [PcdsFixedAtBuild.X64] [PcdsFixedAtBuild.common, PcdsDynamic.common] gEmbeddedTokenSpaceGuid.PcdFdtDevicePaths|L""|VOID*|0x00000055 + + # + # Value to add to a host address to obtain a device address, using + # unsigned 64-bit integer arithmetic. This means we can rely on + # truncation on overflow to specify negative offsets. + # + gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset|0x0|UINT64|0x0000058 diff --git a/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c b/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c index 4cbe349190a9..564db83c901c 100644 --- a/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c +++ b/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.c @@ -19,6 +19,14 @@ #include +STATIC +PHYSICAL_ADDRESS +HostToDeviceAddress ( + IN VOID *Address + ) +{ + return (PHYSICAL_ADDRESS)(UINTN)Address + PcdGet64 (PcdDmaDeviceOffset); +} /** Provides the DMA controller-specific addresses needed to access system memory. @@ -50,7 +58,7 @@ DmaMap ( OUT VOID **Mapping ) { - *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)HostAddress; + *DeviceAddress = HostToDeviceAddress (HostAddress); *Mapping = NULL; return EFI_SUCCESS; } diff --git a/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf b/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf index c40a600cf6a3..f64d780e16ed 100644 --- a/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf +++ b/EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf @@ -31,3 +31,6 @@ [Packages] [LibraryClasses] DebugLib MemoryAllocationLib + +[Pcd] + gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset -- 2.11.0