Hi all,
This patch series does update mach-generic/dma-coherence.h to test whether a
machine is already defining any of the functions. This is aimed at avoiding the
need for every single platform to redefine its own functions, as well as make
us future proof in case we need to add new infrastructure, which I am about to.
Thanks
Florian Fainelli (2):
MIPS: Allow including mach-generic/dma-coherence.h
MIPS: Update dma-coherence.h files
arch/mips/include/asm/mach-ath25/dma-coherence.h | 10 +++++---
arch/mips/include/asm/mach-bmips/dma-coherence.h | 24 +++++--------------
.../include/asm/mach-cavium-octeon/dma-coherence.h | 14 +++++++----
arch/mips/include/asm/mach-generic/dma-coherence.h | 16 +++++++++++++
arch/mips/include/asm/mach-ip27/dma-coherence.h | 28 +++++-----------------
arch/mips/include/asm/mach-ip32/dma-coherence.h | 16 ++++++-------
arch/mips/include/asm/mach-jazz/dma-coherence.h | 24 ++++++-------------
.../include/asm/mach-loongson64/dma-coherence.h | 16 ++++++-------
8 files changed, 67 insertions(+), 81 deletions(-)
--
2.7.4
Check whether a platform is already defining any of the functions we
provide in mach-generic/dma-coherence.h. This is a preliminary change to
allow cleaning up machine's dma-coherence.h files.
Signed-off-by: Florian Fainelli <[email protected]>
---
arch/mips/include/asm/mach-generic/dma-coherence.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/arch/mips/include/asm/mach-generic/dma-coherence.h b/arch/mips/include/asm/mach-generic/dma-coherence.h
index 61addb1677e9..e6e7dfa15801 100644
--- a/arch/mips/include/asm/mach-generic/dma-coherence.h
+++ b/arch/mips/include/asm/mach-generic/dma-coherence.h
@@ -11,29 +11,38 @@
struct device;
+#ifndef plat_map_dma_mem
static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
size_t size)
{
return virt_to_phys(addr);
}
+#endif
+#ifndef plat_map_dma_mem_page
static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
struct page *page)
{
return page_to_phys(page);
}
+#endif
+#ifndef plat_dma_addr_to_phys
static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
dma_addr_t dma_addr)
{
return dma_addr;
}
+#endif
+#ifndef plat_unmap_dma_mem
static inline void plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr,
size_t size, enum dma_data_direction direction)
{
}
+#endif
+#ifndef plat_dma_supported
static inline int plat_dma_supported(struct device *dev, u64 mask)
{
/*
@@ -46,7 +55,9 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
return 1;
}
+#endif
+#ifndef plat_device_is_coherent
static inline int plat_device_is_coherent(struct device *dev)
{
#ifdef CONFIG_DMA_PERDEV_COHERENT
@@ -63,6 +74,7 @@ static inline int plat_device_is_coherent(struct device *dev)
}
#endif
}
+#endif
#ifndef plat_post_dma_flush
static inline void plat_post_dma_flush(struct device *dev)
@@ -71,15 +83,19 @@ static inline void plat_post_dma_flush(struct device *dev)
#endif
#ifdef CONFIG_SWIOTLB
+#ifndef phys_to_dma
static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
{
return paddr;
}
+#endif
+#ifndef dma_to_phys
static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
{
return daddr;
}
#endif
+#endif /* CONFIG_SWIOTLB */
#endif /* __ASM_MACH_GENERIC_DMA_COHERENCE_H */
--
2.7.4
Define all functions that differ from the generic implementation, kill
the redundant generic implementation where relevant, and finally include
asm/mach-generic/dma-coherence.h to be future proof when new functions
will be added.
Signed-off-by: Florian Fainelli <[email protected]>
---
arch/mips/include/asm/mach-ath25/dma-coherence.h | 10 +++++---
arch/mips/include/asm/mach-bmips/dma-coherence.h | 24 +++++--------------
.../include/asm/mach-cavium-octeon/dma-coherence.h | 14 +++++++----
arch/mips/include/asm/mach-ip27/dma-coherence.h | 28 +++++-----------------
arch/mips/include/asm/mach-ip32/dma-coherence.h | 16 ++++++-------
arch/mips/include/asm/mach-jazz/dma-coherence.h | 24 ++++++-------------
.../include/asm/mach-loongson64/dma-coherence.h | 16 ++++++-------
7 files changed, 51 insertions(+), 81 deletions(-)
diff --git a/arch/mips/include/asm/mach-ath25/dma-coherence.h b/arch/mips/include/asm/mach-ath25/dma-coherence.h
index d5defdde32db..63bce15fa54d 100644
--- a/arch/mips/include/asm/mach-ath25/dma-coherence.h
+++ b/arch/mips/include/asm/mach-ath25/dma-coherence.h
@@ -30,35 +30,41 @@ static inline dma_addr_t ath25_dev_offset(struct device *dev)
return 0;
}
+#define plat_map_dma_mem plat_map_dma_mem
static inline dma_addr_t
plat_map_dma_mem(struct device *dev, void *addr, size_t size)
{
return virt_to_phys(addr) + ath25_dev_offset(dev);
}
+#define plat_map_dma_mem_page plat_map_dma_mem_page
static inline dma_addr_t
plat_map_dma_mem_page(struct device *dev, struct page *page)
{
return page_to_phys(page) + ath25_dev_offset(dev);
}
+#define plat_dma_addr_to_phys plat_dma_addr_to_phys
static inline unsigned long
plat_dma_addr_to_phys(struct device *dev, dma_addr_t dma_addr)
{
return dma_addr - ath25_dev_offset(dev);
}
+#define plat_unmap_dma_mem plat_unmap_dma_mem
static inline void
plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr, size_t size,
enum dma_data_direction direction)
{
}
+#define plat_dma_supported plat_dma_supported
static inline int plat_dma_supported(struct device *dev, u64 mask)
{
return 1;
}
+#define plat_device_is_coherent plat_device_is_coherent
static inline int plat_device_is_coherent(struct device *dev)
{
#ifdef CONFIG_DMA_COHERENT
@@ -69,8 +75,6 @@ static inline int plat_device_is_coherent(struct device *dev)
#endif
}
-static inline void plat_post_dma_flush(struct device *dev)
-{
-}
+#include <asm/mach-generic/dma-coherence.h>
#endif /* __ASM_MACH_ATH25_DMA_COHERENCE_H */
diff --git a/arch/mips/include/asm/mach-bmips/dma-coherence.h b/arch/mips/include/asm/mach-bmips/dma-coherence.h
index d29781f02285..b56380066573 100644
--- a/arch/mips/include/asm/mach-bmips/dma-coherence.h
+++ b/arch/mips/include/asm/mach-bmips/dma-coherence.h
@@ -21,29 +21,15 @@
struct device;
+#define plat_map_dma_mem plat_map_dma_mem
extern dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, size_t size);
+#define plat_map_dma_mem_page plat_map_dma_mem_page
extern dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page);
+#define plat_dma_addr_to_phys plat_dma_addr_to_phys
extern unsigned long plat_dma_addr_to_phys(struct device *dev,
dma_addr_t dma_addr);
-static inline void plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr,
- size_t size, enum dma_data_direction direction)
-{
-}
-
-static inline int plat_dma_supported(struct device *dev, u64 mask)
-{
- /*
- * we fall back to GFP_DMA when the mask isn't all 1s,
- * so we can't guarantee allocations that must be
- * within a tighter range than GFP_DMA..
- */
- if (mask < DMA_BIT_MASK(24))
- return 0;
-
- return 1;
-}
-
+#define plat_device_is_coherent plat_device_is_coherent
static inline int plat_device_is_coherent(struct device *dev)
{
return 0;
@@ -51,4 +37,6 @@ static inline int plat_device_is_coherent(struct device *dev)
#define plat_post_dma_flush bmips_post_dma_flush
+#include <asm/mach-generic/dma-coherence.h>
+
#endif /* __ASM_MACH_BMIPS_DMA_COHERENCE_H */
diff --git a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
index 9110988b92a1..165e13aba3ff 100644
--- a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
+++ b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
@@ -19,6 +19,7 @@ struct device;
extern void octeon_pci_dma_init(void);
+#define plat_map_dma_mem plat_map_dma_mem
static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
size_t size)
{
@@ -26,6 +27,7 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
return 0;
}
+#define plat_map_dma_mem_page plat_map_dma_mem_page
static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
struct page *page)
{
@@ -33,6 +35,7 @@ static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
return 0;
}
+#define plat_dma_addr_to_phys plat_dma_addr_to_phys
static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
dma_addr_t dma_addr)
{
@@ -40,32 +43,35 @@ static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
return 0;
}
+#define plat_unmap_dma_mem plat_unmap_dma_mem
static inline void plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr,
size_t size, enum dma_data_direction direction)
{
BUG();
}
+#define plat_dma_supported plat_dma_supported
static inline int plat_dma_supported(struct device *dev, u64 mask)
{
BUG();
return 0;
}
+#define plat_device_is_coherent plat_device_is_coherent
static inline int plat_device_is_coherent(struct device *dev)
{
return 1;
}
-static inline void plat_post_dma_flush(struct device *dev)
-{
-}
-
+#define phys_to_dma phys_to_dma
dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr);
+#define dma_to_phys dma_to_phys
phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
struct dma_map_ops;
extern const struct dma_map_ops *octeon_pci_dma_map_ops;
extern char *octeon_swiotlb;
+#include <asm/mach-generic/dma-coherence.h>
+
#endif /* __ASM_MACH_CAVIUM_OCTEON_DMA_COHERENCE_H */
diff --git a/arch/mips/include/asm/mach-ip27/dma-coherence.h b/arch/mips/include/asm/mach-ip27/dma-coherence.h
index 04d862020ac9..996147f8db4c 100644
--- a/arch/mips/include/asm/mach-ip27/dma-coherence.h
+++ b/arch/mips/include/asm/mach-ip27/dma-coherence.h
@@ -18,6 +18,7 @@
struct device;
+#define plat_map_dma_mem plat_map_dma_mem
static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
size_t size)
{
@@ -26,6 +27,7 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
return pa;
}
+#define plat_map_dma_mem_page plat_map_dma_mem_page
static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
struct page *page)
{
@@ -34,37 +36,19 @@ static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
return pa;
}
+#define plat_dma_addr_to_phys plat_dma_addr_to_phys
static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
dma_addr_t dma_addr)
{
return dma_addr & ~(0xffUL << 56);
}
-static inline void plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr,
- size_t size, enum dma_data_direction direction)
-{
-}
-
-static inline int plat_dma_supported(struct device *dev, u64 mask)
-{
- /*
- * we fall back to GFP_DMA when the mask isn't all 1s,
- * so we can't guarantee allocations that must be
- * within a tighter range than GFP_DMA..
- */
- if (mask < DMA_BIT_MASK(24))
- return 0;
-
- return 1;
-}
-
-static inline void plat_post_dma_flush(struct device *dev)
-{
-}
-
+#define plat_device_is_coherent plat_device_is_coherent
static inline int plat_device_is_coherent(struct device *dev)
{
return 1; /* IP27 non-coherent mode is unsupported */
}
+#include <asm/mach-generic/dma-coherence.h>
+
#endif /* __ASM_MACH_IP27_DMA_COHERENCE_H */
diff --git a/arch/mips/include/asm/mach-ip32/dma-coherence.h b/arch/mips/include/asm/mach-ip32/dma-coherence.h
index 7bdf212587a0..23640029d85c 100644
--- a/arch/mips/include/asm/mach-ip32/dma-coherence.h
+++ b/arch/mips/include/asm/mach-ip32/dma-coherence.h
@@ -26,6 +26,7 @@ struct device;
#define RAM_OFFSET_MASK 0x3fffffffUL
+#define plat_map_dma_mem plat_map_dma_mem
static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
size_t size)
{
@@ -37,6 +38,7 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
return pa;
}
+#define plat_map_dma_mem_page plat_map_dma_mem_page
static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
struct page *page)
{
@@ -51,6 +53,7 @@ static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
}
/* This is almost certainly wrong but it's what dma-ip32.c used to use */
+#define plat_dma_addr_to_phys plat_dma_addr_to_phys
static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
dma_addr_t dma_addr)
{
@@ -62,11 +65,7 @@ static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
return addr;
}
-static inline void plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr,
- size_t size, enum dma_data_direction direction)
-{
-}
-
+#define plat_dma_supported plat_dma_supported
static inline int plat_dma_supported(struct device *dev, u64 mask)
{
/*
@@ -80,13 +79,12 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
return 1;
}
-static inline void plat_post_dma_flush(struct device *dev)
-{
-}
-
+#define plat_device_is_coherent plat_device_is_coherent
static inline int plat_device_is_coherent(struct device *dev)
{
return 0; /* IP32 is non-coherent */
}
+#include <asm/mach-generic/dma-coherence.h>
+
#endif /* __ASM_MACH_IP32_DMA_COHERENCE_H */
diff --git a/arch/mips/include/asm/mach-jazz/dma-coherence.h b/arch/mips/include/asm/mach-jazz/dma-coherence.h
index dc347c25c343..83eb573abcca 100644
--- a/arch/mips/include/asm/mach-jazz/dma-coherence.h
+++ b/arch/mips/include/asm/mach-jazz/dma-coherence.h
@@ -12,49 +12,39 @@
struct device;
+#define plat_map_dma_mem plat_map_dma_mem
static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, size_t size)
{
return vdma_alloc(virt_to_phys(addr), size);
}
+#define plat_map_dma_mem_page plat_map_dma_mem_page
static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
struct page *page)
{
return vdma_alloc(page_to_phys(page), PAGE_SIZE);
}
+#define plat_dma_addr_to_phys plat_dma_addr_to_phys
static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
dma_addr_t dma_addr)
{
return vdma_log2phys(dma_addr);
}
+#define plat_unmap_dma_mem plat_unmap_dma_mem
static inline void plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr,
size_t size, enum dma_data_direction direction)
{
vdma_free(dma_addr);
}
-static inline int plat_dma_supported(struct device *dev, u64 mask)
-{
- /*
- * we fall back to GFP_DMA when the mask isn't all 1s,
- * so we can't guarantee allocations that must be
- * within a tighter range than GFP_DMA..
- */
- if (mask < DMA_BIT_MASK(24))
- return 0;
-
- return 1;
-}
-
-static inline void plat_post_dma_flush(struct device *dev)
-{
-}
-
+#define plat_device_is_coherent plat_device_is_coherent
static inline int plat_device_is_coherent(struct device *dev)
{
return 0;
}
+#include <asm/mach-generic/dma-coherence.h>
+
#endif /* __ASM_MACH_JAZZ_DMA_COHERENCE_H */
diff --git a/arch/mips/include/asm/mach-loongson64/dma-coherence.h b/arch/mips/include/asm/mach-loongson64/dma-coherence.h
index 1602a9e9e8c2..0a9bbc4c1449 100644
--- a/arch/mips/include/asm/mach-loongson64/dma-coherence.h
+++ b/arch/mips/include/asm/mach-loongson64/dma-coherence.h
@@ -17,8 +17,11 @@
struct device;
+#define phys_to_dma phys_to_dma
extern dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr);
+#define dma_to_phys dma_to_phys
extern phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
+#define plat_map_dma_mem plat_map_dma_mem
static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
size_t size)
{
@@ -29,6 +32,7 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
#endif
}
+#define plat_map_dma_mem_page plat_map_dma_mem_page
static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
struct page *page)
{
@@ -39,6 +43,7 @@ static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
#endif
}
+#define plat_dma_addr_to_phys plat_dma_addr_to_phys
static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
dma_addr_t dma_addr)
{
@@ -51,11 +56,7 @@ static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
#endif
}
-static inline void plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr,
- size_t size, enum dma_data_direction direction)
-{
-}
-
+#define plat_dma_supported plat_dma_supported
static inline int plat_dma_supported(struct device *dev, u64 mask)
{
/*
@@ -69,6 +70,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
return 1;
}
+#define plat_device_is_coherent plat_device_is_coherent
static inline int plat_device_is_coherent(struct device *dev)
{
#ifdef CONFIG_DMA_NONCOHERENT
@@ -78,8 +80,6 @@ static inline int plat_device_is_coherent(struct device *dev)
#endif /* CONFIG_DMA_NONCOHERENT */
}
-static inline void plat_post_dma_flush(struct device *dev)
-{
-}
+#include <asm/mach-generic/dma-coherence.h>
#endif /* __ASM_MACH_LOONGSON64_DMA_COHERENCE_H */
--
2.7.4
On 01/23/2018 07:40 PM, Florian Fainelli wrote:
[...]
>
> Florian Fainelli (2):
> MIPS: Allow including mach-generic/dma-coherence.h
> MIPS: Update dma-coherence.h files
>
I have tested these on our Octeon III platforms with PCIe and saw
no issues. Thanks.
Steve
Tested-by: Steven J. Hill <[email protected]>
On 01/26/2018 12:31 AM, Steven J. Hill wrote:
> On 01/23/2018 07:40 PM, Florian Fainelli wrote:
>
> [...]
>
>>
>> Florian Fainelli (2):
>> MIPS: Allow including mach-generic/dma-coherence.h
>> MIPS: Update dma-coherence.h files
>>
> I have tested these on our Octeon III platforms with PCIe and saw
> no issues. Thanks.
>
> Steve
>
>
> Tested-by: Steven J. Hill <[email protected]>
Thanks for testing Steven!
--
Florian
On Tue, Jan 23, 2018 at 05:40:10PM -0800, Florian Fainelli wrote:
> diff --git a/arch/mips/include/asm/mach-ath25/dma-coherence.h b/arch/mips/include/asm/mach-ath25/dma-coherence.h
> index d5defdde32db..63bce15fa54d 100644
> --- a/arch/mips/include/asm/mach-ath25/dma-coherence.h
> +++ b/arch/mips/include/asm/mach-ath25/dma-coherence.h
> +#define plat_unmap_dma_mem plat_unmap_dma_mem
> static inline void
> plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr, size_t size,
> enum dma_data_direction direction)
> {
> }
This could presumably be removed too.
> diff --git a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
> index 9110988b92a1..165e13aba3ff 100644
> --- a/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
> +++ b/arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h
> +#define phys_to_dma phys_to_dma
> dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr);
> +#define dma_to_phys dma_to_phys
> phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
I suppose these #defines can be dropped since commit ea8c64ace866
("dma-mapping: move swiotlb arch helpers to a new header").
> diff --git a/arch/mips/include/asm/mach-loongson64/dma-coherence.h b/arch/mips/include/asm/mach-loongson64/dma-coherence.h
> index 1602a9e9e8c2..0a9bbc4c1449 100644
> --- a/arch/mips/include/asm/mach-loongson64/dma-coherence.h
> +++ b/arch/mips/include/asm/mach-loongson64/dma-coherence.h
> +#define phys_to_dma phys_to_dma
> extern dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr);
> +#define dma_to_phys dma_to_phys
> extern phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
same here
> +#define plat_dma_supported plat_dma_supported
> static inline int plat_dma_supported(struct device *dev, u64 mask)
> {
> /*
> @@ -69,6 +70,7 @@ static inline int plat_dma_supported(struct device *dev, u64 mask)
> return 1;
> }
That can be removed too, no?
Cheers
James
On Tue, Jan 23, 2018 at 05:40:09PM -0800, Florian Fainelli wrote:
> @@ -71,15 +83,19 @@ static inline void plat_post_dma_flush(struct device *dev)
> #endif
>
> #ifdef CONFIG_SWIOTLB
> +#ifndef phys_to_dma
> static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
> {
> return paddr;
> }
> +#endif
>
> +#ifndef dma_to_phys
> static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
> {
> return daddr;
> }
> #endif
> +#endif /* CONFIG_SWIOTLB */
FYI these were removed in commit ea8c64ace866 ("dma-mapping: move
swiotlb arch helpers to a new header"), and are only implemented by
platforms which select ARCH_HAS_PHYS_TO_DMA.
Cheers
James