2018-04-16 13:24:51 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _LINUX_DMA_NONCOHERENT_H
|
|
|
|
#define _LINUX_DMA_NONCOHERENT_H 1
|
|
|
|
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
|
2018-08-19 12:53:20 +00:00
|
|
|
#ifdef CONFIG_ARCH_HAS_DMA_COHERENCE_H
|
|
|
|
#include <asm/dma-coherence.h>
|
|
|
|
#elif defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \
|
|
|
|
defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \
|
|
|
|
defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL)
|
|
|
|
static inline bool dev_is_dma_coherent(struct device *dev)
|
|
|
|
{
|
|
|
|
return dev->dma_coherent;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline bool dev_is_dma_coherent(struct device *dev)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ARCH_HAS_DMA_COHERENCE_H */
|
|
|
|
|
2019-06-14 14:06:10 +00:00
|
|
|
/*
|
|
|
|
* Check if an allocation needs to be marked uncached to be coherent.
|
|
|
|
*/
|
2019-07-08 19:55:27 +00:00
|
|
|
static __always_inline bool dma_alloc_need_uncached(struct device *dev,
|
2019-06-14 14:06:10 +00:00
|
|
|
unsigned long attrs)
|
|
|
|
{
|
|
|
|
if (dev_is_dma_coherent(dev))
|
|
|
|
return false;
|
2019-06-14 14:17:27 +00:00
|
|
|
if (attrs & DMA_ATTR_NO_KERNEL_MAPPING)
|
|
|
|
return false;
|
2019-06-14 14:06:10 +00:00
|
|
|
if (IS_ENABLED(CONFIG_DMA_NONCOHERENT_CACHE_SYNC) &&
|
|
|
|
(attrs & DMA_ATTR_NON_CONSISTENT))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-16 13:24:51 +00:00
|
|
|
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
|
|
|
|
gfp_t gfp, unsigned long attrs);
|
|
|
|
void arch_dma_free(struct device *dev, size_t size, void *cpu_addr,
|
|
|
|
dma_addr_t dma_addr, unsigned long attrs);
|
2018-09-11 06:55:28 +00:00
|
|
|
long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr,
|
|
|
|
dma_addr_t dma_addr);
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_HAS_DMA_MMAP_PGPROT
|
|
|
|
pgprot_t arch_dma_mmap_pgprot(struct device *dev, pgprot_t prot,
|
2018-04-16 13:24:51 +00:00
|
|
|
unsigned long attrs);
|
2018-09-11 06:55:28 +00:00
|
|
|
#else
|
|
|
|
# define arch_dma_mmap_pgprot(dev, prot, attrs) pgprot_noncached(prot)
|
|
|
|
#endif
|
2018-04-16 13:24:51 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DMA_NONCOHERENT_CACHE_SYNC
|
|
|
|
void arch_dma_cache_sync(struct device *dev, void *vaddr, size_t size,
|
|
|
|
enum dma_data_direction direction);
|
|
|
|
#else
|
2018-12-06 21:39:32 +00:00
|
|
|
static inline void arch_dma_cache_sync(struct device *dev, void *vaddr,
|
|
|
|
size_t size, enum dma_data_direction direction)
|
|
|
|
{
|
|
|
|
}
|
2018-04-16 13:24:51 +00:00
|
|
|
#endif /* CONFIG_DMA_NONCOHERENT_CACHE_SYNC */
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE
|
|
|
|
void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
|
|
|
|
size_t size, enum dma_data_direction dir);
|
|
|
|
#else
|
|
|
|
static inline void arch_sync_dma_for_device(struct device *dev,
|
|
|
|
phys_addr_t paddr, size_t size, enum dma_data_direction dir)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* ARCH_HAS_SYNC_DMA_FOR_DEVICE */
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU
|
|
|
|
void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
|
|
|
|
size_t size, enum dma_data_direction dir);
|
|
|
|
#else
|
|
|
|
static inline void arch_sync_dma_for_cpu(struct device *dev,
|
|
|
|
phys_addr_t paddr, size_t size, enum dma_data_direction dir)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* ARCH_HAS_SYNC_DMA_FOR_CPU */
|
|
|
|
|
2018-06-15 11:08:51 +00:00
|
|
|
#ifdef CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL
|
|
|
|
void arch_sync_dma_for_cpu_all(struct device *dev);
|
|
|
|
#else
|
|
|
|
static inline void arch_sync_dma_for_cpu_all(struct device *dev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL */
|
|
|
|
|
2019-03-25 14:44:06 +00:00
|
|
|
#ifdef CONFIG_ARCH_HAS_DMA_PREP_COHERENT
|
2018-11-04 19:29:28 +00:00
|
|
|
void arch_dma_prep_coherent(struct page *page, size_t size);
|
2019-03-25 14:44:06 +00:00
|
|
|
#else
|
|
|
|
static inline void arch_dma_prep_coherent(struct page *page, size_t size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ARCH_HAS_DMA_PREP_COHERENT */
|
2018-11-04 19:29:28 +00:00
|
|
|
|
2019-06-03 06:43:51 +00:00
|
|
|
void *uncached_kernel_address(void *addr);
|
|
|
|
void *cached_kernel_address(void *addr);
|
|
|
|
|
2018-04-16 13:24:51 +00:00
|
|
|
#endif /* _LINUX_DMA_NONCOHERENT_H */
|