summaryrefslogtreecommitdiff
path: root/include/linux/dma-iommu.h
blob: b5e4f60f1086ba4d2bc8dc8de4106ebf849dbea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) 2014 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 __DMA_IOMMU_H
#define __DMA_IOMMU_H

#ifdef __KERNEL__

#include <linux/types.h>
#include <linux/iommu.h>

#ifdef CONFIG_IOMMU_DMA

int iommu_dma_init(void);


struct iommu_dma_domain *iommu_dma_create_domain(struct bus_type *bus,
		dma_addr_t base, size_t size);
void iommu_dma_release_domain(struct iommu_dma_domain *dma_domain);

struct iommu_domain *iommu_dma_raw_domain(struct iommu_dma_domain *dma_domain);

int iommu_dma_attach_device(struct device *dev, struct iommu_dma_domain *domain);
void iommu_dma_detach_device(struct device *dev);

/*
 * Implementation of these is left to arch code - it can associate domains
 * with devices however it likes, provided the lookup is efficient.
 */
struct iommu_dma_domain *get_dma_domain(struct device *dev);
void set_dma_domain(struct device *dev, struct iommu_dma_domain *dma_domain);


dma_addr_t iommu_dma_create_iova_mapping(struct device *dev,
		struct page **pages, size_t size, bool coherent);
int iommu_dma_release_iova_mapping(struct device *dev, dma_addr_t iova,
		size_t size);

struct page **iommu_dma_alloc_buffer(struct device *dev, size_t size,
		gfp_t gfp, struct dma_attrs *attrs,
		void (clear_buffer)(struct page *page, size_t size));
int iommu_dma_free_buffer(struct device *dev, struct page **pages, size_t size,
		struct dma_attrs *attrs);

dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
		unsigned long offset, size_t size, enum dma_data_direction dir,
		struct dma_attrs *attrs);
dma_addr_t iommu_dma_coherent_map_page(struct device *dev, struct page *page,
		unsigned long offset, size_t size, enum dma_data_direction dir,
		struct dma_attrs *attrs);
void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
		enum dma_data_direction dir, struct dma_attrs *attrs);

int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
		enum dma_data_direction dir, struct dma_attrs *attrs);
int iommu_dma_coherent_map_sg(struct device *dev, struct scatterlist *sg,
		int nents, enum dma_data_direction dir,
		struct dma_attrs *attrs);
void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sgl, int nents,
		enum dma_data_direction dir, struct dma_attrs *attrs);

int iommu_dma_init_reserved(struct device *dev, struct iommu_dma_domain *dma_domain);
int iommu_dma_supported(struct device *dev, u64 mask);
int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);

#else

static inline int iommu_dma_init(void)
{
	return 0;
}

static inline struct iommu_dma_domain *get_dma_domain(struct device *dev)
{
	return NULL;
}

static inline void set_dma_domain(struct device *dev,
		struct iommu_dma_domain *dma_domain)
{ }

#endif  /* CONFIG_IOMMU_DMA */

#endif	/* __KERNEL__ */
#endif	/* __DMA_IOMMU_H */