Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp648509pxf; Thu, 8 Apr 2021 10:04:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKs6uq1Qs3ly1udHy3QLknNZGekb0Vb9EcTm3J781XhUASxB9bnMsqpqE7Of58mZQDX78f X-Received: by 2002:a65:5289:: with SMTP id y9mr8746586pgp.447.1617901459491; Thu, 08 Apr 2021 10:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617901459; cv=none; d=google.com; s=arc-20160816; b=ZZqehSK231LzFUyoZhyPC8ooT04GPrAUM2z7K7719pxS5oDBjyYUnVUf9XM2xbjnka Nl3JRPGkukx7efigtdBhvNcxcJ92lTX4GZVtitGons0v7lhn3fGUtsHsCGr7gSy1Jeo2 kJtpHqIFB4QnY4lOg55MwGJoM/OEEfUzpBuILiNGvoxtIGSR4/9htADzOR5i1xI4UXyB yNmEDTIpuLn2ceMnV2UGuSVSWQQMwYPwUhrwFOZp+MfKfNp5pY6P3FY1202lKePqCwGO cJ1B0jjlHN5R4UqfJZFb3qNsNk6xF/CnOj+LCPg5mAaDyciSARyTsBDo7UFEe/ypN7DD gO5g== 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=XO9yhW7XTrx3mfwGwE6QpMd7kEnzVAWliIF1dzhOXeU=; b=uzvp8yko+eEBlkrt2HLGRrpXh6ENOPjUnpS1I8SxD7ZdOwL/KDPlaqNtr3o2wcfavf CISfLDsst92gXkkedrFNtyGtjQJzP5AXkYwRAVtAM1UJNYFxJFHQnFs74ZOFP3xlDnjB Kn0kE0h1tuQwzjJod91FAZrd20Kjaewj9k+tHYeplGTu3oA8cRgm/FkECSxDMjw4hsSw YBOWKUGIR6ep4NcfHJ1v0Bs9sK/DF3nEwF5J+U+wEEHwTtS+GVpJ12OoibsGT8F10snO TzbdPyjfwsxba4fSZTPX0scGmUcnLCyt6Cyj0XYqB5Z017S/VKTEC6DFfxDBGmoxEtUy vrXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=rib3kUEt; 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 e24si25642784pgv.298.2021.04.08.10.04.06; Thu, 08 Apr 2021 10:04:19 -0700 (PDT) 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=rib3kUEt; 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 S232563AbhDHRCL (ORCPT + 99 others); Thu, 8 Apr 2021 13:02:11 -0400 Received: from ale.deltatee.com ([204.191.154.188]:36070 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232435AbhDHRBu (ORCPT ); Thu, 8 Apr 2021 13:01:50 -0400 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=XO9yhW7XTrx3mfwGwE6QpMd7kEnzVAWliIF1dzhOXeU=; b=rib3kUEtVNJRlvV53SL0zFjEgT QROYfOqlhCRGJaDNhadz5PM0yzRr/WPXms/S5ZtwptuzITnq8w+5SzAmNcvyma9TT/GL6Jy6xof38 q76FKTmfS20cfoBRx+BP4KJeAKSzOnVbFGzKSrvi3Gl9mM6E8gUpvxtXrMgOoBeVKdgK+WVRiC+Tz /5eLHSL97LSmePUr3BPV+H2aa7B/6yvz9Qma+QzpoQNgYCpQ5+R6Blj5oHXNnfEvgTCFtNwqrXskn 2zLMkaNp61pjKvfNcmzj90K4+dmrSEmtcjzFicSWifWJk+r+TxUGfy1/jx+mxZKzcClCkG+W1j4VC P6i5g2KA==; 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 1lUY2D-0002Ll-OO; Thu, 08 Apr 2021 11:01:38 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1lUY26-0002JC-AA; Thu, 08 Apr 2021 11:01:30 -0600 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?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Jakowski Andrzej , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Logan Gunthorpe Date: Thu, 8 Apr 2021 11:01:17 -0600 Message-Id: <20210408170123.8788-11-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210408170123.8788-1-logang@deltatee.com> References: <20210408170123.8788-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, helgaas@kernel.org, dan.j.williams@intel.com, andrzej.jakowski@intel.com, dave.b.minturn@intel.com, jianxin.xiong@intel.com, ira.weiny@intel.com, robin.murphy@arm.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: [PATCH 10/16] 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 | 18 ++++++++++++++++++ 3 files changed, 26 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 50b8f586cf59..c31980ecca62 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -146,6 +146,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); +bool 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); @@ -247,6 +248,10 @@ static inline int dma_supported(struct device *dev, u64 mask) { return 0; } +static inline bool 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 923089c4267b..ce44a0fcc4e5 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -573,6 +573,24 @@ int dma_supported(struct device *dev, u64 mask) } EXPORT_SYMBOL(dma_supported); +bool dma_pci_p2pdma_supported(struct device *dev) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + + /* if ops is not set, dma direct will be used which supports P2PDMA */ + if (!ops) + return true; + + /* + * Note: dma_ops_bypass is not checked here because P2PDMA should + * not be used with dma mapping ops that do not have support even + * if the specific device is bypassing them. + */ + + return ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED; +} +EXPORT_SYMBOL_GPL(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