Merge tag 'drm-misc-next-2019-04-10' of git://anongit.freedesktop.org/drm/drm-misc...
[linux-block.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__
8a22a3e1 20#include <linux/types.h>
0db2e5d1
RM
21#include <asm/errno.h>
22
23#ifdef CONFIG_IOMMU_DMA
461a6946 24#include <linux/dma-mapping.h>
0db2e5d1 25#include <linux/iommu.h>
44bb7e24 26#include <linux/msi.h>
0db2e5d1
RM
27
28int iommu_dma_init(void);
29
30/* Domain management interface for IOMMU drivers */
31int iommu_get_dma_cookie(struct iommu_domain *domain);
fdbe574e 32int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
0db2e5d1
RM
33void iommu_put_dma_cookie(struct iommu_domain *domain);
34
35/* Setup call for arch DMA mapping code */
fade1ec0
RM
36int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
37 u64 size, struct device *dev);
0db2e5d1
RM
38
39/* General helpers for DMA-API <-> IOMMU-API interaction */
737c85ca
MH
40int dma_info_to_prot(enum dma_data_direction dir, bool coherent,
41 unsigned long attrs);
0db2e5d1
RM
42
43/*
44 * These implement the bulk of the relevant DMA mapping callbacks, but require
45 * the arch code to take care of attributes and cache maintenance
46 */
3b6b7e19 47struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp,
00085f1e 48 unsigned long attrs, int prot, dma_addr_t *handle,
0db2e5d1
RM
49 void (*flush_page)(struct device *, const void *, phys_addr_t));
50void iommu_dma_free(struct device *dev, struct page **pages, size_t size,
51 dma_addr_t *handle);
52
53int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
54
55dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
56 unsigned long offset, size_t size, int prot);
57int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
58 int nents, int prot);
59
60/*
61 * Arch code with no special attribute handling may use these
62 * directly as DMA mapping callbacks for simplicity
63 */
64void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
00085f1e 65 enum dma_data_direction dir, unsigned long attrs);
0db2e5d1 66void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
00085f1e 67 enum dma_data_direction dir, unsigned long attrs);
51f8cc9e
RM
68dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
69 size_t size, enum dma_data_direction dir, unsigned long attrs);
70void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
71 size_t size, enum dma_data_direction dir, unsigned long attrs);
0db2e5d1 72
44bb7e24
RM
73/* The DMA API isn't _quite_ the whole story, though... */
74void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg);
273df963 75void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
44bb7e24 76
0db2e5d1
RM
77#else
78
79struct iommu_domain;
44bb7e24 80struct msi_msg;
4b1c8898 81struct device;
0db2e5d1
RM
82
83static inline int iommu_dma_init(void)
84{
85 return 0;
86}
87
88static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
89{
90 return -ENODEV;
91}
92
fdbe574e
RM
93static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
94{
95 return -ENODEV;
96}
97
0db2e5d1
RM
98static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
99{
100}
101
44bb7e24
RM
102static inline void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg)
103{
104}
105
273df963
RM
106static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list)
107{
108}
109
0db2e5d1
RM
110#endif /* CONFIG_IOMMU_DMA */
111#endif /* __KERNEL__ */
112#endif /* __DMA_IOMMU_H */