From patchwork Wed May 30 14:06:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 10439303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 01252601D3 for ; Wed, 30 May 2018 15:47:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E2A3C2875C for ; Wed, 30 May 2018 15:47:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D66A12892B; Wed, 30 May 2018 15:47:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8BB7B2875C for ; Wed, 30 May 2018 15:47:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D9EED6EBA7; Wed, 30 May 2018 14:06:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x243.google.com (mail-wr0-x243.google.com [IPv6:2a00:1450:400c:c0c::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id BF6A36EBA4; Wed, 30 May 2018 14:06:32 +0000 (UTC) Received: by mail-wr0-x243.google.com with SMTP id w10-v6so29691239wrk.9; Wed, 30 May 2018 07:06:32 -0700 (PDT) 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=C1H19eDS0goG/L1R3D+SDiRCtKOqjXJm0QVnIcHi8Kc=; b=Zkai1WtbBCW0v5SOrCrdSUZlrFZ/jFfMpZAgwVAb3Ju1zdZy0qRMOaQkp6gx4h3l/K cI/mrLDXYhkRjYJL17e/VLICeDK+N2+qI48M5hTN3QpManZaZ2RN1p/CBNdN8X3KjeoM XWBnAYcoTf4iG8LvfVYG2QAB/JH4AT1kahWi0bVwLBjV/9g+YLS+rECEWe4YvyfY8oYq rgZsSyeXJSl3eCREhQjvqtfipOqMSMaTEuBLmu5/jTLKpTHmbUV64ox9PX3XBHxjygUN sxODTvX4kh4hhalXEqNGK6+pwQBm2XijFwGxyx05rV5F2v1gcvpT/dah8MdChZ/1EbhB spDw== X-Gm-Message-State: ALKqPwdrKwy19EnLpzeHu/vKGUUMvV5kjE6ytO5sAaGyMzzMU+4+AjFm X1acFtsFlNvGqb0fVLeAzbs= X-Google-Smtp-Source: ADUXVKIFXOoZ1oGyBR+QYarqaUtRoJa7RDuHixG1GQNj47Ur6ncQodDlkX/02Vci245Ig9SCcrtTtw== X-Received: by 2002:adf:d250:: with SMTP id o16-v6mr2176422wri.59.1527689191298; Wed, 30 May 2018 07:06:31 -0700 (PDT) Received: from localhost (p2E5BEDA6.dip0.t-ipconnect.de. [46.91.237.166]) by smtp.gmail.com with ESMTPSA id x73-v6sm14506986wmf.21.2018.05.30.07.06.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 May 2018 07:06:30 -0700 (PDT) From: Thierry Reding To: Ben Skeggs , Christoph Hellwig , Russell King Subject: [PATCH v4 2/2] drm/nouveau: tegra: Detach from ARM DMA/IOMMU mapping Date: Wed, 30 May 2018 16:06:25 +0200 Message-Id: <20180530140625.21247-3-thierry.reding@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180530140625.21247-1-thierry.reding@gmail.com> References: <20180530140625.21247-1-thierry.reding@gmail.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nouveau@lists.freedesktop.org, iommu@lists.linux-foundation.org, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, Robin Murphy , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding Depending on the kernel configuration, early ARM architecture setup code may have attached the GPU to a DMA/IOMMU mapping that transparently uses the IOMMU to back the DMA API. Tegra requires special handling for IOMMU backed buffers (a special bit in the GPU's MMU page tables indicates the memory path to take: via the SMMU or directly to the memory controller). Transparently backing DMA memory with an IOMMU prevents Nouveau from properly handling such memory accesses and causes memory access faults. As a side-note: buffers other than those allocated in instance memory don't need to be physically contiguous from the GPU's perspective since the GPU can map them into contiguous buffers using its own MMU. Mapping these buffers through the IOMMU is unnecessary and will even lead to performance degradation because of the additional translation. One exception to this are compressible buffers which need large pages. In order to enable these large pages, multiple small pages will have to be combined into one large (I/O virtually contiguous) mapping via the IOMMU. However, that is a topic outside the scope of this fix and isn't currently supported. An implementation will want to explicitly create these large pages in the Nouveau driver, so detaching from a DMA/IOMMU mapping would still be required. Signed-off-by: Thierry Reding Acked-by: Christoph Hellwig Reviewed-by: Robin Murphy Tested-by: Nicolas Chauvet --- Changes in v4: - use existing APIs to detach from a DMA/IOMMU mapping Changes in v3: - clarify the use of IOMMU mapping for compressible buffers - squash multiple patches into this drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c index 78597da6313a..0e372a190d3f 100644 --- a/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c +++ b/drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c @@ -23,6 +23,10 @@ #ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER #include "priv.h" +#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) +#include +#endif + static int nvkm_device_tegra_power_up(struct nvkm_device_tegra *tdev) { @@ -105,6 +109,15 @@ nvkm_device_tegra_probe_iommu(struct nvkm_device_tegra *tdev) unsigned long pgsize_bitmap; int ret; +#if IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU) + if (dev->archdata.mapping) { + struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); + + arm_iommu_detach_device(dev); + arm_iommu_release_mapping(mapping); + } +#endif + if (!tdev->func->iommu_bit) return;