2012-03-05 11:49:30 +00:00
/*
* Copyright ( C ) 2012 ARM Ltd .
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef __ASM_DMA_MAPPING_H
# define __ASM_DMA_MAPPING_H
# ifdef __KERNEL__
# include <linux/types.h>
# include <linux/vmalloc.h>
2013-10-18 16:01:32 +00:00
# include <xen/xen.h>
# include <asm/xen/hypervisor.h>
2013-10-15 15:49:03 +00:00
# define DMA_ERROR_CODE (~(dma_addr_t)0)
2015-06-10 11:08:53 -05:00
extern struct dma_map_ops dummy_dma_ops ;
2012-03-05 11:49:30 +00:00
2013-10-18 16:01:32 +00:00
static inline struct dma_map_ops * __generic_dma_ops ( struct device * dev )
2012-03-05 11:49:30 +00:00
{
2015-11-16 17:25:48 +01:00
if ( dev & & dev - > archdata . dma_ops )
2012-03-05 11:49:30 +00:00
return dev - > archdata . dma_ops ;
2015-06-10 11:08:53 -05:00
/*
2015-11-16 17:25:48 +01:00
* We expect no ISA devices , and all other DMA masters are expected to
* have someone call arch_setup_dma_ops at device creation time .
2015-06-10 11:08:53 -05:00
*/
return & dummy_dma_ops ;
2012-03-05 11:49:30 +00:00
}
2013-10-18 16:01:32 +00:00
static inline struct dma_map_ops * get_dma_ops ( struct device * dev )
{
if ( xen_initial_domain ( ) )
return xen_dma_ops ;
else
return __generic_dma_ops ( dev ) ;
}
2015-10-01 20:14:00 +01:00
void arch_setup_dma_ops ( struct device * dev , u64 dma_base , u64 size ,
struct iommu_ops * iommu , bool coherent ) ;
2014-12-18 17:13:49 +00:00
# define arch_setup_dma_ops arch_setup_dma_ops
2014-09-22 11:48:31 +01:00
2015-10-01 20:14:00 +01:00
# ifdef CONFIG_IOMMU_DMA
void arch_teardown_dma_ops ( struct device * dev ) ;
# define arch_teardown_dma_ops arch_teardown_dma_ops
# endif
2014-11-20 10:41:35 +00:00
/* do not use this function in a driver */
static inline bool is_device_dma_coherent ( struct device * dev )
{
2015-01-12 20:48:53 +00:00
if ( ! dev )
return false ;
2014-11-20 10:41:35 +00:00
return dev - > archdata . dma_coherent ;
}
2012-03-05 11:49:30 +00:00
static inline dma_addr_t phys_to_dma ( struct device * dev , phys_addr_t paddr )
{
return ( dma_addr_t ) paddr ;
}
static inline phys_addr_t dma_to_phys ( struct device * dev , dma_addr_t dev_addr )
{
return ( phys_addr_t ) dev_addr ;
}
static inline bool dma_capable ( struct device * dev , dma_addr_t addr , size_t size )
{
if ( ! dev - > dma_mask )
2015-03-31 00:46:00 +01:00
return false ;
2012-03-05 11:49:30 +00:00
return addr + size - 1 < = * dev - > dma_mask ;
}
static inline void dma_mark_clean ( void * addr , size_t size )
{
}
# endif /* __KERNEL__ */
# endif /* __ASM_DMA_MAPPING_H */