xref: /linux/drivers/gpu/drm/panthor/panthor_mmu.h (revision 903a7d37d9ea03cfed21040467d3d345d1e6fc76)
1 /* SPDX-License-Identifier: GPL-2.0 or MIT */
2 /* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */
3 /* Copyright 2023 Collabora ltd. */
4 
5 #ifndef __PANTHOR_MMU_H__
6 #define __PANTHOR_MMU_H__
7 
8 #include <linux/dma-resv.h>
9 
10 struct drm_exec;
11 struct drm_sched_job;
12 struct panthor_gem_object;
13 struct panthor_heap_pool;
14 struct panthor_vm;
15 struct panthor_vma;
16 struct panthor_mmu;
17 
18 int panthor_mmu_init(struct panthor_device *ptdev);
19 void panthor_mmu_unplug(struct panthor_device *ptdev);
20 void panthor_mmu_pre_reset(struct panthor_device *ptdev);
21 void panthor_mmu_post_reset(struct panthor_device *ptdev);
22 void panthor_mmu_suspend(struct panthor_device *ptdev);
23 void panthor_mmu_resume(struct panthor_device *ptdev);
24 
25 int panthor_vm_map_bo_range(struct panthor_vm *vm, struct panthor_gem_object *bo,
26 			    u64 offset, u64 size, u64 va, u32 flags);
27 int panthor_vm_unmap_range(struct panthor_vm *vm, u64 va, u64 size);
28 struct panthor_gem_object *
29 panthor_vm_get_bo_for_va(struct panthor_vm *vm, u64 va, u64 *bo_offset);
30 
31 int panthor_vm_active(struct panthor_vm *vm);
32 void panthor_vm_idle(struct panthor_vm *vm);
33 u32 panthor_vm_page_size(struct panthor_vm *vm);
34 int panthor_vm_as(struct panthor_vm *vm);
35 int panthor_vm_flush_all(struct panthor_vm *vm);
36 
37 struct panthor_heap_pool *
38 panthor_vm_get_heap_pool(struct panthor_vm *vm, bool create);
39 
40 struct panthor_vm *panthor_vm_get(struct panthor_vm *vm);
41 void panthor_vm_put(struct panthor_vm *vm);
42 struct panthor_vm *panthor_vm_create(struct panthor_device *ptdev, bool for_mcu,
43 				     u64 kernel_va_start, u64 kernel_va_size,
44 				     u64 kernel_auto_va_start,
45 				     u64 kernel_auto_va_size);
46 
47 int panthor_vm_prepare_mapped_bos_resvs(struct drm_exec *exec,
48 					struct panthor_vm *vm,
49 					u32 slot_count);
50 int panthor_vm_add_bos_resvs_deps_to_job(struct panthor_vm *vm,
51 					 struct drm_sched_job *job);
52 void panthor_vm_add_job_fence_to_bos_resvs(struct panthor_vm *vm,
53 					   struct drm_sched_job *job);
54 
55 struct dma_resv *panthor_vm_resv(struct panthor_vm *vm);
56 struct drm_gem_object *panthor_vm_root_gem(struct panthor_vm *vm);
57 
58 void panthor_vm_pool_destroy(struct panthor_file *pfile);
59 int panthor_vm_pool_create(struct panthor_file *pfile);
60 int panthor_vm_pool_create_vm(struct panthor_device *ptdev,
61 			      struct panthor_vm_pool *pool,
62 			      struct drm_panthor_vm_create *args);
63 int panthor_vm_pool_destroy_vm(struct panthor_vm_pool *pool, u32 handle);
64 struct panthor_vm *panthor_vm_pool_get_vm(struct panthor_vm_pool *pool, u32 handle);
65 
66 bool panthor_vm_has_unhandled_faults(struct panthor_vm *vm);
67 bool panthor_vm_is_unusable(struct panthor_vm *vm);
68 
69 /*
70  * PANTHOR_VM_KERNEL_AUTO_VA: Use this magic address when you want the GEM
71  * logic to auto-allocate the virtual address in the reserved kernel VA range.
72  */
73 #define PANTHOR_VM_KERNEL_AUTO_VA		~0ull
74 
75 int panthor_vm_alloc_va(struct panthor_vm *vm, u64 va, u64 size,
76 			struct drm_mm_node *va_node);
77 void panthor_vm_free_va(struct panthor_vm *vm, struct drm_mm_node *va_node);
78 
79 int panthor_vm_bind_exec_sync_op(struct drm_file *file,
80 				 struct panthor_vm *vm,
81 				 struct drm_panthor_vm_bind_op *op);
82 
83 struct drm_sched_job *
84 panthor_vm_bind_job_create(struct drm_file *file,
85 			   struct panthor_vm *vm,
86 			   const struct drm_panthor_vm_bind_op *op);
87 void panthor_vm_bind_job_put(struct drm_sched_job *job);
88 int panthor_vm_bind_job_prepare_resvs(struct drm_exec *exec,
89 				      struct drm_sched_job *job);
90 void panthor_vm_bind_job_update_resvs(struct drm_exec *exec, struct drm_sched_job *job);
91 
92 void panthor_vm_update_resvs(struct panthor_vm *vm, struct drm_exec *exec,
93 			     struct dma_fence *fence,
94 			     enum dma_resv_usage private_usage,
95 			     enum dma_resv_usage extobj_usage);
96 
97 int panthor_mmu_pt_cache_init(void);
98 void panthor_mmu_pt_cache_fini(void);
99 
100 #ifdef CONFIG_DEBUG_FS
101 void panthor_mmu_debugfs_init(struct drm_minor *minor);
102 #endif
103 
104 #endif
105