blob: 7f7e9a7e3839966cfcb19c49995213188ca1e2b3 [file] [log] [blame]
Robin Murphy0db2e5d2015-10-01 20:13:58 +01001/*
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>
Robin Murphy44bb7e22016-09-12 17:13:59 +010024#include <linux/msi.h>
Robin Murphy0db2e5d2015-10-01 20:13:58 +010025
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 */
Robin Murphyfade1ec2016-09-12 17:14:00 +010033int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
34 u64 size, struct device *dev);
Robin Murphy0db2e5d2015-10-01 20:13:58 +010035
36/* General helpers for DMA-API <-> IOMMU-API interaction */
37int dma_direction_to_prot(enum dma_data_direction dir, bool coherent);
38
39/*
40 * These implement the bulk of the relevant DMA mapping callbacks, but require
41 * the arch code to take care of attributes and cache maintenance
42 */
Robin Murphy3b6b7e12016-04-13 17:29:10 +010043struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -070044 unsigned long attrs, int prot, dma_addr_t *handle,
Robin Murphy0db2e5d2015-10-01 20:13:58 +010045 void (*flush_page)(struct device *, const void *, phys_addr_t));
46void iommu_dma_free(struct device *dev, struct page **pages, size_t size,
47 dma_addr_t *handle);
48
49int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma);
50
51dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
52 unsigned long offset, size_t size, int prot);
53int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
54 int nents, int prot);
55
56/*
57 * Arch code with no special attribute handling may use these
58 * directly as DMA mapping callbacks for simplicity
59 */
60void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -070061 enum dma_data_direction dir, unsigned long attrs);
Robin Murphy0db2e5d2015-10-01 20:13:58 +010062void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
Krzysztof Kozlowski00085f12016-08-03 13:46:00 -070063 enum dma_data_direction dir, unsigned long attrs);
Robin Murphyc84ed862016-11-14 12:16:26 +000064dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
65 size_t size, enum dma_data_direction dir, unsigned long attrs);
66void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
67 size_t size, enum dma_data_direction dir, unsigned long attrs);
Robin Murphy0db2e5d2015-10-01 20:13:58 +010068int iommu_dma_supported(struct device *dev, u64 mask);
69int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
70
Robin Murphy44bb7e22016-09-12 17:13:59 +010071/* The DMA API isn't _quite_ the whole story, though... */
72void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg);
73
Robin Murphy0db2e5d2015-10-01 20:13:58 +010074#else
75
76struct iommu_domain;
Robin Murphy44bb7e22016-09-12 17:13:59 +010077struct msi_msg;
Robin Murphy0db2e5d2015-10-01 20:13:58 +010078
79static inline int iommu_dma_init(void)
80{
81 return 0;
82}
83
84static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
85{
86 return -ENODEV;
87}
88
89static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
90{
91}
92
Robin Murphy44bb7e22016-09-12 17:13:59 +010093static inline void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg)
94{
95}
96
Robin Murphy0db2e5d2015-10-01 20:13:58 +010097#endif /* CONFIG_IOMMU_DMA */
98#endif /* __KERNEL__ */
99#endif /* __DMA_IOMMU_H */