diff options
author | Christoph Hellwig <hch@lst.de> | 2020-06-29 15:03:56 +0200 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2020-06-30 15:44:03 +0200 |
commit | 3aa91625007807bfca4155df1867a5c924a08662 (patch) | |
tree | 200b5d80ea2b377dcdc560056f1fc247dc18024f /kernel | |
parent | 2bdeb3ed547d8822b2566797afa6c2584abdb119 (diff) | |
download | linux-3aa91625007807bfca4155df1867a5c924a08662.tar.bz2 |
dma-mapping: Add a new dma_need_sync API
Add a new API to check if calls to dma_sync_single_for_{device,cpu} are
required for a given DMA streaming mapping.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200629130359.2690853-2-hch@lst.de
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/dma/direct.c | 6 | ||||
-rw-r--r-- | kernel/dma/mapping.c | 10 |
2 files changed, 16 insertions, 0 deletions
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 0a4881e59aa7..ecb922a0bfa0 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -530,3 +530,9 @@ size_t dma_direct_max_mapping_size(struct device *dev) return swiotlb_max_mapping_size(dev); return SIZE_MAX; } + +bool dma_direct_need_sync(struct device *dev, dma_addr_t dma_addr) +{ + return !dev_is_dma_coherent(dev) || + is_swiotlb_buffer(dma_to_phys(dev, dma_addr)); +} diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 98e3d873792e..a8c18c9a796f 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -397,6 +397,16 @@ size_t dma_max_mapping_size(struct device *dev) } EXPORT_SYMBOL_GPL(dma_max_mapping_size); +bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) +{ + const struct dma_map_ops *ops = get_dma_ops(dev); + + if (dma_is_direct(ops)) + return dma_direct_need_sync(dev, dma_addr); + return ops->sync_single_for_cpu || ops->sync_single_for_device; +} +EXPORT_SYMBOL_GPL(dma_need_sync); + unsigned long dma_get_merge_boundary(struct device *dev) { const struct dma_map_ops *ops = get_dma_ops(dev); |