Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1229011iol; Fri, 10 Jun 2022 03:07:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4tLdpiv5/9oO7gwvpZzJgDdeL/TDVoQymHujgrAcTycl0fpFHbwWF+4rv6mQUxsUsh2k3 X-Received: by 2002:a17:906:84b:b0:70c:d506:7817 with SMTP id f11-20020a170906084b00b0070cd5067817mr37087027ejd.206.1654855662938; Fri, 10 Jun 2022 03:07:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654855662; cv=none; d=google.com; s=arc-20160816; b=FGt22RizS4RUvdjn/QKrEeV5+PG8Un89TnN4nELH9g0qAzZhkcjmU03RVrUcu77pCL nZ45uNMkBB7IXnMkEZOxkfRyCM/xQO6TL0C+/4mGSeYTe1rT8Nyflw4M1G0Yo5APzeTt OswGmldhQVBN5648QGWZs2f/suZJgbzfmrQoi8n6ANF0cO3X2f5KdbPlAXeHVjw/KE/l UgXbY3OX0usCLLcNcXKaIr1jRI4dgCRBRnPp9h6RYhm+uAsT8P8VLCBifrrPUREuhGmK hM4KeGQiz4ZqjkR+UMkTQVZP/H0j8WaF6COsiAo/apCvEZD8J+oiiPpA2TqcuVhzBhuI UdEA== 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:dkim-filter; bh=pr/QdRUOOkPRhoaavZaHsiYvmKEv5KzXe+H64JY7rMI=; b=cLOyoFOgfbHnhr3QGfWIpVw/zzPt2oZaOyfS/MKJji4ylbZsLY2XikRW03jZUZ5K// gSnrsCKT8B28jsJoUx0zGEXwdJienDYS8OKJ9CQBfiKecSjz3KkvedERWrz5ejWlpoWh kyPE/8aygPTvYR8oQSAdhdiskKwOdC9gMok+ObbLQRjiMupYpoS/HtgxSSihT4i5uF1r mC6m/ZxfLBmFDkeWFMz9LRWYWtyQiuSc6vCsxhsDM+OM/EX1G6sJZfnIaJ2goA34XUan 3XE5EzsZ6ziLMQAPvw0H33QfCKuhjkgqKuuuz5dsAy3zxv+lkxlC2WEeX0r70ASLNkhj o+TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baikalelectronics.ru header.s=mail header.b="Q3Y/UDT8"; 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 6-20020a170906308600b006fef5188c39si793452ejv.307.2022.06.10.03.07.16; Fri, 10 Jun 2022 03:07:42 -0700 (PDT) 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=mail header.b="Q3Y/UDT8"; 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 S1348787AbiFJJSY (ORCPT + 99 others); Fri, 10 Jun 2022 05:18:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348688AbiFJJPT (ORCPT ); Fri, 10 Jun 2022 05:15:19 -0400 Received: from mail.baikalelectronics.com (mail.baikalelectronics.com [87.245.175.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4E9011BFEFB; Fri, 10 Jun 2022 02:15:18 -0700 (PDT) Received: from mail (mail.baikal.int [192.168.51.25]) by mail.baikalelectronics.com (Postfix) with ESMTP id 3D1BC16A9; Fri, 10 Jun 2022 12:16:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.baikalelectronics.com 3D1BC16A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baikalelectronics.ru; s=mail; t=1654852562; bh=pr/QdRUOOkPRhoaavZaHsiYvmKEv5KzXe+H64JY7rMI=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=Q3Y/UDT8R+Z8xi+VdpPmAL+v2GKyo9jjYIWto1swyWqT2Xk5fTuXSSzGYDfHAvFdT PQuJpurlimAG0xSJ3sdfJrh+vplYxwKtgkZ4gMRAp7usvEts41ZNNl9ny4nkpUBspN eqIyDwANP0YsYP44LmxBUCDWGou8Z7LiRwxINs8M= Received: from localhost (192.168.53.207) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 10 Jun 2022 12:15:09 +0300 From: Serge Semin To: Gustavo Pimentel , Vinod Koul , Rob Herring , Bjorn Helgaas , Lorenzo Pieralisi , Jingoo Han , Frank Li , Manivannan Sadhasivam CC: Serge Semin , Serge Semin , Alexey Malahov , Pavel Parkhomenko , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , , , , Gustavo Pimentel Subject: [PATCH v3 08/24] dmaengine: dw-edma: Add PCIe bus address getter to the remote EP glue-driver Date: Fri, 10 Jun 2022 12:14:43 +0300 Message-ID: <20220610091459.17612-9-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20220610091459.17612-1-Sergey.Semin@baikalelectronics.ru> References: <20220610091459.17612-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 --- 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.35.1