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