1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __NVKM_MMU_H__ 3 #define __NVKM_MMU_H__ 4 #include <core/subdev.h> 5 #include <core/mm.h> 6 struct nvkm_device; 7 struct nvkm_mem; 8 9 struct nvkm_vm_pgt { 10 struct nvkm_memory *mem[2]; 11 u32 refcount[2]; 12 }; 13 14 struct nvkm_vm_pgd { 15 struct list_head head; 16 struct nvkm_gpuobj *obj; 17 }; 18 19 struct nvkm_vma { 20 struct list_head head; 21 int refcount; 22 struct nvkm_vm *vm; 23 struct nvkm_mm_node *node; 24 u64 offset; 25 u32 access; 26 }; 27 28 struct nvkm_vm { 29 struct nvkm_mmu *mmu; 30 31 struct mutex mutex; 32 struct nvkm_mm mm; 33 struct kref refcount; 34 35 struct list_head pgd_list; 36 atomic_t engref[NVKM_SUBDEV_NR]; 37 38 struct nvkm_vm_pgt *pgt; 39 u32 fpde; 40 u32 lpde; 41 }; 42 43 int nvkm_vm_new(struct nvkm_device *, u64 offset, u64 length, u64 mm_offset, 44 struct lock_class_key *, struct nvkm_vm **); 45 int nvkm_vm_ref(struct nvkm_vm *, struct nvkm_vm **, struct nvkm_gpuobj *pgd); 46 int nvkm_vm_boot(struct nvkm_vm *, u64 size); 47 int nvkm_vm_get(struct nvkm_vm *, u64 size, u32 page_shift, u32 access, 48 struct nvkm_vma *); 49 void nvkm_vm_put(struct nvkm_vma *); 50 void nvkm_vm_map(struct nvkm_vma *, struct nvkm_mem *); 51 void nvkm_vm_map_at(struct nvkm_vma *, u64 offset, struct nvkm_mem *); 52 void nvkm_vm_unmap(struct nvkm_vma *); 53 void nvkm_vm_unmap_at(struct nvkm_vma *, u64 offset, u64 length); 54 55 struct nvkm_mmu { 56 const struct nvkm_mmu_func *func; 57 struct nvkm_subdev subdev; 58 59 u64 limit; 60 u8 dma_bits; 61 u8 lpg_shift; 62 }; 63 64 int nv04_mmu_new(struct nvkm_device *, int, struct nvkm_mmu **); 65 int nv41_mmu_new(struct nvkm_device *, int, struct nvkm_mmu **); 66 int nv44_mmu_new(struct nvkm_device *, int, struct nvkm_mmu **); 67 int nv50_mmu_new(struct nvkm_device *, int, struct nvkm_mmu **); 68 int gf100_mmu_new(struct nvkm_device *, int, struct nvkm_mmu **); 69 #endif 70