1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2015-2018 Etnaviv Project 4 */ 5 6 #ifndef __ETNAVIV_MMU_H__ 7 #define __ETNAVIV_MMU_H__ 8 9 #define ETNAVIV_PROT_READ (1 << 0) 10 #define ETNAVIV_PROT_WRITE (1 << 1) 11 12 enum etnaviv_iommu_version { 13 ETNAVIV_IOMMU_V1 = 0, 14 ETNAVIV_IOMMU_V2, 15 }; 16 17 struct etnaviv_gpu; 18 struct etnaviv_vram_mapping; 19 struct etnaviv_iommu_domain; 20 21 struct etnaviv_iommu_domain_ops { 22 void (*free)(struct etnaviv_iommu_domain *); 23 int (*map)(struct etnaviv_iommu_domain *domain, unsigned long iova, 24 phys_addr_t paddr, size_t size, int prot); 25 size_t (*unmap)(struct etnaviv_iommu_domain *domain, unsigned long iova, 26 size_t size); 27 size_t (*dump_size)(struct etnaviv_iommu_domain *); 28 void (*dump)(struct etnaviv_iommu_domain *, void *); 29 }; 30 31 struct etnaviv_iommu_domain { 32 struct device *dev; 33 void *bad_page_cpu; 34 dma_addr_t bad_page_dma; 35 u64 base; 36 u64 size; 37 38 const struct etnaviv_iommu_domain_ops *ops; 39 }; 40 41 struct etnaviv_iommu { 42 struct etnaviv_gpu *gpu; 43 struct etnaviv_iommu_domain *domain; 44 45 enum etnaviv_iommu_version version; 46 47 /* memory manager for GPU address area */ 48 struct mutex lock; 49 struct list_head mappings; 50 struct drm_mm mm; 51 bool need_flush; 52 }; 53 54 struct etnaviv_gem_object; 55 56 int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu, 57 struct etnaviv_gem_object *etnaviv_obj, u32 memory_base, 58 struct etnaviv_vram_mapping *mapping); 59 void etnaviv_iommu_unmap_gem(struct etnaviv_iommu *mmu, 60 struct etnaviv_vram_mapping *mapping); 61 62 int etnaviv_iommu_get_suballoc_va(struct etnaviv_gpu *gpu, dma_addr_t paddr, 63 struct drm_mm_node *vram_node, size_t size, 64 u32 *iova); 65 void etnaviv_iommu_put_suballoc_va(struct etnaviv_gpu *gpu, 66 struct drm_mm_node *vram_node, size_t size, 67 u32 iova); 68 69 size_t etnaviv_iommu_dump_size(struct etnaviv_iommu *iommu); 70 void etnaviv_iommu_dump(struct etnaviv_iommu *iommu, void *buf); 71 72 struct etnaviv_iommu *etnaviv_iommu_new(struct etnaviv_gpu *gpu); 73 void etnaviv_iommu_destroy(struct etnaviv_iommu *iommu); 74 void etnaviv_iommu_restore(struct etnaviv_gpu *gpu); 75 76 #endif /* __ETNAVIV_MMU_H__ */ 77