From patchwork Fri Jan 13 09:03:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shunsuke Mie X-Patchwork-Id: 13100285 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FC65C54EBD for ; Fri, 13 Jan 2023 09:05:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241135AbjAMJFV (ORCPT ); Fri, 13 Jan 2023 04:05:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241041AbjAMJEU (ORCPT ); Fri, 13 Jan 2023 04:04:20 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D7A174641 for ; Fri, 13 Jan 2023 01:04:02 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id b17so15328582pld.7 for ; Fri, 13 Jan 2023 01:04:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8BZHqfo7sFuXP72fnPp/JPxWAqzMlK6d2jnnMQV3zqE=; b=mCZTClX+9zwz1K99NSs2vAa1hO/adLIB4vn6t+EUxTWLPFL5Ma3Ao5JOXnwQNCUetj FARd3QvLL4iLl5lWb8wlV6zbIX52LEacsNm51RT4Q7z/5RxQKIzp7elDl29oDTeUJHkl BN8zW4m6JUifl0QCt4mSrLlxyQd7xhyJqe7lfNzP5C9tGxpGXnSlLxDebAgPSplqFAPB TGF/RxQHr0AqWA2zm+5n3sKmE9yDOiHT/dsWmpKZHtdxrCmuFds1uDzTyEYSREUyLE7L yr7k4Y5W3kGu/8YMYXmgrqfGSLf9DyAQ1pPtcp10kyz9qQre5n8oLj5M9wKQrQ8I5vJg h26g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8BZHqfo7sFuXP72fnPp/JPxWAqzMlK6d2jnnMQV3zqE=; b=MCV7yINwfkcOvMQqdFtFDo4r9ZmLA9TJn6WlyL6duElOkGYoLK9/Vj088B7QtY2VYY JpsWTZQRzgBt55cZ6dDJV9wztT3BBZCWjmWJpqgUMmaz6a5ihcaLbDBV62pQb2omtS2k 7Xpidp+O8yGwhGqRSaNuvHUCrDpSHbJSIz+VzA6rfXpcEeWGnzbgXa409vjV9BIXvsVd X1ya6hwk3hEPT+as5mE4itXHsYnQPn96E2D2vgQX4B7qNV0VrPPxwDHYa1Fzr1G/VAM0 Kowd9oBIhapkaTrEdt2O4EwOhWv1jCWp+u62c5T92cJ+Qqq9C+JKJ10xMlfRMt+zYBcH CnLw== X-Gm-Message-State: AFqh2krQIMXpZzZTJp0UQwKkU/EFk6Y6B4hiGTNSetwOHBwacTACjOpN 9bJ8Yz+Zx1OGrPfLM+clBDOFhQ== X-Google-Smtp-Source: AMrXdXton3HGLHrvkGuNbTEbGlI/Mo+sFQahSF2HIwe598OifzLl925iAO71L7ad4MOjLVut2A7K/Q== X-Received: by 2002:a17:902:da83:b0:189:8425:730d with SMTP id j3-20020a170902da8300b001898425730dmr111444062plx.27.1673600641918; Fri, 13 Jan 2023 01:04:01 -0800 (PST) Received: from tyrell.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id p15-20020a170902e74f00b00189bf5deda3sm13645510plf.133.2023.01.13.01.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 01:04:01 -0800 (PST) From: Shunsuke Mie To: Jingoo Han Cc: Gustavo Pimentel , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , Manivannan Sadhasivam , Kishon Vijay Abraham I , Shunsuke Mie , Kunihiko Hayashi , Hou Zhiqiang , Frank Li , Li Chen , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/3] PCI: endpoint: support an alignment aware map/unmaping Date: Fri, 13 Jan 2023 18:03:48 +0900 Message-Id: <20230113090350.1103494-2-mie@igel.co.jp> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230113090350.1103494-1-mie@igel.co.jp> References: <20230113090350.1103494-1-mie@igel.co.jp> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Add an align_mem operation to the EPC ops, which function is used to pci_epc_map/unmap_addr(). These change to enable mapping for any alignment restriction of EPC. The map function maps an aligned memory to include a requested memory region. Signed-off-by: Shunsuke Mie --- drivers/pci/endpoint/pci-epc-core.c | 57 ++++++++++++++++++++++++----- include/linux/pci-epc.h | 10 +++-- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c index 2542196e8c3d..60d586e05e7d 100644 --- a/drivers/pci/endpoint/pci-epc-core.c +++ b/drivers/pci/endpoint/pci-epc-core.c @@ -430,8 +430,12 @@ EXPORT_SYMBOL_GPL(pci_epc_set_msix); * Invoke to unmap the CPU address from PCI address. */ void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, - phys_addr_t phys_addr) + phys_addr_t phys_addr, void __iomem *virt_addr, size_t size) { + u64 aligned_phys; + void __iomem *aligned_virt; + size_t offset; + if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) return; @@ -441,9 +445,22 @@ void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, if (!epc->ops->unmap_addr) return; + if (epc->ops->align_mem) { + mutex_lock(&epc->lock); + aligned_phys = epc->ops->align_mem(epc, phys_addr, &size); + mutex_unlock(&epc->lock); + } else { + aligned_phys = phys_addr; + } + + offset = phys_addr - aligned_phys; + aligned_virt = virt_addr - offset; + mutex_lock(&epc->lock); - epc->ops->unmap_addr(epc, func_no, vfunc_no, phys_addr); + epc->ops->unmap_addr(epc, func_no, vfunc_no, aligned_phys); mutex_unlock(&epc->lock); + + pci_epc_mem_free_addr(epc, aligned_phys, aligned_virt, size); } EXPORT_SYMBOL_GPL(pci_epc_unmap_addr); @@ -458,26 +475,46 @@ EXPORT_SYMBOL_GPL(pci_epc_unmap_addr); * * Invoke to map CPU address with PCI address. */ -int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, - phys_addr_t phys_addr, u64 pci_addr, size_t size) +void __iomem *pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, + u64 pci_addr, phys_addr_t *phys_addr, size_t size) { int ret; + u64 aligned_addr; + size_t offset; + void __iomem *virt_addr; if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions) - return -EINVAL; + return ERR_PTR(-EINVAL); if (vfunc_no > 0 && (!epc->max_vfs || vfunc_no > epc->max_vfs[func_no])) - return -EINVAL; + return ERR_PTR(-EINVAL); if (!epc->ops->map_addr) - return 0; + return ERR_PTR(-ENOPTSUPP); + + if (epc->ops->align_mem) { + mutex_lock(&epc->lock); + aligned_addr = epc->ops->align_mem(epc, pci_addr, &size); + mutex_unlock(&epc->lock); + } else { + aligned_addr = pci_addr; + } + + offset = pci_addr - aligned_addr; + + virt_addr = pci_epc_mem_alloc_addr(epc, phys_addr, size); + if (!virt_addr) + return ERR_PTR(-ENOMEM); mutex_lock(&epc->lock); - ret = epc->ops->map_addr(epc, func_no, vfunc_no, phys_addr, pci_addr, - size); + ret = epc->ops->map_addr(epc, func_no, vfunc_no, *phys_addr, aligned_addr, size); mutex_unlock(&epc->lock); + if (ret) + return ERR_PTR(ret); - return ret; + *phys_addr += offset; + + return virt_addr + offset; } EXPORT_SYMBOL_GPL(pci_epc_map_addr); diff --git a/include/linux/pci-epc.h b/include/linux/pci-epc.h index a48778e1a4ee..8f29161bce80 100644 --- a/include/linux/pci-epc.h +++ b/include/linux/pci-epc.h @@ -84,6 +84,7 @@ struct pci_epc_ops { phys_addr_t phys_addr, u8 interrupt_num, u32 entry_size, u32 *msi_data, u32 *msi_addr_offset); + u64 (*align_mem)(struct pci_epc *epc, u64 addr, size_t *size); int (*start)(struct pci_epc *epc); void (*stop)(struct pci_epc *epc); const struct pci_epc_features* (*get_features)(struct pci_epc *epc, @@ -218,11 +219,12 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no, struct pci_epf_bar *epf_bar); void pci_epc_clear_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no, struct pci_epf_bar *epf_bar); -int pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, - phys_addr_t phys_addr, - u64 pci_addr, size_t size); +void __iomem *pci_epc_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, + u64 pci_addr, phys_addr_t *phys_addr, + size_t size); void pci_epc_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no, - phys_addr_t phys_addr); + phys_addr_t phys_addr, void __iomem *virt_addr, + size_t size); int pci_epc_set_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no, u8 interrupts); int pci_epc_get_msi(struct pci_epc *epc, u8 func_no, u8 vfunc_no); From patchwork Fri Jan 13 09:03:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shunsuke Mie X-Patchwork-Id: 13100286 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AC81C54EBE for ; Fri, 13 Jan 2023 09:05:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241046AbjAMJFd (ORCPT ); Fri, 13 Jan 2023 04:05:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241063AbjAMJEY (ORCPT ); Fri, 13 Jan 2023 04:04:24 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B39B755D8 for ; Fri, 13 Jan 2023 01:04:06 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so23760474pjj.4 for ; Fri, 13 Jan 2023 01:04:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7zt7o8mGSey8mVhw10mPNKPVnAWSwiJUiUWfZxevgFM=; b=LvpLZZGyqxgQkhNmzgfZKniI5kjlNpm3T5oc+JklXv39y7j2DiD+um706Aaw+KVRpx mZEnqUXu69NW0+HCY23D6Tx8K+e89aF7d8F63qcjQ5/Jn9+jPk5F0vBshiFY2vldec0T xfG25TsDWvA93P7uOa8YdrYkMySS4ewd51j2Qlchbp+WVaGdcfjeC2hd+iiHM5gsR8CT /YhFYvQfyWYmILwzvekDQhc8byZo2BIjh5qcTNO41J1LloyI6eo04jpf7QRuPCv16HeQ SyNff8AdvDosgvCtygrHFQhhxjDx4GWGo77WQ4jGI/p7ztvN/5ugsUwDd/tEnVFG/CsZ a02w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7zt7o8mGSey8mVhw10mPNKPVnAWSwiJUiUWfZxevgFM=; b=YbGriwR1sDQlqDykbg6dcYtu6n659GeuwuKzOopsgbT3bw0e4+ovYkddfvJjPmSgI4 zljcR3kuPB46AxR8H1aF1pcQ1Kp9tuOFHMuSmuv9mzwz6oFuCRrYZoYTIjxDvwAsVntO 5HdeZhaovp+dhEh+W0GASId1RL1N9f4tXOVS9xFqZO9gitqgZcdwPc7BAlEnWgkefmC8 4VKeEe35CvBV90w2hE2vHzIddne6c6tJy3YtmsZn/QPz02Xz2j/E9VDSXXNVxcmZdnuy kAhgZV0e2TseLMNSD4YuQ+1uJ1RRqHn7VGzdZHUd7Q2n6aBSBBi/x8ca8M487o0veQbG qGXw== X-Gm-Message-State: AFqh2kowM1wdSu+JMxRgNKePYPW/J179zh4Yr6WMXhr4+NEAYil+x32O vjxhsrSE9t/GXuB2qA5ZxTGs1Q== X-Google-Smtp-Source: AMrXdXsifyFFGZOyVJ3vdvcqAJ/NB4SkH3SHpN3A9qmrrBoWSh6LxuKjJazYR3ZoS+pxYjBz079LNg== X-Received: by 2002:a05:6a21:3a45:b0:9d:efbe:e607 with SMTP id zu5-20020a056a213a4500b0009defbee607mr93246543pzb.35.1673600645525; Fri, 13 Jan 2023 01:04:05 -0800 (PST) Received: from tyrell.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id p15-20020a170902e74f00b00189bf5deda3sm13645510plf.133.2023.01.13.01.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 01:04:05 -0800 (PST) From: Shunsuke Mie To: Jingoo Han Cc: Gustavo Pimentel , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , Manivannan Sadhasivam , Kishon Vijay Abraham I , Shunsuke Mie , Kunihiko Hayashi , Hou Zhiqiang , Frank Li , Li Chen , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/3] PCI: dwc: support align_mem() callback for pci_epc_epc Date: Fri, 13 Jan 2023 18:03:49 +0900 Message-Id: <20230113090350.1103494-3-mie@igel.co.jp> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230113090350.1103494-1-mie@igel.co.jp> References: <20230113090350.1103494-1-mie@igel.co.jp> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org DWC PCIe EPC driver has alignment restriction for mapping as pci->region_align. Use it to align memory. Signed-off-by: Shunsuke Mie --- drivers/pci/controller/dwc/pcie-designware-ep.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-designware-ep.c b/drivers/pci/controller/dwc/pcie-designware-ep.c index d06654895eba..7a7d7513b612 100644 --- a/drivers/pci/controller/dwc/pcie-designware-ep.c +++ b/drivers/pci/controller/dwc/pcie-designware-ep.c @@ -444,6 +444,18 @@ static void dw_pcie_ep_stop(struct pci_epc *epc) dw_pcie_stop_link(pci); } +static u64 dw_pcie_ep_align_mem(struct pci_epc *epc, u64 addr, size_t *size) +{ + struct dw_pcie_ep *ep = epc_get_drvdata(epc); + struct dw_pcie *pci = to_dw_pcie_from_ep(ep); + u64 aaddr; + + aaddr = ALIGN_DOWN(addr, pci->region_align); + *size += addr - aaddr; + + return aaddr; +} + static int dw_pcie_ep_start(struct pci_epc *epc) { struct dw_pcie_ep *ep = epc_get_drvdata(epc); @@ -474,6 +486,7 @@ static const struct pci_epc_ops epc_ops = { .set_msix = dw_pcie_ep_set_msix, .get_msix = dw_pcie_ep_get_msix, .raise_irq = dw_pcie_ep_raise_irq, + .align_mem = dw_pcie_ep_align_mem, .start = dw_pcie_ep_start, .stop = dw_pcie_ep_stop, .get_features = dw_pcie_ep_get_features, From patchwork Fri Jan 13 09:03:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shunsuke Mie X-Patchwork-Id: 13100287 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B0F5C54EBD for ; Fri, 13 Jan 2023 09:05:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241105AbjAMJFp (ORCPT ); Fri, 13 Jan 2023 04:05:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240830AbjAMJFK (ORCPT ); Fri, 13 Jan 2023 04:05:10 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DA79736F0 for ; Fri, 13 Jan 2023 01:04:09 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id w4-20020a17090ac98400b002186f5d7a4cso26426481pjt.0 for ; Fri, 13 Jan 2023 01:04:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hZXGSNWlfPLDUVH1iGddBW0l88BlZlK09bpAmm1lhmY=; b=6Xi6bt0Ya85oYGvBiB8XVOqsGmOeuImFPi8YUQmFpLyBbvMRW8wQ3ncWNYy7CrCCP5 7Bp5l3FqLFwFc+teXf4lcKx+tqseBiI2In/92EvMSusgGuUBXI/UCMeQwC6r6Wz5gzfs amr/e/jV8iGhrmJhLxiP8n2OS+iX0vmNVJUHGxQKw2YHPv/2JDPG2O9eOXgzYWh2lIGb LmtMbMob2J/Si3uqRiG35feI1RnRG+KZn5lP6ZzLKohi1mFsEOiFAQd2eRGExtc01dHX CWILOI9FP8bc78/Yj3N1kjOirm3B+DToda7tD1rD+NXyeMAAkTZhFjYT9viuZcC36Ug8 KvnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hZXGSNWlfPLDUVH1iGddBW0l88BlZlK09bpAmm1lhmY=; b=kMTdFfMM8tLEPeSlcsw/KTRgutg55tLn/SgCAZa713dze1YGC1ON9r/x43Rti0Qvvm 9zgZmoAcQnPfZA/o8utEL4TkivWW0hz7QvPYTuLJBNYp6wQgJcHPbWZRh1ddfvWMRQCX VtF1VdeRaBEDo1LPdha4kQfBRLwqRNiP8e0kLsG77uYg4ZJHbm+2+AHyFT3pXRRp6yM8 2LuvnxDQ758hXLItpzt4ldtaRh7/etYlRES9Rvq8BSxh4hVwdZOf8NCubjfKZSoXNhzZ 71AAdBmfvCsSde6WX87BJsJZTe0cC0IHDmrR8ljanAHeCP998ruBlwtu4WgVYQdY+ISN J1hw== X-Gm-Message-State: AFqh2krJdthsrBT56BKknFUx82iI6rX1dqb8Kz1INorQ8n9olZqWzYfE pPjNSKlUh69Tbg0XiOdVFcB1rA== X-Google-Smtp-Source: AMrXdXvri2Qepeukyexki5xgsBZ2ZmJCQ1Uu3PE520x2rvuu313ZsZ+U3mGUYtdp0BpMZzcbYrlxdw== X-Received: by 2002:a17:902:b609:b0:192:e9cf:93ba with SMTP id b9-20020a170902b60900b00192e9cf93bamr32178510pls.12.1673600649254; Fri, 13 Jan 2023 01:04:09 -0800 (PST) Received: from tyrell.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id p15-20020a170902e74f00b00189bf5deda3sm13645510plf.133.2023.01.13.01.04.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 01:04:08 -0800 (PST) From: Shunsuke Mie To: Jingoo Han Cc: Gustavo Pimentel , Lorenzo Pieralisi , Rob Herring , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas , Manivannan Sadhasivam , Kishon Vijay Abraham I , Shunsuke Mie , Kunihiko Hayashi , Hou Zhiqiang , Frank Li , Li Chen , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/3] PCI: endpoint: support pci_epc_mem_map/unmap API changes Date: Fri, 13 Jan 2023 18:03:50 +0900 Message-Id: <20230113090350.1103494-4-mie@igel.co.jp> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230113090350.1103494-1-mie@igel.co.jp> References: <20230113090350.1103494-1-mie@igel.co.jp> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The APIs have changed to support non aligned memory mapping on endpoint. Adapt the new API to pci-epf-test. The API allocate pci epc memory inside, so remove allocations. Signed-off-by: Shunsuke Mie --- drivers/pci/endpoint/functions/pci-epf-test.c | 89 +++++-------------- 1 file changed, 24 insertions(+), 65 deletions(-) diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c index 55283d2379a6..73e75591fd81 100644 --- a/drivers/pci/endpoint/functions/pci-epf-test.c +++ b/drivers/pci/endpoint/functions/pci-epf-test.c @@ -323,37 +323,22 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) struct pci_epc *epc = epf->epc; enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + size_t size = reg->size; - src_addr = pci_epc_mem_alloc_addr(epc, &src_phys_addr, reg->size); - if (!src_addr) { - dev_err(dev, "Failed to allocate source address\n"); - reg->status = STATUS_SRC_ADDR_INVALID; - ret = -ENOMEM; - goto err; - } - - ret = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, src_phys_addr, - reg->src_addr, reg->size); - if (ret) { + src_addr = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, reg->src_addr, + &src_phys_addr, size); + if (IS_ERR(src_addr)) { dev_err(dev, "Failed to map source address\n"); reg->status = STATUS_SRC_ADDR_INVALID; - goto err_src_addr; - } - - dst_addr = pci_epc_mem_alloc_addr(epc, &dst_phys_addr, reg->size); - if (!dst_addr) { - dev_err(dev, "Failed to allocate destination address\n"); - reg->status = STATUS_DST_ADDR_INVALID; - ret = -ENOMEM; - goto err_src_map_addr; + goto err; } - ret = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, dst_phys_addr, - reg->dst_addr, reg->size); + dst_addr = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, reg->dst_addr, + &dst_phys_addr, size); if (ret) { dev_err(dev, "Failed to map destination address\n"); reg->status = STATUS_DST_ADDR_INVALID; - goto err_dst_addr; + goto err_src_map_addr; } ktime_get_ts64(&start); @@ -393,16 +378,10 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) pci_epf_test_print_rate("COPY", reg->size, &start, &end, use_dma); err_map_addr: - pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, dst_phys_addr); - -err_dst_addr: - pci_epc_mem_free_addr(epc, dst_phys_addr, dst_addr, reg->size); + pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, dst_phys_addr, dst_addr, size); err_src_map_addr: - pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, src_phys_addr); - -err_src_addr: - pci_epc_mem_free_addr(epc, src_phys_addr, src_addr, reg->size); + pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, src_phys_addr, src_addr, size); err: return ret; @@ -410,7 +389,7 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test) static int pci_epf_test_read(struct pci_epf_test *epf_test) { - int ret; + int ret = 0; void __iomem *src_addr; void *buf; u32 crc32; @@ -424,21 +403,14 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) struct device *dma_dev = epf->epc->dev.parent; enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + size_t size = reg->size; - src_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); - if (!src_addr) { - dev_err(dev, "Failed to allocate address\n"); - reg->status = STATUS_SRC_ADDR_INVALID; - ret = -ENOMEM; - goto err; - } - - ret = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, phys_addr, - reg->src_addr, reg->size); - if (ret) { + src_addr = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, + reg->src_addr, &phys_addr, size); + if (IS_ERR(src_addr)) { dev_err(dev, "Failed to map address\n"); reg->status = STATUS_SRC_ADDR_INVALID; - goto err_addr; + goto err; } buf = kzalloc(reg->size, GFP_KERNEL); @@ -489,10 +461,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) kfree(buf); err_map_addr: - pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, phys_addr); - -err_addr: - pci_epc_mem_free_addr(epc, phys_addr, src_addr, reg->size); + pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, phys_addr, src_addr, size); err: return ret; @@ -500,7 +469,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) static int pci_epf_test_write(struct pci_epf_test *epf_test) { - int ret; + int ret = 0; void __iomem *dst_addr; void *buf; bool use_dma; @@ -513,21 +482,14 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) struct device *dma_dev = epf->epc->dev.parent; enum pci_barno test_reg_bar = epf_test->test_reg_bar; struct pci_epf_test_reg *reg = epf_test->reg[test_reg_bar]; + size_t size = reg->size; - dst_addr = pci_epc_mem_alloc_addr(epc, &phys_addr, reg->size); - if (!dst_addr) { - dev_err(dev, "Failed to allocate address\n"); - reg->status = STATUS_DST_ADDR_INVALID; - ret = -ENOMEM; - goto err; - } - - ret = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, phys_addr, - reg->dst_addr, reg->size); - if (ret) { + dst_addr = pci_epc_map_addr(epc, epf->func_no, epf->vfunc_no, + reg->dst_addr, &phys_addr, size); + if (IS_ERR(dst_addr)) { dev_err(dev, "Failed to map address\n"); reg->status = STATUS_DST_ADDR_INVALID; - goto err_addr; + goto err; } buf = kzalloc(reg->size, GFP_KERNEL); @@ -585,10 +547,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) kfree(buf); err_map_addr: - pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, phys_addr); - -err_addr: - pci_epc_mem_free_addr(epc, phys_addr, dst_addr, reg->size); + pci_epc_unmap_addr(epc, epf->func_no, epf->vfunc_no, phys_addr, dst_addr, size); err: return ret;