From patchwork Thu Nov 30 18:53:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 120273 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp163971qgn; Thu, 30 Nov 2017 10:54:05 -0800 (PST) X-Google-Smtp-Source: AGs4zMY/JTjdSHW/2S3I9X6uZQQ3V+6I9IGS69zXfz1iev8JxWu7eQ3+6vETNZ9j0n3pmKvzfe8E X-Received: by 10.99.121.4 with SMTP id u4mr3320239pgc.235.1512068045603; Thu, 30 Nov 2017 10:54:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512068045; cv=none; d=google.com; s=arc-20160816; b=nGql5rZvHfILuVvtKpUEbQUO2D1MEWMtH/9R2TNsOPoUY8GLvtztqZ7tM7gJNZ2x5d NfRYaY3ASqqk/yI3mD0QWPjcvDMXx5vmCj9CH90Vguk4akf3tRtc35eSkmeg++UojQQL 7uiDMYYfxnGMaaLgLgNdZP/V8DveKcSoCltnoZyiPrvX5fduptHP2FjUvcI1fIE71gRN HgnxAQckj7KgTR7EYFrV5jtwkexKW2xLfUtZuem0GSX+QutX0JXwN4LBiHEDFbctA4TA /9ui8QwIYzr4eFNOeb5LMYCTc/o0+1JVh2pQdkNEmgYdRKbQMVfx2H5ilMYO2pGI9XzJ PbSQ== 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:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=DZgLcFnVorhc6KTTGCqtmV/5uIrroMeiIj340vuxC6c=; b=CJUuT69LMZ3XUVw59CLV79GO8eQht6mUiqupGqzBC2t20bm/lwtCyEbNNsn13dGchg dby8c8rv4rg9ewNMsVUK6IW7FipEAz/nGu/ac/sPJ9RBB1Nuun49b5FyI5Jtgjbzw35W 44hWeUcJ7j2gG1e4yMOC5f4upXGGjZtP+Yj3knPAJbWeghepldEhWxxGeEB3onL/FPEj HRmfq9/B3hlmBuzqvkBTqLf5Y3+/nbRsTs8di+xHkmrn+e6j5hxh8UlDMg6owE3pWebm j8cZyFVd/FF0gyLw05mCMUqWTzGZo6Ootw1Mb76ksch9V5L5HWJjxhTPJux0mqI0n/S2 /7uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Iyo8EL5f; 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 l11si3587474plt.290.2017.11.30.10.54.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 10:54:05 -0800 (PST) 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=Iyo8EL5f; 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 5E94221A04E2F; Thu, 30 Nov 2017 10:49:39 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c0c::243; helo=mail-wr0-x243.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) (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 F3581221786B1 for ; Thu, 30 Nov 2017 10:49:37 -0800 (PST) Received: by mail-wr0-x243.google.com with SMTP id z34so7644253wrz.10 for ; Thu, 30 Nov 2017 10:54:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=wXx9CsBqWsZKOACn2JavAvZp1zq0VtrL+MUwizCuWLU=; b=Iyo8EL5fPGIjOD0YaLAbHd5SE6PiEE8USJVc1d+u+5Bo4UYH86BDdn2XoL2h//atRC Mswg35i0hHrzo96ri0jrR1Q0fk46fPr0feC7Xe51jDrNR3SgcITStCcsNDlvLho8Hdwk Q66CrOAhQjIdTLur9kAM4mnKNBSgpJrLgyszQ= 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; bh=wXx9CsBqWsZKOACn2JavAvZp1zq0VtrL+MUwizCuWLU=; b=ZpZmvh3T4LYfC3ECOoe9S6Bwt5D1lCqEjQgOR4iVCrrKHsmtDJVBhdJ5lOyjVOmOpG ymVf5ORm5J5BArMgjW6uvSOqEs4mxheWsflKFjpm+r2pR56QZDqHUke28KwrPj4Wgits +wO66WPw56IdMAIQi8tISXMX4W7XgcX6c7Uzxq3B4CigLOJ7W8xMBKMQj9Qgf0xY9hDb hBT7O4UIdh06gPQihmxqdMI2QvKy7TMTqw6//WyTXALHWoh1WGrZkRHR0O5f9bqnknb7 YRQh5b57/J63PXYsF33kJXp/1Ysb9MM1GskqXESiOwVV9wT3sQEBFCR7EN8o1OUiuv1i KevQ== X-Gm-Message-State: AJaThX7zOw9XUCXqyAcnrvs7ADJxVfEu29Wci3PRsR4RfWVwdV6d6Ga0 tvZjyog50f6VErHbrU8/SlG9x2kr27A= X-Received: by 10.223.199.212 with SMTP id y20mr3176830wrg.60.1512068040824; Thu, 30 Nov 2017 10:54:00 -0800 (PST) Received: from localhost.localdomain ([105.150.171.234]) by smtp.gmail.com with ESMTPSA id p81sm2422326wrc.61.2017.11.30.10.53.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 10:53:59 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 30 Nov 2017 18:53:55 +0000 Message-Id: <20171130185355.20985-1-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 Subject: [edk2] [PATCH edk2-platforms v2] Silicon/SynQuacer: enable coherent DMA for NETSEC and eMMC 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: leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" As it turns out, it is surprisingly easy to configure both the NETSEC and eMMC devices as cache coherent for DMA, given that they are both behind the same SMMU which is already configured in passthrough mode by the firmware running on the SCP. So update the static SMMU configuration to make memory accesses performed by these devices inner shareable inner/outer writeback cacheable, which makes them cache coherent with the CPUs. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- v2: update DeveloperBox as well update commit log to clarify that the SMMU is configured in pass through mode by the firmware running on the Cortex-M3 SCP Platform/Socionext/DeveloperBox/DeveloperBox.dsc | 2 +- Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc | 2 +- Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi | 2 ++ Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c | 2 +- Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c | 23 ++++++++++++++++++++ Silicon/Socionext/SynQuacer/Include/Platform/MemoryMap.h | 4 ++++ Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c | 3 +++ 7 files changed, 35 insertions(+), 3 deletions(-) -- 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/Platform/Socionext/DeveloperBox/DeveloperBox.dsc b/Platform/Socionext/DeveloperBox/DeveloperBox.dsc index 7ca9fb104311..e1183b529b73 100644 --- a/Platform/Socionext/DeveloperBox/DeveloperBox.dsc +++ b/Platform/Socionext/DeveloperBox/DeveloperBox.dsc @@ -600,7 +600,7 @@ [Components.common] NetworkPkg/HttpBootDxe/HttpBootDxe.inf Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf { - DmaLib|EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf + DmaLib|EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf } # diff --git a/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc b/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc index 10da45ad2837..637f6d414d24 100644 --- a/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc +++ b/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc @@ -592,7 +592,7 @@ [Components.common] NetworkPkg/HttpBootDxe/HttpBootDxe.inf Silicon/Socionext/SynQuacer/Drivers/Net/NetsecDxe/NetsecDxe.inf { - DmaLib|EmbeddedPkg/Library/NonCoherentDmaLib/NonCoherentDmaLib.inf + DmaLib|EmbeddedPkg/Library/CoherentDmaLib/CoherentDmaLib.inf } # diff --git a/Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi b/Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi index 5e663c59efbd..ec784c70afe7 100644 --- a/Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi +++ b/Silicon/Socionext/SynQuacer/DeviceTree/SynQuacer.dtsi @@ -456,6 +456,7 @@ max-speed = <1000>; max-frame-size = <9000>; phy-handle = <ðphy0>; + dma-coherent; #address-cells = <1>; #size-cells = <0>; @@ -557,6 +558,7 @@ fujitsu,cmd-dat-delay-select; clocks = <&clk_alw_c_0 &clk_alw_b_0>; clock-names = "core", "iface"; + dma-coherent; status = "disabled"; }; }; diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c index e577076ada4f..5a99283977fb 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c +++ b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/Emmc.c @@ -191,7 +191,7 @@ RegisterEmmc ( Status = RegisterNonDiscoverableMmioDevice ( NonDiscoverableDeviceTypeSdhci, - NonDiscoverableDeviceDmaTypeNonCoherent, + NonDiscoverableDeviceDmaTypeCoherent, NULL, &mSdMmcControllerHandle, 1, diff --git a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c index c64ccf3b3c30..7e7c790a6113 100644 --- a/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c +++ b/Silicon/Socionext/SynQuacer/Drivers/PlatformDxe/PlatformDxe.c @@ -123,6 +123,27 @@ FreeDevice: return Status; } +#define SMMU_SCR0 0x0 +#define SMMU_SCR0_SHCFG_INNER (0x2 << 22) +#define SMMU_SCR0_MTCFG (0x1 << 20) +#define SMMU_SCR0_MEMATTR_INNER_OUTER_WB (0xf << 16) + +STATIC +VOID +SmmuEnableCoherentDma ( + VOID + ) +{ + // + // The SCB SMMU (MMU-500) is shared between the NETSEC and eMMC devices, and + // is configured in passthrough mode by default. Let's set the global memory + // type override as well, so that all memory accesses by these devices are + // inner shareable inner/outer writeback cacheable. + // + MmioOr32 (SYNQUACER_SCB_SMMU_BASE + SMMU_SCR0, + SMMU_SCR0_SHCFG_INNER | SMMU_SCR0_MTCFG | SMMU_SCR0_MEMATTR_INNER_OUTER_WB); +} + EFI_STATUS EFIAPI PlatformDxeEntryPoint ( @@ -174,5 +195,7 @@ PlatformDxeEntryPoint ( Status = RegisterEmmc (); ASSERT_EFI_ERROR (Status); + SmmuEnableCoherentDma (); + return EFI_SUCCESS; } diff --git a/Silicon/Socionext/SynQuacer/Include/Platform/MemoryMap.h b/Silicon/Socionext/SynQuacer/Include/Platform/MemoryMap.h index 3c7bd58866cc..f43adcc8607f 100644 --- a/Silicon/Socionext/SynQuacer/Include/Platform/MemoryMap.h +++ b/Silicon/Socionext/SynQuacer/Include/Platform/MemoryMap.h @@ -65,4 +65,8 @@ #define SYNQUACER_PCIE_BASE 0x58200000 #define SYNQUACER_PCIE_SIZE 0x00200000 +// SCB SMMU +#define SYNQUACER_SCB_SMMU_BASE 0x52E00000 +#define SYNQUACER_SCB_SMMU_SIZE SIZE_64KB + #endif diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c index a640b3e0c0d1..1402ecafce4a 100644 --- a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c +++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c @@ -115,6 +115,9 @@ STATIC CONST ARM_MEMORY_REGION_DESCRIPTOR mVirtualMemoryTable[] = { FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize)), ARM_DEVICE_REGION (FixedPcdGet32 (PcdFlashNvStorageFtwSpareBase), FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize)), + + // NETSEC/eMMC SMMU + ARM_DEVICE_REGION (SYNQUACER_SCB_SMMU_BASE, SYNQUACER_SCB_SMMU_SIZE), }; STATIC