-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MIPS: consolidate the swiotlb implementations
Octeon and Loongson share exactly the same code, move it into a common implementation, and use that implementation directly from get_arch_dma_ops. Also provide the expected dma-direct.h helpers directly instead of delegating to platform dma-coherence.h headers. Signed-off-by: Christoph Hellwig <hch@lst.de> Patchwork: https://patchwork.linux-mips.org/patch/19534/ Signed-off-by: Paul Burton <paul.burton@mips.com> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: David Daney <david.daney@cavium.com> Cc: Kevin Cernekee <cernekee@gmail.com> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com> Cc: Tom Bogendoerfer <tsbogend@alpha.franken.de> Cc: Huacai Chen <chenhc@lemote.com> Cc: iommu@lists.linux-foundation.org Cc: linux-mips@linux-mips.org
- Loading branch information
Christoph Hellwig
authored and
Paul Burton
committed
Jun 24, 2018
1 parent
e799de3
commit f6d302e
Showing
8 changed files
with
84 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
#include <asm/dma-coherence.h> | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef _MIPS_DMA_DIRECT_H | ||
#define _MIPS_DMA_DIRECT_H 1 | ||
|
||
static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) | ||
{ | ||
if (!dev->dma_mask) | ||
return false; | ||
|
||
return addr + size - 1 <= *dev->dma_mask; | ||
} | ||
|
||
dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr); | ||
phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr); | ||
|
||
#endif /* _MIPS_DMA_DIRECT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <linux/dma-mapping.h> | ||
#include <linux/swiotlb.h> | ||
|
||
static void *mips_swiotlb_alloc(struct device *dev, size_t size, | ||
dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) | ||
{ | ||
void *ret = swiotlb_alloc(dev, size, dma_handle, gfp, attrs); | ||
|
||
mb(); | ||
return ret; | ||
} | ||
|
||
static dma_addr_t mips_swiotlb_map_page(struct device *dev, | ||
struct page *page, unsigned long offset, size_t size, | ||
enum dma_data_direction dir, unsigned long attrs) | ||
{ | ||
dma_addr_t daddr = swiotlb_map_page(dev, page, offset, size, | ||
dir, attrs); | ||
mb(); | ||
return daddr; | ||
} | ||
|
||
static int mips_swiotlb_map_sg(struct device *dev, struct scatterlist *sg, | ||
int nents, enum dma_data_direction dir, unsigned long attrs) | ||
{ | ||
int r = swiotlb_map_sg_attrs(dev, sg, nents, dir, attrs); | ||
mb(); | ||
|
||
return r; | ||
} | ||
|
||
static void mips_swiotlb_sync_single_for_device(struct device *dev, | ||
dma_addr_t dma_handle, size_t size, enum dma_data_direction dir) | ||
{ | ||
swiotlb_sync_single_for_device(dev, dma_handle, size, dir); | ||
mb(); | ||
} | ||
|
||
static void mips_swiotlb_sync_sg_for_device(struct device *dev, | ||
struct scatterlist *sg, int nents, enum dma_data_direction dir) | ||
{ | ||
swiotlb_sync_sg_for_device(dev, sg, nents, dir); | ||
mb(); | ||
} | ||
|
||
const struct dma_map_ops mips_swiotlb_ops = { | ||
.alloc = mips_swiotlb_alloc, | ||
.free = swiotlb_free, | ||
.map_page = mips_swiotlb_map_page, | ||
.unmap_page = swiotlb_unmap_page, | ||
.map_sg = mips_swiotlb_map_sg, | ||
.unmap_sg = swiotlb_unmap_sg_attrs, | ||
.sync_single_for_cpu = swiotlb_sync_single_for_cpu, | ||
.sync_single_for_device = mips_swiotlb_sync_single_for_device, | ||
.sync_sg_for_cpu = swiotlb_sync_sg_for_cpu, | ||
.sync_sg_for_device = mips_swiotlb_sync_sg_for_device, | ||
.mapping_error = swiotlb_dma_mapping_error, | ||
.dma_supported = swiotlb_dma_supported, | ||
}; | ||
EXPORT_SYMBOL(mips_swiotlb_ops); |