]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/dma-iommu.h
iommu/dma: Add support for mapping MSIs
[mirror_ubuntu-zesty-kernel.git] / include / linux / dma-iommu.h
CommitLineData
0db2e5d1
RM
1/*
2 * Copyright (C) 2014-2015 ARM Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16#ifndef __DMA_IOMMU_H
17#define __DMA_IOMMU_H
18
19#ifdef __KERNEL__
20#include <asm/errno.h>
21
22#ifdef CONFIG_IOMMU_DMA
23#include <linux/iommu.h>
44bb7e24 24#include <linux/msi.h>
0db2e5d1
RM
25
26int iommu_dma_init(void);
27
28/* Domain management interface for IOMMU drivers */
29int iommu_get_dma_cookie(struct iommu_domain *domain);
30void iommu_put_dma_cookie(struct iommu_domain *domain);
31
32/* Setup call for arch DMA mapping code */
33int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base, u64 size);
34
35/* General helpers for DMA-API <-> IOMMU-API interaction */
36int dma_direction_to_prot(enum dma_data_direction dir, bool coherent);
37
38/*
39 * These implement the bulk of the relevant DMA mapping callbacks, but require
40 * the arch code to take care of attributes and cache maintenance
41 */
3b6b7e19 42struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp,
00085f1e 43 unsigned long attrs, int prot, dma_addr_t *handle,
0db2e5d1
RM
44 void (*flush_page)(struct device *, const void *, phys_addr_t));
45void iommu_dma_free(struct device *dev, struct page **pages, size_t size,
46 dma_addr_t *handle);
47
48int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
49
50dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
51 unsigned long offset, size_t size, int prot);
52int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
53 int nents, int prot);
54
55/*
56 * Arch code with no special attribute handling may use these
57 * directly as DMA mapping callbacks for simplicity
58 */
59void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
00085f1e 60 enum dma_data_direction dir, unsigned long attrs);
0db2e5d1 61void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
00085f1e 62 enum dma_data_direction dir, unsigned long attrs);
0db2e5d1
RM
63int iommu_dma_supported(struct device *dev, u64 mask);
64int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
65
44bb7e24
RM
66/* The DMA API isn't _quite_ the whole story, though... */
67void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg);
68
0db2e5d1
RM
69#else
70
71struct iommu_domain;
44bb7e24 72struct msi_msg;
0db2e5d1
RM
73
74static inline int iommu_dma_init(void)
75{
76 return 0;
77}
78
79static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
80{
81 return -ENODEV;
82}
83
84static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
85{
86}
87
44bb7e24
RM
88static inline void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg)
89{
90}
91
0db2e5d1
RM
92#endif /* CONFIG_IOMMU_DMA */
93#endif /* __KERNEL__ */
94#endif /* __DMA_IOMMU_H */