Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2426897rwb; Mon, 7 Nov 2022 13:10:46 -0800 (PST) X-Google-Smtp-Source: AMsMyM7EqmHnFz+oe72txs3OPm9r3ZaOuCXmFDxe2SVD5OyCHpGasOE8P8oWIKUpfd9oQybrYMrl X-Received: by 2002:a63:4461:0:b0:43c:dbdb:90c4 with SMTP id t33-20020a634461000000b0043cdbdb90c4mr43265919pgk.340.1667855446386; Mon, 07 Nov 2022 13:10:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667855446; cv=none; d=google.com; s=arc-20160816; b=dp8K803TeAbo1TWz7Kf3tmMFQZYW2Bub3LLIZ+TS6+TJdpMfwK4nWR9NuNb/qGC+/L hMt+ijNWyUGlztvscc/kPsDhMgUDsaa58GaAcLoErOMyQsJsjo9sYVGPkVs/agRiUr2w 8rnEq9iD9fllvOp/5XqqaSaukDO9WsuzQbEBkpav6A4j+e9zuTC3nhJ8v7Q9VhoeyEeO Tb7hm8zz5U4Glh6s5iAK5IHBrklQE3wj+x6UE22zc5QXuP+DoEaFfahR0VRAKp4UJ8WJ 7ZwF2e9KEIGlolMbCgSMAPHyWBcoSex3JNJJcvBBfXtO/r6CxtQwgXYIpUj7D+lnLbY8 Aa3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9h7dS4QrWKWOTqtPtbuvDyKihSQ7MoE9BsNBgXy0LMQ=; b=Vu9RZxWWU175b3kzTxXyf06mApFphUEzW/f5Qhb081O190QpwvZ5BWpAUpqO7dU34T 6k5AdFaVOwKTfHvWbxzXFD2X6bDl+KwqbvTeaKtrPTc0gZuxsvz59NFHJynbcJK3sDNN Lu+d6y/LdBJPgMTc+6NmOSuOFWfYYKxHbZq5YUGxTWZAa33MnMJsNxHUQO86aLh8Nfj4 ALrXOGqNI3+opl1ZfQ3/HrR26Jzwdy2TZQ1JArqmv5UFAtL5vDmYkBOHHbB8Lto1da/Q JmydJj0Q3VqMA1RpAGq2ytdu2K0A6NOowb9ggwxGSFO5uGjpY+MwarRMuy8vGPSUZu8G 6VQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=post header.b=RmiTHmd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=baikalelectronics.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a170902f54900b001768a29b9dfsi13759237plf.68.2022.11.07.13.10.32; Mon, 07 Nov 2022 13:10:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=post header.b=RmiTHmd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=baikalelectronics.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233328AbiKGVGQ (ORCPT + 92 others); Mon, 7 Nov 2022 16:06:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233264AbiKGVFS (ORCPT ); Mon, 7 Nov 2022 16:05:18 -0500 Received: from post.baikalelectronics.com (post.baikalelectronics.com [213.79.110.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 34FE3B4AF; Mon, 7 Nov 2022 13:05:02 -0800 (PST) Received: from post.baikalelectronics.com (localhost.localdomain [127.0.0.1]) by post.baikalelectronics.com (Proxmox) with ESMTP id 6AF1DE0EE0; Tue, 8 Nov 2022 00:05:02 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= baikalelectronics.ru; h=cc:cc:content-transfer-encoding :content-type:content-type:date:from:from:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=post; bh=9h7dS4QrWKWOTqtPtbuvDyKihSQ7MoE9BsNBgXy0LMQ=; b=RmiTHmd4gupS ElXTwapE15dFptTAghkeGlWcEG1DYCY6IX3+Q36DeTwyOn4eVM3AD+rrIIGTYiim jLsuy3THF6jYQG6YBdKtLPrEQjneTEqmOtKjtWpUkpFkVXIPrmDLKPAlcoZRshHn TRa1uNdi886qIQQE3ys9rMNcLOAfiD0= Received: from mail.baikal.int (mail.baikal.int [192.168.51.25]) by post.baikalelectronics.com (Proxmox) with ESMTP id 5812DE0ED3; Tue, 8 Nov 2022 00:05:02 +0300 (MSK) Received: from localhost (192.168.168.10) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 8 Nov 2022 00:05:01 +0300 From: Serge Semin To: Gustavo Pimentel , Vinod Koul , Rob Herring , Bjorn Helgaas , Lorenzo Pieralisi , Cai Huoqing , Robin Murphy , Jingoo Han , Frank Li , Manivannan Sadhasivam CC: Serge Semin , Serge Semin , Alexey Malahov , Pavel Parkhomenko , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , caihuoqing , , , Subject: [PATCH v6 22/24] dmaengine: dw-edma: Bypass dma-ranges mapping for the local setup Date: Tue, 8 Nov 2022 00:04:36 +0300 Message-ID: <20221107210438.1515-23-Sergey.Semin@baikalelectronics.ru> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221107210438.1515-1-Sergey.Semin@baikalelectronics.ru> References: <20221107210438.1515-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [192.168.168.10] X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org DW eDMA doesn't perform any translation of the traffic generated on the CPU/Application side. It just generates read/write AXI-bus requests with the specified addresses. But in case if the dma-ranges DT-property is specified for a platform device node, Linux will use it to create a mapping the PCIe-bus regions into the CPU memory ranges. This isn't what we want for the eDMA embedded into the locally accessed DW PCIe Root Port and End-point. In order to work that around let's set the chan_dma_dev flag for each DW eDMA channel thus forcing the client drivers to getting a custom dma-ranges-less parental device for the mappings. Note it will only work for the client drivers using the dmaengine_get_dma_device() method to get the parental DMA device. Signed-off-by: Serge Semin --- Changelog v2: - Fix the comment a bit to being clearer. (@Manivannan) Changelog v3: - Conditionally set dchan->dev->device.dma_coherent field since it can be missing on some platforms. (@Manivannan) - Remove Manivannan' rb and tb tags since the patch content has been changed. Changelog v6: - Directly call *_dma_configure() method on the child device used for the DMA buffers mapping. (@Robin) - Explicitly set the DMA-mask of the child device in the channel allocation proecedure. (@Robin) - Drop @Manivannan and @Vinod rb- and ab-tags due to significant patch content change. --- drivers/dma/dw-edma/dw-edma-core.c | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index e3671bfbe186..846518509753 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -6,9 +6,11 @@ * Author: Gustavo Pimentel */ +#include #include #include #include +#include #include #include #include @@ -711,10 +713,52 @@ static irqreturn_t dw_edma_interrupt_common(int irq, void *data) static int dw_edma_alloc_chan_resources(struct dma_chan *dchan) { struct dw_edma_chan *chan = dchan2dw_edma_chan(dchan); + struct device *dev = chan->dw->chip->dev; + int ret; if (chan->status != EDMA_ST_IDLE) return -EBUSY; + /* Bypass the dma-ranges based memory regions mapping for the eDMA + * controlled from the CPU/Application side since in that case + * the local memory address is left untranslated. + */ + if (chan->dw->chip->flags & DW_EDMA_CHIP_LOCAL) { + ret = dma_coerce_mask_and_coherent(&dchan->dev->device, + DMA_BIT_MASK(64)); + if (ret) { + ret = dma_coerce_mask_and_coherent(&dchan->dev->device, + DMA_BIT_MASK(32)); + if (ret) + return ret; + } + + if (dev_of_node(dev)) { + struct device_node *node = dev_of_node(dev); + + ret = of_dma_configure(&dchan->dev->device, node, true); + } else if (has_acpi_companion(dev)) { + struct acpi_device *adev = to_acpi_device_node(dev->fwnode); + + ret = acpi_dma_configure(&dchan->dev->device, + acpi_get_dma_attr(adev)); + } else { + ret = -EINVAL; + } + + if (ret) + return ret; + + if (dchan->dev->device.dma_range_map) { + kfree(dchan->dev->device.dma_range_map); + dchan->dev->device.dma_range_map = NULL; + } + + dchan->dev->chan_dma_dev = true; + } else { + dchan->dev->chan_dma_dev = false; + } + return 0; } -- 2.38.0