Message ID | 20210311233142.7900-8-logang@deltatee.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
Series | Add support to dma_map_sg for P2PDMA | expand |
On Thu, Mar 11, 2021 at 04:31:37PM -0700, Logan Gunthorpe wrote: > +int dma_pci_p2pdma_supported(struct device *dev) ^^^ bool? > +{ > + const struct dma_map_ops *ops = get_dma_ops(dev); > + > + return !ops || ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED; Is this logic correct? I would have expected. return (ops && ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED); Ira
On 2021-03-12 7:36 p.m., Ira Weiny wrote: > On Thu, Mar 11, 2021 at 04:31:37PM -0700, Logan Gunthorpe wrote: > >> +int dma_pci_p2pdma_supported(struct device *dev) > ^^^ > bool? Sure. > >> +{ >> + const struct dma_map_ops *ops = get_dma_ops(dev); >> + >> + return !ops || ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED; > > Is this logic correct? I would have expected. > > return (ops && ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED); If ops is NULL then the operations in kernel/dma/direct.c are used and support is added to those in patch 6. So it is correct as written. Logan
On Mon, Mar 15, 2021 at 10:33:13AM -0600, Logan Gunthorpe wrote: > >> + return !ops || ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED; > > > > Is this logic correct? I would have expected. > > > > return (ops && ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED); > > > If ops is NULL then the operations in kernel/dma/direct.c are used and > support is added to those in patch 6. So it is correct as written. It is not quite that easy. There also is the bypass flag and for the specific case where that is ignored the code needs a really good comment. And to assist that formatted so that it makes sense. The above line is indeed highly confusing even if it ends up being correct.
On Thu, Mar 11, 2021 at 04:31:37PM -0700, Logan Gunthorpe wrote: > +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); EXPORT_SYMBOL_GPL like all new DMA APIs.
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
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 <logang@deltatee.com> --- include/linux/dma-map-ops.h | 3 +++ include/linux/dma-mapping.h | 5 +++++ kernel/dma/mapping.c | 8 ++++++++ 3 files changed, 16 insertions(+)