Skip to content

Commit 159bf19

Browse files
lsgunthChristoph Hellwig
authored andcommitted
dma-mapping: add flags to dma_map_ops to indicate PCI P2PDMA support
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> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent f02ad36 commit 159bf19

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

include/linux/dma-map-ops.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@
1111

1212
struct cma;
1313

14+
/*
15+
* Values for struct dma_map_ops.flags:
16+
*
17+
* DMA_F_PCI_P2PDMA_SUPPORTED: Indicates the dma_map_ops implementation can
18+
* handle PCI P2PDMA pages in the map_sg/unmap_sg operation.
19+
*/
20+
#define DMA_F_PCI_P2PDMA_SUPPORTED (1 << 0)
21+
1422
struct dma_map_ops {
23+
unsigned int flags;
24+
1525
void *(*alloc)(struct device *dev, size_t size,
1626
dma_addr_t *dma_handle, gfp_t gfp,
1727
unsigned long attrs);

include/linux/dma-mapping.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ int dma_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
140140
unsigned long attrs);
141141
bool dma_can_mmap(struct device *dev);
142142
int dma_supported(struct device *dev, u64 mask);
143+
bool dma_pci_p2pdma_supported(struct device *dev);
143144
int dma_set_mask(struct device *dev, u64 mask);
144145
int dma_set_coherent_mask(struct device *dev, u64 mask);
145146
u64 dma_get_required_mask(struct device *dev);
@@ -251,6 +252,10 @@ static inline int dma_supported(struct device *dev, u64 mask)
251252
{
252253
return 0;
253254
}
255+
static inline bool dma_pci_p2pdma_supported(struct device *dev)
256+
{
257+
return false;
258+
}
254259
static inline int dma_set_mask(struct device *dev, u64 mask)
255260
{
256261
return -EIO;

kernel/dma/mapping.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,24 @@ int dma_supported(struct device *dev, u64 mask)
723723
}
724724
EXPORT_SYMBOL(dma_supported);
725725

726+
bool dma_pci_p2pdma_supported(struct device *dev)
727+
{
728+
const struct dma_map_ops *ops = get_dma_ops(dev);
729+
730+
/* if ops is not set, dma direct will be used which supports P2PDMA */
731+
if (!ops)
732+
return true;
733+
734+
/*
735+
* Note: dma_ops_bypass is not checked here because P2PDMA should
736+
* not be used with dma mapping ops that do not have support even
737+
* if the specific device is bypassing them.
738+
*/
739+
740+
return ops->flags & DMA_F_PCI_P2PDMA_SUPPORTED;
741+
}
742+
EXPORT_SYMBOL_GPL(dma_pci_p2pdma_supported);
743+
726744
#ifdef CONFIG_ARCH_HAS_DMA_SET_MASK
727745
void arch_dma_set_mask(struct device *dev, u64 mask);
728746
#else

0 commit comments

Comments
 (0)