2 * Copyright (C) 2014-2015 ARM Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <asm/errno.h>
22 #ifdef CONFIG_IOMMU_DMA
23 #include <linux/iommu.h>
25 int iommu_dma_init(void);
27 /* Domain management interface for IOMMU drivers */
28 int iommu_get_dma_cookie(struct iommu_domain
*domain
);
29 void iommu_put_dma_cookie(struct iommu_domain
*domain
);
31 /* Setup call for arch DMA mapping code */
32 int iommu_dma_init_domain(struct iommu_domain
*domain
, dma_addr_t base
, u64 size
);
34 /* General helpers for DMA-API <-> IOMMU-API interaction */
35 int dma_direction_to_prot(enum dma_data_direction dir
, bool coherent
);
38 * These implement the bulk of the relevant DMA mapping callbacks, but require
39 * the arch code to take care of attributes and cache maintenance
41 struct page
**iommu_dma_alloc(struct device
*dev
, size_t size
,
42 gfp_t gfp
, int prot
, dma_addr_t
*handle
,
43 void (*flush_page
)(struct device
*, const void *, phys_addr_t
));
44 void iommu_dma_free(struct device
*dev
, struct page
**pages
, size_t size
,
47 int iommu_dma_mmap(struct page
**pages
, size_t size
, struct vm_area_struct
*vma
);
49 dma_addr_t
iommu_dma_map_page(struct device
*dev
, struct page
*page
,
50 unsigned long offset
, size_t size
, int prot
);
51 int iommu_dma_map_sg(struct device
*dev
, struct scatterlist
*sg
,
55 * Arch code with no special attribute handling may use these
56 * directly as DMA mapping callbacks for simplicity
58 void iommu_dma_unmap_page(struct device
*dev
, dma_addr_t handle
, size_t size
,
59 enum dma_data_direction dir
, struct dma_attrs
*attrs
);
60 void iommu_dma_unmap_sg(struct device
*dev
, struct scatterlist
*sg
, int nents
,
61 enum dma_data_direction dir
, struct dma_attrs
*attrs
);
62 int iommu_dma_supported(struct device
*dev
, u64 mask
);
63 int iommu_dma_mapping_error(struct device
*dev
, dma_addr_t dma_addr
);
69 static inline int iommu_dma_init(void)
74 static inline int iommu_get_dma_cookie(struct iommu_domain
*domain
)
79 static inline void iommu_put_dma_cookie(struct iommu_domain
*domain
)
83 #endif /* CONFIG_IOMMU_DMA */
84 #endif /* __KERNEL__ */
85 #endif /* __DMA_IOMMU_H */