1a8c21a54SThe etnaviv authors /*
2a8c21a54SThe etnaviv authors  * Copyright (C) 2015 Etnaviv Project
3a8c21a54SThe etnaviv authors  *
4a8c21a54SThe etnaviv authors  * This program is free software; you can redistribute it and/or modify it
5a8c21a54SThe etnaviv authors  * under the terms of the GNU General Public License version 2 as published by
6a8c21a54SThe etnaviv authors  * the Free Software Foundation.
7a8c21a54SThe etnaviv authors  *
8a8c21a54SThe etnaviv authors  * This program is distributed in the hope that it will be useful, but WITHOUT
9a8c21a54SThe etnaviv authors  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10a8c21a54SThe etnaviv authors  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11a8c21a54SThe etnaviv authors  * more details.
12a8c21a54SThe etnaviv authors  *
13a8c21a54SThe etnaviv authors  * You should have received a copy of the GNU General Public License along with
14a8c21a54SThe etnaviv authors  * this program.  If not, see <http://www.gnu.org/licenses/>.
15a8c21a54SThe etnaviv authors  */
16a8c21a54SThe etnaviv authors 
17a8c21a54SThe etnaviv authors #ifndef __ETNAVIV_MMU_H__
18a8c21a54SThe etnaviv authors #define __ETNAVIV_MMU_H__
19a8c21a54SThe etnaviv authors 
20a8c21a54SThe etnaviv authors #include <linux/iommu.h>
21a8c21a54SThe etnaviv authors 
22a8c21a54SThe etnaviv authors enum etnaviv_iommu_version {
23a8c21a54SThe etnaviv authors 	ETNAVIV_IOMMU_V1 = 0,
24a8c21a54SThe etnaviv authors 	ETNAVIV_IOMMU_V2,
25a8c21a54SThe etnaviv authors };
26a8c21a54SThe etnaviv authors 
27a8c21a54SThe etnaviv authors struct etnaviv_gpu;
28a8c21a54SThe etnaviv authors struct etnaviv_vram_mapping;
29a8c21a54SThe etnaviv authors 
30a8c21a54SThe etnaviv authors struct etnaviv_iommu_ops {
31a8c21a54SThe etnaviv authors 	struct iommu_ops ops;
32a8c21a54SThe etnaviv authors 	size_t (*dump_size)(struct iommu_domain *);
33a8c21a54SThe etnaviv authors 	void (*dump)(struct iommu_domain *, void *);
34a8c21a54SThe etnaviv authors };
35a8c21a54SThe etnaviv authors 
36a8c21a54SThe etnaviv authors struct etnaviv_iommu {
37a8c21a54SThe etnaviv authors 	struct etnaviv_gpu *gpu;
38a8c21a54SThe etnaviv authors 	struct iommu_domain *domain;
39a8c21a54SThe etnaviv authors 
40a8c21a54SThe etnaviv authors 	enum etnaviv_iommu_version version;
41a8c21a54SThe etnaviv authors 
42a8c21a54SThe etnaviv authors 	/* memory manager for GPU address area */
43a8c21a54SThe etnaviv authors 	struct mutex lock;
44a8c21a54SThe etnaviv authors 	struct list_head mappings;
45a8c21a54SThe etnaviv authors 	struct drm_mm mm;
46a8c21a54SThe etnaviv authors 	u32 last_iova;
47a8c21a54SThe etnaviv authors 	bool need_flush;
48a8c21a54SThe etnaviv authors };
49a8c21a54SThe etnaviv authors 
50a8c21a54SThe etnaviv authors struct etnaviv_gem_object;
51a8c21a54SThe etnaviv authors 
52a8c21a54SThe etnaviv authors int etnaviv_iommu_attach(struct etnaviv_iommu *iommu, const char **names,
53a8c21a54SThe etnaviv authors 	int cnt);
54a8c21a54SThe etnaviv authors int etnaviv_iommu_map(struct etnaviv_iommu *iommu, u32 iova,
55a8c21a54SThe etnaviv authors 	struct sg_table *sgt, unsigned len, int prot);
56a8c21a54SThe etnaviv authors int etnaviv_iommu_unmap(struct etnaviv_iommu *iommu, u32 iova,
57a8c21a54SThe etnaviv authors 	struct sg_table *sgt, unsigned len);
58a8c21a54SThe etnaviv authors int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu,
59a8c21a54SThe etnaviv authors 	struct etnaviv_gem_object *etnaviv_obj, u32 memory_base,
60a8c21a54SThe etnaviv authors 	struct etnaviv_vram_mapping *mapping);
61a8c21a54SThe etnaviv authors void etnaviv_iommu_unmap_gem(struct etnaviv_iommu *mmu,
62a8c21a54SThe etnaviv authors 	struct etnaviv_vram_mapping *mapping);
63a8c21a54SThe etnaviv authors void etnaviv_iommu_destroy(struct etnaviv_iommu *iommu);
64a8c21a54SThe etnaviv authors 
65a8c21a54SThe etnaviv authors size_t etnaviv_iommu_dump_size(struct etnaviv_iommu *iommu);
66a8c21a54SThe etnaviv authors void etnaviv_iommu_dump(struct etnaviv_iommu *iommu, void *buf);
67a8c21a54SThe etnaviv authors 
68a8c21a54SThe etnaviv authors struct etnaviv_iommu *etnaviv_iommu_new(struct etnaviv_gpu *gpu,
69a8c21a54SThe etnaviv authors 	struct iommu_domain *domain, enum etnaviv_iommu_version version);
70a8c21a54SThe etnaviv authors 
71a8c21a54SThe etnaviv authors #endif /* __ETNAVIV_MMU_H__ */
72