Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp810233pxf; Thu, 11 Mar 2021 15:50:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMZ22oRVNSfUe8CrmzKKApQFAWuyILaFLO1X3AdcjDN6VOo09z5BSJkGljZWqAmoBRDC6U X-Received: by 2002:a50:e14d:: with SMTP id i13mr10995700edl.106.1615506647456; Thu, 11 Mar 2021 15:50:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615506647; cv=none; d=google.com; s=arc-20160816; b=SACVRVc8Qnifk3rNOWpGMcmTbX6EMjcl4fY/cVUejsT+W4KChzGXU1kWP8/Zbogvxb tGw6x48a7yaYHF+Kw0YT897kFENIq/4HYjYRtTnlAjwbbVIePJ7fCJexMtWFmmgD8/26 p5f2EWl/mxpshudvwHWbcynu2isHSilp+9K3gugP2AAX9G6uQtncyKcA6Tvh1tr1PKYR ZamC4eGvMz/0gAlK8YDbUaH7j/6Y02nsoJg1jHfyM6wU8izw+LM4MwrNtMWhE5IFOWzc +Hmaj2MXlMOZ6KfR7d+Xje1ehmEtzXoLhR7odq5TSCYosW5QUDJX6v46/l41YgRLp3cW A8wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=KOMMXadwrYwZEB6tWYvcMS2uWikbMkq234oR8x5l6uU=; b=lE3D0E/dRSHqXgSet1+3sGZ7GFyrx3/DCRsbqUNPAh3NbtjUbic8QVq/ou8eVauRua qtS5GU4qEkLRKUpX8tEUJotWBAd7eLQlxB6skqn9lAiwDIlh9CQ4IpcLXW4SGZzO1GTt Gl0FbMXVh5hkW3sOYSA3g1F+m793MBHegB4u0ltsIKY8HhuqU5/flPNHH/QQFiiJERRA sJXn0t28oQhS0yfcHkYZeB032mLCW3YJdUy1xRBLIMZMAXGVHq0+SLyTM1mctbXV0Gqz fOfPb7B2KZ5WD/7af9e8V3ymq7/qwB9CvieeEufsRlO+BblYlhB/3jCgTG4VDFaVOF6z LUaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=NOigEiKa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ec23si2819588ejb.710.2021.03.11.15.50.25; Thu, 11 Mar 2021 15:50:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=NOigEiKa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231378AbhCKXtD (ORCPT + 99 others); Thu, 11 Mar 2021 18:49:03 -0500 Received: from ale.deltatee.com ([204.191.154.188]:58788 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229606AbhCKXsg (ORCPT ); Thu, 11 Mar 2021 18:48:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=KOMMXadwrYwZEB6tWYvcMS2uWikbMkq234oR8x5l6uU=; b=NOigEiKa5QVhqkJx08sL74oozH IZ3CiU8+eeNi0GWrmCuxBvytyQml8bVvak4gI55pcE2jXr1VSHIoSsjrWGiFBqneKdlc/tREjEfQK vpBhsUQYflR8mj4rh+OgbyUcpWwHvWJro43CV02zDTEMELz51KCyW4YJ1HEQ5aT++Wx4fWd0e2UIz 1Fdm889jVbolaeVeZCD1GDvmPKyUJzpB3kfWPtbn3sTqKbzNUDsxzF+bTniILfxZ6v1Lj6Izgqeej bn38QX113rFGYQkNk83OpSUc66XivY5TKSYhkyr9Yr5OB+kx3ZkOj25E4nbNn9vcglbG8mk4sRFr+ 74XDjSSA==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKUmm-0003ev-8M; Thu, 11 Mar 2021 16:32:09 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1lKUmW-00024e-Lc; Thu, 11 Mar 2021 16:31:52 -0700 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org Cc: Stephen Bates , Christoph Hellwig , Dan Williams , Jason Gunthorpe , =?UTF-8?q?Christian=20K=C3=B6nig?= , Ira Weiny , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Logan Gunthorpe Date: Thu, 11 Mar 2021 16:31:37 -0700 Message-Id: <20210311233142.7900-8-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210311233142.7900-1-logang@deltatee.com> References: <20210311233142.7900-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, iommu@lists.linux-foundation.org, sbates@raithlin.com, hch@lst.de, jgg@ziepe.ca, christian.koenig@amd.com, jhubbard@nvidia.com, ddutile@redhat.com, willy@infradead.org, daniel.vetter@ffwll.ch, jason@jlekstrand.net, dave.hansen@linux.intel.com, dan.j.williams@intel.com, iweiny@intel.com, andrzej.jakowski@intel.com, dave.b.minturn@intel.com, jianxin.xiong@intel.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-6.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, MYRULES_NO_TEXT autolearn=no autolearn_force=no version=3.4.2 Subject: [RFC PATCH v2 07/11] dma-mapping: Add flags to dma_map_ops to indicate PCI P2PDMA support X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a flags member to the dma_map_ops structure with one flag to indicate support for PCI P2PDMA. Also, add a helper to check if a device supports PCI P2PDMA. Signed-off-by: Logan Gunthorpe --- include/linux/dma-map-ops.h | 3 +++ include/linux/dma-mapping.h | 5 +++++ kernel/dma/mapping.c | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 51872e736e7b..481892822104 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -12,6 +12,9 @@ struct cma; struct dma_map_ops { + unsigned int flags; +#define DMA_F_PCI_P2PDMA_SUPPORTED (1 << 0) + void *(*alloc)(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs); diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 2a984cb4d1e0..a6bced004de8 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -138,6 +138,7 @@ int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma, unsigned long attrs); bool dma_can_mmap(struct device *dev); int dma_supported(struct device *dev, u64 mask); +int dma_pci_p2pdma_supported(struct device *dev); int dma_set_mask(struct device *dev, u64 mask); int dma_set_coherent_mask(struct device *dev, u64 mask); u64 dma_get_required_mask(struct device *dev); @@ -233,6 +234,10 @@ static inline int dma_supported(struct device *dev, u64 mask) { return 0; } +static inline int dma_pci_p2pdma_supported(struct device *dev) +{ + return 0; +} static inline int dma_set_mask(struct device *dev, u64 mask) { return -EIO; diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index adc1a83950be..cc1b97deb74d 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -540,6 +540,14 @@ int dma_supported(struct device *dev, u64 mask) } EXPORT_SYMBOL(dma_supported); +int dma_pci_p2pdma_supported(struct device *dev) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + + return !ops || ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED; +} +EXPORT_SYMBOL(dma_pci_p2pdma_supported); + #ifdef CONFIG_ARCH_HAS_DMA_SET_MASK void arch_dma_set_mask(struct device *dev, u64 mask); #else -- 2.20.1