Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp223154rwb; Wed, 14 Dec 2022 16:27:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf58BfmhN693qTAvCJfKDnzqqxy6C/drBI5wPOOWRSdFCAlNlvOfbN6kWhMc7yBeLEThB3c6 X-Received: by 2002:a05:6a20:939e:b0:ac:36bd:3f74 with SMTP id x30-20020a056a20939e00b000ac36bd3f74mr35391317pzh.34.1671064035343; Wed, 14 Dec 2022 16:27:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671064035; cv=none; d=google.com; s=arc-20160816; b=InNt0Fmq7tS8ZqG8JOklxGqSEZNYSSSf/VrXi4YGPD9eFSNVyi4KY2up5mCA9RRpW/ 0nlZ8NZacuudaXv9U63C5cCcfaZubRY6RPxnv7mDA2OTVvMaBk/4FEdCprzSf4/86xMm 7uMXZdWhW3MT3Zj3fQJY442XF/RHHqGFkND9R3I6HQp2BztYoL3gyFXqleinj696g3fE OwFcsGD4nKpcy2ykqexTGYdUCjFV9M2w/DFdqOQNxEcep0WAgI6XKEUEwDfdUVbYn2ES dIhb2GE0YveSBcc2NGq4d2+/YBFjoUZu+GYVDuH+Pd95RVPrmkS0tcLDi19DtJmTV7a/ zYkw== 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=wQDGlXtR0T6fGYFp6Rn98xoC9dALb52VWLv6gbMrfRw=; b=gawzha+HEw3uH9dZMbDKo/jWWKY1IbR/ocXpy7xz3yYv+8XQfP7v7dtD8ejJBuWpxF 2GpzV4iQpinc8x9HqWSiKvk6+bhXcS1zhFzgK9qlO1JZlDZLzFH6uJk25QxDsbD7r6he 2l3VMVDoPARUNeywvZ5t7rcCjMXtjCXVrw7D0B1uPe5fUQRU3A0K6dzjQvcXPUYK1MQ4 MdPaiNBhVYwHbWvjSJ+s//uqBKO1tMzncAU2xuXhNQWY6weYgFM1L6H84iwXqX9Q5BQ3 eDqV/pJRps9O8d4SfVMT0zJFmQD0l9IPxvOl3jnm5znkaO+XdGSDPNU2+Wi3wDTDGtoo dXEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=post header.b="sARQ/ad2"; 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 o23-20020a63fb17000000b00461bf5f86fdsi1354977pgh.403.2022.12.14.16.27.05; Wed, 14 Dec 2022 16:27:15 -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="sARQ/ad2"; 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 S230071AbiLNXyW (ORCPT + 69 others); Wed, 14 Dec 2022 18:54:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229783AbiLNXxP (ORCPT ); Wed, 14 Dec 2022 18:53:15 -0500 Received: from post.baikalelectronics.com (post.baikalelectronics.com [213.79.110.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0D7574A047; Wed, 14 Dec 2022 15:53:14 -0800 (PST) Received: from post.baikalelectronics.com (localhost.localdomain [127.0.0.1]) by post.baikalelectronics.com (Proxmox) with ESMTP id 98B3EE0EDC; Thu, 15 Dec 2022 02:53:13 +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=wQDGlXtR0T6fGYFp6Rn98xoC9dALb52VWLv6gbMrfRw=; b=sARQ/ad2YIh5 xFZ9g5BJy99uUdb7ezUB8Fy+M6hNV1bgJ6t/CqH0ZYskIVq3NLmk56lEI96CJnlD 7UqduUidhbIG26nT4MqXAYuN3Oc89HFCBF1xZ8nr3PFf+e9Ap1yYWFBSE8cIfpcc O3RV+GW3amkVrqZkkldtxwKoghD8LCU= Received: from mail.baikal.int (mail.baikal.int [192.168.51.25]) by post.baikalelectronics.com (Proxmox) with ESMTP id 81F06E0E6B; Thu, 15 Dec 2022 02:53:13 +0300 (MSK) Received: from localhost (10.8.30.6) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 15 Dec 2022 02:53:13 +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 , Yoshihiro Shimoda , , , , Gustavo Pimentel Subject: [PATCH v7 08/25] dmaengine: dw-edma: Add PCIe bus address getter to the remote EP glue-driver Date: Thu, 15 Dec 2022 02:52:48 +0300 Message-ID: <20221214235305.31744-9-Sergey.Semin@baikalelectronics.ru> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221214235305.31744-1-Sergey.Semin@baikalelectronics.ru> References: <20221214235305.31744-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.8.30.6] 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 In general the Synopsys PCIe EndPoint IP prototype kit can be attached to a PCIe bus with any PCIe Host controller including to the one with distinctive from CPU address space. Due to that we need to make sure that the source and destination addresses of the DMA-slave devices are properly converted to the PCIe bus address space, otherwise the DMA transaction will not only work as expected, but may cause the memory corruption with subsequent system crash. Let's do that by introducing a new dw_edma_pcie_address() method defined in the dw-edma-pcie.c, which will perform the denoted translation by using the pcibios_resource_to_bus() method. Fixes: 41aaff2a2ac0 ("dmaengine: Add Synopsys eDMA IP PCIe glue-logic") Signed-off-by: Serge Semin Reviewed-by: Manivannan Sadhasivam Tested-by: Manivannan Sadhasivam Acked-by: Vinod Koul --- Note this patch depends on the patch "dmaengine: dw-edma: Add CPU to PCIe bus address translation" from this series. --- drivers/dma/dw-edma/dw-edma-pcie.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/dma/dw-edma/dw-edma-pcie.c b/drivers/dma/dw-edma/dw-edma-pcie.c index 04c95cba1244..f530bacfd716 100644 --- a/drivers/dma/dw-edma/dw-edma-pcie.c +++ b/drivers/dma/dw-edma/dw-edma-pcie.c @@ -95,8 +95,23 @@ static int dw_edma_pcie_irq_vector(struct device *dev, unsigned int nr) return pci_irq_vector(to_pci_dev(dev), nr); } +static u64 dw_edma_pcie_address(struct device *dev, phys_addr_t cpu_addr) +{ + struct pci_dev *pdev = to_pci_dev(dev); + struct pci_bus_region region; + struct resource res = { + .flags = IORESOURCE_MEM, + .start = cpu_addr, + .end = cpu_addr, + }; + + pcibios_resource_to_bus(pdev->bus, ®ion, &res); + return region.start; +} + static const struct dw_edma_core_ops dw_edma_pcie_core_ops = { .irq_vector = dw_edma_pcie_irq_vector, + .pci_address = dw_edma_pcie_address, }; static void dw_edma_pcie_get_vsec_dma_data(struct pci_dev *pdev, -- 2.38.1