From patchwork Wed Aug 30 08:21:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 111271 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp552435ybm; Wed, 30 Aug 2017 01:21:26 -0700 (PDT) X-Google-Smtp-Source: ADKCNb6pL7swLGOd3Grx88Twix+VIo5d1eKdKLHOzOSNWEC/GaR2a9hfd7q/sq1vRj0sRW86rRLo X-Received: by 10.84.217.25 with SMTP id o25mr958097pli.320.1504081286700; Wed, 30 Aug 2017 01:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504081286; cv=none; d=google.com; s=arc-20160816; b=CupU64/2VrCzISz/afkSQ5aF2C+YVcR589HudR1o9Rsbnry8QXP+IEXLYjUJZl59e7 gnX041w34qCQ62G9apFcnioLXyseTkOhRajjwMWJqaVjPdc9to+gvRJ1WuDhUHfn66rH LGdUXDnD/sR1jw7v6x4Hzo2joI8d6PRa91xfuQx8JNphxCszXEWLAhP/7aLO6U5o8MFj DJp4DQ3xg3qDWSOqYiO/pmohc++5luX8qC2jiA5r84nH3WAPoej/xSGiX/PSZBrnl8AP t1ui/6SXpijR0yKhFugYdydoFUB66sYt7LAdLkJ9m7dv/GBWVcRag41nwZPzktzUc037 U22A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=djf3c5dGXjJUuUrOk5s6gvC0D3egUSIMDU7Mgi81Pcw=; b=Pj+3RlpTEP2tRKJmDYiKMXh90RnIiTu4qep18s8KWUnxrheJH4v0pHe/4oU11gJyzH KpndYuXXp4Pm9nFvbhZWdxiuLbrJZAxfROT/SX2ECs0CNzI/0h2NGeVidFyMIcMYGHXS L13VtGQCIt+UcoWflKLzOnV93BC7gnQFWRb/VLIQxkVjinkPnBjE2sci5BnKczevbgLO ZwEMD9juYKmFhTZLrqw2WsJ25a+c0r/XGYjvroXsg1f1uA4cpqEmB454/EhHCXjvsiHc IG6ouMmYwe+KPaVxOKymxUDEDMx6XrTHpyDwkzyixFVhJ0CiriFYNG/QjsgEo/6YVuz3 P3bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=R5b//KOw; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id 14si3962864pfh.386.2017.08.30.01.21.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Aug 2017 01:21:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=R5b//KOw; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3C61221E95E1B; Wed, 30 Aug 2017 01:18:41 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org 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 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: [edk2] [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: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(-) -- 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Leif Lindholm 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