1 #ifndef __NVKM_MMU_H__ 2 #define __NVKM_MMU_H__ 3 #include <core/subdev.h> 4 #include <core/mm.h> 5 struct nvkm_device; 6 struct nvkm_mem; 7 8 struct nvkm_vm_pgt { 9 struct nvkm_gpuobj *obj[2]; 10 u32 refcount[2]; 11 }; 12 13 struct nvkm_vm_pgd { 14 struct list_head head; 15 struct nvkm_gpuobj *obj; 16 }; 17 18 struct nvkm_vma { 19 struct list_head head; 20 int refcount; 21 struct nvkm_vm *vm; 22 struct nvkm_mm_node *node; 23 u64 offset; 24 u32 access; 25 }; 26 27 struct nvkm_vm { 28 struct nvkm_mmu *mmu; 29 struct nvkm_mm mm; 30 struct kref refcount; 31 32 struct list_head pgd_list; 33 atomic_t engref[NVDEV_SUBDEV_NR]; 34 35 struct nvkm_vm_pgt *pgt; 36 u32 fpde; 37 u32 lpde; 38 }; 39 40 struct nvkm_mmu { 41 struct nvkm_subdev base; 42 43 u64 limit; 44 u8 dma_bits; 45 u32 pgt_bits; 46 u8 spg_shift; 47 u8 lpg_shift; 48 49 int (*create)(struct nvkm_mmu *, u64 offset, u64 length, 50 u64 mm_offset, struct nvkm_vm **); 51 52 void (*map_pgt)(struct nvkm_gpuobj *pgd, u32 pde, 53 struct nvkm_gpuobj *pgt[2]); 54 void (*map)(struct nvkm_vma *, struct nvkm_gpuobj *, 55 struct nvkm_mem *, u32 pte, u32 cnt, 56 u64 phys, u64 delta); 57 void (*map_sg)(struct nvkm_vma *, struct nvkm_gpuobj *, 58 struct nvkm_mem *, u32 pte, u32 cnt, dma_addr_t *); 59 void (*unmap)(struct nvkm_gpuobj *pgt, u32 pte, u32 cnt); 60 void (*flush)(struct nvkm_vm *); 61 }; 62 63 static inline struct nvkm_mmu * 64 nvkm_mmu(void *obj) 65 { 66 return (void *)nvkm_subdev(obj, NVDEV_SUBDEV_MMU); 67 } 68 69 #define nvkm_mmu_create(p,e,o,i,f,d) \ 70 nvkm_subdev_create((p), (e), (o), 0, (i), (f), (d)) 71 #define nvkm_mmu_destroy(p) \ 72 nvkm_subdev_destroy(&(p)->base) 73 #define nvkm_mmu_init(p) \ 74 nvkm_subdev_init(&(p)->base) 75 #define nvkm_mmu_fini(p,s) \ 76 nvkm_subdev_fini(&(p)->base, (s)) 77 78 #define _nvkm_mmu_dtor _nvkm_subdev_dtor 79 #define _nvkm_mmu_init _nvkm_subdev_init 80 #define _nvkm_mmu_fini _nvkm_subdev_fini 81 82 extern struct nvkm_oclass nv04_mmu_oclass; 83 extern struct nvkm_oclass nv41_mmu_oclass; 84 extern struct nvkm_oclass nv44_mmu_oclass; 85 extern struct nvkm_oclass nv50_mmu_oclass; 86 extern struct nvkm_oclass gf100_mmu_oclass; 87 88 int nv04_vm_create(struct nvkm_mmu *, u64, u64, u64, 89 struct nvkm_vm **); 90 void nv04_mmu_dtor(struct nvkm_object *); 91 92 int nvkm_vm_create(struct nvkm_mmu *, u64 offset, u64 length, u64 mm_offset, 93 u32 block, struct nvkm_vm **); 94 int nvkm_vm_new(struct nvkm_device *, u64 offset, u64 length, u64 mm_offset, 95 struct nvkm_vm **); 96 int nvkm_vm_ref(struct nvkm_vm *, struct nvkm_vm **, struct nvkm_gpuobj *pgd); 97 int nvkm_vm_get(struct nvkm_vm *, u64 size, u32 page_shift, u32 access, 98 struct nvkm_vma *); 99 void nvkm_vm_put(struct nvkm_vma *); 100 void nvkm_vm_map(struct nvkm_vma *, struct nvkm_mem *); 101 void nvkm_vm_map_at(struct nvkm_vma *, u64 offset, struct nvkm_mem *); 102 void nvkm_vm_unmap(struct nvkm_vma *); 103 void nvkm_vm_unmap_at(struct nvkm_vma *, u64 offset, u64 length); 104 #endif 105